This repository was archived by the owner on Dec 8, 2025. It is now read-only.
forked from AqlaSolutions/MagicStorage
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathModSearchBox.cs
More file actions
93 lines (82 loc) · 2.2 KB
/
ModSearchBox.cs
File metadata and controls
93 lines (82 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Terraria.GameContent.UI.Elements;
using Terraria.ModLoader;
namespace MagicStorageExtra
{
public class ModSearchBox
{
public const int ModIndexBaseGame = -1;
public const int ModIndexAll = -2;
private UITextPanel<string> _modButton;
public Action OnChanged;
public ModSearchBox(Action onChanged)
{
OnChanged = onChanged;
}
public int ModIndex { get; private set; } = ModIndexAll;
public string ModName { get; private set; }
public UIPanel Button => _modButton;
public void InitLangStuff()
{
if (_modButton == null)
_modButton = new UITextPanel<string>(MakeModButtonText(), 0.8f);
}
private void SetSearchMod(int index, bool silent)
{
if (ModIndex == index)
return;
ModIndex = index;
_modButton?.SetText(MakeModButtonText());
ModName = "";
if (index > -1)
ModName = MagicStorageExtra.Instance.AllMods[index].Name;
if (!silent)
OnChanged?.Invoke();
}
public void Reset(bool silent)
{
SetSearchMod(ModIndexAll, silent);
}
private string MakeModButtonText()
{
switch (ModIndex)
{
case ModIndexAll:
return "All mods";
case ModIndexBaseGame:
return "Terraria";
default:
return MagicStorageExtra.Instance.AllMods[ModIndex].Name;
}
}
public void Update(MouseState curMouse, MouseState oldMouse)
{
Rectangle dim = InterfaceHelper.GetFullRectangle(_modButton);
if (curMouse.X > dim.X && curMouse.X < dim.X + dim.Width && curMouse.Y > dim.Y && curMouse.Y < dim.Y + dim.Height)
{
_modButton.BackgroundColor = new Color(73, 94, 171);
Mod[] allMods = MagicStorageExtra.Instance.AllMods;
int index = ModIndex;
if (curMouse.LeftButton == ButtonState.Pressed && oldMouse.LeftButton == ButtonState.Released)
{
index++;
if (index >= allMods.Length)
index = ModIndexAll;
}
else if (curMouse.RightButton == ButtonState.Pressed && oldMouse.RightButton == ButtonState.Released)
{
index--;
if (index < -2)
index = allMods.Length - 1;
}
SetSearchMod(index, false);
}
else
{
_modButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
}
}
}
}