Skip to content

Commit

Permalink
More game generalization work and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed May 14, 2020
1 parent 86f5539 commit 7625335
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 105 deletions.
8 changes: 4 additions & 4 deletions AngelLoader/Common/GameSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions AngelLoader/Common/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion AngelLoader/FMAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions AngelLoader/FMInstallAndPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -1233,7 +1233,7 @@ internal static async Task<bool> 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" +
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AngelLoader.Forms.CustomControls.Static_LazyLoaded
{
// @GENGAMES
// @GENGAMES - Play original game menu
internal static class PlayOriginalGameLLMenu
{
private static bool _constructed;
Expand Down
12 changes: 5 additions & 7 deletions AngelLoader/Forms/Import/ImportFromMultipleInisForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Windows.Forms;
using AngelLoader.DataClasses;
using AngelLoader.Importing;
using static AngelLoader.GameSupport;

namespace AngelLoader.Forms.Import
{
Expand Down Expand Up @@ -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<string>
IniFiles = new List<string>(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;
Expand Down
123 changes: 59 additions & 64 deletions AngelLoader/Forms/Import/User_FMSel_NDL_ImportControls.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using AngelLoader.DataClasses;
using AngelLoader.Importing;
Expand All @@ -10,27 +10,56 @@ 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)
{
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()
Expand All @@ -39,80 +68,46 @@ 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)
{
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);
}
}
}
17 changes: 8 additions & 9 deletions AngelLoader/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -765,15 +765,14 @@ public MainForm()
#endif

// -------- New games go here!
// @GENGAMES
// @GENGAMES - tabs and filter buttons
GameTabsInOrder = new[]
{
Thief1TabPage,
Thief2TabPage,
Thief3TabPage,
SS2TabPage
};

FilterByGameButtonsInOrder = new[]
{
FilterByThief1Button,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7625335

Please sign in to comment.