Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.yarinch.modularmachines.client.interfaces;
- import com.yarinch.modularmachines.block.BlockMachineBase;
- import com.yarinch.modularmachines.block.MachineComponents;
- import com.yarinch.modularmachines.tileentity.TileEntityMachineCore;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.GuiButton;
- import net.minecraft.client.gui.inventory.GuiContainer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.util.ResourceLocation;
- import org.lwjgl.opengl.GL11;
- public class GuiMachine extends GuiContainer {
- private TileEntityMachineCore core;
- private boolean up = false;
- private boolean down = false;
- private int activeY;
- private MachineComponents[] unSaved;
- public boolean update = false;
- public GuiMachine(InventoryPlayer playerInv, TileEntityMachineCore core) {
- super(new ContainerMachineCore(playerInv, core));
- unSaved = core.getComponents();
- this.core = core;
- xSize = 256;
- ySize = 228;
- }
- private static final ResourceLocation texture = new ResourceLocation("modularmachines", "textures/gui/machine.png");
- @Override
- protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
- GL11.glColor4f(1, 1, 1, 1);
- Minecraft.getMinecraft().renderEngine.bindTexture(texture);
- drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
- //draws the boxes
- for (int i = 0; i < unSaved.length; i++) {
- int xStart = guiLeft + 64;
- int yStart = guiTop + 40 + 19 * (i + 1);
- int rectWidth = 128;
- int rectHeight = 12;
- boolean active = activeY == yStart || inRect(x, y, xStart, yStart, rectWidth, rectHeight);
- drawTexturedModalRect(xStart, yStart, active ? 128 : 0, 244, rectWidth, rectHeight);
- }
- //checks how the arrows should be drawn
- arrowCheck: {
- if (activeY == 0) {
- up = down = false;
- }else{
- for (int i = 0; i < unSaved.length; i++) {
- if (activeY == guiTop + 40 + 19 * (i + 1)) {
- up = i != 0 && unSaved.length > 1;
- down = i != unSaved.length - 1 && unSaved.length > 1;
- break arrowCheck;
- }
- }
- }
- }
- //draws the arrows
- for (int i = 0; i < 2; i++) {
- int xStart = guiLeft + 214;
- int yStart = guiTop + 44 + 24 * i;
- int srcY = 228;
- int srcX = i * 16;
- if (i == 0 ? !up : !down) {
- srcX += 64;
- }else if (inRect(x, y, xStart, yStart, 16, 16)) {
- srcX += 32;
- }
- drawTexturedModalRect(xStart, yStart, srcX, srcY, 16, 16);
- }
- }
- @Override
- protected void drawGuiContainerForegroundLayer(int x, int y) {
- fontRendererObj.drawString("Text test! Ting Tang Walla Walla Bing Bang", 9, 5, 0xCC00FF);
- //draws the boxes names
- for (int i = 0; i < unSaved.length; i++) {
- int srcX = 64;
- String str = unSaved[i].getLocalizedName();
- srcX += (128 - fontRendererObj.getStringWidth(str))/2;
- fontRendererObj.drawString(str, srcX, 42 + 19 * (i + 1), 0x3F7F47);
- }
- }
- @Override
- public void initGui() {
- super.initGui();
- buttonList.clear();
- buttonList.add(new GuiButton(0, guiLeft + 32, guiTop + 32, fontRendererObj.getStringWidth("Save Changes") + 10, 20, "Save Changes"));
- }
- private boolean inRect(int mouseX, int mouseY, int xStart, int yStart, int width, int height) {
- return xStart <= mouseX && mouseX <= xStart + width && yStart <= mouseY && mouseY <= yStart + height; //checks if the mouse is inside the rectangle
- }
- @Override
- protected void mouseClicked(int x, int y, int timeSinceClicked) {
- super.mouseClicked(x, y, timeSinceClicked);
- for (int i = 0; i < unSaved.length; i++) {
- if (inRect(x, y, guiLeft + 64, guiTop + 40 + 19 * (i + 1), 128, 12)) {
- int temp = guiTop + 40 + 19 * (i + 1);
- if (temp == activeY) {
- activeY = 0;
- up = down = false;
- } else {
- activeY = temp;
- up = i != 0 && unSaved.length > 1;
- down = i != unSaved.length - 1 && unSaved.length > 1;
- return;
- }
- }
- }
- for (int i = 0; i < 2; i++) {
- if (i == 0 ? up : down) {
- if (inRect(x, y, guiLeft + 214, guiTop + 43 + 24 * i, 16, 16)) {
- int j = (activeY - guiTop - 40) / 19 - 1;
- MachineComponents temp = unSaved[j];
- if (i == 1) {
- unSaved[j] = unSaved[j + 1];
- unSaved[j + 1] = temp;
- activeY += 19;
- }else{
- unSaved[j] = unSaved[j - 1];
- unSaved[j - 1] = temp;
- activeY -= 19;
- }
- return;
- }
- }
- }
- }
- @Override
- protected void actionPerformed(GuiButton button) {
- if (button.id == 0) {
- core.setComponents(unSaved);
- core.markDirty();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement