-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiList.java
executable file
·226 lines (176 loc) · 5.98 KB
/
GuiList.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
/**
* Copyright (c) 2011-2015, 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.core.gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import buildcraft.BuildCraftCore;
import buildcraft.core.ItemList;
import buildcraft.core.lib.gui.AdvancedSlot;
import buildcraft.core.lib.gui.GuiAdvancedInterface;
public class GuiList extends GuiAdvancedInterface {
private static final ResourceLocation TEXTURE_BASE = new ResourceLocation(
"buildcraftcore:textures/gui/list.png");
private GuiTextField textField;
private EntityPlayer player;
private static class MainSlot extends AdvancedSlot {
public int lineIndex;
public MainSlot(GuiAdvancedInterface gui, int x, int y, int iLineIndex) {
super(gui, x, y);
lineIndex = iLineIndex;
}
@Override
public ItemStack getItemStack() {
ContainerList container = (ContainerList) gui.getContainer();
if (container.lines[lineIndex].getStack(0) != null) {
return container.lines[lineIndex].getStack(0);
} else {
return null;
}
}
}
private static class SecondarySlot extends AdvancedSlot {
public int lineIndex;
public int slotIndex;
public SecondarySlot(GuiAdvancedInterface gui, int x, int y, int iLineIndex, int iSlotIndex) {
super(gui, x, y);
lineIndex = iLineIndex;
slotIndex = iSlotIndex;
}
@Override
public ItemStack getItemStack() {
ContainerList container = (ContainerList) gui.getContainer();
if (slotIndex == 6 && container.lines[lineIndex].getStack(7) != null) {
return null;
}
if (container.lines[lineIndex].getStack(slotIndex) != null) {
return container.lines[lineIndex].getStack(slotIndex);
} else {
return null;
}
}
}
private static class Button extends AdvancedSlot {
public int line;
public int kind;
private String desc;
public Button(GuiAdvancedInterface gui, int x, int y, int iLine, int iKind, String iDesc) {
super(gui, x, y);
line = iLine;
kind = iKind;
desc = iDesc;
}
@Override
public String getDescription() {
return desc;
}
}
public GuiList(EntityPlayer iPlayer) {
super(new ContainerList(iPlayer), iPlayer.inventory, TEXTURE_BASE);
xSize = 176;
ySize = 241;
for (int sy = 0; sy < 6; ++sy) {
slots.add(new MainSlot(this, 44, 31 + sy * 18, sy));
for (int sx = 1; sx < 7; ++sx) {
slots.add(new SecondarySlot(this, 44 + sx * 18, 31 + sy * 18, sy, sx));
}
slots.add(new Button(this, 8, 31 + sy * 18, sy, 0, "gui.list.metadata"));
slots.add(new Button(this, 26, 31 + sy * 18, sy, 1, "gui.list.oredict"));
}
player = iPlayer;
}
@Override
public void initGui() {
super.initGui();
textField = new GuiTextField(this.fontRendererObj, 10, 10, 156, 12);
textField.setMaxStringLength(32);
textField.setText(BuildCraftCore.listItem.getLabel(player.getCurrentEquippedItem()));
textField.setFocused(false);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
super.drawGuiContainerBackgroundLayer(f, x, y);
ContainerList container = (ContainerList) getContainer();
bindTexture(TEXTURE_BASE);
for (int i = 0; i < 6; ++i) {
if (container.lines[i].subitemsWildcard) {
drawTexturedModalRect(guiLeft + 7, guiTop + 30 + 18 * i, 194, 18, 18, 18);
} else {
drawTexturedModalRect(guiLeft + 7, guiTop + 30 + 18 * i, 194, 0, 18, 18);
}
if (container.lines[i].isOre) {
if (container.lines[i].oreWildcard) {
drawTexturedModalRect(guiLeft + 25, guiTop + 30 + 18 * i, 176, 18, 18, 18);
} else {
drawTexturedModalRect(guiLeft + 25, guiTop + 30 + 18 * i, 176, 0, 18, 18);
}
}
if (container.lines[i].subitemsWildcard || container.lines[i].oreWildcard) {
for (int j = 0; j < 6; ++j) {
drawTexturedModalRect(guiLeft + 62 + 18 * j, guiTop + 31 + 18 * i, 195, 37, 16, 16);
}
}
}
drawBackgroundSlots();
bindTexture(TEXTURE_BASE);
for (int i = 0; i < 6; ++i) {
if (container.lines[i].getStack(7) != null) {
drawTexturedModalRect(guiLeft + 152, guiTop + 31 + 18 * i, 177, 37, 16, 16);
}
}
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
super.drawGuiContainerForegroundLayer(par1, par2);
textField.drawTextBox();
drawTooltipForSlotAt(par1, par2);
}
private boolean isCarryingList() {
ItemStack stack = mc.thePlayer.inventory.getItemStack();
return stack != null && stack.getItem() instanceof ItemList;
}
private boolean hasListEquipped() {
return mc.thePlayer.getCurrentEquippedItem() != null && mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemList;
}
@Override
protected void mouseClicked(int x, int y, int b) {
super.mouseClicked(x, y, b);
if (isCarryingList() || !hasListEquipped()) {
return;
}
AdvancedSlot slot = getSlotAtLocation(x, y);
ContainerList container = (ContainerList) getContainer();
if (slot instanceof MainSlot) {
container.setStack(((MainSlot) slot).lineIndex, 0, mc.thePlayer.inventory.getItemStack());
} else if (slot instanceof SecondarySlot) {
container.setStack(((SecondarySlot) slot).lineIndex, ((SecondarySlot) slot).slotIndex,
mc.thePlayer.inventory.getItemStack());
} else if (slot instanceof Button) {
Button button = (Button) slot;
container.switchButton(button.line, button.kind);
}
textField.mouseClicked(x - guiLeft, y - guiTop, b);
}
@Override
protected void keyTyped(char c, int i) {
if (textField.isFocused()) {
if (c == 13 || c == 27) {
textField.setFocused(false);
} else {
textField.textboxKeyTyped(c, i);
((ContainerList) container).setLabel(textField.getText());
// RPCHandler.rpcServer(architect, "handleClientSetName",
// textField.getText());
}
} else {
super.keyTyped(c, i);
}
}
}