From 869c206c4fcc8001bd2e1d66f704290331813835 Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Wed, 20 Jan 2016 14:24:34 +1000 Subject: Initial Commit --- .../craftgui/minecraft/ContainerCraftGUI.java | 549 +++++++++++++++++++ src/Java/binnie/craftgui/minecraft/CustomSlot.java | 54 ++ src/Java/binnie/craftgui/minecraft/Dialog.java | 53 ++ src/Java/binnie/craftgui/minecraft/EnumColor.java | 32 ++ src/Java/binnie/craftgui/minecraft/GUIIcon.java | 30 + .../binnie/craftgui/minecraft/GuiCraftGUI.java | 605 +++++++++++++++++++++ .../craftgui/minecraft/IMachineInformation.java | 6 + .../craftgui/minecraft/IMinecraftTooltip.java | 9 + .../minecraft/IWindowAffectsShiftClick.java | 8 + .../binnie/craftgui/minecraft/InventoryType.java | 8 + src/Java/binnie/craftgui/minecraft/ListMap.java | 149 +++++ .../binnie/craftgui/minecraft/MinecraftGUI.java | 14 + .../craftgui/minecraft/MinecraftTooltip.java | 63 +++ .../binnie/craftgui/minecraft/ModuleCraftGUI.java | 18 + src/Java/binnie/craftgui/minecraft/Window.java | 338 ++++++++++++ .../binnie/craftgui/minecraft/WindowInventory.java | 144 +++++ .../minecraft/control/ControlEnergyBar.java | 161 ++++++ .../minecraft/control/ControlErrorState.java | 113 ++++ .../craftgui/minecraft/control/ControlHelp.java | 41 ++ .../minecraft/control/ControlIconDisplay.java | 25 + .../craftgui/minecraft/control/ControlImage.java | 25 + .../craftgui/minecraft/control/ControlInfo.java | 38 ++ .../minecraft/control/ControlItemDisplay.java | 98 ++++ .../minecraft/control/ControlLiquidTank.java | 223 ++++++++ .../minecraft/control/ControlMachineProgress.java | 14 + .../minecraft/control/ControlPlayerInventory.java | 108 ++++ .../minecraft/control/ControlPowerSystem.java | 39 ++ .../minecraft/control/ControlProgress.java | 30 + .../minecraft/control/ControlProgressBase.java | 100 ++++ .../craftgui/minecraft/control/ControlSlide.java | 113 ++++ .../craftgui/minecraft/control/ControlSlot.java | 221 ++++++++ .../minecraft/control/ControlSlotArray.java | 76 +++ .../minecraft/control/ControlSlotBase.java | 77 +++ .../minecraft/control/ControlSlotCharge.java | 43 ++ .../craftgui/minecraft/control/ControlTabIcon.java | 47 ++ .../craftgui/minecraft/control/ControlUser.java | 41 ++ .../minecraft/control/EnumHighlighting.java | 28 + .../minecraft/render/MinecraftTexture.java | 10 + .../craftgui/minecraft/render/RenderCommand.java | 16 + 39 files changed, 3767 insertions(+) create mode 100644 src/Java/binnie/craftgui/minecraft/ContainerCraftGUI.java create mode 100644 src/Java/binnie/craftgui/minecraft/CustomSlot.java create mode 100644 src/Java/binnie/craftgui/minecraft/Dialog.java create mode 100644 src/Java/binnie/craftgui/minecraft/EnumColor.java create mode 100644 src/Java/binnie/craftgui/minecraft/GUIIcon.java create mode 100644 src/Java/binnie/craftgui/minecraft/GuiCraftGUI.java create mode 100644 src/Java/binnie/craftgui/minecraft/IMachineInformation.java create mode 100644 src/Java/binnie/craftgui/minecraft/IMinecraftTooltip.java create mode 100644 src/Java/binnie/craftgui/minecraft/IWindowAffectsShiftClick.java create mode 100644 src/Java/binnie/craftgui/minecraft/InventoryType.java create mode 100644 src/Java/binnie/craftgui/minecraft/ListMap.java create mode 100644 src/Java/binnie/craftgui/minecraft/MinecraftGUI.java create mode 100644 src/Java/binnie/craftgui/minecraft/MinecraftTooltip.java create mode 100644 src/Java/binnie/craftgui/minecraft/ModuleCraftGUI.java create mode 100644 src/Java/binnie/craftgui/minecraft/Window.java create mode 100644 src/Java/binnie/craftgui/minecraft/WindowInventory.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlEnergyBar.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlErrorState.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlHelp.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlIconDisplay.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlImage.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlInfo.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlItemDisplay.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlLiquidTank.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlMachineProgress.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlPlayerInventory.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlPowerSystem.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlProgress.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlProgressBase.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlSlide.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlSlot.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlSlotArray.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlSlotBase.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlSlotCharge.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlTabIcon.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/ControlUser.java create mode 100644 src/Java/binnie/craftgui/minecraft/control/EnumHighlighting.java create mode 100644 src/Java/binnie/craftgui/minecraft/render/MinecraftTexture.java create mode 100644 src/Java/binnie/craftgui/minecraft/render/RenderCommand.java (limited to 'src/Java/binnie/craftgui/minecraft') diff --git a/src/Java/binnie/craftgui/minecraft/ContainerCraftGUI.java b/src/Java/binnie/craftgui/minecraft/ContainerCraftGUI.java new file mode 100644 index 0000000000..9b6a2809d9 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/ContainerCraftGUI.java @@ -0,0 +1,549 @@ +package binnie.craftgui.minecraft; + +import binnie.core.BinnieCore; +import binnie.core.machines.IMachine; +import binnie.core.machines.Machine; +import binnie.core.machines.network.INetwork.RecieveGuiNBT; +import binnie.core.machines.network.INetwork.SendGuiNBT; +import binnie.core.machines.power.ErrorState; +import binnie.core.machines.power.IErrorStateSource; +import binnie.core.machines.power.IPoweredMachine; +import binnie.core.machines.power.IProcess; +import binnie.core.machines.power.ITankMachine; +import binnie.core.machines.power.PowerInfo; +import binnie.core.machines.power.ProcessInfo; +import binnie.core.machines.power.TankInfo; +import binnie.core.machines.transfer.TransferRequest; +import binnie.core.machines.transfer.TransferRequest.TransferSlot; +import binnie.core.network.packet.MessageContainerUpdate; +import binnie.core.proxy.BinnieProxy; +import binnie.craftgui.minecraft.control.ControlSlot; +import binnie.craftgui.minecraft.control.EnumHighlighting; +import com.mojang.authlib.GameProfile; +import cpw.mods.fml.relauncher.Side; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class ContainerCraftGUI + extends Container +{ + private Window window; + + public ContainerCraftGUI(Window window) + { + this.window = window; + IMachine machine = Machine.getMachine(window.getInventory()); + if (getSide() == Side.SERVER) + { + this.inventoryItemStacks = new ListMap(); + this.inventorySlots = new ListMap(); + if (machine != null) + { + GameProfile user = machine.getOwner(); + if (user != null) + { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setString("username", user.getName()); + sendNBTToClient("username", nbt); + } + } + } + } + + protected Slot addSlotToContainer(Slot slot) + { + return super.addSlotToContainer(slot); + } + + private Side getSide() + { + return this.window.isServer() ? Side.SERVER : Side.CLIENT; + } + + public Slot getSlot(int par1) + { + if ((par1 < 0) || (par1 >= this.inventorySlots.size())) { + return null; + } + return (Slot)this.inventorySlots.get(par1); + } + + public void putStackInSlot(int par1, ItemStack par2ItemStack) + { + if (getSlot(par1) != null) { + getSlot(par1).putStack(par2ItemStack); + } + } + + public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack) + { + for (int i = 0; i < par1ArrayOfItemStack.length; i++) { + if (getSlot(i) != null) { + getSlot(i).putStack(par1ArrayOfItemStack[i]); + } + } + } + + public void onContainerClosed(EntityPlayer par1EntityPlayer) + { + super.onContainerClosed(par1EntityPlayer); + + WindowInventory inventory = this.window.getWindowInventory(); + for (int i = 0; i < inventory.getSizeInventory(); i++) { + if (inventory.dispenseOnClose(i)) + { + ItemStack stack = inventory.getStackInSlot(i); + if (stack != null) + { + stack = new TransferRequest(stack, par1EntityPlayer.inventory).transfer(true); + if (stack != null) { + par1EntityPlayer.dropPlayerItemWithRandomChoice(stack, false); + } + } + } + } + } + + public ItemStack slotClick(int slotNum, int mouseButton, int modifier, EntityPlayer player) + { + Slot slot = getSlot(slotNum); + if (((slot instanceof CustomSlot)) && (((CustomSlot)slot).handleClick())) + { + ((CustomSlot)slot).onSlotClick(this, mouseButton, modifier, player); + return player.inventory.getItemStack(); + } + ItemStack stack = super.slotClick(slotNum, mouseButton, modifier, player); + return stack; + } + + public void sendNBTToClient(String key, NBTTagCompound nbt) + { + this.syncedNBT.put(key, nbt); + } + + public boolean canInteractWith(EntityPlayer var1) + { + return true; + } + + public final ItemStack transferStackInSlot(EntityPlayer player, int slotID) + { + return shiftClick(player, slotID); + } + + private ItemStack shiftClick(EntityPlayer player, int slotnumber) + { + TransferRequest request = getShiftClickRequest(player, slotnumber); + if (request == null) { + return null; + } + ItemStack itemstack = request.transfer(true); + Slot shiftClickedSlot = (Slot)this.inventorySlots.get(slotnumber); + + shiftClickedSlot.putStack(itemstack); + shiftClickedSlot.onSlotChanged(); + + return null; + } + + private TransferRequest getShiftClickRequest(EntityPlayer player, int slotnumber) + { + if (slotnumber < 0) { + return null; + } + Slot shiftClickedSlot = (Slot)this.inventorySlots.get(slotnumber); + + ItemStack itemstack = null; + if (shiftClickedSlot.getHasStack()) { + itemstack = shiftClickedSlot.getStack().copy(); + } + IInventory playerInventory = player.inventory; + IInventory containerInventory = this.window.getInventory(); + IInventory windowInventory = this.window.getWindowInventory(); + + IInventory fromPlayer = containerInventory == null ? windowInventory : containerInventory; + + int[] target = new int[36]; + for (int i = 0; i < 36; i++) { + target[i] = i; + } + TransferRequest request; + TransferRequest request; + if (shiftClickedSlot.inventory == playerInventory) { + request = new TransferRequest(itemstack, fromPlayer).setOrigin(shiftClickedSlot.inventory); + } else { + request = new TransferRequest(itemstack, playerInventory).setOrigin(shiftClickedSlot.inventory).setTargetSlots(target); + } + if ((this.window instanceof IWindowAffectsShiftClick)) { + ((IWindowAffectsShiftClick)this.window).alterRequest(request); + } + return request; + } + + public final ItemStack tankClick(EntityPlayer player, int slotID) + { + if (player.inventory.getItemStack() == null) { + return null; + } + ItemStack heldItem = player.inventory.getItemStack().copy(); + + heldItem = new TransferRequest(heldItem, this.window.getInventory()).setOrigin(player.inventory).setTargetSlots(new int[0]).setTargetTanks(new int[] { slotID }).transfer(true); + + + player.inventory.setItemStack(heldItem); + if ((player instanceof EntityPlayerMP)) { + ((EntityPlayerMP)player).updateHeldItem(); + } + return heldItem; + } + + public boolean handleNBT(Side side, EntityPlayer player, String name, NBTTagCompound action) + { + if (side == Side.SERVER) + { + if (name.equals("tank-click")) { + tankClick(player, action.getByte("id")); + } + if (name.equals("slot-reg")) + { + int type = action.getByte("t"); + int index = action.getShort("i"); + int slotNumber = action.getShort("n"); + getOrCreateSlot(InventoryType.values()[(type % 4)], index, slotNumber); + } + } + if (name.contains("tank-update")) { + onTankUpdate(action); + } else if (name.equals("power-update")) { + onPowerUpdate(action); + } else if (name.equals("process-update")) { + onProcessUpdate(action); + } else if (name.equals("error-update")) { + onErrorUpdate(action); + } else if (name.equals("mouse-over-slot")) { + onMouseOverSlot(player, action); + } else if (name.equals("shift-click-info")) { + onRecieveShiftClickHighlights(player, action); + } + return false; + } + + private Map syncedNBT = new HashMap(); + private Map sentNBT = new HashMap(); + + public void detectAndSendChanges() + { + super.detectAndSendChanges(); + + + + + ITankMachine tanks = (ITankMachine)Machine.getInterface(ITankMachine.class, this.window.getInventory()); + IPoweredMachine powered = (IPoweredMachine)Machine.getInterface(IPoweredMachine.class, this.window.getInventory()); + IErrorStateSource error = (IErrorStateSource)Machine.getInterface(IErrorStateSource.class, this.window.getInventory()); + IProcess process = (IProcess)Machine.getInterface(IProcess.class, this.window.getInventory()); + if ((tanks != null) && (this.window.isServer())) { + for (int i = 0; i < tanks.getTankInfos().length; i++) + { + TankInfo tank = tanks.getTankInfos()[i]; + if (!getTankInfo(i).equals(tank)) + { + this.syncedNBT.put("tank-update-" + i, createTankNBT(i, tank)); + + this.syncedTanks.put(Integer.valueOf(i), tank); + } + } + } + if ((powered != null) && (this.window.isServer())) { + this.syncedNBT.put("power-update", createPowerNBT(powered.getPowerInfo())); + } + if ((process != null) && (this.window.isServer())) { + this.syncedNBT.put("process-update", createProcessNBT(process.getInfo())); + } + if ((error != null) && (this.window.isServer())) { + this.syncedNBT.put("error-update", createErrorNBT(error)); + } + INetwork.SendGuiNBT machineSync = (INetwork.SendGuiNBT)Machine.getInterface(INetwork.SendGuiNBT.class, this.window.getInventory()); + if (machineSync != null) { + machineSync.sendGuiNBT(this.syncedNBT); + } + Map sentThisTime = new HashMap(); + for (Map.Entry nbt : this.syncedNBT.entrySet()) + { + ((NBTTagCompound)nbt.getValue()).setString("type", (String)nbt.getKey()); + + + + + + + boolean shouldSend = true; + NBTTagCompound lastSent = (NBTTagCompound)this.sentNBT.get(nbt.getKey()); + if (lastSent != null) { + shouldSend = !lastSent.equals(nbt.getValue()); + } + if (shouldSend) + { + for (int j = 0; j < this.crafters.size(); j++) { + if ((this.crafters.get(j) instanceof EntityPlayerMP)) + { + EntityPlayerMP player = (EntityPlayerMP)this.crafters.get(j); + BinnieCore.proxy.sendToPlayer(new MessageContainerUpdate((NBTTagCompound)nbt.getValue()), player); + } + } + sentThisTime.put(nbt.getKey(), nbt.getValue()); + } + } + this.sentNBT.putAll(sentThisTime); + + this.syncedNBT.clear(); + } + + private NBTTagCompound createErrorNBT(IErrorStateSource error) + { + NBTTagCompound nbt = new NBTTagCompound(); + ErrorState state = null; + if (error.canWork() != null) + { + nbt.setByte("type", (byte)0); + state = error.canWork(); + } + else if (error.canProgress() != null) + { + nbt.setByte("type", (byte)1); + state = error.canProgress(); + } + if (state != null) { + state.writeToNBT(nbt); + } + return nbt; + } + + public NBTTagCompound createPowerNBT(PowerInfo powerInfo) + { + NBTTagCompound nbt = new NBTTagCompound(); + powerInfo.writeToNBT(nbt); + return nbt; + } + + public NBTTagCompound createProcessNBT(ProcessInfo powerInfo) + { + NBTTagCompound nbt = new NBTTagCompound(); + powerInfo.writeToNBT(nbt); + return nbt; + } + + public NBTTagCompound createTankNBT(int tank, TankInfo tankInfo) + { + NBTTagCompound nbt = new NBTTagCompound(); + tankInfo.writeToNBT(nbt); + nbt.setByte("tank", (byte)tank); + return nbt; + } + + private Map syncedTanks = new HashMap(); + private PowerInfo syncedPower = new PowerInfo(); + private ProcessInfo syncedProcess = new ProcessInfo(); + private int errorType = 0; + private ErrorState error = null; + + public void onTankUpdate(NBTTagCompound nbt) + { + int tankID = nbt.getByte("tank"); + TankInfo tank = new TankInfo(); + tank.readFromNBT(nbt); + this.syncedTanks.put(Integer.valueOf(tankID), tank); + } + + public void onProcessUpdate(NBTTagCompound nbt) + { + this.syncedProcess = new ProcessInfo(); + this.syncedProcess.readFromNBT(nbt); + } + + public void onPowerUpdate(NBTTagCompound nbt) + { + this.syncedPower = new PowerInfo(); + this.syncedPower.readFromNBT(nbt); + } + + public PowerInfo getPowerInfo() + { + return this.syncedPower; + } + + public ProcessInfo getProcessInfo() + { + return this.syncedProcess; + } + + public TankInfo getTankInfo(int tank) + { + return this.syncedTanks.containsKey(Integer.valueOf(tank)) ? (TankInfo)this.syncedTanks.get(Integer.valueOf(tank)) : new TankInfo(); + } + + public void onErrorUpdate(NBTTagCompound nbt) + { + this.errorType = nbt.getByte("type"); + if (nbt.hasKey("name")) + { + this.error = new ErrorState("", ""); + this.error.readFromNBT(nbt); + } + else + { + this.error = null; + } + } + + public ErrorState getErrorState() + { + return this.error; + } + + public int getErrorType() + { + return this.errorType; + } + + public CustomSlot[] getCustomSlots() + { + List slots = new ArrayList(); + for (Object object : this.inventorySlots) { + if ((object instanceof CustomSlot)) { + slots.add((CustomSlot)object); + } + } + return (CustomSlot[])slots.toArray(new CustomSlot[0]); + } + + private int mousedOverSlotNumber = -1; + + public void setMouseOverSlot(Slot slot) + { + if (slot.slotNumber != this.mousedOverSlotNumber) + { + this.mousedOverSlotNumber = slot.slotNumber; + ((List)ControlSlot.highlighting.get(EnumHighlighting.ShiftClick)).clear(); + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setShort("slot", (short)slot.slotNumber); + this.window.sendClientAction("mouse-over-slot", nbt); + } + } + + private void onMouseOverSlot(EntityPlayer player, NBTTagCompound data) + { + int slotnumber = data.getShort("slot"); + TransferRequest request = getShiftClickRequest(player, slotnumber); + if (request == null) { + return; + } + request.transfer(false); + NBTTagCompound nbt = new NBTTagCompound(); + + List slots = new ArrayList(); + for (TransferRequest.TransferSlot tslot : request.getInsertedSlots()) + { + Slot slot = getSlot(tslot.inventory, tslot.id); + if (slot != null) { + slots.add(Integer.valueOf(slot.slotNumber)); + } + } + int[] array = new int[slots.size()]; + for (int i = 0; i < slots.size(); i++) { + array[i] = ((Integer)slots.get(i)).intValue(); + } + nbt.setIntArray("slots", array); + nbt.setShort("origin", (short)slotnumber); + + this.syncedNBT.put("shift-click-info", nbt); + } + + private void onRecieveShiftClickHighlights(EntityPlayer player, NBTTagCompound data) + { + ((List)ControlSlot.highlighting.get(EnumHighlighting.ShiftClick)).clear(); + for (int slotnumber : data.getIntArray("slots")) { + ((List)ControlSlot.highlighting.get(EnumHighlighting.ShiftClick)).add(Integer.valueOf(slotnumber)); + } + } + + private CustomSlot getSlot(IInventory inventory, int id) + { + for (Object o : this.inventorySlots) + { + CustomSlot slot = (CustomSlot)o; + if ((slot.inventory == inventory) && (slot.getSlotIndex() == id)) { + return slot; + } + } + return null; + } + + public void recieveNBT(Side side, EntityPlayer player, NBTTagCompound action) + { + String name = action.getString("type"); + if (handleNBT(side, player, name, action)) { + return; + } + this.window.recieveGuiNBT(getSide(), player, name, action); + INetwork.RecieveGuiNBT machine = (INetwork.RecieveGuiNBT)Machine.getInterface(INetwork.RecieveGuiNBT.class, this.window.getInventory()); + if (machine != null) { + machine.recieveGuiNBT(getSide(), player, name, action); + } + } + + public Slot getOrCreateSlot(InventoryType type, int index) + { + IInventory inventory = getInventory(type); + Slot slot = getSlot(inventory, index); + if (slot == null) + { + slot = new CustomSlot(inventory, index); + addSlotToContainer(slot); + } + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setByte("t", (byte)type.ordinal()); + nbt.setShort("i", (short)index); + nbt.setShort("n", (short)slot.slotNumber); + this.window.sendClientAction("slot-reg", nbt); + return slot; + } + + protected IInventory getInventory(InventoryType type) + { + if (type == InventoryType.Machine) { + return this.window.getInventory(); + } + if (type == InventoryType.Player) { + return this.window.getPlayer().inventory; + } + if (type == InventoryType.Window) { + return this.window.getWindowInventory(); + } + return null; + } + + private Slot getOrCreateSlot(InventoryType type, int index, int slotNumber) + { + IInventory inventory = getInventory(type); + if (this.inventorySlots.get(slotNumber) != null) { + return null; + } + Slot slot = new CustomSlot(inventory, index); + slot.slotNumber = slotNumber; + this.inventorySlots.add(slotNumber, slot); + this.inventoryItemStacks.add(slotNumber, (Object)null); + return slot; + } +} diff --git a/src/Java/binnie/craftgui/minecraft/CustomSlot.java b/src/Java/binnie/craftgui/minecraft/CustomSlot.java new file mode 100644 index 0000000000..ae45ffb3fd --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/CustomSlot.java @@ -0,0 +1,54 @@ +package binnie.craftgui.minecraft; + +import binnie.core.machines.Machine; +import binnie.core.machines.inventory.IInventorySlots; +import binnie.core.machines.inventory.InventorySlot; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class CustomSlot + extends Slot +{ + public boolean isItemValid(ItemStack par1ItemStack) + { + return this.inventory.isItemValidForSlot(getSlotIndex(), par1ItemStack); + } + + public CustomSlot(IInventory inventory, int index) + { + super(inventory, index, 0, 0); + } + + public InventorySlot getInventorySlot() + { + IInventorySlots slots = (IInventorySlots)Machine.getInterface(IInventorySlots.class, this.inventory); + if (slots != null) { + return slots.getSlot(getSlotIndex()); + } + return null; + } + + public boolean handleClick() + { + InventorySlot slot = getInventorySlot(); + return (slot != null) && (slot.isRecipe()); + } + + public void onSlotClick(ContainerCraftGUI container, int mouseButton, int modifier, EntityPlayer player) + { + ItemStack stack = player.inventory.getItemStack(); + if ((stack == null) || (mouseButton == 2)) + { + putStack(null); + } + else + { + stack = stack.copy(); + stack.stackSize = 1; + putStack(stack); + } + } +} diff --git a/src/Java/binnie/craftgui/minecraft/Dialog.java b/src/Java/binnie/craftgui/minecraft/Dialog.java new file mode 100644 index 0000000000..efd67dec25 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/Dialog.java @@ -0,0 +1,53 @@ +package binnie.craftgui.minecraft; + +import binnie.craftgui.controls.core.Control; +import binnie.craftgui.core.Attribute; +import binnie.craftgui.core.CraftGUI; +import binnie.craftgui.core.IWidget; +import binnie.craftgui.core.geometry.IArea; +import binnie.craftgui.core.geometry.IPoint; +import binnie.craftgui.core.renderer.Renderer; +import binnie.craftgui.events.EventHandler.Origin; +import binnie.craftgui.events.EventMouse.Down; +import binnie.craftgui.events.EventMouse.Down.Handler; +import binnie.craftgui.resource.minecraft.CraftGUITexture; + +public abstract class Dialog + extends Control +{ + public Dialog(IWidget parent, float w, float h) + { + super(parent, (parent.w() - w) / 2.0F, (parent.h() - h) / 2.0F, w, h); + addAttribute(Attribute.MouseOver); + addAttribute(Attribute.AlwaysOnTop); + addAttribute(Attribute.BlockTooltip); + initialise(); + addEventHandler(new EventMouse.Down.Handler() + { + public void onEvent(EventMouse.Down event) + { + if (!Dialog.this.getArea().contains(Dialog.this.getRelativeMousePosition())) + { + Dialog.this.onClose(); + Dialog.this.getParent().deleteChild(Dialog.this); + } + } + }.setOrigin(EventHandler.Origin.Any, this)); + } + + public abstract void initialise(); + + public abstract void onClose(); + + public void onRenderBackground() + { + CraftGUI.Render.gradientRect(getArea().outset(400), -1442840576, -1442840576); + CraftGUI.Render.texture(CraftGUITexture.Window, getArea()); + CraftGUI.Render.texture(CraftGUITexture.TabOutline, getArea().inset(4)); + } + + public boolean isMouseOverWidget(IPoint relativeMouse) + { + return true; + } +} diff --git a/src/Java/binnie/craftgui/minecraft/EnumColor.java b/src/Java/binnie/craftgui/minecraft/EnumColor.java new file mode 100644 index 0000000000..e778cf31c8 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/EnumColor.java @@ -0,0 +1,32 @@ +package binnie.craftgui.minecraft; + +public enum EnumColor +{ + Black("Black", 0, '0'), DarkBlue("Dark Blue", 170, '1'), DarkGreen("Dark Green", 43520, '2'), DarkAqua("Dark Aqua", 43690, '3'), DarkRed("Dark Red", 11141120, '4'), Purple("Purple", 11141290, '5'), Gold("Gold", 16755200, '6'), Grey("Grey", 11184810, '7'), DarkGrey("Dark Grey", 5592405, '8'), Blue("Blue", 5592575, '9'), Green("Green", 5635925, 'a'), Aqua("Aqua", 5636095, 'b'), Red("Red", 16733525, 'c'), Pink("Pink", 16733695, 'd'), Yellow("Yellow", 16777045, 'e'), White("White", 16777215, 'f'); + + int colour; + String name; + char code; + + private EnumColor(String name, int colour, char code) + { + this.name = name; + this.colour = colour; + this.code = code; + } + + public int getColour() + { + return this.colour; + } + + public String getCode() + { + return "ยง" + this.code; + } + + public String toString() + { + return this.name; + } +} diff --git a/src/Java/binnie/craftgui/minecraft/GUIIcon.java b/src/Java/binnie/craftgui/minecraft/GUIIcon.java new file mode 100644 index 0000000000..96338b2551 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/GUIIcon.java @@ -0,0 +1,30 @@ +package binnie.craftgui.minecraft; + +import binnie.Binnie; +import binnie.core.BinnieCore; +import binnie.core.resource.BinnieIcon; +import binnie.core.resource.ManagerResource; +import net.minecraft.util.IIcon; + +public enum GUIIcon +{ + ArrowUp("arrow-up"), ArrowDown("arrow-down"), ArrowLeft("arrow-left"), ArrowRight("arrow-right"), ArrowUpLeft("arrow-upleft"), ArrowUpRight("arrow-upright"), ArrowRightUp("arrow-rightup"), ArrowRightDown("arrow-rightdown"), ArrowDownRight("arrow-downright"), ArrowDownLeft("arrow-downleft"), ArrowLeftDown("arrow-leftdown"), ArrowLeftUp("arrow-leftup"); + + String path; + BinnieIcon icon; + + private GUIIcon(String path) + { + this.path = path; + } + + public void register() + { + this.icon = Binnie.Resource.getItemIcon(BinnieCore.instance, "gui/" + this.path); + } + + public IIcon getIcon() + { + return this.icon.getIcon(); + } +} diff --git a/src/Java/binnie/craftgui/minecraft/GuiCraftGUI.java b/src/Java/binnie/craftgui/minecraft/GuiCraftGUI.java new file mode 100644 index 0000000000..bfd4a5f876 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/GuiCraftGUI.java @@ -0,0 +1,605 @@ +package binnie.craftgui.minecraft; + +import binnie.core.BinnieCore; +import binnie.core.proxy.BinnieProxy; +import binnie.craftgui.core.CraftGUI; +import binnie.craftgui.core.IWidget; +import binnie.craftgui.core.Tooltip.Type; +import binnie.craftgui.core.geometry.IArea; +import binnie.craftgui.core.geometry.IBorder; +import binnie.craftgui.core.geometry.IPoint; +import binnie.craftgui.core.renderer.Renderer; +import binnie.craftgui.events.EventKey.Down; +import binnie.craftgui.events.EventMouse.Down; +import binnie.craftgui.events.EventMouse.Up; +import binnie.craftgui.events.EventMouse.Wheel; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.settings.GameSettings; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class GuiCraftGUI + extends GuiContainer +{ + IPoint mousePos = new IPoint(0.0F, 0.0F); + private Window window; + private ItemStack draggedItem; + + public void updateScreen() + { + this.window.updateClient(); + } + + public Minecraft getMinecraft() + { + return this.mc; + } + + public GuiCraftGUI(Window window) + { + super(window.getContainer()); + this.window = window; + resize(window.getSize()); + } + + protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {} + + public void initGui() + { + super.initGui(); + this.mc.thePlayer.openContainer = this.inventorySlots; + this.guiLeft = ((this.width - this.xSize) / 2); + this.guiTop = ((this.height - this.ySize) / 2); + this.window.setSize(new IPoint(this.xSize, this.ySize)); + this.window.setPosition(new IPoint(this.guiLeft, this.guiTop)); + this.window.initGui(); + } + + public ItemStack getDraggedItem() + { + return this.draggedItem; + } + + public void drawScreen(int mouseX, int mouseY, float par3) + { + this.window.setMousePosition(mouseX - (int)this.window.getPosition().x(), mouseY - (int)this.window.getPosition().y()); + + + drawDefaultBackground(); + + + GL11.glDisable(32826); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(2896); + GL11.glDisable(2929); + + this.zLevel = 10.0F; + itemRender.zLevel = this.zLevel; + + this.window.render(); + + + RenderHelper.enableGUIStandardItemLighting(); + GL11.glPushMatrix(); + GL11.glEnable(32826); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F); + + + + + + InventoryPlayer playerInventory = this.mc.thePlayer.inventory; + this.draggedItem = playerInventory.getItemStack(); + if (this.draggedItem != null) + { + renderItem(new IPoint(mouseX - 8, mouseY - 8), this.draggedItem, 200, false); + renderItem(new IPoint(mouseX - 8, mouseY - 8), this.draggedItem, 200, false); + } + GL11.glDisable(32826); + GL11.glPopMatrix(); + + + + + + GL11.glDisable(2896); + GL11.glDisable(2929); + + + MinecraftTooltip tooltip = new MinecraftTooltip(); + if (isHelpMode()) + { + tooltip.setType(Tooltip.Type.Help); + this.window.getHelpTooltip(tooltip); + } + else + { + tooltip.setType(Tooltip.Type.Standard); + this.window.getTooltip(tooltip); + } + if (tooltip.exists()) { + renderTooltip(new IPoint(mouseX, mouseY), tooltip); + } + this.zLevel = 0.0F; + + GL11.glEnable(2896); + GL11.glEnable(2929); + } + + public void renderTooltip(IPoint mousePosition, MinecraftTooltip tooltip) + { + int mouseX = (int)mousePosition.x(); + int mouseY = (int)mousePosition.y(); + FontRenderer font = getFontRenderer(); + GL11.glDisable(32826); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(2896); + GL11.glDisable(2929); + int k = 0; + + List strings = new ArrayList(); + for (String string : tooltip.getList()) { + if (string != null) { + if (!string.contains("~~~")) { + strings.addAll(font.listFormattedStringToWidth(string, tooltip.maxWidth)); + } else { + strings.add(string); + } + } + } + Iterator iterator = strings.iterator(); + while (iterator.hasNext()) + { + String s = (String)iterator.next(); + int l = font.getStringWidth(s); + if (s.contains("~~~")) { + l = 12 + font.getStringWidth(s.replaceAll("~~~(.*?)~~~", "")); + } + if (l > k) { + k = l; + } + } + int i1 = mouseX + 12; + int j1 = mouseY - 12; + int k1 = 8; + if (strings.size() > 1) { + k1 += 2 + (strings.size() - 1) * 10; + } + if (i1 + k > this.width) { + i1 -= 28 + k; + } + if (j1 + k1 + 6 > this.height) { + j1 = this.height - k1 - 6; + } + this.zLevel = 300.0F; + itemRender.zLevel = 300.0F; + int l1 = -267386864; + int i2 = 1342177280 + MinecraftTooltip.getOutline(tooltip.getType()); + int j2 = i2; + drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1); + drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1); + drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1); + drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1); + drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1); + + drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2); + drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2); + drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2); + drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2); + for (int k2 = 0; k2 < strings.size(); k2++) + { + String s1 = (String)strings.get(k2); + if (k2 == 0) { + s1 = MinecraftTooltip.getTitle(tooltip.getType()) + s1; + } else { + s1 = MinecraftTooltip.getBody(tooltip.getType()) + s1; + } + if (s1.contains("~~~")) + { + String split = s1.split("~~~")[1]; + try + { + NBTTagCompound nbt = (NBTTagCompound)JsonToNBT.func_150315_a(split); + ItemStack stack = ItemStack.loadItemStackFromNBT(nbt); + GL11.glPushMatrix(); + GL11.glTranslatef(i1, j1 - 1.5F, 0.0F); + GL11.glScalef(0.6F, 0.6F, 1.0F); + renderItem(new IPoint(0.0F, 0.0F), stack, false); + GL11.glPopMatrix(); + } + catch (NBTException e) + { + e.printStackTrace(); + } + s1 = " " + s1.replaceAll("~~~(.*?)~~~", ""); + } + font.drawStringWithShadow(s1, i1, j1, -1); + if (k2 == 0) { + j1 += 2; + } + j1 += 10; + } + this.zLevel = 0.0F; + itemRender.zLevel = 0.0F; + GL11.glEnable(2896); + GL11.glEnable(2929); + RenderHelper.enableStandardItemLighting(); + GL11.glEnable(32826); + } + + protected void mouseClicked(int x, int y, int button) + { + IWidget origin = this.window; + if (this.window.getMousedOverWidget() != null) { + origin = this.window.getMousedOverWidget(); + } + this.window.callEvent(new EventMouse.Down(origin, x, y, button)); + } + + public boolean isShiftDown() + { + return Keyboard.isKeyDown(this.mc.gameSettings.keyBindSneak.getKeyCode()); + } + + protected void keyTyped(char c, int key) + { + if ((key == 1) || ((key == this.mc.gameSettings.keyBindInventory.getKeyCode()) && (this.window.getFocusedWidget() == null))) { + this.mc.thePlayer.closeScreen(); + } + IWidget origin = this.window.getFocusedWidget() == null ? this.window : this.window.getFocusedWidget(); + + this.window.callEvent(new EventKey.Down(origin, c, key)); + } + + protected void mouseMovedOrUp(int x, int y, int button) + { + IWidget origin = this.window.getMousedOverWidget() == null ? this.window : this.window.getMousedOverWidget(); + float dy; + if (button == -1) + { + float dx = Mouse.getEventDX() * this.width / this.mc.displayWidth; + dy = -(Mouse.getEventDY() * this.height / this.mc.displayHeight); + } + else + { + this.window.callEvent(new EventMouse.Up(origin, x, y, button)); + } + } + + public void handleMouseInput() + { + super.handleMouseInput(); + int dWheel = Mouse.getDWheel(); + IWidget origin = this.window.getFocusedWidget() == null ? this.window : this.window.getFocusedWidget(); + if (dWheel != 0) { + this.window.callEvent(new EventMouse.Wheel(this.window, dWheel)); + } + } + + public void onGuiClosed() + { + this.window.onClose(); + } + + public void renderTexturedRect(float x, float y, float u, float v, float w, float h) + { + drawTexturedModalRect((int)x, (int)y, (int)u, (int)v, (int)w, (int)h); + } + + public void renderTexture(IPoint position, IArea textureArea) + { + drawTexturedModalRect((int)position.x(), (int)position.y(), (int)textureArea.pos().x(), (int)textureArea.pos().y(), (int)textureArea.size().x(), (int)textureArea.size().y()); + } + + private void renderTexturedRect(IArea area, IPoint uv) + { + renderTexturedRect(area.pos().x(), area.pos().y(), uv.x(), uv.y(), area.size().x(), area.size().y()); + } + + public void renderTexturePadded(IArea area, IArea texture, IBorder padding) + { + int borderLeft = (int)padding.l(); + int borderRight = (int)padding.r(); + int borderTop = (int)padding.t(); + int borderBottom = (int)padding.b(); + + int posX = (int)area.pos().x(); + int posY = (int)area.pos().y(); + int width = (int)area.size().x(); + int height = (int)area.size().y(); + + int textWidth = (int)texture.w(); + int textHeight = (int)texture.h(); + + int u = (int)texture.x(); + int v = (int)texture.y(); + if (borderTop + borderBottom > height) + { + borderTop = height / 2; + borderBottom = height / 2; + } + if (borderLeft + borderRight > width) + { + borderLeft = width / 2; + borderRight = width / 2; + } + IPoint origin = area.pos(); + + drawTexturedModalRect(posX, posY, u, v, borderLeft, borderTop); + + + drawTexturedModalRect(posX + width - borderRight, posY, u + textWidth - borderRight, v, borderRight, borderTop); + + + drawTexturedModalRect(posX, posY + height - borderBottom, u, v + textHeight - borderBottom, borderLeft, borderBottom); + + + drawTexturedModalRect(posX + width - borderRight, posY + height - borderBottom, u + textWidth - borderRight, v + textHeight - borderBottom, borderRight, borderBottom); + + + + int currentXPos = borderLeft; + while (currentXPos < width - borderRight) + { + int distanceXRemaining = width - borderRight - currentXPos; + + + int texturingWidth = textWidth - borderLeft - borderRight; + if (texturingWidth > distanceXRemaining) { + texturingWidth = distanceXRemaining; + } + if (texturingWidth <= 0) { + break; + } + drawTexturedModalRect(posX + currentXPos, posY, u + borderLeft, v, texturingWidth, borderTop); + + drawTexturedModalRect(posX + currentXPos, posY + height - borderBottom, u + borderLeft, v + textHeight - borderBottom, texturingWidth, borderBottom); + + + int currentYPos = borderTop; + while (currentYPos < height - borderBottom) + { + int distanceYRemaining = height - borderBottom - currentYPos; + + + int texturingHeight = textHeight - borderTop - borderBottom; + if (texturingHeight > distanceYRemaining) { + texturingHeight = distanceYRemaining; + } + if (texturingHeight <= 0) { + break; + } + drawTexturedModalRect(posX + currentXPos, posY + currentYPos, u + borderLeft, v + borderTop, texturingWidth, texturingHeight); + + currentYPos += texturingHeight; + } + currentXPos += texturingWidth; + } + int currentYPos = borderTop; + while (currentYPos < height - borderBottom) + { + int distanceYRemaining = height - borderBottom - currentYPos; + + + int texturingHeight = textHeight - borderTop - borderBottom; + if (texturingHeight > distanceYRemaining) { + texturingHeight = distanceYRemaining; + } + if (texturingHeight <= 0) { + break; + } + drawTexturedModalRect(posX, posY + currentYPos, u, v + borderTop, borderLeft, texturingHeight); + + drawTexturedModalRect(posX + width - borderRight, posY + currentYPos, u + textWidth - borderRight, v + borderTop, borderRight, texturingHeight); + currentYPos += texturingHeight; + } + } + + public void drawGradientArea(float p_73733_1_, float p_73733_2_, float p_73733_3_, float p_73733_4_, int p_73733_5_, int p_73733_6_) + { + float f = (p_73733_5_ >> 24 & 0xFF) / 255.0F; + float f1 = (p_73733_5_ >> 16 & 0xFF) / 255.0F; + float f2 = (p_73733_5_ >> 8 & 0xFF) / 255.0F; + float f3 = (p_73733_5_ & 0xFF) / 255.0F; + float f4 = (p_73733_6_ >> 24 & 0xFF) / 255.0F; + float f5 = (p_73733_6_ >> 16 & 0xFF) / 255.0F; + float f6 = (p_73733_6_ >> 8 & 0xFF) / 255.0F; + float f7 = (p_73733_6_ & 0xFF) / 255.0F; + GL11.glDisable(3553); + GL11.glEnable(3042); + GL11.glDisable(3008); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glShadeModel(7425); + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_F(f1, f2, f3, f); + tessellator.addVertex(p_73733_3_, p_73733_2_, this.zLevel); + tessellator.addVertex(p_73733_1_, p_73733_2_, this.zLevel); + tessellator.setColorRGBA_F(f5, f6, f7, f4); + tessellator.addVertex(p_73733_1_, p_73733_4_, this.zLevel); + tessellator.addVertex(p_73733_3_, p_73733_4_, this.zLevel); + tessellator.draw(); + GL11.glShadeModel(7424); + GL11.glDisable(3042); + GL11.glEnable(3008); + GL11.glEnable(3553); + } + + public void renderItem(IPoint pos, ItemStack item, boolean rotating) + { + renderItem(pos, item, (int)this.zLevel + 3, rotating); + } + + private void renderItem(IPoint pos, ItemStack item, int zLevel, boolean rotating) + { + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F); + + GL11.glPushMatrix(); + + RenderHelper.enableGUIStandardItemLighting(); + GL11.glEnable(32826); + GL11.glEnable(2929); + + + + + + + + FontRenderer font = item.getItem().getFontRenderer(item); + if (font == null) { + font = getFontRenderer(); + } + if (item != null) + { + BinnieCore.proxy.getMinecraftInstance();float phase = (float)Minecraft.getSystemTime() / 20.0F; + + GL11.glPushMatrix(); + if (rotating) + { + GL11.glTranslatef(8.0F, 8.0F, 0.0F); + GL11.glRotatef(phase, 0.0F, -0.866F, 0.5F); + GL11.glTranslatef(-8.0F, -8.0F, -67.099998F); + } + itemRender.renderItemAndEffectIntoGUI(font, this.mc.renderEngine, item, (int)pos.x(), (int)pos.y()); + GL11.glPopMatrix(); + itemRender.renderItemOverlayIntoGUI(font, this.mc.renderEngine, item, (int)pos.x(), (int)pos.y(), null); + } + GL11.glClear(256); + GL11.glEnable(3042); + + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + + + RenderHelper.disableStandardItemLighting(); + + CraftGUI.Render.colour(-1); + + GL11.glEnable(32826); + GL11.glPopMatrix(); + } + + public void renderIcon(IPoint pos, IIcon icon, ResourceLocation map) + { + if (icon == null) { + return; + } + GL11.glPushMatrix(); + GL11.glEnable(32826); + + + BinnieCore.proxy.bindTexture(map); + + + itemRender.zLevel = this.zLevel; + + itemRender.renderIcon((int)pos.x(), (int)pos.y(), icon, 16, 16); + + + + GL11.glEnable(32826); + GL11.glPopMatrix(); + } + + public boolean isHelpMode() + { + return Keyboard.isKeyDown(15); + } + + public FontRenderer getFontRenderer() + { + return this.fontRendererObj; + } + + public void resize(IPoint size) + { + this.xSize = ((int)size.x()); + this.ySize = ((int)size.y()); + this.guiLeft = ((this.width - this.xSize) / 2); + this.guiTop = ((this.height - this.ySize) / 2); + this.window.setPosition(new IPoint(this.guiLeft, this.guiTop)); + } + + public void limitArea(IArea area) + { + float x = area.pos().x(); + float y = area.pos().y(); + float w = area.size().x(); + float h = area.size().y(); + + y = this.height - (y + h); + float k = this.xSize; + float scaleX = this.width / this.mc.displayWidth; + float scaleY = this.height / this.mc.displayHeight; + + x += 0.0F; + y += 0.0F; + w += 0.0F; + h += 0.0F; + + + + GL11.glScissor((int)(x / scaleX), (int)(y / scaleY), (int)(w / scaleX), (int)(h / scaleY)); + } + + public int getZLevel() + { + return (int)this.zLevel; + } + + public void drawRect(float p_73734_0_, float p_73734_1_, float p_73734_2_, float p_73734_3_, int p_73734_4_) + { + if (p_73734_0_ < p_73734_2_) + { + float j1 = p_73734_0_; + p_73734_0_ = p_73734_2_; + p_73734_2_ = j1; + } + if (p_73734_1_ < p_73734_3_) + { + float j1 = p_73734_1_; + p_73734_1_ = p_73734_3_; + p_73734_3_ = j1; + } + float f3 = (p_73734_4_ >> 24 & 0xFF) / 255.0F; + float f = (p_73734_4_ >> 16 & 0xFF) / 255.0F; + float f1 = (p_73734_4_ >> 8 & 0xFF) / 255.0F; + float f2 = (p_73734_4_ & 0xFF) / 255.0F; + Tessellator tessellator = Tessellator.instance; + GL11.glEnable(3042); + GL11.glDisable(3553); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glColor4f(f, f1, f2, f3); + tessellator.startDrawingQuads(); + tessellator.addVertex(p_73734_0_, p_73734_3_, 0.0D); + tessellator.addVertex(p_73734_2_, p_73734_3_, 0.0D); + tessellator.addVertex(p_73734_2_, p_73734_1_, 0.0D); + tessellator.addVertex(p_73734_0_, p_73734_1_, 0.0D); + tessellator.draw(); + GL11.glEnable(3553); + GL11.glDisable(3042); + } +} diff --git a/src/Java/binnie/craftgui/minecraft/IMachineInformation.java b/src/Java/binnie/craftgui/minecraft/IMachineInformation.java new file mode 100644 index 0000000000..cd709bbf8a --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/IMachineInformation.java @@ -0,0 +1,6 @@ +package binnie.craftgui.minecraft; + +public abstract interface IMachineInformation +{ + public abstract String getInformation(); +} diff --git a/src/Java/binnie/craftgui/minecraft/IMinecraftTooltip.java b/src/Java/binnie/craftgui/minecraft/IMinecraftTooltip.java new file mode 100644 index 0000000000..5bdec6e4ae --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/IMinecraftTooltip.java @@ -0,0 +1,9 @@ +package binnie.craftgui.minecraft; + +import binnie.craftgui.core.ITooltip; + +public abstract interface IMinecraftTooltip + extends ITooltip +{ + public abstract void getTooltip(MinecraftTooltip paramMinecraftTooltip); +} diff --git a/src/Java/binnie/craftgui/minecraft/IWindowAffectsShiftClick.java b/src/Java/binnie/craftgui/minecraft/IWindowAffectsShiftClick.java new file mode 100644 index 0000000000..ced88aa028 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/IWindowAffectsShiftClick.java @@ -0,0 +1,8 @@ +package binnie.craftgui.minecraft; + +import binnie.core.machines.transfer.TransferRequest; + +public abstract interface IWindowAffectsShiftClick +{ + public abstract void alterRequest(TransferRequest paramTransferRequest); +} diff --git a/src/Java/binnie/craftgui/minecraft/InventoryType.java b/src/Java/binnie/craftgui/minecraft/InventoryType.java new file mode 100644 index 0000000000..f10a065a99 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/InventoryType.java @@ -0,0 +1,8 @@ +package binnie.craftgui.minecraft; + +public enum InventoryType +{ + Player, Machine, Window, Custom; + + private InventoryType() {} +} diff --git a/src/Java/binnie/craftgui/minecraft/ListMap.java b/src/Java/binnie/craftgui/minecraft/ListMap.java new file mode 100644 index 0000000000..7c0fbf37dd --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/ListMap.java @@ -0,0 +1,149 @@ +package binnie.craftgui.minecraft; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map.Entry; +import java.util.Set; + +class ListMap + implements List +{ + private LinkedHashMap map = new LinkedHashMap(); + + public int size() + { + int i = -1; + for (Iterator i$ = this.map.keySet().iterator(); i$.hasNext();) + { + int k = ((Integer)i$.next()).intValue(); + if (k > i) { + i = k; + } + } + return i + 1; + } + + public boolean isEmpty() + { + return this.map.isEmpty(); + } + + public boolean contains(Object o) + { + return this.map.containsValue(o); + } + + public Iterator iterator() + { + return this.map.values().iterator(); + } + + public Object[] toArray() + { + return this.map.values().toArray(); + } + + public

P[] toArray(P[] a) + { + return this.map.values().toArray(a); + } + + public boolean add(T e) + { + if (get(size()) == null) + { + add(size(), e); + return true; + } + return false; + } + + public boolean remove(Object o) + { + return false; + } + + public boolean containsAll(Collection c) + { + return this.map.values().containsAll(c); + } + + public boolean addAll(Collection c) + { + return false; + } + + public boolean addAll(int index, Collection c) + { + return false; + } + + public boolean removeAll(Collection c) + { + return false; + } + + public boolean retainAll(Collection c) + { + return false; + } + + public void clear() + { + this.map.clear(); + } + + public T get(int index) + { + return this.map.get(Integer.valueOf(index)); + } + + public T set(int index, T element) + { + this.map.put(Integer.valueOf(index), element); + return element; + } + + public void add(int index, T element) + { + this.map.put(Integer.valueOf(index), element); + } + + public T remove(int index) + { + return null; + } + + public int indexOf(Object o) + { + for (Map.Entry entry : this.map.entrySet()) { + if (entry.getValue() == o) { + return ((Integer)entry.getKey()).intValue(); + } + } + return 0; + } + + public int lastIndexOf(Object o) + { + return indexOf(o); + } + + public ListIterator listIterator() + { + return null; + } + + public ListIterator listIterator(int index) + { + return null; + } + + public List subList(int fromIndex, int toIndex) + { + return null; + } +} diff --git a/src/Java/binnie/craftgui/minecraft/MinecraftGUI.java b/src/Java/binnie/craftgui/minecraft/MinecraftGUI.java new file mode 100644 index 0000000000..a87b4deeb8 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/MinecraftGUI.java @@ -0,0 +1,14 @@ +package binnie.craftgui.minecraft; + +import binnie.craftgui.window.Panel.IPanelType; + +public class MinecraftGUI +{ + public static enum PanelType + implements Panel.IPanelType + { + Black, Gray, Tinted, Coloured, Outline, TabOutline; + + private PanelType() {} + } +} diff --git a/src/Java/binnie/craftgui/minecraft/MinecraftTooltip.java b/src/Java/binnie/craftgui/minecraft/MinecraftTooltip.java new file mode 100644 index 0000000000..4b48e33e6d --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/MinecraftTooltip.java @@ -0,0 +1,63 @@ +package binnie.craftgui.minecraft; + +import binnie.craftgui.core.Tooltip; +import binnie.craftgui.core.Tooltip.ITooltipType; +import net.minecraft.util.EnumChatFormatting; + +public class MinecraftTooltip + extends Tooltip +{ + public static enum Type + implements Tooltip.ITooltipType + { + Error, Warning; + + private Type() {} + } + + public static int getOutline(Tooltip.ITooltipType type) + { + return TypeColour.valueOf(type.toString()).getOutline(); + } + + public static String getTitle(Tooltip.ITooltipType type) + { + return TypeColour.valueOf(type.toString()).getTitle(); + } + + public static String getBody(Tooltip.ITooltipType type) + { + return TypeColour.valueOf(type.toString()).getBody(); + } + + private static enum TypeColour + { + Standard(5243135, EnumChatFormatting.WHITE, EnumChatFormatting.GRAY), Help(5046016, EnumChatFormatting.GREEN, EnumChatFormatting.DARK_GREEN), Information(49151, EnumChatFormatting.AQUA, EnumChatFormatting.DARK_AQUA), Error(16724224, EnumChatFormatting.RED, EnumChatFormatting.DARK_RED), Warning(16752384, EnumChatFormatting.YELLOW, EnumChatFormatting.GOLD), User(9839667, EnumChatFormatting.RED, EnumChatFormatting.DARK_RED), Power(9006592, EnumChatFormatting.YELLOW, EnumChatFormatting.GOLD); + + int outline; + String mainText; + String bodyText; + + private TypeColour(int outline, EnumChatFormatting mainText, EnumChatFormatting bodyText) + { + this.outline = outline; + this.mainText = mainText.toString(); + this.bodyText = bodyText.toString(); + } + + public int getOutline() + { + return this.outline; + } + + public String getTitle() + { + return this.mainText; + } + + public String getBody() + { + return this.bodyText; + } + } +} diff --git a/src/Java/binnie/craftgui/minecraft/ModuleCraftGUI.java b/src/Java/binnie/craftgui/minecraft/ModuleCraftGUI.java new file mode 100644 index 0000000000..d2655dc2fc --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/ModuleCraftGUI.java @@ -0,0 +1,18 @@ +package binnie.craftgui.minecraft; + +import binnie.core.IInitializable; + +public class ModuleCraftGUI + implements IInitializable +{ + public void preInit() {} + + public void init() {} + + public void postInit() + { + for (GUIIcon icon : ) { + icon.register(); + } + } +} diff --git a/src/Java/binnie/craftgui/minecraft/Window.java b/src/Java/binnie/craftgui/minecraft/Window.java new file mode 100644 index 0000000000..e09cf1e376 --- /dev/null +++ b/src/Java/binnie/craftgui/minecraft/Window.java @@ -0,0 +1,338 @@ +package binnie.craftgui.minecraft; + +import binnie.Binnie; +import binnie.core.AbstractMod; +import binnie.core.BinnieCore; +import binnie.core.machines.Machine; +import binnie.core.machines.inventory.IInventoryMachine; +import binnie.core.machines.network.INetwork.RecieveGuiNBT; +import binnie.core.machines.power.PowerSystem; +import binnie.core.network.packet.MessageCraftGUI; +import binnie.core.proxy.BinnieProxy; +import binnie.core.resource.BinnieResource; +import binnie.core.resource.ManagerResource; +import binnie.core.resource.ResourceType; +import binnie.craftgui.controls.ControlText; +import binnie.craftgui.controls.ControlTextCentered; +import binnie.craftgui.core.Attribute; +import binnie.craftgui.core.CraftGUI; +import binnie.craftgui.core.ITooltip; +import binnie.craftgui.core.ITooltipHelp; +import binnie.craftgui.core.IWidget; +import binnie.craftgui.core.Tooltip; +import binnie.craftgui.core.TopLevelWidget; +import binnie.craftgui.core.geometry.IPoint; +import binnie.craftgui.core.renderer.Renderer; +import binnie.craftgui.events.EventWidget.ChangeSize; +import binnie.craftgui.events.EventWidget.ChangeSize.Handler; +import binnie.craftgui.minecraft.control.ControlHelp; +import binnie.craftgui.minecraft.control.ControlInfo; +import binnie.craftgui.minecraft.control.ControlPowerSystem; +import binnie.craftgui.minecraft.control.ControlSlot; +import binnie.craftgui.minecraft.control.ControlUser; +import binnie.craftgui.minecraft.control.EnumHighlighting; +import binnie.craftgui.resource.StyleSheetManager; +import binnie.craftgui.resource.Texture; +import binnie.craftgui.resource.minecraft.CraftGUITexture; +import binnie.craftgui.resource.minecraft.StandardTexture; +import com.mojang.authlib.GameProfile; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.Deque; +import java.util.List; +import java.util.Map; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public abstract class Window + extends TopLevelWidget + implements INetwork.RecieveGuiNBT +{ + private GuiCraftGUI gui; + private ContainerCraftGUI container; + private WindowInventory windowInventory; + private ControlText title; + + public void getTooltip(Tooltip tooltip) + { + Deque queue = calculateMousedOverWidgets(); + while (!queue.isEmpty()) + { + IWidget widget = (IWidget)queue.removeFirst(); + if ((widget.isEnabled()) && (widget.isVisible()) && (widget.calculateIsMouseOver())) + { + if ((widget instanceof ITooltip)) + { + ((ITooltip)widget).getTooltip(tooltip); + if (tooltip.exists()) { + return; + } + } + if (widget.hasAttribute(Attribute.BlockTooltip)) { + return; + } + } + } + } + + public void getHelpTooltip(MinecraftTooltip tooltip) + { + Deque queue = calculateMousedOverWidgets(); + while (!queue.isEmpty()) + { + IWidget widget = (IWidget)queue.removeFirst(); + if ((widget.isEnabled()) && (widget.isVisible()) && (widget.calculateIsMouseOver())) + { + if ((widget instanceof ITooltipHelp)) + { + ((ITooltipHelp)widget).getHelpTooltip(tooltip); + if (tooltip.exists()) { + return; + } + } + if (widget.hasAttribute(Attribute.BlockTooltip)) { + return; + } + } + } + } + + protected abstract AbstractMod getMod(); + + protected abstract String getName(); + + public BinnieResource getBackgroundTextureFile(int i) + { + return Binnie.Resource.getPNG(getMod(), ResourceType.GUI, getName() + (i == 1 ? "" : Integer.valueOf(i))); + } + + public boolean showHelpButton() + { + return Machine.getInterface(IInventoryMachine.class, getInventory()) != null; + } + + public String showInfoButton() + { + if (Machine.getInterface(IMachineInformation.class, getInventory()) != null) { + return ((IMachineInformation)Machine.getInterface(IMachineInformation.class, getInventory())).getInformation(); + } + return null; + } + + public Window(float width, float height, EntityPlayer player, IInventory inventory, Side side) + { + this.side = side; + setInventories(player, inventory); + this.container = new ContainerCraftGUI(this); + this.windowInventory = new WindowInventory(this); + if (side == Side.SERVER) { + return; + } + setSize(new IPoint(width, height)); + this.gui = new GuiCraftGUI(this); + for (EnumHighlighting h : EnumHighlighting.values()) { + ControlSlot.highlighting.put(h, new ArrayList()); + } + CraftGUI.Render = new Renderer(this.gui); + CraftGUI.Render.stylesheet(StyleSheetManager.getDefault()); + + this.titleButtonLeft = -14.0F; + if (showHelpButton()) { + new ControlHelp(this, this.titleButtonLeft += 22.0F, 8.0F); + } + if (showInfoButton() != null) { + new ControlInfo(this, this.titleButtonLeft += 22.0F, 8.0F, showInfoButton()); + } + Window wind = this; + + addSelfEventHandler(new EventWidget.ChangeSize.Handler() + { + public void onEvent(EventWidget.ChangeSize event) + { + if ((Window.this.isClient()) && (Window.this.getGui() != null)) + { + Window.this.getGui().resize(Window.this.getSize()); + if (Window.this.title != null) { + Window.this.title.setSize(new IPoint(Window.this.w(), Window.this.title.h())); + } + } + } + }); + } + + protected float titleButtonLeft = 8.0F; + protected float titleButtonRight = 8.0F; + + public void setTitle(String title) + { + this.title = new ControlTextCentered(this, 12.0F, title); + this.title.setColour(4210752); + } + + @SideOnly(Side.CLIENT) + public final GuiCraftGUI getGui() + { + return this.gui; + } + + public final ContainerCraftGUI getContainer() + { + return this.container; + } + + public final WindowInventory getWindowInventory() + { + return this.windowInventory; + } + + private StandardTexture bgText1 = null; + private StandardTexture bgText2 = null; + private boolean hasBeenInitialised = false; + private EntityPlayer player; + private IInventory entityInventory; + + public final void initGui() + { + if (this.hasBeenInitialised) { + return; + } + this.bgText1 = new StandardTexture(0, 0, 256, 256, getBackgroundTextureFile(1)); + if (getSize().x() > 256.0F) { + this.bgText2 = new StandardTexture(0, 0, 256, 256, getBackgroundTextureFile(2)); + } + if (!BinnieCore.proxy.checkTexture(this.bgText1.getTexture())) + { + this.bgText1 = null; + this.bgText2 = null; + } + initialiseClient(); + this.hasBeenInitialised = true; + } + + public abstract void initialiseClient(); + + public void initialiseServer() {} + + public void onRenderBackground() + { + CraftGUI.Render.colour(16777215); + if (getBackground1() != null) { + CraftGUI.Render.texture(getBackground1(), IPoint.ZERO); + } + if (getBackground2() != null) { + CraftGUI.Render.texture(getBackground2(), new IPoint(256.0F, 0.0F)); + } + CraftGUI.Render.colour(getColour()); + CraftGUI.Render.texture(CraftGUITexture.Window, getArea()); + } + + public void onUpdateClient() + { + ((List)ControlSlot.highlighting.get(EnumHighlighting.Help)).clear(); + + ControlSlot.shiftClickActive = false; + } + + public EntityPlayer getPlayer() + { + return this.player; + } + + public GameProfile getUsername() + { + return getPlayer().getGameProfile(); + } + + public ItemStack getHeldItemStack() + { + if (this.player != null) { + return this.player.inventory.getItemStack(); + } + return null; + } + + public IInventory getInventory() + { + return this.entityInventory; + } + + public void setInventories(EntityPlayer player2, IInventory inventory) + {