Skip to content

Commit 713f54c

Browse files
committed
feat: add new text formatting options for enchantment lore #185
1 parent 97ac743 commit 713f54c

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
@@ -115,12 +115,17 @@ else if (strippedLine.isBlank() && endEnchant == -1) {
115115
// Figure out whether the item tooltip is gonna wrap, and if so, try to make our enchantments wrap
116116
maxTooltipWidth = correctTooltipWidth(maxTooltipWidth);
117117

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

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

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

184187
List<Component> insertEnchants;
188+
boolean isCommaDefault = comma.getStyle().isEmpty();
185189
int commaLength = MC.font.width(COMMA);
186190
RegistrableEnum layout = feature.getAsEnum(FeatureSetting.ENCHANT_LAYOUT);
187191
// Pack as many enchantments as we can into one line (while not overstuffing it)
@@ -200,7 +204,10 @@ else if (strippedLine.isBlank() && endEnchant == -1) {
200204
sum = 0;
201205
}
202206
// Add to enchant followed by a comma
203-
loreLine.append(enchant.getFormattedComponent()).append(comma);
207+
Component formattedEnchantComponent = enchant.getFormattedComponent();
208+
loreLine.append(formattedEnchantComponent).append(
209+
isCommaDefault ? comma.copy().withStyle(formattedEnchantComponent.getStyle()) : comma
210+
);
204211
sum += enchant.getRenderLength() + commaLength;
205212
}
206213
// Flush any remaining enchants
@@ -216,9 +223,12 @@ else if (layout == EnchantLayout.NORMAL && !hasLore) {
216223
int i = 0;
217224
MutableComponent loreLine = Component.empty();
218225
for (FormattedEnchant enchant : orderedEnchants) {
219-
loreLine.append(enchant.getFormattedComponent());
226+
Component formattedEnchantComponent = enchant.getFormattedComponent();
227+
loreLine.append(formattedEnchantComponent);
220228
if (i % maxEnchantsPerLine < maxEnchantsPerLine - 1) {
221-
loreLine.append(comma);
229+
loreLine.append(
230+
isCommaDefault ? comma.copy().withStyle(formattedEnchantComponent.getStyle()) : comma
231+
);
222232
} else {
223233
insertEnchants.add(loreLine);
224234
loreLine = Component.empty();
@@ -373,6 +383,19 @@ private static int correctTooltipWidth(int maxTooltipWidth) {
373383
return maxTooltipWidth;
374384
}
375385

386+
private static Component findSibling(Component originalLine, EnchantmentsData.Enchant enchant) {
387+
List<Component> siblings = originalLine.getSiblings();
388+
if (siblings.isEmpty()) return null;
389+
390+
for (Component sibling : siblings) {
391+
if (sibling.getString().contains(enchant.getLoreName())) {
392+
return sibling;
393+
}
394+
}
395+
396+
return null;
397+
}
398+
376399
/**
377400
* Signals that the lore cache is stale due to a config change. The next call to
378401
* {@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
@@ -23,6 +23,9 @@ public class ButtonFeatureToggle extends ButtonFeature {
2323
private static final int ANIMATION_SLIDE_DISTANCE = 12;
2424
private static final int ANIMATION_SLIDE_TIME = 150;
2525

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

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

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

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

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

360-
boxWidth = 31;
363+
boxWidth = ButtonSettingToggle.WIDTH;
361364
x = halfWidth - (boxWidth / 2);
362365
y = getRowHeightSetting(row);
363366
addRenderableWidget(new ButtonSettingToggle(x, y, Translations.getMessage("settings.expandDeployableStatus"), setting));
@@ -435,7 +438,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
435438
break;
436439

437440
case TREVOR_SHOW_QUEST_COOLDOWN:
438-
boxWidth = 31; // Default size and stuff.
441+
boxWidth = ButtonSettingToggle.WIDTH;
439442
x = halfWidth - (boxWidth / 2);
440443
y = getRowHeightSetting(row);
441444
addRenderableWidget(new ButtonSettingToggle(x, y, setting.getMessage(), setting));
@@ -446,7 +449,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
446449
break;
447450

448451
case TREVOR_HIGHLIGHT_TRACKED_ENTITY:
449-
boxWidth = 31; // Default size and stuff.
452+
boxWidth = ButtonSettingToggle.WIDTH;
450453
x = halfWidth - (boxWidth / 2);
451454
y = getRowHeightSetting(row);
452455
addRenderableWidget(new ButtonSettingToggle(x, y, setting.getMessage(), setting));
@@ -457,7 +460,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
457460
break;
458461

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

495528
case ENCHANT_LAYOUT:
@@ -557,7 +590,7 @@ private void addButton(FeatureSetting setting, Object settingValue) {
557590
default:
558591
if (setting.isUniversal()) return; // see addUniversalButton()
559592

560-
boxWidth = 31; // Default size and stuff.
593+
boxWidth = ButtonSettingToggle.WIDTH; // Default size and stuff.
561594
x = halfWidth - (boxWidth / 2);
562595
y = getRowHeightSetting(row);
563596
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
@@ -150,17 +150,42 @@ public String getUnformattedName() {
150150

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

166191
@Override
@@ -194,7 +219,7 @@ public static class Dummy extends Enchant {
194219

195220
public Dummy(String name) {
196221
loreName = name;
197-
nbtName = name.toLowerCase(Locale.US).replaceAll(" ", "_");
222+
nbtName = name.toLowerCase(Locale.US).replace(" ", "_");
198223
}
199224

200225
@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)