diff --git a/HaCreator/GUI/HaEditor.xaml b/HaCreator/GUI/HaEditor.xaml index 6cb4e250..3f5cb446 100644 --- a/HaCreator/GUI/HaEditor.xaml +++ b/HaCreator/GUI/HaEditor.xaml @@ -48,7 +48,8 @@ + VerticalScrollBarVisibility="Visible" + x:Name="editorPanel"> - /// Context menu for editing map info + /// Context menu for editing map info (right clicking) /// /// /// @@ -361,10 +363,12 @@ private void MapEditInfo(object sender, EventArgs e) System.Windows.Controls.TabItem tabItem = (System.Windows.Controls.TabItem)item.Tag; TabItemContainer container = (TabItemContainer)tabItem.Tag; + Board selectedBoard = container.Board; lock (selectedBoard.ParentControl) { - new InfoEditor(selectedBoard, selectedBoard.MapInfo, multiBoard).ShowDialog(); + InfoEditor infoEditor = new InfoEditor(selectedBoard, selectedBoard.MapInfo, multiBoard, tabItem); + infoEditor.ShowDialog(); if (selectedBoard.ParentControl.SelectedBoard == selectedBoard) selectedBoard.ParentControl.AdjustScrollBars(); } @@ -440,18 +444,18 @@ private void MapAddMinimap(object sender, EventArgs e) /// private void CloseMapTab(object sender, EventArgs e) { - if (tabs.Items.Count <= 1) // at least 1 tabs for now + if (tabs.Items.Count <= 0) // at least 1 tabs for now { return; } if (MessageBox.Show("Are you sure you want to close this map?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return; - System.Windows.Controls.MenuItem item = (System.Windows.Controls.MenuItem)sender; + System.Windows.Controls.MenuItem item = (System.Windows.Controls.MenuItem)sender; if (item == null) return; - System.Windows.Controls.TabItem tabItem = (System.Windows.Controls.TabItem) item.Tag; + System.Windows.Controls.TabItem tabItem = (System.Windows.Controls.TabItem)item.Tag; TabItemContainer container = (TabItemContainer)tabItem.Tag; Board selectedBoard = container.Board; lock (selectedBoard.ParentControl) @@ -461,10 +465,23 @@ private void CloseMapTab(object sender, EventArgs e) selectedBoard.Dispose(); } + + UpdateEditorPanelVisibility(); + } + + /// + /// If there's no more tabs, disable the ability for the user to select any new map objects to be added + /// + public void UpdateEditorPanelVisibility() + { + editorPanel.IsEnabled = tabs.Items.Count > 0; // at least 1 tabs for now } private void Tabs_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { + if (multiBoard.SelectedBoard == null) + return; + lock (multiBoard) { MultiBoard_ReturnToSelectionState(); @@ -480,11 +497,12 @@ private void Tabs_SelectionChanged(object sender, System.Windows.Controls.Select ribbon.SetLayers(multiBoard.SelectedBoard.Layers); ribbon.SetSelectedLayer(multiBoard.SelectedBoard.SelectedLayerIndex, multiBoard.SelectedBoard.SelectedPlatform, multiBoard.SelectedBoard.SelectedAllLayers, multiBoard.SelectedBoard.SelectedAllPlatforms); ribbon.SetHasMinimap(multiBoard.SelectedBoard.MinimapRectangle != null); + + ParseVisibleEditedTypes(); } else { multiBoard.SelectedBoard = null; } - ParseVisibleEditedTypes(); multiBoard.Focus(); } } diff --git a/HaCreator/MapEditor/MultiBoard.xaml.cs b/HaCreator/MapEditor/MultiBoard.xaml.cs index 4d5740af..bf7376be 100644 --- a/HaCreator/MapEditor/MultiBoard.xaml.cs +++ b/HaCreator/MapEditor/MultiBoard.xaml.cs @@ -309,16 +309,23 @@ public void RenderFrame() #else sprite.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, Matrix.CreateScale(1.0f)); #endif - lock (this) + + if (selectedBoard != null) // No map selected to draw on { - selectedBoard.RenderBoard(sprite); - if (selectedBoard.MapSize.X < _CurrentDXWindowSize.Width) - { - DrawLine(sprite, new Vector2(MapSize.X, 0), new Vector2(MapSize.X, _CurrentDXWindowSize.Height), Color.Black); - } - if (selectedBoard.MapSize.Y < _CurrentDXWindowSize.Height) + lock (this) { - DrawLine(sprite, new Vector2(0, MapSize.Y), new Vector2(_CurrentDXWindowSize.Width, MapSize.Y), Color.Black); + if (selectedBoard != null) // check again + { + selectedBoard.RenderBoard(sprite); + if (selectedBoard.MapSize.X < _CurrentDXWindowSize.Width) + { + DrawLine(sprite, new Vector2(MapSize.X, 0), new Vector2(MapSize.X, _CurrentDXWindowSize.Height), Color.Black); + } + if (selectedBoard.MapSize.Y < _CurrentDXWindowSize.Height) + { + DrawLine(sprite, new Vector2(0, MapSize.Y), new Vector2(_CurrentDXWindowSize.Width, MapSize.Y), Color.Black); + } + } } } #if FPS_TEST @@ -672,6 +679,9 @@ private void DxContainer_MouseWheel(object sender, System.Windows.Forms.MouseEve /// private void DxContainer_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { + if (selectedBoard == null) + return; + // If the mouse has not been moved while we were in focus (e.g. when clicking on the editor while another window focused), this event will be sent without a mousemove event preceding it. // We will move it to its correct position by invoking the move event handler manually. if (selectedBoard.Mouse.X != e.X || selectedBoard.Mouse.Y != e.Y) @@ -700,6 +710,9 @@ private void DxContainer_MouseDown(object sender, System.Windows.Forms.MouseEven /// private void DxContainer_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { + if (selectedBoard == null) + return; + selectedBoard.Mouse.IsDown = false; if (e.Button == System.Windows.Forms.MouseButtons.Left && LeftMouseUp != null) { @@ -720,6 +733,9 @@ private void DxContainer_MouseUp(object sender, System.Windows.Forms.MouseEventA /// public void DxContainer_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { + if (selectedBoard == null) + return; + lock (this) { if (ShortcutKeyPressed != null) @@ -750,6 +766,9 @@ public void DxContainer_KeyDown(object sender, System.Windows.Forms.KeyEventArgs /// private void DxContainer_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { + if (selectedBoard == null) + return; + lock (this) { Point realPosition = new Point(e.X, e.Y); diff --git a/HaCreator/Wz/MapLoader.cs b/HaCreator/Wz/MapLoader.cs index c313a8a6..8e87e482 100644 --- a/HaCreator/Wz/MapLoader.cs +++ b/HaCreator/Wz/MapLoader.cs @@ -784,33 +784,41 @@ public static void LoadMisc(WzImage mapImage, Board mapBoard) public static System.Windows.Controls.ContextMenu CreateStandardMapMenu(System.Windows.RoutedEventHandler[] rightClickHandler) { System.Windows.Controls.ContextMenu menu = new System.Windows.Controls.ContextMenu(); - - System.Windows.Controls.MenuItem menuItem1 = new System.Windows.Controls.MenuItem(); - menuItem1.Header = "Edit map info..."; + + System.Windows.Controls.MenuItem menuItem1 = new System.Windows.Controls.MenuItem + { + Header = "Edit map info..." + }; menuItem1.Click += rightClickHandler[0]; menuItem1.Icon = new System.Windows.Controls.Image { Source = BitmapHelper.Convert(Properties.Resources.mapEditMenu, System.Drawing.Imaging.ImageFormat.Png) }; - System.Windows.Controls.MenuItem menuItem2 = new System.Windows.Controls.MenuItem(); - menuItem2.Header = "Add VR"; + System.Windows.Controls.MenuItem menuItem2 = new System.Windows.Controls.MenuItem + { + Header = "Add VR" + }; menuItem2.Click += rightClickHandler[1]; menuItem2.Icon = new System.Windows.Controls.Image { Source = BitmapHelper.Convert(Properties.Resources.mapEditMenu, System.Drawing.Imaging.ImageFormat.Png) }; - System.Windows.Controls.MenuItem menuItem3 = new System.Windows.Controls.MenuItem(); - menuItem3.Header = "Add Minimap"; + System.Windows.Controls.MenuItem menuItem3 = new System.Windows.Controls.MenuItem + { + Header = "Add Minimap" + }; menuItem3.Click += rightClickHandler[2]; menuItem3.Icon = new System.Windows.Controls.Image { Source = BitmapHelper.Convert(Properties.Resources.mapEditMenu, System.Drawing.Imaging.ImageFormat.Png) }; - System.Windows.Controls.MenuItem menuItem4 = new System.Windows.Controls.MenuItem(); - menuItem4.Header = "Close"; + System.Windows.Controls.MenuItem menuItem4 = new System.Windows.Controls.MenuItem + { + Header = "Close" + }; menuItem4.Click += rightClickHandler[3]; menuItem4.Icon = new System.Windows.Controls.Image { @@ -1000,7 +1008,7 @@ public static void CreateMap(string streetName, string mapName, int mapId, strin System.Windows.Controls.TabItem newTabPage = new System.Windows.Controls.TabItem { - Header = string.Format("[{0}] {1}: {2}", mapId == -1 ? "" : mapId.ToString(), streetName, mapName) // Header of the tab + Header = GetFormattedMapNameForTabItem(mapId, streetName, mapName) }; newTabPage.MouseRightButtonUp += (sender, e) => { @@ -1021,9 +1029,24 @@ public static void CreateMap(string streetName, string mapName, int mapId, strin { item.Tag = newTabPage; } + + + multiBoard.HaCreatorStateManager.UpdateEditorPanelVisibility(); } } + /// + /// Gets the formatted text of the TabItem (mapid, street name, mapName) + /// + /// + /// + /// + /// + public static string GetFormattedMapNameForTabItem(int mapId, string streetName, string mapName) + { + return string.Format("[{0}] {1}: {2}", mapId == -1 ? "" : mapId.ToString(), streetName, mapName); // Header of the tab + } + public static void CreateMapFromHam(MultiBoard multiBoard, System.Windows.Controls.TabControl Tabs, string data, System.Windows.RoutedEventHandler[] rightClickHandler) { CreateMap("", "", -1, "", CreateStandardMapMenu(rightClickHandler), new XNA.Point(), new XNA.Point(), Tabs, multiBoard); diff --git a/HaCreator/Wz/MapSaver.cs b/HaCreator/Wz/MapSaver.cs index 9e7bf7d2..3f031bcb 100644 --- a/HaCreator/Wz/MapSaver.cs +++ b/HaCreator/Wz/MapSaver.cs @@ -36,7 +36,7 @@ public MapSaver(Board board) private void CreateImage() { - string name = ""; + string name; switch (board.MapInfo.mapType) { case MapType.RegularMap: @@ -49,8 +49,10 @@ private void CreateImage() default: throw new Exception("Unknown map type"); } - this.image = new WzImage(name + ".img"); - this.image.Parsed = true; + this.image = new WzImage(name + ".img") + { + Parsed = true + }; } private void InsertImage() diff --git a/HaRepacker/Comparer/TreeViewNodeSorter.cs b/HaRepacker/Comparer/TreeViewNodeSorter.cs index e1e62617..9c7703a6 100644 --- a/HaRepacker/Comparer/TreeViewNodeSorter.cs +++ b/HaRepacker/Comparer/TreeViewNodeSorter.cs @@ -7,7 +7,7 @@ namespace HaRepacker.Comparer { public class TreeViewNodeSorter : IComparer { - private TreeNode startNode; + private readonly TreeNode startNode; /// /// Constructor