Skip to content

Commit

Permalink
Allows to change menu selection from hovering to mouse click
Browse files Browse the repository at this point in the history
New option in the menu available. This new  menu behaviour is disabled by default.
  • Loading branch information
yareky authored and LBPHacker committed Jul 6, 2019
1 parent b2adbb5 commit 5508f0c
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 35 deletions.
5 changes: 5 additions & 0 deletions src/gui/game/GameController.cpp
Expand Up @@ -1781,3 +1781,8 @@ void GameController::RunUpdater()
Platform::OpenURI(file);
#endif // MACOSX
}

bool GameController::GetMouseClickRequired()
{
return gameModel->GetMouseClickRequired();
}
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Expand Up @@ -177,6 +177,7 @@ class GameController: public ClientListener
void NotifyAuthUserChanged(Client * sender) override;
void NotifyNewNotification(Client * sender, std::pair<String, ByteString> notification) override;
void RunUpdater();
bool GetMouseClickRequired();
};

#endif // GAMECONTROLLER_H
15 changes: 15 additions & 0 deletions src/gui/game/GameModel.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -1294,3 +1298,14 @@ void GameModel::notifyLastToolChanged()
observers[i]->NotifyLastToolChanged(this);
}
}

bool GameModel::GetMouseClickRequired()
{
return mouseClickRequired;
}

void GameModel::SetMouseClickRequired(bool mouseClickRequired_)
{
mouseClickRequired = mouseClickRequired_;
notifyMenuListChanged();
}
3 changes: 3 additions & 0 deletions src/gui/game/GameModel.h
Expand Up @@ -67,6 +67,7 @@ class GameModel
Snapshot *redoHistory;
unsigned int historyPosition;
unsigned int undoHistoryLimit;
bool mouseClickRequired;

size_t activeColourPreset;
std::vector<ui::Colour> colourPresets;
Expand Down Expand Up @@ -202,6 +203,8 @@ class GameModel
std::deque<String> GetLog();
GameSave * GetClipboard();
GameSave * GetPlaceSave();
bool GetMouseClickRequired();
void SetMouseClickRequired(bool mouseClickRequired_);

std::vector<Notification*> GetNotifications();
void AddNotification(Notification * notification);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/game/GameView.cpp
Expand Up @@ -492,10 +492,10 @@ class GameView::MenuAction: public ui::ButtonAction
{
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
{
Expand Down
5 changes: 5 additions & 0 deletions src/gui/options/OptionsController.cpp
Expand Up @@ -92,6 +92,11 @@ OptionsView * OptionsController::GetView()
return view;
}

void OptionsController::SetMouseClickrequired(bool mouseClickRequired)
{
model->SetMouseClickRequired(mouseClickRequired);
}

void OptionsController::Exit()
{
view->CloseActiveWindow();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/options/OptionsController.h
Expand Up @@ -28,6 +28,8 @@ class OptionsController
void SetResizable(bool resizable);
void SetFastQuit(bool fastquit);
void SetShowAvatars(bool showAvatars);
void SetMouseClickrequired(bool mouseClickRequired);

void Exit();
OptionsView * GetView();
virtual ~OptionsController();
Expand Down
12 changes: 12 additions & 0 deletions src/gui/options/OptionsModel.cpp
Expand Up @@ -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++)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/options/OptionsModel.h
Expand Up @@ -43,6 +43,8 @@ class OptionsModel
void SetForceIntegerScaling(bool forceIntegerScaling);
bool GetFastQuit();
void SetFastQuit(bool fastquit);
bool GetMouseClickRequired();
void SetMouseClickRequired(bool mouseClickRequired);
virtual ~OptionsModel();
};

Expand Down
92 changes: 59 additions & 33 deletions src/gui/options/OptionsView.cpp
Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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<String, int>("On", 0));
airMode->AddOption(std::pair<String, int>("Pressure off", 1));
airMode->AddOption(std::pair<String, int>("Velocity off", 2));
Expand All @@ -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
{
Expand All @@ -131,15 +137,15 @@ 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<String, int>("Vertical", 0));
gravityMode->AddOption(std::pair<String, int>("Off", 1));
gravityMode->AddOption(std::pair<String, int>("Radial", 2));
gravityMode->SetActionCallback(new GravityModeChanged(this));

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
{
Expand All @@ -152,15 +158,15 @@ 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<String, int>("Void", 0));
edgeMode->AddOption(std::pair<String, int>("Solid", 1));
edgeMode->AddOption(std::pair<String, int>("Loop", 2));
edgeMode->SetActionCallback(new EdgeModeChanged(this));

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
{
Expand Down Expand Up @@ -188,11 +194,11 @@ OptionsView::OptionsView():
scale->AddOption(std::pair<String, int>("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
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -347,6 +370,8 @@ OptionsView::OptionsView():
AddComponent(tempButton);
SetCancelButton(tempButton);
SetOkayButton(tempButton);

scrollPanel->InnerSize = ui::Point(Size.X, currentY);
}

void OptionsView::NotifySettingsChanged(OptionsModel * sender)
Expand All @@ -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_)
Expand Down

0 comments on commit 5508f0c

Please sign in to comment.