Separate layout/header features of new map dialog

This commit is contained in:
GriffinR
2024-11-12 15:57:27 -05:00
parent 7d7db3857d
commit 8bb0100540
19 changed files with 1134 additions and 820 deletions

View File

@@ -70,7 +70,7 @@ public:
this->showTilesetEditorLayerGrid = true;
this->monitorFiles = true;
this->tilesetCheckerboardFill = true;
this->newMapHeaderSectionExpanded = false;
this->newMapHeaderSectionExpanded = true;
this->theme = "default";
this->wildMonChartTheme = "";
this->textEditorOpenFolder = "";

View File

@@ -7,6 +7,7 @@
#include "maplayout.h"
#include "tileset.h"
#include "events.h"
#include "mapheader.h"
#include <QUndoStack>
#include <QPixmap>
@@ -56,30 +57,8 @@ public:
int getBorderWidth() const;
int getBorderHeight() const;
// TODO: Combine these into a separate MapHeader class?
void setSong(const QString &song);
void setLocation(const QString &location);
void setRequiresFlash(bool requiresFlash);
void setWeather(const QString &weather);
void setType(const QString &type);
void setShowsLocationName(bool showsLocationName);
void setAllowsRunning(bool allowsRunning);
void setAllowsBiking(bool allowsBiking);
void setAllowsEscaping(bool allowsEscaping);
void setFloorNumber(int floorNumber);
void setBattleScene(const QString &battleScene);
QString song() const { return m_song; }
QString location() const { return m_location; }
bool requiresFlash() const { return m_requiresFlash; }
QString weather() const { return m_weather; }
QString type() const { return m_type; }
bool showsLocationName() const { return m_showsLocationName; }
bool allowsRunning() const { return m_allowsRunning; }
bool allowsBiking() const { return m_allowsBiking; }
bool allowsEscaping() const { return m_allowsEscaping; }
int floorNumber() const { return m_floorNumber; }
QString battleScene() const { return m_battleScene; }
void setHeader(const MapHeader &header) { *m_header = header; }
MapHeader* header() const { return m_header; }
void setSharedEventsMap(const QString &sharedEventsMap) { m_sharedEventsMap = sharedEventsMap; }
void setSharedScriptsMap(const QString &sharedScriptsMap) { m_sharedScriptsMap = sharedScriptsMap; }
@@ -130,25 +109,13 @@ private:
QString m_name;
QString m_constantName;
QString m_layoutId; // TODO: Why do we do half this->layout()->id and half this->layoutId. Should these ever be different?
QString m_song;
QString m_location;
bool m_requiresFlash;
QString m_weather;
QString m_type;
bool m_showsLocationName;
bool m_allowsRunning;
bool m_allowsBiking;
bool m_allowsEscaping;
int m_floorNumber = 0;
QString m_battleScene;
QString m_sharedEventsMap = "";
QString m_sharedScriptsMap = "";
QStringList m_scriptsFileLabels;
QMap<QString, QJsonValue> m_customAttributes;
MapHeader *m_header = nullptr;
Layout *m_layout = nullptr;
bool m_isPersistedToFile = true;

83
include/core/mapheader.h Normal file
View File

@@ -0,0 +1,83 @@
#ifndef MAPHEADER_H
#define MAPHEADER_H
#include <QObject>
class MapHeader : public QObject
{
Q_OBJECT
public:
MapHeader(QObject *parent = nullptr) : QObject(parent) {};
~MapHeader() {};
MapHeader(const MapHeader& other);
MapHeader& operator=(const MapHeader& other);
bool operator==(const MapHeader& other) const {
return m_song == other.m_song
&& m_location == other.m_location
&& m_requiresFlash == other.m_requiresFlash
&& m_weather == other.m_weather
&& m_type == other.m_type
&& m_showsLocationName == other.m_showsLocationName
&& m_allowsRunning == other.m_allowsRunning
&& m_allowsBiking == other.m_allowsBiking
&& m_allowsEscaping == other.m_allowsEscaping
&& m_floorNumber == other.m_floorNumber
&& m_battleScene == other.m_battleScene;
}
bool operator!=(const MapHeader& other) const {
return !(operator==(other));
}
void setSong(const QString &song);
void setLocation(const QString &location);
void setRequiresFlash(bool requiresFlash);
void setWeather(const QString &weather);
void setType(const QString &type);
void setShowsLocationName(bool showsLocationName);
void setAllowsRunning(bool allowsRunning);
void setAllowsBiking(bool allowsBiking);
void setAllowsEscaping(bool allowsEscaping);
void setFloorNumber(int floorNumber);
void setBattleScene(const QString &battleScene);
QString song() const { return m_song; }
QString location() const { return m_location; }
bool requiresFlash() const { return m_requiresFlash; }
QString weather() const { return m_weather; }
QString type() const { return m_type; }
bool showsLocationName() const { return m_showsLocationName; }
bool allowsRunning() const { return m_allowsRunning; }
bool allowsBiking() const { return m_allowsBiking; }
bool allowsEscaping() const { return m_allowsEscaping; }
int floorNumber() const { return m_floorNumber; }
QString battleScene() const { return m_battleScene; }
signals:
void songChanged(QString, QString);
void locationChanged(QString, QString);
void requiresFlashChanged(bool, bool);
void weatherChanged(QString, QString);
void typeChanged(QString, QString);
void showsLocationNameChanged(bool, bool);
void allowsRunningChanged(bool, bool);
void allowsBikingChanged(bool, bool);
void allowsEscapingChanged(bool, bool);
void floorNumberChanged(int, int);
void battleSceneChanged(QString, QString);
void modified();
private:
QString m_song;
QString m_location;
bool m_requiresFlash = false;
QString m_weather;
QString m_type;
bool m_showsLocationName = false;
bool m_allowsRunning = false;
bool m_allowsBiking = false;
bool m_allowsEscaping = false;
int m_floorNumber = 0;
QString m_battleScene;
};
#endif // MAPHEADER_H

View File

@@ -327,7 +327,7 @@ private:
QAction *copyAction = nullptr;
QAction *pasteAction = nullptr;
MapHeaderForm *mapHeader = nullptr;
MapHeaderForm *mapHeaderForm = nullptr;
QMap<Event::Group, DraggablePixmapItem*> lastSelectedEvent;

View File

@@ -263,7 +263,7 @@ private:
signals:
void fileChanged(QString filepath);
void mapSectionIdNamesChanged();
void mapSectionIdNamesChanged(const QStringList &idNames);
void mapLoaded(Map *map);
};

View File

@@ -1,18 +1,18 @@
#ifndef MAPHEADERFORM_H
#define MAPHEADERFORM_H
#include "project.h"
#include "map.h"
#include "ui_mapheaderform.h"
#include <QWidget>
/*
This is the UI class used to edit the fields in a map's header.
It's intended to be used anywhere the UI needs to present an editor for a map's header,
e.g. for the current map in the main editor or in the new map dialog.
*/
#include <QWidget>
#include <QPointer>
#include "mapheader.h"
class Project;
namespace Ui {
class MapHeaderForm;
}
@@ -25,32 +25,43 @@ public:
explicit MapHeaderForm(QWidget *parent = nullptr);
~MapHeaderForm();
void setProject(Project * project);
void setMap(Map * map);
void clearDisplay();
void init(const Project * project);
void clear();
void refreshLocationsComboBox();
void setHeader(MapHeader *header);
MapHeader headerData() const;
Ui::MapHeaderForm *ui;
void setLocations(QStringList locations);
void setLocationsDisabled(bool disabled);
private:
QPointer<Map> map = nullptr;
QPointer<Project> project = nullptr;
Ui::MapHeaderForm *ui;
QPointer<MapHeader> m_header = nullptr;
private slots:
void on_comboBox_Song_currentTextChanged(const QString &);
void on_comboBox_Location_currentTextChanged(const QString &);
void on_comboBox_Weather_currentTextChanged(const QString &);
void on_comboBox_Type_currentTextChanged(const QString &);
void on_comboBox_BattleScene_currentTextChanged(const QString &);
void on_checkBox_RequiresFlash_stateChanged(int);
void on_checkBox_ShowLocationName_stateChanged(int);
void on_checkBox_AllowRunning_stateChanged(int);
void on_checkBox_AllowBiking_stateChanged(int);
void on_checkBox_AllowEscaping_stateChanged(int);
void on_spinBox_FloorNumber_valueChanged(int);
void updateUi();
void updateSong();
void updateLocation();
void updateRequiresFlash();
void updateWeather();
void updateType();
void updateBattleScene();
void updateShowsLocationName();
void updateAllowsRunning();
void updateAllowsBiking();
void updateAllowsEscaping();
void updateFloorNumber();
void onSongUpdated(const QString &song);
void onLocationChanged(const QString &location);
void onWeatherChanged(const QString &weather);
void onTypeChanged(const QString &type);
void onBattleSceneChanged(const QString &battleScene);
void onRequiresFlashChanged(int selected);
void onShowLocationNameChanged(int selected);
void onAllowRunningChanged(int selected);
void onAllowBikingChanged(int selected);
void onAllowEscapingChanged(int selected);
void onFloorNumberChanged(int offset);
};
#endif // MAPHEADERFORM_H

View File

@@ -0,0 +1,46 @@
#ifndef NEWLAYOUTFORM_H
#define NEWLAYOUTFORM_H
#include <QWidget>
class Project;
namespace Ui {
class NewLayoutForm;
}
class NewLayoutForm : public QWidget
{
Q_OBJECT
public:
explicit NewLayoutForm(QWidget *parent = nullptr);
~NewLayoutForm();
void initUi(Project *project);
struct Settings {
int width;
int height;
int borderWidth;
int borderHeight;
QString primaryTilesetLabel;
QString secondaryTilesetLabel;
};
void setSettings(const Settings &settings);
NewLayoutForm::Settings settings() const;
void setDisabled(bool disabled);
bool validate();
private:
Ui::NewLayoutForm *ui;
Project *m_project;
bool validateMapDimensions();
bool validateTilesets();
};
#endif // NEWLAYOUTFORM_H

View File

@@ -7,6 +7,7 @@
#include "project.h"
#include "map.h"
#include "mapheaderform.h"
#include "newlayoutform.h"
#include "lib/collapsiblesection.h"
namespace Ui {
@@ -25,7 +26,6 @@ public:
bool importedMap;
QString layoutId;
void init();
//void initUi();//TODO
void init(int tabIndex, QString data);
void init(Layout *);
static void setDefaultSettings(Project *project);
@@ -37,11 +37,9 @@ private:
Ui::NewMapDialog *ui;
Project *project;
CollapsibleSection *headerSection;
MapHeaderForm *headerData;
MapHeaderForm *headerForm;
bool validateMapDimensions();
bool validateMapGroup();
bool validateTilesets();
bool validateID();
bool validateName();
@@ -51,33 +49,18 @@ private:
struct Settings {
QString group;
int width;
int height;
int borderWidth;
int borderHeight;
QString primaryTilesetLabel;
QString secondaryTilesetLabel;
QString song;
QString location;
bool requiresFlash;
QString weather;
QString type;
QString battleScene;
bool showLocationName;
bool allowRunning;
bool allowBiking;
bool allowEscaping;
int floorNumber;
bool canFlyTo;
NewLayoutForm::Settings layout;
MapHeader header;
};
static struct Settings settings;
private slots:
//void on_checkBox_UseExistingLayout_stateChanged(int state);
//void on_checkBox_UseExistingLayout_stateChanged(int state); //TODO
//void on_comboBox_Layout_currentTextChanged(const QString &text);
void on_pushButton_Accept_clicked();
void on_lineEdit_Name_textChanged(const QString &);
void on_lineEdit_ID_textChanged(const QString &);
void on_lineEdit_MapID_textChanged(const QString &);
};
#endif // NEWMAPDIALOG_H