Skip to content

Commit

Permalink
Merge pull request #226 from elderwyn/bugfix/SkillGump
Browse files Browse the repository at this point in the history
Advanced Skill Gump (sorting + renaming + remember maximized grps)
  • Loading branch information
bittiez committed Apr 10, 2024
2 parents 446fef2 + a482970 commit a337074
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 32 deletions.
37 changes: 25 additions & 12 deletions src/ClassicUO.Client/Game/Managers/SkillsGroupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@

#endregion

using ClassicUO.Assets;
using ClassicUO.Configuration;
using ClassicUO.Game.UI.Gumps;
using ClassicUO.Resources;
using ClassicUO.Utility.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using ClassicUO.Configuration;
using ClassicUO.Game.UI.Gumps;
using ClassicUO.IO;
using ClassicUO.Assets;
using ClassicUO.Resources;
using ClassicUO.Utility.Logging;

namespace ClassicUO.Game.Managers
{
Expand Down Expand Up @@ -165,6 +164,7 @@ public void Save(XmlTextWriter xml)
{
xml.WriteStartElement("group");
xml.WriteAttributeString("name", Name);
xml.WriteAttributeString("isMaximized", IsMaximized.ToString());
xml.WriteStartElement("skillids");

for (int i = 0; i < Count; i++)
Expand All @@ -186,8 +186,16 @@ public void Save(XmlTextWriter xml)

internal static class SkillsGroupManager
{
private static bool _isActive;
public static readonly List<SkillsGroup> Groups = new List<SkillsGroup>();

public static bool IsActive
{
get { return _isActive; }
set
{
_isActive = value;
}
}

public static void Add(SkillsGroup g)
{
Expand Down Expand Up @@ -226,7 +234,7 @@ public static void Load()
if (!File.Exists(path))
{
Log.Trace("No skillsgroups.xml file. Creating a default file.");

MakeDefault();

return;
Expand All @@ -241,21 +249,25 @@ public static void Load()
catch (Exception ex)
{
MakeDefault();

Log.Error(ex.ToString());

return;
}

XmlElement root = doc["skillsgroups"];


XmlElement root = doc["skillsgroups"];
if (root != null)
{
Boolean.TryParse(root.GetAttribute("isActive"), out _isActive);
foreach (XmlElement xml in root.GetElementsByTagName("group"))
{
SkillsGroup g = new SkillsGroup();
g.Name = xml.GetAttribute("name");

Boolean.TryParse(xml.GetAttribute("isMaximized"), out g.IsMaximized);

XmlElement xmlIdsRoot = xml["skillids"];

if (xmlIdsRoot != null)
Expand Down Expand Up @@ -286,6 +298,7 @@ public static void Save()
{
xml.WriteStartDocument(true);
xml.WriteStartElement("skillsgroups");
xml.WriteAttributeString("isActive", IsActive.ToString());

foreach (SkillsGroup k in Groups)
{
Expand Down Expand Up @@ -525,14 +538,14 @@ private static bool LoadMULFile(string path)
{
while ((strbuild = bin.ReadInt16()) != 0)
{
sb.Append((char) strbuild);
sb.Append((char)strbuild);
}
}
else
{
while ((strbuild = bin.ReadByte()) != 0)
{
sb.Append((char) strbuild);
sb.Append((char)strbuild);
}
}

Expand Down
104 changes: 84 additions & 20 deletions src/ClassicUO.Client/Game/UI/Gumps/SkillGumpAdvanced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;

namespace ClassicUO.Game.UI.Gumps
{
Expand All @@ -67,7 +68,6 @@ internal class SkillGumpAdvanced : Gump

public static bool Dragging;

private bool _showGroups;
private bool _sortAsc;
private string _sortField;
private readonly GumpPic _sortOrderIndicator;
Expand Down Expand Up @@ -248,11 +248,12 @@ public SkillGumpAdvanced() : base(0, 0)
0xFF,
1153
));

showGrp.IsChecked = SkillsGroupManager.IsActive;
showGrp.ValueChanged += (sender, e) =>
{
_showGroups = showGrp.IsChecked;
SkillsGroupManager.IsActive = showGrp.IsChecked;
ForceUpdate();
SkillsGroupManager.Save();
};


Expand Down Expand Up @@ -314,19 +315,30 @@ private void BuildGump()
_skillListEntries.Clear();
PropertyInfo pi = typeof(Skill).GetProperty(_sortField);

if (_showGroups)
if (SkillsGroupManager.IsActive)
{
var reversedGroupNames = new List<string>() {
ResGeneral.Miscellaneous,
ResGeneral.Combat,
ResGeneral.TradeSkills,
ResGeneral.Magic,
ResGeneral.Wilderness,
ResGeneral.Thieving,
ResGeneral.Bard,
};

foreach (SkillsGroup g in SkillsGroupManager.Groups.OrderBy(g => reversedGroupNames.Contains(g.Name)).ThenBy(g => g.Name))
SkillsGroupManager.Groups.Sort((s1, s2) =>
{
var m1 = Regex.Match(s1.Name, "^\\d+");
var m2 = Regex.Match(s2.Name, "^\\d+");
if (!m1.Success || !m2.Success)
{
return s1.Name.CompareTo(s2.Name);
}
if (!int.TryParse(m1.Value, out var v1) || !int.TryParse(m2.Value, out var v2))
{
return s1.Name.CompareTo(s2.Name);
}
return v1.CompareTo(v2);
});
if (_sortAsc)
{
SkillsGroupManager.Groups.Reverse();
}

foreach (SkillsGroup g in SkillsGroupManager.Groups)
{
var skillEntries = new List<SkillListEntry>();
var a = new Area();
Expand All @@ -335,9 +347,10 @@ private void BuildGump()
a.CanMove = true;
a.Height = 26;
a.Width = Width - 26;
a.Tag = true;
a.Tag = g.IsMaximized;
a.MouseUp += (sender, e) =>
{
g.IsMaximized = !g.IsMaximized;
var _a = (Area)sender;
var newState = !(bool)_a.Tag;
_a.Tag = newState;
Expand Down Expand Up @@ -376,18 +389,69 @@ private void BuildGump()
{
skillEntries.Add(new SkillListEntry(s));
}
a.Add
(
new ResizePic(0x0BB8)
{
X = 1,
Y = 3,
Width = 180,
Height = 22
}
);
StbTextBox _textbox;
a.Add
(
_textbox = new StbTextBox
(
3,
-1,
200,
false,
FontStyle.Fixed
)
{
X = 5,
Y = 3,
Width = 180,
Height = 17,
IsEditable = false
}
);

_textbox.SetText(g.Name);
_textbox.IsEditable = false;

a.Add(new Label(g.Name, true, 1153, font: 3)
_textbox.MouseDown += (s, e) =>
{
X = 3,
Y = 3
});
if (!g.IsMaximized)
{
a.InvokeMouseUp(e.Location, e.Button);
}
UIManager.KeyboardFocusControl = _textbox;
_textbox.SetKeyboardFocus();
_textbox.IsEditable = true;
_textbox.AllowSelection = true;
};

_textbox.FocusLost += (s, e) =>
{
_textbox.IsEditable = false;
_textbox.AllowSelection = false;
UIManager.KeyboardFocusControl = null;
UIManager.SystemChat.SetFocus();
};
_textbox.TextChanged += (s, e) =>
{
g.Name = _textbox.Text;
};
a.Add(new Label(grpReal.ToString("F1"), true, 1153) { X = 205, Y = 3 });
a.Add(new Label(grpVal.ToString("F1"), true, 1153) { X = 255, Y = 3 });

_databox.Add(a);
foreach (var entry in skillEntries)
{
entry.IsVisible = g.IsMaximized;
_skillListEntries.Add(entry);
_databox.Add(entry);
}
Expand Down

0 comments on commit a337074

Please sign in to comment.