Skip to content

Commit

Permalink
[HaCreator] Create a new map by cloning
Browse files Browse the repository at this point in the history
- speeds things up
  • Loading branch information
lastbattle committed Dec 6, 2020
1 parent 88d1141 commit 81a6e6c
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 27 deletions.
8 changes: 3 additions & 5 deletions HaCreator/GUI/Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ namespace HaCreator.GUI
{
public partial class Load : System.Windows.Forms.Form
{
public bool usebasepng = false;
public int bufferzone = 100;
private MultiBoard multiBoard;
private System.Windows.Controls.TabControl Tabs;
private System.Windows.RoutedEventHandler[] rightClickHandler;
private readonly MultiBoard multiBoard;
private readonly System.Windows.Controls.TabControl Tabs;
private readonly System.Windows.RoutedEventHandler[] rightClickHandler;

private readonly string defaultMapNameFilter;

Expand Down
144 changes: 128 additions & 16 deletions HaCreator/GUI/New.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 80 additions & 6 deletions HaCreator/GUI/New.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

using HaCreator.GUI.InstanceEditor;
using HaCreator.MapEditor;
using HaCreator.Wz;
using MapleLib.WzLib;
using MapleLib.WzLib.WzProperties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -33,15 +36,91 @@ public New(MultiBoard board, System.Windows.Controls.TabControl Tabs, System.Win
this.rightClickHandler = rightClickHandler;
}

/// <summary>
/// On Load
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void New_Load(object sender, EventArgs e)
{
newWidth.Text = ApplicationSettings.LastMapSize.Width.ToString();
newHeight.Text = ApplicationSettings.LastMapSize.Height.ToString();
}

#region Create new
private void newButton_Click(object sender, EventArgs e)
{
int w = int.Parse(newWidth.Text);
int h = int.Parse(newHeight.Text);

MapLoader.CreateMap("", "<Untitled>", -1, "", MapLoader.CreateStandardMapMenu(rightClickHandler), new XNA.Point(w, h), new XNA.Point(w / 2, h / 2), Tabs, multiBoard);
DialogResult = DialogResult.OK;
Close();
}
#endregion

#region Clone map
/// <summary>
/// Select a map
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_SelectCloneMap_Click(object sender, EventArgs e)
{
LoadMapSelector selector = new LoadMapSelector(numericUpDown1);
selector.ShowDialog();
}

/// <summary>
/// On map id selection changed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown1.Value != -1)
{
buttonCreateFrmClone.Enabled = true; // enable the button after selecting a map
}
}


/// <summary>
/// Button on create map
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateFrmClone_Click(object sender, EventArgs e)
{
if (numericUpDown1.Value == -1)
return;

long mapid = (long) numericUpDown1.Value; // should be int, but anyway in case the future version uses more than 2.1b
string mapId_str = mapid.ToString();
string mapId_PaddingZeros = mapId_str.PadLeft(9, '0') + ".img"; // 100000000.img.xml
string mapcat = "Map" + mapId_PaddingZeros.Substring(0, 1);

WzDirectory directory = Program.WzManager.FindMapWz(mapcat);
WzImage mapImage = (WzImage)directory[mapId_PaddingZeros];

if (mapImage == null)
{
MessageBox.Show("Map is null.");
return;
}

WzSubProperty strMapProp = WzInfoTools.GetMapStringProp(mapId_str);
string cloneMapName = WzInfoTools.GetMapName(strMapProp);
string cloneStreetName = WzInfoTools.GetMapStreetName(strMapProp);
string cloneCategoryName = WzInfoTools.GetMapCategoryName(strMapProp);

MapLoader.CreateMapFromImage(-1 /*mapid*/, mapImage.DeepClone(), cloneMapName, cloneStreetName, cloneCategoryName, (WzSubProperty) strMapProp.DeepClone(), Tabs, multiBoard, rightClickHandler);

Close();
}
#endregion

#region Misc
private void New_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
Expand All @@ -53,11 +132,6 @@ private void New_KeyDown(object sender, KeyEventArgs e)
newButton_Click(null, null);
}
}

private void New_Load(object sender, EventArgs e)
{
newWidth.Text = ApplicationSettings.LastMapSize.Width.ToString();
newHeight.Text = ApplicationSettings.LastMapSize.Height.ToString();
}
#endregion
}
}

1 comment on commit 81a6e6c

@lastbattle
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Please sign in to comment.