porymap/include/core/regionmap.h

153 lines
3.3 KiB
C
Raw Normal View History

2020-09-13 23:37:55 +01:00
#pragma once
#ifndef REGIONMAP_H
#define REGIONMAP_H
#include "map.h"
2019-01-22 20:06:49 +00:00
#include "project.h"
#include "tilemaptileselector.h"
#include "history.h"
#include <QStringList>
#include <QString>
2019-01-14 00:27:28 +00:00
#include <QVector>
#include <QList>
#include <QMap>
#include <QGraphicsScene>
#include <QGraphicsView>
enum RegionMapEditorBox {
BackgroundImage = 1,
CityMapImage = 2,
};
class RegionMapHistoryItem {
public:
int which;
int mapWidth = 0;
int mapHeight = 0;
QVector<uint8_t> tiles;
QString cityMap;
2020-08-27 01:42:42 +01:00
RegionMapHistoryItem(int which, QVector<uint8_t> tiles, QString cityMap) {
this->which = which;
this->tiles = tiles;
this->cityMap = cityMap;
}
2020-08-27 01:42:42 +01:00
RegionMapHistoryItem(int which, QVector<uint8_t> tiles, int width, int height) {
this->which = which;
this->tiles = tiles;
this->mapWidth = width;
this->mapHeight = height;
}
~RegionMapHistoryItem() {}
};
2019-04-13 02:25:43 +01:00
class RegionMapEntry
2019-01-05 04:04:14 +00:00
{
2019-04-13 02:25:43 +01:00
public:
2019-04-13 04:07:00 +01:00
RegionMapEntry()=default;
RegionMapEntry(int x_, int y_, int width_, int height_, QString name_) {
this-> x = x_;
this-> y = y_;
this-> width = width_;
this-> height = height_;
this-> name = name_;
}
2019-01-05 04:04:14 +00:00
int x;
int y;
int width;
int height;
2019-01-14 00:27:28 +00:00
QString name;
2019-04-13 02:25:43 +01:00
void setX(int);
void setY(int);
void setWidth(int);
void setHeight(int);
2019-01-05 04:04:14 +00:00
};
class RegionMapSquare
{
public:
2019-01-14 00:27:28 +00:00
int x = -1;
int y = -1;
2019-01-28 18:47:20 +00:00
uint8_t tile_img_id = 0x00;
uint8_t secid = 0x00;
2019-01-14 00:27:28 +00:00
bool has_map = false;
2019-01-28 18:47:20 +00:00
bool has_city_map = false;
bool duplicated = false;
2019-01-14 00:27:28 +00:00
QString map_name;
2019-01-05 04:04:14 +00:00
QString mapsec;
2019-01-14 00:27:28 +00:00
QString city_map_name;
};
2021-02-18 13:43:52 +00:00
class RegionMap
{
public:
RegionMap() = default;
Project *project = nullptr;
2019-01-05 04:04:14 +00:00
2019-01-14 00:27:28 +00:00
QVector<RegionMapSquare> map_squares;
2019-01-28 18:47:20 +00:00
History<RegionMapHistoryItem*> history;
2019-04-13 02:25:43 +01:00
QMap<QString, QString> sMapNamesMap;
QMap<QString, RegionMapEntry> mapSecToMapEntry;
QVector<QString> sMapNames;
const int padLeft = 1;
const int padRight = 3;
const int padTop = 2;
const int padBottom = 3;
bool init(Project*);
bool readBkgImgBin();
bool readLayout();
void save();
2019-03-25 04:10:57 +00:00
void saveTileImages();
void saveBkgImgBin();
void saveLayout();
2019-01-28 18:47:20 +00:00
void saveOptions(int id, QString sec, QString name, int x, int y);
void resize(int width, int height);
void resetSquare(int index);
void clearLayout();
void clearImage();
void replaceSectionId(unsigned oldId, unsigned newId);
int width();
int height();
QSize imgSize();
2019-01-28 18:47:20 +00:00
unsigned getTileId(int x, int y);
int getMapSquareIndex(int x, int y);
QString pngPath();
2019-03-25 04:10:57 +00:00
void setTemporaryPngPath(QString);
2019-01-28 18:47:20 +00:00
QString cityTilesPath();
2019-03-25 04:10:57 +00:00
void setTemporaryCityTilesPath(QString);
2019-01-22 20:06:49 +00:00
QVector<uint8_t> getTiles();
2019-01-28 18:47:20 +00:00
void setTiles(QVector<uint8_t> tileIds);
2019-04-13 04:07:00 +01:00
QString fixCase(QString);
private:
int layout_width_;
int layout_height_;
int img_width_;
int img_height_;
2019-01-28 18:47:20 +00:00
QString region_map_png_path;
QString region_map_bin_path;
QString region_map_entries_path;
QString region_map_layout_bin_path;
QString city_map_tiles_path;
2019-08-19 15:21:40 +01:00
bool region_map_png_needs_saving = false;
bool city_map_png_needs_saving = false;
2019-01-28 18:47:20 +00:00
int img_index_(int x, int y);
int layout_index_(int x, int y);
};
#endif // REGIONMAP_H