-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathTeamStartMappingPanel.cs
More file actions
68 lines (53 loc) · 2.11 KB
/
TeamStartMappingPanel.cs
File metadata and controls
68 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using ClientGUI;
using DTAClient.Domain.Multiplayer;
using Microsoft.Xna.Framework;
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;
namespace DTAClient.DXGUI.Multiplayer
{
public class TeamStartMappingPanel : XNAPanel
{
private readonly int _start;
private readonly int _defaultTeamIndex = -1;
private const int ddWidth = 35;
private XNAClientDropDown ddTeams;
public event EventHandler OptionsChanged;
public TeamStartMappingPanel(WindowManager windowManager, int start) : base(windowManager)
{
_start = start;
DrawBorders = false;
}
public override void Initialize()
{
base.Initialize();
var startLabel = new XNALabel(WindowManager);
startLabel.Text = _start.ToString();
startLabel.ClientRectangle = new Rectangle(0, 0, 10, 22);
AddChild(startLabel);
ddTeams = new XNAClientDropDown(WindowManager);
ddTeams.Name = nameof(ddTeams);
ddTeams.ClientRectangle = new Rectangle(startLabel.Right, startLabel.Y - 3, ddWidth, 22);
TeamStartMapping.TEAMS.ForEach(ddTeams.AddItem);
AddChild(ddTeams);
ddTeams.SelectedIndexChanged += DD_SelectedItemChanged;
}
private void DD_SelectedItemChanged(object sender, EventArgs e) => OptionsChanged?.Invoke(sender, e);
public void SetTeamStartMapping(TeamStartMapping teamStartMapping)
{
var teamIndex = teamStartMapping?.TeamIndex ?? _defaultTeamIndex;
ddTeams.SelectedIndex = teamIndex >= 0 && teamIndex < ddTeams.Items.Count ?
teamIndex : -1;
}
public void EnableControls(bool enable) => ddTeams.AllowDropDown = enable;
public void ClearSelections() => ddTeams.SelectedIndex = _defaultTeamIndex;
public TeamStartMapping GetTeamStartMapping()
{
return new TeamStartMapping()
{
Team = ddTeams.SelectedItem?.Text,
Start = _start
};
}
}
}