add entries editing tab to rme

This commit is contained in:
garak 2019-04-12 21:25:43 -04:00 committed by huderlem
parent d094dced1f
commit 875320ae26
8 changed files with 779 additions and 201 deletions

View file

@ -15,6 +15,188 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QSlider" name="verticalSlider_Zoom_Image_Tiles">
<property name="minimumSize">
<size>
<width>30</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSlider" name="verticalSlider_Zoom_City_Tiles">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QSlider" name="verticalSlider_Zoom_Map_Image">
<property name="minimumSize">
<size>
<width>30</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSlider" name="verticalSlider_Zoom_City_Map">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QSplitter" name="splitter_3">
<property name="orientation">
@ -282,6 +464,127 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_RM_Entries">
<attribute name="title">
<string>Map Entries</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_RM_Entries">
<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_10">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>225</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_24">
<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_Region_Map_Entries">
<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_RME_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_RME_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_RME_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_RME_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 class="QStackedWidget" name="stackedWidget_RM_Options">
<property name="minimumSize">
@ -542,6 +845,167 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_RM_Entries">
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QFrame" name="frame_RM_Entries">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout_23">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_RM_Entry_MapSection">
<property name="text">
<string>Map Section</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_RM_Entry_MapSection">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The section of the region map which the map is grouped under. This also determines the name of the map that is display when the player enters it.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_RM_MapName_2">
<property name="text">
<string>Location</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_RM_CityMap_2">
<property name="text">
<string>Dimensions</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>x</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_RM_Entry_x"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_RM_Entry_y"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>y</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="1">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_RM_Entry_width"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_RM_Entry_height"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>height</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QSplitter" name="splitter_2">
@ -861,188 +1325,6 @@
</widget>
</widget>
</item>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QSlider" name="verticalSlider_Zoom_Map_Image">
<property name="minimumSize">
<size>
<width>30</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSlider" name="verticalSlider_Zoom_City_Map">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QSlider" name="verticalSlider_Zoom_Image_Tiles">
<property name="minimumSize">
<size>
<width>30</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSlider" name="verticalSlider_Zoom_City_Tiles">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>160</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">

View file

@ -15,13 +15,19 @@
#include <QGraphicsScene>
#include <QGraphicsView>
struct RegionMapEntry
class RegionMapEntry
{
public:
int x;
int y;
int width;
int height;
QString name;
void setX(int);
void setY(int);
void setWidth(int);
void setHeight(int);
};
class RegionMapSquare
@ -53,6 +59,10 @@ public:
QVector<RegionMapSquare> map_squares;
History<RegionMapHistoryItem*> history;
QMap<QString, QString> sMapNamesMap;
QMap<QString, RegionMapEntry> mapSecToMapEntry;
QVector<QString> sMapNames;
const int padLeft = 1;
const int padRight = 3;
const int padTop = 2;
@ -100,10 +110,6 @@ private:
QString region_map_layout_bin_path;
QString city_map_tiles_path;
QMap<QString, QString> sMapNamesMap;
QMap<QString, struct RegionMapEntry> mapSecToMapEntry;
QVector<QString> sMapNames;
int img_index_(int x, int y);
int layout_index_(int x, int y);

View file

@ -4,6 +4,7 @@
#include "regionmappixmapitem.h"
#include "citymappixmapitem.h"
#include "regionmaplayoutpixmapitem.h"
#include "regionmapentriespixmapitem.h"
#include "regionmap.h"
#include "history.h"
#include "historyitem.h"
@ -40,6 +41,8 @@ public:
void onRegionMapLayoutHoveredTileChanged(int index);
void onRegionMapLayoutHoveredTileCleared();
void onRegionMapEntriesSelectedTileChanged(QString) {};
void undo();
void redo();
@ -54,23 +57,27 @@ private:
int currIndex;
unsigned selectedCityTile;
unsigned selectedImageTile;
QString activeEntry;
bool hasUnsavedChanges = false;
bool cityMapFirstDraw = true;
bool regionMapFirstDraw = true;
bool entriesFirstDraw = true;
double scaleUpFactor = 2.0;
double initialScale = 30.0;
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;
QGraphicsScene *scene_region_map_image = nullptr;
QGraphicsScene *scene_city_map_image = nullptr;
QGraphicsScene *scene_region_map_layout = nullptr;
QGraphicsScene *scene_region_map_entries = nullptr;
QGraphicsScene *scene_region_map_tiles = nullptr;
QGraphicsScene *scene_city_map_tiles = nullptr;
TilemapTileSelector *mapsquare_selector_item = nullptr;
TilemapTileSelector *city_map_selector_item = nullptr;
RegionMapEntriesPixmapItem *region_map_entries_item = nullptr;
RegionMapLayoutPixmapItem *region_map_layout_item = nullptr;
RegionMapPixmapItem *region_map_item = nullptr;
CityMapPixmapItem *city_map_item = nullptr;
@ -78,12 +85,16 @@ private:
void displayRegionMap();
void displayRegionMapImage();
void displayRegionMapLayout();
void displayRegionMapEntriesImage();
void displayRegionMapLayoutOptions();
void updateRegionMapLayoutOptions(int index);
void displayRegionMapTileSelector();
void displayCityMapTileSelector();
void displayCityMap(QString name);
void importTileImage(bool city = false);//QString path);// what is this path tho?
void displayRegionMapEntryOptions();
void uodateRegionMapEntryOptions(int);//
void updateRegionMapEntryOptions(QString);//
void importTileImage(bool city = false);
bool createCityMap(QString name);
@ -101,14 +112,19 @@ private slots:
void on_action_Import_CityMap_ImageTiles_triggered();
void on_tabWidget_Region_Map_currentChanged(int);
void on_pushButton_RM_Options_delete_clicked();
void on_comboBox_RM_ConnectedMap_activated(const QString &text);
void on_comboBox_RM_ConnectedMap_activated(const QString &);
void on_comboBox_RM_Entry_MapSection_activated(const QString &);
void on_spinBox_RM_Entry_x_valueChanged(int);
void on_spinBox_RM_Entry_y_valueChanged(int);
void on_spinBox_RM_Entry_width_valueChanged(int);
void on_spinBox_RM_Entry_height_valueChanged(int);
void on_pushButton_CityMap_add_clicked();
void on_verticalSlider_Zoom_Map_Image_valueChanged(int);
void on_verticalSlider_Zoom_Image_Tiles_valueChanged(int);
void on_verticalSlider_Zoom_City_Map_valueChanged(int);
void on_verticalSlider_Zoom_City_Tiles_valueChanged(int);
void on_comboBox_CityMap_picker_currentTextChanged(const QString &text);
void on_lineEdit_RM_MapName_textEdited(const QString &text);
void on_comboBox_CityMap_picker_currentTextChanged(const QString &);
void on_lineEdit_RM_MapName_textEdited(const QString &);
void onHoveredRegionMapTileChanged(int x, int y);
void onHoveredRegionMapTileCleared();
void mouseEvent_region_map(QGraphicsSceneMouseEvent *event, RegionMapPixmapItem *item);

View file

@ -0,0 +1,41 @@
#ifndef REGIONMAPENTRIESPIXMAPITEM_H
#define REGIONMAPENTRIESPIXMAPITEM_H
#include "tilemaptileselector.h"
#include "regionmap.h"
class RegionMapEntriesPixmapItem : public SelectablePixmapItem {
Q_OBJECT
public:
RegionMapEntriesPixmapItem(RegionMap *rm, TilemapTileSelector *ts) : SelectablePixmapItem(8, 8, 1, 1) {
this->region_map = rm;
this->tile_selector = ts;
}
RegionMap *region_map;
TilemapTileSelector *tile_selector;
QString currentSection = QString();
int selectedTile;
int highlightedTile;
void draw();
void select(int, int);
void select(int);
void highlight(int, int, int);
private:
void updateSelectedTile();
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, RegionMapEntriesPixmapItem *);
void hoveredTileChanged(int);
void hoveredTileCleared();
void selectedTileChanged(QString);
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
};
#endif // REGIONMAPENTRIESPIXMAPITEM_H

View file

@ -35,6 +35,7 @@ SOURCES += src/core/block.cpp \
src/ui/connectionpixmapitem.cpp \
src/ui/currentselectedmetatilespixmapitem.cpp \
src/ui/regionmaplayoutpixmapitem.cpp \
src/ui/regionmapentriespixmapitem.cpp \
src/ui/cursortilerect.cpp \
src/ui/customattributestable.cpp \
src/ui/eventpropertiesframe.cpp \
@ -92,6 +93,7 @@ HEADERS += include/core/block.h \
include/ui/connectionpixmapitem.h \
include/ui/currentselectedmetatilespixmapitem.h \
include/ui/regionmaplayoutpixmapitem.h \
include/ui/regionmapentriespixmapitem.h \
include/ui/cursortilerect.h \
include/ui/customattributestable.h \
include/ui/eventpropertiesframe.h \

View file

@ -165,7 +165,7 @@ void RegionMap::saveLayout() {
for (auto sec : project->mapSectionNameToValue.keys()) {
if (!mapSecToMapEntry.contains(sec)) continue;
struct RegionMapEntry entry = mapSecToMapEntry.value(sec);
RegionMapEntry entry = mapSecToMapEntry.value(sec);
entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
+ QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
}
@ -205,7 +205,7 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
sMapNamesMap.insert(sName, name);
if (!mapSecToMapEntry.keys().contains(sec)) {
sMapNames.append(sName);
struct RegionMapEntry entry = {x, y, 1, 1, sName};
RegionMapEntry entry = {x, y, 1, 1, sName};
mapSecToMapEntry.insert(sec, entry);
}
}
@ -359,3 +359,19 @@ QString RegionMap::fix_case(QString caps) {
}
return camel;
}
void RegionMapEntry::setX(const int val) {
this->x = val;
}
void RegionMapEntry::setY(int val) {
this->y = val;
}
void RegionMapEntry::setWidth(int val) {
this->width = val;
}
void RegionMapEntry::setHeight(int val) {
this->height = val;
}

View file

@ -46,9 +46,6 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() {
if (project && region_map) {
this->region_map->save();
this->city_map_item->save();
this->currIndex = this->region_map_layout_item->highlightedTile;
this->region_map_layout_item->highlightedTile = -1;
displayRegionMap();
}
this->hasUnsavedChanges = false;
}
@ -87,6 +84,8 @@ void RegionMapEditor::displayRegionMap() {
displayRegionMapImage();
displayRegionMapLayout();
displayRegionMapLayoutOptions();
displayRegionMapEntriesImage();
displayRegionMapEntryOptions();
}
void RegionMapEditor::displayRegionMapImage() {
@ -171,6 +170,60 @@ void RegionMapEditor::updateRegionMapLayoutOptions(int index) {
this->ui->comboBox_RM_ConnectedMap->blockSignals(false);
}
void RegionMapEditor::displayRegionMapEntriesImage() {
if (!scene_region_map_entries) {
this->scene_region_map_entries = new QGraphicsScene;
}
if (region_map_entries_item && scene_region_map_entries) {
this->scene_region_map_entries->removeItem(region_map_entries_item);
delete region_map_entries_item;
}
this->region_map_entries_item = new RegionMapEntriesPixmapItem(this->region_map, this->mapsquare_selector_item);
if (entriesFirstDraw) {
QString first = this->project->mapSectionValueToName.first();
this->region_map_entries_item->currentSection = first;
this->activeEntry = first;
updateRegionMapEntryOptions(first);
entriesFirstDraw = false;
}
this->region_map_entries_item->draw();
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
this->region_map_entries_item->select(idx);
this->scene_region_map_entries->addItem(region_map_entries_item);
this->scene_region_map_entries->setSceneRect(this->scene_region_map_entries->itemsBoundingRect());
this->ui->graphicsView_Region_Map_Entries->setScene(this->scene_region_map_entries);
}
void RegionMapEditor::displayRegionMapEntryOptions() {
this->ui->comboBox_RM_Entry_MapSection->addItems(this->project->mapSectionValueToName.values());
int width = this->region_map->width() - this->region_map->padLeft - this->region_map->padRight;
int height = this->region_map->height() - this->region_map->padTop - this->region_map->padBottom;
this->ui->spinBox_RM_Entry_x->setMaximum(width - 1);
this->ui->spinBox_RM_Entry_y->setMaximum(height - 1);
this->ui->spinBox_RM_Entry_width->setMinimum(1);
this->ui->spinBox_RM_Entry_height->setMinimum(1);
this->ui->spinBox_RM_Entry_width->setMaximum(width);
this->ui->spinBox_RM_Entry_height->setMaximum(height);
}
void RegionMapEditor::updateRegionMapEntryOptions(QString section) {
this->ui->comboBox_RM_Entry_MapSection->setCurrentText(section);
this->activeEntry = section;
this->region_map_entries_item->currentSection = section;
RegionMapEntry entry = this->region_map->mapSecToMapEntry.value(section);
this->ui->spinBox_RM_Entry_x->setValue(entry.x);
this->ui->spinBox_RM_Entry_y->setValue(entry.y);
this->ui->spinBox_RM_Entry_width->setValue(entry.width);
this->ui->spinBox_RM_Entry_height->setValue(entry.height);
}
void RegionMapEditor::displayRegionMapTileSelector() {
if (!scene_region_map_tiles) {
this->scene_region_map_tiles = new QGraphicsScene;
@ -402,9 +455,15 @@ void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
{
case 0:
this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(true);
this->region_map_item->draw();
break;
case 1:
this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(false);
this->region_map_layout_item->draw();
break;
case 2:
this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(false);
this->region_map_entries_item->draw();
break;
}
}
@ -414,6 +473,47 @@ void RegionMapEditor::on_comboBox_RM_ConnectedMap_activated(const QString &mapse
this->hasUnsavedChanges = true;// sometimes this is called for unknown reasons
}
void RegionMapEditor::on_comboBox_RM_Entry_MapSection_activated(const QString &text) {
this->activeEntry = text;
this->region_map_entries_item->currentSection = activeEntry;
updateRegionMapEntryOptions(activeEntry);
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
this->region_map_entries_item->select(idx);
this->region_map_entries_item->draw();
}
void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
this->region_map->mapSecToMapEntry[activeEntry].setX(x);
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
this->region_map_entries_item->select(idx);
this->region_map_entries_item->draw();
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
this->region_map->mapSecToMapEntry[activeEntry].setY(y);
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
this->region_map_entries_item->select(idx);
this->region_map_entries_item->draw();
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
this->region_map->mapSecToMapEntry[activeEntry].setWidth(width);
this->region_map_entries_item->draw();
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
this->region_map->mapSecToMapEntry[activeEntry].setHeight(height);
this->region_map_entries_item->draw();
this->hasUnsavedChanges = true;
}
void RegionMapEditor::on_lineEdit_RM_MapName_textEdited(const QString &text) {
this->hasUnsavedChanges = true;
}
@ -507,6 +607,7 @@ void RegionMapEditor::undo() {
this->region_map->setTiles(commit->tiles);
this->region_map_item->draw();
this->region_map_layout_item->draw();
this->region_map_entries_item->draw();
break;
case RegionMapEditorBox::CityMapImage:
if (commit->cityMap == this->city_map_item->file)
@ -533,6 +634,7 @@ void RegionMapEditor::redo() {
this->region_map->setTiles(commit->tiles);
this->region_map_item->draw();
this->region_map_layout_item->draw();
this->region_map_entries_item->draw();
break;
case RegionMapEditorBox::CityMapImage:
this->city_map_item->setTiles(commit->tiles);
@ -766,6 +868,9 @@ void RegionMapEditor::on_verticalSlider_Zoom_Map_Image_valueChanged(int val) {
ui->graphicsView_Region_Map_Layout->setResizeAnchor(QGraphicsView::NoAnchor);
ui->graphicsView_Region_Map_Layout->setMatrix(matrix);
ui->graphicsView_Region_Map_Layout->setFixedSize(width + 2, height + 2);
ui->graphicsView_Region_Map_Entries->setResizeAnchor(QGraphicsView::NoAnchor);
ui->graphicsView_Region_Map_Entries->setMatrix(matrix);
ui->graphicsView_Region_Map_Entries->setFixedSize(width + 2, height + 2);
}
void RegionMapEditor::on_verticalSlider_Zoom_Image_Tiles_valueChanged(int val) {

View file

@ -0,0 +1,110 @@
#include "regionmapentriespixmapitem.h"
void RegionMapEntriesPixmapItem::draw() {
if (!region_map) return;
RegionMapEntry entry = region_map->mapSecToMapEntry.value(currentSection);
bool selectingEntry = false;
int entry_x, entry_y, entry_w, entry_h;
if (entry.name.isEmpty() || entry.name == "MAPSEC_NONE") {
entry_x = entry_y = 0;
entry_w = entry_h = 1;
} else {
selectingEntry = true;
entry_x = entry.x, entry_y = entry.y;
entry_w = entry.width, entry_h = entry.height;
}
QImage image(region_map->width() * 8, region_map->height() * 8, QImage::Format_RGBA8888);
QPainter painter(&image);
for (int i = 0; i < region_map->map_squares.size(); i++) {
QImage bottom_img = this->tile_selector->tileImg(region_map->map_squares[i].tile_img_id);
QImage top_img(8, 8, QImage::Format_RGBA8888);
int x = i % region_map->width();
int y = i / region_map->width();
bool insideEntry = false;
if (selectingEntry) {
if (x == entry_x + this->region_map->padLeft && y == entry_y + this->region_map->padTop)
insideEntry = true;
else if (x - this->region_map->padLeft - entry_x < entry_w && x >= entry_x + this->region_map->padLeft
&& y - this->region_map->padTop - entry_y < entry_h && y >= entry_y + this->region_map->padTop)
insideEntry = true;
}
if (insideEntry) {
top_img.fill(QColor(255, 68, 68));
} else if (region_map->map_squares[i].has_map) {
top_img.fill(Qt::gray);
} else {
top_img.fill(Qt::black);
}
QPoint pos = QPoint(x * 8, y * 8);
painter.setOpacity(1);
painter.drawImage(pos, bottom_img);
painter.save();
painter.setOpacity(0.55);
painter.drawImage(pos, top_img);
painter.restore();
}
painter.end();
this->selectionOffsetX = entry_w - 1;
this->selectionOffsetY = entry_h - 1;
this->setPixmap(QPixmap::fromImage(image));
this->drawSelection();
}
void RegionMapEntriesPixmapItem::select(int x, int y) {
int index = this->region_map->getMapSquareIndex(x, y);
SelectablePixmapItem::select(x, y, 0, 0);
this->selectedTile = index;
this->updateSelectedTile();
emit selectedTileChanged(this->region_map->map_squares[index].mapsec);
}
void RegionMapEntriesPixmapItem::select(int index) {
int x = index % this->region_map->width();
int y = index / this->region_map->width();
SelectablePixmapItem::select(x, y, 0, 0);
this->selectedTile = index;
this->updateSelectedTile();
emit selectedTileChanged(this->region_map->map_squares[index].mapsec);
}
void RegionMapEntriesPixmapItem::highlight(int x, int y, int red) {
this->highlightedTile = red;
SelectablePixmapItem::select(x + this->region_map->padLeft, y + this->region_map->padTop, 0, 0);
draw();
}
void RegionMapEntriesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
event->ignore();
}
void RegionMapEntriesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
event->ignore();
}
void RegionMapEntriesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
event->ignore();
}
void RegionMapEntriesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
event->ignore();
}
void RegionMapEntriesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) {
event->ignore();
}
void RegionMapEntriesPixmapItem::updateSelectedTile() {
QPoint origin = this->getSelectionStart();
this->selectedTile = this->region_map->getMapSquareIndex(origin.x(), origin.y());
this->highlightedTile = -1;
draw();
}