Skip to content

Commit 8959f55

Browse files
committed
Migrate CampaignSelector to INItializableWindow
1 parent c5ec4fb commit 8959f55

File tree

4 files changed

+88
-131
lines changed

4 files changed

+88
-131
lines changed

DXMainClient/DXGUI/GameClass.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ private IServiceProvider BuildServiceProvider(WindowManager windowManager)
318318
.AddTransientXnaControl<XNAProgressBar>()
319319
.AddTransientXnaControl<XNASuggestionTextBox>()
320320
.AddTransientXnaControl<XNATextBox>()
321+
.AddTransientXnaControl<XNATextBlock>()
321322
.AddTransientXnaControl<XNATrackbar>()
322323
.AddTransientXnaControl<XNAChatTextBox>()
323324
.AddTransientXnaControl<ChatListBox>()

DXMainClient/DXGUI/Generic/CampaignSelector.cs

Lines changed: 18 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace DTAClient.DXGUI.Generic
2020
{
21-
public class CampaignSelector : XNAWindow
21+
public class CampaignSelector : INItializableWindow
2222
{
2323
private const int DEFAULT_WIDTH = 650;
2424
private const int DEFAULT_HEIGHT = 600;
@@ -92,127 +92,41 @@ private void AddMission(Mission mission)
9292

9393
public override void Initialize()
9494
{
95+
Name = nameof(CampaignSelector);
9596
BackgroundTexture = AssetLoader.LoadTexture("missionselectorbg.png");
9697
ClientRectangle = new Rectangle(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
9798
BorderColor = UISettings.ActiveSettings.PanelBorderColor;
9899

99-
Name = "CampaignSelector";
100-
101-
var lblSelectCampaign = new XNALabel(WindowManager);
102-
lblSelectCampaign.Name = nameof(lblSelectCampaign);
103-
lblSelectCampaign.FontIndex = 1;
104-
lblSelectCampaign.ClientRectangle = new Rectangle(12, 12, 0, 0);
105-
lblSelectCampaign.Text = "MISSIONS:".L10N("Client:Main:Missions");
100+
base.Initialize();
101+
WindowManager.CenterControlOnScreen(this);
106102

107-
lbCampaignList = new XNAListBox(WindowManager);
108-
lbCampaignList.Name = nameof(lbCampaignList);
109-
lbCampaignList.BackgroundTexture = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 2, 2);
110-
lbCampaignList.PanelBackgroundDrawMode = PanelBackgroundImageDrawMode.STRETCHED;
111-
lbCampaignList.ClientRectangle = new Rectangle(12,
112-
lblSelectCampaign.Bottom + 6, 300, 516);
103+
lbCampaignList = FindChild<XNAListBox>(nameof(lbCampaignList));
113104
lbCampaignList.SelectedIndexChanged += LbCampaignList_SelectedIndexChanged;
114105

115-
var lblMissionDescriptionHeader = new XNALabel(WindowManager);
116-
lblMissionDescriptionHeader.Name = nameof(lblMissionDescriptionHeader);
117-
lblMissionDescriptionHeader.FontIndex = 1;
118-
lblMissionDescriptionHeader.ClientRectangle = new Rectangle(
119-
lbCampaignList.Right + 12,
120-
lblSelectCampaign.Y, 0, 0);
121-
lblMissionDescriptionHeader.Text = "MISSION DESCRIPTION:".L10N("Client:Main:MissionDescription");
122-
123-
tbMissionDescription = new XNATextBlock(WindowManager);
124-
tbMissionDescription.Name = nameof(tbMissionDescription);
125-
tbMissionDescription.ClientRectangle = new Rectangle(
126-
lblMissionDescriptionHeader.X,
127-
lblMissionDescriptionHeader.Bottom + 6,
128-
Width - 24 - lbCampaignList.Right, 430);
129-
tbMissionDescription.PanelBackgroundDrawMode = PanelBackgroundImageDrawMode.STRETCHED;
130-
tbMissionDescription.Alpha = 1.0f;
131-
132-
tbMissionDescription.BackgroundTexture = AssetLoader.CreateTexture(AssetLoader.GetColorFromString(ClientConfiguration.Instance.AltUIBackgroundColor),
133-
tbMissionDescription.Width, tbMissionDescription.Height);
134-
135-
var lblDifficultyLevel = new XNALabel(WindowManager);
136-
lblDifficultyLevel.Name = nameof(lblDifficultyLevel);
137-
lblDifficultyLevel.Text = "DIFFICULTY LEVEL".L10N("Client:Main:DifficultyLevel");
138-
lblDifficultyLevel.FontIndex = 1;
139-
Vector2 textSize = Renderer.GetTextDimensions(lblDifficultyLevel.Text, lblDifficultyLevel.FontIndex);
140-
lblDifficultyLevel.ClientRectangle = new Rectangle(
141-
tbMissionDescription.X + (tbMissionDescription.Width - (int)textSize.X) / 2,
142-
tbMissionDescription.Bottom + 12, (int)textSize.X, (int)textSize.Y);
143-
144-
trbDifficultySelector = new XNATrackbar(WindowManager);
145-
trbDifficultySelector.Name = nameof(trbDifficultySelector);
146-
trbDifficultySelector.ClientRectangle = new Rectangle(
147-
tbMissionDescription.X, lblDifficultyLevel.Bottom + 6,
148-
tbMissionDescription.Width, 30);
149-
trbDifficultySelector.MinValue = 0;
150-
trbDifficultySelector.MaxValue = 2;
151-
trbDifficultySelector.BackgroundTexture = AssetLoader.CreateTexture(
152-
new Color(0, 0, 0, 128), 2, 2);
106+
tbMissionDescription = FindChild<XNATextBlock>(nameof(tbMissionDescription));
107+
108+
if (tbMissionDescription.BackgroundTexture == null)
109+
{
110+
tbMissionDescription.BackgroundTexture = AssetLoader.CreateTexture(AssetLoader.GetColorFromString(ClientConfiguration.Instance.AltUIBackgroundColor),
111+
tbMissionDescription.Width, tbMissionDescription.Height);
112+
}
113+
114+
trbDifficultySelector = FindChild<XNATrackbar>(nameof(trbDifficultySelector));
153115
trbDifficultySelector.ButtonTexture = AssetLoader.LoadTextureUncached(
154116
"trackbarButton_difficulty.png");
155117

156-
var lblEasy = new XNALabel(WindowManager);
157-
lblEasy.Name = nameof(lblEasy);
158-
lblEasy.FontIndex = 1;
159-
lblEasy.Text = "EASY".L10N("Client:Main:DifficultyEasy");
160-
lblEasy.ClientRectangle = new Rectangle(trbDifficultySelector.X,
161-
trbDifficultySelector.Bottom + 6, 1, 1);
162-
163-
var lblNormal = new XNALabel(WindowManager);
164-
lblNormal.Name = nameof(lblNormal);
165-
lblNormal.FontIndex = 1;
166-
lblNormal.Text = "NORMAL".L10N("Client:Main:DifficultyNormal");
167-
textSize = Renderer.GetTextDimensions(lblNormal.Text, lblNormal.FontIndex);
168-
lblNormal.ClientRectangle = new Rectangle(
169-
tbMissionDescription.X + (tbMissionDescription.Width - (int)textSize.X) / 2,
170-
lblEasy.Y, (int)textSize.X, (int)textSize.Y);
171-
172-
var lblHard = new XNALabel(WindowManager);
173-
lblHard.Name = nameof(lblHard);
174-
lblHard.FontIndex = 1;
175-
lblHard.Text = "HARD".L10N("Client:Main:DifficultyHard");
176-
lblHard.ClientRectangle = new Rectangle(
177-
tbMissionDescription.Right - lblHard.Width,
178-
lblEasy.Y, 1, 1);
179-
180-
btnLaunch = new XNAClientButton(WindowManager);
181-
btnLaunch.Name = nameof(btnLaunch);
182-
btnLaunch.ClientRectangle = new Rectangle(12, Height - 35, UIDesignConstants.BUTTON_WIDTH_133, UIDesignConstants.BUTTON_HEIGHT);
183-
btnLaunch.Text = "Launch".L10N("Client:Main:ButtonLaunch");
118+
btnLaunch = FindChild<XNAClientButton>(nameof(btnLaunch));
184119
btnLaunch.AllowClick = false;
185120
btnLaunch.LeftClick += BtnLaunch_LeftClick;
186121

187-
var btnCancel = new XNAClientButton(WindowManager);
188-
btnCancel.Name = nameof(btnCancel);
189-
btnCancel.ClientRectangle = new Rectangle(Width - 145,
190-
btnLaunch.Y, UIDesignConstants.BUTTON_WIDTH_133, UIDesignConstants.BUTTON_HEIGHT);
191-
btnCancel.Text = "Cancel".L10N("Client:Main:ButtonCancel");
122+
var btnCancel = FindChild<XNAClientButton>("btnCancel");
192123
btnCancel.LeftClick += BtnCancel_LeftClick;
193124

194-
AddChild(lblSelectCampaign);
195-
AddChild(lblMissionDescriptionHeader);
196-
AddChild(lbCampaignList);
197-
AddChild(tbMissionDescription);
198-
AddChild(lblDifficultyLevel);
199-
AddChild(btnLaunch);
200-
AddChild(btnCancel);
201-
AddChild(trbDifficultySelector);
202-
AddChild(lblEasy);
203-
AddChild(lblNormal);
204-
AddChild(lblHard);
205-
206-
// Set control attributes from INI file
207-
base.Initialize();
208-
209-
// Center on screen
210-
CenterOnParent();
211-
212125
trbDifficultySelector.Value = UserINISettings.Instance.Difficulty;
213126

214-
settingCheckBoxes = this.Children.Where(c => c is SettingCheckBox chk).Cast<SettingCheckBox>().ToList();
127+
settingCheckBoxes = Children.Where(c => c is SettingCheckBox chk).Cast<SettingCheckBox>().ToList();
215128
chkHardcoreMode = settingCheckBoxes.Find(c => c.Name == "HardcoreMode");
129+
216130
if (chkHardcoreMode != null)
217131
{
218132
chkHardcoreMode.Checked = false;

DXMainClient/DXGUI/Generic/CampaignTagSelector.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class CampaignTagSelector : INItializableWindow
1212
{
1313
private const int DEFAULT_WIDTH = 576;
1414
private const int DEFAULT_HEIGHT = 475;
15-
private string _iniSectionName = nameof(CampaignTagSelector);
1615
private DiscordHandler discordHandler;
1716

1817
public CampaignTagSelector(WindowManager windowManager, DiscordHandler discordHandler)
@@ -32,8 +31,7 @@ public override void Initialize()
3231
CampaignSelector = new CampaignSelector(WindowManager, discordHandler, this);
3332
DarkeningPanel.AddAndInitializeWithControl(WindowManager, CampaignSelector);
3433
CampaignSelector.Disable();
35-
36-
Name = _iniSectionName;
34+
Name = nameof(CampaignTagSelector);
3735

3836
if (!ClientConfiguration.Instance.CampaignTagSelectorEnabled)
3937
return;

DXMainClient/Resources/DTA/CampaignSelector.ini

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,96 @@ BasedOn=GenericWindow.ini
55
BackgroundTexture=MainMenu/dbak.png
66
DrawMode=Centered
77
DrawBorders=false
8-
Size=672,600
8+
$Width=682
9+
$Height=600
10+
; Controls
11+
$CC00=lblSelectCampaign:XNALabel
12+
$CC01=lbCampaignList:XNAListBox
13+
$CC02=lblMissionDescriptionHeader:XNALabel
14+
$CC03=tbMissionDescription:XNATextBlock
15+
$CC04=lblDifficultyLevel:XNALabel
16+
$CC05=trbDifficultySelector:XNATrackbar
17+
$CC06=lblEasy:XNALabel
18+
$CC07=lblNormal:XNALabel
19+
$CC08=lblHard:XNALabel
20+
$CC09=btnLaunch:XNAClientButton
21+
$CC10=btnCancel:XNAClientButton
22+
23+
[lblSelectCampaign]
24+
$X=16
25+
$Y=EMPTY_SPACE_TOP
26+
FontIndex=1
27+
Text=MISSIONS:
928

1029
[lbCampaignList]
11-
Size=322,554
30+
$X=16
31+
$Y=getBottom(lblSelectCampaign) + 6
32+
$Width=322
33+
$Height=554
34+
SolidColorBackgroundTexture=0,0,0,128
35+
DrawMode=Stretched
1236
EnableScrollbar=true
1337

1438
[lblMissionDescriptionHeader]
15-
TextAnchor=RIGHT
16-
AnchorPoint=346,12
39+
$X=getRight(lbCampaignList) + 12
40+
$Y=getY(lblSelectCampaign)
41+
FontIndex=1
42+
Text=MISSION DESCRIPTION:
1743

1844
[tbMissionDescription]
19-
Location=346,34
20-
DistanceFromRightBorder=12
45+
$X=getX(lblMissionDescriptionHeader)
46+
$Y=getY(lbCampaignList)
47+
$Width=getWidth(CampaignSelector) - getX($Self) - 16
48+
$Height=430
49+
DrawMode=Stretched
2150

2251
[lblDifficultyLevel]
23-
TextAnchor=HORIZONTAL_CENTER
24-
AnchorPoint=503,476
52+
FontIndex=1
53+
Text=DIFFICULTY LEVEL
54+
$X=getX(tbMissionDescription) + (getWidth(tbMissionDescription) / 2) - (getWidth($Self) / 2)
55+
$Y=getBottom(tbMissionDescription) + EMPTY_SPACE_TOP
2556

2657
[trbDifficultySelector]
27-
Location=346,498
28-
DistanceFromRightBorder=12
58+
$X=getX(tbMissionDescription)
59+
$Y=getBottom(tbMissionDescription) + 34
60+
$Width=getWidth(tbMissionDescription)
61+
$Height=30
62+
SolidColorBackgroundTexture=0,0,0,128
63+
MinValue=0
64+
MaxValue=2
2965

3066
[lblEasy]
31-
TextAnchor=RIGHT
32-
AnchorPoint=346,534
67+
FontIndex=1
68+
Text=EASY
69+
$X=getX(trbDifficultySelector)
70+
$Y=getBottom(trbDifficultySelector) + 5
3371

3472
[lblNormal]
35-
TextAnchor=HORIZONTAL_CENTER
36-
AnchorPoint=503,534
73+
FontIndex=1
74+
Text=NORMAL
75+
$X=getX(trbDifficultySelector) + (getWidth(trbDifficultySelector) / 2) - (getWidth($Self) / 2)
76+
$Y=getY(lblEasy)
3777

3878
[lblHard]
39-
TextAnchor=LEFT
40-
AnchorPoint=660,534
41-
42-
[lblDifficultyNames]
43-
Location=346,538
79+
FontIndex=1
80+
Text=HARD
81+
$X=getRight(trbDifficultySelector) - getWidth($Self)
82+
$Y=getY(lblEasy)
4483

4584
[btnLaunch]
85+
$Width=147
86+
$Height=23
87+
$X=getX(trbDifficultySelector)
88+
$Y=getHeight(CampaignSelector) - getHeight($Self) - 12
4689
IdleTexture=147pxbtn.png
4790
HoverTexture=147pxbtn_c.png
48-
Width=147
49-
DistanceFromRightBorder=179
50-
DistanceFromBottomBorder=12
91+
Text=Launch
5192

5293
[btnCancel]
94+
$Width=147
95+
$Height=23
96+
$X=getRight(trbDifficultySelector) - getWidth($Self)
97+
$Y=getY(btnLaunch)
5398
IdleTexture=147pxbtn.png
5499
HoverTexture=147pxbtn_c.png
55-
Width=147
56-
DistanceFromRightBorder=12
100+
Text=Cancel

0 commit comments

Comments
 (0)