Skip to content

Commit

Permalink
Adjust tooltip rendering to after rendering of the screen to prevent …
Browse files Browse the repository at this point in the history
…being covered by other rendering elements
  • Loading branch information
Dragon-Seeker committed Dec 11, 2024
1 parent 478c7f7 commit 76c26ed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/main/java/io/wispforest/owo/compat/rei/ReiUIAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ public ReiUIAdapter(Rectangle bounds, BiFunction<Sizing, Sizing, T> rootComponen
this.adapter = OwoUIAdapter.createWithoutScreen(bounds.x, bounds.y, bounds.width, bounds.height, rootComponentMaker);
this.adapter.inspectorZOffset = 900;

if (MinecraftClient.getInstance().currentScreen != null) {
ScreenEvents.remove(MinecraftClient.getInstance().currentScreen).register(screen -> this.adapter.dispose());
var screenWithREI = MinecraftClient.getInstance().currentScreen;

if (screenWithREI != null) {
ScreenEvents.remove(screenWithREI).register(screen -> this.adapter.dispose());
ScreenEvents.afterRender(screenWithREI).register((screen, drawContext, mouseX, mouseY, tickDelta) -> {
this.adapter.drawTooltip(drawContext, mouseX, mouseY, tickDelta);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.wispforest.owo.ui.util.DisposableScreen;
import io.wispforest.owo.ui.util.UIErrorToast;
import io.wispforest.owo.util.pond.OwoSlotExtension;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
Expand Down Expand Up @@ -82,6 +83,10 @@ protected void init() {
this.build(this.uiAdapter.rootComponent);

this.uiAdapter.inflateAndMount();

ScreenEvents.afterRender(this).register((screen, drawContext, mouseX, mouseY, tickDelta) -> {
if (this.uiAdapter != null) this.uiAdapter.drawTooltip(drawContext, mouseX, mouseY, tickDelta);
});
} catch (Exception error) {
Owo.LOGGER.warn("Could not initialize owo screen", error);
UIErrorToast.report(error);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/wispforest/owo/ui/base/BaseOwoScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.wispforest.owo.ui.inject.GreedyInputComponent;
import io.wispforest.owo.ui.util.DisposableScreen;
import io.wispforest.owo.ui.util.UIErrorToast;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
Expand Down Expand Up @@ -91,6 +92,10 @@ protected void init() {
this.build(this.uiAdapter.rootComponent);

this.uiAdapter.inflateAndMount();

ScreenEvents.afterRender(this).register((screen, drawContext, mouseX, mouseY, tickDelta) -> {
if (this.uiAdapter != null) this.uiAdapter.drawTooltip(drawContext, mouseX, mouseY, tickDelta);
});
} catch (Exception error) {
Owo.LOGGER.warn("Could not initialize owo screen", error);
UIErrorToast.report(error);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/io/wispforest/owo/ui/core/OwoUIAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTic
GlStateManager._disableScissorTest();
RenderSystem.disableDepthTest();

this.rootComponent.drawTooltip(owoContext, mouseX, mouseY, partialTicks, delta);

final var hovered = this.rootComponent.childAt(mouseX, mouseY);
if (!disposed && hovered != null) {
this.cursorAdapter.applyStyle(hovered.cursorStyle());
Expand All @@ -200,6 +198,15 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTic
}
}

public void drawTooltip(DrawContext context, int mouseX, int mouseY, float partialTicks) {
if (!(context instanceof OwoUIDrawContext)) context = OwoUIDrawContext.of(context);
var owoContext = (OwoUIDrawContext) context;

final var delta = MinecraftClient.getInstance().getRenderTickCounter().getLastFrameDuration();

this.rootComponent.drawTooltip(owoContext, mouseX, mouseY, partialTicks, delta);
}

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return this.rootComponent.isInBoundingBox(mouseX, mouseY);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/wispforest/owo/ui/layers/Layers.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public static <S extends Screen, R extends ParentComponent> Layer<S, R> add(BiFu
for (var instance : getInstances(screen)) {
instance.adapter.render(context, mouseX, mouseY, tickDelta);
}

for (var instance : getInstances(screen)) {
instance.adapter.drawTooltip(context, mouseX, mouseY, tickDelta);
}
});

ScreenMouseEvents.allowMouseClick(screeen).register((screen, mouseX, mouseY, button) -> {
Expand Down

0 comments on commit 76c26ed

Please sign in to comment.