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 "NameEntryScreen.h"
3#include "Button.h"
4#include "..\Minecraft.World\StringHelpers.h"
5
6const wstring NameEntryScreen::allowedChars = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.:-_'*!\"#%/()=+?[]{}<>";
7
8NameEntryScreen::NameEntryScreen(Screen *lastScreen, const wstring& oldName, int slot)
9{
10 frame = 0; // 4J added
11
12 this->lastScreen = lastScreen;
13 this->slot = slot;
14 this->name = oldName;
15 if (name==L"-") name = L"";
16}
17
18void NameEntryScreen::init()
19{
20 buttons.clear();
21 Keyboard::enableRepeatEvents(true);
22 buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5, L"Save"));
23 buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 6, L"Cancel"));
24 buttons[0]->active = trimString(name).length() > 1;
25}
26
27void NameEntryScreen::removed()
28{
29 Keyboard::enableRepeatEvents(false);
30}
31
32void NameEntryScreen::tick()
33{
34 frame++;
35}
36
37void NameEntryScreen::buttonClicked(Button button)
38{
39 if (!button.active) return;
40
41 if (button.id == 0 && trimString(name).length() > 1)
42 {
43 minecraft->saveSlot(slot, trimString(name));
44 minecraft->setScreen(NULL);
45// minecraft->grabMouse(); // 4J - removed
46 }
47 if (button.id == 1)
48 {
49 minecraft->setScreen(lastScreen);
50 }
51}
52
53void NameEntryScreen::keyPressed(wchar_t ch, int eventKey)
54{
55 if (eventKey == Keyboard::KEY_BACK && name.length() > 0) name = name.substr(0, name.length() - 1);
56 if (allowedChars.find(ch) != wstring::npos && name.length()<64)
57 {
58 name += ch;
59 }
60 buttons[0]->active = trimString(name).length() > 1;
61}
62
63void NameEntryScreen::render(int xm, int ym, float a)
64{
65 renderBackground();
66
67 drawCenteredString(font, title, width / 2, 40, 0xffffff);
68
69 int bx = width / 2 - 100;
70 int by = height / 2 - 10;
71 int bw = 200;
72 int bh = 20;
73 fill(bx - 1, by - 1, bx + bw + 1, by + bh + 1, 0xffa0a0a0);
74 fill(bx, by, bx + bw, by + bh, 0xff000000);
75 drawString(font, name + (frame / 6 % 2 == 0 ? L"_" : L""), bx + 4, by + (bh - 8) / 2, 0xe0e0e0);
76
77 Screen::render(xm, ym, a);
78}