Skip to content

Commit

Permalink
Merge pull request #89 from FTBTeam/1.20.4/dev
Browse files Browse the repository at this point in the history
1.20.4/dev
  • Loading branch information
desht authored Jun 3, 2024
2 parents 499e484 + 2cd2024 commit 3be92c8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Java CI - Build on Push

on:
push:
branches: [ main, dev, "1.*" ]
branches: [ main, dev, "1.**" ]
workflow_dispatch:
inputs:
skip_maven_publish:
Expand All @@ -20,4 +20,4 @@ jobs:
maven-snapshots: true
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.ftb.mods.ftblibrary.ui;

import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;

public abstract class BaseMenuScreen<T extends AbstractContainerMenu> extends BaseScreen {
protected final T menu;
protected final Inventory playerInventory;

public BaseMenuScreen(T menu, Inventory playerInventory) {
this.menu = menu;
this.playerInventory = playerInventory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public void onPostInit() {
public void pushModalPanel(ModalPanel modalPanel) {
modalPanels.addFirst(modalPanel);
modalPanel.refreshWidgets();

// since the panel size will have changed, make sure it's still on-screen
modalPanel.setX(Math.min(modalPanel.getX(), getWidth() - modalPanel.getWidth() - 10));
modalPanel.setY(Math.min(modalPanel.getY(), getHeight() - modalPanel.getHeight() - 10));
}

/**
Expand All @@ -154,6 +158,7 @@ public ModalPanel popModalPanel() {
}
ModalPanel panel = modalPanels.removeFirst();
panel.onClosed();
focusedWidget = null; // in case an editfield in the panel had focus
return panel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
import dev.ftb.mods.ftblibrary.ui.input.MouseButton;
import dev.ftb.mods.ftblibrary.util.TooltipList;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner;
import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;

import java.util.List;

public class MenuScreenWrapper<T extends AbstractContainerMenu> extends AbstractContainerScreen<T> implements IScreenWrapper {
private final BaseScreen wrappedGui;
private boolean drawSlots = true;
private final TooltipList tooltipList = new TooltipList();

public MenuScreenWrapper(BaseScreen g, T c, Inventory playerInventory, Component title) {
super(c, playerInventory, title);
public MenuScreenWrapper(BaseScreen g, T menu, Inventory playerInventory, Component title) {
super(menu, playerInventory, title);
wrappedGui = g;
}

Expand Down Expand Up @@ -50,8 +54,7 @@ public boolean mouseClicked(double x, double y, int button) {
wrappedGui.onBack();
return true;
} else {
wrappedGui.mousePressed(MouseButton.get(button));
return super.mouseClicked(x, y, button);
return wrappedGui.mousePressed(MouseButton.get(button)) || super.mouseClicked(x, y, button);
}
}

Expand All @@ -64,8 +67,7 @@ public boolean mouseReleased(double x, double y, int button) {

@Override
public boolean mouseScrolled(double x, double y, double dirX, double dirY) {
wrappedGui.mouseScrolled(dirY);
return super.mouseScrolled(x, y, dirX, dirY);
return wrappedGui.mouseScrolled(dirY) || super.mouseScrolled(x, y, dirX, dirY);
}

@Override
Expand All @@ -77,10 +79,14 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
} else {
if (key.backspace()) {
wrappedGui.onBack();
return true;
} else if (wrappedGui.onClosedByKey(key)) {
if (shouldCloseOnEsc()) {
wrappedGui.closeGui(true);
// false is important here; menu-based screens are driven by messages from the server,
// so we can't just switch between screens
wrappedGui.closeGui(false);
}
return true;
}

return super.keyPressed(keyCode, scanCode, modifiers);
Expand Down Expand Up @@ -129,7 +135,7 @@ protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
var theme = wrappedGui.getTheme();
wrappedGui.drawForeground(graphics, theme, leftPos, topPos, imageWidth, imageHeight);

wrappedGui./*getContextMenu().orElse(wrappedGui).*/addMouseOverText(tooltipList);
wrappedGui.addMouseOverText(tooltipList);

if (!tooltipList.shouldRender()) {
wrappedGui.getIngredientUnderMouse().ifPresent(underMouse -> {
Expand All @@ -144,14 +150,23 @@ protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
}
});
} else {
tooltipList.render(graphics, mouseX, Math.max(mouseY, 18), wrappedGui.getScreen().getGuiScaledWidth(), wrappedGui.getScreen().getGuiScaledHeight(), theme.getFont());
List<FormattedCharSequence> lines = Tooltip.splitTooltip(minecraft, tooltipList.getLines().stream()
.reduce((c1, c2) -> c1.copy().append("\n").append(c2))
.orElse(Component.empty())
);
graphics.pose().translate(0, 0, 600);
graphics.setColor(1f, 1f, 1f, 0.8f);
graphics.renderTooltip(theme.getFont(), lines, DefaultTooltipPositioner.INSTANCE, mouseX, Math.max(mouseY, 18));
graphics.setColor(1f, 1f, 1f, 1f);
graphics.pose().translate(0, 0, -600);
// tooltipList.render(graphics, mouseX, Math.max(mouseY, 18), wrappedGui.getScreen().getGuiScaledWidth(), wrappedGui.getScreen().getGuiScaledHeight(), theme.getFont());
}

tooltipList.reset();

if (wrappedGui.getContextMenu().isEmpty()) {
renderTooltip(graphics, mouseX, mouseY);
}
// if (wrappedGui.getContextMenu().isEmpty()) {
// renderTooltip(graphics, mouseX, mouseY);
// }

graphics.pose().popPose();
}
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/dev/ftb/mods/ftblibrary/ui/TextBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,10 @@ public boolean mousePressed(MouseButton button) {
setSelectionPos(theme.trimStringToWidth(s, i).length() + displayPos);
} else {
setCursorPos(theme.trimStringToWidth(s, i).length() + displayPos);
setSelectionPos(getCursorPos());
}
}
} else if (button.isRight() && getText().length() > 0 && allowInput()) {
} else if (button.isRight() && !getText().isEmpty() && allowInput()) {
setText("");
}

Expand Down Expand Up @@ -444,7 +445,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
}

// highlight the selection if needed
int k = Math.min(s.length(), highlightPos - displayPos);
int k = Mth.clamp(highlightPos - displayPos, 0, s.length());
if (k != j) {
var xMax = textX + theme.getStringWidth(Component.literal(s.substring(0, k)));

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

# Mod
mod_id=ftblibrary
mod_version=2004.2.2
mod_version=2004.2.3
mod_author=FTB Team

# Maven
Expand Down
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ side = "BOTH"
[[dependencies.ftblibrary]]
modId = "minecraft"
type = "required"
versionRange = "[1.20.2,)"
versionRange = "[${mcversion},)"
ordering = "NONE"
side = "BOTH"

Expand Down

0 comments on commit 3be92c8

Please sign in to comment.