Wall brush, fixes #63

This commit is contained in:
Simon Robertshaw 2012-08-10 18:59:05 +01:00
parent cd051924d9
commit 3499cb3035
8 changed files with 84 additions and 11 deletions

View File

@ -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<ui::Point*> & 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))

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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,32 +1650,51 @@ 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)
{
activeBrush->RenderFill(ren, finalCurrentMouse);
}
else
{
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();
if(selectMode!=SelectNone)

View File

@ -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();

View File

@ -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){

View File

@ -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);

View File

@ -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<XRES/CELL&&oy>=0&&oy<YRES/CELL)
{