Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace BizHawk.Client.EmuHawk
{
public static class ControlExtensions
{
private const int WM_SETREDRAW = 0x000B;

/// <exception cref="ArgumentException"><typeparamref name="T"/> does not inherit <see cref="Enum"/></exception>
public static void PopulateFromEnum<T>(this ComboBox box, T enumVal)
where T : Enum
Expand Down Expand Up @@ -199,6 +201,22 @@ public static CheckState ToCheckState(this bool? tristate)
false => CheckState.Unchecked,
null => CheckState.Indeterminate,
};

public static void SuspendDrawing(this Control control)
{
if (!OSTailoredCode.IsUnixHost)
{
WmImports.SendMessageW(control.Handle, WM_SETREDRAW, (IntPtr) 0, IntPtr.Zero);
}
}

public static void ResumeDrawing(this Control control)
{
if (!OSTailoredCode.IsUnixHost)
{
WmImports.SendMessageW(control.Handle, WM_SETREDRAW, (IntPtr) 1, IntPtr.Zero);
}
}
}

public static class ListViewExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace BizHawk.Client.EmuHawk
{
public partial class RCheevos
{
#if false
// #if false
private readonly RCheevosAchievementListForm _cheevoListForm = new();
#endif
// #endif

private sealed class CheevoUnlockRequest : RCheevoHttpRequest
{
Expand Down Expand Up @@ -97,6 +97,17 @@ public void LoadImages(IList<RCheevoHttpRequest> requests)
requests.Add(_badgeLockedRequest);
}

public int OrderByKey(Func<uint, string> getCheevoProgress)
{
var ret = 0;
ret += IsHardcoreUnlocked ? 3 : 0;
ret += IsSoftcoreUnlocked ? 2 : 0;
ret += IsPrimed ? 1 : 0;
ret += string.IsNullOrEmpty(getCheevoProgress(ID)) ? 0 : 1;
ret += IsOfficial ? 0 : -10;
return ret;
}

public Cheevo(in LibRCheevos.rc_api_achievement_definition_t cheevo, Func<bool> allowUnofficialCheevos)
{
ID = cheevo.id;
Expand Down Expand Up @@ -218,4 +229,4 @@ private void OneShotActivateActiveModeCheevos()
ActivateCheevos(HardcoreMode);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace BizHawk.Client.EmuHawk
{
public partial class RCheevos
{
#if false
// #if false
private readonly RCheevosLeaderboardListForm _lboardListForm = new();
#endif
// #endif

private sealed class LboardTriggerRequest : RCheevoHttpRequest
{
Expand Down Expand Up @@ -89,4 +89,4 @@ public LBoard(in LBoard lboard)
}
}
}
}
}
24 changes: 12 additions & 12 deletions src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ private void BuildMenu(ToolStripItemCollection raDropDownItems)
_gameInfoForm.Show();
};
raDropDownItems.Add(viewGameInfoItem);
#if false
// #if false
var viewCheevoListItem = new ToolStripMenuItem("View Achievement List");
viewCheevoListItem.Click += (_, _) =>
{
_cheevoListForm.OnFrameAdvance(HardcoreMode, true);
_cheevoListForm.OnFrameAdvance(HardcoreMode);
_cheevoListForm.Show();
};
raDropDownItems.Add(viewCheevoListItem);
Expand All @@ -204,7 +204,7 @@ private void BuildMenu(ToolStripItemCollection raDropDownItems)
_lboardListForm.Show();
};
raDropDownItems.Add(viewLboardListItem);
#endif
// #endif
}

protected override void HandleHardcoreModeDisable(string reason)
Expand Down Expand Up @@ -266,10 +266,10 @@ public override void Dispose()
_runtime = IntPtr.Zero;
Stop();
_gameInfoForm.Dispose();
#if false
// #if false
_cheevoListForm.Dispose();
_lboardListForm.Dispose();
#endif
// #endif
_mainForm.QuicksaveLoad -= QuickLoadCallback;
}

Expand Down Expand Up @@ -454,10 +454,10 @@ public override void Restart()
_lib.rc_runtime_validate_addresses(_runtime, _eventcb, _validatecb);

_gameInfoForm.Restart(_gameData.Title, _gameData.TotalCheevoPoints(HardcoreMode), CurrentRichPresence ?? "N/A");
#if false
_cheevoListForm.Restart(_gameData.GameID == 0 ? Array.Empty<Cheevo>() : _gameData.CheevoEnumerable, GetCheevoProgress);
// #if false
_cheevoListForm.Restart(_gameData.GameID == 0 ? Array.Empty<Cheevo>() : _gameData.CheevoEnumerable, GetCheevoProgress, () => HardcoreMode);
_lboardListForm.Restart(_gameData.GameID == 0 ? Array.Empty<LBoard>() : _gameData.LBoardEnumerable);
#endif
// #endif

Update();

Expand Down Expand Up @@ -705,17 +705,17 @@ public override void OnFrameAdvance()
CurrentLboard is null ? "N/A" : $"{CurrentLboard.Description} ({CurrentLboard.Score})",
CurrentRichPresence ?? "N/A");
}
#if false
if (_cheevoListForm.IsShown)
// #if false
if (_cheevoListForm.Visible)
{
_cheevoListForm.OnFrameAdvance(HardcoreMode);
}

if (_lboardListForm.IsShown)
if (_lboardListForm.Visible)
{
_lboardListForm.OnFrameAdvance();
}
#endif
// #endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,58 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
public partial class RCheevosAchievementForm : Form
{
public int OrderByKey()
{
var ret = 0;
ret += hcUnlockedCheckBox.Checked ? 3 : 0;
ret += scUnlockedCheckBox.Checked ? 2 : 0;
ret += primedCheckBox.Checked ? 1 : 0;
ret += string.IsNullOrEmpty(progressBox.Text) ? 0 : 1;
ret += unofficialCheckBox.Checked ? -10 : 0;
return ret;
}

private Bitmap _unlockedBadge, _lockedBadge;
private readonly RCheevos.Cheevo _cheevo;
private RCheevos.Cheevo _cheevo;
private readonly Func<uint, string> _getCheevoProgress;

public RCheevosAchievementForm(RCheevos.Cheevo cheevo, Func<uint, string> getCheevoProgress)
public RCheevosAchievementForm(Func<uint, string> getCheevoProgress)
{
InitializeComponent();
_getCheevoProgress = getCheevoProgress;
TopLevel = false;
Show();
}

public bool UpdateCheevo(RCheevos.Cheevo cheevo, bool isHardcodeMode)
{
bool updated = _cheevo != cheevo;

_cheevo = cheevo;

titleBox.Text = cheevo.Title;
descriptionBox.Text = cheevo.Description;
pointsBox.Text = cheevo.Points.ToString();
progressBox.Text = getCheevoProgress(cheevo.ID);
unofficialCheckBox.Checked = !cheevo.IsOfficial;

// badges are lazy loaded so we need to make sure they are updated even when _cheevo == cheevo
if (updated)
{
_unlockedBadge = null;
_lockedBadge = null;
cheevoBadgeBox.Image = null;
}
_unlockedBadge ??= UpscaleBadge(cheevo.BadgeUnlocked);
_lockedBadge ??= UpscaleBadge(cheevo.BadgeLocked);

var badge = _cheevo.IsUnlocked(isHardcodeMode) ? _unlockedBadge : _lockedBadge;

if (cheevoBadgeBox.Image != badge)
{
cheevoBadgeBox.Image = badge;
updated = true;
}
progressBox.Text = _getCheevoProgress(cheevo.ID);
hcUnlockedCheckBox.Checked = cheevo.IsHardcoreUnlocked;
primedCheckBox.Checked = cheevo.IsPrimed;
scUnlockedCheckBox.Checked = cheevo.IsSoftcoreUnlocked;
_cheevo = cheevo;
_getCheevoProgress = getCheevoProgress;
TopLevel = false;
Show();

return updated;
}

private static Bitmap UpscaleBadge(Bitmap src)
{
if (src is null) return null;

var ret = new Bitmap(120, 120);
using var g = Graphics.FromImage(ret);
g.InterpolationMode = InterpolationMode.NearestNeighbor;
Expand All @@ -53,26 +71,13 @@ private static Bitmap UpscaleBadge(Bitmap src)

public void OnFrameAdvance(bool hardcore)
{
var unlockedBadge = _cheevo.BadgeUnlocked;
if (_unlockedBadge is null && unlockedBadge is not null)
{
_unlockedBadge = UpscaleBadge(unlockedBadge);
}

var lockedBadge = _cheevo.BadgeLocked;
if (_lockedBadge is null && lockedBadge is not null)
{
_lockedBadge = UpscaleBadge(lockedBadge);
}

var badge = _cheevo.IsUnlocked(hardcore) ? _unlockedBadge : _lockedBadge;

if (cheevoBadgeBox.Image != badge)
{
cheevoBadgeBox.Image = badge;
}

pointsBox.Text = _cheevo.Points.ToString();
progressBox.Text = _getCheevoProgress(_cheevo.ID);
hcUnlockedCheckBox.Checked = _cheevo.IsHardcoreUnlocked;
primedCheckBox.Checked = _cheevo.IsPrimed;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading