new map popup window
This commit is contained in:
parent
25bc9e44ce
commit
6b18ec3abb
9 changed files with 429 additions and 7 deletions
|
@ -2205,6 +2205,7 @@
|
|||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="action_Open_Project"/>
|
||||
<addaction name="action_NewMap"/>
|
||||
<addaction name="action_Save"/>
|
||||
<addaction name="action_Save_Project"/>
|
||||
<addaction name="separator"/>
|
||||
|
@ -2422,6 +2423,12 @@
|
|||
</property>
|
||||
<property name="text">
|
||||
<string>Sort by &Layout</string>
|
||||
<action name="action_NewMap">
|
||||
<property name="text">
|
||||
<string>New Map</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
|
201
forms/newmappopup.ui
Normal file
201
forms/newmappopup.ui
Normal file
|
@ -0,0 +1,201 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NewMapPopup</class>
|
||||
<widget class="QMainWindow" name="NewMapPopup">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>410</width>
|
||||
<height>451</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QFrame" name="frame_NewMap_Options">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<property name="verticalSpacing">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Group">
|
||||
<property name="text">
|
||||
<string>Group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBox_NewMap_Group">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>The default background music for this map.</p></body></html></string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Width">
|
||||
<property name="text">
|
||||
<string>Width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_NewMap_Width"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Height">
|
||||
<property name="text">
|
||||
<string>Height</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="spinBox_NewMap_Height"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Primary_Tileset">
|
||||
<property name="text">
|
||||
<string>Primary Tileset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="NoScrollComboBox" name="comboBox_NewMap_Primary_Tileset">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>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.</p></body></html></string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Secondary_Tileset">
|
||||
<property name="text">
|
||||
<string>Secondary Tileset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="NoScrollComboBox" name="comboBox_NewMap_Secondary_Tileset">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>The default weather for this map.</p></body></html></string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="comboBox_NewMap_Type">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>The map type is a general attribute, which is used for many different things. For example. it determines whether biking or running is allowed.</p></body></html></string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Location">
|
||||
<property name="text">
|
||||
<string>Location</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QComboBox" name="comboBox_NewMap_Location">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Determines the type of battle scene graphics to use.</p></body></html></string>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_NewMap_Flyable">
|
||||
<property name="text">
|
||||
<string>Can Fly To</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QCheckBox" name="checkBox_NewMap_Flyable">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_NewMap_Name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton_NewMap_Accept">
|
||||
<property name="text">
|
||||
<string>Accept</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>410</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>NoScrollComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>noscrollcombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -15,6 +15,7 @@
|
|||
#include "editor.h"
|
||||
#include "tileseteditor.h"
|
||||
#include "filterchildrenproxymodel.h"
|
||||
#include "newmappopup.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -46,7 +47,10 @@ private slots:
|
|||
void onMapChanged(Map *map);
|
||||
void onMapNeedsRedrawing();
|
||||
void onTilesetsSaved(QString, QString);
|
||||
void openNewMapPopupWindow(int);
|
||||
void onNewMapCreated();
|
||||
|
||||
void on_action_NewMap_triggered();
|
||||
void on_action_Save_triggered();
|
||||
void on_tabWidget_2_currentChanged(int index);
|
||||
void on_action_Exit_triggered();
|
||||
|
@ -140,6 +144,7 @@ private:
|
|||
Ui::MainWindow *ui;
|
||||
TilesetEditor *tilesetEditor = nullptr;
|
||||
FilterChildrenProxyModel *mapListProxyModel;
|
||||
NewMapPopup *newmapprompt = nullptr;
|
||||
QStandardItemModel *mapListModel;
|
||||
QList<QStandardItem*> *mapGroupItemsList;
|
||||
QMap<QString, QModelIndex> mapListIndexes;
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
|
||||
void readMapGroups();
|
||||
Map* addNewMapToGroup(QString mapName, int groupNum);
|
||||
Map* addNewMapToGroup(QString, int, Map*);
|
||||
QString getNewMapName();
|
||||
QString getProjectTitle();
|
||||
|
||||
|
|
37
include/ui/newmappopup.h
Normal file
37
include/ui/newmappopup.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef NEWMAPPOPUP_H
|
||||
#define NEWMAPPOPUP_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QString>
|
||||
#include "editor.h"
|
||||
#include "project.h"
|
||||
#include "map.h"
|
||||
|
||||
namespace Ui {
|
||||
class NewMapPopup;
|
||||
}
|
||||
|
||||
class NewMapPopup : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NewMapPopup(QWidget *parent = nullptr, Project *project = nullptr);
|
||||
~NewMapPopup();
|
||||
Map *map;
|
||||
int group;
|
||||
void init(int);
|
||||
|
||||
signals:
|
||||
void applied();
|
||||
|
||||
private:
|
||||
Ui::NewMapPopup *ui;
|
||||
Project *project;
|
||||
void setDefaultValues(int);
|
||||
|
||||
private slots:
|
||||
void on_pushButton_NewMap_Accept_clicked();
|
||||
void on_lineEdit_NewMap_Name_textChanged(const QString &);
|
||||
};
|
||||
|
||||
#endif // NEWMAPPOPUP_H
|
|
@ -46,6 +46,7 @@ SOURCES += src/core/block.cpp \
|
|||
src/ui/tileseteditor.cpp \
|
||||
src/ui/tileseteditormetatileselector.cpp \
|
||||
src/ui/tileseteditortileselector.cpp \
|
||||
src/ui/newmappopup.cpp \
|
||||
src/editor.cpp \
|
||||
src/main.cpp \
|
||||
src/mainwindow.cpp \
|
||||
|
@ -86,6 +87,7 @@ HEADERS += include/core/block.h \
|
|||
include/ui/tileseteditor.h \
|
||||
include/ui/tileseteditormetatileselector.h \
|
||||
include/ui/tileseteditortileselector.h \
|
||||
include/ui/newmappopup.h \
|
||||
include/editor.h \
|
||||
include/mainwindow.h \
|
||||
include/project.h \
|
||||
|
@ -94,7 +96,8 @@ HEADERS += include/core/block.h \
|
|||
FORMS += forms/mainwindow.ui \
|
||||
forms/eventpropertiesframe.ui \
|
||||
forms/tileseteditor.ui \
|
||||
forms/paletteeditor.ui
|
||||
forms/paletteeditor.ui \
|
||||
forms/newmappopup.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources/images.qrc
|
||||
|
|
|
@ -170,7 +170,7 @@ void MainWindow::loadUserSettings() {
|
|||
|
||||
void MainWindow::restoreWindowState() {
|
||||
QSettings settings;
|
||||
|
||||
|
||||
if (settings.contains("saved_widget_geometry")) {
|
||||
this->restoreGeometry(settings.value("window_geometry").toByteArray());
|
||||
this->restoreState(settings.value("window_state").toByteArray());
|
||||
|
@ -666,19 +666,47 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
|||
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
|
||||
{
|
||||
int groupNum = triggeredAction->data().toInt();
|
||||
QStandardItem* groupItem = mapGroupItemsList->at(groupNum);
|
||||
openNewMapPopupWindow(groupNum);
|
||||
}
|
||||
|
||||
void MainWindow::onNewMapCreated() {
|
||||
QString newMapName = this->newmapprompt->map->name;
|
||||
int newMapGroup = this->newmapprompt->group;
|
||||
Map *newMap_ = this->newmapprompt->map;
|
||||
Map *newMap = editor->project->addNewMapToGroup(newMapName, newMapGroup, newMap_);
|
||||
|
||||
qDebug() << "Created a new map named" << newMapName;
|
||||
|
||||
QString newMapName = editor->project->getNewMapName();
|
||||
Map* newMap = editor->project->addNewMapToGroup(newMapName, groupNum);
|
||||
editor->project->saveMap(newMap);
|
||||
editor->project->saveAllDataStructures();
|
||||
|
||||
QStandardItem* groupItem = mapGroupsModel->at(newMapGroup);
|
||||
int numMapsInGroup = groupItem->rowCount();
|
||||
QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);
|
||||
|
||||
QStandardItem *newMapItem = createMapItem(newMapName, newMapGroup, numMapsInGroup);
|
||||
groupItem->appendRow(newMapItem);
|
||||
mapListIndexes.insert(newMapName, newMapItem->index());
|
||||
|
||||
setMap(newMapName);
|
||||
setMap(newMapName, true);
|
||||
|
||||
disconnect(this->newmapprompt, SIGNAL(applied()), this, SLOT(onNewMapCreated()));
|
||||
}
|
||||
|
||||
void MainWindow::openNewMapPopupWindow(int groupNum) {
|
||||
if (!this->newmapprompt) {
|
||||
this->newmapprompt = new NewMapPopup(this, this->editor->project);
|
||||
}
|
||||
if (!this->newmapprompt->isVisible()) {
|
||||
this->newmapprompt->show();
|
||||
} else {
|
||||
this->newmapprompt->activateWindow();
|
||||
}
|
||||
this->newmapprompt->init(groupNum);
|
||||
connect(this->newmapprompt, SIGNAL(applied()), this, SLOT(onNewMapCreated()));
|
||||
}
|
||||
|
||||
void MainWindow::on_action_NewMap_triggered() {
|
||||
openNewMapPopupWindow(0);
|
||||
}
|
||||
|
||||
void MainWindow::onTilesetChanged(QString mapName)
|
||||
|
|
|
@ -1181,6 +1181,43 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
|||
return map;
|
||||
}
|
||||
|
||||
Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap) {
|
||||
mapNames->append(mapName);
|
||||
map_groups->insert(mapName, groupNum);
|
||||
groupedMapNames[groupNum].append(mapName);
|
||||
|
||||
Map *map = new Map;
|
||||
map = newMap;
|
||||
|
||||
map->isPersistedToFile = false;
|
||||
map->setName(mapName);
|
||||
mapConstantsToMapNames->insert(map->constantName, map->name);
|
||||
mapNamesToMapConstants->insert(map->name, map->constantName);
|
||||
map->layout_label = QString("%1_Layout").arg(map->name);
|
||||
map->events_label = QString("%1_MapEvents").arg(map->name);;
|
||||
map->scripts_label = QString("%1_MapScripts").arg(map->name);;
|
||||
map->connections_label = "0x0";
|
||||
map->song = "MUS_DAN02";
|
||||
map->layout_id = QString("%1").arg(mapLayoutsTable.size() + 1);
|
||||
map->requiresFlash = "FALSE";
|
||||
map->weather = "WEATHER_SUNNY";
|
||||
map->unknown = "0";
|
||||
map->show_location = "TRUE";
|
||||
map->battle_scene = "MAP_BATTLE_SCENE_NORMAL";
|
||||
mapLayouts.insert(map->layout->label, map->layout);
|
||||
mapLayoutsTable.append(map->layout->label);
|
||||
loadMapTilesets(map);
|
||||
setNewMapBlockdata(map);
|
||||
setNewMapBorder(map);
|
||||
//setNewMapEvents(map);
|
||||
setNewMapConnections(map);
|
||||
map->commit();
|
||||
map->metatileHistory.save();
|
||||
map_cache->insert(mapName, map);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
QString Project::getNewMapName() {
|
||||
// Ensure default name doesn't already exist.
|
||||
int i = 0;
|
||||
|
|
103
src/ui/newmappopup.cpp
Normal file
103
src/ui/newmappopup.cpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include "newmappopup.h"
|
||||
#include "event.h"
|
||||
#include "maplayout.h"
|
||||
#include "mainwindow.h"
|
||||
#include "ui_newmappopup.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QPalette>
|
||||
#include <QStringList>
|
||||
|
||||
NewMapPopup::NewMapPopup(QWidget *parent, Project *project) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::NewMapPopup)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->project = project;
|
||||
}
|
||||
|
||||
NewMapPopup::~NewMapPopup()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void NewMapPopup::init(int group) {
|
||||
setDefaultValues(group);
|
||||
}
|
||||
|
||||
void NewMapPopup::setDefaultValues(int groupNum) {
|
||||
ui->lineEdit_NewMap_Name->setText(project->getNewMapName());
|
||||
|
||||
QMap<QString, QStringList> tilesets = project->getTilesets();
|
||||
ui->comboBox_NewMap_Primary_Tileset->addItems(tilesets.value("primary"));
|
||||
ui->comboBox_NewMap_Secondary_Tileset->addItems(tilesets.value("secondary"));
|
||||
|
||||
ui->comboBox_NewMap_Group->addItems(*project->groupNames);
|
||||
ui->comboBox_NewMap_Group->setCurrentText("gMapGroup" + QString::number(groupNum));
|
||||
|
||||
ui->spinBox_NewMap_Width->setValue(20);
|
||||
ui->spinBox_NewMap_Height->setValue(20);
|
||||
|
||||
ui->comboBox_NewMap_Type->addItems(*project->mapTypes);
|
||||
ui->comboBox_NewMap_Location->addItems(*project->regionMapSections);
|
||||
|
||||
ui->frame_NewMap_Options->setEnabled(true);
|
||||
}
|
||||
|
||||
void NewMapPopup::on_lineEdit_NewMap_Name_textChanged(const QString &text) {
|
||||
if (project->mapNames->contains(text)) {
|
||||
QPalette palette = this->ui->lineEdit_NewMap_Name->palette();
|
||||
QColor color = Qt::red;
|
||||
color.setAlpha(25);
|
||||
palette.setColor(QPalette::Base, color);
|
||||
this->ui->lineEdit_NewMap_Name->setPalette(palette);
|
||||
} else {
|
||||
this->ui->lineEdit_NewMap_Name->setPalette(QPalette());
|
||||
}
|
||||
}
|
||||
|
||||
void NewMapPopup::on_pushButton_NewMap_Accept_clicked() {
|
||||
Map *newMap = new Map;
|
||||
MapLayout *layout = new MapLayout;
|
||||
|
||||
// If map name is not unique, use default value. Also replace spaces with underscores.
|
||||
QString newMapName = this->ui->lineEdit_NewMap_Name->text().replace(" ","_");
|
||||
if (project->mapNames->contains(newMapName)) {
|
||||
newMapName = project->getNewMapName();
|
||||
}
|
||||
newMap->name = newMapName;
|
||||
|
||||
newMap->type = this->ui->comboBox_NewMap_Type->currentText();
|
||||
newMap->location = this->ui->comboBox_NewMap_Location->currentText();
|
||||
|
||||
layout->width = QString::number(this->ui->spinBox_NewMap_Width->value());
|
||||
layout->height = QString::number(this->ui->spinBox_NewMap_Height->value());
|
||||
layout->tileset_primary_label = this->ui->comboBox_NewMap_Primary_Tileset->currentText();
|
||||
layout->tileset_secondary_label = this->ui->comboBox_NewMap_Secondary_Tileset->currentText();
|
||||
layout->label = QString("%1_Layout").arg(newMap->name);
|
||||
layout->name = MapLayout::getNameFromLabel(layout->label);
|
||||
layout->border_label = QString("%1_MapBorder").arg(newMap->name);
|
||||
layout->border_path = QString("data/layouts/%1/border.bin").arg(newMap->name);
|
||||
layout->blockdata_label = QString("%1_MapBlockdata").arg(newMap->name);
|
||||
layout->blockdata_path = QString("data/layouts/%1/map.bin").arg(newMap->name);
|
||||
|
||||
// EMERGENCY (MUST FIX):causes a segfault...
|
||||
// how do I add new event to newMap without behavior being undefined???
|
||||
if (this->ui->checkBox_NewMap_Flyable->isChecked()) {
|
||||
Event *healSpot = new Event;
|
||||
healSpot = Event::createNewEvent("event_heal_location", newMapName);
|
||||
healSpot->put("map_name", newMapName);
|
||||
newMap->addEvent(healSpot);
|
||||
}
|
||||
|
||||
newMap->layout = layout;
|
||||
newMap->layout_label = layout->label;
|
||||
|
||||
map = newMap;
|
||||
group = this->ui->comboBox_NewMap_Group->currentText().remove("gMapGroup").toInt();
|
||||
|
||||
emit applied();
|
||||
|
||||
this->close();
|
||||
}
|
Loading…
Reference in a new issue