comparison Options.cs @ 0:a54c09901f4e default tip

Initial commit to Mercurial at v1.9.3 - now GPLed!
author IBBoard <dev@ibboard.co.uk>
date Sat, 06 Oct 2018 19:19:03 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a54c09901f4e
1 // This file is a part of the Texture Tool program and is copyright 2006-2018 IBBoard.
2 //
3 // The file and the library/program it is in are licensed under the GNU GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
4
5 using System;
6 using System.Drawing;
7 using System.Collections;
8 using System.ComponentModel;
9 using System.Windows.Forms;
10 using System.IO;
11 using System.Text.RegularExpressions;
12
13 using IBBoard;
14 using IBBoard.Graphics;
15
16 namespace IBBoard.Relic.TextureTool
17 {
18 /// <summary>
19 /// Summary description for Options.
20 /// </summary>
21 public class Options : System.Windows.Forms.Form
22 {
23 private Preferences pref;
24
25 private System.Windows.Forms.Button bttnImportTeamcolour;
26 private System.Windows.Forms.Button bttnOK;
27 private System.Windows.Forms.Button bttnCancel;
28 private System.Windows.Forms.ColorDialog colorDialog;
29 private System.Windows.Forms.OpenFileDialog openFileDialog;
30 private System.Windows.Forms.Label lblDoWPath;
31 private System.Windows.Forms.Button bttnDoWPath;
32 private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
33 private System.Windows.Forms.Button bttnPrimary;
34 private System.Windows.Forms.Button bttnSecondary;
35 private System.Windows.Forms.Button bttnTrim;
36 private System.Windows.Forms.Button bttnWeapon;
37 private System.Windows.Forms.Button bttnTrim2;
38 private System.Windows.Forms.PictureBox pbBadge;
39 private System.Windows.Forms.Label lblBadge;
40 private System.Windows.Forms.Label lblBanner;
41 private System.Windows.Forms.PictureBox pbBanner;
42 private System.Windows.Forms.Button bttnSave;
43 private System.Windows.Forms.TabControl tabControl1;
44 private System.Windows.Forms.TabPage tabPage1;
45 private System.Windows.Forms.TabPage tabPage2;
46 private System.Windows.Forms.TextBox txtDoWPath;
47 private System.Windows.Forms.Label label1;
48 private System.Windows.Forms.Button bttnTexturePath;
49 private System.Windows.Forms.TextBox txtTexturePath;
50 private System.Windows.Forms.Label label2;
51 private System.Windows.Forms.Button bttnTeamcolourPath;
52 private System.Windows.Forms.TextBox txtTeamcolourPath;
53 private System.Windows.Forms.Label label3;
54 private System.Windows.Forms.RadioButton rbBasicMode;
55 private System.Windows.Forms.RadioButton rbAdvancedMode;
56 /// <summary>
57 /// Required designer variable.
58 /// </summary>
59 private System.ComponentModel.Container components = null;
60
61 public Options(Preferences p)
62 {
63 pref = p;
64 //
65 // Required for Windows Form Designer support
66 //
67 InitializeComponent();
68
69 pbBadge.Tag = "";
70 pbBanner.Tag = "";
71
72 colorDialog.FullOpen = true;
73 txtDoWPath.Text = pref["DoWPath"].ToString();
74 txtTeamcolourPath.Text = pref["TeamcolourPath"].ToString();
75 txtTexturePath.Text = pref["TexturePath"].ToString();
76
77 if ((bool)pref["settingBasic"])
78 {
79 rbBasicMode.Checked = true;
80 }
81 else
82 {
83 rbAdvancedMode.Checked = true;
84 }
85
86 SetButtonColour(bttnPrimary, Color.FromArgb((byte)pref["PrimaryRed"], (byte)pref["PrimaryGreen"], (byte)pref["PrimaryBlue"]));
87 SetButtonColour(bttnSecondary, Color.FromArgb((byte)pref["SecondaryRed"], (byte)pref["SecondaryGreen"], (byte)pref["SecondaryBlue"]));
88 SetButtonColour(bttnTrim, Color.FromArgb((byte)pref["TrimRed"], (byte)pref["TrimGreen"], (byte)pref["TrimBlue"]));
89 SetButtonColour(bttnWeapon, Color.FromArgb((byte)pref["WeaponRed"], (byte)pref["WeaponGreen"], (byte)pref["WeaponBlue"]));
90 SetButtonColour(bttnTrim2, Color.FromArgb((byte)pref["EyesRed"], (byte)pref["EyesGreen"], (byte)pref["EyesBlue"]));
91
92 string temp = pref["BadgeName"].ToString();
93
94 if (temp.LastIndexOf(IBBoard.Constants.DirectoryChar)==-1)
95 {
96 temp = pref["DoWPath"].ToString().TrimEnd(IBBoard.Constants.DirectoryChar)+IBBoard.Constants.DirectoryChar+"badges"+IBBoard.Constants.DirectoryChar+pref["BadgeName"].ToString();
97 }
98
99 if (File.Exists(temp))
100 {
101 SetPictureBoxImage(pbBadge, temp);
102 }
103
104 temp = pref["BannerName"].ToString();
105
106 if (temp.LastIndexOf(IBBoard.Constants.DirectoryChar)==-1)
107 {
108 temp = pref["DoWPath"].ToString().TrimEnd(IBBoard.Constants.DirectoryChar)+IBBoard.Constants.DirectoryChar+"banners"+IBBoard.Constants.DirectoryChar+pref["BannerName"].ToString();
109 }
110
111 if (File.Exists(temp))
112 {
113 SetPictureBoxImage(pbBanner, temp);
114 }
115 }
116
117 /// <summary>
118 /// Clean up any resources being used.
119 /// </summary>
120 protected override void Dispose( bool disposing )
121 {
122 if( disposing )
123 {
124 if(components != null)
125 {
126 components.Dispose();
127 }
128 }
129 base.Dispose( disposing );
130 }
131
132 #region Windows Form Designer generated code
133 /// <summary>
134 /// Required method for Designer support - do not modify
135 /// the contents of this method with the code editor.
136 /// </summary>
137 private void InitializeComponent()
138 {
139 this.colorDialog = new System.Windows.Forms.ColorDialog();
140 this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
141 this.bttnImportTeamcolour = new System.Windows.Forms.Button();
142 this.bttnOK = new System.Windows.Forms.Button();
143 this.bttnCancel = new System.Windows.Forms.Button();
144 this.txtDoWPath = new System.Windows.Forms.TextBox();
145 this.lblDoWPath = new System.Windows.Forms.Label();
146 this.bttnDoWPath = new System.Windows.Forms.Button();
147 this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
148 this.pbBanner = new System.Windows.Forms.PictureBox();
149 this.lblBanner = new System.Windows.Forms.Label();
150 this.lblBadge = new System.Windows.Forms.Label();
151 this.pbBadge = new System.Windows.Forms.PictureBox();
152 this.bttnTrim2 = new System.Windows.Forms.Button();
153 this.bttnWeapon = new System.Windows.Forms.Button();
154 this.bttnTrim = new System.Windows.Forms.Button();
155 this.bttnSecondary = new System.Windows.Forms.Button();
156 this.bttnPrimary = new System.Windows.Forms.Button();
157 this.bttnSave = new System.Windows.Forms.Button();
158 this.tabControl1 = new System.Windows.Forms.TabControl();
159 this.tabPage1 = new System.Windows.Forms.TabPage();
160 this.rbAdvancedMode = new System.Windows.Forms.RadioButton();
161 this.rbBasicMode = new System.Windows.Forms.RadioButton();
162 this.label3 = new System.Windows.Forms.Label();
163 this.label2 = new System.Windows.Forms.Label();
164 this.bttnTeamcolourPath = new System.Windows.Forms.Button();
165 this.txtTeamcolourPath = new System.Windows.Forms.TextBox();
166 this.label1 = new System.Windows.Forms.Label();
167 this.bttnTexturePath = new System.Windows.Forms.Button();
168 this.txtTexturePath = new System.Windows.Forms.TextBox();
169 this.tabPage2 = new System.Windows.Forms.TabPage();
170 this.tabControl1.SuspendLayout();
171 this.tabPage1.SuspendLayout();
172 this.tabPage2.SuspendLayout();
173 this.SuspendLayout();
174 //
175 // bttnImportTeamcolour
176 //
177 this.bttnImportTeamcolour.FlatStyle = System.Windows.Forms.FlatStyle.System;
178 this.bttnImportTeamcolour.Location = new System.Drawing.Point(16, 168);
179 this.bttnImportTeamcolour.Name = "bttnImportTeamcolour";
180 this.bttnImportTeamcolour.Size = new System.Drawing.Size(128, 23);
181 this.bttnImportTeamcolour.TabIndex = 3;
182 this.bttnImportTeamcolour.Text = "Import Teamcolour";
183 this.bttnImportTeamcolour.Click += new System.EventHandler(this.bttnImportTeamcolour_Click);
184 //
185 // bttnOK
186 //
187 this.bttnOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
188 this.bttnOK.Location = new System.Drawing.Point(368, 240);
189 this.bttnOK.Name = "bttnOK";
190 this.bttnOK.TabIndex = 2;
191 this.bttnOK.Text = "OK";
192 this.bttnOK.Click += new System.EventHandler(this.bttnOK_Click);
193 //
194 // bttnCancel
195 //
196 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
197 this.bttnCancel.Location = new System.Drawing.Point(280, 240);
198 this.bttnCancel.Name = "bttnCancel";
199 this.bttnCancel.TabIndex = 1;
200 this.bttnCancel.Text = "Cancel";
201 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
202 //
203 // txtDoWPath
204 //
205 this.txtDoWPath.Cursor = System.Windows.Forms.Cursors.Default;
206 this.txtDoWPath.Location = new System.Drawing.Point(112, 8);
207 this.txtDoWPath.Name = "txtDoWPath";
208 this.txtDoWPath.Size = new System.Drawing.Size(240, 20);
209 this.txtDoWPath.TabIndex = 3;
210 this.txtDoWPath.TabStop = false;
211 this.txtDoWPath.Text = "";
212 this.txtDoWPath.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textbox_KeyDown);
213 this.txtDoWPath.TextChanged += new System.EventHandler(this.textbox_TextChanged);
214 this.txtDoWPath.Leave += new System.EventHandler(this.txtDoWPath_Leave);
215 //
216 // lblDoWPath
217 //
218 this.lblDoWPath.Location = new System.Drawing.Point(8, 8);
219 this.lblDoWPath.Name = "lblDoWPath";
220 this.lblDoWPath.TabIndex = 4;
221 this.lblDoWPath.Text = "Dawn of War Path:";
222 this.lblDoWPath.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
223 //
224 // bttnDoWPath
225 //
226 this.bttnDoWPath.FlatStyle = System.Windows.Forms.FlatStyle.System;
227 this.bttnDoWPath.Location = new System.Drawing.Point(360, 8);
228 this.bttnDoWPath.Name = "bttnDoWPath";
229 this.bttnDoWPath.Size = new System.Drawing.Size(56, 23);
230 this.bttnDoWPath.TabIndex = 4;
231 this.bttnDoWPath.Text = "Select";
232 this.bttnDoWPath.Click += new System.EventHandler(this.bttnDoWPath_Click);
233 //
234 // pbBanner
235 //
236 this.pbBanner.Location = new System.Drawing.Point(296, 64);
237 this.pbBanner.Name = "pbBanner";
238 this.pbBanner.Size = new System.Drawing.Size(64, 96);
239 this.pbBanner.TabIndex = 8;
240 this.pbBanner.TabStop = false;
241 this.pbBanner.Click += new System.EventHandler(this.pbBanner_Click);
242 //
243 // lblBanner
244 //
245 this.lblBanner.Location = new System.Drawing.Point(232, 72);
246 this.lblBanner.Name = "lblBanner";
247 this.lblBanner.Size = new System.Drawing.Size(64, 23);
248 this.lblBanner.TabIndex = 7;
249 this.lblBanner.Text = "Banner:";
250 this.lblBanner.TextAlign = System.Drawing.ContentAlignment.TopRight;
251 //
252 // lblBadge
253 //
254 this.lblBadge.Location = new System.Drawing.Point(24, 72);
255 this.lblBadge.Name = "lblBadge";
256 this.lblBadge.Size = new System.Drawing.Size(48, 23);
257 this.lblBadge.TabIndex = 6;
258 this.lblBadge.Text = "Badge:";
259 this.lblBadge.TextAlign = System.Drawing.ContentAlignment.TopRight;
260 //
261 // pbBadge
262 //
263 this.pbBadge.BackColor = System.Drawing.SystemColors.Control;
264 this.pbBadge.Location = new System.Drawing.Point(80, 72);
265 this.pbBadge.Name = "pbBadge";
266 this.pbBadge.Size = new System.Drawing.Size(64, 64);
267 this.pbBadge.TabIndex = 5;
268 this.pbBadge.TabStop = false;
269 this.pbBadge.Click += new System.EventHandler(this.pbBadge_Click);
270 //
271 // bttnTrim2
272 //
273 this.bttnTrim2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
274 this.bttnTrim2.Location = new System.Drawing.Point(336, 16);
275 this.bttnTrim2.Name = "bttnTrim2";
276 this.bttnTrim2.Size = new System.Drawing.Size(72, 40);
277 this.bttnTrim2.TabIndex = 4;
278 this.bttnTrim2.Tag = "Eye";
279 this.bttnTrim2.Text = "Trim 2/Eye";
280 this.bttnTrim2.Click += new System.EventHandler(this.bttnTrim2_Click);
281 //
282 // bttnWeapon
283 //
284 this.bttnWeapon.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
285 this.bttnWeapon.Location = new System.Drawing.Point(256, 16);
286 this.bttnWeapon.Name = "bttnWeapon";
287 this.bttnWeapon.Size = new System.Drawing.Size(72, 40);
288 this.bttnWeapon.TabIndex = 3;
289 this.bttnWeapon.Tag = "Weapon";
290 this.bttnWeapon.Text = "Weapon";
291 this.bttnWeapon.Click += new System.EventHandler(this.bttnWeapon_Click);
292 //
293 // bttnTrim
294 //
295 this.bttnTrim.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
296 this.bttnTrim.Location = new System.Drawing.Point(176, 16);
297 this.bttnTrim.Name = "bttnTrim";
298 this.bttnTrim.Size = new System.Drawing.Size(72, 40);
299 this.bttnTrim.TabIndex = 2;
300 this.bttnTrim.Tag = "Trim";
301 this.bttnTrim.Text = "Trim";
302 this.bttnTrim.Click += new System.EventHandler(this.bttnTrim_Click);
303 //
304 // bttnSecondary
305 //
306 this.bttnSecondary.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
307 this.bttnSecondary.Location = new System.Drawing.Point(96, 16);
308 this.bttnSecondary.Name = "bttnSecondary";
309 this.bttnSecondary.Size = new System.Drawing.Size(72, 40);
310 this.bttnSecondary.TabIndex = 1;
311 this.bttnSecondary.Tag = "Secondary";
312 this.bttnSecondary.Text = "Secondary";
313 this.bttnSecondary.Click += new System.EventHandler(this.bttnSecondary_Click);
314 //
315 // bttnPrimary
316 //
317 this.bttnPrimary.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
318 this.bttnPrimary.Location = new System.Drawing.Point(16, 16);
319 this.bttnPrimary.Name = "bttnPrimary";
320 this.bttnPrimary.Size = new System.Drawing.Size(72, 40);
321 this.bttnPrimary.TabIndex = 0;
322 this.bttnPrimary.Tag = "Primary";
323 this.bttnPrimary.Text = "Primary";
324 this.bttnPrimary.Click += new System.EventHandler(this.bttnPrimary_Click);
325 //
326 // bttnSave
327 //
328 this.bttnSave.Enabled = false;
329 this.bttnSave.FlatStyle = System.Windows.Forms.FlatStyle.System;
330 this.bttnSave.Location = new System.Drawing.Point(8, 240);
331 this.bttnSave.Name = "bttnSave";
332 this.bttnSave.Size = new System.Drawing.Size(112, 23);
333 this.bttnSave.TabIndex = 7;
334 this.bttnSave.Text = "Save Preferences";
335 this.bttnSave.Click += new System.EventHandler(this.bttnSave_Click);
336 //
337 // tabControl1
338 //
339 this.tabControl1.Controls.Add(this.tabPage1);
340 this.tabControl1.Controls.Add(this.tabPage2);
341 this.tabControl1.Location = new System.Drawing.Point(8, 8);
342 this.tabControl1.Name = "tabControl1";
343 this.tabControl1.SelectedIndex = 0;
344 this.tabControl1.Size = new System.Drawing.Size(432, 224);
345 this.tabControl1.TabIndex = 8;
346 //
347 // tabPage1
348 //
349 this.tabPage1.Controls.Add(this.rbAdvancedMode);
350 this.tabPage1.Controls.Add(this.rbBasicMode);
351 this.tabPage1.Controls.Add(this.label3);
352 this.tabPage1.Controls.Add(this.label2);
353 this.tabPage1.Controls.Add(this.bttnTeamcolourPath);
354 this.tabPage1.Controls.Add(this.txtTeamcolourPath);
355 this.tabPage1.Controls.Add(this.label1);
356 this.tabPage1.Controls.Add(this.bttnTexturePath);
357 this.tabPage1.Controls.Add(this.txtTexturePath);
358 this.tabPage1.Controls.Add(this.lblDoWPath);
359 this.tabPage1.Controls.Add(this.bttnDoWPath);
360 this.tabPage1.Controls.Add(this.txtDoWPath);
361 this.tabPage1.Location = new System.Drawing.Point(4, 22);
362 this.tabPage1.Name = "tabPage1";
363 this.tabPage1.Size = new System.Drawing.Size(424, 198);
364 this.tabPage1.TabIndex = 0;
365 this.tabPage1.Text = "Game/Path Settings";
366 //
367 // rbAdvancedMode
368 //
369 this.rbAdvancedMode.Location = new System.Drawing.Point(200, 120);
370 this.rbAdvancedMode.Name = "rbAdvancedMode";
371 this.rbAdvancedMode.Size = new System.Drawing.Size(80, 24);
372 this.rbAdvancedMode.TabIndex = 13;
373 this.rbAdvancedMode.Text = "Advanced";
374 this.rbAdvancedMode.CheckedChanged += new System.EventHandler(this.rbMode_CheckedChanged);
375 //
376 // rbBasicMode
377 //
378 this.rbBasicMode.Location = new System.Drawing.Point(120, 120);
379 this.rbBasicMode.Name = "rbBasicMode";
380 this.rbBasicMode.Size = new System.Drawing.Size(72, 24);
381 this.rbBasicMode.TabIndex = 12;
382 this.rbBasicMode.Text = "Basic";
383 this.rbBasicMode.CheckedChanged += new System.EventHandler(this.rbMode_CheckedChanged);
384 //
385 // label3
386 //
387 this.label3.Location = new System.Drawing.Point(8, 120);
388 this.label3.Name = "label3";
389 this.label3.TabIndex = 11;
390 this.label3.Text = "Texture Mode:";
391 this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
392 //
393 // label2
394 //
395 this.label2.Location = new System.Drawing.Point(8, 72);
396 this.label2.Name = "label2";
397 this.label2.TabIndex = 10;
398 this.label2.Text = "Teamcolour Path:";
399 this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
400 //
401 // bttnTeamcolourPath
402 //
403 this.bttnTeamcolourPath.FlatStyle = System.Windows.Forms.FlatStyle.System;
404 this.bttnTeamcolourPath.Location = new System.Drawing.Point(360, 72);
405 this.bttnTeamcolourPath.Name = "bttnTeamcolourPath";
406 this.bttnTeamcolourPath.Size = new System.Drawing.Size(56, 23);
407 this.bttnTeamcolourPath.TabIndex = 9;
408 this.bttnTeamcolourPath.Text = "Select";
409 this.bttnTeamcolourPath.Click += new System.EventHandler(this.bttnTeamcolourPath_Click);
410 //
411 // txtTeamcolourPath
412 //
413 this.txtTeamcolourPath.Cursor = System.Windows.Forms.Cursors.Default;
414 this.txtTeamcolourPath.Location = new System.Drawing.Point(112, 72);
415 this.txtTeamcolourPath.Name = "txtTeamcolourPath";
416 this.txtTeamcolourPath.Size = new System.Drawing.Size(240, 20);
417 this.txtTeamcolourPath.TabIndex = 8;
418 this.txtTeamcolourPath.TabStop = false;
419 this.txtTeamcolourPath.Text = "";
420 this.txtTeamcolourPath.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textbox_KeyDown);
421 this.txtTeamcolourPath.TextChanged += new System.EventHandler(this.textbox_TextChanged);
422 this.txtTeamcolourPath.Leave += new System.EventHandler(this.textbox_Leave);
423 //
424 // label1
425 //
426 this.label1.Location = new System.Drawing.Point(8, 40);
427 this.label1.Name = "label1";
428 this.label1.TabIndex = 7;
429 this.label1.Text = "Texture Path:";
430 this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
431 //
432 // bttnTexturePath
433 //
434 this.bttnTexturePath.FlatStyle = System.Windows.Forms.FlatStyle.System;
435 this.bttnTexturePath.Location = new System.Drawing.Point(360, 40);
436 this.bttnTexturePath.Name = "bttnTexturePath";
437 this.bttnTexturePath.Size = new System.Drawing.Size(56, 23);
438 this.bttnTexturePath.TabIndex = 6;
439 this.bttnTexturePath.Text = "Select";
440 this.bttnTexturePath.Click += new System.EventHandler(this.bttnTexturePath_Click);
441 //
442 // txtTexturePath
443 //
444 this.txtTexturePath.Cursor = System.Windows.Forms.Cursors.Default;
445 this.txtTexturePath.Location = new System.Drawing.Point(112, 40);
446 this.txtTexturePath.Name = "txtTexturePath";
447 this.txtTexturePath.Size = new System.Drawing.Size(240, 20);
448 this.txtTexturePath.TabIndex = 5;
449 this.txtTexturePath.TabStop = false;
450 this.txtTexturePath.Text = "";
451 this.txtTexturePath.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textbox_KeyDown);
452 this.txtTexturePath.TextChanged += new System.EventHandler(this.textbox_TextChanged);
453 this.txtTexturePath.Leave += new System.EventHandler(this.textbox_Leave);
454 //
455 // tabPage2
456 //
457 this.tabPage2.Controls.Add(this.bttnTrim2);
458 this.tabPage2.Controls.Add(this.pbBadge);
459 this.tabPage2.Controls.Add(this.lblBadge);
460 this.tabPage2.Controls.Add(this.lblBanner);
461 this.tabPage2.Controls.Add(this.bttnImportTeamcolour);
462 this.tabPage2.Controls.Add(this.pbBanner);
463 this.tabPage2.Controls.Add(this.bttnWeapon);
464 this.tabPage2.Controls.Add(this.bttnPrimary);
465 this.tabPage2.Controls.Add(this.bttnSecondary);
466 this.tabPage2.Controls.Add(this.bttnTrim);
467 this.tabPage2.Location = new System.Drawing.Point(4, 22);
468 this.tabPage2.Name = "tabPage2";
469 this.tabPage2.Size = new System.Drawing.Size(424, 198);
470 this.tabPage2.TabIndex = 1;
471 this.tabPage2.Text = "Team Colouring Settings";
472 //
473 // Options
474 //
475 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
476 this.ClientSize = new System.Drawing.Size(450, 270);
477 this.ControlBox = false;
478 this.Controls.Add(this.tabControl1);
479 this.Controls.Add(this.bttnSave);
480 this.Controls.Add(this.bttnCancel);
481 this.Controls.Add(this.bttnOK);
482 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
483 this.MinimizeBox = false;
484 this.Name = "Options";
485 this.ShowInTaskbar = false;
486 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
487 this.Text = "Options";
488 this.tabControl1.ResumeLayout(false);
489 this.tabPage1.ResumeLayout(false);
490 this.tabPage2.ResumeLayout(false);
491 this.ResumeLayout(false);
492
493 }
494 #endregion
495
496 private void bttnDoWPath_Click(object sender, System.EventArgs e)
497 {
498 setPath(txtDoWPath);
499 }
500
501 private void bttnOK_Click(object sender, System.EventArgs e)
502 {
503 setPrefs();
504
505 this.Close();
506 }
507
508 private void bttnCancel_Click(object sender, System.EventArgs e)
509 {
510 this.Close();
511 }
512
513 private void bttnPrimary_Click(object sender, System.EventArgs e)
514 {
515 colorDialog.Color = bttnPrimary.BackColor;
516 DialogResult dr = colorDialog.ShowDialog(this);
517
518 if (dr==DialogResult.OK)
519 {
520 SetButtonColour(bttnPrimary, colorDialog.Color);
521 }
522 }
523
524 private void bttnSecondary_Click(object sender, System.EventArgs e)
525 {
526 colorDialog.Color = bttnSecondary.BackColor;
527 DialogResult dr = colorDialog.ShowDialog(this);
528
529 if (dr==DialogResult.OK)
530 {
531 SetButtonColour(bttnSecondary, colorDialog.Color);
532 }
533 }
534
535 private void bttnTrim_Click(object sender, System.EventArgs e)
536 {
537 colorDialog.Color = bttnTrim.BackColor;
538 DialogResult dr = colorDialog.ShowDialog(this);
539
540 if (dr==DialogResult.OK)
541 {
542 SetButtonColour(bttnTrim, colorDialog.Color);
543 }
544 }
545
546 private void bttnWeapon_Click(object sender, System.EventArgs e)
547 {
548 colorDialog.Color = bttnWeapon.BackColor;
549 DialogResult dr = colorDialog.ShowDialog(this);
550
551 if (dr==DialogResult.OK)
552 {
553 SetButtonColour(bttnWeapon, colorDialog.Color);
554 }
555 }
556
557 private void bttnTrim2_Click(object sender, System.EventArgs e)
558 {
559 colorDialog.Color = bttnTrim2.BackColor;
560 DialogResult dr = colorDialog.ShowDialog(this);
561
562 if (dr==DialogResult.OK)
563 {
564 SetButtonColour(bttnTrim2, colorDialog.Color);
565 }
566 }
567
568 private void SetButtonColour(Button bttn, Color colour)
569 {
570 if (bttn.BackColor!=colour)
571 {
572 bttn.BackColor = colour;
573
574 if (colour.R<128 && colour.G<128 && colour.B<128)
575 {
576 bttn.ForeColor = Color.White;
577 }
578 else
579 {
580 bttn.ForeColor = Color.Black;
581 }
582
583 if (bttn == bttnSecondary)
584 {
585 pbBadge.BackColor = colour;
586 SetPictureBoxImage(pbBadge, null);
587 pbBanner.BackColor = colour;
588 SetPictureBoxImage(pbBanner, null);
589 }
590
591 setSaveEnabled();
592 }
593 }
594
595 private void pbBadge_Click(object sender, System.EventArgs e)
596 {
597 openFileDialog.InitialDirectory = txtDoWPath.Text.TrimEnd(IBBoard.Constants.DirectoryChar)+IBBoard.Constants.DirectoryChar+"badges"+IBBoard.Constants.DirectoryChar;
598 openFileDialog.Filter = "Badge Image (*.tga)|*.tga";
599 openFileDialog.FileName = "";
600 openFileDialog.CheckFileExists = true;
601 DialogResult dr = openFileDialog.ShowDialog(this);
602
603 if (dr==DialogResult.OK)
604 {
605 SetPictureBoxImage(pbBadge, openFileDialog.FileName);
606 }
607 }
608
609 private void pbBanner_Click(object sender, System.EventArgs e)
610 {
611 openFileDialog.InitialDirectory = txtDoWPath.Text.TrimEnd(IBBoard.Constants.DirectoryChar)+IBBoard.Constants.DirectoryChar+"banners"+IBBoard.Constants.DirectoryChar;
612 openFileDialog.Filter = "Banner Image (*.tga)|*.tga";
613 openFileDialog.FileName = "";
614 openFileDialog.CheckFileExists = true;
615 DialogResult dr = openFileDialog.ShowDialog(this);
616
617 if (dr==DialogResult.OK)
618 {
619 SetPictureBoxImage(pbBanner, openFileDialog.FileName);
620 }
621 }
622
623 private bool SetPictureBoxImage(PictureBox box, string filepath)
624 {
625 if (filepath == "")
626 {
627 box.Image = null;
628 box.Tag = "";
629 return true;
630 }
631
632 if (filepath==null)
633 {
634 filepath = (string)box.Tag;
635 }
636
637 bool success = false;
638
639 if (File.Exists(filepath))
640 {
641 try
642 {
643 Bitmap bmp = IBBoard.Graphics.ImageConverter.TGAtoBMP(filepath, box.BackColor);
644
645 if (bmp.Width!=64)
646 {
647 MessageBox.Show(this, "The image you selected was not the correct width. Badges and banners must be 64px wide.", "Invalid image");
648 }
649 else if (box == pbBadge && bmp.Height!=64)
650 {
651 MessageBox.Show(this, "The image you selected was not the correct size. Badges must be 64px high.", "Invalid image");
652 }
653 else if (box == pbBanner && bmp.Height!=96)
654 {
655 MessageBox.Show(this, "The image you selected was not the correct size. Banners must be 96px high.", "Invalid image");
656 }
657 else
658 {
659 box.Image = bmp;
660 box.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
661 box.Tag = filepath;
662 success = true;
663 }
664 }
665 catch(InvalidOperationException ex)
666 {
667 if (box==pbBanner)
668 {
669 MessageBox.Show(this, ex.Message, "Invalid banner");
670 }
671 else
672 {
673 MessageBox.Show(this, ex.Message, "Invalid badge");
674 }
675 }
676 }
677 else
678 {
679 box.Image = null;
680 box.Tag = "";
681
682 }
683
684 setSaveEnabled();
685
686 return success;
687 }
688
689 private void bttnImportTeamcolour_Click(object sender, System.EventArgs e)
690 {
691 openFileDialog.Filter = "Team Colour files (*.teamcolour)|*.teamcolour";
692 openFileDialog.FileName = "";
693 openFileDialog.InitialDirectory = txtTeamcolourPath.Text;
694 openFileDialog.CheckFileExists = true;
695 DialogResult dr = openFileDialog.ShowDialog(this);
696
697 if (dr==DialogResult.OK)
698 {
699 string error = "";
700 string temp = "";
701
702 FileInfo file = new FileInfo(openFileDialog.FileName);
703 TextReader tr = file.OpenText();
704 string content = tr.ReadToEnd();
705 tr.Close();
706 Match match = Regex.Match(content, "\"BADGES:([\\w\\.]+)\"");
707
708 if (match.Success)
709 {
710 temp = txtDoWPath.Text.TrimEnd(IBBoard.Constants.DirectoryChar)+IBBoard.Constants.DirectoryChar+"badges"+IBBoard.Constants.DirectoryChar+match.Groups[1].Value;
711 SetPictureBoxImage(pbBadge, temp);
712 }
713 else
714 {
715 SetPictureBoxImage(pbBadge, "");
716 }
717
718 match = Regex.Match(content, "\"BANNERS:([\\w\\.]+)\"");
719 if (match.Success)
720 {
721 temp = txtDoWPath.Text.ToString().TrimEnd(IBBoard.Constants.DirectoryChar)+IBBoard.Constants.DirectoryChar+"banners"+IBBoard.Constants.DirectoryChar+match.Groups[1].Value;
722
723 SetPictureBoxImage(pbBanner, temp);
724 }
725 else
726 {
727 SetPictureBoxImage(pbBanner, "");
728 }
729
730 match = Regex.Match(content, "Primary =\\s+{\\s+b = ([12]?[0-9]?[0-9]),\\s+g = ([12]?[0-9]?[0-9]),\\s+r = ([12]?[0-9]?[0-9]),");
731 if (match.Success)
732 {
733 SetButtonColour(bttnPrimary, Color.FromArgb(byte.Parse(match.Groups[3].Value), byte.Parse(match.Groups[2].Value), byte.Parse(match.Groups[1].Value)));
734 }
735 else
736 {
737 error+= "\r\n* Primary";
738 }
739
740 match = Regex.Match(content, "Secondary =\\s+{\\s+b = ([12]?[0-9]?[0-9]),\\s+g = ([12]?[0-9]?[0-9]),\\s+r = ([12]?[0-9]?[0-9]),");
741 if (match.Success)
742 {
743 SetButtonColour(bttnSecondary, Color.FromArgb(byte.Parse(match.Groups[3].Value), byte.Parse(match.Groups[2].Value), byte.Parse(match.Groups[1].Value)));
744 }
745 else
746 {
747 error+= "\r\n* Secondary";
748 }
749
750 match = Regex.Match(content, "Trim =\\s+{\\s+b = ([12]?[0-9]?[0-9]),\\s+g = ([12]?[0-9]?[0-9]),\\s+r = ([12]?[0-9]?[0-9]),");
751 if (match.Success)
752 {
753 SetButtonColour(bttnTrim, Color.FromArgb(byte.Parse(match.Groups[3].Value), byte.Parse(match.Groups[2].Value), byte.Parse(match.Groups[1].Value)));
754 }
755 else
756 {
757 error+= "\r\n* Trim";
758 }
759
760 match = Regex.Match(content, "Weapons =\\s+{\\s+b = ([12]?[0-9]?[0-9]),\\s+g = ([12]?[0-9]?[0-9]),\\s+r = ([12]?[0-9]?[0-9]),");
761 if (match.Success)
762 {
763 SetButtonColour(bttnWeapon, Color.FromArgb(byte.Parse(match.Groups[3].Value), byte.Parse(match.Groups[2].Value), byte.Parse(match.Groups[1].Value)));
764 }
765 else
766 {
767 error+= "\r\n* Weapon";
768 }
769
770 match = Regex.Match(content, "Eyes =\\s+{\\s+b = ([12]?[0-9]?[0-9]),\\s+g = ([12]?[0-9]?[0-9]),\\s+r = ([12]?[0-9]?[0-9]),");
771 if (match.Success)
772 {
773 SetButtonColour(bttnTrim2, Color.FromArgb(byte.Parse(match.Groups[3].Value), byte.Parse(match.Groups[2].Value), byte.Parse(match.Groups[1].Value)));
774 }
775 else
776 {
777 error+= "\r\n* Trim 2/Eye";
778 }
779
780 if (error!="")
781 {
782 MessageBox.Show(this, "Invalid .teamcolour file - Error loading:"+error, "Import error");
783 }
784 }
785 }
786
787 private void bttnSave_Click(object sender, System.EventArgs e)
788 {
789 setPrefs();
790 pref.Save();
791 bttnSave.Enabled = false;
792 }
793
794 private void textbox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
795 {
796 if (sender is TextBox)
797 {
798 if(e.KeyData == (Keys.Control|Keys.A) && e.Control)
799 {
800 ((TextBox)sender).SelectAll();
801 }
802 }
803 }
804
805 private void setSaveEnabled()
806 {
807 if (bttnOK.Enabled && (!folderMatches(txtDoWPath.Text, "DoWPath")
808 || !folderMatches(txtTexturePath.Text, "TexturePath")
809 || !folderMatches(txtTeamcolourPath.Text, "TeamcolourPath")
810 || modeChanged() || !coloursMatch(bttnPrimary, "Primary")
811 || !coloursMatch(bttnSecondary, "Secondary") || !coloursMatch(bttnTrim, "Trim")
812 || !coloursMatch(bttnTrim2, "Eyes") || !coloursMatch(bttnWeapon, "Weapon")
813 || pbBadge.Tag.ToString()!=pref["BadgeName"].ToString()
814 || pbBanner.Tag.ToString()!=pref["BannerName"].ToString()))
815 {
816 bttnSave.Enabled = true;
817 }
818 else
819 {
820 bttnSave.Enabled = pref.IsModified();
821 }
822 }
823
824 private void txtDoWPath_Leave(object sender, System.EventArgs e)
825 {
826 textbox_Leave(sender, e);
827
828 if (!foldersExist())
829 {
830 MessageBox.Show(this, "Could not find 'badges' and 'banners' folder in "+txtDoWPath.Text+"\r\nPlease check that it points to your Dawn of War/Dark Crusade installation folder", "Invalid path", MessageBoxButtons.OK, MessageBoxIcon.Error);
831 }
832 }
833 private void textbox_Leave(object sender, System.EventArgs e)
834 {
835 if (sender is TextBox)
836 {
837 TextBox tb = (TextBox)sender;
838 if (!tb.Text.EndsWith(Path.DirectorySeparatorChar.ToString()))
839 {
840 tb.Text = tb.Text + Path.DirectorySeparatorChar;
841 }
842 }
843 }
844
845 private bool foldersExist()
846 {
847 if (!txtDoWPath.Text.EndsWith(Path.DirectorySeparatorChar.ToString()))
848 {
849 return (Directory.Exists(txtDoWPath.Text+Path.DirectorySeparatorChar+"Badges") &&
850 Directory.Exists(txtDoWPath.Text+Path.DirectorySeparatorChar+"Banners"));
851 }
852 else
853 {
854 return (Directory.Exists(txtDoWPath.Text+"Badges") &&
855 Directory.Exists(txtDoWPath.Text+"Banners"));
856 }
857 }
858
859 private bool folderMatches(string path, string prefID)
860 {
861 if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
862 {
863 return (path.ToLower()+Path.DirectorySeparatorChar == pref[prefID].ToString().ToLower());
864 }
865 else
866 {
867 return (path.ToLower() == pref[prefID].ToString().ToLower());
868 }
869 }
870
871 private bool coloursMatch(Button bttn, string colourName)
872 {
873 return (bttn.BackColor.R == (byte)pref[colourName+"Red"] && bttn.BackColor.G == (byte)pref[colourName+"Green"] && bttn.BackColor.B == (byte)pref[colourName+"Blue"]);
874 }
875
876 private void setPrefs()
877 {
878 pref["DoWPath"] = txtDoWPath.Text;
879 pref["TeamcolourPath"] = txtTeamcolourPath.Text;
880 pref["TexturePath"] = txtTexturePath.Text;
881
882 pref["settingBasic"] = rbBasicMode.Checked;
883
884 pref["PrimaryRed"] = bttnPrimary.BackColor.R;
885 pref["PrimaryGreen"] = bttnPrimary.BackColor.G;
886 pref["PrimaryBlue"] = bttnPrimary.BackColor.B;
887 pref["SecondaryRed"] = bttnSecondary.BackColor.R;
888 pref["SecondaryGreen"] = bttnSecondary.BackColor.G;
889 pref["SecondaryBlue"] = bttnSecondary.BackColor.B;
890 pref["TrimRed"] = bttnTrim.BackColor.R;
891 pref["TrimGreen"] = bttnTrim.BackColor.G;
892 pref["TrimBlue"] = bttnTrim.BackColor.B;
893 pref["WeaponRed"] = bttnWeapon.BackColor.R;
894 pref["WeaponGreen"] = bttnWeapon.BackColor.G;
895 pref["WeaponBlue"] = bttnWeapon.BackColor.B;
896 pref["EyesRed"] = bttnTrim2.BackColor.R;
897 pref["EyesGreen"] = bttnTrim2.BackColor.G;
898 pref["EyesBlue"] = bttnTrim2.BackColor.B;
899
900 pref["BadgeName"] = pbBadge.Tag.ToString();
901 pref["BannerName"] = pbBanner.Tag.ToString();
902 }
903
904 private void textbox_TextChanged(object sender, System.EventArgs e)
905 {
906 setOkayEnabled();
907 setSaveEnabled();
908 }
909
910 private void bttnTexturePath_Click(object sender, System.EventArgs e)
911 {
912 setPath(txtTexturePath);
913 }
914
915 private void bttnTeamcolourPath_Click(object sender, System.EventArgs e)
916 {
917 setPath(txtTeamcolourPath);
918 }
919
920 private void setPath(TextBox textbox)
921 {
922 folderBrowserDialog.SelectedPath = textbox.Text;
923 DialogResult dr = folderBrowserDialog.ShowDialog(this);
924
925 if (dr==DialogResult.OK)
926 {
927 textbox.Text = folderBrowserDialog.SelectedPath + Path.DirectorySeparatorChar;
928 }
929 }
930
931 private void setOkayEnabled()
932 {
933 bool enabled = true;
934
935 if (foldersExist())
936 {
937 txtDoWPath.ForeColor = SystemColors.WindowText;
938 }
939 else
940 {
941 enabled = false;
942 txtDoWPath.ForeColor = Color.Red;
943 }
944
945 if (Directory.Exists(txtTexturePath.Text))
946 {
947 txtTexturePath.ForeColor = SystemColors.WindowText;
948 }
949 else
950 {
951 enabled = false;
952 txtTexturePath.ForeColor = Color.Red;
953 }
954
955 if (Directory.Exists(txtTeamcolourPath.Text))
956 {
957 txtTeamcolourPath.ForeColor = SystemColors.WindowText;
958 }
959 else
960 {
961 enabled = false;
962 txtTeamcolourPath.ForeColor = Color.Red;
963 }
964
965 bttnOK.Enabled = enabled;
966 }
967
968 private bool modeChanged()
969 {
970 bool basicMode = (bool)pref["settingBasic"];
971 return ((rbAdvancedMode.Checked && basicMode) || (rbBasicMode.Checked && !basicMode));
972 }
973
974 private void rbMode_CheckedChanged(object sender, System.EventArgs e)
975 {
976 setSaveEnabled();
977 }
978 }
979 }