|
18 | 18 |
|
19 | 19 | namespace DTAClient.DXGUI.Generic
|
20 | 20 | {
|
21 |
| - public class CampaignSelector : XNAWindow |
| 21 | + public class CampaignSelector : INItializableWindow |
22 | 22 | {
|
23 | 23 | private const int DEFAULT_WIDTH = 650;
|
24 | 24 | private const int DEFAULT_HEIGHT = 600;
|
@@ -92,127 +92,41 @@ private void AddMission(Mission mission)
|
92 | 92 |
|
93 | 93 | public override void Initialize()
|
94 | 94 | {
|
| 95 | + Name = nameof(CampaignSelector); |
95 | 96 | BackgroundTexture = AssetLoader.LoadTexture("missionselectorbg.png");
|
96 | 97 | ClientRectangle = new Rectangle(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
97 | 98 | BorderColor = UISettings.ActiveSettings.PanelBorderColor;
|
98 | 99 |
|
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); |
106 | 102 |
|
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)); |
113 | 104 | lbCampaignList.SelectedIndexChanged += LbCampaignList_SelectedIndexChanged;
|
114 | 105 |
|
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)); |
153 | 115 | trbDifficultySelector.ButtonTexture = AssetLoader.LoadTextureUncached(
|
154 | 116 | "trackbarButton_difficulty.png");
|
155 | 117 |
|
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)); |
184 | 119 | btnLaunch.AllowClick = false;
|
185 | 120 | btnLaunch.LeftClick += BtnLaunch_LeftClick;
|
186 | 121 |
|
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"); |
192 | 123 | btnCancel.LeftClick += BtnCancel_LeftClick;
|
193 | 124 |
|
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 |
| - |
212 | 125 | trbDifficultySelector.Value = UserINISettings.Instance.Difficulty;
|
213 | 126 |
|
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(); |
215 | 128 | chkHardcoreMode = settingCheckBoxes.Find(c => c.Name == "HardcoreMode");
|
| 129 | + |
216 | 130 | if (chkHardcoreMode != null)
|
217 | 131 | {
|
218 | 132 | chkHardcoreMode.Checked = false;
|
|
0 commit comments