Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix play time column if no playtime, hide game column if single game #3570

Merged
merged 3 commits into from
Apr 22, 2022
Merged
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
3 changes: 3 additions & 0 deletions GUI/CKAN-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@
<EmbeddedResource Include="Controls\PlayTime.resx">
<DependentUpon>PlayTime.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Localization\de-DE\PlayTime.de-DE.resx">
<DependentUpon>..\..\Controls\PlayTime.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Localization\fr-FR\PlayTime.fr-FR.resx">
<DependentUpon>..\..\Controls\PlayTime.cs</DependentUpon>
</EmbeddedResource>
Expand Down
61 changes: 39 additions & 22 deletions GUI/Dialogs/ManageGameInstancesDialog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
Expand Down Expand Up @@ -73,27 +74,15 @@ public void UpdateInstancesList()
GameInstancesListView.Items.Clear();
UpdateButtonState();

if (!GameInstancesListView.Columns.Contains(GamePlayTime))
{
// Always show the play time column so our rows load correctly
GameInstancesListView.Columns.Insert(
GameInstallPath.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(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
})
Expand All @@ -102,13 +91,41 @@ public void UpdateInstancesList()

GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}

var hasPlayTime = _manager.Instances.Any(instance => (instance.Value.playTime?.Time ?? TimeSpan.Zero) > TimeSpan.Zero);
if (!hasPlayTime && GameInstancesListView.Columns.Contains(GamePlayTime))
private void AddOrRemoveColumn(ListView listView, ColumnHeader column, bool condition)
{
if (condition && !listView.Columns.Contains(column))
{
// Hide the play time column if not in use
GameInstancesListView.Columns.Remove(GamePlayTime);
listView.Columns.Insert(column.Index, column);
}
else if (!condition && listView.Columns.Contains(column))
{
listView.Columns.Remove(column);
}
}

private string[] rowItems(GameInstance instance, bool includeGame, bool includePlayTime)
{
var list = new List<string>
{
!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)
Expand Down
3 changes: 3 additions & 0 deletions GUI/Localization/de-DE/Main.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@
<data name="WaitTabPage.Text" xml:space="preserve"><value>Statuslog</value></data>
<data name="ChooseProvidedModsTabPage.Text" xml:space="preserve"><value>Wähle Mods</value></data>
<data name="ChooseRecommendedModsTabPage.Text" xml:space="preserve"><value>Auswahl von Empfehlungen, Vorschlägen und unterstützenden Mods</value></data>
<data name="PlayTimeTabPage.Text" xml:space="preserve"><value>Spielzeit</value></data>
<data name="DeleteDirectoriesTabPage.Text" xml:space="preserve"><value>Ordner entfernen</value></data>
<data name="EditModpackTabPage.Text" xml:space="preserve"><value>Modpack bearbeiten</value></data>
<data name="updatesToolStripMenuItem.Text" xml:space="preserve"><value>N verfügbare Updates</value></data>
<data name="refreshToolStripMenuItem.Text" xml:space="preserve"><value>Aktualisieren</value></data>
Expand All @@ -197,4 +199,5 @@
<data name="openGameDirectoryToolStripMenuItem1.Text" xml:space="preserve"><value>Spielverzeichnis öffnen</value></data>
<data name="cKANSettingsToolStripMenuItem1.Text" xml:space="preserve"><value>CKAN Einstellungen</value></data>
<data name="quitToolStripMenuItem.Text" xml:space="preserve"><value>Beenden</value></data>
<data name="viewPlayTimeStripMenuItem.Text" xml:space="preserve"><value>Spielzeit</value></data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<data name="openDirectoryMenuItem.Text" xml:space="preserve"><value>Verzeichnis öffnen</value></data>
<data name="GameInstallName.Text" xml:space="preserve"><value>Name</value></data>
<data name="Game.Text" xml:space="preserve"><value>Spiel</value></data>
<data name="GamePlayTime.Text" xml:space="preserve"><value>Spielstunden</value></data>
<data name="GameInstallPath.Text" xml:space="preserve"><value>Pfad</value></data>
<data name="SelectButton.Text" xml:space="preserve"><value>Wählen</value></data>
<data name="AddNewButton.Text" xml:space="preserve"><value>Neue Spielinstanz</value></data>
Expand Down
124 changes: 124 additions & 0 deletions GUI/Localization/de-DE/PlayTime.de-DE.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="EditHelpLabel.Text" xml:space="preserve"><value>Zum Ändern das Stundenfeld anklicken und einfach einen neuen Wert eingeben oder F2 drücken um den alten Wert zu bearbeiten</value></data>
<data name="NameColumn.HeaderText" xml:space="preserve"><value>Instanzname</value></data>
<data name="TimeColumn.HeaderText" xml:space="preserve"><value>Spielzeit in Stunden</value></data>
<data name="OKButton.Text" xml:space="preserve"><value>OK</value></data>
</root>
2 changes: 2 additions & 0 deletions GUI/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ Möchtest du CKAN dies erlauben?
Wenn du auf Nein klickst, siehst du diese Nachricht nicht mehr.</value>
</data>
<data name="UtilCopyLink" xml:space="preserve"><value>&amp;Linkadresse kopieren</value></data>
<data name="StatusInstanceLabelTextWithPlayTime" xml:space="preserve"><value>Spielinstanz: {0} ({1} {2}, {3}h gespielt)</value></data>
<data name="StatusInstanceLabelText" xml:space="preserve"><value>Spielinstanz: {0} ({1} {2})</value></data>
<data name="ModuleLabelListFavourites" xml:space="preserve"><value>Favoriten</value></data>
<data name="ModuleLabelListHidden" xml:space="preserve"><value>Versteckt</value></data>
Expand Down Expand Up @@ -389,4 +390,5 @@ Wenn du auf Nein klickst, siehst du diese Nachricht nicht mehr.</value>
<data name="EditModSearchTooltipExpandButton" xml:space="preserve"><value>Detailierte Suchfelder ein-/ausklappen (Strg-Shift-F)</value></data>
<data name="EditModSearchesTooltipAddSearchButton" xml:space="preserve"><value>Füge eine weitere Suche hinzu</value></data>
<data name="ManageModsInstallAllCheckboxTooltip" xml:space="preserve"><value>Abwählen um alle Mods zu deinstallieren, anwählen um die Änderungsliste zu leeren</value></data>
<data name="TotalPlayTime" xml:space="preserve"><value>Gesamtspielzeit: {0} Stunden</value></data>
</root>