-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiUrbanist.java
executable file
·185 lines (138 loc) · 4.51 KB
/
GuiUrbanist.java
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
* 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.builders.urbanism;
import buildcraft.core.DefaultProps;
import buildcraft.core.gui.GuiAdvancedInterface;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class GuiUrbanist extends GuiAdvancedInterface {
private static final ResourceLocation TOOLBAR_TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/urbanist_tools.png");
private static final int TOOLBAR_TEXTURE_WIDTH = 194;
private static final int TOOLBAR_TEXTURE_HEIGHT = 27;
IInventory playerInventory;
public TileUrbanist urbanist;
int selectedTool = -1;
class ToolSlot extends AdvancedSlot {
UrbanistTool tool;
public ToolSlot(UrbanistTool tool) {
super(0, 0);
this.tool = tool;
}
@SideOnly(Side.CLIENT)
@Override
public Icon getIcon() {
return tool.getIcon();
}
@Override
public String getDescription() {
return tool.getDescription();
}
}
public UrbanistTool [] tools = new UrbanistTool [10];
public GuiUrbanist(IInventory playerInventory, TileUrbanist urbanist) {
super(new ContainerUrbanist(playerInventory, urbanist), urbanist, TOOLBAR_TEXTURE);
xSize = width;
ySize = height;
this.playerInventory = playerInventory;
this.urbanist = urbanist;
slots = new AdvancedSlot[0];
urbanist.createUrbanistEntity();
tools [0] = new UrbanistToolBlock();
tools [1] = new UrbanistToolErase();
tools [2] = new UrbanistToolArea();
tools [3] = new UrbanistToolPath();
tools [4] = new UrbanistToolFiller();
tools [5] = new UrbanistToolBlueprint();
tools [6] = new UrbanistTool();
tools [7] = new UrbanistTool();
tools [8] = new UrbanistTool();
tools [9] = new UrbanistTool();
slots = new AdvancedSlot[10];
for (int i = 0; i < 10; ++i) {
slots [i] = new ToolSlot(tools [i]);
}
}
@Override
public void drawDefaultBackground() {
// cancels the dark background
}
@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
xSize = width;
ySize = height;
guiLeft = 0;
guiTop = 0;
super.drawScreen(mouseX, mouseY, par3);
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
super.drawGuiContainerForegroundLayer(par1, par2);
drawForegroundSelection(par1, par2);
if (selectedTool != -1) {
tools [selectedTool].drawGuiContainerForegroundLayer(this, par1, par2);
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int cornerX = (width - TOOLBAR_TEXTURE_WIDTH) / 2;
int cornerY = height - TOOLBAR_TEXTURE_HEIGHT;
mc.renderEngine.bindTexture(TOOLBAR_TEXTURE);
drawTexturedModalRect(cornerX, cornerY, 0, 0, TOOLBAR_TEXTURE_WIDTH, TOOLBAR_TEXTURE_HEIGHT);
for (int i = 0; i < 10; ++i) {
slots [i].x = cornerX + 8 + i * 18;
slots [i].y = cornerY + 8;
}
if (selectedTool != -1) {
tools [selectedTool].drawGuiContainerBackgroundLayer(this, f, x, y);
}
drawBackgroundSlots();
if (selectedTool != -1) {
mc.renderEngine.bindTexture(TOOLBAR_TEXTURE);
drawTexturedModalRect(cornerX + 8 + selectedTool * 18, cornerY + 8, 194, 0, 18, 18);
}
}
@Override
public void onGuiClosed() {
urbanist.destroyUrbanistEntity();
}
private boolean interfaceClicked (int mouseX, int mouseY) {
int cornerX = (width - TOOLBAR_TEXTURE_WIDTH) / 2;
int cornerY = height - TOOLBAR_TEXTURE_HEIGHT;
if (mouseX >= cornerX && mouseX <= cornerX + TOOLBAR_TEXTURE_WIDTH
&& mouseY >= cornerY && mouseY <= cornerY + TOOLBAR_TEXTURE_HEIGHT) {
return true;
}
if (selectedTool != -1 && tools [selectedTool].interfaceClicked(mouseX, mouseY)) {
return true;
}
return false;
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
if (!interfaceClicked(mouseX, mouseY)) {
if (selectedTool != -1) {
tools [selectedTool].worldClicked(this, urbanist.urbanist.mouseClick());
}
return;
}
int clicked = getSlotAtLocation(mouseX, mouseY);
if (clicked != -1 && clicked < 10) {
selectedTool = clicked;
}
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
}