diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-17 12:40:10 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-17 12:40:10 (GMT) |
| commit | 6500923aa574bad86339f231382a7fcc11e64f96 (patch) | |
| tree | ea48ca236dc8fe543a4b6044dea9ce2e800b1de8 /src | |
| parent | be42cec4984d4af0dc35ff101d7323d1746cd5d5 (diff) | |
| download | powder-6500923aa574bad86339f231382a7fcc11e64f96.zip powder-6500923aa574bad86339f231382a7fcc11e64f96.tar.gz | |
Sample tool, fixes #122
Diffstat (limited to 'src')
| -rw-r--r-- | src/game/GameModel.cpp | 38 | ||||
| -rw-r--r-- | src/game/GameModel.h | 11 | ||||
| -rw-r--r-- | src/game/SampleTool.cpp | 36 | ||||
| -rw-r--r-- | src/game/SignTool.cpp | 2 | ||||
| -rw-r--r-- | src/game/Tool.h | 21 |
5 files changed, 104 insertions, 4 deletions
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 8512a9a..f27ebfa 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -109,6 +109,10 @@ GameModel::~GameModel() { delete menuList[i]; } + for(std::vector<Tool*>::iterator iter = extraElementTools.begin(), end = extraElementTools.end(); iter != end; ++iter) + { + delete *iter; + } for(int i = 0; i < brushList.size(); i++) { delete brushList[i]; @@ -163,6 +167,13 @@ void GameModel::BuildMenus() menuList.clear(); toolList.clear(); + for(std::vector<Tool*>::iterator iter = extraElementTools.begin(), end = extraElementTools.end(); iter != end; ++iter) + { + delete *iter; + } + extraElementTools.clear(); + elementTools.clear(); + //Create menus for(int i = 0; i < SC_TOTAL; i++) { @@ -172,7 +183,7 @@ void GameModel::BuildMenus() //Build menus from Simulation elements for(int i = 0; i < PT_NUM; i++) { - if(sim->elements[i].MenuSection < 12 && sim->elements[i].Enabled && sim->elements[i].MenuVisible) + if(sim->elements[i].Enabled) { Tool * tempTool; if(i == PT_LIGH) @@ -191,7 +202,16 @@ void GameModel::BuildMenus() { tempTool = new ElementTool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour), sim->elements[i].IconGenerator); } - menuList[sim->elements[i].MenuSection]->AddTool(tempTool); + + if(sim->elements[i].MenuSection < 12 && sim->elements[i].MenuVisible) + { + menuList[sim->elements[i].MenuSection]->AddTool(tempTool); + } + else + { + extraElementTools.push_back(tempTool); + } + elementTools.push_back(tempTool); } } @@ -211,6 +231,7 @@ void GameModel::BuildMenus() } //Add special sign and prop tools + menuList[SC_TOOL]->AddTool(new SampleTool(this)); menuList[SC_TOOL]->AddTool(new SignTool()); menuList[SC_TOOL]->AddTool(new PropertyTool()); menuList[SC_TOOL]->AddTool(new WindTool(0, "WIND", "Create air movement", 64, 64, 64)); @@ -240,7 +261,7 @@ void GameModel::BuildMenus() //Set default tools activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0]; activeTools[1] = menuList[SC_SPECIAL]->GetToolList()[0]; - activeTools[2] = NULL; + activeTools[2] = menuList[SC_TOOL]->GetToolList()[0]; lastTool = activeTools[0]; //Set default menu @@ -347,6 +368,17 @@ Menu * GameModel::GetActiveMenu() return activeMenu; } +Tool * GameModel::GetElementTool(int elementID) +{ + std::cout << elementID << std::endl; + for(std::vector<Tool*>::iterator iter = elementTools.begin(), end = elementTools.end(); iter != end; ++iter) + { + if((*iter)->GetToolID() == elementID) + return *iter; + } + return NULL; +} + Tool * GameModel::GetActiveTool(int selection) { return activeTools[selection]; diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 0531f87..847e940 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -43,6 +43,12 @@ private: deque<string> consoleLog; vector<GameView*> observers; vector<Tool*> toolList; + + //All tools that are associated with elements + vector<Tool*> elementTools; + //Tools that are present in elementTools, but don't have an associated menu and need to be freed manually + vector<Tool*> extraElementTools; + vector<Menu*> menuList; vector<QuickOption*> quickOptions; Menu * activeMenu; @@ -118,8 +124,13 @@ public: void SetSave(SaveInfo * newSave); void SetSaveFile(SaveFile * newSave); void AddObserver(GameView * observer); + + //Get an element tool from an element ID + Tool * GetElementTool(int elementID); + Tool * GetActiveTool(int selection); void SetActiveTool(int selection, Tool * tool); + bool GetPaused(); void SetPaused(bool pauseState); bool GetDecoration(); diff --git a/src/game/SampleTool.cpp b/src/game/SampleTool.cpp new file mode 100644 index 0000000..a8880b3 --- /dev/null +++ b/src/game/SampleTool.cpp @@ -0,0 +1,36 @@ +#include <iostream> +#include "graphics/Graphics.h" +#include "Tool.h" +#include "GameModel.h" + +VideoBuffer * SampleTool::GetIcon(int toolID, int width, int height) +{ + VideoBuffer * newTexture = new VideoBuffer(width, height); + for (int y=0; y<height; y++) + { + for (int x=0; x<width; x++) + { + pixel pc = x==0||x==width-1||y==0||y==height-1 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000); + newTexture->SetPixel(x, y, PIXR(pc), PIXG(pc), PIXB(pc), 255); + } + } + newTexture->SetCharacter((width/2)-5, (height/2)-5, 0xE6, 255, 255, 255, 255); + newTexture->BlendCharacter((width/2)-5, (height/2)-5, 0xE7, 100, 180, 255, 255); + return newTexture; +} + +void SampleTool::Draw(Simulation * sim, Brush * brush, ui::Point position) +{ + int particleType = 0; + if(sim->pmap[position.Y][position.X]) + particleType = sim->parts[sim->pmap[position.Y][position.X]>>8].type; + else if(sim->photons[position.Y][position.X]) + particleType = sim->parts[sim->photons[position.Y][position.X]>>8].type; + + if(particleType) + { + Tool * elementTool = gameModel->GetElementTool(particleType); + if(elementTool) + gameModel->SetActiveTool(0, elementTool); + } +} diff --git a/src/game/SignTool.cpp b/src/game/SignTool.cpp index 169c5b7..00f54b6 100644 --- a/src/game/SignTool.cpp +++ b/src/game/SignTool.cpp @@ -269,7 +269,7 @@ VideoBuffer * SignTool::GetIcon(int toolID, int width, int height) } } newTexture->SetCharacter((width/2)-5, (height/2)-5, 0xA1, 32, 64, 128, 255); - newTexture->SetCharacter((width/2)-5, (height/2)-5, 0xA0, 255, 255, 255, 255); + newTexture->BlendCharacter((width/2)-5, (height/2)-5, 0xA0, 255, 255, 255, 255); return newTexture; } diff --git a/src/game/Tool.h b/src/game/Tool.h index d4181a7..2540a22 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -29,6 +29,7 @@ protected: int resolution; public: Tool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL); + int GetToolID() { return toolID; } string GetName(); string GetDescription(); int GetResolution() { return resolution; } @@ -61,6 +62,26 @@ public: virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } }; +class GameModel; + +class SampleTool: public Tool +{ + GameModel * gameModel; +public: + SampleTool(GameModel * model): + Tool(0, "SMPL", "Sample an element on the screen", 0, 0, 0, SampleTool::GetIcon), + gameModel(model) + { + } + static VideoBuffer * GetIcon(int toolID, int width, int height); + virtual ~SampleTool() {} + 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, bool dragging = false) { } + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } +}; + class PropertyTool: public Tool { public: |
