2019-01-07 19:46:27 +00:00
|
|
|
#include "regionmapeditor.h"
|
|
|
|
#include "ui_regionmapeditor.h"
|
2019-01-15 22:06:18 +00:00
|
|
|
#include "regionmapgenerator.h"
|
|
|
|
#include "config.h"
|
2019-01-07 19:46:27 +00:00
|
|
|
|
|
|
|
#include <QDir>
|
2019-01-09 02:03:54 +00:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QColor>
|
2019-01-07 19:46:27 +00:00
|
|
|
|
|
|
|
RegionMapEditor::RegionMapEditor(QWidget *parent, Project *pro) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
ui(new Ui::RegionMapEditor)
|
|
|
|
{
|
2019-01-09 02:03:54 +00:00
|
|
|
this->ui->setupUi(this);
|
2019-01-07 19:46:27 +00:00
|
|
|
this->project = pro;
|
|
|
|
this->region_map = new RegionMap;
|
2019-01-14 00:27:28 +00:00
|
|
|
this->setFixedSize(this->size());
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RegionMapEditor::~RegionMapEditor()
|
|
|
|
{
|
|
|
|
delete ui;
|
2019-01-14 00:27:28 +00:00
|
|
|
delete region_map;
|
|
|
|
delete region_map_item;
|
|
|
|
delete mapsquare_selector_item;
|
|
|
|
delete region_map_layout_item;
|
|
|
|
delete scene_region_map_image;
|
|
|
|
delete city_map_selector_item;
|
|
|
|
delete city_map_item;
|
|
|
|
delete scene_city_map_tiles;
|
|
|
|
delete scene_city_map_image;
|
|
|
|
delete scene_region_map_layout;
|
|
|
|
delete scene_region_map_tiles;
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::on_action_RegionMap_Save_triggered() {
|
|
|
|
if (project && region_map) {
|
|
|
|
region_map->save();
|
|
|
|
displayRegionMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::loadRegionMapData() {
|
|
|
|
this->region_map->init(project);
|
2019-01-15 22:06:18 +00:00
|
|
|
this->currIndex = this->region_map->width() * this->region_map->padTop + this->region_map->padLeft;
|
2019-01-07 19:46:27 +00:00
|
|
|
displayRegionMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::loadCityMaps() {
|
|
|
|
QDir directory(project->root + "/graphics/pokenav/city_maps");
|
|
|
|
QStringList files = directory.entryList(QStringList() << "*.bin", QDir::Files);
|
|
|
|
QStringList without_bin;
|
|
|
|
for (QString file : files) {
|
|
|
|
without_bin.append(file.remove(".bin"));
|
|
|
|
}
|
|
|
|
this->ui->comboBox_CityMap_picker->addItems(without_bin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::displayRegionMap() {
|
|
|
|
displayRegionMapTileSelector();
|
|
|
|
displayCityMapTileSelector();
|
|
|
|
displayRegionMapImage();
|
|
|
|
displayRegionMapLayout();
|
|
|
|
displayRegionMapLayoutOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::displayRegionMapImage() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (!scene_region_map_image) {
|
|
|
|
this->scene_region_map_image = new QGraphicsScene;
|
|
|
|
}
|
|
|
|
if (region_map_item && scene_region_map_image) {
|
|
|
|
scene_region_map_image->removeItem(region_map_item);
|
|
|
|
delete region_map_item;
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
this->region_map_item = new RegionMapPixmapItem(this->region_map, this->mapsquare_selector_item);
|
|
|
|
this->region_map_item->draw();
|
|
|
|
|
2019-01-14 00:27:28 +00:00
|
|
|
connect(this->region_map_item, &RegionMapPixmapItem::mouseEvent,
|
|
|
|
this, &RegionMapEditor::mouseEvent_region_map);
|
|
|
|
connect(this->region_map_item, &RegionMapPixmapItem::hoveredRegionMapTileChanged,
|
|
|
|
this, &RegionMapEditor::onHoveredRegionMapTileChanged);
|
|
|
|
connect(this->region_map_item, &RegionMapPixmapItem::hoveredRegionMapTileCleared,
|
|
|
|
this, &RegionMapEditor::onHoveredRegionMapTileCleared);
|
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
this->scene_region_map_image->addItem(this->region_map_item);
|
2019-01-15 22:06:18 +00:00
|
|
|
this->scene_region_map_image->setSceneRect(this->scene_region_map_image->itemsBoundingRect());
|
2019-01-07 19:46:27 +00:00
|
|
|
|
|
|
|
this->ui->graphicsView_Region_Map_BkgImg->setScene(this->scene_region_map_image);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::displayRegionMapLayout() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (!scene_region_map_layout) {
|
|
|
|
this->scene_region_map_layout = new QGraphicsScene;
|
|
|
|
}
|
|
|
|
if (region_map_layout_item && scene_region_map_layout) {
|
|
|
|
this->scene_region_map_layout->removeItem(region_map_layout_item);
|
|
|
|
delete region_map_layout_item;
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
this->region_map_layout_item = new RegionMapLayoutPixmapItem(this->region_map, this->mapsquare_selector_item);
|
2019-01-14 00:27:28 +00:00
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
connect(this->region_map_layout_item, &RegionMapLayoutPixmapItem::selectedTileChanged,
|
2019-01-14 00:27:28 +00:00
|
|
|
this, &RegionMapEditor::onRegionMapLayoutSelectedTileChanged);
|
2019-01-07 19:46:27 +00:00
|
|
|
connect(this->region_map_layout_item, &RegionMapLayoutPixmapItem::hoveredTileChanged,
|
|
|
|
this, &RegionMapEditor::onRegionMapLayoutHoveredTileChanged);
|
|
|
|
connect(this->region_map_layout_item, &RegionMapLayoutPixmapItem::hoveredTileCleared,
|
|
|
|
this, &RegionMapEditor::onRegionMapLayoutHoveredTileCleared);
|
2019-01-14 00:27:28 +00:00
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
this->region_map_layout_item->draw();
|
2019-01-14 00:27:28 +00:00
|
|
|
this->region_map_layout_item->select(this->currIndex);
|
2019-01-07 19:46:27 +00:00
|
|
|
|
|
|
|
this->scene_region_map_layout->addItem(region_map_layout_item);
|
2019-01-15 22:06:18 +00:00
|
|
|
this->scene_region_map_layout->setSceneRect(this->scene_region_map_layout->itemsBoundingRect());
|
2019-01-07 19:46:27 +00:00
|
|
|
|
|
|
|
this->ui->graphicsView_Region_Map_Layout->setScene(this->scene_region_map_layout);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::displayRegionMapLayoutOptions() {
|
2019-01-15 22:06:18 +00:00
|
|
|
this->ui->comboBox_RM_ConnectedMap->clear();
|
2019-01-07 19:46:27 +00:00
|
|
|
this->ui->comboBox_RM_ConnectedMap->addItems(*(this->project->regionMapSections));
|
|
|
|
|
|
|
|
this->ui->frame_RM_Options->setEnabled(true);
|
|
|
|
|
2019-01-15 22:06:18 +00:00
|
|
|
this->ui->spinBox_RM_Options_x->setMaximum(
|
|
|
|
this->region_map->width() - this->region_map->padLeft - this->region_map->padRight - 1
|
|
|
|
);
|
|
|
|
this->ui->spinBox_RM_Options_y->setMaximum(
|
|
|
|
this->region_map->height() - this->region_map->padTop - this->region_map->padBottom - 1
|
|
|
|
);
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-14 00:27:28 +00:00
|
|
|
updateRegionMapLayoutOptions(currIndex);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::updateRegionMapLayoutOptions(int index) {
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->spinBox_RM_Options_x->blockSignals(true);
|
|
|
|
this->ui->spinBox_RM_Options_y->blockSignals(true);
|
2019-01-15 22:06:18 +00:00
|
|
|
this->ui->lineEdit_RM_MapName->setText(this->project->mapSecToMapHoverName->value(this->region_map->map_squares[index].mapsec));
|
2019-01-07 19:46:27 +00:00
|
|
|
this->ui->comboBox_RM_ConnectedMap->setCurrentText(this->region_map->map_squares[index].mapsec);
|
|
|
|
this->ui->spinBox_RM_Options_x->setValue(this->region_map->map_squares[index].x);
|
|
|
|
this->ui->spinBox_RM_Options_y->setValue(this->region_map->map_squares[index].y);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->spinBox_RM_Options_x->blockSignals(false);
|
|
|
|
this->ui->spinBox_RM_Options_y->blockSignals(false);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::displayRegionMapTileSelector() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (!scene_region_map_tiles) {
|
|
|
|
this->scene_region_map_tiles = new QGraphicsScene;
|
|
|
|
}
|
|
|
|
if (mapsquare_selector_item && scene_region_map_tiles) {
|
|
|
|
this->scene_region_map_tiles->removeItem(mapsquare_selector_item);
|
|
|
|
delete mapsquare_selector_item;
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
this->mapsquare_selector_item = new TilemapTileSelector(QPixmap(this->region_map->region_map_png_path));
|
|
|
|
this->mapsquare_selector_item->draw();
|
|
|
|
|
|
|
|
this->scene_region_map_tiles->addItem(this->mapsquare_selector_item);
|
|
|
|
|
2019-01-15 22:06:18 +00:00
|
|
|
connect(this->mapsquare_selector_item, &TilemapTileSelector::selectedTileChanged,
|
|
|
|
this, &RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged);
|
2019-01-07 19:46:27 +00:00
|
|
|
connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileChanged,
|
|
|
|
this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged);
|
|
|
|
connect(this->mapsquare_selector_item, &TilemapTileSelector::hoveredTileCleared,
|
|
|
|
this, &RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared);
|
|
|
|
|
|
|
|
this->ui->graphicsView_RegionMap_Tiles->setScene(this->scene_region_map_tiles);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2,
|
|
|
|
this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2);
|
2019-01-15 22:06:18 +00:00
|
|
|
|
|
|
|
this->mapsquare_selector_item->select(this->selectedImageTile);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::displayCityMapTileSelector() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (!scene_city_map_tiles) {
|
|
|
|
this->scene_city_map_tiles = new QGraphicsScene;
|
|
|
|
}
|
|
|
|
if (city_map_selector_item && scene_city_map_tiles) {
|
|
|
|
scene_city_map_tiles->removeItem(city_map_selector_item);
|
|
|
|
delete city_map_selector_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->city_map_selector_item = new TilemapTileSelector(QPixmap(this->region_map->city_map_tiles_path));
|
2019-01-07 19:46:27 +00:00
|
|
|
this->city_map_selector_item->draw();
|
|
|
|
|
|
|
|
this->scene_city_map_tiles->addItem(this->city_map_selector_item);
|
|
|
|
|
2019-01-15 22:06:18 +00:00
|
|
|
connect(this->city_map_selector_item, &TilemapTileSelector::selectedTileChanged,
|
|
|
|
this, &RegionMapEditor::onCityMapTileSelectorSelectedTileChanged);
|
2019-01-07 19:46:27 +00:00
|
|
|
|
|
|
|
this->ui->graphicsView_City_Map_Tiles->setScene(this->scene_city_map_tiles);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2,
|
|
|
|
this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2);
|
2019-01-15 22:06:18 +00:00
|
|
|
|
|
|
|
this->city_map_selector_item->select(this->selectedCityTile);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::displayCityMap(QString f) {
|
|
|
|
QString file = this->project->root + "/graphics/pokenav/city_maps/" + f + ".bin";
|
|
|
|
|
|
|
|
if (!scene_city_map_image) {
|
|
|
|
scene_city_map_image = new QGraphicsScene;
|
|
|
|
}
|
|
|
|
if (city_map_item && scene_city_map_image) {
|
|
|
|
scene_city_map_image->removeItem(city_map_item);
|
|
|
|
delete city_map_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
city_map_item = new CityMapPixmapItem(file, this->city_map_selector_item);
|
|
|
|
city_map_item->draw();
|
|
|
|
|
2019-01-14 00:27:28 +00:00
|
|
|
connect(this->city_map_item, &CityMapPixmapItem::mouseEvent,
|
|
|
|
this, &RegionMapEditor::mouseEvent_city_map);
|
2019-01-07 19:46:27 +00:00
|
|
|
|
|
|
|
scene_city_map_image->addItem(city_map_item);
|
|
|
|
scene_city_map_image->setSceneRect(this->scene_city_map_image->sceneRect());
|
|
|
|
|
|
|
|
this->ui->graphicsView_City_Map->setScene(scene_city_map_image);
|
2019-01-15 22:06:18 +00:00
|
|
|
this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2,
|
|
|
|
8 * city_map_item->height() * scaleCityMapImage + 2);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
bool RegionMapEditor::createCityMap(QString name) {
|
|
|
|
bool errored = false;
|
|
|
|
|
|
|
|
QString file = this->project->root + "/graphics/pokenav/city_maps/" + name + ".bin";
|
|
|
|
|
|
|
|
uint8_t filler = 0x30;
|
|
|
|
uint8_t border = 0x7;
|
|
|
|
uint8_t blank = 0x1;
|
|
|
|
QByteArray new_data(400, filler);
|
|
|
|
for (int i = 0; i < new_data.size(); i++) {
|
|
|
|
if (i % 2) continue;
|
|
|
|
int x = i % 20;
|
|
|
|
int y = i / 20;
|
|
|
|
if (y <= 1 || y >= 8 || x <= 3 || x >= 16)
|
|
|
|
new_data[i] = border;
|
|
|
|
else
|
|
|
|
new_data[i] = blank;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile binFile(file);
|
|
|
|
if (!binFile.open(QIODevice::WriteOnly)) errored = true;
|
|
|
|
binFile.write(new_data);
|
|
|
|
binFile.close();
|
|
|
|
|
|
|
|
loadCityMaps();
|
|
|
|
this->ui->comboBox_CityMap_picker->setCurrentText(name);
|
|
|
|
|
|
|
|
return !errored;
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-15 22:06:18 +00:00
|
|
|
void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) {
|
|
|
|
this->selectedImageTile = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::onCityMapTileSelectorSelectedTileChanged(unsigned id) {
|
|
|
|
this->selectedCityTile = id;
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
void RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged(unsigned tileId) {
|
|
|
|
QString message = QString("Tile: 0x") + QString("%1").arg(tileId, 4, 16, QChar('0')).toUpper();
|
|
|
|
this->ui->statusbar->showMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared() {
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->statusbar->clearMessage();
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
|
|
|
|
QString message = QString();
|
2019-01-14 00:27:28 +00:00
|
|
|
this->currIndex = index;
|
2019-01-07 19:46:27 +00:00
|
|
|
if (this->region_map->map_squares[index].has_map) {
|
2019-01-09 02:03:54 +00:00
|
|
|
message = QString("\t %1").arg(this->project->mapSecToMapHoverName->value(
|
2019-01-14 00:27:28 +00:00
|
|
|
this->region_map->map_squares[index].mapsec)).remove("{NAME_END}");// ruby-specific
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
this->ui->statusbar->showMessage(message);
|
|
|
|
|
|
|
|
updateRegionMapLayoutOptions(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::onRegionMapLayoutHoveredTileChanged(int index) {
|
|
|
|
QString message = QString();
|
|
|
|
int x = this->region_map->map_squares[index].x;
|
|
|
|
int y = this->region_map->map_squares[index].y;
|
|
|
|
if (x >= 0 && y >= 0) {
|
|
|
|
message = QString("(%1, %2)").arg(x).arg(y);
|
|
|
|
if (this->region_map->map_squares[index].has_map) {
|
2019-01-09 02:03:54 +00:00
|
|
|
message += QString("\t %1").arg(this->project->mapSecToMapHoverName->value(
|
2019-01-07 19:46:27 +00:00
|
|
|
this->region_map->map_squares[index].mapsec)).remove("{NAME_END}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->ui->statusbar->showMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::onRegionMapLayoutHoveredTileCleared() {
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->statusbar->clearMessage();
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::onHoveredRegionMapTileChanged(int x, int y) {
|
2019-01-15 22:06:18 +00:00
|
|
|
QString message = QString("x: %1, y: %2 Tile: 0x").arg(x).arg(y)
|
|
|
|
+ QString("%1").arg(this->region_map->getTileId(x, y), 4, 16, QChar('0')).toUpper();
|
2019-01-14 00:27:28 +00:00
|
|
|
this->ui->statusbar->showMessage(message);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::onHoveredRegionMapTileCleared() {
|
|
|
|
this->ui->statusbar->clearMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item) {
|
|
|
|
if (event->buttons() & Qt::RightButton) {
|
|
|
|
item->select(event);
|
2019-01-15 22:06:18 +00:00
|
|
|
//} else if (event->buttons() & Qt::MiddleButton) {// TODO
|
2019-01-07 19:46:27 +00:00
|
|
|
} else {
|
2019-01-09 02:03:54 +00:00
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 8;
|
|
|
|
int y = static_cast<int>(pos.y()) / 8;
|
|
|
|
int index = this->region_map->getMapSquareIndex(x, y);
|
2019-01-14 00:27:28 +00:00
|
|
|
if (index > this->region_map->map_squares.size() - 1) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::BackgroundImage, index,
|
|
|
|
this->region_map->map_squares[index].tile_img_id, this->mapsquare_selector_item->getSelectedTile());
|
|
|
|
history.push(commit);
|
2019-01-15 22:06:18 +00:00
|
|
|
item->paint(event);
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) {
|
|
|
|
//
|
2019-01-14 00:27:28 +00:00
|
|
|
if (event->buttons() & Qt::RightButton) {// TODO
|
2019-01-15 22:06:18 +00:00
|
|
|
//} else if (event->buttons() & Qt::MiddleButton) {// TODO
|
2019-01-07 19:46:27 +00:00
|
|
|
} else {
|
2019-01-09 02:03:54 +00:00
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 8;
|
|
|
|
int y = static_cast<int>(pos.y()) / 8;
|
|
|
|
int index = this->city_map_item->getIndexAt(x, y);
|
|
|
|
RegionMapHistoryItem *commit = new RegionMapHistoryItem(RegionMapEditorBox::CityMapImage, index,
|
|
|
|
this->city_map_item->data[index], this->city_map_selector_item->getSelectedTile());
|
|
|
|
history.push(commit);
|
2019-01-07 19:46:27 +00:00
|
|
|
item->paint(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
|
|
|
|
this->ui->stackedWidget_RM_Options->setCurrentIndex(index);
|
2019-01-15 22:06:18 +00:00
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
this->ui->pushButton_Zoom_In_Image_Tiles->setVisible(true);
|
|
|
|
this->ui->pushButton_Zoom_Out_Image_Tiles->setVisible(true);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
this->ui->pushButton_Zoom_In_Image_Tiles->setVisible(false);
|
|
|
|
this->ui->pushButton_Zoom_Out_Image_Tiles->setVisible(false);
|
|
|
|
break;
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 00:27:28 +00:00
|
|
|
void RegionMapEditor::on_spinBox_RM_Options_x_valueChanged(int x) {
|
|
|
|
int y = this->ui->spinBox_RM_Options_y->value();
|
2019-01-15 22:06:18 +00:00
|
|
|
int red = this->region_map->getMapSquareIndex(x + this->region_map->padLeft, y + this->region_map->padTop);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->region_map_layout_item->highlight(x, y, red);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::on_spinBox_RM_Options_y_valueChanged(int y) {
|
|
|
|
int x = this->ui->spinBox_RM_Options_x->value();
|
2019-01-15 22:06:18 +00:00
|
|
|
int red = this->region_map->getMapSquareIndex(x + this->region_map->padLeft, y + this->region_map->padTop);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->region_map_layout_item->highlight(x, y, red);
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
void RegionMapEditor::on_pushButton_RM_Options_save_clicked() {
|
|
|
|
this->region_map->saveOptions(
|
2019-01-15 22:06:18 +00:00
|
|
|
this->region_map_layout_item->selectedTile,
|
2019-01-07 19:46:27 +00:00
|
|
|
this->ui->comboBox_RM_ConnectedMap->currentText(),
|
|
|
|
this->ui->lineEdit_RM_MapName->text(),
|
|
|
|
this->ui->spinBox_RM_Options_x->value(),
|
|
|
|
this->ui->spinBox_RM_Options_y->value()
|
|
|
|
);
|
2019-01-14 00:27:28 +00:00
|
|
|
this->region_map_layout_item->highlightedTile = -1;
|
2019-01-07 19:46:27 +00:00
|
|
|
this->region_map_layout_item->draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::on_pushButton_CityMap_save_clicked() {
|
|
|
|
this->city_map_item->save();
|
|
|
|
}
|
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_RM_Options_delete_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
this->region_map->resetSquare(this->region_map_layout_item->selectedTile);
|
|
|
|
this->region_map_layout_item->draw();
|
|
|
|
this->region_map_layout_item->select(this->region_map_layout_item->selectedTile);
|
2019-01-09 02:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::on_pushButton_CityMap_add_clicked() {
|
|
|
|
QDialog popup(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
|
|
|
popup.setWindowTitle("New City Map");
|
|
|
|
popup.setWindowModality(Qt::NonModal);
|
|
|
|
|
|
|
|
QFormLayout form(&popup);
|
|
|
|
|
|
|
|
QLineEdit *input = new QLineEdit();
|
|
|
|
form.addRow(new QLabel("Name:"), input);
|
|
|
|
|
|
|
|
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &popup);
|
|
|
|
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
form.addRow(&buttonBox);
|
|
|
|
connect(&buttonBox, SIGNAL(rejected()), &popup, SLOT(reject()));
|
|
|
|
connect(&buttonBox, &QDialogButtonBox::accepted, [&popup, &input, &name](){
|
|
|
|
name = input->text().remove(QRegularExpression("[^a-zA-Z0-9_]+"));
|
|
|
|
if (!name.isEmpty())
|
|
|
|
popup.accept();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (popup.exec() == QDialog::Accepted) {
|
|
|
|
createCityMap(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 00:27:28 +00:00
|
|
|
void RegionMapEditor::on_action_RegionMap_Resize_triggered() {
|
|
|
|
QDialog popup(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
|
|
|
popup.setWindowTitle("New Region Map Dimensions");
|
|
|
|
popup.setWindowModality(Qt::NonModal);
|
|
|
|
|
|
|
|
QFormLayout form(&popup);
|
|
|
|
|
|
|
|
QSpinBox *widthSpinBox = new QSpinBox();
|
|
|
|
QSpinBox *heightSpinBox = new QSpinBox();
|
|
|
|
widthSpinBox->setMinimum(32);
|
|
|
|
heightSpinBox->setMinimum(20);
|
2019-01-15 22:06:18 +00:00
|
|
|
widthSpinBox->setMaximum(60);// w * h * 2 <= 4960
|
2019-01-14 00:27:28 +00:00
|
|
|
heightSpinBox->setMaximum(40);
|
|
|
|
widthSpinBox->setValue(this->region_map->width());
|
|
|
|
heightSpinBox->setValue(this->region_map->height());
|
|
|
|
form.addRow(new QLabel("Width"), widthSpinBox);
|
|
|
|
form.addRow(new QLabel("Height"), heightSpinBox);
|
|
|
|
|
|
|
|
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &popup);
|
|
|
|
|
|
|
|
form.addRow(&buttonBox);
|
|
|
|
connect(&buttonBox, SIGNAL(rejected()), &popup, SLOT(reject()));
|
|
|
|
connect(&buttonBox, SIGNAL(accepted()), &popup, SLOT(accept()));
|
|
|
|
|
|
|
|
if (popup.exec() == QDialog::Accepted) {
|
|
|
|
resize(widthSpinBox->value(), heightSpinBox->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_action_RegionMap_Undo_triggered() {
|
2019-01-14 00:27:28 +00:00
|
|
|
undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::undo() {
|
2019-01-09 02:03:54 +00:00
|
|
|
RegionMapHistoryItem *commit = history.current();
|
|
|
|
if (!commit) return;
|
|
|
|
|
|
|
|
uint8_t tile = static_cast<uint8_t>(commit->prev);
|
|
|
|
|
|
|
|
history.back();
|
|
|
|
|
|
|
|
switch (commit->which)
|
|
|
|
{
|
|
|
|
case RegionMapEditorBox::BackgroundImage:
|
|
|
|
history.back();// TODO: why do I need to do this?
|
|
|
|
this->region_map->map_squares[commit->index].tile_img_id = tile;
|
|
|
|
this->region_map_item->draw();
|
|
|
|
break;
|
|
|
|
case RegionMapEditorBox::CityMapImage:
|
|
|
|
this->city_map_item->data[commit->index] = tile;
|
|
|
|
this->city_map_item->draw();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::on_action_RegionMap_Redo_triggered() {
|
2019-01-14 00:27:28 +00:00
|
|
|
redo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegionMapEditor::redo() {
|
2019-01-09 02:03:54 +00:00
|
|
|
RegionMapHistoryItem *commit = history.next();
|
|
|
|
if (!commit) return;
|
|
|
|
|
|
|
|
uint8_t tile = static_cast<uint8_t>(commit->tile);
|
|
|
|
|
|
|
|
switch (commit->which)
|
|
|
|
{
|
|
|
|
case RegionMapEditorBox::BackgroundImage:
|
|
|
|
history.next();// TODO: why do I need to do this?
|
|
|
|
this->region_map->map_squares[commit->index].tile_img_id = tile;
|
|
|
|
this->region_map_item->draw();
|
|
|
|
break;
|
|
|
|
case RegionMapEditorBox::CityMapImage:
|
|
|
|
this->city_map_item->data[commit->index] = tile;
|
|
|
|
this->city_map_item->draw();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 00:27:28 +00:00
|
|
|
void RegionMapEditor::resize(int w, int h) {
|
|
|
|
this->region_map->resize(w, h);
|
|
|
|
this->currIndex = 2 * w + 1;
|
|
|
|
displayRegionMap();
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:46:27 +00:00
|
|
|
void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) {
|
|
|
|
this->displayCityMap(file);
|
|
|
|
}
|
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_In_Image_Tiles_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (scaleRegionMapTiles >= 8.0) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
scaleRegionMapTiles *= 2.0;
|
|
|
|
this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2,
|
|
|
|
this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2);
|
|
|
|
this->ui->graphicsView_RegionMap_Tiles->scale(2.0, 2.0);
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_Out_Image_Tiles_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (scaleRegionMapTiles <= 1.0) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
scaleRegionMapTiles /= 2.0;
|
|
|
|
this->ui->graphicsView_RegionMap_Tiles->setFixedSize(this->mapsquare_selector_item->pixelWidth * scaleRegionMapTiles + 2,
|
|
|
|
this->mapsquare_selector_item->pixelHeight * scaleRegionMapTiles + 2);
|
|
|
|
this->ui->graphicsView_RegionMap_Tiles->scale(0.5, 0.5);
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_In_City_Tiles_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (scaleCityMapTiles >= 8.0) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
scaleCityMapTiles *= 2.0;
|
|
|
|
this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2,
|
|
|
|
this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2);
|
|
|
|
this->ui->graphicsView_City_Map_Tiles->scale(2.0,2.0);
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_Out_City_Tiles_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (scaleCityMapTiles <= 1.0) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
scaleCityMapTiles /= 2.0;
|
|
|
|
this->ui->graphicsView_City_Map_Tiles->setFixedSize(this->city_map_selector_item->pixelWidth * scaleCityMapTiles + 2,
|
|
|
|
this->city_map_selector_item->pixelHeight * scaleCityMapTiles + 2);
|
|
|
|
this->ui->graphicsView_City_Map_Tiles->scale(0.5,0.5);
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_In_City_Map_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (scaleCityMapImage >= 8.0) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
scaleCityMapImage *= 2.0;
|
2019-01-15 22:06:18 +00:00
|
|
|
this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2,
|
|
|
|
8 * city_map_item->height() * scaleCityMapImage + 2);
|
2019-01-09 02:03:54 +00:00
|
|
|
this->ui->graphicsView_City_Map->scale(2.0,2.0);
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_Out_City_Map_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (scaleCityMapImage <= 1.0) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
scaleCityMapImage /= 2.0;
|
2019-01-15 22:06:18 +00:00
|
|
|
this->ui->graphicsView_City_Map->setFixedSize(8 * city_map_item->width() * scaleCityMapImage + 2,
|
|
|
|
8 * city_map_item->height() * scaleCityMapImage + 2);
|
2019-01-09 02:03:54 +00:00
|
|
|
this->ui->graphicsView_City_Map->scale(0.5,0.5);
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_In_Map_Image_clicked() {
|
2019-01-14 00:27:28 +00:00
|
|
|
if (scaleRegionMapImage >= 8.0) return;
|
2019-01-09 02:03:54 +00:00
|
|
|
scaleRegionMapImage *= 2.0;
|
|
|
|
this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage);
|
|
|
|
this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage);
|
|
|
|
this->ui->graphicsView_Region_Map_BkgImg->scale(2.0,2.0);
|
|
|
|
this->ui->graphicsView_Region_Map_Layout->scale(2.0,2.0);
|
|
|
|
}
|
2019-01-07 19:46:27 +00:00
|
|
|
|
2019-01-09 02:03:54 +00:00
|
|
|
void RegionMapEditor::on_pushButton_Zoom_Out_Map_Image_clicked() {
|
|
|
|
if (scaleRegionMapImage <= 1.0) return;
|
|
|
|
scaleRegionMapImage /= 2.0;
|
|
|
|
this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage);
|
|
|
|
this->ui->graphicsView_Region_Map_Layout->setFixedSize(this->region_map->imgSize() * scaleRegionMapImage);
|
|
|
|
this->ui->graphicsView_Region_Map_BkgImg->scale(0.5,0.5);
|
|
|
|
this->ui->graphicsView_Region_Map_Layout->scale(0.5,0.5);
|
|
|
|
}
|
2019-01-15 22:06:18 +00:00
|
|
|
|
|
|
|
void RegionMapEditor::on_action_RegionMap_Generate_triggered() {
|
|
|
|
//
|
|
|
|
RegionMapGenerator generator(this->project);
|
|
|
|
generator.generate("LittlerootTown");
|
|
|
|
}
|