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

This commit is contained in:
jacob1 2012-10-04 10:42:09 -04:00
parent 0fd86e994a
commit a623959a31
2 changed files with 30 additions and 25 deletions

View File

@ -942,9 +942,9 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
if(selectMode!=SelectNone) if(selectMode!=SelectNone)
{ {
if(selectMode==PlaceSave) if(selectMode==PlaceSave)
selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); selectPoint1 = c->PointTranslate(ui::Point(x, y));
if(selectPoint1.X!=-1) if(selectPoint1.X!=-1)
selectPoint2 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); selectPoint2 = c->PointTranslate(ui::Point(x, y));
return; return;
} }
currentMouse = ui::Point(x, y); currentMouse = ui::Point(x, y);
@ -963,7 +963,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
{ {
if(button==BUTTON_LEFT) if(button==BUTTON_LEFT)
{ {
selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); selectPoint1 = c->PointTranslate(ui::Point(x, y));
selectPoint2 = selectPoint1; selectPoint2 = selectPoint1;
} }
return; return;
@ -1023,8 +1023,6 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y;
int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X; int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X;
int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y; int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y;
if(x2-x1>0 && y2-y1>0)
{
if(selectMode==SelectCopy) if(selectMode==SelectCopy)
c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2));
else if(selectMode==SelectCut) else if(selectMode==SelectCut)
@ -1033,7 +1031,6 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2)); c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2));
} }
} }
}
currentMouse = ui::Point(x, y); currentMouse = ui::Point(x, y);
selectMode = SelectNone; selectMode = SelectNone;
return; return;

View File

@ -167,7 +167,7 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
GameSave * Simulation::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) 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; blockX = fullX/CELL;
blockY = fullY/CELL; blockY = fullY/CELL;
blockX2 = fullX2/CELL; blockX2 = (fullX2+CELL)/CELL;
blockY2 = fullY2/CELL; blockY2 = (fullY2+CELL)/CELL;
fullX = blockX*CELL; //fullX = blockX*CELL;
fullY = blockY*CELL; //fullY = blockY*CELL;
fullX2 = blockX2*CELL; //fullX2 = blockX2*CELL;
fullY2 = blockY2*CELL; //fullY2 = blockY2*CELL;
blockW = blockX2-blockX; blockW = blockX2-blockX;
blockH = blockY2-blockY; blockH = blockY2-blockY;
@ -216,11 +216,11 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
int x, y; int x, y;
x = int(parts[i].x + 0.5f); x = int(parts[i].x + 0.5f);
y = int(parts[i].y + 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]; Particle tempPart = parts[i];
tempPart.x -= fullX; tempPart.x -= blockX*CELL;
tempPart.y -= fullY; tempPart.y -= blockY*CELL;
if(elements[tempPart.type].Enabled) if(elements[tempPart.type].Enabled)
{ {
*newSave << tempPart; *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++) 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]; sign tempSign = signs[i];
tempSign.x -= fullX; tempSign.x -= blockX*CELL;
tempSign.y -= fullY; tempSign.y -= blockY*CELL;
*newSave << tempSign; *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) if(bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] == WL_GRAV)
gravWallChanged = true; gravWallChanged = true;
bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0; 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); 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) void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags)