Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmEditArmy.cs @ 242:ea5cb50ebe5e
Fixes #384: Validation warnings don't get cleared when creating new armies
* Check whether army is valid when it changes (also means we validate on load as well as clearing on close)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 21 Jan 2012 16:51:07 +0000 |
parents | 4ada3252d1ea |
children |
rev | line source |
---|---|
225
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 using System; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 using System.Collections.Generic; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 using System.ComponentModel; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System.Data; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System.Drawing; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Text; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.Windows.Forms; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using IBBoard.Commands; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using IBBoard.WarFoundry.API.Commands; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using IBBoard.WarFoundry.API.Objects; |
226
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
225
diff
changeset
|
11 using IBBoard.Windows.Forms; |
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
225
diff
changeset
|
12 using IBBoard.Windows.Forms.I18N; |
225
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 namespace IBBoard.WarFoundry.GUI.WinForms |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 { |
226
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
225
diff
changeset
|
16 public partial class FrmEditArmy : IBBForm |
225
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 private Army army; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 private CommandStack stack; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 public FrmEditArmy(CommandStack cmdStack, Army toEdit) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 army = toEdit; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 stack = cmdStack; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 InitializeComponent(); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 txtArmyName.Text = army.Name; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 armySize.Value = army.MaxPoints; |
226
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
225
diff
changeset
|
28 ControlTranslator.TranslateControl(this); |
225
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 private void bttnOkay_Click(object sender, EventArgs e) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 EditArmyCommand command = new EditArmyCommand(army); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 command.NewName = txtArmyName.Text; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 command.NewSize = (int)armySize.Value; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 stack.Execute(command); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 DialogResult = DialogResult.OK; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 Close(); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 private void bttnCancel_Click(object sender, EventArgs e) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 Close(); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 private void armySize_ValueChanged(object sender, EventArgs e) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 SetOkayEnabled(); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 private void SetOkayEnabled() |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 string trimmedName = txtArmyName.Text.Trim(); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 bttnOkay.Enabled = ((army.MaxPoints != armySize.Value || army.Name != trimmedName) && trimmedName != ""); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 private void txtArmyName_TextChanged(object sender, EventArgs e) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 SetOkayEnabled(); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 private void armySize_KeyUp(object sender, KeyEventArgs e) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 SetOkayEnabled(); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 } |