From a623959a314e544f092c85f037d8b564adc2af45 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 4 Oct 2012 10:42:09 -0400 Subject: [PATCH] save stamps on 1 pixel grid (works exactly like in tpt now), delete signs with Ctrl+X, also fixes stamps on very bottom/right edge and other edge cases --- src/game/GameView.cpp | 21 +++++++++------------ src/simulation/Simulation.cpp | 34 +++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 9d900bae5..a1c7f70ee 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -942,9 +942,9 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy) if(selectMode!=SelectNone) { if(selectMode==PlaceSave) - selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); + selectPoint1 = c->PointTranslate(ui::Point(x, y)); if(selectPoint1.X!=-1) - selectPoint2 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); + selectPoint2 = c->PointTranslate(ui::Point(x, y)); return; } currentMouse = ui::Point(x, y); @@ -963,7 +963,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button) { if(button==BUTTON_LEFT) { - selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); + selectPoint1 = c->PointTranslate(ui::Point(x, y)); selectPoint2 = selectPoint1; } return; @@ -1023,15 +1023,12 @@ void GameView::OnMouseUp(int x, int y, unsigned button) int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; int x1 = (selectPoint2.X0 && y2-y1>0) - { - if(selectMode==SelectCopy) - c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); - else if(selectMode==SelectCut) - c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2)); - else if(selectMode==SelectStamp) - c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2)); - } + if(selectMode==SelectCopy) + c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); + else if(selectMode==SelectCut) + c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2)); + else if(selectMode==SelectStamp) + c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2)); } } currentMouse = ui::Point(x, y); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index f016112e0..21f810938 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -167,7 +167,7 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) GameSave * Simulation::Save() { - return Save(0, 0, XRES, YRES); + return Save(0, 0, XRES-1, YRES-1); } GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) @@ -192,14 +192,14 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) blockX = fullX/CELL; blockY = fullY/CELL; - blockX2 = fullX2/CELL; - blockY2 = fullY2/CELL; + blockX2 = (fullX2+CELL)/CELL; + blockY2 = (fullY2+CELL)/CELL; - fullX = blockX*CELL; - fullY = blockY*CELL; + //fullX = blockX*CELL; + //fullY = blockY*CELL; - fullX2 = blockX2*CELL; - fullY2 = blockY2*CELL; + //fullX2 = blockX2*CELL; + //fullY2 = blockY2*CELL; blockW = blockX2-blockX; blockH = blockY2-blockY; @@ -216,11 +216,11 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) int x, y; x = int(parts[i].x + 0.5f); y = int(parts[i].y + 0.5f); - if(parts[i].type && x >= fullX && y >= fullY && x < fullX2 && y < fullY2) + if(parts[i].type && x >= fullX && y >= fullY && x <= fullX2 && y <= fullY2) { Particle tempPart = parts[i]; - tempPart.x -= fullX; - tempPart.y -= fullY; + tempPart.x -= blockX*CELL; + tempPart.y -= blockY*CELL; if(elements[tempPart.type].Enabled) { *newSave << tempPart; @@ -243,11 +243,11 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) for(int i = 0; i < MAXSIGNS && i < signs.size(); i++) { - if(signs[i].text.length() && signs[i].x >= fullX && signs[i].y >= fullY && signs[i].x < fullX2 && signs[i].y < fullY2) + if(signs[i].text.length() && signs[i].x >= fullX && signs[i].y >= fullY && signs[i].x <= fullX2 && signs[i].y <= fullY2) { sign tempSign = signs[i]; - tempSign.x -= fullX; - tempSign.y -= fullY; + tempSign.x -= blockX*CELL; + tempSign.y -= blockY*CELL; *newSave << tempSign; } } @@ -340,9 +340,17 @@ void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h) if(bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] == WL_GRAV) gravWallChanged = true; bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0; + emap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0; delete_part(cx+area_x, cy+area_y, 0); } } + for(int i = 0; i < MAXSIGNS && i < signs.size(); i++) + { + if(signs[i].text.length() && signs[i].x >= area_x && signs[i].y >= area_y && signs[i].x <= area_x+area_w && signs[i].y <= area_y+area_h) + { + signs.erase(signs.begin()+i); + } + } } void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags)