diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-04-12 16:29:24 +0300 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-04-12 16:29:24 +0300 |
| commit | 4f29b0ed24e393be7074abd851e207aadab38196 (patch) | |
| tree | be8e5211a2956589c08b5e88b5e083e6aaeb96ce /src/main/java/darkknight/jewelrycraft/client/gui/GuiJewelryModifier.java | |
| parent | 6312636fd9a4d0f56dc7c9ff474a99d879bcb4e9 (diff) | |
I rearranged files and added a few cool stuff.
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/client/gui/GuiJewelryModifier.java')
| -rw-r--r-- | src/main/java/darkknight/jewelrycraft/client/gui/GuiJewelryModifier.java | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/client/gui/GuiJewelryModifier.java b/src/main/java/darkknight/jewelrycraft/client/gui/GuiJewelryModifier.java new file mode 100644 index 0000000..f03f54b --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/client/gui/GuiJewelryModifier.java @@ -0,0 +1,204 @@ +package darkknight.jewelrycraft.client.gui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.client.gui.container.ContainerJewelryModifier; +import darkknight.jewelrycraft.network.PacketRequestSetSlot; +import darkknight.jewelrycraft.util.JewelryNBT; +import darkknight.jewelrycraft.util.JewelrycraftUtil; + +public class GuiJewelryModifier extends GuiContainer +{ + private ResourceLocation texture; + private GuiButton addItems; + private GuiTextField searchField, pages; + private boolean clicked; + private int page = 1, maxPages = 1, selectedX = 0, selectedY = 0, selectedPage = 0; + private ItemStack selectedItem; + private ArrayList<ItemStack> selectedItems = new ArrayList<ItemStack>(); + private List<Map<Integer, Map<Integer, Integer>>> selectedItemsPos = new ArrayList<Map<Integer, Map<Integer, Integer>>>(); + ContainerJewelryModifier jMod; + + public GuiJewelryModifier(ContainerJewelryModifier containerJewelryTab, ResourceLocation texture) + { + super(containerJewelryTab); + xSize = 211; + ySize = 247; + jMod = containerJewelryTab; + this.maxPages = JewelrycraftUtil.objects.size() / 48 + 1; + this.texture = texture; + } + + @Override + public void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) + { + GL11.glColor3f(1, 1, 1); + Minecraft.getMinecraft().getTextureManager().bindTexture(texture); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + if (selectedX != 0 && selectedY != 0 && page == selectedPage) drawTexturedModalRect(selectedX, selectedY, 211, 0, 18, 18); + for(Map items: selectedItemsPos){ + for(Object itemPage: items.keySet()){ + if (page == (Integer)itemPage) for(Object x: ((Map)items.get(itemPage)).keySet()) + drawTexturedModalRect((int)x, (int)((Map)items.get(itemPage)).get(x), 211, 0, 18, 18); + } + } + this.searchField.drawTextBox(); + this.pages.drawTextBox(); + } + + @Override + public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) + { + int i = 0; + for(ItemStack item: JewelrycraftUtil.objects){ + if (this.searchField.getText() == "" || item.getDisplayName().toLowerCase().contains(this.searchField.getText().toLowerCase())){ + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glColor3f(1F, 1F, 1F); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + if (i >= (page - 1) * 48 && i < page * 48) itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), item, 88 + 20 * (i % 6), 7 + 17 * (i / 6) - 136 * (page - 1)); + GL11.glDisable(GL11.GL_LIGHTING); + i++; + } + } + } + + @Override + protected void keyTyped(char character, int key) + { + if (this.searchField.textboxKeyTyped(character, key)){ + int items = 0; + for(ItemStack item: JewelrycraftUtil.objects) + if (item.getDisplayName().toLowerCase().contains(this.searchField.getText().toLowerCase())) items++; + maxPages = items / 48 + 1; + page = 1; + this.pages.setText(page + "/" + maxPages); + }else super.keyTyped(character, key); + } + + protected void mouseClicked(int x, int y, int id) + { + super.mouseClicked(x, y, id); + if (x >= this.searchField.xPosition && x <= this.searchField.xPosition + this.searchField.width && y >= this.searchField.yPosition && y <= this.searchField.yPosition + this.searchField.height){ + this.searchField.setText(""); + this.searchField.setFocused(true); + maxPages = JewelrycraftUtil.objects.size() / 48 + 1; + }else this.searchField.setFocused(false); + for(Object button: this.buttonList){ + if (((GuiButton)button).id < 3 && ((GuiButton)button).mousePressed(mc, x, y)){ + if (((GuiButton)button).id < 2){ + this.selectedItems.removeAll(selectedItems); + this.selectedItemsPos.removeAll(selectedItemsPos); + }else{ + this.selectedX = 0; + this.selectedY = 0; + this.selectedItem = null; + } + ((GuiButton)buttonList.get(0)).enabled = true; + ((GuiButton)buttonList.get(1)).enabled = true; + ((GuiButton)buttonList.get(2)).enabled = true; + ((GuiButton)button).enabled = false; + } + } + int i = 0; + for(ItemStack item: JewelrycraftUtil.objects){ + if (this.searchField.getText() == "" || item.getDisplayName().toLowerCase().contains(this.searchField.getText().toLowerCase())){ + if (i >= (page - 1) * 48 && i < page * 48 && x >= this.guiLeft + 88 + 20 * (i % 6) && x < this.guiLeft + 108 + 20 * (i % 6) && y >= this.guiTop + 9 + 17 * (i / 6) - 136 * (page - 1) && y < this.guiTop + 25 + 17 * (i / 6) - 136 * (page - 1)){ + if (!((GuiButton)buttonList.get(0)).enabled || !((GuiButton)buttonList.get(1)).enabled){ + this.selectedItem = item; + this.selectedX = this.guiLeft + 87 + 20 * (i % 6); + this.selectedY = this.guiTop + 6 + 17 * (i / 6) - 136 * (page - 1); + this.selectedPage = page; + }else if (!((GuiButton)buttonList.get(2)).enabled){ + Map<Integer, Map<Integer, Integer>> itemPage = new HashMap<Integer, Map<Integer, Integer>>(); + Map<Integer, Integer> pos = new HashMap<Integer, Integer>(); + pos.put(this.guiLeft + 87 + 20 * (i % 6), this.guiTop + 6 + 17 * (i / 6) - 136 * (page - 1)); + itemPage.put(page, pos); + if (!this.selectedItems.contains(item)){ + this.selectedItems.add(item); + this.selectedItemsPos.add(itemPage); + }else{ + this.selectedItems.remove(item); + this.selectedItemsPos.remove(itemPage); + } + } + } + i++; + } + } + if (((GuiButton)buttonList.get(4)).mousePressed(mc, x, y) && page > 1) page--; + if (((GuiButton)buttonList.get(5)).mousePressed(mc, x, y) && page < maxPages) page++; + if (jMod.modInv.getStackInSlot(36) != null){ + ItemStack targetItem = jMod.modInv.getStackInSlot(36).copy(); + if (((GuiButton)buttonList.get(3)).mousePressed(mc, x, y) && !((GuiButton)buttonList.get(0)).enabled){ + JewelryNBT.addIngotColor(targetItem, 16777215); + JewelryNBT.addMetal(targetItem, new ItemStack(Item.getItemById(0), 0, 0)); + JewelryNBT.addMetal(targetItem, this.selectedItem); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestSetSlot(targetItem)); + } + if (((GuiButton)buttonList.get(3)).mousePressed(mc, x, y) && !((GuiButton)buttonList.get(1)).enabled){ + JewelryNBT.addGemColor(targetItem, 16777215); + JewelryNBT.addGem(targetItem, new ItemStack(Item.getItemById(0), 0, 0)); + JewelryNBT.addGem(targetItem, this.selectedItem); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestSetSlot(targetItem)); + } + if (((GuiButton)buttonList.get(3)).mousePressed(mc, x, y) && !((GuiButton)buttonList.get(2)).enabled){ + JewelryNBT.addModifiers(targetItem, selectedItems); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestSetSlot(targetItem)); + } + } + this.pages.setText(page + "/" + maxPages); + } + + @Override + public void initGui() + { + super.initGui(); + this.searchField = new GuiTextField(this.fontRendererObj, this.guiLeft + 89, this.guiTop + 148, 115, this.fontRendererObj.FONT_HEIGHT + 3); + this.searchField.setMaxStringLength(15); + this.searchField.setTextColor(16777215); + this.searchField.setVisible(true); + this.searchField.setCanLoseFocus(true); + this.pages = new GuiTextField(this.fontRendererObj, this.guiLeft + 20, this.guiTop + 146, 50, this.fontRendererObj.FONT_HEIGHT + 3); + this.pages.setMaxStringLength(15); + this.pages.setTextColor(16777215); + this.pages.setVisible(true); + this.pages.setText(page + "/" + maxPages); + this.buttonList.add(new GuiButton(0, this.guiLeft + 17, this.guiTop + 30, 52, 20, "Metal")); + this.buttonList.add(new GuiButton(1, this.guiLeft + 17, this.guiTop + 52, 52, 20, "Gem")); + this.buttonList.add(new GuiButton(2, this.guiLeft + 17, this.guiTop + 74, 52, 20, "Modifiers")); + this.buttonList.add(new GuiButton(3, this.guiLeft + 17, this.guiTop + 96, 52, 20, "Add Items")); + this.buttonList.add(new GuiButton(4, this.guiLeft + 5, this.guiTop + 142, 13, 20, "<<")); + this.buttonList.add(new GuiButton(5, this.guiLeft + 73, this.guiTop + 142, 13, 20, ">>")); + ((GuiButton)buttonList.get(0)).enabled = false; + } + + public void drawScreen(int x, int y, float z) + { + super.drawScreen(x, y, z); + int i = 0; + List<String> list = new ArrayList<String>(); + for(ItemStack item: JewelrycraftUtil.objects){ + if (this.searchField.getText() == "" || item.getDisplayName().toLowerCase().contains(this.searchField.getText().toLowerCase())){ + if (i >= (page - 1) * 48 && i < page * 48 && x >= this.guiLeft + 88 + 20 * (i % 6) && x < this.guiLeft + 108 + 20 * (i % 6) && y >= this.guiTop + 9 + 17 * (i / 6) - 136 * (page - 1) && y < this.guiTop + 25 + 17 * (i / 6) - 136 * (page - 1)){ + list.add(item.getDisplayName()); + if (item.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips) != null) this.renderToolTip(item, x, y); + else this.drawHoveringText(list, x, y, this.fontRendererObj); + } + i++; + } + } + } +} |
