Remove more dead UI code.
This commit is contained in:
parent
d78fdf426b
commit
82c84c7a88
10 changed files with 34 additions and 232 deletions
|
@ -25,14 +25,11 @@
|
|||
package reborncore.client.gui.builder.slot;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.client.gui.builder.slot.elements.ConfigFluidElement;
|
||||
import reborncore.client.gui.builder.slot.elements.ElementBase;
|
||||
import reborncore.client.gui.builder.slot.elements.SlotType;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -57,17 +54,13 @@ public class FluidConfigGui {
|
|||
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)) {
|
||||
if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isPressing = true;
|
||||
boolean action = element.onStartPress(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isPressing = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
element.isPressing = false;
|
||||
}
|
||||
|
@ -77,38 +70,15 @@ public class FluidConfigGui {
|
|||
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) {
|
||||
boolean clicked = false;
|
||||
if (mouseButton == 0) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
|
@ -128,16 +98,4 @@ public class FluidConfigGui {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -137,17 +137,13 @@ public class SlotConfigGui {
|
|||
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)) {
|
||||
if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
|
||||
element.isPressing = true;
|
||||
boolean action = element.onStartPress(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
if (e != element) {
|
||||
e.isPressing = false;
|
||||
}
|
||||
}
|
||||
if (action) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
element.isPressing = false;
|
||||
}
|
||||
|
@ -170,38 +166,15 @@ public class SlotConfigGui {
|
|||
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) {
|
||||
boolean clicked = false;
|
||||
if (mouseButton == 0) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY);
|
||||
for (ElementBase e : getVisibleElements()) {
|
||||
|
|
|
@ -115,7 +115,7 @@ public abstract class AbstractConfigPopupElement extends ElementBase {
|
|||
Quaternionf quaternion) {
|
||||
MatrixStack matrixStack = drawContext.getMatrices();
|
||||
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.translate(0.5F, 0.5F, 0);
|
||||
matrixStack.scale(-1, -1, 0);
|
||||
|
|
|
@ -31,12 +31,13 @@ public class ButtonElement extends ElementBase {
|
|||
public ButtonElement(int x, int y, Sprite.Button buttonSprite) {
|
||||
super(x, y, buttonSprite.normal());
|
||||
this.buttonSprite = buttonSprite;
|
||||
this.addUpdateAction((gui, element) -> {
|
||||
if (isHovering) {
|
||||
element.container.setSprite(0, buttonSprite.hovered());
|
||||
} else {
|
||||
element.container.setSprite(0, buttonSprite.normal());
|
||||
}
|
||||
});
|
||||
// TODO fix hovering, was broken anyway.
|
||||
// this.addUpdateAction((gui, element) -> {
|
||||
// if (isHovering) {
|
||||
// element.container.setSprite(0, buttonSprite.hovered());
|
||||
// } else {
|
||||
// element.container.setSprite(0, buttonSprite.normal());
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,8 +71,8 @@ public class CheckBoxElement extends ElementBase {
|
|||
if (ticked.test(this)) {
|
||||
sprite = checkBoxSprite.ticked();
|
||||
}
|
||||
drawSprite(drawContext, gui, sprite, x, y);
|
||||
drawText(drawContext, gui, label, x + checkBoxSprite.normal().width + 5, ((y + getHeight(gui.getMachine()) / 2) - (gui.getTextRenderer().fontHeight / 2)), labelColor);
|
||||
drawSprite(drawContext, gui, sprite, getX(), getY() );
|
||||
drawText(drawContext, gui, label, getX() + checkBoxSprite.normal().width + 5, ((getY() + getHeight(gui.getMachine()) / 2) - (gui.getTextRenderer().fontHeight / 2)), labelColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ConfigFluidElement extends ElementBase {
|
|||
public void draw(DrawContext drawContext, GuiBase<?> gui) {
|
||||
super.draw(drawContext, gui);
|
||||
if (isHovering) {
|
||||
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), x, y);
|
||||
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY());
|
||||
}
|
||||
elements.forEach(elementBase -> elementBase.draw(drawContext, gui));
|
||||
}
|
||||
|
|
|
@ -102,13 +102,13 @@ public class ConfigSlotElement extends ElementBase {
|
|||
public void draw(DrawContext drawContext, GuiBase<?> gui) {
|
||||
super.draw(drawContext, gui);
|
||||
ItemStack stack = inventory.getStack(id);
|
||||
int xPos = x + 1 + gui.getGuiLeft();
|
||||
int yPos = y + 1 + gui.getGuiTop();
|
||||
int xPos = getX() + 1 + gui.getGuiLeft();
|
||||
int yPos = getY() + 1 + gui.getGuiTop();
|
||||
|
||||
drawContext.drawItemInSlot(gui.getTextRenderer(), stack, xPos, yPos);
|
||||
|
||||
if (isHovering) {
|
||||
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), x, y);
|
||||
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY());
|
||||
}
|
||||
elements.forEach(elementBase -> elementBase.draw(drawContext, gui));
|
||||
}
|
||||
|
|
|
@ -36,37 +36,20 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class ElementBase {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
private final int x;
|
||||
private final int y;
|
||||
public boolean isHovering = false;
|
||||
public boolean isDragging = false;
|
||||
public boolean isPressing = 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> releaseActions = new ArrayList<>();
|
||||
public SpriteContainer container;
|
||||
public List<UpdateAction> updateActions = new ArrayList<>();
|
||||
public List<UpdateAction> buttonUpdate = new ArrayList<>();
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
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) {
|
||||
this.container = new SpriteContainer();
|
||||
for (ISprite sprite : sprites) {
|
||||
|
@ -76,33 +59,6 @@ public class ElementBase {
|
|||
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() {
|
||||
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() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public ElementBase setX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public ElementBase setY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getWidth(MachineBaseBlockEntity provider) {
|
||||
adjustDimensions(provider);
|
||||
return width;
|
||||
|
@ -182,6 +100,14 @@ public class ElementBase {
|
|||
return height;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
@ -190,21 +116,6 @@ public class ElementBase {
|
|||
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) {
|
||||
this.pressActions.add(action);
|
||||
return this;
|
||||
|
@ -215,27 +126,6 @@ public class ElementBase {
|
|||
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) {
|
||||
for (ElementBase.Action action : releaseActions) {
|
||||
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) {
|
||||
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);
|
||||
|
|
|
@ -30,14 +30,12 @@ import reborncore.RebornCore;
|
|||
import reborncore.client.ClientNetworkManager;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
import reborncore.common.blockentity.FluidConfiguration;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.network.IdentifiedPacket;
|
||||
import reborncore.common.network.ServerBoundPackets;
|
||||
import reborncore.common.util.Color;
|
||||
|
||||
public class FluidConfigPopupElement extends AbstractConfigPopupElement {
|
||||
ConfigFluidElement fluidElement;
|
||||
double lastMouseX, lastMouseY;
|
||||
|
||||
public FluidConfigPopupElement(int x, int y, ConfigFluidElement fluidElement) {
|
||||
super(x, y, Sprite.SLOT_CONFIG_POPUP);
|
||||
|
@ -70,13 +68,6 @@ public class FluidConfigPopupElement extends AbstractConfigPopupElement {
|
|||
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
|
||||
protected void drawSateColor(DrawContext drawContext, GuiBase<?> gui, Direction side, int inx, int iny) {
|
||||
iny += 4;
|
||||
|
|
|
@ -45,9 +45,9 @@ public class SlotConfigExclusionZones implements ExclusionZonesProvider<GuiBase<
|
|||
return Collections.emptyList();
|
||||
}
|
||||
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() ) {
|
||||
int slotY = element.y + screen.getGuiTop() + 25;
|
||||
int slotY = element.getY() + screen.getGuiTop() + 25;
|
||||
int exclusionX = screen.getScreenWidth() + screen.getGuiLeft();
|
||||
int exclusionY = slotY + screen.getGuiTop() - (element.getHeight()/2);
|
||||
int exclusionWidth = element.getWidth() + slotX - screen.getScreenWidth() + 15;
|
||||
|
|
Loading…
Reference in a new issue