Skip to content

Commit

Permalink
FinishedOn menu items code compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed May 14, 2020
1 parent 0d88829 commit 845b02a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
32 changes: 23 additions & 9 deletions AngelLoader/Common/GameSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,31 @@ internal enum GameIndex : uint

#endregion

internal static string GetLocalizedDifficultyName(FanMission? fm, Difficulty difficulty)
internal static string GetLocalizedDifficultyName(Game game, Difficulty difficulty)
{
bool fmIsT3 = fm != null && fm.Game == Game.Thief3;
bool fmIsSS2 = fm != null && fm.Game == Game.SS2;

return difficulty switch
// More verbose but also more clear
return game == Game.Thief3 ? difficulty switch
{
Difficulty.Normal => LText.Difficulties.Easy,
Difficulty.Hard => LText.Difficulties.Normal,
Difficulty.Expert => LText.Difficulties.Hard,
Difficulty.Extreme => LText.Difficulties.Expert,
_ => throw new ArgumentOutOfRangeException(nameof(difficulty) + " is not a valid value")
}
: game == Game.SS2 ? difficulty switch
{
Difficulty.Normal => LText.Difficulties.Easy,
Difficulty.Hard => LText.Difficulties.Normal,
Difficulty.Expert => LText.Difficulties.Hard,
Difficulty.Extreme => LText.Difficulties.Impossible,
_ => throw new ArgumentOutOfRangeException(nameof(difficulty) + " is not a valid value")
}
: difficulty switch
{
Difficulty.Normal => fmIsT3 || fmIsSS2 ? LText.Difficulties.Easy : LText.Difficulties.Normal,
Difficulty.Hard => fmIsT3 || fmIsSS2 ? LText.Difficulties.Normal : LText.Difficulties.Hard,
Difficulty.Expert => fmIsT3 || fmIsSS2 ? LText.Difficulties.Hard : LText.Difficulties.Expert,
Difficulty.Extreme => fmIsT3 ? LText.Difficulties.Expert : fmIsSS2 ? LText.Difficulties.Impossible : LText.Difficulties.Extreme,
Difficulty.Normal => LText.Difficulties.Normal,
Difficulty.Hard => LText.Difficulties.Hard,
Difficulty.Expert => LText.Difficulties.Expert,
Difficulty.Extreme => LText.Difficulties.Extreme,
_ => throw new ArgumentOutOfRangeException(nameof(difficulty) + " is not a valid value")
};
}
Expand Down
31 changes: 11 additions & 20 deletions AngelLoader/Forms/CustomControls/DataGridViewCustom/Menu_FM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,7 @@ private void SetFMMenuTextToLocalized()

FinishedOnMenuItem!.Text = LText.FMsList.FMMenu_FinishedOn.EscapeAmpersands();

FinishedOnNormalMenuItem!.Text = GetLocalizedDifficultyName(selFM, Difficulty.Normal).EscapeAmpersands();
FinishedOnHardMenuItem!.Text = GetLocalizedDifficultyName(selFM, Difficulty.Hard).EscapeAmpersands();
FinishedOnExpertMenuItem!.Text = GetLocalizedDifficultyName(selFM, Difficulty.Expert).EscapeAmpersands();
FinishedOnExtremeMenuItem!.Text = GetLocalizedDifficultyName(selFM, Difficulty.Extreme).EscapeAmpersands();
SetGameSpecificFinishedOnMenuItemsText(selFM?.Game ?? Game.Null);
FinishedOnUnknownMenuItem!.Text = LText.Difficulties.Unknown.EscapeAmpersands();

#endregion
Expand Down Expand Up @@ -565,23 +562,17 @@ internal void SetFinishedOnMenuItemChecked(Difficulty difficulty, bool value)
}
}

internal void SetFinishedOnMenuItemText(Difficulty difficulty, string text)
// Thief 1+2 difficulties: Normal, Hard, Expert, Extreme ("Extreme" is for DarkLoader compatibility)
// Thief 3 difficulties: Easy, Normal, Hard, Expert
// SS2 difficulties: Easy, Normal, Hard, Impossible
internal void SetGameSpecificFinishedOnMenuItemsText(Game game)
{
switch (difficulty)
{
case Difficulty.Normal:
if (_fmMenuConstructed) FinishedOnNormalMenuItem!.Text = text;
break;
case Difficulty.Hard:
if (_fmMenuConstructed) FinishedOnHardMenuItem!.Text = text;
break;
case Difficulty.Expert:
if (_fmMenuConstructed) FinishedOnExpertMenuItem!.Text = text;
break;
case Difficulty.Extreme:
if (_fmMenuConstructed) FinishedOnExtremeMenuItem!.Text = text;
break;
}
if (!_fmMenuConstructed) return;

FinishedOnNormalMenuItem!.Text = GetLocalizedDifficultyName(game, Difficulty.Normal).EscapeAmpersands();
FinishedOnHardMenuItem!.Text = GetLocalizedDifficultyName(game, Difficulty.Hard).EscapeAmpersands();
FinishedOnExpertMenuItem!.Text = GetLocalizedDifficultyName(game, Difficulty.Expert).EscapeAmpersands();
FinishedOnExtremeMenuItem!.Text = GetLocalizedDifficultyName(game, Difficulty.Extreme).EscapeAmpersands();
}

internal void SetFinishedOnUnknownMenuItemChecked(bool value)
Expand Down
8 changes: 1 addition & 7 deletions AngelLoader/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2730,13 +2730,7 @@ private async Task DisplaySelectedFM(bool refreshReadme, bool refreshCache = fal
// We should never get here when FMsList.Count == 0, but hey
if (FMsViewList.Count > 0) ScanAllFMsButton.Enabled = true;

// Thief 1+2 difficulties: Normal, Hard, Expert, Extreme ("Extreme" is for DarkLoader compatibility)
// Thief 3 difficulties: Easy, Normal, Hard, Expert
// SS2 difficulties: Easy, Normal, Hard, Impossible
FMsDGV.SetFinishedOnMenuItemText(Difficulty.Normal, GetLocalizedDifficultyName(fm, Difficulty.Normal));
FMsDGV.SetFinishedOnMenuItemText(Difficulty.Hard, GetLocalizedDifficultyName(fm, Difficulty.Hard));
FMsDGV.SetFinishedOnMenuItemText(Difficulty.Expert, GetLocalizedDifficultyName(fm, Difficulty.Expert));
FMsDGV.SetFinishedOnMenuItemText(Difficulty.Extreme, GetLocalizedDifficultyName(fm, Difficulty.Extreme));
FMsDGV.SetGameSpecificFinishedOnMenuItemsText(fm.Game);
// FinishedOnUnknownMenuItem text stays the same

bool gameIsSupported = GameIsKnownAndSupported(fm.Game);
Expand Down

0 comments on commit 845b02a

Please sign in to comment.