Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -3629,6 +3629,7 @@
"gtceu.universal.tooltip.working_area_max": "%dx%dɟ§ :ɐǝɹⱯ buıʞɹoM xɐWq§",
"gtceu.vacuum_freezer": "ɹǝzǝǝɹℲ ɯnnɔɐΛ",
"gtceu.wiremill": "ןןıɯǝɹıM",
"gui.gtceu.ae.amount": "ʇunoɯⱯ",
"gui.gtceu.refund_all.desc": "ᄅƎⱯ oʇ sʇuǝʇuoƆ pǝɹoʇS uɹnʇǝᴚ",
"gui.gtceu.rename.desc": "ɹǝɟɟnᗺ uɹǝʇʇɐԀ ǝɯɐuǝᴚ",
"gui.gtceu.share_inventory.desc.0": "¡ɹǝɟɟnq uıɥʇıʍ suɹǝʇʇɐd ןןɐ ɥʇıʍ sɯǝʇı pǝʇɹǝsuı sǝɹɐɥS",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3629,6 +3629,7 @@
"gtceu.universal.tooltip.working_area_max": "§bMax Working Area: §f%dx%d",
"gtceu.vacuum_freezer": "Vacuum Freezer",
"gtceu.wiremill": "Wiremill",
"gui.gtceu.ae.amount": "Amount",
"gui.gtceu.refund_all.desc": "Return Stored Contents to AE2",
"gui.gtceu.rename.desc": "Rename Pattern Buffer",
"gui.gtceu.share_inventory.desc.0": "Shares inserted items with all patterns within buffer!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ protected static void init(RegistrateLangProvider provider) {
"Shares inserted fluids/gasses/etc. with all patterns within buffer!");
provider.add("gui.gtceu.rename.desc", "Rename Pattern Buffer");
provider.add("gui.gtceu.refund_all.desc", "Return Stored Contents to AE2");
provider.add("gui.gtceu.ae.amount", "Amount");

provider.add("gtceu.machine.dual_hatch.import.tooltip", "Item and Fluid Input for Multiblocks");
provider.add("gtceu.machine.dual_hatch.export.tooltip", "Item and Fluid Output for Multiblocks");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
package com.gregtechceu.gtceu.integration.ae2.gui.widget;

import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.widget.LongInputWidget;
import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot;

import com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget;
import com.lowdragmc.lowdraglib.gui.widget.Widget;
import com.lowdragmc.lowdraglib.utils.Position;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import appeng.api.stacks.GenericStack;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import static com.lowdragmc.lowdraglib.gui.util.DrawerHelper.drawStringSized;

public class AmountSetWidget extends Widget {

private int index = -1;
@Getter
private final TextFieldWidget amountText;
private final LongInputWidget amountText;
private final ConfigWidget parentWidget;

public AmountSetWidget(int x, int y, ConfigWidget widget) {
super(x, y, 80, 30);
this.parentWidget = widget;
this.amountText = new TextFieldWidget(x + 3, y + 12, 65, 13, this::getAmountStr, this::setNewAmount)
.setNumbersOnly(0, Integer.MAX_VALUE)
.setMaxStringLength(10);
this.amountText = new LongInputWidget(x, y, 105, 11, this::getAmount, this::setAmount);
amountText.setMin(0L);
}

@OnlyIn(Dist.CLIENT)
Expand All @@ -43,28 +36,25 @@ public void setSlotIndex(int slotIndex) {
this.index = slotIndex;
}

public String getAmountStr() {
if (this.index < 0) {
return "0";
public long getAmount() {
if (index < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very tiny nitpick, either use this.index both here and in setAmount, or just index in both <3

return 0;
}
IConfigurableSlot slot = this.parentWidget.getConfig(this.index);
if (slot.getConfig() != null) {
return String.valueOf(slot.getConfig().amount());
return slot.getConfig().amount();
}
return "0";
return 0;
}

public void setNewAmount(String amount) {
try {
long newAmount = Long.parseLong(amount);
if (this.index < 0) {
return;
}
IConfigurableSlot slot = this.parentWidget.getConfig(this.index);
if (newAmount > 0 && slot.getConfig() != null) {
slot.setConfig(new GenericStack(slot.getConfig().what(), newAmount));
}
} catch (NumberFormatException ignore) {}
public void setAmount(long amount) {
if (this.index < 0) {
return;
}
IConfigurableSlot slot = this.parentWidget.getConfig(this.index);
if (amount > 0 && slot.getConfig() != null) {
slot.setConfig(new GenericStack(slot.getConfig().what(), amount));
}
}

@Override
Expand All @@ -74,14 +64,4 @@ public void handleClientAction(int id, FriendlyByteBuf buffer) {
this.index = buffer.readVarInt();
}
}

@OnlyIn(Dist.CLIENT)
@Override
public void drawInBackground(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
super.drawInBackground(graphics, mouseX, mouseY, partialTicks);
Position position = getPosition();
GuiTextures.BACKGROUND.draw(graphics, mouseX, mouseY, position.x, position.y, 80, 30);
drawStringSized(graphics, "Amount", position.x + 3, position.y + 3, 0x404040, false, 1f, false);
GuiTextures.DISPLAY.draw(graphics, mouseX, mouseY, position.x + 3, position.y + 11, 65, 14);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.gregtechceu.gtceu.integration.ae2.gui.widget;

import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.integration.ae2.gui.widget.slot.AEConfigSlotWidget;
import com.gregtechceu.gtceu.integration.ae2.slot.IConfigurableSlot;

import com.lowdragmc.lowdraglib.gui.widget.ImageWidget;
import com.lowdragmc.lowdraglib.gui.widget.LabelWidget;
import com.lowdragmc.lowdraglib.gui.widget.Widget;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import com.lowdragmc.lowdraglib.utils.Position;
Expand All @@ -17,13 +20,17 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;

import java.awt.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hold up, what AWT class did you import? we can't use those because JREs don't have AWT by default


public abstract class ConfigWidget extends WidgetGroup {

protected final IConfigurableSlot[] config;
protected IConfigurableSlot[] cached;
protected Int2ObjectMap<IConfigurableSlot> changeMap = new Int2ObjectOpenHashMap<>();
protected IConfigurableSlot[] displayList;
protected AmountSetWidget amountSetWidget;
protected LabelWidget titleWidget;
protected ImageWidget backgroundImage;
protected final static int UPDATE_ID = 1000;

@Getter
Expand All @@ -33,45 +40,60 @@ public ConfigWidget(int x, int y, IConfigurableSlot[] config, boolean isStocking
super(new Position(x, y), new Size(config.length / 2 * 18, 18 * 4 + 2));
this.isStocking = isStocking;
this.config = config;
this.init();
this.amountSetWidget = new AmountSetWidget(31, -50, this);
this.addWidget(this.amountSetWidget);
this.addWidget(this.amountSetWidget.getAmountText());
this.amountSetWidget.setVisible(false);
this.amountSetWidget.getAmountText().setVisible(false);
init();
var asw = new AmountSetWidget(15, -53, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just do this.amountSetWidget = ... here?

titleWidget = new LabelWidget(15, -65, "gui.gtceu.ae.amount").setTextColor(0x404040).setDropShadow(false);
backgroundImage = new ImageWidget(12, -68, 112, 40, GuiTextures.BACKGROUND);
addWidget(backgroundImage);
addWidget(titleWidget);
addWidget(asw);
addWidget(asw.getAmountText());
asw.setVisible(false);
asw.getAmountText().setVisible(false);
titleWidget.setVisible(false);
backgroundImage.setVisible(false);
amountSetWidget = asw;
}

@OnlyIn(Dist.CLIENT)
public void enableAmountClient(int slotIndex) {
this.amountSetWidget.setSlotIndexClient(slotIndex);
this.amountSetWidget.setVisible(true);
this.amountSetWidget.getAmountText().setVisible(true);
amountSetWidget.setSlotIndexClient(slotIndex);
amountSetWidget.setVisible(true);
amountSetWidget.getAmountText().setVisible(true);
Comment on lines +60 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the this. from all of these?

titleWidget.setVisible(true);
backgroundImage.setVisible(true);
}

@OnlyIn(Dist.CLIENT)
public void disableAmountClient() {
this.amountSetWidget.setSlotIndexClient(-1);
this.amountSetWidget.setVisible(false);
this.amountSetWidget.getAmountText().setVisible(false);
amountSetWidget.setSlotIndexClient(-1);
amountSetWidget.setVisible(false);
amountSetWidget.getAmountText().setVisible(false);
titleWidget.setVisible(false);
backgroundImage.setVisible(false);
}

public void enableAmount(int slotIndex) {
this.amountSetWidget.setSlotIndex(slotIndex);
this.amountSetWidget.setVisible(true);
this.amountSetWidget.getAmountText().setVisible(true);
amountSetWidget.setSlotIndex(slotIndex);
amountSetWidget.setVisible(true);
amountSetWidget.getAmountText().setVisible(true);
titleWidget.setVisible(true);
backgroundImage.setVisible(true);
}

public void disableAmount() {
this.amountSetWidget.setSlotIndex(-1);
this.amountSetWidget.setVisible(false);
this.amountSetWidget.getAmountText().setVisible(false);
amountSetWidget.setSlotIndex(-1);
amountSetWidget.setVisible(false);
amountSetWidget.getAmountText().setVisible(false);
titleWidget.setVisible(false);
backgroundImage.setVisible(false);
}

@OnlyIn(Dist.CLIENT)
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.amountSetWidget.isVisible()) {
if (this.amountSetWidget.getAmountText().mouseClicked(mouseX, mouseY, button)) {
if (amountSetWidget.isVisible()) {
if (amountSetWidget.getAmountText().mouseClicked(mouseX, mouseY, button)) {
return true;
}
}
Expand Down