city map editor

This commit is contained in:
garak 2019-01-05 17:59:57 -05:00
parent 0f02d7b955
commit 62009373f7
8 changed files with 349 additions and 120 deletions

View file

@ -3091,126 +3091,6 @@
</widget>
</widget>
</widget>
<widget class="QScrollArea" name="scrollArea_City_Map">
<property name="geometry">
<rect>
<x>80</x>
<y>380</y>
<width>261</width>
<height>251</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_City_Map">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>259</width>
<height>249</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="1" column="1">
<widget class="QGraphicsView" name="graphicsView_City_Map">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="dragMode">
<enum>QGraphicsView::NoDrag</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_CM_West">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>166</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_CM_South">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>166</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_CM_East">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>166</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer_CM_North">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>166</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<widget class="QStackedWidget" name="stackedWidget_RM_Options">
<property name="geometry">
<rect>
@ -3485,6 +3365,166 @@
</widget>
</widget>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>40</x>
<y>350</y>
<width>341</width>
<height>281</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>City Map:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_CityMap_picker"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_CityMap_save">
<property name="text">
<string>save</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea_City_Map">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_City_Map">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>337</width>
<height>235</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="1" column="1">
<widget class="QGraphicsView" name="graphicsView_City_Map">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="dragMode">
<enum>QGraphicsView::NoDrag</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_CM_West">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>166</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_CM_South">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>166</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_CM_East">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>166</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer_CM_North">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>166</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</widget>

View file

@ -20,6 +20,7 @@
#include "collisionpixmapitem.h"
#include "mappixmapitem.h"
#include "regionmappixmapitem.h"
#include "citymappixmapitem.h"
#include "regionmaplayoutpixmapitem.h"
#include "regionmapeditor.h"
#include "settings.h"
@ -85,12 +86,14 @@ public:
void loadRegionMapData();
QGraphicsScene *scene_region_map_image = nullptr;
QGraphicsScene *scene_city_map_image = nullptr;
QGraphicsScene *scene_region_map_layout = nullptr;
QGraphicsScene *scene_region_map_tiles = nullptr;
QGraphicsScene *scene_city_map_tiles = nullptr;
TilemapTileSelector *mapsquare_selector_item = nullptr;
TilemapTileSelector *city_map_selector_item = nullptr;
RegionMapPixmapItem *region_map_item = nullptr;
CityMapPixmapItem *city_map_item = nullptr;
RegionMapLayoutPixmapItem *region_map_layout_item = nullptr;
void displayRegionMap();
@ -100,6 +103,8 @@ public:
void updateRegionMapLayoutOptions(int);
void displayRegionMapTileSelector();
void displayCityMapTileSelector();
void displayCityMap(QString);
void loadCityMaps();
void onRegionMapTileSelectorSelectedTileChanged();
void onRegionMapTileSelectorHoveredTileChanged(unsigned);
@ -113,6 +118,7 @@ private slots:
void onHoveredRegionMapTileChanged(int, int);
void onHoveredRegionMapTileCleared();
void mouseEvent_region_map(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *);
void mouseEvent_city_map(QGraphicsSceneMouseEvent *, CityMapPixmapItem *);
public:
QString rmStatusbarMessage;

View file

@ -134,6 +134,9 @@ private slots:
void on_pushButton_clicked();
void on_pushButton_CityMap_save_clicked();
void on_comboBox_CityMap_picker_currentTextChanged(const QString &);
void on_checkBox_smartPaths_stateChanged(int selected);
void on_checkBox_Visibility_clicked(bool checked);

View file

@ -0,0 +1,41 @@
#ifndef CITYMAPPIXMAPITEM_H
#define CITYMAPPIXMAPITEM_H
#include "tilemaptileselector.h"
#include <QGraphicsPixmapItem>
#include <QByteArray>
class CityMapPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
CityMapPixmapItem(QString fname, TilemapTileSelector *tile_selector) {
this->file = fname;
this->tile_selector = tile_selector;
setAcceptHoverEvents(true);
init();
}
TilemapTileSelector *tile_selector;
QString file;
int width;
int height;
QByteArray data;
void init();
void save();
void create(QString);
virtual void paint(QGraphicsSceneMouseEvent*);
virtual void draw();
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, CityMapPixmapItem *);
void hoveredRegionMapTileChanged(int x, int y);
void hoveredRegionMapTileCleared();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
};
#endif // CITYMAPPIXMAPITEM_H

View file

@ -43,6 +43,7 @@ SOURCES += src/core/block.cpp \
src/ui/imageproviders.cpp \
src/ui/mappixmapitem.cpp \
src/ui/regionmappixmapitem.cpp \
src/ui/citymappixmapitem.cpp \
src/ui/mapsceneeventfilter.cpp \
src/ui/metatilelayersitem.cpp \
src/ui/metatileselector.cpp \
@ -97,6 +98,7 @@ HEADERS += include/core/block.h \
include/ui/imageproviders.h \
include/ui/mappixmapitem.h \
include/ui/regionmappixmapitem.h \
include/ui/citymappixmapitem.h \
include/ui/mapsceneeventfilter.h \
include/ui/metatilelayersitem.h \
include/ui/metatileselector.h \

View file

@ -8,6 +8,7 @@
#include <QCheckBox>
#include <QPainter>
#include <QMouseEvent>
#include <QDir>
#include <math.h>
static bool selectingEvent = false;
@ -1295,6 +1296,17 @@ void Editor::deleteEvent(Event *event) {
//updateSelectedObjects();
}
void Editor::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 Editor::loadRegionMapData() {
//
this->region_map->init(project);
@ -1363,6 +1375,46 @@ void Editor::displayRegionMapImage() {
this->ui->graphicsView_Region_Map_BkgImg->setFixedSize(this->region_map->imgSize());
}
/*
if (!scene) {
scene = new QGraphicsScene;
MapSceneEventFilter *filter = new MapSceneEventFilter();
scene->installEventFilter(filter);
connect(filter, &MapSceneEventFilter::wheelZoom, this, &Editor::wheelZoom);
}
if (map_item && scene) {
scene->removeItem(map_item);
delete map_item;
}
*/
void Editor::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();
connect(city_map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*, CityMapPixmapItem*)),
this, SLOT(mouseEvent_city_map(QGraphicsSceneMouseEvent*, CityMapPixmapItem*)));
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);
this->ui->graphicsView_City_Map->setFixedSize(QSize(82,82));
// set fixed size?
}
// TODO: add if (item) and if(scene) checks because called more than once per instance
void Editor::displayRegionMapLayout() {
//
this->region_map_layout_item = new RegionMapLayoutPixmapItem(this->region_map, this->mapsquare_selector_item);
@ -1489,6 +1541,19 @@ void Editor::mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPix
}
}
void Editor::mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item) {
//
if (event->buttons() & Qt::RightButton) {
//
//item->select(event);
} else if (event->buttons() & Qt::MiddleButton) {
// TODO: add functionality here? replace or?
} else {
//
item->paint(event);
}
}
// It doesn't seem to be possible to prevent the mousePress event
// from triggering both event's DraggablePixmapItem and the background mousePress.
// Since the DraggablePixmapItem's event fires first, we can set a temp

View file

@ -264,6 +264,7 @@ bool MainWindow::openProject(QString dir) {
loadDataStructures();
populateMapList();
editor->loadRegionMapData();
editor->loadCityMaps();
success = setMap(getDefaultMap(), true);
} else {
setWindowTitle(editor->project->getProjectTitle());
@ -1999,6 +2000,14 @@ void MainWindow::on_pushButton_RM_Options_save_clicked() {
this->editor->region_map_layout_item->draw();
}
void MainWindow::on_pushButton_CityMap_save_clicked() {
this->editor->city_map_item->save();
}
void MainWindow::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) {
this->editor->displayCityMap(file);
}
void MainWindow::closeEvent(QCloseEvent *event) {
porymapConfig.setGeometry(
this->saveGeometry(),

View file

@ -0,0 +1,63 @@
#include "citymappixmapitem.h"
#include "imageproviders.h"
#include <QFile>
#include <QPainter>
#include <QDebug>
// read to byte array from filename
void CityMapPixmapItem::init() {
// TODO: are they always 10x10 squares?
width = 10;
height = 10;
QFile binFile(file);
if (!binFile.open(QIODevice::ReadOnly)) return;
data = binFile.readAll();
binFile.close();
}
void CityMapPixmapItem::draw() {
QImage image(width * 8, height * 8, QImage::Format_RGBA8888);
QPainter painter(&image);
for (int i = 0; i < data.size() / 2; i++) {
QImage img = this->tile_selector->tileImg(data[i * 2]);// need to skip every other tile
int x = i % width;
int y = i / width;
QPoint pos = QPoint(x * 8, y * 8);
painter.drawImage(pos, img);
}
painter.end();
this->setPixmap(QPixmap::fromImage(image));
}
void CityMapPixmapItem::save() {
//
QFile binFile(file);
if (!binFile.open(QIODevice::WriteOnly)) return;
binFile.write(data);
binFile.close();
}
void CityMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
//
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8;
int y = static_cast<int>(pos.y()) / 8;
int index = 2 * (x + y * width);
data[index] = static_cast<uint8_t>(this->tile_selector->selectedTile);
draw();
}
void CityMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8;
int y = static_cast<int>(pos.y()) / 8;
emit mouseEvent(event, this);
}