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 "EditBox.h"
3#include "..\Minecraft.World\SharedConstants.h"
4
5EditBox::EditBox(Screen *screen, Font *font, int x, int y, int width, int height, const wstring& value)
6{
7 // 4J - added initialisers
8 maxLength = 0;
9 frame = 0;
10
11 this->screen = screen;
12 this->font = font;
13 this->x = x;
14 this->y = y;
15 this->width = width;
16 this->height = height;
17 this->setValue(value);
18}
19
20void EditBox::setValue(const wstring& value)
21{
22 this->value = value;
23}
24
25wstring EditBox::getValue()
26{
27 return value;
28}
29
30void EditBox::tick()
31{
32 frame++;
33}
34
35void EditBox::keyPressed(wchar_t ch, int eventKey)
36{
37 if (!active || !inFocus) {
38 return;
39 }
40
41
42 if (ch == 9)
43 {
44 screen->tabPressed();
45 }
46/* 4J removed
47 if (ch == 22)
48 {
49 String msg = Screen.getClipboard();
50 if (msg == null) msg = "";
51 int toAdd = 32 - value.length();
52 if (toAdd > msg.length()) toAdd = msg.length();
53 if (toAdd > 0) {
54 value += msg.substring(0, toAdd);
55 }
56 }
57 */
58
59 if (eventKey == Keyboard::KEY_BACK && value.length() > 0)
60 {
61 value = value.substr(0, value.length() - 1);
62 }
63 if (SharedConstants::acceptableLetters.find(ch) != wstring::npos && (value.length() < maxLength || maxLength == 0))
64 {
65 value += ch;
66 }
67
68}
69
70void EditBox::mouseClicked(int mouseX, int mouseY, int buttonNum)
71{
72 bool newFocus = active && (mouseX >= x && mouseX < (x + width) && mouseY >= y && mouseY < (y + height));
73 focus(newFocus);
74}
75
76void EditBox::focus(bool newFocus)
77{
78 if (newFocus && !inFocus)
79 {
80 // reset the underscore counter to give quicker selection feedback
81 frame = 0;
82 }
83 inFocus = newFocus;
84}
85
86void EditBox::render()
87{
88 fill(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
89 fill(x, y, x + width, y + height, 0xff000000);
90
91 if (active)
92 {
93 bool renderUnderscore = inFocus && (frame / 6 % 2 == 0);
94 drawString(font, value + (renderUnderscore ? L"_" : L""), x + 4, y + (height - 8) / 2, 0xe0e0e0);
95 }
96 else
97 {
98 drawString(font, value, x + 4, y + (height - 8) / 2, 0x707070);
99 }
100}
101
102void EditBox::setMaxLength(int maxLength)
103{
104 this->maxLength = maxLength;
105}
106
107int EditBox::getMaxLength()
108{
109 return maxLength;
110}