aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/java/kr/syeyoung
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2023-01-18 08:32:56 +0900
committersyeyoung <cyoung06@naver.com>2023-01-18 08:32:56 +0900
commit470585150a1f2a506215e17bc9b9871bfdd80aa6 (patch)
tree5a8b38c5f02c74a595c781aa126e81493864458f /mod/src/main/java/kr/syeyoung
parent75c0a7edec9fb7a64a3df5f19e52342036e5bf41 (diff)
downloadSkyblock-Dungeons-Guide-470585150a1f2a506215e17bc9b9871bfdd80aa6.tar.gz
Skyblock-Dungeons-Guide-470585150a1f2a506215e17bc9b9871bfdd80aa6.tar.bz2
Skyblock-Dungeons-Guide-470585150a1f2a506215e17bc9b9871bfdd80aa6.zip
- gui overhaul and stuff
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src/main/java/kr/syeyoung')
-rwxr-xr-xmod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java3
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java5
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractFeature.java2
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractGuiFeature.java62
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/GuiFeature.java29
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java14
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetInvite.java18
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetJoinRequest.java18
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetPartyInviteViewer.java2
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/onlinealarm/PlayingDGAlarm.java10
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/DomElement.java5
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/Widget.java1
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/ConstrainedBox.java8
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/SelectiveContainer.java64
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java1
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManagerRootWidget.java1
16 files changed, 202 insertions, 41 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java
index bda96e56..960c927a 100755
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java
@@ -71,7 +71,6 @@ public class SkyblockStatus {
}
-
public static boolean isOnSkyblock(){
SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus();
@@ -94,7 +93,7 @@ public class SkyblockStatus {
@Setter
private boolean forceIsOnDungeon;
- public boolean isOnHypixel() {
+ public static boolean isOnHypixel() {
Minecraft mc = Minecraft.getMinecraft();
if (mc == null || mc.thePlayer == null) return false;
if (!mc.isSingleplayer() && mc.thePlayer.getClientBrand() != null) {
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java
index 6771fc62..a0d3df8a 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java
@@ -226,7 +226,7 @@ public class DiscordIntegrationManager implements IPCListener {
presence.setJoinSecret(PartyManager.INSTANCE.getAskToJoinSecret());
}
presence.setInstance(false);
-// sendRichPresence(presence.build());
+ sendRichPresence(presence.build());
}
}
private void run() {
@@ -249,8 +249,11 @@ public class DiscordIntegrationManager implements IPCListener {
+ private long next = 0;
public void onActivityJoin(Packet packet) {
String secret = packet.getJson().getJSONObject("data").getString("secret");
+ if (System.currentTimeMillis() < next) return;
+ next = System.currentTimeMillis() + 500;
PartyManager.INSTANCE.joinWithToken(secret);
logger.log(Level.DEBUG, "Trying to join with token: "+secret);
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractFeature.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractFeature.java
index 59029dde..4d1e4892 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractFeature.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractFeature.java
@@ -73,7 +73,7 @@ public abstract class AbstractFeature implements IFeature {
}
public void loadConfig(JsonObject jsonObject) { // gets key, calls it
- enabled = jsonObject.get("$enabled").getAsBoolean();
+ setEnabled(jsonObject.get("$enabled").getAsBoolean());
for (Map.Entry<String, FeatureParameter> parameterEntry : parameters.entrySet()) {
parameterEntry.getValue().setToDefault();
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractGuiFeature.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractGuiFeature.java
new file mode 100644
index 00000000..c8112dbe
--- /dev/null
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractGuiFeature.java
@@ -0,0 +1,62 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2023 cyoung06 (syeyoung)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.mod.features;
+
+import kr.syeyoung.dungeonsguide.mod.guiv2.Widget;
+import kr.syeyoung.dungeonsguide.mod.overlay.OverlayManager;
+import kr.syeyoung.dungeonsguide.mod.overlay.OverlayWidget;
+
+public abstract class AbstractGuiFeature extends AbstractFeature {
+ protected AbstractGuiFeature(String category, String name, String description, String key) {
+ super(category, name, description, key);
+ getWidget();
+ }
+
+ public abstract OverlayWidget instantiateWidget();
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ checkVisibility();
+ }
+
+ private boolean wasVisible = false;
+ private OverlayWidget widget;
+ public OverlayWidget getWidget() {
+ if (widget == null) widget = instantiateWidget();
+ return widget;
+ }
+ public void checkVisibility() {
+ boolean shouldBeVisible = isVisible();
+ if (!wasVisible && shouldBeVisible) {
+ OverlayManager.getInstance().addOverlay(getWidget());
+ } else if (wasVisible && !shouldBeVisible) {
+ OverlayManager.getInstance().removeOverlay(getWidget());
+ }
+ wasVisible = shouldBeVisible;
+ }
+
+ public void updatePosition() {
+ if (isVisible())
+ OverlayManager.getInstance().updateOverlayPosition(getWidget());
+ }
+ public boolean isVisible() {
+ return isEnabled();
+ }
+}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/GuiFeature.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/GuiFeature.java
index 6b255f8d..fba7aa86 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/GuiFeature.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/GuiFeature.java
@@ -58,12 +58,12 @@ import java.util.Collections;
import java.util.List;
@Getter
-public abstract class GuiFeature extends AbstractFeature {
+public abstract class GuiFeature extends AbstractGuiFeature {
private GUIRectangle featureRect;
public void setFeatureRect(GUIRectangle featureRect) {
this.featureRect = featureRect;
- OverlayManager.getInstance().updateOverlayPosition(widget);
+ updatePosition();
}
@Setter(value = AccessLevel.PROTECTED)
@@ -74,8 +74,6 @@ public abstract class GuiFeature extends AbstractFeature {
private double defaultHeight;
private final double defaultRatio;
- private OverlayWidget widget;
-
protected GuiFeature(String category, String name, String description, String key, boolean keepRatio, int width, int height) {
super(category, name, description, key);
this.keepRatio = keepRatio;
@@ -83,16 +81,6 @@ public abstract class GuiFeature extends AbstractFeature {
this.defaultHeight = height;
this.defaultRatio = defaultWidth / defaultHeight;
this.featureRect = new GUIRectangle(0, 0, width, height);
-
- widget = new OverlayWidget(
- new WidgetFeatureWrapper(),
- OverlayType.UNDER_CHAT,
- () -> {
- Rectangle loc = featureRect.getRectangleNoScale();
- return new Rect(loc.x, loc.y, loc.width, loc.height);
- }
- );
- OverlayManager.getInstance().addOverlay(widget);
}
public class WidgetFeatureWrapper extends Widget implements Renderer, Layouter {
@@ -112,6 +100,17 @@ public abstract class GuiFeature extends AbstractFeature {
}
}
+ public OverlayWidget instantiateWidget() {
+ return new OverlayWidget(
+ new WidgetFeatureWrapper(),
+ OverlayType.UNDER_CHAT,
+ () -> {
+ Rectangle loc = featureRect.getRectangleNoScale();
+ return new Rect(loc.x, loc.y, loc.width, loc.height);
+ }
+ );
+ }
+
public void drawScreen(float partialTicks) {
Rectangle featureRect = this.featureRect.getRectangleNoScale();
clip(featureRect.x, featureRect.y, featureRect.width, featureRect.height);
@@ -142,7 +141,7 @@ public abstract class GuiFeature extends AbstractFeature {
public void loadConfig(JsonObject jsonObject) {
super.loadConfig(jsonObject);
this.featureRect = TypeConverterRegistry.getTypeConverter("guirect",GUIRectangle.class).deserialize(jsonObject.get("$bounds"));
- OverlayManager.getInstance().updateOverlayPosition(widget);
+ updatePosition();
}
@Override
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java
index e849c210..41444669 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java
@@ -20,11 +20,13 @@ package kr.syeyoung.dungeonsguide.mod.features.impl.discord.inviteViewer;
import kr.syeyoung.dungeonsguide.mod.DungeonsGuide;
+import kr.syeyoung.dungeonsguide.mod.SkyblockStatus;
import kr.syeyoung.dungeonsguide.mod.discord.DiscordIntegrationManager;
import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler;
import kr.syeyoung.dungeonsguide.mod.events.impl.DGTickEvent;
import kr.syeyoung.dungeonsguide.mod.events.impl.DiscordUserInvitedEvent;
import kr.syeyoung.dungeonsguide.mod.events.impl.DiscordUserJoinRequestEvent;
+import kr.syeyoung.dungeonsguide.mod.features.AbstractGuiFeature;
import kr.syeyoung.dungeonsguide.mod.features.FeatureParameter;
import kr.syeyoung.dungeonsguide.mod.features.SimpleFeature;
import kr.syeyoung.dungeonsguide.mod.guiv2.elements.image.ImageTexture;
@@ -50,19 +52,22 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
-public class PartyInviteViewer extends SimpleFeature {
+public class PartyInviteViewer extends AbstractGuiFeature {
private WidgetPartyInviteViewer partyInviteViewer;
private OverlayWidget widget;
public PartyInviteViewer() {
super("Discord", "Party Invite Viewer","Simply type /dg asktojoin or /dg atj to toggle whether ask-to-join would be presented as option on discord!\n\nRequires Discord RPC to be enabled", "discord.discord_party_invite_viewer");
addParameter("ttl", new FeatureParameter<Integer>("ttl", "Request Duration", "The duration after which the requests will be dismissed automatically. The value is in seconds.", 15, "integer"));
- widget = new OverlayWidget(
+ }
+
+ @Override
+ public OverlayWidget instantiateWidget() {
+ return new OverlayWidget(
partyInviteViewer = new WidgetPartyInviteViewer(),
OverlayType.OVER_ANY,
() -> new Rect(0,0,Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)
);
- OverlayManager.getInstance().addOverlay(widget);
}
@Override
@@ -85,6 +90,7 @@ public class PartyInviteViewer extends SimpleFeature {
}
@DGEventHandler(triggerOutOfSkyblock = true)
public void onDiscordUserJoinRequest(DiscordUserInvitedEvent event) {
- partyInviteViewer.addInvite(event);
+ if (SkyblockStatus.isOnHypixel())
+ partyInviteViewer.addInvite(event);
}
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetInvite.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetInvite.java
index ebad7821..b780bf3b 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetInvite.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetInvite.java
@@ -36,9 +36,15 @@ public class WidgetInvite extends AnnotatedWidget implements TTL {
public final BindableAttribute<String> discriminator;
@Bind(variableName = "avatarUrl")
public final BindableAttribute<String> avatarURL;
+ @Bind(variableName = "visible")
+ public final BindableAttribute<String> visiblePage = new BindableAttribute<>(String.class, "buttons");
+
private WidgetPartyInviteViewer inviteViewer;
private DiscordUserInvitedEvent event;
private long start;
+
+
+ private boolean actionDone = false;
public WidgetInvite(WidgetPartyInviteViewer parent, DiscordUserInvitedEvent invitedEvent) {
super(new ResourceLocation("dungeonsguide:gui/features/discordParty/invite.gui"));
this.inviteViewer = parent;
@@ -55,21 +61,25 @@ public class WidgetInvite extends AnnotatedWidget implements TTL {
@On(functionName = "accept")
public void accept() {
- inviteViewer.remove(this);
+ actionDone = true;
+ visiblePage.setValue("accepted");
+ start = System.currentTimeMillis();
DiscordIntegrationManager.INSTANCE.acceptInvite(event.getHandle());
}
@On(functionName = "deny")
public void deny() {
- inviteViewer.remove(this);
+ actionDone = true;
+ visiblePage.setValue("denied");
+ start = System.currentTimeMillis();
}
@Override
public long startedDisplaying() {
- return 0;
+ return start;
}
@Override
public long ttl() {
- return FeatureRegistry.DISCORD_ASKTOJOIN.<Integer>getParameter("ttl").getValue() * 1000;
+ return actionDone ? 2000 : FeatureRegistry.DISCORD_ASKTOJOIN.<Integer>getParameter("ttl").getValue() * 1000;
}
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetJoinRequest.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetJoinRequest.java
index 7c51636b..ef5e25e0 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetJoinRequest.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetJoinRequest.java
@@ -35,9 +35,13 @@ public class WidgetJoinRequest extends AnnotatedWidget implements TTL{
public final BindableAttribute<String> discriminator;
@Bind(variableName = "avatarUrl")
public final BindableAttribute<String> avatarURL;
+ @Bind(variableName = "visible")
+ public final BindableAttribute<String> visiblePage = new BindableAttribute<>(String.class, "buttons");
+
private WidgetPartyInviteViewer inviteViewer;
private DiscordUserJoinRequestEvent event;
private long start;
+ private boolean actionDone = false;
public WidgetJoinRequest(WidgetPartyInviteViewer parent, DiscordUserJoinRequestEvent joinRequestEvent) {
super(new ResourceLocation("dungeonsguide:gui/features/discordParty/joinRequest.gui"));
this.inviteViewer = parent;
@@ -54,17 +58,23 @@ public class WidgetJoinRequest extends AnnotatedWidget implements TTL{
@On(functionName = "accept")
public void accept() {
- inviteViewer.remove(this);
+ start = System.currentTimeMillis();
+ visiblePage.setValue("accepted");
+ actionDone = true;
DiscordIntegrationManager.INSTANCE.respondToJoinRequest(event.getDiscordUser().getId(), Reply.ACCEPT);
}
@On(functionName = "deny")
public void deny() {
- inviteViewer.remove(this);
+ start = System.currentTimeMillis();
+ visiblePage.setValue("denied");
+ actionDone = true;
DiscordIntegrationManager.INSTANCE.respondToJoinRequest(event.getDiscordUser().getId(), Reply.DENY);
}
@On(functionName = "ignore")
public void ignore() {
- inviteViewer.remove(this);
+ start = System.currentTimeMillis();
+ visiblePage.setValue("ignored");
+ actionDone = true;
DiscordIntegrationManager.INSTANCE.respondToJoinRequest(event.getDiscordUser().getId(), Reply.IGNORE);
}
@@ -75,6 +85,6 @@ public class WidgetJoinRequest extends AnnotatedWidget implements TTL{
@Override
public long ttl() {
- return FeatureRegistry.DISCORD_ASKTOJOIN.<Integer>getParameter("ttl").getValue() * 1000;
+ return actionDone ? 2000 : FeatureRegistry.DISCORD_ASKTOJOIN.<Integer>getParameter("ttl").getValue() * 1000;
}
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetPartyInviteViewer.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetPartyInviteViewer.java
index 969e7f94..e7afcb4d 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetPartyInviteViewer.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/WidgetPartyInviteViewer.java
@@ -52,10 +52,10 @@ public class WidgetPartyInviteViewer extends AnnotatedWidget {
public void addInvite(DiscordUserInvitedEvent inviteEvent) {
if (inviteUid.contains(inviteEvent.getDiscordUser().getId())) return;
- inviteUid.add(inviteEvent.getDiscordUser().getId());
WidgetInvite invite;
columnApi.getValue().addWidget(invite = new WidgetInvite(this, inviteEvent));
widgetList.add(invite);
+ inviteUid.add(inviteEvent.getDiscordUser().getId());
}
public void remove(Widget widget) {
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/onlinealarm/PlayingDGAlarm.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/onlinealarm/PlayingDGAlarm.java
index 09cd4ed3..83160231 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/onlinealarm/PlayingDGAlarm.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/onlinealarm/PlayingDGAlarm.java
@@ -24,6 +24,7 @@ import kr.syeyoung.dungeonsguide.mod.discord.JDiscordRelation;
import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler;
import kr.syeyoung.dungeonsguide.mod.events.impl.DGTickEvent;
import kr.syeyoung.dungeonsguide.mod.events.impl.DiscordUserUpdateEvent;
+import kr.syeyoung.dungeonsguide.mod.features.AbstractGuiFeature;
import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry;
import kr.syeyoung.dungeonsguide.mod.features.SimpleFeature;
import kr.syeyoung.dungeonsguide.mod.features.impl.discord.inviteViewer.WidgetPartyInviteViewer;
@@ -50,18 +51,21 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-public class PlayingDGAlarm extends SimpleFeature {
+public class PlayingDGAlarm extends AbstractGuiFeature {
private WidgetOnlinePeopleViewer onlinePeopleViewer;
private OverlayWidget widget;
public PlayingDGAlarm() {
super("Discord", "Friend Online Notification","Notifies you in bottom when your discord friend has launched a Minecraft with DG!\n\nRequires the Friend's Discord RPC to be enabled", "discord.discord_playingalarm");
- widget = new OverlayWidget(
+ }
+
+ @Override
+ public OverlayWidget instantiateWidget() {
+ return new OverlayWidget(
onlinePeopleViewer = new WidgetOnlinePeopleViewer(),
OverlayType.OVER_ANY,
() -> new Rect(0,0,Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight)
);
- OverlayManager.getInstance().addOverlay(widget);
}
@DGEventHandler(triggerOutOfSkyblock = true)
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/DomElement.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/DomElement.java
index 8e1c847a..5d44c89a 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/DomElement.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/DomElement.java
@@ -101,6 +101,11 @@ public class DomElement {
// event propagation
+
+ public void requestRelayoutParent() {
+ if (parent != null)
+ parent.requestRelayout();
+ }
public void requestRelayout() {
if (layouter.canCutRequest() && size != null) {
layouter.layout(this, new ConstraintBox(
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/Widget.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/Widget.java
index 4895ae8b..f6b820e2 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/Widget.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/Widget.java
@@ -34,7 +34,6 @@ public abstract class Widget {
private boolean multiatfirst = false;
public DomElement createDomElement(DomElement parent) {
- if (domElement.getWidget() != null) throw new IllegalStateException("Controller already has corresponding DomElement!");
domElement = new DomElement();
domElement.setWidget(this);
domElement.setParent(parent);
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/ConstrainedBox.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/ConstrainedBox.java
index e26085c5..a7604fcb 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/ConstrainedBox.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/ConstrainedBox.java
@@ -52,10 +52,10 @@ public class ConstrainedBox extends AnnotatedExportOnlyWidget implements Layoute
}
public ConstrainedBox() {
- minWidth.addOnUpdate((a, b) -> getDomElement().requestRelayout());
- minHeight.addOnUpdate((a, b) -> getDomElement().requestRelayout());
- maxWidth.addOnUpdate((a, b) -> getDomElement().requestRelayout());
- maxHeight.addOnUpdate((a, b) -> getDomElement().requestRelayout());
+ minWidth.addOnUpdate((a, b) -> getDomElement().requestRelayoutParent());
+ minHeight.addOnUpdate((a, b) -> getDomElement().requestRelayoutParent());
+ maxWidth.addOnUpdate((a, b) -> getDomElement().requestRelayoutParent());
+ maxHeight.addOnUpdate((a, b) -> getDomElement().requestRelayoutParent());
}
@Override
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/SelectiveContainer.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/SelectiveContainer.java
new file mode 100644
index 00000000..c9cdcd10
--- /dev/null
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/SelectiveContainer.java
@@ -0,0 +1,64 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2023 cyoung06 (syeyoung)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.mod.guiv2.elements;
+
+import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute;
+import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement;
+import kr.syeyoung.dungeonsguide.mod.guiv2.Widget;
+import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedExportOnlyWidget;
+import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Export;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SelectiveContainer extends AnnotatedExportOnlyWidget {
+ @Export(attributeName = "visible")
+ public final BindableAttribute<String> visibleChild = new BindableAttribute<>(String.class);
+
+ private final Map<String, BindableAttribute<Widget>> widgetMap = new HashMap<>();
+
+ public SelectiveContainer() {
+ visibleChild.addOnUpdate((old, neu) -> {
+ if (getDomElement().getChildren().size() > 0)
+ getDomElement().removeElement(getDomElement().getChildren().get(0));
+ if (getDomElement().getParent() != null) {
+ Widget widget = widgetMap.get("$"+visibleChild.getValue()).getValue();
+ getDomElement().addElement(widget.createDomElement(getDomElement()));
+ }
+ });
+ }
+
+ @Override
+ public List<Widget> build(DomElement buildContext) {
+ return Collections.singletonList(widgetMap.get("$"+visibleChild.getValue()).getValue());
+ }
+
+ @Override
+ public <T> BindableAttribute<T> getExportedAttribute(String attributeName) {
+ BindableAttribute<T> bindableAttribute = super.getExportedAttribute(attributeName);
+ if (bindableAttribute == null && attributeName.startsWith("$")) {
+ BindableAttribute attribute = new BindableAttribute(Widget.class);
+ widgetMap.put(attributeName, attribute);
+ return attribute;
+ }
+ return bindableAttribute;
+ }
+}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java
index 1ac6c747..eb0f9eb8 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/xml/DomElementRegistry.java
@@ -81,6 +81,7 @@ public class DomElementRegistry {
register("size", new DelegatingWidgetConverter(new ResourceLocation("dungeonsguide:gui/elements/size.gui")));
register("ResourceImage", new DelegatingWidgetConverter(new ResourceLocation("dungeonsguide:gui/elements/ratioResourceImage.gui")));
register("UrlImage", new ExportedWidgetConverter(URLImage::new));
+ register("SelectiveContainer", new ExportedWidgetConverter(SelectiveContainer::new));
}
public static Parser obtainParser(ResourceLocation resourceLocation) {
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManagerRootWidget.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManagerRootWidget.java
index 83a8f739..ea18884c 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManagerRootWidget.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/overlay/OverlayManagerRootWidget.java
@@ -39,7 +39,6 @@ public class OverlayManagerRootWidget extends Widget implements Layouter {
public void addOverlay(OverlayWidget overlayWidget) {
if (getDomElement().getChildren().contains(overlayWidget.getDomElement())) return;
-
DomElement domElement = overlayWidget.createDomElement(getDomElement());
getDomElement().addElement(domElement);