QuickOptions!! #46
This commit is contained in:
parent
80dfc96c7c
commit
36b2aa0191
@ -74,6 +74,7 @@ public:
|
||||
OptionsCallback(GameController * cc_) { cc = cc_; }
|
||||
virtual void ControllerExit()
|
||||
{
|
||||
cc->gameModel->UpdateQuickOptions();
|
||||
//cc->gameModel->SetUser(cc->loginWindow->GetUser());
|
||||
}
|
||||
};
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "client/Client.h"
|
||||
#include "game/DecorationTool.h"
|
||||
#include "GameModelException.h"
|
||||
#include "QuickOptions.h"
|
||||
|
||||
GameModel::GameModel():
|
||||
sim(NULL),
|
||||
@ -68,6 +69,7 @@ GameModel::GameModel():
|
||||
}
|
||||
|
||||
BuildMenus();
|
||||
BuildQuickOptionMenu();
|
||||
|
||||
//Set default decoration colour
|
||||
unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
|
||||
@ -114,6 +116,33 @@ GameModel::~GameModel()
|
||||
// delete[] activeTools;
|
||||
}
|
||||
|
||||
void GameModel::UpdateQuickOptions()
|
||||
{
|
||||
for(std::vector<QuickOption*>::iterator iter = quickOptions.begin(), end = quickOptions.end(); iter != end; ++iter)
|
||||
{
|
||||
QuickOption * option = *iter;
|
||||
option->Update();
|
||||
}
|
||||
}
|
||||
|
||||
void GameModel::BuildQuickOptionMenu()
|
||||
{
|
||||
for(std::vector<QuickOption*>::iterator iter = quickOptions.begin(), end = quickOptions.end(); iter != end; ++iter)
|
||||
{
|
||||
delete *iter;
|
||||
}
|
||||
quickOptions.clear();
|
||||
|
||||
quickOptions.push_back(new SandEffectOption(this));
|
||||
quickOptions.push_back(new DrawGravOption(this));
|
||||
quickOptions.push_back(new DecorationsOption(this));
|
||||
quickOptions.push_back(new NGravityOption(this));
|
||||
quickOptions.push_back(new AHeatOption(this));
|
||||
|
||||
notifyQuickOptionsChanged();
|
||||
UpdateQuickOptions();
|
||||
}
|
||||
|
||||
void GameModel::BuildMenus()
|
||||
{
|
||||
//Empty current menus
|
||||
@ -246,6 +275,8 @@ void GameModel::AddObserver(GameView * observer){
|
||||
observer->NotifyZoomChanged(this);
|
||||
observer->NotifyColourSelectorVisibilityChanged(this);
|
||||
observer->NotifyColourSelectorColourChanged(this);
|
||||
observer->NotifyQuickOptionsChanged(this);
|
||||
UpdateQuickOptions();
|
||||
}
|
||||
|
||||
void GameModel::SetActiveMenu(Menu * menu)
|
||||
@ -282,6 +313,11 @@ void GameModel::SetActiveTool(int selection, Tool * tool)
|
||||
notifyActiveToolsChanged();
|
||||
}
|
||||
|
||||
vector<QuickOption*> GameModel::GetQuickOptions()
|
||||
{
|
||||
return quickOptions;
|
||||
}
|
||||
|
||||
vector<Menu*> GameModel::GetMenuList()
|
||||
{
|
||||
return menuList;
|
||||
@ -320,6 +356,7 @@ void GameModel::SetSave(SaveInfo * newSave)
|
||||
sim->Load(saveData);
|
||||
}
|
||||
notifySaveChanged();
|
||||
UpdateQuickOptions();
|
||||
}
|
||||
|
||||
void GameModel::SetSaveFile(SaveFile * newSave)
|
||||
@ -348,6 +385,7 @@ void GameModel::SetSaveFile(SaveFile * newSave)
|
||||
delete newSave;
|
||||
|
||||
notifySaveChanged();
|
||||
UpdateQuickOptions();
|
||||
}
|
||||
|
||||
Simulation * GameModel::GetSimulation()
|
||||
@ -476,6 +514,7 @@ void GameModel::SetDecoration(bool decorationState)
|
||||
{
|
||||
ren->decorations_enable = decorationState?1:0;
|
||||
notifyDecorationChanged();
|
||||
UpdateQuickOptions();
|
||||
}
|
||||
|
||||
bool GameModel::GetDecoration()
|
||||
@ -750,3 +789,11 @@ void GameModel::notifyToolTipChanged()
|
||||
observers[i]->NotifyToolTipChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void GameModel::notifyQuickOptionsChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
observers[i]->NotifyQuickOptionsChanged(this);
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ class GameView;
|
||||
class Simulation;
|
||||
class Renderer;
|
||||
|
||||
class QuickOption;
|
||||
class ToolSelection
|
||||
{
|
||||
public:
|
||||
@ -43,6 +44,7 @@ private:
|
||||
vector<GameView*> observers;
|
||||
vector<Tool*> toolList;
|
||||
vector<Menu*> menuList;
|
||||
vector<QuickOption*> quickOptions;
|
||||
Menu * activeMenu;
|
||||
int currentBrush;
|
||||
vector<Brush *> brushList;
|
||||
@ -76,6 +78,7 @@ private:
|
||||
void notifyLogChanged(string entry);
|
||||
void notifyInfoTipChanged();
|
||||
void notifyToolTipChanged();
|
||||
void notifyQuickOptionsChanged();
|
||||
public:
|
||||
GameModel();
|
||||
~GameModel();
|
||||
@ -92,6 +95,9 @@ public:
|
||||
std::string GetInfoTip();
|
||||
|
||||
void BuildMenus();
|
||||
void BuildQuickOptionMenu();
|
||||
|
||||
void UpdateQuickOptions();
|
||||
|
||||
void SetVote(int direction);
|
||||
SaveInfo * GetSave();
|
||||
@ -108,6 +114,7 @@ public:
|
||||
void ClearSimulation();
|
||||
vector<Menu*> GetMenuList();
|
||||
vector<Tool*> GetToolList();
|
||||
vector<QuickOption*> GetQuickOptions();
|
||||
void SetActiveMenu(Menu * menu);
|
||||
Menu * GetActiveMenu();
|
||||
void FrameStep(int frames);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "interface/Slider.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "simulation/SaveRenderer.h"
|
||||
#include "QuickOption.h"
|
||||
|
||||
GameView::GameView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
||||
@ -362,6 +363,33 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class GameView::OptionAction: public ui::ButtonAction
|
||||
{
|
||||
QuickOption * option;
|
||||
public:
|
||||
OptionAction(QuickOption * _option) { option = _option; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
option->Perform();
|
||||
}
|
||||
};
|
||||
|
||||
class GameView::OptionListener: public QuickOptionListener
|
||||
{
|
||||
ui::Button * button;
|
||||
public:
|
||||
OptionListener(ui::Button * _button) { button = _button; }
|
||||
virtual void OnValueChanged(QuickOption * option)
|
||||
{
|
||||
switch(option->GetType())
|
||||
{
|
||||
case QuickOption::Toggle:
|
||||
button->SetTogglable(true);
|
||||
button->SetToggleState(option->GetToggle());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class GameView::ToolAction: public ui::ButtonAction
|
||||
{
|
||||
GameView * v;
|
||||
@ -376,6 +404,31 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void GameView::NotifyQuickOptionsChanged(GameModel * sender)
|
||||
{
|
||||
for(int i = 0; i < quickOptionButtons.size(); i++)
|
||||
{
|
||||
RemoveComponent(quickOptionButtons[i]);
|
||||
delete quickOptionButtons[i];
|
||||
}
|
||||
|
||||
int currentY = 1;
|
||||
vector<QuickOption*> optionList = sender->GetQuickOptions();
|
||||
for(vector<QuickOption*>::iterator iter = optionList.begin(), end = optionList.end(); iter != end; ++iter)
|
||||
{
|
||||
QuickOption * option = *iter;
|
||||
ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), option->GetIcon(), option->GetDescription());
|
||||
//tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2);
|
||||
tempButton->SetTogglable(true);
|
||||
tempButton->SetActionCallback(new OptionAction(option));
|
||||
option->AddListener(new OptionListener(tempButton));
|
||||
AddComponent(tempButton);
|
||||
|
||||
quickOptionButtons.push_back(tempButton);
|
||||
currentY += 16;
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::NotifyMenuListChanged(GameModel * sender)
|
||||
{
|
||||
int currentY = YRES+MENUSIZE-48;//-(sender->GetMenuList().size()*16);
|
||||
|
@ -54,6 +54,7 @@ private:
|
||||
Renderer * ren;
|
||||
Brush * activeBrush;
|
||||
//UI Elements
|
||||
vector<ui::Button*> quickOptionButtons;
|
||||
vector<ui::Button*> menuButtons;
|
||||
vector<ToolButton*> toolButtons;
|
||||
vector<ui::Component*> notificationComponents;
|
||||
@ -139,6 +140,7 @@ public:
|
||||
void NotifyLogChanged(GameModel * sender, string entry);
|
||||
void NotifyToolTipChanged(GameModel * sender);
|
||||
void NotifyInfoTipChanged(GameModel * sender);
|
||||
void NotifyQuickOptionsChanged(GameModel * sender);
|
||||
|
||||
virtual void ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip);
|
||||
|
||||
@ -163,6 +165,8 @@ public:
|
||||
|
||||
class MenuAction;
|
||||
class ToolAction;
|
||||
class OptionAction;
|
||||
class OptionListener;
|
||||
};
|
||||
|
||||
#endif // GAMEVIEW_H
|
||||
|
76
src/game/QuickOption.h
Normal file
76
src/game/QuickOption.h
Normal file
@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class GameModel;
|
||||
class QuickOption;
|
||||
class QuickOptionListener
|
||||
{
|
||||
protected:
|
||||
QuickOptionListener() {}
|
||||
public:
|
||||
virtual ~QuickOptionListener() {}
|
||||
virtual void OnValueChanged(QuickOption * sender) {}
|
||||
};
|
||||
class QuickOption
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
Toggle, Multi
|
||||
};
|
||||
protected:
|
||||
std::vector<QuickOptionListener*> listeners;
|
||||
GameModel * m;
|
||||
Type type;
|
||||
std::string icon;
|
||||
std::string description;
|
||||
QuickOption(std::string icon, std::string description, GameModel * m, Type type) :
|
||||
icon(icon),
|
||||
description(description),
|
||||
m(m),
|
||||
type(type)
|
||||
{
|
||||
|
||||
}
|
||||
virtual void perform() {}
|
||||
public:
|
||||
virtual ~QuickOption()
|
||||
{
|
||||
//for(std::vector<QuickOptionListener*>::iterator iter = listeners.begin(), end = listeners.end(); iter != end; ++iter)
|
||||
// delete *iter;
|
||||
}
|
||||
|
||||
std::vector<QuickOptionListener*> GetListeners()
|
||||
{
|
||||
return listeners;
|
||||
}
|
||||
|
||||
void AddListener(QuickOptionListener * listener)
|
||||
{
|
||||
listeners.push_back(listener);
|
||||
}
|
||||
|
||||
Type GetType() { return type; }
|
||||
|
||||
virtual bool GetToggle() {}
|
||||
virtual int GetMutli() {}
|
||||
virtual int GetMultiCount() {}
|
||||
|
||||
std::string GetIcon() { return icon; }
|
||||
void SetIcon(std::string icon) { this->icon = icon; }
|
||||
std::string GetDescription() { return description; }
|
||||
void SetDescription(std::string description) { this->description = description; }
|
||||
void Perform()
|
||||
{
|
||||
perform();
|
||||
for(std::vector<QuickOptionListener*>::iterator iter = listeners.begin(), end = listeners.end(); iter != end; ++iter)
|
||||
(*iter)->OnValueChanged(this);
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
for(std::vector<QuickOptionListener*>::iterator iter = listeners.begin(), end = listeners.end(); iter != end; ++iter)
|
||||
(*iter)->OnValueChanged(this);
|
||||
}
|
||||
};
|
||||
|
99
src/game/QuickOptions.h
Normal file
99
src/game/QuickOptions.h
Normal file
@ -0,0 +1,99 @@
|
||||
#include "QuickOption.h"
|
||||
#include "GameModel.h"
|
||||
|
||||
class SandEffectOption: public QuickOption
|
||||
{
|
||||
public:
|
||||
SandEffectOption(GameModel * m):
|
||||
QuickOption("P", "Sand effect", m, Toggle)
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool GetToggle()
|
||||
{
|
||||
return m->GetSimulation()->pretty_powder;
|
||||
}
|
||||
virtual void perform()
|
||||
{
|
||||
m->GetSimulation()->pretty_powder = !m->GetSimulation()->pretty_powder;
|
||||
}
|
||||
};
|
||||
|
||||
class DrawGravOption: public QuickOption
|
||||
{
|
||||
public:
|
||||
DrawGravOption(GameModel * m):
|
||||
QuickOption("G", "Draw gravity field", m, Toggle)
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool GetToggle()
|
||||
{
|
||||
return m->GetRenderer()->gravifyFieldEnabled;
|
||||
}
|
||||
virtual void perform()
|
||||
{
|
||||
m->GetRenderer()->gravifyFieldEnabled = !m->GetRenderer()->gravifyFieldEnabled;
|
||||
}
|
||||
};
|
||||
|
||||
class DecorationsOption: public QuickOption
|
||||
{
|
||||
public:
|
||||
DecorationsOption(GameModel * m):
|
||||
QuickOption("D", "Draw decorations", m, Toggle)
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool GetToggle()
|
||||
{
|
||||
return m->GetRenderer()->decorations_enable;
|
||||
}
|
||||
virtual void perform()
|
||||
{
|
||||
m->GetRenderer()->decorations_enable = !m->GetRenderer()->decorations_enable;
|
||||
}
|
||||
};
|
||||
|
||||
class NGravityOption: public QuickOption
|
||||
{
|
||||
public:
|
||||
NGravityOption(GameModel * m):
|
||||
QuickOption("N", "Newtonian Gravity", m, Toggle)
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool GetToggle()
|
||||
{
|
||||
return m->GetSimulation()->grav->ngrav_enable;
|
||||
}
|
||||
virtual void perform()
|
||||
{
|
||||
if(m->GetSimulation()->grav->ngrav_enable)
|
||||
{
|
||||
m->GetSimulation()->grav->stop_grav_async();
|
||||
}
|
||||
else
|
||||
{
|
||||
m->GetSimulation()->grav->start_grav_async();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class AHeatOption: public QuickOption
|
||||
{
|
||||
public:
|
||||
AHeatOption(GameModel * m):
|
||||
QuickOption("A", "Ambient heat", m, Toggle)
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool GetToggle()
|
||||
{
|
||||
return m->GetSimulation()->aheat_enable;
|
||||
}
|
||||
virtual void perform()
|
||||
{
|
||||
m->GetSimulation()->aheat_enable = !m->GetSimulation()->aheat_enable;
|
||||
}
|
||||
};
|
@ -39,9 +39,9 @@ void Renderer::RenderBegin()
|
||||
{
|
||||
|
||||
draw_air();
|
||||
draw_grav();
|
||||
render_parts();
|
||||
render_fire();
|
||||
draw_grav();
|
||||
DrawWalls();
|
||||
DrawSigns();
|
||||
#ifndef OGLR
|
||||
@ -1899,6 +1899,9 @@ void Renderer::draw_grav()
|
||||
int x, y, i, ca;
|
||||
float nx, ny, dist;
|
||||
|
||||
if(!gravifyFieldEnabled)
|
||||
return;
|
||||
|
||||
for (y=0; y<YRES/CELL; y++)
|
||||
{
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
@ -2096,7 +2099,8 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
|
||||
zoomScopeSize(32),
|
||||
ZFACTOR(8),
|
||||
zoomEnabled(false),
|
||||
decorations_enable(1)
|
||||
decorations_enable(1),
|
||||
gravifyFieldEnabled(false)
|
||||
{
|
||||
this->g = g;
|
||||
this->sim = sim;
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
char * plasma_data;
|
||||
int emp_decor;
|
||||
//
|
||||
bool gravifyFieldEnabled;
|
||||
int decorations_enable;
|
||||
Simulation * sim;
|
||||
Graphics * g;
|
||||
|
Loading…
Reference in New Issue
Block a user