Skip to content

Commit

Permalink
fix: resolve some Z-ordering issues in the quest gui
Browse files Browse the repository at this point in the history
In particular, block item icons with scaled up quests could end up
rendering above gui layers that they shouldn't have...

FTBTeam/FTB-Mods-Issues#1320
  • Loading branch information
desht committed Aug 29, 2024
1 parent bbe681e commit 3ca185a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ContextMenuBuilder insertAtBottom(Collection<ContextMenuItem> toAdd) {
}

public void openContextMenu(BaseScreen gui) {
gui.openContextMenu(build(gui));
gui.openContextMenu(build(gui)).setExtraZlevel(QuestScreen.Z_LEVEL);
}

public List<ContextMenuItem> build(BaseScreen gui) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
public class ChapterPanel extends Panel {
public static final Icon ARROW_COLLAPSED = Icon.getIcon("ftbquests:textures/gui/arrow_collapsed.png");
public static final Icon ARROW_EXPANDED = Icon.getIcon("ftbquests:textures/gui/arrow_expanded.png");
public static final int Z_LEVEL = 300;
private static final Pattern NON_EMPTY_PAT = Pattern.compile("^.+$");

private final QuestScreen questScreen;
Expand Down Expand Up @@ -140,7 +139,7 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int
@Override
public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
graphics.pose().pushPose();
graphics.pose().translate(0, 0, Z_LEVEL);
graphics.pose().translate(0, 0, QuestScreen.Z_LEVEL);
RenderSystem.enableDepthTest();
super.draw(graphics, theme, x, y, w, h);
graphics.pose().popPose();
Expand Down Expand Up @@ -209,7 +208,7 @@ public void onClicked(MouseButton button) {
run();
}, b.getTitle()).atMousePosition();
overlay.setWidth(150);
overlay.setExtraZlevel(Z_LEVEL + 10);
overlay.setExtraZlevel(QuestScreen.Z_LEVEL + 10);
getGui().pushModalPanel(overlay);
}));

Expand All @@ -226,7 +225,7 @@ public void onClicked(MouseButton button) {
}
}, b.getTitle()).atMousePosition();
overlay.setWidth(150);
overlay.setExtraZlevel(Z_LEVEL + 10);
overlay.setExtraZlevel(QuestScreen.Z_LEVEL + 10);
getGui().pushModalPanel(overlay);
}));

Expand Down Expand Up @@ -311,7 +310,7 @@ public void onClicked(MouseButton button) {
run();
}, Component.translatable("ftbquests.chapter")).atMousePosition();
overlay.setWidth(150);
overlay.setExtraZlevel(Z_LEVEL + 10);
overlay.setExtraZlevel(QuestScreen.Z_LEVEL + 10);
getGui().pushModalPanel(overlay);

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
if (!questIcon.isEmpty()) {
int s = (int) (w / 8F * 3F);
poseStack.pushPose();
poseStack.translate(x + w - s, y, 0);
poseStack.translate(x + w - s, y, QuestScreen.Z_LEVEL);
questIcon.draw(graphics, 0, 0, s, s);
poseStack.popPose();
}

if (!hiddenIcon.isEmpty()) {
int s = (int) (w / 8F * 3F);
poseStack.pushPose();
poseStack.translate(x, y, 0);
poseStack.translate(x, y, QuestScreen.Z_LEVEL);
hiddenIcon.draw(graphics, 0, 0, s, s);
poseStack.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
import java.util.*;

public class QuestScreen extends BaseScreen {
// A fairly large z-offset is needed to ensure various GUI elements render above drawn block items,
// which can extend quite some way out of the screen if the quest button is scaled up...
public static final int Z_LEVEL = 1250;

final ClientQuestFile file;

double scrollWidth, scrollHeight;
Expand Down Expand Up @@ -107,6 +111,11 @@ public boolean doesGuiPauseGame() {
return ClientQuestFile.INSTANCE.isPauseGame();
}

@Override
public int getMaxZLevel() {
return Z_LEVEL + 100;
}

@Override
public void addWidgets() {
QuestTheme.currentObject = selectedChapter;
Expand Down

0 comments on commit 3ca185a

Please sign in to comment.