mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-31 19:51:45 +02:00
Simulation options
This commit is contained in:
@@ -59,6 +59,17 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GameController::OptionsCallback: public ControllerCallback
|
||||||
|
{
|
||||||
|
GameController * cc;
|
||||||
|
public:
|
||||||
|
OptionsCallback(GameController * cc_) { cc = cc_; }
|
||||||
|
virtual void ControllerExit()
|
||||||
|
{
|
||||||
|
//cc->gameModel->SetUser(cc->loginWindow->GetUser());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class GameController::SSaveCallback: public ControllerCallback
|
class GameController::SSaveCallback: public ControllerCallback
|
||||||
{
|
{
|
||||||
GameController * cc;
|
GameController * cc;
|
||||||
@@ -108,7 +119,8 @@ GameController::GameController():
|
|||||||
loginWindow(NULL),
|
loginWindow(NULL),
|
||||||
ssave(NULL),
|
ssave(NULL),
|
||||||
console(NULL),
|
console(NULL),
|
||||||
tagsWindow(NULL)
|
tagsWindow(NULL),
|
||||||
|
options(NULL)
|
||||||
{
|
{
|
||||||
gameView = new GameView();
|
gameView = new GameView();
|
||||||
gameModel = new GameModel();
|
gameModel = new GameModel();
|
||||||
@@ -484,9 +496,11 @@ void GameController::OpenStamps()
|
|||||||
ui::Engine::Ref().ShowWindow(stamps->GetView());
|
ui::Engine::Ref().ShowWindow(stamps->GetView());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::OpenDisplayOptions()
|
void GameController::OpenOptions()
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
options = new OptionsController(gameModel->GetSimulation(), new OptionsCallback(this));
|
||||||
|
ui::Engine::Ref().ShowWindow(options->GetView());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::ShowConsole()
|
void GameController::ShowConsole()
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#include "stamps/StampsController.h"
|
#include "stamps/StampsController.h"
|
||||||
//#include "cat/TPTScriptInterface.h"
|
//#include "cat/TPTScriptInterface.h"
|
||||||
#include "cat/LuaScriptInterface.h"
|
#include "cat/LuaScriptInterface.h"
|
||||||
|
#include "options/OptionsController.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -36,6 +37,7 @@ private:
|
|||||||
ConsoleController * console;
|
ConsoleController * console;
|
||||||
TagsController * tagsWindow;
|
TagsController * tagsWindow;
|
||||||
StampsController * stamps;
|
StampsController * stamps;
|
||||||
|
OptionsController * options;
|
||||||
CommandInterface * commandInterface;
|
CommandInterface * commandInterface;
|
||||||
public:
|
public:
|
||||||
class LoginCallback;
|
class LoginCallback;
|
||||||
@@ -44,6 +46,7 @@ public:
|
|||||||
class SSaveCallback;
|
class SSaveCallback;
|
||||||
class TagsCallback;
|
class TagsCallback;
|
||||||
class StampsCallback;
|
class StampsCallback;
|
||||||
|
class OptionsCallback;
|
||||||
GameController();
|
GameController();
|
||||||
~GameController();
|
~GameController();
|
||||||
GameView * GetView();
|
GameView * GetView();
|
||||||
@@ -77,7 +80,7 @@ public:
|
|||||||
void OpenSearch();
|
void OpenSearch();
|
||||||
void OpenLogin();
|
void OpenLogin();
|
||||||
void OpenTags();
|
void OpenTags();
|
||||||
void OpenDisplayOptions();
|
void OpenOptions();
|
||||||
void OpenRenderOptions();
|
void OpenRenderOptions();
|
||||||
void OpenSaveWindow();
|
void OpenSaveWindow();
|
||||||
void OpenStamps();
|
void OpenStamps();
|
||||||
|
@@ -169,7 +169,7 @@ GameView::GameView():
|
|||||||
SimulationOptionAction(GameView * _v) { v = _v; }
|
SimulationOptionAction(GameView * _v) { v = _v; }
|
||||||
void ActionCallback(ui::Button * sender)
|
void ActionCallback(ui::Button * sender)
|
||||||
{
|
{
|
||||||
v->c->OpenDisplayOptions();
|
v->c->OpenOptions();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
simulationOptionButton = new ui::Button(ui::Point(Size.X-54, Size.Y-18), ui::Point(16, 16));
|
simulationOptionButton = new ui::Button(ui::Point(Size.X-54, Size.Y-18), ui::Point(16, 16));
|
||||||
|
@@ -7,12 +7,60 @@
|
|||||||
|
|
||||||
#include "OptionsController.h"
|
#include "OptionsController.h"
|
||||||
|
|
||||||
OptionsController::OptionsController() {
|
OptionsController::OptionsController(Simulation * sim, ControllerCallback * callback_):
|
||||||
// TODO Auto-generated constructor stub
|
callback(callback_),
|
||||||
|
HasExited(false)
|
||||||
|
{
|
||||||
|
view = new OptionsView();
|
||||||
|
model = new OptionsModel(sim);
|
||||||
|
model->AddObserver(view);
|
||||||
|
|
||||||
|
view->AttachController(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionsController::SetHeatSimulation(bool state)
|
||||||
|
{
|
||||||
|
model->SetHeatSimulation(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsController::SetAmbientHeatSimulation(bool state)
|
||||||
|
{
|
||||||
|
model->SetAmbientHeatSimulation(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsController::SetNewtonianGravity(bool state)
|
||||||
|
{
|
||||||
|
model->SetNewtonianGravity(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsController::SetWaterEqualisation(bool state)
|
||||||
|
{
|
||||||
|
model->SetWaterEqualisation(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionsView * OptionsController::GetView()
|
||||||
|
{
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsController::Exit()
|
||||||
|
{
|
||||||
|
if(ui::Engine::Ref().GetWindow() == view)
|
||||||
|
{
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
}
|
||||||
|
if(callback)
|
||||||
|
callback->ControllerExit();
|
||||||
|
HasExited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
OptionsController::~OptionsController() {
|
OptionsController::~OptionsController() {
|
||||||
// TODO Auto-generated destructor stub
|
if(ui::Engine::Ref().GetWindow() == view)
|
||||||
|
{
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
}
|
||||||
|
delete model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,9 +8,26 @@
|
|||||||
#ifndef OPTIONSCONTROLLER_H_
|
#ifndef OPTIONSCONTROLLER_H_
|
||||||
#define OPTIONSCONTROLLER_H_
|
#define OPTIONSCONTROLLER_H_
|
||||||
|
|
||||||
|
#include "Controller.h"
|
||||||
|
#include "simulation/Simulation.h"
|
||||||
|
#include "OptionsView.h"
|
||||||
|
#include "OptionsModel.h"
|
||||||
|
|
||||||
|
class OptionsModel;
|
||||||
|
class OptionsView;
|
||||||
class OptionsController {
|
class OptionsController {
|
||||||
|
OptionsView * view;
|
||||||
|
OptionsModel * model;
|
||||||
|
ControllerCallback * callback;
|
||||||
public:
|
public:
|
||||||
OptionsController();
|
bool HasExited;
|
||||||
|
OptionsController(Simulation * sim, ControllerCallback * callback_);
|
||||||
|
void SetHeatSimulation(bool state);
|
||||||
|
void SetAmbientHeatSimulation(bool state);
|
||||||
|
void SetNewtonianGravity(bool state);
|
||||||
|
void SetWaterEqualisation(bool state);
|
||||||
|
void Exit();
|
||||||
|
OptionsView * GetView();
|
||||||
virtual ~OptionsController();
|
virtual ~OptionsController();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -7,9 +7,66 @@
|
|||||||
|
|
||||||
#include "OptionsModel.h"
|
#include "OptionsModel.h"
|
||||||
|
|
||||||
OptionsModel::OptionsModel() {
|
OptionsModel::OptionsModel(Simulation * sim_) {
|
||||||
// TODO Auto-generated constructor stub
|
sim = sim_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsModel::AddObserver(OptionsView* view)
|
||||||
|
{
|
||||||
|
observers.push_back(view);
|
||||||
|
view->NotifySettingsChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OptionsModel::GetHeatSimulation()
|
||||||
|
{
|
||||||
|
return sim->legacy_enable?false:true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsModel::SetHeatSimulation(bool state)
|
||||||
|
{
|
||||||
|
sim->legacy_enable = state?0:1;
|
||||||
|
notifySettingsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OptionsModel::GetAmbientHeatSimulation()
|
||||||
|
{
|
||||||
|
return sim->aheat_enable?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsModel::SetAmbientHeatSimulation(bool state)
|
||||||
|
{
|
||||||
|
sim->aheat_enable = state?1:0;
|
||||||
|
notifySettingsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OptionsModel::GetNewtonianGravity()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
//sim->
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsModel::SetNewtonianGravity(bool state)
|
||||||
|
{
|
||||||
|
notifySettingsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OptionsModel::GetWaterEqualisation()
|
||||||
|
{
|
||||||
|
return sim->water_equal_test?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsModel::SetWaterEqualisation(bool state)
|
||||||
|
{
|
||||||
|
sim->water_equal_test = state?1:0;
|
||||||
|
notifySettingsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsModel::notifySettingsChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifySettingsChanged(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionsModel::~OptionsModel() {
|
OptionsModel::~OptionsModel() {
|
||||||
|
@@ -7,10 +7,27 @@
|
|||||||
|
|
||||||
#ifndef OPTIONSMODEL_H_
|
#ifndef OPTIONSMODEL_H_
|
||||||
#define OPTIONSMODEL_H_
|
#define OPTIONSMODEL_H_
|
||||||
|
#include <vector>
|
||||||
|
#include "OptionsView.h"
|
||||||
|
#include "simulation/Simulation.h"
|
||||||
|
|
||||||
|
class Simulation;
|
||||||
|
class OptionsView;
|
||||||
class OptionsModel {
|
class OptionsModel {
|
||||||
|
Simulation * sim;
|
||||||
|
std::vector<OptionsView*> observers;
|
||||||
|
void notifySettingsChanged();
|
||||||
public:
|
public:
|
||||||
OptionsModel();
|
OptionsModel(Simulation * sim_);
|
||||||
|
void AddObserver(OptionsView* view);
|
||||||
|
bool GetHeatSimulation();
|
||||||
|
void SetHeatSimulation(bool state);
|
||||||
|
bool GetAmbientHeatSimulation();
|
||||||
|
void SetAmbientHeatSimulation(bool state);
|
||||||
|
bool GetNewtonianGravity();
|
||||||
|
void SetNewtonianGravity(bool state);
|
||||||
|
bool GetWaterEqualisation();
|
||||||
|
void SetWaterEqualisation(bool state);
|
||||||
virtual ~OptionsModel();
|
virtual ~OptionsModel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -6,13 +6,123 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "OptionsView.h"
|
#include "OptionsView.h"
|
||||||
|
#include "interface/Button.h"
|
||||||
|
#include "interface/Label.h"
|
||||||
|
|
||||||
OptionsView::OptionsView():
|
OptionsView::OptionsView():
|
||||||
ui::Window(ui::Point(-1, -1), ui::Point(300, 300)){
|
ui::Window(ui::Point(-1, -1), ui::Point(300, 300)){
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
|
|
||||||
|
ui::Label * tempLabel = new ui::Label(ui::Point(3, 3), ui::Point(Size.X-6, 14), "Simulation Options");
|
||||||
|
tempLabel->SetTextColour(ui::Colour(255, 220, 0));
|
||||||
|
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
AddComponent(tempLabel);
|
||||||
|
|
||||||
|
class HeatSimulationAction: public ui::CheckboxAction
|
||||||
|
{
|
||||||
|
OptionsView * v;
|
||||||
|
public:
|
||||||
|
HeatSimulationAction(OptionsView * v_){ v = v_; }
|
||||||
|
virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetHeatSimulation(sender->GetChecked()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
heatSimulation = new ui::Checkbox(ui::Point(3, 23), ui::Point(Size.X-6, 16), "Heat simulation \bgIntroduced in version 34");
|
||||||
|
heatSimulation->SetActionCallback(new HeatSimulationAction(this));
|
||||||
|
AddComponent(heatSimulation);
|
||||||
|
tempLabel = new ui::Label(ui::Point(24, heatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with very old saves");
|
||||||
|
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
AddComponent(tempLabel);
|
||||||
|
|
||||||
|
class AmbientHeatSimulationAction: public ui::CheckboxAction
|
||||||
|
{
|
||||||
|
OptionsView * v;
|
||||||
|
public:
|
||||||
|
AmbientHeatSimulationAction(OptionsView * v_){ v = v_; }
|
||||||
|
virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetAmbientHeatSimulation(sender->GetChecked()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
ambientHeatSimulation = new ui::Checkbox(ui::Point(3, 53), ui::Point(Size.X-6, 16), "Ambient heat simulation \bgIntroduced in version 50");
|
||||||
|
ambientHeatSimulation->SetActionCallback(new AmbientHeatSimulationAction(this));
|
||||||
|
AddComponent(ambientHeatSimulation);
|
||||||
|
tempLabel = new ui::Label(ui::Point(24, ambientHeatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with old saves");
|
||||||
|
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
AddComponent(tempLabel);
|
||||||
|
|
||||||
|
class NewtonianGravityAction: public ui::CheckboxAction
|
||||||
|
{
|
||||||
|
OptionsView * v;
|
||||||
|
public:
|
||||||
|
NewtonianGravityAction(OptionsView * v_){ v = v_; }
|
||||||
|
virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetNewtonianGravity(sender->GetChecked()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
newtonianGravity = new ui::Checkbox(ui::Point(3, 83), ui::Point(Size.X-6, 16), "Newtonian gravity \bgIntroduced in version 48");
|
||||||
|
newtonianGravity->SetActionCallback(new NewtonianGravityAction(this));
|
||||||
|
AddComponent(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->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
AddComponent(tempLabel);
|
||||||
|
|
||||||
|
class WaterEqualisationAction: public ui::CheckboxAction
|
||||||
|
{
|
||||||
|
OptionsView * v;
|
||||||
|
public:
|
||||||
|
WaterEqualisationAction(OptionsView * v_){ v = v_; }
|
||||||
|
virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetWaterEqualisation(sender->GetChecked()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
waterEqualisation = new ui::Checkbox(ui::Point(3, 113), ui::Point(Size.X-6, 16), "Water equalisation \bgIntroduced in version 61");
|
||||||
|
waterEqualisation->SetActionCallback(new WaterEqualisationAction(this));
|
||||||
|
AddComponent(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->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
AddComponent(tempLabel);
|
||||||
|
|
||||||
|
tempLabel = new ui::Label(ui::Point(3, 143), ui::Point(Size.X-24, 16), "Air Simulation Mode");
|
||||||
|
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
AddComponent(tempLabel);
|
||||||
|
|
||||||
|
tempLabel = new ui::Label(ui::Point(3, 163), ui::Point(Size.X-24, 16), "Gravity Simulation Mode");
|
||||||
|
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||||
|
AddComponent(tempLabel);
|
||||||
|
|
||||||
|
|
||||||
|
class CloseAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OptionsView * v;
|
||||||
|
CloseAction(OptionsView * v_) { v = v_; }
|
||||||
|
void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->c->Exit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ui::Button * tempButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "OK");
|
||||||
|
tempButton->SetActionCallback(new CloseAction(this));
|
||||||
|
AddComponent(tempButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionsView::NotifySettingsChanged(OptionsModel * sender)
|
||||||
|
{
|
||||||
|
heatSimulation->SetChecked(sender->GetHeatSimulation());
|
||||||
|
ambientHeatSimulation->SetChecked(sender->GetAmbientHeatSimulation());
|
||||||
|
newtonianGravity->SetChecked(sender->GetNewtonianGravity());
|
||||||
|
waterEqualisation->SetChecked(sender->GetWaterEqualisation());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsView::AttachController(OptionsController * c_)
|
||||||
|
{
|
||||||
|
c = c_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsView::OnDraw()
|
||||||
|
{
|
||||||
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
|
||||||
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
OptionsView::~OptionsView() {
|
OptionsView::~OptionsView() {
|
||||||
// TODO Auto-generated destructor stub
|
// TODO Auto-generated destructor stub
|
||||||
}
|
}
|
||||||
|
@@ -9,10 +9,23 @@
|
|||||||
#define OPTIONSVIEW_H_
|
#define OPTIONSVIEW_H_
|
||||||
|
|
||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
|
#include "OptionsController.h"
|
||||||
|
#include "interface/Checkbox.h"
|
||||||
|
#include "OptionsModel.h"
|
||||||
|
|
||||||
|
class OptionsModel;
|
||||||
|
class OptionsController;
|
||||||
class OptionsView: public ui::Window {
|
class OptionsView: public ui::Window {
|
||||||
|
OptionsController * c;
|
||||||
|
ui::Checkbox * heatSimulation;
|
||||||
|
ui::Checkbox * ambientHeatSimulation;
|
||||||
|
ui::Checkbox * newtonianGravity;
|
||||||
|
ui::Checkbox * waterEqualisation;
|
||||||
public:
|
public:
|
||||||
OptionsView();
|
OptionsView();
|
||||||
|
void NotifySettingsChanged(OptionsModel * sender);
|
||||||
|
void AttachController(OptionsController * c_);
|
||||||
|
void OnDraw();
|
||||||
virtual ~OptionsView();
|
virtual ~OptionsView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user