forked from Kolyah35/minecraft-pe-0.6.1
TextBox / removed BuyButton / impoved CreateWorldScreen
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
#include "TextBox.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
TextBox::TextBox( int id, const std::string& msg )
|
||||
: id(0), w(0), h(0), x(0), y(0), text(msg), focused(false) {
|
||||
#include "platform/input/Mouse.h"
|
||||
|
||||
}
|
||||
TextBox::TextBox( int id, const std::string& msg )
|
||||
: TextBox(id, 0, 0, msg) {}
|
||||
|
||||
TextBox::TextBox( int id, int x, int y, const std::string& msg )
|
||||
: id(id), w(0), h(0), x(x), y(y), text(msg), focused(false) {
|
||||
: TextBox(id, x, y, 24, msg) {}
|
||||
|
||||
}
|
||||
|
||||
TextBox::TextBox( int id, int x, int y, int w, int h, const std::string& msg )
|
||||
: id(id), w(w), h(h), x(x), y(y), text(msg) {
|
||||
|
||||
}
|
||||
TextBox::TextBox( int id, int x, int y, int w, const std::string& msg )
|
||||
: GuiElement(true, true, x, y, w, Font::DefaultLineHeight + 4),
|
||||
id(id), hint(msg), focused(false), blink(false) {}
|
||||
|
||||
void TextBox::setFocus(Minecraft* minecraft) {
|
||||
if(!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
|
||||
blinkTicks = 0;
|
||||
blink = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,59 @@ bool TextBox::loseFocus(Minecraft* minecraft) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextBox::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
|
||||
void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
if (pointInside(x, y)) {
|
||||
setFocus(minecraft);
|
||||
} else {
|
||||
loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::handleChar(char c) {
|
||||
if (focused) {
|
||||
text.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::handleKey(int key) {
|
||||
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
|
||||
text.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::tick(Minecraft* minecraft) {
|
||||
blinkTicks++;
|
||||
|
||||
if (blinkTicks >= 5) {
|
||||
blink = !blink;
|
||||
blinkTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
// textbox like in beta 1.7.3
|
||||
fill(x, y, x + width, y + height, 0xffa0a0a0);
|
||||
fill(x + 1, y + 1, x + width - 1, y + height - 1, 0xff000000);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
glScissor(
|
||||
Gui::GuiScale * (x + 2),
|
||||
minecraft->height - Gui::GuiScale * (y + height - 2),
|
||||
Gui::GuiScale * (width - 2),
|
||||
Gui::GuiScale * (height - 2)
|
||||
);
|
||||
|
||||
if (text.empty() && !focused) {
|
||||
drawString(minecraft->font, hint, x + 2, y + 2, 0xff5e5e5e);
|
||||
}
|
||||
|
||||
if (focused && blink) text.push_back('_');
|
||||
|
||||
drawString(minecraft->font, text, x + 2, y + 2, 0xffffffff);
|
||||
|
||||
if (focused && blink) text.pop_back();
|
||||
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
@@ -4,31 +4,39 @@
|
||||
//package net.minecraft.client.gui;
|
||||
|
||||
#include <string>
|
||||
#include "../GuiComponent.h"
|
||||
#include "GuiElement.h"
|
||||
#include "../../Options.h"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
|
||||
class TextBox: public GuiComponent
|
||||
class TextBox: public GuiElement
|
||||
{
|
||||
public:
|
||||
TextBox(int id, const std::string& msg);
|
||||
TextBox(int id, int x, int y, const std::string& msg);
|
||||
TextBox(int id, int x, int y, int w, int h, const std::string& msg);
|
||||
TextBox(int id, int x, int y, int w, const std::string& msg);
|
||||
|
||||
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum);
|
||||
|
||||
virtual void setFocus(Minecraft* minecraft);
|
||||
virtual bool loseFocus(Minecraft* minecraft);
|
||||
|
||||
virtual void render(Minecraft* minecraft, int xm, int ym);
|
||||
|
||||
virtual void handleKey(int key);
|
||||
virtual void handleChar(char c);
|
||||
virtual void tick(Minecraft* minecraft);
|
||||
|
||||
public:
|
||||
int w, h;
|
||||
int x, y;
|
||||
|
||||
std::string hint;
|
||||
std::string text;
|
||||
int id;
|
||||
|
||||
int blinkTicks;
|
||||
|
||||
bool focused;
|
||||
bool blink;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__TextBox_H__*/
|
||||
|
||||
Reference in New Issue
Block a user