New crafting settings gui
This commit is contained in:
107
src/main/java/refinedstorage/container/ContainerCraftingSettings.java
Executable file
107
src/main/java/refinedstorage/container/ContainerCraftingSettings.java
Executable file
@@ -0,0 +1,107 @@
|
||||
package refinedstorage.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.container.slot.SlotDisabled;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ContainerCraftingSettings extends ContainerBase {
|
||||
public ContainerCraftingSettings(EntityPlayer player, final ItemStack stack) {
|
||||
super(player);
|
||||
|
||||
final ItemStack slot = ItemHandlerHelper.copyStackWithSize(stack, 1);
|
||||
|
||||
addSlotToContainer(new SlotDisabled(new IInventory() {
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index) {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, @Nullable ItemStack stack) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return null;
|
||||
}
|
||||
}, 0, 89, 48));
|
||||
}
|
||||
}
|
||||
@@ -3,40 +3,59 @@ package refinedstorage.gui;
|
||||
import com.google.common.primitives.Ints;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.container.ContainerDummy;
|
||||
import refinedstorage.container.ContainerCraftingSettings;
|
||||
import refinedstorage.network.MessageGridCraftingStart;
|
||||
import refinedstorage.tile.controller.StorageHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiCraftingSettings extends GuiBase {
|
||||
public static final int DEFAULT_AMOUNT = 1;
|
||||
|
||||
private GuiTextField amountField;
|
||||
private GuiGrid gridGui;
|
||||
private GuiGrid gui;
|
||||
private ItemStack stack;
|
||||
private GuiButton startButton;
|
||||
private GuiButton cancelButton;
|
||||
private GuiButton[] incrementButtons = new GuiButton[6];
|
||||
|
||||
public GuiCraftingSettings(GuiGrid gridGui, ItemStack stack) {
|
||||
super(new ContainerDummy(), 143, 61);
|
||||
public GuiCraftingSettings(GuiGrid gui, EntityPlayer player, ItemStack stack) {
|
||||
super(new ContainerCraftingSettings(player, stack), 170, 99);
|
||||
|
||||
this.gridGui = gridGui;
|
||||
this.gui = gui;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int x, int y) {
|
||||
startButton = addButton(x + 48, y + 35, 50, 20, t("misc.refinedstorage:start"));
|
||||
startButton = addButton(x + 114, y + 33, 50, 20, t("misc.refinedstorage:start"));
|
||||
cancelButton = addButton(x + 114, y + 57, 50, 20, t("gui.cancel"));
|
||||
|
||||
amountField = new GuiTextField(0, fontRendererObj, x + 39 + 1, y + 21 + 1, 69 - 6, fontRendererObj.FONT_HEIGHT);
|
||||
amountField = new GuiTextField(0, fontRendererObj, x + 7 + 1, y + 50 + 1, 69 - 6, fontRendererObj.FONT_HEIGHT);
|
||||
amountField.setEnableBackgroundDrawing(false);
|
||||
amountField.setVisible(true);
|
||||
amountField.setText("1");
|
||||
amountField.setText(String.valueOf(DEFAULT_AMOUNT));
|
||||
amountField.setTextColor(16777215);
|
||||
amountField.setCanLoseFocus(false);
|
||||
amountField.setFocused(true);
|
||||
|
||||
int[] increments = new int[]{
|
||||
1, 10, 64,
|
||||
-1, -10, -64
|
||||
};
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
incrementButtons[i] = addButton(x + 6 + (i * (30 + 3)), y + 20, 30, 20, "+" + increments[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
incrementButtons[3 + i] = addButton(x + 6 + (i * (30 + 3)), y + 72, 30, 20, String.valueOf(increments[3 + i]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +73,7 @@ public class GuiCraftingSettings extends GuiBase {
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
drawString((width - fontRendererObj.getStringWidth(t("container.crafting"))) / 2, 8, t("container.crafting"));
|
||||
drawString(7, 7, t("container.crafting"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,6 +97,26 @@ public class GuiCraftingSettings extends GuiBase {
|
||||
|
||||
if (button.id == startButton.id) {
|
||||
startRequest();
|
||||
} else if (button.id == cancelButton.id) {
|
||||
close();
|
||||
} else {
|
||||
for (GuiButton incrementButton : incrementButtons) {
|
||||
if (incrementButton.id == button.id) {
|
||||
Integer oldAmount = Ints.tryParse(amountField.getText());
|
||||
|
||||
if (oldAmount == null) {
|
||||
oldAmount = 0;
|
||||
}
|
||||
|
||||
int newAmount = Integer.parseInt(incrementButton.displayString);
|
||||
|
||||
newAmount = Math.min(Math.max(DEFAULT_AMOUNT, oldAmount + newAmount), StorageHandler.MAX_CRAFTING_PER_REQUEST);
|
||||
|
||||
amountField.setText(String.valueOf(newAmount));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +131,6 @@ public class GuiCraftingSettings extends GuiBase {
|
||||
}
|
||||
|
||||
private void close() {
|
||||
FMLClientHandler.instance().showGuiScreen(gridGui);
|
||||
FMLClientHandler.instance().showGuiScreen(gui);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ public class GuiGrid extends GuiBase {
|
||||
|
||||
if (isOverSlotWithItem() && container.getPlayer().inventory.getItemStack() == null) {
|
||||
if (items.get(slotNumber).stackSize == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown())) {
|
||||
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, items.get(slotNumber)));
|
||||
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, container.getPlayer(), items.get(slotNumber)));
|
||||
} else {
|
||||
int flags = 0;
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user