Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
changeset 222:4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
* Fix up translations
* Correct enabling of menu item
* Add translation text
* Update army names in tree and app title when edited
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 29 Aug 2011 20:53:53 +0100 |
parents | 5233147ca7e4 |
children | 4e5f913a472a |
files | FrmArmyTree.cs FrmEditArmy.cs FrmMain.cs translations/en.translation |
diffstat | 4 files changed, 37 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmArmyTree.cs Mon Aug 29 20:06:54 2011 +0100 +++ b/FrmArmyTree.cs Mon Aug 29 20:53:53 2011 +0100 @@ -54,7 +54,10 @@ ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName); TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged); nodes = new Dictionary<string, TreeNode>(); - this.Name = "ArmyTree"; + this.Name = "ArmyTree"; + miDeleteUnit.Name = "miDeleteUnit"; + miEditUnit.Name = "miEditUnit"; + miEditArmy.Name = "miEditArmy"; WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged); TranslateForm(); Translation.TranslationChanged += new MethodInvoker(TranslateForm); @@ -73,6 +76,7 @@ { ControlTranslator.TranslateComponent(mi); } + foreach (TreeNode node in nodes.Values) { node.Text = CreateNodeName((ICostedWarFoundryObject)node.Tag); @@ -291,6 +295,7 @@ { if (oldArmy != null) { + oldArmy.NameChanged -= ArmyNameChangedMethod; oldArmy.UnitAdded -= UnitAddedMethod; oldArmy.UnitRemoved -= UnitRemovedMethod; oldArmy.PointsValueChanged -= NodePointsValueChanged; @@ -298,6 +303,7 @@ if (newArmy != null) { + newArmy.NameChanged += ArmyNameChangedMethod; newArmy.UnitAdded += UnitAddedMethod; newArmy.UnitRemoved += UnitRemovedMethod; newArmy.PointsValueChanged += NodePointsValueChanged; @@ -444,13 +450,7 @@ { if (obj is Army) { - Army army = (Army)obj; - TreeNode node = treeView.Nodes[0]; - - if (node!=null) - { - node.Text = army.Name; - } + SetNodeName((Army)obj); } }
--- a/FrmEditArmy.cs Mon Aug 29 20:06:54 2011 +0100 +++ b/FrmEditArmy.cs Mon Aug 29 20:53:53 2011 +0100 @@ -8,10 +8,12 @@ using IBBoard.Commands; using IBBoard.WarFoundry.API.Commands; using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms; +using IBBoard.Windows.Forms.I18N; namespace IBBoard.WarFoundry.GUI.WinForms { - public partial class FrmEditArmy : Form + public partial class FrmEditArmy : IBBForm { private Army army; private CommandStack stack; @@ -23,6 +25,7 @@ InitializeComponent(); txtArmyName.Text = army.Name; armySize.Value = army.MaxPoints; + ControlTranslator.TranslateControl(this); } private void bttnOkay_Click(object sender, EventArgs e)
--- a/FrmMain.cs Mon Aug 29 20:06:54 2011 +0100 +++ b/FrmMain.cs Mon Aug 29 20:53:53 2011 +0100 @@ -49,7 +49,9 @@ public ObjectAddDelegate UnitAddedMethod; public ObjectRemoveDelegate UnitRemovedMethod; + public StringValChangedDelegate ArmyNameChangedMethod; public DoubleValChangedDelegate PointsValueChangedMethod; + public IntValChangedDelegate MaxPointsValueChangedMethod; private FrmArmyTree armyTree; private string loadedFilePath; @@ -148,7 +150,9 @@ WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged); UnitAddedMethod = new ObjectAddDelegate(FrmMain_UnitAddedMethod); UnitRemovedMethod = new ObjectRemoveDelegate(FrmMain_UnitRemovedMethod); + ArmyNameChangedMethod = new StringValChangedDelegate(FrmMain_ArmyNameChangedMethod); PointsValueChangedMethod = new DoubleValChangedDelegate(FrmMain_PointsValueChangedMethod); + MaxPointsValueChangedMethod = new IntValChangedDelegate(FrmMain_MaxPointsValueChangedMethod); sbErrorPanel.Color = Color.Red; SetPointsPanelToolTipText(); @@ -578,6 +582,7 @@ // // miEditArmy // + this.miEditArmy.Enabled = false; this.miEditArmy.Name = "miEditArmy"; this.miEditArmy.Size = new System.Drawing.Size(152, 22); this.miEditArmy.Text = "&edit army"; @@ -913,7 +918,7 @@ loadedFilePath = null; miSaveArmy.Enabled = false; bttnSaveArmy.Enabled = false; - miEditArmy.Enabled = (CurrentArmy == null); + miEditArmy.Enabled = (CurrentArmy != null); //TODO: Subscribe to an "army changed" event here SetPointsPanelText(); SetAppTitle(); @@ -944,7 +949,9 @@ { oldArmy.UnitAdded -= UnitAddedMethod; oldArmy.UnitRemoved -= UnitRemovedMethod; + oldArmy.NameChanged -= ArmyNameChangedMethod; oldArmy.PointsValueChanged -= PointsValueChangedMethod; + oldArmy.MaxPointsValueChanged -= MaxPointsValueChangedMethod; } } @@ -966,7 +973,9 @@ { newArmy.UnitAdded += UnitAddedMethod; newArmy.UnitRemoved += UnitRemovedMethod; + newArmy.NameChanged += ArmyNameChangedMethod; newArmy.PointsValueChanged += PointsValueChangedMethod; + newArmy.MaxPointsValueChanged += MaxPointsValueChangedMethod; } } @@ -1297,6 +1306,11 @@ OpenArmy(); } + private void FrmMain_ArmyNameChangedMethod(WarFoundryObject obj, string oldString, string newString) + { + SetAppTitle(); + } + private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal) { if (obj is Army) @@ -1305,6 +1319,14 @@ } } + private void FrmMain_MaxPointsValueChangedMethod(WarFoundryObject obj, int oldVal, int newVal) + { + if (obj is Army) + { + SetPointsPanelText(); + } + } + private void SetPointsPanelText() { if (CurrentArmy==null)
--- a/translations/en.translation Mon Aug 29 20:06:54 2011 +0100 +++ b/translations/en.translation Mon Aug 29 20:53:53 2011 +0100 @@ -15,6 +15,7 @@ <translation id="miExit">E&xit</translation> <translation id="miUndo">&Undo</translation> <translation id="miRedo">&Redo</translation> + <translation id="miEditArmy">&Edit army</translation> <translation id="miPreferences">&Preferences</translation> <translation id="miAbout">&About</translation> <translation id="bttnOkay">OK</translation> @@ -45,6 +46,7 @@ <translation id="bttnSelectRace">Create army</translation> <translation id="newArmyNoGameSystems">WarFoundry couldn't find any game system data. Please check the logs for errors and ensure you have some game system data files in the "data" folder.</translation> + <translation id="FrmEditArmy">Edit Army</translation> <translation id="FrmNewUnit">Add New {0} Choice</translation> <translation id="lblUnitList">Unit types:</translation> <translation id="bttnSelectUnit">Create unit</translation>