Skip to content

Commit

Permalink
Merge pull request #126 from lastbattle/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
lastbattle authored Jun 27, 2021
2 parents f89f057 + 5abb50c commit 7117339
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 34 deletions.
3 changes: 2 additions & 1 deletion HaCreator/GUI/HaEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
<!-- Side panel-->
<ScrollViewer Grid.Row="1" Grid.Column="1"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Visible">
VerticalScrollBarVisibility="Visible"
x:Name="editorPanel">
<StackPanel Orientation="Vertical">

<Expander Header="Tile"
Expand Down
4 changes: 3 additions & 1 deletion HaCreator/GUI/HaEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ private void HaEditor2_Loaded(object sender, RoutedEventArgs e)
{
// helper classes
handler = new InputHandler(multiBoard);
hcsm = new HaCreatorStateManager(multiBoard, ribbon, tabControl1, handler, textblock_CursorX, textblock_CursorY, textblock_RCursorX, textblock_RCursorY, textblock_selectedItem);
hcsm = new HaCreatorStateManager(
multiBoard, ribbon, tabControl1, handler, editorPanel,
textblock_CursorX, textblock_CursorY, textblock_RCursorX, textblock_RCursorY, textblock_selectedItem);
hcsm.CloseRequested += Hcsm_CloseRequested;
hcsm.FirstMapLoaded += Hcsm_FirstMapLoaded;

Expand Down
9 changes: 7 additions & 2 deletions HaCreator/GUI/InfoEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using MapleLib.WzLib.WzStructure.Data;
using HaCreator.GUI.InstanceEditor;
using MapleLib.WzLib.WzStructure.Data.MapStructure;
using HaCreator.Wz;

namespace HaCreator.GUI
{
Expand All @@ -28,14 +29,16 @@ public partial class InfoEditor : EditorBase
public MapInfo info;
private readonly MultiBoard multiBoard;
private readonly Board board;
private readonly System.Windows.Controls.TabItem tabItem;

public InfoEditor(Board board, MapInfo info, MultiBoard multiBoard)
public InfoEditor(Board board, MapInfo info, MultiBoard multiBoard, System.Windows.Controls.TabItem tabItem)
{
InitializeComponent();

this.board = board;
this.info = info;
this.multiBoard = multiBoard;
this.tabItem = tabItem;

timeLimitEnable.Tag = timeLimit;
lvLimitEnable.Tag = lvLimit;
Expand Down Expand Up @@ -313,7 +316,9 @@ protected override void okButton_Click(object sender, EventArgs e)
info.strCategoryName = categoryBox.Text;

// We do, however, need to change the tab's name/info
((TabItemContainer)board.TabPage.Tag).Text = info.strMapName;
((TabItemContainer)tabItem.Tag).Text = info.strMapName;

tabItem.Header = MapLoader.GetFormattedMapNameForTabItem(info.id, info.strStreetName, info.strMapName);
}
info.returnMap = cannotReturnCBX.Checked ? info.id : (int)returnBox.Value;
info.forcedReturn = returnHereCBX.Checked ? 999999999 : (int)forcedRet.Value;
Expand Down
2 changes: 1 addition & 1 deletion HaCreator/GUI/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace HaCreator.GUI
{
public partial class Save : Form
{
private Board board;
private readonly Board board;

public Save(Board board)
{
Expand Down
32 changes: 25 additions & 7 deletions HaCreator/MapEditor/HaCreatorStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public class HaCreatorStateManager
private readonly InputHandler input;
private TilePanel tilePanel;
private ObjPanel objPanel;
private System.Windows.Controls.ScrollViewer editorPanel;
public readonly BackupManager backupMan;

public HaCreatorStateManager(MultiBoard multiBoard, HaRibbon ribbon, System.Windows.Controls.TabControl tabs, InputHandler input,
public HaCreatorStateManager(MultiBoard multiBoard, HaRibbon ribbon, System.Windows.Controls.TabControl tabs, InputHandler input, System.Windows.Controls.ScrollViewer editorPanel,
SystemWinCtl.TextBlock textblock_CursorX, SystemWinCtl.TextBlock textblock_CursorY, SystemWinCtl.TextBlock textblock_RCursorX, SystemWinCtl.TextBlock textblock_RCursorY, SystemWinCtl.TextBlock textblock_selectedItem)
{
this.multiBoard = multiBoard;
Expand All @@ -61,6 +62,7 @@ public HaCreatorStateManager(MultiBoard multiBoard, HaRibbon ribbon, System.Wind
this.ribbon = ribbon;
this.tabs = tabs;
this.input = input;
this.editorPanel = editorPanel;

// Status bar
this.textblock_CursorX = textblock_CursorX;
Expand Down Expand Up @@ -349,7 +351,7 @@ void MultiBoard_OnBringToFrontClicked(BoardItem boardRefItem)

#region Tab Events
/// <summary>
/// Context menu for editing map info
/// Context menu for editing map info (right clicking)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Expand All @@ -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();
}
Expand Down Expand Up @@ -440,18 +444,18 @@ private void MapAddMinimap(object sender, EventArgs e)
/// <param name="e"></param>
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)
Expand All @@ -461,10 +465,23 @@ private void CloseMapTab(object sender, EventArgs e)

selectedBoard.Dispose();
}

UpdateEditorPanelVisibility();
}

/// <summary>
/// If there's no more tabs, disable the ability for the user to select any new map objects to be added
/// </summary>
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();
Expand All @@ -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();
}
}
Expand Down
35 changes: 27 additions & 8 deletions HaCreator/MapEditor/MultiBoard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -672,6 +679,9 @@ private void DxContainer_MouseWheel(object sender, System.Windows.Forms.MouseEve
/// <param name="e"></param>
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)
Expand Down Expand Up @@ -700,6 +710,9 @@ private void DxContainer_MouseDown(object sender, System.Windows.Forms.MouseEven
/// <param name="e"></param>
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)
{
Expand All @@ -720,6 +733,9 @@ private void DxContainer_MouseUp(object sender, System.Windows.Forms.MouseEventA
/// <param name="e"></param>
public void DxContainer_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (selectedBoard == null)
return;

lock (this)
{
if (ShortcutKeyPressed != null)
Expand Down Expand Up @@ -750,6 +766,9 @@ public void DxContainer_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
/// <param name="e"></param>
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);
Expand Down
43 changes: 33 additions & 10 deletions HaCreator/Wz/MapLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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) =>
{
Expand All @@ -1021,9 +1029,24 @@ public static void CreateMap(string streetName, string mapName, int mapId, strin
{
item.Tag = newTabPage;
}


multiBoard.HaCreatorStateManager.UpdateEditorPanelVisibility();
}
}

/// <summary>
/// Gets the formatted text of the TabItem (mapid, street name, mapName)
/// </summary>
/// <param name="mapId"></param>
/// <param name="streetName"></param>
/// <param name="mapName"></param>
/// <returns></returns>
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);
Expand Down
8 changes: 5 additions & 3 deletions HaCreator/Wz/MapSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public MapSaver(Board board)

private void CreateImage()
{
string name = "";
string name;
switch (board.MapInfo.mapType)
{
case MapType.RegularMap:
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion HaRepacker/Comparer/TreeViewNodeSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace HaRepacker.Comparer
{
public class TreeViewNodeSorter : IComparer
{
private TreeNode startNode;
private readonly TreeNode startNode;

/// <summary>
/// Constructor
Expand Down

0 comments on commit 7117339

Please sign in to comment.