From 18dd40d6260d8d17e0a4471a2b0b3de8e1562a7b Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Fri, 22 Apr 2022 15:02:27 +0200 Subject: [PATCH 1/3] Fix play time column if no playtime, hide game column if single game --- GUI/Dialogs/ManageGameInstancesDialog.cs | 61 +++++++++++++++++------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/GUI/Dialogs/ManageGameInstancesDialog.cs b/GUI/Dialogs/ManageGameInstancesDialog.cs index 7e639a8f40..dac269e4b7 100644 --- a/GUI/Dialogs/ManageGameInstancesDialog.cs +++ b/GUI/Dialogs/ManageGameInstancesDialog.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.IO; @@ -73,42 +74,66 @@ public void UpdateInstancesList() GameInstancesListView.Items.Clear(); UpdateButtonState(); + + if (!GameInstancesListView.Columns.Contains(Game)) + { + // Always show the game column so our rows load correctly + GameInstancesListView.Columns.Insert(Game.Index, Game); + } if (!GameInstancesListView.Columns.Contains(GamePlayTime)) { // Always show the play time column so our rows load correctly - GameInstancesListView.Columns.Insert( - GameInstallPath.Index, GamePlayTime); + GameInstancesListView.Columns.Insert(GamePlayTime.Index, GamePlayTime); } + var allSameGame = _manager.Instances.Select(i => i.Value.game).Distinct().Count() <= 1; + var hasPlayTime = _manager.Instances.Any(instance => (instance.Value.playTime?.Time ?? TimeSpan.Zero) > TimeSpan.Zero); + GameInstancesListView.Items.AddRange(_manager.Instances .OrderByDescending(instance => instance.Value.Version()) - .Select(instance => new ListViewItem(new string[] - { - !instance.Value.Valid - ? string.Format(Properties.Resources.ManageGameInstancesNameColumnInvalid, instance.Key) - : _manager.CurrentInstance != instance.Value && instance.Value.IsMaybeLocked - ? string.Format(Properties.Resources.ManageGameInstancesNameColumnLocked, instance.Key) - : instance.Key, - instance.Value.game.ShortName, - FormatVersion(instance.Value.Version()), - instance.Value.playTime?.ToString() ?? "", - instance.Value.GameDir().Replace('/', Path.DirectorySeparatorChar) - }) + .Select(instance => new ListViewItem(rowItems(instance.Value, !allSameGame, hasPlayTime)) { Tag = instance.Key }) .ToArray() ); - GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); - GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); - - var hasPlayTime = _manager.Instances.Any(instance => (instance.Value.playTime?.Time ?? TimeSpan.Zero) > TimeSpan.Zero); + if (allSameGame && GameInstancesListView.Columns.Contains(Game)) + { + // Hide the game column if not in use + GameInstancesListView.Columns.Remove(Game); + } if (!hasPlayTime && GameInstancesListView.Columns.Contains(GamePlayTime)) { // Hide the play time column if not in use GameInstancesListView.Columns.Remove(GamePlayTime); } + + GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); + GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); + } + + private string[] rowItems(GameInstance instance, bool includeGame, bool includePlayTime) + { + var list = new List + { + !instance.Valid + ? string.Format(Properties.Resources.ManageGameInstancesNameColumnInvalid, instance.Name) + : !(_manager.CurrentInstance?.Equals(instance) ?? false) && instance.IsMaybeLocked + ? string.Format(Properties.Resources.ManageGameInstancesNameColumnLocked, instance.Name) + : instance.Name + }; + + if (includeGame) + list.Add(instance.game.ShortName); + + list.Add(FormatVersion(instance.Version())); + + if (includePlayTime) + list.Add(instance.playTime?.ToString() ?? ""); + + list.Add(instance.GameDir().Replace('/', Path.DirectorySeparatorChar)); + return list.ToArray(); } private static string FormatVersion(GameVersion v) From c86ac056fc9dca7171d7015509c96e00fdd9394c Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Fri, 22 Apr 2022 16:39:21 +0200 Subject: [PATCH 2/3] German localization for play time feature --- GUI/CKAN-GUI.csproj | 3 + GUI/Localization/de-DE/Main.de-DE.resx | 3 + .../ManageGameInstancesDialog.de-DE.resx | 1 + GUI/Localization/de-DE/PlayTime.de-DE.resx | 124 ++++++++++++++++++ GUI/Properties/Resources.de-DE.resx | 2 + 5 files changed, 133 insertions(+) create mode 100644 GUI/Localization/de-DE/PlayTime.de-DE.resx diff --git a/GUI/CKAN-GUI.csproj b/GUI/CKAN-GUI.csproj index a433794c61..4a387f224e 100644 --- a/GUI/CKAN-GUI.csproj +++ b/GUI/CKAN-GUI.csproj @@ -690,6 +690,9 @@ PlayTime.cs + + ..\..\Controls\PlayTime.cs + ..\..\Controls\PlayTime.cs diff --git a/GUI/Localization/de-DE/Main.de-DE.resx b/GUI/Localization/de-DE/Main.de-DE.resx index 313391af4f..872accc53e 100644 --- a/GUI/Localization/de-DE/Main.de-DE.resx +++ b/GUI/Localization/de-DE/Main.de-DE.resx @@ -188,6 +188,8 @@ Statuslog Wähle Mods Auswahl von Empfehlungen, Vorschlägen und unterstützenden Mods + Spielzeit + Ordner entfernen Modpack bearbeiten N verfügbare Updates Aktualisieren @@ -197,4 +199,5 @@ Spielverzeichnis öffnen CKAN Einstellungen Beenden + Spielzeit diff --git a/GUI/Localization/de-DE/ManageGameInstancesDialog.de-DE.resx b/GUI/Localization/de-DE/ManageGameInstancesDialog.de-DE.resx index 1543822da7..3f166a0511 100644 --- a/GUI/Localization/de-DE/ManageGameInstancesDialog.de-DE.resx +++ b/GUI/Localization/de-DE/ManageGameInstancesDialog.de-DE.resx @@ -124,6 +124,7 @@ Verzeichnis öffnen Name Spiel + Spielstunden Pfad Wählen Neue Spielinstanz diff --git a/GUI/Localization/de-DE/PlayTime.de-DE.resx b/GUI/Localization/de-DE/PlayTime.de-DE.resx new file mode 100644 index 0000000000..1fb3cacb64 --- /dev/null +++ b/GUI/Localization/de-DE/PlayTime.de-DE.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Zum Ändern das Stundenfeld anklicken und einfach einen neuen Wert eingeben oder F2 drücken um den alten Wert zu bearbeiten + Instanzname + Spielzeit in Stunden + OK + diff --git a/GUI/Properties/Resources.de-DE.resx b/GUI/Properties/Resources.de-DE.resx index e73a55e9cc..35d746de6d 100644 --- a/GUI/Properties/Resources.de-DE.resx +++ b/GUI/Properties/Resources.de-DE.resx @@ -336,6 +336,7 @@ Möchtest du CKAN dies erlauben? Wenn du auf Nein klickst, siehst du diese Nachricht nicht mehr. &Linkadresse kopieren + Spielinstanz: {0} ({1} {2}, {3}h gespielt) Spielinstanz: {0} ({1} {2}) Favoriten Versteckt @@ -389,4 +390,5 @@ Wenn du auf Nein klickst, siehst du diese Nachricht nicht mehr. Detailierte Suchfelder ein-/ausklappen (Strg-Shift-F) Füge eine weitere Suche hinzu Abwählen um alle Mods zu deinstallieren, anwählen um die Änderungsliste zu leeren + Gesamtspielzeit: {0} Stunden From 550287aa9e1a79bde7451bedafa75b810b556eab Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Fri, 22 Apr 2022 16:24:44 +0000 Subject: [PATCH 3/3] Refactor column add/remove --- GUI/Dialogs/ManageGameInstancesDialog.cs | 34 +++++++++--------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/GUI/Dialogs/ManageGameInstancesDialog.cs b/GUI/Dialogs/ManageGameInstancesDialog.cs index dac269e4b7..e1ad839449 100644 --- a/GUI/Dialogs/ManageGameInstancesDialog.cs +++ b/GUI/Dialogs/ManageGameInstancesDialog.cs @@ -74,21 +74,12 @@ public void UpdateInstancesList() GameInstancesListView.Items.Clear(); UpdateButtonState(); - - if (!GameInstancesListView.Columns.Contains(Game)) - { - // Always show the game column so our rows load correctly - GameInstancesListView.Columns.Insert(Game.Index, Game); - } - if (!GameInstancesListView.Columns.Contains(GamePlayTime)) - { - // Always show the play time column so our rows load correctly - GameInstancesListView.Columns.Insert(GamePlayTime.Index, GamePlayTime); - } - var allSameGame = _manager.Instances.Select(i => i.Value.game).Distinct().Count() <= 1; var hasPlayTime = _manager.Instances.Any(instance => (instance.Value.playTime?.Time ?? TimeSpan.Zero) > TimeSpan.Zero); + AddOrRemoveColumn(GameInstancesListView, Game, !allSameGame); + AddOrRemoveColumn(GameInstancesListView, GamePlayTime, hasPlayTime); + GameInstancesListView.Items.AddRange(_manager.Instances .OrderByDescending(instance => instance.Value.Version()) .Select(instance => new ListViewItem(rowItems(instance.Value, !allSameGame, hasPlayTime)) @@ -98,19 +89,20 @@ public void UpdateInstancesList() .ToArray() ); - if (allSameGame && GameInstancesListView.Columns.Contains(Game)) + GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); + GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); + } + + private void AddOrRemoveColumn(ListView listView, ColumnHeader column, bool condition) + { + if (condition && !listView.Columns.Contains(column)) { - // Hide the game column if not in use - GameInstancesListView.Columns.Remove(Game); + listView.Columns.Insert(column.Index, column); } - if (!hasPlayTime && GameInstancesListView.Columns.Contains(GamePlayTime)) + else if (!condition && listView.Columns.Contains(column)) { - // Hide the play time column if not in use - GameInstancesListView.Columns.Remove(GamePlayTime); + listView.Columns.Remove(column); } - - GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); - GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } private string[] rowItems(GameInstance instance, bool includeGame, bool includePlayTime)