This commit is contained in:
asdflj committed 2022-11-05 15:34:36 +08:00
1 parent fd6eb37369
commit ce1ac164dc
26 files changed
+912 -43

No files matched your search

@@ -6,12 +6,15 @@ import net.minecraft.client.gui.GuiTextField;
public class FCGuiTextField extends GuiTextField {
private static final int PADDING = 2;
private final FontRenderer _fontRender;
private String tooltip;
private final int _xPos;
private final int _yPos;
private final int _width;
private final int _height;
private int _border;
private int _color;
/**
* Uses the values to instantiate a padded version of a text field.
@@ -30,6 +33,48 @@ public class FCGuiTextField extends GuiTextField {
this._yPos = yPos;
this._width = width;
this._height = height;
this._fontRender = fontRenderer;
}
@Override
public void drawTextBox() {
super.drawTextBox();
if (this.getBorder() > 0 && this.getVisible()) {
GuiTextField.drawRect(
this._xPos - this.getBorder(),
this._yPos - this.getBorder(),
this._width - 2 * PADDING - this._fontRender.getCharWidth('_') + this.getBorder(),
this._height - 2 * PADDING + this.getBorder(),
this.getColor()
);
}
}
public int getBorder() {
return this._border;
}
public void setBorder(int border) {
this._border = border;
this._color = 0;
}
public void setBorder(int border, int color) {
this._border = border;
this._color = color;
}
public void setBorder() {
this._border = 0;
this._color = 0;
}
public int getColor() {
return this._color;
}
public void setColor(int color) {
this._color = color;
}
@Override
@@ -35,10 +35,11 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
if( appearances == null ) {
appearances = new HashMap<>();
this.registerApp( 0, "NOT_COMBINE", "DONT_COMBINE", "not_combine" );
this.registerApp( 1, "FORCE_COMBINE", "DO_COMBINE", "combine" );
this.registerApp( 2, "FORCE_PRIO", "DO_PRIO", "prio" );
this.registerApp( 3, "NOT_PRIO", "DONT_PRIO", "not_prio" );
this.registerApp(0, "NOT_COMBINE", "DONT_COMBINE", "not_combine");
this.registerApp(1, "FORCE_COMBINE", "DO_COMBINE", "combine");
this.registerApp(2, "FORCE_PRIO", "DO_PRIO", "prio");
this.registerApp(3, "NOT_PRIO", "DONT_PRIO", "not_prio");
this.registerApp(4, "SUBMIT", "SUBMIT", "submit");
}
}
@@ -221,35 +222,34 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
par1Minecraft.renderEngine.bindTexture( FluidCraft.resource("textures/gui/states.png") );
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
final int uv_y = (int) Math.floor( iconIndex / 3.0 );
final int uv_y = (int) Math.floor(iconIndex / 3.0);
final int uv_x = iconIndex - uv_y * 3;
this.drawTexturedModalRect( 0, 0, Math.round(32F * 16F / 3F), Math.round(32F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F) );
this.drawTexturedModalRect( 0, 0, Math.round(uv_x * 16F * 16F / 3F), Math.round(uv_y * 16F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F) );
this.mouseDragged( par1Minecraft, par2, par3 );
this.drawTexturedModalRect(0, 0, Math.round(32F * 16F / 3F), Math.round(32F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F));
this.drawTexturedModalRect(0, 0, Math.round(uv_x * 16F * 16F / 3F), Math.round(uv_y * 16F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F));
this.mouseDragged(par1Minecraft, par2, par3);
GL11.glPopMatrix();
}
else
{
if( this.enabled )
{
GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
else
{
GL11.glColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
} else {
GL11.glPushMatrix();
GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F);
GL11.glScalef(0.5f / 16 * 6, 0.5f / 16 * 6, 0.5f / 16 * 6);
if (this.enabled) {
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} else {
GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
}
par1Minecraft.renderEngine.bindTexture( FluidCraft.resource("textures/gui/states.png") );
par1Minecraft.renderEngine.bindTexture(FluidCraft.resource("textures/gui/states.png"));
this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
final int uv_y = (int) Math.floor( iconIndex / 3.0 );
final int uv_y = (int) Math.floor(iconIndex / 3.0);
final int uv_x = iconIndex - uv_y * 3;
this.drawTexturedModalRect( this.xPosition, this.yPosition, 32, 32, 16, 16 );
this.drawTexturedModalRect( this.xPosition, this.yPosition, uv_x * 16, uv_y * 16, 16, 16 );
this.mouseDragged( par1Minecraft, par2, par3 );
this.drawTexturedModalRect(0, 0, Math.round(32F * 16F / 3F), Math.round(32F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F));
this.drawTexturedModalRect(0, 0, Math.round(uv_x * 16F * 16F / 3F), Math.round(uv_y * 16F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F));
this.mouseDragged(par1Minecraft, par2, par3);
GL11.glPopMatrix();
}
}
GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
@@ -0,0 +1,246 @@
package com.glodblock.github.client.gui;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.AEBaseGui;
import appeng.client.render.AppEngRenderItem;
import appeng.container.slot.SlotFake;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.ContainerLevelMaintainer;
import com.glodblock.github.common.item.ItemFluidPacket;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.inventory.gui.MouseRegionManager;
import com.glodblock.github.inventory.slot.SlotSingleItem;
import com.glodblock.github.network.CPacketLevelMaintainer;
import com.glodblock.github.util.Ae2ReflectClient;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.NameConst;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import java.util.List;
public class GuiLevelMaintainer extends AEBaseGui {
private static final ResourceLocation TEX_BG = FluidCraft.resource("textures/gui/level_maintainer.png");
private final ContainerLevelMaintainer cont;
private final Widget[] qtyInputs = new Widget[TileLevelMaintainer.REQ_COUNT];
private final Widget[] batchInputs = new Widget[TileLevelMaintainer.REQ_COUNT];
private final MouseRegionManager mouseRegions = new MouseRegionManager(this);
private final AppEngRenderItem stackSizeRenderer = Ae2ReflectClient.getStackSizeRenderer(this);
private TileLevelMaintainer tile;
private FCGuiTextField input;
public GuiLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) {
super(new ContainerLevelMaintainer(ipl, tile));
this.cont = (ContainerLevelMaintainer) inventorySlots;
this.xSize = 195;
this.ySize = 214;
this.tile = tile;
}
public void postUpdate(List<IAEItemStack> list) {
for (IAEItemStack is : list) {
long size = is.getItemStack().getTagCompound().getLong("BatchSize");
int i = is.getItemStack().getTagCompound().getInteger("Index");
qtyInputs[i].textField.setText(String.valueOf(is.getStackSize()));
batchInputs[i].textField.setText(String.valueOf(size));
}
}
public void drawScreen(final int mouseX, final int mouseY, final float btn) {
super.drawScreen(mouseX, mouseY, btn);
if (ModAndClassUtil.isSearchBar) {
for (Widget i : qtyInputs) {
handleTooltip(mouseX, mouseY, i.textField.new TooltipProvider());
}
for (Widget i : batchInputs) {
handleTooltip(mouseX, mouseY, i.textField.new TooltipProvider());
}
}
}
public void initGui() {
super.initGui();
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
qtyInputs[i] = new Widget(
new FCGuiTextField(this.fontRendererObj, guiLeft + 37, guiTop + 21 + 20 * i, 52, 16),
new GuiFCImgButton(guiLeft + 37 + 47, guiTop + 20 + 20 * i, "SUBMIT", "SUBMIT"), I18n.format(NameConst.TT_REQUEST_SIZE),
i, 0);
this.buttonList.add(qtyInputs[i].btn());
batchInputs[i] = new Widget(
new FCGuiTextField(this.fontRendererObj, guiLeft + 100, guiTop + 21 + 20 * i, 52, 16),
new GuiFCImgButton(guiLeft + 100 + 47, guiTop + 20 + 20 * i, "SUBMIT", "SUBMIT"), I18n.format(NameConst.TT_BATCH_SIZE),
i, 1
);
this.buttonList.add(batchInputs[i].btn());
}
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(-1));
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
mc.getTextureManager().bindTexture(TEX_BG);
drawTexturedModalRect(offsetX, offsetY, 0, 0, 176, ySize);
for (int i = 0; i < TileLevelMaintainer.REQ_COUNT; i++) {
qtyInputs[i].draw();
batchInputs[i].draw();
}
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
fontRendererObj.drawString(getGuiDisplayName(I18n.format(NameConst.GUI_LEVEL_MAINTAINER)), 8, 6, 0x404040);
mouseRegions.render(mouseX, mouseY);
}
@Override
public void func_146977_a(final Slot s) {
if (drawSlot0(s))
super.func_146977_a(s);
}
public boolean drawSlot0(Slot slot) {
if (slot instanceof SlotFake) {
IAEItemStack stack = ((ContainerLevelMaintainer.FakeSlot) slot).getAeStack();
super.func_146977_a(new SlotSingleItem(slot));
if (stack == null) return true;
IAEItemStack fake = stack.copy();
if (fake.getItemStack().getItem() instanceof ItemFluidPacket) {
if (ItemFluidPacket.getFluidStack(stack) != null && ItemFluidPacket.getFluidStack(stack).amount > 0)
fake.setStackSize(ItemFluidPacket.getFluidStack(stack).amount);
}
stackSizeRenderer.setAeStack(fake);
stackSizeRenderer.renderItemOverlayIntoGUI(fontRendererObj, mc.getTextureManager(), stack.getItemStack(), slot.xDisplayPosition, slot.yDisplayPosition);
return false;
}
return true;
}
@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
if (btn == 0) {
if (input != null) {
input.setFocused(false);
}
for (Widget i : qtyInputs) {
if (i.textField.isMouseIn(xCoord, yCoord)) {
i.textField.setFocused(true);
this.input = i.textField;
super.mouseClicked(xCoord, yCoord, btn);
return;
}
}
for (Widget i : batchInputs) {
if (i.textField.isMouseIn(xCoord, yCoord)) {
i.textField.setFocused(true);
this.input = i.textField;
super.mouseClicked(xCoord, yCoord, btn);
return;
}
}
this.input = null;
}
super.mouseClicked(xCoord, yCoord, btn);
}
@Override
protected void keyTyped(final char character, final int key) {
if (this.input == null) {
super.keyTyped(character, key);
return;
}
if (!this.checkHotbarKeys(key)) {
if (!((character == ' ') && this.input.getText().isEmpty())) {
this.input.textboxKeyTyped(character, key);
}
super.keyTyped(character, key);
if (!this.input.getText().matches("[0-9]+")) {
this.input.setTextColor(0xFF0000);
} else {
this.input.setTextColor(0xFFFFFF);
}
if (key == Keyboard.KEY_RETURN) {
this.input.setFocused(false);
this.input = null;
}
}
}
@Override
protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) {
super.handleMouseClick(slot, slotIdx, ctrlDown, mouseButton);
if (slot instanceof ContainerLevelMaintainer.FakeSlot && this.cont.getPlayerInv().getItemStack() != null) {
this.qtyInputs[slot.getSlotIndex()].textField.setText(String.valueOf(this.cont.getPlayerInv().getItemStack().stackSize));
}
}
public void updateAmount(int idx, int stackSize) {
this.qtyInputs[idx].textField.setText(String.valueOf(stackSize));
}
private boolean sendToServer(Widget widget) {
if (((ContainerLevelMaintainer.FakeSlot) cont.inventorySlots.get(widget.idx)).getHasStack()) {
if (!widget.textField.getText().isEmpty() && widget.textField.getText().matches("[0-9]+") && Long.parseLong(widget.textField.getText()) <= Integer.MAX_VALUE) {
FluidCraft.proxy.netHandler.sendToServer(new CPacketLevelMaintainer(widget.action, widget.idx, widget.textField.getText()));
widget.textField.setTextColor(0xFFFFFF);
return true;
} else {
widget.textField.setTextColor(0xFF0000);
return false;
}
}
return false;
}
@Override
protected void actionPerformed(final GuiButton btn) {
super.actionPerformed(btn);
for (Widget widget : qtyInputs) {
if (widget.button == btn) {
sendToServer(widget);
return;
}
}
for (Widget widget : batchInputs) {
if (widget.button == btn) {
sendToServer(widget);
return;
}
}
}
private class Widget {
public final int idx;
public final int action;
private FCGuiTextField textField;
private GuiFCImgButton button;
public Widget(FCGuiTextField textField, GuiFCImgButton button, String tooltip, int idx, int action) {
this.textField = textField;
this.textField.setMessage(tooltip);
this.textField.setEnableBackgroundDrawing(false);
this.textField.setText("0");
this.button = button;
this.idx = idx;
this.action = action;
}
public void draw() {
this.textField.drawTextBox();
}
public GuiFCImgButton btn() {
return this.button;
}
public void setTooltip(String message) {
this.textField.setMessage(message);
}
}
}
@@ -168,7 +168,7 @@ public class ContainerFluidPatternEncoder extends AEBaseContainer implements Pat
}
}
private static class SlotFluidConvertingFake extends SlotFake implements SlotFluid {
public static class SlotFluidConvertingFake extends SlotFake implements SlotFluid {
private final AeStackInventory<IAEItemStack> inv;
@@ -0,0 +1,89 @@
package com.glodblock.github.client.gui.container;
import appeng.container.AEBaseContainer;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.glodblock.github.client.gui.GuiLevelMaintainer;
import com.glodblock.github.common.tile.TileLevelMaintainer;
import com.glodblock.github.inventory.AeItemStackHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerLevelMaintainer extends AEBaseContainer {
private final TileLevelMaintainer tile;
private final FakeSlot[] craftingSlots = new FakeSlot[TileLevelMaintainer.REQ_COUNT];
public ContainerLevelMaintainer(InventoryPlayer ipl, TileLevelMaintainer tile) {
super(ipl, tile);
this.tile = tile;
AeItemStackHandler crafting = new AeItemStackHandler(tile.getCraftingSlots());
for (int y = 0; y < TileLevelMaintainer.REQ_COUNT; y++) {
FakeSlot slot = new FakeSlot(crafting, y, 17, 19 + y * 20);
addSlotToContainer(slot);
craftingSlots[y] = slot;
}
bindPlayerInventory(ipl, 0, 132);
}
public TileLevelMaintainer getTile() {
return tile;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int idx) {
for (ContainerFluidPatternEncoder.SlotFluidConvertingFake slot : craftingSlots) {
if (!slot.getHasStack()) {
slot.setAeStack(AEItemStack.create(((Slot) this.inventorySlots.get(idx)).getStack()), true);
if (Platform.isClient()) {
GuiLevelMaintainer gui = (GuiLevelMaintainer) Minecraft.getMinecraft().currentScreen;
gui.updateAmount(slot.getSlotIndex(), ((Slot) this.inventorySlots.get(idx)).getStack().stackSize);
}
break;
}
}
this.detectAndSendChanges();
return null;
}
public void handleClientInteraction(int action, int idx, long size) {
if (action == 0) {
tile.updateQuantity(idx, size);
} else if (action == 1) {
tile.updateBatchSize(idx, size);
}
}
@Override
public void onSlotChange(final Slot s) {
if (Platform.isServer()) {
for (final Object crafter : this.crafters) {
final ICrafting icrafting = (ICrafting) crafter;
for (final Object g : this.inventorySlots) {
if (g instanceof OptionalSlotFake || g instanceof SlotFakeCraftingMatrix) {
final Slot sri = (Slot) g;
icrafting.sendSlotContents(this, sri.slotNumber, sri.getStack());
}
}
((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
}
this.detectAndSendChanges();
}
}
public static class FakeSlot extends ContainerFluidPatternEncoder.SlotFluidConvertingFake {
public FakeSlot(AeItemStackHandler inv, int idx, int x, int y) {
super(inv, idx, x, y);
}
}
}