diff options
| author | Sage <salbeira@gmail.com> | 2025-07-26 21:13:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-26 15:13:07 -0400 |
| commit | 308ca74fb4480d75146ede4bfb355e856084bf11 (patch) | |
| tree | 5290df095e9ab019edebfa7319e73b18ff30bc5a /src | |
| parent | c7095baac13db03eb8d0d0d6d2e1572a0555b129 (diff) | |
| download | Skyblocker-308ca74fb4480d75146ede4bfb355e856084bf11.tar.gz Skyblocker-308ca74fb4480d75146ede4bfb355e856084bf11.tar.bz2 Skyblocker-308ca74fb4480d75146ede4bfb355e856084bf11.zip | |
add option to split sack and inventory notifications of pickup widget (#1387)
* add option to split sack and inventory notifications of pickup widget
* Formatting
* Make Line without Text the same as Line with Text
* allow component to get information about parent widget to render separator line without hacks
* some cleanup
* update to pass the spotless check
* adhere to new config codestyle
---------
Co-authored-by: Sebastian Hauer <sebastian.hauer@tu-dortmund.de>
Diffstat (limited to 'src')
6 files changed, 121 insertions, 13 deletions
diff --git a/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java index 87b8a0a3..5da332e3 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/UIAndVisualsCategory.java @@ -809,6 +809,14 @@ public class UIAndVisualsCategory { newValue -> config.uiAndVisuals.itemPickup.lifeTime = newValue) .controller(IntegerController.createBuilder().range(1, 10).slider(1).build()) .build()) + .option(Option.<Boolean>createBuilder() + .name(Text.translatable("skyblocker.config.uiAndVisuals.itemPickup.splitSack")) + .description(Text.translatable("skyblocker.config.uiAndVisuals.itemPickup.splitSack.@Tooltip")) + .binding(defaults.uiAndVisuals.itemPickup.splitNotifications, + () -> config.uiAndVisuals.itemPickup.splitNotifications, + newValue -> config.uiAndVisuals.itemPickup.splitNotifications = newValue) + .controller(ConfigUtils.createBooleanController()) + .build()) .build() ) .build(); diff --git a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java index d0592437..9ad54784 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -388,5 +388,7 @@ public class UIAndVisualsConfig { public boolean showItemName = true; public int lifeTime = 3; + + public boolean splitNotifications = false; } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/ItemPickupWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/ItemPickupWidget.java index 234da0cb..6d001ccd 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/ItemPickupWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/ItemPickupWidget.java @@ -7,6 +7,7 @@ import de.hysky.skyblocker.skyblock.itemlist.ItemRepository; import de.hysky.skyblocker.skyblock.tabhud.config.WidgetsConfigurationScreen; import de.hysky.skyblocker.skyblock.tabhud.util.Ico; import de.hysky.skyblocker.skyblock.tabhud.widget.ComponentBasedWidget; +import de.hysky.skyblocker.skyblock.tabhud.widget.component.SeparatorComponent; import de.hysky.skyblocker.utils.Formatters; import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.NEURepoManager; @@ -40,6 +41,9 @@ public class ItemPickupWidget extends ComponentBasedWidget { private final Object2ObjectOpenHashMap<String, ChangeData> addedCount = new Object2ObjectOpenHashMap<>(); private final Object2ObjectOpenHashMap<String, ChangeData> removedCount = new Object2ObjectOpenHashMap<>(); + private final Object2ObjectOpenHashMap<String, ChangeData> addedSackCount = new Object2ObjectOpenHashMap<>(); + private final Object2ObjectOpenHashMap<String, ChangeData> removedSackCount = new Object2ObjectOpenHashMap<>(); + public ItemPickupWidget() { super(Text.literal("Items"), Formatting.AQUA.getColorValue(), "Item Pickup"); instance = this; @@ -84,17 +88,17 @@ public class ItemPickupWidget extends ComponentBasedWidget { //positive int existingCount = 0; if (matcher.group(1).equals("+")) { - if (addedCount.containsKey(item.getNeuName())) { - existingCount = addedCount.get(item.getNeuName()).amount; + if (addedSackCount.containsKey(item.getNeuName())) { + existingCount = addedSackCount.get(item.getNeuName()).amount; } - addedCount.put(item.getNeuName(), new ChangeData(item, existingCount + Formatters.parseNumber(matcher.group(2)).intValue(), System.currentTimeMillis())); + addedSackCount.put(item.getNeuName(), new ChangeData(item, existingCount + Formatters.parseNumber(matcher.group(2)).intValue(), System.currentTimeMillis())); } //negative else if (matcher.group(1).equals("-")) { - if (removedCount.containsKey(item.getNeuName())) { - existingCount = removedCount.get(item.getNeuName()).amount; + if (removedSackCount.containsKey(item.getNeuName())) { + existingCount = removedSackCount.get(item.getNeuName()).amount; } - removedCount.put(item.getNeuName(), new ChangeData(item, existingCount - Formatters.parseNumber(matcher.group(2)).intValue(), System.currentTimeMillis())); + removedSackCount.put(item.getNeuName(), new ChangeData(item, existingCount - Formatters.parseNumber(matcher.group(2)).intValue(), System.currentTimeMillis())); } } @@ -112,6 +116,30 @@ public class ItemPickupWidget extends ComponentBasedWidget { addSimpleIcoText(Ico.BONE, "Bone ", Formatting.GREEN, "+64"); return; } + // If the notifications should not be split, merge the counts. + boolean split = SkyblockerConfigManager.get().uiAndVisuals.itemPickup.splitNotifications; + if (!split) { + for (String item : addedSackCount.keySet()) { + ChangeData sackEntry = addedSackCount.get(item); + if (addedCount.containsKey(item)) { + ChangeData generalEntry = addedCount.get(item); + addedCount.put(item, new ChangeData(generalEntry.item, generalEntry.amount + sackEntry.amount, System.currentTimeMillis())); + } else { + addedCount.put(item, new ChangeData(sackEntry.item, sackEntry.amount, System.currentTimeMillis())); + } + } + for (String item : removedSackCount.keySet()) { + ChangeData sackEntry = removedSackCount.get(item); + if (removedCount.containsKey(item)) { + ChangeData generalEntry = removedCount.get(item); + removedCount.put(item, new ChangeData(generalEntry.item, generalEntry.amount + sackEntry.amount, System.currentTimeMillis())); + } else { + removedCount.put(item, new ChangeData(sackEntry.item, sackEntry.amount, System.currentTimeMillis())); + } + } + addedSackCount.clear(); + removedSackCount.clear(); + } //add each diff item to the widget //add positive changes for (String item : addedCount.keySet()) { @@ -133,6 +161,28 @@ public class ItemPickupWidget extends ComponentBasedWidget { } addSimpleIcoText(entry.item, itemName, Formatting.RED, Formatters.DIFF_NUMBERS.format(entry.amount)); } + if (split && !(this.addedSackCount.isEmpty() && this.removedSackCount.isEmpty())) { + // Remove the borders and some random 8 value I do not know where that comes from from the width of the widget to make it fit. + this.addComponent(new SeparatorComponent(Text.of("Sacks"))); + for (String item : addedSackCount.keySet()) { + ChangeData entry = addedSackCount.get(item); + String itemName = checkNextItem(entry); + if (itemName == null) { + addedSackCount.remove(item); + continue; + } + addSimpleIcoText(entry.item, itemName, Formatting.GREEN, Formatters.DIFF_NUMBERS.format(entry.amount)); + } + for (String item : removedSackCount.keySet()) { + ChangeData entry = removedSackCount.get(item); + String itemName = checkNextItem(entry); + if (itemName == null) { + removedSackCount.remove(item); + continue; + } + addSimpleIcoText(entry.item, itemName, Formatting.RED, Formatters.DIFF_NUMBERS.format(entry.amount)); + } + } } /** @@ -156,7 +206,7 @@ public class ItemPickupWidget extends ComponentBasedWidget { //render if enabled if (SkyblockerConfigManager.get().uiAndVisuals.itemPickup.enabled) { //render if there are items in history - return !addedCount.isEmpty() || !removedCount.isEmpty(); + return !addedCount.isEmpty() || !removedCount.isEmpty() || !addedSackCount.isEmpty() || !removedSackCount.isEmpty(); } } return false; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ComponentBasedWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ComponentBasedWidget.java index 4abfe1d6..825f5a93 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ComponentBasedWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ComponentBasedWidget.java @@ -41,13 +41,13 @@ public abstract class ComponentBasedWidget extends HudWidget { private int prevW = 0, prevH = 0; - static final int BORDER_SZE_N = txtRend.fontHeight + 4; - static final int BORDER_SZE_S = 4; - static final int BORDER_SZE_W = 4; - static final int BORDER_SZE_E = 4; - static final int DEFAULT_COL_BG_BOX = 0xc00c0c0c; + public static final int BORDER_SZE_N = txtRend.fontHeight + 4; + public static final int BORDER_SZE_S = 4; + public static final int BORDER_SZE_W = 4; + public static final int BORDER_SZE_E = 4; + public static final int DEFAULT_COL_BG_BOX = 0xc00c0c0c; // More transparent background for minimal style - static final int MINIMAL_COL_BG_BOX = 0x64000000; + public static final int MINIMAL_COL_BG_BOX = 0x64000000; private final int color; private final Text title; @@ -66,6 +66,7 @@ public abstract class ComponentBasedWidget extends HudWidget { } public void addComponent(Component c) { + c.setParent(this); this.components.add(c); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/Component.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/Component.java index 42f78916..2247cb32 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/Component.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/Component.java @@ -1,5 +1,6 @@ package de.hysky.skyblocker.skyblock.tabhud.widget.component; +import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; @@ -18,8 +19,18 @@ public abstract class Component { // these should always be the content dimensions without any padding. int width, height; + private Widget parent; + public abstract void render(DrawContext context, int x, int y); + public void setParent(Widget parent) { + this.parent = parent; + } + + public Widget getParent() { + return this.parent; + } + public int getWidth() { return this.width; } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/SeparatorComponent.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/SeparatorComponent.java new file mode 100644 index 00000000..0cfe173f --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/component/SeparatorComponent.java @@ -0,0 +1,36 @@ +package de.hysky.skyblocker.skyblock.tabhud.widget.component; + +import de.hysky.skyblocker.skyblock.tabhud.widget.ComponentBasedWidget; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.Text; + +/** + * Component that draws a line with optional text across a widget box. + * Can be used to separate information visible in a widget into different categories. + */ +public class SeparatorComponent extends Component { + + private final Text text; + private final int textWidth; + + public SeparatorComponent(Text text) { + this.text = text; + this.textWidth = text != null ? txtRend.getWidth(text) : 0; + this.height = txtRend.fontHeight; + this.width = textWidth + 4; + } + + @Override + public void render(DrawContext context, int x, int y) { + int parentWidth = this.getParent().getWidth(); + if (text != null && !text.equals(Text.of(""))) { + context.fill(x - (ComponentBasedWidget.BORDER_SZE_E / 2), y + this.height / 2, x + 2, y + this.height / 2 + 1, 0xff55ffff); + context.drawText(txtRend, text, x + 4, y, 0xff55ffff, false); + context.fill(x + textWidth + 2 + 4, y + this.height / 2, x + parentWidth - ComponentBasedWidget.BORDER_SZE_E - ComponentBasedWidget.BORDER_SZE_W + 2, y + this.height / 2 + 1, 0xff55ffff); + } else { + context.fill(x - 2, y + this.height / 2, x + parentWidth - ComponentBasedWidget.BORDER_SZE_E - ComponentBasedWidget.BORDER_SZE_W + 2, y + this.height / 2 + 1, 0xff55ffff); + } + + } + +} |
