summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/UI/UIMaster.java
blob: 8709aabf0d4d2f59c8624e004e53dfb7e29a37c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package net.tylermurphy.Minecraft.UI;

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

import net.tylermurphy.Minecraft.Render.FontRenderer;
import net.tylermurphy.Minecraft.Render.GuiRenderer;
import net.tylermurphy.Minecraft.UI.Text.TextMaster;

public class UIMaster {

	private static List<UI> uis = new ArrayList<UI>();
	private static int bindedID = 0;
	protected static List<UIComponent> componentBatch = new ArrayList<UIComponent>();
	
	public static void createUI(int id) {
		uis.add(id,new UI());
		bindedID = id;
	}
	
	private static UI getUI() {
		return uis.get(bindedID);
	}
	
	public static void add(UIComponent... components) {
		for(UIComponent component : components) {
			getUI().add(component);
		}
	}
	
	public static UIImage getImage(String key) {
		return (UIImage) getUI().findKey(key);
	}
	
	public static UIText getText(String key) {
		return (UIText) getUI().findKey(key);
	}
	
	public static void bindUI(int id) {
		bindedID = id;
	}
	
	public static void setEnabled(boolean value) {
		getUI().enabled = value;
	}
	
	public static boolean isEnabled() {
		return getUI().enabled;
	}
	
	public static void renderUI(GuiRenderer renderer, FontRenderer fontrenderer) {
		for(UI ui : uis) {
			if(!ui.enabled) continue;
			ui.prepare();
		}
		try{
			UILayerQuickSort.quickSort(componentBatch, 0, componentBatch.size()-1);
		} catch (Exception ignore) {}
		renderer.render(componentBatch);
		TextMaster.render(componentBatch,fontrenderer);
		componentBatch.clear();
	}
	
}