Package logisticspipes.gui.modules

Source Code of logisticspipes.gui.modules.GuiOreDictItemSink

package logisticspipes.gui.modules;

import java.util.ArrayList;
import java.util.List;

import logisticspipes.modules.ModuleOreDictItemSink;
import logisticspipes.utils.gui.BasicGuiHelper;
import logisticspipes.utils.gui.DummyContainer;
import logisticspipes.utils.gui.SmallGuiButton;
import logisticspipes.utils.item.ItemIdentifierInventory;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

public class GuiOreDictItemSink extends ModuleBaseGui {

  private final ModuleOreDictItemSink _itemSink;
  private final ItemIdentifierInventory tmpInv;

  private int mouseX = 0;
  private int mouseY = 0;

  private List<String> unsunkNames = new ArrayList<String>();
  private int currentOffset = 0;

  public GuiOreDictItemSink(IInventory playerInventory, ModuleOreDictItemSink itemSink) {
    super(null, itemSink);

    _itemSink = itemSink;

    tmpInv = new ItemIdentifierInventory(1, "Analyse Slot", 1);

    DummyContainer dummy = new DummyContainer(playerInventory, tmpInv);
    dummy.addDummySlot(0, 7, 8);

    dummy.addNormalSlotsForPlayerInventory(7, 126);

      this.inventorySlots = dummy;
    xSize = 175;
    ySize = 208;
  }

  @SuppressWarnings("unchecked")
  @Override
  public void initGui() {
    super.initGui();
    this.buttonList.clear();
    this.buttonList.add(new SmallGuiButton(0, guiLeft + 159, guiTop + 5, 10, 10, ""));
    this.buttonList.add(new SmallGuiButton(1, guiLeft + 159, guiTop + 17, 10, 10, ""));
    ((GuiButton)buttonList.get(0)).enabled = true;
    ((GuiButton)buttonList.get(1)).enabled = true;
  }

  @Override
  protected void actionPerformed(GuiButton par1GuiButton) {
    if(par1GuiButton.id == 0) {
      currentOffset -= 1;
    } else if(par1GuiButton.id == 1) {
      currentOffset += 1;
    } else {
      super.actionPerformed(par1GuiButton);
    }
  }

  @Override
  protected void mouseClicked(int i, int j, int k) {
    int x = i - guiLeft;
    int y = j - guiTop;
    if(0 < x && x < 175 && 0 < y && y < 208) {
      mouseX = x;
      mouseY = y;
    }
    super.mouseClicked(i, j, k);
  }

  @Override
  protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
    int pointerX = var2 - guiLeft;
    int pointerY = var3 - guiTop;
    BasicGuiHelper.drawGuiBackGround(mc, guiLeft, guiTop, right, bottom, zLevel, true);
    BasicGuiHelper.drawPlayerInventoryBackground(mc, guiLeft + 7, guiTop + 126);
    BasicGuiHelper.drawSlotBackground(mc, guiLeft + 6, guiTop + 7);

    if(tmpInv.getStackInSlot(0) != null) {
      List<String> oreNames = getOreNames(tmpInv.getStackInSlot(0));
      for(String name : oreNames) {
        if(!unsunkNames.contains(name))
          unsunkNames.add(name);
      }
      tmpInv.clearInventorySlotContents(0);
    }

    if(currentOffset > unsunkNames.size() - 2)
      currentOffset = unsunkNames.size() - 2;
    if(currentOffset < 0)
      currentOffset = 0;

    //draw unsunk list and highlight bar, handle clicks
    BasicGuiHelper.drawRect(guiLeft + 26, guiTop + 5, guiLeft + 159, guiTop + 27, 0xff808080);
    for(int i=0; i + currentOffset < unsunkNames.size() && i < 2; i++) {
      if(27 <= pointerX && pointerX < 158 && 6 + (10 * i) <= pointerY && pointerY < 6 + (10 * (i + 1))) {
        BasicGuiHelper.drawRect(guiLeft + 27, guiTop + 6 + (10 * i), guiLeft + 158, guiTop + 6 + (10 * (i + 1)), 0xffc0c0c0);
      }
      mc.fontRenderer.drawString(unsunkNames.get(currentOffset + i), guiLeft + 28, guiTop + 7 + (10 * i), 0x404040);
      if(27 <= mouseX && mouseX < 158 && 6 + (10 * i) <= mouseY && mouseY < 6 + (10 * (i + 1))) {
        mouseX = 0;
        mouseY = 0;
        if(_itemSink.oreList.size() < 9) {
          String oreName = unsunkNames.get(currentOffset + i);
          if(!_itemSink.oreList.contains(oreName)) {
            _itemSink.oreList.add(oreName);
            _itemSink.OreListChanged();
          }
          unsunkNames.remove(oreName);
        }
      }
    }

    //draw main list and highlight bar, handle clicks
    BasicGuiHelper.drawRect(guiLeft + 5, guiTop + 30, guiLeft + 169, guiTop + 122, 0xff808080);
    for(int i=0; i < _itemSink.oreList.size() && i < 9; i++) {
      if(6 <= pointerX && pointerX < 168 && 31 + (10 * i) <= pointerY && pointerY < 31 + (10 * (i + 1))) {
        BasicGuiHelper.drawRect(guiLeft + 6, guiTop + 31 + (10 * i), guiLeft + 168, guiTop + 31 + (10 * (i + 1)), 0xffc0c0c0);
      }
      mc.fontRenderer.drawString(_itemSink.oreList.get(i), guiLeft + 7, guiTop + 32 + (10 * i), 0x404040);
      if(6 <= mouseX && mouseX < 168 && 31 + (10 * i) <= mouseY && mouseY < 31 + (10 * (i + 1))) {
        mouseX = 0;
        mouseY = 0;
        String oreName = _itemSink.oreList.get(i);
        if(!unsunkNames.contains(oreName))
          unsunkNames.add(oreName);
        _itemSink.oreList.remove(oreName);
        _itemSink.OreListChanged();
      }
    }
  }

  private List<String> getOreNames(ItemStack s) {
    int oreids[] = OreDictionary.getOreIDs(s);
    List<String> oreNames = new ArrayList<String>(oreids.length);
    for(int i=0; i < oreids.length; i++) {
      String oreName = OreDictionary.getOreName(oreids[i]);
      if(oreName != null && !oreName.equals("Unknown") && !oreNames.contains(oreName))
        oreNames.add(oreName);
    }
    return oreNames;
  }
}
TOP

Related Classes of logisticspipes.gui.modules.GuiOreDictItemSink

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.