-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiUrbanist.java
executable file
·218 lines (166 loc) · 5.31 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* 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 org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.core.DefaultProps;
import buildcraft.core.gui.AdvancedSlot;
import buildcraft.core.gui.GuiAdvancedInterface;
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;
public TileUrbanist urbanist;
public UrbanistTool[] tools = new UrbanistTool[10];
private IInventory playerInventory;
private int selectedTool = -1;
class ToolSlot extends AdvancedSlot {
UrbanistTool tool;
public ToolSlot(UrbanistTool tool) {
super(GuiUrbanist.this, 0, 0);
this.tool = tool;
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon() {
return tool.getIcon();
}
@Override
public String getDescription() {
return tool.getDescription();
}
}
public GuiUrbanist(IInventory playerInventory, TileUrbanist urbanist) {
super(new ContainerUrbanist(playerInventory, urbanist), urbanist, TOOLBAR_TEXTURE);
xSize = width;
ySize = height;
this.playerInventory = playerInventory;
this.urbanist = urbanist;
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();
for (int i = 0; i < 10; ++i) {
slots.add(new ToolSlot(tools[i]));
}
for (UrbanistTool t : tools) {
t.createSlots(this, slots);
}
}
@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);
drawTooltipForSlotAt(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.get(i).x = cornerX + 8 + i * 18;
slots.get(i).y = cornerY + 8;
}
if (selectedTool != -1) {
tools [selectedTool].drawGuiContainerBackgroundLayer(this, f, x, y);
}
drawBackgroundSlots();
if (selectedTool != -1) {
tools [selectedTool].drawSelection(this, f, x, y);
}
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 onInterface (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].onInterface(mouseX, mouseY)) {
return true;
}
return false;
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
if (!onInterface(mouseX, mouseY)) {
if (selectedTool != -1) {
tools [selectedTool].worldClicked(this, urbanist.urbanist.rayTraceMouse());
}
return;
}
int clicked = getSlotIndexAtLocation(mouseX, mouseY);
if (clicked != -1 && clicked < 10) {
if (clicked != selectedTool) {
if (selectedTool != -1) {
tools [selectedTool].hide();
}
selectedTool = clicked;
tools [selectedTool].show();
}
}
if (clicked != -1) {
slots.get(clicked).selected();
}
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
public void handleMouseInput() {
super.handleMouseInput();
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
if (onInterface(x, x)) {
return;
}
if (selectedTool != -1) {
tools [selectedTool].worldMoved(this, urbanist.urbanist.rayTraceMouse());
}
}
}