Skip to content

Commit

Permalink
Added support to make notes for each mod.
Browse files Browse the repository at this point in the history
- Notes can be edited from the new note tab in mod info panel or using the note column in the mod list view (column is hidden by default).
- Mod description is no longer editable.
- Mod description now gets properly updated, not only in case it is empty. Fixes #280. This will (obviously) overwrite all manual changes made to the description.
  • Loading branch information
RevZero committed Jul 5, 2024
1 parent 9828280 commit 2340cc5
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 208 deletions.
18 changes: 10 additions & 8 deletions xcom2-launcher/xcom2-launcher/Classes/Mod/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ModEntry
public DateTime? DateCreated { get; set; } = null;
public DateTime? DateUpdated { get; set; } = null;

public string Note { get; set; } = null;
public string Note { get; set; }

/// <summary>
/// Contains workshop id's from all mods, that this mod requires to run properly (as reported from workshop).
Expand Down Expand Up @@ -140,24 +140,26 @@ public Classes.Mod.ModProperty GetProperty()

#region Mod

public string GetDescription(bool CleanBBCode = false)
public string GetDescription(bool cleanBbCode = false)
{
string dsc;

if (!string.IsNullOrEmpty(Description))
dsc = Description;
else
dsc = new ModInfo(GetModInfoFile()).Description;

if (CleanBBCode)
if (cleanBbCode)
{
dsc = Tools.GetRtfEscapedString(dsc);
Regex Regexp = new Regex(@"(?<!\\\\)\[(/?)(.*?)(?<!\\\\)\]");
dsc = Regexp.Replace(dsc, RTFEvaluator);
Regex replace_linebreaks = new Regex(@"[\r\n]{1,2}");
dsc = replace_linebreaks.Replace(dsc, @"\line ");
var regexp = new Regex(@"(?<!\\\\)\[(/?)(.*?)(?<!\\\\)\]");
dsc = regexp.Replace(dsc, RTFEvaluator);
var replaceLinebreaks = new Regex(@"[\r\n]{1,2}");
dsc = replaceLinebreaks.Replace(dsc, @"\line ");
return @"{\rtf1\ansi " + dsc + "}";
}
return Description;

return dsc;
}

private string RTFEvaluator(Match match)
Expand Down
11 changes: 6 additions & 5 deletions xcom2-launcher/xcom2-launcher/Classes/Mod/ModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,9 @@ async Task UpdateLocalModAsync(ModEntry m)
var modInfo = new ModInfo(m.GetModInfoFile());

if (!m.ManualName || m.Name == "")
{
m.Name = modInfo.Title;
}

m.Description = modInfo.Description;
m.SetRequiresWOTC(modInfo.RequiresXPACK);
Expand Down Expand Up @@ -514,8 +516,10 @@ async Task UpdateSteamModAsync(ModEntry m, SteamUGCDetails workshopDetailsWrappe

Log.Debug("Processing Workshop details for " + m.ID);

if (!m.ManualName)
if (!m.ManualName || m.Name == "")
{
m.Name = workshopDetails.m_rgchTitle;
}

m.DateCreated = DateTimeOffset.FromUnixTimeSeconds(workshopDetails.m_rtimeCreated).DateTime;
m.DateUpdated = DateTimeOffset.FromUnixTimeSeconds(workshopDetails.m_rtimeUpdated).DateTime;
Expand All @@ -530,10 +534,7 @@ async Task UpdateSteamModAsync(ModEntry m, SteamUGCDetails workshopDetailsWrappe
m.CalculateSize();
}

if (string.IsNullOrEmpty(m.Description))
{
m.Description = workshopDetails.m_rgchDescription;
}
m.Description = workshopDetails.m_rgchDescription;

// Request mod author name if necessary.
if (string.IsNullOrEmpty(m.Author) || m.Author == ModEntry.DEFAULT_AUTHOR_NAME)
Expand Down
7 changes: 1 addition & 6 deletions xcom2-launcher/xcom2-launcher/Classes/Mod/ModProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ public string Author
public string Description
{
get { return modEntry.Description; }
set {
modEntry.Description = value;
PropertyChangedEventArgs e = new PropertyChangedEventArgs("Description");
PropertyChanged?.Invoke(this, e);
}
}

[Category("Mod Properties")]
Expand Down Expand Up @@ -147,7 +142,7 @@ public bool isHidden
[Category("Mod Properties")]
public string DateUpdated { get { return modEntry.DateUpdated.HasValue ? modEntry.DateUpdated.Value.ToString() : "Unknown"; } }

[Category("Mod Info")]
[Browsable(false)]
public string Note
{
get { return modEntry.Note; }
Expand Down
204 changes: 113 additions & 91 deletions xcom2-launcher/xcom2-launcher/Forms/MainForm.Designer.cs

Large diffs are not rendered by default.

37 changes: 9 additions & 28 deletions xcom2-launcher/xcom2-launcher/Forms/MainForm.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,34 +816,6 @@ private void modinfo_config_CompareButton_Click(object sender, EventArgs e)
}
}

private void modinfo_info_DescriptionRichTextBox_TextChanged(object sender, EventArgs e)
{
//var contents = modinfo_info_DescriptionRichTextBox.Text;
//if (!CurrentMod.Description.Equals(contents))
// CurrentMod.Description = contents;
btnDescSave.Enabled = true;
btnDescUndo.Enabled = true;
}

private void btnDescSave_Click(object sender, EventArgs e)
{
if (CurrentMod != null)
{
var contents = modinfo_info_DescriptionRichTextBox.Text;

if (!CurrentMod.Description.Equals(contents))
CurrentMod.Description = contents;
}

btnDescSave.Enabled = false;
btnDescUndo.Enabled = false;
}

private void btnDescUndo_Click(object sender, EventArgs e)
{
UpdateModDescription(CurrentMod);
}

private void modlist_toggleGroupsButton_Click(object sender, EventArgs e)
{
if (modlist_ListObjectListView.OLVGroups == null)
Expand Down Expand Up @@ -898,6 +870,15 @@ private void cShowPrimaryDuplicates_CheckedChanged(object sender, EventArgs e)
UpdateDependencyInformation(mod);
}
}

private void modInfoNotesText_TextChanged(object sender, EventArgs e)
{
if (CurrentMod != null)
{
CurrentMod.Note = modInfoNotesText.Text;
modlist_ListObjectListView.RefreshObject(CurrentMod);
}
}

#endregion
}
Expand Down
59 changes: 56 additions & 3 deletions xcom2-launcher/xcom2-launcher/Forms/MainForm.ModList.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Drawing.Text;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -165,6 +164,60 @@ private void InitModListView()
// Restore State
if (Settings.Windows.ContainsKey("main") && Settings.Windows["main"].Data != null)
modlist_ListObjectListView.RestoreState(Settings.Windows["main"].Data);

olvColNotes.AspectGetter += rowObject =>
{
if (!(rowObject is ModEntry mod))
{
return "";
}
// Return only the first line of the note
if (String.IsNullOrWhiteSpace(mod.Note))
{
return "";
}
var firstLine = new Regex("[^\r\n]*").Match(mod.Note).Value;
return firstLine;
};

modlist_ListObjectListView.CellEditStarting += (sender, args) =>
{
if (!(args.RowObject is ModEntry mod))
{
return;
}
// Use Multi-Line editor for notes
if (args.Column == olvColNotes)
{
var tb = new TextBox
{
Multiline = true,
ScrollBars = ScrollBars.Both,
Bounds = args.CellBounds,
};
tb.Height *= 4;
tb.Text = mod.Note?.Replace("\n", "\r\n") ?? "";
args.Control = tb;
}
};

modlist_ListObjectListView.CellEditFinished += (sender, args) =>
{
if (!(args.RowObject is ModEntry mod))
{
return;
}
// Refresh info in mod overview if note was changed in OLV
if (args.Column == olvColNotes)
{
modInfoNotesText.Text = mod.Note;
}
};

RefreshModList();
}
Expand Down Expand Up @@ -1070,7 +1123,7 @@ private ContextMenuStrip CreateModListContextMenu(ModEntry m, OLVListItem curren
if (installedWorkShopMods.Any())
{
unsubscribeItem = new ToolStripMenuItem("Unsubscribe", null, delegate { ConfirmUnsubscribeMods(installedWorkShopMods); });
unsubscribeItem.ToolTipText = "Unsubscribes the selected the mod(s) from the Workshop, but keeps the mod(s) listed in AML, so you can re-subscribe later.";
unsubscribeItem.ToolTipText = "Unsubscribes the selected mod(s) from the Workshop, but keeps the mod(s) listed in AML, so you can re-subscribe later.";
}
}

Expand Down
7 changes: 4 additions & 3 deletions xcom2-launcher/xcom2-launcher/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,6 @@ private void UpdateModDescription(ModEntry m)
modinfo_info_DescriptionRichTextBox.Font = DefaultFont;
modinfo_info_DescriptionRichTextBox.Rtf = m.GetDescription(true);
}

btnDescSave.Enabled = false;
btnDescUndo.Enabled = false;
}

private void UpdateDependencyInformation(ModEntry m)
Expand Down Expand Up @@ -703,6 +700,8 @@ private void UpdateModInfo(ModEntry m)
modinfo_info_InstalledTextBox.Clear();
modinfo_readme_RichTextBox.Clear();
modinfo_changelog_richtextbox.Clear();
modInfoNotesText.Clear();
modInfoNotesText.ReadOnly = true;
UpdateModDescription(null);
modinfo_image_picturebox.ImageLocation = null;
modinfo_inspect_propertygrid.SelectedObject = null;
Expand All @@ -724,6 +723,8 @@ private void UpdateModInfo(ModEntry m)
modinfo_info_AuthorTextBox.Text = m.Author;
modinfo_info_DateCreatedTextBox.Text = m.DateCreated?.ToString() ?? "";
modinfo_info_InstalledTextBox.Text = m.DateAdded?.ToString() ?? "";
modInfoNotesText.Text = m.Note;
modInfoNotesText.ReadOnly = false;
UpdateModDescription(m);
UpdateModChangeLog(m);
modinfo_readme_RichTextBox.Text = m.GetReadMe();
Expand Down
Loading

0 comments on commit 2340cc5

Please sign in to comment.