package Horizon.modules.render;

import java.util.List;

import org.lwjgl.input.Keyboard;

import Horizon.Client;
import Horizon.events.Event;
import Horizon.events.listeners.EventKey;
import Horizon.events.listeners.EventRenderGUI;
import Horizon.events.listeners.EventUpdate;
import Horizon.modules.Module;
import Horizon.settings.Setting;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;

public class TabGUI extends Module {

public int currentTab;
public boolean expanded;

public TabGUI() {
	super("TabGUI", Keyboard.KEY_NONE, Category.RENDER);
	toggled = true;
}

public void onEvent(Event e) {
	if(e instanceof EventRenderGUI) {
		FontRenderer fr = mc.fontRendererObj;
		
		Gui.drawRect(5, 30.5, 70, 30 + Module.Category.values().length * 16 + 1.5, 0x90000000);
		Gui.drawRect(5, 30.5f + currentTab * 16, 7 + 61 + 2, 33 + currentTab * 16 + 12 + 2.5f, 0xff0090ff);
		
		int count = 0;
		for(Category c : Module.Category.values()) {
			fr.drawString(c.name, 11, 35 + count*16, -1);
			
			count++;
		}
		
		if(expanded) {
			Category category = Module.Category.values()[currentTab];
			List<Module> modules = Client.getModulesByCategory(category);
		
			if(modules.size() == 0)
				return;
			
			Gui.drawRect(70, 30.5, 70 + 68, 30 + modules.size() * 16 + 1.5, 0x90000000);
			Gui.drawRect(70, 30.5f + category.moduleIndex * 16, 7 + 61 + 70, 33 + category.moduleIndex * 16 + 12 + 2.5f, 0xff0090ff);
			
			count = 0;
			for(Module m : modules) {
				fr.drawString(m.name, 73, 35 + count*16, -1);
				
				if(count == category.moduleIndex && m.expanded) {
					
					Gui.drawRect(70 + 68, 30.5, 70 + 68 + 68, 30 + m.settings.size() * 16 + 1.5, 0x90000000);
					Gui.drawRect(70 + 68, 30.5f + m.index * 16, 7 + 61 + 68 + 70, 33 + m.index * 16 + 12 + 2.5f, 0xff0090ff);
					int index = 0;
					for(Setting setting : m.settings) {
						fr.drawString(setting.name, 73 + 68 + 2, 35 + index*16, -1);
						index++;
					}
				}
				
				count++;
			}
		}
	}
	if(e instanceof EventKey) {
		int code = ((EventKey)e).code;
		

		Category category = Module.Category.values()[currentTab];
		List<Module> modules = Client.getModulesByCategory(category);
		
		if(code == Keyboard.KEY_UP) {
			if(expanded) {
				if(category.moduleIndex <= 0) {
					category.moduleIndex = modules.size() - 1;
				}else
					category.moduleIndex--;
			}else {
				if(currentTab <= 0) {
					currentTab = Module.Category.values().length - 1;
				}else
					currentTab--;
			}
		}
		
		if(code == Keyboard.KEY_DOWN) {
			if(expanded) {
				if(category.moduleIndex >= modules.size() - 1) {
					category.moduleIndex = 0;
				}else
					category.moduleIndex++;
			}else {
				if(currentTab >= Module.Category.values().length - 1) {
					currentTab = 0;
				}else
					currentTab++;
			}
		}
		
		if(code == Keyboard.KEY_RETURN) {
			if(expanded && modules.size() != 0) {
				Module module = modules.get(category.moduleIndex);
				
					if(!module.expanded);
					module.expanded = true;
			}
		}
		
		if(code == Keyboard.KEY_RIGHT) {
			if(expanded && modules.size() != 0) {
				Module module = modules.get(category.moduleIndex);
				if(!module.name.equals("TabGUI"))
					module.toggle();
			}else {
				expanded = true;
			}
		}	
		
		if(code == Keyboard.KEY_LEFT) {
			if(expanded && !modules.isEmpty() && modules.get(category.moduleIndex).expanded) {
				modules.get(category.moduleIndex).expanded = false;
			}else
				expanded = false;
		}
	}
	
}

}

    I have a question, has the GUI ever worked before, like after episode 4 was it working

      Also can I have a screenshot of what it looks like in game

        meFroggy It worked but then stopped when I made the tab GUI.