Skip to content

Commit

Permalink
Side buttons rework (#4990)
Browse files Browse the repository at this point in the history
Fixes issues with mods that do weird things with screens
  • Loading branch information
kirderf1 committed Sep 18, 2022
1 parent 3bbb352 commit 9729035
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 213 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package slimeknights.tconstruct.tables.client.inventory;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import lombok.Getter;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Widget;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -38,7 +39,7 @@
import slimeknights.tconstruct.library.utils.TinkerTooltipFlags;
import slimeknights.tconstruct.tables.block.entity.table.TinkerStationBlockEntity;
import slimeknights.tconstruct.tables.client.inventory.module.InfoPanelScreen;
import slimeknights.tconstruct.tables.client.inventory.module.TinkerStationButtonsScreen;
import slimeknights.tconstruct.tables.client.inventory.widget.TinkerStationButtonsWidget;
import slimeknights.tconstruct.tables.client.inventory.widget.SlotButtonItem;
import slimeknights.tconstruct.tables.menu.TinkerStationContainerMenu;
import slimeknights.tconstruct.tables.menu.slot.TinkerStationSlot;
Expand Down Expand Up @@ -108,14 +109,14 @@ public class TinkerStationScreen extends BaseTabbedScreen<TinkerStationBlockEnti
@Nonnull @Getter
private final StationSlotLayout defaultLayout;
/** Currently selected tool */
@Nonnull
@Nonnull @Getter
private StationSlotLayout currentLayout;

// components
//protected TextFieldWidget textField;
protected InfoPanelScreen tinkerInfo;
protected InfoPanelScreen modifierInfo;
protected TinkerStationButtonsScreen buttonsScreen;
protected TinkerStationButtonsWidget buttonsScreen;

/** Maximum available slots */
@Getter
Expand All @@ -126,9 +127,6 @@ public class TinkerStationScreen extends BaseTabbedScreen<TinkerStationBlockEnti
public TinkerStationScreen(TinkerStationContainerMenu container, Inventory playerInventory, Component title) {
super(container, playerInventory, title);

this.buttonsScreen = new TinkerStationButtonsScreen(this, container, playerInventory, title);
this.addModule(this.buttonsScreen);

this.tinkerInfo = new InfoPanelScreen(this, container, playerInventory, title);
this.tinkerInfo.setTextScale(8/9f);
this.addModule(this.tinkerInfo);
Expand Down Expand Up @@ -182,8 +180,6 @@ public void init() {
//this.textField.setEnableBackgroundDrawing(false);
//this.textField.setMaxStringLength(40);

this.buttonsScreen.xOffset = -2;
this.buttonsScreen.yOffset = this.centerBeam.h + this.buttonDecorationTop.h;
this.tinkerInfo.xOffset = 2;
this.tinkerInfo.yOffset = this.centerBeam.h + this.panelDecorationL.h;
this.modifierInfo.xOffset = this.tinkerInfo.xOffset;
Expand All @@ -194,6 +190,19 @@ public void init() {
}

super.init();

int buttonsStyle = this.maxInputs > 3 ? TinkerStationButtonsWidget.METAL_STYLE : TinkerStationButtonsWidget.WOOD_STYLE;

List<StationSlotLayout> layouts = Lists.newArrayList();
// repair layout
layouts.add(this.defaultLayout);
// tool layouts
layouts.addAll(StationSlotLayoutLoader.getInstance().getSortedSlots().stream()
.filter(layout -> layout.getInputSlots().size() <= this.maxInputs).toList());

this.buttonsScreen = new TinkerStationButtonsWidget(this, this.cornerX - TinkerStationButtonsWidget.width(COLUMN_COUNT) - 2,
this.cornerY + this.centerBeam.h + this.buttonDecorationTop.h, layouts, buttonsStyle);

this.updateLayout();
}

Expand Down Expand Up @@ -429,11 +438,11 @@ protected void renderBg(PoseStack matrices, float partialTicks, int mouseX, int
}

// sidebar beams
x = this.buttonsScreen.leftPos - this.leftBeam.w;
x = this.buttonsScreen.getLeftPos() - this.leftBeam.w;
y = this.cornerY;
// draw the beams at the top
x += this.leftBeam.draw(matrices, x, y);
x += this.centerBeam.drawScaledX(matrices, x, y, this.buttonsScreen.imageWidth);
x += this.centerBeam.drawScaledX(matrices, x, y, this.buttonsScreen.getImageWidth());
this.rightBeam.draw(matrices, x, y);

x = tinkerInfo.leftPos - this.leftBeam.w;
Expand All @@ -442,13 +451,11 @@ protected void renderBg(PoseStack matrices, float partialTicks, int mouseX, int
this.rightBeam.draw(matrices, x, y);

// draw the decoration for the buttons
for (Widget widget : this.buttonsScreen.getButtons()) {
if (widget instanceof SlotButtonItem button) {
this.buttonDecorationTop.draw(matrices, button.x, button.y - this.buttonDecorationTop.h);
// don't draw the bottom for the buttons in the last row
if (button.buttonId < this.buttonsScreen.getButtons().size() - COLUMN_COUNT) {
this.buttonDecorationBot.draw(matrices, button.x, button.y + button.getHeight());
}
for (SlotButtonItem button : this.buttonsScreen.getButtons()) {
this.buttonDecorationTop.draw(matrices, button.x, button.y - this.buttonDecorationTop.h);
// don't draw the bottom for the buttons in the last row
if (button.buttonId < this.buttonsScreen.getButtons().size() - COLUMN_COUNT) {
this.buttonDecorationBot.draw(matrices, button.x, button.y + button.getHeight());
}
}

Expand All @@ -473,6 +480,8 @@ protected void renderBg(PoseStack matrices, float partialTicks, int mouseX, int
RenderSystem.enableDepthTest();

super.renderBg(matrices, partialTicks, mouseX, mouseY);

this.buttonsScreen.render(matrices, mouseX, mouseY, partialTicks);
}

@Override
Expand Down Expand Up @@ -633,8 +642,6 @@ protected void wood() {
this.panelDecorationL = PANEL_SPACE_LEFT.shift(18, 0);
this.panelDecorationR = PANEL_SPACE_RIGHT.shift(18, 0);

this.buttonsScreen.shiftStyle(TinkerStationButtonsScreen.WOOD_STYLE);

this.leftBeam = LEFT_BEAM;
this.rightBeam = RIGHT_BEAM;
this.centerBeam = CENTER_BEAM;
Expand All @@ -649,8 +656,6 @@ protected void metal() {
this.panelDecorationL = PANEL_SPACE_LEFT.shift(18 * 2, 0);
this.panelDecorationR = PANEL_SPACE_RIGHT.shift(18 * 2, 0);

this.buttonsScreen.shiftStyle(TinkerStationButtonsScreen.METAL_STYLE);

this.leftBeam = LEFT_BEAM.shift(0, LEFT_BEAM.h);
this.rightBeam = RIGHT_BEAM.shift(0, RIGHT_BEAM.h);
this.centerBeam = CENTER_BEAM.shift(0, CENTER_BEAM.h);
Expand Down Expand Up @@ -685,4 +690,17 @@ public void onToolSelection(StationSlotLayout layout) {
// this.container.setToolSelection(layout); TODO: needed?
TinkerNetwork.getInstance().sendToServer(new TinkerStationSelectionPacket(layout.getName()));
}

@Override
public List<Rect2i> getModuleAreas() {
List<Rect2i> list = super.getModuleAreas();
list.add(this.buttonsScreen.getArea());
return list;
}

@Override
protected boolean hasClickedOutside(double mouseX, double mouseY, int guiLeft, int guiTop, int mouseButton) {
return super.hasClickedOutside(mouseX, mouseY, guiLeft, guiTop, mouseButton)
&& !this.buttonsScreen.isMouseOver(mouseX, mouseY);
}
}

This file was deleted.

This file was deleted.

0 comments on commit 9729035

Please sign in to comment.