Skip to content

Commit 63dc81e

Browse files
Remove Ad Modal: Return to Ad Modal on exit
1 parent c5905e7 commit 63dc81e

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/main/java/gg/essential/ad/modal/AdModal.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void init() {
7474
}));
7575

7676
buttonList.add(new TextureButton(centreX - 64, startY + height + 8, 128, 8, REMOVE_INTEGRATION, 0xFF5C5C5C, 0xFF757575, false, () -> {
77-
ModalManager.INSTANCE.setModal(TwoButtonModal.removeAds());
77+
ModalManager.INSTANCE.setModal(TwoButtonModal.removeAds(this));
7878
}));
7979
buttonList.add(new TextureButton(startX + width - 8 - 5, startY + 8, 5, 5, X_ICON, 0xFF757575, 0xFF999999, true, () -> ModalManager.INSTANCE.setModal(null)));
8080
}
@@ -215,6 +215,7 @@ public void close() {
215215
for (ResourceLocation location : iconTextures.values()) {
216216
Minecraft.getMinecraft().getTextureManager().deleteTexture(location);
217217
}
218+
iconTextures.clear();
218219
super.close();
219220
}
220221

src/main/java/gg/essential/ad/modal/ModalManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ public class ModalManager {
4646
private int previousHeight = -1;
4747

4848
public void setModal(Modal modal) {
49-
if (currentModal != null) {
50-
currentModal.close();
51-
}
49+
Modal previous = currentModal;
5250
previousWidth = -1;
5351
previousHeight = -1;
5452
this.currentModal = modal;
53+
if (previous != null) {
54+
previous.close();
55+
}
5556
}
5657

5758
public MousePosition getMousePosition() {

src/main/java/gg/essential/ad/modal/TwoButtonModal.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,28 @@ public static TwoButtonModal postInstall() {
5555
);
5656
}
5757

58-
public static TwoButtonModal removeAds() {
58+
public static TwoButtonModal removeAds(AdModal adModal) {
59+
boolean[] removed = new boolean[1];
5960
return new TwoButtonModal(
6061
"Do you want to remove all\n'Get Essential Mod' buttons?",
61-
(x, y, width) -> new ModalButton(x, y, width, ButtonColor.GRAY, "No", () -> {
62+
(x, y, width) -> new ModalButton(x, y, width, ButtonColor.GRAY, "Back", () -> {
6263
ModalManager.INSTANCE.setModal(null);
6364
}),
64-
(x, y, width) -> new ModalButton(x, y, width, ButtonColor.RED, "Yes", () -> {
65+
(x, y, width) -> new ModalButton(x, y, width, ButtonColor.RED, "Remove", () -> {
6566
EssentialAd.CONFIG.hideButtons();
67+
removed[0] = true;
6668
ModalManager.INSTANCE.setModal(null);
6769
Minecraft.getMinecraft().currentScreen.onResize(Minecraft.getMinecraft(), UResolution.getScaledWidth(), UResolution.getScaledHeight());
6870
})
69-
);
71+
) {
72+
@Override
73+
public void close() {
74+
super.close();
75+
if (!removed[0]) {
76+
ModalManager.INSTANCE.setModal(adModal);
77+
}
78+
}
79+
};
7080
}
7181

7282
public static TwoButtonModal installFailed() {

0 commit comments

Comments
 (0)