Skip to content

Commit 8084cfd

Browse files
committed
Add McLib icon registry
1 parent 295ae5f commit 8084cfd

File tree

3 files changed

+100
-66
lines changed

3 files changed

+100
-66
lines changed

src/main/java/mchorse/mclib/client/gui/utils/Icon.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import net.minecraft.client.Minecraft;
55
import net.minecraft.client.renderer.GlStateManager;
66
import net.minecraft.util.ResourceLocation;
7-
import net.minecraftforge.fml.client.config.GuiUtils;
7+
import net.minecraftforge.fml.relauncher.Side;
8+
import net.minecraftforge.fml.relauncher.SideOnly;
89

910
public class Icon
1011
{
@@ -37,11 +38,13 @@ public Icon(ResourceLocation location, int x, int y, int w, int h, int textureW,
3738
this.textureH = textureH;
3839
}
3940

41+
@SideOnly(Side.CLIENT)
4042
public void render(int x, int y)
4143
{
4244
this.render(x, y, 0, 0);
4345
}
4446

47+
@SideOnly(Side.CLIENT)
4548
public void render(int x, int y, float ax, float ay)
4649
{
4750
if (this.location == null)
@@ -60,6 +63,7 @@ public void render(int x, int y, float ax, float ay)
6063
GlStateManager.disableAlpha();
6164
}
6265

66+
@SideOnly(Side.CLIENT)
6367
public void renderArea(int x, int y, int w, int h)
6468
{
6569
GlStateManager.enableAlpha();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package mchorse.mclib.client.gui.utils;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class IconRegistry
7+
{
8+
public static final Map<String, Icon> icons = new HashMap<String, Icon>();
9+
10+
public static Icon register(String key, Icon icon)
11+
{
12+
if (icons.containsKey(key))
13+
{
14+
try
15+
{
16+
throw new IllegalStateException("[Icons] Icon " + key + " was already registered prior...");
17+
}
18+
catch (Exception e)
19+
{
20+
e.printStackTrace();
21+
}
22+
}
23+
else
24+
{
25+
icons.put(key, icon);
26+
}
27+
28+
return icon;
29+
}
30+
}

src/main/java/mchorse/mclib/client/gui/utils/Icons.java

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,73 +12,73 @@ public class Icons
1212

1313
public static final Icon NONE = new Icon(null, 0, 0);
1414

15-
public static final Icon GEAR = new Icon(ICONS, 0, 0);
16-
public static final Icon MORE = new Icon(ICONS, 16, 0);
17-
public static final Icon SAVED = new Icon(ICONS, 32, 0);
18-
public static final Icon SAVE = new Icon(ICONS, 48, 0);
19-
public static final Icon ADD = new Icon(ICONS, 64, 0);
20-
public static final Icon DUPE = new Icon(ICONS, 80, 0);
21-
public static final Icon REMOVE = new Icon(ICONS, 96, 0);
22-
public static final Icon POSE = new Icon(ICONS, 112, 0);
23-
public static final Icon FILTER = new Icon(ICONS, 128, 0);
24-
public static final Icon MOVE_UP = new Icon(ICONS, 144, 0, 16, 8);
25-
public static final Icon MOVE_DOWN = new Icon(ICONS, 144, 8, 16, 8);
26-
public static final Icon LOCKED = new Icon(ICONS, 160, 0);
27-
public static final Icon UNLOCKED = new Icon(ICONS, 176, 0);
28-
public static final Icon COPY = new Icon(ICONS, 192, 0);
29-
public static final Icon PASTE = new Icon(ICONS, 208, 0);
30-
public static final Icon CUT = new Icon(ICONS, 224, 0);
31-
public static final Icon REFRESH = new Icon(ICONS, 240, 0);
15+
public static final Icon GEAR = IconRegistry.register("gear", new Icon(ICONS, 0, 0));
16+
public static final Icon MORE = IconRegistry.register("more", new Icon(ICONS, 16, 0));
17+
public static final Icon SAVED = IconRegistry.register("saved", new Icon(ICONS, 32, 0));
18+
public static final Icon SAVE = IconRegistry.register("save", new Icon(ICONS, 48, 0));
19+
public static final Icon ADD = IconRegistry.register("add", new Icon(ICONS, 64, 0));
20+
public static final Icon DUPE = IconRegistry.register("dupe", new Icon(ICONS, 80, 0));
21+
public static final Icon REMOVE = IconRegistry.register("remove", new Icon(ICONS, 96, 0));
22+
public static final Icon POSE = IconRegistry.register("pose", new Icon(ICONS, 112, 0));
23+
public static final Icon FILTER = IconRegistry.register("filter", new Icon(ICONS, 128, 0));
24+
public static final Icon MOVE_UP = IconRegistry.register("move_up", new Icon(ICONS, 144, 0, 16, 8));
25+
public static final Icon MOVE_DOWN = IconRegistry.register("move_down", new Icon(ICONS, 144, 8, 16, 8));
26+
public static final Icon LOCKED = IconRegistry.register("locked", new Icon(ICONS, 160, 0));
27+
public static final Icon UNLOCKED = IconRegistry.register("unlocked", new Icon(ICONS, 176, 0));
28+
public static final Icon COPY = IconRegistry.register("copy", new Icon(ICONS, 192, 0));
29+
public static final Icon PASTE = IconRegistry.register("paste", new Icon(ICONS, 208, 0));
30+
public static final Icon CUT = IconRegistry.register("cut", new Icon(ICONS, 224, 0));
31+
public static final Icon REFRESH = IconRegistry.register("refresh", new Icon(ICONS, 240, 0));
3232

33-
public static final Icon DOWNLOAD = new Icon(ICONS, 0, 16);
34-
public static final Icon UPLOAD = new Icon(ICONS, 16, 16);
35-
public static final Icon SERVER = new Icon(ICONS, 32, 16);
36-
public static final Icon FOLDER = new Icon(ICONS, 48, 16);
37-
public static final Icon IMAGE = new Icon(ICONS, 64, 16);
38-
public static final Icon EDIT = new Icon(ICONS, 80, 16);
39-
public static final Icon MATERIAL = new Icon(ICONS, 96, 16);
40-
public static final Icon CLOSE = new Icon(ICONS, 112, 16);
41-
public static final Icon LIMB = new Icon(ICONS, 128, 16);
42-
public static final Icon CODE = new Icon(ICONS, 144, 16);
43-
public static final Icon MOVE_LEFT = new Icon(ICONS, 144, 16, 8, 16);
44-
public static final Icon MOVE_RIGHT = new Icon(ICONS, 152, 16, 8, 16);
45-
public static final Icon HELP = new Icon(ICONS, 160, 16);
46-
public static final Icon LEFT_HANDLE = new Icon(ICONS, 176, 16);
47-
public static final Icon MAIN_HANDLE = new Icon(ICONS, 192, 16);
48-
public static final Icon RIGHT_HANDLE = new Icon(ICONS, 208, 16);
49-
public static final Icon REVERSE = new Icon(ICONS, 224, 16);
50-
public static final Icon BLOCK = new Icon(ICONS, 240, 16);
33+
public static final Icon DOWNLOAD = IconRegistry.register("download", new Icon(ICONS, 0, 16));
34+
public static final Icon UPLOAD = IconRegistry.register("upload", new Icon(ICONS, 16, 16));
35+
public static final Icon SERVER = IconRegistry.register("server", new Icon(ICONS, 32, 16));
36+
public static final Icon FOLDER = IconRegistry.register("folder", new Icon(ICONS, 48, 16));
37+
public static final Icon IMAGE = IconRegistry.register("image", new Icon(ICONS, 64, 16));
38+
public static final Icon EDIT = IconRegistry.register("edit", new Icon(ICONS, 80, 16));
39+
public static final Icon MATERIAL = IconRegistry.register("material", new Icon(ICONS, 96, 16));
40+
public static final Icon CLOSE = IconRegistry.register("close", new Icon(ICONS, 112, 16));
41+
public static final Icon LIMB = IconRegistry.register("limb", new Icon(ICONS, 128, 16));
42+
public static final Icon CODE = IconRegistry.register("code", new Icon(ICONS, 144, 16));
43+
public static final Icon MOVE_LEFT = IconRegistry.register("move_left", new Icon(ICONS, 144, 16, 8, 16));
44+
public static final Icon MOVE_RIGHT = IconRegistry.register("move_right", new Icon(ICONS, 152, 16, 8, 16));
45+
public static final Icon HELP = IconRegistry.register("help", new Icon(ICONS, 160, 16));
46+
public static final Icon LEFT_HANDLE = IconRegistry.register("left_handle", new Icon(ICONS, 176, 16));
47+
public static final Icon MAIN_HANDLE = IconRegistry.register("main_handle", new Icon(ICONS, 192, 16));
48+
public static final Icon RIGHT_HANDLE = IconRegistry.register("right_handle", new Icon(ICONS, 208, 16));
49+
public static final Icon REVERSE = IconRegistry.register("reverse", new Icon(ICONS, 224, 16));
50+
public static final Icon BLOCK = IconRegistry.register("block", new Icon(ICONS, 240, 16));
5151

52-
public static final Icon FAVORITE = new Icon(ICONS, 0, 32);
53-
public static final Icon VISIBLE = new Icon(ICONS, 16, 32);
54-
public static final Icon INVISIBLE = new Icon(ICONS, 32, 32);
55-
public static final Icon PLAY = new Icon(ICONS, 48, 32);
56-
public static final Icon PAUSE = new Icon(ICONS, 64, 32);
57-
public static final Icon MAXIMIZE = new Icon(ICONS, 80, 32);
58-
public static final Icon MINIMIZE = new Icon(ICONS, 96, 32);
59-
public static final Icon STOP = new Icon(ICONS, 112, 32);
60-
public static final Icon FULLSCREEN = new Icon(ICONS, 128, 32);
61-
public static final Icon ALL_DIRECTIONS = new Icon(ICONS, 144, 32);
62-
public static final Icon SPHERE = new Icon(ICONS, 160, 32);
63-
public static final Icon SHIFT_TO = new Icon(ICONS, 176, 32);
64-
public static final Icon SHIFT_FORWARD = new Icon(ICONS, 192, 32);
65-
public static final Icon SHIFT_BACKWARD = new Icon(ICONS, 208, 32);
66-
public static final Icon MOVE_TO = new Icon(ICONS, 224, 32);
67-
public static final Icon GRAPH = new Icon(ICONS, 240, 32);
52+
public static final Icon FAVORITE = IconRegistry.register("favorite", new Icon(ICONS, 0, 32));
53+
public static final Icon VISIBLE = IconRegistry.register("visible", new Icon(ICONS, 16, 32));
54+
public static final Icon INVISIBLE = IconRegistry.register("invisible", new Icon(ICONS, 32, 32));
55+
public static final Icon PLAY = IconRegistry.register("play", new Icon(ICONS, 48, 32));
56+
public static final Icon PAUSE = IconRegistry.register("pause", new Icon(ICONS, 64, 32));
57+
public static final Icon MAXIMIZE = IconRegistry.register("maximize", new Icon(ICONS, 80, 32));
58+
public static final Icon MINIMIZE = IconRegistry.register("minimize", new Icon(ICONS, 96, 32));
59+
public static final Icon STOP = IconRegistry.register("stop", new Icon(ICONS, 112, 32));
60+
public static final Icon FULLSCREEN = IconRegistry.register("fullscreen", new Icon(ICONS, 128, 32));
61+
public static final Icon ALL_DIRECTIONS = IconRegistry.register("all_directions", new Icon(ICONS, 144, 32));
62+
public static final Icon SPHERE = IconRegistry.register("sphere", new Icon(ICONS, 160, 32));
63+
public static final Icon SHIFT_TO = IconRegistry.register("shift_to", new Icon(ICONS, 176, 32));
64+
public static final Icon SHIFT_FORWARD = IconRegistry.register("shift_forward", new Icon(ICONS, 192, 32));
65+
public static final Icon SHIFT_BACKWARD = IconRegistry.register("shift_backward", new Icon(ICONS, 208, 32));
66+
public static final Icon MOVE_TO = IconRegistry.register("move_to", new Icon(ICONS, 224, 32));
67+
public static final Icon GRAPH = IconRegistry.register("graph", new Icon(ICONS, 240, 32));
6868

69-
public static final Icon WRENCH = new Icon(ICONS, 0, 48);
70-
public static final Icon EXCLAMATION = new Icon(ICONS, 16, 48);
71-
public static final Icon LEFTLOAD = new Icon(ICONS, 32, 48);
72-
public static final Icon RIGHTLOAD = new Icon(ICONS, 48, 48);
73-
public static final Icon BUBBLE = new Icon(ICONS, 64, 48);
74-
public static final Icon FILE = new Icon(ICONS, 80, 48);
75-
public static final Icon PROCESSOR = new Icon(ICONS, 96, 48);
76-
public static final Icon MAZE = new Icon(ICONS, 112, 48);
77-
public static final Icon BOOKMARK = new Icon(ICONS, 128, 48);
78-
public static final Icon SOUND = new Icon(ICONS, 144, 48);
79-
public static final Icon SEARCH = new Icon(ICONS, 160, 48);
69+
public static final Icon WRENCH = IconRegistry.register("wrench", new Icon(ICONS, 0, 48));
70+
public static final Icon EXCLAMATION = IconRegistry.register("exclamation", new Icon(ICONS, 16, 48));
71+
public static final Icon LEFTLOAD = IconRegistry.register("leftload", new Icon(ICONS, 32, 48));
72+
public static final Icon RIGHTLOAD = IconRegistry.register("rightload", new Icon(ICONS, 48, 48));
73+
public static final Icon BUBBLE = IconRegistry.register("bubble", new Icon(ICONS, 64, 48));
74+
public static final Icon FILE = IconRegistry.register("file", new Icon(ICONS, 80, 48));
75+
public static final Icon PROCESSOR = IconRegistry.register("processor", new Icon(ICONS, 96, 48));
76+
public static final Icon MAZE = IconRegistry.register("maze", new Icon(ICONS, 112, 48));
77+
public static final Icon BOOKMARK = IconRegistry.register("bookmark", new Icon(ICONS, 128, 48));
78+
public static final Icon SOUND = IconRegistry.register("sound", new Icon(ICONS, 144, 48));
79+
public static final Icon SEARCH = IconRegistry.register("search", new Icon(ICONS, 160, 48));
8080

81-
public static final Icon CHECKBOARD = new Icon(ICONS, 0, 240, 16, 16);
82-
public static final Icon DISABLED = new Icon(ICONS, 16, 240, 16, 16);
83-
public static final Icon CURSOR = new Icon(ICONS, 32, 240, 16, 16);
81+
public static final Icon CHECKBOARD = IconRegistry.register("checkboard", new Icon(ICONS, 0, 240));
82+
public static final Icon DISABLED = IconRegistry.register("disabled", new Icon(ICONS, 16, 240));
83+
public static final Icon CURSOR = IconRegistry.register("cursor", new Icon(ICONS, 32, 240));
8484
}

0 commit comments

Comments
 (0)