Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
changeset 13:6b2c8e55564a
* Fix line terminators
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Jun 2009 19:05:57 +0000 |
parents | 685532d43a96 |
children | abbf8a3ac431 |
files | AssemblyInfo.cs FrmMainWindow.cs FrmNewUnit.cs Widgets/UnitDisplayWidget.cs |
diffstat | 4 files changed, 280 insertions(+), 280 deletions(-) [+] |
line wrap: on
line diff
--- a/AssemblyInfo.cs Thu Jun 25 18:12:43 2009 +0000 +++ b/AssemblyInfo.cs Sat Jun 27 19:05:57 2009 +0000 @@ -7,13 +7,13 @@ // change them to the information which is associated with the assembly // you compile. -[assembly: AssemblyTitle("WarFoundry GTK#")] -[assembly: AssemblyDescription("The GTK# interface for the WarFoundry army builder")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("IBBoard.WarFoundry.GTK")] -[assembly: AssemblyCopyright("IBBoard 2009")] -[assembly: AssemblyTrademark("")] +[assembly: AssemblyTitle("WarFoundry GTK#")] +[assembly: AssemblyDescription("The GTK# interface for the WarFoundry army builder")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IBBoard.WarFoundry.GTK")] +[assembly: AssemblyCopyright("IBBoard 2009")] +[assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // The assembly version has following format :
--- a/FrmMainWindow.cs Thu Jun 25 18:12:43 2009 +0000 +++ b/FrmMainWindow.cs Sat Jun 27 19:05:57 2009 +0000 @@ -6,44 +6,44 @@ using System.IO; using System.Collections.Generic; using System.Configuration; -using Gtk; -using IBBoard; +using Gtk; +using IBBoard; using IBBoard.Commands; using IBBoard.GtkSharp; using IBBoard.IO; -using IBBoard.Lang; -using IBBoard.Logging; +using IBBoard.Lang; +using IBBoard.Logging; using IBBoard.CustomMath; using IBBoard.Log4Net; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Factories; -using IBBoard.WarFoundry.API.Factories.Xml; -using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.API.Factories.Xml; +using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Commands; using IBBoard.WarFoundry.API.Savers; using IBBoard.WarFoundry.API.Requirements; using IBBoard.WarFoundry.GTK.Widgets; -using IBBoard.WarFoundry.Plugin.Rollcall; +using IBBoard.WarFoundry.Plugin.Rollcall; using IBBoard.Xml; using log4net; -namespace IBBoard.WarFoundry.GTK +namespace IBBoard.WarFoundry.GTK { public partial class FrmMainWindow: Gtk.Window { private static readonly string AppTitle = "WarFoundry"; - private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6; - - private Preferences preferences; - private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); - + private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6; + + private Preferences preferences; + private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); + private CommandStack commandStack; private Dictionary<ToolButton, Category> categoryMap = new Dictionary<ToolButton, Category>(); - private Dictionary<IBBoard.WarFoundry.API.Objects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<IBBoard.WarFoundry.API.Objects.Unit,UnitDisplayWidget>(); - - private ObjectAddDelegate UnitAddedMethod; - private ObjectRemoveDelegate UnitRemovedMethod; - private DoubleValChangedDelegate PointsValueChangedMethod; + private Dictionary<IBBoard.WarFoundry.API.Objects.Unit, UnitDisplayWidget> unitToWidgetMap = new Dictionary<IBBoard.WarFoundry.API.Objects.Unit,UnitDisplayWidget>(); + + private ObjectAddDelegate UnitAddedMethod; + private ObjectRemoveDelegate UnitRemovedMethod; + private DoubleValChangedDelegate PointsValueChangedMethod; private FailedUnitRequirementDelegate FailedUnitRequirementMethod; private StringValChangedDelegate UnitNameChangedMethod; @@ -53,18 +53,18 @@ private MenuToolButton undoMenuButton, redoMenuButton; public static void Main (string[] args) - { - try + { + try { Application.Init(); FrmMainWindow win = new FrmMainWindow(args); win.Show(); Application.Run(); - LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); - } - catch(Exception ex) - { - LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("("+ex.GetType().Name+") "+ex.Message + Environment.NewLine + ex.StackTrace); + LogManager.GetLogger(typeof(FrmMainWindow)).Debug("Application ended"); + } + catch(Exception ex) + { + LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("("+ex.GetType().Name+") "+ex.Message + Environment.NewLine + ex.StackTrace); } } @@ -118,16 +118,16 @@ dialog.Destroy(); } - logger.Debug("Initialising"); - commandStack = new CommandStack(); + logger.Debug("Initialising"); + commandStack = new CommandStack(); commandStack.CommandStackUpdated+=new MethodInvoker(commandStack_CommandStackUpdated); WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(OnGameSystemChanged); WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(OnArmyChanged); Destroyed+= new EventHandler(OnWindowDestroyed); //TODO: Translate and subscribe to other events - UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded); - UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved); - PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged); + UnitAddedMethod = new ObjectAddDelegate(OnUnitAdded); + UnitRemovedMethod = new ObjectRemoveDelegate(OnUnitRemoved); + PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged); FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement); UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged); logger.Debug("Initialising complete - trying to load default army or system"); @@ -411,7 +411,7 @@ if (response==ResponseType.Ok) { - CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy); + CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy); commandStack.Execute(cmd); } @@ -419,10 +419,10 @@ } } } - - public CommandStack CommandStack - { - get { return commandStack; } + + public CommandStack CommandStack + { + get { return commandStack; } } private void SetAppTitle() @@ -462,10 +462,10 @@ SetArmyTree(newArmy); if (oldArmy!=null) - { - oldArmy.UnitAdded-= UnitAddedMethod; - oldArmy.UnitRemoved-= UnitRemovedMethod; - oldArmy.PointsValueChanged-= PointsValueChangedMethod; + { + oldArmy.UnitAdded-= UnitAddedMethod; + oldArmy.UnitRemoved-= UnitRemovedMethod; + oldArmy.PointsValueChanged-= PointsValueChangedMethod; oldArmy.FailedRequirement-=FailedUnitRequirementMethod; } @@ -476,33 +476,33 @@ unitsNotebook.RemovePage(0); } - if (newArmy==null) - { - DisableCategoryButtons(); - } - else - { - newArmy.UnitAdded+= UnitAddedMethod; - newArmy.UnitRemoved+= UnitRemovedMethod; - newArmy.PointsValueChanged+= PointsValueChangedMethod; - newArmy.FailedRequirement+=FailedUnitRequirementMethod; - //TODO: Clear all buttons - EnableCategoryButtons(); - - if (newArmy.Race.HasCategoryOverrides()) - { - RemoveCategoryButtons(); - AddCategoryButtons(newArmy.Race.Categories); - } + if (newArmy==null) + { + DisableCategoryButtons(); + } + else + { + newArmy.UnitAdded+= UnitAddedMethod; + newArmy.UnitRemoved+= UnitRemovedMethod; + newArmy.PointsValueChanged+= PointsValueChangedMethod; + newArmy.FailedRequirement+=FailedUnitRequirementMethod; + //TODO: Clear all buttons + EnableCategoryButtons(); + + if (newArmy.Race.HasCategoryOverrides()) + { + RemoveCategoryButtons(); + AddCategoryButtons(newArmy.Race.Categories); + } } miCloseArmy.Sensitive = newArmy!=null; miSaveArmyAs.Sensitive = newArmy!=null; //New army has no changes, so we can't save it miSaveArmy.Sensitive = false; - saveArmyButton.Sensitive = false; - - CommandStack.Reset(); + saveArmyButton.Sensitive = false; + + CommandStack.Reset(); SetPointsPanelText(); } @@ -594,108 +594,108 @@ //TODO: Set the points value in the status bar } - private void commandStack_CommandStackUpdated() - { - undoMenuButton.Sensitive = commandStack.CanUndo(); - miUndo.Sensitive = undoMenuButton.Sensitive; - redoMenuButton.Sensitive = commandStack.CanRedo(); - miRedo.Sensitive = redoMenuButton.Sensitive; + private void commandStack_CommandStackUpdated() + { + undoMenuButton.Sensitive = commandStack.CanUndo(); + miUndo.Sensitive = undoMenuButton.Sensitive; + redoMenuButton.Sensitive = commandStack.CanRedo(); + miRedo.Sensitive = redoMenuButton.Sensitive; int redoLength = commandStack.RedoLength; - //TODO: Build menus for undo/redo and find way of adding tooltips - /*int maxRedo = Math.Min(10, redoLength); - MenuItem[] menuItems = null; - - if (redoLength > 0) - { - menuItems = new MenuItem[maxRedo]; - Command com; - MenuItem mi; - - for (int i = 0; i < maxRedo; i++) - { - com = commandStack.PeekRedoCommand(i+1); - - if (com == null) - { - break; - } - - mi = new MenuItem(com.Description); - mi.Click+=new EventHandler(redoMenu_Click); - menuItems[i] = mi; - } - } - - redoMenu.MenuItems.Clear(); - - if (menuItems!=null && menuItems[0]!=null) - { - bttnRedo.ToolTipText = menuItems[0].Text; - redoMenu.MenuItems.AddRange(menuItems); + //TODO: Build menus for undo/redo and find way of adding tooltips + /*int maxRedo = Math.Min(10, redoLength); + MenuItem[] menuItems = null; + + if (redoLength > 0) + { + menuItems = new MenuItem[maxRedo]; + Command com; + MenuItem mi; + + for (int i = 0; i < maxRedo; i++) + { + com = commandStack.PeekRedoCommand(i+1); + + if (com == null) + { + break; + } + + mi = new MenuItem(com.Description); + mi.Click+=new EventHandler(redoMenu_Click); + menuItems[i] = mi; + } + } + + redoMenu.MenuItems.Clear(); + + if (menuItems!=null && menuItems[0]!=null) + { + bttnRedo.ToolTipText = menuItems[0].Text; + redoMenu.MenuItems.AddRange(menuItems); }*/ //TODO: Put above code back when we have a dropdown version of the redo button if (redoLength > 0) { //redoMenuButton.Tooltip = CommandStack.PeekRedoCommand().Description; - } - - int undoLength = commandStack.UndoLength; - /*int maxUndo = Math.Min(10, undoLength); - MenuItem[] menuItemsUndo = null; - - if (undoLength > 0) - { - menuItemsUndo = new MenuItem[maxUndo]; - Command com; - MenuItem mi; - - for (int i = 0; i < maxUndo; i++) - { - com = commandStack.PeekUndoCommand(i+1); - - if (com == null) - { - break; - } - - mi = new MenuItem(com.UndoDescription); - mi.Click+=new EventHandler(undoMenu_Click); - menuItemsUndo[i] = mi; - } - } - - undoMenu.MenuItems.Clear(); - - if (menuItemsUndo!=null && menuItemsUndo[0]!=null) - { - bttnUndo.ToolTipText = menuItemsUndo[0].Text; - undoMenu.MenuItems.AddRange(menuItemsUndo); + } + + int undoLength = commandStack.UndoLength; + /*int maxUndo = Math.Min(10, undoLength); + MenuItem[] menuItemsUndo = null; + + if (undoLength > 0) + { + menuItemsUndo = new MenuItem[maxUndo]; + Command com; + MenuItem mi; + + for (int i = 0; i < maxUndo; i++) + { + com = commandStack.PeekUndoCommand(i+1); + + if (com == null) + { + break; + } + + mi = new MenuItem(com.UndoDescription); + mi.Click+=new EventHandler(undoMenu_Click); + menuItemsUndo[i] = mi; + } + } + + undoMenu.MenuItems.Clear(); + + if (menuItemsUndo!=null && menuItemsUndo[0]!=null) + { + bttnUndo.ToolTipText = menuItemsUndo[0].Text; + undoMenu.MenuItems.AddRange(menuItemsUndo); }*/ - //TODO: Put above code back when we have a dropdown version of the undo button + //TODO: Put above code back when we have a dropdown version of the undo button if (undoLength > 0) { //undoMenuButton.Tooltip = CommandStack.PeekUndoCommand().UndoDescription; } - - saveArmyButton.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave(); - miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave(); + + saveArmyButton.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave(); + miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave(); } private bool CanSave() { return loadedArmyPath!=null && WarFoundryCore.CurrentArmy!=null && WarFoundrySaver.GetSaver()!=null; - } - - private bool SaveCurrentArmyOrSaveAs() - { - if (CanSave()) - { - return SaveCurrentArmy(); - } - else - { - return SaveCurrentArmyAs(); - } + } + + private bool SaveCurrentArmyOrSaveAs() + { + if (CanSave()) + { + return SaveCurrentArmy(); + } + else + { + return SaveCurrentArmyAs(); + } } private bool OpenArmy() @@ -704,22 +704,22 @@ bool success = false; loadedArmyPath = null;//TODO: Set loaded file path return success; - } - - private bool SaveCurrentArmy() + } + + private bool SaveCurrentArmy() { bool success = false; - - if (CanSave()) + + if (CanSave()) { try - { - if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, loadedArmyPath)) + { + if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, loadedArmyPath)) { saveArmyButton.Sensitive = false; - miSaveArmy.Sensitive = false; - CommandStack.setCleanMark(); - success = true; + miSaveArmy.Sensitive = false; + CommandStack.setCleanMark(); + success = true; } } catch (IOException ex) @@ -727,74 +727,74 @@ logger.Error("Saving army failed", ex); MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "An error occured while saving the army. Please check the logs for details on what failed"); md.Show(); - } + } } - return success; - } - - private bool SaveCurrentArmyAs() - { - /*if (saveArmyDialog.Filter == "") - { - string savePath = UserDataPath+Constants.DirectoryString+"armies"+Constants.DirectoryString; - - 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) - { - if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, saveArmyDialog.FileName)) - { - miSaveArmy.Enabled = false; - bttnSaveArmy.Enabled = false; + return success; + } + + private bool SaveCurrentArmyAs() + { + /*if (saveArmyDialog.Filter == "") + { + string savePath = UserDataPath+Constants.DirectoryString+"armies"+Constants.DirectoryString; + + 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) + { + if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, saveArmyDialog.FileName)) + { + miSaveArmy.Enabled = false; + bttnSaveArmy.Enabled = false; CommandStack.setCleanMark(); - loadedArmyPath = saveArmyDialog.FileName; - return true; - } - else - { - MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - } - else - { - return false; + loadedArmyPath = saveArmyDialog.FileName; + return true; + } + else + { + MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + } + else + { + return false; }*/ - return false; + return false; } - private bool CloseCurrentArmy() - { - if (WarFoundryCore.CurrentArmy!=null) - { - bool canClose = false; - - if (CommandStack.IsDirty()) + private bool CloseCurrentArmy() + { + if (WarFoundryCore.CurrentArmy!=null) + { + bool canClose = false; + + if (CommandStack.IsDirty()) { - MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo | ButtonsType.Cancel, "The army \""+WarFoundryCore.CurrentArmy.Name+"\" has been modified.\r\nSave changes before closing army?"); + MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo | ButtonsType.Cancel, "The army \""+WarFoundryCore.CurrentArmy.Name+"\" has been modified.\r\nSave changes before closing army?"); ResponseType dr = (ResponseType)dia.Run(); - if (dr == ResponseType.Yes) + if (dr == ResponseType.Yes) { //They want to save so try to save it or prompt for save as - //If they cancel the save as then assume they don't want to close - canClose = SaveCurrentArmyOrSaveAs(); - } - else if (dr == ResponseType.No) + //If they cancel the save as then assume they don't want to close + canClose = SaveCurrentArmyOrSaveAs(); + } + else if (dr == ResponseType.No) { - //They don't care about their changes - canClose = true; + //They don't care about their changes + canClose = true; } else { @@ -802,33 +802,33 @@ canClose = false; } - dia.Dispose(); - } - else + dia.Dispose(); + } + else + { + //Nothing has changed so we can safely close + canClose = true; + } + + if (canClose) { - //Nothing has changed so we can safely close - canClose = true; - } - - if (canClose) - { - //do close - WarFoundryCore.CurrentArmy = null; - return true; - } - else - { - return false; - } - } - else - { - //pretend we succeeded - return true; - } - } - - private void CreateNewArmy() + //do close + WarFoundryCore.CurrentArmy = null; + return true; + } + else + { + return false; + } + } + else + { + //pretend we succeeded + return true; + } + } + + private void CreateNewArmy() { logger.Debug("Create new army"); FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem); @@ -836,8 +836,8 @@ newArmy.Hide(); if (type == ResponseType.Ok) - { - if (CloseCurrentArmy()) + { + if (CloseCurrentArmy()) { WarFoundryCore.CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); } @@ -847,7 +847,7 @@ logger.Debug("Create new army cancelled"); } - newArmy.Destroy(); + newArmy.Destroy(); } private void ChangeCurrentGameSystem()
--- a/FrmNewUnit.cs Thu Jun 25 18:12:43 2009 +0000 +++ b/FrmNewUnit.cs Sat Jun 27 19:05:57 2009 +0000 @@ -12,7 +12,7 @@ namespace IBBoard.WarFoundry.GTK { public partial class FrmNewUnit : Gtk.Dialog - { + { private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); private UnitType unitType; @@ -54,7 +54,7 @@ SetSelectUnitEnabledVal(); } - public UnitType SelectedUnit + public UnitType SelectedUnit { get { return unitType; } } @@ -74,27 +74,27 @@ return toReturn; } - private void SetSelectUnitEnabledVal() + private void SetSelectUnitEnabledVal() { UnitType type = GetSelectedUnitType(); - - if (type!=null) - { + + if (type!=null) + { buttonOk.Sensitive = true; - List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); - lblNewUnitWarning.Visible = (fails != null); - - if (fails.Count > 0) + List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); + lblNewUnitWarning.Visible = (fails != null); + + if (fails.Count > 0) { - //FIXME: currently only show the first error - lblNewUnitWarning.Text = fails[0].Description; - } - } - else - { + //FIXME: currently only show the first error + lblNewUnitWarning.Text = fails[0].Description; + } + } + else + { buttonOk.Sensitive = false; - lblNewUnitWarning.Visible = false; - } + lblNewUnitWarning.Visible = false; + } } protected virtual void OnButtonCancelActivated (object sender, System.EventArgs e)
--- a/Widgets/UnitDisplayWidget.cs Thu Jun 25 18:12:43 2009 +0000 +++ b/Widgets/UnitDisplayWidget.cs Sat Jun 27 19:05:57 2009 +0000 @@ -37,28 +37,28 @@ unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged); unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged); SetStats(); - } - - private void SetStats() - { - //GameSystem system = unit.Army.GameSystem; + } + + private void SetStats() + { + //GameSystem system = unit.Army.GameSystem; //SystemStats stats = system.StandardSystemStats; CellRendererText renderer = new CellRendererText(); unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); - Stat[] stats = unit.UnitStatsArray; - - int length = stats.Length; - - for (int i = 0; i < length; i++) + Stat[] stats = unit.UnitStatsArray; + + int length = stats.Length; + + for (int i = 0; i < length; i++) { - unitStats.AppendColumn(stats[i].ParentSlot.Name, renderer, statFunc); - } + unitStats.AppendColumn(stats[i].ParentSlot.Name, renderer, statFunc); + } TreeStore model = new TreeStore(typeof(IBBoard.WarFoundry.API.Objects.Unit)); - model.AppendValues(unit); - unitStats.Model = model; + model.AppendValues(unit); + unitStats.Model = model; } private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)