feat: Rank item editor prefixes by value and color them by rarity
This commit is contained in:
1 parent
249787187d
commit
23ac33cb93
1 file changed
+30
-5
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
using Terraria.GameContent.UI;
|
||||||
using Terraria.ID;
|
using Terraria.ID;
|
||||||
#if TMODLOADER
|
#if TMODLOADER
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
@@ -19,6 +20,8 @@ public sealed class ItemEditor() : Window("itemEditor", "Item Editor", new Vecto
|
|||||||
readonly Scroll _scroll = new();
|
readonly Scroll _scroll = new();
|
||||||
readonly Item _reference = new();
|
readonly Item _reference = new();
|
||||||
(int Type, int Prefix) _referenceKey = (-1, -1);
|
(int Type, int Prefix) _referenceKey = (-1, -1);
|
||||||
|
(int Prefix, int Value, int Rarity)[] _prefixOptions = [];
|
||||||
|
int _prefixType = -1;
|
||||||
int _x, _y, _width;
|
int _x, _y, _width;
|
||||||
bool _firstGroup;
|
bool _firstGroup;
|
||||||
|
|
||||||
@@ -141,21 +144,43 @@ public sealed class ItemEditor() : Window("itemEditor", "Item Editor", new Vecto
|
|||||||
return Lang.prefix[prefix].Value;
|
return Lang.prefix[prefix].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ranked by the value each prefix gives, like reforge tiers.
|
||||||
|
(int Prefix, int Value, int Rarity)[] PrefixOptions(Item item)
|
||||||
|
{
|
||||||
|
if (_prefixType == item.type)
|
||||||
|
return _prefixOptions;
|
||||||
|
|
||||||
|
var sample = new Item();
|
||||||
|
_prefixOptions = [.. Prefixes(item).Prepend(0).Select(prefix =>
|
||||||
|
{
|
||||||
|
sample.SetDefaults(item.type);
|
||||||
|
if (prefix > 0)
|
||||||
|
sample.Prefix(prefix);
|
||||||
|
return (prefix, sample.value, sample.rare);
|
||||||
|
}).OrderBy(option => option.prefix != 0).ThenByDescending(option => option.value).ThenBy(option => PrefixName(option.prefix), StringComparer.OrdinalIgnoreCase)];
|
||||||
|
_prefixType = item.type;
|
||||||
|
return _prefixOptions;
|
||||||
|
}
|
||||||
|
|
||||||
void DrawPrefixes(Item item)
|
void DrawPrefixes(Item item)
|
||||||
{
|
{
|
||||||
int[] prefixes = [.. Prefixes(item).OrderBy(PrefixName, StringComparer.OrdinalIgnoreCase)];
|
(int Prefix, int Value, int Rarity)[] options = PrefixOptions(item);
|
||||||
if (prefixes.Length == 0)
|
if (options.Length <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Group("Prefix");
|
Group("Prefix");
|
||||||
const int Columns = 3, Gap = 6;
|
const int Columns = 3, Gap = 6;
|
||||||
|
const float Scale = 0.76f;
|
||||||
int width = (_width - Gap * (Columns - 1)) / Columns;
|
int width = (_width - Gap * (Columns - 1)) / Columns;
|
||||||
int[] options = [0, .. prefixes];
|
|
||||||
for (int i = 0; i < options.Length; i++)
|
for (int i = 0; i < options.Length; i++)
|
||||||
{
|
{
|
||||||
var bounds = new Rectangle(_x + i % Columns * (width + Gap), _y + i / Columns * 34, width, 30);
|
var bounds = new Rectangle(_x + i % Columns * (width + Gap), _y + i / Columns * 34, width, 30);
|
||||||
if (Widgets.Button(bounds, options[i] == 0 ? "None" : PrefixName(options[i]), item.prefix == options[i], 0.76f) && item.prefix != options[i])
|
int prefix = options[i].Prefix;
|
||||||
ApplyPrefix(item, options[i]);
|
if (Widgets.Button(bounds, "", item.prefix == prefix, Scale) && item.prefix != prefix)
|
||||||
|
ApplyPrefix(item, prefix);
|
||||||
|
|
||||||
|
string name = Render.Ellipsize(prefix == 0 ? "None" : PrefixName(prefix), Scale, bounds.Width - 12);
|
||||||
|
Render.TextCentered(Widgets.SpriteBatch, name, bounds, ItemRarity.GetColor(options[i].Rarity), Scale);
|
||||||
}
|
}
|
||||||
_y += (options.Length + Columns - 1) / Columns * 34 + 4;
|
_y += (options.Length + Columns - 1) / Columns * 34 + 4;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user