-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiBlueprintLibrary.java
146 lines (118 loc) · 4.15 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
/**
* 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.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import buildcraft.BuildCraftBuilders;
import buildcraft.builders.TileBlueprintLibrary;
import buildcraft.builders.blueprints.BlueprintId;
import buildcraft.builders.blueprints.BlueprintId.Kind;
import buildcraft.core.DefaultProps;
import buildcraft.core.gui.GuiBuildCraft;
import buildcraft.core.utils.StringUtils;
public class GuiBlueprintLibrary extends GuiBuildCraft {
private static final ResourceLocation TEXTURE = new ResourceLocation(
"buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/library_rw.png");
EntityPlayer player;
TileBlueprintLibrary library;
ContainerBlueprintLibrary container;
boolean computeInput;
public GuiBlueprintLibrary(EntityPlayer player, TileBlueprintLibrary library) {
super(new ContainerBlueprintLibrary(player, library), library, TEXTURE);
this.player = player;
xSize = 176;
ySize = 225;
this.library = library;
container = (ContainerBlueprintLibrary) inventorySlots;
}
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, ">");
buttonList.add(prevPageButton);
buttonList.add(nextPageButton);
deleteButton = new GuiButton(2, j + 100, k + 114, 25, 20, StringUtils.localize("gui.del"));
buttonList.add(deleteButton);
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
String title = StringUtils.localize("tile.libraryBlock.name");
fontRendererObj.drawString(title, getCenteredOffset(title), 6, 0x404040);
int c = 0;
for (BlueprintId bpt : library.currentPage) {
String name = bpt.name;
if (name.length() > BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE) {
name = name.substring(0, BuildCraftBuilders.MAX_BLUEPRINTS_NAME_SIZE);
}
if (c == library.selected) {
int l1 = 8;
int i2 = 24;
if (bpt.kind == Kind.Blueprint) {
drawGradientRect(l1, i2 + 9 * c, l1 + 88, i2 + 9 * (c + 1), 0xFFA0A0FF, 0xFFA0A0FF);
} else {
drawGradientRect(l1, i2 + 9 * c, l1 + 88, i2 + 9 * (c + 1), 0x80ffffff, 0x80ffffff);
}
}
if (bpt.kind == Kind.Blueprint) {
fontRendererObj.drawString(name, 9, 25 + 9 * c, 0x1000FF);
} else {
fontRendererObj.drawString(name, 9, 25 + 9 * c, 0x000000);
}
c++;
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(TEXTURE);
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
protected void actionPerformed(GuiButton button) {
if (button == nextPageButton) {
library.pageNext();
} else if (button == prevPageButton) {
library.pagePrev();
} else if (deleteButton != null && button == deleteButton) {
library.deleteSelectedBpt();
}
}
@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.currentPage.size()) {
library.selectBlueprint(ySlot);
}
}
}
}
}