/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014
 *
 * See LICENSE for full License
 */
package kihira.tails.client.gui;

import kihira.foxlib.client.gui.GuiBaseScreen;
import kihira.foxlib.client.toast.ToastManager;
import kihira.tails.common.PartInfo;
import kihira.tails.common.PartsData;
import kihira.tails.common.Tails;
import kihira.tails.common.network.PlayerDataMessage;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.EnumChatFormatting;

public class ControlsPanel extends Panel<GuiEditor> {

    private GuiButton partTypeButton;

    @SuppressWarnings("unchecked")
    public ControlsPanel(GuiEditor parent, int left, int top, int right, int bottom) {
        super(parent, left, top, right, bottom);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void initGui() {
        //Reset/Save
        buttonList.add(new GuiButton(12, width - 83, height - 25, 40, 20, I18n.format("gui.button.reset")));
        buttonList.add(new GuiButton(13, width - 43, height - 25, 40, 20, I18n.format("gui.done")));

        //Export
        buttonList.add(new GuiBaseScreen.GuiButtonTooltip(14, (width / 2) - 20, height - 25, 40, 20, I18n.format("gui.button.export"),
                (width / 2) - 20, I18n.format("gui.button.export.0.tooltip")));

        //PartType Select
        buttonList.add(partTypeButton = new GuiButton(20, 3, height - 25, 40, 20, parent.getPartType().name()));
    }

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        drawRect(0, 0, width, height, 0xDD000000);

        super.drawScreen(mouseX, mouseY, partialTicks);
    }

    @Override
    protected void actionPerformed(GuiButton button) {
        PartsData partsData = parent.getPartsData();
        //Reset All
        if (button.id == 12) {
            PartInfo partInfo = parent.originalPartInfo.deepCopy();
            parent.partsPanel.selectDefaultListEntry();
            parent.setCurrTintEdit(0);
            parent.refreshTintPane();
            parent.setPartsInfo(partInfo);
        }
        //Save All
        else if (button.id == 13) {
            //Update part info, set local and send it to the server
            Tails.setLocalPartsData(partsData);
            Tails.proxy.addPartsData(mc.thePlayer.getPersistentID(), partsData);
            Tails.networkWrapper.sendToServer(new PlayerDataMessage(mc.getSession().func_148256_e().getId(), partsData, false));
            ToastManager.INSTANCE.createCenteredToast(parent.width / 2, parent.height - 40, 100, EnumChatFormatting.GREEN + "Saved!");
            this.mc.displayGuiScreen(null);
        }
        //Export
        else if (button.id == 14) {
            mc.displayGuiScreen(new GuiExport(parent, partsData));
        }
        //PartType
        else if (button.id == 20) {
            if (parent.getPartType().ordinal() + 1 >= PartsData.PartType.values().length) {
                parent.setPartType(PartsData.PartType.values()[0]);
            }
            else {
                parent.setPartType(PartsData.PartType.values()[parent.getPartType().ordinal() + 1]);
            }

            partTypeButton.displayString = parent.getPartType().name();
        }
    }
}

@@ -856,24 +856,124 @@
 initGui() %7B%0A
+        //Mode Switch%0A        buttonList.add(new GuiButton(0, 38, height - 25, 45, 20, %22Library%22));%0A
         //Re
@@ -1019,17 +1019,16 @@
 Button(1
-2
 , width 
@@ -1126,18 +1126,17 @@
 iButton(
-13
+2
 , width 
@@ -1265,18 +1265,17 @@
 Tooltip(
-14
+3
 , (width
@@ -1502,18 +1502,17 @@
 iButton(
-20
+4
 , 3, hei
@@ -1517,26 +1517,26 @@
 eight - 25, 
-40
+35
 , 20, parent
@@ -1887,24 +1887,547 @@
 artsData();%0A
+        //Mode Switch%0A        if (button.id == 0) %7B%0A            //%3E.%3E You see nothing!%0A            boolean libraryMode = button.displayString.equals(%22Library%22);%0A            parent.partsPanel.enabled = !libraryMode;%0A            parent.texturePanel.enabled = !libraryMode;%0A            parent.tintPanel.enabled = !libraryMode;%0A%0A            parent.libraryInfoPanel.enabled = libraryMode;%0A            parent.libraryPanel.enabled = libraryMode;%0A%0A            button.displayString = (libraryMode ? %22Editor%22 : %22Library%22);%0A        %7D%0A
         //Re
@@ -2434,32 +2434,37 @@
 set All%0A        
+else 
 if (button.id ==
@@ -2465,17 +2465,16 @@
 .id == 1
-2
 ) %7B%0A    
@@ -2776,10 +2776,9 @@
  == 
-13
+2
 ) %7B%0A
@@ -3339,18 +3339,17 @@
 n.id == 
-14
+3
 ) %7B%0A    
@@ -3470,18 +3470,17 @@
 n.id == 
-20
+4
 ) %7B%0A    

Add in button to switch between library and editor mode