diff --git a/Makefile b/Makefile index bb1879ea7..1296d1401 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ OBJS := $(patsubst src/%.cpp,build/obj/%.o,$(SOURCES)) FOLDERS := CFLAGS := -w -Isrc/ -Idata/ -OFLAGS := -fkeep-inline-functions #-O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -msse2 +OFLAGS := -fkeep-inline-functions -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -msse2 CPPC := g++ CPPC_WIN := i686-w64-mingw32-gcc diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 5749fd49c..9056ba8c9 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -88,7 +88,7 @@ void GameController::DrawPoints(queue & pointQueue) void GameController::Tick() { - //gameModel->GetSimulation()->update_particles(); + gameModel->GetSimulation()->update_particles(); } void GameController::SetPaused(bool pauseState) @@ -96,11 +96,21 @@ void GameController::SetPaused(bool pauseState) gameModel->SetPaused(pauseState); } +void GameController::SetPaused() +{ + gameModel->SetPaused(!gameModel->GetPaused()); +} + void GameController::SetActiveMenu(Menu * menu) { gameModel->SetActiveMenu(menu); } +void GameController::SetActiveTool(Tool * tool) +{ + gameModel->SetActiveTool(tool); +} + void GameController::OpenSearch() { search = new SearchController(); diff --git a/src/game/GameController.h b/src/game/GameController.h index d83c4597e..d7232d2e7 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -28,7 +28,9 @@ public: void DrawPoints(queue & pointQueue); void Tick(); void SetPaused(bool pauseState); + void SetPaused(); void SetActiveMenu(Menu * menu); + void SetActiveTool(Tool * tool); void OpenSearch(); void OpenLogin(); void OpenTags(); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 090f46ada..91b1c8dc2 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -26,7 +26,7 @@ GameModel::GameModel(): { if(sim->ptypes[i].menusection < 12) { - Tool * tempTool = new ElementTool(i, sim->ptypes[i].name, 0, 0, 0); + Tool * tempTool = new ElementTool(i, sim->ptypes[i].name, PIXR(sim->ptypes[i].pcolors), PIXG(sim->ptypes[i].pcolors), PIXB(sim->ptypes[i].pcolors)); menuList[sim->ptypes[i].menusection]->AddTool(tempTool); } } @@ -96,6 +96,7 @@ Tool * GameModel::GetActiveTool() void GameModel::SetActiveTool(Tool * tool) { activeTool = tool; + notifyActiveToolChanged(); } vector GameModel::GetMenuList() @@ -195,3 +196,11 @@ void GameModel::notifyToolListChanged() observers[i]->NotifyToolListChanged(this); } } + +void GameModel::notifyActiveToolChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyActiveToolChanged(this); + } +} diff --git a/src/game/GameModel.h b/src/game/GameModel.h index d65165b24..14319e759 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -36,6 +36,7 @@ private: void notifyBrushChanged(); void notifyMenuListChanged(); void notifyToolListChanged(); + void notifyActiveToolChanged(); public: GameModel(); ~GameModel(); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index ed2094d96..80965ceef 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -187,6 +187,18 @@ public: } }; +class GameView::ToolAction: public ui::ButtonAction +{ + GameView * v; +public: + Tool * tool; + ToolAction(GameView * _v, Tool * tool_) { v = _v; tool = tool_; } + void ActionCallback(ui::Button * sender) + { + v->c->SetActiveTool(tool); + } +}; + void GameView::NotifyMenuListChanged(GameModel * sender) { int currentY = YRES+MENUSIZE-36; @@ -216,8 +228,24 @@ void GameView::NotifyMenuListChanged(GameModel * sender) } } +void GameView::NotifyActiveToolChanged(GameModel * sender) +{ + for(int i = 0; i < toolButtons.size(); i++) + { + if(((ToolAction*)toolButtons[i]->GetActionCallback())->tool==sender->GetActiveTool()) + { + toolButtons[i]->SetToggleState(true); + } + else + { + toolButtons[i]->SetToggleState(false); + } + } +} + void GameView::NotifyToolListChanged(GameModel * sender) { + int currentX = XRES+BARSIZE-56; for(int i = 0; i < menuButtons.size(); i++) { if(((MenuAction*)menuButtons[i]->GetActionCallback())->menu==sender->GetActiveMenu()) @@ -229,6 +257,25 @@ void GameView::NotifyToolListChanged(GameModel * sender) menuButtons[i]->SetToggleState(false); } } + for(int i = 0; i < toolButtons.size(); i++) + { + RemoveComponent(toolButtons[i]); + delete toolButtons[i]; + } + toolButtons.clear(); + vector toolList = sender->GetToolList(); + for(int i = 0; i < toolList.size(); i++) + { + ui::Button * tempButton = new ui::Button(ui::Point(currentX, YRES), ui::Point(32, 16), toolList[i]->GetName()); + currentX -= 36; + tempButton->SetTogglable(true); + tempButton->SetActionCallback(new ToolAction(this, toolList[i])); + tempButton->SetBackgroundColour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue); + tempButton->SetAlignment(AlignCentre, AlignBottom); + AddComponent(tempButton); + toolButtons.push_back(tempButton); + } + } void GameView::NotifyRendererChanged(GameModel * sender) @@ -313,6 +360,15 @@ void GameView::OnMouseWheel(int x, int y, int d) } } +void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt) +{ + switch(key) + { + case ' ': + c->SetPaused(); + } +} + void GameView::OnTick(float dt) { if(!pointQueue.empty()) @@ -327,6 +383,8 @@ void GameView::OnDraw() if(ren) { ren->render_parts(); + ren->render_fire(); + ren->render_signs(); } if(activeBrush) { diff --git a/src/game/GameView.h b/src/game/GameView.h index c27c2cc02..388179562 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -46,15 +46,18 @@ public: void NotifyBrushChanged(GameModel * sender); void NotifyMenuListChanged(GameModel * sender); void NotifyToolListChanged(GameModel * sender); + void NotifyActiveToolChanged(GameModel * sender); virtual void OnMouseMove(int x, int y, int dx, int dy); virtual void OnMouseDown(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button); virtual void OnMouseWheel(int x, int y, int d); + virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt); //virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {} //virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {} virtual void OnTick(float dt); virtual void OnDraw(); class MenuAction; + class ToolAction; }; #endif // GAMEVIEW_H diff --git a/src/game/Tool.h b/src/game/Tool.h index 842f4a25f..4777e6dfd 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -15,10 +15,10 @@ using namespace std; class Tool { protected: - int toolID, colRed, colBlue, colGreen; + int toolID; string toolName; public: - Tool(int id, string name, int r, int b, int g): + Tool(int id, string name, int r, int g, int b): toolID(id), toolName(name), colRed(r), @@ -26,16 +26,18 @@ public: colBlue(b) { } + string GetName() { return toolName; } virtual ~Tool() {} 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) {} + int colRed, colBlue, colGreen; }; class ElementTool: public Tool { public: - ElementTool(int id, string name, int r, int b, int g): + ElementTool(int id, string name, int r, int g, int b): Tool(id, name, r, g, b) { } diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index e0f5172a8..2694de5f2 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -26,7 +26,10 @@ Button::Button(Window* parent_state, std::string buttonText): textPosition(ui::Point(0, 0)), textVAlign(AlignMiddle), textHAlign(AlignCentre), - Enabled(true) + Enabled(true), + colr(0), + colg(0), + colb(0) { TextPosition(); } @@ -42,7 +45,10 @@ Button::Button(Point position, Point size, std::string buttonText): textPosition(ui::Point(0, 0)), textVAlign(AlignMiddle), textHAlign(AlignCentre), - Enabled(true) + Enabled(true), + colr(0), + colg(0), + colb(0) { TextPosition(); } @@ -58,7 +64,10 @@ Button::Button(std::string buttonText): textPosition(ui::Point(0, 0)), textVAlign(AlignMiddle), textHAlign(AlignCentre), - Enabled(true) + Enabled(true), + colr(0), + colg(0), + colb(0) { TextPosition(); } @@ -135,6 +144,8 @@ void Button::Draw(const Point& screenPos) { if(isMouseInside) g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255); + else + g->fillrect(Position.X, Position.Y, Size.X, Size.Y, colr, colg, colb, 255); g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255); } diff --git a/src/interface/Button.h b/src/interface/Button.h index a137aac37..bff54c951 100644 --- a/src/interface/Button.h +++ b/src/interface/Button.h @@ -59,7 +59,9 @@ public: HorizontalAlignment GetHAlignment() { return textHAlign; } VerticalAlignment GetVAlignment() { return textVAlign; } void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); } + void SetBackgroundColour(int colr, int colg, int colb) { this->colr = colr; this->colg = colg; this->colb = colb; } protected: + int colr, colg, colb; bool isButtonDown, state, isMouseInside, isTogglable, toggle; ButtonAction * actionCallback; ui::Point textPosition;