diff --git a/AngelLoader/Common/GameSupport.cs b/AngelLoader/Common/GameSupport.cs index ac1fe0c94..4d48b727b 100644 --- a/AngelLoader/Common/GameSupport.cs +++ b/AngelLoader/Common/GameSupport.cs @@ -129,9 +129,9 @@ internal static string GetLocalizedDifficultyName(FanMission? fm, Difficulty dif #region Get game name from game type - internal static string GetGameNameFromGameType(GameIndex gameIndex) => GetGameNameFromGameType(GameIndexToGame(gameIndex)); + internal static string GetLocalizedGameName(GameIndex gameIndex) => GetLocalizedGameName(GameIndexToGame(gameIndex)); - internal static string GetGameNameFromGameType(Game game) => game switch + internal static string GetLocalizedGameName(Game game) => game switch { Game.Thief1 => LText.Global.Thief1, Game.Thief2 => LText.Global.Thief2, @@ -140,9 +140,9 @@ internal static string GetLocalizedDifficultyName(FanMission? fm, Difficulty dif _ => "[UnknownGameType]" }; - internal static string GetShortGameNameFromGameType(GameIndex gameIndex) => GetShortGameNameFromGameType(GameIndexToGame(gameIndex)); + internal static string GetShortLocalizedGameName(GameIndex gameIndex) => GetShortLocalizedGameName(GameIndexToGame(gameIndex)); - internal static string GetShortGameNameFromGameType(Game game) => game switch + internal static string GetShortLocalizedGameName(Game game) => game switch { Game.Thief1 => LText.Global.Thief1_Short, Game.Thief2 => LText.Global.Thief2_Short, diff --git a/AngelLoader/Common/Misc.cs b/AngelLoader/Common/Misc.cs index 6b48f2b4e..19fbf2beb 100644 --- a/AngelLoader/Common/Misc.cs +++ b/AngelLoader/Common/Misc.cs @@ -97,14 +97,6 @@ internal static class ByteSize internal const int GB = MB * 1024; } - [PublicAPI] - internal enum Selector - { - FMSel, - NewDarkLoader, - AngelLoader - } - // Public for param accessibility reasons or whatever public enum ProgressTasks { @@ -145,7 +137,7 @@ public enum Direction { Left, Right, Up, Down } internal static readonly string[] FMSupportedLanguages = { - "english", // en, must be first + "english", // en, eng (must be first) "czech", // cz "dutch", // nl "french", // fr diff --git a/AngelLoader/FMAudio.cs b/AngelLoader/FMAudio.cs index a5ef1cee9..1d3d7ea34 100644 --- a/AngelLoader/FMAudio.cs +++ b/AngelLoader/FMAudio.cs @@ -203,7 +203,7 @@ private static (bool Success, bool RefreshSelectedFM) if (!fm.Installed || !GameIsDark(fm.Game)) return (false, false); string gameExe = Config.GetGameExeUnsafe(fm.Game); - string gameName = GetGameNameFromGameType(fm.Game); + string gameName = GetLocalizedGameName(fm.Game); if (GameIsRunning(gameExe)) { Core.View.ShowAlert( diff --git a/AngelLoader/FMInstallAndPlay.cs b/AngelLoader/FMInstallAndPlay.cs index 840061929..ac16b4106 100644 --- a/AngelLoader/FMInstallAndPlay.cs +++ b/AngelLoader/FMInstallAndPlay.cs @@ -612,7 +612,7 @@ private static (bool Success, string GameExe, string GamePath) { var failed = (Success: false, GameExe: "", GamePath: ""); - string gameName = GetGameNameFromGameType(gameIndex); + string gameName = GetLocalizedGameName(gameIndex); string gameExe = Config.GetGameExe(gameIndex); @@ -1233,7 +1233,7 @@ internal static async Task InstallFM(FanMission fm) AssertR(!fm.InstalledDir.IsEmpty(), "fm.InstalledFolderName is null or empty"); string gameExe = Config.GetGameExeUnsafe(fm.Game); - string gameName = GetGameNameFromGameType(fm.Game); + string gameName = GetLocalizedGameName(fm.Game); if (!File.Exists(gameExe)) { Core.View.ShowAlert(gameName + ":\r\n" + @@ -1488,7 +1488,7 @@ private static async Task UninstallFM(FanMission fm) } string gameExe = Config.GetGameExeUnsafe(fm.Game); - string gameName = GetGameNameFromGameType(fm.Game); + string gameName = GetLocalizedGameName(fm.Game); if (GameIsRunning(gameExe)) { Core.View.ShowAlert( diff --git a/AngelLoader/Forms/CustomControls/DataGridViewCustom/Menu_FM.cs b/AngelLoader/Forms/CustomControls/DataGridViewCustom/Menu_FM.cs index d3d409595..f12a20aa5 100644 --- a/AngelLoader/Forms/CustomControls/DataGridViewCustom/Menu_FM.cs +++ b/AngelLoader/Forms/CustomControls/DataGridViewCustom/Menu_FM.cs @@ -322,7 +322,7 @@ private void SetFMMenuTextToLocalized() // make sure those items' text is set correctly. FanMission? selFM = SelectedRows.Count > 0 ? GetSelectedFM() : null; bool sayInstall = selFM == null || !selFM.Installed; - // @GENGAMES + // @GENGAMES - Localize FM context menu - "sayShockEd" bool sayShockEd = selFM != null && selFM.Game == Game.SS2; #endregion diff --git a/AngelLoader/Forms/CustomControls/Static_LazyLoaded/PlayOriginalGameLLMenu.cs b/AngelLoader/Forms/CustomControls/Static_LazyLoaded/PlayOriginalGameLLMenu.cs index 6a91942f6..39b64b0b3 100644 --- a/AngelLoader/Forms/CustomControls/Static_LazyLoaded/PlayOriginalGameLLMenu.cs +++ b/AngelLoader/Forms/CustomControls/Static_LazyLoaded/PlayOriginalGameLLMenu.cs @@ -4,7 +4,7 @@ namespace AngelLoader.Forms.CustomControls.Static_LazyLoaded { - // @GENGAMES + // @GENGAMES - Play original game menu internal static class PlayOriginalGameLLMenu { private static bool _constructed; diff --git a/AngelLoader/Forms/Import/ImportFromMultipleInisForm.cs b/AngelLoader/Forms/Import/ImportFromMultipleInisForm.cs index 78729a6c8..4045d069b 100644 --- a/AngelLoader/Forms/Import/ImportFromMultipleInisForm.cs +++ b/AngelLoader/Forms/Import/ImportFromMultipleInisForm.cs @@ -2,6 +2,7 @@ using System.Windows.Forms; using AngelLoader.DataClasses; using AngelLoader.Importing; +using static AngelLoader.GameSupport; namespace AngelLoader.Forms.Import { @@ -58,14 +59,11 @@ private void ImportFromMultipleInisForm_FormClosing(object sender, FormClosingEv { if (DialogResult != DialogResult.OK) return; - // TODO: @GENGAMES: Put these into an array - IniFiles = new List + IniFiles = new List(SupportedGameCount); + for (int i = 0; i < SupportedGameCount; i++) { - ImportControls.Thief1IniFile.Trim(), - ImportControls.Thief2IniFile.Trim(), - ImportControls.Thief3IniFile.Trim(), - ImportControls.SS2IniFile.Trim() - }; + IniFiles.Add(ImportControls.GetIniFile((GameIndex)i)); + } ImportTitle = ImportTitleCheckBox.Checked; ImportReleaseDate = ImportReleaseDateCheckBox.Checked; diff --git a/AngelLoader/Forms/Import/User_FMSel_NDL_ImportControls.cs b/AngelLoader/Forms/Import/User_FMSel_NDL_ImportControls.cs index 3c674ea39..d7cc90388 100644 --- a/AngelLoader/Forms/Import/User_FMSel_NDL_ImportControls.cs +++ b/AngelLoader/Forms/Import/User_FMSel_NDL_ImportControls.cs @@ -1,5 +1,5 @@ using System; -using System.IO; +using System.Linq; using System.Windows.Forms; using AngelLoader.DataClasses; using AngelLoader.Importing; @@ -10,16 +10,45 @@ namespace AngelLoader.Forms.Import { public partial class User_FMSel_NDL_ImportControls : UserControl { - // @GENGAMES - internal string Thief1IniFile => Thief1IniTextBox.Text; - internal string Thief2IniFile => Thief2IniTextBox.Text; - internal string Thief3IniFile => Thief3IniTextBox.Text; - internal string SS2IniFile => SS2IniTextBox.Text; - private ImportType ImportType; - // Designer use - public User_FMSel_NDL_ImportControls() => InitializeComponent(); + private readonly (GroupBox GroupBox, CheckBox AutodetectCheckBox, TextBox TextBox, Button BrowseButton)[] + GameIniItems; + + internal string GetIniFile(GameIndex game) => GameIniItems[(int)game].TextBox.Text; + + public User_FMSel_NDL_ImportControls() + { + InitializeComponent(); + + GameIniItems = new[] + { + ( + Thief1GroupBox, + Thief1AutodetectCheckBox, + Thief1IniTextBox, + Thief1IniBrowseButton + ), + ( + Thief2GroupBox, + Thief2AutodetectCheckBox, + Thief2IniTextBox, + Thief2IniBrowseButton + ), + ( + Thief3GroupBox, + Thief3AutodetectCheckBox, + Thief3IniTextBox, + Thief3IniBrowseButton + ), + ( + SS2GroupBox, + SS2AutodetectCheckBox, + SS2IniTextBox, + SS2IniBrowseButton + ) + }; + } internal void Init(ImportType importType) { @@ -27,10 +56,10 @@ internal void Init(ImportType importType) Localize(); - AutodetectGameIni(GameIndex.Thief1, Thief1IniTextBox); - AutodetectGameIni(GameIndex.Thief2, Thief2IniTextBox); - AutodetectGameIni(GameIndex.Thief3, Thief3IniTextBox); - AutodetectGameIni(GameIndex.SS2, SS2IniTextBox); + for (int i = 0; i < SupportedGameCount; i++) + { + AutodetectGameIni((GameIndex)i, GameIniItems[i].TextBox); + } } private void Localize() @@ -39,20 +68,12 @@ private void Localize() ? LText.Importing.ChooseNewDarkLoaderIniFiles : LText.Importing.ChooseFMSelIniFiles; - Thief1GroupBox.Text = LText.Global.Thief1; - Thief2GroupBox.Text = LText.Global.Thief2; - Thief3GroupBox.Text = LText.Global.Thief3; - SS2GroupBox.Text = LText.Global.SystemShock2; - - Thief1AutodetectCheckBox.Text = LText.Global.Autodetect; - Thief2AutodetectCheckBox.Text = LText.Global.Autodetect; - Thief3AutodetectCheckBox.Text = LText.Global.Autodetect; - SS2AutodetectCheckBox.Text = LText.Global.Autodetect; - - Thief1IniBrowseButton.SetTextAutoSize(Thief1IniTextBox, LText.Global.BrowseEllipses); - Thief2IniBrowseButton.SetTextAutoSize(Thief2IniTextBox, LText.Global.BrowseEllipses); - Thief3IniBrowseButton.SetTextAutoSize(Thief3IniTextBox, LText.Global.BrowseEllipses); - SS2IniBrowseButton.SetTextAutoSize(SS2IniTextBox, LText.Global.BrowseEllipses); + for (int i = 0; i < SupportedGameCount; i++) + { + GameIniItems[i].GroupBox.Text = GetLocalizedGameName((GameIndex)i); + GameIniItems[i].AutodetectCheckBox.Text = LText.Global.Autodetect; + GameIniItems[i].BrowseButton.SetTextAutoSize(GameIniItems[i].TextBox, LText.Global.BrowseEllipses); + } } private void AutodetectGameIni(GameIndex game, TextBox textBox) @@ -60,59 +81,33 @@ private void AutodetectGameIni(GameIndex game, TextBox textBox) string iniFile = ImportType == ImportType.NewDarkLoader ? Paths.NewDarkLoaderIni : Paths.FMSelIni; string fmsPath = Config.GetFMInstallPath(game); - if (fmsPath.IsWhiteSpace()) - { - textBox.Text = ""; - } - else - { - textBox.Text = TryCombineFilePathAndCheckExistence(fmsPath, iniFile, out string iniFileFull) - ? iniFileFull - : ""; - } + textBox.Text = !fmsPath.IsWhiteSpace() && TryCombineFilePathAndCheckExistence(fmsPath, iniFile, out string iniFileFull) + ? iniFileFull + : ""; } private void ThiefIniBrowseButtons_Click(object sender, EventArgs e) { - var s = (Button)sender; - var tb = - s == Thief1IniBrowseButton ? Thief1IniTextBox : - s == Thief2IniBrowseButton ? Thief2IniTextBox : - s == Thief3IniBrowseButton ? Thief3IniTextBox : - SS2IniTextBox; - using var d = new OpenFileDialog { Filter = LText.BrowseDialogs.IniFiles + @"|*.ini|" + LText.BrowseDialogs.AllFiles + @"|*.*" }; if (d.ShowDialog() != DialogResult.OK) return; + var tb = GameIniItems.First(x => x.BrowseButton == sender).TextBox; tb.Text = d.FileName; } private void AutodetectCheckBoxes_CheckedChanged(object sender, EventArgs e) { var s = (CheckBox)sender; - var textBox = - s == Thief1AutodetectCheckBox ? Thief1IniTextBox : - s == Thief2AutodetectCheckBox ? Thief2IniTextBox : - s == Thief3AutodetectCheckBox ? Thief3IniTextBox : - SS2IniTextBox; - var button = - s == Thief1AutodetectCheckBox ? Thief1IniBrowseButton : - s == Thief2AutodetectCheckBox ? Thief2IniBrowseButton : - s == Thief3AutodetectCheckBox ? Thief3IniBrowseButton : - SS2IniBrowseButton; - var game = - s == Thief1AutodetectCheckBox ? GameIndex.Thief1 : - s == Thief2AutodetectCheckBox ? GameIndex.Thief2 : - s == Thief3AutodetectCheckBox ? GameIndex.Thief3 : - GameIndex.SS2; - - textBox.ReadOnly = s.Checked; - button.Enabled = !s.Checked; - - if (s.Checked) AutodetectGameIni(game, textBox); + + var gameIniItem = GameIniItems.First(x => x.AutodetectCheckBox == sender); + + gameIniItem.TextBox.ReadOnly = s.Checked; + gameIniItem.BrowseButton.Enabled = !s.Checked; + + if (s.Checked) AutodetectGameIni((GameIndex)Array.IndexOf(GameIniItems, gameIniItem), gameIniItem.TextBox); } } } diff --git a/AngelLoader/Forms/MainForm.cs b/AngelLoader/Forms/MainForm.cs index b7bf5965c..c1a254739 100644 --- a/AngelLoader/Forms/MainForm.cs +++ b/AngelLoader/Forms/MainForm.cs @@ -374,8 +374,8 @@ public void ChangeGameTabNameShortness(bool refreshFilterBarPositionIfNeeded) for (int i = 0; i < SupportedGameCount; i++) { GameTabsInOrder[i].Text = Config.UseShortGameTabNames - ? GetShortGameNameFromGameType((GameIndex)i) - : GetGameNameFromGameType((GameIndex)i); + ? GetShortLocalizedGameName((GameIndex)i) + : GetLocalizedGameName((GameIndex)i); } // Prevents the couple-pixel-high tab page from extending out too far and becoming visible @@ -765,7 +765,7 @@ public MainForm() #endif // -------- New games go here! - // @GENGAMES + // @GENGAMES - tabs and filter buttons GameTabsInOrder = new[] { Thief1TabPage, @@ -773,7 +773,6 @@ public MainForm() Thief3TabPage, SS2TabPage }; - FilterByGameButtonsInOrder = new[] { FilterByThief1Button, @@ -972,7 +971,7 @@ public async Task FinishInitAndShow() Core.SetFilter(); if (RefreshFMsList(FMsDGV.CurrentSelFM, startup: true, KeepSel.TrueNearest)) { - await DisplaySelectedFM(true); + await DisplaySelectedFM(refreshReadme: true); } FMsDGV.Focus(); @@ -1295,7 +1294,7 @@ private void Localize(bool startup) for (int i = 0; i < SupportedGameCount; i++) { - FilterByGameButtonsInOrder[i].ToolTipText = GetGameNameFromGameType((GameIndex)i); + FilterByGameButtonsInOrder[i].ToolTipText = GetLocalizedGameName((GameIndex)i); } FilterTitleLabel.Text = LText.FilterBar.Title; @@ -1887,7 +1886,7 @@ public async Task SortAndSetFilter(SelectedFM? selectedFM = null, bool forceDisp // Fix: when resetting release date filter the readme wouldn't load for the selected FM oldSelectedFM == null) { - await DisplaySelectedFM(true); + await DisplaySelectedFM(refreshReadme: true); } } } @@ -2120,7 +2119,7 @@ private async void FMsDGV_ColumnHeaderMouseClick(object sender, DataGridViewCell if (selFM != null && FMsDGV.RowSelected() && selFM.InstalledName != FMsDGV.GetSelectedFM().InstalledDir) { - await DisplaySelectedFM(true); + await DisplaySelectedFM(refreshReadme: true); } } } @@ -2256,7 +2255,7 @@ private void PlayOriginalGameButton_Click(object sender, EventArgs e) ShowMenu(PlayOriginalGameLLMenu.Menu, PlayOriginalGameButton, MenuPos.TopRight); } - // @GENGAMES + // @GENGAMES - Play original game menu Click handler internal void PlayOriginalGameMenuItem_Click(object sender, EventArgs e) { var item = (ToolStripMenuItem)sender; diff --git a/AngelLoader/Forms/SettingsForm.cs b/AngelLoader/Forms/SettingsForm.cs index d9a46274b..edf82e092 100644 --- a/AngelLoader/Forms/SettingsForm.cs +++ b/AngelLoader/Forms/SettingsForm.cs @@ -30,7 +30,7 @@ namespace AngelLoader.Forms -Page ctors - lazy-loading these would be a giant headache - not really worth it */ - // @GENGAMES: There's game stuff in here of course + // @GENGAMES - SettingsForm: lots of manual game stuff in here. Good candidate for a massive gengames cleanup. internal sealed partial class SettingsForm : Form, IEventDisabler { #region Private fields @@ -111,6 +111,7 @@ internal SettingsForm(ILocalizable? ownerForm, ConfigData config, bool startup) PathsPage.Thief2ExePathTextBox, PathsPage.Thief3ExePathTextBox, PathsPage.SS2ExePathTextBox, + PathsPage.SteamExeTextBox }; @@ -120,6 +121,7 @@ internal SettingsForm(ILocalizable? ownerForm, ConfigData config, bool startup) PathsPage.Thief2ExePathTextBox, PathsPage.Thief3ExePathTextBox, PathsPage.SS2ExePathTextBox, + PathsPage.SteamExeTextBox, PathsPage.BackupPathTextBox }; diff --git a/AngelLoader/Importing/ImportDarkLoader.cs b/AngelLoader/Importing/ImportDarkLoader.cs index 094a733c6..877e4fdae 100644 --- a/AngelLoader/Importing/ImportDarkLoader.cs +++ b/AngelLoader/Importing/ImportDarkLoader.cs @@ -309,6 +309,9 @@ await FMScan.ScanAndFind(fmsToScan, private static async Task ImportSaves(string[] lines) { + // We DON'T use game generalization here, because DarkLoader only supports T1/T2/SS2 and will never + // change (it's not updated anymore). So it's okay that we code those games in manually here. + string t1Dir = ""; string t2Dir = ""; string ss2Dir = ""; diff --git a/AngelLoader/Ini/ConfigIni.cs b/AngelLoader/Ini/ConfigIni.cs index e1d5b228d..bfa4bfe56 100644 --- a/AngelLoader/Ini/ConfigIni.cs +++ b/AngelLoader/Ini/ConfigIni.cs @@ -183,7 +183,7 @@ static bool ContainsColWithId(ConfigData _config, ColumnData _col) if (!ContainsColWithId(config, col)) config.Columns.Add(col); } #region Filter - // @GENGAMES + // @GENGAMES - Config reader - filter else if (lineT.StartsWithFast_NoNullChecks("FilterTitle=")) { config.Filter.Title = val; @@ -433,7 +433,6 @@ static bool ContainsColWithId(ConfigData _config, ColumnData _col) { config.GameTabsState.GetFilter(SS2).ShowUnsupported = val.EqualsTrue(); } - #endregion else if (lineT.StartsWithFast_NoNullChecks(nameof(config.EnableArticles) + "=")) { @@ -565,6 +564,7 @@ static bool ContainsColWithId(ConfigData _config, ColumnData _col) { config.LaunchGamesWithSteam = val.EqualsTrue(); } + // @GENGAMES - Config reader - Steam else if (lineT.StartsWithFast_NoNullChecks("T1UseSteam=")) { config.SetUseSteamSwitch(Thief1, val.EqualsTrue()); @@ -586,6 +586,7 @@ static bool ContainsColWithId(ConfigData _config, ColumnData _col) config.SteamExe = val.Trim(); } #endregion + // @GENGAMES - Config reader - Exes else if (lineT.StartsWithFast_NoNullChecks("T1Exe=")) { config.SetGameExe(Thief1, val.Trim()); @@ -624,6 +625,7 @@ static bool ContainsColWithId(ConfigData _config, ColumnData _col) _ => Thief1 }; } + // @GENGAMES - Config reader - Selected FM pos infos else if (lineT.StartsWithFast_NoNullChecks("T1SelFMInstDir=")) { config.GameTabsState.GetSelectedFM(Thief1).InstalledName = val; @@ -910,7 +912,6 @@ static bool ContainsColWithId(ConfigData _config, ColumnData _col) } // This is faster with reflection removed. - // @GENGAMES internal static void WriteConfigIni(ConfigData config, string fileName) { static string commaCombine(List list) where T : notnull @@ -934,7 +935,7 @@ static string commaCombineGameFlags(Game games) string ret = ""; // Hmm... doesn't make for good code, but fast... - // @GENGAMES + // @GENGAMES - Config writer - Comma combine game flags bool notEmpty = false; if ((games & Game.Thief1) == Game.Thief1) @@ -1020,7 +1021,7 @@ static string commaCombineFinishedStates(FinishedState finished) sw.WriteLine(nameof(config.LaunchGamesWithSteam) + "=" + config.LaunchGamesWithSteam); - // @GENGAMES + // @GENGAMES - Config writer - Steam // So far all games are on Steam. If we have one that isn't, we can just add an internal per-game // read-only "IsOnSteam" bool and check it before writing/reading this for (int i = 0; i < SupportedGameCount; i++)