Skip to content

Commit

Permalink
Allow label to pin installed mod version
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jan 18, 2021
1 parent e50b21d commit e49b644
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 16 deletions.
13 changes: 11 additions & 2 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ private void labelMenuItem_Click(object sender, EventArgs e)
{
mlbl.Remove(module.Identifier);
}
if (mlbl.HoldVersion)
{
UpdateAllToolButton.Enabled = mainModList.Modules.Any(mod =>
mod.HasUpdate && !Main.Instance.LabelsHeld(mod.Identifier));
}
mainModList.ReapplyLabels(module, Conflicts?.ContainsKey(module) ?? false, Main.Instance.CurrentInstance.Name);
mainModList.ModuleLabels.Save(ModuleLabelList.DefaultPath);
}
Expand Down Expand Up @@ -400,7 +405,10 @@ public void MarkAllUpdates()
var mod = row.Tag as GUIMod;
if (mod?.HasUpdate ?? false)
{
mod.SetUpgradeChecked(row, UpdateCol, true);
if (!Main.Instance.LabelsHeld(mod.Identifier))
{
mod.SetUpgradeChecked(row, UpdateCol, true);
}
}
}

Expand Down Expand Up @@ -1093,6 +1101,7 @@ private void _UpdateModsList(Dictionary<string, bool> old_modules = null)
Main.Instance.Wait.AddLogMessage(Properties.Resources.MainModListUpdatingFilters);

var has_any_updates = gui_mods.Any(mod => mod.HasUpdate);
var has_unheld_updates = gui_mods.Any(mod => mod.HasUpdate && !Main.Instance.LabelsHeld(mod.Identifier));
var has_any_installed = gui_mods.Any(mod => mod.IsInstalled);
var has_any_replacements = gui_mods.Any(mod => mod.IsInstalled && mod.HasReplacement);

Expand All @@ -1119,7 +1128,7 @@ private void _UpdateModsList(Dictionary<string, bool> old_modules = null)
FilterAllButton.Text = String.Format(Properties.Resources.MainModListAll,
mainModList.CountModsByFilter(GUIModFilter.All));

UpdateAllToolButton.Enabled = has_any_updates;
UpdateAllToolButton.Enabled = has_unheld_updates;
});

(registry as Registry)?.BuildTagIndex(mainModList.ModuleTags);
Expand Down
26 changes: 19 additions & 7 deletions GUI/Dialogs/EditLabelsDialog.Designer.cs

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

26 changes: 19 additions & 7 deletions GUI/Dialogs/EditLabelsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public EditLabelsDialog(IUser user, GameInstanceManager manager, ModuleLabelList
this.ToolTip.SetToolTip(RemoveOnChangesCheckBox, Properties.Resources.EditLabelsToolTipRemoveOnChanges);
this.ToolTip.SetToolTip(AlertOnInstallCheckBox, Properties.Resources.EditLabelsToolTipAlertOnInstall);
this.ToolTip.SetToolTip(RemoveOnInstallCheckBox, Properties.Resources.EditLabelsToolTipRemoveOnInstall);
this.ToolTip.SetToolTip(HoldVersionCheckBox, Properties.Resources.EditLabelsToolTipHoldVersion);
}

private void LoadTree()
Expand All @@ -39,13 +40,21 @@ private void LoadTree()
string groupName = string.IsNullOrEmpty(group.Key)
? Properties.Resources.ModuleLabelListGlobal
: group.Key;
var gnd = LabelSelectionTree.Nodes.Add(groupName);
gnd.NodeFont = new Font(LabelSelectionTree.Font, FontStyle.Bold);
foreach (ModuleLabel mlbl in group.OrderBy(l => l.Name))
{
var lblnd = gnd.Nodes.Add(mlbl.Name);
lblnd.Tag = mlbl;
}
LabelSelectionTree.Nodes.Add(new TreeNode(
groupName,
group.OrderBy(mlbl => mlbl.Name)
.Select(mlbl => new TreeNode(mlbl.Name)
{
// Windows's TreeView has a bug where the node's visual
// width is based on the owning TreeView.Font rather
// than TreeNode.Font, so to ensure there's enough space,
// we have to make the default bold and then override it
// for non-bold nodes.
NodeFont = new Font(LabelSelectionTree.Font, FontStyle.Regular),
Tag = mlbl
})
.ToArray()
));
}
LabelSelectionTree.ExpandAll();
LabelSelectionTree.EndUpdate();
Expand Down Expand Up @@ -159,6 +168,7 @@ private void StartEdit(ModuleLabel lbl)
RemoveOnChangesCheckBox.Checked = lbl.RemoveOnChange;
AlertOnInstallCheckBox.Checked = lbl.AlertOnInstall;
RemoveOnInstallCheckBox.Checked = lbl.RemoveOnInstall;
HoldVersionCheckBox.Checked = lbl.HoldVersion;

DeleteButton.Enabled = labels.Labels.Contains(lbl);

Expand Down Expand Up @@ -209,6 +219,7 @@ private bool TrySave(out string errMsg)
currentlyEditing.RemoveOnChange = RemoveOnChangesCheckBox.Checked;
currentlyEditing.AlertOnInstall = AlertOnInstallCheckBox.Checked;
currentlyEditing.RemoveOnInstall = RemoveOnInstallCheckBox.Checked;
currentlyEditing.HoldVersion = HoldVersionCheckBox.Checked;

EditDetailsPanel.Visible = false;
currentlyEditing = null;
Expand Down Expand Up @@ -267,6 +278,7 @@ private bool HasChanges()
|| currentlyEditing.RemoveOnChange != RemoveOnChangesCheckBox.Checked
|| currentlyEditing.AlertOnInstall != AlertOnInstallCheckBox.Checked
|| currentlyEditing.RemoveOnInstall != RemoveOnInstallCheckBox.Checked
|| currentlyEditing.HoldVersion != HoldVersionCheckBox.Checked
);
}

Expand Down
1 change: 1 addition & 0 deletions GUI/Dialogs/EditLabelsDialog.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<data name="RemoveOnChangesCheckBox.Text" xml:space="preserve"><value>Remove on updates</value></data>
<data name="AlertOnInstallCheckBox.Text" xml:space="preserve"><value>Alert on install</value></data>
<data name="RemoveOnInstallCheckBox.Text" xml:space="preserve"><value>Remove on install</value></data>
<data name="HoldVersionCheckBox.Text" xml:space="preserve"><value>Don't upgrade</value></data>
<data name="CloseButton.Text" xml:space="preserve"><value>Close</value></data>
<data name="SaveButton.Text" xml:space="preserve"><value>Save</value></data>
<data name="CancelEditButton.Text" xml:space="preserve"><value>Cancel</value></data>
Expand Down
4 changes: 4 additions & 0 deletions GUI/Labels/ModuleLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class ModuleLabel
[DefaultValue(false)]
public bool RemoveOnInstall;

[JsonProperty("hold_version", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
[DefaultValue(false)]
public bool HoldVersion;

[JsonProperty("module_identifiers", NullValueHandling = NullValueHandling.Ignore)]
public HashSet<string> ModuleIdentifiers = new HashSet<string>();

Expand Down
6 changes: 6 additions & 0 deletions GUI/Labels/ModuleLabelList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public static ModuleLabelList GetDefaultLabels()
Hide = true,
Color = Color.PaleVioletRed,
},
new ModuleLabel()
{
Name = Properties.Resources.ModuleLabelListHeld,
HoldVersion = true,
Color = Color.FromArgb(255, 255, 176),
}
}
};
}
Expand Down
6 changes: 6 additions & 0 deletions GUI/Main/MainLabels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ private void LabelsAfterInstall(CkanModule mod)
}
}

public bool LabelsHeld(string identifier)
{
return ManageMods.mainModList.ModuleLabels.LabelsFor(CurrentInstance.Name)
.Any(l => l.HoldVersion && l.ModuleIdentifiers.Contains(identifier));
}

#endregion
}
}
6 changes: 6 additions & 0 deletions GUI/Properties/Resources.Designer.cs

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

2 changes: 2 additions & 0 deletions GUI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ Do you want to allow CKAN to do this? If you click no you won't see this message
<data name="StatusInstanceLabelText" xml:space="preserve"><value>Game instance: {0} ({1} {2})</value></data>
<data name="ModuleLabelListFavourites" xml:space="preserve"><value>Favourites</value></data>
<data name="ModuleLabelListHidden" xml:space="preserve"><value>Hidden</value></data>
<data name="ModuleLabelListHeld" xml:space="preserve"><value>Held</value></data>
<data name="ModuleLabelListGlobal" xml:space="preserve"><value>Global</value></data>
<data name="EditLabelsDialogConfirmDelete" xml:space="preserve"><value>Are you sure you want to delete {0}? This can't be undone!</value></data>
<data name="EditLabelsDialogSavePrompt" xml:space="preserve"><value>Save changes?</value></data>
Expand All @@ -373,6 +374,7 @@ Do you want to allow CKAN to do this? If you click no you won't see this message
<data name="EditLabelsToolTipRemoveOnChanges" xml:space="preserve"><value>If checked, a module that changes from incompatible to compatible will be removed from this label</value></data>
<data name="EditLabelsToolTipAlertOnInstall" xml:space="preserve"><value>If checked, the change set screen will alert you if this mod is about to be installed</value></data>
<data name="EditLabelsToolTipRemoveOnInstall" xml:space="preserve"><value>If checked, modules will be removed from this label if they are installed</value></data>
<data name="EditLabelsToolTipHoldVersion" xml:space="preserve"><value>If checked, modules will not be upgraded</value></data>
<data name="MainLabelsUpdateMessage" xml:space="preserve"><value>Some of your watched mods have updated:

{0}</value></data>
Expand Down

0 comments on commit e49b644

Please sign in to comment.