Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Info panel screen rework and tinker station screen tweaks #4988

Open
wants to merge 28 commits into
base: 1.18.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f0d26b6
Convert InfoPanelScreen and PartInfoPanelScreen to widgets
kirderf1 Sep 7, 2022
2632102
Pass xOffset, yOffset and textScale to InfoPanelWidget through the co…
kirderf1 Sep 7, 2022
2b89875
Rename info panel size constants and add BORDER_SIZE constant
kirderf1 Sep 7, 2022
4312359
Bundle info panel texture uvs in a Style object that gets passed thro…
kirderf1 Sep 7, 2022
3dce1da
Width and height as parameters to InfoPanelWidget
kirderf1 Sep 7, 2022
e8a5af8
Roll the content of InfoPanelWidget.updatePosition() into the constru…
kirderf1 Sep 7, 2022
e3acee4
Pass exact position as argument to the info panel instead of an offset
kirderf1 Sep 7, 2022
ee73c4d
Improve interaction between InfoPanelWidget and PartInfoPanelWidget t…
kirderf1 Sep 8, 2022
9ad69f0
Move captions height out of calcNeededHeight() and do some related re…
kirderf1 Sep 8, 2022
75ece15
Use font.lineHeight instead of getScaledFontHeight() for text that do…
kirderf1 Sep 8, 2022
7d49bc9
Extract hoverHintX() and hoverHintY(), and tweak the bounds of the ho…
kirderf1 Sep 8, 2022
a61cb60
Move info panel caption styling out of InfoPanelWidget and PartInfoPa…
kirderf1 Sep 9, 2022
16a7f56
List for captions in InfoPanelWidget to replace PartInfoPanelWidget
kirderf1 Sep 9, 2022
d21cff5
Combine info panel data into a record
kirderf1 Sep 9, 2022
f62c1f0
Tweak tinker station beam rendering to better fit texture change from…
kirderf1 Sep 10, 2022
25095b0
Extra areas for beams
kirderf1 Sep 10, 2022
2eb8b27
Tweak tinker station info panel height
kirderf1 Sep 10, 2022
e1daf31
New helper base class and a new widget interface for handling widget …
kirderf1 Sep 10, 2022
571e3ab
Create SimpleElementWidget and use it for beams and panel decorations
kirderf1 Sep 10, 2022
684c92c
Merge remote-tracking branch 'upstream/1.18.2' into info_panel_rework
kirderf1 Sep 19, 2022
f774e38
Return true when a mouse event is handled by side buttons
kirderf1 Sep 19, 2022
a415fd6
Implement and make use of ExtraAreaWidget for SideButtonsWidget
kirderf1 Sep 19, 2022
e773b69
Define side buttons x position as center of the beam
kirderf1 Sep 19, 2022
daadaf8
Use addRenderableWidget() for side buttons
kirderf1 Sep 19, 2022
df82a6a
Make PartBuilderScreen.CaptionsBuilder to help build captions list in…
kirderf1 Sep 21, 2022
45c1138
Merge remote-tracking branch 'upstream/1.18.2' into info_panel_rework
kirderf1 Sep 21, 2022
2d3a30e
Merge branch '1.18.2' into info_panel_rework
kirderf1 Feb 13, 2023
01072f8
Update ModifierWorktableScreen to use the reworked version of the inf…
kirderf1 Feb 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -11,7 +10,6 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.level.block.entity.BlockEntity;
import slimeknights.mantle.client.screen.ElementScreen;
import slimeknights.mantle.client.screen.MultiModuleScreen;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.client.GuiUtil;
import slimeknights.tconstruct.library.client.Icons;
Expand All @@ -22,9 +20,8 @@
import slimeknights.tconstruct.tables.menu.module.SideInventoryContainer;

import javax.annotation.Nullable;
import java.util.List;

public class BaseTabbedScreen<TILE extends BlockEntity, CONTAINER extends TabbedContainerMenu<TILE>> extends MultiModuleScreen<CONTAINER> {
public class BaseTabbedScreen<TILE extends BlockEntity, CONTAINER extends TabbedContainerMenu<TILE>> extends ExtendedContainerScreen<CONTAINER> {
protected static final Component COMPONENT_WARNING = TConstruct.makeTranslation("gui", "warning");
protected static final Component COMPONENT_ERROR = TConstruct.makeTranslation("gui", "error");

Expand All @@ -43,7 +40,7 @@ public BaseTabbedScreen(CONTAINER container, Inventory playerInventory, Componen
protected void init() {
super.init();

this.tabsScreen = addRenderableWidget(new TinkerTabsWidget(this));
this.tabsScreen = addExtraArea(addRenderableWidget(new TinkerTabsWidget(this)));
}

@Nullable
Expand Down Expand Up @@ -92,17 +89,4 @@ protected void addChestSideInventory(Inventory inventory) {
this.addModule(new SideInventoryScreen<>(this, sideInventoryContainer, inventory, sideInventoryName, sideInventoryContainer.getSlotCount(), sideInventoryContainer.getColumns()));
}
}

@Override
public List<Rect2i> getModuleAreas() {
List<Rect2i> areas = super.getModuleAreas();
areas.add(tabsScreen.getArea());
return areas;
}

@Override
protected boolean hasClickedOutside(double mouseX, double mouseY, int guiLeft, int guiTop, int mouseButton) {
return super.hasClickedOutside(mouseX, mouseY, guiLeft, guiTop, mouseButton)
&& !tabsScreen.isMouseOver(mouseX, mouseY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package slimeknights.tconstruct.tables.client.inventory;

import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import org.apache.commons.compress.utils.Lists;
import slimeknights.mantle.client.screen.MultiModuleScreen;
import slimeknights.mantle.inventory.MultiModuleContainerMenu;
import slimeknights.tconstruct.tables.client.inventory.widget.ExtraAreaWidget;

import java.util.List;

/**
* A helper class that handles custom widget interfaces.
* This class could potentially be relocated to mantle.
* @author kirderf1
*/
public abstract class ExtendedContainerScreen<CONTAINER extends MultiModuleContainerMenu<?>> extends MultiModuleScreen<CONTAINER> {

private final List<ExtraAreaWidget> extraAreas = Lists.newArrayList();

public ExtendedContainerScreen(CONTAINER container, Inventory playerInventory, Component title) {
super(container, playerInventory, title);
}

protected <T extends ExtraAreaWidget> T addExtraArea(T widget) {
this.extraAreas.add(widget);
return widget;
}

@Override
protected void removeWidget(GuiEventListener widget) {
if(widget instanceof ExtraAreaWidget)
this.extraAreas.remove(widget);

super.removeWidget(widget);
}

@Override
protected void clearWidgets() {
super.clearWidgets();
this.extraAreas.clear();
}

@Override
public List<Rect2i> getModuleAreas() {
List<Rect2i> areas = super.getModuleAreas();
this.extraAreas.forEach(widget -> areas.add(widget.getArea()));
return areas;
}

@Override
protected boolean hasClickedOutside(double mouseX, double mouseY, int fuiLeft, int guiTop, int mouseButton) {
return super.hasClickedOutside(mouseX, mouseY, fuiLeft, guiTop, mouseButton)
&& this.extraAreas.stream().noneMatch(widget -> widget.isInArea(mouseX, mouseY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
Expand All @@ -23,7 +24,7 @@
import slimeknights.tconstruct.library.recipe.worktable.IModifierWorktableRecipe;
import slimeknights.tconstruct.library.tools.nbt.ToolStack;
import slimeknights.tconstruct.tables.block.entity.table.ModifierWorktableBlockEntity;
import slimeknights.tconstruct.tables.client.inventory.module.InfoPanelScreen;
import slimeknights.tconstruct.tables.client.inventory.widget.InfoPanelWidget;
import slimeknights.tconstruct.tables.menu.ModifierWorktableContainerMenu;
import slimeknights.tconstruct.tools.item.ModifierCrystalItem;

Expand All @@ -42,8 +43,8 @@ public class ModifierWorktableScreen extends BaseTabbedScreen<ModifierWorktableB
};

/** Side panels, for tools and modifiers */
protected InfoPanelScreen tinkerInfo;
protected InfoPanelScreen modifierInfo;
protected InfoPanelWidget tinkerInfo;
protected InfoPanelWidget modifierInfo;

/** Current scrollbar position */
private float sliderProgress = 0.0F;
Expand All @@ -60,18 +61,16 @@ public class ModifierWorktableScreen extends BaseTabbedScreen<ModifierWorktableB
public ModifierWorktableScreen(ModifierWorktableContainerMenu container, Inventory playerInventory, Component title) {
super(container, playerInventory, title);

this.tinkerInfo = new InfoPanelScreen(this, container, playerInventory, title);
this.tinkerInfo.setTextScale(8/9f);
this.addModule(this.tinkerInfo);

this.modifierInfo = new InfoPanelScreen(this, container, playerInventory, title);
this.modifierInfo.setTextScale(7/9f);
this.addModule(this.modifierInfo);
addChestSideInventory(playerInventory);
}

this.tinkerInfo.yOffset = 0;
this.modifierInfo.yOffset = this.tinkerInfo.imageHeight + 4;
@Override
protected void init() {
super.init();

addChestSideInventory(playerInventory);
final int panelLeft = this.cornerX + this.realWidth;
this.tinkerInfo = addExtraArea(addRenderableWidget(new InfoPanelWidget(this, InfoPanelWidget.Style.PLAIN, panelLeft, this.cornerY, 8/9f)));
this.modifierInfo = addExtraArea(addRenderableWidget(new InfoPanelWidget(this, InfoPanelWidget.Style.PLAIN, panelLeft, this.cornerY + InfoPanelWidget.DEFAULT_HEIGHT + 4, 7/9f)));
}

@Override
Expand Down Expand Up @@ -135,6 +134,8 @@ protected void renderTooltip(PoseStack matrixStack, int mouseX, int mouseY) {
}
}
}
this.tinkerInfo.renderTooltip(matrixStack, mouseX, mouseY);
this.modifierInfo.renderTooltip(matrixStack, mouseX, mouseY);
}

/** Draw backgrounds for all modifiers */
Expand Down Expand Up @@ -201,16 +202,16 @@ public void updateDisplay() {
ItemStack resultStack = getMenu().getOutputSlot().getItem();
TinkerStationScreen.updateToolPanel(tinkerInfo, result, resultStack);

this.modifierInfo.setCaption(TextComponent.EMPTY);
this.modifierInfo.setText(TextComponent.EMPTY);
this.modifierInfo.setCaptions();
this.modifierInfo.setText();
if (result.hasTag(TinkerTags.Items.MODIFIABLE)) {
TinkerStationScreen.updateModifierPanel(modifierInfo, result);
} else {
// modifier crystals can show their modifier, along with anything else with a modifier there
ModifierId modifierId = ModifierCrystalItem.getModifier(resultStack);
if (modifierId != null) {
Modifier modifier = ModifierManager.getValue(modifierId);
modifierInfo.setCaption(TConstruct.makeTranslation("gui", "tinker_station.modifiers"));
modifierInfo.setCaptions(TConstruct.makeTranslation("gui", "tinker_station.modifiers").withStyle(ChatFormatting.UNDERLINE));
modifierInfo.setText(Collections.singletonList(modifier.getDisplayName()), Collections.singletonList(modifier.getDescription()));
}
}
Expand All @@ -223,10 +224,6 @@ public void updateDisplay() {
@Override
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
this.clickedOnScrollBar = false;
if (this.tinkerInfo.handleMouseClicked(mouseX, mouseY, mouseButton)
|| this.modifierInfo.handleMouseClicked(mouseX, mouseY, mouseButton)) {
return false;
}

if (tile != null && !tile.getCurrentButtons().isEmpty()) {
// handle button click
Expand All @@ -252,11 +249,6 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {

@Override
public boolean mouseDragged(double mouseX, double mouseY, int clickedMouseButton, double timeSinceLastClick, double unknown) {
if (this.tinkerInfo.handleMouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick)
|| this.modifierInfo.handleMouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick)) {
return false;
}

if (this.clickedOnScrollBar && this.canScroll()) {
int i = this.cornerY + 14;
int j = i + 54;
Expand All @@ -271,10 +263,6 @@ public boolean mouseDragged(double mouseX, double mouseY, int clickedMouseButton

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
if (this.tinkerInfo.handleMouseScrolled(mouseX, mouseY, delta)
|| this.modifierInfo.handleMouseScrolled(mouseX, mouseY, delta)) {
return false;
}
if (super.mouseScrolled(mouseX, mouseY, delta)) {
return true;
}
Expand All @@ -292,7 +280,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
public boolean mouseReleased(double mouseX, double mouseY, int state) {
if (this.tinkerInfo.handleMouseReleased(mouseX, mouseY, state)
|| this.modifierInfo.handleMouseReleased(mouseX, mouseY, state)) {
return false;
return true;
}
return super.mouseReleased(mouseX, mouseY, state);
}
Expand All @@ -302,18 +290,18 @@ public boolean mouseReleased(double mouseX, double mouseY, int state) {

@Override
public void error(Component message) {
this.tinkerInfo.setCaption(COMPONENT_ERROR);
this.tinkerInfo.setCaptions(COMPONENT_ERROR.copy().withStyle(ChatFormatting.UNDERLINE));
this.tinkerInfo.setText(message);
this.modifierInfo.setCaption(TextComponent.EMPTY);
this.modifierInfo.setText(TextComponent.EMPTY);
this.modifierInfo.setCaptions();
this.modifierInfo.setText();
}

@Override
public void warning(Component message) {
this.tinkerInfo.setCaption(COMPONENT_WARNING);
this.tinkerInfo.setCaptions(COMPONENT_WARNING.copy().withStyle(ChatFormatting.UNDERLINE));
this.tinkerInfo.setText(message);
this.modifierInfo.setCaption(TextComponent.EMPTY);
this.modifierInfo.setText(TextComponent.EMPTY);
this.modifierInfo.setCaptions();
this.modifierInfo.setText();
}

private Component getInfoTitle() {
Expand All @@ -328,10 +316,10 @@ private Component getInfoTitle() {

/** Displays a message with the default title */
public void message(Component message) {
this.tinkerInfo.setCaption(getInfoTitle());
this.tinkerInfo.setCaptions(getInfoTitle().copy().withStyle(ChatFormatting.UNDERLINE));
this.tinkerInfo.setText(message);
this.modifierInfo.setCaption(TextComponent.EMPTY);
this.modifierInfo.setText(TextComponent.EMPTY);
this.modifierInfo.setCaptions();
this.modifierInfo.setText();
}

@Override
Expand Down Expand Up @@ -367,4 +355,15 @@ private boolean canScroll() {
private int getHiddenRows() {
return (this.getPartRecipeCount() + 4 - 1) / 4 - 3;
}

@Override
public void resize(Minecraft mc, int width, int height) {
var tinkerData = tinkerInfo.getData();
var modifierData = modifierInfo.getData();

super.resize(mc, width, height);

tinkerInfo.setData(tinkerData);
modifierInfo.setData(modifierData);
}
}
Loading