Skip to content

Commit dfd38fe

Browse files
committed
feat: add new text formatting options for enchantment lore #185
1 parent 7817c06 commit dfd38fe

8 files changed

Lines changed: 177 additions & 46 deletions

File tree

src/main/java/com/fix3dll/skyblockaddons/core/feature/FeatureSetting.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,31 @@ public enum FeatureSetting {
7878
ENCHANT_LAYOUT("enchantLayout.title", Feature.ENCHANTMENT_LORE_PARSING),
7979
HIGHLIGHT_ENCHANTMENTS("settings.highlightSpecialEnchantments", Feature.ENCHANTMENT_LORE_PARSING),
8080
PERFECT_ENCHANT_COLOR("enchants.superTier", Feature.ENCHANTMENT_LORE_PARSING),
81+
PERFECT_ENCHANT_BOLD("enchants.bold", Feature.ENCHANTMENT_LORE_PARSING),
82+
PERFECT_ENCHANT_ITALIC("enchants.italic", Feature.ENCHANTMENT_LORE_PARSING),
83+
PERFECT_ENCHANT_UNDERLINED("enchants.underlined", Feature.ENCHANTMENT_LORE_PARSING),
84+
PERFECT_ENCHANT_STRIKETHROUGH("enchants.strikethrough", Feature.ENCHANTMENT_LORE_PARSING),
8185
GREAT_ENCHANT_COLOR("enchants.highTier", Feature.ENCHANTMENT_LORE_PARSING),
86+
GREAT_ENCHANT_BOLD("enchants.bold", Feature.ENCHANTMENT_LORE_PARSING),
87+
GREAT_ENCHANT_ITALIC("enchants.italic", Feature.ENCHANTMENT_LORE_PARSING),
88+
GREAT_ENCHANT_UNDERLINED("enchants.underlined", Feature.ENCHANTMENT_LORE_PARSING),
89+
GREAT_ENCHANT_STRIKETHROUGH("enchants.strikethrough", Feature.ENCHANTMENT_LORE_PARSING),
8290
GOOD_ENCHANT_COLOR("enchants.midTier", Feature.ENCHANTMENT_LORE_PARSING),
91+
GOOD_ENCHANT_BOLD("enchants.bold", Feature.ENCHANTMENT_LORE_PARSING),
92+
GOOD_ENCHANT_ITALIC("enchants.italic", Feature.ENCHANTMENT_LORE_PARSING),
93+
GOOD_ENCHANT_UNDERLINED("enchants.underlined", Feature.ENCHANTMENT_LORE_PARSING),
94+
GOOD_ENCHANT_STRIKETHROUGH("enchants.strikethrough", Feature.ENCHANTMENT_LORE_PARSING),
8395
POOR_ENCHANT_COLOR("enchants.lowTier", Feature.ENCHANTMENT_LORE_PARSING),
96+
POOR_ENCHANT_BOLD("enchants.bold", Feature.ENCHANTMENT_LORE_PARSING),
97+
POOR_ENCHANT_ITALIC("enchants.italic", Feature.ENCHANTMENT_LORE_PARSING),
98+
POOR_ENCHANT_UNDERLINED("enchants.underlined", Feature.ENCHANTMENT_LORE_PARSING),
99+
POOR_ENCHANT_STRIKETHROUGH("enchants.strikethrough", Feature.ENCHANTMENT_LORE_PARSING),
84100
COMMA_ENCHANT_COLOR("enchants.commas", Feature.ENCHANTMENT_LORE_PARSING),
101+
COMMA_ENCHANT_BOLD("enchants.bold", Feature.ENCHANTMENT_LORE_PARSING),
102+
COMMA_ENCHANT_ITALIC("enchants.italic", Feature.ENCHANTMENT_LORE_PARSING),
103+
COMMA_ENCHANT_UNDERLINED("enchants.underlined", Feature.ENCHANTMENT_LORE_PARSING),
104+
COMMA_ENCHANT_STRIKETHROUGH("enchants.strikethrough", Feature.ENCHANTMENT_LORE_PARSING),
105+
DEFAULT_COMMA_STYLE("settings.defaultCommaStyle", Feature.ENCHANTMENT_LORE_PARSING),
85106
TREVOR_TRACKED_ENTITY_PROXIMITY_INDICATOR("settings.trevorTheTrapper.trackedEntityProximityIndicator", Feature.TREVOR_THE_TRAPPER_FEATURES),
86107
TREVOR_HIGHLIGHT_TRACKED_ENTITY("settings.trevorTheTrapper.highlightTrackedEntity", Feature.TREVOR_THE_TRAPPER_FEATURES),
87108
TREVOR_SHOW_QUEST_COOLDOWN("settings.trevorTheTrapper.showQuestCooldown", Feature.TREVOR_THE_TRAPPER_FEATURES),

src/main/java/com/fix3dll/skyblockaddons/features/enchants/EnchantManager.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,17 @@ else if (strippedLine.isBlank() && endEnchant == -1) {
116116
// Figure out whether the item tooltip is gonna wrap, and if so, try to make our enchantments wrap
117117
maxTooltipWidth = correctTooltipWidth(maxTooltipWidth);
118118

119-
// Get format for comma
120-
boolean highlightEnchantments = feature.isEnabled(FeatureSetting.HIGHLIGHT_ENCHANTMENTS);
121-
boolean commaFormatted = false;
122-
MutableComponent comma = highlightEnchantments
123-
? Component.literal(COMMA).withColor(feature.getAsNumber(FeatureSetting.COMMA_ENCHANT_COLOR).intValue())
124-
: Component.literal(COMMA);
119+
MutableComponent comma = Component.literal(COMMA);
120+
if (feature.isEnabled(FeatureSetting.HIGHLIGHT_ENCHANTMENTS)
121+
&& feature.isDisabled(FeatureSetting.DEFAULT_COMMA_STYLE)) {
122+
comma.withStyle(style -> style
123+
.withColor(feature.getAsNumber(FeatureSetting.COMMA_ENCHANT_COLOR).intValue())
124+
.withBold(feature.isEnabled(FeatureSetting.COMMA_ENCHANT_BOLD))
125+
.withItalic(feature.isEnabled(FeatureSetting.COMMA_ENCHANT_ITALIC))
126+
.withUnderlined(feature.isEnabled(FeatureSetting.COMMA_ENCHANT_UNDERLINED))
127+
.withStrikethrough(feature.isEnabled(FeatureSetting.COMMA_ENCHANT_STRIKETHROUGH))
128+
);
129+
}
125130

126131
int maxEnchantsPerLine = 0;
127132
boolean hasLore = false;
@@ -139,15 +144,13 @@ else if (strippedLine.isBlank() && endEnchant == -1) {
139144
EnchantmentsData.Enchant enchant = enchants.getFromLore(m.group("enchant"));
140145
int level = RomanNumeralParser.parseNumeral(m.group("levelNumeral"));
141146
if (enchant != null) {
142-
List<Component> lineSiblings = originalLine.getSiblings();
143-
Component enchantSibling = lineSiblings.size() > counter ? lineSiblings.get(counter) : null;
147+
// extra:[{color: "light_purple",text: "",bold: 1b},
148+
// {color: "light_purple", text: "Ultimate Wise V, ",bold: 1b},...
149+
// FIXME Hypixel needs to fix these shitty Components
150+
// List<Component> lineSiblings = originalLine.getSiblings();
151+
// Component enchantSibling = lineSiblings.size() > counter ? lineSiblings.get(counter) : null;
144152

145-
// Inherit comma style from the first normal enchant sibling when not highlighting
146-
if (!commaFormatted && enchantSibling != null && !highlightEnchantments && enchant.isNormal()) {
147-
commaFormatted = true;
148-
comma.withStyle(enchantSibling.getStyle());
149-
}
150-
lastEnchant = new FormattedEnchant(enchant, level, enchantSibling);
153+
lastEnchant = new FormattedEnchant(enchant, level, findSibling(originalLine, enchant));
151154
// Try to add enchant to the list, otherwise find the same enchant that was already present in the list
152155
if (!orderedEnchants.add(lastEnchant)) {
153156
for (FormattedEnchant e : orderedEnchants) {
@@ -183,6 +186,7 @@ else if (strippedLine.isBlank() && endEnchant == -1) {
183186
loreList.subList(startEnchant, endEnchant + 1).clear();
184187

185188
List<Component> insertEnchants;
189+
boolean isCommaDefault = comma.getStyle().isEmpty();
186190
int commaLength = MC.font.width(COMMA);
187191
RegistrableEnum layout = feature.getAsEnum(FeatureSetting.ENCHANT_LAYOUT);
188192
// Pack as many enchantments as we can into one line (while not overstuffing it)
@@ -201,7 +205,10 @@ else if (strippedLine.isBlank() && endEnchant == -1) {
201205
sum = 0;
202206
}
203207
// Add to enchant followed by a comma
204-
loreLine.append(enchant.getFormattedComponent()).append(comma);
208+
Component formattedEnchantComponent = enchant.getFormattedComponent();
209+
loreLine.append(formattedEnchantComponent).append(
210+
isCommaDefault ? comma.copy().withStyle(formattedEnchantComponent.getStyle()) : comma
211+
);
205212
sum += enchant.getRenderLength() + commaLength;
206213
}
207214
// Flush any remaining enchants
@@ -217,9 +224,12 @@ else if (layout == EnchantLayout.NORMAL && !hasLore) {
217224
int i = 0;
218225
MutableComponent loreLine = Component.empty();
219226
for (FormattedEnchant enchant : orderedEnchants) {
220-
loreLine.append(enchant.getFormattedComponent());
227+
Component formattedEnchantComponent = enchant.getFormattedComponent();
228+
loreLine.append(formattedEnchantComponent);
221229
if (i % maxEnchantsPerLine < maxEnchantsPerLine - 1) {
222-
loreLine.append(comma);
230+
loreLine.append(
231+
isCommaDefault ? comma.copy().withStyle(formattedEnchantComponent.getStyle()) : comma
232+
);
223233
} else {
224234
insertEnchants.add(loreLine);
225235
loreLine = Component.empty();
@@ -374,6 +384,19 @@ private static int correctTooltipWidth(int maxTooltipWidth) {
374384
return maxTooltipWidth;
375385
}
376386

387+
private static Component findSibling(Component originalLine, EnchantmentsData.Enchant enchant) {
388+
List<Component> siblings = originalLine.getSiblings();
389+
if (siblings.isEmpty()) return null;
390+
391+
for (Component sibling : siblings) {
392+
if (sibling.getString().contains(enchant.getLoreName())) {
393+
return sibling;
394+
}
395+
}
396+
397+
return null;
398+
}
399+
377400
/**
378401
* Signals that the lore cache is stale due to a config change. The next call to
379402
* {@link #parseEnchants} will perform a full re-parse regardless of whether the lore has changed.

src/main/java/com/fix3dll/skyblockaddons/gui/buttons/feature/ButtonFeatureToggle.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class ButtonFeatureToggle extends ButtonFeature {
2424
private static final int ANIMATION_SLIDE_DISTANCE = 12;
2525
private static final int ANIMATION_SLIDE_TIME = 150;
2626

27+
public static final int WIDTH = 31;
28+
public static final int HEIGHT = 15;
29+
2730
protected long animationButtonClicked = -1;
2831
protected Supplier<Boolean> isEnabled;
2932

@@ -32,8 +35,8 @@ public class ButtonFeatureToggle extends ButtonFeature {
3235
*/
3336
public ButtonFeatureToggle(double x, double y, Feature feature) {
3437
super((int) x, (int) y, Component.empty(), feature);
35-
this.width = 31;
36-
this.height = 15;
38+
this.width = WIDTH;
39+
this.height = HEIGHT;
3740
this.isEnabled = feature::isEnabled;
3841
}
3942

src/main/java/com/fix3dll/skyblockaddons/gui/screens/SettingsGui.java

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public class SettingsGui extends SkyblockAddonsScreen {
9494
private int cachedTrackX;
9595
private int cachedTrackHeight;
9696

97+
private int lastEnchantX;
98+
private double lastEnchantY;
99+
97100
public SettingsGui(@NonNull Feature feature, int page, int lastPage, EnumUtils.GuiTab lastTab, EnumUtils.GUIType lastGUI) {
98101
super(Component.empty());
99102
this.feature = feature;
@@ -358,7 +361,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
358361
return;
359362
}
360363

361-
boxWidth = 31;
364+
boxWidth = ButtonSettingToggle.WIDTH;
362365
x = halfWidth - (boxWidth / 2);
363366
y = getRowHeightSetting(row);
364367
addRenderableWidget(new ButtonSettingToggle(x, y, Translations.getMessage("settings.expandDeployableStatus"), setting));
@@ -436,7 +439,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
436439
break;
437440

438441
case TREVOR_SHOW_QUEST_COOLDOWN:
439-
boxWidth = 31; // Default size and stuff.
442+
boxWidth = ButtonSettingToggle.WIDTH;
440443
x = halfWidth - (boxWidth / 2);
441444
y = getRowHeightSetting(row);
442445
addRenderableWidget(new ButtonSettingToggle(x, y, setting.getMessage(), setting));
@@ -447,7 +450,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
447450
break;
448451

449452
case TREVOR_HIGHLIGHT_TRACKED_ENTITY:
450-
boxWidth = 31; // Default size and stuff.
453+
boxWidth = ButtonSettingToggle.WIDTH;
451454
x = halfWidth - (boxWidth / 2);
452455
y = getRowHeightSetting(row);
453456
addRenderableWidget(new ButtonSettingToggle(x, y, setting.getMessage(), setting));
@@ -458,7 +461,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
458461
break;
459462

460463
case CLASS_COLORED_TEAMMATE:
461-
boxWidth = 31; // Default size and stuff.
464+
boxWidth = ButtonSettingToggle.WIDTH;
462465
x = halfWidth - (boxWidth / 2);
463466
y = getRowHeightSetting(row);
464467
addRenderableWidget(new ButtonSettingToggle(x, y, setting.getMessage(), setting));
@@ -487,10 +490,40 @@ private void addButton(FeatureSetting setting, Object settingValue) {
487490
case POOR_ENCHANT_COLOR:
488491
case COMMA_ENCHANT_COLOR:
489492
boxWidth = 100;
490-
x = halfWidth - (boxWidth / 2);
491-
y = getRowHeightSetting(row);
493+
x = lastEnchantX = halfWidth - (boxWidth / 2) - (ButtonSettingToggle.WIDTH * 4 / 2) - 45;
494+
y = lastEnchantY = getRowHeightSetting(row);
492495
addRenderableWidget(new ButtonOpenColorMenu(x, y, 100, 20, setting.getMessage(), setting));
493-
if (setting == FeatureSetting.COMMA_ENCHANT_COLOR) row += 0.4F; // Last spacing
496+
row--;
497+
break;
498+
499+
case PERFECT_ENCHANT_BOLD:
500+
case GREAT_ENCHANT_BOLD:
501+
case GOOD_ENCHANT_BOLD:
502+
case POOR_ENCHANT_BOLD:
503+
case COMMA_ENCHANT_BOLD:
504+
lastEnchantX += 100 + 10;
505+
addRenderableWidget(new ButtonSettingToggle(lastEnchantX, lastEnchantY + 2.5, setting.getMessage(), setting));
506+
row--;
507+
break;
508+
case PERFECT_ENCHANT_ITALIC:
509+
case GREAT_ENCHANT_ITALIC:
510+
case GOOD_ENCHANT_ITALIC:
511+
case POOR_ENCHANT_ITALIC:
512+
case COMMA_ENCHANT_ITALIC:
513+
case PERFECT_ENCHANT_UNDERLINED:
514+
case GREAT_ENCHANT_UNDERLINED:
515+
case GOOD_ENCHANT_UNDERLINED:
516+
case POOR_ENCHANT_UNDERLINED:
517+
case COMMA_ENCHANT_UNDERLINED:
518+
lastEnchantX -= 20;
519+
case PERFECT_ENCHANT_STRIKETHROUGH:
520+
case GREAT_ENCHANT_STRIKETHROUGH:
521+
case GOOD_ENCHANT_STRIKETHROUGH:
522+
case POOR_ENCHANT_STRIKETHROUGH:
523+
case COMMA_ENCHANT_STRIKETHROUGH:
524+
lastEnchantX += ButtonSettingToggle.WIDTH + 40;
525+
addRenderableWidget(new ButtonSettingToggle(lastEnchantX, lastEnchantY + 2.5, setting.getMessage(), setting));
526+
if (!setting.name().endsWith("_STRIKETHROUGH")) row--; // Except last one
494527
break;
495528

496529
case ENCHANT_LAYOUT:
@@ -558,7 +591,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
558591
default:
559592
if (setting.isUniversal()) return; // see addUniversalButton()
560593

561-
boxWidth = 31; // Default size and stuff.
594+
boxWidth = ButtonSettingToggle.WIDTH; // Default size and stuff.
562595
x = halfWidth - (boxWidth / 2);
563596
y = getRowHeightSetting(row);
564597
addRenderableWidget(new ButtonSettingToggle(x, y, setting.getMessage(), setting));

src/main/java/com/fix3dll/skyblockaddons/utils/data/skyblockdata/EnchantmentsData.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,42 @@ public String getUnformattedName() {
151151

152152
public Style getStyle(int level) {
153153
Feature feature = Feature.ENCHANTMENT_LORE_PARSING;
154-
FeatureSetting setting;
155-
if (level >= maxLevel) setting = FeatureSetting.PERFECT_ENCHANT_COLOR;
156-
else if (level > goodLevel) setting = FeatureSetting.GREAT_ENCHANT_COLOR;
157-
else if (level == goodLevel) setting = FeatureSetting.GOOD_ENCHANT_COLOR;
158-
else setting = FeatureSetting.POOR_ENCHANT_COLOR;
159-
int color = feature.getAsNumber(setting).intValue();
160-
if (color == ColorCode.CHROMA.getColor()) {
161-
return Style.EMPTY.withColor(DrawUtils.CHROMA_TEXT_COLOR);
154+
FeatureSetting colorSetting, boldSetting, italicSetting, underlinedSetting, strikethroughSetting;
155+
if (level >= maxLevel) {
156+
colorSetting = FeatureSetting.PERFECT_ENCHANT_COLOR;
157+
boldSetting = FeatureSetting.PERFECT_ENCHANT_BOLD;
158+
italicSetting = FeatureSetting.PERFECT_ENCHANT_ITALIC;
159+
underlinedSetting = FeatureSetting.PERFECT_ENCHANT_UNDERLINED;
160+
strikethroughSetting = FeatureSetting.PERFECT_ENCHANT_STRIKETHROUGH;
161+
} else if (level > goodLevel) {
162+
colorSetting = FeatureSetting.GREAT_ENCHANT_COLOR;
163+
boldSetting = FeatureSetting.GREAT_ENCHANT_BOLD;
164+
italicSetting = FeatureSetting.GREAT_ENCHANT_ITALIC;
165+
underlinedSetting = FeatureSetting.GREAT_ENCHANT_UNDERLINED;
166+
strikethroughSetting = FeatureSetting.GREAT_ENCHANT_STRIKETHROUGH;
167+
} else if (level == goodLevel) {
168+
colorSetting = FeatureSetting.GOOD_ENCHANT_COLOR;
169+
boldSetting = FeatureSetting.GOOD_ENCHANT_BOLD;
170+
italicSetting = FeatureSetting.GOOD_ENCHANT_ITALIC;
171+
underlinedSetting = FeatureSetting.GOOD_ENCHANT_UNDERLINED;
172+
strikethroughSetting = FeatureSetting.GOOD_ENCHANT_STRIKETHROUGH;
162173
} else {
163-
return Style.EMPTY.withColor(color);
174+
colorSetting = FeatureSetting.POOR_ENCHANT_COLOR;
175+
boldSetting = FeatureSetting.POOR_ENCHANT_BOLD;
176+
italicSetting = FeatureSetting.POOR_ENCHANT_ITALIC;
177+
underlinedSetting = FeatureSetting.POOR_ENCHANT_UNDERLINED;
178+
strikethroughSetting = FeatureSetting.POOR_ENCHANT_STRIKETHROUGH;
164179
}
180+
Style baseStyle = Style.EMPTY
181+
.withBold(feature.isEnabled(boldSetting))
182+
.withItalic(feature.isEnabled(italicSetting))
183+
.withUnderlined(feature.isEnabled(underlinedSetting))
184+
.withStrikethrough(feature.isEnabled(strikethroughSetting));
185+
186+
int colorCode = feature.getAsNumber(colorSetting).intValue();
187+
return colorCode == ColorCode.CHROMA.getColor()
188+
? baseStyle.withColor(DrawUtils.CHROMA_TEXT_COLOR)
189+
: baseStyle.withColor(colorCode);
165190
}
166191

167192
@Override
@@ -195,7 +220,7 @@ public static class Dummy extends Enchant {
195220

196221
public Dummy(String name) {
197222
loreName = name;
198-
nbtName = name.toLowerCase(Locale.US).replaceAll(" ", "_");
223+
nbtName = name.toLowerCase(Locale.US).replace(" ", "_");
199224
}
200225

201226
@Override

src/main/resources/defaults.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,31 @@
224224
"ENCHANT_LAYOUT": "NORMAL",
225225
"HIGHLIGHT_ENCHANTMENTS": true,
226226
"PERFECT_ENCHANT_COLOR": -2,
227+
"PERFECT_ENCHANT_BOLD": false,
228+
"PERFECT_ENCHANT_ITALIC": false,
229+
"PERFECT_ENCHANT_UNDERLINED": false,
230+
"PERFECT_ENCHANT_STRIKETHROUGH": false,
227231
"GREAT_ENCHANT_COLOR": -22016,
232+
"GREAT_ENCHANT_BOLD": false,
233+
"GREAT_ENCHANT_ITALIC": false,
234+
"GREAT_ENCHANT_UNDERLINED": false,
235+
"GREAT_ENCHANT_STRIKETHROUGH": false,
228236
"GOOD_ENCHANT_COLOR": -11184641,
237+
"GOOD_ENCHANT_BOLD": false,
238+
"GOOD_ENCHANT_ITALIC": false,
239+
"GOOD_ENCHANT_UNDERLINED": false,
240+
"GOOD_ENCHANT_STRIKETHROUGH": false,
229241
"POOR_ENCHANT_COLOR": -5592406,
230-
"COMMA_ENCHANT_COLOR": -11184641
242+
"POOR_ENCHANT_BOLD": false,
243+
"POOR_ENCHANT_ITALIC": false,
244+
"POOR_ENCHANT_UNDERLINED": false,
245+
"POOR_ENCHANT_STRIKETHROUGH": false,
246+
"COMMA_ENCHANT_COLOR": -11184641,
247+
"COMMA_ENCHANT_BOLD": false,
248+
"COMMA_ENCHANT_ITALIC": false,
249+
"COMMA_ENCHANT_UNDERLINED": false,
250+
"COMMA_ENCHANT_STRIKETHROUGH": false,
251+
"DEFAULT_COMMA_STYLE": false
231252
}
232253
},
233254
"SHOW_ITEM_COOLDOWNS": {

src/main/resources/enchants.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,14 +1363,14 @@
13631363
"stackLevel": [
13641364
0,
13651365
1000,
1366-
100000,
1367-
100000000,
1368-
1500000,
1369-
20000000,
1370-
25000,
1371-
300000,
13721366
5000,
1373-
5000000
1367+
25000,
1368+
100000,
1369+
250000,
1370+
1000000,
1371+
2500000,
1372+
10000000,
1373+
25000000
13741374
],
13751375
"statLabel": "cultivatedCrops",
13761376
"appliedTo": [

0 commit comments

Comments
 (0)