Gui cleanup

This commit is contained in:
modmuss50 2023-05-31 19:20:28 +01:00 committed by modmuss
parent 0171ef9778
commit 4ee192b4cd
48 changed files with 146 additions and 686 deletions

View file

@ -75,7 +75,6 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
.stack(guiTab -> wrenchStack) .stack(guiTab -> wrenchStack)
.draw(SlotConfigGui::draw) .draw(SlotConfigGui::draw)
.click(SlotConfigGui::mouseClicked) .click(SlotConfigGui::mouseClicked)
.mouseReleased(SlotConfigGui::mouseReleased)
.hideGuiElements() .hideGuiElements()
.keyPressed((guiBase, keyCode, scanCode, modifiers) -> { .keyPressed((guiBase, keyCode, scanCode, modifiers) -> {
if (hasControlDown() && keyCode == GLFW.GLFW_KEY_C) { if (hasControlDown() && keyCode == GLFW.GLFW_KEY_C) {
@ -106,7 +105,6 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
.stack(guiTab -> GuiBase.fluidCellProvider.provide(Fluids.LAVA)) .stack(guiTab -> GuiBase.fluidCellProvider.provide(Fluids.LAVA))
.draw(FluidConfigGui::draw) .draw(FluidConfigGui::draw)
.click(FluidConfigGui::mouseClicked) .click(FluidConfigGui::mouseClicked)
.mouseReleased(FluidConfigGui::mouseReleased)
.hideGuiElements() .hideGuiElements()
); );
@ -324,17 +322,6 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
return super.mouseClicked(mouseX, mouseY, mouseButton); return super.mouseClicked(mouseX, mouseY, mouseButton);
} }
// @Override
// protected void mouseClickMove(double mouseX, double mouseY, int clickedMouseButton, long timeSinceLastClick) {
// if (isConfigEnabled() && slotConfigType == SlotConfigType.ITEMS && getMachine().hasSlotConfig()) {
// GuiSlotConfiguration.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick, this);
// }
// if (isConfigEnabled() && slotConfigType == SlotConfigType.FLUIDS && getMachine().showTankConfig()) {
// GuiFluidConfiguration.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick, this);
// }
// super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
// }
@Override @Override
public boolean mouseReleased(double mouseX, double mouseY, int state) { public boolean mouseReleased(double mouseX, double mouseY, int state) {
int offset = 0; int offset = 0;
@ -354,9 +341,6 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
offset -= 24; offset -= 24;
} }
if (getTab().map(guiTab -> guiTab.mouseReleased(mouseX, mouseY, state)).orElse(false)) {
return true;
}
return super.mouseReleased(mouseX, mouseY, state); return super.mouseReleased(mouseX, mouseY, state);
} }

View file

@ -34,6 +34,7 @@ import reborncore.client.gui.builder.slot.elements.SlotType;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
// Why is this static?
public class FluidConfigGui { public class FluidConfigGui {
static ConfigFluidElement fluidConfigElement; static ConfigFluidElement fluidConfigElement;
@ -43,7 +44,7 @@ public class FluidConfigGui {
} }
public static void draw(DrawContext drawContext, GuiBase<?> guiBase, int mouseX, int mouseY) { public static void draw(DrawContext drawContext, GuiBase<?> guiBase, int mouseX, int mouseY) {
fluidConfigElement.draw(drawContext, guiBase); fluidConfigElement.draw(drawContext, guiBase, mouseX, mouseY);
} }
public static List<ConfigFluidElement> getVisibleElements() { public static List<ConfigFluidElement> getVisibleElements() {
@ -52,50 +53,17 @@ public class FluidConfigGui {
public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) { public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
if (mouseButton == 0) { if (mouseButton == 0) {
for (ConfigFluidElement configFluidElement : getVisibleElements()) { for (ConfigFluidElement configSlotElement : getVisibleElements()) {
for (ElementBase element : configFluidElement.elements) { for (ElementBase element : Lists.reverse(configSlotElement.elements)) {
if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (element.isMouseWithinRect(guiBase, mouseX, mouseY)) {
element.isPressing = true; if (element.onClick(guiBase.getMachine(), guiBase, mouseX, mouseY)) {
for (ElementBase e : getVisibleElements()) { return true;
if (e != element) {
e.isPressing = false;
}
} }
} else {
element.isPressing = false;
} }
} }
} }
} }
return !getVisibleElements().isEmpty(); return !getVisibleElements().isEmpty();
} }
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.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.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()) {
if (e != element) {
e.isReleasing = false;
}
}
if (action) {
clicked = true;
}
break;
} else {
element.isReleasing = false;
}
}
}
}
return clicked;
}
} }

View file

@ -71,10 +71,6 @@ public class GuiTab {
return builder.click.click(guiBase, mouseX, mouseY, mouseButton); return builder.click.click(guiBase, mouseX, mouseY, mouseButton);
} }
public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) {
return builder.mouseReleased.mouseReleased(guiBase, mouseX, mouseY, mouseButton);
}
public boolean keyPress(int keyCode, int scanCode, int modifiers) { public boolean keyPress(int keyCode, int scanCode, int modifiers) {
return builder.keyPressed.keyPress(guiBase, keyCode, scanCode, modifiers); return builder.keyPressed.keyPress(guiBase, keyCode, scanCode, modifiers);
} }
@ -101,7 +97,6 @@ public class GuiTab {
private Draw draw = (matrixStack, gui, x, y) -> { private Draw draw = (matrixStack, gui, x, y) -> {
}; };
private Click click = (guiBase, mouseX, mouseY, mouseButton) -> false; private Click click = (guiBase, mouseX, mouseY, mouseButton) -> false;
private MouseReleased mouseReleased = (guiBase, mouseX, mouseY, state) -> false;
private KeyPressed keyPressed = (guiBase, keyCode, scanCode, modifiers) -> false; private KeyPressed keyPressed = (guiBase, keyCode, scanCode, modifiers) -> false;
private Consumer<List<String>> tips = strings -> { private Consumer<List<String>> tips = strings -> {
}; };
@ -136,11 +131,6 @@ public class GuiTab {
return this; return this;
} }
public Builder mouseReleased(MouseReleased mouseReleased) {
this.mouseReleased = mouseReleased;
return this;
}
public Builder keyPressed(KeyPressed keyPressed) { public Builder keyPressed(KeyPressed keyPressed) {
this.keyPressed = keyPressed; this.keyPressed = keyPressed;
return this; return this;
@ -169,10 +159,6 @@ public class GuiTab {
boolean click(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton); boolean click(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton);
} }
public interface MouseReleased {
boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int state);
}
public interface KeyPressed { public interface KeyPressed {
boolean keyPress(GuiBase<?> guiBase, int keyCode, int scanCode, int modifiers); boolean keyPress(GuiBase<?> guiBase, int keyCode, int scanCode, int modifiers);
} }

View file

@ -46,6 +46,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
// Why is all this static?
public class SlotConfigGui { public class SlotConfigGui {
public static HashMap<Integer, ConfigSlotElement> slotElementMap = new HashMap<>(); public static HashMap<Integer, ConfigSlotElement> slotElementMap = new HashMap<>();
@ -84,7 +85,7 @@ public class SlotConfigGui {
} }
if (selectedSlot != -1) { if (selectedSlot != -1) {
slotElementMap.get(selectedSlot).draw(drawContext, guiBase); slotElementMap.get(selectedSlot).draw(drawContext, guiBase, mouseX, mouseY);
} }
} }
@ -134,22 +135,6 @@ public class SlotConfigGui {
} }
public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) { public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
if (mouseButton == 0) {
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
for (ElementBase element : configSlotElement.elements) {
if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) {
element.isPressing = true;
for (ElementBase e : getVisibleElements()) {
if (e != element) {
e.isPressing = false;
}
}
} else {
element.isPressing = false;
}
}
}
}
BuiltScreenHandler screenHandler = guiBase.builtScreenHandler; BuiltScreenHandler screenHandler = guiBase.builtScreenHandler;
if (getVisibleElements().isEmpty()) { if (getVisibleElements().isEmpty()) {
@ -163,36 +148,19 @@ public class SlotConfigGui {
} }
} }
} }
return !getVisibleElements().isEmpty();
}
public static boolean mouseReleased(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
boolean clicked = false;
if (mouseButton == 0) { if (mouseButton == 0) {
for (ConfigSlotElement configSlotElement : getVisibleElements()) { for (ConfigSlotElement configSlotElement : getVisibleElements()) {
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)) { for (ElementBase element : Lists.reverse(configSlotElement.elements)) {
if (element.isInRect(guiBase, element.getX(), element.getY(), element.getWidth(guiBase.getMachine()), element.getHeight(guiBase.getMachine()), mouseX, mouseY)) { if (element.isMouseWithinRect(guiBase, mouseX, mouseY)) {
element.isReleasing = true; if (element.onClick(guiBase.getMachine(), guiBase, mouseX, mouseY)) {
boolean action = element.onRelease(guiBase.getMachine(), guiBase, mouseX, mouseY); return true;
for (ElementBase e : getVisibleElements()) {
if (e != element) {
e.isReleasing = false;
}
} }
if (action) {
clicked = true;
}
break;
} else {
element.isReleasing = false;
} }
} }
} }
} }
return clicked;
}
return !getVisibleElements().isEmpty();
}
} }

View file

@ -44,14 +44,14 @@ import reborncore.common.util.MachineFacing;
public abstract class AbstractConfigPopupElement extends ElementBase { public abstract class AbstractConfigPopupElement extends ElementBase {
public boolean filter = false; public boolean filter = false;
public AbstractConfigPopupElement(int x, int y, ISprite... sprites) { public AbstractConfigPopupElement(int x, int y, Sprite sprite) {
super(x, y, sprites); super(x, y, sprite);
} }
@Override @Override
public final void draw(DrawContext drawContext, GuiBase<?> gui) { public final void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
drawDefaultBackground(drawContext, gui, adjustX(gui, getX() - 8), adjustY(gui, getY() - 7), 84, 105 + (filter ? 15 : 0)); drawDefaultBackground(drawContext, gui, adjustX(gui, getX() - 8), adjustY(gui, getY() - 7), 84, 105 + (filter ? 15 : 0));
super.draw(drawContext, gui); super.draw(drawContext, gui, mouseX, mouseY);
final MachineBaseBlockEntity machine = ((MachineBaseBlockEntity) gui.be); final MachineBaseBlockEntity machine = ((MachineBaseBlockEntity) gui.be);
final BlockState state = machine.getCachedState(); final BlockState state = machine.getCachedState();
@ -75,23 +75,28 @@ public abstract class AbstractConfigPopupElement extends ElementBase {
} }
@Override @Override
public final boolean onRelease(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) { public final boolean onClick(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
if (isInBox(23, 4, 16, 16, mouseX, mouseY, gui)) { if (isInBox(23, 4, 16, 16, mouseX, mouseY, gui)) {
cycleConfig(MachineFacing.UP.getFacing(provider), gui); cycleConfig(MachineFacing.UP.getFacing(provider), gui);
return true;
} else if (isInBox(23, 23, 16, 16, mouseX, mouseY, gui)) { } else if (isInBox(23, 23, 16, 16, mouseX, mouseY, gui)) {
cycleConfig(MachineFacing.FRONT.getFacing(provider), gui); cycleConfig(MachineFacing.FRONT.getFacing(provider), gui);
return true;
} else if (isInBox(42, 23, 16, 16, mouseX, mouseY, gui)) { } else if (isInBox(42, 23, 16, 16, mouseX, mouseY, gui)) {
cycleConfig(MachineFacing.RIGHT.getFacing(provider), gui); cycleConfig(MachineFacing.RIGHT.getFacing(provider), gui);
return true;
} else if (isInBox(4, 23, 16, 16, mouseX, mouseY, gui)) { } else if (isInBox(4, 23, 16, 16, mouseX, mouseY, gui)) {
cycleConfig(MachineFacing.LEFT.getFacing(provider), gui); cycleConfig(MachineFacing.LEFT.getFacing(provider), gui);
return true;
} else if (isInBox(23, 42, 16, 16, mouseX, mouseY, gui)) { } else if (isInBox(23, 42, 16, 16, mouseX, mouseY, gui)) {
cycleConfig(MachineFacing.DOWN.getFacing(provider), gui); cycleConfig(MachineFacing.DOWN.getFacing(provider), gui);
return true;
} else if (isInBox(42, 42, 16, 16, mouseX, mouseY, gui)) { } else if (isInBox(42, 42, 16, 16, mouseX, mouseY, gui)) {
cycleConfig(MachineFacing.BACK.getFacing(provider), gui); cycleConfig(MachineFacing.BACK.getFacing(provider), gui);
} else { return true;
return false;
} }
return true;
return false;
} }
protected abstract void cycleConfig(Direction side, GuiBase<?> guiBase); protected abstract void cycleConfig(Direction side, GuiBase<?> guiBase);

View file

@ -24,20 +24,29 @@
package reborncore.client.gui.builder.slot.elements; package reborncore.client.gui.builder.slot.elements;
public class ButtonElement extends ElementBase { import net.minecraft.client.gui.DrawContext;
@SuppressWarnings("unused") import reborncore.client.gui.builder.GuiBase;
private final Sprite.Button buttonSprite; import reborncore.common.blockentity.MachineBaseBlockEntity;
public ButtonElement(int x, int y, Sprite.Button buttonSprite) { public class ButtonElement extends ElementBase {
private final Sprite.Button buttonSprite;
private final Runnable onClicked;
public ButtonElement(int x, int y, Sprite.Button buttonSprite, Runnable onClicked) {
super(x, y, buttonSprite.normal()); super(x, y, buttonSprite.normal());
this.buttonSprite = buttonSprite; this.buttonSprite = buttonSprite;
// TODO fix hovering, was broken anyway. this.onClicked = onClicked;
// this.addUpdateAction((gui, element) -> { }
// if (isHovering) {
// element.container.setSprite(0, buttonSprite.hovered()); @Override
// } else { public boolean onClick(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
// element.container.setSprite(0, buttonSprite.normal()); onClicked.run();
// } return true;
// }); }
@Override
public void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
setSprite(isMouseWithinRect(gui, mouseX, mouseY) ? buttonSprite.hovered() : buttonSprite.normal());
super.draw(drawContext, gui, mouseX, mouseY);
} }
} }

View file

@ -32,47 +32,45 @@ import reborncore.common.blockentity.MachineBaseBlockEntity;
import java.util.function.Predicate; import java.util.function.Predicate;
public class CheckBoxElement extends ElementBase { public class CheckBoxElement extends ElementBase {
public Text label; private final Text label;
public String type; private final Predicate<CheckBoxElement> ticked;
public int labelColor, slotID; private final Runnable onChange;
public MachineBaseBlockEntity machineBase;
Predicate<CheckBoxElement> ticked;
private final Sprite.CheckBox checkBoxSprite; private final Sprite.CheckBox checkBoxSprite;
public CheckBoxElement(Text label, int labelColor, int x, int y, String type, int slotID, Sprite.CheckBox checkBoxSprite, MachineBaseBlockEntity machineBase, Predicate<CheckBoxElement> ticked) { public CheckBoxElement(Text label, int x, int y,
super(x, y, checkBoxSprite.normal()); Predicate<CheckBoxElement> ticked,
this.checkBoxSprite = checkBoxSprite; Runnable onChange) {
this.type = type; super(x, y, Sprite.LIGHT_CHECK_BOX.normal());
this.slotID = slotID; this.checkBoxSprite = Sprite.LIGHT_CHECK_BOX;
this.machineBase = machineBase;
this.label = label; this.label = label;
this.labelColor = labelColor;
this.ticked = ticked; this.ticked = ticked;
this.onChange = onChange;
updateSprites();
}
private void updateSprites() {
if (ticked.test(this)) { if (ticked.test(this)) {
container.setSprite(0, checkBoxSprite.ticked()); setSprite(checkBoxSprite.ticked());
} else { } else {
container.setSprite(0, checkBoxSprite.normal()); setSprite(checkBoxSprite.normal());
} }
this.addPressAction((element, gui, provider, mouseX, mouseY) -> {
if (ticked.test(this)) {
element.container.setSprite(0, checkBoxSprite.ticked());
} else {
element.container.setSprite(0, checkBoxSprite.normal());
}
return true;
});
} }
@Override @Override
public void draw(DrawContext drawContext, GuiBase<?> gui) { public boolean onClick(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
// super.draw(gui); onChange.run();
ISprite sprite = checkBoxSprite.normal(); updateSprites();
return true;
}
@Override
public void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
Sprite sprite = checkBoxSprite.normal();
if (ticked.test(this)) { if (ticked.test(this)) {
sprite = checkBoxSprite.ticked(); sprite = checkBoxSprite.ticked();
} }
drawSprite(drawContext, gui, sprite, getX(), getY() ); 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); drawText(drawContext, gui, label, getX() + checkBoxSprite.normal().width() + 5, ((getY() + getHeight() / 2) - (gui.getTextRenderer().fontHeight / 2)), 0xFFFFFFFF);
} }
} }

View file

@ -46,33 +46,33 @@ public class ConfigFluidElement extends ElementBase {
FluidConfigPopupElement popupElement; FluidConfigPopupElement popupElement;
elements.add(popupElement = new FluidConfigPopupElement(x - 22, y - 22, this)); elements.add(popupElement = new FluidConfigPopupElement(x - 22, y - 22, this));
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON).addReleaseAction((element, gui1, provider, mouseX, mouseY) -> { elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON, gui::closeSelectedTab));
gui.closeSelectedTab();
return true;
}));
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pullin"), 0xFFFFFFFF, x - 26, y + 42, "input", 0, Sprite.LIGHT_CHECK_BOX, gui.getMachine(), elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pullin"), x - 26, y + 42,
checkBoxElement -> checkBoxElement.machineBase.fluidConfiguration.autoInput()).addPressAction((element, gui12, provider, mouseX, mouseY) -> { checkBoxElement -> gui.getMachine().fluidConfiguration.autoInput(),
popupElement.updateCheckBox((CheckBoxElement) element, "input", gui12); () -> popupElement.updateCheckBox("input", gui)));
return true; elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pumpout"), x - 26, y + 57,
})); checkBoxElement -> gui.getMachine().fluidConfiguration.autoOutput(),
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pumpout"), 0xFFFFFFFF, x - 26, y + 57, "output", 0, Sprite.LIGHT_CHECK_BOX, gui.getMachine(), () -> popupElement.updateCheckBox("output", gui)));
checkBoxElement -> checkBoxElement.machineBase.fluidConfiguration.autoOutput()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
popupElement.updateCheckBox((CheckBoxElement) element, "output", gui13);
return true;
}));
setWidth(85);
setHeight(105 + (filter ? 15 : 0));
} }
@Override @Override
public void draw(DrawContext drawContext, GuiBase<?> gui) { public int getWidth() {
super.draw(drawContext, gui); return 85;
if (isHovering) { }
@Override
public int getHeight() {
return 105 + (filter ? 15 : 0);
}
@Override
public void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
super.draw(drawContext, gui, mouseX, mouseY);
if (isMouseWithinRect(gui, mouseX, mouseY)) {
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY()); drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY());
} }
elements.forEach(elementBase -> elementBase.draw(drawContext, gui)); elements.forEach(elementBase -> elementBase.draw(drawContext, gui, mouseX, mouseY));
} }
public SlotType getType() { public SlotType getType() {

View file

@ -62,55 +62,56 @@ public class ConfigSlotElement extends ElementBase {
.allMatch(BaseSlot::canWorldBlockInsert); .allMatch(BaseSlot::canWorldBlockInsert);
elements.add(popupElement = new SlotConfigPopupElement(this.id, x - 22, y - 22, this, inputEnabled)); elements.add(popupElement = new SlotConfigPopupElement(this.id, x - 22, y - 22, inputEnabled));
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON).addReleaseAction((element, gui1, provider, mouseX, mouseY) -> { elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON, () -> {
SlotConfigGui.selectedSlot = -1; SlotConfigGui.selectedSlot = -1;
gui.closeSelectedTab(); gui.closeSelectedTab();
return true;
})); }));
if (inputEnabled) { if (inputEnabled) {
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autoinput"), 0xFFFFFFFF, x - 26, y + 42, "input", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(), elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autoinput"), x - 26, y + 42,
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).autoInput()).addPressAction((element, gui12, provider, mouseX, mouseY) -> { checkBoxElement -> gui.getMachine().getSlotConfiguration().getSlotDetails(slotId).autoInput(),
popupElement.updateCheckBox((CheckBoxElement) element, "input", gui12); () -> popupElement.updateCheckBox("input", gui)));
return true;
}));
} }
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autooutput"), 0xFFFFFFFF, x - 26, y + 57, "output", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(), elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autooutput"), x - 26, y + 57,
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).autoOutput()).addPressAction((element, gui13, provider, mouseX, mouseY) -> { checkBoxElement -> gui.getMachine().getSlotConfiguration().getSlotDetails(slotId).autoOutput(),
popupElement.updateCheckBox((CheckBoxElement) element, "output", gui13); () -> popupElement.updateCheckBox("output", gui)));
return true;
}));
if (gui.getMachine() instanceof SlotConfiguration.SlotFilter slotFilter) { if (gui.getMachine() instanceof SlotConfiguration.SlotFilter slotFilter) {
if (Arrays.stream(slotFilter.getInputSlots()).anyMatch(value -> value == slotId)) { if (Arrays.stream(slotFilter.getInputSlots()).anyMatch(value -> value == slotId)) {
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.filter_input"), 0xFFFFFFFF, x - 26, y + 72, "filter", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(), elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.filter_input"), x - 26, y + 72,
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).filter()).addPressAction((element, gui13, provider, mouseX, mouseY) -> { checkBoxElement -> gui.getMachine().getSlotConfiguration().getSlotDetails(slotId).filter(),
popupElement.updateCheckBox((CheckBoxElement) element, "filter", gui13); () -> popupElement.updateCheckBox("filter", gui)));
return true;
}));
filter = true; filter = true;
popupElement.filter = true; popupElement.filter = true;
} }
} }
setWidth(85);
setHeight(105 + (filter ? 15 : 0));
} }
@Override @Override
public void draw(DrawContext drawContext, GuiBase<?> gui) { public int getWidth() {
super.draw(drawContext, gui); return 85;
}
@Override
public int getHeight() {
return 105 + (filter ? 15 : 0);
}
@Override
public void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
super.draw(drawContext, gui, mouseX, mouseY);
ItemStack stack = inventory.getStack(id); ItemStack stack = inventory.getStack(id);
int xPos = getX() + 1 + gui.getGuiLeft(); int xPos = getX() + 1 + gui.getGuiLeft();
int yPos = getY() + 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 (isMouseWithinRect(gui, mouseX, mouseY)) {
drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY()); drawSprite(drawContext, gui, type.getButtonHoverOverlay(), getX(), getY());
} }
elements.forEach(elementBase -> elementBase.draw(drawContext, gui)); elements.forEach(elementBase -> elementBase.draw(drawContext, gui, mouseX, mouseY));
} }
public SlotType getType() { public SlotType getType() {

View file

@ -32,54 +32,25 @@ import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity; import reborncore.common.blockentity.MachineBaseBlockEntity;
import java.util.ArrayList;
import java.util.List;
public class ElementBase { public class ElementBase {
private final int x; private final int x;
private final int y; private final int y;
public boolean isHovering = false; private Sprite sprite;
public boolean isPressing = false;
public boolean isReleasing = false;
public List<ElementBase.Action> pressActions = new ArrayList<>();
public List<ElementBase.Action> releaseActions = new ArrayList<>();
public SpriteContainer container;
private int width;
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, ISprite... sprites) { public ElementBase(int x, int y, Sprite sprite) {
this.container = new SpriteContainer(); this.sprite = sprite;
for (ISprite sprite : sprites) {
container.addSprite(sprite);
}
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
public SpriteContainer getSpriteContainer() { protected void setSprite(Sprite sprite) {
return container; this.sprite = sprite;
} }
public void adjustDimensions(MachineBaseBlockEntity provider) { public void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
if (container.offsetSprites != null) { drawSprite(drawContext, gui, sprite, x, y);
for (OffsetSprite offsetSprite : container.offsetSprites) {
if (offsetSprite.getSprite().getSprite(provider).width + offsetSprite.getOffsetX(provider) > this.width) {
this.width = offsetSprite.getSprite().getSprite(provider).width + offsetSprite.getOffsetX(provider);
}
if (offsetSprite.getSprite().getSprite(provider).height + offsetSprite.getOffsetY(provider) > this.height) {
this.height = offsetSprite.getSprite().getSprite(provider).height + offsetSprite.getOffsetY(provider);
}
}
}
}
public void draw(DrawContext drawContext, GuiBase<?> gui) {
for (OffsetSprite sprite : getSpriteContainer().offsetSprites) {
drawSprite(drawContext, gui, sprite.getSprite(), x + sprite.getOffsetX(gui.getMachine()), y + sprite.getOffsetY(gui.getMachine()));
}
} }
public int getX() { public int getX() {
@ -90,62 +61,16 @@ public class ElementBase {
return y; return y;
} }
public int getWidth(MachineBaseBlockEntity provider) {
adjustDimensions(provider);
return width;
}
public int getHeight(MachineBaseBlockEntity provider) {
adjustDimensions(provider);
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 sprite.width();
} }
public int getHeight() { public int getHeight() {
return height; return sprite.height();
} }
public ElementBase addPressAction(ElementBase.Action action) { public boolean onClick(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
this.pressActions.add(action); return false;
return this;
}
public ElementBase addReleaseAction(ElementBase.Action action) {
this.releaseActions.add(action);
return this;
}
public boolean onRelease(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
for (ElementBase.Action action : releaseActions) {
if (action.execute(this, gui, provider, mouseX, mouseY)) {
return true;
}
}
if (isPressing) {
for (ElementBase.Action action : pressActions) {
action.execute(this, gui, provider, mouseX, mouseY);
}
}
return !releaseActions.isEmpty() || !pressActions.isEmpty();
}
public interface Action {
boolean execute(ElementBase element, GuiBase<?> gui, MachineBaseBlockEntity provider, double mouseX, double mouseY);
}
public interface UpdateAction {
void update(GuiBase<?> gui, ElementBase element);
} }
public int adjustX(GuiBase<?> gui, int x) { public int adjustX(GuiBase<?> gui, int x) {
@ -156,7 +81,11 @@ public class ElementBase {
return gui.getGuiTop() + y; return gui.getGuiTop() + y;
} }
public boolean isInRect(GuiBase<?> gui, int x, int y, int xSize, int ySize, double mouseX, double mouseY) { public boolean isMouseWithinRect(GuiBase<?> gui, double mouseX, double mouseY) {
return isInRect(gui, getX(), getY(), getWidth(), getHeight(), mouseX, mouseY);
}
public static boolean isInRect(GuiBase<?> gui, int x, int y, int xSize, int ySize, double mouseX, double mouseY) {
return gui.isPointInRect(x + gui.getGuiLeft(), y + gui.getGuiTop(), xSize, ySize, mouseX, mouseY); return gui.isPointInRect(x + gui.getGuiLeft(), y + gui.getGuiTop(), xSize, ySize, mouseX, mouseY);
} }
@ -166,16 +95,8 @@ public class ElementBase {
drawContext.drawText(gui.getTextRenderer(), text, x, y, color, false); drawContext.drawText(gui.getTextRenderer(), text, x, y, color, false);
} }
public void drawSprite(DrawContext drawContext, GuiBase<?> gui, ISprite iSprite, int x, int y) { public void drawSprite(DrawContext drawContext, GuiBase<?> gui, Sprite sprite, int x, int y) {
Sprite sprite = iSprite.getSprite(gui.getMachine()); drawContext.drawTexture(sprite.textureLocation(), x + gui.getGuiLeft(), y + gui.getGuiTop(), sprite.x(), sprite.y(), sprite.width(), sprite.height());
if (sprite != null) {
if (sprite.hasTextureInfo()) {
drawContext.drawTexture(sprite.textureLocation, x + gui.getGuiLeft(), y + gui.getGuiTop(), sprite.x, sprite.y, sprite.width, sprite.height);
}
if (sprite.hasStack()) {
drawContext.drawItem(sprite.itemStack, x + gui.getGuiLeft(), y + gui.getGuiTop());
}
}
} }
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) {

View file

@ -53,7 +53,7 @@ public class FluidConfigPopupElement extends AbstractConfigPopupElement {
ClientNetworkManager.sendToServer(packetSave); ClientNetworkManager.sendToServer(packetSave);
} }
public void updateCheckBox(CheckBoxElement checkBoxElement, String type, GuiBase<?> guiBase) { public void updateCheckBox(String type, GuiBase<?> guiBase) {
FluidConfiguration configHolder = guiBase.getMachine().fluidConfiguration; FluidConfiguration configHolder = guiBase.getMachine().fluidConfiguration;
boolean input = configHolder.autoInput(); boolean input = configHolder.autoInput();
boolean output = configHolder.autoOutput(); boolean output = configHolder.autoOutput();

View file

@ -1,31 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.client.gui.builder.slot.elements;
import reborncore.common.blockentity.MachineBaseBlockEntity;
public interface ISprite {
Sprite getSprite(MachineBaseBlockEntity provider);
}

View file

@ -1,69 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.client.gui.builder.slot.elements;
import reborncore.common.blockentity.MachineBaseBlockEntity;
public class OffsetSprite {
public ISprite sprite;
public int offsetX = 0;
public int offsetY = 0;
public OffsetSprite(ISprite sprite, int offsetX, int offsetY) {
this.sprite = sprite;
this.offsetX = offsetX;
this.offsetY = offsetY;
}
public OffsetSprite(ISprite sprite) {
this.sprite = sprite;
}
public OffsetSprite(Sprite sprite, MachineBaseBlockEntity provider) {
this.sprite = sprite;
}
public ISprite getSprite() {
return sprite;
}
public int getOffsetX(MachineBaseBlockEntity provider) {
return offsetX + sprite.getSprite(provider).offsetX;
}
public OffsetSprite setOffsetX(int offsetX) {
this.offsetX = offsetX;
return this;
}
public int getOffsetY(MachineBaseBlockEntity provider) {
return offsetY + sprite.getSprite(provider).offsetY;
}
public OffsetSprite setOffsetY(int offsetY) {
this.offsetY = offsetY;
return this;
}
}

View file

@ -35,14 +35,12 @@ import reborncore.common.network.ServerBoundPackets;
import reborncore.common.util.Color; import reborncore.common.util.Color;
public class SlotConfigPopupElement extends AbstractConfigPopupElement { public class SlotConfigPopupElement extends AbstractConfigPopupElement {
int id; private final int id;
ConfigSlotElement slotElement; private final boolean allowInput;
boolean allowInput;
public SlotConfigPopupElement(int slotId, int x, int y, ConfigSlotElement slotElement, boolean allowInput) { public SlotConfigPopupElement(int slotId, int x, int y, boolean allowInput) {
super(x, y, Sprite.SLOT_CONFIG_POPUP); super(x, y, Sprite.SLOT_CONFIG_POPUP);
this.id = slotId; this.id = slotId;
this.slotElement = slotElement;
this.allowInput = allowInput; this.allowInput = allowInput;
} }
@ -62,7 +60,7 @@ public class SlotConfigPopupElement extends AbstractConfigPopupElement {
ClientNetworkManager.sendToServer(packetSlotSave); ClientNetworkManager.sendToServer(packetSlotSave);
} }
public void updateCheckBox(CheckBoxElement checkBoxElement, String type, GuiBase<?> guiBase) { public void updateCheckBox(String type, GuiBase<?> guiBase) {
SlotConfiguration.SlotConfigHolder configHolder = guiBase.getMachine().getSlotConfiguration().getSlotDetails(id); SlotConfiguration.SlotConfigHolder configHolder = guiBase.getMachine().getSlotConfiguration().getSlotDetails(id);
boolean input = configHolder.autoInput(); boolean input = configHolder.autoInput();
boolean output = configHolder.autoOutput(); boolean output = configHolder.autoOutput();

View file

@ -1,62 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.client.gui.builder.slot.elements;
import net.minecraft.inventory.Inventory;
public class SlotElement extends ElementBase {
protected Inventory slotInventory;
protected SlotType type;
int slotId, slotX, slotY;
public SlotElement(Inventory slotInventory, int slotId, int slotX, int slotY, SlotType type, int x, int y) {
super(x, y, type.getSprite());
this.type = type;
this.slotInventory = slotInventory;
this.slotId = slotId;
this.slotX = slotX;
this.slotY = slotY;
}
public SlotType getType() {
return type;
}
public Inventory getSlotInventory() {
return slotInventory;
}
public int getSlotId() {
return slotId;
}
public int getSlotX() {
return slotX;
}
public int getSlotY() {
return slotY;
}
}

View file

@ -41,20 +41,6 @@ public enum SlotType {
this.buttonHoverOverlay = buttonHoverOverlay; this.buttonHoverOverlay = buttonHoverOverlay;
} }
SlotType(int slotOffset, Sprite sprite) {
this.slotOffsetX = slotOffset;
this.slotOffsetY = slotOffset;
this.sprite = sprite;
}
public int getSlotOffsetX() {
return slotOffsetX;
}
public int getSlotOffsetY() {
return slotOffsetY;
}
public Sprite getSprite() { public Sprite getSprite() {
return sprite; return sprite;
} }

View file

@ -24,13 +24,9 @@
package reborncore.client.gui.builder.slot.elements; package reborncore.client.gui.builder.slot.elements;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import reborncore.common.blockentity.MachineBaseBlockEntity;
public class Sprite implements ISprite { public record Sprite(Identifier textureLocation, int x, int y, int width, int height) {
public static final Sprite EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 0, 0); public static final Sprite EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 0, 0);
public static final Sprite SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 18, 18); public static final Sprite SLOT_NORMAL = new Sprite(ElementBase.MECH_ELEMENTS, 0, 0, 18, 18);
public static final Sprite CHARGE_SLOT_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 18, 0, 18, 18); public static final Sprite CHARGE_SLOT_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 18, 0, 18, 18);
@ -42,9 +38,6 @@ public class Sprite implements ISprite {
public static final Sprite LEFT_TAB = new Sprite(ElementBase.MECH_ELEMENTS, 0, 86, 23, 26); public static final Sprite LEFT_TAB = new Sprite(ElementBase.MECH_ELEMENTS, 0, 86, 23, 26);
public static final Sprite LEFT_TAB_SELECTED = new Sprite(ElementBase.MECH_ELEMENTS, 0, 60, 29, 26); public static final Sprite LEFT_TAB_SELECTED = new Sprite(ElementBase.MECH_ELEMENTS, 0, 60, 29, 26);
public static final Sprite CONFIGURE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 18, 16, 16); public static final Sprite CONFIGURE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 18, 16, 16);
public static final Sprite REDSTONE_DISABLED_ICON = new Sprite(new ItemStack(Items.GUNPOWDER));
public static final Sprite REDSTONE_LOW_ICON = new Sprite(new ItemStack(Items.REDSTONE));
public static final Sprite REDSTONE_HIGH_ICON = new Sprite(new ItemStack(Blocks.REDSTONE_TORCH));
public static final Sprite UPGRADE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 34, 16, 16); public static final Sprite UPGRADE_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 26, 34, 16, 16);
public static final Sprite ENERGY_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 46, 19, 9, 13); public static final Sprite ENERGY_ICON = new Sprite(ElementBase.MECH_ELEMENTS, 46, 19, 9, 13);
public static final Sprite ENERGY_ICON_EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 62, 19, 9, 13); public static final Sprite ENERGY_ICON_EMPTY = new Sprite(ElementBase.MECH_ELEMENTS, 62, 19, 9, 13);
@ -57,65 +50,14 @@ public class Sprite implements ISprite {
public static final Sprite.CheckBox DARK_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 18, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 18, 16, 13)); public static final Sprite.CheckBox DARK_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 18, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 18, 16, 13));
public static final Sprite.CheckBox LIGHT_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 31, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 31, 16, 13)); public static final Sprite.CheckBox LIGHT_CHECK_BOX = new Sprite.CheckBox(new Sprite(ElementBase.MECH_ELEMENTS, 74, 31, 13, 13), new Sprite(ElementBase.MECH_ELEMENTS, 87, 31, 16, 13));
public final Identifier textureLocation; public Sprite {
public final int x; assert x >= 0 && y >= 0 && width >= 0 && height >= 0;
public final int y;
public final int width;
public final int height;
public int offsetX = 0;
public int offsetY = 0;
public ItemStack itemStack;
public Sprite(Identifier textureLocation, int x, int y, int width, int height) {
this.textureLocation = textureLocation;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.itemStack = null;
}
public Sprite(ItemStack stack) {
this.textureLocation = null;
this.x = -1;
this.y = -1;
this.width = -1;
this.height = -1;
this.itemStack = stack;
}
public boolean hasStack() {
return itemStack != null;
}
public boolean hasTextureInfo() {
return x >= 0 && y >= 0 && width >= 0 && height >= 0;
}
public Sprite setOffsetX(int offsetX) {
this.offsetX = offsetX;
return this;
}
public Sprite setOffsetY(int offsetY) {
this.offsetY = offsetY;
return this;
}
@Override
public Sprite getSprite(MachineBaseBlockEntity provider) {
return this;
} }
public record Button(Sprite normal, public record Button(Sprite normal,
Sprite hovered) { Sprite hovered) {
} }
public record ToggleButton(Sprite normal,
Sprite hovered,
Sprite pressed) {
}
public record CheckBox(Sprite normal, public record CheckBox(Sprite normal,
Sprite ticked) { Sprite ticked) {
} }

View file

@ -1,78 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.client.gui.builder.slot.elements;
import java.util.ArrayList;
import java.util.List;
public class SpriteContainer {
public List<OffsetSprite> offsetSprites = new ArrayList<>();
public SpriteContainer setSprite(int index, OffsetSprite sprite) {
offsetSprites.set(index, sprite);
return this;
}
public SpriteContainer setSprite(int index, ISprite sprite, int offsetX, int offsetY) {
if (sprite instanceof Sprite) {
offsetSprites.set(index, new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX + offsetX).setOffsetY(((Sprite) sprite).offsetY + offsetY));
} else {
offsetSprites.set(index, new OffsetSprite(sprite, offsetX, offsetY));
}
return this;
}
public SpriteContainer setSprite(int index, ISprite sprite) {
if (sprite instanceof Sprite) {
offsetSprites.set(index, new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX).setOffsetY(((Sprite) sprite).offsetY));
} else {
offsetSprites.add(index, new OffsetSprite(sprite));
}
return this;
}
public SpriteContainer addSprite(OffsetSprite sprite) {
offsetSprites.add(sprite);
return this;
}
public SpriteContainer addSprite(ISprite sprite, int offsetX, int offsetY) {
if (sprite instanceof Sprite) {
offsetSprites.add(new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX + offsetX).setOffsetY(((Sprite) sprite).offsetY + offsetY));
} else {
offsetSprites.add(new OffsetSprite(sprite, offsetX, offsetY));
}
return this;
}
public SpriteContainer addSprite(ISprite sprite) {
if (sprite instanceof Sprite) {
offsetSprites.add(new OffsetSprite(sprite).setOffsetX(((Sprite) sprite).offsetX).setOffsetY(((Sprite) sprite).offsetY));
} else {
offsetSprites.add(new OffsetSprite(sprite));
}
return this;
}
}

View file

@ -116,25 +116,6 @@ public class GuiBuilder {
drawContext.drawTexture(resourceLocation, x, y, 174, 0, 26, 26); drawContext.drawTexture(resourceLocation, x, y, 174, 0, 26, 26);
} }
/**
* Draws button with JEI icon in the given coords.
*
* @param gui {@link GuiBase} The GUI to draw on
* @param x {@code int} Top left corner where to place button
* @param y {@code int} Top left corner where to place button
* @param layer {@link GuiBase.Layer} The layer to draw on
*/
public void drawJEIButton(DrawContext drawContext, GuiBase<?> gui, int x, int y, GuiBase.Layer layer) {
if (gui.hideGuiElements()) return;
if (FabricLoader.getInstance().isModLoaded("jei")) {
if (layer == GuiBase.Layer.BACKGROUND) {
x += gui.getGuiLeft();
y += gui.getGuiTop();
}
drawContext.drawTexture(resourceLocation, x, y, 202, 0, 12, 12);
}
}
/** /**
* Draws lock button in either locked or unlocked state * Draws lock button in either locked or unlocked state
* *

View file

@ -51,8 +51,6 @@ public class GuiAlloySmelter extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 34, 47, layer); drawSlot(drawContext, 34, 47, layer);
drawSlot(drawContext, 126, 47, layer); drawSlot(drawContext, 126, 47, layer);
drawOutputSlot(drawContext, 80, 47, layer); drawOutputSlot(drawContext, 80, 47, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -53,8 +53,6 @@ public class GuiAssemblingMachine extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 55, 55, layer); drawSlot(drawContext, 55, 55, layer);
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -61,7 +61,6 @@ public class GuiBlastFurnace extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 50, 47, layer); drawSlot(drawContext, 50, 47, layer);
drawOutputSlotBar(drawContext, 92, 36, 2, layer); drawOutputSlotBar(drawContext, 92, 36, 2, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
if (hasMultiBlock) { if (hasMultiBlock) {
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
} }

View file

@ -54,8 +54,6 @@ public class GuiBlockBreaker extends GuiBase<BuiltScreenHandler> {
drawCentredText(drawContext, processor.getStatusEnum().getProgressText(processor.getProgress()), 40, processor.getStatusEnum().getColor(), layer); drawCentredText(drawContext, processor.getStatusEnum().getProgressText(processor.getProgress()), 40, processor.getStatusEnum().getColor(), layer);
drawOutputSlot(drawContext, 80, 60, layer); drawOutputSlot(drawContext, 80, 60, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -54,8 +54,6 @@ public class GuiBlockPlacer extends GuiBase<BuiltScreenHandler> {
drawCentredText(drawContext, processor.getStatusEnum().getProgressText(processor.getProgress()), 40, processor.getStatusEnum().getColor(), layer); drawCentredText(drawContext, processor.getStatusEnum().getProgressText(processor.getProgress()), 40, processor.getStatusEnum().getColor(), layer);
drawSlot(drawContext, 80, 60, layer); drawSlot(drawContext, 80, 60, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -54,8 +54,6 @@ public class GuiCentrifuge extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 101, 25, layer); drawSlot(drawContext, 101, 25, layer);
drawSlot(drawContext, 120, 44, layer); drawSlot(drawContext, 120, 44, layer);
drawSlot(drawContext, 101, 63, layer); drawSlot(drawContext, 101, 63, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -50,8 +50,6 @@ public class GuiChemicalReactor extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 34, 47, layer); drawSlot(drawContext, 34, 47, layer);
drawSlot(drawContext, 126, 47, layer); drawSlot(drawContext, 126, 47, layer);
drawOutputSlot(drawContext, 80, 47, layer); drawOutputSlot(drawContext, 80, 47, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -49,8 +49,6 @@ public class GuiCompressor extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 55, 45, layer); drawSlot(drawContext, 55, 45, layer);
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -46,7 +46,6 @@ public class GuiDieselGenerator extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
drawSlot(drawContext, 25, 35, layer); drawSlot(drawContext, 25, 35, layer);
drawSlot(drawContext, 25, 55, layer); drawSlot(drawContext, 25, 55, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }

View file

@ -52,8 +52,6 @@ public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 35, 47, layer); drawSlot(drawContext, 35, 47, layer);
// Four output slots // Four output slots
drawOutputSlotBar(drawContext, 78, 36, 4, layer); drawOutputSlotBar(drawContext, 78, 36, 4, layer);
// JEI Button
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -49,8 +49,6 @@ public class GuiElectricFurnace extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 55, 45, layer); drawSlot(drawContext, 55, 45, layer);
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -49,8 +49,6 @@ public class GuiExtractor extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 55, 45, layer); drawSlot(drawContext, 55, 45, layer);
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -56,8 +56,6 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 124, 35, layer); drawSlot(drawContext, 124, 35, layer);
// Liquid output slot // Liquid output slot
drawSlot(drawContext, 124, 55, layer); drawSlot(drawContext, 124, 55, layer);
// JEI button
builder.drawJEIButton(drawContext, this, 158, 5, layer);
if (blockEntity.isMultiblockValid()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
} }

View file

@ -71,7 +71,6 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 126, 47, layer); drawSlot(drawContext, 126, 47, layer);
drawOutputSlot(drawContext, 80, 47, layer); drawOutputSlot(drawContext, 80, 47, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
if (blockEntity.isMultiblockValid()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
} }

View file

@ -46,7 +46,6 @@ public class GuiGasTurbine extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
drawSlot(drawContext, 25, 35, layer); drawSlot(drawContext, 25, 35, layer);
drawSlot(drawContext, 25, 55, layer); drawSlot(drawContext, 25, 55, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }

View file

@ -45,10 +45,7 @@ public class GuiGenerator extends GuiBase<BuiltScreenHandler> {
final Layer layer = Layer.BACKGROUND; final Layer layer = Layer.BACKGROUND;
drawSlot(drawContext, 8, 72, layer); drawSlot(drawContext, 8, 72, layer);
drawSlot(drawContext, 80, 54, layer); drawSlot(drawContext, 80, 54, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -48,8 +48,6 @@ public class GuiGrinder extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 55, 45, layer); drawSlot(drawContext, 55, 45, layer);
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -56,8 +56,6 @@ public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
if (blockEntity.isMultiblockValid()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
} }
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -52,7 +52,6 @@ public class GuiIndustrialElectrolyzer extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 81, 72, layer); drawSlot(drawContext, 81, 72, layer);
//Output slots //Output slots
drawOutputSlotBar(drawContext, 50, 23, 4, layer); drawOutputSlotBar(drawContext, 50, 23, 4, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -60,7 +60,6 @@ public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 126, 54, layer); drawSlot(drawContext, 126, 54, layer);
drawSlot(drawContext, 126, 72, layer); drawSlot(drawContext, 126, 72, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
if (blockEntity.isMultiblockValid()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
} }

View file

@ -59,7 +59,6 @@ public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 126, 43, layer); drawSlot(drawContext, 126, 43, layer);
drawSlot(drawContext, 126, 61, layer); drawSlot(drawContext, 126, 61, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
if (blockEntity.isMultiblockValid()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
} }

View file

@ -49,7 +49,6 @@ public class GuiPlasmaGenerator extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
drawSlot(drawContext, 25, 35, layer); drawSlot(drawContext, 25, 35, layer);
drawSlot(drawContext, 25, 55, layer); drawSlot(drawContext, 25, 55, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }

View file

@ -61,7 +61,6 @@ public class GuiRollingMachine extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 8, 70, layer); drawSlot(drawContext, 8, 70, layer);
drawOutputSlot(drawContext, 124, gridYPos + 18, layer); drawOutputSlot(drawContext, 124, gridYPos + 18, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
builder.drawLockButton(drawContext, this, 130, 4, mouseX, mouseY, layer, rollingMachine.locked); builder.drawLockButton(drawContext, this, 130, 4, mouseX, mouseY, layer, rollingMachine.locked);
} }

View file

@ -51,8 +51,6 @@ public class GuiScrapboxinator extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 55, 45, layer); drawSlot(drawContext, 55, 45, layer);
// Output slot // Output slot
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -46,7 +46,6 @@ public class GuiSemifluidGenerator extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
drawSlot(drawContext, 25, 35, layer); drawSlot(drawContext, 25, 35, layer);
drawSlot(drawContext, 25, 55, layer); drawSlot(drawContext, 25, 55, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }

View file

@ -51,8 +51,6 @@ public class GuiSolidCanningMachine extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 34, 47, layer); drawSlot(drawContext, 34, 47, layer);
drawSlot(drawContext, 126, 47, layer); drawSlot(drawContext, 126, 47, layer);
drawOutputSlot(drawContext, 80, 47, layer); drawOutputSlot(drawContext, 80, 47, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override

View file

@ -46,7 +46,6 @@ public class GuiThermalGenerator extends GuiBase<BuiltScreenHandler> {
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
drawSlot(drawContext, 25, 35, layer); drawSlot(drawContext, 25, 35, layer);
drawSlot(drawContext, 25, 55, layer); drawSlot(drawContext, 25, 55, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }

View file

@ -54,7 +54,6 @@ public class GuiVacuumFreezer extends GuiBase<BuiltScreenHandler> {
// Output slot // Output slot
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
if (blockEntity.isMultiblockValid()) { if (blockEntity.isMultiblockValid()) {
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer); builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
} }

View file

@ -53,8 +53,6 @@ public class GuiWireMill extends GuiBase<BuiltScreenHandler> {
drawSlot(drawContext, 101, 45, layer); drawSlot(drawContext, 101, 45, layer);
drawOutputSlot(drawContext, 101, 45, layer); drawOutputSlot(drawContext, 101, 45, layer);
builder.drawJEIButton(drawContext, this, 158, 5, layer);
} }
@Override @Override