Skip to content

Commit

Permalink
GOGSecondClassGameWatcher: Add tooltip with information to plugin con…
Browse files Browse the repository at this point in the history
…trol
  • Loading branch information
darklinkpower committed Dec 11, 2024
1 parent f0bd825 commit 649946a
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Button Foreground="Red"
<Button Foreground="Red" ToolTip="{Binding Tooltip}"
Padding="0" Background="Transparent" BorderThickness="0"
Command="{Binding OpenWindowCommand}">
<StackPanel Orientation="Horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public partial class PlayniteThemesUserControl : PluginUserControl, INotifyPrope
public event PropertyChangedEventHandler PropertyChanged;
private bool _isAtDefaultValues = true;
private string _numberOfIssues = string.Empty;
private string _tooltip = null;
private GogSecondClassGame _secondClassData;

public string NumberOfIssues
Expand All @@ -49,6 +50,16 @@ public string NumberOfIssues
}
}

public string Tooltip
{
get => _tooltip;
set
{
_tooltip = value;
OnPropertyChanged();
}
}

public RelayCommand OpenWindowCommand { get; }

public PlayniteThemesUserControl(IPlayniteAPI playniteApi, GogSecondClassService gogSecondClassService, GOGSecondClassGameWatcherSettingsViewModel gOGSecondClassWatcherSettingsViewModel, GogSecondClassGameWindowCreator gogSecondClassGameWindowCreator)
Expand Down Expand Up @@ -111,6 +122,7 @@ public override void GameContextChanged(Game oldContext, Game newContext)
NumberOfIssues = _secondClassData.TotalIssues.ToString();
Visibility = Visibility.Visible;
_gOGSecondClassWatcherSettingsViewModel.Settings.IsControlVisible = true;
Tooltip = GetTooltip(_secondClassData);
_isAtDefaultValues = false;
}
}
Expand All @@ -119,6 +131,7 @@ private void ResetToDefaultValues()
{
_secondClassData = null;
NumberOfIssues = string.Empty;
Tooltip = null;
Visibility = Visibility.Collapsed;
_gOGSecondClassWatcherSettingsViewModel.Settings.IsControlVisible = false;
_isAtDefaultValues = true;
Expand All @@ -134,6 +147,88 @@ private void OpenWindow()
_gogSecondClassGameWindowCreator.OpenWindow(_secondClassData, this.GameContext);
}

private static string GetTooltip(GogSecondClassGame gogSecondClassGame)
{
if (gogSecondClassGame is null)
{
return string.Empty;
}

var sb = new StringBuilder();
// General Issues
if (gogSecondClassGame.GeneralIssues.GetIssuesCount() > 0)
{
sb.Append(ResourceProvider.GetString("LOC_GogSecondClass_GeneralIssuesLabel"));
sb.Append($"\n{new string('-', 40)}\n");
var lines = new List<string>();
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.MissingUpdates, "LOC_GogSecondClass_MissingUpdatesLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.MissingLanguages, "LOC_GogSecondClass_MissingLanguagesLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.MissingFreeDlc, "LOC_GogSecondClass_MissingFreeDlcLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.MissingPaidDlc, "LOC_GogSecondClass_MissingPaidDlcLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.MissingFeatures, "LOC_GogSecondClass_MissingFeaturesLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.MissingSoundtrack, "LOC_GogSecondClass_MissingSoundtrackLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.OtherIssues, "LOC_GogSecondClass_OtherIssuesLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.MissingBuilds, "LOC_GogSecondClass_MissingBuildsLabel");
AddLinesToTooltip(lines, gogSecondClassGame.GeneralIssues.RegionLocking, "LOC_GogSecondClass_RegionLockingLabel");
sb.Append(string.Join("\n", lines));
}

// Achievements Issues
if (gogSecondClassGame.AchievementsIssues.GetIssuesCount() > 0)
{
if (sb.Length > 0)
{
sb.Append($"\n\n");
}

sb.Append(ResourceProvider.GetString("LOC_GogSecondClass_AchievementsIssuesLabel"));
sb.Append($"\n{new string('-', 40)}\n");
var lines = new List<string>();
AddLinesToTooltip(lines, gogSecondClassGame.AchievementsIssues.MissingAllAchievements, "LOC_GogSecondClass_MissingAllAchievementsLabel");
AddLinesToTooltip(lines, gogSecondClassGame.AchievementsIssues.MissingSomeAchievements, "LOC_GogSecondClass_MissingSomeAchievementsLabel");
AddLinesToTooltip(lines, gogSecondClassGame.AchievementsIssues.BrokenAchievements, "LOC_GogSecondClass_BrokenAchievementsLabel");
AddLinesToTooltip(lines, gogSecondClassGame.AchievementsIssues.AchievementsAskedResponse, "LOC_GogSecondClass_AchievementsAskedResponseLabel");
sb.Append(string.Join("\n", lines));
}

return sb.ToString();
}

private static void AddLinesToTooltip(List<string> lines, IReadOnlyList<string> issuesStrings, string locStringKey)
{
if (!issuesStrings?.Any() == true)
{
return;
}

lines.Add($"{ResourceProvider.GetString(locStringKey)}:");
var lineIndentString = new string(' ', 8);
foreach (var issueString in issuesStrings)
{
var splittedIssueString = issueString.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var str in splittedIssueString)
{
lines.Add($"{lineIndentString}{str}");
}
}
}

private static void AddLinesToTooltip(List<string> lines, string issuesString, string locStringKey)
{
if (issuesString.IsNullOrEmpty())
{
return;
}

lines.Add($"{ResourceProvider.GetString(locStringKey)}:");
var lineIndentString = new string(' ', 8);
var splittedIssueString = issuesString.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (var str in splittedIssueString)
{
lines.Add($"{lineIndentString}{str}");
}
}

protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
Expand Down

0 comments on commit 649946a

Please sign in to comment.