Gui cleanup
This commit is contained in:
parent
0171ef9778
commit
4ee192b4cd
48 changed files with 146 additions and 686 deletions
|
@ -75,7 +75,6 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
|
|||
.stack(guiTab -> wrenchStack)
|
||||
.draw(SlotConfigGui::draw)
|
||||
.click(SlotConfigGui::mouseClicked)
|
||||
.mouseReleased(SlotConfigGui::mouseReleased)
|
||||
.hideGuiElements()
|
||||
.keyPressed((guiBase, keyCode, scanCode, modifiers) -> {
|
||||
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))
|
||||
.draw(FluidConfigGui::draw)
|
||||
.click(FluidConfigGui::mouseClicked)
|
||||
.mouseReleased(FluidConfigGui::mouseReleased)
|
||||
.hideGuiElements()
|
||||
);
|
||||
|
||||
|
@ -324,17 +322,6 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
|
|||
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
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int state) {
|
||||
int offset = 0;
|
||||
|
@ -354,9 +341,6 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
|
|||
offset -= 24;
|
||||
}
|
||||
|
||||
if (getTab().map(guiTab -> guiTab.mouseReleased(mouseX, mouseY, state)).orElse(false)) {
|
||||
return true;
|
||||
}
|
||||
return super.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import reborncore.client.gui.builder.slot.elements.SlotType;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
// Why is this static?
|
||||
public class FluidConfigGui {
|
||||
|
||||
static ConfigFluidElement fluidConfigElement;
|
||||
|
@ -43,7 +44,7 @@ public class FluidConfigGui {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
@ -52,50 +53,17 @@ public class FluidConfigGui {
|
|||
|
||||
public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {
|
||||
if (mouseButton == 0) {
|
||||
for (ConfigFluidElement configFluidElement : getVisibleElements()) {
|
||||
for (ElementBase element : configFluidElement.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;
|
||||
}
|
||||
for (ConfigFluidElement configSlotElement : getVisibleElements()) {
|
||||
for (ElementBase element : Lists.reverse(configSlotElement.elements)) {
|
||||
if (element.isMouseWithinRect(guiBase, mouseX, mouseY)) {
|
||||
if (element.onClick(guiBase.getMachine(), guiBase, mouseX, mouseY)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
element.isPressing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,10 +71,6 @@ public class GuiTab {
|
|||
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) {
|
||||
return builder.keyPressed.keyPress(guiBase, keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
@ -101,7 +97,6 @@ public class GuiTab {
|
|||
private Draw draw = (matrixStack, gui, x, y) -> {
|
||||
};
|
||||
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 Consumer<List<String>> tips = strings -> {
|
||||
};
|
||||
|
@ -136,11 +131,6 @@ public class GuiTab {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder mouseReleased(MouseReleased mouseReleased) {
|
||||
this.mouseReleased = mouseReleased;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keyPressed(KeyPressed keyPressed) {
|
||||
this.keyPressed = keyPressed;
|
||||
return this;
|
||||
|
@ -169,10 +159,6 @@ public class GuiTab {
|
|||
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 {
|
||||
boolean keyPress(GuiBase<?> guiBase, int keyCode, int scanCode, int modifiers);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// Why is all this static?
|
||||
public class SlotConfigGui {
|
||||
|
||||
public static HashMap<Integer, ConfigSlotElement> slotElementMap = new HashMap<>();
|
||||
|
@ -84,7 +85,7 @@ public class SlotConfigGui {
|
|||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
|
||||
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) {
|
||||
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)) {
|
||||
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 (element.isMouseWithinRect(guiBase, mouseX, mouseY)) {
|
||||
if (element.onClick(guiBase.getMachine(), guiBase, mouseX, mouseY)) {
|
||||
return true;
|
||||
}
|
||||
if (action) {
|
||||
clicked = true;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
element.isReleasing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return clicked;
|
||||
}
|
||||
|
||||
return !getVisibleElements().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,14 +44,14 @@ import reborncore.common.util.MachineFacing;
|
|||
public abstract class AbstractConfigPopupElement extends ElementBase {
|
||||
public boolean filter = false;
|
||||
|
||||
public AbstractConfigPopupElement(int x, int y, ISprite... sprites) {
|
||||
super(x, y, sprites);
|
||||
public AbstractConfigPopupElement(int x, int y, Sprite sprite) {
|
||||
super(x, y, sprite);
|
||||
}
|
||||
|
||||
@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));
|
||||
super.draw(drawContext, gui);
|
||||
super.draw(drawContext, gui, mouseX, mouseY);
|
||||
|
||||
final MachineBaseBlockEntity machine = ((MachineBaseBlockEntity) gui.be);
|
||||
final BlockState state = machine.getCachedState();
|
||||
|
@ -75,23 +75,28 @@ public abstract class AbstractConfigPopupElement extends ElementBase {
|
|||
}
|
||||
|
||||
@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)) {
|
||||
cycleConfig(MachineFacing.UP.getFacing(provider), gui);
|
||||
return true;
|
||||
} else if (isInBox(23, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.FRONT.getFacing(provider), gui);
|
||||
return true;
|
||||
} else if (isInBox(42, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.RIGHT.getFacing(provider), gui);
|
||||
return true;
|
||||
} else if (isInBox(4, 23, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.LEFT.getFacing(provider), gui);
|
||||
return true;
|
||||
} else if (isInBox(23, 42, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.DOWN.getFacing(provider), gui);
|
||||
return true;
|
||||
} else if (isInBox(42, 42, 16, 16, mouseX, mouseY, gui)) {
|
||||
cycleConfig(MachineFacing.BACK.getFacing(provider), gui);
|
||||
} else {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract void cycleConfig(Direction side, GuiBase<?> guiBase);
|
||||
|
|
|
@ -24,20 +24,29 @@
|
|||
|
||||
package reborncore.client.gui.builder.slot.elements;
|
||||
|
||||
public class ButtonElement extends ElementBase {
|
||||
@SuppressWarnings("unused")
|
||||
private final Sprite.Button buttonSprite;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import reborncore.client.gui.builder.GuiBase;
|
||||
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());
|
||||
this.buttonSprite = buttonSprite;
|
||||
// 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());
|
||||
// }
|
||||
// });
|
||||
this.onClicked = onClicked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,47 +32,45 @@ import reborncore.common.blockentity.MachineBaseBlockEntity;
|
|||
import java.util.function.Predicate;
|
||||
|
||||
public class CheckBoxElement extends ElementBase {
|
||||
public Text label;
|
||||
public String type;
|
||||
public int labelColor, slotID;
|
||||
public MachineBaseBlockEntity machineBase;
|
||||
Predicate<CheckBoxElement> ticked;
|
||||
|
||||
private final Text label;
|
||||
private final Predicate<CheckBoxElement> ticked;
|
||||
private final Runnable onChange;
|
||||
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) {
|
||||
super(x, y, checkBoxSprite.normal());
|
||||
this.checkBoxSprite = checkBoxSprite;
|
||||
this.type = type;
|
||||
this.slotID = slotID;
|
||||
this.machineBase = machineBase;
|
||||
public CheckBoxElement(Text label, int x, int y,
|
||||
Predicate<CheckBoxElement> ticked,
|
||||
Runnable onChange) {
|
||||
super(x, y, Sprite.LIGHT_CHECK_BOX.normal());
|
||||
this.checkBoxSprite = Sprite.LIGHT_CHECK_BOX;
|
||||
this.label = label;
|
||||
this.labelColor = labelColor;
|
||||
this.ticked = ticked;
|
||||
this.onChange = onChange;
|
||||
updateSprites();
|
||||
}
|
||||
|
||||
private void updateSprites() {
|
||||
if (ticked.test(this)) {
|
||||
container.setSprite(0, checkBoxSprite.ticked());
|
||||
setSprite(checkBoxSprite.ticked());
|
||||
} 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
|
||||
public void draw(DrawContext drawContext, GuiBase<?> gui) {
|
||||
// super.draw(gui);
|
||||
ISprite sprite = checkBoxSprite.normal();
|
||||
public boolean onClick(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
onChange.run();
|
||||
updateSprites();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
|
||||
Sprite sprite = checkBoxSprite.normal();
|
||||
if (ticked.test(this)) {
|
||||
sprite = checkBoxSprite.ticked();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,33 +46,33 @@ public class ConfigFluidElement extends ElementBase {
|
|||
FluidConfigPopupElement popupElement;
|
||||
|
||||
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) -> {
|
||||
gui.closeSelectedTab();
|
||||
return true;
|
||||
}));
|
||||
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON, gui::closeSelectedTab));
|
||||
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pullin"), 0xFFFFFFFF, x - 26, y + 42, "input", 0, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.fluidConfiguration.autoInput()).addPressAction((element, gui12, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "input", gui12);
|
||||
return true;
|
||||
}));
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pumpout"), 0xFFFFFFFF, x - 26, y + 57, "output", 0, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
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));
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pullin"), x - 26, y + 42,
|
||||
checkBoxElement -> gui.getMachine().fluidConfiguration.autoInput(),
|
||||
() -> popupElement.updateCheckBox("input", gui)));
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.fluidconfig.pumpout"), x - 26, y + 57,
|
||||
checkBoxElement -> gui.getMachine().fluidConfiguration.autoOutput(),
|
||||
() -> popupElement.updateCheckBox("output", gui)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(DrawContext drawContext, GuiBase<?> gui) {
|
||||
super.draw(drawContext, gui);
|
||||
if (isHovering) {
|
||||
public int getWidth() {
|
||||
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);
|
||||
if (isMouseWithinRect(gui, mouseX, mouseY)) {
|
||||
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() {
|
||||
|
|
|
@ -62,55 +62,56 @@ public class ConfigSlotElement extends ElementBase {
|
|||
.allMatch(BaseSlot::canWorldBlockInsert);
|
||||
|
||||
|
||||
elements.add(popupElement = new SlotConfigPopupElement(this.id, x - 22, y - 22, this, inputEnabled));
|
||||
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON).addReleaseAction((element, gui1, provider, mouseX, mouseY) -> {
|
||||
elements.add(popupElement = new SlotConfigPopupElement(this.id, x - 22, y - 22, inputEnabled));
|
||||
elements.add(new ButtonElement(x + 37, y - 25, Sprite.EXIT_BUTTON, () -> {
|
||||
SlotConfigGui.selectedSlot = -1;
|
||||
gui.closeSelectedTab();
|
||||
return true;
|
||||
}));
|
||||
|
||||
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(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).autoInput()).addPressAction((element, gui12, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "input", gui12);
|
||||
return true;
|
||||
}));
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autoinput"), x - 26, y + 42,
|
||||
checkBoxElement -> gui.getMachine().getSlotConfiguration().getSlotDetails(slotId).autoInput(),
|
||||
() -> popupElement.updateCheckBox("input", gui)));
|
||||
}
|
||||
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autooutput"), 0xFFFFFFFF, x - 26, y + 57, "output", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).autoOutput()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "output", gui13);
|
||||
return true;
|
||||
}));
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.autooutput"), x - 26, y + 57,
|
||||
checkBoxElement -> gui.getMachine().getSlotConfiguration().getSlotDetails(slotId).autoOutput(),
|
||||
() -> popupElement.updateCheckBox("output", gui)));
|
||||
|
||||
if (gui.getMachine() instanceof SlotConfiguration.SlotFilter slotFilter) {
|
||||
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(),
|
||||
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).filter()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {
|
||||
popupElement.updateCheckBox((CheckBoxElement) element, "filter", gui13);
|
||||
return true;
|
||||
}));
|
||||
elements.add(new CheckBoxElement(Text.translatable("reborncore.gui.slotconfig.filter_input"), x - 26, y + 72,
|
||||
checkBoxElement -> gui.getMachine().getSlotConfiguration().getSlotDetails(slotId).filter(),
|
||||
() -> popupElement.updateCheckBox("filter", gui)));
|
||||
filter = true;
|
||||
popupElement.filter = true;
|
||||
}
|
||||
}
|
||||
setWidth(85);
|
||||
setHeight(105 + (filter ? 15 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(DrawContext drawContext, GuiBase<?> gui) {
|
||||
super.draw(drawContext, gui);
|
||||
public int getWidth() {
|
||||
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);
|
||||
int xPos = getX() + 1 + gui.getGuiLeft();
|
||||
int yPos = getY() + 1 + gui.getGuiTop();
|
||||
|
||||
drawContext.drawItemInSlot(gui.getTextRenderer(), stack, xPos, yPos);
|
||||
|
||||
if (isHovering) {
|
||||
if (isMouseWithinRect(gui, mouseX, mouseY)) {
|
||||
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() {
|
||||
|
|
|
@ -32,54 +32,25 @@ import reborncore.client.gui.builder.GuiBase;
|
|||
import reborncore.client.gui.guibuilder.GuiBuilder;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ElementBase {
|
||||
private final int x;
|
||||
private final int y;
|
||||
public boolean isHovering = false;
|
||||
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;
|
||||
private Sprite sprite;
|
||||
|
||||
public static final Identifier MECH_ELEMENTS = new Identifier("reborncore", "textures/gui/elements.png");
|
||||
|
||||
public ElementBase(int x, int y, ISprite... sprites) {
|
||||
this.container = new SpriteContainer();
|
||||
for (ISprite sprite : sprites) {
|
||||
container.addSprite(sprite);
|
||||
}
|
||||
public ElementBase(int x, int y, Sprite sprite) {
|
||||
this.sprite = sprite;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public SpriteContainer getSpriteContainer() {
|
||||
return container;
|
||||
protected void setSprite(Sprite sprite) {
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public void adjustDimensions(MachineBaseBlockEntity provider) {
|
||||
if (container.offsetSprites != null) {
|
||||
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 void draw(DrawContext drawContext, GuiBase<?> gui, int mouseX, int mouseY) {
|
||||
drawSprite(drawContext, gui, sprite, x, y);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
|
@ -90,62 +61,16 @@ public class ElementBase {
|
|||
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() {
|
||||
return width;
|
||||
return sprite.width();
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
return sprite.height();
|
||||
}
|
||||
|
||||
public ElementBase addPressAction(ElementBase.Action action) {
|
||||
this.pressActions.add(action);
|
||||
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 boolean onClick(MachineBaseBlockEntity provider, GuiBase<?> gui, double mouseX, double mouseY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int adjustX(GuiBase<?> gui, int x) {
|
||||
|
@ -156,7 +81,11 @@ public class ElementBase {
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -166,16 +95,8 @@ public class ElementBase {
|
|||
drawContext.drawText(gui.getTextRenderer(), text, x, y, color, false);
|
||||
}
|
||||
|
||||
public void drawSprite(DrawContext drawContext, GuiBase<?> gui, ISprite iSprite, int x, int y) {
|
||||
Sprite sprite = iSprite.getSprite(gui.getMachine());
|
||||
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 drawSprite(DrawContext drawContext, GuiBase<?> gui, Sprite sprite, int x, int y) {
|
||||
drawContext.drawTexture(sprite.textureLocation(), x + gui.getGuiLeft(), y + gui.getGuiTop(), sprite.x(), sprite.y(), sprite.width(), sprite.height());
|
||||
}
|
||||
|
||||
public void drawDefaultBackground(DrawContext drawContext, Screen gui, int x, int y, int width, int height) {
|
||||
|
|
|
@ -53,7 +53,7 @@ public class FluidConfigPopupElement extends AbstractConfigPopupElement {
|
|||
ClientNetworkManager.sendToServer(packetSave);
|
||||
}
|
||||
|
||||
public void updateCheckBox(CheckBoxElement checkBoxElement, String type, GuiBase<?> guiBase) {
|
||||
public void updateCheckBox(String type, GuiBase<?> guiBase) {
|
||||
FluidConfiguration configHolder = guiBase.getMachine().fluidConfiguration;
|
||||
boolean input = configHolder.autoInput();
|
||||
boolean output = configHolder.autoOutput();
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -35,14 +35,12 @@ import reborncore.common.network.ServerBoundPackets;
|
|||
import reborncore.common.util.Color;
|
||||
|
||||
public class SlotConfigPopupElement extends AbstractConfigPopupElement {
|
||||
int id;
|
||||
ConfigSlotElement slotElement;
|
||||
boolean allowInput;
|
||||
private final int id;
|
||||
private final 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);
|
||||
this.id = slotId;
|
||||
this.slotElement = slotElement;
|
||||
this.allowInput = allowInput;
|
||||
}
|
||||
|
||||
|
@ -62,7 +60,7 @@ public class SlotConfigPopupElement extends AbstractConfigPopupElement {
|
|||
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);
|
||||
boolean input = configHolder.autoInput();
|
||||
boolean output = configHolder.autoOutput();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -41,20 +41,6 @@ public enum SlotType {
|
|||
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() {
|
||||
return sprite;
|
||||
}
|
||||
|
|
|
@ -24,13 +24,9 @@
|
|||
|
||||
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 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 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);
|
||||
|
@ -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_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 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 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);
|
||||
|
@ -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 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 final int x;
|
||||
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 Sprite {
|
||||
assert x >= 0 && y >= 0 && width >= 0 && height >= 0;
|
||||
}
|
||||
|
||||
public record Button(Sprite normal,
|
||||
Sprite hovered) {
|
||||
}
|
||||
|
||||
public record ToggleButton(Sprite normal,
|
||||
Sprite hovered,
|
||||
Sprite pressed) {
|
||||
}
|
||||
|
||||
public record CheckBox(Sprite normal,
|
||||
Sprite ticked) {
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -116,25 +116,6 @@ public class GuiBuilder {
|
|||
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
|
||||
*
|
||||
|
|
|
@ -51,8 +51,6 @@ public class GuiAlloySmelter extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 34, 47, layer);
|
||||
drawSlot(drawContext, 126, 47, layer);
|
||||
drawOutputSlot(drawContext, 80, 47, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -53,8 +53,6 @@ public class GuiAssemblingMachine extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 55, 55, layer);
|
||||
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -61,7 +61,6 @@ public class GuiBlastFurnace extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 50, 47, layer);
|
||||
drawOutputSlotBar(drawContext, 92, 36, 2, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
if (hasMultiBlock) {
|
||||
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
|
||||
}
|
||||
|
|
|
@ -54,8 +54,6 @@ public class GuiBlockBreaker extends GuiBase<BuiltScreenHandler> {
|
|||
drawCentredText(drawContext, processor.getStatusEnum().getProgressText(processor.getProgress()), 40, processor.getStatusEnum().getColor(), layer);
|
||||
|
||||
drawOutputSlot(drawContext, 80, 60, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,8 +54,6 @@ public class GuiBlockPlacer extends GuiBase<BuiltScreenHandler> {
|
|||
drawCentredText(drawContext, processor.getStatusEnum().getProgressText(processor.getProgress()), 40, processor.getStatusEnum().getColor(), layer);
|
||||
|
||||
drawSlot(drawContext, 80, 60, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,8 +54,6 @@ public class GuiCentrifuge extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 101, 25, layer);
|
||||
drawSlot(drawContext, 120, 44, layer);
|
||||
drawSlot(drawContext, 101, 63, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,8 +50,6 @@ public class GuiChemicalReactor extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 34, 47, layer);
|
||||
drawSlot(drawContext, 126, 47, layer);
|
||||
drawOutputSlot(drawContext, 80, 47, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,8 +49,6 @@ public class GuiCompressor extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
drawSlot(drawContext, 55, 45, layer);
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,6 @@ public class GuiDieselGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||
drawSlot(drawContext, 25, 35, layer);
|
||||
drawSlot(drawContext, 25, 55, layer);
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,8 +52,6 @@ public class GuiDistillationTower extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 35, 47, layer);
|
||||
// Four output slots
|
||||
drawOutputSlotBar(drawContext, 78, 36, 4, layer);
|
||||
// JEI Button
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,8 +49,6 @@ public class GuiElectricFurnace extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
drawSlot(drawContext, 55, 45, layer);
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,8 +49,6 @@ public class GuiExtractor extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
drawSlot(drawContext, 55, 45, layer);
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,8 +56,6 @@ public class GuiFluidReplicator extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 124, 35, layer);
|
||||
// Liquid output slot
|
||||
drawSlot(drawContext, 124, 55, layer);
|
||||
// JEI button
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 126, 47, layer);
|
||||
drawOutputSlot(drawContext, 80, 47, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ public class GuiGasTurbine extends GuiBase<BuiltScreenHandler> {
|
|||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||
drawSlot(drawContext, 25, 35, layer);
|
||||
drawSlot(drawContext, 25, 55, layer);
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,10 +45,7 @@ public class GuiGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
final Layer layer = Layer.BACKGROUND;
|
||||
|
||||
drawSlot(drawContext, 8, 72, layer);
|
||||
|
||||
drawSlot(drawContext, 80, 54, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,8 +48,6 @@ public class GuiGrinder extends GuiBase<BuiltScreenHandler> {
|
|||
|
||||
drawSlot(drawContext, 55, 45, layer);
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,8 +56,6 @@ public class GuiImplosionCompressor extends GuiBase<BuiltScreenHandler> {
|
|||
if (blockEntity.isMultiblockValid()) {
|
||||
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
|
||||
}
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,7 +52,6 @@ public class GuiIndustrialElectrolyzer extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 81, 72, layer);
|
||||
//Output slots
|
||||
drawOutputSlotBar(drawContext, 50, 23, 4, layer);
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,7 +60,6 @@ public class GuiIndustrialGrinder extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 126, 54, layer);
|
||||
drawSlot(drawContext, 126, 72, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ public class GuiIndustrialSawmill extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 126, 43, layer);
|
||||
drawSlot(drawContext, 126, 61, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ public class GuiPlasmaGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||
drawSlot(drawContext, 25, 35, layer);
|
||||
drawSlot(drawContext, 25, 55, layer);
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@ public class GuiRollingMachine extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 8, 70, 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,8 +51,6 @@ public class GuiScrapboxinator extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 55, 45, layer);
|
||||
// Output slot
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,6 @@ public class GuiSemifluidGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||
drawSlot(drawContext, 25, 35, layer);
|
||||
drawSlot(drawContext, 25, 55, layer);
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,8 +51,6 @@ public class GuiSolidCanningMachine extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 34, 47, layer);
|
||||
drawSlot(drawContext, 126, 47, layer);
|
||||
drawOutputSlot(drawContext, 80, 47, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,6 @@ public class GuiThermalGenerator extends GuiBase<BuiltScreenHandler> {
|
|||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||
drawSlot(drawContext, 25, 35, layer);
|
||||
drawSlot(drawContext, 25, 55, layer);
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ public class GuiVacuumFreezer extends GuiBase<BuiltScreenHandler> {
|
|||
// Output slot
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
if (blockEntity.isMultiblockValid()) {
|
||||
builder.drawHologramButton(drawContext, this, 6, 4, mouseX, mouseY, layer);
|
||||
}
|
||||
|
|
|
@ -53,8 +53,6 @@ public class GuiWireMill extends GuiBase<BuiltScreenHandler> {
|
|||
drawSlot(drawContext, 101, 45, layer);
|
||||
|
||||
drawOutputSlot(drawContext, 101, 45, layer);
|
||||
|
||||
builder.drawJEIButton(drawContext, this, 158, 5, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue