From 5508f0ccfd9942e89be7e1cec4f01327b1fae51f Mon Sep 17 00:00:00 2001 From: yareky <18265227+yareky@users.noreply.github.com> Date: Tue, 2 Jul 2019 10:47:27 +0200 Subject: [PATCH] Allows to change menu selection from hovering to mouse click New option in the menu available. This new menu behaviour is disabled by default. --- src/gui/game/GameController.cpp | 5 ++ src/gui/game/GameController.h | 1 + src/gui/game/GameModel.cpp | 15 +++++ src/gui/game/GameModel.h | 3 + src/gui/game/GameView.cpp | 4 +- src/gui/options/OptionsController.cpp | 5 ++ src/gui/options/OptionsController.h | 2 + src/gui/options/OptionsModel.cpp | 12 ++++ src/gui/options/OptionsModel.h | 2 + src/gui/options/OptionsView.cpp | 92 +++++++++++++++++---------- src/gui/options/OptionsView.h | 3 + 11 files changed, 109 insertions(+), 35 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 2b1de0f23..0af06bf54 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1781,3 +1781,8 @@ void GameController::RunUpdater() Platform::OpenURI(file); #endif // MACOSX } + +bool GameController::GetMouseClickRequired() +{ + return gameModel->GetMouseClickRequired(); +} \ No newline at end of file diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index a767748ee..d10479b3e 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -177,6 +177,7 @@ public: void NotifyAuthUserChanged(Client * sender) override; void NotifyNewNotification(Client * sender, std::pair notification) override; void RunUpdater(); + bool GetMouseClickRequired(); }; #endif // GAMECONTROLLER_H diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index acaf5e359..95e5a4bac 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -153,6 +153,8 @@ GameModel::GameModel(): // cap due to memory usage (this is about 3.4GB of RAM) if (undoHistoryLimit > 200) undoHistoryLimit = 200; + + mouseClickRequired = Client::Ref().GetPrefBool("MouseClickRequired", false); } GameModel::~GameModel() @@ -182,6 +184,8 @@ GameModel::~GameModel() Client::Ref().SetPref("Simulation.UndoHistoryLimit", undoHistoryLimit); + Client::Ref().SetPref("MouseClickRequired", mouseClickRequired); + Favorite::Ref().SaveFavoritesToPrefs(); for (size_t i = 0; i < menuList.size(); i++) @@ -1294,3 +1298,14 @@ void GameModel::notifyLastToolChanged() observers[i]->NotifyLastToolChanged(this); } } + +bool GameModel::GetMouseClickRequired() +{ + return mouseClickRequired; +} + +void GameModel::SetMouseClickRequired(bool mouseClickRequired_) +{ + mouseClickRequired = mouseClickRequired_; + notifyMenuListChanged(); +} \ No newline at end of file diff --git a/src/gui/game/GameModel.h b/src/gui/game/GameModel.h index e40b971d0..42d414560 100644 --- a/src/gui/game/GameModel.h +++ b/src/gui/game/GameModel.h @@ -67,6 +67,7 @@ private: Snapshot *redoHistory; unsigned int historyPosition; unsigned int undoHistoryLimit; + bool mouseClickRequired; size_t activeColourPreset; std::vector colourPresets; @@ -202,6 +203,8 @@ public: std::deque GetLog(); GameSave * GetClipboard(); GameSave * GetPlaceSave(); + bool GetMouseClickRequired(); + void SetMouseClickRequired(bool mouseClickRequired_); std::vector GetNotifications(); void AddNotification(Notification * notification); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 475997981..8c07467b0 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -492,10 +492,10 @@ public: { v = _v; menuID = menuID_; - if (menuID == SC_DECO) + if (menuID == SC_DECO) needsClick = true; else - needsClick = false; + needsClick = v->c->GetMouseClickRequired(); } void MouseEnterCallback(ui::Button * sender) override { diff --git a/src/gui/options/OptionsController.cpp b/src/gui/options/OptionsController.cpp index e42095ee7..eb16ad9c1 100644 --- a/src/gui/options/OptionsController.cpp +++ b/src/gui/options/OptionsController.cpp @@ -92,6 +92,11 @@ OptionsView * OptionsController::GetView() return view; } +void OptionsController::SetMouseClickrequired(bool mouseClickRequired) +{ + model->SetMouseClickRequired(mouseClickRequired); +} + void OptionsController::Exit() { view->CloseActiveWindow(); diff --git a/src/gui/options/OptionsController.h b/src/gui/options/OptionsController.h index c5acd1178..e47e75c3d 100644 --- a/src/gui/options/OptionsController.h +++ b/src/gui/options/OptionsController.h @@ -28,6 +28,8 @@ public: void SetResizable(bool resizable); void SetFastQuit(bool fastquit); void SetShowAvatars(bool showAvatars); + void SetMouseClickrequired(bool mouseClickRequired); + void Exit(); OptionsView * GetView(); virtual ~OptionsController(); diff --git a/src/gui/options/OptionsModel.cpp b/src/gui/options/OptionsModel.cpp index 2dcdf6e2c..d36f528e3 100644 --- a/src/gui/options/OptionsModel.cpp +++ b/src/gui/options/OptionsModel.cpp @@ -180,6 +180,18 @@ void OptionsModel::SetShowAvatars(bool state) notifySettingsChanged(); } +bool OptionsModel::GetMouseClickRequired() +{ + return Client::Ref().GetPrefBool("MouseClickRequired", false); +} + +void OptionsModel::SetMouseClickRequired(bool mouseClickRequired) +{ + Client::Ref().SetPref("MouseClickRequired", mouseClickRequired); + gModel->SetMouseClickRequired(mouseClickRequired); + notifySettingsChanged(); +} + void OptionsModel::notifySettingsChanged() { for (size_t i = 0; i < observers.size(); i++) diff --git a/src/gui/options/OptionsModel.h b/src/gui/options/OptionsModel.h index d1fa53374..22e4a5780 100644 --- a/src/gui/options/OptionsModel.h +++ b/src/gui/options/OptionsModel.h @@ -43,6 +43,8 @@ public: void SetForceIntegerScaling(bool forceIntegerScaling); bool GetFastQuit(); void SetFastQuit(bool fastquit); + bool GetMouseClickRequired(); + void SetMouseClickRequired(bool mouseClickRequired); virtual ~OptionsModel(); }; diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index 4e990e2ec..50990b47d 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -23,12 +23,18 @@ #include "graphics/Graphics.h" OptionsView::OptionsView(): - ui::Window(ui::Point(-1, -1), ui::Point(300, 389)){ + ui::Window(ui::Point(-1, -1), ui::Point(350, 389)){ + + int currentY = 400; + scrollPanel = new ui::ScrollPanel(ui::Point(-1, -1), ui::Point(Size.X, Size.Y-16)); + + AddComponent(scrollPanel); ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options"); tempLabel->SetTextColour(style::Colour::InformationTitle); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); + class HeatSimulationAction: public ui::CheckboxAction { @@ -42,10 +48,10 @@ OptionsView::OptionsView(): heatSimulation = new ui::Checkbox(ui::Point(8, 23), ui::Point(Size.X-6, 16), "Heat simulation \bgIntroduced in version 34", ""); heatSimulation->SetActionCallback(new HeatSimulationAction(this)); - AddComponent(heatSimulation); + scrollPanel->AddChild(heatSimulation); tempLabel = new ui::Label(ui::Point(24, heatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour when disabled"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class AmbientHeatSimulationAction: public ui::CheckboxAction { @@ -59,10 +65,10 @@ OptionsView::OptionsView(): ambientHeatSimulation = new ui::Checkbox(ui::Point(8, 53), ui::Point(Size.X-6, 16), "Ambient heat simulation \bgIntroduced in version 50", ""); ambientHeatSimulation->SetActionCallback(new AmbientHeatSimulationAction(this)); - AddComponent(ambientHeatSimulation); + scrollPanel->AddChild(ambientHeatSimulation); tempLabel = new ui::Label(ui::Point(24, ambientHeatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd / broken behaviour with many saves"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class NewtonianGravityAction: public ui::CheckboxAction { @@ -76,10 +82,10 @@ OptionsView::OptionsView(): newtonianGravity = new ui::Checkbox(ui::Point(8, 83), ui::Point(Size.X-6, 16), "Newtonian gravity \bgIntroduced in version 48", ""); newtonianGravity->SetActionCallback(new NewtonianGravityAction(this)); - AddComponent(newtonianGravity); + scrollPanel->AddChild(newtonianGravity); tempLabel = new ui::Label(ui::Point(24, newtonianGravity->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance on older computers"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class WaterEqualisationAction: public ui::CheckboxAction { @@ -93,10 +99,10 @@ OptionsView::OptionsView(): waterEqualisation = new ui::Checkbox(ui::Point(8, 113), ui::Point(Size.X-6, 16), "Water equalisation \bgIntroduced in version 61", ""); waterEqualisation->SetActionCallback(new WaterEqualisationAction(this)); - AddComponent(waterEqualisation); + scrollPanel->AddChild(waterEqualisation); tempLabel = new ui::Label(ui::Point(24, waterEqualisation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance with a lot of water"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class AirModeChanged: public ui::DropDownAction { @@ -108,7 +114,7 @@ OptionsView::OptionsView(): } }; airMode = new ui::DropDown(ui::Point(Size.X-88, 146), ui::Point(80, 16)); - AddComponent(airMode); + scrollPanel->AddChild(airMode); airMode->AddOption(std::pair("On", 0)); airMode->AddOption(std::pair("Pressure off", 1)); airMode->AddOption(std::pair("Velocity off", 2)); @@ -118,7 +124,7 @@ OptionsView::OptionsView(): tempLabel = new ui::Label(ui::Point(8, 146), ui::Point(Size.X-96, 16), "Air Simulation Mode"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class GravityModeChanged: public ui::DropDownAction { @@ -131,7 +137,7 @@ OptionsView::OptionsView(): }; gravityMode = new ui::DropDown(ui::Point(Size.X-88, 166), ui::Point(80, 16)); - AddComponent(gravityMode); + scrollPanel->AddChild(gravityMode); gravityMode->AddOption(std::pair("Vertical", 0)); gravityMode->AddOption(std::pair("Off", 1)); gravityMode->AddOption(std::pair("Radial", 2)); @@ -139,7 +145,7 @@ OptionsView::OptionsView(): tempLabel = new ui::Label(ui::Point(8, 166), ui::Point(Size.X-96, 16), "Gravity Simulation Mode"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class EdgeModeChanged: public ui::DropDownAction { @@ -152,7 +158,7 @@ OptionsView::OptionsView(): }; edgeMode = new ui::DropDown(ui::Point(Size.X-88, 186), ui::Point(80, 16)); - AddComponent(edgeMode); + scrollPanel->AddChild(edgeMode); edgeMode->AddOption(std::pair("Void", 0)); edgeMode->AddOption(std::pair("Solid", 1)); edgeMode->AddOption(std::pair("Loop", 2)); @@ -160,7 +166,7 @@ OptionsView::OptionsView(): tempLabel = new ui::Label(ui::Point(8, 186), ui::Point(Size.X-96, 16), "Edge Mode"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class ScaleAction: public ui::DropDownAction { @@ -188,11 +194,11 @@ OptionsView::OptionsView(): scale->AddOption(std::pair("current", current_scale)); } scale->SetActionCallback(new ScaleAction(this)); - AddComponent(scale); + scrollPanel->AddChild(scale); tempLabel = new ui::Label(ui::Point(scale->Position.X+scale->Size.X+3, scale->Position.Y), ui::Point(Size.X-28, 16), "\bg- Window scale factor for larger screens"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class ResizableAction: public ui::CheckboxAction @@ -210,8 +216,8 @@ OptionsView::OptionsView(): resizable->SetActionCallback(new ResizableAction(this)); tempLabel = new ui::Label(ui::Point(resizable->Position.X+Graphics::textwidth(resizable->GetText().c_str())+20, resizable->Position.Y), ui::Point(Size.X-28, 16), "\bg- Allow resizing and maximizing window"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); - AddComponent(resizable); + scrollPanel->AddChild(tempLabel); + scrollPanel->AddChild(resizable); class FullscreenAction: public ui::CheckboxAction { @@ -228,8 +234,8 @@ OptionsView::OptionsView(): fullscreen->SetActionCallback(new FullscreenAction(this)); tempLabel = new ui::Label(ui::Point(fullscreen->Position.X+Graphics::textwidth(fullscreen->GetText().c_str())+20, fullscreen->Position.Y), ui::Point(Size.X-28, 16), "\bg- Fill the entire screen"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); - AddComponent(fullscreen); + scrollPanel->AddChild(tempLabel); + scrollPanel->AddChild(fullscreen); class AltFullscreenAction: public ui::CheckboxAction { @@ -246,8 +252,8 @@ OptionsView::OptionsView(): altFullscreen->SetActionCallback(new AltFullscreenAction(this)); tempLabel = new ui::Label(ui::Point(altFullscreen->Position.X+Graphics::textwidth(altFullscreen->GetText().c_str())+20, altFullscreen->Position.Y), ui::Point(Size.X-28, 16), "\bg- Set optimial screen resolution"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); - AddComponent(altFullscreen); + scrollPanel->AddChild(tempLabel); + scrollPanel->AddChild(altFullscreen); class ForceIntegerScalingAction: public ui::CheckboxAction { @@ -264,8 +270,8 @@ OptionsView::OptionsView(): forceIntegerScaling->SetActionCallback(new ForceIntegerScalingAction(this)); tempLabel = new ui::Label(ui::Point(altFullscreen->Position.X+Graphics::textwidth(forceIntegerScaling->GetText().c_str())+20, forceIntegerScaling->Position.Y), ui::Point(Size.X-28, 16), "\bg- less blurry"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); - AddComponent(forceIntegerScaling); + scrollPanel->AddChild(tempLabel); + scrollPanel->AddChild(forceIntegerScaling); class FastQuitAction: public ui::CheckboxAction @@ -282,8 +288,8 @@ OptionsView::OptionsView(): fastquit->SetActionCallback(new FastQuitAction(this)); tempLabel = new ui::Label(ui::Point(fastquit->Position.X+Graphics::textwidth(fastquit->GetText().c_str())+20, fastquit->Position.Y), ui::Point(Size.X-28, 16), "\bg- Always exit completely when hitting close"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); - AddComponent(fastquit); + scrollPanel->AddChild(tempLabel); + scrollPanel->AddChild(fastquit); class ShowAvatarsAction: public ui::CheckboxAction { @@ -299,8 +305,25 @@ OptionsView::OptionsView(): showAvatars->SetActionCallback(new ShowAvatarsAction(this)); tempLabel = new ui::Label(ui::Point(showAvatars->Position.X+Graphics::textwidth(showAvatars->GetText().c_str())+20, showAvatars->Position.Y), ui::Point(Size.X-28, 16), "\bg- Disable if you have a slow connection"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); - AddComponent(showAvatars); + scrollPanel->AddChild(tempLabel); + scrollPanel->AddChild(showAvatars); + + class MouseClickRequiredAction: public ui::CheckboxAction + { + OptionsView * v; + public: + MouseClickRequiredAction(OptionsView * v_){ v = v_; } + void ActionCallback(ui::Checkbox * sender) override { + v->c->SetMouseClickrequired(sender->GetChecked()); + } + }; + + mouseClickRequired = new ui::Checkbox(ui::Point(8, showAvatars->Position.Y + 20), ui::Point(Size.X-6, 16), "Mouse click required", ""); + mouseClickRequired->SetActionCallback(new MouseClickRequiredAction(this)); + tempLabel = new ui::Label(ui::Point(mouseClickRequired->Position.X+Graphics::textwidth(mouseClickRequired->GetText().c_str())+20, mouseClickRequired->Position.Y), ui::Point(Size.X-28, 16), "\bg- click required to change category in menu"); + tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + scrollPanel->AddChild(tempLabel); + scrollPanel->AddChild(mouseClickRequired); class DataFolderAction: public ui::ButtonAction { @@ -323,13 +346,13 @@ OptionsView::OptionsView(): delete[] workingDirectory; } }; - ui::Button * dataFolderButton = new ui::Button(ui::Point(8, Size.Y-38), ui::Point(90, 16), "Open Data Folder"); + ui::Button * dataFolderButton = new ui::Button(ui::Point(8, mouseClickRequired->Position.Y + 20), ui::Point(90, 16), "Open Data Folder"); dataFolderButton->SetActionCallback(new DataFolderAction()); - AddComponent(dataFolderButton); + scrollPanel->AddChild(dataFolderButton); tempLabel = new ui::Label(ui::Point(dataFolderButton->Position.X+dataFolderButton->Size.X+3, dataFolderButton->Position.Y), ui::Point(Size.X-28, 16), "\bg- Open the data and preferences folder"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - AddComponent(tempLabel); + scrollPanel->AddChild(tempLabel); class CloseAction: public ui::ButtonAction { @@ -347,6 +370,8 @@ OptionsView::OptionsView(): AddComponent(tempButton); SetCancelButton(tempButton); SetOkayButton(tempButton); + + scrollPanel->InnerSize = ui::Point(Size.X, currentY); } void OptionsView::NotifySettingsChanged(OptionsModel * sender) @@ -365,6 +390,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender) forceIntegerScaling->SetChecked(sender->GetForceIntegerScaling()); fastquit->SetChecked(sender->GetFastQuit()); showAvatars->SetChecked(sender->GetShowAvatars()); + mouseClickRequired->SetChecked(sender->GetMouseClickRequired()); } void OptionsView::AttachController(OptionsController * c_) diff --git a/src/gui/options/OptionsView.h b/src/gui/options/OptionsView.h index a9dc3fcce..90564c3fc 100644 --- a/src/gui/options/OptionsView.h +++ b/src/gui/options/OptionsView.h @@ -2,6 +2,7 @@ #define OPTIONSVIEW_H_ #include "gui/interface/Window.h" +#include "gui/interface/ScrollPanel.h" namespace ui { @@ -29,6 +30,8 @@ class OptionsView: public ui::Window ui::Checkbox * forceIntegerScaling; ui::Checkbox * fastquit; ui::Checkbox * showAvatars; + ui::Checkbox * mouseClickRequired; + ui::ScrollPanel * scrollPanel; public: OptionsView(); void NotifySettingsChanged(OptionsModel * sender);