-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiBlueprintLibrary.java
182 lines (149 loc) · 5.5 KB
/
GuiBlueprintLibrary.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
/**
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.gui.GuiButton;
import org.lwjgl.opengl.GL11;
import buildcraft.BuildCraftBuilders;
import buildcraft.builders.TileBlueprintLibrary;
import buildcraft.builders.network.PacketLibraryAction;
import buildcraft.core.DefaultProps;
import buildcraft.core.blueprints.BptPlayerIndex;
import buildcraft.core.gui.GuiBuildCraft;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.StringUtil;
public class GuiBlueprintLibrary extends GuiBuildCraft {
EntityPlayer player;
TileBlueprintLibrary library;
ContainerBlueprintLibrary container;
boolean computeInput;
BptPlayerIndex index;
public GuiBlueprintLibrary(EntityPlayer player, TileBlueprintLibrary library) {
super(new ContainerBlueprintLibrary(player, library), library);
this.player = player;
xSize = 176;
ySize = 225;
this.library = library;
container = (ContainerBlueprintLibrary) inventorySlots;
index = BuildCraftBuilders.getPlayerIndex(player.username);
}
private GuiButton nextPageButton;
private GuiButton prevPageButton;
private GuiButton lockButton;
private GuiButton deleteButton;
@SuppressWarnings("unchecked")
@Override
public void initGui() {
super.initGui();
int j = (width - xSize) / 2;
int k = (height - ySize) / 2;
prevPageButton = new GuiButton(0, j + 100, k + 23, 20, 20, "<");
nextPageButton = new GuiButton(1, j + 122, k + 23, 20, 20, ">");
controlList.add(prevPageButton);
controlList.add(nextPageButton);
// if (library.owner.equals(player.username)) {
deleteButton = new GuiButton(2, j + 100, k + 114, 25, 20, StringUtil.localize("gui.del"));
controlList.add(deleteButton);
lockButton = new GuiButton(3, j + 127, k + 114, 40, 20, StringUtil.localize("gui.lock"));
controlList.add(lockButton);
if (library.locked) {
lockButton.displayString = StringUtil.localize("gui.unlock");
} else {
lockButton.displayString = StringUtil.localize("gui.lock");
}
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
// fontRenderer.drawString(library.owner + "'s Library", 6, 6,
// 0x404040);
String title = StringUtil.localize("tile.libraryBlock");
fontRenderer.drawString(title, getCenteredOffset(title), 6, 0x404040);
int c = 0;
String[] currentNames = library.currentNames;
for (int i = 0; i < currentNames.length; i++) {
String name = currentNames[i];
if(name == null) break;
if(name.length() > BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE){
name = name.substring(0, BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
}
if (i == library.selected) {
int l1 = 8;
int i2 = 24;
drawGradientRect(l1, i2 + 9 * c, l1 + 88, i2 + 9 * (c + 1), 0x80ffffff, 0x80ffffff);
}
fontRenderer.drawString(name, 9, 25 + 9 * c, 0x404040);
c++;
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
int i = 0;
// if (library.owner.equals(player.username)) {
i = mc.renderEngine.getTexture(DefaultProps.TEXTURE_PATH_GUI + "/library_rw.png");
// } else {
// i = mc.renderEngine
// .getTexture("/net/minecraft/src/buildcraft/builders/gui/library_r.png");
// }
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(i);
int j = (width - xSize) / 2;
int k = (height - ySize) / 2;
drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
int inP = (int) (library.progressIn / 100.0 * 22.0);
int outP = (int) (library.progressOut / 100.0 * 22.0);
drawTexturedModalRect(j + 128 + 22 - inP, k + 61, 176 + 22 - inP, 16, inP, 16);
drawTexturedModalRect(j + 128, k + 78, 176, 0, outP, 16);
}
@Override
public void updateScreen(){
if (library.locked) {
lockButton.displayString = StringUtil.localize("gui.unlock");
} else {
lockButton.displayString = StringUtil.localize("gui.lock");
}
}
@Override
protected void actionPerformed(GuiButton button) {
PacketLibraryAction packet = new PacketLibraryAction(PacketIds.LIBRARY_ACTION,
library.xCoord, library.yCoord, library.zCoord);
if (button == nextPageButton) {
packet.actionId = TileBlueprintLibrary.COMMAND_NEXT;
} else if (button == prevPageButton) {
packet.actionId = TileBlueprintLibrary.COMMAND_PREV;
} else if (lockButton != null && button == lockButton) {
packet.actionId = TileBlueprintLibrary.COMMAND_LOCK_UPDATE;
} else if (deleteButton != null && button == deleteButton) {
packet.actionId = TileBlueprintLibrary.COMMAND_DELETE;
}
CoreProxy.proxy.sendToServer(packet.getPacket());
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
int xMin = (width - xSize) / 2;
int yMin = (height - ySize) / 2;
int x = i - xMin;
int y = j - yMin;
if (x >= 8 && x <= 88) {
int ySlot = (y - 24) / 9;
if (ySlot >= 0 && ySlot <= 11){
if (ySlot < library.currentNames.length){
PacketPayload payload = new PacketPayload();
payload.intPayload = new int[]{ySlot};
PacketLibraryAction packet = new PacketLibraryAction(PacketIds.LIBRARY_SELECT,
library.xCoord, library.yCoord, library.zCoord);
packet.actionId = ySlot;
CoreProxy.proxy.sendToServer(packet.getPacket());
}
}
}
}
}