Remove more dead UI code.

This commit is contained in:
modmuss50 2023-05-31 16:35:00 +01:00 committed by modmuss
parent d78fdf426b
commit 82c84c7a88
10 changed files with 34 additions and 232 deletions

View file

@ -25,14 +25,11 @@
package reborncore.client.gui.builder.slot; package reborncore.client.gui.builder.slot;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import org.jetbrains.annotations.Nullable;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.slot.elements.ConfigFluidElement; import reborncore.client.gui.builder.slot.elements.ConfigFluidElement;
import reborncore.client.gui.builder.slot.elements.ElementBase; import reborncore.client.gui.builder.slot.elements.ElementBase;
import reborncore.client.gui.builder.slot.elements.SlotType; import reborncore.client.gui.builder.slot.elements.SlotType;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -57,17 +54,13 @@ public class FluidConfigGui {
if (mouseButton == 0) { if (mouseButton == 0) {
for (ConfigFluidElement configFluidElement : getVisibleElements()) { for (ConfigFluidElement configFluidElement : getVisibleElements()) {
for (ElementBase element : configFluidElement.elements) { for (ElementBase element : configFluidElement.elements) {
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
element.isPressing = true; element.isPressing = true;
boolean action = element.onStartPress(guiBase.getMachine(), guiBase, mouseX, mouseY);
for (ElementBase e : getVisibleElements()) { for (ElementBase e : getVisibleElements()) {
if (e != element) { if (e != element) {
e.isPressing = false; e.isPressing = false;
} }
} }
if (action) {
break;
}
} else { } else {
element.isPressing = false; element.isPressing = false;
} }
@ -77,38 +70,15 @@ public class FluidConfigGui {
return !getVisibleElements().isEmpty(); return !getVisibleElements().isEmpty();
} }
public static void mouseClickMove(double mouseX, double mouseY, int mouseButton, long timeSinceLastClick, GuiBase<?> guiBase) {
if (mouseButton == 0) {
for (ConfigFluidElement configFluidElement : getVisibleElements()) {
for (ElementBase element : configFluidElement.elements) {
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
element.isDragging = true;
boolean action = element.onDrag(guiBase.getMachine(), guiBase, mouseX, mouseY);
for (ElementBase e : getVisibleElements()) {
if (e != element) {
e.isDragging = false;
}
}
if (action) {
break;
}
} else {
element.isDragging = false;
}
}
}
}
}
public static boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) { public static boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
boolean clicked = false; boolean clicked = false;
if (mouseButton == 0) { if (mouseButton == 0) {
for (ConfigFluidElement configFluidElement : getVisibleElements()) { for (ConfigFluidElement configFluidElement : getVisibleElements()) {
if (configFluidElement.isInRect(guiBase, configFluidElement.x, configFluidElement.y, configFluidElement.getWidth(guiBase.getMachine()), configFluidElement.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (configFluidElement.isInRect(guiBase, configFluidElement.getX(), configFluidElement.getY(), configFluidElement.getWidth(guiBase.getMachine()), configFluidElement.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
clicked = true; clicked = true;
} }
for (ElementBase element : Lists.reverse(configFluidElement.elements)) { for (ElementBase element : Lists.reverse(configFluidElement.elements)) {
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
element.isReleasing = true; element.isReleasing = true;
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY); boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY);
for (ElementBase e : getVisibleElements()) { for (ElementBase e : getVisibleElements()) {
@ -128,16 +98,4 @@ public class FluidConfigGui {
} }
return clicked; return clicked;
} }
@Nullable
private static MachineBaseBlockEntity getMachine() {
if (!(MinecraftClient.getInstance().currentScreen instanceof GuiBase<?> base)) {
return null;
}
if (base.be instanceof MachineBaseBlockEntity machineBase) {
return machineBase;
}
return null;
}
} }

View file

@ -137,17 +137,13 @@ public class SlotConfigGui {
if (mouseButton == 0) { if (mouseButton == 0) {
for (ConfigSlotElement configSlotElement : getVisibleElements()) { for (ConfigSlotElement configSlotElement : getVisibleElements()) {
for (ElementBase element : configSlotElement.elements) { for (ElementBase element : configSlotElement.elements) {
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
element.isPressing = true; element.isPressing = true;
boolean action = element.onStartPress(guiBase.getMachine(), guiBase, mouseX, mouseY);
for (ElementBase e : getVisibleElements()) { for (ElementBase e : getVisibleElements()) {
if (e != element) { if (e != element) {
e.isPressing = false; e.isPressing = false;
} }
} }
if (action) {
break;
}
} else { } else {
element.isPressing = false; element.isPressing = false;
} }
@ -170,38 +166,15 @@ public class SlotConfigGui {
return !getVisibleElements().isEmpty(); return !getVisibleElements().isEmpty();
} }
public static void mouseClickMove(double mouseX, double mouseY, int mouseButton, long timeSinceLastClick, GuiBase<?> guiBase) {
if (mouseButton == 0) {
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
for (ElementBase element : configSlotElement.elements) {
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
element.isDragging = true;
boolean action = element.onDrag(guiBase.getMachine(), guiBase, mouseX, mouseY);
for (ElementBase e : getVisibleElements()) {
if (e != element) {
e.isDragging = false;
}
}
if (action) {
break;
}
} else {
element.isDragging = false;
}
}
}
}
}
public static boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) { public static boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
boolean clicked = false; boolean clicked = false;
if (mouseButton == 0) { if (mouseButton == 0) {
for (ConfigSlotElement configSlotElement : getVisibleElements()) { for (ConfigSlotElement configSlotElement : getVisibleElements()) {
if (configSlotElement.isInRect(guiBase, configSlotElement.x, configSlotElement.y, configSlotElement.getWidth(guiBase.getMachine()), configSlotElement.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (configSlotElement.isInRect(guiBase, configSlotElement.getX(), configSlotElement.getY(), configSlotElement.getWidth(guiBase.getMachine()), configSlotElement.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
clicked = true; clicked = true;
} }
for (ElementBase element : Lists.reverse(configSlotElement.elements)) { for (ElementBase element : Lists.reverse(configSlotElement.elements)) {
if (element.isInRect(guiBase, element.x, element.y, element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
element.isReleasing = true; element.isReleasing = true;
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY); boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY);
for (ElementBase e : getVisibleElements()) { for (ElementBase e : getVisibleElements()) {

View file

@ -115,7 +115,7 @@ public abstract class AbstractConfigPopupElement extends ElementBase {
Quaternionf quaternion) { Quaternionf quaternion) {
MatrixStack matrixStack = drawContext.getMatrices(); MatrixStack matrixStack = drawContext.getMatrices();
matrixStack.push(); matrixStack.push();
matrixStack.translate(8 + gui.getGuiLeft() + this.x + x, 8 + gui.getGuiTop() + this.y + y, 0); matrixStack.translate(8 + gui.getGuiLeft() + getX() + x, 8 + gui.getGuiTop() + getY() + y, 0);
matrixStack.scale(16F, 16F, 16F); matrixStack.scale(16F, 16F, 16F);
matrixStack.translate(0.5F, 0.5F, 0); matrixStack.translate(0.5F, 0.5F, 0);
matrixStack.scale(-1, -1, 0); matrixStack.scale(-1, -1, 0);

View file

@ -31,12 +31,13 @@ public class ButtonElement extends ElementBase {
public ButtonElement(int x, int y, Sprite.Button buttonSprite) { public ButtonElement(int x, int y, Sprite.Button buttonSprite) {
super(x, y, buttonSprite.normal()); super(x, y, buttonSprite.normal());
this.buttonSprite = buttonSprite; this.buttonSprite = buttonSprite;
this.addUpdateAction((gui, element) -> { // TODO fix hovering, was broken anyway.
if (isHovering) { // this.addUpdateAction((gui, element) -> {
element.container.setSprite(0, buttonSprite.hovered()); // if (isHovering) {
} else { // element.container.setSprite(0, buttonSprite.hovered());
element.container.setSprite(0, buttonSprite.normal()); // } else {
} // element.container.setSprite(0, buttonSprite.normal());
}); // }
// });
} }
} }

View file

@ -71,8 +71,8 @@ public class CheckBoxElement extends ElementBase {
if (ticked.test(this)) { if (ticked.test(this)) {
sprite = checkBoxSprite.ticked(); sprite = checkBoxSprite.ticked();
} }
drawSprite(drawContext, gui, sprite, x, y); drawSprite(drawContext, gui, sprite, getX(), getY() );
drawText(drawContext, gui, label, x + checkBoxSprite.normal().width + 5, ((y + getHeight(gui.getMachine()) / 2) - (gui.getTextRenderer().fontHeight / 2)), labelColor); drawText(drawContext, gui, label, getX() + checkBoxSprite.normal().width + 5, ((getY() + getHeight(gui.getMachine()) / 2) - (gui.getTextRenderer().fontHeight / 2)), labelColor);
} }
} }

View file

@ -70,7 +70,7 @@ public class ConfigFluidElement extends ElementBase {
public void draw(DrawContext drawContext, GuiBase<?> gui) { public void draw(DrawContext drawContext, GuiBase<?> gui) {
super.draw(drawContext, gui); super.draw(drawContext, gui);
if (isHovering) { if (isHovering) {
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), x, y); drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY());
} }
elements.forEach(elementBase -> elementBase.draw(drawContext, gui)); elements.forEach(elementBase -> elementBase.draw(drawContext, gui));
} }

View file

@ -102,13 +102,13 @@ public class ConfigSlotElement extends ElementBase {
public void draw(DrawContext drawContext, GuiBase<?> gui) { public void draw(DrawContext drawContext, GuiBase<?> gui) {
super.draw(drawContext, gui); super.draw(drawContext, gui);
ItemStack stack = inventory.getStack(id); ItemStack stack = inventory.getStack(id);
int xPos = x + 1 + gui.getGuiLeft(); int xPos = getX() + 1 + gui.getGuiLeft();
int yPos = y + 1 + gui.getGuiTop(); int yPos = getY() + 1 + gui.getGuiTop();
drawContext.drawItemInSlot(gui.getTextRenderer(), stack, xPos, yPos); drawContext.drawItemInSlot(gui.getTextRenderer(), stack, xPos, yPos);
if (isHovering) { if (isHovering) {
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), x, y); drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY());
} }
elements.forEach(elementBase -> elementBase.draw(drawContext, gui)); elements.forEach(elementBase -> elementBase.draw(drawContext, gui));
} }

View file

@ -36,37 +36,20 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ElementBase { public class ElementBase {
private final int x;
public int x; private final int y;
public int y;
public boolean isHovering = false; public boolean isHovering = false;
public boolean isDragging = false;
public boolean isPressing = false; public boolean isPressing = false;
public boolean isReleasing = false; public boolean isReleasing = false;
public boolean startPressLast = false;
public boolean isHoveringLast = false;
public boolean isDraggingLast = false;
public boolean isPressingLast = false;
public boolean isReleasingLast = false;
public List<ElementBase.Action> hoverActions = new ArrayList<>();
public List<ElementBase.Action> dragActions = new ArrayList<>();
public List<ElementBase.Action> startPressActions = new ArrayList<>();
public List<ElementBase.Action> pressActions = new ArrayList<>(); public List<ElementBase.Action> pressActions = new ArrayList<>();
public List<ElementBase.Action> releaseActions = new ArrayList<>(); public List<ElementBase.Action> releaseActions = new ArrayList<>();
public SpriteContainer container; public SpriteContainer container;
public List<UpdateAction> updateActions = new ArrayList<>();
public List<UpdateAction> buttonUpdate = new ArrayList<>();
private int width; private int width;
private int height; private int height;
public static final Identifier MECH_ELEMENTS = new Identifier("reborncore", "textures/gui/elements.png"); public static final Identifier MECH_ELEMENTS = new Identifier("reborncore", "textures/gui/elements.png");
public ElementBase(int x, int y, SpriteContainer container) {
this.container = container;
this.x = x;
this.y = y;
}
public ElementBase(int x, int y, ISprite... sprites) { public ElementBase(int x, int y, ISprite... sprites) {
this.container = new SpriteContainer(); this.container = new SpriteContainer();
for (ISprite sprite : sprites) { for (ISprite sprite : sprites) {
@ -76,33 +59,6 @@ public class ElementBase {
this.y = y; this.y = y;
} }
public ElementBase(int x, int y, int width, int height) {
this.container = new SpriteContainer();
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public ElementBase(int x, int y, int width, int height, SpriteContainer container) {
this.container = container;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public ElementBase(int x, int y, int width, int height, ISprite... sprites) {
this.container = new SpriteContainer();
for (ISprite sprite : sprites) {
container.addSprite(sprite);
}
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public SpriteContainer getSpriteContainer() { public SpriteContainer getSpriteContainer() {
return container; return container;
} }
@ -126,52 +82,14 @@ public class ElementBase {
} }
} }
public void renderUpdate(GuiBase<?> gui) {
isHoveringLast = isHovering;
isPressingLast = isPressing;
isDraggingLast = isDragging;
isReleasingLast = isReleasing;
}
public void update(GuiBase<?> gui) {
for (UpdateAction action : updateActions) {
action.update(gui, this);
}
}
public ElementBase addUpdateAction(UpdateAction action) {
updateActions.add(action);
return this;
}
public ElementBase setWidth(int width) {
this.width = width;
return this;
}
public ElementBase setHeight(int height) {
this.height = height;
return this;
}
public int getX() { public int getX() {
return x; return x;
} }
public ElementBase setX(int x) {
this.x = x;
return this;
}
public int getY() { public int getY() {
return y; return y;
} }
public ElementBase setY(int y) {
this.y = y;
return this;
}
public int getWidth(MachineBaseBlockEntity provider) { public int getWidth(MachineBaseBlockEntity provider) {
adjustDimensions(provider); adjustDimensions(provider);
return width; return width;
@ -182,6 +100,14 @@ public class ElementBase {
return height; return height;
} }
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public int getWidth() { public int getWidth() {
return width; return width;
} }
@ -190,21 +116,6 @@ public class ElementBase {
return height; return height;
} }
public ElementBase addHoverAction(ElementBase.Action action) {
this.hoverActions.add(action);
return this;
}
public ElementBase addDragAction(ElementBase.Action action) {
this.dragActions.add(action);
return this;
}
public ElementBase addStartPressAction(ElementBase.Action action) {
this.startPressActions.add(action);
return this;
}
public ElementBase addPressAction(ElementBase.Action action) { public ElementBase addPressAction(ElementBase.Action action) {
this.pressActions.add(action); this.pressActions.add(action);
return this; return this;
@ -215,27 +126,6 @@ public class ElementBase {
return this; return this;
} }
public boolean onHover(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
for (ElementBase.Action action : hoverActions) {
action.execute(this, gui, provider, mouseX, mouseY);
}
return !hoverActions.isEmpty();
}
public boolean onDrag(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
for (ElementBase.Action action : dragActions) {
action.execute(this, gui, provider, mouseX, mouseY);
}
return !dragActions.isEmpty();
}
public boolean onStartPress(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
for (ElementBase.Action action : startPressActions) {
action.execute(this, gui, provider, mouseX, mouseY);
}
return !startPressActions.isEmpty();
}
public boolean onRelease(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) { public boolean onRelease(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
for (ElementBase.Action action : releaseActions) { for (ElementBase.Action action : releaseActions) {
if (action.execute(this, gui, provider, mouseX, mouseY)) { if (action.execute(this, gui, provider, mouseX, mouseY)) {
@ -288,17 +178,6 @@ public class ElementBase {
} }
} }
public int getScaledBurnTime(int scale, int burnTime, int totalBurnTime) {
return (int) (((float) burnTime / (float) totalBurnTime) * scale);
}
public int getPercentage(int MaxValue, int CurrentValue) {
if (CurrentValue == 0) {
return 0;
}
return (int) ((CurrentValue * 100.0f) / MaxValue);
}
public void drawDefaultBackground(DrawContext drawContext, Screen gui, int x, int y, int width, int height) { public void drawDefaultBackground(DrawContext drawContext, Screen gui, int x, int y, int width, int height) {
drawContext.drawTexture(GuiBuilder.defaultTextureSheet, x, y, 0, 0, width / 2, height / 2); drawContext.drawTexture(GuiBuilder.defaultTextureSheet, x, y, 0, 0, width / 2, height / 2);
drawContext.drawTexture(GuiBuilder.defaultTextureSheet, x + width / 2, y, 150 - width / 2, 0, width / 2, height / 2); drawContext.drawTexture(GuiBuilder.defaultTextureSheet, x + width / 2, y, 150 - width / 2, 0, width / 2, height / 2);

View file

@ -30,14 +30,12 @@ import reborncore.RebornCore;
import reborncore.client.ClientNetworkManager; import reborncore.client.ClientNetworkManager;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.common.blockentity.FluidConfiguration; import reborncore.common.blockentity.FluidConfiguration;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.network.IdentifiedPacket; import reborncore.common.network.IdentifiedPacket;
import reborncore.common.network.ServerBoundPackets; import reborncore.common.network.ServerBoundPackets;
import reborncore.common.util.Color; import reborncore.common.util.Color;
public class FluidConfigPopupElement extends AbstractConfigPopupElement { public class FluidConfigPopupElement extends AbstractConfigPopupElement {
ConfigFluidElement fluidElement; ConfigFluidElement fluidElement;
double lastMouseX, lastMouseY;
public FluidConfigPopupElement(int x, int y, ConfigFluidElement fluidElement) { public FluidConfigPopupElement(int x, int y, ConfigFluidElement fluidElement) {
super(x, y, Sprite.SLOT_CONFIG_POPUP); super(x, y, Sprite.SLOT_CONFIG_POPUP);
@ -70,13 +68,6 @@ public class FluidConfigPopupElement extends AbstractConfigPopupElement {
ClientNetworkManager.sendToServer(packetFluidIOSave); ClientNetworkManager.sendToServer(packetFluidIOSave);
} }
@Override
public boolean onHover(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
lastMouseX = mouseX;
lastMouseY = mouseY;
return super.onHover(provider, gui, mouseX, mouseY);
}
@Override @Override
protected void drawSateColor(DrawContext drawContext, GuiBase<?> gui, Direction side, int inx, int iny) { protected void drawSateColor(DrawContext drawContext, GuiBase<?> gui, Direction side, int inx, int iny) {
iny += 4; iny += 4;

View file

@ -45,9 +45,9 @@ public class SlotConfigExclusionZones implements ExclusionZonesProvider<GuiBase<
return Collections.emptyList(); return Collections.emptyList();
} }
ConfigSlotElement element = SlotConfigGui.slotElementMap.get(SlotConfigGui.selectedSlot); ConfigSlotElement element = SlotConfigGui.slotElementMap.get(SlotConfigGui.selectedSlot);
int slotX = element.x + screen.getGuiLeft() -50; int slotX = element.getX() + screen.getGuiLeft() -50;
if (element.getWidth() + slotX > screen.getScreenWidth() ) { if (element.getWidth() + slotX > screen.getScreenWidth() ) {
int slotY = element.y + screen.getGuiTop() + 25; int slotY = element.getY() + screen.getGuiTop() + 25;
int exclusionX = screen.getScreenWidth() + screen.getGuiLeft(); int exclusionX = screen.getScreenWidth() + screen.getGuiLeft();
int exclusionY = slotY + screen.getGuiTop() - (element.getHeight()/2); int exclusionY = slotY + screen.getGuiTop() - (element.getHeight()/2);
int exclusionWidth = element.getWidth() + slotX - screen.getScreenWidth() + 15; int exclusionWidth = element.getWidth() + slotX - screen.getScreenWidth() + 15;