Skip to content

Commit

Permalink
[HaCreator] QOL - while creating a new map from cloned maps, it will …
Browse files Browse the repository at this point in the history
…not use the 'mapid' of the clone source + allows the user to select mapid from a list to save to

stage 1
#214
  • Loading branch information
lastbattle committed Sep 5, 2023
1 parent cf57813 commit 66142f6
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 65 deletions.
1 change: 1 addition & 0 deletions HaCreator/GUI/Initialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ private void debugButton_Click(object sender, EventArgs e)
new Microsoft.Xna.Framework.Point(),
new Microsoft.Xna.Framework.Point(),
mb,
false,
null,
MapleLib.WzLib.WzStructure.Data.ItemTypes.None,
MapleLib.WzLib.WzStructure.Data.ItemTypes.None);
Expand Down
41 changes: 37 additions & 4 deletions HaCreator/GUI/InstanceEditor/LoadMapSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,65 @@ public partial class LoadMapSelector : System.Windows.Forms.Form
/// <summary>
/// The NumericUpDown text to set upon selection
/// </summary>
private NumericUpDown numericUpDown;
private NumericUpDown numericUpDown = null;

/// <summary>
/// Or the textbox
/// </summary>
private TextBox textBox = null;

/// <summary>
/// Load map selector
/// </summary>
/// <param name="numericUpDown"></param>
public LoadMapSelector(NumericUpDown numericUpDown)
{
InitializeComponent();

DialogResult = DialogResult.Cancel;

this.numericUpDown = numericUpDown;
this.searchBox.TextChanged += this.mapBrowser.searchBox_TextChanged;
}

/// <summary>
/// Load map selector
/// </summary>
/// <param name="textbox"></param>
public LoadMapSelector(TextBox textbox) {
InitializeComponent();

DialogResult = DialogResult.Cancel;

this.textBox = textbox;
this.searchBox.TextChanged += this.mapBrowser.searchBox_TextChanged;
}

/// <summary>
/// On load
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Load_Load(object sender, EventArgs e)
{
this.mapBrowser.InitializeMaps(false); // load list of maps without Cash Shop, Login, etc
}

/// <summary>
/// On load button clicked, selects that map and closes this dialog.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void loadButton_Click(object sender, EventArgs e)
{
string mapid = mapBrowser.SelectedItem.Substring(0, 9);
string mapcat = "Map" + mapid.Substring(0, 1);


this.numericUpDown.Value = long.Parse(mapid);

if (numericUpDown != null) {
this.numericUpDown.Value = long.Parse(mapid);
} else {
this.textBox.Text = mapid;
}
DialogResult = DialogResult.OK;
Close();
}
Expand Down
5 changes: 5 additions & 0 deletions HaCreator/GUI/New.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ private void New_Load(object sender, EventArgs e)
}

#region Create new
/// <summary>
/// Creates a new default map to work from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void newButton_Click(object sender, EventArgs e)
{
int w = int.Parse(newWidth.Text);
Expand Down
48 changes: 30 additions & 18 deletions HaCreator/GUI/Save.Designer.cs

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

86 changes: 63 additions & 23 deletions HaCreator/GUI/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* 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 HaSharedLibrary.Wz;
Expand All @@ -24,39 +25,54 @@ public partial class Save : Form
{
private readonly Board board;

/// <summary>
/// Save UI window for saving a map
/// </summary>
/// <param name="board"></param>
/// <exception cref="NotSupportedException"></exception>
public Save(Board board)
{
this.board = board;
InitializeComponent();
switch (board.MapInfo.mapType)
{
case MapType.CashShopPreview:
case MapType.MapLogin:
idBox.Text = board.MapInfo.strMapName;
break;
case MapType.RegularMap:
idBox.Text = board.MapInfo.id == -1 ? "" : board.MapInfo.id.ToString();
break;
default:
throw new NotSupportedException("Unknown map type at Save::.ctor()");

if (board.IsNewMapDesign) {
idBox_mapId.Text = MapConstants.MaxMap.ToString();
}
else {
switch (board.MapInfo.mapType) {
case MapType.CashShopPreview:
case MapType.MapLogin:
idBox_mapId.Text = board.MapInfo.strMapName;
break;
case MapType.RegularMap:
idBox_mapId.Text = board.MapInfo.id == -1 ? "-1" : board.MapInfo.id.ToString();
break;
default:
throw new NotSupportedException("Unknown map type at Save::.ctor()");
}
}
idBox_TextChanged(null, null);
}

private MapType GetIdBoxMapType()
{
if (idBox.Text.StartsWith("MapLogin"))
if (idBox_mapId.Text.StartsWith("MapLogin"))
return MapType.MapLogin;
else if (idBox.Text == "CashShopPreview")
else if (idBox_mapId.Text == "CashShopPreview")
return MapType.CashShopPreview;
else
return MapType.RegularMap;
}

/// <summary>
/// On map id textbox change
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void idBox_TextChanged(object sender, EventArgs e)
{
int id = 0;
if (idBox.Text == "")
if (idBox_mapId.Text == string.Empty)
{
statusLabel.Text = "Please choose an ID";
saveButton.Enabled = false;
Expand All @@ -66,20 +82,24 @@ private void idBox_TextChanged(object sender, EventArgs e)
statusLabel.Text = "";
saveButton.Enabled = true;
}
else if (!int.TryParse(idBox.Text, out id))
else if (!int.TryParse(idBox_mapId.Text, out id) || id == MapConstants.MaxMap)
{
statusLabel.Text = "Must enter a number";
statusLabel.Text = "You must enter a number.";
saveButton.Enabled = false;
}
else if (id < MapConstants.MinMap || id > MapConstants.MaxMap)
{
statusLabel.Text = "Out of range";
statusLabel.Text = "Out of range. Select between "+ MapConstants.MinMap + " and "+ MapConstants.MaxMap + ".";
saveButton.Enabled = false;
}
else if (WzInfoTools.GetMapStringProp(id.ToString(), Program.WzManager) != null)
{
statusLabel.Text = "WARNING: Will overwrite existing map";
saveButton.Enabled = true;
else if (WzInfoTools.GetMapStringProp(id.ToString(), Program.WzManager) != null) {
if (board.IsNewMapDesign) { // if its a new design, do not allow overriding regardless
statusLabel.Text = "WARNING: It will overwrite existing map, select an empty ID.";
saveButton.Enabled = false;
} else {
statusLabel.Text = "WARNING: It will overwrite existing map.";
saveButton.Enabled = true;
}
}
else
{
Expand All @@ -88,6 +108,11 @@ private void idBox_TextChanged(object sender, EventArgs e)
}
}

/// <summary>
/// Click save button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void saveButton_Click(object sender, EventArgs e)
{
if (board.ParentControl.UserObjects.NewObjects.Count > 0)
Expand All @@ -105,7 +130,7 @@ private void saveButton_Click(object sender, EventArgs e)

if (type == MapType.RegularMap)
{
int newId = int.Parse(idBox.Text);
int newId = int.Parse(idBox_mapId.Text);
saver.ChangeMapTypeAndID(newId, MapType.RegularMap);
saver.SaveMapImage();
saver.UpdateMapLists();
Expand All @@ -114,7 +139,7 @@ private void saveButton_Click(object sender, EventArgs e)
}
else
{
board.MapInfo.strMapName = idBox.Text;
board.MapInfo.strMapName = idBox_mapId.Text;
((TabItemContainer)board.TabPage.Tag).Text = board.MapInfo.strMapName;
saver.ChangeMapTypeAndID(-1, type);
saver.SaveMapImage();
Expand All @@ -124,6 +149,11 @@ private void saveButton_Click(object sender, EventArgs e)
Close();
}

/// <summary>
/// On key down
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Save_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
Expand All @@ -135,5 +165,15 @@ private void Save_KeyDown(object sender, KeyEventArgs e)
saveButton_Click(null, null);
}
}

/// <summary>
/// Select a map from the list
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_select_Click(object sender, EventArgs e) {
LoadMapSelector selector = new LoadMapSelector(idBox_mapId);
selector.ShowDialog();
}
}
}
Loading

1 comment on commit 66142f6

@lastbattle
Copy link
Owner Author

@lastbattle lastbattle commented on 66142f6 Sep 5, 2023

Choose a reason for hiding this comment

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

image

image

Please sign in to comment.