Change pattern system (#504)

To make dumping/loading designs match other dumping/loading buttons (terrain, acre and so on)
+ clicking on "Dump/Load Design" will draw a context menu with 4 options (2 if it's only one design pattern e.g. town flag).
+ when loading designs, I made the Listbox with the design names repopulate (update names) and select the user-selected design instead of going to index = 0;
+ when loading all designs I open a prompt to update "values" or not, instead of by default updating them.
+ fixed file name of dumped singular pro designs to .nhpd instead of .nhd lol
This commit is contained in:
Emil B
2021-09-06 19:31:11 +02:00
committed by GitHub
parent ca3e12b35a
commit 083eae90f2
5 changed files with 170 additions and 55 deletions

View File

@@ -26,6 +26,15 @@ public PatternEditorPRO(DesignPatternPRO[] patterns)
LB_Items.Items.Add(GetPatternSummary(p));
LB_Items.SelectedIndex = 0;
SetCM_DLDesign();
}
private void SetCM_DLDesign()
{
var arr = LB_Items.Items.Count == 0
? new ToolStripItem[] { B_DumpDesign, B_LoadDesign }
: new ToolStripItem[] { B_DumpDesign, B_DumpDesignAll, B_LoadDesign, B_LoadDesignAll };
CM_DLDesign.Items.AddRange(arr);
}
private void B_Cancel_Click(object sender, EventArgs e) => Close();
@@ -44,10 +53,11 @@ private void LB_Items_SelectedIndexChanged(object sender, EventArgs e)
}
private static string GetPatternSummary(DesignPatternPRO p) => p.DesignName;
private static void ShowContextMenuBelow(ToolStripDropDown c, Control n) => c.Show(n.PointToScreen(new Point(0, n.Height)));
private void B_DumpLoadDesign_Click(object sender, EventArgs e) => ShowContextMenuBelow(CM_DLDesign, B_DumpLoadDesign);
private void B_DumpDesign_Click(object sender, EventArgs e)
{
if (ModifierKeys == Keys.Shift)
if (sender == B_DumpDesignAll)
{
using var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() != DialogResult.OK)
@@ -65,7 +75,7 @@ private void B_DumpDesign_Click(object sender, EventArgs e)
using var sfd = new SaveFileDialog
{
Filter = "New Horizons PRO Design (*.nhpd)|*.nhpd|All files (*.*)|*.*",
FileName = $"{name}.nhd",
FileName = $"{name}.nhpd",
};
if (sfd.ShowDialog() != DialogResult.OK)
return;
@@ -76,7 +86,7 @@ private void B_DumpDesign_Click(object sender, EventArgs e)
private void B_LoadDesign_Click(object sender, EventArgs e)
{
if (ModifierKeys == Keys.Shift)
if (sender == B_LoadDesignAll)
{
using var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() != DialogResult.OK)
@@ -85,8 +95,10 @@ private void B_LoadDesign_Click(object sender, EventArgs e)
var dir = Path.GetDirectoryName(fbd.SelectedPath);
if (dir == null || !Directory.Exists(dir))
return;
Patterns.Load(fbd.SelectedPath);
LoadPattern(Patterns[0]);
var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, MessageStrings.MsgAskUpdateValues);
Patterns.Load(fbd.SelectedPath, result == DialogResult.Yes);
LoadPattern(Patterns[Index]);
RepopulateList(Index);
return;
}
@@ -95,7 +107,7 @@ private void B_LoadDesign_Click(object sender, EventArgs e)
using var ofd = new OpenFileDialog
{
Filter = "New Horizons PRO Design (*.nhpd)|*.nhpd|All files (*.*)|*.*",
FileName = $"{name}.nhd",
FileName = $"{name}.nhpd",
};
if (ofd.ShowDialog() != DialogResult.OK)
return;
@@ -125,6 +137,15 @@ private void B_LoadDesign_Click(object sender, EventArgs e)
Patterns[Index] = d;
LoadPattern(d);
RepopulateList(Index);
}
private void RepopulateList(int index)
{
LB_Items.Items.Clear();
foreach (var p in Patterns)
LB_Items.Items.Add(GetPatternSummary(p));
LB_Items.SelectedIndex = index;
}
private void LoadPattern(DesignPatternPRO dp)