Compare commits

...

2 commits

Author SHA1 Message Date
Marcus Huderle
57051b7a4a [clang-format] Format source code 2021-02-17 18:20:14 -06:00
Marcus Huderle
3d50732b80 Create .clang-format 2021-02-17 18:19:24 -06:00
138 changed files with 5763 additions and 6416 deletions

66
.clang-format Normal file
View file

@ -0,0 +1,66 @@
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: false
AlignConsecutiveAssignments: false
AlignEscapedNewlinesLeft: false
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 160
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...

View file

@ -10,18 +10,18 @@
#include <QMultiMap>
enum MapSortOrder {
Group = 0,
Area = 1,
Layout = 2,
Group = 0,
Area = 1,
Layout = 2,
};
class KeyValueConfigBase : public QObject
{
class KeyValueConfigBase : public QObject {
public:
void save();
void load();
virtual ~KeyValueConfigBase();
virtual void reset() = 0;
protected:
virtual QString getConfigFilepath() = 0;
virtual void parseConfigKeyValue(QString key, QString value) = 0;
@ -30,8 +30,7 @@ protected:
virtual void setUnreadKeys() = 0;
};
class PorymapConfig: public KeyValueConfigBase
{
class PorymapConfig : public KeyValueConfigBase {
public:
PorymapConfig() {
reset();
@ -64,8 +63,8 @@ public:
void setMonitorFiles(bool monitor);
void setRegionMapDimensions(int width, int height);
void setTheme(QString theme);
void setTextEditorOpenFolder(const QString &command);
void setTextEditorGotoLine(const QString &command);
void setTextEditorOpenFolder(const QString& command);
void setTextEditorGotoLine(const QString& command);
QString getRecentProject();
MapSortOrder getMapSortOrder();
bool getPrettyCursors();
@ -82,12 +81,14 @@ public:
QString getTheme();
QString getTextEditorOpenFolder();
QString getTextEditorGotoLine();
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 {};
virtual void onNewConfigFileCreated() override{};
virtual void setUnreadKeys() override{};
private:
QString recentProject;
QString stringFromByteArray(QByteArray);
@ -124,8 +125,7 @@ enum BaseGameVersion {
pokeemerald,
};
class ProjectConfig: public KeyValueConfigBase
{
class ProjectConfig : public KeyValueConfigBase {
public:
ProjectConfig() {
reset();
@ -148,7 +148,7 @@ public:
}
void setBaseGameVersion(BaseGameVersion baseGameVersion);
BaseGameVersion getBaseGameVersion();
void setRecentMap(const QString &map);
void setRecentMap(const QString& map);
QString getRecentMap();
void setEncounterJsonActive(bool active);
bool getEncounterJsonActive();
@ -176,12 +176,14 @@ public:
bool getTripleLayerMetatilesEnabled();
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;
private:
BaseGameVersion baseGameVersion;
QString projectDir;
@ -206,48 +208,41 @@ extern ProjectConfig projectConfig;
class QAction;
class Shortcut;
class ShortcutsConfig : public KeyValueConfigBase
{
class ShortcutsConfig : public KeyValueConfigBase {
public:
ShortcutsConfig() :
user_shortcuts({ }),
default_shortcuts({ })
{ }
ShortcutsConfig() : user_shortcuts({}), default_shortcuts({}) {
}
virtual void reset() override { user_shortcuts.clear(); }
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 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;
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 { };
virtual void onNewConfigFileCreated() override{};
virtual void setUnreadKeys() override{};
private:
QMultiMap<QString, QKeySequence> user_shortcuts;
QMultiMap<QString, QKeySequence> default_shortcuts;
enum StoreType {
User,
Default
};
enum StoreType { User, Default };
QString cfgKey(const QObject *object) const;
QList<QKeySequence> currentShortcuts(const QObject *object) const;
QString cfgKey(const QObject* object) const;
QList<QKeySequence> currentShortcuts(const QObject* object) const;
void storeShortcutsFromList(StoreType storeType, const QObjectList &objects);
void storeShortcuts(
StoreType storeType,
const QString &cfgKey,
const QList<QKeySequence> &keySequences);
void storeShortcutsFromList(StoreType storeType, const QObjectList& objects);
void storeShortcuts(StoreType storeType, const QString& cfgKey, const QList<QKeySequence>& keySequences);
};
extern ShortcutsConfig shortcutsConfig;

View file

@ -4,19 +4,18 @@
#include <QObject>
class Block
{
class Block {
public:
Block();
Block(uint16_t);
Block(uint16_t tile, uint16_t collision, uint16_t elevation);
Block(const Block &);
Block &operator=(const Block &);
bool operator ==(Block) const;
bool operator !=(Block) const;
uint16_t tile:10;
uint16_t collision:2;
uint16_t elevation:4;
Block(const Block&);
Block& operator=(const Block&);
bool operator==(Block) const;
bool operator!=(Block) const;
uint16_t tile : 10;
uint16_t collision : 2;
uint16_t elevation : 4;
uint16_t rawValue() const;
};

View file

@ -7,8 +7,7 @@
#include <QByteArray>
#include <QVector>
class Blockdata : public QVector<Block>
{
class Blockdata : public QVector<Block> {
public:
QByteArray serialize() const;
};

View file

@ -32,28 +32,28 @@ enum CommandId {
ID_EventDuplicate,
};
#define IDMask_EventType_Object (1 << 8)
#define IDMask_EventType_Warp (1 << 9)
#define IDMask_EventType_BG (1 << 10)
#define IDMask_EventType_Object (1 << 8)
#define IDMask_EventType_Warp (1 << 9)
#define IDMask_EventType_BG (1 << 10)
#define IDMask_EventType_Trigger (1 << 11)
#define IDMask_EventType_Heal (1 << 12)
#define IDMask_EventType_Heal (1 << 12)
/// Implements a command to commit metatile paint actions
/// onto the map using the pencil tool.
class PaintMetatile : public QUndoCommand {
public:
PaintMetatile(Map *map,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
unsigned actionId, QUndoCommand *parent = nullptr);
PaintMetatile(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override;
int id() const override { return CommandId::ID_PaintMetatile; }
bool mergeWith(const QUndoCommand* command) override;
int id() const override {
return CommandId::ID_PaintMetatile;
}
private:
Map *map;
Map* map;
Blockdata newMetatiles;
Blockdata oldMetatiles;
@ -61,39 +61,37 @@ private:
unsigned actionId;
};
/// Implements a command to commit paint actions
/// on the metatile collision and elevation.
class PaintCollision : public PaintMetatile {
public:
PaintCollision(Map *map,
const Blockdata &oldCollision, const Blockdata &newCollision,
unsigned actionId, QUndoCommand *parent = nullptr)
: PaintMetatile(map, oldCollision, newCollision, actionId, parent) {
PaintCollision(Map* map, const Blockdata& oldCollision, const Blockdata& newCollision, unsigned actionId, QUndoCommand* parent = nullptr)
: PaintMetatile(map, oldCollision, newCollision, actionId, parent) {
setText("Paint Collision");
}
int id() const override { return CommandId::ID_PaintCollision; }
int id() const override {
return CommandId::ID_PaintCollision;
}
};
/// Implements a command to commit paint actions on the map border.
class PaintBorder : public QUndoCommand {
public:
PaintBorder(Map *map,
const Blockdata &oldBorder, const Blockdata &newBorder,
unsigned actionId, QUndoCommand *parent = nullptr);
PaintBorder(Map* map, const Blockdata& oldBorder, const Blockdata& newBorder, unsigned actionId, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; };
int id() const override { return CommandId::ID_PaintBorder; }
bool mergeWith(const QUndoCommand*) override {
return false;
};
int id() const override {
return CommandId::ID_PaintBorder;
}
private:
Map *map;
Map* map;
Blockdata newBorder;
Blockdata oldBorder;
@ -101,88 +99,82 @@ private:
unsigned actionId;
};
/// Implements a command to commit flood fill metatile actions
/// with the bucket tool onto the map.
class BucketFillMetatile : public PaintMetatile {
public:
BucketFillMetatile(Map *map,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
unsigned actionId, QUndoCommand *parent = nullptr)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
BucketFillMetatile(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
setText("Bucket Fill Metatiles");
}
int id() const override { return CommandId::ID_BucketFillMetatile; }
int id() const override {
return CommandId::ID_BucketFillMetatile;
}
};
/// Implements a command to commit flood fill actions
/// on the metatile collision and elevation.
class BucketFillCollision : public PaintCollision {
public:
BucketFillCollision(Map *map,
const Blockdata &oldCollision, const Blockdata &newCollision,
QUndoCommand *parent = nullptr)
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
BucketFillCollision(Map* map, const Blockdata& oldCollision, const Blockdata& newCollision, QUndoCommand* parent = nullptr)
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
setText("Flood Fill Collision");
}
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_BucketFillCollision; }
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_BucketFillCollision;
}
};
/// Implements a command to commit magic fill metatile actions
/// with the bucket or paint tool onto the map.
class MagicFillMetatile : public PaintMetatile {
public:
MagicFillMetatile(Map *map,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
unsigned actionId, QUndoCommand *parent = nullptr)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
MagicFillMetatile(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
setText("Magic Fill Metatiles");
}
int id() const override { return CommandId::ID_MagicFillMetatile; }
int id() const override {
return CommandId::ID_MagicFillMetatile;
}
};
/// Implements a command to commit magic fill collision actions.
class MagicFillCollision : public PaintCollision {
public:
MagicFillCollision(Map *map,
const Blockdata &oldCollision, const Blockdata &newCollision,
QUndoCommand *parent = nullptr)
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
MagicFillCollision(Map* map, const Blockdata& oldCollision, const Blockdata& newCollision, QUndoCommand* parent = nullptr)
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
setText("Magic Fill Collision");
}
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_MagicFillCollision; }
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_MagicFillCollision;
}
};
/// Implements a command to commit metatile shift actions.
class ShiftMetatiles : public QUndoCommand {
public:
ShiftMetatiles(Map *map,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
unsigned actionId, QUndoCommand *parent = nullptr);
ShiftMetatiles(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override;
int id() const override { return CommandId::ID_ShiftMetatiles; }
bool mergeWith(const QUndoCommand* command) override;
int id() const override {
return CommandId::ID_ShiftMetatiles;
}
private:
Map *map;
Map* map;
Blockdata newMetatiles;
Blockdata oldMetatiles;
@ -190,25 +182,24 @@ private:
unsigned actionId;
};
/// Implements a command to commit a map or border resize action.
class ResizeMap : public QUndoCommand {
public:
ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QSize oldBorderDimensions, QSize newBorderDimensions,
const Blockdata &oldBorder, const Blockdata &newBorder,
QUndoCommand *parent = nullptr);
ResizeMap(Map* map, QSize oldMapDimensions, QSize newMapDimensions, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, QSize oldBorderDimensions,
QSize newBorderDimensions, const Blockdata& oldBorder, const Blockdata& newBorder, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_ResizeMap; }
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_ResizeMap;
}
private:
Map *map;
Map* map;
int oldMapWidth;
int oldMapHeight;
@ -227,126 +218,115 @@ private:
Blockdata oldBorder;
};
/// Implements a command to commit a single- or multi-Event move action.
/// Actions are merged into one until the mouse is released.
class EventMove : public QUndoCommand {
public:
EventMove(QList<Event *> events,
int deltaX, int deltaY, unsigned actionId,
QUndoCommand *parent = nullptr);
EventMove(QList<Event*> events, int deltaX, int deltaY, unsigned actionId, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override;
bool mergeWith(const QUndoCommand* command) override;
int id() const override;
private:
QList<Event *> events;
QList<Event*> events;
int deltaX;
int deltaY;
unsigned actionId;
};
/// Implements a command to commit Event shift actions.
class EventShift : public EventMove {
public:
EventShift(QList<Event *> events,
int deltaX, int deltaY, unsigned actionId,
QUndoCommand *parent = nullptr);
EventShift(QList<Event*> events, int deltaX, int deltaY, unsigned actionId, QUndoCommand* parent = nullptr);
int id() const override;
private:
QList<Event *> events;
QList<Event*> events;
};
/// Implements a command to commit Event create actions.
/// Works for a single Event only.
class EventCreate : public QUndoCommand {
public:
EventCreate(Editor *editor, Map *map, Event *event,
QUndoCommand *parent = nullptr);
EventCreate(Editor* editor, Map* map, Event* event, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; }
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override;
private:
Map *map;
Event *event;
Editor *editor;
Map* map;
Event* event;
Editor* editor;
};
/// Implements a command to commit Event deletions.
/// Applies to every currently selected Event.
class EventDelete : public QUndoCommand {
public:
EventDelete(Editor *editor, Map *map,
QList<Event *> selectedEvents, Event *nextSelectedEvent,
QUndoCommand *parent = nullptr);
EventDelete(Editor* editor, Map* map, QList<Event*> selectedEvents, Event* nextSelectedEvent, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; }
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override;
private:
Editor *editor;
Map *map;
QList<Event *> selectedEvents; // allow multiple deletion of events
Event *nextSelectedEvent;
Editor* editor;
Map* map;
QList<Event*> selectedEvents; // allow multiple deletion of events
Event* nextSelectedEvent;
};
/// Implements a command to commit Event duplications.
class EventDuplicate : public QUndoCommand {
public:
EventDuplicate(Editor *editor, Map *map, QList<Event *> selectedEvents,
QUndoCommand *parent = nullptr);
EventDuplicate(Editor* editor, Map* map, QList<Event*> selectedEvents, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; }
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override;
private:
Map *map;
QList<Event *> selectedEvents; // allow multiple deletion of events
Editor *editor;
Map* map;
QList<Event*> selectedEvents; // allow multiple deletion of events
Editor* editor;
};
/// Implements a command to commit map edits from the scripting API.
/// The scripting api can edit metatiles and map dimensions.
class ScriptEditMap : public QUndoCommand {
public:
ScriptEditMap(Map *map,
QSize oldMapDimensions, QSize newMapDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QUndoCommand *parent = nullptr);
ScriptEditMap(
Map* map, QSize oldMapDimensions, QSize newMapDimensions, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_ScriptEditMap; }
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_ScriptEditMap;
}
private:
Map *map;
Map* map;
Blockdata newMetatiles;
Blockdata oldMetatiles;

View file

@ -10,8 +10,7 @@
using OrderedJson = poryjson::Json;
class EventType
{
class EventType {
public:
static QString Object;
static QString Warp;
@ -25,12 +24,12 @@ public:
class DraggablePixmapItem;
class Project;
class Event
{
class Event {
public:
Event();
Event(const Event&);
Event(QJsonObject, QString);
public:
int x() const {
return getInt("x");
@ -47,16 +46,16 @@ public:
void setY(int y) {
put("y", y);
}
QString get(const QString &key) const {
QString get(const QString& key) const {
return values.value(key);
}
int getInt(const QString &key) const {
int getInt(const QString& key) const {
return values.value(key).toInt(nullptr, 0);
}
uint16_t getU16(const QString &key) const {
uint16_t getU16(const QString& key) const {
return values.value(key).toUShort(nullptr, 0);
}
int16_t getS16(const QString &key) const {
int16_t getS16(const QString& key) const {
return values.value(key).toShort(nullptr, 0);
}
void put(QString key, int value) {
@ -77,7 +76,7 @@ public:
static Event* createNewSecretBaseEvent(Project*);
OrderedJson::object buildObjectEventJSON();
OrderedJson::object buildWarpEventJSON(const QMap<QString, QString> &);
OrderedJson::object buildWarpEventJSON(const QMap<QString, QString>&);
OrderedJson::object buildTriggerEventJSON();
OrderedJson::object buildWeatherTriggerEventJSON();
OrderedJson::object buildSignEventJSON();
@ -88,7 +87,7 @@ public:
int getPixelY();
QMap<QString, bool> getExpectedFields();
void readCustomValues(QJsonObject values);
void addCustomValuesTo(OrderedJson::object *obj);
void addCustomValuesTo(OrderedJson::object* obj);
void setFrameFromMovement(QString);
QMap<QString, QString> values;
@ -100,8 +99,10 @@ public:
bool hFlip = false;
bool usingSprite;
DraggablePixmapItem *pixmapItem = nullptr;
void setPixmapItem(DraggablePixmapItem *item) { pixmapItem = item; }
DraggablePixmapItem* pixmapItem = nullptr;
void setPixmapItem(DraggablePixmapItem* item) {
pixmapItem = item;
}
};
#endif // EVENT_H

View file

@ -9,16 +9,16 @@
class HealLocation {
public:
HealLocation()=default;
HealLocation() = default;
HealLocation(QString, QString, int, uint16_t, uint16_t, QString = "", uint16_t = 0);
friend QDebug operator<<(QDebug debug, const HealLocation &hl);
friend QDebug operator<<(QDebug debug, const HealLocation& hl);
public:
QString idName;
QString mapName;
int index;
uint16_t x;
uint16_t y;
int index;
uint16_t x;
uint16_t y;
QString respawnMap;
uint16_t respawnNPC;
static HealLocation fromEvent(Event*);

View file

@ -4,10 +4,10 @@
#include <QList>
template <typename T>
class History {
template <typename T> class History {
public:
History() { }
History() {
}
T back() {
if (head > 0) {
return history.at(--head);

View file

@ -25,11 +25,10 @@ class MapPixmapItem;
class CollisionPixmapItem;
class BorderMetatilesPixmapItem;
class Map : public QObject
{
class Map : public QObject {
Q_OBJECT
public:
explicit Map(QObject *parent = nullptr);
explicit Map(QObject* parent = nullptr);
~Map();
public:
@ -52,7 +51,7 @@ public:
QString sharedEventsMap = "";
QString sharedScriptsMap = "";
QMap<QString, QString> customHeaders;
MapLayout *layout;
MapLayout* layout;
bool isPersistedToFile = true;
bool needsLayoutDir = true;
QImage collision_image;
@ -73,22 +72,22 @@ public:
int getHeight();
int getBorderWidth();
int getBorderHeight();
QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr);
QPixmap render(bool ignoreCache, MapLayout* fromLayout = nullptr);
QPixmap renderCollision(qreal opacity, bool ignoreCache);
bool mapBlockChanged(int i, const Blockdata &cache);
bool borderBlockChanged(int i, const Blockdata &cache);
bool mapBlockChanged(int i, const Blockdata& cache);
bool borderBlockChanged(int i, const Blockdata& cache);
void cacheBlockdata();
void cacheCollision();
bool getBlock(int x, int y, Block *out);
bool getBlock(int x, int y, Block* out);
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
QList<Event*> getAllEvents() const;
QStringList eventScriptLabels(const QString &event_group_type = QString()) const;
QStringList eventScriptLabels(const QString& event_group_type = QString()) const;
void removeEvent(Event*);
void addEvent(Event*);
QPixmap renderConnection(MapConnection, MapLayout *);
QPixmap renderConnection(MapConnection, MapLayout*);
QPixmap renderBorder(bool ignoreCache = false);
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
@ -96,16 +95,22 @@ public:
bool hasUnsavedChanges();
// for memory management
QVector<Event *> ownedEvents;
QVector<Event*> ownedEvents;
MapPixmapItem *mapItem = nullptr;
void setMapItem(MapPixmapItem *item) { mapItem = item; }
MapPixmapItem* mapItem = nullptr;
void setMapItem(MapPixmapItem* item) {
mapItem = item;
}
CollisionPixmapItem *collisionItem = nullptr;
void setCollisionItem(CollisionPixmapItem *item) { collisionItem = item; }
CollisionPixmapItem* collisionItem = nullptr;
void setCollisionItem(CollisionPixmapItem* item) {
collisionItem = item;
}
BorderMetatilesPixmapItem *borderItem = nullptr;
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
BorderMetatilesPixmapItem* borderItem = nullptr;
void setBorderItem(BorderMetatilesPixmapItem* item) {
borderItem = item;
}
QUndoStack editHistory;
@ -114,8 +119,8 @@ private:
void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
signals:
void mapChanged(Map *map);
void mapDimensionsChanged(const QSize &size);
void mapChanged(Map* map);
void mapDimensionsChanged(const QSize& size);
void mapNeedsRedrawing();
};

View file

@ -12,11 +12,11 @@ public:
QString map_name;
};
inline bool operator==(const MapConnection &c1, const MapConnection &c2) {
inline bool operator==(const MapConnection& c1, const MapConnection& c2) {
return c1.map_name == c2.map_name;
}
inline uint qHash(const MapConnection &key) {
inline uint qHash(const MapConnection& key) {
return qHash(key.map_name);
}

View file

@ -10,7 +10,8 @@
class MapLayout {
public:
MapLayout() {}
MapLayout() {
}
static QString layoutConstantFromName(QString mapName);
QString id;
QString name;
@ -22,8 +23,8 @@ public:
QString blockdata_path;
QString tileset_primary_label;
QString tileset_secondary_label;
Tileset *tileset_primary = nullptr;
Tileset *tileset_secondary = nullptr;
Tileset* tileset_primary = nullptr;
Tileset* tileset_secondary = nullptr;
Blockdata blockdata;
QImage border_image;
QPixmap border_pixmap;

View file

@ -7,23 +7,22 @@
#include <QPoint>
#include <QString>
class Metatile
{
class Metatile {
public:
Metatile();
Metatile(const Metatile &other) = default;
Metatile &operator=(const Metatile &other) = default;
Metatile(const Metatile& other) = default;
Metatile& operator=(const Metatile& other) = default;
public:
QList<Tile> tiles;
uint16_t behavior; // 8 bits RSE, 9 bits FRLG
uint16_t behavior; // 8 bits RSE, 9 bits FRLG
uint8_t layerType;
uint8_t encounterType; // FRLG only
uint8_t terrainType; // FRLG only
uint8_t terrainType; // FRLG only
QString label;
static int getBlockIndex(int);
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
static QPoint coordFromPixmapCoord(const QPointF& pixelCoord);
};
#endif // METATILE_H

View file

@ -6,11 +6,10 @@
#include <QList>
#include <QString>
class MetatileParser
{
class MetatileParser {
public:
MetatileParser();
QList<Metatile*> parse(QString filepath, bool *error, bool primaryTileset);
QList<Metatile*> parse(QString filepath, bool* error, bool primaryTileset);
};
#endif // METATILEPARSER_H

View file

@ -6,19 +6,19 @@
#include <QRgb>
#include <QString>
class PaletteUtil
{
class PaletteUtil {
public:
PaletteUtil();
QList<QRgb> parse(QString filepath, bool *error);
QList<QRgb> parse(QString filepath, bool* error);
void writeJASC(QString filepath, QVector<QRgb> colors, int offset, int nColors);
private:
QList<QRgb> parsePal(QString filepath, bool *error);
QList<QRgb> parseJASC(QString filepath, bool *error);
QList<QRgb> parseAdvanceMapPal(QString filepath, bool *error);
QList<QRgb> parseAdobeColorTable(QString filepath, bool *error);
QList<QRgb> parseTileLayerPro(QString filepath, bool *error);
QList<QRgb> parseAdvancePaletteEditor(QString filepath, bool *error);
QList<QRgb> parsePal(QString filepath, bool* error);
QList<QRgb> parseJASC(QString filepath, bool* error);
QList<QRgb> parseAdvanceMapPal(QString filepath, bool* error);
QList<QRgb> parseAdobeColorTable(QString filepath, bool* error);
QList<QRgb> parseTileLayerPro(QString filepath, bool* error);
QList<QRgb> parseAdvancePaletteEditor(QString filepath, bool* error);
int clampColorValue(int value);
};

View file

@ -36,33 +36,32 @@ public:
int operatorPrecedence; // only relevant for operator tokens
};
class ParseUtil
{
class ParseUtil {
public:
ParseUtil() { };
void set_root(const QString &dir);
static QString readTextFile(const QString &path);
static int textFileLineCount(const QString &path);
QList<QStringList> parseAsm(const QString &filename);
ParseUtil(){};
void set_root(const QString& dir);
static QString readTextFile(const QString& path);
static int textFileLineCount(const QString& path);
QList<QStringList> parseAsm(const QString& filename);
int evaluateDefine(const QString&, const QMap<QString, int>&);
QStringList readCArray(const QString &text, const QString &label);
QMap<QString, QString> readNamedIndexCArray(const QString &text, const QString &label);
QString readCIncbin(const QString &text, const QString &label);
QMap<QString, int> readCDefines(const QString &filename, const QStringList &prefixes, QMap<QString, int> = { });
QStringList readCDefinesSorted(const QString&, const QStringList&, const QMap<QString, int>& = { });
QStringList readCArray(const QString& text, const QString& label);
QMap<QString, QString> readNamedIndexCArray(const QString& text, const QString& label);
QString readCIncbin(const QString& text, const QString& label);
QMap<QString, int> readCDefines(const QString& filename, const QStringList& prefixes, QMap<QString, int> = {});
QStringList readCDefinesSorted(const QString&, const QStringList&, const QMap<QString, int>& = {});
QList<QStringList> getLabelMacros(const QList<QStringList>&, const QString&);
QStringList getLabelValues(const QList<QStringList>&, const QString&);
bool tryParseJsonFile(QJsonDocument *out, const QString &filepath);
bool ensureFieldsExist(const QJsonObject &obj, const QList<QString> &fields);
bool tryParseJsonFile(QJsonDocument* out, const QString& filepath);
bool ensureFieldsExist(const QJsonObject& obj, const QList<QString>& fields);
// Returns the 1-indexed line number for the definition of scriptLabel in the scripts file at filePath.
// Returns 0 if a definition for scriptLabel cannot be found.
static int getScriptLineNumber(const QString &filePath, const QString &scriptLabel);
static int getRawScriptLineNumber(QString text, const QString &scriptLabel);
static int getPoryScriptLineNumber(QString text, const QString &scriptLabel);
static int getScriptLineNumber(const QString& filePath, const QString& scriptLabel);
static int getRawScriptLineNumber(QString text, const QString& scriptLabel);
static int getPoryScriptLineNumber(QString text, const QString& scriptLabel);
static QString removeStringLiterals(QString text);
static QString removeLineComments(QString text, const QString &commentSymbol);
static QString removeLineComments(QString text, const QStringList &commentSymbols);
static QString removeLineComments(QString text, const QString& commentSymbol);
static QString removeLineComments(QString text, const QStringList& commentSymbols);
static QStringList splitShellCommand(QStringView command);
@ -70,10 +69,10 @@ private:
QString root;
QString text;
QString file;
QList<Token> tokenizeExpression(QString expression, const QMap<QString, int> &knownIdentifiers);
QList<Token> generatePostfix(const QList<Token> &tokens);
int evaluatePostfix(const QList<Token> &postfix);
void error(const QString &message, const QString &expression);
QList<Token> tokenizeExpression(QString expression, const QMap<QString, int>& knownIdentifiers);
QList<Token> generatePostfix(const QList<Token>& tokens);
int evaluatePostfix(const QList<Token>& postfix);
void error(const QString& message, const QString& expression);
};
#endif // PARSEUTIL_H

View file

@ -17,7 +17,7 @@
enum RegionMapEditorBox {
BackgroundImage = 1,
CityMapImage = 2,
CityMapImage = 2,
};
class RegionMapHistoryItem {
@ -38,19 +38,19 @@ public:
this->mapWidth = width;
this->mapHeight = height;
}
~RegionMapHistoryItem() {}
~RegionMapHistoryItem() {
}
};
class RegionMapEntry
{
class RegionMapEntry {
public:
RegionMapEntry()=default;
RegionMapEntry() = default;
RegionMapEntry(int x_, int y_, int width_, int height_, QString name_) {
this-> x = x_;
this-> y = y_;
this-> width = width_;
this-> height = height_;
this-> name = name_;
this->x = x_;
this->y = y_;
this->width = width_;
this->height = height_;
this->name = name_;
}
int x;
int y;
@ -64,8 +64,7 @@ public:
void setHeight(int);
};
class RegionMapSquare
{
class RegionMapSquare {
public:
int x = -1;
int y = -1;
@ -79,16 +78,15 @@ public:
QString city_map_name;
};
class RegionMap : public QObject
{
class RegionMap : public QObject {
Q_OBJECT
public:
RegionMap() = default;
~RegionMap() {};
~RegionMap(){};
Project *project = nullptr;
Project* project = nullptr;
QVector<RegionMapSquare> map_squares;
History<RegionMapHistoryItem*> history;
@ -97,9 +95,9 @@ public:
QMap<QString, RegionMapEntry> mapSecToMapEntry;
QVector<QString> sMapNames;
const int padLeft = 1;
const int padRight = 3;
const int padTop = 2;
const int padLeft = 1;
const int padRight = 3;
const int padTop = 2;
const int padBottom = 3;
bool init(Project*);
@ -119,8 +117,8 @@ public:
void clearImage();
void replaceSectionId(unsigned oldId, unsigned newId);
int width();
int height();
int width();
int height();
QSize imgSize();
unsigned getTileId(int x, int y);
int getMapSquareIndex(int x, int y);

View file

@ -2,23 +2,13 @@
#ifndef TILE_H
#define TILE_H
class Tile
{
class Tile {
public:
Tile() :
tile(0),
xflip(false),
yflip(false),
palette(0)
{ }
Tile() : tile(0), xflip(false), yflip(false), palette(0) {
}
Tile(int tile, bool xflip, bool yflip, int palette) :
tile(tile),
xflip(xflip),
yflip(yflip),
palette(palette)
{ }
Tile(int tile, bool xflip, bool yflip, int palette) : tile(tile), xflip(xflip), yflip(yflip), palette(palette) {
}
public:
int tile;

View file

@ -6,12 +6,11 @@
#include "tile.h"
#include <QImage>
class Tileset
{
class Tileset {
public:
Tileset() = default;
Tileset(const Tileset &other) = default;
Tileset &operator=(const Tileset &other) = default;
Tileset(const Tileset& other) = default;
Tileset& operator=(const Tileset& other) = default;
public:
QString name;
@ -38,7 +37,7 @@ public:
static Metatile* getMetatile(int, Tileset*, Tileset*);
static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*, bool useTruePalettes = false);
static QList<QRgb> getPalette(int, Tileset*, Tileset*, bool useTruePalettes = false);
static bool metatileIsValid(uint16_t metatileId, Tileset *, Tileset *);
static bool metatileIsValid(uint16_t metatileId, Tileset*, Tileset*);
bool appendToHeaders(QString headerFile, QString friendlyName);
bool appendToGraphics(QString graphicsFile, QString friendlyName, bool primary);

View file

@ -29,6 +29,6 @@ struct EncounterField {
typedef QVector<EncounterField> EncounterFields;
WildMonInfo getDefaultMonInfo(EncounterField field);
WildMonInfo copyMonInfoFromTab(QTableWidget *table, EncounterField monField);
WildMonInfo copyMonInfoFromTab(QTableWidget* table, EncounterField monField);
#endif // GUARD_WILDMONINFO_H

View file

@ -29,23 +29,22 @@
class DraggablePixmapItem;
class MetatilesPixmapItem;
class Editor : public QObject
{
class Editor : public QObject {
Q_OBJECT
public:
Editor(Ui::MainWindow* ui);
~Editor();
Editor() = delete;
Editor(const Editor &) = delete;
Editor & operator = (const Editor &) = delete;
Editor(const Editor&) = delete;
Editor& operator=(const Editor&) = delete;
public:
Ui::MainWindow* ui;
QObject *parent = nullptr;
Project *project = nullptr;
Map *map = nullptr;
Settings *settings;
QObject* parent = nullptr;
Project* project = nullptr;
Map* map = nullptr;
Settings* settings;
void saveProject();
void save();
void closeProject();
@ -81,7 +80,7 @@ public:
void setConnectionMap(QString mapName);
void addNewConnection();
void removeCurrentConnection();
void addNewWildMonGroup(QWidget *window);
void addNewWildMonGroup(QWidget* window);
void deleteWildMonGroup();
void updateDiveMap(QString mapName);
void updateEmergeMap(QString mapName);
@ -89,48 +88,48 @@ public:
void updatePrimaryTileset(QString tilesetLabel, bool forceLoad = false);
void updateSecondaryTileset(QString tilesetLabel, bool forceLoad = false);
void toggleBorderVisibility(bool visible);
void updateCustomMapHeaderValues(QTableWidget *);
void configureEncounterJSON(QWidget *);
Tileset *getCurrentMapPrimaryTileset();
void updateCustomMapHeaderValues(QTableWidget*);
void configureEncounterJSON(QWidget*);
Tileset* getCurrentMapPrimaryTileset();
DraggablePixmapItem *addMapEvent(Event *event);
void selectMapEvent(DraggablePixmapItem *object);
void selectMapEvent(DraggablePixmapItem *object, bool toggle);
DraggablePixmapItem *addNewEvent(QString event_type);
void deleteEvent(Event *);
DraggablePixmapItem* addMapEvent(Event* event);
void selectMapEvent(DraggablePixmapItem* object);
void selectMapEvent(DraggablePixmapItem* object, bool toggle);
DraggablePixmapItem* addNewEvent(QString event_type);
void deleteEvent(Event*);
void updateSelectedEvents();
void duplicateSelectedEvents();
void redrawObject(DraggablePixmapItem *item);
QList<DraggablePixmapItem *> getObjects();
void redrawObject(DraggablePixmapItem* item);
QList<DraggablePixmapItem*> getObjects();
QGraphicsScene *scene = nullptr;
QGraphicsPixmapItem *current_view = nullptr;
MapPixmapItem *map_item = nullptr;
QGraphicsScene* scene = nullptr;
QGraphicsPixmapItem* current_view = nullptr;
MapPixmapItem* map_item = nullptr;
ConnectionPixmapItem* selected_connection_item = nullptr;
QList<QGraphicsPixmapItem*> connection_items;
QList<ConnectionPixmapItem*> connection_edit_items;
QGraphicsPathItem *connection_mask = nullptr;
CollisionPixmapItem *collision_item = nullptr;
QGraphicsItemGroup *events_group = nullptr;
QGraphicsPathItem* connection_mask = nullptr;
CollisionPixmapItem* collision_item = nullptr;
QGraphicsItemGroup* events_group = nullptr;
QList<QGraphicsPixmapItem*> borderItems;
QList<QGraphicsLineItem*> gridLines;
MovableRect *playerViewRect = nullptr;
CursorTileRect *cursorMapTileRect = nullptr;
MapRuler *map_ruler = nullptr;
MovableRect* playerViewRect = nullptr;
CursorTileRect* cursorMapTileRect = nullptr;
MapRuler* map_ruler = nullptr;
QGraphicsScene *scene_metatiles = nullptr;
QGraphicsScene *scene_current_metatile_selection = nullptr;
QGraphicsScene *scene_selected_border_metatiles = nullptr;
QGraphicsScene *scene_collision_metatiles = nullptr;
QGraphicsScene *scene_elevation_metatiles = nullptr;
MetatileSelector *metatile_selector_item = nullptr;
QGraphicsScene* scene_metatiles = nullptr;
QGraphicsScene* scene_current_metatile_selection = nullptr;
QGraphicsScene* scene_selected_border_metatiles = nullptr;
QGraphicsScene* scene_collision_metatiles = nullptr;
QGraphicsScene* scene_elevation_metatiles = nullptr;
MetatileSelector* metatile_selector_item = nullptr;
BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem *current_metatile_selection_item = nullptr;
MovementPermissionsSelector *movement_permissions_selector_item = nullptr;
BorderMetatilesPixmapItem* selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem* current_metatile_selection_item = nullptr;
MovementPermissionsSelector* movement_permissions_selector_item = nullptr;
QList<DraggablePixmapItem*> *events = nullptr;
QList<DraggablePixmapItem*> *selected_events = nullptr;
QList<DraggablePixmapItem*>* events = nullptr;
QList<DraggablePixmapItem*>* selected_events = nullptr;
QString map_edit_mode = "paint";
QString obj_edit_mode = "select";
@ -139,7 +138,7 @@ public:
double scale_base = sqrt(2); // adjust scale factor with this
qreal collisionOpacity = 0.5;
void objectsView_onMousePress(QMouseEvent *event);
void objectsView_onMousePress(QMouseEvent* event);
int getBorderDrawDistance(int dimension);
@ -149,11 +148,11 @@ public:
void shouldReselectEvents();
void scaleMapView(int);
void openInTextEditor(const QString &path, int lineNum = 0) const;
void openInTextEditor(const QString& path, int lineNum = 0) const;
public slots:
void openMapScripts() const;
void openScript(const QString &scriptLabel) const;
void openScript(const QString& scriptLabel) const;
void openProjectInTextEditor() const;
void maskNonVisibleConnectionTiles();
@ -175,18 +174,16 @@ private:
void updateEncounterFields(EncounterFields newFields);
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
QString getMetatileDisplayMessage(uint16_t metatileId);
bool eventLimitReached(Map *, QString);
bool startDetachedProcess(const QString &command,
const QString &workingDirectory = QString(),
qint64 *pid = nullptr) const;
bool eventLimitReached(Map*, QString);
bool startDetachedProcess(const QString& command, const QString& workingDirectory = QString(), qint64* pid = nullptr) const;
private slots:
void onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
void onMapEndPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
void setSmartPathCursorMode(QGraphicsSceneMouseEvent *event);
void setStraightPathCursorMode(QGraphicsSceneMouseEvent *event);
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
void onMapStartPaint(QGraphicsSceneMouseEvent* event, MapPixmapItem* item);
void onMapEndPaint(QGraphicsSceneMouseEvent* event, MapPixmapItem* item);
void setSmartPathCursorMode(QGraphicsSceneMouseEvent* event);
void setStraightPathCursorMode(QGraphicsSceneMouseEvent* event);
void mouseEvent_map(QGraphicsSceneMouseEvent* event, MapPixmapItem* item);
void mouseEvent_collision(QGraphicsSceneMouseEvent* event, CollisionPixmapItem* item);
void onConnectionMoved(MapConnection*);
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
@ -196,7 +193,7 @@ private slots:
void onHoveredMovementPermissionCleared();
void onHoveredMetatileSelectionChanged(uint16_t);
void onHoveredMetatileSelectionCleared();
void onHoveredMapMetatileChanged(const QPoint &pos);
void onHoveredMapMetatileChanged(const QPoint& pos);
void onHoveredMapMetatileCleared();
void onHoveredMapMovementPermissionChanged(int, int);
void onHoveredMapMovementPermissionCleared();
@ -210,7 +207,7 @@ signals:
void wildMonDataChanged();
void warpEventDoubleClicked(QString mapName, QString warpNum);
void currentMetatilesSelectionChanged();
void mapRulerStatusChanged(const QString &);
void mapRulerStatusChanged(const QString&);
};
#endif // EDITOR_H

View file

@ -68,80 +68,90 @@
#include "orderedmap.h"
#ifdef _MSC_VER
#if _MSC_VER <= 1800 // VS 2013
#ifndef noexcept
#define noexcept throw()
#endif
#if _MSC_VER <= 1800 // VS 2013
#ifndef noexcept
#define noexcept throw()
#endif
#ifndef snprintf
#define snprintf _snprintf_s
#endif
#endif
#ifndef snprintf
#define snprintf _snprintf_s
#endif
#endif
#endif
namespace poryjson {
enum JsonParse {
STANDARD, COMMENTS
};
enum JsonParse { STANDARD, COMMENTS };
class JsonValue;
class Json final {
public:
// Types
enum Type {
NUL, NUMBER, BOOL, STRING, ARRAY, OBJECT
};
enum Type { NUL, NUMBER, BOOL, STRING, ARRAY, OBJECT };
// Array and object typedefs
typedef QVector<Json> array;
typedef tsl::ordered_map<QString, Json> object;
// Constructors for the various types of JSON value.
Json() noexcept; // NUL
Json(std::nullptr_t) noexcept; // NUL
Json(double value); // NUMBER
Json(int value); // NUMBER
Json(bool value); // BOOL
Json(const QString &value); // STRING
Json(QString &&value); // STRING
Json(const char * value); // STRING
Json(const array &values); // ARRAY
Json(array &&values); // ARRAY
Json(const object &values); // OBJECT
Json(object &&values); // OBJECT
Json() noexcept; // NUL
Json(std::nullptr_t) noexcept; // NUL
Json(double value); // NUMBER
Json(int value); // NUMBER
Json(bool value); // BOOL
Json(const QString& value); // STRING
Json(QString&& value); // STRING
Json(const char* value); // STRING
Json(const array& values); // ARRAY
Json(array&& values); // ARRAY
Json(const object& values); // OBJECT
Json(object&& values); // OBJECT
// Implicit constructor: anything with a to_json() function.
template <class T, class = decltype(&T::to_json)>
Json(const T & t) : Json(t.to_json()) {}
template <class T, class = decltype(&T::to_json)> Json(const T& t) : Json(t.to_json()) {
}
// Implicit constructor: map-like objects (std::map, std::unordered_map, etc)
template <class M, typename std::enable_if<
std::is_constructible<QString, decltype(std::declval<M>().begin()->first)>::value
&& std::is_constructible<Json, decltype(std::declval<M>().begin()->second)>::value,
int>::type = 0>
Json(const M & m) : Json(object(m.begin(), m.end())) {}
template <class M, typename std::enable_if<std::is_constructible<QString, decltype(std::declval<M>().begin()->first)>::value
&& std::is_constructible<Json, decltype(std::declval<M>().begin()->second)>::value,
int>::type
= 0>
Json(const M& m)
: Json(object(m.begin(), m.end())) {
}
// Implicit constructor: vector-like objects (std::list, std::vector, std::set, etc)
template <class V, typename std::enable_if<
std::is_constructible<Json, decltype(*std::declval<V>().begin())>::value,
int>::type = 0>
Json(const V & v) : Json(array(v.begin(), v.end())) {}
template <class V, typename std::enable_if<std::is_constructible<Json, decltype(*std::declval<V>().begin())>::value, int>::type = 0>
Json(const V& v)
: Json(array(v.begin(), v.end())) {
}
// This prevents Json(some_pointer) from accidentally producing a bool. Use
// Json(bool(some_pointer)) if that behavior is desired.
Json(void *) = delete;
Json(void*) = delete;
// Accessors
Type type() const;
bool is_null() const { return type() == NUL; }
bool is_number() const { return type() == NUMBER; }
bool is_bool() const { return type() == BOOL; }
bool is_string() const { return type() == STRING; }
bool is_array() const { return type() == ARRAY; }
bool is_object() const { return type() == OBJECT; }
bool is_null() const {
return type() == NUL;
}
bool is_number() const {
return type() == NUMBER;
}
bool is_bool() const {
return type() == BOOL;
}
bool is_string() const {
return type() == STRING;
}
bool is_array() const {
return type() == ARRAY;
}
bool is_object() const {
return type() == OBJECT;
}
// Return the enclosed value if this is a number, 0 otherwise. Note that poryjson does not
// distinguish between integer and non-integer numbers - number_value() and int_value()
@ -152,20 +162,20 @@ public:
// Return the enclosed value if this is a boolean, false otherwise.
bool bool_value() const;
// Return the enclosed string if this is a string, "" otherwise.
const QString &string_value() const;
const QString& string_value() const;
// Return the enclosed std::vector if this is an array, or an empty vector otherwise.
const array &array_items() const;
const array& array_items() const;
// Return the enclosed std::map if this is an object, or an empty map otherwise.
const object &object_items() const;
const object& object_items() const;
// Return a reference to arr[i] if this is an array, Json() otherwise.
const Json & operator[](int i) const;
const Json& operator[](int i) const;
// Return a reference to obj[key] if this is an object, Json() otherwise.
const Json & operator[](const QString &key) const;
const Json& operator[](const QString& key) const;
// Serialize.
void dump(QString &out, int *) const;
QString dump(int *indent = nullptr) const {
void dump(QString& out, int*) const;
QString dump(int* indent = nullptr) const {
QString out;
if (!indent) {
int temp = 0;
@ -176,12 +186,8 @@ public:
}
// Parse. If parse fails, return Json() and assign an error message to err.
static Json parse(const QString & in,
QString & err,
JsonParse strategy = JsonParse::STANDARD);
static Json parse(const char * in,
QString & err,
JsonParse strategy = JsonParse::STANDARD) {
static Json parse(const QString& in, QString& err, JsonParse strategy = JsonParse::STANDARD);
static Json parse(const char* in, QString& err, JsonParse strategy = JsonParse::STANDARD) {
if (in) {
return parse(QString(in), err, strategy);
} else {
@ -190,12 +196,20 @@ public:
}
}
bool operator== (const Json &rhs) const;
bool operator< (const Json &rhs) const;
bool operator!= (const Json &rhs) const { return !(*this == rhs); }
bool operator<= (const Json &rhs) const { return !(rhs < *this); }
bool operator> (const Json &rhs) const { return (rhs < *this); }
bool operator>= (const Json &rhs) const { return !(*this < rhs); }
bool operator==(const Json& rhs) const;
bool operator<(const Json& rhs) const;
bool operator!=(const Json& rhs) const {
return !(*this == rhs);
}
bool operator<=(const Json& rhs) const {
return !(rhs < *this);
}
bool operator>(const Json& rhs) const {
return (rhs < *this);
}
bool operator>=(const Json& rhs) const {
return !(*this < rhs);
}
private:
std::shared_ptr<JsonValue> m_ptr;
@ -203,19 +217,19 @@ private:
class JsonDoc {
public:
JsonDoc(Json *object) {
JsonDoc(Json* object) {
this->m_obj = object;
this->m_indent = 0;
};
void dump(QFile *file) {
void dump(QFile* file) {
QTextStream fileStream(file);
fileStream << m_obj->dump(&m_indent);
fileStream << "\n"; // pad file with newline
}
private:
Json *m_obj;
Json* m_obj;
int m_indent;
};
@ -226,18 +240,19 @@ protected:
friend class JsonInt;
friend class JsonDouble;
virtual Json::Type type() const = 0;
virtual bool equals(const JsonValue * other) const = 0;
virtual bool less(const JsonValue * other) const = 0;
virtual void dump(QString &out, int *indent) const = 0;
virtual bool equals(const JsonValue* other) const = 0;
virtual bool less(const JsonValue* other) const = 0;
virtual void dump(QString& out, int* indent) const = 0;
virtual double number_value() const;
virtual int int_value() const;
virtual bool bool_value() const;
virtual const QString &string_value() const;
virtual const Json::array &array_items() const;
virtual const Json &operator[](int i) const;
virtual const Json::object &object_items() const;
virtual const Json &operator[](const QString &key) const;
virtual ~JsonValue() {}
virtual const QString& string_value() const;
virtual const Json::array& array_items() const;
virtual const Json& operator[](int i) const;
virtual const Json::object& object_items() const;
virtual const Json& operator[](const QString& key) const;
virtual ~JsonValue() {
}
};
} // namespace poryjson

File diff suppressed because it is too large Load diff

View file

@ -10,11 +10,11 @@
// a key in a std::hash structure. Qt 5.14 added this function, so
// this file should only be included in earlier versions.
namespace std {
template<> struct hash<QString> {
template <> struct hash<QString> {
std::size_t operator()(const QString& s) const noexcept {
return static_cast<size_t>(qHash(s));
return static_cast<size_t>(qHash(s));
}
};
};
}
#endif // QSTRINGHASH_H

View file

@ -29,17 +29,16 @@ namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent);
explicit MainWindow(QWidget* parent);
~MainWindow();
MainWindow() = delete;
MainWindow(const MainWindow &) = delete;
MainWindow & operator = (const MainWindow &) = delete;
MainWindow(const MainWindow&) = delete;
MainWindow& operator=(const MainWindow&) = delete;
// Scripting API
Q_INVOKABLE QJSValue getBlock(int x, int y);
@ -71,20 +70,20 @@ public:
Q_INVOKABLE void addRect(int x, int y, int width, int height, QString color = "#000000");
Q_INVOKABLE void addFilledRect(int x, int y, int width, int height, QString color = "#000000");
Q_INVOKABLE void addImage(int x, int y, QString filepath);
void refreshAfterPaletteChange(Tileset *tileset);
void setTilesetPalette(Tileset *tileset, int paletteIndex, QList<QList<int>> colors);
void refreshAfterPaletteChange(Tileset* tileset);
void setTilesetPalette(Tileset* tileset, int paletteIndex, QList<QList<int>> colors);
Q_INVOKABLE void setPrimaryTilesetPalette(int paletteIndex, QList<QList<int>> colors);
Q_INVOKABLE void setPrimaryTilesetPalettes(QList<QList<QList<int>>> palettes);
Q_INVOKABLE void setSecondaryTilesetPalette(int paletteIndex, QList<QList<int>> colors);
Q_INVOKABLE void setSecondaryTilesetPalettes(QList<QList<QList<int>>> palettes);
QJSValue getTilesetPalette(const QList<QList<QRgb>> &palettes, int paletteIndex);
QJSValue getTilesetPalettes(const QList<QList<QRgb>> &palettes);
QJSValue getTilesetPalette(const QList<QList<QRgb>>& palettes, int paletteIndex);
QJSValue getTilesetPalettes(const QList<QList<QRgb>>& palettes);
Q_INVOKABLE QJSValue getPrimaryTilesetPalette(int paletteIndex);
Q_INVOKABLE QJSValue getPrimaryTilesetPalettes();
Q_INVOKABLE QJSValue getSecondaryTilesetPalette(int paletteIndex);
Q_INVOKABLE QJSValue getSecondaryTilesetPalettes();
void refreshAfterPalettePreviewChange();
void setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QList<QList<int>> colors);
void setTilesetPalettePreview(Tileset* tileset, int paletteIndex, QList<QList<int>> colors);
Q_INVOKABLE void setPrimaryTilesetPalettePreview(int paletteIndex, QList<QList<int>> colors);
Q_INVOKABLE void setPrimaryTilesetPalettesPreview(QList<QList<QList<int>>> palettes);
Q_INVOKABLE void setSecondaryTilesetPalettePreview(int paletteIndex, QList<QList<int>> colors);
@ -115,21 +114,21 @@ public:
private slots:
void on_action_Open_Project_triggered();
void on_action_Reload_Project_triggered();
void on_mapList_activated(const QModelIndex &index);
void on_mapList_activated(const QModelIndex& index);
void on_action_Save_Project_triggered();
void openWarpMap(QString map_name, QString warp_num);
void duplicate();
void onLoadMapRequested(QString, QString);
void onMapChanged(Map *map);
void onMapChanged(Map* map);
void onMapNeedsRedrawing();
void onTilesetsSaved(QString, QString);
void onWildMonDataChanged();
void openNewMapPopupWindow(int, QVariant);
void onNewMapCreated();
void onMapCacheCleared();
void onMapRulerStatusChanged(const QString &);
void onMapRulerStatusChanged(const QString&);
void applyUserShortcuts();
void on_action_NewMap_triggered();
@ -137,11 +136,11 @@ private slots:
void on_action_Save_triggered();
void on_tabWidget_2_currentChanged(int index);
void on_action_Exit_triggered();
void on_comboBox_Song_currentTextChanged(const QString &arg1);
void on_comboBox_Location_currentTextChanged(const QString &arg1);
void on_comboBox_Weather_currentTextChanged(const QString &arg1);
void on_comboBox_Type_currentTextChanged(const QString &arg1);
void on_comboBox_BattleScene_currentTextChanged(const QString &arg1);
void on_comboBox_Song_currentTextChanged(const QString& arg1);
void on_comboBox_Location_currentTextChanged(const QString& arg1);
void on_comboBox_Weather_currentTextChanged(const QString& arg1);
void on_comboBox_Type_currentTextChanged(const QString& arg1);
void on_comboBox_BattleScene_currentTextChanged(const QString& arg1);
void on_checkBox_ShowLocation_clicked(bool checked);
void on_checkBox_AllowRunning_clicked(bool checked);
void on_checkBox_AllowBiking_clicked(bool checked);
@ -179,7 +178,7 @@ private slots:
void on_toolButton_Move_clicked();
void on_toolButton_Shift_clicked();
void onOpenMapListContextMenu(const QPoint &point);
void onOpenMapListContextMenu(const QPoint& point);
void onAddNewMapToGroupClick(QAction* triggeredAction);
void onAddNewMapToAreaClick(QAction* triggeredAction);
void onAddNewMapToLayoutClick(QAction* triggeredAction);
@ -189,15 +188,15 @@ private slots:
void on_actionExport_Stitched_Map_Image_triggered();
void on_actionExport_Map_Timelapse_Image_triggered();
void on_comboBox_ConnectionDirection_currentIndexChanged(const QString &arg1);
void on_comboBox_ConnectionDirection_currentIndexChanged(const QString& arg1);
void on_spinBox_ConnectionOffset_valueChanged(int offset);
void on_comboBox_ConnectedMap_currentTextChanged(const QString &mapName);
void on_comboBox_ConnectedMap_currentTextChanged(const QString& mapName);
void on_pushButton_AddConnection_clicked();
void on_pushButton_RemoveConnection_clicked();
void on_comboBox_DiveMap_currentTextChanged(const QString &mapName);
void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName);
void on_comboBox_PrimaryTileset_currentTextChanged(const QString &arg1);
void on_comboBox_SecondaryTileset_currentTextChanged(const QString &arg1);
void on_comboBox_DiveMap_currentTextChanged(const QString& mapName);
void on_comboBox_EmergeMap_currentTextChanged(const QString& mapName);
void on_comboBox_PrimaryTileset_currentTextChanged(const QString& arg1);
void on_comboBox_SecondaryTileset_currentTextChanged(const QString& arg1);
void on_pushButton_ChangeDimensions_clicked();
void on_checkBox_smartPaths_stateChanged(int selected);
void on_checkBox_Visibility_clicked(bool checked);
@ -207,12 +206,12 @@ private slots:
void on_actionTileset_Editor_triggered();
void mapSortOrder_changed(QAction *action);
void mapSortOrder_changed(QAction* action);
void on_lineEdit_filterBox_textChanged(const QString &arg1);
void on_lineEdit_filterBox_textChanged(const QString& arg1);
void moveEvent(QMoveEvent *event);
void closeEvent(QCloseEvent *);
void moveEvent(QMoveEvent* event);
void closeEvent(QCloseEvent*);
void eventTabChanged(int index);
@ -237,41 +236,41 @@ private slots:
void togglePreferenceSpecificUi();
private:
Ui::MainWindow *ui;
QLabel *label_MapRulerStatus = nullptr;
Ui::MainWindow* ui;
QLabel* label_MapRulerStatus = nullptr;
QPointer<TilesetEditor> tilesetEditor = nullptr;
QPointer<RegionMapEditor> regionMapEditor = nullptr;
QPointer<ShortcutsEditor> shortcutsEditor = nullptr;
QPointer<MapImageExporter> mapImageExporter = nullptr;
QPointer<NewMapPopup> newmapprompt = nullptr;
QPointer<PreferenceEditor> preferenceEditor = nullptr;
FilterChildrenProxyModel *mapListProxyModel;
QStandardItemModel *mapListModel;
QList<QStandardItem*> *mapGroupItemsList;
FilterChildrenProxyModel* mapListProxyModel;
QStandardItemModel* mapListModel;
QList<QStandardItem*>* mapGroupItemsList;
QMap<QString, QModelIndex> mapListIndexes;
Editor *editor = nullptr;
Editor* editor = nullptr;
QIcon* mapIcon;
QIcon* mapEditedIcon;
QIcon* mapOpenedIcon;
QAction *undoAction;
QAction *redoAction;
QAction* undoAction;
QAction* redoAction;
QWidget *eventTabObjectWidget;
QWidget *eventTabWarpWidget;
QWidget *eventTabTriggerWidget;
QWidget *eventTabBGWidget;
QWidget *eventTabHealspotWidget;
QWidget *eventTabMultipleWidget;
QWidget* eventTabObjectWidget;
QWidget* eventTabWarpWidget;
QWidget* eventTabTriggerWidget;
QWidget* eventTabBGWidget;
QWidget* eventTabHealspotWidget;
QWidget* eventTabMultipleWidget;
DraggablePixmapItem *selectedObject;
DraggablePixmapItem *selectedWarp;
DraggablePixmapItem *selectedTrigger;
DraggablePixmapItem *selectedBG;
DraggablePixmapItem *selectedHealspot;
DraggablePixmapItem* selectedObject;
DraggablePixmapItem* selectedWarp;
DraggablePixmapItem* selectedTrigger;
DraggablePixmapItem* selectedBG;
DraggablePixmapItem* selectedHealspot;
QList<QAction *> registeredActions;
QVector<QToolButton *> openScriptButtons;
QList<QAction*> registeredActions;
QVector<QToolButton*> openScriptButtons;
bool isProgrammaticEventTabChange;
bool projectHasUnsavedChanges;
@ -292,7 +291,7 @@ private:
void setRecentMap(QString map_name);
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
void drawMapListIcons(QAbstractItemModel *model);
void drawMapListIcons(QAbstractItemModel* model);
void updateMapList();
void displayMapProperties();
@ -316,7 +315,7 @@ private:
void setTheme(QString);
bool openRecentProject();
void updateTilesetEditor();
QString getEventGroupFromTabWidget(QWidget *tab);
QString getEventGroupFromTabWidget(QWidget* tab);
void closeSupplementaryWindows();
void setWindowDisabled(bool);
@ -334,7 +333,7 @@ private:
enum MapListUserRoles {
GroupRole = Qt::UserRole + 1, // Used to hold the map group number.
TypeRole, // Used to differentiate between the different layers of the map list tree view.
TypeRole, // Used to differentiate between the different layers of the map list tree view.
TypeRole2, // Used for various extra data needed.
};

View file

@ -21,17 +21,18 @@
static QString NONE_MAP_CONSTANT = "MAP_NONE";
static QString NONE_MAP_NAME = "None";
class Project : public QObject
{
class Project : public QObject {
Q_OBJECT
public:
Project(QWidget *parent = nullptr);
Project(QWidget* parent = nullptr);
~Project();
Project(const Project &) = delete;
Project & operator = (const Project &) = delete;
Project(const Project&) = delete;
Project& operator=(const Project&) = delete;
inline QWidget *parentWidget() const { return static_cast<QWidget *>(parent()); }
inline QWidget* parentWidget() const {
return static_cast<QWidget*>(parent());
}
public:
QString root;
@ -76,8 +77,7 @@ public:
void clearMapCache();
void clearTilesetCache();
struct DataQualifiers
{
struct DataQualifiers {
bool isStatic;
bool isConst;
};
@ -89,7 +89,7 @@ public:
Map* getMap(QString);
QMap<QString, Tileset*> tilesetCache;
Tileset* loadTileset(QString, Tileset *tileset = nullptr);
Tileset* loadTileset(QString, Tileset* tileset = nullptr);
Tileset* getTileset(QString, bool forceLoad = false);
QMap<QString, QStringList> tilesetLabels;
@ -131,7 +131,7 @@ public:
void saveLayoutBlockdata(Map*);
void saveLayoutBorder(Map*);
void writeBlockdata(QString, const Blockdata &);
void writeBlockdata(QString, const Blockdata&);
void saveAllMaps();
void saveMap(Map*);
void saveAllDataStructures();
@ -177,12 +177,12 @@ public:
QString getScriptFileExtension(bool usePoryScript) const;
QString getScriptDefaultString(bool usePoryScript, QString mapName) const;
QString getMapScriptsFilePath(const QString &mapName) const;
QString getMapScriptsFilePath(const QString& mapName) const;
QStringList getEventScriptsFilePaths() const;
bool loadMapBorder(Map *map);
bool loadMapBorder(Map* map);
void saveMapHealEvents(Map *map);
void saveMapHealEvents(Map* map);
static int getNumTilesPrimary();
static int getNumTilesTotal();
@ -205,9 +205,9 @@ private:
void setNewMapHeader(Map* map, int mapIndex);
void setNewMapLayout(Map* map);
void setNewMapBlockdata(Map* map);
void setNewMapBorder(Map *map);
void setNewMapEvents(Map *map);
void setNewMapConnections(Map *map);
void setNewMapBorder(Map* map);
void setNewMapEvents(Map* map);
void setNewMapConnections(Map* map);
void ignoreWatchedFileTemporarily(QString filepath);

View file

@ -15,14 +15,13 @@ enum CallbackType {
OnMapOpened,
};
class Scripting
{
class Scripting {
public:
Scripting(MainWindow *mainWindow);
Scripting(MainWindow* mainWindow);
static QJSValue fromBlock(Block block);
static QJSValue dimensions(int width, int height);
static QJSEngine *getEngine();
static void init(MainWindow *mainWindow);
static QJSEngine* getEngine();
static void init(MainWindow* mainWindow);
static void registerAction(QString functionName, QString actionName);
static int numRegisteredActions();
static void invokeAction(QString actionName);
@ -32,7 +31,7 @@ public:
static void cb_MapOpened(QString mapName);
private:
QJSEngine *engine;
QJSEngine* engine;
QStringList filepaths;
QList<QJSValue> modules;
QMap<QString, QString> registeredActions;

View file

@ -4,8 +4,7 @@
#include <QCursor>
class Settings
{
class Settings {
public:
Settings();
bool smartPathsEnabled;

View file

@ -7,13 +7,13 @@ namespace Ui {
class AboutPorymap;
}
class AboutPorymap : public QMainWindow
{
class AboutPorymap : public QMainWindow {
public:
explicit AboutPorymap(QWidget *parent = nullptr);
explicit AboutPorymap(QWidget* parent = nullptr);
~AboutPorymap();
private:
Ui::AboutPorymap *ui;
Ui::AboutPorymap* ui;
};
#endif // ABOUTPORYMAP_H

View file

@ -3,14 +3,12 @@
#include <QStackedWidget>
class AdjustingStackedWidget : public QStackedWidget
{
class AdjustingStackedWidget : public QStackedWidget {
Q_OBJECT
public:
AdjustingStackedWidget(QWidget *parent = nullptr) : QStackedWidget(parent) {}
AdjustingStackedWidget(QWidget* parent = nullptr) : QStackedWidget(parent) {
}
// override this to allow the stacked widget's current page to dictate size
virtual void setCurrentIndex(int index) {
@ -18,7 +16,7 @@ public:
for (int i = 0; i < this->count(); ++i) {
this->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
}
this->widget(index)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->widget(index)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
};

View file

@ -8,17 +8,18 @@
class BorderMetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
BorderMetatilesPixmapItem(Map *map_, MetatileSelector *metatileSelector) {
BorderMetatilesPixmapItem(Map* map_, MetatileSelector* metatileSelector) {
this->map = map_;
this->map->setBorderItem(this);
this->metatileSelector = metatileSelector;
setAcceptHoverEvents(true);
}
MetatileSelector *metatileSelector;
Map *map;
MetatileSelector* metatileSelector;
Map* map;
void draw();
signals:
void borderMetatilesChanged();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
};

View file

@ -14,13 +14,13 @@ private:
using QGraphicsPixmapItem::paint;
public:
CityMapPixmapItem(QString fname, TilemapTileSelector *tile_selector) {
CityMapPixmapItem(QString fname, TilemapTileSelector* tile_selector) {
this->file = fname;
this->tile_selector = tile_selector;
setAcceptHoverEvents(true);
init();
}
TilemapTileSelector *tile_selector;
TilemapTileSelector* tile_selector;
QString file;
@ -29,7 +29,7 @@ public:
void init();
void save();
void create(QString);
virtual void paint(QGraphicsSceneMouseEvent *);
virtual void paint(QGraphicsSceneMouseEvent*);
virtual void draw();
int getIndexAt(int, int);
int width();
@ -43,7 +43,7 @@ private:
int height_;
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, CityMapPixmapItem *);
void mouseEvent(QGraphicsSceneMouseEvent*, CityMapPixmapItem*);
void hoveredRegionMapTileChanged(int x, int y);
void hoveredRegionMapTileCleared();

View file

@ -10,15 +10,16 @@
class CollisionPixmapItem : public MapPixmapItem {
Q_OBJECT
public:
CollisionPixmapItem(Map *map, MovementPermissionsSelector *movementPermissionsSelector, MetatileSelector *metatileSelector, Settings *settings, qreal *opacity)
: MapPixmapItem(map, metatileSelector, settings){
CollisionPixmapItem(
Map* map, MovementPermissionsSelector* movementPermissionsSelector, MetatileSelector* metatileSelector, Settings* settings, qreal* opacity)
: MapPixmapItem(map, metatileSelector, settings) {
this->movementPermissionsSelector = movementPermissionsSelector;
this->opacity = opacity;
map->setCollisionItem(this);
}
MovementPermissionsSelector *movementPermissionsSelector;
qreal *opacity;
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event);
MovementPermissionsSelector* movementPermissionsSelector;
qreal* opacity;
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent* event);
virtual void paint(QGraphicsSceneMouseEvent*);
virtual void floodFill(QGraphicsSceneMouseEvent*);
virtual void magicFill(QGraphicsSceneMouseEvent*);
@ -29,7 +30,7 @@ private:
unsigned actionId_ = 0;
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
void mouseEvent(QGraphicsSceneMouseEvent*, CollisionPixmapItem*);
void hoveredMapMovementPermissionChanged(int, int);
void hoveredMapMovementPermissionCleared();

View file

@ -8,7 +8,7 @@
class ConnectionPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
ConnectionPixmapItem(QPixmap pixmap, MapConnection* connection, int x, int y, int baseMapWidth, int baseMapHeight): QGraphicsPixmapItem(pixmap) {
ConnectionPixmapItem(QPixmap pixmap, MapConnection* connection, int x, int y, int baseMapWidth, int baseMapHeight) : QGraphicsPixmapItem(pixmap) {
this->basePixmap = pixmap;
this->connection = connection;
setFlag(ItemIsMovable);
@ -31,7 +31,7 @@ public:
int getMaxOffset();
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
QVariant itemChange(GraphicsItemChange change, const QVariant& value);
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);

View file

@ -8,15 +8,17 @@
class CurrentSelectedMetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
CurrentSelectedMetatilesPixmapItem(Map *map, MetatileSelector *metatileSelector) {
CurrentSelectedMetatilesPixmapItem(Map* map, MetatileSelector* metatileSelector) {
this->map = map;
this->metatileSelector = metatileSelector;
}
Map* map = nullptr;
MetatileSelector *metatileSelector;
MetatileSelector* metatileSelector;
void draw();
void setMap(Map *map) { this->map = map; }
void setMap(Map* map) {
this->map = map;
}
};
#endif // CURRENTSELECTEDMETATILESPIXMAPITEM_H

View file

@ -5,12 +5,10 @@
#include <QPainter>
#include <QRgb>
class CursorTileRect : public QGraphicsItem
{
class CursorTileRect : public QGraphicsItem {
public:
CursorTileRect(bool *enabled, QRgb color);
QRectF boundingRect() const override
{
CursorTileRect(bool* enabled, QRgb color);
QRectF boundingRect() const override {
int width = this->width;
int height = this->height;
if (this->singleTileMode) {
@ -21,15 +19,12 @@ public:
height = 32;
}
qreal penWidth = 4;
return QRectF(-penWidth,
-penWidth,
width + penWidth * 2,
height + penWidth * 2);
return QRectF(-penWidth, -penWidth, width + penWidth * 2, height + penWidth * 2);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
if (!(*enabled)) return;
void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override {
if (!(*enabled))
return;
int width = this->width;
int height = this->height;
if (this->singleTileMode) {
@ -51,15 +46,20 @@ public:
void initRightClickSelectionAnchor(int coordX, int coordY);
void stopRightClickSelectionAnchor();
void setSmartPathMode(bool enable);
bool getSmartPathMode() { return this->smartPathMode; }
bool getSmartPathMode() {
return this->smartPathMode;
}
void setStraightPathMode(bool enable);
bool getStraightPathMode() { return this->straightPathMode; }
bool getStraightPathMode() {
return this->straightPathMode;
}
void setSingleTileMode();
void stopSingleTileMode();
void updateLocation(int x, int y);
void updateSelectionSize(int width, int height);
void setVisibility(bool visible);
bool *enabled;
bool* enabled;
private:
bool visible;
int width;
@ -77,5 +77,4 @@ private:
bool smartPathInEffect();
};
#endif // CURSORTILERECT_H

View file

@ -6,15 +6,14 @@
#include <QFrame>
#include <QTableWidget>
class CustomAttributesTable : public QFrame
{
class CustomAttributesTable : public QFrame {
public:
explicit CustomAttributesTable(Event *event, QWidget *parent = nullptr);
explicit CustomAttributesTable(Event* event, QWidget* parent = nullptr);
~CustomAttributesTable();
private:
Event *event;
QTableWidget *table;
Event* event;
QTableWidget* table;
void resizeVertically();
QMap<QString, QString> getTableFields();
};

View file

@ -15,18 +15,19 @@ class Editor;
class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {}
DraggablePixmapItem(Event *event_, Editor *editor_) : QGraphicsPixmapItem(event_->pixmap) {
DraggablePixmapItem(QPixmap pixmap) : QGraphicsPixmapItem(pixmap) {
}
DraggablePixmapItem(Event* event_, Editor* editor_) : QGraphicsPixmapItem(event_->pixmap) {
event = event_;
event->setPixmapItem(this);
editor = editor_;
updatePosition();
}
Editor *editor = nullptr;
Event *event = nullptr;
QGraphicsItemAnimation *pos_anim = nullptr;
Editor* editor = nullptr;
Event* event = nullptr;
QGraphicsItemAnimation* pos_anim = nullptr;
bool active;
int last_x;
@ -36,11 +37,11 @@ public:
void move(int x, int y);
void emitPositionChanged();
void updatePixmap();
void bind(QComboBox *combo, QString key);
void bindToUserData(QComboBox *combo, QString key);
void bind(QComboBox* combo, QString key);
void bindToUserData(QComboBox* combo, QString key);
signals:
void positionChanged(Event *event);
void positionChanged(Event* event);
void xChanged(int);
void yChanged(int);
void elevationChanged(int);
@ -48,23 +49,23 @@ signals:
void onPropertyChanged(QString key, QString value);
public slots:
void set_x(const QString &text) {
void set_x(const QString& text) {
event->put("x", text);
updatePosition();
}
void set_y(const QString &text) {
void set_y(const QString& text) {
event->put("y", text);
updatePosition();
}
void set_elevation(const QString &text) {
void set_elevation(const QString& text) {
event->put("elevation", text);
updatePosition();
}
void set_sprite(const QString &text) {
void set_sprite(const QString& text) {
event->put("sprite", text);
updatePixmap();
}
void set_script(const QString &text) {
void set_script(const QString& text) {
event->put("script_label", text);
}

View file

@ -9,20 +9,19 @@ namespace Ui {
class EventPropertiesFrame;
}
class EventPropertiesFrame : public QFrame
{
class EventPropertiesFrame : public QFrame {
Q_OBJECT
public:
explicit EventPropertiesFrame(Event *event, QWidget *parent = nullptr);
explicit EventPropertiesFrame(Event* event, QWidget* parent = nullptr);
~EventPropertiesFrame();
void paintEvent(QPaintEvent*);
public:
Ui::EventPropertiesFrame *ui;
Ui::EventPropertiesFrame* ui;
private:
Event *event;
Event* event;
bool firstShow = true;
};

View file

@ -3,15 +3,14 @@
#include <QSortFilterProxyModel>
class FilterChildrenProxyModel : public QSortFilterProxyModel
{
class FilterChildrenProxyModel : public QSortFilterProxyModel {
Q_OBJECT
public:
explicit FilterChildrenProxyModel(QObject *parent = nullptr);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
explicit FilterChildrenProxyModel(QObject* parent = nullptr);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
};
#endif // FILTERCHILDRENPROXYMODEL_H

View file

@ -4,32 +4,30 @@
#include <QLayout>
#include <QStyle>
class FlowLayout : public QLayout
{
class FlowLayout : public QLayout {
public:
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
explicit FlowLayout(QWidget* parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void addItem(QLayoutItem *item) override;
void addItem(QLayoutItem* item) override;
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const override;
bool hasHeightForWidth() const override;
int heightForWidth(int) const override;
int count() const override;
QLayoutItem *itemAt(int index) const override;
QLayoutItem* itemAt(int index) const override;
QSize minimumSize() const override;
void setGeometry(const QRect &rect) override;
void setGeometry(const QRect& rect) override;
QSize sizeHint() const override;
QLayoutItem *takeAt(int index) override;
QLayoutItem* takeAt(int index) override;
private:
int doLayout(const QRect &rect, bool testOnly) const;
int doLayout(const QRect& rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QList<QLayoutItem *> itemList;
QList<QLayoutItem*> itemList;
int horzSpace;
int vertSpace;
};

View file

@ -7,24 +7,26 @@
class Editor;
class GraphicsView : public QGraphicsView
{
class GraphicsView : public QGraphicsView {
public:
GraphicsView() : QGraphicsView() {}
GraphicsView(QWidget *parent) : QGraphicsView(parent) {}
GraphicsView() : QGraphicsView() {
}
GraphicsView(QWidget* parent) : QGraphicsView(parent) {
}
public:
// GraphicsView_Object object;
Editor *editor;
// GraphicsView_Object object;
Editor* editor;
Overlay overlay;
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void drawForeground(QPainter *painter, const QRectF &rect);
void moveEvent(QMoveEvent *event);
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void drawForeground(QPainter* painter, const QRectF& rect);
void moveEvent(QMoveEvent* event);
};
//Q_DECLARE_METATYPE(GraphicsView)
// Q_DECLARE_METATYPE(GraphicsView)
#endif // GRAPHICSVIEW_H

View file

@ -11,24 +11,11 @@ QImage getCollisionMetatileImage(int, int);
QImage getMetatileImage(uint16_t, Tileset*, Tileset*, QList<int>, QList<float>, bool useTruePalettes = false);
QImage getTileImage(uint16_t, Tileset*, Tileset*);
QImage getPalettedTileImage(uint16_t, Tileset*, Tileset*, int, bool useTruePalettes = false);
QImage getGreyscaleTileImage(uint16_t tile, Tileset *primaryTileset, Tileset *secondaryTileset);
QImage getGreyscaleTileImage(uint16_t tile, Tileset* primaryTileset, Tileset* secondaryTileset);
static QList<QRgb> greyscalePalette({
qRgb(0, 0, 0),
qRgb(16, 16, 16),
qRgb(32, 32, 32),
qRgb(48, 48, 48),
qRgb(64, 64, 64),
qRgb(80, 80, 80),
qRgb(96, 96, 96),
qRgb(112, 112, 112),
qRgb(128, 128, 128),
qRgb(144, 144, 144),
qRgb(160, 160, 160),
qRgb(176, 176, 176),
qRgb(192, 192, 192),
qRgb(208, 208, 208),
qRgb(224, 224, 224),
qRgb(0, 0, 0), qRgb(16, 16, 16), qRgb(32, 32, 32), qRgb(48, 48, 48), qRgb(64, 64, 64), qRgb(80, 80, 80), qRgb(96, 96, 96), qRgb(112, 112, 112),
qRgb(128, 128, 128), qRgb(144, 144, 144), qRgb(160, 160, 160), qRgb(176, 176, 176), qRgb(192, 192, 192), qRgb(208, 208, 208), qRgb(224, 224, 224),
qRgb(240, 240, 240),
});

View file

@ -16,20 +16,19 @@ enum ImageExporterMode {
Timelapse,
};
class MapImageExporter : public QDialog
{
class MapImageExporter : public QDialog {
Q_OBJECT
public:
explicit MapImageExporter(QWidget *parent, Editor *editor, ImageExporterMode mode);
explicit MapImageExporter(QWidget* parent, Editor* editor, ImageExporterMode mode);
~MapImageExporter();
private:
Ui::MapImageExporter *ui;
Ui::MapImageExporter* ui;
Map *map = nullptr;
Editor *editor = nullptr;
QGraphicsScene *scene = nullptr;
Map* map = nullptr;
Editor* editor = nullptr;
QGraphicsScene* scene = nullptr;
QPixmap preview;
@ -51,9 +50,9 @@ private:
void updatePreview();
void saveImage();
QPixmap getStitchedImage(QProgressDialog *progress, bool includeBorder);
QPixmap getFormattedMapPixmap(Map *map, bool ignoreBorder);
bool historyItemAppliesToFrame(const QUndoCommand *command);
QPixmap getStitchedImage(QProgressDialog* progress, bool includeBorder);
QPixmap getFormattedMapPixmap(Map* map, bool ignoreBorder);
bool historyItemAppliesToFrame(const QUndoCommand* command);
private slots:
void on_checkBox_Objects_stateChanged(int state);

View file

@ -13,12 +13,8 @@ private:
using QGraphicsPixmapItem::paint;
public:
enum class PaintMode {
Disabled,
Metatiles,
EventObjects
};
MapPixmapItem(Map *map_, MetatileSelector *metatileSelector, Settings *settings) {
enum class PaintMode { Disabled, Metatiles, EventObjects };
MapPixmapItem(Map* map_, MetatileSelector* metatileSelector, Settings* settings) {
this->map = map_;
this->map->setMapItem(this);
this->metatileSelector = metatileSelector;
@ -29,9 +25,9 @@ public:
setAcceptHoverEvents(true);
}
MapPixmapItem::PaintMode paintingMode;
Map *map;
MetatileSelector *metatileSelector;
Settings *settings;
Map* map;
MetatileSelector* metatileSelector;
Settings* settings;
bool active;
bool has_mouse = false;
bool right_click;
@ -40,11 +36,7 @@ public:
bool prevStraightPathState;
int straight_path_initial_x;
int straight_path_initial_y;
enum Axis {
None = 0,
X,
Y
};
enum Axis { None = 0, X, Y };
MapPixmapItem::Axis lockedAxis;
QPoint selection_origin;
QList<QPoint> selection;
@ -53,30 +45,21 @@ public:
virtual void magicFill(QGraphicsSceneMouseEvent*);
void magicFill(int x, int y, uint16_t metatileId, bool fromScriptCall = false);
void magicFill(int x, int y, bool fromScriptCall = false);
void magicFill(
int initialX,
int initialY,
QPoint selectionDimensions,
QList<uint16_t> *selectedMetatiles,
QList<QPair<uint16_t, uint16_t>> *selectedCollisions,
bool fromScriptCall = false);
void magicFill(int initialX, int initialY, QPoint selectionDimensions, QList<uint16_t>* selectedMetatiles,
QList<QPair<uint16_t, uint16_t>>* selectedCollisions, bool fromScriptCall = false);
void floodFill(int x, int y, bool fromScriptCall = false);
void floodFill(int x, int y, uint16_t metatileId, bool fromScriptCall = false);
void floodFill(int initialX,
int initialY,
QPoint selectionDimensions,
QList<uint16_t> *selectedMetatiles,
QList<QPair<uint16_t, uint16_t>> *selectedCollisions,
bool fromScriptCall = false);
void floodFill(int initialX, int initialY, QPoint selectionDimensions, QList<uint16_t>* selectedMetatiles,
QList<QPair<uint16_t, uint16_t>>* selectedCollisions, bool fromScriptCall = false);
void floodFillSmartPath(int initialX, int initialY, bool fromScriptCall = false);
virtual void pick(QGraphicsSceneMouseEvent*);
virtual void select(QGraphicsSceneMouseEvent*);
virtual void shift(QGraphicsSceneMouseEvent*);
void shift(int xDelta, int yDelta, bool fromScriptCall = false);
virtual void draw(bool ignoreCache = false);
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
void updateMetatileSelection(QGraphicsSceneMouseEvent* event);
void paintNormal(int x, int y, bool fromScriptCall = false);
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
void lockNondominantAxis(QGraphicsSceneMouseEvent* event);
QPoint adjustCoords(QPoint pos);
private:
@ -86,10 +69,10 @@ private:
unsigned actionId_ = 0;
signals:
void startPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
void endPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *);
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
void hoveredMapMetatileChanged(const QPoint &pos);
void startPaint(QGraphicsSceneMouseEvent*, MapPixmapItem*);
void endPaint(QGraphicsSceneMouseEvent*, MapPixmapItem*);
void mouseEvent(QGraphicsSceneMouseEvent*, MapPixmapItem*);
void hoveredMapMetatileChanged(const QPoint& pos);
void hoveredMapMetatileCleared();
protected:

View file

@ -4,9 +4,7 @@
#include <QGraphicsObject>
#include <QLine>
class MapRuler : public QGraphicsObject, private QLine
{
class MapRuler : public QGraphicsObject, private QLine {
Q_OBJECT
public:
@ -15,35 +13,55 @@ public:
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;
bool eventFilter(QObject *, QEvent *event) override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override;
bool eventFilter(QObject*, QEvent* event) override;
bool isAnchored() const { return anchored; }
bool isLocked() const { return locked; }
bool isAnchored() const {
return anchored;
}
bool isLocked() const {
return locked;
}
// Ruler start point in metatiles
QPoint anchor() const { return QLine::p1(); }
QPoint anchor() const {
return QLine::p1();
}
// Ruler end point in metatiles
QPoint endPos() const { return QLine::p2(); }
QPoint endPos() const {
return QLine::p2();
}
// X-coordinate of the ruler's left edge in metatiles
int left() const { return qMin(anchor().x(), endPos().x()); }
int left() const {
return qMin(anchor().x(), endPos().x());
}
// Y-coordinate of the ruler's top edge in metatiles
int top() const { return qMin(anchor().y(), endPos().y()); }
int top() const {
return qMin(anchor().y(), endPos().y());
}
// Horizontal component of the ruler in metatiles
int deltaX() const { return QLine::dx(); }
int deltaX() const {
return QLine::dx();
}
// Vertical component of the ruler in metatiles
int deltaY() const { return QLine::dy(); }
int deltaY() const {
return QLine::dy();
}
// Ruler width in metatiles
int width() const { return qAbs(deltaX()); }
int width() const {
return qAbs(deltaX());
}
// Ruler height in metatiles
int height() const { return qAbs(deltaY()); }
int height() const {
return qAbs(deltaY());
}
public slots:
void mouseEvent(QGraphicsSceneMouseEvent *event);
void setMapDimensions(const QSize &size);
void mouseEvent(QGraphicsSceneMouseEvent* event);
void setMapDimensions(const QSize& size);
signals:
void statusChanged(const QString &statusMessage);
void statusChanged(const QString& statusMessage);
private:
const int thickness;
@ -58,13 +76,17 @@ private:
bool locked;
void reset();
void setAnchor(const QPointF &scenePos);
void setEndPos(const QPointF &scenePos);
void setAnchor(const QPointF& scenePos);
void setEndPos(const QPointF& scenePos);
QPoint snapToWithinBounds(QPoint pos) const;
void updateGeometry();
void updateStatus(Qt::Corner corner);
int pixWidth() const { return width() * 16; }
int pixHeight() const { return height() * 16; }
int pixWidth() const {
return width() * 16;
}
int pixHeight() const {
return height() * 16;
}
};
#endif // MAPRULER_H

View file

@ -3,13 +3,13 @@
#include <QObject>
class MapSceneEventFilter : public QObject
{
class MapSceneEventFilter : public QObject {
Q_OBJECT
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
bool eventFilter(QObject* obj, QEvent* event) override;
public:
explicit MapSceneEventFilter(QObject *parent = nullptr);
explicit MapSceneEventFilter(QObject* parent = nullptr);
signals:
void wheelZoom(int delta);

View file

@ -6,10 +6,10 @@
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneMouseEvent>
class MetatileLayersItem: public SelectablePixmapItem {
class MetatileLayersItem : public SelectablePixmapItem {
Q_OBJECT
public:
MetatileLayersItem(Metatile *metatile, Tileset *primaryTileset, Tileset *secondaryTileset): SelectablePixmapItem(16, 16, 6, 2) {
MetatileLayersItem(Metatile* metatile, Tileset* primaryTileset, Tileset* secondaryTileset) : SelectablePixmapItem(16, 16, 6, 2) {
this->metatile = metatile;
this->primaryTileset = primaryTileset;
this->secondaryTileset = secondaryTileset;
@ -19,15 +19,17 @@ public:
void setTilesets(Tileset*, Tileset*);
void setMetatile(Metatile*);
void clearLastModifiedCoords();
private:
Metatile* metatile;
Tileset *primaryTileset;
Tileset *secondaryTileset;
Tileset* primaryTileset;
Tileset* secondaryTileset;
QPoint prevChangedTile;
void getBoundedCoords(QPointF, int*, int*);
signals:
void tileChanged(int, int);
void selectedTilesChanged(QPoint, int, int);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);

View file

@ -7,10 +7,10 @@
#include "tileset.h"
#include "maplayout.h"
class MetatileSelector: public SelectablePixmapItem {
class MetatileSelector : public SelectablePixmapItem {
Q_OBJECT
public:
MetatileSelector(int numMetatilesWide, Map *map): SelectablePixmapItem(16, 16) {
MetatileSelector(int numMetatilesWide, Map* map) : SelectablePixmapItem(16, 16) {
this->externalSelection = false;
this->numMetatilesWide = numMetatilesWide;
this->map = map;
@ -31,23 +31,25 @@ public:
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
QPoint getMetatileIdCoordsOnWidget(uint16_t);
void setMap(Map*);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
private:
bool externalSelection;
int numMetatilesWide;
Map *map;
Tileset *primaryTileset;
Tileset *secondaryTileset;
QList<uint16_t> *selectedMetatiles;
QList<QPair<uint16_t, uint16_t>> *selectedCollisions;
Map* map;
Tileset* primaryTileset;
Tileset* secondaryTileset;
QList<uint16_t>* selectedMetatiles;
QList<QPair<uint16_t, uint16_t>>* selectedCollisions;
int externalSelectionWidth;
int externalSelectionHeight;
QList<uint16_t> *externalSelectedMetatiles;
QList<uint16_t>* externalSelectedMetatiles;
void updateSelectedMetatiles();
uint16_t getMetatileId(int x, int y);

View file

@ -13,29 +13,29 @@ class MonTabWidget : public QTabWidget {
Q_OBJECT
public:
explicit MonTabWidget(Editor *editor = nullptr, QWidget *parent = nullptr);
explicit MonTabWidget(Editor* editor = nullptr, QWidget* parent = nullptr);
~MonTabWidget(){};
void populate();
void populateTab(int tabIndex, WildMonInfo monInfo, QString fieldName);
void clear();
void createSpeciesTableRow(QTableWidget *table, WildPokemon mon, int index, QString fieldName);
void createSpeciesTableRow(QTableWidget* table, WildPokemon mon, int index, QString fieldName);
void clearTableAt(int index);
QTableWidget *tableAt(int tabIndex);
QTableWidget* tableAt(int tabIndex);
public slots:
void setTabActive(int index, bool active = true);
private:
bool eventFilter(QObject *object, QEvent *event);
bool eventFilter(QObject* object, QEvent* event);
void askActivateTab(int tabIndex, QPoint menuPos);
QVector<bool> activeTabs;
Editor *editor;
Editor* editor;
};
#endif // MONTABWIDGET_H

View file

@ -5,21 +5,15 @@
#include <QPainter>
#include <QRgb>
class MovableRect : public QGraphicsItem
{
class MovableRect : public QGraphicsItem {
public:
MovableRect(bool *enabled, int width, int height, QRgb color);
QRectF boundingRect() const override
{
MovableRect(bool* enabled, int width, int height, QRgb color);
QRectF boundingRect() const override {
qreal penWidth = 4;
return QRectF(-penWidth,
-penWidth,
30 * 8 + penWidth * 2,
20 * 8 + penWidth * 2);
return QRectF(-penWidth, -penWidth, 30 * 8 + penWidth * 2, 20 * 8 + penWidth * 2);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override {
painter->setPen(this->color);
painter->drawRect(-2, -2, this->width + 3, this->height + 3);
painter->setPen(QColor(0, 0, 0));
@ -27,7 +21,8 @@ public:
painter->drawRect(-1, -1, this->width + 1, this->height + 1);
}
void updateLocation(int x, int y);
bool *enabled;
bool* enabled;
private:
int width;
int height;

View file

@ -3,10 +3,10 @@
#include "selectablepixmapitem.h"
class MovementPermissionsSelector: public SelectablePixmapItem {
class MovementPermissionsSelector : public SelectablePixmapItem {
Q_OBJECT
public:
MovementPermissionsSelector(): SelectablePixmapItem(32, 32, 1, 1) {
MovementPermissionsSelector() : SelectablePixmapItem(32, 32, 1, 1) {
setAcceptHoverEvents(true);
}
void draw();

View file

@ -6,39 +6,37 @@
class QLineEdit;
// A collection of QKeySequenceEdit's laid out horizontally.
class MultiKeyEdit : public QWidget
{
class MultiKeyEdit : public QWidget {
Q_OBJECT
public:
MultiKeyEdit(QWidget *parent = nullptr, int fieldCount = 2);
MultiKeyEdit(QWidget* parent = nullptr, int fieldCount = 2);
bool eventFilter(QObject *watched, QEvent *event) override;
bool eventFilter(QObject* watched, QEvent* event) override;
int fieldCount() const;
void setFieldCount(int count);
QList<QKeySequence> keySequences() const;
bool removeOne(const QKeySequence &keySequence);
bool contains(const QKeySequence &keySequence) const;
bool removeOne(const QKeySequence& keySequence);
bool contains(const QKeySequence& keySequence) const;
void setContextMenuPolicy(Qt::ContextMenuPolicy policy);
bool isClearButtonEnabled() const;
void setClearButtonEnabled(bool enable);
public slots:
void clear();
void setKeySequences(const QList<QKeySequence> &keySequences);
void addKeySequence(const QKeySequence &keySequence);
void setKeySequences(const QList<QKeySequence>& keySequences);
void addKeySequence(const QKeySequence& keySequence);
signals:
void keySequenceChanged(const QKeySequence &keySequence);
void keySequenceChanged(const QKeySequence& keySequence);
void editingFinished();
void customContextMenuRequested(const QPoint &pos);
void customContextMenuRequested(const QPoint& pos);
private:
QVector<QKeySequenceEdit *> keySequenceEdit_vec;
QList<QKeySequence> keySequence_list; // Used to track changes
QVector<QKeySequenceEdit*> keySequenceEdit_vec;
QList<QKeySequence> keySequence_list; // Used to track changes
void addNewKeySequenceEdit();
void alignKeySequencesLeft();
@ -46,7 +44,7 @@ private:
private slots:
void onEditingFinished();
void showDefaultContextMenu(QLineEdit *lineEdit, const QPoint &pos);
void showDefaultContextMenu(QLineEdit* lineEdit, const QPoint& pos);
};
#endif // MULTIKEYEDIT_H

View file

@ -4,20 +4,19 @@
#include "event.h"
#include <QToolButton>
class NewEventToolButton : public QToolButton
{
class NewEventToolButton : public QToolButton {
Q_OBJECT
public:
explicit NewEventToolButton(QWidget *parent = nullptr);
explicit NewEventToolButton(QWidget* parent = nullptr);
QString getSelectedEventType();
QAction *newObjectAction;
QAction *newWarpAction;
QAction *newHealLocationAction;
QAction *newTriggerAction;
QAction *newWeatherTriggerAction;
QAction *newSignAction;
QAction *newHiddenItemAction;
QAction *newSecretBaseAction;
QAction* newObjectAction;
QAction* newWarpAction;
QAction* newHealLocationAction;
QAction* newTriggerAction;
QAction* newWeatherTriggerAction;
QAction* newSignAction;
QAction* newHiddenItemAction;
QAction* newSecretBaseAction;
public slots:
void newObject();
void newWarp();
@ -29,6 +28,7 @@ public slots:
void newSecretBase();
signals:
void newEventAdded(QString);
private:
QString selectedEventType;
void init();

View file

@ -11,13 +11,12 @@ namespace Ui {
class NewMapPopup;
}
class NewMapPopup : public QMainWindow
{
class NewMapPopup : public QMainWindow {
Q_OBJECT
public:
explicit NewMapPopup(QWidget *parent = nullptr, Project *project = nullptr);
explicit NewMapPopup(QWidget* parent = nullptr, Project* project = nullptr);
~NewMapPopup();
Map *map;
Map* map;
int group;
bool existingLayout;
QString layoutId;
@ -29,14 +28,14 @@ signals:
void applied();
private:
Ui::NewMapPopup *ui;
Project *project;
Ui::NewMapPopup* ui;
Project* project;
void setDefaultValues(int, QString);
bool checkNewMapDimensions();
private slots:
void on_pushButton_NewMap_Accept_clicked();
void on_lineEdit_NewMap_Name_textChanged(const QString &);
void on_lineEdit_NewMap_Name_textChanged(const QString&);
};
#endif // NEWMAPPOPUP_H

View file

@ -8,12 +8,11 @@ namespace Ui {
class NewTilesetDialog;
}
class NewTilesetDialog : public QDialog
{
class NewTilesetDialog : public QDialog {
Q_OBJECT
public:
explicit NewTilesetDialog(Project *project, QWidget *parent = nullptr);
explicit NewTilesetDialog(Project* project, QWidget* parent = nullptr);
~NewTilesetDialog();
QString path;
QString fullSymbolName;
@ -25,8 +24,8 @@ private slots:
void SecondaryChanged();
private:
Ui::NewTilesetDialog *ui;
Project *project = nullptr;
Ui::NewTilesetDialog* ui;
Project* project = nullptr;
};
#endif // NEWTILESETDIALOG_H

View file

@ -3,13 +3,12 @@
#include <QComboBox>
class NoScrollComboBox : public QComboBox
{
class NoScrollComboBox : public QComboBox {
Q_OBJECT
public:
explicit NoScrollComboBox(QWidget *parent = nullptr);
void wheelEvent(QWheelEvent *event);
explicit NoScrollComboBox(QWidget* parent = nullptr);
void wheelEvent(QWheelEvent* event);
private:
};

View file

@ -3,14 +3,13 @@
#include <QSpinBox>
class NoScrollSpinBox : public QSpinBox
{
class NoScrollSpinBox : public QSpinBox {
Q_OBJECT
public:
explicit NoScrollSpinBox(QWidget *parent = nullptr);
void wheelEvent(QWheelEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
explicit NoScrollSpinBox(QWidget* parent = nullptr);
void wheelEvent(QWheelEvent* event) override;
void focusOutEvent(QFocusEvent* event) override;
unsigned getActionId();

View file

@ -8,9 +8,10 @@
class OverlayItem {
public:
OverlayItem() {}
virtual ~OverlayItem() {};
virtual void render(QPainter *) {};
OverlayItem() {
}
virtual ~OverlayItem(){};
virtual void render(QPainter*){};
};
class OverlayText : public OverlayItem {
@ -22,8 +23,10 @@ public:
this->color = color;
this->fontSize = fontSize;
}
~OverlayText() {}
virtual void render(QPainter *painter);
~OverlayText() {
}
virtual void render(QPainter* painter);
private:
QString text;
int x;
@ -42,8 +45,10 @@ public:
this->color = color;
this->filled = filled;
}
~OverlayRect() {}
virtual void render(QPainter *painter);
~OverlayRect() {
}
virtual void render(QPainter* painter);
private:
int x;
int y;
@ -60,18 +65,20 @@ public:
this->y = y;
this->image = image;
}
~OverlayImage() {}
virtual void render(QPainter *painter);
~OverlayImage() {
}
virtual void render(QPainter* painter);
private:
int x;
int y;
QImage image;
};
class Overlay
{
class Overlay {
public:
Overlay() {}
Overlay() {
}
~Overlay() {
this->clearItems();
}
@ -80,6 +87,7 @@ public:
void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12);
void addRect(int x, int y, int width, int height, QString color = "#000000", bool filled = false);
void addImage(int x, int y, QString filepath);
private:
QList<OverlayItem*> items;
};

View file

@ -20,22 +20,22 @@ public:
}
};
class PaletteEditor : public QMainWindow {
class PaletteEditor : public QMainWindow {
Q_OBJECT
public:
explicit PaletteEditor(Project*, Tileset*, Tileset*, int paletteId, QWidget *parent = nullptr);
explicit PaletteEditor(Project*, Tileset*, Tileset*, int paletteId, QWidget* parent = nullptr);
~PaletteEditor();
void setPaletteId(int);
void setTilesets(Tileset*, Tileset*);
private:
Ui::PaletteEditor *ui;
Project *project = nullptr;
Ui::PaletteEditor* ui;
Project* project = nullptr;
QList<QList<QSlider*>> sliders;
QList<QFrame*> frames;
QList<QLabel*> rgbLabels;
Tileset *primaryTileset;
Tileset *secondaryTileset;
Tileset* primaryTileset;
Tileset* secondaryTileset;
QList<History<PaletteHistoryItem*>> palettesHistory;
void disableSliderSignals();
void enableSliderSignals();

View file

@ -6,32 +6,30 @@
class NoScrollComboBox;
class QAbstractButton;
namespace Ui {
class PreferenceEditor;
}
class PreferenceEditor : public QMainWindow
{
class PreferenceEditor : public QMainWindow {
Q_OBJECT
public:
explicit PreferenceEditor(QWidget *parent = nullptr);
explicit PreferenceEditor(QWidget* parent = nullptr);
~PreferenceEditor();
signals:
void preferencesSaved();
void themeChanged(const QString &theme);
void themeChanged(const QString& theme);
private:
Ui::PreferenceEditor *ui;
NoScrollComboBox *themeSelector;
Ui::PreferenceEditor* ui;
NoScrollComboBox* themeSelector;
void populateFields();
void saveFields();
private slots:
void dialogButtonClicked(QAbstractButton *button);
void dialogButtonClicked(QAbstractButton* button);
};
#endif // PREFERENCES_H

View file

@ -16,15 +16,14 @@ namespace Ui {
class RegionMapEditor;
}
class RegionMapEditor : public QMainWindow
{
class RegionMapEditor : public QMainWindow {
Q_OBJECT
public:
explicit RegionMapEditor(QWidget *parent = 0, Project *pro = nullptr);
explicit RegionMapEditor(QWidget* parent = 0, Project* pro = nullptr);
~RegionMapEditor();
RegionMap *region_map;
RegionMap* region_map;
bool loadRegionMapData();
bool loadCityMaps();
@ -39,7 +38,7 @@ public:
void onRegionMapLayoutHoveredTileChanged(int index);
void onRegionMapLayoutHoveredTileCleared();
void onRegionMapEntriesSelectedTileChanged(QString) {};
void onRegionMapEntriesSelectedTileChanged(QString){};
void onRegionMapEntryDragged(int, int);
void undo();
@ -53,8 +52,8 @@ public slots:
void applyUserShortcuts();
private:
Ui::RegionMapEditor *ui;
Project *project;
Ui::RegionMapEditor* ui;
Project* project;
History<RegionMapHistoryItem*> history;
@ -71,20 +70,20 @@ private:
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_entries = 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;
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;
RegionMapEntriesPixmapItem* region_map_entries_item = nullptr;
RegionMapLayoutPixmapItem* region_map_layout_item = nullptr;
RegionMapPixmapItem* region_map_item = nullptr;
CityMapPixmapItem* city_map_item = nullptr;
void initShortcuts();
void displayRegionMap();
@ -118,8 +117,8 @@ 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 &);
void on_comboBox_RM_Entry_MapSection_activated(const QString &);
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);
@ -129,12 +128,12 @@ private slots:
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 &);
void on_lineEdit_RM_MapName_textEdited(const QString &);
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);
void mouseEvent_city_map(QGraphicsSceneMouseEvent *event, CityMapPixmapItem *item);
void mouseEvent_region_map(QGraphicsSceneMouseEvent* event, RegionMapPixmapItem* item);
void mouseEvent_city_map(QGraphicsSceneMouseEvent* event, CityMapPixmapItem* item);
};
#endif // REGIONMAPEDITOR_H

View file

@ -7,12 +7,12 @@
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;
RegionMapEntriesPixmapItem(RegionMap* rm, TilemapTileSelector* ts) : SelectablePixmapItem(8, 8, 1, 1) {
this->region_map = rm;
this->tile_selector = ts;
}
RegionMap *region_map;
TilemapTileSelector *tile_selector;
RegionMap* region_map;
TilemapTileSelector* tile_selector;
QString currentSection = QString();
int selectedTile;
int highlightedTile;
@ -27,7 +27,7 @@ private:
void updateSelectedTile();
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, RegionMapEntriesPixmapItem *);
void mouseEvent(QGraphicsSceneMouseEvent*, RegionMapEntriesPixmapItem*);
void hoveredTileChanged(int);
void hoveredTileCleared();
void selectedTileChanged(QString);

View file

@ -7,13 +7,13 @@
class RegionMapLayoutPixmapItem : public SelectablePixmapItem {
Q_OBJECT
public:
RegionMapLayoutPixmapItem(RegionMap *rmap, TilemapTileSelector *ts) : SelectablePixmapItem(8, 8, 1, 1) {
this->region_map = rmap;
this->tile_selector = ts;
setAcceptHoverEvents(true);
RegionMapLayoutPixmapItem(RegionMap* rmap, TilemapTileSelector* ts) : SelectablePixmapItem(8, 8, 1, 1) {
this->region_map = rmap;
this->tile_selector = ts;
setAcceptHoverEvents(true);
}
RegionMap *region_map;
TilemapTileSelector *tile_selector;
RegionMap* region_map;
TilemapTileSelector* tile_selector;
int selectedTile;
int highlightedTile;
void draw();
@ -25,7 +25,7 @@ private:
void updateSelectedTile();
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, RegionMapLayoutPixmapItem *);
void mouseEvent(QGraphicsSceneMouseEvent*, RegionMapLayoutPixmapItem*);
void hoveredTileChanged(int);
void hoveredTileCleared();
void selectedTileChanged(int);

View file

@ -12,29 +12,29 @@ private:
using QGraphicsPixmapItem::paint;
public:
RegionMapPixmapItem(RegionMap *rmap, TilemapTileSelector *tile_selector) {
RegionMapPixmapItem(RegionMap* rmap, TilemapTileSelector* tile_selector) {
this->region_map = rmap;
this->tile_selector = tile_selector;
setAcceptHoverEvents(true);
}
RegionMap *region_map;
TilemapTileSelector *tile_selector;
virtual void paint(QGraphicsSceneMouseEvent *);
virtual void select(QGraphicsSceneMouseEvent *);
RegionMap* region_map;
TilemapTileSelector* tile_selector;
virtual void paint(QGraphicsSceneMouseEvent*);
virtual void select(QGraphicsSceneMouseEvent*);
virtual void draw();
signals:
void mouseEvent(QGraphicsSceneMouseEvent *, RegionMapPixmapItem *);
void mouseEvent(QGraphicsSceneMouseEvent*, RegionMapPixmapItem*);
void hoveredRegionMapTileChanged(int x, int y);
void hoveredRegionMapTileCleared();
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent *);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
void mousePressEvent(QGraphicsSceneMouseEvent *);
void mouseMoveEvent(QGraphicsSceneMouseEvent *);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
};
#endif // REGIONMAPPIXMAPITEM_H

View file

@ -7,7 +7,8 @@
class SelectablePixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
SelectablePixmapItem(int cellWidth, int cellHeight): SelectablePixmapItem(cellWidth, cellHeight, INT_MAX, INT_MAX) {}
SelectablePixmapItem(int cellWidth, int cellHeight) : SelectablePixmapItem(cellWidth, cellHeight, INT_MAX, INT_MAX) {
}
SelectablePixmapItem(int cellWidth, int cellHeight, int maxSelectionWidth, int maxSelectionHeight) {
this->cellWidth = cellWidth;
this->cellHeight = cellHeight;

View file

@ -5,11 +5,9 @@
#include <QKeySequence>
#include <QShortcut>
// Alternative to QShortcut that adds support for multiple key sequences.
// Use this to allow the shortcut to be editable in ShortcutsEditor.
class Shortcut : public QObject
{
class Shortcut : public QObject {
Q_OBJECT
Q_DECLARE_PRIVATE(QShortcut)
Q_PROPERTY(QKeySequence key READ key WRITE setKey)
@ -19,21 +17,19 @@ class Shortcut : public QObject
Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext)
public:
explicit Shortcut(QWidget *parent);
Shortcut(const QKeySequence &key, QWidget *parent,
const char *member = nullptr, const char *ambiguousMember = nullptr,
Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
Shortcut(const QList<QKeySequence> &keys, QWidget *parent,
const char *member = nullptr, const char *ambiguousMember = nullptr,
Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
explicit Shortcut(QWidget* parent);
Shortcut(const QKeySequence& key, QWidget* parent, const char* member = nullptr, const char* ambiguousMember = nullptr,
Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
Shortcut(const QList<QKeySequence>& keys, QWidget* parent, const char* member = nullptr, const char* ambiguousMember = nullptr,
Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
~Shortcut();
void addKey(const QKeySequence &key);
void setKey(const QKeySequence &key);
void addKey(const QKeySequence& key);
void setKey(const QKeySequence& key);
QKeySequence key() const;
void addKeys(const QList<QKeySequence> &keys);
void setKeys(const QList<QKeySequence> &keys);
void addKeys(const QList<QKeySequence>& keys);
void setKeys(const QList<QKeySequence>& keys);
QList<QKeySequence> keys() const;
void setEnabled(bool enable);
@ -42,7 +38,7 @@ public:
void setContext(Qt::ShortcutContext context);
Qt::ShortcutContext context() const;
void setWhatsThis(const QString &text);
void setWhatsThis(const QString& text);
QString whatsThis() const;
void setAutoRepeat(bool on);
@ -51,21 +47,22 @@ public:
int id() const;
QList<int> ids() const;
inline QWidget *parentWidget() const
{ return static_cast<QWidget *>(QObject::parent()); }
inline QWidget* parentWidget() const {
return static_cast<QWidget*>(QObject::parent());
}
signals:
void activated();
void activatedAmbiguously();
protected:
bool event(QEvent *e) override;
bool event(QEvent* e) override;
private:
const char *sc_member;
const char *sc_ambiguousmember;
const char* sc_member;
const char* sc_ambiguousmember;
Qt::ShortcutContext sc_context;
QVector<QShortcut *> sc_vec;
QVector<QShortcut*> sc_vec;
};
#endif // SHORTCUT_H

View file

@ -13,48 +13,46 @@ class QFormLayout;
class MultiKeyEdit;
class QAbstractButton;
namespace Ui {
class ShortcutsEditor;
}
class ShortcutsEditor : public QMainWindow
{
class ShortcutsEditor : public QMainWindow {
Q_OBJECT
public:
explicit ShortcutsEditor(QWidget *parent = nullptr);
explicit ShortcutsEditor(const QObjectList &shortcutableObjects, QWidget *parent = nullptr);
explicit ShortcutsEditor(QWidget* parent = nullptr);
explicit ShortcutsEditor(const QObjectList& shortcutableObjects, QWidget* parent = nullptr);
~ShortcutsEditor();
void setShortcutableObjects(const QObjectList &shortcutableObjects);
void setShortcutableObjects(const QObjectList& shortcutableObjects);
signals:
void shortcutsSaved();
private:
Ui::ShortcutsEditor *ui;
QWidget *main_container;
QMultiMap<QString, const QObject *> labels_objects;
QHash<QString, QFormLayout *> contexts_layouts;
QHash<MultiKeyEdit *, const QObject *> multiKeyEdits_objects;
Ui::ShortcutsEditor* ui;
QWidget* main_container;
QMultiMap<QString, const QObject*> labels_objects;
QHash<QString, QFormLayout*> contexts_layouts;
QHash<MultiKeyEdit*, const QObject*> multiKeyEdits_objects;
void parseObjectList(const QObjectList &objectList);
QString getLabel(const QObject *object) const;
bool stringPropertyIsNotEmpty(const QObject *object, const char *name) const;
void parseObjectList(const QObjectList& objectList);
QString getLabel(const QObject* object) const;
bool stringPropertyIsNotEmpty(const QObject* object, const char* name) const;
void populateMainContainer();
QString getShortcutContext(const QObject *object) const;
void addNewContextGroup(const QString &shortcutContext);
void addNewMultiKeyEdit(const QObject *object, const QString &shortcutContext);
QList<MultiKeyEdit *> siblings(MultiKeyEdit *multiKeyEdit) const;
void promptUserOnDuplicateFound(MultiKeyEdit *current, MultiKeyEdit *sender);
void removeKeySequence(const QKeySequence &keySequence, MultiKeyEdit *multiKeyEdit);
QString getShortcutContext(const QObject* object) const;
void addNewContextGroup(const QString& shortcutContext);
void addNewMultiKeyEdit(const QObject* object, const QString& shortcutContext);
QList<MultiKeyEdit*> siblings(MultiKeyEdit* multiKeyEdit) const;
void promptUserOnDuplicateFound(MultiKeyEdit* current, MultiKeyEdit* sender);
void removeKeySequence(const QKeySequence& keySequence, MultiKeyEdit* multiKeyEdit);
void saveShortcuts();
void resetShortcuts();
private slots:
void checkForDuplicates(const QKeySequence &keySequence);
void dialogButtonClicked(QAbstractButton *button);
void checkForDuplicates(const QKeySequence& keySequence);
void dialogButtonClicked(QAbstractButton* button);
};
#endif // SHORTCUTSEDITOR_H

View file

@ -3,10 +3,10 @@
#include "selectablepixmapitem.h"
class TilemapTileSelector: public SelectablePixmapItem {
class TilemapTileSelector : public SelectablePixmapItem {
Q_OBJECT
public:
TilemapTileSelector(QPixmap pixmap_): SelectablePixmapItem(8, 8, 1, 1) {
TilemapTileSelector(QPixmap pixmap_) : SelectablePixmapItem(8, 8, 1, 1) {
this->tilemap = pixmap_;
this->setPixmap(this->tilemap);
this->numTilesWide = tilemap.width() / 8;

View file

@ -16,7 +16,7 @@ class TilesetEditor;
class MetatileHistoryItem {
public:
MetatileHistoryItem(uint16_t metatileId, Metatile *prevMetatile, Metatile *newMetatile) {
MetatileHistoryItem(uint16_t metatileId, Metatile* prevMetatile, Metatile* newMetatile) {
this->metatileId = metatileId;
this->prevMetatile = prevMetatile;
this->newMetatile = newMetatile;
@ -26,19 +26,18 @@ public:
delete this->newMetatile;
}
uint16_t metatileId;
Metatile *prevMetatile;
Metatile *newMetatile;
Metatile* prevMetatile;
Metatile* newMetatile;
};
class TilesetEditor : public QMainWindow
{
class TilesetEditor : public QMainWindow {
Q_OBJECT
public:
explicit TilesetEditor(Project*, Map*, QWidget *parent = nullptr);
explicit TilesetEditor(Project*, Map*, QWidget* parent = nullptr);
~TilesetEditor();
void update(Map *map, QString primaryTilsetLabel, QString secondaryTilesetLabel);
void updateMap(Map *map);
void update(Map* map, QString primaryTilsetLabel, QString secondaryTilesetLabel);
void updateMap(Map* map);
void updateTilesets(QString primaryTilsetLabel, QString secondaryTilesetLabel);
bool selectMetatile(uint16_t metatileId);
@ -79,7 +78,7 @@ private slots:
void on_actionRedo_triggered();
void on_comboBox_metatileBehaviors_activated(const QString &arg1);
void on_comboBox_metatileBehaviors_activated(const QString& arg1);
void on_lineEdit_metatileLabel_editingFinished();
@ -120,26 +119,26 @@ private:
void saveMetatileLabel();
void closeEvent(QCloseEvent*);
Ui::TilesetEditor *ui;
Ui::TilesetEditor* ui;
History<MetatileHistoryItem*> metatileHistory;
TilesetEditorMetatileSelector *metatileSelector = nullptr;
TilesetEditorTileSelector *tileSelector = nullptr;
MetatileLayersItem *metatileLayersItem = nullptr;
PaletteEditor *paletteEditor = nullptr;
Project *project = nullptr;
Map *map = nullptr;
Metatile *metatile = nullptr;
TilesetEditorMetatileSelector* metatileSelector = nullptr;
TilesetEditorTileSelector* tileSelector = nullptr;
MetatileLayersItem* metatileLayersItem = nullptr;
PaletteEditor* paletteEditor = nullptr;
Project* project = nullptr;
Map* map = nullptr;
Metatile* metatile = nullptr;
int paletteId;
bool tileXFlip;
bool tileYFlip;
bool hasUnsavedChanges;
Tileset *primaryTileset = nullptr;
Tileset *secondaryTileset = nullptr;
QGraphicsScene *metatilesScene = nullptr;
QGraphicsScene *tilesScene = nullptr;
QGraphicsScene *selectedTileScene = nullptr;
QGraphicsPixmapItem *selectedTilePixmapItem = nullptr;
QGraphicsScene *metatileLayersScene = nullptr;
Tileset* primaryTileset = nullptr;
Tileset* secondaryTileset = nullptr;
QGraphicsScene* metatilesScene = nullptr;
QGraphicsScene* tilesScene = nullptr;
QGraphicsScene* selectedTileScene = nullptr;
QGraphicsPixmapItem* selectedTilePixmapItem = nullptr;
QGraphicsScene* metatileLayersScene = nullptr;
signals:
void tilesetsSaved(QString, QString);

View file

@ -5,17 +5,17 @@
#include "tileset.h"
#include "map.h"
class TilesetEditorMetatileSelector: public SelectablePixmapItem {
class TilesetEditorMetatileSelector : public SelectablePixmapItem {
Q_OBJECT
public:
TilesetEditorMetatileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, Map *map): SelectablePixmapItem(32, 32, 1, 1) {
TilesetEditorMetatileSelector(Tileset* primaryTileset, Tileset* secondaryTileset, Map* map) : SelectablePixmapItem(32, 32, 1, 1) {
this->primaryTileset = primaryTileset;
this->secondaryTileset = secondaryTileset;
this->numMetatilesWide = 8;
this->map = map;
setAcceptHoverEvents(true);
}
Map *map = nullptr;
Map* map = nullptr;
void draw();
bool select(uint16_t metatileId);
void setTilesets(Tileset*, Tileset*);
@ -31,8 +31,8 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
private:
Tileset *primaryTileset = nullptr;
Tileset *secondaryTileset = nullptr;
Tileset* primaryTileset = nullptr;
Tileset* secondaryTileset = nullptr;
uint16_t selectedMetatile;
int numMetatilesWide;
uint16_t getMetatileId(int x, int y);

View file

@ -4,11 +4,10 @@
#include "selectablepixmapitem.h"
#include "tileset.h"
class TilesetEditorTileSelector: public SelectablePixmapItem {
class TilesetEditorTileSelector : public SelectablePixmapItem {
Q_OBJECT
public:
TilesetEditorTileSelector(Tileset *primaryTileset, Tileset *secondaryTileset, bool isTripleLayer)
: SelectablePixmapItem(16, 16, isTripleLayer ? 6 : 4, 2) {
TilesetEditorTileSelector(Tileset* primaryTileset, Tileset* secondaryTileset, bool isTripleLayer) : SelectablePixmapItem(16, 16, isTripleLayer ? 6 : 4, 2) {
this->primaryTileset = primaryTileset;
this->secondaryTileset = secondaryTileset;
this->numTilesWide = 16;
@ -45,8 +44,8 @@ private:
QList<Tile> externalSelectedTiles;
QList<int> externalSelectedPos;
Tileset *primaryTileset;
Tileset *secondaryTileset;
Tileset* primaryTileset;
Tileset* secondaryTileset;
QList<uint16_t> selectedTiles;
int numTilesWide;
int paletteId;

View file

@ -16,7 +16,6 @@
#include <QAbstractButton>
KeyValueConfigBase::~KeyValueConfigBase() {
}
void KeyValueConfigBase::load() {
@ -81,15 +80,11 @@ void KeyValueConfigBase::save() {
}
const QMap<MapSortOrder, QString> mapSortOrderMap = {
{MapSortOrder::Group, "group"},
{MapSortOrder::Layout, "layout"},
{MapSortOrder::Area, "area"},
{ MapSortOrder::Group, "group" }, { MapSortOrder::Layout, "layout" }, { MapSortOrder::Area, "area" },
};
const QMap<QString, MapSortOrder> mapSortOrderReverseMap = {
{"group", MapSortOrder::Group},
{"layout", MapSortOrder::Layout},
{"area", MapSortOrder::Area},
{ "group", MapSortOrder::Group }, { "layout", MapSortOrder::Layout }, { "area", MapSortOrder::Area },
};
PorymapConfig porymapConfig;
@ -217,8 +212,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("show_player_view", this->showPlayerView ? "1" : "0");
map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0");
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width())
.arg(this->regionMapDimensions.height()));
map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width()).arg(this->regionMapDimensions.height()));
map.insert("theme", this->theme);
map.insert("text_editor_open_directory", this->textEditorOpenFolder);
map.insert("text_editor_goto_line", this->textEditorGotoLine);
@ -262,8 +256,7 @@ void PorymapConfig::setMonitorFiles(bool monitor) {
this->save();
}
void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_,
QByteArray mapSplitterState_, QByteArray mainSplitterState_) {
void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_, QByteArray mapSplitterState_, QByteArray mainSplitterState_) {
this->mainWindowGeometry = mainWindowGeometry_;
this->mainWindowState = mainWindowState_;
this->mapSplitterState = mapSplitterState_;
@ -317,12 +310,12 @@ void PorymapConfig::setTheme(QString theme) {
this->theme = theme;
}
void PorymapConfig::setTextEditorOpenFolder(const QString &command) {
void PorymapConfig::setTextEditorOpenFolder(const QString& command) {
this->textEditorOpenFolder = command;
this->save();
}
void PorymapConfig::setTextEditorGotoLine(const QString &command) {
void PorymapConfig::setTextEditorGotoLine(const QString& command) {
this->textEditorGotoLine = command;
this->save();
}
@ -414,15 +407,11 @@ QString PorymapConfig::getTextEditorGotoLine() {
}
const QMap<BaseGameVersion, QString> baseGameVersionMap = {
{BaseGameVersion::pokeruby, "pokeruby"},
{BaseGameVersion::pokefirered, "pokefirered"},
{BaseGameVersion::pokeemerald, "pokeemerald"},
{ BaseGameVersion::pokeruby, "pokeruby" }, { BaseGameVersion::pokefirered, "pokefirered" }, { BaseGameVersion::pokeemerald, "pokeemerald" },
};
const QMap<QString, BaseGameVersion> baseGameVersionReverseMap = {
{"pokeruby", BaseGameVersion::pokeruby},
{"pokefirered", BaseGameVersion::pokefirered},
{"pokeemerald", BaseGameVersion::pokeemerald},
{ "pokeruby", BaseGameVersion::pokeruby }, { "pokefirered", BaseGameVersion::pokefirered }, { "pokeemerald", BaseGameVersion::pokeemerald },
};
ProjectConfig projectConfig;
@ -527,14 +516,22 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
void ProjectConfig::setUnreadKeys() {
// Set game-version specific defaults for any config field that wasn't read
bool isPokefirered = this->baseGameVersion == BaseGameVersion::pokefirered;
if (!readKeys.contains("use_custom_border_size")) this->useCustomBorderSize = isPokefirered;
if (!readKeys.contains("enable_event_weather_trigger")) this->enableEventWeatherTrigger = !isPokefirered;
if (!readKeys.contains("enable_event_secret_base")) this->enableEventSecretBase = !isPokefirered;
if (!readKeys.contains("enable_hidden_item_quantity")) this->enableHiddenItemQuantity = isPokefirered;
if (!readKeys.contains("enable_hidden_item_requires_itemfinder")) this->enableHiddenItemRequiresItemfinder = isPokefirered;
if (!readKeys.contains("enable_heal_location_respawn_data")) this->enableHealLocationRespawnData = isPokefirered;
if (!readKeys.contains("enable_object_event_in_connection")) this->enableObjectEventInConnection = isPokefirered;
if (!readKeys.contains("enable_floor_number")) this->enableFloorNumber = isPokefirered;
if (!readKeys.contains("use_custom_border_size"))
this->useCustomBorderSize = isPokefirered;
if (!readKeys.contains("enable_event_weather_trigger"))
this->enableEventWeatherTrigger = !isPokefirered;
if (!readKeys.contains("enable_event_secret_base"))
this->enableEventSecretBase = !isPokefirered;
if (!readKeys.contains("enable_hidden_item_quantity"))
this->enableHiddenItemQuantity = isPokefirered;
if (!readKeys.contains("enable_hidden_item_requires_itemfinder"))
this->enableHiddenItemRequiresItemfinder = isPokefirered;
if (!readKeys.contains("enable_heal_location_respawn_data"))
this->enableHealLocationRespawnData = isPokefirered;
if (!readKeys.contains("enable_object_event_in_connection"))
this->enableObjectEventInConnection = isPokefirered;
if (!readKeys.contains("enable_floor_number"))
this->enableFloorNumber = isPokefirered;
}
QMap<QString, QString> ProjectConfig::getKeyValueMap() {
@ -568,7 +565,7 @@ void ProjectConfig::onNewConfigFileCreated() {
QFormLayout form(&dialog);
QComboBox *baseGameVersionComboBox = new QComboBox();
QComboBox* baseGameVersionComboBox = new QComboBox();
baseGameVersionComboBox->addItem("pokeruby", BaseGameVersion::pokeruby);
baseGameVersionComboBox->addItem("pokefirered", BaseGameVersion::pokefirered);
baseGameVersionComboBox->addItem("pokeemerald", BaseGameVersion::pokeemerald);
@ -614,7 +611,7 @@ BaseGameVersion ProjectConfig::getBaseGameVersion() {
return this->baseGameVersion;
}
void ProjectConfig::setRecentMap(const QString &map) {
void ProjectConfig::setRecentMap(const QString& map) {
this->recentMap = map;
this->save();
}
@ -762,42 +759,38 @@ QMap<QString, QString> ShortcutsConfig::getKeyValueMap() {
return map;
}
void ShortcutsConfig::setDefaultShortcuts(const QObjectList &objects) {
void ShortcutsConfig::setDefaultShortcuts(const QObjectList& objects) {
storeShortcutsFromList(StoreType::Default, objects);
save();
}
QList<QKeySequence> ShortcutsConfig::defaultShortcuts(const QObject *object) const {
QList<QKeySequence> ShortcutsConfig::defaultShortcuts(const QObject* object) const {
return default_shortcuts.values(cfgKey(object));
}
void ShortcutsConfig::setUserShortcuts(const QObjectList &objects) {
void ShortcutsConfig::setUserShortcuts(const QObjectList& objects) {
storeShortcutsFromList(StoreType::User, objects);
save();
}
void ShortcutsConfig::setUserShortcuts(const QMultiMap<const QObject *, QKeySequence> &objects_keySequences) {
for (auto *object : objects_keySequences.uniqueKeys())
void ShortcutsConfig::setUserShortcuts(const QMultiMap<const QObject*, QKeySequence>& objects_keySequences) {
for (auto* object : objects_keySequences.uniqueKeys())
if (!object->objectName().isEmpty() && !object->objectName().startsWith("_q_"))
storeShortcuts(StoreType::User, cfgKey(object), objects_keySequences.values(object));
save();
}
QList<QKeySequence> ShortcutsConfig::userShortcuts(const QObject *object) const {
QList<QKeySequence> ShortcutsConfig::userShortcuts(const QObject* object) const {
return user_shortcuts.values(cfgKey(object));
}
void ShortcutsConfig::storeShortcutsFromList(StoreType storeType, const QObjectList &objects) {
for (const auto *object : objects)
void ShortcutsConfig::storeShortcutsFromList(StoreType storeType, const QObjectList& objects) {
for (const auto* object : objects)
if (!object->objectName().isEmpty() && !object->objectName().startsWith("_q_"))
storeShortcuts(storeType, cfgKey(object), currentShortcuts(object));
}
void ShortcutsConfig::storeShortcuts(
StoreType storeType,
const QString &cfgKey,
const QList<QKeySequence> &keySequences)
{
void ShortcutsConfig::storeShortcuts(StoreType storeType, const QString& cfgKey, const QList<QKeySequence>& keySequences) {
bool storeUser = (storeType == User) || !user_shortcuts.contains(cfgKey);
if (storeType == Default)
@ -820,11 +813,11 @@ void ShortcutsConfig::storeShortcuts(
}
}
/* Creates a config key from the object's name prepended with the parent
/* Creates a config key from the object's name prepended with the parent
* window's object name, and converts camelCase to snake_case. */
QString ShortcutsConfig::cfgKey(const QObject *object) const {
QString ShortcutsConfig::cfgKey(const QObject* object) const {
auto cfg_key = QString();
auto *parentWidget = static_cast<QWidget *>(object->parent());
auto* parentWidget = static_cast<QWidget*>(object->parent());
if (parentWidget)
cfg_key = parentWidget->window()->objectName() + '_';
cfg_key += object->objectName();
@ -839,19 +832,19 @@ QString ShortcutsConfig::cfgKey(const QObject *object) const {
return cfg_key.toLower();
}
QList<QKeySequence> ShortcutsConfig::currentShortcuts(const QObject *object) const {
QList<QKeySequence> ShortcutsConfig::currentShortcuts(const QObject* object) const {
if (object->inherits("QAction")) {
const auto *action = qobject_cast<const QAction *>(object);
const auto* action = qobject_cast<const QAction*>(object);
return action->shortcuts();
} else if (object->inherits("Shortcut")) {
const auto *shortcut = qobject_cast<const Shortcut *>(object);
const auto* shortcut = qobject_cast<const Shortcut*>(object);
return shortcut->keys();
} else if (object->inherits("QShortcut")) {
const auto *qshortcut = qobject_cast<const QShortcut *>(object);
const auto* qshortcut = qobject_cast<const QShortcut*>(object);
return { qshortcut->key() };
} else if (object->property("shortcut").isValid()) {
return { object->property("shortcut").value<QKeySequence>() };
} else {
return { };
return {};
}
}

View file

@ -1,26 +1,18 @@
#include "block.h"
Block::Block() : tile(0), collision(0), elevation(0) { }
Block::Block() : tile(0), collision(0), elevation(0) {
}
Block::Block(uint16_t tile, uint16_t collision, uint16_t elevation) :
tile(tile),
collision(collision),
elevation(elevation)
{ }
Block::Block(uint16_t tile, uint16_t collision, uint16_t elevation) : tile(tile), collision(collision), elevation(elevation) {
}
Block::Block(uint16_t word) :
tile(word & 0x3ff),
collision((word >> 10) & 0x3),
elevation((word >> 12) & 0xf)
{ }
Block::Block(uint16_t word) : tile(word & 0x3ff), collision((word >> 10) & 0x3), elevation((word >> 12) & 0xf) {
}
Block::Block(const Block &other) :
tile(other.tile),
collision(other.collision),
elevation(other.elevation)
{ }
Block::Block(const Block& other) : tile(other.tile), collision(other.collision), elevation(other.elevation) {
}
Block &Block::operator=(const Block &other) {
Block& Block::operator=(const Block& other) {
tile = other.tile;
collision = other.collision;
elevation = other.elevation;
@ -28,16 +20,13 @@ Block &Block::operator=(const Block &other) {
}
uint16_t Block::rawValue() const {
return static_cast<uint16_t>(
(tile & 0x3ff) +
((collision & 0x3) << 10) +
((elevation & 0xf) << 12));
return static_cast<uint16_t>((tile & 0x3ff) + ((collision & 0x3) << 10) + ((elevation & 0xf) << 12));
}
bool Block::operator ==(Block other) const {
bool Block::operator==(Block other) const {
return (tile == other.tile) && (collision == other.collision) && (elevation == other.elevation);
}
bool Block::operator !=(Block other) const {
return !(operator ==(other));
bool Block::operator!=(Block other) const {
return !(operator==(other));
}

View file

@ -2,7 +2,7 @@
QByteArray Blockdata::serialize() const {
QByteArray data;
for (const auto &block : *this) {
for (const auto& block : *this) {
uint16_t word = block.rawValue();
data.append(static_cast<char>(word & 0xff));
data.append(static_cast<char>((word >> 8) & 0xff));

View file

@ -6,19 +6,17 @@
#include <QDebug>
int getEventTypeMask(QList<Event *> events) {
int getEventTypeMask(QList<Event*> events) {
int eventTypeMask = 0;
for (auto event : events) {
if (event->get("event_type") == EventType::Object) {
eventTypeMask |= IDMask_EventType_Object;
} else if (event->get("event_type") == EventType::Warp) {
eventTypeMask |= IDMask_EventType_Warp;
} else if (event->get("event_type") == EventType::Trigger ||
event->get("event_type") == EventType::WeatherTrigger) {
} else if (event->get("event_type") == EventType::Trigger || event->get("event_type") == EventType::WeatherTrigger) {
eventTypeMask |= IDMask_EventType_Trigger;
} else if (event->get("event_type") == EventType::Sign ||
event->get("event_type") == EventType::HiddenItem ||
event->get("event_type") == EventType::SecretBase) {
} else if (event->get("event_type") == EventType::Sign || event->get("event_type") == EventType::HiddenItem
|| event->get("event_type") == EventType::SecretBase) {
eventTypeMask |= IDMask_EventType_BG;
} else if (event->get("event_type") == EventType::HealLocation) {
eventTypeMask |= IDMask_EventType_Heal;
@ -27,14 +25,13 @@ int getEventTypeMask(QList<Event *> events) {
return eventTypeMask;
}
void renderMapBlocks(Map *map, bool ignoreCache = false) {
void renderMapBlocks(Map* map, bool ignoreCache = false) {
map->mapItem->draw(ignoreCache);
map->collisionItem->draw(ignoreCache);
}
PaintMetatile::PaintMetatile(Map *map,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
PaintMetatile::PaintMetatile(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent)
: QUndoCommand(parent) {
setText("Paint Metatiles");
this->map = map;
@ -47,7 +44,8 @@ PaintMetatile::PaintMetatile(Map *map,
void PaintMetatile::redo() {
QUndoCommand::redo();
if (!map) return;
if (!map)
return;
map->layout->blockdata = newMetatiles;
@ -57,7 +55,8 @@ void PaintMetatile::redo() {
}
void PaintMetatile::undo() {
if (!map) return;
if (!map)
return;
map->layout->blockdata = oldMetatiles;
@ -68,8 +67,8 @@ void PaintMetatile::undo() {
QUndoCommand::undo();
}
bool PaintMetatile::mergeWith(const QUndoCommand *command) {
const PaintMetatile *other = static_cast<const PaintMetatile *>(command);
bool PaintMetatile::mergeWith(const QUndoCommand* command) {
const PaintMetatile* other = static_cast<const PaintMetatile*>(command);
if (map != other->map)
return false;
@ -86,9 +85,7 @@ bool PaintMetatile::mergeWith(const QUndoCommand *command) {
************************************************************************
******************************************************************************/
PaintBorder::PaintBorder(Map *map,
const Blockdata &oldBorder, const Blockdata &newBorder,
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
PaintBorder::PaintBorder(Map* map, const Blockdata& oldBorder, const Blockdata& newBorder, unsigned actionId, QUndoCommand* parent) : QUndoCommand(parent) {
setText("Paint Border");
this->map = map;
@ -101,7 +98,8 @@ PaintBorder::PaintBorder(Map *map,
void PaintBorder::redo() {
QUndoCommand::redo();
if (!map) return;
if (!map)
return;
map->layout->border = newBorder;
@ -109,7 +107,8 @@ void PaintBorder::redo() {
}
void PaintBorder::undo() {
if (!map) return;
if (!map)
return;
map->layout->border = oldBorder;
@ -122,9 +121,8 @@ void PaintBorder::undo() {
************************************************************************
******************************************************************************/
ShiftMetatiles::ShiftMetatiles(Map *map,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
ShiftMetatiles::ShiftMetatiles(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent)
: QUndoCommand(parent) {
setText("Shift Metatiles");
this->map = map;
@ -137,7 +135,8 @@ ShiftMetatiles::ShiftMetatiles(Map *map,
void ShiftMetatiles::redo() {
QUndoCommand::redo();
if (!map) return;
if (!map)
return;
map->layout->blockdata = newMetatiles;
@ -147,7 +146,8 @@ void ShiftMetatiles::redo() {
}
void ShiftMetatiles::undo() {
if (!map) return;
if (!map)
return;
map->layout->blockdata = oldMetatiles;
@ -158,8 +158,8 @@ void ShiftMetatiles::undo() {
QUndoCommand::undo();
}
bool ShiftMetatiles::mergeWith(const QUndoCommand *command) {
const ShiftMetatiles *other = static_cast<const ShiftMetatiles *>(command);
bool ShiftMetatiles::mergeWith(const QUndoCommand* command) {
const ShiftMetatiles* other = static_cast<const ShiftMetatiles*>(command);
if (this->map != other->map)
return false;
@ -176,11 +176,9 @@ bool ShiftMetatiles::mergeWith(const QUndoCommand *command) {
************************************************************************
******************************************************************************/
ResizeMap::ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QSize oldBorderDimensions, QSize newBorderDimensions,
const Blockdata &oldBorder, const Blockdata &newBorder,
QUndoCommand *parent) : QUndoCommand(parent) {
ResizeMap::ResizeMap(Map* map, QSize oldMapDimensions, QSize newMapDimensions, const Blockdata& oldMetatiles, const Blockdata& newMetatiles,
QSize oldBorderDimensions, QSize newBorderDimensions, const Blockdata& oldBorder, const Blockdata& newBorder, QUndoCommand* parent)
: QUndoCommand(parent) {
setText("Resize Map");
this->map = map;
@ -207,7 +205,8 @@ ResizeMap::ResizeMap(Map *map, QSize oldMapDimensions, QSize newMapDimensions,
void ResizeMap::redo() {
QUndoCommand::redo();
if (!map) return;
if (!map)
return;
map->layout->blockdata = newMetatiles;
map->setDimensions(newMapWidth, newMapHeight, false);
@ -221,7 +220,8 @@ void ResizeMap::redo() {
}
void ResizeMap::undo() {
if (!map) return;
if (!map)
return;
map->layout->blockdata = oldMetatiles;
map->setDimensions(oldMapWidth, oldMapHeight, false);
@ -240,9 +240,7 @@ void ResizeMap::undo() {
************************************************************************
******************************************************************************/
EventMove::EventMove(QList<Event *> events,
int deltaX, int deltaY, unsigned actionId,
QUndoCommand *parent) : QUndoCommand(parent) {
EventMove::EventMove(QList<Event*> events, int deltaX, int deltaY, unsigned actionId, QUndoCommand* parent) : QUndoCommand(parent) {
setText("Move Event");
this->events = events;
@ -256,21 +254,21 @@ EventMove::EventMove(QList<Event *> events,
void EventMove::redo() {
QUndoCommand::redo();
for (Event *event : events) {
for (Event* event : events) {
event->pixmapItem->move(deltaX, deltaY);
}
}
void EventMove::undo() {
for (Event *event : events) {
for (Event* event : events) {
event->pixmapItem->move(-deltaX, -deltaY);
}
QUndoCommand::undo();
}
bool EventMove::mergeWith(const QUndoCommand *command) {
const EventMove *other = static_cast<const EventMove *>(command);
bool EventMove::mergeWith(const QUndoCommand* command) {
const EventMove* other = static_cast<const EventMove*>(command);
if (actionId != other->actionId)
return false;
@ -291,10 +289,8 @@ int EventMove::id() const {
************************************************************************
******************************************************************************/
EventShift::EventShift(QList<Event *> events,
int deltaX, int deltaY, unsigned actionId,
QUndoCommand *parent)
: EventMove(events, deltaX, deltaY, actionId, parent) {
EventShift::EventShift(QList<Event*> events, int deltaX, int deltaY, unsigned actionId, QUndoCommand* parent)
: EventMove(events, deltaX, deltaY, actionId, parent) {
this->events = events;
setText("Shift Events");
}
@ -307,8 +303,7 @@ int EventShift::id() const {
************************************************************************
******************************************************************************/
EventCreate::EventCreate(Editor *editor, Map *map, Event *event,
QUndoCommand *parent) : QUndoCommand(parent) {
EventCreate::EventCreate(Editor* editor, Map* map, Event* event, QUndoCommand* parent) : QUndoCommand(parent) {
setText("Create Event");
this->editor = editor;
@ -344,16 +339,14 @@ void EventCreate::undo() {
}
int EventCreate::id() const {
return CommandId::ID_EventCreate | getEventTypeMask(QList<Event*>({this->event}));
return CommandId::ID_EventCreate | getEventTypeMask(QList<Event*>({ this->event }));
}
/******************************************************************************
************************************************************************
******************************************************************************/
EventDelete::EventDelete(Editor *editor, Map *map,
QList<Event *> selectedEvents, Event *nextSelectedEvent,
QUndoCommand *parent) : QUndoCommand(parent) {
EventDelete::EventDelete(Editor* editor, Map* map, QList<Event*> selectedEvents, Event* nextSelectedEvent, QUndoCommand* parent) : QUndoCommand(parent) {
if (selectedEvents.size() > 1) {
setText("Delete Events");
} else {
@ -370,7 +363,7 @@ EventDelete::EventDelete(Editor *editor, Map *map,
void EventDelete::redo() {
QUndoCommand::redo();
for (Event *event : selectedEvents) {
for (Event* event : selectedEvents) {
map->removeEvent(event);
if (editor->scene->items().contains(event->pixmapItem)) {
@ -386,7 +379,7 @@ void EventDelete::redo() {
}
void EventDelete::undo() {
for (Event *event : selectedEvents) {
for (Event* event : selectedEvents) {
map->addEvent(event);
editor->project->loadEventPixmaps(map->getAllEvents());
@ -395,7 +388,7 @@ void EventDelete::undo() {
// select these events
editor->selected_events->clear();
for (Event *event : selectedEvents) {
for (Event* event : selectedEvents) {
editor->selected_events->append(event->pixmapItem);
}
editor->shouldReselectEvents();
@ -411,9 +404,7 @@ int EventDelete::id() const {
************************************************************************
******************************************************************************/
EventDuplicate::EventDuplicate(Editor *editor, Map *map,
QList<Event *> selectedEvents,
QUndoCommand *parent) : QUndoCommand(parent) {
EventDuplicate::EventDuplicate(Editor* editor, Map* map, QList<Event*> selectedEvents, QUndoCommand* parent) : QUndoCommand(parent) {
setText("Duplicate Event");
this->editor = editor;
@ -425,26 +416,26 @@ EventDuplicate::EventDuplicate(Editor *editor, Map *map,
void EventDuplicate::redo() {
QUndoCommand::redo();
for (Event *event : selectedEvents) {
for (Event* event : selectedEvents) {
map->addEvent(event);
}
editor->project->loadEventPixmaps(map->getAllEvents());
for (Event *event : selectedEvents) {
for (Event* event : selectedEvents) {
editor->addMapEvent(event);
}
// select these events
editor->selected_events->clear();
for (Event *event : selectedEvents) {
for (Event* event : selectedEvents) {
editor->selected_events->append(event->pixmapItem);
}
editor->shouldReselectEvents();
}
void EventDuplicate::undo() {
for (Event *event : selectedEvents) {
for (Event* event : selectedEvents) {
map->removeEvent(event);
if (editor->scene->items().contains(event->pixmapItem)) {
@ -466,10 +457,9 @@ int EventDuplicate::id() const {
************************************************************************
******************************************************************************/
ScriptEditMap::ScriptEditMap(Map *map,
QSize oldMapDimensions, QSize newMapDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
QUndoCommand *parent) : QUndoCommand(parent) {
ScriptEditMap::ScriptEditMap(
Map* map, QSize oldMapDimensions, QSize newMapDimensions, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, QUndoCommand* parent)
: QUndoCommand(parent) {
setText("Script Edit Map");
this->map = map;
@ -486,7 +476,8 @@ ScriptEditMap::ScriptEditMap(Map *map,
void ScriptEditMap::redo() {
QUndoCommand::redo();
if (!map) return;
if (!map)
return;
map->layout->blockdata = newMetatiles;
if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) {
@ -500,7 +491,8 @@ void ScriptEditMap::redo() {
}
void ScriptEditMap::undo() {
if (!map) return;
if (!map)
return;
map->layout->blockdata = oldMetatiles;
if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) {

View file

@ -12,32 +12,27 @@ QString EventType::HiddenItem = "event_hidden_item";
QString EventType::SecretBase = "event_secret_base";
QString EventType::HealLocation = "event_heal_location";
Event::Event() :
spriteWidth(16),
spriteHeight(16),
usingSprite(false)
{ }
Event::Event() : spriteWidth(16), spriteHeight(16), usingSprite(false) {
}
Event::Event(const Event& toCopy) :
values(toCopy.values),
customValues(toCopy.customValues),
pixmap(toCopy.pixmap),
spriteWidth(toCopy.spriteWidth),
spriteHeight(toCopy.spriteHeight),
frame(toCopy.frame),
hFlip(toCopy.hFlip),
usingSprite(toCopy.usingSprite)
{ }
Event::Event(const Event& toCopy)
: values(toCopy.values),
customValues(toCopy.customValues),
pixmap(toCopy.pixmap),
spriteWidth(toCopy.spriteWidth),
spriteHeight(toCopy.spriteHeight),
frame(toCopy.frame),
hFlip(toCopy.hFlip),
usingSprite(toCopy.usingSprite) {
}
Event::Event(QJsonObject obj, QString type) : Event()
{
Event::Event(QJsonObject obj, QString type) : Event() {
this->put("event_type", type);
this->readCustomValues(obj);
}
Event* Event::createNewEvent(QString event_type, QString map_name, Project *project)
{
Event *event = nullptr;
Event* Event::createNewEvent(QString event_type, QString map_name, Project* project) {
Event* event = nullptr;
if (event_type == EventType::Object) {
event = createNewObjectEvent(project);
event->setFrameFromMovement(event->get("movement_type"));
@ -65,9 +60,8 @@ Event* Event::createNewEvent(QString event_type, QString map_name, Project *proj
return event;
}
Event* Event::createNewObjectEvent(Project *project)
{
Event *event = new Event;
Event* Event::createNewObjectEvent(Project* project) {
Event* event = new Event;
event->put("event_group_type", "object_event_group");
event->put("event_type", EventType::Object);
event->put("sprite", project->getEventObjGfxConstants().keys().first());
@ -86,9 +80,8 @@ Event* Event::createNewObjectEvent(Project *project)
return event;
}
Event* Event::createNewWarpEvent(QString map_name)
{
Event *event = new Event;
Event* Event::createNewWarpEvent(QString map_name) {
Event* event = new Event;
event->put("event_group_type", "warp_event_group");
event->put("event_type", EventType::Warp);
event->put("destination_warp", 0);
@ -97,12 +90,11 @@ Event* Event::createNewWarpEvent(QString map_name)
return event;
}
Event* Event::createNewHealLocationEvent(QString map_name)
{
Event *event = new Event;
Event* Event::createNewHealLocationEvent(QString map_name) {
Event* event = new Event;
event->put("event_group_type", "heal_event_group");
event->put("event_type", EventType::HealLocation);
event->put("loc_name", QString(Map::mapConstantFromName(map_name)).remove(0,4));
event->put("loc_name", QString(Map::mapConstantFromName(map_name)).remove(0, 4));
event->put("id_name", map_name.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2").toUpper());
event->put("elevation", 3);
if (projectConfig.getHealLocationRespawnDataEnabled()) {
@ -112,9 +104,8 @@ Event* Event::createNewHealLocationEvent(QString map_name)
return event;
}
Event* Event::createNewTriggerEvent(Project *project)
{
Event *event = new Event;
Event* Event::createNewTriggerEvent(Project* project) {
Event* event = new Event;
event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::Trigger);
event->put("script_label", "NULL");
@ -124,9 +115,8 @@ Event* Event::createNewTriggerEvent(Project *project)
return event;
}
Event* Event::createNewWeatherTriggerEvent(Project *project)
{
Event *event = new Event;
Event* Event::createNewWeatherTriggerEvent(Project* project) {
Event* event = new Event;
event->put("event_group_type", "coord_event_group");
event->put("event_type", EventType::WeatherTrigger);
event->put("weather", project->coordEventWeatherNames.first());
@ -134,9 +124,8 @@ Event* Event::createNewWeatherTriggerEvent(Project *project)
return event;
}
Event* Event::createNewSignEvent(Project *project)
{
Event *event = new Event;
Event* Event::createNewSignEvent(Project* project) {
Event* event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::Sign);
event->put("player_facing_direction", project->bgEventFacingDirections.first());
@ -145,9 +134,8 @@ Event* Event::createNewSignEvent(Project *project)
return event;
}
Event* Event::createNewHiddenItemEvent(Project *project)
{
Event *event = new Event;
Event* Event::createNewHiddenItemEvent(Project* project) {
Event* event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::HiddenItem);
event->put("item", project->itemNames.first());
@ -162,9 +150,8 @@ Event* Event::createNewHiddenItemEvent(Project *project)
return event;
}
Event* Event::createNewSecretBaseEvent(Project *project)
{
Event *event = new Event;
Event* Event::createNewSecretBaseEvent(Project* project) {
Event* event = new Event;
event->put("event_group_type", "bg_event_group");
event->put("event_type", EventType::SecretBase);
event->put("secret_base_id", project->secretBaseIds.first());
@ -172,84 +159,44 @@ Event* Event::createNewSecretBaseEvent(Project *project)
return event;
}
int Event::getPixelX()
{
int Event::getPixelX() {
return (this->x() * 16) - qMax(0, (this->spriteWidth - 16) / 2);
}
int Event::getPixelY()
{
int Event::getPixelY() {
return (this->y() * 16) - qMax(0, this->spriteHeight - 16);
}
static QMap<QString, bool> expectedObjectFields {
{"graphics_id", true},
{"x", true},
{"y", true},
{"elevation", true},
{"movement_type", true},
{"movement_range_x", true},
{"movement_range_y", true},
{"trainer_type", true},
{"trainer_sight_or_berry_tree_id", true},
{"script", true},
{"flag", true},
static QMap<QString, bool> expectedObjectFields{
{ "graphics_id", true }, { "x", true }, { "y", true }, { "elevation", true }, { "movement_type", true }, { "movement_range_x", true },
{ "movement_range_y", true }, { "trainer_type", true }, { "trainer_sight_or_berry_tree_id", true }, { "script", true }, { "flag", true },
};
static QMap<QString, bool> expectedWarpFields {
{"x", true},
{"y", true},
{"elevation", true},
{"dest_map", true},
{"dest_warp_id", true},
static QMap<QString, bool> expectedWarpFields{
{ "x", true }, { "y", true }, { "elevation", true }, { "dest_map", true }, { "dest_warp_id", true },
};
static QMap<QString, bool> expectedTriggerFields {
{"type", true},
{"x", true},
{"y", true},
{"elevation", true},
{"var", true},
{"var_value", true},
{"script", true},
static QMap<QString, bool> expectedTriggerFields{
{ "type", true }, { "x", true }, { "y", true }, { "elevation", true }, { "var", true }, { "var_value", true }, { "script", true },
};
static QMap<QString, bool> expectedWeatherTriggerFields {
{"type", true},
{"x", true},
{"y", true},
{"elevation", true},
{"weather", true},
static QMap<QString, bool> expectedWeatherTriggerFields{
{ "type", true }, { "x", true }, { "y", true }, { "elevation", true }, { "weather", true },
};
static QMap<QString, bool> expectedSignFields {
{"type", true},
{"x", true},
{"y", true},
{"elevation", true},
{"player_facing_dir", true},
{"script", true},
static QMap<QString, bool> expectedSignFields{
{ "type", true }, { "x", true }, { "y", true }, { "elevation", true }, { "player_facing_dir", true }, { "script", true },
};
static QMap<QString, bool> expectedHiddenItemFields {
{"type", true},
{"x", true},
{"y", true},
{"elevation", true},
{"item", true},
{"flag", true},
static QMap<QString, bool> expectedHiddenItemFields{
{ "type", true }, { "x", true }, { "y", true }, { "elevation", true }, { "item", true }, { "flag", true },
};
static QMap<QString, bool> expectedSecretBaseFields {
{"type", true},
{"x", true},
{"y", true},
{"elevation", true},
{"secret_base_id", true},
static QMap<QString, bool> expectedSecretBaseFields{
{ "type", true }, { "x", true }, { "y", true }, { "elevation", true }, { "secret_base_id", true },
};
QMap<QString, bool> Event::getExpectedFields()
{
QMap<QString, bool> Event::getExpectedFields() {
QString type = this->get("event_type");
QMap<QString, bool> expectedFields = QMap<QString, bool>();
if (type == EventType::Object) {
@ -260,7 +207,7 @@ QMap<QString, bool> Event::getExpectedFields()
} else if (type == EventType::Warp) {
expectedFields = expectedWarpFields;
} else if (type == EventType::Trigger) {
expectedFields = expectedTriggerFields;
expectedFields = expectedTriggerFields;
} else if (type == EventType::WeatherTrigger) {
expectedFields = expectedWeatherTriggerFields;
} else if (type == EventType::Sign) {
@ -279,8 +226,7 @@ QMap<QString, bool> Event::getExpectedFields()
return expectedFields;
};
void Event::readCustomValues(QJsonObject values)
{
void Event::readCustomValues(QJsonObject values) {
this->customValues.clear();
QMap<QString, bool> expectedValues = this->getExpectedFields();
for (QString key : values.keys()) {
@ -290,8 +236,7 @@ void Event::readCustomValues(QJsonObject values)
}
}
void Event::addCustomValuesTo(OrderedJson::object *obj)
{
void Event::addCustomValuesTo(OrderedJson::object* obj) {
for (QString key : this->customValues.keys()) {
if (!obj->contains(key)) {
(*obj)[key] = this->customValues[key];
@ -299,8 +244,7 @@ void Event::addCustomValuesTo(OrderedJson::object *obj)
}
}
OrderedJson::object Event::buildObjectEventJSON()
{
OrderedJson::object Event::buildObjectEventJSON() {
OrderedJson::object eventObj;
eventObj["graphics_id"] = this->get("sprite");
if (projectConfig.getObjectEventInConnectionEnabled()) {
@ -321,8 +265,7 @@ OrderedJson::object Event::buildObjectEventJSON()
return eventObj;
}
OrderedJson::object Event::buildWarpEventJSON(const QMap<QString, QString> &mapNamesToMapConstants)
{
OrderedJson::object Event::buildWarpEventJSON(const QMap<QString, QString>& mapNamesToMapConstants) {
OrderedJson::object warpObj;
warpObj["x"] = this->getU16("x");
warpObj["y"] = this->getU16("y");
@ -334,8 +277,7 @@ OrderedJson::object Event::buildWarpEventJSON(const QMap<QString, QString> &mapN
return warpObj;
}
OrderedJson::object Event::buildTriggerEventJSON()
{
OrderedJson::object Event::buildTriggerEventJSON() {
OrderedJson::object triggerObj;
triggerObj["type"] = "trigger";
triggerObj["x"] = this->getU16("x");
@ -349,8 +291,7 @@ OrderedJson::object Event::buildTriggerEventJSON()
return triggerObj;
}
OrderedJson::object Event::buildWeatherTriggerEventJSON()
{
OrderedJson::object Event::buildWeatherTriggerEventJSON() {
OrderedJson::object weatherObj;
weatherObj["type"] = "weather";
weatherObj["x"] = this->getU16("x");
@ -362,8 +303,7 @@ OrderedJson::object Event::buildWeatherTriggerEventJSON()
return weatherObj;
}
OrderedJson::object Event::buildSignEventJSON()
{
OrderedJson::object Event::buildSignEventJSON() {
OrderedJson::object signObj;
signObj["type"] = "sign";
signObj["x"] = this->getU16("x");
@ -376,8 +316,7 @@ OrderedJson::object Event::buildSignEventJSON()
return signObj;
}
OrderedJson::object Event::buildHiddenItemEventJSON()
{
OrderedJson::object Event::buildHiddenItemEventJSON() {
OrderedJson::object hiddenItemObj;
hiddenItemObj["type"] = "hidden_item";
hiddenItemObj["x"] = this->getU16("x");
@ -396,8 +335,7 @@ OrderedJson::object Event::buildHiddenItemEventJSON()
return hiddenItemObj;
}
OrderedJson::object Event::buildSecretBaseEventJSON()
{
OrderedJson::object Event::buildSecretBaseEventJSON() {
OrderedJson::object secretBaseObj;
secretBaseObj["type"] = "secret_base";
secretBaseObj["x"] = this->getU16("x");
@ -409,8 +347,7 @@ OrderedJson::object Event::buildSecretBaseEventJSON()
return secretBaseObj;
}
void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight, int frame, bool hFlip)
{
void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight, int frame, bool hFlip) {
// Set first palette color fully transparent.
QImage img = spritesheet.copy(frame * spriteWidth % spritesheet.width(), 0, spriteWidth, spriteHeight);
if (hFlip) {

View file

@ -2,8 +2,7 @@
#include "config.h"
#include "map.h"
HealLocation::HealLocation(QString id, QString map, int i, uint16_t x, uint16_t y, QString respawnMap, uint16_t respawnNPC)
{
HealLocation::HealLocation(QString id, QString map, int i, uint16_t x, uint16_t y, QString respawnMap, uint16_t respawnNPC) {
this->idName = id;
this->mapName = map;
this->index = i;
@ -13,28 +12,25 @@ HealLocation::HealLocation(QString id, QString map, int i, uint16_t x, uint16_t
this->respawnNPC = respawnNPC;
}
HealLocation HealLocation::fromEvent(Event *event)
{
HealLocation HealLocation::fromEvent(Event* event) {
HealLocation hl;
hl.idName = event->get("id_name");
hl.mapName = event->get("loc_name");
try {
hl.index = event->get("index").toInt();
}
catch(...) {
} catch (...) {
hl.index = 0;
}
hl.x = event->getU16("x");
hl.y = event->getU16("y");
hl.x = event->getU16("x");
hl.y = event->getU16("y");
if (projectConfig.getHealLocationRespawnDataEnabled()) {
hl.respawnNPC = event->getU16("respawn_npc");
hl.respawnMap = Map::mapConstantFromName(event->get("respawn_map")).remove(0,4);
hl.respawnMap = Map::mapConstantFromName(event->get("respawn_map")).remove(0, 4);
}
return hl;
}
QDebug operator<<(QDebug debug, const HealLocation &hl)
{
QDebug operator<<(QDebug debug, const HealLocation& hl) {
debug << "HealLocation_" + hl.mapName << "(" << hl.x << ',' << hl.y << ")";
return debug;
}

View file

@ -11,22 +11,21 @@ unsigned long crc_table[256];
int crc_table_computed = 0;
/* Make the table for a fast CRC. */
void make_crc_table(void)
{
unsigned long c;
int n, k;
void make_crc_table(void) {
unsigned long c;
int n, k;
for (n = 0; n < 256; n++) {
c = (unsigned long) n;
for (k = 0; k < 8; k++) {
if (c & 1)
c = 0xedb88320L ^ (c >> 1);
else
c = c >> 1;
for (n = 0; n < 256; n++) {
c = (unsigned long)n;
for (k = 0; k < 8; k++) {
if (c & 1)
c = 0xedb88320L ^ (c >> 1);
else
c = c >> 1;
}
crc_table[n] = c;
}
crc_table[n] = c;
}
crc_table_computed = 1;
crc_table_computed = 1;
}
/* Update a running CRC with the bytes buf[0..len-1]--the CRC
@ -34,24 +33,21 @@ void make_crc_table(void)
is the 1's complement of the final running CRC (see the
crc() routine below)). */
unsigned long update_crc(unsigned long crc, QByteArray buf,
int len)
{
unsigned long c = crc;
int n;
unsigned long update_crc(unsigned long crc, QByteArray buf, int len) {
unsigned long c = crc;
int n;
if (!crc_table_computed)
make_crc_table();
for (n = 0; n < len; n++) {
c = crc_table[(c ^ static_cast<unsigned char>(buf[n])) & 0xff] ^ (c >> 8);
}
return c;
if (!crc_table_computed)
make_crc_table();
for (n = 0; n < len; n++) {
c = crc_table[(c ^ static_cast<unsigned char>(buf[n])) & 0xff] ^ (c >> 8);
}
return c;
}
/* Return the CRC of the bytes buf[0..len-1]. */
unsigned long crc(QByteArray buf, int len)
{
return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
unsigned long crc(QByteArray buf, int len) {
return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;
}
// Qt does not have the ability to export indexed PNG files with a
@ -60,8 +56,7 @@ unsigned long crc(QByteArray buf, int len)
// and re-importing into porymap (Qt), will cause the image to be
// interpreted as having too many colors. By properly exporting 16-palette
// images in porymap, we can effectively avoid that issue.
void exportIndexed4BPPPng(QImage image, QString filepath)
{
void exportIndexed4BPPPng(QImage image, QString filepath) {
// Verify that the image is not empty
if (image.isNull()) {
logError(QString("Failed to export %1: the image is null.").arg(filepath));
@ -83,13 +78,13 @@ void exportIndexed4BPPPng(QImage image, QString filepath)
int width = image.width();
ihdr.append(static_cast<char>((width >> 24) & 0xFF));
ihdr.append(static_cast<char>((width >> 16) & 0xFF));
ihdr.append(static_cast<char>((width >> 8) & 0xFF));
ihdr.append(static_cast<char>((width >> 0) & 0xFF));
ihdr.append(static_cast<char>((width >> 8) & 0xFF));
ihdr.append(static_cast<char>((width >> 0) & 0xFF));
int height = image.height();
ihdr.append(static_cast<char>((height >> 24) & 0xFF));
ihdr.append(static_cast<char>((height >> 16) & 0xFF));
ihdr.append(static_cast<char>((height >> 8) & 0xFF));
ihdr.append(static_cast<char>((height >> 0) & 0xFF));
ihdr.append(static_cast<char>((height >> 8) & 0xFF));
ihdr.append(static_cast<char>((height >> 0) & 0xFF));
ihdr.append(static_cast<char>(4)); // bit depth
ihdr.append(static_cast<char>(3)); // indexed color type
ihdr.append(static_cast<char>(0)); // compression method
@ -98,8 +93,8 @@ void exportIndexed4BPPPng(QImage image, QString filepath)
unsigned long ihdrCRC = crc(ihdr, 17);
ihdr.append(static_cast<char>((ihdrCRC >> 24) & 0xFF));
ihdr.append(static_cast<char>((ihdrCRC >> 16) & 0xFF));
ihdr.append(static_cast<char>((ihdrCRC >> 8) & 0xFF));
ihdr.append(static_cast<char>((ihdrCRC >> 0) & 0xFF));
ihdr.append(static_cast<char>((ihdrCRC >> 8) & 0xFF));
ihdr.append(static_cast<char>((ihdrCRC >> 0) & 0xFF));
// PLTE Chunk
int numColors = image.colorCount();
@ -114,8 +109,8 @@ void exportIndexed4BPPPng(QImage image, QString filepath)
unsigned long plteCRC = crc(plte, numColors * 3 + 4);
plte.append(static_cast<char>((plteCRC >> 24) & 0xFF));
plte.append(static_cast<char>((plteCRC >> 16) & 0xFF));
plte.append(static_cast<char>((plteCRC >> 8) & 0xFF));
plte.append(static_cast<char>((plteCRC >> 0) & 0xFF));
plte.append(static_cast<char>((plteCRC >> 8) & 0xFF));
plte.append(static_cast<char>((plteCRC >> 0) & 0xFF));
// IDAT Chunk
QByteArray idat;
@ -146,8 +141,8 @@ void exportIndexed4BPPPng(QImage image, QString filepath)
unsigned long idatCRC = crc(idat, compressedPixelData.length() + 4);
idat.append(static_cast<char>((idatCRC >> 24) & 0xFF));
idat.append(static_cast<char>((idatCRC >> 16) & 0xFF));
idat.append(static_cast<char>((idatCRC >> 8) & 0xFF));
idat.append(static_cast<char>((idatCRC >> 0) & 0xFF));
idat.append(static_cast<char>((idatCRC >> 8) & 0xFF));
idat.append(static_cast<char>((idatCRC >> 0) & 0xFF));
// IEND Chunk
QByteArray iend;
@ -155,30 +150,30 @@ void exportIndexed4BPPPng(QImage image, QString filepath)
unsigned long iendCRC = crc(iend, 4);
iend.append(static_cast<char>((iendCRC >> 24) & 0xFF));
iend.append(static_cast<char>((iendCRC >> 16) & 0xFF));
iend.append(static_cast<char>((iendCRC >> 8) & 0xFF));
iend.append(static_cast<char>((iendCRC >> 0) & 0xFF));
iend.append(static_cast<char>((iendCRC >> 8) & 0xFF));
iend.append(static_cast<char>((iendCRC >> 0) & 0xFF));
QByteArray data;
data.append(pngHeader);
data.append(static_cast<char>(((ihdr.length() - 8) >> 24) & 0xFF));
data.append(static_cast<char>(((ihdr.length() - 8) >> 16) & 0xFF));
data.append(static_cast<char>(((ihdr.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((ihdr.length() - 8) >> 0) & 0xFF));
data.append(static_cast<char>(((ihdr.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((ihdr.length() - 8) >> 0) & 0xFF));
data.append(ihdr);
data.append(static_cast<char>(((plte.length() - 8) >> 24) & 0xFF));
data.append(static_cast<char>(((plte.length() - 8) >> 16) & 0xFF));
data.append(static_cast<char>(((plte.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((plte.length() - 8) >> 0) & 0xFF));
data.append(static_cast<char>(((plte.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((plte.length() - 8) >> 0) & 0xFF));
data.append(plte);
data.append(static_cast<char>(((idat.length() - 8) >> 24) & 0xFF));
data.append(static_cast<char>(((idat.length() - 8) >> 16) & 0xFF));
data.append(static_cast<char>(((idat.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((idat.length() - 8) >> 0) & 0xFF));
data.append(static_cast<char>(((idat.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((idat.length() - 8) >> 0) & 0xFF));
data.append(idat);
data.append(static_cast<char>(((iend.length() - 8) >> 24) & 0xFF));
data.append(static_cast<char>(((iend.length() - 8) >> 16) & 0xFF));
data.append(static_cast<char>(((iend.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((iend.length() - 8) >> 0) & 0xFF));
data.append(static_cast<char>(((iend.length() - 8) >> 8) & 0xFF));
data.append(static_cast<char>(((iend.length() - 8) >> 0) & 0xFF));
data.append(iend);
QFile file(filepath);

View file

@ -10,17 +10,16 @@
#include <QImage>
#include <QRegularExpression>
Map::Map(QObject *parent) : QObject(parent)
{
Map::Map(QObject* parent) : QObject(parent) {
editHistory.setClean();
}
Map::~Map() {
// delete all associated events
while (!ownedEvents.isEmpty()) {
Event *last = ownedEvents.takeLast();
if (last) delete last;
Event* last = ownedEvents.takeLast();
if (last)
delete last;
}
}
@ -42,23 +41,19 @@ QString Map::mapConstantFromName(QString mapName) {
return constantName;
}
QString Map::objectEventsLabelFromName(QString mapName)
{
QString Map::objectEventsLabelFromName(QString mapName) {
return QString("%1_EventObjects").arg(mapName);
}
QString Map::warpEventsLabelFromName(QString mapName)
{
QString Map::warpEventsLabelFromName(QString mapName) {
return QString("%1_MapWarps").arg(mapName);
}
QString Map::coordEventsLabelFromName(QString mapName)
{
QString Map::coordEventsLabelFromName(QString mapName) {
return QString("%1_MapCoordEvents").arg(mapName);
}
QString Map::bgEventsLabelFromName(QString mapName)
{
QString Map::bgEventsLabelFromName(QString mapName) {
return QString("%1_MapBGEvents").arg(mapName);
}
@ -78,7 +73,7 @@ int Map::getBorderHeight() {
return layout->border_height.toInt(nullptr, 0);
}
bool Map::mapBlockChanged(int i, const Blockdata &cache) {
bool Map::mapBlockChanged(int i, const Blockdata& cache) {
if (cache.length() <= i)
return true;
if (layout->blockdata.length() <= i)
@ -87,7 +82,7 @@ bool Map::mapBlockChanged(int i, const Blockdata &cache) {
return layout->blockdata.at(i) != cache.at(i);
}
bool Map::borderBlockChanged(int i, const Blockdata &cache) {
bool Map::borderBlockChanged(int i, const Blockdata& cache) {
if (cache.length() <= i)
return true;
if (layout->border.length() <= i)
@ -98,19 +93,19 @@ bool Map::borderBlockChanged(int i, const Blockdata &cache) {
void Map::cacheBorder() {
layout->cached_border.clear();
for (const auto &block : layout->border)
for (const auto& block : layout->border)
layout->cached_border.append(block);
}
void Map::cacheBlockdata() {
layout->cached_blockdata.clear();
for (const auto &block : layout->blockdata)
for (const auto& block : layout->blockdata)
layout->cached_blockdata.append(block);
}
void Map::cacheCollision() {
layout->cached_collision.clear();
for (const auto &block : layout->blockdata)
for (const auto& block : layout->blockdata)
layout->cached_collision.append(block);
}
@ -153,7 +148,7 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
return collision_pixmap;
}
QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) {
QPixmap Map::render(bool ignoreCache = false, MapLayout* fromLayout) {
bool changed_any = false;
int width_ = getWidth();
int height_ = getHeight();
@ -173,13 +168,8 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) {
}
changed_any = true;
Block block = layout->blockdata.at(i);
QImage metatile_image = getMetatileImage(
block.tile,
fromLayout ? fromLayout->tileset_primary : layout->tileset_primary,
fromLayout ? fromLayout->tileset_secondary : layout->tileset_secondary,
metatileLayerOrder,
metatileLayerOpacity
);
QImage metatile_image = getMetatileImage(block.tile, fromLayout ? fromLayout->tileset_primary : layout->tileset_primary,
fromLayout ? fromLayout->tileset_secondary : layout->tileset_secondary, metatileLayerOrder, metatileLayerOpacity);
int map_y = width_ ? i / width_ : 0;
int map_x = width_ ? i % width_ : 0;
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
@ -232,7 +222,7 @@ QPixmap Map::renderBorder(bool ignoreCache) {
return layout->border_pixmap;
}
QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) {
QPixmap Map::renderConnection(MapConnection connection, MapLayout* fromLayout) {
render(true, fromLayout);
int x, y, w, h;
if (connection.direction == "up") {
@ -263,7 +253,7 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout)
h = getHeight();
}
QImage connection_image = image.copy(x * 16, y * 16, w * 16, h * 16);
//connection_image = connection_image.convertToFormat(QImage::Format_Grayscale8);
// connection_image = connection_image.convertToFormat(QImage::Format_Grayscale8);
return QPixmap::fromImage(connection_image);
}
@ -274,14 +264,14 @@ void Map::setNewDimensionsBlockdata(int newWidth, int newHeight) {
Blockdata newBlockdata;
for (int y = 0; y < newHeight; y++)
for (int x = 0; x < newWidth; x++) {
if (x < oldWidth && y < oldHeight) {
int index = y * oldWidth + x;
newBlockdata.append(layout->blockdata.value(index));
} else {
newBlockdata.append(0);
for (int x = 0; x < newWidth; x++) {
if (x < oldWidth && y < oldHeight) {
int index = y * oldWidth + x;
newBlockdata.append(layout->blockdata.value(index));
} else {
newBlockdata.append(0);
}
}
}
layout->blockdata = newBlockdata;
}
@ -293,14 +283,14 @@ void Map::setNewBorderDimensionsBlockdata(int newWidth, int newHeight) {
Blockdata newBlockdata;
for (int y = 0; y < newHeight; y++)
for (int x = 0; x < newWidth; x++) {
if (x < oldWidth && y < oldHeight) {
int index = y * oldWidth + x;
newBlockdata.append(layout->border.value(index));
} else {
newBlockdata.append(0);
for (int x = 0; x < newWidth; x++) {
if (x < oldWidth && y < oldHeight) {
int index = y * oldWidth + x;
newBlockdata.append(layout->border.value(index));
} else {
newBlockdata.append(0);
}
}
}
layout->border = newBlockdata;
}
@ -328,7 +318,7 @@ void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata)
emit mapChanged(this);
}
bool Map::getBlock(int x, int y, Block *out) {
bool Map::getBlock(int x, int y, Block* out) {
if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
int i = y * getWidth() + x;
*out = layout->blockdata.value(i);
@ -409,21 +399,21 @@ void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t colli
}
}
QList<Event *> Map::getAllEvents() const {
QList<Event *> all_events;
for (const auto &event_list : events) {
QList<Event*> Map::getAllEvents() const {
QList<Event*> all_events;
for (const auto& event_list : events) {
all_events << event_list;
}
return all_events;
}
QStringList Map::eventScriptLabels(const QString &event_group_type) const {
QStringList Map::eventScriptLabels(const QString& event_group_type) const {
QStringList scriptLabels;
if (event_group_type.isEmpty()) {
for (const auto *event : getAllEvents())
for (const auto* event : getAllEvents())
scriptLabels << event->get("script_label");
} else {
for (const auto *event : events.value(event_group_type))
for (const auto* event : events.value(event_group_type))
scriptLabels << event->get("script_label");
}
@ -437,15 +427,16 @@ QStringList Map::eventScriptLabels(const QString &event_group_type) const {
return scriptLabels;
}
void Map::removeEvent(Event *event) {
void Map::removeEvent(Event* event) {
for (QString key : events.keys()) {
events[key].removeAll(event);
}
}
void Map::addEvent(Event *event) {
void Map::addEvent(Event* event) {
events[event->get("event_group_type")].append(event);
if (!ownedEvents.contains(event)) ownedEvents.append(event);
if (!ownedEvents.contains(event))
ownedEvents.append(event);
}
bool Map::hasUnsavedChanges() {

View file

@ -2,12 +2,8 @@
#include "tileset.h"
#include "project.h"
Metatile::Metatile() :
behavior(0),
layerType(0),
encounterType(0),
terrainType(0)
{ }
Metatile::Metatile() : behavior(0), layerType(0), encounterType(0), terrainType(0) {
}
int Metatile::getBlockIndex(int index) {
if (index < Project::getNumMetatilesPrimary()) {
@ -17,7 +13,7 @@ int Metatile::getBlockIndex(int index) {
}
}
QPoint Metatile::coordFromPixmapCoord(const QPointF &pixelCoord) {
QPoint Metatile::coordFromPixmapCoord(const QPointF& pixelCoord) {
int x = static_cast<int>(pixelCoord.x()) / 16;
int y = static_cast<int>(pixelCoord.y()) / 16;
return QPoint(x, y);

View file

@ -3,18 +3,15 @@
#include "log.h"
#include "project.h"
MetatileParser::MetatileParser()
{
MetatileParser::MetatileParser() {
}
QList<Metatile*> MetatileParser::parse(QString filepath, bool *error, bool primaryTileset)
{
QList<Metatile*> MetatileParser::parse(QString filepath, bool* error, bool primaryTileset) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
*error = true;
logError(QString("Could not open Advance Map 1.92 Metatile .bvd file '%1': ").arg(filepath) + file.errorString());
return { };
return {};
}
QByteArray in = file.readAll();
@ -23,81 +20,69 @@ QList<Metatile*> MetatileParser::parse(QString filepath, bool *error, bool prima
if (in.length() < 9 || in.length() % 2 != 0) {
*error = true;
logError(QString("Advance Map 1.92 Metatile .bvd file '%1' is an unexpected size.").arg(filepath));
return { };
return {};
}
int projIdOffset = in.length() - 4;
int metatileSize = 16;
int attrSize;
BaseGameVersion version;
if (in.at(projIdOffset + 0) == 'R'
&& in.at(projIdOffset + 1) == 'S'
&& in.at(projIdOffset + 2) == 'E'
&& in.at(projIdOffset + 3) == ' ') {
if (in.at(projIdOffset + 0) == 'R' && in.at(projIdOffset + 1) == 'S' && in.at(projIdOffset + 2) == 'E' && in.at(projIdOffset + 3) == ' ') {
// ruby and emerald are handled equally here.
version = BaseGameVersion::pokeemerald;
attrSize = 2;
} else if (in.at(projIdOffset + 0) == 'F'
&& in.at(projIdOffset + 1) == 'R'
&& in.at(projIdOffset + 2) == 'L'
&& in.at(projIdOffset + 3) == 'G') {
} else if (in.at(projIdOffset + 0) == 'F' && in.at(projIdOffset + 1) == 'R' && in.at(projIdOffset + 2) == 'L' && in.at(projIdOffset + 3) == 'G') {
version = BaseGameVersion::pokefirered;
attrSize = 4;
} else {
*error = true;
logError(QString("Detected unsupported game type from .bvd file. Last 4 bytes of file must be 'RSE ' or 'FRLG'."));
return { };
return {};
}
int maxMetatiles = primaryTileset ? Project::getNumMetatilesPrimary() : Project::getNumMetatilesTotal() - Project::getNumMetatilesPrimary();
int numMetatiles = static_cast<unsigned char>(in.at(0)) |
(static_cast<unsigned char>(in.at(1)) << 8) |
(static_cast<unsigned char>(in.at(2)) << 16) |
(static_cast<unsigned char>(in.at(3)) << 24);
int numMetatiles = static_cast<unsigned char>(in.at(0)) | (static_cast<unsigned char>(in.at(1)) << 8) | (static_cast<unsigned char>(in.at(2)) << 16)
| (static_cast<unsigned char>(in.at(3)) << 24);
if (numMetatiles > maxMetatiles) {
*error = true;
logError(QString(".bvd file contains data for %1 metatiles, but the maximum number of metatiles is %2.").arg(numMetatiles).arg(maxMetatiles));
return { };
return {};
}
if (numMetatiles < 1) {
*error = true;
logError(QString(".bvd file contains no data for metatiles."));
return { };
return {};
}
int expectedFileSize = 4 + (metatileSize * numMetatiles) + (attrSize * numMetatiles) + 4;
if (in.length() != expectedFileSize) {
*error = true;
logError(QString(".bvd file is an unexpected size. Expected %1 bytes, but it has %2 bytes.").arg(expectedFileSize).arg(in.length()));
return { };
return {};
}
QList<Metatile*> metatiles;
for (int i = 0; i < numMetatiles; i++) {
Metatile *metatile = new Metatile();
Metatile* metatile = new Metatile();
QList<Tile> tiles;
for (int j = 0; j < 8; j++) {
int metatileOffset = 4 + i * metatileSize + j * 2;
uint16_t word = static_cast<uint16_t>(
static_cast<unsigned char>(in.at(metatileOffset)) |
(static_cast<unsigned char>(in.at(metatileOffset + 1)) << 8));
uint16_t word
= static_cast<uint16_t>(static_cast<unsigned char>(in.at(metatileOffset)) | (static_cast<unsigned char>(in.at(metatileOffset + 1)) << 8));
Tile tile(word & 0x3ff, (word >> 10) & 1, (word >> 11) & 1, (word >> 12) & 0xf);
tiles.append(tile);
}
int attrOffset = 4 + (numMetatiles * metatileSize) + (i * attrSize);
if (version == BaseGameVersion::pokefirered) {
int value = static_cast<unsigned char>(in.at(attrOffset)) |
(static_cast<unsigned char>(in.at(attrOffset + 1)) << 8) |
(static_cast<unsigned char>(in.at(attrOffset + 2)) << 16) |
(static_cast<unsigned char>(in.at(attrOffset + 3)) << 24);
int value = static_cast<unsigned char>(in.at(attrOffset)) | (static_cast<unsigned char>(in.at(attrOffset + 1)) << 8)
| (static_cast<unsigned char>(in.at(attrOffset + 2)) << 16) | (static_cast<unsigned char>(in.at(attrOffset + 3)) << 24);
metatile->behavior = value & 0x1FF;
metatile->terrainType = (value & 0x3E00) >> 9;
metatile->encounterType = (value & 0x7000000) >> 24;
metatile->layerType = (value & 0x60000000) >> 29;
} else {
int value = static_cast<unsigned char>(in.at(attrOffset)) |
(static_cast<unsigned char>(in.at(attrOffset + 1)) << 8);
int value = static_cast<unsigned char>(in.at(attrOffset)) | (static_cast<unsigned char>(in.at(attrOffset + 1)) << 8);
metatile->behavior = value & 0xFF;
metatile->layerType = (value & 0xF000) >> 12;
metatile->encounterType = 0;

View file

@ -3,12 +3,10 @@
#include <QFileInfo>
#include <QRegularExpression>
PaletteUtil::PaletteUtil()
{
PaletteUtil::PaletteUtil() {
}
QList<QRgb> PaletteUtil::parse(QString filepath, bool *error) {
QList<QRgb> PaletteUtil::parse(QString filepath, bool* error) {
QFileInfo info(filepath);
QString extension = info.completeSuffix();
if (extension.isNull()) {
@ -34,7 +32,7 @@ QList<QRgb> PaletteUtil::parse(QString filepath, bool *error) {
return QList<QRgb>();
}
QList<QRgb> PaletteUtil::parsePal(QString filepath, bool *error) {
QList<QRgb> PaletteUtil::parsePal(QString filepath, bool* error) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
*error = true;
@ -53,7 +51,7 @@ QList<QRgb> PaletteUtil::parsePal(QString filepath, bool *error) {
}
}
QList<QRgb> PaletteUtil::parseJASC(QString filepath, bool *error) {
QList<QRgb> PaletteUtil::parseJASC(QString filepath, bool* error) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
*error = true;
@ -105,9 +103,7 @@ QList<QRgb> PaletteUtil::parseJASC(QString filepath, bool *error) {
return QList<QRgb>();
}
palette.append(qRgb(this->clampColorValue(red),
this->clampColorValue(green),
this->clampColorValue(blue)));
palette.append(qRgb(this->clampColorValue(red), this->clampColorValue(green), this->clampColorValue(blue)));
} else {
*error = true;
logError(QString("JASC palette file '%1' had an unexpected format. Invalid color '%2'.").arg(filepath).arg(line));
@ -120,7 +116,7 @@ QList<QRgb> PaletteUtil::parseJASC(QString filepath, bool *error) {
return palette;
}
QList<QRgb> PaletteUtil::parseAdvanceMapPal(QString filepath, bool *error) {
QList<QRgb> PaletteUtil::parseAdvanceMapPal(QString filepath, bool* error) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
*error = true;
@ -133,7 +129,9 @@ QList<QRgb> PaletteUtil::parseAdvanceMapPal(QString filepath, bool *error) {
if (in.length() % 4 != 0) {
*error = true;
logError(QString("Advance Map 1.92 palette file '%1' had an unexpected format. File's length must be a multiple of 4, but the length is %2.").arg(filepath).arg(in.length()));
logError(QString("Advance Map 1.92 palette file '%1' had an unexpected format. File's length must be a multiple of 4, but the length is %2.")
.arg(filepath)
.arg(in.length()));
return QList<QRgb>();
}
@ -143,16 +141,14 @@ QList<QRgb> PaletteUtil::parseAdvanceMapPal(QString filepath, bool *error) {
unsigned char red = static_cast<unsigned char>(in.at(i));
unsigned char green = static_cast<unsigned char>(in.at(i + 1));
unsigned char blue = static_cast<unsigned char>(in.at(i + 2));
palette.append(qRgb(this->clampColorValue(red),
this->clampColorValue(green),
this->clampColorValue(blue)));
palette.append(qRgb(this->clampColorValue(red), this->clampColorValue(green), this->clampColorValue(blue)));
i += 4;
}
return palette;
}
QList<QRgb> PaletteUtil::parseAdobeColorTable(QString filepath, bool *error) {
QList<QRgb> PaletteUtil::parseAdobeColorTable(QString filepath, bool* error) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
*error = true;
@ -165,7 +161,9 @@ QList<QRgb> PaletteUtil::parseAdobeColorTable(QString filepath, bool *error) {
if (in.length() != 0x300) {
*error = true;
logError(QString("Adobe Color Table palette file '%1' had an unexpected format. File's length must be exactly 768, but the length is %2.").arg(filepath).arg(in.length()));
logError(QString("Adobe Color Table palette file '%1' had an unexpected format. File's length must be exactly 768, but the length is %2.")
.arg(filepath)
.arg(in.length()));
return QList<QRgb>();
}
@ -175,16 +173,14 @@ QList<QRgb> PaletteUtil::parseAdobeColorTable(QString filepath, bool *error) {
unsigned char red = static_cast<unsigned char>(in.at(i));
unsigned char green = static_cast<unsigned char>(in.at(i + 1));
unsigned char blue = static_cast<unsigned char>(in.at(i + 2));
palette.append(qRgb(this->clampColorValue(red),
this->clampColorValue(green),
this->clampColorValue(blue)));
palette.append(qRgb(this->clampColorValue(red), this->clampColorValue(green), this->clampColorValue(blue)));
i += 3;
}
return palette;
}
QList<QRgb> PaletteUtil::parseTileLayerPro(QString filepath, bool *error) {
QList<QRgb> PaletteUtil::parseTileLayerPro(QString filepath, bool* error) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
*error = true;
@ -203,7 +199,9 @@ QList<QRgb> PaletteUtil::parseTileLayerPro(QString filepath, bool *error) {
if (in.length() != 0x304) {
*error = true;
logError(QString("Tile Layer Pro palette file '%1' had an unexpected format. File's length must be exactly 772, but the length is %2.").arg(filepath).arg(in.length()));
logError(QString("Tile Layer Pro palette file '%1' had an unexpected format. File's length must be exactly 772, but the length is %2.")
.arg(filepath)
.arg(in.length()));
return QList<QRgb>();
}
@ -213,16 +211,14 @@ QList<QRgb> PaletteUtil::parseTileLayerPro(QString filepath, bool *error) {
unsigned char red = static_cast<unsigned char>(in.at(i));
unsigned char green = static_cast<unsigned char>(in.at(i + 1));
unsigned char blue = static_cast<unsigned char>(in.at(i + 2));
palette.append(qRgb(this->clampColorValue(red),
this->clampColorValue(green),
this->clampColorValue(blue)));
palette.append(qRgb(this->clampColorValue(red), this->clampColorValue(green), this->clampColorValue(blue)));
i += 3;
}
return palette;
}
QList<QRgb> PaletteUtil::parseAdvancePaletteEditor(QString filepath, bool *error) {
QList<QRgb> PaletteUtil::parseAdvancePaletteEditor(QString filepath, bool* error) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
*error = true;
@ -254,13 +250,11 @@ QList<QRgb> PaletteUtil::parseAdvancePaletteEditor(QString filepath, bool *error
return QList<QRgb>();
}
raw = ((raw & 0xFF)<< 8) | ((raw >> 8) & 0xFF);
raw = ((raw & 0xFF) << 8) | ((raw >> 8) & 0xFF);
int red = (raw & 0x1F) * 8;
int green = ((raw >> 5) & 0x1F) * 8;
int blue = ((raw >> 10) & 0x1F) * 8;
palette.append(qRgb(this->clampColorValue(red),
this->clampColorValue(green),
this->clampColorValue(blue)));
palette.append(qRgb(this->clampColorValue(red), this->clampColorValue(green), this->clampColorValue(blue)));
}
file.close();
@ -282,9 +276,7 @@ void PaletteUtil::writeJASC(QString filepath, QVector<QRgb> palette, int offset,
for (int i = offset; i < offset + nColors; i++) {
QRgb color = palette.at(i);
text += QString::number(qRed(color)) + " "
+ QString::number(qGreen(color)) + " "
+ QString::number(qBlue(color)) + "\r\n";
text += QString::number(qRed(color)) + " " + QString::number(qGreen(color)) + " " + QString::number(qBlue(color)) + "\r\n";
}
QFile file(filepath);

View file

@ -6,23 +6,23 @@
#include <QJsonObject>
#include <QStack>
void ParseUtil::set_root(const QString &dir) {
void ParseUtil::set_root(const QString& dir) {
this->root = dir;
}
void ParseUtil::error(const QString &message, const QString &expression) {
void ParseUtil::error(const QString& message, const QString& expression) {
QStringList lines = text.split(QRegularExpression("[\r\n]"));
int lineNum = 0, colNum = 0;
for (QString line : lines) {
lineNum++;
colNum = line.indexOf(expression) + 1;
if (colNum) break;
if (colNum)
break;
}
logError(QString("%1:%2:%3: %4").arg(file).arg(lineNum).arg(colNum).arg(message));
}
QString ParseUtil::readTextFile(const QString &path) {
QString ParseUtil::readTextFile(const QString& path) {
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
logError(QString("Could not open '%1': ").arg(path) + file.errorString());
@ -37,17 +37,17 @@ QString ParseUtil::readTextFile(const QString &path) {
return text;
}
int ParseUtil::textFileLineCount(const QString &path) {
int ParseUtil::textFileLineCount(const QString& path) {
const QString text = readTextFile(path);
return text.split('\n').count() + 1;
}
QList<QStringList> ParseUtil::parseAsm(const QString &filename) {
QList<QStringList> ParseUtil::parseAsm(const QString& filename) {
QList<QStringList> parsed;
text = readTextFile(root + '/' + filename);
const QStringList lines = removeLineComments(text, "@").split('\n');
for (const auto &line : lines) {
for (const auto& line : lines) {
const QString trimmedLine = line.trimmed();
if (trimmedLine.isEmpty()) {
continue;
@ -70,17 +70,23 @@ QList<QStringList> ParseUtil::parseAsm(const QString &filename) {
return parsed;
}
int ParseUtil::evaluateDefine(const QString &define, const QMap<QString, int> &knownDefines) {
int ParseUtil::evaluateDefine(const QString& define, const QMap<QString, int>& knownDefines) {
QList<Token> tokens = tokenizeExpression(define, knownDefines);
QList<Token> postfixExpression = generatePostfix(tokens);
return evaluatePostfix(postfixExpression);
}
QList<Token> ParseUtil::tokenizeExpression(QString expression, const QMap<QString, int> &knownIdentifiers) {
QList<Token> ParseUtil::tokenizeExpression(QString expression, const QMap<QString, int>& knownIdentifiers) {
QList<Token> tokens;
QStringList tokenTypes = (QStringList() << "hex" << "decimal" << "identifier" << "operator" << "leftparen" << "rightparen");
QRegularExpression re("^(?<hex>0x[0-9a-fA-F]+)|(?<decimal>[0-9]+)|(?<identifier>[a-zA-Z_0-9]+)|(?<operator>[+\\-*\\/<>|^%]+)|(?<leftparen>\\()|(?<rightparen>\\))");
QStringList tokenTypes = (QStringList() << "hex"
<< "decimal"
<< "identifier"
<< "operator"
<< "leftparen"
<< "rightparen");
QRegularExpression re(
"^(?<hex>0x[0-9a-fA-F]+)|(?<decimal>[0-9]+)|(?<identifier>[a-zA-Z_0-9]+)|(?<operator>[+\\-*\\/<>|^%]+)|(?<leftparen>\\()|(?<rightparen>\\))");
expression = expression.trimmed();
while (!expression.isEmpty()) {
@ -100,15 +106,12 @@ QList<Token> ParseUtil::tokenizeExpression(QString expression, const QMap<QStrin
tokenType = "decimal";
} else {
tokenType = "error";
QString message = QString("unknown token '%1' found in expression '%2'")
.arg(token).arg(expression);
QString message = QString("unknown token '%1' found in expression '%2'").arg(token).arg(expression);
error(message, expression);
}
}
else if (tokenType == "operator") {
} else if (tokenType == "operator") {
if (!Token::precedenceMap.contains(token)) {
QString message = QString("unsupported postfix operator: '%1'")
.arg(token);
QString message = QString("unsupported postfix operator: '%1'").arg(token);
error(message, expression);
}
}
@ -122,22 +125,12 @@ QList<Token> ParseUtil::tokenizeExpression(QString expression, const QMap<QStrin
return tokens;
}
QMap<QString, int> Token::precedenceMap = QMap<QString, int>(
{
{"*", 3},
{"/", 3},
{"+", 4},
{"-", 4},
{"<<", 5},
{">>", 5},
{"&", 8},
{"^", 9},
{"|", 10}
});
QMap<QString, int> Token::precedenceMap
= QMap<QString, int>({ { "*", 3 }, { "/", 3 }, { "+", 4 }, { "-", 4 }, { "<<", 5 }, { ">>", 5 }, { "&", 8 }, { "^", 9 }, { "|", 10 } });
// Shunting-yard algorithm for generating postfix notation.
// https://en.wikipedia.org/wiki/Shunting-yard_algorithm
QList<Token> ParseUtil::generatePostfix(const QList<Token> &tokens) {
QList<Token> ParseUtil::generatePostfix(const QList<Token>& tokens) {
QList<Token> output;
QStack<Token> operatorStack;
for (Token token : tokens) {
@ -157,9 +150,7 @@ QList<Token> ParseUtil::generatePostfix(const QList<Token> &tokens) {
}
} else {
// token is an operator
while (!operatorStack.isEmpty()
&& operatorStack.top().operatorPrecedence <= token.operatorPrecedence
&& operatorStack.top().value != "(") {
while (!operatorStack.isEmpty() && operatorStack.top().operatorPrecedence <= token.operatorPrecedence && operatorStack.top().value != "(") {
output.append(operatorStack.pop());
}
operatorStack.push(token);
@ -179,7 +170,7 @@ QList<Token> ParseUtil::generatePostfix(const QList<Token> &tokens) {
// Evaluate postfix expression.
// https://en.wikipedia.org/wiki/Reverse_Polish_notation#Postfix_evaluation_algorithm
int ParseUtil::evaluatePostfix(const QList<Token> &postfix) {
int ParseUtil::evaluatePostfix(const QList<Token>& postfix) {
QStack<Token> stack;
for (Token token : postfix) {
if (token.type == TokenClass::Operator && stack.size() > 1) {
@ -213,7 +204,7 @@ int ParseUtil::evaluatePostfix(const QList<Token> &postfix) {
return stack.size() ? stack.pop().value.toInt(nullptr, 0) : 0;
}
QString ParseUtil::readCIncbin(const QString &filename, const QString &label) {
QString ParseUtil::readCIncbin(const QString& filename, const QString& label) {
QString path;
if (label.isNull()) {
@ -222,11 +213,11 @@ QString ParseUtil::readCIncbin(const QString &filename, const QString &label) {
text = readTextFile(root + "/" + filename);
QRegExp *re = new QRegExp(QString(
"\\b%1\\b"
"\\s*\\[?\\s*\\]?\\s*=\\s*"
"INCBIN_[US][0-9][0-9]?"
"\\(\\s*\"([^\"]*)\"\\s*\\)").arg(label));
QRegExp* re = new QRegExp(QString("\\b%1\\b"
"\\s*\\[?\\s*\\]?\\s*=\\s*"
"INCBIN_[US][0-9][0-9]?"
"\\(\\s*\"([^\"]*)\"\\s*\\)")
.arg(label));
int pos = re->indexIn(text);
if (pos != -1) {
@ -236,10 +227,7 @@ QString ParseUtil::readCIncbin(const QString &filename, const QString &label) {
return path;
}
QMap<QString, int> ParseUtil::readCDefines(const QString &filename,
const QStringList &prefixes,
QMap<QString, int> allDefines)
{
QMap<QString, int> ParseUtil::readCDefines(const QString& filename, const QStringList& prefixes, QMap<QString, int> allDefines) {
QMap<QString, int> filteredDefines;
file = filename;
@ -267,7 +255,8 @@ QMap<QString, int> ParseUtil::readCDefines(const QString &filename,
QRegularExpressionMatch match = iter.next();
QString name = match.captured("defineName");
QString expression = match.captured("defineValue");
if (expression == " ") continue;
if (expression == " ")
continue;
int value = evaluateDefine(expression, allDefines);
allDefines.insert(name, value);
for (QString prefix : prefixes) {
@ -279,10 +268,7 @@ QMap<QString, int> ParseUtil::readCDefines(const QString &filename,
return filteredDefines;
}
QStringList ParseUtil::readCDefinesSorted(const QString &filename,
const QStringList &prefixes,
const QMap<QString, int> &knownDefines)
{
QStringList ParseUtil::readCDefinesSorted(const QString& filename, const QStringList& prefixes, const QMap<QString, int>& knownDefines) {
QMap<QString, int> defines = readCDefines(filename, prefixes, knownDefines);
// The defines should to be sorted by their underlying value, not alphabetically.
@ -294,7 +280,7 @@ QStringList ParseUtil::readCDefinesSorted(const QString &filename,
return definesInverse.values();
}
QStringList ParseUtil::readCArray(const QString &filename, const QString &label) {
QStringList ParseUtil::readCArray(const QString& filename, const QString& label) {
QStringList list;
if (label.isNull()) {
@ -312,7 +298,8 @@ QStringList ParseUtil::readCArray(const QString &filename, const QString &label)
QStringList split = body.split(',');
for (QString item : split) {
item = item.trimmed();
if (!item.contains(QRegularExpression("[^A-Za-z0-9_&()\\s]"))) list.append(item);
if (!item.contains(QRegularExpression("[^A-Za-z0-9_&()\\s]")))
list.append(item);
// do not print error info here because this is called dozens of times
}
}
@ -320,7 +307,7 @@ QStringList ParseUtil::readCArray(const QString &filename, const QString &label)
return list;
}
QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString &filename, const QString &label) {
QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString& filename, const QString& label) {
text = readTextFile(root + "/" + filename);
QMap<QString, QString> map;
@ -340,10 +327,10 @@ QMap<QString, QString> ParseUtil::readNamedIndexCArray(const QString &filename,
return map;
}
QList<QStringList> ParseUtil::getLabelMacros(const QList<QStringList> &list, const QString &label) {
QList<QStringList> ParseUtil::getLabelMacros(const QList<QStringList>& list, const QString& label) {
bool in_label = false;
QList<QStringList> new_list;
for (const auto &params : list) {
for (const auto& params : list) {
const QString macro = params.value(0);
if (macro == ".label") {
if (params.value(1) == label) {
@ -364,10 +351,10 @@ QList<QStringList> ParseUtil::getLabelMacros(const QList<QStringList> &list, con
// For if you don't care about filtering by macro,
// and just want all values associated with some label.
QStringList ParseUtil::getLabelValues(const QList<QStringList> &list, const QString &label) {
QStringList ParseUtil::getLabelValues(const QList<QStringList>& list, const QString& label) {
const QList<QStringList> labelMacros = getLabelMacros(list, label);
QStringList values;
for (const auto &params : labelMacros) {
for (const auto& params : labelMacros) {
const QString macro = params.value(0);
if (macro == ".align" || macro == ".ifdef" || macro == ".ifndef") {
continue;
@ -379,7 +366,7 @@ QStringList ParseUtil::getLabelValues(const QList<QStringList> &list, const QStr
return values;
}
bool ParseUtil::tryParseJsonFile(QJsonDocument *out, const QString &filepath) {
bool ParseUtil::tryParseJsonFile(QJsonDocument* out, const QString& filepath) {
QFile file(filepath);
if (!file.open(QIODevice::ReadOnly)) {
logError(QString("Error: Could not open %1 for reading").arg(filepath));
@ -399,7 +386,7 @@ bool ParseUtil::tryParseJsonFile(QJsonDocument *out, const QString &filepath) {
return true;
}
bool ParseUtil::ensureFieldsExist(const QJsonObject &obj, const QList<QString> &fields) {
bool ParseUtil::ensureFieldsExist(const QJsonObject& obj, const QList<QString>& fields) {
for (QString field : fields) {
if (!obj.contains(field)) {
logError(QString("JSON object is missing field '%1'.").arg(field));
@ -409,7 +396,7 @@ bool ParseUtil::ensureFieldsExist(const QJsonObject &obj, const QList<QString> &
return true;
}
int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scriptLabel) {
int ParseUtil::getScriptLineNumber(const QString& filePath, const QString& scriptLabel) {
if (scriptLabel.isEmpty())
return 0;
@ -421,7 +408,7 @@ int ParseUtil::getScriptLineNumber(const QString &filePath, const QString &scrip
return 0;
}
int ParseUtil::getRawScriptLineNumber(QString text, const QString &scriptLabel) {
int ParseUtil::getRawScriptLineNumber(QString text, const QString& scriptLabel) {
text = removeStringLiterals(text);
text = removeLineComments(text, "@");
@ -436,9 +423,9 @@ int ParseUtil::getRawScriptLineNumber(QString text, const QString &scriptLabel)
return 0;
}
int ParseUtil::getPoryScriptLineNumber(QString text, const QString &scriptLabel) {
int ParseUtil::getPoryScriptLineNumber(QString text, const QString& scriptLabel) {
text = removeStringLiterals(text);
text = removeLineComments(text, {"//", "#"});
text = removeLineComments(text, { "//", "#" });
static const QRegularExpression re_poryScriptLabel("\\b(script)(\\((global|local)\\))?\\s*\\b(?<label>[\\w_][\\w\\d_]*)");
QRegularExpressionMatchIterator it = re_poryScriptLabel.globalMatch(text);
@ -465,13 +452,13 @@ QString ParseUtil::removeStringLiterals(QString text) {
return text.remove(re_string);
}
QString ParseUtil::removeLineComments(QString text, const QString &commentSymbol) {
QString ParseUtil::removeLineComments(QString text, const QString& commentSymbol) {
const QRegularExpression re_lineComment(commentSymbol + "+.*");
return text.remove(re_lineComment);
}
QString ParseUtil::removeLineComments(QString text, const QStringList &commentSymbols) {
for (const auto &commentSymbol : commentSymbols)
QString ParseUtil::removeLineComments(QString text, const QStringList& commentSymbols) {
for (const auto& commentSymbol : commentSymbols)
text = removeLineComments(text, commentSymbol);
return text;
}

View file

@ -19,7 +19,7 @@ static bool ensureRegionMapFileExists(QString filepath) {
return true;
}
bool RegionMap::init(Project *pro) {
bool RegionMap::init(Project* pro) {
QString path = pro->root;
this->project = pro;
@ -27,23 +27,19 @@ bool RegionMap::init(Project *pro) {
img_width_ = dimensions.width();
img_height_ = dimensions.height();
layout_width_ = img_width_ - this->padLeft - this->padRight;
layout_height_ = img_height_ - this->padTop - this->padBottom;
layout_width_ = img_width_ - this->padLeft - this->padRight;
layout_height_ = img_height_ - this->padTop - this->padBottom;
region_map_bin_path = path + "/graphics/pokenav/region_map_map.bin";
region_map_png_path = path + "/graphics/pokenav/region_map.png";
region_map_entries_path = path + "/src/data/region_map/region_map_entries.h";
region_map_bin_path = path + "/graphics/pokenav/region_map_map.bin";
region_map_png_path = path + "/graphics/pokenav/region_map.png";
region_map_entries_path = path + "/src/data/region_map/region_map_entries.h";
region_map_layout_bin_path = path + "/graphics/pokenav/region_map_section_layout.bin";
city_map_tiles_path = path + "/graphics/pokenav/zoom_tiles.png";
bool allFilesExist = ensureRegionMapFileExists(region_map_bin_path)
&& ensureRegionMapFileExists(region_map_png_path)
&& ensureRegionMapFileExists(region_map_entries_path)
&& ensureRegionMapFileExists(region_map_layout_bin_path)
&& ensureRegionMapFileExists(city_map_tiles_path);
city_map_tiles_path = path + "/graphics/pokenav/zoom_tiles.png";
bool allFilesExist = ensureRegionMapFileExists(region_map_bin_path) && ensureRegionMapFileExists(region_map_png_path)
&& ensureRegionMapFileExists(region_map_entries_path) && ensureRegionMapFileExists(region_map_layout_bin_path)
&& ensureRegionMapFileExists(city_map_tiles_path);
return allFilesExist
&& readBkgImgBin()
&& readLayout();
return allFilesExist && readBkgImgBin() && readLayout();
}
void RegionMap::save() {
@ -106,7 +102,7 @@ bool RegionMap::readBkgImgBin() {
}
void RegionMap::saveBkgImgBin() {
QByteArray data(pow(img_width_ * 2, 2),0);
QByteArray data(pow(img_width_ * 2, 2), 0);
for (int m = 0; m < img_height_; m++) {
for (int n = 0; n < img_width_; n++) {
@ -115,7 +111,8 @@ void RegionMap::saveBkgImgBin() {
}
QFile file(region_map_bin_path);
if (!file.open(QIODevice::WriteOnly)) return;
if (!file.open(QIODevice::WriteOnly))
return;
file.write(data);
file.close();
}
@ -152,12 +149,11 @@ bool RegionMap::readLayout() {
} else if (line.contains("MAPSEC")) {
QRegularExpression reBefore("\\[(.*)\\]");
QRegularExpression reAfter("{(.*)}");
QStringList entry = reAfter.match(line).captured(1).remove(" ").split(",");
QStringList entry = reAfter.match(line).captured(1).remove(" ").split(",");
QString mapsec = reBefore.match(line).captured(1);
QString insertion = entry[4].remove("sMapName_");
qmap.insert(mapsec, sMapNamesMap.value(insertion));
mapSecToMapEntry[mapsec] = {
// x y width height name
mapSecToMapEntry[mapsec] = { // x y width height name
entry[0].toInt(), entry[1].toInt(), entry[2].toInt(), entry[3].toInt(), insertion
};
} else if (line.contains("gRegionMapEntries")) {
@ -181,11 +177,11 @@ bool RegionMap::readLayout() {
for (int y = 0; y < layout_height_; y++) {
for (int x = 0; x < layout_width_; x++) {
int i = img_index_(x,y);
int i = img_index_(x, y);
if (i >= map_squares.size()) {
continue;
}
int layoutIndex = layout_index_(x,y);
int layoutIndex = layout_index_(x, y);
if (layoutIndex >= mapBinData.size()) {
continue;
}
@ -213,26 +209,27 @@ void RegionMap::saveLayout() {
for (auto sName : sMapNames) {
entries_text += QString("%1%2u8 sMapName_")
.arg(project->dataQualifiers.value("region_map_entries_names").isStatic ? "static " : "")
.arg(project->dataQualifiers.value("region_map_entries_names").isConst ? "const " : "")
+ sName + "[] = _(\"" + sMapNamesMap.value(sName) + "\");\n";
.arg(project->dataQualifiers.value("region_map_entries_names").isStatic ? "static " : "")
.arg(project->dataQualifiers.value("region_map_entries_names").isConst ? "const " : "")
+ sName + "[] = _(\"" + sMapNamesMap.value(sName) + "\");\n";
}
entries_text += QString("\n%1%2struct RegionMapLocation gRegionMapEntries[] = {\n")
.arg(project->dataQualifiers.value("region_map_entries").isStatic ? "static " : "")
.arg(project->dataQualifiers.value("region_map_entries").isConst ? "const " : "");
.arg(project->dataQualifiers.value("region_map_entries").isStatic ? "static " : "")
.arg(project->dataQualifiers.value("region_map_entries").isConst ? "const " : "");
int longest = 1;
for (auto sec : project->mapSectionNameToValue.keys()) {
if (sec.length() > longest) longest = sec.length();
if (sec.length() > longest)
longest = sec.length();
}
for (auto sec : project->mapSectionNameToValue.keys()) {
if (!mapSecToMapEntry.contains(sec) || sec == "MAPSEC_NONE") continue;
if (!mapSecToMapEntry.contains(sec) || sec == "MAPSEC_NONE")
continue;
RegionMapEntry entry = mapSecToMapEntry.value(sec);
entries_text += " [" + sec + QString("]%1= {").arg(QString(" ").repeated(1 + longest - sec.length()))
+ QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
+ QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
entries_text += " [" + sec + QString("]%1= {").arg(QString(" ").repeated(1 + longest - sec.length())) + QString::number(entry.x) + ", "
+ QString::number(entry.y) + ", " + QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
}
entries_text += "};\n\n#endif // GUARD_DATA_REGION_MAP_REGION_MAP_ENTRIES_H\n";
@ -241,12 +238,13 @@ void RegionMap::saveLayout() {
QByteArray data;
for (int m = 0; m < layout_height_; m++) {
for (int n = 0; n < layout_width_; n++) {
int i = img_index_(n,m);
int i = img_index_(n, m);
data.append(map_squares[i].secid);
}
}
QFile bfile(region_map_layout_bin_path);
if (!bfile.open(QIODevice::WriteOnly)) return;
if (!bfile.open(QIODevice::WriteOnly))
return;
bfile.write(data);
bfile.close();
}
@ -301,12 +299,13 @@ void RegionMap::clearImage() {
}
void RegionMap::replaceSectionId(unsigned oldId, unsigned newId) {
for (auto &square : map_squares) {
for (auto& square : map_squares) {
if (square.secid == oldId) {
square.has_map = false;
square.secid = newId;
QString secname = project->mapSectionValueToName.value(newId);
if (secname != "MAPSEC_NONE") square.has_map = true;
if (secname != "MAPSEC_NONE")
square.has_map = true;
square.mapsec = secname;
square.map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name);
}
@ -348,7 +347,8 @@ QVector<uint8_t> RegionMap::getTiles() {
}
void RegionMap::setTiles(QVector<uint8_t> tileIds) {
if (tileIds.size() != map_squares.size()) return;
if (tileIds.size() != map_squares.size())
return;
int i = 0;
for (uint8_t tileId : tileIds) {
@ -421,8 +421,8 @@ QString RegionMap::fixCase(QString caps) {
if (big) {
camel += ch.toUpper();
big = false;
}
else camel += ch.toLower();
} else
camel += ch.toLower();
}
return camel;
}

View file

@ -7,8 +7,7 @@
#include <QPainter>
#include <QImage>
Tileset* Tileset::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
Tileset* Tileset::getBlockTileset(int metatile_index, Tileset* primaryTileset, Tileset* secondaryTileset) {
if (metatile_index < Project::getNumMetatilesPrimary()) {
return primaryTileset;
} else {
@ -16,8 +15,8 @@ Tileset* Tileset::getBlockTileset(int metatile_index, Tileset *primaryTileset, T
}
}
Metatile* Tileset::getMetatile(int index, Tileset *primaryTileset, Tileset *secondaryTileset) {
Tileset *tileset = Tileset::getBlockTileset(index, primaryTileset, secondaryTileset);
Metatile* Tileset::getMetatile(int index, Tileset* primaryTileset, Tileset* secondaryTileset) {
Tileset* tileset = Tileset::getBlockTileset(index, primaryTileset, secondaryTileset);
int local_index = Metatile::getBlockIndex(index);
if (!tileset) {
return nullptr;
@ -25,7 +24,7 @@ Metatile* Tileset::getMetatile(int index, Tileset *primaryTileset, Tileset *seco
return tileset->metatiles.value(local_index, nullptr);
}
bool Tileset::metatileIsValid(uint16_t metatileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
bool Tileset::metatileIsValid(uint16_t metatileId, Tileset* primaryTileset, Tileset* secondaryTileset) {
if (metatileId >= Project::getNumMetatilesTotal())
return false;
@ -38,7 +37,7 @@ bool Tileset::metatileIsValid(uint16_t metatileId, Tileset *primaryTileset, Tile
return true;
}
QList<QList<QRgb>> Tileset::getBlockPalettes(Tileset *primaryTileset, Tileset *secondaryTileset, bool useTruePalettes) {
QList<QList<QRgb>> Tileset::getBlockPalettes(Tileset* primaryTileset, Tileset* secondaryTileset, bool useTruePalettes) {
QList<QList<QRgb>> palettes;
auto primaryPalettes = useTruePalettes ? primaryTileset->palettes : primaryTileset->palettePreviews;
for (int i = 0; i < Project::getNumPalettesPrimary(); i++) {
@ -51,11 +50,9 @@ QList<QList<QRgb>> Tileset::getBlockPalettes(Tileset *primaryTileset, Tileset *s
return palettes;
}
QList<QRgb> Tileset::getPalette(int paletteId, Tileset *primaryTileset, Tileset *secondaryTileset, bool useTruePalettes) {
QList<QRgb> Tileset::getPalette(int paletteId, Tileset* primaryTileset, Tileset* secondaryTileset, bool useTruePalettes) {
QList<QRgb> paletteTable;
Tileset *tileset = paletteId < Project::getNumPalettesPrimary()
? primaryTileset
: secondaryTileset;
Tileset* tileset = paletteId < Project::getNumPalettesPrimary() ? primaryTileset : secondaryTileset;
auto palettes = useTruePalettes ? tileset->palettes : tileset->palettePreviews;
for (int i = 0; i < palettes.at(paletteId).length(); i++) {
paletteTable.append(palettes.at(paletteId).at(i));
@ -63,7 +60,7 @@ QList<QRgb> Tileset::getPalette(int paletteId, Tileset *primaryTileset, Tileset
return paletteTable;
}
bool Tileset::appendToHeaders(QString headerFile, QString friendlyName){
bool Tileset::appendToHeaders(QString headerFile, QString friendlyName) {
QFile file(headerFile);
if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) {
logError(QString("Could not write to file \"%1\"").arg(headerFile));
@ -99,10 +96,9 @@ bool Tileset::appendToGraphics(QString graphicsFile, QString friendlyName, bool
}
QString dataString = "\n\t.align 2\n";
dataString.append(QString("gTilesetPalettes_%1::\n").arg(friendlyName));
for(int i = 0; i < Project::getNumPalettesTotal(); ++i) {
for (int i = 0; i < Project::getNumPalettesTotal(); ++i) {
QString paletteString = QString("%1.gbapal").arg(i, 2, 10, QLatin1Char('0'));
dataString.append(QString("\t.incbin \"data/tilesets/%1/%2/palettes/%3\"\n").arg(primaryString, friendlyName.toLower(), paletteString));
}
dataString.append("\n\t.align 2\n");
dataString.append(QString("gTilesetTiles_%1::\n").arg(friendlyName));

View file

@ -1,8 +1,6 @@
#include "wildmoninfo.h"
#include "montabwidget.h"
WildMonInfo getDefaultMonInfo(EncounterField field) {
WildMonInfo newInfo;
newInfo.active = true;
@ -15,21 +13,21 @@ WildMonInfo getDefaultMonInfo(EncounterField field) {
return newInfo;
}
WildMonInfo copyMonInfoFromTab(QTableWidget *monTable, EncounterField monField) {
WildMonInfo copyMonInfoFromTab(QTableWidget* monTable, EncounterField monField) {
WildMonInfo newInfo;
QVector<WildPokemon> newWildMons;
bool extraColumn = !monField.groups.isEmpty();
for (int row = 0; row < monTable->rowCount(); row++) {
WildPokemon newWildMon;
newWildMon.species = monTable->cellWidget(row, extraColumn ? 2 : 1)->findChild<QComboBox *>()->currentText();
newWildMon.minLevel = monTable->cellWidget(row, extraColumn ? 3 : 2)->findChild<QSpinBox *>()->value();
newWildMon.maxLevel = monTable->cellWidget(row, extraColumn ? 4 : 3)->findChild<QSpinBox *>()->value();
newWildMon.species = monTable->cellWidget(row, extraColumn ? 2 : 1)->findChild<QComboBox*>()->currentText();
newWildMon.minLevel = monTable->cellWidget(row, extraColumn ? 3 : 2)->findChild<QSpinBox*>()->value();
newWildMon.maxLevel = monTable->cellWidget(row, extraColumn ? 4 : 3)->findChild<QSpinBox*>()->value();
newWildMons.append(newWildMon);
}
newInfo.active = true;
newInfo.wildPokemon = newWildMons;
newInfo.encounterRate = monTable->findChild<QSpinBox *>()->value();
newInfo.encounterRate = monTable->findChild<QSpinBox*>()->value();
return newInfo;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -7,15 +7,15 @@
// Enabling this does not seem to be simple to color console output
// on Windows for all CLIs without external libraries or extreme bloat.
#ifdef Q_OS_WIN
#define ERROR_COLOR ""
#define WARNING_COLOR ""
#define INFO_COLOR ""
#define CLEAR_COLOR ""
#define ERROR_COLOR ""
#define WARNING_COLOR ""
#define INFO_COLOR ""
#define CLEAR_COLOR ""
#else
#define ERROR_COLOR "\033[31;1m"
#define WARNING_COLOR "\033[1;33m"
#define INFO_COLOR "\033[32m"
#define CLEAR_COLOR "\033[0m"
#define ERROR_COLOR "\033[31;1m"
#define WARNING_COLOR "\033[1;33m"
#define INFO_COLOR "\033[32m"
#define CLEAR_COLOR "\033[0m"
#endif
void logInfo(QString message) {
@ -35,8 +35,7 @@ void logError(QString message) {
QString colorizeMessage(QString message, LogType type) {
QString colorized = message;
switch (type)
{
switch (type) {
case LogType::LOG_INFO:
colorized = colorized.replace("INFO", INFO_COLOR "INFO" CLEAR_COLOR);
break;
@ -53,8 +52,7 @@ QString colorizeMessage(QString message, LogType type) {
void log(QString message, LogType type) {
QString now = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
QString typeString = "";
switch (type)
{
switch (type) {
case LogType::LOG_INFO:
typeString = " [INFO]";
break;

View file

@ -1,8 +1,7 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
QApplication a(argc, argv);
a.setStyle("fusion");
MainWindow w(nullptr);

File diff suppressed because it is too large Load diff

View file

@ -22,12 +22,10 @@ void MainWindow::tryRedrawMapArea(bool forceRedraw) {
void MainWindow::tryCommitMapChanges(bool commitChanges) {
if (commitChanges) {
Map *map = this->editor->map;
Map* map = this->editor->map;
if (map) {
map->editHistory.push(new ScriptEditMap(map,
map->layout->lastCommitMapBlocks.dimensions, QSize(map->getWidth(), map->getHeight()),
map->layout->lastCommitMapBlocks.blocks, map->layout->blockdata
));
map->editHistory.push(new ScriptEditMap(map, map->layout->lastCommitMapBlocks.dimensions, QSize(map->getWidth(), map->getHeight()),
map->layout->lastCommitMapBlocks.blocks, map->layout->blockdata));
}
}
}
@ -245,7 +243,7 @@ void MainWindow::addImage(int x, int y, QString filepath) {
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::refreshAfterPaletteChange(Tileset *tileset) {
void MainWindow::refreshAfterPaletteChange(Tileset* tileset) {
if (this->tilesetEditor) {
this->tilesetEditor->updateTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label);
}
@ -257,7 +255,7 @@ void MainWindow::refreshAfterPaletteChange(Tileset *tileset) {
this->editor->project->saveTilesetPalettes(tileset);
}
void MainWindow::setTilesetPalette(Tileset *tileset, int paletteIndex, QList<QList<int>> colors) {
void MainWindow::setTilesetPalette(Tileset* tileset, int paletteIndex, QList<QList<int>> colors) {
if (!this->editor || !this->editor->map || !this->editor->map->layout)
return;
if (paletteIndex >= tileset->palettes.size())
@ -305,23 +303,23 @@ void MainWindow::setSecondaryTilesetPalettes(QList<QList<QList<int>>> palettes)
this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary);
}
QJSValue MainWindow::getTilesetPalette(const QList<QList<QRgb>> &palettes, int paletteIndex) {
QJSValue MainWindow::getTilesetPalette(const QList<QList<QRgb>>& palettes, int paletteIndex) {
if (paletteIndex >= palettes.size())
return QJSValue();
QList<QList<int>> palette;
for (auto color : palettes.value(paletteIndex)) {
palette.append(QList<int>({qRed(color), qGreen(color), qBlue(color)}));
palette.append(QList<int>({ qRed(color), qGreen(color), qBlue(color) }));
}
return Scripting::getEngine()->toScriptValue(palette);
}
QJSValue MainWindow::getTilesetPalettes(const QList<QList<QRgb>> &palettes) {
QJSValue MainWindow::getTilesetPalettes(const QList<QList<QRgb>>& palettes) {
QList<QList<QList<int>>> outPalettes;
for (int i = 0; i < palettes.size(); i++) {
QList<QList<int>> colors;
for (auto color : palettes.value(i)) {
colors.append(QList<int>({qRed(color), qGreen(color), qBlue(color)}));
colors.append(QList<int>({ qRed(color), qGreen(color), qBlue(color) }));
}
outPalettes.append(colors);
}
@ -360,7 +358,7 @@ void MainWindow::refreshAfterPalettePreviewChange() {
this->editor->updateMapConnections();
}
void MainWindow::setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QList<QList<int>> colors) {
void MainWindow::setTilesetPalettePreview(Tileset* tileset, int paletteIndex, QList<QList<int>> colors) {
if (!this->editor || !this->editor->map || !this->editor->map->layout)
return;
if (paletteIndex >= tileset->palettePreviews.size())
@ -481,12 +479,10 @@ void MainWindow::registerAction(QString functionName, QString actionName, QStrin
Scripting::registerAction(functionName, actionName);
if (Scripting::numRegisteredActions() == 1) {
QAction *section = this->ui->menuTools->addSection("Custom Actions");
QAction* section = this->ui->menuTools->addSection("Custom Actions");
this->registeredActions.append(section);
}
QAction *action = this->ui->menuTools->addAction(actionName, [actionName](){
Scripting::invokeAction(actionName);
});
QAction* action = this->ui->menuTools->addAction(actionName, [actionName]() { Scripting::invokeAction(actionName); });
if (!shortcut.isEmpty()) {
action->setShortcut(QKeySequence(shortcut));
}
@ -494,13 +490,11 @@ void MainWindow::registerAction(QString functionName, QString actionName, QStrin
}
void MainWindow::setTimeout(QJSValue callback, int milliseconds) {
if (!callback.isCallable() || milliseconds < 0)
return;
if (!callback.isCallable() || milliseconds < 0)
return;
QTimer *timer = new QTimer(0);
connect(timer, &QTimer::timeout, [=](){
this->invokeCallback(callback);
});
QTimer* timer = new QTimer(0);
connect(timer, &QTimer::timeout, [=]() { this->invokeCallback(callback); });
connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater);
timer->setSingleShot(true);
timer->start(milliseconds);

File diff suppressed because it is too large Load diff

View file

@ -2,15 +2,12 @@
#include "log.h"
QMap<CallbackType, QString> callbackFunctions = {
{OnProjectOpened, "onProjectOpened"},
{OnProjectClosed, "onProjectClosed"},
{OnBlockChanged, "onBlockChanged"},
{OnMapOpened, "onMapOpened"},
{ OnProjectOpened, "onProjectOpened" }, { OnProjectClosed, "onProjectClosed" }, { OnBlockChanged, "onBlockChanged" }, { OnMapOpened, "onMapOpened" },
};
Scripting *instance = nullptr;
Scripting* instance = nullptr;
void Scripting::init(MainWindow *mainWindow) {
void Scripting::init(MainWindow* mainWindow) {
if (instance) {
instance->engine->setInterrupted(true);
delete instance;
@ -18,7 +15,7 @@ void Scripting::init(MainWindow *mainWindow) {
instance = new Scripting(mainWindow);
}
Scripting::Scripting(MainWindow *mainWindow) {
Scripting::Scripting(MainWindow* mainWindow) {
this->engine = new QJSEngine(mainWindow);
this->engine->installExtensions(QJSEngine::ConsoleExtension);
this->engine->globalObject().setProperty("map", this->engine->newQObject(mainWindow));
@ -36,12 +33,12 @@ void Scripting::loadModules(QStringList moduleFiles) {
module = this->engine->importModule(relativePath);
if (module.isError()) {
logError(QString("Failed to load custom script file '%1'\nName: %2\nMessage: %3\nFile: %4\nLine Number: %5\nStack: %6")
.arg(filepath)
.arg(module.property("name").toString())
.arg(module.property("message").toString())
.arg(module.property("fileName").toString())
.arg(module.property("lineNumber").toString())
.arg(module.property("stack").toString()));
.arg(filepath)
.arg(module.property("name").toString())
.arg(module.property("message").toString())
.arg(module.property("fileName").toString())
.arg(module.property("lineNumber").toString())
.arg(module.property("stack").toString()));
continue;
}
}
@ -68,18 +65,22 @@ void Scripting::invokeCallback(CallbackType type, QJSValueList args) {
}
void Scripting::registerAction(QString functionName, QString actionName) {
if (!instance) return;
if (!instance)
return;
instance->registeredActions.insert(actionName, functionName);
}
int Scripting::numRegisteredActions() {
if (!instance) return 0;
if (!instance)
return 0;
return instance->registeredActions.size();
}
void Scripting::invokeAction(QString actionName) {
if (!instance) return;
if (!instance->registeredActions.contains(actionName)) return;
if (!instance)
return;
if (!instance->registeredActions.contains(actionName))
return;
QString functionName = instance->registeredActions.value(actionName);
for (QJSValue module : instance->modules) {
@ -97,39 +98,40 @@ void Scripting::invokeAction(QString actionName) {
}
void Scripting::cb_ProjectOpened(QString projectPath) {
if (!instance) return;
if (!instance)
return;
QJSValueList args {
QJSValueList args{
projectPath,
};
instance->invokeCallback(OnProjectOpened, args);
}
void Scripting::cb_ProjectClosed(QString projectPath) {
if (!instance) return;
if (!instance)
return;
QJSValueList args {
QJSValueList args{
projectPath,
};
instance->invokeCallback(OnProjectClosed, args);
}
void Scripting::cb_MetatileChanged(int x, int y, Block prevBlock, Block newBlock) {
if (!instance) return;
if (!instance)
return;
QJSValueList args {
x,
y,
instance->fromBlock(prevBlock),
instance->fromBlock(newBlock),
QJSValueList args{
x, y, instance->fromBlock(prevBlock), instance->fromBlock(newBlock),
};
instance->invokeCallback(OnBlockChanged, args);
}
void Scripting::cb_MapOpened(QString mapName) {
if (!instance) return;
if (!instance)
return;
QJSValueList args {
QJSValueList args{
mapName,
};
instance->invokeCallback(OnMapOpened, args);
@ -151,6 +153,6 @@ QJSValue Scripting::dimensions(int width, int height) {
return obj;
}
QJSEngine *Scripting::getEngine() {
QJSEngine* Scripting::getEngine() {
return instance->engine;
}

View file

@ -1,7 +1,6 @@
#include "settings.h"
Settings::Settings()
{
Settings::Settings() {
this->smartPathsEnabled = false;
this->betterCursors = true;
this->playerViewRectEnabled = false;

View file

@ -1,14 +1,10 @@
#include "aboutporymap.h"
#include "ui_aboutporymap.h"
AboutPorymap::AboutPorymap(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::AboutPorymap)
{
AboutPorymap::AboutPorymap(QWidget* parent) : QMainWindow(parent), ui(new Ui::AboutPorymap) {
ui->setupUi(this);
}
AboutPorymap::~AboutPorymap()
{
AboutPorymap::~AboutPorymap() {
delete ui;
}

View file

@ -4,8 +4,8 @@
#include "editcommands.h"
#include <QPainter>
void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QList<uint16_t> *selectedMetatiles = this->metatileSelector->getSelectedMetatiles();
void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
QList<uint16_t>* selectedMetatiles = this->metatileSelector->getSelectedMetatiles();
QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions();
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
int width = map->getBorderWidth();
@ -41,12 +41,8 @@ void BorderMetatilesPixmapItem::draw() {
int x = i * 16;
int y = j * 16;
int index = j * width + i;
QImage metatile_image = getMetatileImage(
map->layout->border.value(index).tile,
map->layout->tileset_primary,
map->layout->tileset_secondary,
map->metatileLayerOrder,
map->metatileLayerOpacity);
QImage metatile_image = getMetatileImage(map->layout->border.value(index).tile, map->layout->tileset_primary, map->layout->tileset_secondary,
map->metatileLayerOrder, map->metatileLayerOpacity);
QPoint metatile_origin = QPoint(x, y);
painter.drawImage(metatile_origin, metatile_image);
}

View file

@ -12,7 +12,8 @@ void CityMapPixmapItem::init() {
height_ = 10;
QFile binFile(file);
if (!binFile.open(QIODevice::ReadOnly)) return;
if (!binFile.open(QIODevice::ReadOnly))
return;
data = binFile.readAll();
if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokeruby) {
@ -28,7 +29,7 @@ void CityMapPixmapItem::draw() {
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
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);
@ -53,7 +54,7 @@ void CityMapPixmapItem::save() {
binFile.close();
}
void CityMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
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;
@ -63,22 +64,21 @@ void CityMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
draw();
}
void CityMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
void CityMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
emit mouseEvent(event, this);
}
void CityMapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
void CityMapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8;
int y = static_cast<int>(pos.y()) / 8;
if (x < width_ && x >= 0
&& y < height_ && y >= 0) {
if (x < width_ && x >= 0 && y < height_ && y >= 0) {
emit this->hoveredRegionMapTileChanged(x, y);
emit mouseEvent(event, this);
}
}
void CityMapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
void CityMapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
emit mouseEvent(event, this);
}

View file

@ -2,7 +2,7 @@
#include "editcommands.h"
#include "metatile.h"
void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event) {
int x = static_cast<int>(event->pos().x()) / 16;
int y = static_cast<int>(event->pos().y()) / 16;
emit this->hoveredMapMovementPermissionChanged(x, y);
@ -11,25 +11,25 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
}
}
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
emit this->hoveredMapMovementPermissionCleared();
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles){
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
unsetCursor();
}
}
void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
this->paint_tile_initial_x = this->straight_path_initial_x = pos.x();
this->paint_tile_initial_y = this->straight_path_initial_y = pos.y();
emit mouseEvent(event, this);
}
void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
emit mouseEvent(event, this);
}
void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
this->lockedAxis = CollisionPixmapItem::Axis::None;
emit mouseEvent(event, this);
}
@ -41,7 +41,7 @@ void CollisionPixmapItem::draw(bool ignoreCache) {
}
}
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent* event) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
actionId_++;
} else if (map) {
@ -71,7 +71,7 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
}
}
void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent* event) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
this->actionId_++;
} else if (map) {
@ -88,7 +88,7 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
}
}
void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent* event) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
this->actionId_++;
} else if (map) {
@ -104,7 +104,7 @@ void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
}
}
void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent* event) {
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
Block block;
if (map->getBlock(pos.x(), pos.y(), &block)) {
@ -112,14 +112,18 @@ void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
}
}
void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent* event) {
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
// Snap point to within map bounds.
if (pos.x() < 0) pos.setX(0);
if (pos.x() >= map->getWidth()) pos.setX(map->getWidth() - 1);
if (pos.y() < 0) pos.setY(0);
if (pos.y() >= map->getHeight()) pos.setY(map->getHeight() - 1);
if (pos.x() < 0)
pos.setX(0);
if (pos.x() >= map->getWidth())
pos.setX(map->getWidth() - 1);
if (pos.y() < 0)
pos.setY(0);
if (pos.y() >= map->getHeight())
pos.setY(map->getHeight() - 1);
Block block;
if (map->getBlock(pos.x(), pos.y(), &block)) {

View file

@ -27,8 +27,7 @@ int ConnectionPixmapItem::getMaxOffset() {
return this->baseMapHeight + 6;
}
QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVariant& value) {
if (change == ItemPositionChange) {
QPointF newPos = value.toPointF();
@ -40,8 +39,7 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
newOffset = qMin(newOffset, this->getMaxOffset());
newOffset = qMax(newOffset, this->getMinOffset());
x = newOffset * 16;
}
else {
} else {
x = this->initialX;
}
@ -51,24 +49,22 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
newOffset = qMin(newOffset, this->getMaxOffset());
newOffset = qMax(newOffset, this->getMinOffset());
y = newOffset * 16;
}
else {
} else {
y = this->initialY;
}
this->connection->offset = QString::number(newOffset);
emit connectionMoved(this->connection);
return QPointF(x, y);
}
else {
} else {
return QGraphicsItem::itemChange(change, value);
}
}
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) {
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent*) {
emit connectionItemSelected(this);
}
void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) {
emit connectionItemDoubleClicked(this);
}

Some files were not shown because too many files have changed in this diff Show more