Skip to content

Commit

Permalink
Fix overlays within overlays failing to close properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGravyBoat committed Nov 7, 2024
1 parent 26fa744 commit 2cef497
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
4 changes: 1 addition & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
- Added action modals
- Added icons for use in renderers
- Fixed rounded colored rectangle on MacOS - J10a1n15
- Fix overlays opened inside of overlays closing all overlays
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ protected void init() {

@Override
protected void repositionElements() {
if (this.background != null) this.background.resize(Minecraft.getInstance(), this.width, this.height);
if (this.background instanceof Overlay overlay) overlay.isInitialized = false;
if (this.isInitialized) {
Minecraft.getInstance().setScreen(this.background);
} else {
rebuildWidgets();
if (this.background != null) this.background.resize(Minecraft.getInstance(), this.width, this.height);
super.repositionElements();
}

@Override
public void resize(Minecraft minecraft, int width, int height) {
super.resize(minecraft, width, height);
// We want to close all overlays when the screen is resized
Screen screenToGoTo = this.background;
while (screenToGoTo instanceof Overlay overlay) {
overlay.onClose();
screenToGoTo = overlay.background;
}
Minecraft.getInstance().setScreen(screenToGoTo);
}

public void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package earth.terrarium.olympus.client.ui.modals;

import earth.terrarium.olympus.client.components.Widgets;
import earth.terrarium.olympus.client.components.base.BaseWidget;
import earth.terrarium.olympus.client.components.renderers.WidgetRenderers;
import earth.terrarium.olympus.client.components.string.MultilineTextWidget;
import earth.terrarium.olympus.client.layouts.Layouts;
Expand Down Expand Up @@ -142,8 +143,13 @@ public Builder withContent(Int2ObjectFunction<AbstractWidget> widget) {
return this;
}

public Builder withContent(BaseWidget widget) {
this.content.add(width -> widget.withSize(width, widget.getHeight()));
return this;
}

public Builder withContent(Component text) {
this.content.add(i -> new MultilineTextWidget(i, text, Minecraft.getInstance().font));
this.content.add(i -> new MultilineTextWidget(i, text, Minecraft.getInstance().font).alignLeft());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import earth.terrarium.example.base.ExampleScreen;
import earth.terrarium.example.base.OlympusExample;
import earth.terrarium.olympus.client.components.Widgets;
import earth.terrarium.olympus.client.components.dropdown.DropdownState;
import earth.terrarium.olympus.client.components.renderers.WidgetRenderers;
import earth.terrarium.olympus.client.layouts.Layouts;
import earth.terrarium.olympus.client.ui.UIConstants;
import earth.terrarium.olympus.client.ui.modals.ActionModal;
import earth.terrarium.olympus.client.ui.modals.Modals;
import earth.terrarium.olympus.client.utils.State;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.layouts.FrameLayout;
import net.minecraft.network.chat.Component;

Expand All @@ -17,6 +19,7 @@ public class ModalExample extends ExampleScreen {

@Override
protected void init() {
DropdownState<ChatFormatting> dropdownState = DropdownState.of(ChatFormatting.RESET);
ActionModal.Builder actionModal = Modals.action()
.withTitle(Component.literal("Action modal"))
.withContent(Component.literal(
Expand All @@ -28,6 +31,7 @@ protected void init() {
"Nam ut mollis nisl."
))
.withContent(i -> Widgets.textInput(State.of("Input text")).withSize(i, 20))
.withContent(i -> Widgets.dropdown(dropdownState, ChatFormatting.class).withSize(i, 20))
.withAction(Widgets.button()
.withSize(50, 20)
.withTexture(UIConstants.PRIMARY_BUTTON)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G

enabledPlatforms=fabric,neoforge

version=1.0.12
version=1.0.13
group=earth.terrarium.olympus

minecraftVersion=1.21
Expand Down

0 comments on commit 2cef497

Please sign in to comment.