the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "AchievementScreen.h"
3#include "SmallButton.h"
4#include "Options.h"
5#include "KeyMapping.h"
6#include "Font.h"
7#include "Lighting.h"
8#include "Textures.h"
9#include "StatsCounter.h"
10#include "ItemRenderer.h"
11#include "..\Minecraft.World\System.h"
12#include "..\Minecraft.World\net.minecraft.locale.h"
13#include "..\Minecraft.World\net.minecraft.world.level.tile.h"
14#include "..\Minecraft.World\JavaMath.h"
15
16
17
18AchievementScreen::AchievementScreen(StatsCounter *statsCounter)
19{
20 // 4J - added initialisers
21 imageWidth = 256;
22 imageHeight = 202;
23 xLastScroll = 0;
24 yLastScroll = 0;
25 scrolling = 0;
26
27 // 4J - TODO - investigate - these were static final ints before, but based on members of Achievements which
28 // aren't final Or actually initialised
29 xMin = Achievements::xMin * ACHIEVEMENT_COORD_SCALE - BIGMAP_WIDTH / 2;
30 yMin = Achievements::yMin * ACHIEVEMENT_COORD_SCALE - BIGMAP_WIDTH / 2;
31 xMax = Achievements::xMax * ACHIEVEMENT_COORD_SCALE - BIGMAP_HEIGHT / 2;
32 yMax = Achievements::yMax * ACHIEVEMENT_COORD_SCALE - BIGMAP_HEIGHT / 2;
33
34 this->statsCounter = statsCounter;
35 int wBigMap = 141;
36 int hBigMap = 141;
37
38 xScrollO = xScrollP = xScrollTarget = Achievements::openInventory->x * ACHIEVEMENT_COORD_SCALE - wBigMap / 2 - 12;
39 yScrollO = yScrollP = yScrollTarget = Achievements::openInventory->y * ACHIEVEMENT_COORD_SCALE - hBigMap / 2;
40
41}
42
43void AchievementScreen::init()
44{
45 buttons.clear();
46// buttons.add(new SmallButton(0, width / 2 - 80 - 24, height / 2 + 74, 110, 20, I18n.get("gui.achievements")));
47 buttons.push_back(new SmallButton(1, width / 2 + 24, height / 2 + 74, 80, 20, I18n::get(L"gui.done")));
48
49}
50
51void AchievementScreen::buttonClicked(Button *button)
52{
53 if (button->id == 1)
54 {
55 minecraft->setScreen(NULL);
56// minecraft->grabMouse(); // 4J removed
57 }
58 Screen::buttonClicked(button);
59}
60
61void AchievementScreen::keyPressed(char eventCharacter, int eventKey)
62{
63 if (eventKey == minecraft->options->keyBuild->key)
64 {
65 minecraft->setScreen(NULL);
66// minecraft->grabMouse(); // 4J removed
67 }
68 else
69 {
70 Screen::keyPressed(eventCharacter, eventKey);
71 }
72}
73
74void AchievementScreen::render(int mouseX, int mouseY, float a)
75{
76 if (Mouse::isButtonDown(0))
77 {
78 int xo = (width - imageWidth) / 2;
79 int yo = (height - imageHeight) / 2;
80
81 int xBigMap = xo + 8;
82 int yBigMap = yo + 17;
83
84 if (scrolling == 0 || scrolling == 1)
85 {
86 if (mouseX >= xBigMap && mouseX < xBigMap + BIGMAP_WIDTH && mouseY >= yBigMap && mouseY < yBigMap + BIGMAP_HEIGHT)
87 {
88 if (scrolling == 0)
89 {
90 scrolling = 1;
91 }
92 else
93 {
94 xScrollP -= mouseX - xLastScroll;
95 yScrollP -= mouseY - yLastScroll;
96 xScrollTarget = xScrollO = xScrollP;
97 yScrollTarget = yScrollO = yScrollP;
98 }
99 xLastScroll = mouseX;
100 yLastScroll = mouseY;
101 }
102 }
103
104 if (xScrollTarget < xMin) xScrollTarget = xMin;
105 if (yScrollTarget < yMin) yScrollTarget = yMin;
106 if (xScrollTarget >= xMax) xScrollTarget = xMax - 1;
107 if (yScrollTarget >= yMax) yScrollTarget = yMax - 1;
108 }
109 else
110 {
111 scrolling = 0;
112 }
113
114 renderBackground();
115
116 renderBg(mouseX, mouseY, a);
117
118 glDisable(GL_LIGHTING);
119 glDisable(GL_DEPTH_TEST);
120
121 renderLabels();
122
123 glEnable(GL_LIGHTING);
124 glEnable(GL_DEPTH_TEST);
125
126}
127
128void AchievementScreen::tick()
129{
130 xScrollO = xScrollP;
131 yScrollO = yScrollP;
132
133 double xd = (xScrollTarget - xScrollP);
134 double yd = (yScrollTarget - yScrollP);
135 if (xd * xd + yd * yd < 4)
136 {
137 xScrollP += xd;
138 yScrollP += yd;
139 }
140 else
141 {
142 xScrollP += xd * 0.85;
143 yScrollP += yd * 0.85;
144 }
145}
146
147void AchievementScreen::renderLabels()
148{
149 int xo = (width - imageWidth) / 2;
150 int yo = (height - imageHeight) / 2;
151 font->draw(L"Achievements", xo + 15, yo + 5, 0x404040);
152
153// font.draw(xScrollP + ", " + yScrollP, xo + 5, yo + 5 + BIGMAP_HEIGHT + 18, 0x404040);
154// font.drawWordWrap("Ride a pig off a cliff.", xo + 5, yo + 5 + BIGMAP_HEIGHT + 16, BIGMAP_WIDTH, 0x404040);
155
156}
157
158void AchievementScreen::renderBg(int xm, int ym, float a)
159{
160 // 4J Unused
161#if 0
162 int xScroll = Mth::floor(xScrollO + (xScrollP - xScrollO) * a);
163 int yScroll = Mth::floor(yScrollO + (yScrollP - yScrollO) * a);
164
165 if (xScroll < xMin) xScroll = xMin;
166 if (yScroll < yMin) yScroll = yMin;
167 if (xScroll >= xMax) xScroll = xMax - 1;
168 if (yScroll >= yMax) yScroll = yMax - 1;
169
170
171 int terrainTex = minecraft->textures->loadTexture(L"/terrain.png");
172 int tex = minecraft->textures->loadTexture(L"/achievement/bg.png");
173
174 int xo = (width - imageWidth) / 2;
175 int yo = (height - imageHeight) / 2;
176
177 int xBigMap = xo + BIGMAP_X;
178 int yBigMap = yo + BIGMAP_Y;
179
180 blitOffset = 0;
181// glDisable(GL_DEPTH_TEST);
182 glDepthFunc(GL_GEQUAL);
183 glPushMatrix();
184 glTranslatef(0, 0, -200);
185
186 {
187 glEnable(GL_TEXTURE_2D);
188 glDisable(GL_LIGHTING);
189 glEnable(GL_RESCALE_NORMAL);
190 glEnable(GL_COLOR_MATERIAL);
191
192 minecraft->textures->bind(terrainTex);
193
194 int leftTile = (xScroll + EDGE_VALUE_X) >> 4;
195 int topTile = (yScroll + EDGE_VALUE_Y) >> 4;
196 int xMod = (xScroll + EDGE_VALUE_X) % 16;
197 int yMod = (yScroll + EDGE_VALUE_Y) % 16;
198
199 const int rockLevel = (Achievements::ACHIEVEMENT_HEIGHT_POSITION * 4) / 10;
200 const int coalLevel = (Achievements::ACHIEVEMENT_HEIGHT_POSITION * 7) / 10;
201 const int ironLevel = (Achievements::ACHIEVEMENT_HEIGHT_POSITION * 9) / 10;
202 const int diamondLevel = (Achievements::ACHIEVEMENT_HEIGHT_POSITION * 19) / 10;
203 const int bedrockLevel = (Achievements::ACHIEVEMENT_HEIGHT_POSITION * 31) / 10;
204
205 Random *random = new Random();
206
207 for (int tileY = 0; (tileY * 16) - yMod < BIGMAP_HEIGHT; tileY++)
208 {
209
210 float amount = .6f - (float) (topTile + tileY) / (float) (Achievements::ACHIEVEMENT_HEIGHT_POSITION * 2 + 1) * .3f;
211 glColor4f(amount, amount, amount, 1);
212
213 for (int tileX = 0; (tileX * 16) - xMod < BIGMAP_WIDTH; tileX++)
214 {
215
216 random->setSeed(1234 + leftTile + tileX);
217 random->nextInt();
218 int heightValue = random->nextInt(1 + topTile + tileY) + (topTile + tileY) / 2;
219 int tileType = Tile::sand->tex;
220
221 if (heightValue > bedrockLevel || (topTile + tileY) == MAX_BG_TILE_Y)
222 {
223 tileType = Tile::unbreakable->tex;
224 }
225 else if (heightValue == diamondLevel)
226 {
227 if (random->nextInt(2) == 0)
228 {
229 tileType = Tile::diamondOre->tex;
230 }
231 else
232 {
233 tileType = Tile::redStoneOre->tex;
234 }
235 }
236 else if (heightValue == ironLevel)
237 {
238 tileType = Tile::ironOre->tex;
239 }
240 else if (heightValue == coalLevel)
241 {
242 tileType = Tile::coalOre->tex;
243 }
244 else if (heightValue > rockLevel)
245 {
246 tileType = Tile::rock->tex;
247 }
248 else if (heightValue > 0)
249 {
250 tileType = Tile::dirt->tex;
251 }
252
253 this->blit(xBigMap + tileX * 16 - xMod, yBigMap + tileY * 16 - yMod, (tileType % 16) << 4, (tileType >> 4) << 4, 16, 16);
254 }
255 }
256
257 }
258 glEnable(GL_DEPTH_TEST);
259
260
261 glDepthFunc(GL_LEQUAL);
262
263 glDisable(GL_TEXTURE_2D);
264
265 AUTO_VAR(itEnd, Achievements::achievements->end());
266 for (AUTO_VAR(it, Achievements::achievements->begin()); it != itEnd; it++)
267 {
268 Achievement *ach = *it; //Achievements::achievements->at(i);
269 if (ach->requires == NULL) continue;
270
271 int x1 = ach->x * ACHIEVEMENT_COORD_SCALE - (int) xScroll + 11 + xBigMap;
272 int y1 = ach->y * ACHIEVEMENT_COORD_SCALE - (int) yScroll + 11 + yBigMap;
273
274 int x2 = ach->requires->x * ACHIEVEMENT_COORD_SCALE - (int) xScroll + 11 + xBigMap;
275 int y2 = ach->requires->y * ACHIEVEMENT_COORD_SCALE - (int) yScroll + 11 + yBigMap;
276
277 int color = 0;
278
279 bool taken = statsCounter->hasTaken(ach);
280 bool canTake = statsCounter->canTake(ach);
281
282 int alph = (int) (sin(System::currentTimeMillis() % 600 / 600.0 * PI * 2) > 0.6 ? 255 : 130);
283 if (taken) color = 0xff707070;
284 else if (canTake) color = 0x00ff00 + (alph << 24);
285 else color = 0xff000000;
286
287 hLine(x1, x2, y1, color);
288 vLine(x2, y1, y2, color);
289 }
290
291 Achievement *hoveredAchievement = NULL;
292 ItemRenderer *ir = new ItemRenderer();
293
294 glPushMatrix();
295 glRotatef(180, 1, 0, 0);
296 Lighting::turnOn();
297 glPopMatrix();
298 glDisable(GL_LIGHTING);
299 glEnable(GL_RESCALE_NORMAL);
300 glEnable(GL_COLOR_MATERIAL);
301
302 itEnd = Achievements::achievements->end();
303 for (AUTO_VAR(it, Achievements::achievements->begin()); it != itEnd; it++)
304 {
305 Achievement *ach = *it; //Achievements::achievements->at(i);
306
307 int x = ach->x * ACHIEVEMENT_COORD_SCALE - (int) xScroll;
308 int y = ach->y * ACHIEVEMENT_COORD_SCALE - (int) yScroll;
309
310 if (x >= -24 && y >= -24 && x <= BIGMAP_WIDTH && y <= BIGMAP_HEIGHT)
311 {
312
313 if (statsCounter->hasTaken(ach))
314 {
315 float br = 1.0f;
316 glColor4f(br, br, br, 1);
317 }
318 else if (statsCounter->canTake(ach))
319 {
320 float br = (sin(System::currentTimeMillis() % 600 / 600.0 * PI * 2) < 0.6 ? 0.6f : 0.8f);
321 glColor4f(br, br, br, 1);
322 }
323 else
324 {
325 float br = 0.3f;
326 glColor4f(br, br, br, 1);
327 }
328
329 minecraft->textures->bind(tex);
330 int xx = xBigMap + x;
331 int yy = yBigMap + y;
332 if (ach->isGolden())
333 {
334 this->blit(xx - 2, yy - 2, 26, 202, 26, 26);
335 }
336 else
337 {
338 this->blit(xx - 2, yy - 2, 0, 202, 26, 26);
339 }
340
341 if (!statsCounter->canTake(ach))
342 {
343 float br = 0.1f;
344 glColor4f(br, br, br, 1);
345 ir->setColor = false;
346 }
347 glEnable(GL_LIGHTING);
348 glEnable(GL_CULL_FACE);
349 ir->renderGuiItem(minecraft->font, minecraft->textures, ach->icon, xx + 3, yy + 3);
350 glDisable(GL_LIGHTING);
351 if (!statsCounter->canTake(ach))
352 {
353 ir->setColor = true;
354 }
355 glColor4f(1, 1, 1, 1);
356
357
358 if (xm >= xBigMap && ym >= yBigMap && xm < xBigMap + BIGMAP_WIDTH && ym < yBigMap + BIGMAP_HEIGHT && xm >= xx && xm <= xx + 22 && ym >= yy && ym <= yy + 22) {
359 hoveredAchievement = ach;
360 }
361 }
362 }
363
364 glDisable(GL_DEPTH_TEST);
365 glEnable(GL_BLEND);
366 glColor4f(1, 1, 1, 1);
367 minecraft->textures->bind(tex);
368 blit(xo, yo, 0, 0, imageWidth, imageHeight);
369
370
371 glPopMatrix();
372
373 blitOffset = 0;
374 glDepthFunc(GL_LEQUAL);
375
376 glDisable(GL_DEPTH_TEST);
377 glEnable(GL_TEXTURE_2D);
378 Screen::render(xm, ym, a);
379
380 if (hoveredAchievement != NULL)
381 {
382 Achievement *ach = hoveredAchievement;
383 wstring name = ach->name;
384 wstring descr = ach->getDescription();
385
386 int x = xm + 12;
387 int y = ym - 4;
388
389 if (statsCounter->canTake(ach))
390 {
391 int width = Math::_max(font->width(name), 120);
392 int height = font->wordWrapHeight(descr, width);
393 if (statsCounter->hasTaken(ach))
394 {
395 height += 12;
396 }
397 fillGradient(x - 3, y - 3, x + width + 3, y + height + 3 + 12, 0xc0000000, 0xc0000000);
398
399 font->drawWordWrap(descr, x, y + 12, width, 0xffa0a0a0);
400 if (statsCounter->hasTaken(ach))
401 {
402 font->drawShadow(I18n::get(L"achievement.taken"), x, y + height + 4, 0xff9090ff);
403 }
404 }
405 else
406 {
407 int width = Math::_max(font->width(name), 120);
408 wstring msg = I18n::get(L"achievement.requires", ach->requires->name);
409 int height = font->wordWrapHeight(msg, width);
410 fillGradient(x - 3, y - 3, x + width + 3, y + height + 12 + 3, 0xc0000000, 0xc0000000);
411 font->drawWordWrap(msg, x, y + 12, width, 0xff705050);
412 }
413 font->drawShadow(name, x, y, statsCounter->canTake(ach) ? ach->isGolden() ? 0xffffff80 : 0xffffffff : ach->isGolden() ? 0xff808040 : 0xff808080);
414
415
416 }
417 glEnable(GL_DEPTH_TEST);
418 glEnable(GL_LIGHTING);
419 Lighting::turnOff();
420#endif
421}
422
423bool AchievementScreen::isPauseScreen()
424{
425 return true;
426}