aboutsummaryrefslogtreecommitdiff
path: root/Source/MapEditor
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2018-11-25 18:02:18 +0100
committerXavier ASUS <xavi92psx@gmail.com>2018-11-25 18:02:18 +0100
commit64dbf5cdd5c16ab6ccdadcfd66949aba5b8fa1e2 (patch)
treed408c06ac5573c35eaee8fd451114fd73acde2f8 /Source/MapEditor
parent135a1e93cb9b3a859c4269a94ababe33b3558f9a (diff)
Bugfix: minutes were not being retrieved from PLT files.
Game.c: parking slots cannot be selected if an aircraft in STATE_PARKED state is on it. Other fixes and improvements. Added some tiles from TILESET2.TIM
Diffstat (limited to 'Source/MapEditor')
-rw-r--r--Source/MapEditor/MapEditor.pro.user2
-rw-r--r--Source/MapEditor/mainwindow.cpp189
-rw-r--r--Source/MapEditor/mainwindow.h3
-rw-r--r--Source/MapEditor/mygraphicsscene.cpp2
-rw-r--r--Source/MapEditor/tileset.ini8
5 files changed, 136 insertions, 68 deletions
diff --git a/Source/MapEditor/MapEditor.pro.user b/Source/MapEditor/MapEditor.pro.user
index dc09951..2ef5a22 100644
--- a/Source/MapEditor/MapEditor.pro.user
+++ b/Source/MapEditor/MapEditor.pro.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.7.2, 2018-11-24T13:04:29. -->
+<!-- Written by QtCreator 4.7.2, 2018-11-25T17:34:10. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
diff --git a/Source/MapEditor/mainwindow.cpp b/Source/MapEditor/mainwindow.cpp
index 3758925..e641a4d 100644
--- a/Source/MapEditor/mainwindow.cpp
+++ b/Source/MapEditor/mainwindow.cpp
@@ -251,20 +251,24 @@ void MainWindow::processMapFile(const QByteArray& data)
level_size = ch;
- const QString filePath = "../../Sprites/TILESET1.bmp";
-
- QPixmap tile1(filePath);
+ if (not tilesetPaths[0].isEmpty()
+ &&
+ not tilesetPaths[1].isEmpty())
+ {
+ QPixmap tile1(tilesetPaths[0]);
+ QPixmap tile2(tilesetPaths[1]);
- const int expected_filesize = (DATA_HEADER_SIZE + (level_size * level_size));
+ const int expected_filesize = (DATA_HEADER_SIZE + (level_size * level_size));
- if (data.count() >= expected_filesize)
- {
- parseMapData(ds, tile1);
- }
- else
- {
- showError(tr("Invalid file size. Expected ")
- + QString::number(expected_filesize, 10));
+ if (data.count() >= expected_filesize)
+ {
+ parseMapData(ds, tile1, tile2);
+ }
+ else
+ {
+ showError(tr("Invalid file size. Expected ")
+ + QString::number(expected_filesize, 10));
+ }
}
}
else
@@ -273,7 +277,7 @@ void MainWindow::processMapFile(const QByteArray& data)
}
}
-void MainWindow::parseMapData(QDataStream& ds, const QPixmap& tileSet)
+void MainWindow::parseMapData(QDataStream& ds, const QPixmap& tileSet, const QPixmap& tileSet2)
{
char airportName[0x1A];
@@ -290,89 +294,143 @@ void MainWindow::parseMapData(QDataStream& ds, const QPixmap& tileSet)
{
for (int i = 0; i < level_size; i++)
{
+ enum
+ {
+ TILE_GRASS = 0,
+ TILE_ASPHALT_WITH_BORDERS,
+ TILE_WATER,
+ TILE_ASPHALT,
+
+ TILE_RWY_MID,
+ TILE_RWY_START_1,
+ TILE_RWY_START_2,
+ TILE_PARKING,
+
+ TILE_PARKING_2,
+ TILE_TAXIWAY_INTERSECT_GRASS,
+ TILE_TAXIWAY_GRASS,
+ TILE_TAXIWAY_CORNER_GRASS,
+
+ TILE_HALF_WATER_1,
+ TILE_HALF_WATER_2,
+ TILE_RWY_HOLDING_POINT,
+ TILE_RWY_HOLDING_POINT_2,
+
+ TILE_RWY_EXIT,
+ TILE_TAXIWAY_CORNER_GRASS_2,
+ TILE_TAXIWAY_4WAY_CROSSING,
+ TILE_RWY_EXIT_2,
+
+ LAST_TILE_TILESET1 = TILE_RWY_EXIT_2,
+
+ TILE_UNUSED_1,
+ TILE_TAXIWAY_CORNER_GRASS_3,
+
+ FIRST_TILE_TILESET2 = TILE_UNUSED_1,
+ LAST_TILE_TILESET2 = TILE_TAXIWAY_CORNER_GRASS_3
+ };
+
int u;
int v;
char byte[2];
ds.readRawData(byte, 2);
quint8 CurrentTile = static_cast<quint8>(byte[1]);
+ quint8 CurrentBuilding = static_cast<quint8>(byte[0]);
+ quint8 buildingNoMirror = CurrentBuilding & 0x7F;
+ quint8 tileNoMirror = CurrentTile & 0x7F;
+ const QPixmap* p = nullptr;
- if (CurrentTile & TILE_MIRROR_FLAG)
+ if (tileNoMirror <= LAST_TILE_TILESET1)
{
- u = static_cast<int>(((CurrentTile & 0x7F) % 4) * 64);
- v = static_cast<int>(((CurrentTile & 0x7F) / 4) * 48);
+ p = &tileSet;
}
- else
+ else if (tileNoMirror <= LAST_TILE_TILESET2)
{
- u = static_cast<int>((CurrentTile % 4) * 64);
- v = static_cast<int>((CurrentTile / 4) * 48);
+ p = &tileSet2;
+ CurrentTile -= FIRST_TILE_TILESET2;
+ tileNoMirror -= FIRST_TILE_TILESET2;
}
- QImage cropped = tileSet.copy(u, v, 64, 48).toImage();
-
- if (CurrentTile & TILE_MIRROR_FLAG)
+ if (p != nullptr)
{
- cropped = cropped.mirrored(true, false);
- }
+ if (CurrentTile & TILE_MIRROR_FLAG)
+ {
+ u = static_cast<int>((tileNoMirror % 4) * 64);
+ v = static_cast<int>((tileNoMirror / 4) * 48);
+ }
+ else
+ {
+ u = static_cast<int>((CurrentTile % 4) * 64);
+ v = static_cast<int>((CurrentTile / 4) * 48);
+ }
- bool selected = false;
+ QImage cropped = p->copy(u, v, 64, 48).toImage();
- if (selected_item != -1)
- {
- if (selected_item == ((j * level_size) + i))
+ if (CurrentTile & TILE_MIRROR_FLAG)
{
- selected = true;
+ cropped = cropped.mirrored(true, false);
}
- }
- cropped = cropped.convertToFormat(QImage::Format_ARGB32); // or maybe other format
+ bool selected = false;
- for (int i = 0; i < cropped.width(); i++)
- {
- for (int j = 0; j < cropped.height(); j++)
+ if (selected_item != -1)
{
- QColor rgb = cropped.pixel(i, j);
-
- if (rgb == QColor(Qt::magenta))
+ if (selected_item == ((j * level_size) + i))
{
- cropped.setPixel(i, j, qRgba(0,0,0,0));
+ selected = true;
}
- else if (selected )
- {
- QColor c = cropped.pixelColor(i, j);
+ }
- c.setRed(255 - c.red());
- c.setBlue(255 - c.blue());
- c.setGreen(255 - c.green());
+ cropped = cropped.convertToFormat(QImage::Format_ARGB32); // or maybe other format
- cropped.setPixel(i, j, qRgb(c.red(), c.green(), c.blue()));
+ for (int i = 0; i < cropped.width(); i++)
+ {
+ for (int j = 0; j < cropped.height(); j++)
+ {
+ QColor rgb = cropped.pixel(i, j);
+
+ if (rgb == QColor(Qt::magenta))
+ {
+ cropped.setPixel(i, j, qRgba(0,0,0,0));
+ }
+ else if (selected )
+ {
+ QColor c = cropped.pixelColor(i, j);
+
+ c.setRed(255 - c.red());
+ c.setBlue(255 - c.blue());
+ c.setGreen(255 - c.green());
+
+ cropped.setPixel(i, j, qRgb(c.red(), c.green(), c.blue()));
+ }
}
}
- }
-
- QGraphicsPixmapItem* const it = gscene.addPixmap(QPixmap::fromImage(cropped));
- if (it != nullptr)
- {
- const int x = ((i * TILE_SIZE) - (i * (TILE_SIZE / 2))) - (j * (TILE_SIZE / 2));
- const int y = (j * (TILE_SIZE / 4)) + (i * (TILE_SIZE / 4));
-
- it->setX(x);
- it->setY(y);
+ QGraphicsPixmapItem* const it = gscene.addPixmap(QPixmap::fromImage(cropped));
- if (ui.showNumbers_Checkbox->isChecked() )
+ if (it != nullptr)
{
- QGraphicsTextItem* const io = new QGraphicsTextItem();
+ const int x = ((i * TILE_SIZE) - (i * (TILE_SIZE / 2))) - (j * (TILE_SIZE / 2));
+ const int y = (j * (TILE_SIZE / 4)) + (i * (TILE_SIZE / 4));
+
+ it->setX(x);
+ it->setY(y);
- if (io != nullptr)
+ if (ui.showNumbers_Checkbox->isChecked() )
{
- io->setPos(x + (TILE_SIZE / 4), y);
- io->setPlainText(QString::number(i + (j * level_size)));
+ QGraphicsTextItem* const io = new QGraphicsTextItem();
- gscene.addItem(io);
+ if (io != nullptr)
+ {
+ io->setPos(x + (TILE_SIZE / 4), y);
+ io->setPlainText(QString::number(i + (j * level_size)));
- /* Append pointer to the list so it can be
- * safely removed on the constructor. */
- textItems.append(io);
+ gscene.addItem(io);
+
+ /* Append pointer to the list so it can be
+ * safely removed on the constructor. */
+ textItems.append(io);
+ }
}
}
}
@@ -438,12 +496,15 @@ void MainWindow::loadTilesetData(void)
tilesets_to_check << "tileset1";
tilesets_to_check << "tileset2";
+ int j = 0;
int i = 0;
foreach (QString tileset, tilesets_to_check)
{
tilesetFile.beginGroup(tileset);
+ tilesetPaths[j++] = tilesetFile.value("path").toString();
+
while (1)
{
QString tileNumber = "tile" + QString::number(i);
diff --git a/Source/MapEditor/mainwindow.h b/Source/MapEditor/mainwindow.h
index 40963c9..97e39ef 100644
--- a/Source/MapEditor/mainwindow.h
+++ b/Source/MapEditor/mainwindow.h
@@ -37,7 +37,7 @@ private:
void appSettings(void);
void loadTilesetData(void);
void loadBuildingData(void);
- void parseMapData(QDataStream &ds, const QPixmap &tileSet);
+ void parseMapData(QDataStream &ds, const QPixmap &tileSet, const QPixmap &tileSet2);
Ui::MainWindow ui;
QString _last_dir;
@@ -49,6 +49,7 @@ private:
QList<QGraphicsTextItem*> textItems;
QShortcut tileSet;
QShortcut tileMoveUp;
+ QString tilesetPaths[2];
private slots:
void loadMap(void);
diff --git a/Source/MapEditor/mygraphicsscene.cpp b/Source/MapEditor/mygraphicsscene.cpp
index e108375..d0241ae 100644
--- a/Source/MapEditor/mygraphicsscene.cpp
+++ b/Source/MapEditor/mygraphicsscene.cpp
@@ -15,7 +15,7 @@ void MyGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
QGraphicsItem *it = this->itemAt(mouseEvent->scenePos(), QTransform());
- if (it != NULL)
+ if (it != nullptr)
{
emit positionClicked(mouseEvent->scenePos());
}
diff --git a/Source/MapEditor/tileset.ini b/Source/MapEditor/tileset.ini
index 488e023..8030b9f 100644
--- a/Source/MapEditor/tileset.ini
+++ b/Source/MapEditor/tileset.ini
@@ -1,4 +1,5 @@
[tileset1]
+path = "../../Sprites/TILESET1.bmp"
tile0 = "Grass"
tile1 = "Asphalt with borders"
tile2 = "Water"
@@ -18,4 +19,9 @@ tile15 = "Runway holding point 2"
tile16 = "Runway enter/exit, asphalt border 1"
tile17 = "Taxiway corner, grass border 2"
tile18 = "Taxiway 4-way crossing, grass border"
-tile19 = "Runway enter/exit, asphalt border 2" \ No newline at end of file
+tile19 = "Runway enter/exit, asphalt border 2"
+
+[tileset2]
+path = "../../Sprites/TILESET2.bmp"
+tile20 = "Unused"
+tile21 = "Taxiway corner, grass border 3"