FIX: Rewrite options

This commit is contained in:
Kolyah35
2026-03-14 14:13:49 +03:00
parent 09d28be195
commit badd59b644
67 changed files with 1093 additions and 1377 deletions

View File

@@ -119,7 +119,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
#if defined(RPI)
renderDebugInfo();
#elif defined(PLATFORM_DESKTOP)
if (minecraft->options.renderDebug)
if (minecraft->options.getBooleanValue(OPTIONS_RENDER_DEBUG))
renderDebugInfo();
#endif
@@ -219,7 +219,7 @@ void Gui::handleKeyPressed(int key)
{
minecraft->screenChooser.setScreen(SCREEN_BLOCKSELECTION);
}
else if (key == minecraft->options.keyDrop.key)
else if (key == minecraft->options.getIntValue(OPTIONS_KEY_DROP))
{
minecraft->player->inventory->dropSlot(minecraft->player->inventory->selected, false);
}
@@ -402,7 +402,7 @@ void Gui::onConfigChanged( const Config& c ) {
if (c.minecraft->useTouchscreen()) {
// I'll bump this up to 6.
int num = 6; // without "..." dots
if (!c.minecraft->options.isJoyTouchArea && c.width > 480) {
if (!c.minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) && c.width > 480) {
while (num < Inventory::MAX_SELECTION_SIZE - 1) {
int x0, x1, y;
getSlotPos(0, x0, y);
@@ -516,7 +516,7 @@ void Gui::renderProgressIndicator( const bool isTouchInterface, const int screen
ItemInstance* currentItem = minecraft->player->inventory->getSelected();
bool bowEquipped = currentItem != NULL ? currentItem->getItem() == Item::bow : false;
bool itemInUse = currentItem != NULL ? currentItem->getItem() == minecraft->player->getUseItem()->getItem() : false;
if (!isTouchInterface || minecraft->options.isJoyTouchArea || (bowEquipped && itemInUse)) {
if (!isTouchInterface || minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) || (bowEquipped && itemInUse)) {
minecraft->textures->loadAndBindTexture("gui/icons.png");
glEnable(GL_BLEND);
glBlendFunc2(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR);

View File

@@ -104,7 +104,7 @@ void Screen::keyboardEvent()
}
void Screen::keyboardTextEvent()
{
keyboardNewChar(Keyboard::getChar());
charPressed(Keyboard::getChar());
}
void Screen::renderBackground()
{
@@ -166,7 +166,7 @@ void Screen::keyPressed( int eventKey )
// pass key events to any text boxes first
for (auto& textbox : textBoxes) {
textbox->handleKey(eventKey);
textbox->keyPressed(minecraft, eventKey);
}
if (minecraft->useTouchscreen())
@@ -178,11 +178,11 @@ void Screen::keyPressed( int eventKey )
return;
Options& o = minecraft->options;
if (eventKey == o.keyMenuNext.key)
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_NEXT))
if (++tabButtonIndex == tabButtonCount) tabButtonIndex = 0;
if (eventKey == o.keyMenuPrevious.key)
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_PREV))
if (--tabButtonIndex == -1) tabButtonIndex = tabButtonCount-1;
if (eventKey == o.keyMenuOk.key) {
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) {
Button* button = tabButtons[tabButtonIndex];
if (button->active) {
minecraft->soundEngine->playUI("random.click", 1, 1);
@@ -193,6 +193,12 @@ void Screen::keyPressed( int eventKey )
updateTabButtonSelection();
}
void Screen::charPressed(char inputChar) {
for (auto& textbox : textBoxes) {
textbox->charPressed(minecraft, inputChar);
}
}
void Screen::updateTabButtonSelection()
{
if (minecraft->useTouchscreen())

View File

@@ -58,7 +58,7 @@ protected:
virtual void mouseReleased(int x, int y, int buttonNum);
virtual void keyPressed(int eventKey);
virtual void keyboardNewChar(char inputChar) {}
virtual void charPressed(char inputChar);
public:
int width;
int height;

View File

@@ -9,13 +9,20 @@ class GuiElement : public GuiComponent {
public:
GuiElement(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24);
virtual ~GuiElement() {}
virtual void tick(Minecraft* minecraft) {}
virtual void tick(Minecraft* minecraft) {}
virtual void render(Minecraft* minecraft, int xm, int ym) { }
virtual void setupPositions() {}
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {}
virtual void mouseReleased(Minecraft* minecraft, int x, int y, int buttonNum) {}
virtual void keyPressed(Minecraft* minecraft, int key) {}
virtual void charPressed(Minecraft* minecraft, char key) {}
virtual bool pointInside(int x, int y);
void setVisible(bool visible);
bool active;
bool visible;
int x;

View File

@@ -52,3 +52,15 @@ void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int
(*it)->mouseReleased(minecraft, x, y, buttonNum);
}
}
void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->keyPressed(minecraft, key);
}
}
void GuiElementContainer::charPressed(Minecraft* minecraft, char key) {
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->charPressed(minecraft, key);
}
}

View File

@@ -17,8 +17,9 @@ public:
virtual void tick( Minecraft* minecraft );
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void keyPressed(Minecraft* minecraft, int key);
virtual void charPressed(Minecraft* minecraft, char key);
protected:
std::vector<GuiElement*> children;

View File

@@ -4,6 +4,7 @@
#include "../../../platform/log.h"
#include "../../../util/Mth.h"
#include "../../renderer/Textures.h"
#include <client/Option.h>
ImageButton::ImageButton(int id, const std::string& msg)
@@ -112,43 +113,17 @@ void ImageButton::render(Minecraft* minecraft, int xm, int ym) {
//
// A toggleable Button
//
OptionButton::OptionButton(const Options::Option* option)
: _option(option),
_isFloat(false),
super(ButtonId, "")
{
}
OptionButton::OptionButton(const Options::Option* option, float onValue, float offValue)
: _option(option),
_isFloat(true),
_onValue(onValue),
_offValue(offValue),
super(ButtonId, "")
{
}
bool OptionButton::isSecondImage(bool hovered) {
return _secondImage;
}
OptionButton::OptionButton(OptionId option) : m_optId(option), super(ButtonId, "") {}
void OptionButton::toggle(Options* options) {
if (_isFloat) {
options->set(_option, (Mth::abs(_current - _onValue) < 0.01f) ? _offValue : _onValue);
} else {
options->toggle(_option, 1);
}
options->toggle(m_optId);
// Update graphics here
updateImage(options);
}
void OptionButton::updateImage(Options* options) {
if (_isFloat) {
_current = options->getProgressValue(_option);
_secondImage = Mth::abs(_current - _onValue) < 0.01f;
} else {
_secondImage = options->getBooleanValue(_option);
}
_secondImage = options->getBooleanValue(m_optId);
}
void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {

View File

@@ -77,28 +77,20 @@ class OptionButton: public ImageButton
{
typedef ImageButton super;
public:
OptionButton(const Options::Option* option);
OptionButton(const Options::Option* option, float onValue, float offValue);
OptionButton(OptionId optId);
void toggle(Options* options);
void updateImage(Options* options);
static const int ButtonId = 9999999;
protected:
bool isSecondImage(bool hovered);
bool isSecondImage(bool hovered) { return _secondImage; }
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
private:
const Options::Option* _option;
OptionId m_optId;
bool _secondImage;
// If not float, it's considered to be a boolean value
bool _isFloat;
float _onValue;
float _offValue;
float _current;
};

View File

@@ -0,0 +1,22 @@
#include "KeyOption.h"
#include <client/Minecraft.h>
KeyOption::KeyOption(Minecraft* minecraft, OptionId optId)
: Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {}
void KeyOption::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
selected = isInside(x, y);
msg = (selected)? "..." : Keyboard::getKeyName(minecraft->options.getIntValue((OptionId)id));
}
void KeyOption::keyPressed(Minecraft* minecraft, int key) {
if (!selected) return;
if (key != Keyboard::KEY_ESCAPE) {
minecraft->options.set((OptionId)id, key);
}
selected = false;
msg = Keyboard::getKeyName(minecraft->options.getIntValue((OptionId)id));
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include "Button.h"
#include <client/Options.h>
class KeyOption : public Touch::TButton {
public:
KeyOption(Minecraft* minecraft, OptionId optId);
virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum);
virtual void released(int mx, int my) {}
virtual void keyPressed(Minecraft* minecraft, int key);
protected:
bool m_captureMode;
};

View File

@@ -4,6 +4,9 @@
#include "OptionsItem.h"
#include "Slider.h"
#include "../../../locale/I18n.h"
#include "TextOption.h"
#include "KeyOption.h"
OptionsGroup::OptionsGroup( std::string labelID ) {
label = I18n::get(labelID);
}
@@ -25,74 +28,88 @@ void OptionsGroup::setupPositions() {
void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) {
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);
}
OptionsGroup& OptionsGroup::addOptionItem( const Options::Option* option, Minecraft* minecraft ) {
if(option->isBoolean())
createToggle(option, minecraft);
else if(option->isProgress())
createProgressSlider(option, minecraft);
else if(option->isInt())
createStepSlider(option, minecraft);
OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) {
auto option = minecraft->options.getOpt(optId);
if (option == nullptr) return *this;
// TODO: do a options key class to check it faster via dynamic_cast
if (option->getStringId().find("options.key") != std::string::npos) createKey(optId, minecraft);
else if (dynamic_cast<OptionBool*>(option)) createToggle(optId, minecraft);
else if (dynamic_cast<OptionFloat*>(option)) createProgressSlider(optId, minecraft);
else if (dynamic_cast<OptionInt*>(option)) createStepSlider(optId, minecraft);
else if (dynamic_cast<OptionString*>(option)) createTextbox(optId, minecraft);
return *this;
}
void OptionsGroup::createToggle( const Options::Option* option, Minecraft* minecraft ) {
// TODO: wrap this copypaste shit into templates
void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) {
ImageDef def;
def.setSrc(IntRectangle(160, 206, 39, 20));
def.name = "gui/touchgui.png";
def.width = 39 * 0.7f;
def.height = 20 * 0.7f;
OptionButton* element = new OptionButton(option);
OptionButton* element = new OptionButton(optId);
element->setImageDef(def, true);
element->updateImage(&minecraft->options);
std::string itemLabel = I18n::get(option->getCaptionId());
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(itemLabel, element);
addChild(item);
setupPositions();
}
void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) {
Slider* element = new SliderFloat(minecraft, optId);
element->width = 100;
element->height = 20;
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(itemLabel, element);
addChild(item);
setupPositions();
}
void OptionsGroup::createProgressSlider( const Options::Option* option, Minecraft* minecraft ) {
Slider* element = new Slider(minecraft,
option,
minecraft->options.getProgrssMin(option),
minecraft->options.getProgrssMax(option));
void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) {
Slider* element = new SliderInt(minecraft, optId);
element->width = 100;
element->height = 20;
std::string itemLabel = I18n::get(option->getCaptionId());
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
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);
void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) {
TextBox* element = new TextOption(minecraft, optId);
element->width = 100;
element->height = 20;
std::string itemLabel = I18n::get(option->getCaptionId());
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(itemLabel, element);
addChild(item);
setupPositions();
}
void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) {
KeyOption* element = new KeyOption(minecraft, optId);
element->width = 50;
element->height = 20;
std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId());
OptionsItem* item = new OptionsItem(itemLabel, element);
addChild(item);
setupPositions();
}

View File

@@ -5,6 +5,7 @@
#include <string>
#include "GuiElementContainer.h"
#include "ScrollingPane.h"
#include "../../Options.h"
class Font;
@@ -16,11 +17,15 @@ public:
OptionsGroup(std::string labelID);
virtual void setupPositions();
virtual void render(Minecraft* minecraft, int xm, int ym);
virtual OptionsGroup& addOptionItem(const Options::Option* option, Minecraft* minecraft);
OptionsGroup& addOptionItem(OptionId optId, Minecraft* minecraft);
protected:
virtual void createToggle(const Options::Option* option, Minecraft* minecraft);
virtual void createProgressSlider(const Options::Option* option, Minecraft* minecraft);
virtual void createStepSlider(const Options::Option* option, Minecraft* minecraft);
void createToggle(OptionId optId, Minecraft* minecraft);
void createProgressSlider(OptionId optId, Minecraft* minecraft);
void createStepSlider(OptionId optId, Minecraft* minecraft);
void createTextbox(OptionId optId, Minecraft* minecraft);
void createKey(OptionId optId, Minecraft* minecraft);
std::string label;
};

View File

@@ -1,64 +0,0 @@
#include "OptionsPane.h"
#include "OptionsGroup.h"
#include "OptionsItem.h"
#include "ImageButton.h"
#include "Slider.h"
#include "../../Minecraft.h"
OptionsPane::OptionsPane() {
}
void OptionsPane::setupPositions() {
int currentHeight = y + 1;
for(std::vector<GuiElement*>::iterator it = children.begin(); it != children.end(); ++it ) {
(*it)->width = width;
(*it)->y = currentHeight;
(*it)->x = x;
currentHeight += (*it)->height + 1;
}
height = currentHeight;
super::setupPositions();
}
OptionsGroup& OptionsPane::createOptionsGroup( std::string label ) {
OptionsGroup* newGroup = new OptionsGroup(label);
children.push_back(newGroup);
// create and return a new group index
return *newGroup;
}
void OptionsPane::createToggle( unsigned int group, std::string label, const Options::Option* option ) {
// if(group > children.size()) return;
// ImageDef def;
// def.setSrc(IntRectangle(160, 206, 39, 20));
// def.name = "gui/touchgui.png";
// def.width = 39 * 0.7f;
// def.height = 20 * 0.7f;
// OptionButton* element = new OptionButton(option);
// element->setImageDef(def, true);
// OptionsItem* item = new OptionsItem(label, element);
// ((OptionsGroup*)children[group])->addChild(item);
// setupPositions();
}
void OptionsPane::createProgressSlider( Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, float progressMin/*=1.0f*/, float progressMax/*=1.0f */ ) {
// if(group > children.size()) return;
// Slider* element = new Slider(minecraft, option, progressMin, progressMax);
// element->width = 100;
// element->height = 20;
// OptionsItem* item = new OptionsItem(label, element);
// ((OptionsGroup*)children[group])->addChild(item);
// setupPositions();
}
void OptionsPane::createStepSlider( Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, const std::vector<int>& stepVec ) {
// if(group > children.size()) return;
// Slider* element = new Slider(minecraft, option, stepVec);
// element->width = 100;
// element->height = 20;
// sliders.push_back(element);
// OptionsItem* item = new OptionsItem(label, element);
// ((OptionsGroup*)children[group])->addChild(item);
// setupPositions();
}

View File

@@ -1,30 +0,0 @@
#ifndef ITEMPANE_H__
#define ITEMPANE_H__
#include <string>
#include <vector>
#include "GuiElementContainer.h"
#include "../../../world/item/ItemInstance.h"
#include "../../../client/Options.h"
class Font;
class Textures;
class NinePatchLayer;
class ItemPane;
class OptionButton;
class Button;
class OptionsGroup;
class Slider;
class Minecraft;
class OptionsPane: public GuiElementContainer
{
typedef GuiElementContainer super;
public:
OptionsPane();
OptionsGroup& createOptionsGroup( std::string label );
void createToggle( unsigned int group, std::string label, const Options::Option* option );
void createProgressSlider(Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, float progressMin=1.0f, float progressMax=1.0f );
void createStepSlider(Minecraft* minecraft, unsigned int group, std::string label, const Options::Option* option, const std::vector<int>& stepVec );
void setupPositions();
};
#endif /*ITEMPANE_H__*/

View File

@@ -5,39 +5,8 @@
#include "../../../util/Mth.h"
#include <algorithm>
#include <assert.h>
Slider::Slider(Minecraft* minecraft, const Options::Option* option, float progressMin, float progressMax)
: sliderType(SliderProgress), mouseDownOnElement(false), option(option), numSteps(0), progressMin(progressMin), progressMax(progressMax) {
if(option != NULL) {
percentage = (minecraft->options.getProgressValue(option) - progressMin) / (progressMax - progressMin);
}
}
Slider::Slider(Minecraft* minecraft, const Options::Option* option, const std::vector<int>& stepVec )
: sliderType(SliderStep),
curStepValue(0),
curStep(0),
sliderSteps(stepVec),
mouseDownOnElement(false),
option(option),
percentage(0),
progressMin(0.0f),
progressMax(1.0) {
assert(stepVec.size() > 1);
numSteps = sliderSteps.size();
if(option != NULL) {
// initialize slider position based on the current option value
curStepValue = minecraft->options.getIntValue(option);
auto currentItem = std::find(sliderSteps.begin(), sliderSteps.end(), curStepValue);
if(currentItem != sliderSteps.end()) {
curStep = static_cast<int>(currentItem - sliderSteps.begin());
} else {
// fallback to first step
curStep = 0;
curStepValue = sliderSteps[0];
}
percentage = float(curStep) / float(numSteps - 1);
}
}
Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {}
void Slider::render( Minecraft* minecraft, int xm, int ym ) {
int xSliderStart = x + 5;
@@ -49,61 +18,71 @@ void Slider::render( Minecraft* minecraft, int xm, int ym ) {
int barWidth = xSliderEnd - xSliderStart;
//fill(x, y + 8, x + (int)(width * percentage), y + height, 0xffff00ff);
fill(xSliderStart, ySliderStart, xSliderEnd, ySliderEnd, 0xff606060);
if(sliderType == SliderStep) {
// 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);
}
if (m_numSteps > 2) {
int stepDistance = barWidth / (m_numSteps-1);
for(int a = 0; a <= m_numSteps; ++a) {
int renderSliderStepPosX = xSliderStart + a * stepDistance + 1;
fill(renderSliderStepPosX - 1, ySliderStart - 2, renderSliderStepPosX + 1, ySliderEnd + 2, 0xff606060);
}
}
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
blit(xSliderStart + (int)(percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY);
blit(xSliderStart + (int)(m_percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY);
}
void Slider::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) {
if(pointInside(x, y)) {
mouseDownOnElement = true;
m_mouseDownOnElement = true;
}
}
void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
mouseDownOnElement = false;
if(sliderType == SliderStep) {
curStep = Mth::floor((percentage * (numSteps-1) + 0.5f));
curStepValue = sliderSteps[Mth::Min(curStep, numSteps-1)];
percentage = float(curStep) / (numSteps - 1);
setOption(minecraft);
}
}
m_mouseDownOnElement = false;
}
void Slider::tick(Minecraft* minecraft) {
if(minecraft->screen != NULL) {
int xm = Mouse::getX();
int ym = Mouse::getY();
minecraft->screen->toGUICoordinate(xm, ym);
if(mouseDownOnElement) {
percentage = float(xm - x) / float(width);
percentage = Mth::clamp(percentage, 0.0f, 1.0f);
setOption(minecraft);
if(m_mouseDownOnElement) {
m_percentage = float(xm - x) / float(width);
m_percentage = Mth::clamp(m_percentage, 0.0f, 1.0f);
}
}
}
void Slider::setOption( Minecraft* minecraft ) {
if(option != NULL) {
if(sliderType == SliderStep) {
if(minecraft->options.getIntValue(option) != curStepValue) {
minecraft->options.set(option, curStepValue);
}
} else {
if(minecraft->options.getProgressValue(option) != percentage * (progressMax - progressMin) + progressMin) {
minecraft->options.set(option, percentage * (progressMax - progressMin) + progressMin);
}
}
SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option)
: Slider(option), m_option(dynamic_cast<OptionFloat*>(minecraft->options.getOpt(option)))
{
m_percentage = Mth::clamp((m_option->get() - m_option->getMin()) / (m_option->getMax() - m_option->getMin()), 0.f, 1.f);
}
SliderInt::SliderInt(Minecraft* minecraft, OptionId option)
: Slider(option), m_option(dynamic_cast<OptionInt*>(minecraft->options.getOpt(option)))
{
m_numSteps = m_option->getMax() - m_option->getMin();
m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1);
}
void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
Slider::mouseReleased(minecraft, x, y, buttonNum);
if (pointInside(x, y)) {
int curStep = Mth::floor(m_percentage * (m_numSteps-1));
m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1);
minecraft->options.set(m_optId, curStep);
}
}
void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) {
Slider::mouseReleased(minecraft, x, y, buttonNum);
if (pointInside(x, y)) {
minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin());
}
}

View File

@@ -3,38 +3,45 @@
#include "GuiElement.h"
#include "../../../client/Options.h"
enum SliderType {
SliderProgress, // Sets slider between {0..1}
SliderStep // Uses the closest step
};
#include <client/Option.h>
class Slider : public GuiElement {
typedef GuiElement super;
public:
// Creates a progress slider with no steps
Slider(Minecraft* minecraft, const Options::Option* option, float progressMin, float progressMax);
Slider(Minecraft* minecraft, const Options::Option* option, const std::vector<int>& stepVec);
virtual void render( Minecraft* minecraft, int xm, int ym );
virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum );
virtual void tick(Minecraft* minecraft);
private:
virtual void setOption(Minecraft* minecraft);
private:
SliderType sliderType;
std::vector<int> sliderSteps;
bool mouseDownOnElement;
float percentage;
int curStepValue;
int curStep;
int numSteps;
float progressMin;
float progressMax;
const Options::Option* option;
protected:
Slider(OptionId optId);
OptionId m_optId;
bool m_mouseDownOnElement;
float m_percentage;
int m_numSteps;
};
class SliderFloat : public Slider {
public:
SliderFloat(Minecraft* minecraft, OptionId option);
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
OptionFloat* m_option;
};
class SliderInt : public Slider {
public:
SliderInt(Minecraft* minecraft, OptionId option);
virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override;
protected:
OptionInt* m_option;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__*/

View File

@@ -1,24 +0,0 @@
#include "SmallButton.h"
SmallButton::SmallButton( int id, int x, int y, const std::string& msg )
: super(id, x, y, 150, 20, msg),
option(NULL)
{
}
SmallButton::SmallButton( int id, int x, int y, int width, int height, const std::string& msg )
: super(id, x, y, width, height, msg),
option(NULL)
{
}
SmallButton::SmallButton( int id, int x, int y, Options::Option* item, const std::string& msg )
: super(id, x, y, 150, 20, msg),
option(item)
{
}
Options::Option* SmallButton::getOption()
{
return option;
}

View File

@@ -1,23 +0,0 @@
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__
//package net.minecraft.client.gui;
#include <string>
#include "Button.h"
#include "../../Options.h"
class SmallButton: public Button
{
typedef Button super;
public:
SmallButton(int id, int x, int y, const std::string& msg);
SmallButton(int id, int x, int y, int width, int height, const std::string& msg);
SmallButton(int id, int x, int y, Options::Option* item, const std::string& msg);
Options::Option* getOption();
private:
Options::Option* option;
};
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__SmallButton_H__*/

View File

@@ -49,13 +49,13 @@ void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {
}
}
void TextBox::handleChar(char c) {
void TextBox::charPressed(Minecraft* minecraft, char c) {
if (focused && c >= 32 && c < 127 && (int)text.size() < 256) {
text.push_back(c);
}
}
void TextBox::handleKey(int key) {
void TextBox::keyPressed(Minecraft* minecraft, int key) {
if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) {
text.pop_back();
}

View File

@@ -26,8 +26,8 @@ public:
virtual void render(Minecraft* minecraft, int xm, int ym);
virtual void handleKey(int key);
virtual void handleChar(char c);
virtual void keyPressed(Minecraft* minecraft, int key);
virtual void charPressed(Minecraft* minecraft, char c);
virtual void tick(Minecraft* minecraft);
public:

View File

@@ -0,0 +1,17 @@
#include "TextOption.h"
#include <client/Minecraft.h>
TextOption::TextOption(Minecraft* minecraft, OptionId optId)
: TextBox((int)optId, minecraft->options.getOpt(optId)->getStringId())
{
text = minecraft->options.getStringValue(optId);
}
bool TextOption::loseFocus(Minecraft* minecraft) {
if (TextBox::loseFocus(minecraft)) {
minecraft->options.set((OptionId)id, text);
return true;
}
return false;
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "TextBox.h"
#include <client/Options.h>
class TextOption : public TextBox {
public:
TextOption(Minecraft* minecraft, OptionId optId);
virtual bool loseFocus(Minecraft* minecraft);
};

View File

@@ -4,7 +4,6 @@
//package net.minecraft.client.gui;
#include "../Screen.h"
#include "../components/SmallButton.h"
#include <string>
class ConfirmScreen: public Screen

View File

@@ -48,7 +48,7 @@ void ConsoleScreen::keyPressed(int eventKey)
}
}
void ConsoleScreen::keyboardNewChar(char inputChar)
void ConsoleScreen::charPressed(char inputChar)
{
if (inputChar >= 32 && inputChar < 127)
_input += inputChar;

View File

@@ -20,7 +20,7 @@ public:
virtual bool isPauseScreen() { return false; }
virtual void keyPressed(int eventKey);
virtual void keyboardNewChar(char inputChar);
virtual void charPressed(char inputChar);
virtual bool handleBackEvent(bool isDown);
private:

View File

@@ -169,19 +169,19 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey)
int tmpSelectedSlot = selectedItem;
Options& o = minecraft->options;
if (eventKey == o.keyLeft.key && selX > 0)
if (eventKey == o.getIntValue(OPTIONS_KEY_LEFT) && selX > 0)
{
tmpSelectedSlot -= 1;
}
else if (eventKey == o.keyRight.key && selX < (InventoryCols - 1))
else if (eventKey == o.getIntValue(OPTIONS_KEY_RIGHT) && selX < (InventoryCols - 1))
{
tmpSelectedSlot += 1;
}
else if (eventKey == o.keyDown.key && selY < (InventoryRows - 1))
else if (eventKey == o.getIntValue(OPTIONS_KEY_BACK) && selY < (InventoryRows - 1))
{
tmpSelectedSlot += InventoryCols;
}
else if (eventKey == o.keyUp.key && selY > 0)
else if (eventKey == o.getIntValue(OPTIONS_KEY_FORWARD) && selY > 0)
{
tmpSelectedSlot -= InventoryCols;
}
@@ -189,15 +189,15 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey)
if (isAllowed(tmpSelectedSlot))
selectedItem = tmpSelectedSlot;
if (eventKey == o.keyMenuOk.key)
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK))
selectSlotAndClose();
#ifdef RPI
if (eventKey == o.keyMenuCancel.key
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL)
|| eventKey == Keyboard::KEY_ESCAPE)
minecraft->setScreen(NULL);
#else
if (eventKey == o.keyMenuCancel.key)
if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL))
minecraft->setScreen(NULL);
#endif
}

View File

@@ -3,7 +3,6 @@
#include "../Screen.h"
#include "../components/Button.h"
#include "../components/SmallButton.h"
#include "../components/ScrolledSelectionList.h"
#include "../../Minecraft.h"
#include "../../../network/RakNetInstance.h"

View File

@@ -7,14 +7,12 @@
#include "../../../AppPlatform.h"
#include "CreditsScreen.h"
#include "../components/OptionsPane.h"
#include "../components/ImageButton.h"
#include "../components/OptionsGroup.h"
OptionsScreen::OptionsScreen()
: btnClose(NULL),
bHeader(NULL),
btnChangeUsername(NULL),
btnCredits(NULL),
selectedCategory(0) {
}
@@ -31,11 +29,6 @@ OptionsScreen::~OptionsScreen() {
bHeader = NULL;
}
if (btnChangeUsername != NULL) {
delete btnChangeUsername;
btnChangeUsername = NULL;
}
if (btnCredits != NULL) {
delete btnCredits;
btnCredits = NULL;
@@ -48,7 +41,7 @@ OptionsScreen::~OptionsScreen() {
}
}
for (std::vector<OptionsPane*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
for (std::vector<OptionsGroup*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
if (*it != NULL) {
delete* it;
*it = NULL;
@@ -72,17 +65,15 @@ void OptionsScreen::init() {
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
btnClose->setImageDef(def, true);
categoryButtons.push_back(new Touch::TButton(2, "Login"));
categoryButtons.push_back(new Touch::TButton(2, "General"));
categoryButtons.push_back(new Touch::TButton(3, "Game"));
categoryButtons.push_back(new Touch::TButton(4, "Controls"));
categoryButtons.push_back(new Touch::TButton(5, "Graphics"));
btnChangeUsername = new Touch::TButton(10, "Username");
btnCredits = new Touch::TButton(11, "Credits");
buttons.push_back(bHeader);
buttons.push_back(btnClose);
buttons.push_back(btnChangeUsername);
buttons.push_back(btnCredits);
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
@@ -118,27 +109,13 @@ void OptionsScreen::setupPositions() {
bHeader->width = width - btnClose->width;
bHeader->height = btnClose->height;
// Username button (bottom-left)
if (btnChangeUsername != NULL) {
btnChangeUsername->width = categoryButtons.empty() ? 80 : categoryButtons[0]->width;
btnChangeUsername->height = btnClose->height;
btnChangeUsername->x = 0;
btnChangeUsername->y = height - btnChangeUsername->height;
}
// Credits button (bottom-right)
if (btnCredits != NULL) {
btnCredits->width = btnChangeUsername->width;
btnCredits->height = btnChangeUsername->height;
btnCredits->x = width - btnCredits->width;
btnCredits->y = height - btnCredits->height;
}
for (std::vector<OptionsPane*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
for (std::vector<OptionsGroup*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
if (categoryButtons.size() > 0 && categoryButtons[0] != NULL) {
@@ -158,13 +135,13 @@ void OptionsScreen::render(int xm, int ym, float a) {
renderBackground();
super::render(xm, ym, a);
int xmm = xm * width / minecraft->width;
int ymm = ym * height / minecraft->height - 1;
if (currentOptionPane != NULL)
currentOptionPane->render(minecraft, xmm, ymm);
if (currentOptionsGroup != NULL)
currentOptionsGroup->render(minecraft, xmm, ymm);
super::render(xm, ym, a);
}
void OptionsScreen::removed() {
@@ -173,16 +150,9 @@ void OptionsScreen::removed() {
void OptionsScreen::buttonClicked(Button* button) {
if (button == btnClose) {
minecraft->options.save();
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
}
else if (button == btnChangeUsername) {
minecraft->options.save();
minecraft->setScreen(new UsernameScreen());
}
else if (button->id > 1 && button->id < 7) {
@@ -212,63 +182,88 @@ void OptionsScreen::selectCategory(int index) {
}
if (index < (int)optionPanes.size())
currentOptionPane = optionPanes[index];
currentOptionsGroup = optionPanes[index];
}
void OptionsScreen::generateOptionScreens() {
// how the fuck it works
optionPanes.push_back(new OptionsPane());
optionPanes.push_back(new OptionsPane());
optionPanes.push_back(new OptionsPane());
optionPanes.push_back(new OptionsPane());
optionPanes.push_back(new OptionsGroup("options.group.general"));
optionPanes.push_back(new OptionsGroup("options.group.game"));
optionPanes.push_back(new OptionsGroup("options.group.control"));
optionPanes.push_back(new OptionsGroup("options.group.graphics"));
// Login Pane
optionPanes[0]->createOptionsGroup("options.group.mojang")
.addOptionItem(&Options::Option::SENSITIVITY, minecraft);
// General Pane
optionPanes[0]->addOptionItem(OPTIONS_USERNAME, minecraft)
.addOptionItem(OPTIONS_SENSITIVITY, minecraft);
// Game Pane
optionPanes[1]->createOptionsGroup("options.group.game")
.addOptionItem(&Options::Option::DIFFICULTY, minecraft)
.addOptionItem(&Options::Option::SERVER_VISIBLE, minecraft)
.addOptionItem(&Options::Option::THIRD_PERSON, minecraft)
.addOptionItem(&Options::Option::GUI_SCALE, minecraft);
optionPanes[1]->addOptionItem(OPTIONS_DIFFICULTY, minecraft)
.addOptionItem(OPTIONS_SERVER_VISIBLE, minecraft)
.addOptionItem(OPTIONS_THIRD_PERSON_VIEW, minecraft)
.addOptionItem(OPTIONS_GUI_SCALE, minecraft)
.addOptionItem(OPTIONS_SENSITIVITY, minecraft)
.addOptionItem(OPTIONS_MUSIC_VOLUME, minecraft)
.addOptionItem(OPTIONS_SOUND_VOLUME, minecraft)
.addOptionItem(OPTIONS_SMOOTH_CAMERA, minecraft)
.addOptionItem(OPTIONS_DESTROY_VIBRATION, minecraft)
.addOptionItem(OPTIONS_IS_LEFT_HANDED, minecraft);
// Controls Pane
optionPanes[2]->createOptionsGroup("options.group.controls")
.addOptionItem(&Options::Option::INVERT_MOUSE, minecraft);
// // Controls Pane
optionPanes[2]->addOptionItem(OPTIONS_INVERT_Y_MOUSE, minecraft)
.addOptionItem(OPTIONS_USE_TOUCHSCREEN, minecraft);
// Graphics Pane
optionPanes[3]->createOptionsGroup("options.group.graphics")
.addOptionItem(&Options::Option::GRAPHICS, minecraft)
.addOptionItem(&Options::Option::VIEW_BOBBING, minecraft)
.addOptionItem(&Options::Option::AMBIENT_OCCLUSION, minecraft)
.addOptionItem(&Options::Option::ANAGLYPH, minecraft)
.addOptionItem(&Options::Option::LIMIT_FRAMERATE, minecraft)
.addOptionItem(&Options::Option::VSYNC, minecraft)
.addOptionItem(&Options::Option::MUSIC, minecraft)
.addOptionItem(&Options::Option::SOUND, minecraft);
for (int i = OPTIONS_KEY_FORWARD; i <= OPTIONS_KEY_USE; i++) {
optionPanes[2]->addOptionItem((OptionId)i, minecraft);
}
// // Graphics Pane
optionPanes[3]->addOptionItem(OPTIONS_FANCY_GRAPHICS, minecraft)
// .addOptionItem(&Options::Option::VIEW_BOBBING, minecraft)
// .addOptionItem(&Options::Option::AMBIENT_OCCLUSION, minecraft)
// .addOptionItem(&Options::Option::ANAGLYPH, minecraft)
.addOptionItem(OPTIONS_LIMIT_FRAMERATE, minecraft)
.addOptionItem(OPTIONS_VSYNC, minecraft)
.addOptionItem(OPTIONS_RENDER_DEBUG, minecraft)
.addOptionItem(OPTIONS_ANAGLYPH_3D, minecraft)
.addOptionItem(OPTIONS_VIEW_BOBBING, minecraft)
.addOptionItem(OPTIONS_AMBIENT_OCCLUSION, minecraft);
}
void OptionsScreen::mouseClicked(int x, int y, int buttonNum) {
if (currentOptionPane != NULL)
currentOptionPane->mouseClicked(minecraft, x, y, buttonNum);
if (currentOptionsGroup != NULL)
currentOptionsGroup->mouseClicked(minecraft, x, y, buttonNum);
super::mouseClicked(x, y, buttonNum);
}
void OptionsScreen::mouseReleased(int x, int y, int buttonNum) {
if (currentOptionPane != NULL)
currentOptionPane->mouseReleased(minecraft, x, y, buttonNum);
if (currentOptionsGroup != NULL)
currentOptionsGroup->mouseReleased(minecraft, x, y, buttonNum);
super::mouseReleased(x, y, buttonNum);
}
void OptionsScreen::keyPressed(int eventKey) {
if (currentOptionsGroup != NULL)
currentOptionsGroup->keyPressed(minecraft, eventKey);
super::keyPressed(eventKey);
}
void OptionsScreen::charPressed(char inputChar) {
if (currentOptionsGroup != NULL)
currentOptionsGroup->charPressed(minecraft, inputChar);
super::keyPressed(inputChar);
}
void OptionsScreen::tick() {
if (currentOptionPane != NULL)
currentOptionPane->tick(minecraft);
if (currentOptionsGroup != NULL)
currentOptionsGroup->tick(minecraft);
super::tick();
}

View File

@@ -3,6 +3,7 @@
#include "../Screen.h"
#include "../components/Button.h"
#include "../components/OptionsGroup.h"
class ImageButton;
class OptionsPane;
@@ -26,19 +27,21 @@ public:
virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseReleased(int x, int y, int buttonNum);
virtual void keyPressed(int eventKey);
virtual void charPressed(char inputChar);
virtual void tick();
private:
Touch::THeader* bHeader;
ImageButton* btnClose;
Button* btnChangeUsername;
Button* btnCredits; // <-- ADD THIS
std::vector<Touch::TButton*> categoryButtons;
std::vector<OptionsPane*> optionPanes;
std::vector<OptionsGroup*> optionPanes;
OptionsPane* currentOptionPane;
OptionsGroup* currentOptionsGroup;
int selectedCategory;
};

View File

@@ -15,9 +15,9 @@ PauseScreen::PauseScreen(bool wasBackPaused)
bServerVisibility(0),
// bThirdPerson(0),
wasBackPaused(wasBackPaused),
bSound(&Options::Option::SOUND, 1, 0),
bThirdPerson(&Options::Option::THIRD_PERSON),
bHideGui(&Options::Option::HIDE_GUI)
// bSound(OPTIONS_SOUND_VOLUME, 1, 0),
bThirdPerson(OPTIONS_THIRD_PERSON_VIEW),
bHideGui(OPTIONS_HIDEGUI)
{
ImageDef def;
def.setSrc(IntRectangle(160, 144, 39, 31));
@@ -27,7 +27,7 @@ PauseScreen::PauseScreen(bool wasBackPaused)
def.width = defSrc.w * 0.666667f;
def.height = defSrc.h * 0.666667f;
bSound.setImageDef(def, true);
// bSound.setImageDef(def, true);
defSrc.y += defSrc.h;
bThirdPerson.setImageDef(def, true);
bHideGui.setImageDef(def, true);
@@ -60,10 +60,10 @@ void PauseScreen::init() {
buttons.push_back(bContinue);
buttons.push_back(bQuit);
bSound.updateImage(&minecraft->options);
// bSound.updateImage(&minecraft->options);
bThirdPerson.updateImage(&minecraft->options);
bHideGui.updateImage(&minecraft->options);
buttons.push_back(&bSound);
// buttons.push_back(&bSound);
buttons.push_back(&bThirdPerson);
//buttons.push_back(&bHideGui);
@@ -88,7 +88,7 @@ void PauseScreen::init() {
// buttons.push_back(bThirdPerson);
for (unsigned int i = 0; i < buttons.size(); ++i) {
if (buttons[i] == &bSound) continue;
// if (buttons[i] == &bSound) continue;
if (buttons[i] == &bThirdPerson) continue;
if (buttons[i] == &bHideGui) continue;
tabButtons.push_back(buttons[i]);
@@ -115,10 +115,10 @@ void PauseScreen::setupPositions() {
bQuitAndSaveLocally->x = bServerVisibility->x = (width - bQuitAndSaveLocally->width) / 2;
bQuitAndSaveLocally->y = bServerVisibility->y = yBase + 32 * 3;
bSound.y = bThirdPerson.y = 8;
bSound.x = 4;
bThirdPerson.x = bSound.x + 4 + bSound.width;
bHideGui.x = bThirdPerson.x + 4 + bThirdPerson.width;
// bSound.y = bThirdPerson.y = 8;
// bSound.x = 4;
// bThirdPerson.x = bSound.x + 4 + bSound.width;
// bHideGui.x = bThirdPerson.x + 4 + bThirdPerson.width;
//bThirdPerson->x = (width - bThirdPerson->w) / 2;
//bThirdPerson->y = yBase + 32 * 4;

View File

@@ -35,7 +35,7 @@ private:
Button* bServerVisibility;
// Button* bThirdPerson;
OptionButton bSound;
// OptionButton bSound;
OptionButton bThirdPerson;
OptionButton bHideGui;
};

View File

@@ -12,6 +12,8 @@
#include "../../Minecraft.h"
#include <client/gui/screens/UsernameScreen.h>
Screen* ScreenChooser::createScreen( ScreenId id )
{
Screen* screen = NULL;

View File

@@ -415,9 +415,9 @@ bool SelectWorldScreen::isInGameScreen() { return true; }
void SelectWorldScreen::keyPressed( int eventKey )
{
if (bWorldView.selected) {
if (eventKey == minecraft->options.keyLeft.key)
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT))
worldsList->stepLeft();
if (eventKey == minecraft->options.keyRight.key)
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT))
worldsList->stepRight();
}

View File

@@ -4,7 +4,6 @@
#include "../Screen.h"
#include "../TweenData.h"
#include "../components/Button.h"
#include "../components/SmallButton.h"
#include "../components/RolledSelectionListH.h"
#include "../../Minecraft.h"
#include "../../../world/level/storage/LevelStorageSource.h"

View File

@@ -223,12 +223,6 @@ void SimpleChooseLevelScreen::keyPressed(int eventKey)
Screen::keyPressed(eventKey);
}
void SimpleChooseLevelScreen::keyboardNewChar(char inputChar)
{
// forward character input to focused textbox(s)
for (auto* tb : textBoxes) tb->handleChar(inputChar);
}
bool SimpleChooseLevelScreen::handleBackEvent(bool isDown) {
if (!isDown)
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);

View File

@@ -23,7 +23,6 @@ public:
void buttonClicked(Button* button);
bool handleBackEvent(bool isDown);
virtual void keyPressed(int eventKey);
virtual void keyboardNewChar(char inputChar);
virtual void mouseClicked(int x, int y, int buttonNum);
private:

View File

@@ -10,7 +10,6 @@
#include "../../../util/Mth.h"
#include "../Font.h"
#include "../components/SmallButton.h"
#include "../components/ScrolledSelectionList.h"
#include "../../Minecraft.h"
@@ -38,7 +37,7 @@ void StartMenuScreen::init()
bJoin.active = bHost.active = bOptions.active = true;
if (minecraft->options.username.empty()) {
if (minecraft->options.getStringValue(OPTIONS_USERNAME).empty()) {
return; // tick() will redirect to UsernameScreen
}
@@ -105,7 +104,7 @@ void StartMenuScreen::setupPositions() {
}
void StartMenuScreen::tick() {
if (minecraft->options.username.empty()) {
if (minecraft->options.getStringValue(OPTIONS_USERNAME).empty()) {
minecraft->setScreen(new UsernameScreen());
return;
}

View File

@@ -132,7 +132,7 @@ void TextEditScreen::keyPressed( int eventKey ) {
}
}
void TextEditScreen::keyboardNewChar( char inputChar ) {
void TextEditScreen::charPressed( char inputChar ) {
std::string fullstring = sign->messages[line] + inputChar;
if(fullstring.length() < 16) {
sign->messages[line] = fullstring;

View File

@@ -20,7 +20,7 @@ public:
void render(int xm, int ym, float a);
virtual void lostFocus();
virtual void keyPressed(int eventKey);
virtual void keyboardNewChar(char inputChar);
virtual void charPressed(char inputChar);
void setupPositions();
void buttonClicked(Button* button);
protected:

View File

@@ -63,30 +63,6 @@ void UsernameScreen::keyPressed(int eventKey)
Screen::keyPressed(eventKey);
}
void UsernameScreen::keyboardNewChar(char inputChar)
{
for (auto* tb : textBoxes) tb->handleChar(inputChar);
}
void UsernameScreen::mouseClicked(int x, int y, int button)
{
int lvlTop = tUsername.y - (Font::DefaultLineHeight + 4);
int lvlBottom = tUsername.y + tUsername.height;
int lvlLeft = tUsername.x;
int lvlRight = tUsername.x + tUsername.width;
bool clickedLevel = x >= lvlLeft && x < lvlRight && y >= lvlTop && y < lvlBottom;
if (clickedLevel) {
tUsername.setFocus(minecraft);
} else {
// click outside both fields -> blur both
tUsername.loseFocus(minecraft);
}
// also let the parent class handle button presses/etc.
Screen::mouseClicked(x, y, button);
}
void UsernameScreen::removed()
{
minecraft->platform()->hideKeyboard();
@@ -95,7 +71,7 @@ void UsernameScreen::removed()
void UsernameScreen::buttonClicked(Button* button)
{
if (button == &_btnDone && !tUsername.text.empty()) {
minecraft->options.username = tUsername.text;
minecraft->options.set(OPTIONS_USERNAME, tUsername.text);
minecraft->options.save();
minecraft->user->name = tUsername.text;
minecraft->setScreen(NULL); // goes to StartMenuScreen

View File

@@ -13,24 +13,22 @@ public:
UsernameScreen();
virtual ~UsernameScreen();
void init();
void init() override;
virtual void setupPositions() override;
void render(int xm, int ym, float a);
void tick();
void render(int xm, int ym, float a) override;
void tick() override;
virtual bool isPauseScreen() { return false; }
virtual bool isPauseScreen() override { return false; }
virtual void keyPressed(int eventKey);
virtual void keyboardNewChar(char inputChar);
virtual bool handleBackEvent(bool isDown) { return true; } // block back/escape
virtual void removed();
virtual void mouseClicked(int x, int y, int button);
virtual void keyPressed(int eventKey) override;
virtual bool handleBackEvent(bool isDown) override { return true; } // block back/escape
virtual void removed() override;
protected:
virtual void buttonClicked(Button* button);
virtual void buttonClicked(Button* button) override;
private:
Button _btnDone;
Touch::TButton _btnDone;
TextBox tUsername;
std::string _input;
int _cursorBlink;

View File

@@ -3,7 +3,6 @@
#include "../../Screen.h"
#include "../../components/Button.h"
#include "../../components/SmallButton.h"
#include "../../components/RolledSelectionListV.h"
#include "../../../Minecraft.h"
#include "../../../../platform/input/Multitouch.h"

View File

@@ -552,9 +552,9 @@ bool SelectWorldScreen::isInGameScreen() { return true; }
void SelectWorldScreen::keyPressed( int eventKey )
{
if (bWorldView.selected) {
if (eventKey == minecraft->options.keyLeft.key)
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT))
worldsList->stepLeft();
if (eventKey == minecraft->options.keyRight.key)
if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT))
worldsList->stepRight();
}

View File

@@ -4,7 +4,6 @@
#include "../PauseScreen.h"
#include "../../Font.h"
#include "../../components/SmallButton.h"
#include "../../components/ScrolledSelectionList.h"
#include "../../components/GuiElement.h"
@@ -58,7 +57,6 @@ void StartMenuScreen::init()
buttons.push_back(&bHost);
buttons.push_back(&bJoin);
buttons.push_back(&bOptions);
tabButtons.push_back(&bHost);