From 704fa991bf58afe30c9be0927a62d3681fe749f5 Mon Sep 17 00:00:00 2001 From: Tad Taylor Date: Mon, 27 Mar 2023 07:59:28 -0600 Subject: [PATCH 1/8] Started work on grid property highlighting --- .../Game/UI/Gumps/GridHightlightMenu.cs | 97 +++++++++++++++++++ .../Game/UI/Gumps/OptionsGump.cs | 15 ++- 2 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs new file mode 100644 index 0000000000..2edbcc5c42 --- /dev/null +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs @@ -0,0 +1,97 @@ +using ClassicUO.Game.UI.Controls; +using ClassicUO.Renderer; +using Microsoft.Xna.Framework; +using static ClassicUO.Game.UI.Gumps.OptionsGump; + +namespace ClassicUO.Game.UI.Gumps +{ + internal class GridHightlightMenu : Gump + { + private const int WIDTH = 350, HEIGHT = 600; + private AlphaBlendControl background; + private SettingsSection highlightSection; + + public GridHightlightMenu() : base(0, 0) + { + #region SET VARS + Width = WIDTH; + Height = HEIGHT; + CanMove = true; + AcceptMouseInput = true; + CanCloseWithRightClick = true; + #endregion + + BuildGump(); + } + + private void BuildGump() + { + { + background = new AlphaBlendControl(0.85f); + background.Width = WIDTH; + background.Height = HEIGHT; + Add(background); + }//Background + int y = 0; + { + SettingsSection section = new SettingsSection("Grid highlighting settings", WIDTH); + section.Add(new Label("You can add object properties that you would like the grid to be highlighted for here.", true, 0xffff, WIDTH)); + + NiceButton _; + section.Add(_ = new NiceButton(0, 0, 40, 20, ButtonAction.Activate, "Add") { IsSelectable = false }); + _.MouseUp += (s, e) => + { + if (e.Button == Input.MouseButtonType.Left) + { + highlightSection?.Add(NewAreaSection()); + } + }; + + Add(section); + y = section.Y + section.Height; + }//Top section + + highlightSection = new SettingsSection("", WIDTH) { Y = y }; + + Add(highlightSection); + } + + private Area NewAreaSection() + { + Area area = new Area(); + area.Width = WIDTH - 30; + area.Height = 150; + int y = 0; + area.Add(new NiceButton(0, y, 120, 20, ButtonAction.Activate, "Add property")); + + ModernColorPicker.HueDisplay hueDisplay; + area.Add(hueDisplay = new ModernColorPicker.HueDisplay(0, null, true) { X = 150, Y = y }); + hueDisplay.SetTooltip("Select grid highlight hue"); + + y += 20; + + area.Add(new Label("Property name", true, 0xffff, 120) { X = 0, Y = y }); + area.Add(new Label("Min value", true, 0xffff, 120) { X = 200, Y = y }); + + y += 20; + + area.Add(new InputField(0x0BB8, 0xFF, 0xFFFF, true, 150, 20) { Y = y }); + + return area; + } + + public override bool Draw(UltimaBatcher2D batcher, int x, int y) + { + base.Draw(batcher, x, y); + + batcher.DrawRectangle( + SolidColorTextureCache.GetTexture(Color.LightGray), + x - 1, y - 1, + WIDTH + 2, HEIGHT + 2, + new Vector3(0, 0, 1) + ); + + return true; + } + } +} diff --git a/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs index dad128a839..7a583a2221 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs @@ -82,7 +82,6 @@ internal class OptionsGump : Gump private HSliderBar _containerOpacity, _gridBorderOpacity, _gridContainerScale; private InputField _gridDefaultColumns, _gridDefaultRows; - //counters private Checkbox _enableCounters, _highlightOnUse, _highlightOnAmount, _enableAbbreviatedAmount; private Checkbox _enableDragSelect, _dragSelectHumanoidsOnly; @@ -3769,6 +3768,16 @@ private void BuildContainers() _gridDefaultColumns.SetText(_currentProfile.Grid_DefaultColumns.ToString()); } //Grid default rows and columns + { + NiceButton _; + gridSection.Add(_ = new NiceButton(X, 0, 150, TEXTBOX_HEIGHT, ButtonAction.Activate, "Grid highlight settings")); + _.IsSelectable = false; + _.MouseUp += (s, e) => { + UIManager.GetGump()?.Dispose(); + UIManager.Add(new GridHightlightMenu()); + }; + } //Grid highlight settings + rightArea.Add(gridSection); #endregion @@ -5098,7 +5107,7 @@ private enum Buttons } - private class SettingsSection : Control + public class SettingsSection : Control { private readonly DataBox _databox; private int _indent; @@ -5259,7 +5268,7 @@ public void SetSelectedFont(int index) } } - private class InputField : Control + public class InputField : Control { private readonly StbTextBox _textbox; From d816cb1cf7e6727e7d46b22dee20637f9d947a1d Mon Sep 17 00:00:00 2001 From: Tad Taylor Date: Tue, 28 Mar 2023 03:33:07 -0600 Subject: [PATCH 2/8] Started work on grid highlighting properties --- src/ClassicUO.Client/Configuration/Profile.cs | 7 + .../Game/UI/Gumps/GridHightlightMenu.cs | 170 ++++++++++++++++-- 2 files changed, 165 insertions(+), 12 deletions(-) diff --git a/src/ClassicUO.Client/Configuration/Profile.cs b/src/ClassicUO.Client/Configuration/Profile.cs index a4ae515cda..6faeb2dd6f 100644 --- a/src/ClassicUO.Client/Configuration/Profile.cs +++ b/src/ClassicUO.Client/Configuration/Profile.cs @@ -375,6 +375,13 @@ public int CoolDownConditionCount public ushort DamageHueOther { get; set; } = 0x0021; #endregion + #region GridHighlightingProps + public List GridHighlight_Name { get; set; } = new List(); + public List GridHighlight_Hue { get; set; } = new List(); + public List> GridHighlight_PropNames { get; set; } = new List>(); + public List> GridHighlight_PropMinVal { get; set; } = new List>(); + #endregion + public static uint GumpsVersion { get; private set; } public void Save(string path) diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs index 2edbcc5c42..0385223a9e 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs @@ -1,13 +1,18 @@ -using ClassicUO.Game.UI.Controls; +using ClassicUO.Assets; +using ClassicUO.Configuration; +using ClassicUO.Game.Managers; +using ClassicUO.Game.UI.Controls; using ClassicUO.Renderer; using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; using static ClassicUO.Game.UI.Gumps.OptionsGump; namespace ClassicUO.Game.UI.Gumps { internal class GridHightlightMenu : Gump { - private const int WIDTH = 350, HEIGHT = 600; + private const int WIDTH = 350, HEIGHT = 500; private AlphaBlendControl background; private SettingsSection highlightSection; @@ -19,6 +24,8 @@ public GridHightlightMenu() : base(0, 0) CanMove = true; AcceptMouseInput = true; CanCloseWithRightClick = true; + X = 100; + Y = 100; #endregion BuildGump(); @@ -43,7 +50,7 @@ private void BuildGump() { if (e.Button == Input.MouseButtonType.Left) { - highlightSection?.Add(NewAreaSection()); + highlightSection?.Add(NewAreaSection(ProfileManager.CurrentProfile.GridHighlight_Name.Count)); } }; @@ -53,30 +60,43 @@ private void BuildGump() highlightSection = new SettingsSection("", WIDTH) { Y = y }; + for (int i = 0; i < ProfileManager.CurrentProfile.GridHighlight_Name.Count; i++) + { + highlightSection.Add(NewAreaSection(i)); + } + Add(highlightSection); } - private Area NewAreaSection() + private Area NewAreaSection(int keyLoc) { + GridHighlightData data = GridHighlightData.GetGridHighlightData(keyLoc); Area area = new Area(); area.Width = WIDTH - 30; area.Height = 150; int y = 0; - area.Add(new NiceButton(0, y, 120, 20, ButtonAction.Activate, "Add property")); + + NiceButton _button; + area.Add(_button = new NiceButton(WIDTH - 170, y, 120, 20, ButtonAction.Activate, "Open property menu") { IsSelectable = false }); + _button.MouseUp += (s, e) => + { + if (e.Button == Input.MouseButtonType.Left) + { + UIManager.GetGump()?.Dispose(); + UIManager.Add(new GridHightlightProperties(keyLoc, 100, 100)); + } + }; ModernColorPicker.HueDisplay hueDisplay; - area.Add(hueDisplay = new ModernColorPicker.HueDisplay(0, null, true) { X = 150, Y = y }); + area.Add(hueDisplay = new ModernColorPicker.HueDisplay(data.Hue, null, true) { X = 150, Y = y }); hueDisplay.SetTooltip("Select grid highlight hue"); - y += 20; - - area.Add(new Label("Property name", true, 0xffff, 120) { X = 0, Y = y }); - area.Add(new Label("Min value", true, 0xffff, 120) { X = 200, Y = y }); + InputField _name; + area.Add(_name = new InputField(0x0BB8, 0xFF, 0xFFFF, true, 140, 20) { X = 0, Y = y }); + _name.SetText(data.Name); y += 20; - area.Add(new InputField(0x0BB8, 0xFF, 0xFFFF, true, 150, 20) { Y = y }); - return area; } @@ -93,5 +113,131 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y) return true; } + + private class GridHighlightData + { + + public readonly string Name; + public readonly ushort Hue; + public readonly List Properties; + public readonly List PropMinVal; + + private GridHighlightData(int keyLoc) + { + if(ProfileManager.CurrentProfile.GridHighlight_Name.Count > keyLoc) //Key exists? + { + Name = ProfileManager.CurrentProfile.GridHighlight_Name[keyLoc]; + Hue = ProfileManager.CurrentProfile.GridHighlight_Hue[keyLoc]; + Properties = ProfileManager.CurrentProfile.GridHighlight_PropNames[keyLoc]; + PropMinVal = ProfileManager.CurrentProfile.GridHighlight_PropMinVal[keyLoc]; + } else + { + Name = "Name"; + ProfileManager.CurrentProfile.GridHighlight_Name.Add(Name); + Hue = 1; + ProfileManager.CurrentProfile.GridHighlight_Hue.Add(Hue); + Properties = new List(); + ProfileManager.CurrentProfile.GridHighlight_PropNames.Add(Properties); + PropMinVal = new List(); + ProfileManager.CurrentProfile.GridHighlight_PropMinVal.Add(PropMinVal); + } + } + + public static GridHighlightData GetGridHighlightData(int keyLoc) + { + return new GridHighlightData(keyLoc); + } + } + + private class GridHightlightProperties : Gump + { + private int lastYitem = 0; + private ScrollArea scrollArea; + GridHighlightData data; + + public GridHightlightProperties(int keyLoc, int x, int y) : base(0, 0) + { + data = GridHighlightData.GetGridHighlightData(keyLoc); + X = x; + Y = y; + Width = WIDTH; + Height = HEIGHT; + CanMove = true; + AcceptMouseInput = true; + CanCloseWithRightClick = true; + + Add(new AlphaBlendControl(0.85f) { Width = WIDTH, Height = HEIGHT }); + + NiceButton _addPropertyButton, _save; + Add(_addPropertyButton = new NiceButton(0, 0, 120, 20, ButtonAction.Activate, "Add property") { IsSelectable = false }); + _addPropertyButton.MouseUp += (s, e) => + { + if (e.Button == Input.MouseButtonType.Left) + { + AddProperty(); + + lastYitem += 20; + } + }; + + Add(_save = new NiceButton(WIDTH - 60, 0, 60, 20, ButtonAction.Activate, "Save") { IsSelectable = false }); + _save.MouseUp += (o, e) => { + if (e.Button == Input.MouseButtonType.Left) + { + Add(new FadingLabel(5, "Saved", true, 0xff) { X = _save.X, Y = _save.Y + 20 }); + } + }; + + Add(scrollArea = new ScrollArea(0, 20, WIDTH, HEIGHT - 20, true) { ScrollbarBehaviour = ScrollbarBehaviour.ShowAlways }); + + scrollArea.Add(new Label("Property name", true, 0xffff, 120) { X = 0, Y = lastYitem }); + scrollArea.Add(new Label("Min value", true, 0xffff, 120) { X = 200, Y = lastYitem }); + + lastYitem += 20; + + + + } + + private void AddProperty() + { + scrollArea.Add(new InputField(0x0BB8, 0xFF, 0xFFFF, true, 150, 20) { Y = lastYitem }); + scrollArea.Add(new InputField(0x0BB8, 0xFF, 0xFFFF, true, 100, 20) { X = 200, Y = lastYitem, NumbersOnly = true }); + } + + public override bool Draw(UltimaBatcher2D batcher, int x, int y) + { + base.Draw(batcher, x, y); + + batcher.DrawRectangle( + SolidColorTextureCache.GetTexture(Color.LightGray), + x - 1, y - 1, + WIDTH + 2, HEIGHT + 2, + new Vector3(0, 0, 1) + ); + + return true; + } + } + + private class FadingLabel : Label + { + private readonly int tickSpeed; + private int c = 0; + public FadingLabel(int tickSpeed, string text, bool isunicode, ushort hue, int maxwidth = 0, byte font = 255, FontStyle style = FontStyle.None, TEXT_ALIGN_TYPE align = TEXT_ALIGN_TYPE.TS_LEFT, bool ishtml = false) : base(text, isunicode, hue, maxwidth, font, style, align, ishtml) + { + this.tickSpeed = tickSpeed; + } + + public override bool Draw(UltimaBatcher2D batcher, int x, int y) + { + if(c>=tickSpeed) + Alpha -= 0.01f; + if (Alpha <= 0f) + Dispose(); + c++; + return base.Draw(batcher, x, y); + } + } } } From 392df3d6fbee1edf1974c8bfbfaaa10e93e2d2b8 Mon Sep 17 00:00:00 2001 From: elderwyn Date: Tue, 28 Mar 2023 08:14:48 -0400 Subject: [PATCH 3/8] Bugfix to Resolve Multiple Vendor Containers --- src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs index c4f472c3d5..cd94491e0c 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs @@ -100,7 +100,7 @@ public GridContainer(uint local, ushort ogContainer) : base(GetWidth(), GetHeigh { if (m.NotorietyFlag == NotorietyFlag.Invulnerable && m.Serial != World.Player.Serial) { - OpenOldContainer(ogContainer); + OpenOldContainer(local); } } From a2e19b2605c47d99bcfe9cb27fdb131ed216792e Mon Sep 17 00:00:00 2001 From: Tad Taylor Date: Tue, 28 Mar 2023 16:47:37 -0600 Subject: [PATCH 4/8] Finished up the highlight save/edit/delete functions --- .../Game/UI/Gumps/GridHightlightMenu.cs | 222 ++++++++++++++---- .../Game/UI/Gumps/ModernColorPicker.cs | 4 +- .../Game/UI/Gumps/OptionsGump.cs | 2 + 3 files changed, 183 insertions(+), 45 deletions(-) diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs index 0385223a9e..5733062b3a 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs @@ -6,6 +6,7 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; +using System.Threading.Tasks; using static ClassicUO.Game.UI.Gumps.OptionsGump; namespace ClassicUO.Game.UI.Gumps @@ -15,8 +16,9 @@ internal class GridHightlightMenu : Gump private const int WIDTH = 350, HEIGHT = 500; private AlphaBlendControl background; private SettingsSection highlightSection; + private ScrollArea highlightSectionScroll; - public GridHightlightMenu() : base(0, 0) + public GridHightlightMenu(int x=100, int y = 100) : base(0, 0) { #region SET VARS Width = WIDTH; @@ -24,8 +26,8 @@ public GridHightlightMenu() : base(0, 0) CanMove = true; AcceptMouseInput = true; CanCloseWithRightClick = true; - X = 100; - Y = 100; + X = x; + Y = y; #endregion BuildGump(); @@ -45,12 +47,13 @@ private void BuildGump() section.Add(new Label("You can add object properties that you would like the grid to be highlighted for here.", true, 0xffff, WIDTH)); NiceButton _; - section.Add(_ = new NiceButton(0, 0, 40, 20, ButtonAction.Activate, "Add") { IsSelectable = false }); + section.Add(_ = new NiceButton(0, 0, 40, 20, ButtonAction.Activate, "Add +") { IsSelectable = false }); _.MouseUp += (s, e) => { if (e.Button == Input.MouseButtonType.Left) { - highlightSection?.Add(NewAreaSection(ProfileManager.CurrentProfile.GridHighlight_Name.Count)); + highlightSectionScroll?.Add(NewAreaSection(ProfileManager.CurrentProfile.GridHighlight_Name.Count, y)); + y += 21; } }; @@ -59,25 +62,28 @@ private void BuildGump() }//Top section highlightSection = new SettingsSection("", WIDTH) { Y = y }; + highlightSection.Add(highlightSectionScroll = new ScrollArea(0, 0, WIDTH - 20, Height - y - 10, true) { ScrollbarBehaviour = ScrollbarBehaviour.ShowAlways }); ; + y = 0; for (int i = 0; i < ProfileManager.CurrentProfile.GridHighlight_Name.Count; i++) { - highlightSection.Add(NewAreaSection(i)); + highlightSectionScroll.Add(NewAreaSection(i, y)); + y += 21; } Add(highlightSection); } - private Area NewAreaSection(int keyLoc) + private Area NewAreaSection(int keyLoc, int y) { GridHighlightData data = GridHighlightData.GetGridHighlightData(keyLoc); - Area area = new Area(); - area.Width = WIDTH - 30; + Area area = new Area() { Y = y }; + area.Width = WIDTH - 40; area.Height = 150; - int y = 0; + y = 0; - NiceButton _button; - area.Add(_button = new NiceButton(WIDTH - 170, y, 120, 20, ButtonAction.Activate, "Open property menu") { IsSelectable = false }); + NiceButton _button, _del; + area.Add(_button = new NiceButton(WIDTH - 170, y, 130, 20, ButtonAction.Activate, "Open property menu") { IsSelectable = false }); _button.MouseUp += (s, e) => { if (e.Button == Input.MouseButtonType.Left) @@ -90,11 +96,42 @@ private Area NewAreaSection(int keyLoc) ModernColorPicker.HueDisplay hueDisplay; area.Add(hueDisplay = new ModernColorPicker.HueDisplay(data.Hue, null, true) { X = 150, Y = y }); hueDisplay.SetTooltip("Select grid highlight hue"); + hueDisplay.HueChanged += (s, e) => + { + data.Hue = hueDisplay.Hue; + area.Add(new FadingLabel(10, "Saved", true, 0xff) { X = hueDisplay.X - 40, Y = hueDisplay.Y }); + }; InputField _name; - area.Add(_name = new InputField(0x0BB8, 0xFF, 0xFFFF, true, 140, 20) { X = 0, Y = y }); + area.Add(_name = new InputField(0x0BB8, 0xFF, 0xFFFF, true, 120, 20) { X = 25, Y = y, AcceptKeyboardInput = true }); _name.SetText(data.Name); + _name.TextChanged += (s, e) => + { + Task.Factory.StartNew(() => + { + var tVal = _name.Text; + System.Threading.Thread.Sleep(2500); + if (_name.Text == tVal) + { + data.Name = _name.Text; + area.Add(new FadingLabel(10, "Saved", true, 0xff) { X = _name.X, Y = _name.Y - 20 }); + } + }); + }; + + area.Add(_del = new NiceButton(0, y, 20, 20, ButtonAction.Activate, "X") { IsSelectable = false }); + _del.SetTooltip("Delete this highlight configuration"); + _del.MouseUp += (s, e) => + { + if (e.Button == Input.MouseButtonType.Left) + { + data.Delete(); + Dispose(); + UIManager.Add(new GridHightlightMenu(X, Y)); + } + }; + y += 20; return area; @@ -116,31 +153,68 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y) private class GridHighlightData { + private string name; + private ushort hue; + private List properties; + private List propMinVal; + private readonly int keyLoc; + + public string Name { get { return name; } set { name = value; SaveName(); } } + public ushort Hue { get { return hue; } set { hue = value; SaveHue(); } } + public List Properties { get { return properties; } set { properties = value; SaveProps(); } } + public List PropMinVal { get { return propMinVal; } set { propMinVal = value; SaveMinVals(); } } - public readonly string Name; - public readonly ushort Hue; - public readonly List Properties; - public readonly List PropMinVal; private GridHighlightData(int keyLoc) { - if(ProfileManager.CurrentProfile.GridHighlight_Name.Count > keyLoc) //Key exists? + if (ProfileManager.CurrentProfile.GridHighlight_Name.Count > keyLoc) //Key exists? { - Name = ProfileManager.CurrentProfile.GridHighlight_Name[keyLoc]; - Hue = ProfileManager.CurrentProfile.GridHighlight_Hue[keyLoc]; - Properties = ProfileManager.CurrentProfile.GridHighlight_PropNames[keyLoc]; - PropMinVal = ProfileManager.CurrentProfile.GridHighlight_PropMinVal[keyLoc]; - } else + name = ProfileManager.CurrentProfile.GridHighlight_Name[keyLoc]; + hue = ProfileManager.CurrentProfile.GridHighlight_Hue[keyLoc]; + properties = ProfileManager.CurrentProfile.GridHighlight_PropNames[keyLoc]; + propMinVal = ProfileManager.CurrentProfile.GridHighlight_PropMinVal[keyLoc]; + } + else { - Name = "Name"; + name = "Name"; ProfileManager.CurrentProfile.GridHighlight_Name.Add(Name); - Hue = 1; + hue = 1; ProfileManager.CurrentProfile.GridHighlight_Hue.Add(Hue); - Properties = new List(); + properties = new List(); ProfileManager.CurrentProfile.GridHighlight_PropNames.Add(Properties); - PropMinVal = new List(); + propMinVal = new List(); ProfileManager.CurrentProfile.GridHighlight_PropMinVal.Add(PropMinVal); } + + this.keyLoc = keyLoc; + } + + private void SaveName() + { + ProfileManager.CurrentProfile.GridHighlight_Name[keyLoc] = name; + } + + private void SaveHue() + { + ProfileManager.CurrentProfile.GridHighlight_Hue[keyLoc] = hue; + } + + private void SaveProps() + { + ProfileManager.CurrentProfile.GridHighlight_PropNames[keyLoc] = properties; + } + + private void SaveMinVals() + { + ProfileManager.CurrentProfile.GridHighlight_PropMinVal[keyLoc] = propMinVal; + } + + public void Delete() + { + ProfileManager.CurrentProfile.GridHighlight_Name.RemoveAt(keyLoc); + ProfileManager.CurrentProfile.GridHighlight_Hue.RemoveAt(keyLoc); + ProfileManager.CurrentProfile.GridHighlight_PropNames.RemoveAt(keyLoc); + ProfileManager.CurrentProfile.GridHighlight_PropMinVal.RemoveAt(keyLoc); } public static GridHighlightData GetGridHighlightData(int keyLoc) @@ -154,6 +228,7 @@ private class GridHightlightProperties : Gump private int lastYitem = 0; private ScrollArea scrollArea; GridHighlightData data; + private readonly int keyLoc; public GridHightlightProperties(int keyLoc, int x, int y) : base(0, 0) { @@ -168,41 +243,93 @@ public GridHightlightProperties(int keyLoc, int x, int y) : base(0, 0) Add(new AlphaBlendControl(0.85f) { Width = WIDTH, Height = HEIGHT }); - NiceButton _addPropertyButton, _save; + NiceButton _addPropertyButton; Add(_addPropertyButton = new NiceButton(0, 0, 120, 20, ButtonAction.Activate, "Add property") { IsSelectable = false }); _addPropertyButton.MouseUp += (s, e) => { if (e.Button == Input.MouseButtonType.Left) { - AddProperty(); + AddProperty(data.Properties.Count); lastYitem += 20; } }; - Add(_save = new NiceButton(WIDTH - 60, 0, 60, 20, ButtonAction.Activate, "Save") { IsSelectable = false }); - _save.MouseUp += (o, e) => { - if (e.Button == Input.MouseButtonType.Left) - { - Add(new FadingLabel(5, "Saved", true, 0xff) { X = _save.X, Y = _save.Y + 20 }); - } - }; - Add(scrollArea = new ScrollArea(0, 20, WIDTH, HEIGHT - 20, true) { ScrollbarBehaviour = ScrollbarBehaviour.ShowAlways }); scrollArea.Add(new Label("Property name", true, 0xffff, 120) { X = 0, Y = lastYitem }); - scrollArea.Add(new Label("Min value", true, 0xffff, 120) { X = 200, Y = lastYitem }); + scrollArea.Add(new Label("Min value", true, 0xffff, 120) { X = 180, Y = lastYitem }); lastYitem += 20; + for (int i = 0; i < data.Properties.Count; i++) + { + AddProperty(i); + lastYitem += 20; + } - + this.keyLoc = keyLoc; } - private void AddProperty() - { - scrollArea.Add(new InputField(0x0BB8, 0xFF, 0xFFFF, true, 150, 20) { Y = lastYitem }); - scrollArea.Add(new InputField(0x0BB8, 0xFF, 0xFFFF, true, 100, 20) { X = 200, Y = lastYitem, NumbersOnly = true }); + private void AddProperty(int subKeyLoc) + { + while (data.Properties.Count <= subKeyLoc) + { + data.Properties.Add(""); + data.PropMinVal.Add(-1); + } + InputField propInput, valInput; + scrollArea.Add(propInput = new InputField(0x0BB8, 0xFF, 0xFFFF, true, 150, 20) { Y = lastYitem }); + propInput.SetText(data.Properties[subKeyLoc]); + propInput.TextChanged += (s, e) => + { + Task.Factory.StartNew(() => + { + var tVal = propInput.Text; + System.Threading.Thread.Sleep(2500); + if (propInput.Text == tVal) + { + data.Properties[subKeyLoc] = propInput.Text; + propInput.Add(new FadingLabel(10, "Saved", true, 0xff) { X = 0, Y = -20 }); + } + }); + }; + + scrollArea.Add(valInput = new InputField(0x0BB8, 0xFF, 0xFFFF, true, 100, 20) { X = 180, Y = lastYitem, NumbersOnly = true }); + valInput.SetText(data.PropMinVal[subKeyLoc].ToString()); + valInput.TextChanged += (s, e) => + { + Task.Factory.StartNew(() => + { + var tVal = valInput.Text; + System.Threading.Thread.Sleep(2500); + if (valInput.Text == tVal) + { + if (int.TryParse(valInput.Text, out int val)) + { + data.PropMinVal[subKeyLoc] = val; + valInput.Add(new FadingLabel(10, "Saved", true, 0xff) { X = 0, Y = -20 }); + } + else + { + valInput.Add(new FadingLabel(20, "Couldn't parse number", true, 0xff) { X = 0, Y = -20 }); + } + } + }); + }; + + NiceButton _del; + scrollArea.Add(_del = new NiceButton(285, lastYitem, 20, 20, ButtonAction.Activate, "X") { IsSelectable = false }); + _del.SetTooltip("Delete this property"); + _del.MouseUp += (s, e) => { + if(e.Button == Input.MouseButtonType.Left) + { + Dispose(); + data.Properties.RemoveAt(subKeyLoc); + data.PropMinVal.RemoveAt(subKeyLoc); + UIManager.Add(new GridHightlightProperties(keyLoc, X, Y)); + } + }; } public override bool Draw(UltimaBatcher2D batcher, int x, int y) @@ -224,6 +351,7 @@ private class FadingLabel : Label { private readonly int tickSpeed; private int c = 0; + public FadingLabel(int tickSpeed, string text, bool isunicode, ushort hue, int maxwidth = 0, byte font = 255, FontStyle style = FontStyle.None, TEXT_ALIGN_TYPE align = TEXT_ALIGN_TYPE.TS_LEFT, bool ishtml = false) : base(text, isunicode, hue, maxwidth, font, style, align, ishtml) { this.tickSpeed = tickSpeed; @@ -231,11 +359,17 @@ public FadingLabel(int tickSpeed, string text, bool isunicode, ushort hue, int m public override bool Draw(UltimaBatcher2D batcher, int x, int y) { - if(c>=tickSpeed) + if (c >= tickSpeed) Alpha -= 0.01f; if (Alpha <= 0f) Dispose(); c++; + + batcher.Draw(SolidColorTextureCache.GetTexture(Color.Green), + new Rectangle(x, y, Width, Height), + new Vector3(1, 0, Alpha) + ); + return base.Draw(batcher, x, y); } } diff --git a/src/ClassicUO.Client/Game/UI/Gumps/ModernColorPicker.cs b/src/ClassicUO.Client/Game/UI/Gumps/ModernColorPicker.cs index a5abe4ccea..62e2669859 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/ModernColorPicker.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/ModernColorPicker.cs @@ -109,7 +109,9 @@ public class HueDisplay : Control private float flashAlpha = 1f; private bool rev = false; - public ushort Hue { get { return hue; } set { hue = value; } } + public ushort Hue { get { return hue; } set { hue = value; HueChanged?.Invoke(this, null); } } + + public event EventHandler HueChanged; public HueDisplay(ushort hue, Action hueChanged, bool isClickable = false) { diff --git a/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs b/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs index 7a583a2221..c5db660c6a 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/OptionsGump.cs @@ -5272,6 +5272,8 @@ public class InputField : Control { private readonly StbTextBox _textbox; + public event EventHandler TextChanged { add { _textbox.TextChanged += value; } remove { _textbox.TextChanged -= value; } } + public InputField ( ushort backgroundGraphic, From 9ddf54b136a98b7dfd680551848f5f1adafe0310 Mon Sep 17 00:00:00 2001 From: Tad Taylor Date: Tue, 28 Mar 2023 18:49:20 -0600 Subject: [PATCH 5/8] Added applyhighlight method for grid highlighting --- src/ClassicUO.Client/Configuration/Profile.cs | 1 + .../Game/UI/Gumps/GridContainer.cs | 60 +++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/ClassicUO.Client/Configuration/Profile.cs b/src/ClassicUO.Client/Configuration/Profile.cs index 6faeb2dd6f..dcfb5da3cf 100644 --- a/src/ClassicUO.Client/Configuration/Profile.cs +++ b/src/ClassicUO.Client/Configuration/Profile.cs @@ -380,6 +380,7 @@ public int CoolDownConditionCount public List GridHighlight_Hue { get; set; } = new List(); public List> GridHighlight_PropNames { get; set; } = new List>(); public List> GridHighlight_PropMinVal { get; set; } = new List>(); + public bool GridHighlight_CorpseOnly { get; set; } = false; #endregion public static uint GumpsVersion { get; private set; } diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs index cd94491e0c..cc5f671e9f 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs @@ -34,6 +34,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; using ClassicUO.Assets; @@ -430,9 +432,6 @@ public override void Dispose() _lastX = X; _lastY = Y; - if (gridSlotManager.ItemPositions.Count > 0 && !_container.IsCorpse) - gridSaveSystem.SaveContainer(LocalSerial, gridSlotManager.ItemPositions, Width, Height, X, Y); - if (_container != null) { if (_container == SelectedObject.CorpseObject) @@ -441,6 +440,9 @@ public override void Dispose() } } + if (gridSlotManager.ItemPositions.Count > 0 && !_container.IsCorpse) + gridSaveSystem.SaveContainer(LocalSerial, gridSlotManager.ItemPositions, Width, Height, X, Y); + base.Dispose(); } @@ -640,7 +642,10 @@ public GridItem(uint serial, int size, Item _container, GridContainer gridContai hit.MouseDoubleClick += _hit_MouseDoubleClick; } - + public void SetBackgroundHue(ushort hue) + { + background.Hue = hue; + } public void Resize() { @@ -714,6 +719,7 @@ private void _hit_MouseUp(object sender, MouseEventArgs e) Rectangle containerBounds = ContainerManager.Get(container.Graphic).Bounds; gridContainer.gridSlotManager.AddLockedItemSlot(Client.Game.GameCursor.ItemHold.Serial, slot); GameActions.DropItem(Client.Game.GameCursor.ItemHold.Serial, containerBounds.X / 2, containerBounds.Y / 2, 0, container.Serial); + gridContainer.gridSlotManager.ApplyHighlightProperties(); } } else if (TargetManager.IsTargeting) @@ -951,6 +957,7 @@ public void AddLockedItemSlot(uint serial, int specificSlot) if (ItemPositions.ContainsKey(specificSlot)) //Is the slot they wanted this item in already taken? Lets remove that item ItemPositions.Remove(specificSlot); ItemPositions.Add(specificSlot, serial); //Now we add this item at the desired slot + ApplyHighlightProperties(); } public void RebuildContainer(List filteredItems, string searchText = "", bool overrideSort = false) @@ -1003,6 +1010,8 @@ public void RebuildContainer(List filteredItems, string searchText = "", b } } } + + ApplyHighlightProperties(); } private void SetGridPositions() @@ -1086,6 +1095,49 @@ public static List GetItemsInContainer(Item _container) } return contents.OrderBy((x) => x.Graphic).ToList(); } + + public void ApplyHighlightProperties() + { + if (ProfileManager.CurrentProfile.GridHighlight_CorpseOnly && !container.IsCorpse) + return; + Task.Factory.StartNew(() => + { + int propNameIndex = 0; + foreach (var item in gridSlots) + { + item.Value.SetBackgroundHue(0); + if (item.Value.SlotItem != null) + for (int propNames = 0; propNames < ProfileManager.CurrentProfile.GridHighlight_PropNames.Count; propNames++) + foreach (string text in ProfileManager.CurrentProfile.GridHighlight_PropNames[propNames]) + { + if (World.OPL.TryGetNameAndData(item.Value.SlotItem.Serial, out string name, out string data)) + { + if (name != null && name.ToLower().Contains(text.ToLower())) + { + item.Value.SetBackgroundHue(ProfileManager.CurrentProfile.GridHighlight_Hue[propNames]); + } + else if (data != null) + { + string[] lines = data.Split(new string[] { "\n" }, StringSplitOptions.None); + foreach (string line in lines) + { + if (line.ToLower().Contains(text.ToLower())) + { + Match m = Regex.Match(line, @"\d+"); + if (m.Success) + if (int.TryParse(m.Value, out int val)) + if (val >= ProfileManager.CurrentProfile.GridHighlight_PropMinVal[propNames][propNameIndex]) + item.Value.SetBackgroundHue(ProfileManager.CurrentProfile.GridHighlight_Hue[propNames]); + } + } + } + } + propNameIndex++; + } + } + }); + } + } private class GridScrollArea : Control From 4a5110fc809d9870bcf860ddbe5076e886a32945 Mon Sep 17 00:00:00 2001 From: Tad Taylor Date: Wed, 29 Mar 2023 15:20:49 -0600 Subject: [PATCH 6/8] Finishing up grid highlight configurations --- .../Game/UI/Gumps/GridContainer.cs | 66 ++++++++++++++----- .../Game/UI/Gumps/GridHightlightMenu.cs | 2 +- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs index cc5f671e9f..b5b4249e02 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs @@ -47,6 +47,7 @@ using ClassicUO.Input; using ClassicUO.Renderer; using Microsoft.Xna.Framework; +using static ClassicUO.Game.UI.Gumps.GridHightlightMenu; namespace ClassicUO.Game.UI.Gumps { @@ -608,6 +609,9 @@ private class GridItem : Control AlphaBlendControl background; private CustomToolTip toolTipThis, toolTipitem1, toolTipitem2; + private bool borderHighlight = false; + private ushort borderHighlightHue = 0; + public bool Hightlight = false; public Item SlotItem { get { return _item; } set { _item = value; LocalSerial = value.Serial; } } @@ -642,9 +646,10 @@ public GridItem(uint serial, int size, Item _container, GridContainer gridContai hit.MouseDoubleClick += _hit_MouseDoubleClick; } - public void SetBackgroundHue(ushort hue) + public void SetHighLightBorder(ushort hue) { - background.Hue = hue; + borderHighlight = hue == 0 ? false : true; + borderHighlightHue = hue; } public void Resize() @@ -719,7 +724,6 @@ private void _hit_MouseUp(object sender, MouseEventArgs e) Rectangle containerBounds = ContainerManager.Get(container.Graphic).Bounds; gridContainer.gridSlotManager.AddLockedItemSlot(Client.Game.GameCursor.ItemHold.Serial, slot); GameActions.DropItem(Client.Game.GameCursor.ItemHold.Serial, containerBounds.X / 2, containerBounds.Y / 2, 0, container.Serial); - gridContainer.gridSlotManager.ApplyHighlightProperties(); } } else if (TargetManager.IsTargeting) @@ -839,6 +843,17 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y) hueVector ); + if(borderHighlight) + batcher.DrawRectangle + ( + SolidColorTextureCache.GetTexture(Color.White), + x + 6, + y + 6, + Width - 12, + Height - 12, + ShaderHueTranslator.GetHueVector(borderHighlightHue, false, 0.8f) + ); + if (hit.MouseIsOver && _item != null) { hueVector.Z = 0.3f; @@ -957,7 +972,6 @@ public void AddLockedItemSlot(uint serial, int specificSlot) if (ItemPositions.ContainsKey(specificSlot)) //Is the slot they wanted this item in already taken? Lets remove that item ItemPositions.Remove(specificSlot); ItemPositions.Add(specificSlot, serial); //Now we add this item at the desired slot - ApplyHighlightProperties(); } public void RebuildContainer(List filteredItems, string searchText = "", bool overrideSort = false) @@ -1096,45 +1110,65 @@ public static List GetItemsInContainer(Item _container) return contents.OrderBy((x) => x.Graphic).ToList(); } + public int hcount = 0; + public void ApplyHighlightProperties() { if (ProfileManager.CurrentProfile.GridHighlight_CorpseOnly && !container.IsCorpse) return; Task.Factory.StartNew(() => { - int propNameIndex = 0; - foreach (var item in gridSlots) + var tcount = hcount; + System.Threading.Thread.Sleep(1000); + + if(tcount != hcount) { return; } //Another call has already been made + List highlightConfigs = new List(); + for (int propIndex = 0; propIndex < ProfileManager.CurrentProfile.GridHighlight_PropNames.Count; propIndex++) { - item.Value.SetBackgroundHue(0); + highlightConfigs.Add(GridHighlightData.GetGridHighlightData(propIndex)); + } + + + foreach (var item in gridSlots) //For each grid slot + { + item.Value.SetHighLightBorder(0); if (item.Value.SlotItem != null) - for (int propNames = 0; propNames < ProfileManager.CurrentProfile.GridHighlight_PropNames.Count; propNames++) - foreach (string text in ProfileManager.CurrentProfile.GridHighlight_PropNames[propNames]) + foreach (GridHighlightData configData in highlightConfigs) //For each highlight configuration + { + for (int i = 0; i < configData.Properties.Count; i++) //For each property in the highlight config { + string propText = configData.Properties[i]; + if (World.OPL.TryGetNameAndData(item.Value.SlotItem.Serial, out string name, out string data)) { - if (name != null && name.ToLower().Contains(text.ToLower())) + if (name != null) Console.WriteLine(name); + if (name != null && name.ToLower().Contains(propText.ToLower())) { - item.Value.SetBackgroundHue(ProfileManager.CurrentProfile.GridHighlight_Hue[propNames]); + item.Value.SetHighLightBorder(configData.Hue); } else if (data != null) { string[] lines = data.Split(new string[] { "\n" }, StringSplitOptions.None); - foreach (string line in lines) + foreach (string line in lines) //For each property on the item { - if (line.ToLower().Contains(text.ToLower())) + if (line.ToLower().Contains(propText.ToLower())) { Match m = Regex.Match(line, @"\d+"); if (m.Success) if (int.TryParse(m.Value, out int val)) - if (val >= ProfileManager.CurrentProfile.GridHighlight_PropMinVal[propNames][propNameIndex]) - item.Value.SetBackgroundHue(ProfileManager.CurrentProfile.GridHighlight_Hue[propNames]); + { + if (val >= configData.PropMinVal[i]) + item.Value.SetHighLightBorder(configData.Hue); + //Console.WriteLine($"{line} ---> {propText}-{val} >= {configData.PropMinVal[i]}"); + } } } } } - propNameIndex++; } + } } + Console.WriteLine($"Finished apply highlight {hcount++}"); }); } diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs index 5733062b3a..55cbdbe91b 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridHightlightMenu.cs @@ -151,7 +151,7 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y) return true; } - private class GridHighlightData + public class GridHighlightData { private string name; private ushort hue; From f9e227aa8d5ef8806423ec1f5e91ca6aae55f36d Mon Sep 17 00:00:00 2001 From: Tad Taylor Date: Wed, 29 Mar 2023 15:24:46 -0600 Subject: [PATCH 7/8] Update GridContainer.cs --- src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs index b5b4249e02..3ef7360344 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs @@ -1141,7 +1141,6 @@ public void ApplyHighlightProperties() if (World.OPL.TryGetNameAndData(item.Value.SlotItem.Serial, out string name, out string data)) { - if (name != null) Console.WriteLine(name); if (name != null && name.ToLower().Contains(propText.ToLower())) { item.Value.SetHighLightBorder(configData.Hue); @@ -1159,7 +1158,6 @@ public void ApplyHighlightProperties() { if (val >= configData.PropMinVal[i]) item.Value.SetHighLightBorder(configData.Hue); - //Console.WriteLine($"{line} ---> {propText}-{val} >= {configData.PropMinVal[i]}"); } } } @@ -1168,7 +1166,6 @@ public void ApplyHighlightProperties() } } } - Console.WriteLine($"Finished apply highlight {hcount++}"); }); } From 78af4b1aa7a645a12b090f929613471d6615f724 Mon Sep 17 00:00:00 2001 From: Tad Taylor Date: Wed, 29 Mar 2023 15:33:27 -0600 Subject: [PATCH 8/8] Update GridContainer.cs --- src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs index 3ef7360344..5d8cd38f78 100644 --- a/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs +++ b/src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs @@ -1154,11 +1154,14 @@ public void ApplyHighlightProperties() { Match m = Regex.Match(line, @"\d+"); if (m.Success) + { if (int.TryParse(m.Value, out int val)) { if (val >= configData.PropMinVal[i]) item.Value.SetHighLightBorder(configData.Hue); } + } else if (configData.PropMinVal[i] < 0) + item.Value.SetHighLightBorder(configData.Hue); } } }