diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-24 18:22:58 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-24 18:22:58 (GMT) |
| commit | ba802b3243c3e1721a84126e2bed6c3b24532b27 (patch) | |
| tree | 858767f6f853c798809b5c595cd813e493cd75b8 /src/game | |
| parent | f5547f267b9e73be3d8153df3dd36d7e3b69a2d9 (diff) | |
| download | powder-ba802b3243c3e1721a84126e2bed6c3b24532b27.zip powder-ba802b3243c3e1721a84126e2bed6c3b24532b27.tar.gz | |
Element search
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/GameController.cpp | 16 | ||||
| -rw-r--r-- | src/game/GameController.h | 1 | ||||
| -rw-r--r-- | src/game/GameView.cpp | 26 | ||||
| -rw-r--r-- | src/game/Tool.cpp | 94 | ||||
| -rw-r--r-- | src/game/Tool.h | 103 |
5 files changed, 163 insertions, 77 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index affb885..5c5c928 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -13,6 +13,7 @@ #include "dialogues/ConfirmPrompt.h" #include "GameModelException.h" #include "simulation/Air.h" +#include "elementsearch/ElementSearchActivity.h" #include "update/UpdateActivity.h" #include "Notification.h" @@ -513,6 +514,21 @@ void GameController::OpenLogin() ui::Engine::Ref().ShowWindow(loginWindow->GetView()); } +void GameController::OpenElementSearch() +{ + vector<Tool*> toolList; + vector<Menu*> menuList = gameModel->GetMenuList(); + for(std::vector<Menu*>::iterator iter = menuList.begin(), end = menuList.end(); iter!=end; ++iter) { + if(!(*iter)) + continue; + vector<Tool*> menuToolList = (*iter)->GetToolList(); + if(!menuToolList.size()) + continue; + toolList.insert(toolList.end(), menuToolList.begin(), menuToolList.end()); + } + ui::Engine::Ref().ShowWindow(new ElementSearchActivity(gameModel, toolList)); +} + void GameController::OpenTags() { if(gameModel->GetUser().ID) diff --git a/src/game/GameController.h b/src/game/GameController.h index c424656..4e2b43a 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -90,6 +90,7 @@ public: void OpenRenderOptions(); void OpenSaveWindow(); void OpenStamps(); + void OpenElementSearch(); void PlaceSave(ui::Point position); void ClearSim(); void ReloadSim(); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 5593d4b..29e7042 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -238,6 +238,21 @@ GameView::GameView(): colourBSlider->SetActionCallback(colC); colourASlider = new ui::Slider(ui::Point(275, Size.Y-39), ui::Point(50, 14), 255); colourASlider->SetActionCallback(colC); + + class ElementSearchAction : public ui::ButtonAction + { + GameView * v; + public: + ElementSearchAction(GameView * _v) { v = _v; } + void ActionCallback(ui::Button * sender) + { + v->c->OpenElementSearch(); + } + }; + ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, YRES+MENUSIZE-32), ui::Point(15, 15), ""); + tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2); + tempButton->SetActionCallback(new ElementSearchAction(this)); + AddComponent(tempButton); } class GameView::MenuAction: public ui::ButtonAction @@ -272,7 +287,7 @@ public: void GameView::NotifyMenuListChanged(GameModel * sender) { - int currentY = YRES+MENUSIZE-16-(sender->GetMenuList().size()*16); + int currentY = YRES+MENUSIZE-48;//-(sender->GetMenuList().size()*16); for(int i = 0; i < menuButtons.size(); i++) { RemoveComponent(menuButtons[i]); @@ -286,15 +301,16 @@ void GameView::NotifyMenuListChanged(GameModel * sender) } toolButtons.clear(); vector<Menu*> menuList = sender->GetMenuList(); - for(int i = 0; i < menuList.size(); i++) + for(vector<Menu*>::reverse_iterator iter = menuList.rbegin(), end = menuList.rend(); iter != end; ++iter) { std::string tempString = ""; - tempString += menuList[i]->GetIcon(); + Menu * item = *iter; + tempString += item->GetIcon(); ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), tempString); tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2); tempButton->SetTogglable(true); - tempButton->SetActionCallback(new MenuAction(this, menuList[i])); - currentY+=16; + tempButton->SetActionCallback(new MenuAction(this, item)); + currentY-=16; AddComponent(tempButton); menuButtons.push_back(tempButton); } diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp new file mode 100644 index 0000000..2467d3f --- /dev/null +++ b/src/game/Tool.cpp @@ -0,0 +1,94 @@ +/* + * Tool.cpp + * + * Created on: Jun 24, 2012 + * Author: Simon + */ + +#include <string> +#include "Tool.h" + +#include "simulation/Simulation.h" + +using namespace std; + +Tool::Tool(int id, string name, int r, int g, int b): + toolID(id), + toolName(name), + colRed(r), + colGreen(g), + colBlue(b) +{ +} +string Tool::GetName() { return toolName; } +Tool::~Tool() {} +void Tool::Click(Simulation * sim, Brush * brush, ui::Point position) { } +void Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) { + sim->ToolBrush(position.X, position.Y, toolID, brush); +} +void Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); +} +void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); +} +void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}; + +ElementTool::ElementTool(int id, string name, int r, int g, int b): + Tool(id, name, r, g, b) +{ +} +ElementTool::~ElementTool() {} +void ElementTool::Draw(Simulation * sim, Brush * brush, ui::Point position){ + sim->CreateParts(position.X, position.Y, toolID, brush); +} +void ElementTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); +} +void ElementTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0); +} +void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { + sim->FloodParts(position.X, position.Y, toolID, -1, -1, 0); +} + + +WallTool::WallTool(int id, string name, int r, int g, int b): +Tool(id, name, r, g, b) +{ +} +WallTool::~WallTool() {} +void WallTool::Draw(Simulation * sim, Brush * brush, ui::Point position){ + sim->CreateWalls(position.X, position.Y, 1, 1, toolID, 0, brush); +} +void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush); +} +void WallTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0); +} +void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { + sim->FloodWalls(position.X, position.Y, toolID, -1, -1, 0); +} + + +GolTool::GolTool(int id, string name, int r, int g, int b): + Tool(id, name, r, g, b) +{ +} +GolTool::~GolTool() {} +void GolTool::Draw(Simulation * sim, Brush * brush, ui::Point position){ + sim->CreateParts(position.X, position.Y, PT_LIFE|(toolID<<8), brush); +} +void GolTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), brush); +} +void GolTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { + sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), 0); +} +void GolTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { + sim->FloodParts(position.X, position.Y, PT_LIFE|(toolID<<8), -1, -1, 0); +} + + + diff --git a/src/game/Tool.h b/src/game/Tool.h index 4a78be8..819620d 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -12,33 +12,25 @@ using namespace std; +#include "interface/Point.h" + +class Simulation; +class Brush; + class Tool { protected: int toolID; string toolName; public: - Tool(int id, string name, int r, int g, int b): - toolID(id), - toolName(name), - colRed(r), - colGreen(g), - colBlue(b) - { - } - string GetName() { return toolName; } - virtual ~Tool() {} - virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { } - virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) { - sim->ToolBrush(position.X, position.Y, toolID, brush); - } - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); - } - virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->ToolBox(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); - } - virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}; + Tool(int id, string name, int r, int g, int b); + string GetName(); + virtual ~Tool(); + virtual void Click(Simulation * sim, Brush * brush, ui::Point position); + virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); int colRed, colBlue, colGreen; }; @@ -75,67 +67,34 @@ public: class ElementTool: public Tool { public: - ElementTool(int id, string name, int r, int g, int b): - Tool(id, name, r, g, b) - { - } - virtual ~ElementTool() {} - virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){ - sim->CreateParts(position.X, position.Y, toolID, brush); - } - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); - } - virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0); - } - virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { - sim->FloodParts(position.X, position.Y, toolID, -1, -1, 0); - } + ElementTool(int id, string name, int r, int g, int b); + virtual ~ElementTool(); + virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); }; class WallTool: public Tool { public: - WallTool(int id, string name, int r, int g, int b): - Tool(id, name, r, g, b) - { - } - virtual ~WallTool() {} - virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){ - sim->CreateWalls(position.X, position.Y, 1, 1, toolID, 0, brush); - } - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush); - } - virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0); - } - virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { - sim->FloodWalls(position.X, position.Y, toolID, -1, -1, 0); - } + WallTool(int id, string name, int r, int g, int b); + virtual ~WallTool(); + virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); }; class GolTool: public Tool { public: - GolTool(int id, string name, int r, int g, int b): - Tool(id, name, r, g, b) - { - } - virtual ~GolTool() {} - virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){ - sim->CreateParts(position.X, position.Y, PT_LIFE|(toolID<<8), brush); - } - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), brush); - } - virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), 0); - } - virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { - sim->FloodParts(position.X, position.Y, PT_LIFE|(toolID<<8), -1, -1, 0); - } + GolTool(int id, string name, int r, int g, int b); + virtual ~GolTool(); + virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); }; #endif /* TOOL_H_ */ |
