v0.5, amazing sorts and categories, no longer ugly. 💃
BIN
UIElements/MoreLeft.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
UIElements/MoreRight.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
332
UIElements/NewUITextBox.cs
Normal file
@@ -0,0 +1,332 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using ReLogic.Graphics;
|
||||
using System;
|
||||
using Terraria;
|
||||
using Terraria.GameContent.UI.Elements;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
internal class NewUITextBox : UIPanel//UITextPanel<string>
|
||||
{
|
||||
internal bool focused = false;
|
||||
|
||||
//private int _cursor;
|
||||
//private int _frameCount;
|
||||
private int _maxLength = 60;
|
||||
|
||||
private string hintText;
|
||||
internal string currentString = "";
|
||||
private int textBlinkerCount;
|
||||
private int textBlinkerState;
|
||||
|
||||
public event Action OnFocus;
|
||||
|
||||
public event Action OnUnfocus;
|
||||
|
||||
public event Action OnTextChanged;
|
||||
|
||||
public event Action OnTabPressed;
|
||||
|
||||
public event Action OnEnterPressed;
|
||||
|
||||
//public event Action OnUpPressed;
|
||||
internal bool unfocusOnEnter = true;
|
||||
|
||||
internal bool unfocusOnTab = true;
|
||||
|
||||
//public NewUITextBox(string text, float textScale = 1, bool large = false) : base("", textScale, large)
|
||||
public NewUITextBox(string hintText, string text = "")
|
||||
{
|
||||
this.hintText = hintText;
|
||||
currentString = text;
|
||||
SetPadding(0);
|
||||
BackgroundColor = Color.White;
|
||||
BorderColor = Color.White;
|
||||
// keyBoardInput.newKeyEvent += KeyboardInput_newKeyEvent;
|
||||
|
||||
Texture2D texture = ItemChecklist.instance.GetTexture("UIElements/closeButtonSmallWhite");
|
||||
var closeButton = new UIHoverImageButton(texture, "");
|
||||
closeButton.OnClick += (a, b) => SetText("");
|
||||
closeButton.Left.Set(-20f, 1f);
|
||||
//closeButton.Top.Set(0f, .5f);
|
||||
closeButton.VAlign = 0.5f;
|
||||
//closeButton.HAlign = 0.5f;
|
||||
Append(closeButton);
|
||||
}
|
||||
|
||||
public override void Click(UIMouseEvent evt)
|
||||
{
|
||||
Focus();
|
||||
base.Click(evt);
|
||||
}
|
||||
|
||||
public override void RightClick(UIMouseEvent evt)
|
||||
{
|
||||
base.RightClick(evt);
|
||||
SetText("");
|
||||
}
|
||||
|
||||
public void SetUnfocusKeys(bool unfocusOnEnter, bool unfocusOnTab)
|
||||
{
|
||||
this.unfocusOnEnter = unfocusOnEnter;
|
||||
this.unfocusOnTab = unfocusOnTab;
|
||||
}
|
||||
|
||||
//void KeyboardInput_newKeyEvent(char obj)
|
||||
//{
|
||||
// // Problem: keyBoardInput.newKeyEvent only fires on regular keyboard buttons.
|
||||
|
||||
// if (!focused) return;
|
||||
// if (obj.Equals((char)Keys.Back)) // '\b'
|
||||
// {
|
||||
// Backspace();
|
||||
// }
|
||||
// else if (obj.Equals((char)Keys.Enter))
|
||||
// {
|
||||
// Unfocus();
|
||||
// Main.chatRelease = false;
|
||||
// }
|
||||
// else if (Char.IsLetterOrDigit(obj))
|
||||
// {
|
||||
// Write(obj.ToString());
|
||||
// }
|
||||
//}
|
||||
|
||||
public void Unfocus()
|
||||
{
|
||||
if (focused)
|
||||
{
|
||||
focused = false;
|
||||
Main.blockInput = false;
|
||||
|
||||
OnUnfocus?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void Focus()
|
||||
{
|
||||
if (!focused)
|
||||
{
|
||||
Main.clrInput();
|
||||
focused = true;
|
||||
Main.blockInput = true;
|
||||
|
||||
OnFocus?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
Vector2 MousePosition = new Vector2((float)Main.mouseX, (float)Main.mouseY);
|
||||
if (!ContainsPoint(MousePosition) && Main.mouseLeft)
|
||||
{
|
||||
// TODO, figure out how to refocus without triggering unfocus while clicking enable button.
|
||||
Unfocus();
|
||||
}
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
//public void Write(string text)
|
||||
//{
|
||||
// base.SetText(base.Text.Insert(this._cursor, text));
|
||||
// this._cursor += text.Length;
|
||||
// _cursor = Math.Min(Text.Length, _cursor);
|
||||
// Recalculate();
|
||||
|
||||
// OnTextChanged?.Invoke();
|
||||
//}
|
||||
|
||||
//public void WriteAll(string text)
|
||||
//{
|
||||
// bool changed = text != Text;
|
||||
// if (!changed) return;
|
||||
// base.SetText(text);
|
||||
// this._cursor = text.Length;
|
||||
// //_cursor = Math.Min(Text.Length, _cursor);
|
||||
// Recalculate();
|
||||
|
||||
// if (changed)
|
||||
// {
|
||||
// OnTextChanged?.Invoke();
|
||||
// }
|
||||
//}
|
||||
|
||||
public void SetText(string text)
|
||||
{
|
||||
if (text.ToString().Length > this._maxLength)
|
||||
{
|
||||
text = text.ToString().Substring(0, this._maxLength);
|
||||
}
|
||||
if (currentString != text)
|
||||
{
|
||||
currentString = text;
|
||||
OnTextChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTextMaxLength(int maxLength)
|
||||
{
|
||||
this._maxLength = maxLength;
|
||||
}
|
||||
|
||||
//public void Backspace()
|
||||
//{
|
||||
// if (this._cursor == 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// base.SetText(base.Text.Substring(0, base.Text.Length - 1));
|
||||
// Recalculate();
|
||||
//}
|
||||
|
||||
/*public void CursorLeft()
|
||||
{
|
||||
if (this._cursor == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._cursor--;
|
||||
}
|
||||
|
||||
public void CursorRight()
|
||||
{
|
||||
if (this._cursor < base.Text.Length)
|
||||
{
|
||||
this._cursor++;
|
||||
}
|
||||
}*/
|
||||
|
||||
private static bool JustPressed(Keys key)
|
||||
{
|
||||
return Main.inputText.IsKeyDown(key) && !Main.oldInputText.IsKeyDown(key);
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
Rectangle hitbox = GetInnerDimensions().ToRectangle();
|
||||
|
||||
// Draw panel
|
||||
base.DrawSelf(spriteBatch);
|
||||
// Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Yellow);
|
||||
|
||||
if (focused)
|
||||
{
|
||||
Terraria.GameInput.PlayerInput.WritingText = true;
|
||||
Main.instance.HandleIME();
|
||||
string newString = Main.GetInputText(currentString);
|
||||
if (!newString.Equals(currentString))
|
||||
{
|
||||
currentString = newString;
|
||||
OnTextChanged?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentString = newString;
|
||||
}
|
||||
|
||||
if (JustPressed(Keys.Tab))
|
||||
{
|
||||
if (unfocusOnTab) Unfocus();
|
||||
OnTabPressed?.Invoke();
|
||||
}
|
||||
if (JustPressed(Keys.Enter))
|
||||
{
|
||||
Main.drawingPlayerChat = false;
|
||||
if (unfocusOnEnter) Unfocus();
|
||||
OnEnterPressed?.Invoke();
|
||||
}
|
||||
if (++textBlinkerCount >= 20)
|
||||
{
|
||||
textBlinkerState = (textBlinkerState + 1) % 2;
|
||||
textBlinkerCount = 0;
|
||||
}
|
||||
Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f);
|
||||
}
|
||||
string displayString = currentString;
|
||||
if (this.textBlinkerState == 1 && focused)
|
||||
{
|
||||
displayString = displayString + "|";
|
||||
}
|
||||
CalculatedStyle space = base.GetDimensions();
|
||||
Color color = Color.Black;
|
||||
if (currentString.Length == 0)
|
||||
{
|
||||
}
|
||||
Vector2 drawPos = space.Position() + new Vector2(4, 2);
|
||||
if (currentString.Length == 0 && !focused)
|
||||
{
|
||||
color *= 0.5f;
|
||||
//Utils.DrawBorderString(spriteBatch, hintText, new Vector2(space.X, space.Y), Color.Gray, 1f);
|
||||
spriteBatch.DrawString(Main.fontMouseText, hintText, drawPos, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Utils.DrawBorderString(spriteBatch, displayString, drawPos, Color.White, 1f);
|
||||
spriteBatch.DrawString(Main.fontMouseText, displayString, drawPos, color);
|
||||
}
|
||||
|
||||
// CalculatedStyle innerDimensions2 = base.GetInnerDimensions();
|
||||
// Vector2 pos2 = innerDimensions2.Position();
|
||||
// if (IsLarge)
|
||||
// {
|
||||
// pos2.Y -= 10f * TextScale * TextScale;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// pos2.Y -= 2f * TextScale;
|
||||
// }
|
||||
// //pos2.X += (innerDimensions2.Width - TextSize.X) * 0.5f;
|
||||
// if (IsLarge)
|
||||
// {
|
||||
// Utils.DrawBorderStringBig(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);
|
||||
// return;
|
||||
// }
|
||||
// Utils.DrawBorderString(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1);
|
||||
//
|
||||
// this._frameCount++;
|
||||
//
|
||||
// CalculatedStyle innerDimensions = base.GetInnerDimensions();
|
||||
// Vector2 pos = innerDimensions.Position();
|
||||
// DynamicSpriteFont spriteFont = base.IsLarge ? Main.fontDeathText : Main.fontMouseText;
|
||||
// Vector2 vector = new Vector2(spriteFont.MeasureString(base.Text.Substring(0, this._cursor)).X, base.IsLarge ? 32f : 16f) * base.TextScale;
|
||||
// if (base.IsLarge)
|
||||
// {
|
||||
// pos.Y -= 8f * base.TextScale;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// pos.Y -= 1f * base.TextScale;
|
||||
// }
|
||||
// if (Text.Length == 0)
|
||||
// {
|
||||
// Vector2 hintTextSize = new Vector2(spriteFont.MeasureString(hintText.ToString()).X, IsLarge ? 32f : 16f) * TextScale;
|
||||
// pos.X += 5;//(hintTextSize.X);
|
||||
// if (base.IsLarge)
|
||||
// {
|
||||
// Utils.DrawBorderStringBig(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
|
||||
// return;
|
||||
// }
|
||||
// Utils.DrawBorderString(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1);
|
||||
// pos.X -= 5;
|
||||
// //pos.X -= (innerDimensions.Width - hintTextSize.X) * 0.5f;
|
||||
// }
|
||||
//
|
||||
// if (!focused) return;
|
||||
//
|
||||
// pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f;
|
||||
// if ((this._frameCount %= 40) > 20)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// if (base.IsLarge)
|
||||
// {
|
||||
// Utils.DrawBorderStringBig(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
|
||||
// return;
|
||||
// }
|
||||
// Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
UIElements/ScrollbarHorizontal.png
Normal file
|
After Width: | Height: | Size: 211 B |
BIN
UIElements/ScrollbarInnerHorizontal.png
Normal file
|
After Width: | Height: | Size: 185 B |
69
UIElements/UICheckbox.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using Terraria.GameContent.UI.Elements;
|
||||
using Terraria.ModLoader;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
class UICheckbox : UIText
|
||||
{
|
||||
public static Texture2D checkboxTexture;
|
||||
public static Texture2D checkmarkTexture;
|
||||
public event EventHandler SelectedChanged;
|
||||
float order = 0;
|
||||
|
||||
private bool selected = false;
|
||||
public bool Selected
|
||||
{
|
||||
get { return selected; }
|
||||
set
|
||||
{
|
||||
if (value != selected)
|
||||
{
|
||||
selected = value;
|
||||
SelectedChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UICheckbox(float order, string text, float textScale = 1, bool large = false) : base(text, textScale, large)
|
||||
{
|
||||
this.order = order;
|
||||
this.Left.Pixels += 20;
|
||||
//TextColor = Color.Blue;
|
||||
//OnClick += UICheckbox_onLeftClick;
|
||||
Recalculate();
|
||||
}
|
||||
|
||||
//private void UICheckbox_onLeftClick(UIMouseEvent evt, UIElement listeningElement)
|
||||
//{
|
||||
// this.Selected = !Selected;
|
||||
//}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
CalculatedStyle innerDimensions = base.GetInnerDimensions();
|
||||
Vector2 pos = new Vector2(innerDimensions.X - 20, innerDimensions.Y - 5);
|
||||
|
||||
spriteBatch.Draw(checkboxTexture, pos, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
|
||||
if (Selected)
|
||||
spriteBatch.Draw(checkmarkTexture, pos, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
|
||||
|
||||
base.DrawSelf(spriteBatch);
|
||||
}
|
||||
|
||||
public override int CompareTo(object obj)
|
||||
{
|
||||
UICheckbox other = obj as UICheckbox;
|
||||
return order.CompareTo(other.order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//public string Text
|
||||
//{
|
||||
// get { return label.Text; }
|
||||
// set { label.Text = value; }
|
||||
//}
|
||||
212
UIElements/UIGrid.cs
Normal file
@@ -0,0 +1,212 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Terraria;
|
||||
using Terraria.GameContent.UI.Elements;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
public class UIGrid : UIElement
|
||||
{
|
||||
public delegate bool ElementSearchMethod(UIElement element);
|
||||
|
||||
private class UIInnerList : UIElement
|
||||
{
|
||||
public override bool ContainsPoint(Vector2 point)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void DrawChildren(SpriteBatch spriteBatch)
|
||||
{
|
||||
Vector2 position = this.Parent.GetDimensions().Position();
|
||||
Vector2 dimensions = new Vector2(this.Parent.GetDimensions().Width, this.Parent.GetDimensions().Height);
|
||||
foreach (UIElement current in this.Elements)
|
||||
{
|
||||
Vector2 position2 = current.GetDimensions().Position();
|
||||
Vector2 dimensions2 = new Vector2(current.GetDimensions().Width, current.GetDimensions().Height);
|
||||
if (Collision.CheckAABBvAABBCollision(position, dimensions, position2, dimensions2))
|
||||
{
|
||||
current.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<UIElement> _items = new List<UIElement>();
|
||||
protected UIScrollbar _scrollbar;
|
||||
internal UIElement _innerList = new UIGrid.UIInnerList();
|
||||
private float _innerListHeight;
|
||||
public float ListPadding = 5f;
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._items.Count;
|
||||
}
|
||||
}
|
||||
|
||||
int cols = 1;
|
||||
|
||||
public UIGrid(int columns = 1)
|
||||
{
|
||||
cols = columns;
|
||||
this._innerList.OverflowHidden = false;
|
||||
this._innerList.Width.Set(0f, 1f);
|
||||
this._innerList.Height.Set(0f, 1f);
|
||||
this.OverflowHidden = true;
|
||||
base.Append(this._innerList);
|
||||
}
|
||||
|
||||
public float GetTotalHeight()
|
||||
{
|
||||
return this._innerListHeight;
|
||||
}
|
||||
|
||||
public void Goto(UIGrid.ElementSearchMethod searchMethod, bool center = false)
|
||||
{
|
||||
for (int i = 0; i < this._items.Count; i++)
|
||||
{
|
||||
if (searchMethod(this._items[i]))
|
||||
{
|
||||
this._scrollbar.ViewPosition = this._items[i].Top.Pixels;
|
||||
if (center)
|
||||
{
|
||||
this._scrollbar.ViewPosition = this._items[i].Top.Pixels - GetInnerDimensions().Height/2 + _items[i].GetOuterDimensions().Height/2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Add(UIElement item)
|
||||
{
|
||||
this._items.Add(item);
|
||||
this._innerList.Append(item);
|
||||
this.UpdateOrder();
|
||||
this._innerList.Recalculate();
|
||||
}
|
||||
|
||||
public virtual void AddRange(IEnumerable<UIElement> items)
|
||||
{
|
||||
this._items.AddRange(items);
|
||||
foreach (var item in items)
|
||||
this._innerList.Append(item);
|
||||
this.UpdateOrder();
|
||||
this._innerList.Recalculate();
|
||||
}
|
||||
|
||||
public virtual bool Remove(UIElement item)
|
||||
{
|
||||
this._innerList.RemoveChild(item);
|
||||
this.UpdateOrder();
|
||||
return this._items.Remove(item);
|
||||
}
|
||||
|
||||
public virtual void Clear()
|
||||
{
|
||||
this._innerList.RemoveAllChildren();
|
||||
this._items.Clear();
|
||||
}
|
||||
|
||||
public override void Recalculate()
|
||||
{
|
||||
base.Recalculate();
|
||||
this.UpdateScrollbar();
|
||||
}
|
||||
|
||||
public override void ScrollWheel(UIScrollWheelEvent evt)
|
||||
{
|
||||
base.ScrollWheel(evt);
|
||||
if (this._scrollbar != null)
|
||||
{
|
||||
this._scrollbar.ViewPosition -= (float)evt.ScrollWheelValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override void RecalculateChildren()
|
||||
{
|
||||
base.RecalculateChildren();
|
||||
float top = 0f;
|
||||
float left = 0f;
|
||||
for (int i = 0; i < this._items.Count; i++)
|
||||
{
|
||||
this._items[i].Top.Set(top, 0f);
|
||||
this._items[i].Left.Set(left, 0f);
|
||||
this._items[i].Recalculate();
|
||||
if (i % cols == cols - 1)
|
||||
{
|
||||
top += this._items[i].GetOuterDimensions().Height + this.ListPadding;
|
||||
left = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
left += this._items[i].GetOuterDimensions().Width + this.ListPadding;
|
||||
}
|
||||
//num += this._items[i].GetOuterDimensions().Height + this.ListPadding;
|
||||
}
|
||||
if (_items.Count > 0)
|
||||
{
|
||||
top += ListPadding + _items[0].GetOuterDimensions().Height;
|
||||
}
|
||||
this._innerListHeight = top;
|
||||
}
|
||||
|
||||
private void UpdateScrollbar()
|
||||
{
|
||||
if (this._scrollbar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._scrollbar.SetView(base.GetInnerDimensions().Height, this._innerListHeight);
|
||||
}
|
||||
|
||||
public void SetScrollbar(UIScrollbar scrollbar)
|
||||
{
|
||||
this._scrollbar = scrollbar;
|
||||
this.UpdateScrollbar();
|
||||
}
|
||||
|
||||
internal Comparison<UIElement> alternateSort;
|
||||
public void UpdateOrder()
|
||||
{
|
||||
if (alternateSort != null)
|
||||
this._items.Sort(alternateSort);
|
||||
else
|
||||
this._items.Sort(new Comparison<UIElement>(this.SortMethod));
|
||||
this.UpdateScrollbar();
|
||||
}
|
||||
|
||||
public int SortMethod(UIElement item1, UIElement item2)
|
||||
{
|
||||
return item1.CompareTo(item2);
|
||||
}
|
||||
|
||||
public override List<SnapPoint> GetSnapPoints()
|
||||
{
|
||||
List<SnapPoint> list = new List<SnapPoint>();
|
||||
SnapPoint item;
|
||||
if (base.GetSnapPoint(out item))
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
foreach (UIElement current in this._items)
|
||||
{
|
||||
list.AddRange(current.GetSnapPoints());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (this._scrollbar != null)
|
||||
{
|
||||
this._innerList.Top.Set(-this._scrollbar.GetValue(), 0f);
|
||||
}
|
||||
this.Recalculate();
|
||||
}
|
||||
}
|
||||
}
|
||||
227
UIElements/UIHorizontalGrid.cs
Normal file
@@ -0,0 +1,227 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Terraria;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
public class UIHorizontalGrid : UIElement
|
||||
{
|
||||
public delegate bool ElementSearchMethod(UIElement element);
|
||||
|
||||
private class UIInnerList : UIElement
|
||||
{
|
||||
public override bool ContainsPoint(Vector2 point)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void DrawChildren(SpriteBatch spriteBatch)
|
||||
{
|
||||
Vector2 position = this.Parent.GetDimensions().Position();
|
||||
Vector2 dimensions = new Vector2(this.Parent.GetDimensions().Width, this.Parent.GetDimensions().Height);
|
||||
foreach (UIElement current in this.Elements)
|
||||
{
|
||||
Vector2 position2 = current.GetDimensions().Position();
|
||||
Vector2 dimensions2 = new Vector2(current.GetDimensions().Width, current.GetDimensions().Height);
|
||||
if (Collision.CheckAABBvAABBCollision(position, dimensions, position2, dimensions2))
|
||||
{
|
||||
current.Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<UIElement> _items = new List<UIElement>();
|
||||
protected UIHorizontalScrollbar _scrollbar;
|
||||
internal UIElement _innerList = new UIHorizontalGrid.UIInnerList();
|
||||
private float _innerListWidth;
|
||||
public float ListPadding = 5f;
|
||||
|
||||
public static Texture2D moreLeftTexture;
|
||||
public static Texture2D moreRightTexture;
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._items.Count;
|
||||
}
|
||||
}
|
||||
|
||||
// todo, vertical/horizontal orientation, left to right, etc?
|
||||
public UIHorizontalGrid()
|
||||
{
|
||||
this._innerList.OverflowHidden = false;
|
||||
this._innerList.Width.Set(0f, 1f);
|
||||
this._innerList.Height.Set(0f, 1f);
|
||||
this.OverflowHidden = true;
|
||||
base.Append(this._innerList);
|
||||
}
|
||||
|
||||
public float GetTotalWidth()
|
||||
{
|
||||
return this._innerListWidth;
|
||||
}
|
||||
|
||||
public void Goto(UIHorizontalGrid.ElementSearchMethod searchMethod, bool center = false)
|
||||
{
|
||||
for (int i = 0; i < this._items.Count; i++)
|
||||
{
|
||||
if (searchMethod(this._items[i]))
|
||||
{
|
||||
this._scrollbar.ViewPosition = this._items[i].Left.Pixels;
|
||||
if (center)
|
||||
{
|
||||
this._scrollbar.ViewPosition = this._items[i].Left.Pixels - GetInnerDimensions().Width / 2 + _items[i].GetOuterDimensions().Width / 2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Add(UIElement item)
|
||||
{
|
||||
this._items.Add(item);
|
||||
this._innerList.Append(item);
|
||||
this.UpdateOrder();
|
||||
this._innerList.Recalculate();
|
||||
}
|
||||
|
||||
public virtual void AddRange(IEnumerable<UIElement> items)
|
||||
{
|
||||
this._items.AddRange(items);
|
||||
foreach (var item in items)
|
||||
this._innerList.Append(item);
|
||||
this.UpdateOrder();
|
||||
this._innerList.Recalculate();
|
||||
}
|
||||
|
||||
public virtual bool Remove(UIElement item)
|
||||
{
|
||||
this._innerList.RemoveChild(item);
|
||||
this.UpdateOrder();
|
||||
return this._items.Remove(item);
|
||||
}
|
||||
|
||||
public virtual void Clear()
|
||||
{
|
||||
this._innerList.RemoveAllChildren();
|
||||
this._items.Clear();
|
||||
}
|
||||
|
||||
public override void Recalculate()
|
||||
{
|
||||
base.Recalculate();
|
||||
this.UpdateScrollbar();
|
||||
}
|
||||
|
||||
public override void ScrollWheel(UIScrollWheelEvent evt)
|
||||
{
|
||||
base.ScrollWheel(evt);
|
||||
if (this._scrollbar != null)
|
||||
{
|
||||
this._scrollbar.ViewPosition -= (float)evt.ScrollWheelValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override void RecalculateChildren()
|
||||
{
|
||||
float availableHeight = GetInnerDimensions().Height;
|
||||
base.RecalculateChildren();
|
||||
float left = 0f;
|
||||
float top = 0f;
|
||||
float maxRowWidth = 0f;
|
||||
for (int i = 0; i < this._items.Count; i++)
|
||||
{
|
||||
var item = this._items[i];
|
||||
var outerDimensions = item.GetOuterDimensions();
|
||||
if (top + outerDimensions.Height > availableHeight && top > 0)
|
||||
{
|
||||
left += maxRowWidth + this.ListPadding;
|
||||
top = 0;
|
||||
maxRowWidth = 0;
|
||||
}
|
||||
maxRowWidth = Math.Max(maxRowWidth, outerDimensions.Width);
|
||||
item.Top.Set(top, 0f);
|
||||
top += outerDimensions.Height + this.ListPadding;
|
||||
item.Left.Set(left, 0f);
|
||||
item.Recalculate();
|
||||
}
|
||||
this._innerListWidth = left + maxRowWidth;
|
||||
}
|
||||
|
||||
private void UpdateScrollbar()
|
||||
{
|
||||
if (this._scrollbar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._scrollbar.SetView(base.GetInnerDimensions().Width, this._innerListWidth);
|
||||
}
|
||||
|
||||
public void SetScrollbar(UIHorizontalScrollbar scrollbar)
|
||||
{
|
||||
this._scrollbar = scrollbar;
|
||||
this.UpdateScrollbar();
|
||||
}
|
||||
|
||||
public void UpdateOrder()
|
||||
{
|
||||
this._items.Sort(new Comparison<UIElement>(this.SortMethod));
|
||||
this.UpdateScrollbar();
|
||||
}
|
||||
|
||||
public int SortMethod(UIElement item1, UIElement item2)
|
||||
{
|
||||
return item1.CompareTo(item2);
|
||||
}
|
||||
|
||||
public override List<SnapPoint> GetSnapPoints()
|
||||
{
|
||||
List<SnapPoint> list = new List<SnapPoint>();
|
||||
SnapPoint item;
|
||||
if (base.GetSnapPoint(out item))
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
foreach (UIElement current in this._items)
|
||||
{
|
||||
list.AddRange(current.GetSnapPoints());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
//var r = GetDimensions().ToRectangle();
|
||||
//r.Inflate(-10,-10);
|
||||
//spriteBatch.Draw(Main.magicPixel, r, Color.Yellow);
|
||||
if (this._scrollbar != null)
|
||||
{
|
||||
this._innerList.Left.Set(-this._scrollbar.GetValue(), 0f);
|
||||
}
|
||||
this.Recalculate();
|
||||
}
|
||||
|
||||
public bool drawArrows;
|
||||
protected override void DrawChildren(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.DrawChildren(spriteBatch);
|
||||
if (drawArrows)
|
||||
{
|
||||
var inner = GetInnerDimensions().ToRectangle();
|
||||
if (this._scrollbar.ViewPosition != 0)
|
||||
{
|
||||
spriteBatch.Draw(moreLeftTexture, new Vector2(inner.X, inner.Y), Color.White * .5f);
|
||||
}
|
||||
if (this._scrollbar.ViewPosition < _innerListWidth - inner.Width)
|
||||
{
|
||||
spriteBatch.Draw(moreRightTexture, new Vector2(inner.Right - moreRightTexture.Width, inner.Y), Color.White * .5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
170
UIElements/UIHorizontalScrollbar.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
public class UIHorizontalScrollbar : UIElement
|
||||
{
|
||||
private float _viewPosition;
|
||||
private float _viewSize = 1f;
|
||||
private float _maxViewSize = 20f;
|
||||
private bool _isDragging;
|
||||
private bool _isHoveringOverHandle;
|
||||
private float _dragXOffset;
|
||||
private Texture2D _texture;
|
||||
private Texture2D _innerTexture;
|
||||
|
||||
public float ViewPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._viewPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._viewPosition = MathHelper.Clamp(value, 0f, this._maxViewSize - this._viewSize);
|
||||
}
|
||||
}
|
||||
|
||||
public UIHorizontalScrollbar()
|
||||
{
|
||||
this.Height.Set(20f, 0f);
|
||||
this.MaxHeight.Set(20f, 0f);
|
||||
this._texture = ItemChecklist.instance.GetTexture("UIElements/ScrollbarHorizontal"); //TextureManager.Load("Images/UI/Scrollbar");
|
||||
this._innerTexture = ItemChecklist.instance.GetTexture("UIElements/ScrollbarInnerHorizontal"); //TextureManager.Load("Images/UI/ScrollbarInner");
|
||||
this.PaddingLeft = 5f;
|
||||
this.PaddingRight = 5f;
|
||||
}
|
||||
|
||||
public void SetView(float viewSize, float maxViewSize)
|
||||
{
|
||||
viewSize = MathHelper.Clamp(viewSize, 0f, maxViewSize);
|
||||
this._viewPosition = MathHelper.Clamp(this._viewPosition, 0f, maxViewSize - viewSize);
|
||||
this._viewSize = viewSize;
|
||||
this._maxViewSize = maxViewSize;
|
||||
}
|
||||
|
||||
public float GetValue()
|
||||
{
|
||||
return this._viewPosition;
|
||||
}
|
||||
|
||||
private Rectangle GetHandleRectangle()
|
||||
{
|
||||
CalculatedStyle innerDimensions = base.GetInnerDimensions();
|
||||
if (this._maxViewSize == 0f && this._viewSize == 0f)
|
||||
{
|
||||
this._viewSize = 1f;
|
||||
this._maxViewSize = 1f;
|
||||
}
|
||||
//return new Rectangle((int)innerDimensions.X, (int)(innerDimensions.Y + innerDimensions.Height * (this._viewPosition / this._maxViewSize)) - 3, 20, (int)(innerDimensions.Height * (this._viewSize / this._maxViewSize)) + 7);
|
||||
return new Rectangle((int)(innerDimensions.X + innerDimensions.Width * (this._viewPosition / this._maxViewSize)) - 3, (int)innerDimensions.Y, (int)(innerDimensions.Width * (this._viewSize / this._maxViewSize)) + 7, 20);
|
||||
}
|
||||
|
||||
private void DrawBar(SpriteBatch spriteBatch, Texture2D texture, Rectangle dimensions, Color color)
|
||||
{
|
||||
//spriteBatch.Draw(texture, new Rectangle(dimensions.X, dimensions.Y - 6, dimensions.Width, 6), new Rectangle?(new Rectangle(0, 0, texture.Width, 6)), color);
|
||||
//spriteBatch.Draw(texture, new Rectangle(dimensions.X, dimensions.Y, dimensions.Width, dimensions.Height), new Rectangle?(new Rectangle(0, 6, texture.Width, 4)), color);
|
||||
//spriteBatch.Draw(texture, new Rectangle(dimensions.X, dimensions.Y + dimensions.Height, dimensions.Width, 6), new Rectangle?(new Rectangle(0, texture.Height - 6, texture.Width, 6)), color);
|
||||
spriteBatch.Draw(texture, new Rectangle(dimensions.X - 6, dimensions.Y, 6, dimensions.Height), new Rectangle(0, 0, 6, texture.Height), color);
|
||||
spriteBatch.Draw(texture, new Rectangle(dimensions.X, dimensions.Y, dimensions.Width, dimensions.Height), new Rectangle(6, 0, 4, texture.Height), color);
|
||||
spriteBatch.Draw(texture, new Rectangle(dimensions.X + dimensions.Width, dimensions.Y, 6, dimensions.Height), new Rectangle(texture.Width - 6, 0, 6, texture.Height), color);
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
CalculatedStyle dimensions = base.GetDimensions();
|
||||
CalculatedStyle innerDimensions = base.GetInnerDimensions();
|
||||
if (this._isDragging)
|
||||
{
|
||||
float num = UserInterface.ActiveInstance.MousePosition.X - innerDimensions.X - this._dragXOffset;
|
||||
this._viewPosition = MathHelper.Clamp(num / innerDimensions.Width * this._maxViewSize, 0f, this._maxViewSize - this._viewSize);
|
||||
}
|
||||
Rectangle handleRectangle = this.GetHandleRectangle();
|
||||
Vector2 mousePosition = UserInterface.ActiveInstance.MousePosition;
|
||||
bool isHoveringOverHandle = this._isHoveringOverHandle;
|
||||
this._isHoveringOverHandle = handleRectangle.Contains(new Point((int)mousePosition.X, (int)mousePosition.Y));
|
||||
if (!isHoveringOverHandle && this._isHoveringOverHandle && Main.hasFocus)
|
||||
{
|
||||
Main.PlaySound(12, -1, -1, 1, 1f, 0f);
|
||||
}
|
||||
this.DrawBar(spriteBatch, this._texture, dimensions.ToRectangle(), Color.White);
|
||||
this.DrawBar(spriteBatch, this._innerTexture, handleRectangle, Color.White * ((this._isDragging || this._isHoveringOverHandle) ? 1f : 0.85f));
|
||||
}
|
||||
|
||||
public override void MouseDown(UIMouseEvent evt)
|
||||
{
|
||||
base.MouseDown(evt);
|
||||
if (evt.Target == this)
|
||||
{
|
||||
Rectangle handleRectangle = this.GetHandleRectangle();
|
||||
if (handleRectangle.Contains(new Point((int)evt.MousePosition.X, (int)evt.MousePosition.Y)))
|
||||
{
|
||||
this._isDragging = true;
|
||||
this._dragXOffset = evt.MousePosition.X - (float)handleRectangle.X;
|
||||
return;
|
||||
}
|
||||
CalculatedStyle innerDimensions = base.GetInnerDimensions();
|
||||
float num = UserInterface.ActiveInstance.MousePosition.X - innerDimensions.X - (float)(handleRectangle.Width >> 1);
|
||||
this._viewPosition = MathHelper.Clamp(num / innerDimensions.Width * this._maxViewSize, 0f, this._maxViewSize - this._viewSize);
|
||||
}
|
||||
}
|
||||
|
||||
public override void MouseUp(UIMouseEvent evt)
|
||||
{
|
||||
base.MouseUp(evt);
|
||||
this._isDragging = false;
|
||||
}
|
||||
}
|
||||
|
||||
public class FixedUIHorizontalScrollbar : UIHorizontalScrollbar
|
||||
{
|
||||
internal UserInterface userInterface;
|
||||
|
||||
public FixedUIHorizontalScrollbar(UserInterface userInterface)
|
||||
{
|
||||
this.userInterface = userInterface;
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
UserInterface temp = UserInterface.ActiveInstance;
|
||||
UserInterface.ActiveInstance = userInterface;
|
||||
base.DrawSelf(spriteBatch);
|
||||
UserInterface.ActiveInstance = temp;
|
||||
}
|
||||
|
||||
public override void MouseDown(UIMouseEvent evt)
|
||||
{
|
||||
UserInterface temp = UserInterface.ActiveInstance;
|
||||
UserInterface.ActiveInstance = userInterface;
|
||||
base.MouseDown(evt);
|
||||
UserInterface.ActiveInstance = temp;
|
||||
}
|
||||
}
|
||||
|
||||
public class InvisibleFixedUIHorizontalScrollbar : FixedUIHorizontalScrollbar
|
||||
{
|
||||
public InvisibleFixedUIHorizontalScrollbar(UserInterface userInterface) : base(userInterface)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
UserInterface temp = UserInterface.ActiveInstance;
|
||||
UserInterface.ActiveInstance = userInterface;
|
||||
//base.DrawSelf(spriteBatch);
|
||||
UserInterface.ActiveInstance = temp;
|
||||
}
|
||||
|
||||
public override void MouseDown(UIMouseEvent evt)
|
||||
{
|
||||
UserInterface temp = UserInterface.ActiveInstance;
|
||||
UserInterface.ActiveInstance = userInterface;
|
||||
base.MouseDown(evt);
|
||||
UserInterface.ActiveInstance = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
UIElements/UIHoverImageButton.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
internal class UIHoverImageButton : UIImageButton
|
||||
{
|
||||
internal string hoverText;
|
||||
|
||||
public UIHoverImageButton(Texture2D texture, string hoverText) : base(texture)
|
||||
{
|
||||
this.hoverText = hoverText;
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
base.DrawSelf(spriteBatch);
|
||||
if (IsMouseHovering)
|
||||
{
|
||||
ItemChecklistUI.hoverText = hoverText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
114
UIElements/UIItemSlot.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using ReLogic.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
internal class UIItemSlot : UIElement
|
||||
{
|
||||
public static Texture2D backgroundTexture = Main.inventoryBack9Texture;
|
||||
|
||||
private Texture2D _texture;
|
||||
// private float _visibilityActive = 1f;
|
||||
// private float _visibilityInactive = 0.4f;
|
||||
private float scale = 0.75f;
|
||||
internal int id;
|
||||
internal Item item;
|
||||
public string badge;
|
||||
|
||||
public UIItemSlot(int id)
|
||||
{
|
||||
this._texture = Main.itemTexture[id];
|
||||
this.id = id;
|
||||
this.item = new Item();
|
||||
item.SetDefaults(id, true);
|
||||
|
||||
this.Width.Set(backgroundTexture.Width * scale, 0f);
|
||||
this.Height.Set(backgroundTexture.Height * scale, 0f);
|
||||
}
|
||||
|
||||
//public override int CompareTo(object obj)
|
||||
//{
|
||||
// UIItemSlot other = obj as UIItemSlot;
|
||||
// int result;
|
||||
// switch (ItemChecklistUI.sortMode)
|
||||
// {
|
||||
// case SortModes.ID:
|
||||
// return id.CompareTo(other.id);
|
||||
// case SortModes.AZ:
|
||||
// return item.Name.CompareTo(other.item.Name);
|
||||
// case SortModes.Value:
|
||||
// result = item.value.CompareTo(other.item.value);
|
||||
// if (result == 0)
|
||||
// result = item.Name.CompareTo(other.item.Name);
|
||||
// return result;
|
||||
// case SortModes.Rare:
|
||||
// result = item.rare.CompareTo(other.item.rare);
|
||||
// if (result == 0)
|
||||
// result = item.Name.CompareTo(other.item.Name);
|
||||
// return result;
|
||||
// case SortModes.TerrariaSort:
|
||||
// return ItemChecklistUI.vanillaIDsInSortOrder[id].CompareTo(ItemChecklistUI.vanillaIDsInSortOrder[other.id]);
|
||||
// }
|
||||
|
||||
// return id.CompareTo(other.id);
|
||||
//}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
CalculatedStyle dimensions = base.GetDimensions();
|
||||
//spriteBatch.Draw(this._texture, dimensions.Position(), Color.White * (base.IsMouseHovering ? this._visibilityActive : this._visibilityInactive));
|
||||
|
||||
spriteBatch.Draw(backgroundTexture, dimensions.Position(), null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
|
||||
//Texture2D texture2D = Main.itemTexture[this.item.type];
|
||||
Rectangle rectangle2;
|
||||
if (Main.itemAnimations[id] != null)
|
||||
{
|
||||
rectangle2 = Main.itemAnimations[id].GetFrame(_texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
rectangle2 = _texture.Frame(1, 1, 0, 0);
|
||||
}
|
||||
float num = 1f;
|
||||
float num2 = (float)backgroundTexture.Width * scale;
|
||||
if ((float)rectangle2.Width > num2 || (float)rectangle2.Height > num2)
|
||||
{
|
||||
if (rectangle2.Width > rectangle2.Height)
|
||||
{
|
||||
num = num2 / (float)rectangle2.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
num = num2 / (float)rectangle2.Height;
|
||||
}
|
||||
}
|
||||
Vector2 drawPosition = dimensions.Position();
|
||||
drawPosition.X += (float)backgroundTexture.Width * scale / 2f - (float)rectangle2.Width * num / 2f;
|
||||
drawPosition.Y += (float)backgroundTexture.Height * scale / 2f - (float)rectangle2.Height * num / 2f;
|
||||
|
||||
item.GetColor(Color.White);
|
||||
Color alphaColor = Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>(ItemChecklist.instance).foundItem[id] ? this.item.GetAlpha(Color.White) : Color.Black;
|
||||
Color colorColor = Main.LocalPlayer.GetModPlayer<ItemChecklistPlayer>(ItemChecklist.instance).foundItem[id] ? this.item.GetColor(Color.White) : Color.Black;
|
||||
//spriteBatch.Draw(_texture, drawPosition, new Rectangle?(rectangle2), this.item.GetAlpha(Color.White), 0f, Vector2.Zero, num, SpriteEffects.None, 0f);
|
||||
spriteBatch.Draw(_texture, drawPosition, new Rectangle?(rectangle2), alphaColor, 0f, Vector2.Zero, num, SpriteEffects.None, 0f);
|
||||
if (this.item.color != Color.Transparent)
|
||||
{
|
||||
spriteBatch.Draw(_texture, drawPosition, new Rectangle?(rectangle2), colorColor, 0f, Vector2.Zero, num, SpriteEffects.None, 0f);
|
||||
}
|
||||
if (ItemChecklistUI.showBadge && !string.IsNullOrEmpty(badge))
|
||||
{
|
||||
spriteBatch.DrawString(Main.fontItemStack, badge, new Vector2(dimensions.Position().X + 10f * scale, dimensions.Position().Y + 26f * scale), Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f);
|
||||
}
|
||||
|
||||
if (IsMouseHovering)
|
||||
{
|
||||
ItemChecklistUI.hoverText = item.Name + (item.modItem != null ? " [" + item.modItem.mod.Name + "]" : "");
|
||||
|
||||
Main.HoverItem = item.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
UIElements/UISilentImageButton.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
class UISilentImageButton : UIElement
|
||||
{
|
||||
private Texture2D _texture;
|
||||
private float _visibilityActive = 1f;
|
||||
private float _visibilityHovered = .9f;
|
||||
private float _visibilityInactive = 0.8f; // or color? same thing?
|
||||
|
||||
public bool selected;
|
||||
internal string hoverText;
|
||||
|
||||
public UISilentImageButton(Texture2D texture, string hoverText)
|
||||
{
|
||||
this._texture = texture;
|
||||
this.Width.Set((float)this._texture.Width, 0f);
|
||||
this.Height.Set((float)this._texture.Height, 0f);
|
||||
this.hoverText = hoverText;
|
||||
}
|
||||
|
||||
public void SetImage(Texture2D texture)
|
||||
{
|
||||
this._texture = texture;
|
||||
this.Width.Set((float)this._texture.Width, 0f);
|
||||
this.Height.Set((float)this._texture.Height, 0f);
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
var r = GetDimensions().ToRectangle();
|
||||
r.Inflate(0,0);
|
||||
//spriteBatch.Draw(UIElements.UIRecipeSlot.selectedBackgroundTexture, r, Color.White);
|
||||
spriteBatch.Draw( Main.inventoryBack14Texture, r, Color.White);
|
||||
}
|
||||
|
||||
CalculatedStyle dimensions = base.GetDimensions();
|
||||
spriteBatch.Draw(this._texture, dimensions.Position(), Color.White * (selected ? _visibilityActive : ( IsMouseHovering ? _visibilityHovered : this._visibilityInactive)));
|
||||
if (IsMouseHovering)
|
||||
{
|
||||
Main.hoverItemName = hoverText;
|
||||
}
|
||||
}
|
||||
|
||||
public override void MouseOver(UIMouseEvent evt)
|
||||
{
|
||||
base.MouseOver(evt);
|
||||
//Main.PlaySound(12, -1, -1, 1, 1f, 0f);
|
||||
}
|
||||
|
||||
//public void SetVisibility(float whenActive, float whenInactive)
|
||||
//{
|
||||
// this._visibilityActive = MathHelper.Clamp(whenActive, 0f, 1f);
|
||||
// this._visibilityInactive = MathHelper.Clamp(whenInactive, 0f, 1f);
|
||||
//}
|
||||
}
|
||||
}
|
||||
92
UIElements/UIToggleHoverImageButton.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Terraria;
|
||||
using Terraria.UI;
|
||||
|
||||
namespace ItemChecklist.UIElements
|
||||
{
|
||||
public class UIToggleHoverImageButton : UIImageButton
|
||||
{
|
||||
//private Texture2D _texture;
|
||||
private Texture2D overlay;
|
||||
private float _visibilityActive = 1f;
|
||||
private float _visibilityInactive = 0.4f;
|
||||
bool enabled;
|
||||
internal string hoverText;
|
||||
|
||||
public UIToggleHoverImageButton(Texture2D texture, Texture2D overlay, string hoverText, bool enabled = false) : base(texture)
|
||||
{
|
||||
this._texture = texture;
|
||||
this.overlay = overlay;
|
||||
this.Width.Set((float)this._texture.Width, 0f);
|
||||
this.Height.Set((float)this._texture.Height, 0f);
|
||||
this.hoverText = hoverText;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void SetEnabled(bool enabled)
|
||||
{
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
CalculatedStyle dimensions = base.GetDimensions();
|
||||
spriteBatch.Draw(this._texture, dimensions.Position(), Color.White * (base.IsMouseHovering ? this._visibilityActive : this._visibilityInactive));
|
||||
if (!enabled)
|
||||
{
|
||||
// 32x32, overlay is 24x24.
|
||||
spriteBatch.Draw(this.overlay, dimensions.Position() + new Vector2(4), Color.White * (base.IsMouseHovering ? this._visibilityActive : this._visibilityInactive));
|
||||
}
|
||||
if (IsMouseHovering)
|
||||
{
|
||||
ItemChecklistUI.hoverText = hoverText;
|
||||
}
|
||||
}
|
||||
|
||||
public override void MouseOver(UIMouseEvent evt)
|
||||
{
|
||||
base.MouseOver(evt);
|
||||
Main.PlaySound(12, -1, -1, 1, 1f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public class UIImageButton : UIElement
|
||||
{
|
||||
protected Texture2D _texture;
|
||||
private float _visibilityActive = 1f;
|
||||
private float _visibilityInactive = 0.4f;
|
||||
|
||||
public UIImageButton(Texture2D texture)
|
||||
{
|
||||
this._texture = texture;
|
||||
this.Width.Set((float)this._texture.Width, 0f);
|
||||
this.Height.Set((float)this._texture.Height, 0f);
|
||||
}
|
||||
|
||||
public void SetImage(Texture2D texture)
|
||||
{
|
||||
this._texture = texture;
|
||||
this.Width.Set((float)this._texture.Width, 0f);
|
||||
this.Height.Set((float)this._texture.Height, 0f);
|
||||
}
|
||||
|
||||
protected override void DrawSelf(SpriteBatch spriteBatch)
|
||||
{
|
||||
CalculatedStyle dimensions = base.GetDimensions();
|
||||
spriteBatch.Draw(this._texture, dimensions.Position(), Color.White * (base.IsMouseHovering ? this._visibilityActive : this._visibilityInactive));
|
||||
}
|
||||
|
||||
public override void MouseOver(UIMouseEvent evt)
|
||||
{
|
||||
base.MouseOver(evt);
|
||||
Main.PlaySound(12, -1, -1, 1, 1f, 0f);
|
||||
}
|
||||
|
||||
public void SetVisibility(float whenActive, float whenInactive)
|
||||
{
|
||||
this._visibilityActive = MathHelper.Clamp(whenActive, 0f, 1f);
|
||||
this._visibilityInactive = MathHelper.Clamp(whenInactive, 0f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
UIElements/checkBox.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
UIElements/checkMark.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
UIElements/closeButton.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
UIElements/closeButtonSmallWhite.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
UIElements/spacer.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |