Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
changeset 1:42cf06b8f897
Re #8 - Get a working Windows WarFoundry
* Update forms to use new package structures for API objects
* Update forms to use separate control translation
* Remove PIDB file from source control
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Dec 2008 18:39:37 +0000 |
parents | 7dd160dacb60 |
children | 74df258710fe |
files | FrmArmyTree.cs FrmEditUnitEquipment.cs FrmMain.cs FrmNewArmy.cs FrmNewUnit.cs FrmNewUnitEquipment.cs FrmReplaceUnitEquipment.cs FrmSelectSystem.cs FrmUnit.cs IBBoard.WarFoundry.csproj IBBoard.WarFoundry.mdp IBBoard.WarFoundry.pidb |
diffstat | 12 files changed, 98 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmArmyTree.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmArmyTree.cs Sat Dec 27 18:39:37 2008 +0000 @@ -7,6 +7,7 @@ using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Commands; using IBBoard.Windows.Forms; +using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry {
--- a/FrmEditUnitEquipment.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmEditUnitEquipment.cs Sat Dec 27 18:39:37 2008 +0000 @@ -6,6 +6,7 @@ using IBBoard.Commands; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry {
--- a/FrmMain.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmMain.cs Sat Dec 27 18:39:37 2008 +0000 @@ -16,7 +16,10 @@ using IBBoard.WarFoundry.API.Commands; using IBBoard.Windows.Forms; using IBBoard.Xml; -using log4net; +using log4net; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms.I18N; +using IBBoard.WarFoundry.API.Savers; namespace IBBoard.WarFoundry { @@ -28,11 +31,10 @@ private static readonly string AppTitle = "WarFoundry"; private Preferences preferences; - protected readonly ILog logger = LogManager.GetLogger(typeof(WarFoundryFactory)); + protected readonly ILog logger = LogManager.GetLogger(typeof(FrmMain)); private CommandStack commandStack; - private ToolBarButton[] categoryButtons; - private Type factoryType = typeof(WarFoundryXmlFactory); + private ToolBarButton[] categoryButtons; public ObjectAddDelegate UnitAddedMethod; public ObjectRemoveDelegate UnitRemovedMethod; @@ -40,7 +42,8 @@ //public FailedUnitRequirementDelegate FailedUnitRequirementMethod; private FrmArmyTree armyTree; - private FrmDebugOutput debugWindow; + private FrmDebugOutput debugWindow; + private string loadedFilePath; private IBBoard.Windows.Forms.ColorableStatusBar statusBar; private System.Windows.Forms.ToolBar toolBar; @@ -96,22 +99,22 @@ //pnlRight.Height = ClientRectangle.Bottom - statusBar.Height - pnlRight.Top - 3; foreach (Control ctrl in Controls) - { - Translation.TranslateControl(ctrl); + { + ControlTranslator.TranslateControl(ctrl); } foreach(Component comp in components.Components) - { - Translation.TranslateComponent(comp); + { + ControlTranslator.TranslateComponent(comp); } foreach (IBBMenuItem mi in Menu.MenuItems) - { - Translation.TranslateComponent(mi); - } - - Translation.TranslateComponent(openArmyDialog); - Translation.TranslateComponent(saveArmyDialog); + { + ControlTranslator.TranslateComponent(mi); + } + + ControlTranslator.TranslateComponent(openArmyDialog); + ControlTranslator.TranslateComponent(saveArmyDialog); WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(FrmMain_GameSystemChanged); WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged); @@ -126,9 +129,10 @@ armyTree.MdiParent = this; armyTree.Show(); armyTree.StartPosition = FormStartPosition.Manual; - armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10); - Translation.TranslateControl(armyTree); + armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10); + ControlTranslator.TranslateControl(armyTree); + /* if (args.Length == 1) { logger.Debug("Attempting to load from file"); @@ -168,7 +172,7 @@ logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); } } - } + }*/ } public static string DataPath @@ -566,11 +570,6 @@ MessageBox.Show(null, "A major, unexpected and fatal error ocurred while starting the application: \r\n\r\n"+ex.Message+"\r\n\r\n"+ex.StackTrace, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - - public WarFoundryFactory Factory - { - get { return WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(Constants.ExecutablePath, factoryType); } - } private void miExit_Click(object sender, System.EventArgs e) { @@ -586,12 +585,12 @@ { if (closeCurrentArmy()) { - FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem, Factory); + FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem); DialogResult dr = newArmy.ShowDialog(); if (dr == DialogResult.OK) { - CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize, Factory); + CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); } } } @@ -619,6 +618,7 @@ if (dr == DialogResult.OK) { + /* try { CurrentArmy = Factory.LoadArmy(openArmyDialog.FileName); @@ -630,6 +630,8 @@ MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidFileBoxTitle", "Invalid data file"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } + * */ + return false; } else { @@ -653,8 +655,8 @@ DialogResult dr = MessageBox.Show(this, "The army \""+CurrentArmy.Name+"\" has been modified.\r\nSave changes before closing army?", "Unsaved changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3); if (dr == DialogResult.Yes) - { - canClose = saveCurrentArmyOrSaveAs(); + { + canClose = SaveCurrentArmy(); } else if (dr == DialogResult.No) { @@ -703,42 +705,48 @@ } } - private bool saveCurrentArmyOrSaveAs() - { - if (WarFoundrySaver.GetSaver().CanSave(CurrentArmy)) - { - return saveCurrentArmy(); - } - else - { - return saveCurrentArmyAs(); - } - } - - private bool saveCurrentArmy() + private bool SaveCurrentArmy() { - if (WarFoundrySaver.GetSaver().CanSave(CurrentArmy)) - { - if (WarFoundrySaver.GetSaver().Save(CurrentArmy)) - { - miSaveArmy.Enabled = false; - bttnSaveArmy.Enabled = false; - CommandStack.setCleanMark(); - return true; - } - else - { - MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } + bool saved = false; + + if (loadedFilePath != null || PromptForFilePath()) + { + saved = SaveCurrentArmyToFile(); + } + + return saved; + } + + private bool SaveCurrentArmyAs() + { + bool saved = false; + + if (PromptForFilePath()) + { + saved = SaveCurrentArmyToFile(); + } + + return saved; + } + + private bool SaveCurrentArmyToFile() + { + if (WarFoundrySaver.GetSaver().Save(CurrentArmy, loadedFilePath)) + { + miSaveArmy.Enabled = false; + bttnSaveArmy.Enabled = false; + CommandStack.setCleanMark(); + return true; } else - { + { + loadedFilePath = null; + MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } - } - - private bool saveCurrentArmyAs() + } + + private bool PromptForFilePath() { if (saveArmyDialog.Filter == "") { @@ -758,18 +766,8 @@ if (dr == DialogResult.OK) { - if (WarFoundrySaver.GetSaver().SaveAs(CurrentArmy, saveArmyDialog.FileName)) - { - miSaveArmy.Enabled = false; - bttnSaveArmy.Enabled = false; - CommandStack.setCleanMark(); - return true; - } - else - { - MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } + loadedFilePath = saveArmyDialog.FileName; + return true; } else { @@ -796,8 +794,8 @@ openArmy(); } else if (e.Button == bttnSaveArmy) - { - saveCurrentArmyOrSaveAs(); + { + SaveCurrentArmy(); } else { @@ -820,7 +818,7 @@ private void SelectGameSystem() { - FrmSelectSystem selectSystem = new FrmSelectSystem(Factory); + FrmSelectSystem selectSystem = new FrmSelectSystem(); DialogResult dr = selectSystem.ShowDialog(this); if (dr==DialogResult.OK) @@ -954,8 +952,8 @@ } private void miSaveArmyAs_Click(object sender, System.EventArgs e) - { - saveCurrentArmyAs(); + { + SaveCurrentArmyAs(); } private void commandStack_CommandStackUpdated() @@ -1030,16 +1028,14 @@ undoMenu.MenuItems.AddRange(menuItemsUndo); } - bool canSave = WarFoundrySaver.GetSaver().CanSave(CurrentArmy); + bool canSave = loadedFilePath != null; bttnSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null && canSave; miSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null && canSave; } private void miSaveArmy_Click(object sender, System.EventArgs e) { - //we should only be saving when the army can be saved (i.e. it has been opened from a file or Save As-ed) - //so use the "just save" version - saveCurrentArmy(); + SaveCurrentArmy(); } private void setAppTitle() @@ -1066,7 +1062,7 @@ if (dr == DialogResult.OK) { - CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, cat, CurrentArmy, Factory); + CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, cat, CurrentArmy); commandStack.Execute(cmd); } } @@ -1243,7 +1239,7 @@ private void miReloadFiles_Click(object sender, System.EventArgs e) { - Factory.LoadAllGameSystems(); + WarFoundryLoader.GetDefault().LoadFiles(); sbMainPanel.Text = Translation.GetTranslation("GameSystemFilesReloaded", "Game system and race files reloaded"); statusBarTimer.Enabled = true; }
--- a/FrmNewArmy.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmNewArmy.cs Sat Dec 27 18:39:37 2008 +0000 @@ -7,6 +7,8 @@ using IBBoard.Lang; using IBBoard.Windows.Forms; using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms.I18N; namespace IBBoard.WarFoundry { @@ -29,13 +31,13 @@ private System.Windows.Forms.NumericUpDown armySize; private System.Windows.Forms.TextBox txtArmyName; - public FrmNewArmy(GameSystem system, WarFoundryFactory factory) + public FrmNewArmy(GameSystem system) { InitializeComponent(); - Translation.TranslateControl(this); + ControlTranslator.TranslateControl(this); - races = factory.GetRaces(system); + races = WarFoundryLoader.GetDefault().GetRaces(system); for (int i = 0; i<races.Length; i++) {
--- a/FrmNewUnit.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmNewUnit.cs Sat Dec 27 18:39:37 2008 +0000 @@ -7,6 +7,8 @@ using IBBoard.Lang; using IBBoard.Windows.Forms; using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms.I18N; namespace IBBoard.WarFoundry { @@ -31,7 +33,7 @@ { InitializeComponent(); - Translation.TranslateControl(this, cat.Name); + ControlTranslator.TranslateControl(this, cat.Name); units = race.GetUnitTypes(cat); allowed = new bool[units.Length]; this.army = army;
--- a/FrmNewUnitEquipment.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmNewUnitEquipment.cs Sat Dec 27 18:39:37 2008 +0000 @@ -7,6 +7,7 @@ using IBBoard.Commands; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry {
--- a/FrmReplaceUnitEquipment.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmReplaceUnitEquipment.cs Sat Dec 27 18:39:37 2008 +0000 @@ -7,6 +7,7 @@ using IBBoard.Commands; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry {
--- a/FrmSelectSystem.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmSelectSystem.cs Sat Dec 27 18:39:37 2008 +0000 @@ -8,6 +8,8 @@ using IBBoard.Lang; using IBBoard.WarFoundry.API; using IBBoard.Windows.Forms; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.Windows.Forms.I18N; namespace IBBoard.WarFoundry { @@ -27,21 +29,18 @@ private GameSystem selectedSystem; - public FrmSelectSystem() : this(null) - { - } - - public FrmSelectSystem(WarFoundryFactory currFactory) + public FrmSelectSystem() { // // Required for Windows Form Designer support // InitializeComponent(); - Translation.TranslateControl(this); + ControlTranslator.TranslateControl(this); lstSystems.Items.Clear(); - GameSystem[] systems = currFactory.GetGameSystems(); + + GameSystem[] systems = WarFoundryLoader.GetDefault().GetGameSystems(); lstSystems.DataSource = systems;
--- a/FrmUnit.cs Fri Dec 19 15:57:51 2008 +0000 +++ b/FrmUnit.cs Sat Dec 27 18:39:37 2008 +0000 @@ -8,6 +8,7 @@ using IBBoard.Windows.Forms; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry {
--- a/IBBoard.WarFoundry.csproj Fri Dec 19 15:57:51 2008 +0000 +++ b/IBBoard.WarFoundry.csproj Sat Dec 27 18:39:37 2008 +0000 @@ -91,7 +91,7 @@ <Reference Include="System.Xml"> <Name>System.XML</Name> </Reference> - <ProjectReference Include="..\..\IBBoardWF\IBBoardWF.csproj"> + <ProjectReference Include="..\IBBoard.Windows.Forms\IBBoardWF.csproj"> <Name>IBBoardWF</Name> <Project>{E3790268-2082-4975-B1A3-C70B37842CE8}</Project> <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
--- a/IBBoard.WarFoundry.mdp Fri Dec 19 15:57:51 2008 +0000 +++ b/IBBoard.WarFoundry.mdp Sat Dec 27 18:39:37 2008 +0000 @@ -1,4 +1,4 @@ -<Project name="IBBoard.WarFoundry" fileversion="2.0" DefaultNamespace="IBBoard.WarFoundry" language="C#" clr-version="Net_1_1" ctype="DotNetProject"> +<Project name="IBBoard.WarFoundry" fileversion="2.0" language="C#" DefaultNamespace="IBBoard.WarFoundry" clr-version="Net_1_1" ctype="DotNetProject"> <Configurations active="Debug"> <Configuration name="Debug" ctype="DotNetProjectConfiguration"> <Output directory="bin/Debug/" assembly="WarFoundry" />