porymap/include/config.h

395 lines
13 KiB
C
Raw Normal View History

2020-09-13 23:37:55 +01:00
#pragma once
2018-12-21 15:25:28 +00:00
#ifndef CONFIG_H
#define CONFIG_H
#include <QString>
#include <QObject>
#include <QByteArrayList>
#include <QSize>
#include <QKeySequence>
#include <QMultiMap>
2018-12-21 15:25:28 +00:00
2022-09-11 04:30:28 +01:00
// In both versions the default new map border is a generic tree
#define DEFAULT_BORDER_RSE (QList<int>{468, 469, 476, 477})
#define DEFAULT_BORDER_FRLG (QList<int>{20, 21, 28, 29})
#define CONFIG_BACKWARDS_COMPATABILITY
2018-12-21 15:25:28 +00:00
enum MapSortOrder {
Group = 0,
Area = 1,
Layout = 2,
};
2021-02-18 13:43:52 +00:00
class KeyValueConfigBase
2018-12-21 15:25:28 +00:00
{
public:
void save();
void load();
virtual ~KeyValueConfigBase();
2020-04-07 19:44:14 +01:00
virtual void reset() = 0;
protected:
virtual QString getConfigFilepath() = 0;
virtual void parseConfigKeyValue(QString key, QString value) = 0;
virtual QMap<QString, QString> getKeyValueMap() = 0;
virtual void onNewConfigFileCreated() = 0;
2020-05-26 22:01:18 +01:00
virtual void setUnreadKeys() = 0;
2022-09-11 04:30:28 +01:00
bool getConfigBool(QString key, QString value);
int getConfigInteger(QString key, QString value, int min, int max, int defaultValue);
};
class PorymapConfig: public KeyValueConfigBase
{
public:
PorymapConfig() {
2020-04-07 19:44:14 +01:00
reset();
}
virtual void reset() override {
this->recentProject = "";
2022-07-04 20:47:03 +01:00
this->reopenOnLaunch = true;
this->mapSortOrder = MapSortOrder::Group;
this->prettyCursors = true;
this->collisionOpacity = 50;
2019-02-16 20:32:19 +00:00
this->metatilesZoom = 30;
this->showPlayerView = false;
this->showCursorTile = true;
this->showBorder = true;
this->showGrid = false;
this->monitorFiles = true;
this->tilesetCheckerboardFill = true;
this->theme = "default";
this->textEditorOpenFolder = "";
this->textEditorGotoLine = "";
}
void setRecentProject(QString project);
2022-07-04 20:47:03 +01:00
void setReopenOnLaunch(bool enabled);
void setMapSortOrder(MapSortOrder order);
void setPrettyCursors(bool enabled);
void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray);
void setTilesetEditorGeometry(QByteArray, QByteArray);
void setPaletteEditorGeometry(QByteArray, QByteArray);
void setRegionMapEditorGeometry(QByteArray, QByteArray);
void setCollisionOpacity(int opacity);
2019-02-16 20:32:19 +00:00
void setMetatilesZoom(int zoom);
void setShowPlayerView(bool enabled);
void setShowCursorTile(bool enabled);
void setShowBorder(bool enabled);
void setShowGrid(bool enabled);
void setMonitorFiles(bool monitor);
void setTilesetCheckerboardFill(bool checkerboard);
void setTheme(QString theme);
void setTextEditorOpenFolder(const QString &command);
void setTextEditorGotoLine(const QString &command);
QString getRecentProject();
2022-07-04 20:47:03 +01:00
bool getReopenOnLaunch();
MapSortOrder getMapSortOrder();
bool getPrettyCursors();
QMap<QString, QByteArray> getMainGeometry();
QMap<QString, QByteArray> getTilesetEditorGeometry();
QMap<QString, QByteArray> getPaletteEditorGeometry();
QMap<QString, QByteArray> getRegionMapEditorGeometry();
int getCollisionOpacity();
2019-02-16 20:32:19 +00:00
int getMetatilesZoom();
bool getShowPlayerView();
bool getShowCursorTile();
bool getShowBorder();
bool getShowGrid();
bool getMonitorFiles();
bool getTilesetCheckerboardFill();
QString getTheme();
QString getTextEditorOpenFolder();
QString getTextEditorGotoLine();
protected:
2020-04-07 19:44:14 +01:00
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
2020-05-26 22:01:18 +01:00
virtual void onNewConfigFileCreated() override {};
virtual void setUnreadKeys() override {};
2018-12-21 15:25:28 +00:00
private:
QString recentProject;
2022-07-04 20:47:03 +01:00
bool reopenOnLaunch;
QString stringFromByteArray(QByteArray);
QByteArray bytesFromString(QString);
MapSortOrder mapSortOrder;
bool prettyCursors;
QByteArray mainWindowGeometry;
QByteArray mainWindowState;
QByteArray mapSplitterState;
QByteArray eventsSlpitterState;
QByteArray mainSplitterState;
QByteArray tilesetEditorGeometry;
QByteArray tilesetEditorState;
QByteArray paletteEditorGeometry;
QByteArray paletteEditorState;
QByteArray regionMapEditorGeometry;
QByteArray regionMapEditorState;
int collisionOpacity;
2019-02-16 20:32:19 +00:00
int metatilesZoom;
bool showPlayerView;
bool showCursorTile;
bool showBorder;
bool showGrid;
bool monitorFiles;
bool tilesetCheckerboardFill;
QString theme;
QString textEditorOpenFolder;
QString textEditorGotoLine;
2018-12-21 15:25:28 +00:00
};
extern PorymapConfig porymapConfig;
enum BaseGameVersion {
pokeruby,
pokefirered,
pokeemerald,
};
enum ProjectFilePath {
data_map_folders,
data_scripts_folders,
data_layouts_folders,
2022-09-27 23:06:43 +01:00
data_tilesets_folders,
data_event_scripts,
json_map_groups,
json_layouts,
json_wild_encounters,
json_region_map_entries,
json_region_porymap_cfg,
tilesets_headers,
tilesets_graphics,
tilesets_metatiles,
2022-09-28 01:17:55 +01:00
tilesets_headers_asm,
tilesets_graphics_asm,
tilesets_metatiles_asm,
data_obj_event_gfx_pointers,
data_obj_event_gfx_info,
data_obj_event_pic_tables,
data_obj_event_gfx,
data_pokemon_gfx,
data_heal_locations,
constants_global,
constants_map_groups,
constants_items,
constants_opponents,
constants_flags,
constants_vars,
constants_weather,
constants_songs,
constants_heal_locations,
constants_pokemon,
constants_map_types,
constants_trainer_types,
constants_secret_bases,
constants_obj_event_movement,
constants_obj_events,
constants_event_bg,
constants_region_map_sections,
constants_metatile_labels,
constants_metatile_behaviors,
constants_fieldmap,
2022-10-24 13:03:51 +01:00
initial_facing_table,
pokemon_icon_table,
};
class ProjectConfig: public KeyValueConfigBase
{
public:
ProjectConfig() {
2020-04-07 19:44:14 +01:00
reset();
}
virtual void reset() override {
this->baseGameVersion = BaseGameVersion::pokeemerald;
2020-04-07 19:44:14 +01:00
this->useCustomBorderSize = false;
this->enableEventWeatherTrigger = true;
this->enableEventSecretBase = true;
this->enableHiddenItemQuantity = false;
this->enableHiddenItemRequiresItemfinder = false;
this->enableHealLocationRespawnData = false;
2022-02-06 02:31:54 +00:00
this->enableEventCloneObject = false;
this->enableFloorNumber = false;
this->createMapTextFile = false;
this->usePoryScript = false;
this->enableTripleLayerMetatiles = false;
2022-09-11 04:30:28 +01:00
this->newMapMetatileId = 1;
this->newMapElevation = 3;
this->newMapBorderMetatileIds = DEFAULT_BORDER_RSE;
2022-10-24 00:28:55 +01:00
this->defaultPrimaryTileset = "gTileset_General";
2022-09-06 02:51:31 +01:00
this->prefabFilepath = QString();
this->prefabImportPrompted = false;
this->tilesetsHaveCallback = true;
this->tilesetsHaveIsCompressed = true;
this->filePaths.clear();
2020-05-26 22:01:18 +01:00
this->readKeys.clear();
}
void setBaseGameVersion(BaseGameVersion baseGameVersion);
BaseGameVersion getBaseGameVersion();
2021-12-15 04:50:56 +00:00
QString getBaseGameVersionString();
void setUsePoryScript(bool usePoryScript);
bool getUsePoryScript();
void setProjectDir(QString projectDir);
QString getProjectDir();
void setUseCustomBorderSize(bool enable);
bool getUseCustomBorderSize();
void setEventWeatherTriggerEnabled(bool enable);
bool getEventWeatherTriggerEnabled();
void setEventSecretBaseEnabled(bool enable);
bool getEventSecretBaseEnabled();
void setHiddenItemQuantityEnabled(bool enable);
bool getHiddenItemQuantityEnabled();
void setHiddenItemRequiresItemfinderEnabled(bool enable);
bool getHiddenItemRequiresItemfinderEnabled();
void setHealLocationRespawnDataEnabled(bool enable);
bool getHealLocationRespawnDataEnabled();
2022-02-06 02:31:54 +00:00
void setEventCloneObjectEnabled(bool enable);
bool getEventCloneObjectEnabled();
void setFloorNumberEnabled(bool enable);
bool getFloorNumberEnabled();
void setCreateMapTextFileEnabled(bool enable);
bool getCreateMapTextFileEnabled();
void setTripleLayerMetatilesEnabled(bool enable);
bool getTripleLayerMetatilesEnabled();
int getNumLayersInMetatile();
int getNumTilesInMetatile();
2022-09-11 04:30:28 +01:00
void setNewMapMetatileId(int metatileId);
int getNewMapMetatileId();
void setNewMapElevation(int elevation);
int getNewMapElevation();
void setNewMapBorderMetatileIds(QList<int> metatileIds);
QList<int> getNewMapBorderMetatileIds();
2022-10-24 00:28:55 +01:00
QString getDefaultPrimaryTileset();
QString getDefaultSecondaryTileset();
void setFilePath(ProjectFilePath pathId, QString path);
QString getFilePath(ProjectFilePath pathId);
2022-09-06 02:51:31 +01:00
void setPrefabFilepath(QString filepath);
QString getPrefabFilepath(bool setIfEmpty);
void setPrefabImportPrompted(bool prompted);
bool getPrefabImportPrompted();
void setTilesetsHaveCallback(bool has);
bool getTilesetsHaveCallback();
void setTilesetsHaveIsCompressed(bool has);
bool getTilesetsHaveIsCompressed();
protected:
2020-04-07 19:44:14 +01:00
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
virtual void onNewConfigFileCreated() override;
2020-05-26 22:01:18 +01:00
virtual void setUnreadKeys() override;
private:
BaseGameVersion baseGameVersion;
QString projectDir;
QMap<ProjectFilePath, QString> filePaths;
bool usePoryScript;
bool useCustomBorderSize;
bool enableEventWeatherTrigger;
bool enableEventSecretBase;
bool enableHiddenItemQuantity;
bool enableHiddenItemRequiresItemfinder;
bool enableHealLocationRespawnData;
2022-02-06 02:31:54 +00:00
bool enableEventCloneObject;
bool enableFloorNumber;
bool createMapTextFile;
bool enableTripleLayerMetatiles;
2022-09-11 04:30:28 +01:00
int newMapMetatileId;
int newMapElevation;
QList<int> newMapBorderMetatileIds;
2022-10-24 00:28:55 +01:00
QString defaultPrimaryTileset;
QString defaultSecondaryTileset;
2020-05-26 22:01:18 +01:00
QStringList readKeys;
2022-09-06 02:51:31 +01:00
QString prefabFilepath;
bool prefabImportPrompted;
bool tilesetsHaveCallback;
bool tilesetsHaveIsCompressed;
};
extern ProjectConfig projectConfig;
class UserConfig: public KeyValueConfigBase
{
public:
UserConfig() {
reset();
}
virtual void reset() override {
this->recentMap = QString();
this->useEncounterJson = true;
this->customScripts.clear();
this->readKeys.clear();
}
void setRecentMap(const QString &map);
QString getRecentMap();
void setEncounterJsonActive(bool active);
bool getEncounterJsonActive();
void setProjectDir(QString projectDir);
QString getProjectDir();
void setCustomScripts(QList<QString> scripts);
QList<QString> getCustomScripts();
protected:
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
virtual void onNewConfigFileCreated() override;
virtual void setUnreadKeys() override;
#ifdef CONFIG_BACKWARDS_COMPATABILITY
friend class ProjectConfig;
#endif
private:
QString projectDir;
QString recentMap;
bool useEncounterJson;
QList<QString> customScripts;
QStringList readKeys;
};
extern UserConfig userConfig;
class QAction;
class Shortcut;
class ShortcutsConfig : public KeyValueConfigBase
{
public:
ShortcutsConfig() :
user_shortcuts({ }),
default_shortcuts({ })
{ }
virtual void reset() override { user_shortcuts.clear(); }
// Call this before applying user shortcuts so that the user can restore defaults.
void setDefaultShortcuts(const QObjectList &objects);
QList<QKeySequence> defaultShortcuts(const QObject *object) const;
void setUserShortcuts(const QObjectList &objects);
void setUserShortcuts(const QMultiMap<const QObject *, QKeySequence> &objects_keySequences);
QList<QKeySequence> userShortcuts(const QObject *object) const;
protected:
virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override;
virtual QMap<QString, QString> getKeyValueMap() override;
virtual void onNewConfigFileCreated() override { };
virtual void setUnreadKeys() override { };
private:
QMultiMap<QString, QKeySequence> user_shortcuts;
QMultiMap<QString, QKeySequence> default_shortcuts;
2020-11-05 11:32:31 +00:00
enum StoreType {
User,
Default
};
QString cfgKey(const QObject *object) const;
QList<QKeySequence> currentShortcuts(const QObject *object) const;
void storeShortcutsFromList(StoreType storeType, const QObjectList &objects);
2020-11-05 11:32:31 +00:00
void storeShortcuts(
StoreType storeType,
const QString &cfgKey,
const QList<QKeySequence> &keySequences);
};
extern ShortcutsConfig shortcutsConfig;
2018-12-21 15:25:28 +00:00
#endif // CONFIG_H