diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 9636c8f90..02dd4df53 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -276,6 +276,7 @@ void GameController::DrawRect(int toolSelection, ui::Point point1, ui::Point poi { Simulation * sim = gameModel->GetSimulation(); Tool * activeTool = gameModel->GetActiveTool(toolSelection); + gameModel->SetLastTool(activeTool); Brush * cBrush = gameModel->GetBrush(); if(!activeTool || !cBrush) return; @@ -287,6 +288,7 @@ void GameController::DrawLine(int toolSelection, ui::Point point1, ui::Point poi { Simulation * sim = gameModel->GetSimulation(); Tool * activeTool = gameModel->GetActiveTool(toolSelection); + gameModel->SetLastTool(activeTool); Brush * cBrush = gameModel->GetBrush(); if(!activeTool || !cBrush) return; @@ -298,6 +300,7 @@ void GameController::DrawFill(int toolSelection, ui::Point point) { Simulation * sim = gameModel->GetSimulation(); Tool * activeTool = gameModel->GetActiveTool(toolSelection); + gameModel->SetLastTool(activeTool); Brush * cBrush = gameModel->GetBrush(); if(!activeTool || !cBrush) return; @@ -309,6 +312,7 @@ void GameController::DrawPoints(int toolSelection, queue & pointQueu { Simulation * sim = gameModel->GetSimulation(); Tool * activeTool = gameModel->GetActiveTool(toolSelection); + gameModel->SetLastTool(activeTool); Brush * cBrush = gameModel->GetBrush(); if(!activeTool || !cBrush) { @@ -701,6 +705,7 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool) { gameModel->SetActiveTool(toolSelection, tool); gameModel->GetRenderer()->gravityZonesEnabled = false; + gameModel->SetLastTool(tool); for(int i = 0; i < 3; i++) { if(gameModel->GetActiveTool(i) == gameModel->GetMenuList().at(SC_WALL)->GetToolList().at(WL_GRAV)) diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 3da3074da..e88a1aa8a 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -239,6 +239,7 @@ void GameModel::BuildMenus() activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0]; activeTools[1] = menuList[SC_SPECIAL]->GetToolList()[0]; activeTools[2] = NULL; + lastTool = activeTools[0]; //Set default menu activeMenu = menuList[SC_POWDERS]; @@ -247,6 +248,7 @@ void GameModel::BuildMenus() notifyMenuListChanged(); notifyToolListChanged(); notifyActiveToolsChanged(); + notifyLastToolChanged(); } void GameModel::SetVote(int direction) @@ -293,6 +295,7 @@ void GameModel::AddObserver(GameView * observer){ observer->NotifyColourSelectorVisibilityChanged(this); observer->NotifyColourSelectorColourChanged(this); observer->NotifyQuickOptionsChanged(this); + observer->NotifyLastToolChanged(this); UpdateQuickOptions(); } @@ -429,6 +432,20 @@ User GameModel::GetUser() return currentUser; } +Tool * GameModel::GetLastTool() +{ + return lastTool; +} + +void GameModel::SetLastTool(Tool * newTool) +{ + if(lastTool != newTool) + { + lastTool = newTool; + notifyLastToolChanged(); + } +} + void GameModel::SetZoomEnabled(bool enabled) { ren->zoomEnabled = enabled; @@ -823,3 +840,11 @@ void GameModel::notifyQuickOptionsChanged() observers[i]->NotifyQuickOptionsChanged(this); } } + +void GameModel::notifyLastToolChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyLastToolChanged(this); + } +} diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 47a6904d0..33cf1195f 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -51,6 +51,7 @@ private: SaveInfo * currentSave; Simulation * sim; Renderer * ren; + Tool * lastTool; Tool * activeTools[3]; User currentUser; bool colourSelector; @@ -80,6 +81,7 @@ private: void notifyInfoTipChanged(); void notifyToolTipChanged(); void notifyQuickOptionsChanged(); + void notifyLastToolChanged(); public: GameModel(); ~GameModel(); @@ -103,6 +105,9 @@ public: void SetToolStrength(float value); float GetToolStrength(); + Tool * GetLastTool(); + void SetLastTool(Tool * newTool); + void SetVote(int direction); SaveInfo * GetSave(); Brush * GetBrush(); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 85d0e8d25..073d8dad4 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -174,7 +174,8 @@ GameView::GameView(): showHud(true), showDebug(false), introText(2048), - introTextMessage(introTextData) + introTextMessage(introTextData), + wallBrush(false) { int currentX = 1; @@ -642,6 +643,18 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender) } } +void GameView::NotifyLastToolChanged(GameModel * sender) +{ + if(sender->GetLastTool()->GetResolution() == CELL) + { + wallBrush = true; + } + else + { + wallBrush = false; + } +} + void GameView::NotifyToolListChanged(GameModel * sender) { //int currentY = YRES+MENUSIZE-36; @@ -1637,22 +1650,29 @@ void GameView::OnDraw() if(selectMode == SelectNone && activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES) { ui::Point finalCurrentMouse = c->PointTranslate(currentMouse); + ui::Point initialDrawPoint = drawPoint1; + + if(wallBrush) + { + finalCurrentMouse = c->NormaliseBlockCoord(finalCurrentMouse); + initialDrawPoint = c->NormaliseBlockCoord(initialDrawPoint); + } if(drawMode==DrawRect && isMouseDown) { if(drawSnap) { - finalCurrentMouse = rectSnapCoords(c->PointTranslate(drawPoint1), finalCurrentMouse); + finalCurrentMouse = rectSnapCoords(c->PointTranslate(initialDrawPoint), finalCurrentMouse); } - activeBrush->RenderRect(ren, c->PointTranslate(drawPoint1), finalCurrentMouse); + activeBrush->RenderRect(ren, c->PointTranslate(initialDrawPoint), finalCurrentMouse); } else if(drawMode==DrawLine && isMouseDown) { if(drawSnap) { - finalCurrentMouse = lineSnapCoords(c->PointTranslate(drawPoint1), finalCurrentMouse); + finalCurrentMouse = lineSnapCoords(c->PointTranslate(initialDrawPoint), finalCurrentMouse); } - activeBrush->RenderLine(ren, c->PointTranslate(drawPoint1), finalCurrentMouse); + activeBrush->RenderLine(ren, c->PointTranslate(initialDrawPoint), finalCurrentMouse); } else if(drawMode==DrawFill) { @@ -1660,7 +1680,19 @@ void GameView::OnDraw() } else { - activeBrush->RenderPoint(ren, finalCurrentMouse); + if(wallBrush) + { + ui::Point finalBrushRadius = c->NormaliseBlockCoord(activeBrush->GetRadius()); + ren->xor_line(finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y-finalBrushRadius.Y, finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y-finalBrushRadius.Y); + ren->xor_line(finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-1, finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-1); + + ren->xor_line(finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y-finalBrushRadius.Y+1, finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-2); + ren->xor_line(finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y-finalBrushRadius.Y+1, finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-2); + } + else + { + activeBrush->RenderPoint(ren, finalCurrentMouse); + } } } ren->RenderEnd(); diff --git a/src/game/GameView.h b/src/game/GameView.h index 4d1683ab4..efb4895c3 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -43,6 +43,7 @@ private: bool altBehaviour; bool showHud; bool showDebug; + bool wallBrush; int introText; std::string introTextMessage; int toolIndex; @@ -144,6 +145,7 @@ public: void NotifyToolTipChanged(GameModel * sender); void NotifyInfoTipChanged(GameModel * sender); void NotifyQuickOptionsChanged(GameModel * sender); + void NotifyLastToolChanged(GameModel * sender); void ExitPrompt(); diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp index a93afaff6..ad987121f 100644 --- a/src/game/Tool.cpp +++ b/src/game/Tool.cpp @@ -20,7 +20,8 @@ Tool::Tool(int id, string name, string description, int r, int g, int b, VideoBu colGreen(g), colBlue(b), textureGen(textureGen), - strength(1.0f) + strength(1.0f), + resolution(1) { } VideoBuffer * Tool::GetTexture(int width, int height) @@ -72,6 +73,7 @@ void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) WallTool::WallTool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int)): Tool(id, name, description, r, g, b, textureGen) { + resolution = CELL; } WallTool::~WallTool() {} void WallTool::Draw(Simulation * sim, Brush * brush, ui::Point position){ diff --git a/src/game/Tool.h b/src/game/Tool.h index c4f44bb27..d4181a7a7 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -26,10 +26,12 @@ protected: string toolName; string toolDescription; float strength; + int resolution; public: Tool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL); string GetName(); string GetDescription(); + int GetResolution() { return resolution; } void SetStrength(float value) { strength = value; } float GetStrength() { return strength; } VideoBuffer * GetTexture(int width, int height); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index c11bde069..f70560a64 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1250,11 +1250,11 @@ int Simulation::CreateWalls(int x, int y, int rx, int ry, int c, int flags, Brus rx = rx/CELL; x = x/CELL; y = y/CELL; - x -= rx/2; - y -= ry/2; - for (ox=x; ox<=x+rx; ox++) + x -= rx;///2; + y -= ry;///2; + for (ox=x; ox<=x+rx+rx; ox++) { - for (oy=y; oy<=y+rx; oy++) + for (oy=y; oy<=y+ry+ry; oy++) { if (ox>=0&&ox=0&&oy