|
@@ -6,6 +6,7 @@
|
6
|
6
|
#include <QImage>
|
7
|
7
|
#include <QRegularExpression>
|
8
|
8
|
|
|
9
|
+
|
9
|
10
|
Map::Map(QObject *parent) : QObject(parent)
|
10
|
11
|
{
|
11
|
12
|
paint_tile_index = 1;
|
|
@@ -276,6 +277,7 @@ QPixmap Map::render(bool ignoreCache = false) {
|
276
|
277
|
cacheBlockdata();
|
277
|
278
|
pixmap = pixmap.fromImage(image);
|
278
|
279
|
}
|
|
280
|
+
|
279
|
281
|
return pixmap;
|
280
|
282
|
}
|
281
|
283
|
|
|
@@ -427,7 +429,7 @@ QPixmap Map::renderMetatiles() {
|
427
|
429
|
return QPixmap::fromImage(image);
|
428
|
430
|
}
|
429
|
431
|
|
430
|
|
-void Map::setDimensions(int newWidth, int newHeight) {
|
|
432
|
+void Map::setNewDimensionsBlockdata(int newWidth, int newHeight) {
|
431
|
433
|
int oldWidth = getWidth();
|
432
|
434
|
int oldHeight = getHeight();
|
433
|
435
|
|
|
@@ -444,9 +446,15 @@ void Map::setDimensions(int newWidth, int newHeight) {
|
444
|
446
|
}
|
445
|
447
|
|
446
|
448
|
layout->blockdata->copyFrom(newBlockData);
|
|
449
|
+}
|
|
450
|
+
|
|
451
|
+void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
|
|
452
|
+ if (setNewBlockdata) {
|
|
453
|
+ setNewDimensionsBlockdata(newWidth, newHeight);
|
|
454
|
+ }
|
|
455
|
+
|
447
|
456
|
layout->width = QString::number(newWidth);
|
448
|
457
|
layout->height = QString::number(newHeight);
|
449
|
|
- commit();
|
450
|
458
|
|
451
|
459
|
emit mapChanged(this);
|
452
|
460
|
}
|
|
@@ -602,29 +610,48 @@ void Map::_floodFillCollisionElevation(int x, int y, uint collision, uint elevat
|
602
|
610
|
|
603
|
611
|
|
604
|
612
|
void Map::undo() {
|
|
613
|
+ HistoryItem *commit = history.back();
|
|
614
|
+ if (!commit)
|
|
615
|
+ return;
|
|
616
|
+
|
605
|
617
|
if (layout->blockdata) {
|
606
|
|
- Blockdata *commit = history.back();
|
607
|
|
- if (commit != NULL) {
|
608
|
|
- layout->blockdata->copyFrom(commit);
|
609
|
|
- emit mapChanged(this);
|
|
618
|
+ layout->blockdata->copyFrom(commit->metatiles);
|
|
619
|
+ if (commit->layoutWidth != this->getWidth() || commit->layoutHeight != this->getHeight())
|
|
620
|
+ {
|
|
621
|
+ this->setDimensions(commit->layoutWidth, commit->layoutHeight, false);
|
|
622
|
+ emit mapNeedsRedrawing(this);
|
610
|
623
|
}
|
|
624
|
+
|
|
625
|
+ emit mapChanged(this);
|
611
|
626
|
}
|
612
|
627
|
}
|
613
|
628
|
|
614
|
629
|
void Map::redo() {
|
|
630
|
+ HistoryItem *commit = history.next();
|
|
631
|
+ if (!commit)
|
|
632
|
+ return;
|
|
633
|
+
|
615
|
634
|
if (layout->blockdata) {
|
616
|
|
- Blockdata *commit = history.next();
|
617
|
|
- if (commit != NULL) {
|
618
|
|
- layout->blockdata->copyFrom(commit);
|
619
|
|
- emit mapChanged(this);
|
|
635
|
+ layout->blockdata->copyFrom(commit->metatiles);
|
|
636
|
+ if (commit->layoutWidth != this->getWidth() || commit->layoutHeight != this->getHeight())
|
|
637
|
+ {
|
|
638
|
+ this->setDimensions(commit->layoutWidth, commit->layoutHeight, false);
|
|
639
|
+ emit mapNeedsRedrawing(this);
|
620
|
640
|
}
|
|
641
|
+
|
|
642
|
+ emit mapChanged(this);
|
621
|
643
|
}
|
622
|
644
|
}
|
623
|
645
|
|
624
|
646
|
void Map::commit() {
|
625
|
647
|
if (layout->blockdata) {
|
626
|
|
- if (!layout->blockdata->equals(history.current())) {
|
627
|
|
- Blockdata* commit = layout->blockdata->copy();
|
|
648
|
+ HistoryItem *item = history.current();
|
|
649
|
+ bool atCurrentHistory = item
|
|
650
|
+ && layout->blockdata->equals(item->metatiles)
|
|
651
|
+ && this->getWidth() == item->layoutWidth
|
|
652
|
+ && this->getHeight() == item->layoutHeight;
|
|
653
|
+ if (!atCurrentHistory) {
|
|
654
|
+ HistoryItem *commit = new HistoryItem(layout->blockdata->copy(), this->getWidth(), this->getHeight());
|
628
|
655
|
history.push(commit);
|
629
|
656
|
emit mapChanged(this);
|
630
|
657
|
}
|