# HG changeset patch # User IBBoard # Date 1271274165 0 # Node ID e0af96397e260484bb1f813c7a342f5038989f88 # Parent 4aabe514c868e85b2c8c010166b84ed39304575e Re #203: Translate WarFoundry * Actually add German translation * Make controls on Pref form use custom translatable IBB versions so that they translate * Make new menu item a custom translatable IBB version so that it translates diff -r 4aabe514c868 -r e0af96397e26 FrmMain.cs --- a/FrmMain.cs Tue Apr 13 20:02:49 2010 +0000 +++ b/FrmMain.cs Wed Apr 14 19:42:45 2010 +0000 @@ -1,165 +1,165 @@ -// This file (FrmMain.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard. -// -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero 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. - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.ComponentModel; -using System.Windows.Forms; -using System.Data; -using System.IO; -using System.Threading; -using log4net; -using IBBoard; -using IBBoard.CustomMath; -using IBBoard.Commands; -using IBBoard.IO; -using IBBoard.Lang; -using IBBoard.Windows.Forms; -using IBBoard.Windows.Forms.I18N; -using IBBoard.Xml; -using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Commands; -using IBBoard.WarFoundry.API.Exporters; -using IBBoard.WarFoundry.API.Objects; -using IBBoard.WarFoundry.API.Savers; -using IBBoard.WarFoundry.API.Factories; -using IBBoard.WarFoundry.API.Factories.Xml; - -namespace IBBoard.WarFoundry.GUI.WinForms -{ - /// - /// Summary description for Form1. - /// - public class FrmMain : System.Windows.Forms.Form - { - private static readonly string AppTitle = "WarFoundry"; - internal static readonly string VERSION = "0.1b8pre"; - const string DefaultDataDir = "data"; - - private Preferences preferences; - private readonly ILog log = LogManager.GetLogger(typeof(FrmMain)); - - private CommandStack commandStack; - - public ObjectAddDelegate UnitAddedMethod; - public ObjectRemoveDelegate UnitRemovedMethod; - public DoubleValChangedDelegate PointsValueChangedMethod; - //public FailedUnitRequirementDelegate FailedUnitRequirementMethod; - - private FrmArmyTree armyTree; - private string loadedFilePath; - private Dictionary unitWindows; - - private System.ComponentModel.IContainer components; - private System.Windows.Forms.OpenFileDialog openArmyDialog; - private System.Windows.Forms.SaveFileDialog saveArmyDialog; - private System.Windows.Forms.MainMenu mainMenu; - private IBBoard.Windows.Forms.ColorableStatusBarPanel sbMainPanel; - private IBBoard.Windows.Forms.ColorableStatusBarPanel sbErrorPanel; - private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel; - private System.Windows.Forms.ContextMenu undoMenu; - private System.Windows.Forms.ContextMenu redoMenu; - private IBBoard.Windows.Forms.ColorableStatusBar statusBar; - private System.Windows.Forms.Timer statusBarTimer; - private MenuStrip menuStrip; - private IBBToolStripMenuItem menuFile; - private IBBToolStripMenuItem miNewArmy; - private IBBToolStripMenuItem miOpenArmy; - private IBBToolStripMenuItem miSaveArmy; - private IBBToolStripMenuItem miSaveArmyAs; - private IBBToolStripMenuItem miExportArmyAs; - private IBBToolStripMenuItem miExportArmyAsBasicHTML; - private IBBToolStripMenuItem miCloseArmy; - private ToolStripSeparator toolStripSeparator1; - private IBBToolStripMenuItem miReloadFiles; - private ToolStripSeparator toolStripSeparator2; - private IBBToolStripMenuItem miExit; - private IBBToolStripMenuItem menuEdit; - private IBBToolStripMenuItem miUndo; - private IBBToolStripMenuItem miRedo; - private IBBToolStripMenuItem menuHelp; - private ToolStrip mainToolStrip; - private IBBToolStripButton bttnNewArmy; - private IBBToolStripButton bttnOpenArmy; - private IBBToolStripButton bttnSaveArmy; - private ToolStripSeparator toolStripSeparator3; - private IBBToolStripSplitButton bttnUndo; - private IBBToolStripSplitButton bttnRedo; - private ToolStrip catToolStrip; +// This file (FrmMain.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard. +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero 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. + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.ComponentModel; +using System.Windows.Forms; +using System.Data; +using System.IO; +using System.Threading; +using log4net; +using IBBoard; +using IBBoard.CustomMath; +using IBBoard.Commands; +using IBBoard.IO; +using IBBoard.Lang; +using IBBoard.Windows.Forms; +using IBBoard.Windows.Forms.I18N; +using IBBoard.Xml; +using IBBoard.WarFoundry.API; +using IBBoard.WarFoundry.API.Commands; +using IBBoard.WarFoundry.API.Exporters; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.API.Savers; +using IBBoard.WarFoundry.API.Factories; +using IBBoard.WarFoundry.API.Factories.Xml; + +namespace IBBoard.WarFoundry.GUI.WinForms +{ + /// + /// Summary description for Form1. + /// + public class FrmMain : System.Windows.Forms.Form + { + private static readonly string AppTitle = "WarFoundry"; + internal static readonly string VERSION = "0.1b8pre"; + const string DefaultDataDir = "data"; + + private Preferences preferences; + private readonly ILog log = LogManager.GetLogger(typeof(FrmMain)); + + private CommandStack commandStack; + + public ObjectAddDelegate UnitAddedMethod; + public ObjectRemoveDelegate UnitRemovedMethod; + public DoubleValChangedDelegate PointsValueChangedMethod; + //public FailedUnitRequirementDelegate FailedUnitRequirementMethod; + + private FrmArmyTree armyTree; + private string loadedFilePath; + private Dictionary unitWindows; + + private System.ComponentModel.IContainer components; + private System.Windows.Forms.OpenFileDialog openArmyDialog; + private System.Windows.Forms.SaveFileDialog saveArmyDialog; + private System.Windows.Forms.MainMenu mainMenu; + private IBBoard.Windows.Forms.ColorableStatusBarPanel sbMainPanel; + private IBBoard.Windows.Forms.ColorableStatusBarPanel sbErrorPanel; + private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel; + private System.Windows.Forms.ContextMenu undoMenu; + private System.Windows.Forms.ContextMenu redoMenu; + private IBBoard.Windows.Forms.ColorableStatusBar statusBar; + private System.Windows.Forms.Timer statusBarTimer; + private MenuStrip menuStrip; + private IBBToolStripMenuItem menuFile; + private IBBToolStripMenuItem miNewArmy; + private IBBToolStripMenuItem miOpenArmy; + private IBBToolStripMenuItem miSaveArmy; + private IBBToolStripMenuItem miSaveArmyAs; + private IBBToolStripMenuItem miExportArmyAs; + private IBBToolStripMenuItem miExportArmyAsBasicHTML; + private IBBToolStripMenuItem miCloseArmy; + private ToolStripSeparator toolStripSeparator1; + private IBBToolStripMenuItem miReloadFiles; + private ToolStripSeparator toolStripSeparator2; + private IBBToolStripMenuItem miExit; + private IBBToolStripMenuItem menuEdit; + private IBBToolStripMenuItem miUndo; + private IBBToolStripMenuItem miRedo; + private IBBToolStripMenuItem menuHelp; + private ToolStrip mainToolStrip; + private IBBToolStripButton bttnNewArmy; + private IBBToolStripButton bttnOpenArmy; + private IBBToolStripButton bttnSaveArmy; + private ToolStripSeparator toolStripSeparator3; + private IBBToolStripSplitButton bttnUndo; + private IBBToolStripSplitButton bttnRedo; + private ToolStrip catToolStrip; private ToolStripPanel toolStripPanel; private ToolStripSeparator toolStripSeparator4; - private ToolStripMenuItem miPreferences; - private IBBToolStripMenuItem miAbout; - - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main(string[] args) - { - try - { - LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms"); - Application.EnableVisualStyles(); - Application.Run(new FrmMain(args)); - LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms"); - } - catch (Exception ex) - { - LogManager.GetLogger(typeof(FrmMain)).Fatal(ex); - 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 FrmMain(string[] args) - { - this.Closing+=new CancelEventHandler(FrmMain_Closing); - CommandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated); - - InitializeComponent(); - toolStripPanel.Join(mainToolStrip, 0, 0); - toolStripPanel.Join(catToolStrip, mainToolStrip.Right, 0); - - Preferences = new Preferences("WarFoundry"); - try - { - Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); - } - catch (TranslationLoadException ex) - { - log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex); - MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error); + private IBBToolStripMenuItem miPreferences; + private IBBToolStripMenuItem miAbout; + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main(string[] args) + { + try + { + LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms"); + Application.EnableVisualStyles(); + Application.Run(new FrmMain(args)); + LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms"); + } + catch (Exception ex) + { + LogManager.GetLogger(typeof(FrmMain)).Fatal(ex); + 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 FrmMain(string[] args) + { + this.Closing+=new CancelEventHandler(FrmMain_Closing); + CommandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated); + + InitializeComponent(); + toolStripPanel.Join(mainToolStrip, 0, 0); + toolStripPanel.Join(catToolStrip, mainToolStrip.Right, 0); + + Preferences = new Preferences("WarFoundry"); + try + { + Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); + } + catch (TranslationLoadException ex) + { + log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex); + MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } Translation.TranslationChanged += new MethodInvoker(TranslationChanged); - TranslateControls(); - unitWindows = new Dictionary(); - - WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(FrmMain_GameSystemChanged); - WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged); - UnitAddedMethod = new ObjectAddDelegate(FrmMain_UnitAddedMethod); - UnitRemovedMethod = new ObjectRemoveDelegate(FrmMain_UnitRemovedMethod); - PointsValueChangedMethod = new DoubleValChangedDelegate(FrmMain_PointsValueChangedMethod); - //FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(FrmMain_FailedUnitRequirement); - - sbErrorPanel.Color = Color.Red; - sbPointsPanel.ToolTipText = Translation.GetTranslation("statusPanelPointsToolTip", "total points value"); - - armyTree = new FrmArmyTree(CommandStack); - armyTree.MdiParent = this; - armyTree.StartPosition = FormStartPosition.Manual; - armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10); - ControlTranslator.TranslateControl(armyTree); - - // hack to load default files - WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir)); - WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); - WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; - WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); + TranslateControls(); + unitWindows = new Dictionary(); + + WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(FrmMain_GameSystemChanged); + WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged); + UnitAddedMethod = new ObjectAddDelegate(FrmMain_UnitAddedMethod); + UnitRemovedMethod = new ObjectRemoveDelegate(FrmMain_UnitRemovedMethod); + PointsValueChangedMethod = new DoubleValChangedDelegate(FrmMain_PointsValueChangedMethod); + //FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(FrmMain_FailedUnitRequirement); + + sbErrorPanel.Color = Color.Red; + sbPointsPanel.ToolTipText = Translation.GetTranslation("statusPanelPointsToolTip", "total points value"); + + armyTree = new FrmArmyTree(CommandStack); + armyTree.MdiParent = this; + armyTree.StartPosition = FormStartPosition.Manual; + armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10); + ControlTranslator.TranslateControl(armyTree); + + // hack to load default files + WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir)); + WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); + WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; + WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); } private void TranslateControls() @@ -173,58 +173,58 @@ void TranslationChanged() { TranslateControls(); - } - - public static string DataPath - { - get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; } - } - - public static String ArmiesPath - { - get { return Environment.GetFolderPath(Environment.SpecialFolder.Personal); } - } - - public Preferences Preferences - { - get { return preferences; } - set { preferences = value; } - } - - public CommandStack CommandStack - { - get - { - if (commandStack == null) - { - commandStack = new CommandStack(); - } - - return commandStack; - } - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() + } + + public static string DataPath + { + get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; } + } + + public static String ArmiesPath + { + get { return Environment.GetFolderPath(Environment.SpecialFolder.Personal); } + } + + public Preferences Preferences + { + get { return preferences; } + set { preferences = value; } + } + + public CommandStack CommandStack + { + get + { + if (commandStack == null) + { + commandStack = new CommandStack(); + } + + return commandStack; + } + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose( bool disposing ) + { + if( disposing ) + { + if (components != null) + { + components.Dispose(); + } + } + base.Dispose( disposing ); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain)); @@ -266,7 +266,7 @@ this.sbPointsPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel(); this.toolStripPanel = new System.Windows.Forms.ToolStripPanel(); this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); - this.miPreferences = new System.Windows.Forms.ToolStripMenuItem(); + this.miPreferences = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.menuStrip.SuspendLayout(); this.mainToolStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize) (this.sbMainPanel)).BeginInit(); @@ -598,796 +598,796 @@ this.ResumeLayout(false); this.PerformLayout(); - } - #endregion - - private void FileLoadingFinished(List failures) - { - foreach (FileLoadFailure failure in failures) - { - log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); - } - } - - private void miExit_Click(object sender, System.EventArgs e) - { - Application.Exit(); - } - - private void miNewArmy_Click(object sender, System.EventArgs e) - { - CreateNewArmy(); - } - - private void CreateNewArmy() - { - if (CloseCurrentArmy()) - { - FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem); - DialogResult dr = newArmy.ShowDialog(); - - if (dr == DialogResult.OK) - { - try - { - CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); - } - catch (RequiredDataMissingException ex) - { - log.Error("Required data missing from race file", ex); - MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error); - } - catch (InvalidFileException ex) - { - log.Error("Race file was invalid", ex); - MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - - private bool OpenArmy() - { - if (openArmyDialog.Filter=="") - { - string savePath = ArmiesPath; - - if (!Directory.Exists(savePath)) - { - Directory.CreateDirectory(savePath); - } - - openArmyDialog.InitialDirectory = savePath; - openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; - openArmyDialog.Title = Translation.GetTranslation("openArmyDialog"); - - } - - DialogResult dr = openArmyDialog.ShowDialog(this); - - if (dr == DialogResult.OK) - { - if (CloseCurrentArmy()) - { - try - { - string newFilePath = openArmyDialog.FileName; - CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath)); - loadedFilePath = newFilePath; - return true; - } - catch (RequiredDataMissingException ex) - { - log.Error(ex); - MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - catch (InvalidFileException ex) - { - log.Error(ex); - MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - } - else - { - return false; - } - } - else - { - return false; - } - } - - private bool CloseCurrentArmy() - { - if (CurrentArmy!=null) - { - bool canClose = false; - - if (CommandStack.IsDirty()) - { - string saveChanges = Translation.GetTranslation("SaveChangesQuestion", "the army \"{0}\" has been modified\r\nsave changes before closing army?", CurrentArmy.Name); - string saveChangesTitle = Translation.GetTranslation("SaveChangesTitle", "unsaved changes"); - DialogResult dr = MessageBox.Show(this, saveChanges, saveChangesTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3); - - if (dr == DialogResult.Yes) - { - canClose = SaveCurrentArmy(); - } - else if (dr == DialogResult.No) - { - canClose = true; - } - //else they said cancel and we default to "canClose = false" so do nothing - } - else - { - canClose = true; - } - - if (canClose) - { - //do close - DisableCategoryButtons(); - CurrentArmy = null; - return true; - } - else - { - return false; - } - } - else - { - DisableCategoryButtons(); - //pretend we succeeded - return true; - } - } - - private void UndoLastAction() - { - if (commandStack.CanUndo()) - { - commandStack.Undo(); - } - } - - private void RedoAction() - { - if (commandStack.CanRedo()) - { - commandStack.Redo(); - } - } - - private bool SaveCurrentArmy() - { - bool saved = false; - - string filePath = loadedFilePath; - - if (filePath == null) - { - filePath = PromptForArmyFilePath(); - } - - if (filePath != null) - { - saved = SaveCurrentArmyToFile(filePath); - } - - return saved; - } - - private bool SaveCurrentArmyAs() - { - bool saved = false; - string filePath = PromptForArmyFilePath(); - - if (filePath != null) - { - saved = SaveCurrentArmyToFile(filePath); - } - - return saved; - } - - private bool SaveCurrentArmyToFile(string filePath) - { - if (WarFoundrySaver.GetSaver().Save(CurrentArmy, filePath)) - { - loadedFilePath = filePath; - miSaveArmy.Enabled = false; - bttnSaveArmy.Enabled = false; - CommandStack.setCleanMark(); - return true; - } - else - { - MessageBox.Show(this, Translation.GetTranslation("SaveFailed", "file save failed - check log for details"), Translation.GetTranslation("SaveFailedTitle", "file save failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - } - - private string PromptForArmyFilePath() - { - if (saveArmyDialog.Filter == "") - { - string savePath = ArmiesPath; - - if (!Directory.Exists(savePath)) - { - Directory.CreateDirectory(savePath); - } - - saveArmyDialog.InitialDirectory = savePath; - saveArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; - saveArmyDialog.Title = Translation.GetTranslation("saveArmyDialog"); - } - - DialogResult dr = saveArmyDialog.ShowDialog(this); - - if (dr == DialogResult.OK) - { - return saveArmyDialog.FileName; - } - else - { - return null; - } - } - - public GameSystem CurrentGameSystem - { - get { return WarFoundryCore.CurrentGameSystem; } - set { WarFoundryCore.CurrentGameSystem = value; } - } - - public Army CurrentArmy - { - get { return WarFoundryCore.CurrentArmy; } - set { SetArmy(value); } - } - - private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem) - { - SetAppTitle(); - RemoveCategoryButtons(); - } - - private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy) - { - CommandStack.Reset(); - loadedFilePath = null; - miSaveArmy.Enabled = false; - bttnSaveArmy.Enabled = false; - SetPointsPanelText(); - SetAppTitle(); - } - - private void SetArmy(Army newArmy) - { - IgnoreArmy(CurrentArmy); - CloseAllUnitWindows(); - - if (newArmy == null) - { - SetNullArmyState(); - } - else - { - WarFoundryCore.CurrentGameSystem = newArmy.GameSystem; - ListenToArmy(newArmy); - SetNonNullArmyState(newArmy); - } - - WarFoundryCore.CurrentArmy = newArmy; - } - - private void IgnoreArmy(Army oldArmy) - { - if (oldArmy != null) - { - oldArmy.UnitAdded -= UnitAddedMethod; - oldArmy.UnitRemoved -= UnitRemovedMethod; - oldArmy.PointsValueChanged -= PointsValueChangedMethod; - } - } - - private void CloseAllUnitWindows() - { - FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows); - - foreach (FrmUnit window in unitForms) - { - window.Close(); - } - - unitWindows.Clear(); - } - - private void ListenToArmy(Army newArmy) - { - if (newArmy != null) - { - newArmy.UnitAdded += UnitAddedMethod; - newArmy.UnitRemoved += UnitRemovedMethod; - newArmy.PointsValueChanged += PointsValueChangedMethod; - } - } - - private void SetNullArmyState() - { - miSaveArmyAs.Enabled = false; - miCloseArmy.Enabled = false; - miExportArmyAs.Enabled = false; - DisableCategoryButtons(); - armyTree.Hide(); - } - - private void SetNonNullArmyState(Army newArmy) - { - SetCategoryButtons(newArmy.Race.Categories); - EnableCategoryButtons(); - miSaveArmyAs.Enabled = true; - miCloseArmy.Enabled = true; - miExportArmyAs.Enabled = true; - armyTree.Show(); - } - - private void SetCategoryButtons(Category[] cats) - { - if (CategoryButtonsHaveChanged(cats)) - { - RemoveCategoryButtons(); - AddCategoryButtons(cats); - } - } - - private bool CategoryButtonsHaveChanged(Category[] cats) - { - int catCount = cats.Length; - ToolStripItemCollection items = catToolStrip.Items; - bool haveChanged = (!catToolStrip.Visible || catCount != items.Count); - - if (!haveChanged) - { - for (int i = 0; i < catCount; i++) - { - if (cats[i].Equals(items[i+1].Tag)) - { - haveChanged = true; - break; - } - } - } - - return haveChanged; - } - - private void RemoveCategoryButtons() - { - this.Invoke(new MethodInvoker(catToolStrip.Items.Clear)); - } - - private void AddCategoryButtons(Category[] cats) - { - int catCount = cats.Length; - Category cat; - IBBToolStripButton[] categoryButtons = new IBBToolStripButton[catCount]; - int buttonWidths = 0; - - for (int i = 0; i < catCount; i++) - { - cat = cats[i]; - IBBToolStripButton button = new IBBToolStripButton(); - button.Text = cat.Name; - button.Tag = cat; - button.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add; - button.Enabled = false; - button.Click += new EventHandler(CreateUnitForCategoryButtonClick); - categoryButtons[i] = button; - buttonWidths += button.Width; - } - - log.Debug("Toolstrip width: " + catToolStrip.Width); - log.Debug("Button widths: " + buttonWidths); - - this.Invoke(new ArrayMethodInvoker(catToolStrip.Items.AddRange), new object[]{ categoryButtons }); - } - - private void CreateUnitForCategoryButtonClick(object sender, EventArgs e) - { - if (sender is IBBToolStripButton) - { - IBBToolStripButton button = (IBBToolStripButton)sender; - object tag = button.Tag; - - if (tag is Category) - { - AddUnitFromCategory((Category)tag); - } - } - } - - private void EnableCategoryButtons() - { - catToolStrip.Visible = true; - SetCategoryButtonState(true); - } - - private void DisableCategoryButtons() - { - catToolStrip.Visible = false; - SetCategoryButtonState(false); - } - - private void SetCategoryButtonState(bool state) - { - foreach (IBBToolStripButton button in catToolStrip.Items) - { - button.Enabled = state; - } - } - - private void miSaveArmyAs_Click(object sender, System.EventArgs e) - { - SaveCurrentArmyAs(); - } - - private void commandStack_CommandStackUpdated() - { - bttnUndo.Enabled = commandStack.CanUndo(); - miUndo.Enabled = bttnUndo.Enabled; - bttnRedo.Enabled = commandStack.CanRedo(); - miRedo.Enabled = bttnRedo.Enabled; - - PopulateRedoMenu(); - PopulateUndoMenu(); - - bttnSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null; - miSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null; - } - - private void PopulateRedoMenu() - { - int redoLength = commandStack.RedoLength; - int maxRedo = Math.Min(10, redoLength); - ToolStripItemCollection dropDownItems = bttnRedo.DropDownItems; - dropDownItems.Clear(); - - for (int i = 1; i <= maxRedo; i++) - { - Command cmd = commandStack.PeekRedoCommand(i); - - if (cmd == null) - { - break; - } - - dropDownItems.Add(cmd.Description, null, redoMenu_Click); - } - - if (redoLength > 0) - { - bttnRedo.Text = commandStack.PeekRedoCommand(1).Description; - } - else - { - bttnRedo.Text = Translation.GetTranslation("bttnRedo"); - } - } - - private void PopulateUndoMenu() - { - int undoLength = commandStack.UndoLength; - int maxUndo = Math.Min(10, undoLength); - ToolStripItemCollection dropDownItems = bttnUndo.DropDownItems; - dropDownItems.Clear(); - - for (int i = 1; i <= maxUndo; i++) - { - Command cmd = commandStack.PeekUndoCommand(i); - - if (cmd == null) - { - break; - } - - dropDownItems.Add(cmd.UndoDescription, null, undoMenu_Click); - } - - if (undoLength > 0) - { - bttnUndo.Text = commandStack.PeekUndoCommand(1).UndoDescription; - } - else - { - bttnUndo.Text = Translation.GetTranslation("bttnUndo"); - } - } - - private void miSaveArmy_Click(object sender, System.EventArgs e) - { - SaveCurrentArmy(); - } - - private void SetAppTitle() - { - string str = AppTitle; - - if (CurrentGameSystem!=null) - { - str+= " - "+CurrentGameSystem.Name; - } - - if (CurrentArmy!=null) - { - str+= " - "+CurrentArmy.Name; - } - - this.Text = str; - } - - private void AddUnitFromCategory(Category cat) - { - FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy); - DialogResult dr = newUnit.ShowDialog(this); - - if (dr == DialogResult.OK) - { - CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat)); - commandStack.Execute(cmd); - OpenUnitDialog(cmd.Unit); - } - } - - internal void OpenUnitDialog(Unit unit) - { - string unitID = unit.ID; - - if (unitWindows.ContainsKey(unitID)) - { - unitWindows[unitID].Focus(); - } - else - { - FrmUnit unitForm = new FrmUnit(unit, commandStack); - unitWindows.Add(unitID, unitForm); - unitForm.MdiParent = this; - unitForm.Closing += new CancelEventHandler(unitForm_Closing); - unitForm.Show(); - } - } - - private void unitForm_Closing(object sender, CancelEventArgs e) - { - if (sender is FrmUnit) - { - FrmUnit unitForm = (FrmUnit) sender; - unitWindows.Remove(unitForm.Unit.ID); - } - } - - private void FrmMain_UnitAddedMethod(object unitObj) - { - if (unitObj is Unit) - { - Unit unit = (Unit)unitObj; - sbErrorPanel.Text = ""; - } - } - - private void FrmMain_UnitRemovedMethod(object unitObj) - { - if (unitObj is Unit) - { - Unit unit = (Unit)unitObj; - sbErrorPanel.Text = ""; - - //check if window is open, and close it if it is - foreach (Form frm in this.MdiChildren) - { - if (frm is FrmUnit) - { - if (((FrmUnit)frm).Unit == unit) - { - frm.Close(); - break; - } - } - } - } - } - - /*private void FrmMain_FailedUnitRequirement(FailedUnitRequirement failedRequirement) - { - sbErrorPanel.Text = Translation.GetTranslation("UnitRequirementFailed", "Unit Requirement Failed"); - sbErrorPanel.Tag = failedRequirement.Description; - }*/ - - /*public void MdiChildMoved() - { - Point mouseAt = PointToClient(ActiveMdiChild.Location); - - if (Comparisons.ValueWithinAmount(pnlRight.Right, ActiveMdiChild.Right, 10)) - { - pnlRight.Visible = true; - //pnlRight.Container.Add(ActiveMdiChild); - } - else - { - pnlRight.Visible = false; - } - }*/ - - private void miUndo_Click(object sender, System.EventArgs e) - { - UndoLastAction(); - } - - private void miRedo_Click(object sender, System.EventArgs e) - { - RedoAction(); - } - - private void miCloseArmy_Click(object sender, EventArgs e) - { - CloseCurrentArmy(); - } - - private void miOpenArmy_Click(object sender, EventArgs e) - { - OpenArmy(); - } - - private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal) - { - if (obj is Army) - { - SetPointsPanelText(); - } - } - - private void SetPointsPanelText() - { - if (CurrentArmy==null) - { - sbPointsPanel.Text = ""; - sbPointsPanel.ResetColor(); - } - else - { - sbPointsPanel.Text = String.Format(Translation.GetTranslation("statusPanelPoints"), CurrentArmy.Points, CurrentArmy.MaxPoints); - - if (CurrentArmy.Points>CurrentArmy.MaxPoints) - { - sbPointsPanel.Color = Color.Red; - } - else - { - sbPointsPanel.ResetColor(); - } - } - } - - private void redoMenu_Click(object sender, EventArgs e) - { - if (sender is ToolStripDropDownItem) - { - ToolStripDropDownItem item = (ToolStripDropDownItem)sender; - //we know it's an redo menu item so find it's index and redo everything - int max = bttnRedo.DropDownItems.IndexOf(item); - - if (max >= 0) - { - for (int i = 0; i <= max; i++) - { - commandStack.Redo(); - } - } - } - } - - private void undoMenu_Click(object sender, EventArgs e) - { - if (sender is ToolStripDropDownItem) - { - ToolStripDropDownItem item = (ToolStripDropDownItem)sender; - //we know it's an redo menu item so find it's index and redo everything - int max = bttnUndo.DropDownItems.IndexOf(item); - - if (max >= 0) - { - for (int i = 0; i <= max; i++) - { - commandStack.Undo(); - } - } - } - } - - private void statusBar_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent) - { - statusBar.ColorableStatusBarDrawItem(sender, sbdevent); - } - - private void FrmMain_Closing(object sender, CancelEventArgs e) - { - if (!CloseCurrentArmy()) - { - e.Cancel = true; - } - } - - private void miReloadFiles_Click(object sender, System.EventArgs e) - { - WarFoundryLoader.GetDefault().LoadFiles(); - sbMainPanel.Text = Translation.GetTranslation("GameSystemFilesReloaded", "Game system and race files reloaded"); - statusBarTimer.Enabled = true; - } - - private void statusBarTimer_Tick(object sender, System.EventArgs e) - { - sbMainPanel.Text = ""; - statusBarTimer.Enabled = false; - } - - private void statusBar_PanelClick(object sender, StatusBarPanelClickEventArgs e) - { - if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="") - { - MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - } - - private void miExportArmyAsBasicHTML_Click(object sender, EventArgs e) - { - SaveFileDialog dialog = new SaveFileDialog(); - dialog.Filter = Translation.GetTranslation("armyExportBasicHtmlFilter", "HTML pages") + "|*.html"; - dialog.Title = Translation.GetTranslation("exportArmyDialog", "Export army"); - - DialogResult dr = dialog.ShowDialog(this); - - if (dr == DialogResult.OK) - { - Army army = CurrentArmy; - string filePath = dialog.FileName; - log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); - WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); - } - } - - private void FrmMain_Load(object sender, EventArgs e) - { - string gameSystemID = Preferences.GetStringProperty("currSystem"); - - if (gameSystemID != null && !"".Equals(gameSystemID)) - { - log.Debug("Attempting to load current game system from properties"); - GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); - - if (sys != null) - { - WarFoundryCore.CurrentGameSystem = sys; - log.InfoFormat("Loaded game system {0} from properties", gameSystemID); - } - } - } - - private void miAbout_Click(object sender, EventArgs e) - { - FrmAbout about = new FrmAbout(); - about.ShowDialog(this); + } + #endregion + + private void FileLoadingFinished(List failures) + { + foreach (FileLoadFailure failure in failures) + { + log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); + } + } + + private void miExit_Click(object sender, System.EventArgs e) + { + Application.Exit(); + } + + private void miNewArmy_Click(object sender, System.EventArgs e) + { + CreateNewArmy(); + } + + private void CreateNewArmy() + { + if (CloseCurrentArmy()) + { + FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem); + DialogResult dr = newArmy.ShowDialog(); + + if (dr == DialogResult.OK) + { + try + { + CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); + } + catch (RequiredDataMissingException ex) + { + log.Error("Required data missing from race file", ex); + MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (InvalidFileException ex) + { + log.Error("Race file was invalid", ex); + MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private bool OpenArmy() + { + if (openArmyDialog.Filter=="") + { + string savePath = ArmiesPath; + + if (!Directory.Exists(savePath)) + { + Directory.CreateDirectory(savePath); + } + + openArmyDialog.InitialDirectory = savePath; + openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; + openArmyDialog.Title = Translation.GetTranslation("openArmyDialog"); + + } + + DialogResult dr = openArmyDialog.ShowDialog(this); + + if (dr == DialogResult.OK) + { + if (CloseCurrentArmy()) + { + try + { + string newFilePath = openArmyDialog.FileName; + CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath)); + loadedFilePath = newFilePath; + return true; + } + catch (RequiredDataMissingException ex) + { + log.Error(ex); + MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + catch (InvalidFileException ex) + { + log.Error(ex); + MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + } + else + { + return false; + } + } + else + { + return false; + } + } + + private bool CloseCurrentArmy() + { + if (CurrentArmy!=null) + { + bool canClose = false; + + if (CommandStack.IsDirty()) + { + string saveChanges = Translation.GetTranslation("SaveChangesQuestion", "the army \"{0}\" has been modified\r\nsave changes before closing army?", CurrentArmy.Name); + string saveChangesTitle = Translation.GetTranslation("SaveChangesTitle", "unsaved changes"); + DialogResult dr = MessageBox.Show(this, saveChanges, saveChangesTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3); + + if (dr == DialogResult.Yes) + { + canClose = SaveCurrentArmy(); + } + else if (dr == DialogResult.No) + { + canClose = true; + } + //else they said cancel and we default to "canClose = false" so do nothing + } + else + { + canClose = true; + } + + if (canClose) + { + //do close + DisableCategoryButtons(); + CurrentArmy = null; + return true; + } + else + { + return false; + } + } + else + { + DisableCategoryButtons(); + //pretend we succeeded + return true; + } + } + + private void UndoLastAction() + { + if (commandStack.CanUndo()) + { + commandStack.Undo(); + } + } + + private void RedoAction() + { + if (commandStack.CanRedo()) + { + commandStack.Redo(); + } + } + + private bool SaveCurrentArmy() + { + bool saved = false; + + string filePath = loadedFilePath; + + if (filePath == null) + { + filePath = PromptForArmyFilePath(); + } + + if (filePath != null) + { + saved = SaveCurrentArmyToFile(filePath); + } + + return saved; + } + + private bool SaveCurrentArmyAs() + { + bool saved = false; + string filePath = PromptForArmyFilePath(); + + if (filePath != null) + { + saved = SaveCurrentArmyToFile(filePath); + } + + return saved; + } + + private bool SaveCurrentArmyToFile(string filePath) + { + if (WarFoundrySaver.GetSaver().Save(CurrentArmy, filePath)) + { + loadedFilePath = filePath; + miSaveArmy.Enabled = false; + bttnSaveArmy.Enabled = false; + CommandStack.setCleanMark(); + return true; + } + else + { + MessageBox.Show(this, Translation.GetTranslation("SaveFailed", "file save failed - check log for details"), Translation.GetTranslation("SaveFailedTitle", "file save failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + } + + private string PromptForArmyFilePath() + { + if (saveArmyDialog.Filter == "") + { + string savePath = ArmiesPath; + + if (!Directory.Exists(savePath)) + { + Directory.CreateDirectory(savePath); + } + + saveArmyDialog.InitialDirectory = savePath; + saveArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army"; + saveArmyDialog.Title = Translation.GetTranslation("saveArmyDialog"); + } + + DialogResult dr = saveArmyDialog.ShowDialog(this); + + if (dr == DialogResult.OK) + { + return saveArmyDialog.FileName; + } + else + { + return null; + } + } + + public GameSystem CurrentGameSystem + { + get { return WarFoundryCore.CurrentGameSystem; } + set { WarFoundryCore.CurrentGameSystem = value; } + } + + public Army CurrentArmy + { + get { return WarFoundryCore.CurrentArmy; } + set { SetArmy(value); } + } + + private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem) + { + SetAppTitle(); + RemoveCategoryButtons(); + } + + private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy) + { + CommandStack.Reset(); + loadedFilePath = null; + miSaveArmy.Enabled = false; + bttnSaveArmy.Enabled = false; + SetPointsPanelText(); + SetAppTitle(); + } + + private void SetArmy(Army newArmy) + { + IgnoreArmy(CurrentArmy); + CloseAllUnitWindows(); + + if (newArmy == null) + { + SetNullArmyState(); + } + else + { + WarFoundryCore.CurrentGameSystem = newArmy.GameSystem; + ListenToArmy(newArmy); + SetNonNullArmyState(newArmy); + } + + WarFoundryCore.CurrentArmy = newArmy; + } + + private void IgnoreArmy(Army oldArmy) + { + if (oldArmy != null) + { + oldArmy.UnitAdded -= UnitAddedMethod; + oldArmy.UnitRemoved -= UnitRemovedMethod; + oldArmy.PointsValueChanged -= PointsValueChangedMethod; + } + } + + private void CloseAllUnitWindows() + { + FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows); + + foreach (FrmUnit window in unitForms) + { + window.Close(); + } + + unitWindows.Clear(); + } + + private void ListenToArmy(Army newArmy) + { + if (newArmy != null) + { + newArmy.UnitAdded += UnitAddedMethod; + newArmy.UnitRemoved += UnitRemovedMethod; + newArmy.PointsValueChanged += PointsValueChangedMethod; + } + } + + private void SetNullArmyState() + { + miSaveArmyAs.Enabled = false; + miCloseArmy.Enabled = false; + miExportArmyAs.Enabled = false; + DisableCategoryButtons(); + armyTree.Hide(); + } + + private void SetNonNullArmyState(Army newArmy) + { + SetCategoryButtons(newArmy.Race.Categories); + EnableCategoryButtons(); + miSaveArmyAs.Enabled = true; + miCloseArmy.Enabled = true; + miExportArmyAs.Enabled = true; + armyTree.Show(); + } + + private void SetCategoryButtons(Category[] cats) + { + if (CategoryButtonsHaveChanged(cats)) + { + RemoveCategoryButtons(); + AddCategoryButtons(cats); + } + } + + private bool CategoryButtonsHaveChanged(Category[] cats) + { + int catCount = cats.Length; + ToolStripItemCollection items = catToolStrip.Items; + bool haveChanged = (!catToolStrip.Visible || catCount != items.Count); + + if (!haveChanged) + { + for (int i = 0; i < catCount; i++) + { + if (cats[i].Equals(items[i+1].Tag)) + { + haveChanged = true; + break; + } + } + } + + return haveChanged; + } + + private void RemoveCategoryButtons() + { + this.Invoke(new MethodInvoker(catToolStrip.Items.Clear)); + } + + private void AddCategoryButtons(Category[] cats) + { + int catCount = cats.Length; + Category cat; + IBBToolStripButton[] categoryButtons = new IBBToolStripButton[catCount]; + int buttonWidths = 0; + + for (int i = 0; i < catCount; i++) + { + cat = cats[i]; + IBBToolStripButton button = new IBBToolStripButton(); + button.Text = cat.Name; + button.Tag = cat; + button.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add; + button.Enabled = false; + button.Click += new EventHandler(CreateUnitForCategoryButtonClick); + categoryButtons[i] = button; + buttonWidths += button.Width; + } + + log.Debug("Toolstrip width: " + catToolStrip.Width); + log.Debug("Button widths: " + buttonWidths); + + this.Invoke(new ArrayMethodInvoker(catToolStrip.Items.AddRange), new object[]{ categoryButtons }); + } + + private void CreateUnitForCategoryButtonClick(object sender, EventArgs e) + { + if (sender is IBBToolStripButton) + { + IBBToolStripButton button = (IBBToolStripButton)sender; + object tag = button.Tag; + + if (tag is Category) + { + AddUnitFromCategory((Category)tag); + } + } + } + + private void EnableCategoryButtons() + { + catToolStrip.Visible = true; + SetCategoryButtonState(true); + } + + private void DisableCategoryButtons() + { + catToolStrip.Visible = false; + SetCategoryButtonState(false); + } + + private void SetCategoryButtonState(bool state) + { + foreach (IBBToolStripButton button in catToolStrip.Items) + { + button.Enabled = state; + } + } + + private void miSaveArmyAs_Click(object sender, System.EventArgs e) + { + SaveCurrentArmyAs(); + } + + private void commandStack_CommandStackUpdated() + { + bttnUndo.Enabled = commandStack.CanUndo(); + miUndo.Enabled = bttnUndo.Enabled; + bttnRedo.Enabled = commandStack.CanRedo(); + miRedo.Enabled = bttnRedo.Enabled; + + PopulateRedoMenu(); + PopulateUndoMenu(); + + bttnSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null; + miSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null; + } + + private void PopulateRedoMenu() + { + int redoLength = commandStack.RedoLength; + int maxRedo = Math.Min(10, redoLength); + ToolStripItemCollection dropDownItems = bttnRedo.DropDownItems; + dropDownItems.Clear(); + + for (int i = 1; i <= maxRedo; i++) + { + Command cmd = commandStack.PeekRedoCommand(i); + + if (cmd == null) + { + break; + } + + dropDownItems.Add(cmd.Description, null, redoMenu_Click); + } + + if (redoLength > 0) + { + bttnRedo.Text = commandStack.PeekRedoCommand(1).Description; + } + else + { + bttnRedo.Text = Translation.GetTranslation("bttnRedo"); + } + } + + private void PopulateUndoMenu() + { + int undoLength = commandStack.UndoLength; + int maxUndo = Math.Min(10, undoLength); + ToolStripItemCollection dropDownItems = bttnUndo.DropDownItems; + dropDownItems.Clear(); + + for (int i = 1; i <= maxUndo; i++) + { + Command cmd = commandStack.PeekUndoCommand(i); + + if (cmd == null) + { + break; + } + + dropDownItems.Add(cmd.UndoDescription, null, undoMenu_Click); + } + + if (undoLength > 0) + { + bttnUndo.Text = commandStack.PeekUndoCommand(1).UndoDescription; + } + else + { + bttnUndo.Text = Translation.GetTranslation("bttnUndo"); + } + } + + private void miSaveArmy_Click(object sender, System.EventArgs e) + { + SaveCurrentArmy(); + } + + private void SetAppTitle() + { + string str = AppTitle; + + if (CurrentGameSystem!=null) + { + str+= " - "+CurrentGameSystem.Name; + } + + if (CurrentArmy!=null) + { + str+= " - "+CurrentArmy.Name; + } + + this.Text = str; + } + + private void AddUnitFromCategory(Category cat) + { + FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy); + DialogResult dr = newUnit.ShowDialog(this); + + if (dr == DialogResult.OK) + { + CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat)); + commandStack.Execute(cmd); + OpenUnitDialog(cmd.Unit); + } + } + + internal void OpenUnitDialog(Unit unit) + { + string unitID = unit.ID; + + if (unitWindows.ContainsKey(unitID)) + { + unitWindows[unitID].Focus(); + } + else + { + FrmUnit unitForm = new FrmUnit(unit, commandStack); + unitWindows.Add(unitID, unitForm); + unitForm.MdiParent = this; + unitForm.Closing += new CancelEventHandler(unitForm_Closing); + unitForm.Show(); + } + } + + private void unitForm_Closing(object sender, CancelEventArgs e) + { + if (sender is FrmUnit) + { + FrmUnit unitForm = (FrmUnit) sender; + unitWindows.Remove(unitForm.Unit.ID); + } + } + + private void FrmMain_UnitAddedMethod(object unitObj) + { + if (unitObj is Unit) + { + Unit unit = (Unit)unitObj; + sbErrorPanel.Text = ""; + } + } + + private void FrmMain_UnitRemovedMethod(object unitObj) + { + if (unitObj is Unit) + { + Unit unit = (Unit)unitObj; + sbErrorPanel.Text = ""; + + //check if window is open, and close it if it is + foreach (Form frm in this.MdiChildren) + { + if (frm is FrmUnit) + { + if (((FrmUnit)frm).Unit == unit) + { + frm.Close(); + break; + } + } + } + } + } + + /*private void FrmMain_FailedUnitRequirement(FailedUnitRequirement failedRequirement) + { + sbErrorPanel.Text = Translation.GetTranslation("UnitRequirementFailed", "Unit Requirement Failed"); + sbErrorPanel.Tag = failedRequirement.Description; + }*/ + + /*public void MdiChildMoved() + { + Point mouseAt = PointToClient(ActiveMdiChild.Location); + + if (Comparisons.ValueWithinAmount(pnlRight.Right, ActiveMdiChild.Right, 10)) + { + pnlRight.Visible = true; + //pnlRight.Container.Add(ActiveMdiChild); + } + else + { + pnlRight.Visible = false; + } + }*/ + + private void miUndo_Click(object sender, System.EventArgs e) + { + UndoLastAction(); + } + + private void miRedo_Click(object sender, System.EventArgs e) + { + RedoAction(); + } + + private void miCloseArmy_Click(object sender, EventArgs e) + { + CloseCurrentArmy(); + } + + private void miOpenArmy_Click(object sender, EventArgs e) + { + OpenArmy(); + } + + private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal) + { + if (obj is Army) + { + SetPointsPanelText(); + } + } + + private void SetPointsPanelText() + { + if (CurrentArmy==null) + { + sbPointsPanel.Text = ""; + sbPointsPanel.ResetColor(); + } + else + { + sbPointsPanel.Text = String.Format(Translation.GetTranslation("statusPanelPoints"), CurrentArmy.Points, CurrentArmy.MaxPoints); + + if (CurrentArmy.Points>CurrentArmy.MaxPoints) + { + sbPointsPanel.Color = Color.Red; + } + else + { + sbPointsPanel.ResetColor(); + } + } + } + + private void redoMenu_Click(object sender, EventArgs e) + { + if (sender is ToolStripDropDownItem) + { + ToolStripDropDownItem item = (ToolStripDropDownItem)sender; + //we know it's an redo menu item so find it's index and redo everything + int max = bttnRedo.DropDownItems.IndexOf(item); + + if (max >= 0) + { + for (int i = 0; i <= max; i++) + { + commandStack.Redo(); + } + } + } + } + + private void undoMenu_Click(object sender, EventArgs e) + { + if (sender is ToolStripDropDownItem) + { + ToolStripDropDownItem item = (ToolStripDropDownItem)sender; + //we know it's an redo menu item so find it's index and redo everything + int max = bttnUndo.DropDownItems.IndexOf(item); + + if (max >= 0) + { + for (int i = 0; i <= max; i++) + { + commandStack.Undo(); + } + } + } + } + + private void statusBar_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent) + { + statusBar.ColorableStatusBarDrawItem(sender, sbdevent); + } + + private void FrmMain_Closing(object sender, CancelEventArgs e) + { + if (!CloseCurrentArmy()) + { + e.Cancel = true; + } + } + + private void miReloadFiles_Click(object sender, System.EventArgs e) + { + WarFoundryLoader.GetDefault().LoadFiles(); + sbMainPanel.Text = Translation.GetTranslation("GameSystemFilesReloaded", "Game system and race files reloaded"); + statusBarTimer.Enabled = true; + } + + private void statusBarTimer_Tick(object sender, System.EventArgs e) + { + sbMainPanel.Text = ""; + statusBarTimer.Enabled = false; + } + + private void statusBar_PanelClick(object sender, StatusBarPanelClickEventArgs e) + { + if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="") + { + MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + + private void miExportArmyAsBasicHTML_Click(object sender, EventArgs e) + { + SaveFileDialog dialog = new SaveFileDialog(); + dialog.Filter = Translation.GetTranslation("armyExportBasicHtmlFilter", "HTML pages") + "|*.html"; + dialog.Title = Translation.GetTranslation("exportArmyDialog", "Export army"); + + DialogResult dr = dialog.ShowDialog(this); + + if (dr == DialogResult.OK) + { + Army army = CurrentArmy; + string filePath = dialog.FileName; + log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); + WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); + } + } + + private void FrmMain_Load(object sender, EventArgs e) + { + string gameSystemID = Preferences.GetStringProperty("currSystem"); + + if (gameSystemID != null && !"".Equals(gameSystemID)) + { + log.Debug("Attempting to load current game system from properties"); + GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID); + + if (sys != null) + { + WarFoundryCore.CurrentGameSystem = sys; + log.InfoFormat("Loaded game system {0} from properties", gameSystemID); + } + } + } + + private void miAbout_Click(object sender, EventArgs e) + { + FrmAbout about = new FrmAbout(); + about.ShowDialog(this); } private void miPreferences_Click(object sender, EventArgs e) { FrmPreferences prefsForm = new FrmPreferences(Preferences); prefsForm.Show(this); - } - } -} + } + } +} diff -r 4aabe514c868 -r e0af96397e26 FrmPreferences.Designer.cs --- a/FrmPreferences.Designer.cs Tue Apr 13 20:02:49 2010 +0000 +++ b/FrmPreferences.Designer.cs Wed Apr 14 19:42:45 2010 +0000 @@ -32,8 +32,8 @@ this.languagesGroup = new System.Windows.Forms.GroupBox(); this.lblLanguage = new IBBoard.Windows.Forms.IBBLabel(); this.languageList = new System.Windows.Forms.ComboBox(); - this.bttnOkay = new System.Windows.Forms.Button(); - this.bttnCancel = new System.Windows.Forms.Button(); + this.bttnOkay = new IBBoard.Windows.Forms.IBBButton(); + this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); this.languagesGroup.SuspendLayout(); this.SuspendLayout(); // @@ -115,7 +115,7 @@ private System.Windows.Forms.GroupBox languagesGroup; private System.Windows.Forms.ComboBox languageList; private IBBoard.Windows.Forms.IBBLabel lblLanguage; - private System.Windows.Forms.Button bttnOkay; - private System.Windows.Forms.Button bttnCancel; + private IBBoard.Windows.Forms.IBBButton bttnOkay; + private IBBoard.Windows.Forms.IBBButton bttnCancel; } } \ No newline at end of file diff -r 4aabe514c868 -r e0af96397e26 translations/de.translation --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/translations/de.translation Wed Apr 14 19:42:45 2010 +0000 @@ -0,0 +1,116 @@ + + + Datei + Editieren + Hilfe + Neue Armee + Laden + Speichern + Speichern unter... + Exportieren + Einfaches HTML + Schließen + Dateien neu laden + Beenden + Rückgängig + Wiederholen + Über + OK + Abbrechen + Neue Armee + Armee laden + Armee speichern + Rückgängig + Wiederholen + Armeebaum + Einheit &löschen + Einheit &bearbeiten + Lade Armee + Speichere Armee + WarFoundry Armeedateien (*.army) + {0} von {1} Punkten + Aktueller Armeewert + Einheit aus {0} {1} + Armee erstellen + Spielsystem: + Rasse/Volk: + Armeename: + Armeegröße: + Neue Armee erstellen + Füge eine neue {0}-Auswahl hinzu + Einheiten: + Einheit hinzufügen + Neue Ausrüstung für {0} + Anzahl: + Ausrüstung: + Alle ausrüsten + Die gewählte Prozentzahl ({0}%) ist größer als das Maximum für diesen Ausrüstungsgegenstand ({1}%). Das Maximum wird stattdessen genutzt. + Prozentzahl zu groß + Die gewählte Prozentzahl ({0}%) ist kleiner als das Minimum für diesen Ausrüstungsgegenstand ({1}%). Das Minimum wird stattdessen genutzt. + Prozentzahl zu klein + Die gewählte Anzahl ({0}%) ist größer als das Maximum für diesen Ausrüstungsgegenstand ({1}%). Das Maximum wird stattdessen genutzt. + Anzahl zu groß + Die gewählte Anzahl ({0}%) ist kleiner als das Minimum für diesen Ausrüstungsgegenstand ({1}%). Das Minimum wird stattdessen genutzt. + Anzahl zu klein + Bearbeite {0} für {1} + Über WarFoundry + Version: {0} + Entwickler: + Vielen Dank an: + {0} + Einheitsgröße: + Ausrüstung: + Hinzufügen + Fähigkeiten: + Notizen: + Entfernen + Ersetzen + Bearbeiten + {0} ({1} für je {2} Punkt(e)) + {0} ({1} kostenlos) + Für alle ({1}) + Für {0}% ({1}) + {0} + Ungültige Rassen-/Volksdatei + Ungültige Armeedatei + Die Armee "{0}" wurde geändert. +Änderungen vorm Schließen der Armee speichern? + Nicht gespeicherte Änderungen + WarFoundry konnte die Datei nicht speichern. Die Logdatei kann Hinweise zu dem Problem enthalten. + Speichern fehlgeschlagen + {0} - {1} Punkte + Name + Anmerkungen + Punkte + alle ({1}) + {0}% ({1}) + {0} + {0} für {1} + alle ({1}) + {0}% ({1}) + {0} + {0}-Anzahl für {1} auf {2} setzen + {0}-Anzahl für {1} auf {2} setzen + {0} mit {1} für {2} ersetzen + {0} mit {1} für {2} ersetzen + Einheit {0} hinzufügen + Einheit {0} entfernen + {0} entfernen + {0} wieder hinzufügen + "{0}" in "{1}" umbenennen + "{0}" in "{1}" umbenennen + Größe von {0} auf {1} setzen + Größe von {0} auf {1} setzen + {0}; und {1} + {0}; oder {1} + {0} kann nur gewählt werden, wenn keine der folgenden Auswahlen gewählt werden: {1} + {1} kann nur {0}-mal gewählt werden + {1} muss mindestens {0}-mal gewählt werden + {1} {0} + {0}, {1} + {0} kann nur gewählt werden, wenn folgende Auswahlen gewählt werden: {1} + Einstellungen + Sprache + Sprache: + Sprache + \ No newline at end of file