diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-03 14:29:18 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-03 14:29:18 (GMT) |
| commit | 36b2aa01918344d91df30c4a6722ac39eaca0642 (patch) | |
| tree | 4833adffc9aa2db54f00e9c162b65eb9117a600f /src/game/GameView.cpp | |
| parent | 80dfc96c7c30f9bc22cc802b876c79f4205d0cbd (diff) | |
| download | powder-36b2aa01918344d91df30c4a6722ac39eaca0642.zip powder-36b2aa01918344d91df30c4a6722ac39eaca0642.tar.gz | |
QuickOptions!! #46
Diffstat (limited to 'src/game/GameView.cpp')
| -rw-r--r-- | src/game/GameView.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index d86f2b6..39211fc 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -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); |
