diff options
| author | viciscat <51047087+viciscat@users.noreply.github.com> | 2024-07-06 18:18:20 +0200 |
|---|---|---|
| committer | viciscat <51047087+viciscat@users.noreply.github.com> | 2024-12-12 18:19:05 +0100 |
| commit | e39c1cc586306870579c3976d7393f23ab7fd3b9 (patch) | |
| tree | 6fc22a3605d1021f7733edf5d29fe76e66cf2cb7 /src/main | |
| parent | 16e002e467d69e37f4dfe88404c3c89fb232e232 (diff) | |
| download | Skyblocker-e39c1cc586306870579c3976d7393f23ab7fd3b9.tar.gz Skyblocker-e39c1cc586306870579c3976d7393f23ab7fd3b9.tar.bz2 Skyblocker-e39c1cc586306870579c3976d7393f23ab7fd3b9.zip | |
yea I don't remember what I did
Diffstat (limited to 'src/main')
8 files changed, 71 insertions, 136 deletions
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 95738542..7381a21a 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -169,7 +169,7 @@ public class UIAndVisualsConfig { public boolean plainPlayerNames = false; @SerialEntry - public ScreenBuilder.DefaultPositioner defaultPositioning = ScreenBuilder.DefaultPositioner.TOP; + public ScreenBuilder.DefaultPositioner defaultPositioning = ScreenBuilder.DefaultPositioner.CENTERED; @SerialEntry public NameSorting nameSorting = NameSorting.DEFAULT; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/PreviewTab.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/PreviewTab.java index b2c2ff36..92a0268f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/PreviewTab.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/PreviewTab.java @@ -17,6 +17,7 @@ import net.minecraft.client.gui.ScreenPos; import net.minecraft.client.gui.ScreenRect; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.tab.Tab; +import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.client.gui.widget.ScrollableWidget; @@ -47,6 +48,7 @@ public class PreviewTab implements Tab { private final WidgetsConfigurationScreen parent; private final WidgetOptionsScrollable widgetOptions; private final boolean dungeon; + private final ButtonWidget restorePositioning; private ScreenMaster.ScreenLayer currentScreenLayer = ScreenMaster.ScreenLayer.MAIN_TAB; private final ButtonWidget[] layerButtons; private final TextWidget textWidget; @@ -78,6 +80,14 @@ public class PreviewTab implements Tab { .build(); if (screenLayer == currentScreenLayer) layerButtons[i].active = false; } + + restorePositioning = ButtonWidget.builder(Text.literal("Restore Positioning"), button -> { + ScreenMaster.getScreenBuilder(getCurrentLocation()).restorePositioningFromBackup(); + updateWidgets(); + }) + .width(100) + .tooltip(Tooltip.of(Text.literal("Reset positions to before you opened this screen!"))) + .build(); } public void goToLayer(ScreenMaster.ScreenLayer layer) { @@ -97,20 +107,18 @@ public class PreviewTab implements Tab { consumer.accept(layerButton); } consumer.accept(widgetOptions); + consumer.accept(restorePositioning); if (dungeon) consumer.accept(textWidget); } @Override public void refreshGrid(ScreenRect tabArea) { - float scale = SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudScale / 100.f; - float ratio = Math.min((tabArea.height() - 5) / (parent.height / scale), (tabArea.width() - RIGHT_SIDE_WIDTH - 5) / (parent.width / scale)); + float ratio = Math.min((tabArea.height() - 35) / (float) (parent.height), (tabArea.width() - RIGHT_SIDE_WIDTH - 5) / (float) (parent.width)); previewWidget.setPosition(5, tabArea.getTop() + 5); previewWidget.setWidth((int) (parent.width * ratio)); previewWidget.setHeight((int) (parent.height * ratio)); previewWidget.ratio = ratio; - updatePlayerListFromPreview(); - ScreenBuilder screenBuilder = ScreenMaster.getScreenBuilder(getCurrentLocation()); - screenBuilder.positionWidgets(parent.width, parent.height); + updateWidgets(); for (int i = 0; i < layerButtons.length; i++) { ButtonWidget layerButton = layerButtons[i]; @@ -121,6 +129,7 @@ public class PreviewTab implements Tab { widgetOptions.setHeight(tabArea.height() - optionsY - 5); textWidget.setWidth(tabArea.width()); textWidget.setPosition(0, tabArea.getBottom() - 9); + restorePositioning.setPosition(10, tabArea.getBottom() - 25); forEachChild(clickableWidget -> clickableWidget.visible = parent.isPreviewVisible() || parent.noHandler); } @@ -246,7 +255,8 @@ public class PreviewTab implements Tab { void updateWidgets() { ScreenBuilder screenBuilder = ScreenMaster.getScreenBuilder(getCurrentLocation()); updatePlayerListFromPreview(); - screenBuilder.positionWidgets(parent.width, parent.height); + float scale = SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudScale / 100.f; + screenBuilder.positionWidgets((int) (parent.width / scale), (int) (parent.height / scale)); } private Location getCurrentLocation() { @@ -259,6 +269,9 @@ public class PreviewTab implements Tab { public class PreviewWidget extends ClickableWidget { private float ratio = 1f; + private float scaledRatio = 1f; + private float scaledScreenWidth = parent.width; + private float scaledScreenHeight = parent.height; /** * The widget the user is hovering with the mouse */ @@ -281,6 +294,10 @@ public class PreviewTab implements Tab { @Override protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { hoveredWidget = null; + float scale = SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudScale / 100.f; + scaledRatio = ratio * scale; + scaledScreenWidth = parent.width / scale; + scaledScreenHeight = parent.height / scale; ScreenBuilder screenBuilder = ScreenMaster.getScreenBuilder(getCurrentLocation()); context.drawBorder(getX() - 1, getY() - 1, getWidth() + 2, getHeight() + 2, -1); @@ -288,14 +305,12 @@ public class PreviewTab implements Tab { MatrixStack matrices = context.getMatrices(); matrices.push(); matrices.translate(getX(), getY(), 0f); - matrices.scale(ratio, ratio, 1f); + matrices.scale(scaledRatio, scaledRatio, 1f); screenBuilder.renderWidgets(context, PreviewTab.this.currentScreenLayer); - float localMouseX = (mouseX - getX()) / ratio; - float localMouseY = (mouseY - getY()) / ratio; - - context.drawBorder((int) localMouseX, (int) localMouseY, 2, 2, Colors.RED); + float localMouseX = (mouseX - getX()) / scaledRatio; + float localMouseY = (mouseY - getY()) / scaledRatio; for (HudWidget hudWidget : screenBuilder.getHudWidgets(PreviewTab.this.currentScreenLayer)) { if (hudWidget.isMouseOver(localMouseX, localMouseY)) { @@ -339,8 +354,8 @@ public class PreviewTab implements Tab { int thisAnchorX = (int) (selectedWidget.getX() + rule.thisPoint().horizontalPoint().getPercentage() * selectedWidget.getWidth()); int thisAnchorY = (int) (selectedWidget.getY() + rule.thisPoint().verticalPoint().getPercentage() * selectedWidget.getHeight()); - int translatedX = Math.min(thisAnchorX - rule.relativeX() - relativeX, parent.width - 2); - int translatedY = Math.min(thisAnchorY - rule.relativeY() - relativeY, parent.height - 2); + int translatedX = Math.min(thisAnchorX - rule.relativeX() - relativeX, (int) scaledScreenWidth - 2); + int translatedY = Math.min(thisAnchorY - rule.relativeY() - relativeY, (int) scaledScreenHeight - 2); renderUnits(context, relativeX, rule, thisAnchorX, thisAnchorY, relativeY, translatedX, translatedY); @@ -360,12 +375,12 @@ public class PreviewTab implements Tab { private void renderUnits(DrawContext context, int relativeX, PositionRule rule, int thisAnchorX, int thisAnchorY, int relativeY, int translatedX, int translatedY) { boolean xUnitOnTop = rule.relativeY() > 0; if (xUnitOnTop && thisAnchorY < 10) xUnitOnTop = false; - if (!xUnitOnTop && thisAnchorY > parent.height - 10) xUnitOnTop = true; + if (!xUnitOnTop && thisAnchorY > scaledScreenHeight - 10) xUnitOnTop = true; String yUnitText = String.valueOf(rule.relativeY() + relativeY); int yUnitTextWidth = client.textRenderer.getWidth(yUnitText); boolean yUnitOnRight = rule.relativeX() > 0; - if (yUnitOnRight && translatedX + 2 + yUnitTextWidth >= parent.width) yUnitOnRight = false; + if (yUnitOnRight && translatedX + 2 + yUnitTextWidth >= scaledScreenWidth) yUnitOnRight = false; if (!yUnitOnRight && translatedX - 2 - yUnitTextWidth <= 0) yUnitOnRight = true; // X @@ -383,8 +398,8 @@ public class PreviewTab implements Tab { @Override protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) { - double localDeltaX = deltaX / ratio + bufferedDeltaX; - double localDeltaY = deltaY / ratio + bufferedDeltaY; + double localDeltaX = deltaX / scaledRatio + bufferedDeltaX; + double localDeltaY = deltaY / scaledRatio + bufferedDeltaY; bufferedDeltaX = localDeltaX - (int) localDeltaX; bufferedDeltaY = localDeltaY - (int) localDeltaY; @@ -454,8 +469,8 @@ public class PreviewTab implements Tab { return true; } - double localMouseX = (mouseX - getX()) / ratio; - double localMouseY = (mouseY - getY()) / ratio; + double localMouseX = (mouseX - getX()) / scaledRatio; + double localMouseY = (mouseY - getY()) / scaledRatio; if (selectedWidget != null && selectedWidget.isMouseOver(localMouseX, localMouseY) && screenBuilder.getPositionRule(selectedWidget.getInternalID()) != null) { @@ -613,7 +628,8 @@ public class PreviewTab implements Tab { String internalID = affectedWidget.getInternalID(); PositionRule oldRule = screenBuilder.getPositionRuleOrDefault(internalID); // Get the x, y of the parent's point - ScreenPos startPos = WidgetPositioner.getStartPosition(oldRule.parent(), parent.width, parent.height, other ? hoveredPoint: oldRule.parentPoint()); + float scale = SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudScale / 100.f; + ScreenPos startPos = WidgetPositioner.getStartPosition(oldRule.parent(), (int) (parent.width / scale), (int) (parent.height / scale), other ? hoveredPoint: oldRule.parentPoint()); if (startPos == null) startPos = new ScreenPos(0, 0); // Same but for the affected widget PositionRule.Point thisPoint = other ? oldRule.thisPoint() : hoveredPoint; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java index d0339307..7e997b9e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsConfigurationScreen.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.skyblock.tabhud.config; import com.mojang.logging.LogUtils; +import de.hysky.skyblocker.skyblock.tabhud.screenbuilder.ScreenBuilder; import de.hysky.skyblocker.skyblock.tabhud.screenbuilder.ScreenMaster; import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr; import de.hysky.skyblocker.utils.ItemUtils; @@ -55,7 +56,7 @@ public class WidgetsConfigurationScreen extends Screen implements ScreenHandlerL Map.entry("the rift", Location.THE_RIFT), Map.entry("jerry's workshop", Location.WINTER_ISLAND) ); - private Location currentLocation = Location.HUB; + private Location currentLocation = Utils.getLocation(); public Location getCurrentLocation() { return currentLocation; @@ -90,6 +91,7 @@ public class WidgetsConfigurationScreen extends Screen implements ScreenHandlerL currentLocation = targetLocation; widgetsLayer = widgetLayerToGoTo; } + ScreenMaster.getScreenBuilder(currentLocation).backupPositioning(); } /** @@ -138,7 +140,7 @@ public class WidgetsConfigurationScreen extends Screen implements ScreenHandlerL this.tabNavigation.setWidth(this.width); this.tabNavigation.init(); int i = this.tabNavigation.getNavigationFocus().getBottom(); - ScreenRect screenRect = new ScreenRect(0, i, this.width, this.height - i - 20 /* A bit of a footer */); + ScreenRect screenRect = new ScreenRect(0, i, this.width, this.height - i - 5); this.tabManager.setTabArea(screenRect); } } @@ -160,12 +162,16 @@ public class WidgetsConfigurationScreen extends Screen implements ScreenHandlerL .trim(); if (nameToLocation.containsKey(trim)) { + Location old = currentLocation; currentLocation = nameToLocation.get(trim); + if (old != currentLocation) { + ScreenMaster.getScreenBuilder(currentLocation).backupPositioning(); + } } else { //currentLocation = Utils.getLocation(); - LOGGER.warn("[Skyblocker] Couldn't find location for {} (trimmed: {})", this.titleLowercase, trim); + if (this.titleLowercase.startsWith("widgets ")) + LOGGER.warn("[Skyblocker] Couldn't find location for {} (trimmed: {})", this.titleLowercase, trim); } - System.out.println("Curent location: " + currentLocation); } public GenericContainerScreenHandler getHandler() { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java index 0791c8a5..cc56b8c4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/config/WidgetsElementList.java @@ -42,8 +42,8 @@ public class WidgetsElementList extends ElementListWidget<WidgetsListEntry> { private int x, y, entryWidth, entryHeight; @Override - protected void renderList(DrawContext context, int mouseX, int mouseY, float delta) { - super.renderList(context, mouseX, mouseY, delta); + public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { + super.renderWidget(context, mouseX, mouseY, delta); WidgetsListEntry hoveredEntry = getHoveredEntry(); if (hoveredEntry != null) hoveredEntry.renderTooltip(context, x, y, entryWidth, entryHeight, mouseX, mouseY); if (rightUpArrowHovered || rightDownArrowHovered) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java index 2369d37f..ce9aacbb 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenBuilder.java @@ -23,6 +23,7 @@ public class ScreenBuilder { //private final String builderName; private final Map<String, PositionRule> positioning = new Object2ObjectOpenHashMap<>(); + private Map<String, PositionRule> positioningBackup = null; private final Location location; /** @@ -30,111 +31,6 @@ public class ScreenBuilder { */ public ScreenBuilder(Location location) { this.location = location; - - /*try (BufferedReader reader = MinecraftClient.getInstance().getResourceManager().openAsReader(ident)) { - this.builderName = ident.getPath(); - - JsonObject json = JsonParser.parseReader(reader).getAsJsonObject(); - - JsonArray widgets = json.getAsJsonArray("widgets"); - JsonArray layout = json.getAsJsonArray("layout"); - - for (JsonElement w : widgets) { - JsonObject widget = w.getAsJsonObject(); - String name = widget.get("name").getAsString(); - String alias = widget.get("alias").getAsString(); - - HudWidget wid = instanceFrom(name, widget); - objectMap.put(alias, wid); - instances.add(wid); - } - - for (JsonElement l : layout) { - PipelineStage ps = createStage(l.getAsJsonObject()); - layoutPipeline.add(ps); - } - } catch (Exception ex) { - // rethrow as unchecked exception so that I don't have to catch anything in the ScreenMaster - throw new IllegalStateException("Failed to load file " + ident + ". Reason: " + ex.getMessage()); - }*/ - } - - /** - * Try to find a class in the widget package that has the supplied name and - * call it's constructor. Manual work is required if the class has arguments. - */ - public HudWidget instanceFrom(String name, JsonObject widget) { - - /*// do widgets that require args the normal way - JsonElement arg; - switch (name) { - case "DungeonPlayerWidget" -> { - return new DungeonPlayerWidget(widget.get("player").getAsInt()); - } - case "ErrorWidget" -> { - arg = widget.get("text"); - if (arg == null) { - return new ErrorWidget(); - } else { - return new ErrorWidget(arg.getAsString()); - } - } - case "Widget" -> - // clown case sanity check. don't instantiate the superclass >:| - throw new NoSuchElementException(builderName + "[ERROR]: No such Widget type \"Widget\"!"); - } - - // reflect something together for the "normal" ones. - - // list all packages that might contain widget classes - // using Package isn't reliable, as some classes might not be loaded yet, - // causing the packages not to show. - String packbase = "de.hysky.skyblocker.skyblock.tabhud.widget"; - String[] packnames = { - packbase, - packbase + ".rift" - }; - - // construct the full class name and try to load. - Class<?> clazz = null; - for (String pn : packnames) { - try { - clazz = Class.forName(pn + "." + name); - } catch (LinkageError | ClassNotFoundException ex) { - continue; - } - } - - // load failed. - if (clazz == null) { - throw new NoSuchElementException(builderName + "/[ERROR]: No such Widget type \"" + name + "\"!"); - } - - // return instance of that class. - try { - Constructor<?> ctor = clazz.getConstructor(); - return (HudWidget) ctor.newInstance(); - } catch (NoSuchMethodException | InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException | SecurityException ex) { - throw new IllegalStateException(builderName + "/" + name + ": Internal error..."); - }*/ - return null; - } - - /** - * Create a PipelineStage from a json object. - */ - public PipelineStage createStage(JsonObject descr) throws NoSuchElementException { - - String op = descr.get("op").getAsString(); - - return switch (op) { - case "place" -> new PlaceStage(this, descr); - case "stack" -> new StackStage(this, descr); - case "align" -> new AlignStage(this, descr); - case "collideAgainst" -> new CollideStage(this, descr); - default -> throw new NoSuchElementException("No such op " + op + " as requested by "); - }; } public @Nullable PositionRule getPositionRule(String widgetInternalId) { @@ -155,6 +51,17 @@ public class ScreenBuilder { else positioning.put(widgetInternalId, newPositionRule); } + public void backupPositioning() { + positioningBackup = Map.copyOf(positioning); + } + + public void restorePositioningFromBackup() { + if (positioningBackup == null) return; + positioning.clear(); + positioning.putAll(positioningBackup); + positioningBackup = null; + } + /** * Lookup Widget instance from alias name */ @@ -238,6 +145,9 @@ public class ScreenBuilder { } } + /** + * Renders the widgets present on the specified layer. Doesn't scale with the config option. + */ public void renderWidgets(DrawContext context, ScreenMaster.ScreenLayer screenLayer) { List<HudWidget> widgetsToRender = getHudWidgets(screenLayer); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java index abbdebb8..6184767f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/screenbuilder/ScreenMaster.java @@ -23,6 +23,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.Window; +import net.minecraft.client.util.math.MatrixStack; import org.slf4j.Logger; import java.io.BufferedReader; @@ -162,7 +163,11 @@ public class ScreenMaster { MinecraftClient client = MinecraftClient.getInstance(); Window window = client.getWindow(); float scale = SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudScale / 100f; + MatrixStack matrices = context.getMatrices(); + matrices.push(); + matrices.scale(scale, scale, 1.F); render(context, (int) (window.getScaledWidth() / scale), (int) (window.getScaledHeight() / scale)); + matrices.pop(); }); ClientLifecycleEvents.CLIENT_STARTED.register(client -> { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java index 642ebc08..7100fe1e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java @@ -42,7 +42,7 @@ import java.util.regex.Pattern; public class PlayerListMgr { public static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Regex"); - private static final Pattern PLAYERS_COLUMN_PATTERN = Pattern.compile("(^|\\s*)(Players \\(\\d+\\)|Island)(\\s*|$)"); + private static final Pattern PLAYERS_COLUMN_PATTERN = Pattern.compile("(^|\\s*)(Players \\(\\d+\\)|Island|Coop \\(\\d+\\))(\\s*|$)"); private static final Pattern INFO_COLUMN_PATTERN = Pattern.compile("(^|\\s*)Info(\\s*|$)"); /** @@ -60,6 +60,7 @@ public class PlayerListMgr { public static void updateList() { if (!Utils.isOnSkyblock() || !SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudEnabled) { + if (!tabWidgetsToShow.isEmpty()) tabWidgetsToShow.clear(); return; } 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 fb100c48..a6e901ba 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 @@ -91,9 +91,6 @@ public abstract class ComponentBasedWidget extends HudWidget { RenderSystem.enableDepthTest(); ms.push(); - float scale = SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudScale / 100f; - ms.scale(scale, scale, 1); - // move above other UI elements ms.translate(0, 0, 200); if (SkyblockerConfigManager.get().uiAndVisuals.tabHud.enableHudBackground) { |
