mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-03-21 06:40:02 +01:00
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:
parent
be29fad7e8
commit
a12785cd5d
@ -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
|
||||
{
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
@ -64,7 +63,7 @@ void OptionsController::SetShowAvatars(bool showAvatars)
|
||||
|
||||
void OptionsController::SetScale(int scale)
|
||||
{
|
||||
newScale = scale;
|
||||
model->SetScale(scale);
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
|
@ -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_);
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -31,6 +31,8 @@ public:
|
||||
void SetEdgeMode(int edgeMode);
|
||||
int GetGravityMode();
|
||||
void SetGravityMode(int gravityMode);
|
||||
int GetScale();
|
||||
void SetScale(int scale);
|
||||
bool GetFullscreen();
|
||||
void SetFullscreen(bool fullscreen);
|
||||
bool GetFastQuit();
|
||||
|
@ -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);
|
||||
|
||||
@ -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());
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user