1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
6 namespace Loot.UI.Common.Controls.Button
8 internal class GuiArrowButton : UIElement
10 public enum ArrowDirection
17 private static Texture2D _btnTexture => Assets.Textures.GUI.ArrowButtonTexture;
18 public bool CanBeClicked;
19 public string HoverText;
20 private readonly ArrowDirection _arrowDirection;
22 public delegate
void WhenClickedEvent(UIMouseEvent evt, UIElement listeningElement, GuiArrowButton btn);
23 public event WhenClickedEvent WhenClicked;
25 private SpriteEffects GetSpriteEffects()
27 switch (_arrowDirection)
30 case ArrowDirection.RIGHT:
31 return SpriteEffects.None;
32 case ArrowDirection.LEFT:
33 return SpriteEffects.FlipHorizontally;
37 public GuiArrowButton(ArrowDirection direction)
39 _arrowDirection = direction;
40 Width.Set(_btnTexture.Width, 0);
41 Height.Set(_btnTexture.Height, 0);
44 public override void OnInitialize()
46 OnClick += (evt, element) =>
50 WhenClicked?.Invoke(evt, element,
this);
55 protected override void DrawSelf(SpriteBatch spriteBatch)
57 Color drawColor = Color.Gray * 0.75f;
59 var parentBounds = GetOuterDimensions().ToRectangle();
61 if (parentBounds.Contains(Main.MouseScreen.ToPoint()))
65 drawColor = Color.White;
66 Main.hoverItemName = HoverText;
69 if (Main.mouseLeft && Main.mouseLeftRelease)
71 Click(
new UIMouseEvent(
this, Main.MouseScreen));
79 null, drawColor, 0f, Vector2.Zero,
80 GetSpriteEffects(), 0f