Skip to content

Commit

Permalink
Control cleanup and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
bittiez committed Feb 9, 2024
1 parent 48bde68 commit 6efb55d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 28 deletions.
16 changes: 7 additions & 9 deletions src/ClassicUO.Client/Game/UI/Controls/ScrollArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

#endregion

using System;
using ClassicUO.Input;
using ClassicUO.Renderer;
using Microsoft.Xna.Framework;
using System;

namespace ClassicUO.Game.UI.Controls
{
Expand Down Expand Up @@ -72,7 +72,8 @@ public ScrollArea
{
_scrollBar = new ScrollFlag
{
X = Width - 19, Height = h
X = Width - 19,
Height = h
};

Width += 15;
Expand Down Expand Up @@ -100,11 +101,9 @@ public ScrollArea

public Rectangle ScissorRectangle;


public override void Update()
public override void SlowUpdate()
{
base.Update();

base.SlowUpdate();
CalculateScrollBarMaxValue();

if (ScrollbarBehaviour == ScrollbarBehaviour.ShowAlways)
Expand Down Expand Up @@ -138,7 +137,7 @@ public void Scroll(bool isup)

public override bool Draw(UltimaBatcher2D batcher, int x, int y)
{
ScrollBarBase scrollbar = (ScrollBarBase) Children[0];
ScrollBarBase scrollbar = (ScrollBarBase)Children[0];
scrollbar.Draw(batcher, x + scrollbar.X, y + scrollbar.Y);

if (batcher.ClipBegin(x + ScissorRectangle.X, y + ScissorRectangle.Y, Width - 14 + ScissorRectangle.Width, Height + ScissorRectangle.Height))
Expand All @@ -153,7 +152,7 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y)
}

int finalY = y + child.Y - scrollbar.Value + ScissorRectangle.Y;

child.Draw(batcher, x + child.X, finalY);
}

Expand All @@ -163,7 +162,6 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y)
return true;
}


protected override void OnMouseWheel(MouseEventType delta)
{
switch (delta)
Expand Down
7 changes: 3 additions & 4 deletions src/ClassicUO.Client/Game/UI/Controls/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@

#endregion

using System;
using ClassicUO.Input;
using ClassicUO.Assets;
using ClassicUO.Renderer;
using Microsoft.Xna.Framework;
using System;

namespace ClassicUO.Game.UI.Controls
{
Expand All @@ -52,6 +51,8 @@ internal class ScrollBar : ScrollBarBase
const ushort BACKGROUND_2 = 255;
const ushort SLIDER = 254;

private Vector3 hueVector = ShaderHueTranslator.GetHueVector(0);

public ScrollBar(int x, int y, int height)
{
Height = height;
Expand Down Expand Up @@ -91,8 +92,6 @@ public override bool Draw(UltimaBatcher2D batcher, int x, int y)
return false;
}

var hueVector = ShaderHueTranslator.GetHueVector(0);

ref readonly var gumpInfoUp0 = ref Client.Game.Gumps.GetGump(BUTTON_UP_0);
ref readonly var gumpInfoUp1 = ref Client.Game.Gumps.GetGump(BUTTON_UP_1);
ref readonly var gumpInfoDown0 = ref Client.Game.Gumps.GetGump(BUTTON_DOWN_0);
Expand Down
8 changes: 3 additions & 5 deletions src/ClassicUO.Client/Game/UI/Controls/ScrollFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@

#endregion

using System;
using ClassicUO.Input;
using ClassicUO.Assets;
using ClassicUO.Renderer;
using Microsoft.Xna.Framework;
using System;

namespace ClassicUO.Game.UI.Controls
{
Expand All @@ -46,6 +44,8 @@ internal class ScrollFlag : ScrollBarBase
const ushort BUTTON_DOWN = 0x0825;
const ushort BUTTON_FLAG = 0x0828;

private Vector3 hueVector = ShaderHueTranslator.GetHueVector(0);

public ScrollFlag(int x, int y, int height, bool showbuttons) : this()
{
X = x;
Expand Down Expand Up @@ -90,8 +90,6 @@ public ScrollFlag()

public override bool Draw(UltimaBatcher2D batcher, int x, int y)
{
var hueVector = ShaderHueTranslator.GetHueVector(0);

ref readonly var gumpInfoFlag = ref Client.Game.Gumps.GetGump(BUTTON_FLAG);
ref readonly var gumpInfoUp = ref Client.Game.Gumps.GetGump(BUTTON_UP);
ref readonly var gumpInfoDown = ref Client.Game.Gumps.GetGump(BUTTON_DOWN);
Expand Down
23 changes: 20 additions & 3 deletions src/ClassicUO.Client/Game/UI/Controls/SimpleBorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ namespace ClassicUO.Game.UI.Controls
{
internal class SimpleBorder : Control
{
public ushort Hue = 0;
public ushort Hue
{
get => hue;
set
{
hue = value;
hueVector = ShaderHueTranslator.GetHueVector(value, false, Alpha);
}
}

private int _width = 0, _height = 0;
private Vector3 hueVector;
private ushort hue = 0;

//Return 0 so this control has a 0, 0 size to not interfere with hitboxes
public new int Width { get { return 0; } set { _width = value; } }
Expand All @@ -16,16 +26,23 @@ internal class SimpleBorder : Control
public override bool Draw(UltimaBatcher2D batcher, int x, int y)
{
if (IsDisposed)
{
return false;
}

base.Draw(batcher, x, y);

var huevec = ShaderHueTranslator.GetHueVector(Hue, false, Alpha);
if (hueVector == default)
{
GameActions.Print($"{Hue}, {Alpha}");
hueVector = ShaderHueTranslator.GetHueVector(Hue, false, Alpha);
}

batcher.DrawRectangle(
SolidColorTextureCache.GetTexture(Color.White),
x, y,
_width, _height,
huevec
hueVector
);

return true;
Expand Down
34 changes: 27 additions & 7 deletions src/ClassicUO.Client/Game/UI/Controls/StaticPic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@

#endregion

using System.Collections.Generic;
using ClassicUO.Assets;
using ClassicUO.Renderer;
using ClassicUO.Utility;
using Microsoft.Xna.Framework;
using System.Collections.Generic;

namespace ClassicUO.Game.UI.Controls
{
public class StaticPic : Control
{
private ushort _graphic;
private ushort graphic;
private Vector3 hueVector;
private ushort hue;
private bool isPartialHue;

public StaticPic(ushort graphic, ushort hue)
{
Expand All @@ -61,15 +64,29 @@ public StaticPic(List<string> parts)
IsFromServer = true;
}

public ushort Hue { get; set; }
public bool IsPartialHue { get; set; }
public ushort Hue
{
get => hue; set
{
hue = value;
hueVector = ShaderHueTranslator.GetHueVector(value, IsPartialHue, 1);
}
}
public bool IsPartialHue
{
get => isPartialHue; set
{
isPartialHue = value;
hueVector = ShaderHueTranslator.GetHueVector(Hue, value, 1);
}
}

public ushort Graphic
{
get => _graphic;
get => graphic;
set
{
_graphic = value;
graphic = value;

ref readonly var artInfo = ref Client.Game.Arts.GetArt(value);

Expand All @@ -89,7 +106,10 @@ public ushort Graphic

public override bool Draw(UltimaBatcher2D batcher, int x, int y)
{
Vector3 hueVector = ShaderHueTranslator.GetHueVector(Hue, IsPartialHue, 1);
if (hueVector == default)
{
hueVector = ShaderHueTranslator.GetHueVector(Hue, IsPartialHue, 1);
}

ref readonly var artInfo = ref Client.Game.Arts.GetArt(Graphic);

Expand Down

0 comments on commit 6efb55d

Please sign in to comment.