From b4f1bda2c733a27f2bff54ab693665f858f17d77 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 21 Apr 2020 12:43:16 -0700 Subject: [PATCH] Extract translatable strings to static class --- .../Structures/Villager/IVillagerOrigin.cs | 2 + NHSE.WinForms/Controls/VillagerEditor.cs | 17 ++++----- NHSE.WinForms/Editor.cs | 24 ++++++------ NHSE.WinForms/Main.cs | 7 ++-- NHSE.WinForms/Subforms/Map/AcreEditor.cs | 7 ++-- NHSE.WinForms/Subforms/Map/BuildingEditor.cs | 2 +- NHSE.WinForms/Subforms/Map/FieldItemEditor.cs | 12 +++--- NHSE.WinForms/Subforms/Map/TerrainEditor.cs | 10 ++--- .../Subforms/SysBot/SysBotController.cs | 9 ++--- .../Subforms/SysBot/SysBotRAMEdit.cs | 2 +- NHSE.WinForms/Subforms/SysBot/SysBotUI.cs | 4 +- NHSE.WinForms/Util/MessageStrings.cs | 38 ++++++++++++++++++- 12 files changed, 81 insertions(+), 53 deletions(-) diff --git a/NHSE.Core/Structures/Villager/IVillagerOrigin.cs b/NHSE.Core/Structures/Villager/IVillagerOrigin.cs index 03ef3eb..1d462aa 100644 --- a/NHSE.Core/Structures/Villager/IVillagerOrigin.cs +++ b/NHSE.Core/Structures/Villager/IVillagerOrigin.cs @@ -4,6 +4,8 @@ namespace NHSE.Core { public interface IVillagerOrigin { + string PlayerName { get; } + string TownName { get; } byte[] GetTownIdentity(); byte[] GetPlayerIdentity(); } diff --git a/NHSE.WinForms/Controls/VillagerEditor.cs b/NHSE.WinForms/Controls/VillagerEditor.cs index 3ca0a71..a710409 100644 --- a/NHSE.WinForms/Controls/VillagerEditor.cs +++ b/NHSE.WinForms/Controls/VillagerEditor.cs @@ -83,9 +83,7 @@ private void CHK_VillagerMovingOut_CheckedChanged(object sender, EventArgs e) if (!CHK_VillagerMovingOut.Checked) return; - const string question = "Are you trying to make the Villager move out?"; - const string reply = "If so, set the Event Flag (024 - ForceMoveOut) to 1 so that the Villager is removed by the game."; - WinFormsUtil.Alert(question, reply); + WinFormsUtil.Alert(MessageStrings.MsgMoveOut, MessageStrings.MsgMoveOutSuggest); } private void B_DumpVillager_Click(object sender, EventArgs e) @@ -128,14 +126,13 @@ private void B_LoadVillager_Click(object sender, EventArgs e) if (ofd.ShowDialog() != DialogResult.OK) return; - var file = ofd.FileName; + var path = ofd.FileName; var original = Villagers[VillagerIndex]; var expectLength = original.Data.Length; - var fi = new FileInfo(file); + var fi = new FileInfo(path); if (fi.Length != expectLength) { - var msg = $"Imported villager's data length (0x{fi.Length:X}) does not match the required length (0x{expectLength:X})."; - WinFormsUtil.Error("Cancelling:", msg); + WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path); return; } @@ -144,8 +141,8 @@ private void B_LoadVillager_Click(object sender, EventArgs e) var player0 = Origin; if (!v.IsOriginatedFrom(player0)) { - const string msg = "Imported Villager did not originate from Resident Rep's data."; - var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, msg, "Update values?"); + string msg = string.Format(MessageStrings.MsgDataDidNotOriginateFromHost_0, player0.PlayerName); + var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, msg, MessageStrings.MsgAskUpdateValues); if (result == DialogResult.Cancel) return; if (result == DialogResult.Yes) @@ -229,7 +226,7 @@ private void B_LoadHouse_Click(object sender, EventArgs e) if (fi.Length != expectLength) { var msg = $"Imported villager house's data length (0x{fi.Length:X}) does not match the required length (0x{expectLength:X})."; - WinFormsUtil.Error("Cancelling:", msg); + WinFormsUtil.Error(MessageStrings.MsgCanceling, msg); return; } diff --git a/NHSE.WinForms/Editor.cs b/NHSE.WinForms/Editor.cs index 6682275..7f13460 100644 --- a/NHSE.WinForms/Editor.cs +++ b/NHSE.WinForms/Editor.cs @@ -45,10 +45,10 @@ private void Menu_Save_Click(object sender, EventArgs e) catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { - WinFormsUtil.Error("Unable to save files to their original location.", ex.Message); + WinFormsUtil.Error(MessageStrings.MsgSaveDataExportFail, ex.Message); return; } - WinFormsUtil.Alert("Saved all save data!"); + WinFormsUtil.Alert(MessageStrings.MsgSaveDataExportSuccess); } private void Menu_DumpDecrypted_Click(object sender, EventArgs e) @@ -78,7 +78,7 @@ private void LoadDecryptedFromPath(string main) var dir = Path.GetDirectoryName(main); if (dir is null || !Directory.Exists(dir)) { - WinFormsUtil.Alert("Directory does not exist!"); + WinFormsUtil.Alert(MessageStrings.MsgImportDirectoryDoesNotExist); return; } @@ -92,11 +92,11 @@ private void Menu_VerifyHashes_Click(object sender, EventArgs e) var result = SAV.GetInvalidHashes().ToArray(); if (result.Length == 0) { - WinFormsUtil.Alert("Hashes are valid."); + WinFormsUtil.Alert(MessageStrings.MsgSaveDataHashesValid); return; } - if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Export results to clipboard?") != DialogResult.Yes) + if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MessageStrings.MsgAskExportResultToClipboard) != DialogResult.Yes) return; var lines = result.Select(z => z.ToString()); @@ -318,7 +318,7 @@ private void Menu_SavePNG_Click(object sender, EventArgs e) var pb = WinFormsUtil.GetUnderlyingControl(sender); if (pb?.Image == null) { - WinFormsUtil.Alert("No picture loaded."); + WinFormsUtil.Alert(MessageStrings.MsgNoPictureLoaded); return; } @@ -386,8 +386,8 @@ private void B_LoadDesign_Click(object sender, EventArgs e) var fi = new FileInfo(file); if (fi.Length != expectLength) { - var msg = $"Imported Design Pattern's data length (0x{fi.Length:X}) does not match the required length (0x{expectLength:X})."; - WinFormsUtil.Error("Cancelling:", msg); + var msg = string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength); + WinFormsUtil.Error(MessageStrings.MsgCanceling, msg); return; } @@ -396,8 +396,8 @@ private void B_LoadDesign_Click(object sender, EventArgs e) var player0 = SAV.Players[0].Personal; if (!d.IsOriginatedFrom(player0)) { - var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, - $"Imported Design Pattern did not originate from Villager0 ({player0.PlayerName})'s data.", "Update values?"); + var notHost = string.Format(MessageStrings.MsgDataDidNotOriginateFromHost_0, player0.PlayerName); + var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, notHost, MessageStrings.MsgAskUpdateValues); if (result == DialogResult.Cancel) return; if (result == DialogResult.Yes) @@ -492,8 +492,8 @@ private void B_LoadHouse_Click(object sender, EventArgs e) const int expectLength = PlayerHouse.SIZE; if (fi.Length != expectLength) { - var msg = $"Imported player house's data length (0x{fi.Length:X}) does not match the required length (0x{expectLength:X})."; - WinFormsUtil.Error("Cancelling:", msg); + var msg = string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength); + WinFormsUtil.Error(MessageStrings.MsgCanceling, msg); return; } diff --git a/NHSE.WinForms/Main.cs b/NHSE.WinForms/Main.cs index ba002a9..0c9262e 100644 --- a/NHSE.WinForms/Main.cs +++ b/NHSE.WinForms/Main.cs @@ -36,8 +36,8 @@ private static void Open(HorizonSave file) bool sized = file.ValidateSizes(); if (!sized) { - const string sizeBad = "Save file sizes appear to be incorrect."; - if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, sizeBad, "Continue?") != DialogResult.Yes) + var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MessageStrings.MsgSaveDataSizeMismatch, MessageStrings.MsgAskContinue); + if (prompt != DialogResult.Yes) return; } @@ -116,8 +116,7 @@ private static void OpenFileOrPath(string path) var dir = Path.GetDirectoryName(path); if (dir is null || !Directory.Exists(dir)) // ya never know { - WinFormsUtil.Error("Unable to open the folder that contains the save file.", - "Try moving it to another location and opening from there."); + WinFormsUtil.Error(MessageStrings.MsgSaveDataImportFail, MessageStrings.MsgSaveDataImportSuggest); return; } diff --git a/NHSE.WinForms/Subforms/Map/AcreEditor.cs b/NHSE.WinForms/Subforms/Map/AcreEditor.cs index a3d0439..d8eb431 100644 --- a/NHSE.WinForms/Subforms/Map/AcreEditor.cs +++ b/NHSE.WinForms/Subforms/Map/AcreEditor.cs @@ -102,13 +102,12 @@ private void B_Import_Click(object sender, EventArgs e) if (ofd.ShowDialog() != DialogResult.OK) return; + var path = ofd.FileName; var original = SAV.GetAcreBytes(); - var modified = File.ReadAllBytes(ofd.FileName); + var modified = File.ReadAllBytes(path); if (original.Length != modified.Length) { - WinFormsUtil.Error( - $"Imported size (0x{modified.Length}) does not match expected size (0x{original.Length:X}).", - "Aborting the import operation."); + WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, modified.Length, original.Length), path); return; } SAV.SetAcreBytes(modified); diff --git a/NHSE.WinForms/Subforms/Map/BuildingEditor.cs b/NHSE.WinForms/Subforms/Map/BuildingEditor.cs index 4c99910..6d711b4 100644 --- a/NHSE.WinForms/Subforms/Map/BuildingEditor.cs +++ b/NHSE.WinForms/Subforms/Map/BuildingEditor.cs @@ -153,7 +153,7 @@ private void B_ImportAll_Click(object sender, EventArgs e) const int oldSize = Building.SIZE * 40; if (fi.Length != expect && fi.Length != oldSize) { - WinFormsUtil.Error($"Expected size (0x{expect:X}) != Input size (0x{fi.Length:X})", path); + WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect)); return; } diff --git a/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs b/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs index 5c75e66..92927b0 100644 --- a/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs +++ b/NHSE.WinForms/Subforms/Map/FieldItemEditor.cs @@ -271,7 +271,7 @@ private void B_ImportAcre_Click(object sender, EventArgs e) int expect = layer.AcreTileCount * FieldItem.SIZE; if (fi.Length != expect) { - WinFormsUtil.Error($"Expected size (0x{expect:X}) != Input size (0x{fi.Length:X})", path); + WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect)); return; } @@ -298,7 +298,7 @@ private void B_ImportAllAcres_Click(object sender, EventArgs e) int expect = layer.MapTileCount * FieldItem.SIZE; if (fi.Length != expect) { - WinFormsUtil.Error($"Expected size (0x{expect:X}) != Input size (0x{fi.Length:X})", path); + WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect)); return; } @@ -313,7 +313,7 @@ private void Menu_SavePNG_Click(object sender, EventArgs e) var pb = WinFormsUtil.GetUnderlyingControl(sender); if (pb?.Image == null) { - WinFormsUtil.Alert("No picture loaded."); + WinFormsUtil.Alert(MessageStrings.MsgNoPictureLoaded); return; } @@ -403,7 +403,7 @@ private void Remove(Control sender, Func removal) { bool wholeMap = ModifierKeys == Keys.Shift; - string q = $"Are you sure you want to remove {sender.Text}?"; + string q = string.Format(MessageStrings.MsgFieldItemRemoveAsk, sender.Text); var question = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, q); if (question != DialogResult.Yes) return; @@ -414,11 +414,11 @@ private void Remove(Control sender, Func removal) if (count == 0) { - WinFormsUtil.Alert("Nothing removed (none found)."); + WinFormsUtil.Alert(MessageStrings.MsgFieldItemRemoveNone); return; } LoadGrid(X, Y); - WinFormsUtil.Alert($"Removed {count} from the map."); + WinFormsUtil.Alert(string.Format(MessageStrings.MsgFieldItemRemoveCount, count)); } private void B_RemoveAllWeeds_Click(object sender, EventArgs e) => Remove(B_RemoveAllWeeds, Layer.RemoveAllWeeds); diff --git a/NHSE.WinForms/Subforms/Map/TerrainEditor.cs b/NHSE.WinForms/Subforms/Map/TerrainEditor.cs index 5dd6c80..8c9f34c 100644 --- a/NHSE.WinForms/Subforms/Map/TerrainEditor.cs +++ b/NHSE.WinForms/Subforms/Map/TerrainEditor.cs @@ -203,7 +203,7 @@ private static void RefreshTile(Control button, TerrainTile tile) private void B_ZeroElevation_Click(object sender, EventArgs e) { - if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Set the elevation of all tiles on the map to 0?")) + if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MessageStrings.MsgTerrainSetElevation0)) return; foreach (var t in Terrain.Tiles) t.Elevation = 0; @@ -213,7 +213,7 @@ private void B_ZeroElevation_Click(object sender, EventArgs e) private void B_SetAll_Click(object sender, EventArgs e) { - if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Set the tile from the Tile Editor to all tiles on the map?")) + if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MessageStrings.MsgTerrainSetAll)) return; var pgt = (TerrainTile)PG_Tile.SelectedObject; foreach (var t in Terrain.Tiles) @@ -269,7 +269,7 @@ private void B_ImportAcre_Click(object sender, EventArgs e) int expect = Terrain.AcreTileCount * TerrainTile.SIZE; if (fi.Length != expect) { - WinFormsUtil.Error($"Expected size (0x{expect:X}) != Input size (0x{fi.Length:X})", path); + WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect)); return; } @@ -295,7 +295,7 @@ private void B_ImportAllAcres_Click(object sender, EventArgs e) int expect = Terrain.MapTileCount * TerrainTile.SIZE; if (fi.Length != expect) { - WinFormsUtil.Error($"Expected size (0x{expect:X}) != Input size (0x{fi.Length:X})", path); + WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect)); return; } @@ -310,7 +310,7 @@ private void Menu_SavePNG_Click(object sender, EventArgs e) var pb = WinFormsUtil.GetUnderlyingControl(sender); if (pb?.Image == null) { - WinFormsUtil.Alert("No picture loaded."); + WinFormsUtil.Alert(MessageStrings.MsgNoPictureLoaded); return; } diff --git a/NHSE.WinForms/Subforms/SysBot/SysBotController.cs b/NHSE.WinForms/Subforms/SysBot/SysBotController.cs index f437bb1..7c08b62 100644 --- a/NHSE.WinForms/Subforms/SysBot/SysBotController.cs +++ b/NHSE.WinForms/Subforms/SysBot/SysBotController.cs @@ -75,8 +75,8 @@ public void HexEdit(uint offset, int length) if (read.Length != write.Length) { var prompt = WinFormsUtil.Prompt(MessageBoxButtons.OKCancel, - $"Read size (0x{read.Length:X}) != Write Size (0x{write.Length})", - "Write anyway?"); + string.Format(MessageStrings.MsgDataSizeMismatchRAM, read.Length, write.Length), + MessageStrings.MsgAskWriteAnyway); if (prompt != DialogResult.OK) return; @@ -92,10 +92,7 @@ public void PopPrompt() if (Settings.SysBotPrompted) return; - const string info = "This SysBot reads and writes RAM directly to your game when called to Read/Write."; - const string reqd = "Using this functionality requires the sys-botbase sysmodule running on the console." + - "Your console must be on the same network as the PC running this program."; - WinFormsUtil.Alert(info, reqd); + WinFormsUtil.Alert(MessageStrings.MsgSysBotInfo, MessageStrings.MsgSysBotRequired); Settings.SysBotPrompted = true; Settings.Save(); } diff --git a/NHSE.WinForms/Subforms/SysBot/SysBotRAMEdit.cs b/NHSE.WinForms/Subforms/SysBot/SysBotRAMEdit.cs index 99de86a..2d0ade2 100644 --- a/NHSE.WinForms/Subforms/SysBot/SysBotRAMEdit.cs +++ b/NHSE.WinForms/Subforms/SysBot/SysBotRAMEdit.cs @@ -32,7 +32,7 @@ private void B_Edit_Click(object sender, EventArgs e) var offset = StringUtil.GetHexValue(RamOffset.Text); if (offset == 0) { - WinFormsUtil.Error("Incorrect hex offset."); + WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue); return; } diff --git a/NHSE.WinForms/Subforms/SysBot/SysBotUI.cs b/NHSE.WinForms/Subforms/SysBot/SysBotUI.cs index 7def676..f66bcdf 100644 --- a/NHSE.WinForms/Subforms/SysBot/SysBotUI.cs +++ b/NHSE.WinForms/Subforms/SysBot/SysBotUI.cs @@ -40,7 +40,7 @@ private void B_WriteCurrent_Click(object sender, EventArgs e) var offset = StringUtil.GetHexValue(RamOffset.Text); if (offset == 0) { - WinFormsUtil.Error("Incorrect hex offset."); + WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue); return; } @@ -85,7 +85,7 @@ private void RamOffset_TextChanged(object sender, EventArgs e) var offset = StringUtil.GetHexValue(RamOffset.Text); if (offset == 0) { - WinFormsUtil.Error("Incorrect hex offset."); + WinFormsUtil.Error(MessageStrings.MsgInvalidHexValue); return; } diff --git a/NHSE.WinForms/Util/MessageStrings.cs b/NHSE.WinForms/Util/MessageStrings.cs index dc5d5a9..458f05c 100644 --- a/NHSE.WinForms/Util/MessageStrings.cs +++ b/NHSE.WinForms/Util/MessageStrings.cs @@ -1,8 +1,42 @@ -namespace NHSE.WinForms +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global +namespace NHSE.WinForms { public static class MessageStrings { - public static string MsgBackupCreateLocation { get; set; } = "NHSE can perform automatic backups if you create a folder with the name '{0}' in the same folder as NHSE's executable."; + public static string MsgBackupCreateLocation { get; set; } = "NHSE can perform automatic backups if you create a folder with the name '{0}' in the same folder as the executable."; public static string MsgBackupCreateQuestion { get; set; } = "Would you NHSE to automatically keep a backup of your save data?"; + + public static string MsgDataSizeMismatchImport { get; set; } = "The size of the imported file (0x{0:X}) does not match the required size (0x{1:X})."; + public static string MsgDataSizeMismatchRAM { get; set; } = "Read size (0x{0:X}) != Write size (0x{1:X})."; + public static string MsgDataDidNotOriginateFromHost_0 { get; set; } = "Imported data did not originate from Villager0 ({0})'s data."; + + public static string MsgAskUpdateValues { get; set; } = "Update values?"; + public static string MsgAskContinue { get; set; } = "Continue?"; + public static string MsgAskWriteAnyway { get; set; } = "Write anyway?"; + public static string MsgAskExportResultToClipboard { get; set; } = "Export results to clipboard?"; + public static string MsgCanceling { get; set; } = "Canceling:"; + public static string MsgInvalidHexValue { get; set; } = "Bad hex value."; + public static string MsgImportDirectoryDoesNotExist { get; set; } = "Directory does not exist!"; + public static string MsgNoPictureLoaded { get; set; } = "No picture loaded."; + + public static string MsgSaveDataImportFail { get; set; } = "Unable to open the folder that contains the save file."; + public static string MsgSaveDataImportSuggest { get; set; } = "Try moving it to another location and opening from there."; + public static string MsgSaveDataExportSuccess { get; set; } = "Saved all save data!"; + public static string MsgSaveDataExportFail { get; set; } = "Unable to save files to their original location."; + public static string MsgSaveDataHashesValid { get; set; } = "Hashes are valid."; + public static string MsgSaveDataSizeMismatch { get; set; } = "Save file sizes appear to be incorrect."; + + public static string MsgMoveOut { get; set; } = "Are you trying to make the Villager move out?"; + public static string MsgMoveOutSuggest { get; set; } = "If so, set the Event Flag (024 - ForceMoveOut) to 1 so that the Villager is removed by the game."; + + public static string MsgFieldItemRemoveAsk { get; set; } = "Are you sure you want to remove {0}?"; + public static string MsgFieldItemRemoveNone { get; set; } = "Nothing removed (none found)."; + public static string MsgFieldItemRemoveCount { get; set; } = "Removed {0} from the map."; + + public static string MsgSysBotInfo { get; set; } = "This SysBot reads and writes RAM directly to your game when called to Read/Write."; + public static string MsgSysBotRequired { get; set; } = "Using this functionality requires the sys-botbase sysmodule running on the console. Your console must be on the same network as the PC running this program."; + + public static string MsgTerrainSetElevation0 { get; set; } = "Set the elevation of all tiles on the map to 0?"; + public static string MsgTerrainSetAll { get; set; } = "Set the tile from the Tile Editor to all tiles on the map?"; } }