forked from Kolyah35/minecraft-pe-0.6.1
Fixes and enhancements from my MCPE repository. (https://github.com/mschiller890/mcpe64)
This commit is contained in:
@@ -10,7 +10,7 @@ OptionsGroup::OptionsGroup( std::string labelID ) {
|
||||
|
||||
void OptionsGroup::setupPositions() {
|
||||
// First we write the header and then we add the items
|
||||
int curY = y + 10;
|
||||
int curY = y + 18;
|
||||
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->width = width - 5;
|
||||
|
||||
@@ -23,7 +23,9 @@ void OptionsGroup::setupPositions() {
|
||||
}
|
||||
|
||||
void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
minecraft->font->draw(label, (float)x + 2, (float)y, 0xffffffff, false);
|
||||
float padX = 10.0f;
|
||||
float padY = 5.0f;
|
||||
minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false);
|
||||
super::render(minecraft, xm, ym);
|
||||
}
|
||||
|
||||
@@ -45,6 +47,7 @@ void OptionsGroup::createToggle( const Options::Option* option, Minecraft* minec
|
||||
def.height = 20 * 0.7f;
|
||||
OptionButton* element = new OptionButton(option);
|
||||
element->setImageDef(def, true);
|
||||
element->updateImage(&minecraft->options);
|
||||
std::string itemLabel = I18n::get(option->getCaptionId());
|
||||
OptionsItem* item = new OptionsItem(itemLabel, element);
|
||||
addChild(item);
|
||||
@@ -58,11 +61,38 @@ void OptionsGroup::createProgressSlider( const Options::Option* option, Minecraf
|
||||
minecraft->options.getProgrssMax(option));
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
OptionsItem* item = new OptionsItem(label, element);
|
||||
std::string itemLabel = I18n::get(option->getCaptionId());
|
||||
OptionsItem* item = new OptionsItem(itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void OptionsGroup::createStepSlider( const Options::Option* option, Minecraft* minecraft ) {
|
||||
|
||||
// integer-valued option; use step slider
|
||||
std::vector<int> steps;
|
||||
// render distance was removed; fall through to other cases
|
||||
if(option == &Options::Option::DIFFICULTY) {
|
||||
steps.push_back(0);
|
||||
steps.push_back(1);
|
||||
steps.push_back(2);
|
||||
steps.push_back(3);
|
||||
} else if(option == &Options::Option::GUI_SCALE) {
|
||||
// slider order: small,normal,large,larger,auto
|
||||
steps.push_back(1);
|
||||
steps.push_back(2);
|
||||
steps.push_back(3);
|
||||
steps.push_back(4);
|
||||
steps.push_back(0);
|
||||
} else {
|
||||
// fallback: use single value; duplicate so numSteps>1 and avoid divide-by-zero
|
||||
steps.push_back(0);
|
||||
steps.push_back(0);
|
||||
}
|
||||
Slider* element = new Slider(minecraft, option, steps);
|
||||
element->width = 100;
|
||||
element->height = 20;
|
||||
std::string itemLabel = I18n::get(option->getCaptionId());
|
||||
OptionsItem* item = new OptionsItem(itemLabel, element);
|
||||
addChild(item);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
@@ -25,13 +25,17 @@ Slider::Slider(Minecraft* minecraft, const Options::Option* option, const std::v
|
||||
assert(stepVec.size() > 1);
|
||||
numSteps = sliderSteps.size();
|
||||
if(option != NULL) {
|
||||
curStepValue;
|
||||
int curStep;
|
||||
// initialize slider position based on the current option value
|
||||
curStepValue = minecraft->options.getIntValue(option);
|
||||
std::vector<int>::iterator currentItem = std::find(sliderSteps.begin(), sliderSteps.end(), curStepValue);
|
||||
auto currentItem = std::find(sliderSteps.begin(), sliderSteps.end(), curStepValue);
|
||||
if(currentItem != sliderSteps.end()) {
|
||||
curStep = currentItem - sliderSteps.begin();
|
||||
curStep = static_cast<int>(currentItem - sliderSteps.begin());
|
||||
} else {
|
||||
// fallback to first step
|
||||
curStep = 0;
|
||||
curStepValue = sliderSteps[0];
|
||||
}
|
||||
percentage = float(curStep) / float(numSteps - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +50,15 @@ void Slider::render( Minecraft* minecraft, int xm, int ym ) {
|
||||
//fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff);
|
||||
fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060);
|
||||
if(sliderType == SliderStep) {
|
||||
int stepDistance = barWidth / (numSteps -1);
|
||||
for(int a = 0; a <= numSteps - 1; ++a) {
|
||||
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
|
||||
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
|
||||
// numSteps should be >=2; protect against bad input (zero division)
|
||||
if(numSteps <= 1) {
|
||||
// nothing to render
|
||||
} else {
|
||||
int stepDistance = barWidth / (numSteps -1);
|
||||
for(int a = 0; a <= numSteps - 1; ++a) {
|
||||
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
|
||||
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
|
||||
}
|
||||
}
|
||||
}
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
@@ -1,90 +1,100 @@
|
||||
#include "TextBox.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "platform/input/Mouse.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
TextBox::TextBox( int id, const std::string& msg )
|
||||
: TextBox(id, 0, 0, msg) {}
|
||||
// delegate constructors
|
||||
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 )
|
||||
: TextBox(id, x, y, 24, msg) {}
|
||||
TextBox::TextBox(int id, int x, int y, const std::string& msg)
|
||||
: TextBox(id, x, y, 24, Font::DefaultLineHeight + 4, 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) {}
|
||||
TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg)
|
||||
: GuiElement(true, true, x, y, w, h),
|
||||
id(id), hint(msg), focused(false), blink(false), blinkTicks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TextBox::setFocus(Minecraft* minecraft) {
|
||||
if(!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
|
||||
blinkTicks = 0;
|
||||
blink = false;
|
||||
}
|
||||
if (!focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = true;
|
||||
blinkTicks = 0;
|
||||
blink = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TextBox::loseFocus(Minecraft* minecraft) {
|
||||
if(focused) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
focused = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (focused) {
|
||||
minecraft->platform()->hideKeyboard();
|
||||
focused = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
|
||||
text.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::handleKey(int key) {
|
||||
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
|
||||
text.pop_back();
|
||||
}
|
||||
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
|
||||
text.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::tick(Minecraft* minecraft) {
|
||||
blinkTicks++;
|
||||
|
||||
if (blinkTicks >= 5) {
|
||||
blink = !blink;
|
||||
blinkTicks = 0;
|
||||
}
|
||||
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);
|
||||
void TextBox::render(Minecraft* minecraft, int xm, int ym) {
|
||||
// textbox like in beta 1.7.3
|
||||
// change appearance when focused so the user can tell it's active
|
||||
// active background darker gray with a subtle border
|
||||
uint32_t bgColor = focused ? 0xffa0a0a0 : 0xffa0a0a0;
|
||||
uint32_t borderColor = focused ? 0xff000000 : 0xff000000;
|
||||
fill(x, y, x + width, y + height, bgColor);
|
||||
fill(x + 1, y + 1, x + width - 1, y + height - 1, borderColor);
|
||||
|
||||
glEnable2(GL_SCISSOR_TEST);
|
||||
glScissor(
|
||||
Gui::GuiScale * (x + 2),
|
||||
minecraft->height - Gui::GuiScale * (y + height - 2),
|
||||
Gui::GuiScale * (width - 2),
|
||||
Gui::GuiScale * (height - 2)
|
||||
);
|
||||
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 (text.empty() && !focused) {
|
||||
drawString(minecraft->font, hint, x + 2, y + 2, 0xff5e5e5e);
|
||||
}
|
||||
|
||||
if (focused && blink) text.push_back('_');
|
||||
if (focused && blink) text.push_back('_');
|
||||
|
||||
drawString(minecraft->font, text, x + 2, y + 2, 0xffffffff);
|
||||
drawString(minecraft->font, text, x + 2, y + 2, 0xffffffff);
|
||||
|
||||
if (focused && blink) text.pop_back();
|
||||
if (focused && blink) text.pop_back();
|
||||
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
glDisable2(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <string>
|
||||
#include "GuiElement.h"
|
||||
#include "../../Options.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
|
||||
class Font;
|
||||
class Minecraft;
|
||||
@@ -14,15 +16,15 @@ 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, 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);
|
||||
|
||||
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 render(Minecraft* minecraft, int xm, int ym);
|
||||
|
||||
virtual void handleKey(int key);
|
||||
virtual void handleChar(char c);
|
||||
|
||||
Reference in New Issue
Block a user