Use a dropdown instead of a textbox

Textboxes don't mix well with error messages fired from from keypress handlers.
This commit is contained in:
LBPHacker 2017-11-23 16:35:44 +01:00 committed by jacob1
parent be29fad7e8
commit a12785cd5d
7 changed files with 39 additions and 26 deletions

View File

@ -278,7 +278,8 @@ void Textbox::Tick(float dt)
keyDown = 0; keyDown = 0;
characterDown = 0; characterDown = 0;
} }
if ((keyDown || characterDown) && repeatTime <= Platform::GetTime()) unsigned long time_pls = Platform::GetTime();
if ((keyDown || characterDown) && repeatTime <= time_pls)
{ {
OnVKeyPress(keyDown, characterDown, false, false, false); OnVKeyPress(keyDown, characterDown, false, false, false);
repeatTime = Platform::GetTime()+30; repeatTime = Platform::GetTime()+30;

View File

@ -9,7 +9,6 @@ OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * c
HasExited(false) HasExited(false)
{ {
this->depth3d = ui::Engine::Ref().Get3dDepth(); this->depth3d = ui::Engine::Ref().Get3dDepth();
this->newScale = ui::Engine::Ref().GetScale();
view = new OptionsView(); view = new OptionsView();
model = new OptionsModel(gModel); model = new OptionsModel(gModel);
model->AddObserver(view); model->AddObserver(view);
@ -64,7 +63,7 @@ void OptionsController::SetShowAvatars(bool showAvatars)
void OptionsController::SetScale(int scale) void OptionsController::SetScale(int scale)
{ {
newScale = scale; model->SetScale(scale);
} }
void OptionsController::SetFastQuit(bool fastquit) void OptionsController::SetFastQuit(bool fastquit)
@ -88,21 +87,6 @@ void OptionsController::Exit()
// only update on close, it would be hard to edit if the changes were live // only update on close, it would be hard to edit if the changes were live
ui::Engine::Ref().Set3dDepth(depth3d); ui::Engine::Ref().Set3dDepth(depth3d);
{
if (newScale < 1)
newScale = 1;
bool reduced_scale = false;
while (!(ui::Engine::Ref().GetMaxWidth() >= ui::Engine::Ref().GetWidth() * newScale && ui::Engine::Ref().GetMaxHeight() >= ui::Engine::Ref().GetHeight() * newScale) && newScale > 1)
{
newScale -= 1;
reduced_scale = true;
}
if (reduced_scale)
new ErrorMessage("Screen resolution error", "Your screen size is too small to use this scale mode. Using largest available scale.");
ui::Engine::Ref().SetScale(newScale);
Client::Ref().SetPref("Scale", newScale);
}
if (callback) if (callback)
callback->ControllerExit(); callback->ControllerExit();
HasExited = true; HasExited = true;

View File

@ -14,7 +14,7 @@ class OptionsController {
OptionsView * view; OptionsView * view;
OptionsModel * model; OptionsModel * model;
ControllerCallback * callback; ControllerCallback * callback;
int depth3d, newScale; int depth3d;
public: public:
bool HasExited; bool HasExited;
OptionsController(GameModel * gModel_, ControllerCallback * callback_); OptionsController(GameModel * gModel_, ControllerCallback * callback_);

View File

@ -90,6 +90,17 @@ void OptionsModel::SetGravityMode(int gravityMode)
notifySettingsChanged(); notifySettingsChanged();
} }
int OptionsModel::GetScale()
{
return ui::Engine::Ref().GetScale();
}
void OptionsModel::SetScale(int scale)
{
ui::Engine::Ref().SetScale(scale);
Client::Ref().SetPref("Scale", int(scale));
notifySettingsChanged();
}
bool OptionsModel::GetFullscreen() bool OptionsModel::GetFullscreen()
{ {

View File

@ -31,6 +31,8 @@ public:
void SetEdgeMode(int edgeMode); void SetEdgeMode(int edgeMode);
int GetGravityMode(); int GetGravityMode();
void SetGravityMode(int gravityMode); void SetGravityMode(int gravityMode);
int GetScale();
void SetScale(int scale);
bool GetFullscreen(); bool GetFullscreen();
void SetFullscreen(bool fullscreen); void SetFullscreen(bool fullscreen);
bool GetFastQuit(); bool GetFastQuit();

View File

@ -142,15 +142,29 @@ OptionsView::OptionsView():
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(tempLabel); AddComponent(tempLabel);
class ScaleAction: public ui::TextboxAction class ScaleAction: public ui::DropDownAction
{ {
OptionsView * v; OptionsView * v;
public: public:
ScaleAction(OptionsView * v_) { v = v_; } ScaleAction(OptionsView * v): v(v) { }
virtual void TextChangedCallback(ui::Textbox * sender) { v->c->SetScale(format::StringToNumber<int>(sender->GetText())); } virtual void OptionChanged(ui::DropDown * sender, std::pair<std::string, int> option) { v->c->SetScale(option.second); }
}; };
scale = new ui::Textbox(ui::Point(8, 210), ui::Point(25, 16), format::NumberToString<int>(ui::Engine::Ref().GetScale())); scale = new ui::DropDown(ui::Point(8, 210), ui::Point(40, 16));
scale->SetInputType(ui::Textbox::Numeric); {
int current_scale = ui::Engine::Ref().GetScale();
int ix_scale = 1;
bool current_scale_valid = false;
do
{
if (current_scale == ix_scale)
current_scale_valid = true;
scale->AddOption(std::pair<std::string, int>(format::NumberToString<int>(ix_scale), ix_scale));
ix_scale += 1;
}
while (ui::Engine::Ref().GetMaxWidth() >= ui::Engine::Ref().GetWidth() * ix_scale && ui::Engine::Ref().GetMaxHeight() >= ui::Engine::Ref().GetHeight() * ix_scale);
if (!current_scale_valid)
scale->AddOption(std::pair<std::string, int>("current", current_scale));
}
scale->SetActionCallback(new ScaleAction(this)); scale->SetActionCallback(new ScaleAction(this));
AddComponent(scale); AddComponent(scale);
@ -286,6 +300,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
airMode->SetOption(sender->GetAirMode()); airMode->SetOption(sender->GetAirMode());
gravityMode->SetOption(sender->GetGravityMode()); gravityMode->SetOption(sender->GetGravityMode());
edgeMode->SetOption(sender->GetEdgeMode()); edgeMode->SetOption(sender->GetEdgeMode());
scale->SetOption(sender->GetScale());
fullscreen->SetChecked(sender->GetFullscreen()); fullscreen->SetChecked(sender->GetFullscreen());
fastquit->SetChecked(sender->GetFastQuit()); fastquit->SetChecked(sender->GetFastQuit());
showAvatars->SetChecked(sender->GetShowAvatars()); showAvatars->SetChecked(sender->GetShowAvatars());

View File

@ -19,7 +19,7 @@ class OptionsView: public ui::Window {
ui::DropDown * airMode; ui::DropDown * airMode;
ui::DropDown * gravityMode; ui::DropDown * gravityMode;
ui::DropDown * edgeMode; ui::DropDown * edgeMode;
ui::Textbox * scale; ui::DropDown * scale;
ui::Checkbox * fullscreen; ui::Checkbox * fullscreen;
ui::Checkbox * fastquit; ui::Checkbox * fastquit;
ui::Checkbox * showAvatars; ui::Checkbox * showAvatars;