-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiMap.java
executable file
·156 lines (119 loc) · 4.02 KB
/
GuiMap.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
/**
* 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.commander;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import buildcraft.core.BCDynamicTexture;
import buildcraft.core.DefaultProps;
import buildcraft.core.MapArea;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.network.RPCHandler;
public class GuiMap extends GuiAdvancedInterface {
private static final int MAP_WIDTH = 300;
private static final int MAP_HEIGHT = 200;
private TileMap map;
private BCDynamicTexture newSelection;
private int selX1 = 0,
selX2 = 0,
selY1 = 0,
selY2 = 0;
private boolean inSelection = false;
private MapArea areaSelection;
private BCDynamicTexture currentSelection;
private static final ResourceLocation TMP_TEXTURE = new ResourceLocation("buildcraft",
DefaultProps.TEXTURE_PATH_GUI + "/builder_blueprint.png");
private int mapXMin = 0;
private int mapYMin = 0;
private int zoomLevel = 1;
private int cx;
private int cz;
public GuiMap(IInventory inventory, TileMap iMap) {
super(new ContainerMap(0), inventory, TMP_TEXTURE);
map = iMap;
map.bcTexture = new BCDynamicTexture(MAP_WIDTH, MAP_HEIGHT);
map.bcTexture.createDynamicTexture();
newSelection = new BCDynamicTexture(1, 1);
newSelection.createDynamicTexture();
newSelection.setColor(0, 0, 1, 0, 0, 0.4F);
areaSelection = new MapArea();
cx = map.xCoord;
cz = map.zCoord;
uploadMap();
}
private void uploadMap() {
RPCHandler.rpcServer(map, "computeMap", cx, cz, map.bcTexture.width, map.bcTexture.height,
zoomLevel);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
mapXMin = (width - map.bcTexture.width) / 2;
mapYMin = (height - map.bcTexture.height) / 2;
map.bcTexture.drawMap(mapXMin, mapYMin, zLevel);
newSelection.updateDynamicTexture();
if (selX2 != 0) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_BLEND);
int x1 = selX1 < selX2 ? selX1 : selX2;
int x2 = selX1 < selX2 ? selX2 : selX1;
int y1 = selY1 < selY2 ? selY1 : selY2;
int y2 = selY1 < selY2 ? selY2 : selY1;
drawTexturedModalRect(x1, y1, 0, 0, x2 - x1 + 1, y2 - y1 + 1);
GL11.glPopAttrib();
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
int blocksX = (mouseX - mapXMin) * zoomLevel;
int blocksZ = (mouseY - mapYMin) * zoomLevel;
int blockStartX = cx - MAP_WIDTH * zoomLevel / 2;
int blockStartZ = cz - MAP_HEIGHT * zoomLevel / 2;
boolean clickOnMap = mouseX >= mapXMin
&& mouseX <= mapXMin + map.bcTexture.width && mouseY >= mapYMin &&
mouseY <= mapYMin + map.bcTexture.height;
if (clickOnMap) {
cx = blockStartX + blocksX;
cz = blockStartZ + blocksZ;
uploadMap();
}
/*
* if (inSelection) { inSelection = false; } else if (mouseX >= mapXMin
* && mouseX <= mapXMin + map.bcTexture.width && mouseY >= mapYMin &&
* mouseY <= mapYMin + map.bcTexture.height) {
*
* inSelection = true; selX1 = mouseX; selY1 = mouseY; selX2 = 0; selY2
* = 0; }
*/
}
@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 (inSelection
&& x >= mapXMin && x <= mapXMin + map.bcTexture.width
&& y >= mapYMin && y <= mapYMin + map.bcTexture.height) {
selX2 = x;
selY2 = y;
}
}
@Override
protected void keyTyped(char carac, int val) {
super.keyTyped(carac, val);
if (carac == 'z' && zoomLevel > 1) {
zoomLevel--;
uploadMap();
} else if (carac == 'Z' && zoomLevel < 6) {
zoomLevel++;
uploadMap();
}
}
}