Skip to content

Commit

Permalink
Merge pull request #77 from bittiez/dev
Browse files Browse the repository at this point in the history
Grid highlight based off item properties
  • Loading branch information
bittiez authored Mar 29, 2023
2 parents 4260dac + 78af4b1 commit e38e9bb
Show file tree
Hide file tree
Showing 5 changed files with 493 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/ClassicUO.Client/Configuration/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ public int CoolDownConditionCount
public ushort DamageHueOther { get; set; } = 0x0021;
#endregion

#region GridHighlightingProps
public List<string> GridHighlight_Name { get; set; } = new List<string>();
public List<ushort> GridHighlight_Hue { get; set; } = new List<ushort>();
public List<List<string>> GridHighlight_PropNames { get; set; } = new List<List<string>>();
public List<List<int>> GridHighlight_PropMinVal { get; set; } = new List<List<int>>();
public bool GridHighlight_CorpseOnly { get; set; } = false;
#endregion

public static uint GumpsVersion { get; private set; }

public void Save(string path)
Expand Down
96 changes: 91 additions & 5 deletions src/ClassicUO.Client/Game/UI/Gumps/GridContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,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
{
Expand Down Expand Up @@ -100,7 +103,7 @@ public GridContainer(uint local, ushort ogContainer) : base(GetWidth(), GetHeigh
{
if (m.NotorietyFlag == NotorietyFlag.Invulnerable && m.Serial != World.Player.Serial)
{
OpenOldContainer(ogContainer);
OpenOldContainer(local);
}
}

Expand Down Expand Up @@ -430,9 +433,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)
Expand All @@ -441,6 +441,9 @@ public override void Dispose()
}
}

if (gridSlotManager.ItemPositions.Count > 0 && !_container.IsCorpse)
gridSaveSystem.SaveContainer(LocalSerial, gridSlotManager.ItemPositions, Width, Height, X, Y);

base.Dispose();
}

Expand Down Expand Up @@ -606,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; } }

Expand Down Expand Up @@ -640,7 +646,11 @@ public GridItem(uint serial, int size, Item _container, GridContainer gridContai
hit.MouseDoubleClick += _hit_MouseDoubleClick;
}


public void SetHighLightBorder(ushort hue)
{
borderHighlight = hue == 0 ? false : true;
borderHighlightHue = hue;
}

public void Resize()
{
Expand Down Expand Up @@ -833,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;
Expand Down Expand Up @@ -1003,6 +1024,8 @@ public void RebuildContainer(List<Item> filteredItems, string searchText = "", b
}
}
}

ApplyHighlightProperties();
}

private void SetGridPositions()
Expand Down Expand Up @@ -1086,6 +1109,69 @@ public static List<Item> 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(() =>
{
var tcount = hcount;
System.Threading.Thread.Sleep(1000);
if(tcount != hcount) { return; } //Another call has already been made
List<GridHighlightData> highlightConfigs = new List<GridHighlightData>();
for (int propIndex = 0; propIndex < ProfileManager.CurrentProfile.GridHighlight_PropNames.Count; propIndex++)
{
highlightConfigs.Add(GridHighlightData.GetGridHighlightData(propIndex));
}
foreach (var item in gridSlots) //For each grid slot
{
item.Value.SetHighLightBorder(0);
if (item.Value.SlotItem != null)
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(propText.ToLower()))
{
item.Value.SetHighLightBorder(configData.Hue);
}
else if (data != null)
{
string[] lines = data.Split(new string[] { "\n" }, StringSplitOptions.None);
foreach (string line in lines) //For each property on the item
{
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 >= configData.PropMinVal[i])
item.Value.SetHighLightBorder(configData.Hue);
}
} else if (configData.PropMinVal[i] < 0)
item.Value.SetHighLightBorder(configData.Hue);
}
}
}
}
}
}
}
});
}

}

private class GridScrollArea : Control
Expand Down
Loading

0 comments on commit e38e9bb

Please sign in to comment.