Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
comparison FrmMain.cs @ 117:468a41d79b10
Fixes #237: loading race after choise of race bug
* Don't add buttons when game system changes
* Add buttons on army change when the categories have changed
* Store the game system before we do army stuff so that a change in game system doesn't trigger setting the army to null and resetting our buttons (which is what happened before)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 07 Jan 2010 20:42:05 +0000 |
parents | 1e92802391e3 |
children | d2aa50d97377 |
comparison
equal
deleted
inserted
replaced
116:1e92802391e3 | 117:468a41d79b10 |
---|---|
830 | 830 |
831 private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem) | 831 private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem) |
832 { | 832 { |
833 SetAppTitle(); | 833 SetAppTitle(); |
834 RemoveCategoryButtons(); | 834 RemoveCategoryButtons(); |
835 AddCategoryButtons(); | |
836 } | 835 } |
837 | 836 |
838 private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy) | 837 private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy) |
839 { | 838 { |
840 CommandStack.Reset(); | 839 CommandStack.Reset(); |
854 { | 853 { |
855 SetNullArmyState(); | 854 SetNullArmyState(); |
856 } | 855 } |
857 else | 856 else |
858 { | 857 { |
858 WarFoundryCore.CurrentGameSystem = newArmy.GameSystem; | |
859 ListenToArmy(newArmy); | 859 ListenToArmy(newArmy); |
860 SetNonNullArmyState(newArmy); | 860 SetNonNullArmyState(newArmy); |
861 } | 861 } |
862 | 862 |
863 WarFoundryCore.CurrentArmy = newArmy; | 863 WarFoundryCore.CurrentArmy = newArmy; |
904 armyTree.Hide(); | 904 armyTree.Hide(); |
905 } | 905 } |
906 | 906 |
907 private void SetNonNullArmyState(Army newArmy) | 907 private void SetNonNullArmyState(Army newArmy) |
908 { | 908 { |
909 if (newArmy.Race.HasCategoryOverrides()) | 909 SetCategoryButtons(newArmy.Race.Categories); |
910 { | |
911 RemoveCategoryButtons(); | |
912 AddCategoryButtons(newArmy.Race.Categories); | |
913 } | |
914 | |
915 EnableCategoryButtons(); | 910 EnableCategoryButtons(); |
916 miSaveArmyAs.Enabled = true; | 911 miSaveArmyAs.Enabled = true; |
917 miCloseArmy.Enabled = true; | 912 miCloseArmy.Enabled = true; |
918 miExportArmyAs.Enabled = true; | 913 miExportArmyAs.Enabled = true; |
919 armyTree.Show(); | 914 armyTree.Show(); |
920 } | 915 } |
921 | 916 |
922 private void AddCategoryButtons() | 917 private void SetCategoryButtons(Category[] cats) |
923 { | 918 { |
924 if (CurrentGameSystem!=null) | 919 if (CategoryButtonsHaveChanged(cats)) |
925 { | 920 { |
926 AddCategoryButtons(CurrentGameSystem.Categories); | 921 RemoveCategoryButtons(); |
922 AddCategoryButtons(cats); | |
923 } | |
924 } | |
925 | |
926 private bool CategoryButtonsHaveChanged(Category[] cats) | |
927 { | |
928 int catCount = cats.Length; | |
929 bool haveChanged = (categoryButtons == null || catCount != (categoryButtons.Length - 1)); | |
930 | |
931 if (!haveChanged) | |
932 { | |
933 for (int i = 0; i < catCount; i++) | |
934 { | |
935 if (cats[i].Equals(categoryButtons[i+1].Tag)) | |
936 { | |
937 haveChanged = true; | |
938 break; | |
939 } | |
940 } | |
941 } | |
942 | |
943 return haveChanged; | |
944 } | |
945 | |
946 private void RemoveCategoryButtons() | |
947 { | |
948 if (categoryButtons!=null) | |
949 { | |
950 for (int i = 0; i<categoryButtons.Length; i++) | |
951 { | |
952 this.Invoke(new ToolBarButtonDelegate(toolBar.Buttons.Remove), new object[]{categoryButtons[i]}); | |
953 } | |
927 } | 954 } |
928 } | 955 } |
929 | 956 |
930 private void AddCategoryButtons(Category[] cats) | 957 private void AddCategoryButtons(Category[] cats) |
931 { | 958 { |
932 int catCount = cats.Length; | 959 int catCount = cats.Length; |
933 Category cat; | 960 Category cat; |
934 categoryButtons = new ToolBarButton[catCount+1]; | 961 categoryButtons = new ToolBarButton[catCount + 1]; |
935 | 962 |
936 ToolBarButton sep = new ToolBarButton(); | 963 ToolBarButton sep = new ToolBarButton(); |
937 sep.Style = ToolBarButtonStyle.Separator; | 964 sep.Style = ToolBarButtonStyle.Separator; |
938 categoryButtons[0] = sep; | 965 categoryButtons[0] = sep; |
939 | 966 |
940 IBBToolBarButton button; | 967 IBBToolBarButton button; |
941 | 968 |
942 for (int i = 0; i<catCount; i++) | 969 for (int i = 0; i < catCount; i++) |
943 { | 970 { |
944 cat = cats[i]; | 971 cat = cats[i]; |
945 button = new IBBToolBarButton(); | 972 button = new IBBToolBarButton(); |
946 ///button.Name = "bttnAddCategory" + cat.Name[0].ToString(); | 973 button.Text = cat.Name; |
947 button.Text = cat.Name.ToString();//String.Format(Translation.GetTranslation("bttnAddCategory"), cat.Name); | |
948 button.Tag = cat; | 974 button.Tag = cat; |
949 button.ImageIndex = 6; | 975 button.ImageIndex = 6; |
950 button.Enabled = false; | 976 button.Enabled = false; |
951 categoryButtons[i+1] = button; | 977 categoryButtons[i + 1] = button; |
952 } | 978 } |
953 | 979 |
954 this.Invoke(new ToolBarButtonRangeDelegate(toolBar.Buttons.AddRange), new object[]{categoryButtons}); | 980 this.Invoke(new ToolBarButtonRangeDelegate(toolBar.Buttons.AddRange), new object[] { categoryButtons }); |
955 } | |
956 | |
957 private void RemoveCategoryButtons() | |
958 { | |
959 if (categoryButtons!=null) | |
960 { | |
961 for (int i = 0; i<categoryButtons.Length; i++) | |
962 { | |
963 this.Invoke(new ToolBarButtonDelegate(toolBar.Buttons.Remove), new object[]{categoryButtons[i]}); | |
964 } | |
965 } | |
966 } | 981 } |
967 | 982 |
968 private void EnableCategoryButtons() | 983 private void EnableCategoryButtons() |
969 { | 984 { |
970 SetCategoryButtonState(true); | 985 SetCategoryButtonState(true); |