Skip to content

Commit

Permalink
Use a dropdown instead of a textbox
Browse files Browse the repository at this point in the history
Textboxes don't mix well with error messages fired from from keypress handlers.
  • Loading branch information
LBPHacker authored and jacob1 committed Nov 23, 2017
1 parent be29fad commit a12785c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/gui/interface/Textbox.cpp
Expand Up @@ -144,7 +144,7 @@ void Textbox::cutSelection()
std::string toCopy = backingText.substr(getLowerSelectionBound(), getHigherSelectionBound()-getLowerSelectionBound());
ClipboardPush(format::CleanString(toCopy, false, true, false));
backingText.erase(backingText.begin()+getLowerSelectionBound(), backingText.begin()+getHigherSelectionBound());
cursor = getLowerSelectionBound();
cursor = getLowerSelectionBound();
}
else
{
Expand Down Expand Up @@ -278,7 +278,8 @@ void Textbox::Tick(float dt)
keyDown = 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);
repeatTime = Platform::GetTime()+30;
Expand Down
18 changes: 1 addition & 17 deletions src/gui/options/OptionsController.cpp
Expand Up @@ -9,7 +9,6 @@ OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * c
HasExited(false)
{
this->depth3d = ui::Engine::Ref().Get3dDepth();
this->newScale = ui::Engine::Ref().GetScale();
view = new OptionsView();
model = new OptionsModel(gModel);
model->AddObserver(view);
Expand Down Expand Up @@ -64,7 +63,7 @@ void OptionsController::SetShowAvatars(bool showAvatars)

void OptionsController::SetScale(int scale)
{
newScale = scale;
model->SetScale(scale);
}

void OptionsController::SetFastQuit(bool fastquit)
Expand All @@ -88,21 +87,6 @@ void OptionsController::Exit()
// only update on close, it would be hard to edit if the changes were live
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)
callback->ControllerExit();
HasExited = true;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/options/OptionsController.h
Expand Up @@ -14,7 +14,7 @@ class OptionsController {
OptionsView * view;
OptionsModel * model;
ControllerCallback * callback;
int depth3d, newScale;
int depth3d;
public:
bool HasExited;
OptionsController(GameModel * gModel_, ControllerCallback * callback_);
Expand Down
11 changes: 11 additions & 0 deletions src/gui/options/OptionsModel.cpp
Expand Up @@ -90,6 +90,17 @@ void OptionsModel::SetGravityMode(int gravityMode)
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()
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/options/OptionsModel.h
Expand Up @@ -31,6 +31,8 @@ class OptionsModel {
void SetEdgeMode(int edgeMode);
int GetGravityMode();
void SetGravityMode(int gravityMode);
int GetScale();
void SetScale(int scale);
bool GetFullscreen();
void SetFullscreen(bool fullscreen);
bool GetFastQuit();
Expand Down
25 changes: 20 additions & 5 deletions src/gui/options/OptionsView.cpp
Expand Up @@ -142,15 +142,29 @@ OptionsView::OptionsView():
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(tempLabel);

class ScaleAction: public ui::TextboxAction
class ScaleAction: public ui::DropDownAction
{
OptionsView * v;
public:
ScaleAction(OptionsView * v_) { v = v_; }
virtual void TextChangedCallback(ui::Textbox * sender) { v->c->SetScale(format::StringToNumber<int>(sender->GetText())); }
ScaleAction(OptionsView * v): v(v) { }
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->SetInputType(ui::Textbox::Numeric);
scale = new ui::DropDown(ui::Point(8, 210), ui::Point(40, 16));
{
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));
AddComponent(scale);

Expand Down Expand Up @@ -286,6 +300,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
airMode->SetOption(sender->GetAirMode());
gravityMode->SetOption(sender->GetGravityMode());
edgeMode->SetOption(sender->GetEdgeMode());
scale->SetOption(sender->GetScale());
fullscreen->SetChecked(sender->GetFullscreen());
fastquit->SetChecked(sender->GetFastQuit());
showAvatars->SetChecked(sender->GetShowAvatars());
Expand Down
2 changes: 1 addition & 1 deletion src/gui/options/OptionsView.h
Expand Up @@ -19,7 +19,7 @@ class OptionsView: public ui::Window {
ui::DropDown * airMode;
ui::DropDown * gravityMode;
ui::DropDown * edgeMode;
ui::Textbox * scale;
ui::DropDown * scale;
ui::Checkbox * fullscreen;
ui::Checkbox * fastquit;
ui::Checkbox * showAvatars;
Expand Down

0 comments on commit a12785c

Please sign in to comment.