-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiGateInterface.java
376 lines (287 loc) · 9.08 KB
/
GuiGateInterface.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/**
* 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.transport.gui;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Gate.GateKind;
import buildcraft.transport.Pipe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Iterator;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class GuiGateInterface extends GuiAdvancedInterface {
IInventory playerInventory;
private final ContainerGateInterface _container;
private int nbEntries;
class TriggerSlot extends AdvancedSlot {
Pipe pipe;
int slot;
public TriggerSlot(int x, int y, Pipe pipe, int slot) {
super(x, y);
this.pipe = pipe;
this.slot = slot;
}
@Override
public String getDescription() {
ITrigger trigger = pipe.gate.getTrigger(slot);
if (trigger != null)
return trigger.getDescription();
else
return "";
}
@SideOnly(Side.CLIENT)
@Override
public Icon getTexture() {
ITrigger trigger = pipe.gate.getTrigger(slot);
if (trigger != null)
return trigger.getIcon();
else
return null;
}
@Override
public boolean isDefined() {
return pipe.gate.getTrigger(slot) != null;
}
public ITrigger getTrigger() {
return pipe.gate.getTrigger(slot);
}
}
class ActionSlot extends AdvancedSlot {
Pipe pipe;
int slot;
public ActionSlot(int x, int y, Pipe pipe, int slot) {
super(x, y);
this.pipe = pipe;
this.slot = slot;
}
@Override
public String getDescription() {
IAction action = pipe.gate.getAction(slot);
if (action != null)
return action.getDescription();
else
return "";
}
@SideOnly(Side.CLIENT)
@Override
public Icon getTexture() {
IAction action = pipe.gate.getAction(slot);
if (action != null)
return action.getIcon();
else
return null;
}
@Override
public boolean isDefined() {
return pipe.gate.getAction(slot) != null;
}
public IAction getAction() {
return pipe.gate.getAction(slot);
}
}
class TriggerParameterSlot extends AdvancedSlot {
Pipe pipe;
int slot;
public TriggerParameterSlot(int x, int y, Pipe pipe, int slot) {
super(x, y);
this.pipe = pipe;
this.slot = slot;
}
@Override
public boolean isDefined() {
return pipe.gate.getTriggerParameter(slot) != null;
}
@Override
public ItemStack getItemStack() {
ITriggerParameter parameter = pipe.gate.getTriggerParameter(slot);
if (parameter != null)
return parameter.getItem();
else
return null;
}
public ITriggerParameter getTriggerParameter() {
return pipe.gate.getTriggerParameter(slot);
}
}
public GuiGateInterface(IInventory playerInventory, Pipe pipe) {
super(new ContainerGateInterface(playerInventory, pipe), null);
_container = (ContainerGateInterface) this.inventorySlots;
this.playerInventory = playerInventory;
xSize = 175;
ySize = 207;
int position = 0;
if (pipe.gate.kind == GateKind.Single) {
nbEntries = 1;
slots = new AdvancedSlot[2];
slots[0] = new TriggerSlot(65, 54, pipe, 0);
slots[1] = new ActionSlot(99, 54, pipe, 0);
} else if (pipe.gate.kind == GateKind.AND_2 || pipe.gate.kind == GateKind.OR_2) {
nbEntries = 2;
slots = new AdvancedSlot[4];
slots[0] = new TriggerSlot(65, 46, pipe, 0);
slots[1] = new TriggerSlot(65, 64, pipe, 1);
slots[2] = new ActionSlot(99, 46, pipe, 0);
slots[3] = new ActionSlot(99, 64, pipe, 1);
} else if (pipe.gate.kind == GateKind.AND_3 || pipe.gate.kind == GateKind.OR_3) {
nbEntries = 4;
slots = new AdvancedSlot[12];
for (int k = 0; k < 4; ++k) {
slots[position] = new TriggerSlot(60, 36 + 18 * k, pipe, position);
position++;
}
for (int k = 0; k < 4; ++k) {
slots[position] = new ActionSlot(112, 36 + 18 * k, pipe, position - 4);
position++;
}
for (int k = 0; k < 4; ++k) {
slots[position] = new TriggerParameterSlot(78, 36 + 18 * k, pipe, position - 8);
position++;
}
} else if (pipe.gate.kind == GateKind.AND_4 || pipe.gate.kind == GateKind.OR_4) {
nbEntries = 8;
slots = new AdvancedSlot[24];
for (int k = 0; k < 4; ++k) {
slots[position] = new TriggerSlot(8, 36 + 18 * k, pipe, position);
position++;
slots[position] = new TriggerSlot(100, 36 + 18 * k, pipe, position);
position++;
}
for (int k = 0; k < 4; ++k) {
slots[position] = new ActionSlot(60, 36 + 18 * k, pipe, position - 8);
position++;
slots[position] = new ActionSlot(152, 36 + 18 * k, pipe, position - 8);
position++;
}
for (int k = 0; k < 4; ++k) {
slots[position] = new TriggerParameterSlot(26, 36 + 18 * k, pipe, position - 16);
position++;
slots[position] = new TriggerParameterSlot(118, 36 + 18 * k, pipe, position - 16);
position++;
}
}
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
String name = _container.getGateName();
fontRenderer.drawString(name, getCenteredOffset(name), 15, 0x404040);
fontRenderer.drawString(StringUtils.localize("gui.inventory"), 8, ySize - 97, 0x404040);
drawForegroundSelection(par1, par2);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
_container.synchronize();
ResourceLocation texture = _container.getGateGuiFile();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.func_110577_a(texture);
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
int triggerTracker = 0;
for (int s = 0; s < slots.length; ++s) {
AdvancedSlot slot = slots[s];
if (slot instanceof TriggerSlot) {
ITrigger trigger = ((TriggerSlot) slot).getTrigger();
if (_container.getGateOrdinal() >= GateKind.AND_3.ordinal()) {
if (_container.triggerState[triggerTracker++]) {
mc.renderEngine.func_110577_a(texture);
drawTexturedModalRect(cornerX + slot.x + 35, cornerY + slot.y + 6, 176, 18, 18, 4);
}
if (trigger == null || !trigger.hasParameter()) {
mc.renderEngine.func_110577_a(texture);
drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y - 1, 176, 0, 18, 18);
}
} else if (_container.triggerState[triggerTracker++]) {
mc.renderEngine.func_110577_a(texture);
drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y + 6, 176, 18, 18, 4);
}
}
}
drawBackgroundSlots();
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
int position = getSlotAtLocation(i - cornerX, j - cornerY);
AdvancedSlot slot = null;
if (position < 0)
return;
slot = slots[position];
if (slot instanceof TriggerSlot && _container.hasTriggers()) {
TriggerSlot triggerSlot = (TriggerSlot) slot;
ITrigger changed = null;
if (triggerSlot.getTrigger() == null) {
if (k == 0) {
changed = _container.getFirstTrigger();
} else {
changed = _container.getLastTrigger();
}
} else {
Iterator<ITrigger> it = _container.getTriggerIterator(k != 0);
for (; it.hasNext();) {
ITrigger trigger = it.next();
if (!it.hasNext()) {
changed = null;
break;
}
if (trigger == triggerSlot.getTrigger()) {
changed = it.next();
break;
}
}
}
_container.setTrigger(position, changed, true);
if (_container.getGateOrdinal() >= GateKind.AND_3.ordinal()) {
_container.setTriggerParameter(position, null, true);
}
} else if (slot instanceof ActionSlot) {
ActionSlot actionSlot = (ActionSlot) slot;
IAction changed = null;
if (actionSlot.getAction() == null) {
if (k == 0) {
changed = _container.getFirstAction();
} else {
changed = _container.getLastAction();
}
} else {
Iterator<IAction> it = _container.getActionIterator(k != 0);
for (; it.hasNext();) {
IAction action = it.next();
if (!it.hasNext()) {
changed = null;
break;
}
if (action == actionSlot.getAction()) {
changed = it.next();
break;
}
}
}
_container.setAction(position - nbEntries, changed, true);
} else if (slot instanceof TriggerParameterSlot) {
TriggerSlot trigger = (TriggerSlot) slots[position - nbEntries * 2];
if (trigger.isDefined() && trigger.getTrigger().hasParameter()) {
ITriggerParameter param = trigger.getTrigger().createParameter();
if (param != null) {
param.set(mc.thePlayer.inventory.getItemStack());
_container.setTriggerParameter(position - nbEntries * 2, param, true);
}
}
}
_container.markDirty();
}
}