diff options
93 files changed, 2075 insertions, 1387 deletions
@@ -1,4 +1,18 @@ ----------------- +Rev: 308 +Date: 8 November 2008 +User: MathStuf +----------------- +[FIX] No more asserts in sigmod +[FIX] Moved to using *ById instead of *Index methods in sigmod +[FIX] Tilemaps are now collaged (not completely done on the editing side yet) +[FIX] Removed the resource files (drawn natively instead) +[FIX] ATBTimer now uses the built-in QTimer in a QObject +[FIX] Coordinates are now edited on the map for warps, trainers, and effects +[FIX] Tiles are now completely scripted +[FIX] Config is now thread-safe + +----------------- Rev: 307 Date: 6 November 2008 User: MathStuf diff --git a/sigbattle/ATBTimer.cpp b/sigbattle/ATBTimer.cpp index d41b9db6..d6ae6106 100644 --- a/sigbattle/ATBTimer.cpp +++ b/sigbattle/ATBTimer.cpp @@ -31,7 +31,7 @@ #include <QtCore/QtConcurrentMap> #include <QtCore/QFuture> #include <QtCore/QMultiMap> -#include <QtCore/QTimer> +#include <QtCore/QTimerEvent> bool Sigbattle::compareTimers(TeamMember* const & member1, TeamMember* const & member2) { @@ -53,25 +53,23 @@ bool Sigbattle::isOverflowed(const TeamMember* teamMember) Sigbattle::ATBTimer::ATBTimer(ATBArena* arena, ActionQueue& actions) : QThread(arena), m_arena(arena), - m_actions(actions), - m_timer(new QTimer) + m_actions(actions) { - connect(m_timer, SIGNAL(timeout()), this, SLOT(update())); } Sigbattle::ATBTimer::~ATBTimer() { - delete m_timer; } void Sigbattle::ATBTimer::run() { - m_timer->start(50); + startTimer(50); exec(); } -void Sigbattle::ATBTimer::update() +void Sigbattle::ATBTimer::timerEvent(QTimerEvent* event) { + Q_UNUSED(event) const QList<TeamMember*> active = m_arena->active(); QList<TeamMember::RequestedAction> actions; QtConcurrent::blockingMap(active, increaseMeter); @@ -86,9 +84,9 @@ void Sigbattle::ATBTimer::update() } if (m_arena->sigmod()->rules()->pausedATB()) { - m_timer->stop(); + killTimer(event->timerId()); for (QMutableListIterator<TeamMember::RequestedAction> i(actions); i.hasNext(); i.next()) i.value().second.waitForFinished(); - m_timer->start(50); + startTimer(50); } } diff --git a/sigbattle/ATBTimer.h b/sigbattle/ATBTimer.h index 4b0fb929..5053741e 100644 --- a/sigbattle/ATBTimer.h +++ b/sigbattle/ATBTimer.h @@ -24,9 +24,6 @@ // Qt includes #include <QtCore/QThread> -// Forward declarations -class QTimer; - namespace Sigbattle { class ActionQueue; @@ -43,12 +40,11 @@ class SIGBATTLE_EXPORT ATBTimer : public QThread ~ATBTimer(); protected: void run(); - protected slots: - void update(); + + void timerEvent(QTimerEvent* event); private: ATBArena* m_arena; ActionQueue& m_actions; - QTimer* m_timer; }; SIGBATTLE_EXPORT bool compareTimers(TeamMember* const & member1, TeamMember* const & member2); diff --git a/sigcore/Hat.h b/sigcore/Hat.h index 999dbbe9..3ef768ca 100644 --- a/sigcore/Hat.h +++ b/sigcore/Hat.h @@ -111,7 +111,8 @@ template<class T> inline Hat<T>::Hat() : template<class T> inline T Hat<T>::pick() const { int choice = qrand() % m_count; - foreach (const T& key, m_objects.keys()) + QList<T> keys = m_objects.keys(); + foreach (const T& key, keys) { choice -= m_objects[key]; if (choice < 0) diff --git a/sigmod/Badge.cpp b/sigmod/Badge.cpp index d70833ca..92d60090 100644 --- a/sigmod/Badge.cpp +++ b/sigmod/Badge.cpp @@ -102,7 +102,7 @@ void Sigmod::Badge::setName(const QString& name) void Sigmod::Badge::setFace(const int face) { - if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(face) == INT_MAX) + if (!sigmod()->spriteById(face)) emit(error(bounds("face"))); else CHECK(face); @@ -110,7 +110,7 @@ void Sigmod::Badge::setFace(const int face) void Sigmod::Badge::setBadge(const int badge) { - if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(badge) == INT_MAX) + if (!sigmod()->spriteById(badge)) emit(error(bounds("badge"))); else CHECK(badge); @@ -118,7 +118,7 @@ void Sigmod::Badge::setBadge(const int badge) void Sigmod::Badge::setObey(const int obey) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() < obey) + if (sigmod()->rules()->maxLevel() < obey) { emit(error(bounds("obey"))); return; @@ -136,7 +136,7 @@ void Sigmod::Badge::setStat(const Stat stat, const Sigcore::Fraction& multiplier switch (stat) { case ST_SpecialDefense - ST_Attack + 1: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: break; default: @@ -177,7 +177,7 @@ Sigcore::Fraction Sigmod::Badge::stat(const Stat stat) const switch (stat) { case ST_SpecialDefense - ST_Attack + 1: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: return m_stat[stat - ST_Attack]; default: diff --git a/sigmod/CMakeLists.txt b/sigmod/CMakeLists.txt index 1f60289d..ffd6f5c8 100644 --- a/sigmod/CMakeLists.txt +++ b/sigmod/CMakeLists.txt @@ -18,6 +18,7 @@ SET(sigmod_HEADERS Macros.h MapEffect.h Map.h + MapTile.h MapTrainer.h MapTrainerTeamMember.h MapWarp.h @@ -54,6 +55,7 @@ SET(sigmod_SRCS Item.cpp ItemType.cpp Map.cpp + MapTile.cpp MapEffect.cpp MapTrainer.cpp MapTrainerTeamMember.cpp @@ -93,6 +95,7 @@ SET_TARGET_PROPERTIES(sigmod ) TARGET_LINK_LIBRARIES(sigmod ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} ${QT_QTXML_LIBRARY} sigcore ) diff --git a/sigmod/CoinList.cpp b/sigmod/CoinList.cpp index a36ebeb6..aeeceb46 100644 --- a/sigmod/CoinList.cpp +++ b/sigmod/CoinList.cpp @@ -139,14 +139,16 @@ Sigcore::Script Sigmod::CoinList::script() const const Sigmod::CoinListObject* Sigmod::CoinList::object(const int index) const { - Q_ASSERT(index < objectCount()); - return m_objects.at(index); + if (index < objectCount()) + return m_objects.at(index); + return NULL; } Sigmod::CoinListObject* Sigmod::CoinList::object(const int index) { - Q_ASSERT(index < objectCount()); - return m_objects[index]; + if (index < objectCount()) + return m_objects[index]; + return NULL; } const Sigmod::CoinListObject* Sigmod::CoinList::objectById(const int id) const @@ -197,9 +199,11 @@ Sigmod::CoinListObject* Sigmod::CoinList::newObject(CoinListObject* object) void Sigmod::CoinList::deleteObject(const int index) { - Q_ASSERT(index < objectCount()); - delete m_objects[index]; - m_objects.removeAt(index); + if (index < objectCount()) + { + delete m_objects[index]; + m_objects.removeAt(index); + } } void Sigmod::CoinList::deleteObjectById(const int id) diff --git a/sigmod/CoinListObject.cpp b/sigmod/CoinListObject.cpp index a82c3b2a..e380e016 100644 --- a/sigmod/CoinListObject.cpp +++ b/sigmod/CoinListObject.cpp @@ -87,7 +87,7 @@ void Sigmod::CoinListObject::setType(const Type type) void Sigmod::CoinListObject::setObject(const int object) { - if (((Item == m_type) && (qobject_cast<const Sigmod*>(sigmod())->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(object) == INT_MAX))) + if (((Item == m_type) && !sigmod()->itemById(object)) || ((Species == m_type) && !sigmod()->speciesById(object))) emit(error(bounds("object"))); else CHECK(object); diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp index 5cb9d29e..ff74f736 100644 --- a/sigmod/Item.cpp +++ b/sigmod/Item.cpp @@ -114,7 +114,7 @@ void Sigmod::Item::setSellable(const bool sellable) void Sigmod::Item::setType(const int type) { - if (qobject_cast<const Sigmod*>(sigmod())->itemTypeIndex(type) == INT_MAX) + if (!sigmod()->itemTypeById(type)) emit(error(bounds("type"))); else CHECK(type); @@ -122,7 +122,7 @@ void Sigmod::Item::setType(const int type) void Sigmod::Item::setPrice(const int price) { - if ((price < 0) || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoney() < price)) + if ((price < 0) || (sigmod()->rules()->maxMoney() < price)) emit(error(bounds("price"))); else CHECK(price); @@ -138,10 +138,10 @@ void Sigmod::Item::setSellPrice(const int sellPrice) void Sigmod::Item::setWeight(const int weight) { - const int typeIndex = qobject_cast<const Sigmod*>(sigmod())->itemTypeIndex(m_type); - if (typeIndex != INT_MAX) + const ItemType* type = sigmod()->itemTypeById(m_type); + if (type) { - if (qobject_cast<const Sigmod*>(sigmod())->itemType(typeIndex)->maxWeight() < weight) + if (type->maxWeight() < weight) emit(error(bounds("weight"))); else if (weight < 0) emit(error(bounds("weight"))); diff --git a/sigmod/ItemType.cpp b/sigmod/ItemType.cpp index 80e1b40d..d9d0d754 100644 --- a/sigmod/ItemType.cpp +++ b/sigmod/ItemType.cpp @@ -105,7 +105,7 @@ void Sigmod::ItemType::setPlayer(const int player) void Sigmod::ItemType::setMaxWeight(const int maxWeight) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxTotalWeight() < maxWeight) + if (sigmod()->rules()->maxTotalWeight() < maxWeight) emit(error(bounds("maxWeight"))); else if (maxWeight < 0) emit(error(bounds("maxWeight"))); diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp index 1aaa5e36..bea4f227 100644 --- a/sigmod/Map.cpp +++ b/sigmod/Map.cpp @@ -21,6 +21,7 @@ // Sigmod includes #include "Macros.h" #include "MapEffect.h" +#include "MapTile.h" #include "MapTrainer.h" #include "MapWarp.h" #include "MapWildList.h" @@ -41,7 +42,9 @@ Sigmod::Map::Map(const Sigmod* parent, const int id) : Object(parent, id), m_name(""), m_flyWarp(-1), - m_type(Outdoor) + m_type(Outdoor), + m_width(0), + m_height(0) { } @@ -70,7 +73,10 @@ void Sigmod::Map::validate() emit(error("Name is empty")); TEST(setFlyWarp, flyWarp); TEST(setType, type); - TEST_MATRIX(setTile, map); + if (!m_width) + emit(error("Map has no width")); + if (!m_height) + emit(error("Map has no height")); QSet<int> idChecker; QSet<QString> nameChecker; if (!effectCount()) @@ -81,6 +87,12 @@ void Sigmod::Map::validate() TEST_SUB_END(); idChecker.clear(); nameChecker.clear(); + if (!tileCount()) + emit(warning("There are no tiles")); + TEST_SUB_BEGIN(MapTile, tiles); + TEST_SUB("tile", id); + TEST_SUB_END(); + idChecker.clear(); if (!trainerCount()) emit(warning("There are no trainers")); TEST_SUB_BEGIN(MapTrainer, trainers); @@ -110,8 +122,10 @@ void Sigmod::Map::load(const QDomElement& xml) LOAD(name); LOAD(flyWarp); LOAD(type); - LOAD_MATRIX(map); + LOAD(width); + LOAD(height); LOAD_SUB(newEffect, MapEffect); + LOAD_SUB(newTile, MapTile); LOAD_SUB(newTrainer, MapTrainer); LOAD_SUB(newWarp, MapWarp); LOAD_SUB(newWildList, MapWildList); @@ -123,8 +137,10 @@ QDomElement Sigmod::Map::save() const SAVE(name); SAVE(flyWarp); SAVE(type); - SAVE_MATRIX(map); + SAVE(width); + SAVE(height); SAVE_SUB(MapEffect, effects); + SAVE_SUB(MapTile, tiles); SAVE_SUB(MapTrainer, trainers); SAVE_SUB(MapWarp, warps); SAVE_SUB(MapWildList, wildLists); @@ -138,7 +154,7 @@ void Sigmod::Map::setName(const QString& name) void Sigmod::Map::setFlyWarp(const int flyWarp) { - if ((flyWarp != -1) && (warpIndex(flyWarp) == INT_MAX)) + if ((flyWarp != -1) && !warpById(flyWarp)) emit(error(bounds("flyWarp"))); else CHECK(flyWarp); @@ -149,6 +165,22 @@ void Sigmod::Map::setType(const Type type) CHECK(type); } +void Sigmod::Map::setWidth(const int width) +{ + if (width <= 0) + emit(error(bounds("width"))); + else + CHECK(width); +} + +void Sigmod::Map::setHeight(const int height) +{ + if (height <= 0) + emit(error(bounds("height"))); + else + CHECK(height); +} + QString Sigmod::Map::name() const { return m_name; @@ -164,157 +196,192 @@ Sigmod::Map::Type Sigmod::Map::type() const return m_type; } -void Sigmod::Map::setTile(const int row, const int column, const int tile) +int Sigmod::Map::width() const { - if (qobject_cast<const Sigmod*>(sigmod())->tileIndex(tile) == INT_MAX) - emit(error(bounds("tile"))); - else - m_map(row, column) = tile; + return m_width; } -void Sigmod::Map::insertColumn(const int column) +int Sigmod::Map::height() const { - m_map.insertColumn(column, 0); + return m_height; } -void Sigmod::Map::insertRow(const int row) +const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const { - m_map.insertRow(row, 0); + if (index < effectCount()) + return m_effects.at(index); + return NULL; } -void Sigmod::Map::addColumn() +Sigmod::MapEffect* Sigmod::Map::effect(const int index) { - m_map.addColumn(0); + if (index < effectCount()) + return m_effects[index]; + return NULL; } -void Sigmod::Map::addRow() +const Sigmod::MapEffect* Sigmod::Map::effectById(const int index) const { - m_map.addRow(0); + return effect(effectIndex(index)); } -void Sigmod::Map::deleteColumn(const int column) +Sigmod::MapEffect* Sigmod::Map::effectById(const int index) { - m_map.deleteColumn(column); + return effect(effectIndex(index)); } -void Sigmod::Map::deleteRow(const int row) +int Sigmod::Map::effectIndex(const int id) const { - m_map.deleteRow(row); + for (int i = 0; i < effectCount(); ++i) + { + if (m_effects[i]->id() == id) + return i; + } + return INT_MAX; } -const Sigcore::Matrix<int>* Sigmod::Map::map() const +int Sigmod::Map::effectCount() const { - return &m_map; + return m_effects.size(); } -Sigcore::Matrix<int>* Sigmod::Map::map() +Sigmod::MapEffect* Sigmod::Map::newEffect() { - return &m_map; + return newEffect(new MapEffect(this, newEffectId())); } -int Sigmod::Map::tile(const int row, const int column) const +Sigmod::MapEffect* Sigmod::Map::newEffect(const QDomElement& xml) { - return m_map(row, column); + return newEffect(new MapEffect(xml, this, newEffectId())); } -int Sigmod::Map::width() const +Sigmod::MapEffect* Sigmod::Map::newEffect(const MapEffect& effect) { - return m_map.width(); + return newEffect(new MapEffect(effect, this, newEffectId())); } -int Sigmod::Map::height() const +Sigmod::MapEffect* Sigmod::Map::newEffect(MapEffect* effect) { - return m_map.height(); + m_effects.append(effect); + return effect; } -const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const +void Sigmod::Map::deleteEffect(const int index) { - Q_ASSERT(index < effectCount()); - return m_effects.at(index); + if (index < effectCount()) + { + delete m_effects[index]; + m_effects.removeAt(index); + } } -Sigmod::MapEffect* Sigmod::Map::effect(const int index) +void Sigmod::Map::deleteEffectById(const int id) { - Q_ASSERT(index < effectCount()); - return m_effects[index]; + deleteEffect(effectIndex(id)); } -const Sigmod::MapEffect* Sigmod::Map::effectById(const int index) const +int Sigmod::Map::newEffectId() const { - return effect(effectIndex(index)); + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; } -Sigmod::MapEffect* Sigmod::Map::effectById(const int index) +const Sigmod::MapTile* Sigmod::Map::tile(const int index) const { - return effect(effectIndex(index)); + if (index < tileCount()) + return m_tiles.at(index); + return NULL; } -int Sigmod::Map::effectIndex(const int id) const +Sigmod::MapTile* Sigmod::Map::tile(const int index) { - for (int i = 0; i < effectCount(); ++i) + if (index < tileCount()) + return m_tiles[index]; + return NULL; +} + +const Sigmod::MapTile* Sigmod::Map::tileById(const int index) const +{ + return tile(tileIndex(index)); +} + +Sigmod::MapTile* Sigmod::Map::tileById(const int index) +{ + return tile(tileIndex(index)); +} + +int Sigmod::Map::tileIndex(const int id) const +{ + for (int i = 0; i < tileCount(); ++i) { - if (m_effects[i]->id() == id) + if (m_tiles[i]->id() == id) return i; } return INT_MAX; } -int Sigmod::Map::effectCount() const +int Sigmod::Map::tileCount() const { - return m_effects.size(); + return m_tiles.size(); } -Sigmod::MapEffect* Sigmod::Map::newEffect() +Sigmod::MapTile* Sigmod::Map::newTile() { - return newEffect(new MapEffect(this, newEffectId())); + return newTile(new MapTile(this, newTileId())); } -Sigmod::MapEffect* Sigmod::Map::newEffect(const QDomElement& xml) +Sigmod::MapTile* Sigmod::Map::newTile(const QDomElement& xml) { - return newEffect(new MapEffect(xml, this, newEffectId())); + return newTile(new MapTile(xml, this, newTileId())); } -Sigmod::MapEffect* Sigmod::Map::newEffect(const MapEffect& effect) +Sigmod::MapTile* Sigmod::Map::newTile(const MapTile& tile) { - return newEffect(new MapEffect(effect, this, newEffectId())); + return newTile(new MapTile(tile, this, newTileId())); } -Sigmod::MapEffect* Sigmod::Map::newEffect(MapEffect* effect) +Sigmod::MapTile* Sigmod::Map::newTile(MapTile* tile) { - m_effects.append(effect); - return effect; + m_tiles.append(tile); + return tile; } -void Sigmod::Map::deleteEffect(const int index) +void Sigmod::Map::deleteTile(const int index) { - Q_ASSERT(index < effectCount()); - delete m_effects[index]; - m_effects.removeAt(index); + if (index < tileCount()) + { + delete m_tiles[index]; + m_tiles.removeAt(index); + } } -void Sigmod::Map::deleteEffectById(const int id) +void Sigmod::Map::deleteTileById(const int id) { - deleteEffect(effectIndex(id)); + deleteTile(tileIndex(id)); } -int Sigmod::Map::newEffectId() const +int Sigmod::Map::newTileId() const { int i = 0; - while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + while ((i < tileCount()) && (tileIndex(i) != INT_MAX)) ++i; return i; } const Sigmod::MapTrainer* Sigmod::Map::trainer(const int index) const { - Q_ASSERT(index < trainerCount()); - return m_trainers.at(index); + if (index < trainerCount()) + return m_trainers.at(index); + return NULL; } Sigmod::MapTrainer* Sigmod::Map::trainer(const int index) { - Q_ASSERT(index < trainerCount()); - return m_trainers[index]; + if (index < trainerCount()) + return m_trainers[index]; + return NULL; } const Sigmod::MapTrainer* Sigmod::Map::trainerById(const int id) const @@ -365,9 +432,11 @@ Sigmod::MapTrainer* Sigmod::Map::newTrainer(MapTrainer* trainer) void Sigmod::Map::deleteTrainer(const int index) { - Q_ASSERT(index < trainerCount()); - delete m_trainers[index]; - m_trainers.removeAt(index); + if (index < trainerCount()) + { + delete m_trainers[index]; + m_trainers.removeAt(index); + } } void Sigmod::Map::deleteTrainerById(const int id) @@ -385,14 +454,16 @@ int Sigmod::Map::newTrainerId() const const Sigmod::MapWarp* Sigmod::Map::warp(const int index) const { - Q_ASSERT(index < warpCount()); - return m_warps.at(index); + if (index < warpCount()) + return m_warps.at(index); + return NULL; } Sigmod::MapWarp* Sigmod::Map::warp(const int index) { - Q_ASSERT(index < warpCount()); - return m_warps[index]; + if (index < warpCount()) + return m_warps[index]; + return NULL; } const Sigmod::MapWarp* Sigmod::Map::warpById(const int id) const @@ -443,9 +514,11 @@ Sigmod::MapWarp* Sigmod::Map::newWarp(MapWarp* warp) void Sigmod::Map::deleteWarp(const int index) { - Q_ASSERT(index < warpCount()); - delete m_warps[index]; - m_warps.removeAt(index); + if (index < warpCount()) + { + delete m_warps[index]; + m_warps.removeAt(index); + } } void Sigmod::Map::deleteWarpById(const int id) @@ -463,14 +536,16 @@ int Sigmod::Map::newWarpId() const const Sigmod::MapWildList* Sigmod::Map::wildList(const int index) const { - Q_ASSERT(index < wildListCount()); - return m_wildLists.at(index); + if (index < wildListCount()) + return m_wildLists.at(index); + return NULL; } Sigmod::MapWildList* Sigmod::Map::wildList(const int index) { - Q_ASSERT(index < wildListCount()); - return m_wildLists[index]; + if (index < wildListCount()) + return m_wildLists[index]; + return NULL; } const Sigmod::MapWildList* Sigmod::Map::wildListById(const int id) const @@ -521,9 +596,11 @@ Sigmod::MapWildList* Sigmod::Map::newWildList(MapWildList* wildList) void Sigmod::Map::deleteWildList(const int index) { - Q_ASSERT(index < wildListCount()); - delete m_wildLists[index]; - m_wildLists.removeAt(index); + if (index < wildListCount()) + { + delete m_wildLists[index]; + m_wildLists.removeAt(index); + } } void Sigmod::Map::deleteWildListById(const int id) @@ -547,8 +624,10 @@ Sigmod::Map& Sigmod::Map::operator=(const Map& rhs) COPY(name); COPY(flyWarp); COPY(type); - COPY(map); + COPY(width); + COPY(height); COPY_SUB(MapEffect, effects); + COPY_SUB(MapTile, tiles); COPY_SUB(MapTrainer, trainers); COPY_SUB(MapWarp, warps); COPY_SUB(MapWildList, wildLists); @@ -559,6 +638,8 @@ void Sigmod::Map::clear() { qDeleteAll(m_effects); m_effects.clear(); + qDeleteAll(m_tiles); + m_tiles.clear(); qDeleteAll(m_trainers); m_trainers.clear(); qDeleteAll(m_warps); diff --git a/sigmod/Map.h b/sigmod/Map.h index 490287c6..8a62e2ba 100644 --- a/sigmod/Map.h +++ b/sigmod/Map.h @@ -31,6 +31,7 @@ namespace Sigmod { // Forward declarations class MapEffect; +class MapTile; class MapTrainer; class MapWarp; class MapWildList; @@ -64,22 +65,12 @@ class SIGMOD_EXPORT Map : public Object void setName(const QString& name); void setFlyWarp(const int flyWarp); void setType(const Type type); + void setWidth(const int width); + void setHeight(const int height); QString name() const; int flyWarp() const; Type type() const; - - void setTile(const int row, const int column, const int tile); - void insertColumn(const int column); - void insertRow(const int row); - void addColumn(); - void addRow(); - void deleteColumn(const int column); - void deleteRow(const int row); - - const Sigcore::Matrix<int>* map() const; - Sigcore::Matrix<int>* map(); - int tile(const int row, const int column) const; int width() const; int height() const; @@ -95,6 +86,18 @@ class SIGMOD_EXPORT Map : public Object void deleteEffect(const int index); void deleteEffectById(const int id); + const MapTile* tile(const int index) const; + MapTile* tile(const int index); + const MapTile* tileById(const int id) const; + MapTile* tileById(const int id); + int tileIndex(const int id) const; + int tileCount() const; + MapTile* newTile(); + MapTile* newTile(const QDomElement& xml); + MapTile* newTile(const MapTile& tile); + void deleteTile(const int index); + void deleteTileById(const int id); + const MapTrainer* trainer(const int index) const; MapTrainer* trainer(const int index); const MapTrainer* trainerById(const int id) const; @@ -136,6 +139,9 @@ class SIGMOD_EXPORT Map : public Object int newEffectId() const; MapEffect* newEffect(MapEffect* effect); + int newTileId() const; + MapTile* newTile(MapTile* tile); + int newTrainerId() const; MapTrainer* newTrainer(MapTrainer* trainer); @@ -150,8 +156,10 @@ class SIGMOD_EXPORT Map : public Object QString m_name; int m_flyWarp; Type m_type; - Sigcore::Matrix<int> m_map; + int m_width; + int m_height; QList<MapEffect*> m_effects; + QList<MapTile*> m_tiles; QList<MapTrainer*> m_trainers; QList<MapWarp*> m_warps; QList<MapWildList*> m_wildLists; diff --git a/sigmod/MapEffect.cpp b/sigmod/MapEffect.cpp index 6d5c2734..2d9cfd71 100644 --- a/sigmod/MapEffect.cpp +++ b/sigmod/MapEffect.cpp @@ -98,7 +98,7 @@ void Sigmod::MapEffect::setCoordinate(const QPoint& coordinate) void Sigmod::MapEffect::setSkin(const int skin) { - if (qobject_cast<const Sigmod*>(sigmod())->skinIndex(skin) == INT_MAX) + if (!sigmod()->skinById(skin)) emit(error(bounds("skin"))); else CHECK(skin); diff --git a/sigmod/MapTile.cpp b/sigmod/MapTile.cpp new file mode 100644 index 00000000..c6471969 --- /dev/null +++ b/sigmod/MapTile.cpp @@ -0,0 +1,128 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapTile.h" + +// Sigmod includes +#include "Macros.h" +#include "Map.h" +#include "Sigmod.h" +#include "Tile.h" + +Sigmod::MapTile::MapTile(const MapTile& tile) : + Object(tile.parent(), tile.id()) +{ + *this = tile; +} + +Sigmod::MapTile::MapTile(const Map* parent, const int id) : + Object(parent, id), + m_tile(-1), + m_position(0, 0), + m_zIndex(-1) +{ +} + +Sigmod::MapTile::MapTile(const MapTile& tile, const Map* parent, const int id) : + Object(parent, id) +{ + *this = tile; +} + +Sigmod::MapTile::MapTile(const QDomElement& xml, const Map* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Sigmod::MapTile::~MapTile() +{ +} + +void Sigmod::MapTile::validate() +{ + TEST_BEGIN(); + TEST(setTile, tile); + TEST(setPosition, position); + TEST_END(); +} + +void Sigmod::MapTile::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(tile); + LOAD(position); + LOAD(zIndex); +} + +QDomElement Sigmod::MapTile::save() const +{ + SAVE_CREATE(); + SAVE(tile); + SAVE(position); + SAVE(zIndex); + return xml; +} + +void Sigmod::MapTile::setTile(const int tile) +{ + if (!sigmod()->tileById(tile)) + emit(error(bounds("tile"))); + else + CHECK(tile); +} + +void Sigmod::MapTile::setPosition(const QPoint& position) +{ + if ((qobject_cast<const Map*>(parent())->width() <= position.x()) || (qobject_cast<const Map*>(parent())->height() <= position.y())) + emit(error(bounds("coordinate"))); + else + CHECK(position); +} + +void Sigmod::MapTile::setZIndex(const int zIndex) +{ + CHECK(zIndex); +} + +int Sigmod::MapTile::tile() const +{ + return m_tile; +} + +QPoint Sigmod::MapTile::position() const +{ + return m_position; +} + +int Sigmod::MapTile::zIndex() const +{ + return m_zIndex; +} + +Sigmod::MapTile& Sigmod::MapTile::operator=(const MapTile& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(tile); + COPY(position); + COPY(zIndex); + return *this; +} diff --git a/sigmod/MapTile.h b/sigmod/MapTile.h new file mode 100644 index 00000000..d7d51e93 --- /dev/null +++ b/sigmod/MapTile.h @@ -0,0 +1,58 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMOD_MAPTILE +#define SIGMOD_MAPTILE + +// Sigmod includes +#include "Object.h" + +namespace Sigmod +{ +class SIGMOD_EXPORT MapTile : public Object +{ + Q_OBJECT + + public: + MapTile(const MapTile& tile); + MapTile(const Map* parent, const int id); + MapTile(const MapTile& tile, const Map* parent, const int id); + MapTile(const QDomElement& xml, const Map* parent, const int id = -1); + ~MapTile(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setTile(const int tile); + void setPosition(const QPoint& position); + void setZIndex(const int zIndex); + + int tile() const; + QPoint position() const; + int zIndex() const; + + MapTile& operator=(const MapTile& rhs); + private: + int m_tile; + QPoint m_position; + int m_zIndex; +}; +} + +#endif diff --git a/sigmod/MapTrainer.cpp b/sigmod/MapTrainer.cpp index 2c9307c9..1722df8d 100644 --- a/sigmod/MapTrainer.cpp +++ b/sigmod/MapTrainer.cpp @@ -112,7 +112,7 @@ void Sigmod::MapTrainer::setName(const QString& name) void Sigmod::MapTrainer::setTrainerClass(const int trainerClass) { - if (qobject_cast<const Sigmod*>(sigmod())->trainerIndex(trainerClass) == INT_MAX) + if (!sigmod()->trainerById(trainerClass)) emit(error(bounds("trainerClass"))); else CHECK(trainerClass); @@ -120,7 +120,8 @@ void Sigmod::MapTrainer::setTrainerClass(const int trainerClass) void Sigmod::MapTrainer::setCoordinate(const QPoint& coordinate) { - if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) + const Map* map = qobject_cast<const Map*>(parent()); + if ((map->width() <= coordinate.x()) || (map->height() <= coordinate.y())) emit(error(bounds("coordinate"))); else CHECK(coordinate); @@ -128,7 +129,7 @@ void Sigmod::MapTrainer::setCoordinate(const QPoint& coordinate) void Sigmod::MapTrainer::setNumberFight(const int numberFight) { - if (!numberFight || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxFight() < numberFight)) + if (!numberFight || (sigmod()->rules()->maxFight() < numberFight)) emit(error(bounds("numberFight"))); else CHECK(numberFight); @@ -141,7 +142,7 @@ void Sigmod::MapTrainer::setScript(const Sigcore::Script& script) void Sigmod::MapTrainer::setLeadTeamMember(const int leadTeamMember) { - if (teamMemberIndex(leadTeamMember) == INT_MAX) + if (!teamMemberById(leadTeamMember)) emit(error(bounds("leadTeamMember"))); else CHECK(leadTeamMember); @@ -179,14 +180,16 @@ int Sigmod::MapTrainer::leadTeamMember() const const Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::teamMember(const int index) const { - Q_ASSERT(index < teamMemberCount()); - return m_teamMembers.at(index); + if (index < teamMemberCount()) + return m_teamMembers.at(index); + return NULL; } Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::teamMember(const int index) { - Q_ASSERT(index < teamMemberCount()); - return m_teamMembers[index]; + if (index < teamMemberCount()) + return m_teamMembers[index]; + return NULL; } const Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::teamMemberById(const int id) const @@ -237,9 +240,11 @@ Sigmod::MapTrainerTeamMember* Sigmod::MapTrainer::newTeamMember(MapTrainerTeamMe void Sigmod::MapTrainer::deleteTeamMember(const int index) { - Q_ASSERT(index < teamMemberCount()); - delete m_teamMembers[index]; - m_teamMembers.removeAt(index); + if (index < teamMemberCount()) + { + delete m_teamMembers[index]; + m_teamMembers.removeAt(index); + } } void Sigmod::MapTrainer::deleteTeamMemberById(const int id) diff --git a/sigmod/MapTrainerTeamMember.cpp b/sigmod/MapTrainerTeamMember.cpp index 595277df..3a72811e 100644 --- a/sigmod/MapTrainerTeamMember.cpp +++ b/sigmod/MapTrainerTeamMember.cpp @@ -61,16 +61,16 @@ void Sigmod::MapTrainerTeamMember::validate() TEST_BEGIN(); TEST(setSpecies, species); TEST(setLevel, level); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxAbilities() < m_ability.size()) + if (sigmod()->rules()->maxAbilities() < m_ability.size()) emit(error("Too many abilities")); TEST_LIST(setAbility, ability); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxHeldItems() < m_item.size()) + if (sigmod()->rules()->maxHeldItems() < m_item.size()) emit(error("Too many held items")); TEST_LIST(setItem, item); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoves() < m_move.size()) + if (sigmod()->rules()->maxMoves() < m_move.size()) emit(error("Too many moves")); TEST_LIST(setMove, move); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxNatures() < m_nature.size()) + if (sigmod()->rules()->maxNatures() < m_nature.size()) emit(error("Too many natures")); TEST_LIST(setNature, nature); TEST_END(); @@ -101,7 +101,7 @@ QDomElement Sigmod::MapTrainerTeamMember::save() const void Sigmod::MapTrainerTeamMember::setSpecies(const int species) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(species) == INT_MAX) + if (!sigmod()->speciesById(species)) emit(error(bounds("species"))); else CHECK(species); @@ -109,7 +109,7 @@ void Sigmod::MapTrainerTeamMember::setSpecies(const int species) void Sigmod::MapTrainerTeamMember::setLevel(const int level) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() < level) + if (sigmod()->rules()->maxLevel() < level) emit(error(bounds("level"))); else CHECK(level); @@ -117,11 +117,11 @@ void Sigmod::MapTrainerTeamMember::setLevel(const int level) void Sigmod::MapTrainerTeamMember::setAbility(const int ability, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->abilityIndex(ability) == INT_MAX) + if (!sigmod()->abilityById(ability)) emit(error(bounds("ability"))); else if (state && !m_ability.contains(ability)) { - if (m_ability.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxAbilities()) + if (m_ability.size() < sigmod()->rules()->maxAbilities()) { m_ability.append(ability); emit(changed()); @@ -138,11 +138,11 @@ void Sigmod::MapTrainerTeamMember::setAbility(const int ability, const bool stat void Sigmod::MapTrainerTeamMember::setItem(const int item, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->itemIndex(item) == INT_MAX) + if (!sigmod()->itemById(item)) emit(error(bounds("item"))); else if (state && !m_item.contains(item)) { - if (m_item.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxHeldItems()) + if (m_item.size() < sigmod()->rules()->maxHeldItems()) { if (checkWeight(item)) { @@ -164,17 +164,17 @@ void Sigmod::MapTrainerTeamMember::setItem(const int item, const bool state) void Sigmod::MapTrainerTeamMember::setMove(const int move, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->moveIndex(move) == INT_MAX) + if (!sigmod()->moveById(move)) emit(error(bounds("move"))); else if (state && !m_move.contains(move)) { - const Species* species = qobject_cast<const Sigmod*>(sigmod())->speciesById(move); + const Species* species = sigmod()->speciesById(move); for (int i = 0; i < species->moveCount(); ++i) { const SpeciesMove* speciesMove = species->move(i); if (speciesMove->move() == move) { - if (m_move.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxMoves()) + if (m_move.size() < sigmod()->rules()->maxMoves()) { m_move.append(move); emit(changed()); @@ -195,11 +195,11 @@ void Sigmod::MapTrainerTeamMember::setMove(const int move, const bool state) void Sigmod::MapTrainerTeamMember::setNature(const int nature, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->natureIndex(nature) == INT_MAX) + if (!sigmod()->natureById(nature)) emit(error(bounds("nature"))); else if (state && !m_nature.contains(nature)) { - if (m_nature.size() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxNatures()) + if (m_nature.size() < sigmod()->rules()->maxNatures()) { m_nature.append(nature); emit(changed()); @@ -279,15 +279,15 @@ Sigmod::MapTrainerTeamMember& Sigmod::MapTrainerTeamMember::operator=(const MapT bool Sigmod::MapTrainerTeamMember::checkWeight(const int item) { - const int speciesIndex = qobject_cast<const Sigmod*>(sigmod())->speciesIndex(m_species); - if (speciesIndex == INT_MAX) + const Species* species = sigmod()->speciesById(m_species); + if (!species) return true; - int totalWeight = qobject_cast<const Sigmod*>(sigmod())->itemById(item)->weight(); - foreach (int item, m_item) + int totalWeight = sigmod()->itemById(item)->weight(); + foreach (int itemId, m_item) { - const int itemIndex = qobject_cast<const Sigmod*>(sigmod())->itemIndex(item); - if (itemIndex != INT_MAX) - totalWeight += qobject_cast<const Sigmod*>(sigmod())->item(itemIndex)->weight(); + const Item* item = sigmod()->itemById(itemId); + if (!item) + totalWeight += item->weight(); } - return (totalWeight <= qobject_cast<const Sigmod*>(sigmod())->species(speciesIndex)->maxHoldWeight()); + return (totalWeight <= species->maxHoldWeight()); } diff --git a/sigmod/MapWarp.cpp b/sigmod/MapWarp.cpp index bd4934b6..e0482f14 100644 --- a/sigmod/MapWarp.cpp +++ b/sigmod/MapWarp.cpp @@ -34,7 +34,7 @@ Sigmod::MapWarp::MapWarp(const MapWarp& warp) : Sigmod::MapWarp::MapWarp(const Map* parent, const int id) : Object(parent, id), m_name(""), - m_coordinate(0, 0), + m_area(0, 0, 32, 32), m_type(Door), m_toMap(INT_MAX), m_toWarp(INT_MAX), @@ -60,6 +60,7 @@ void Sigmod::MapWarp::validate() TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); + TEST(setArea, area); TEST(setToMap, toMap); TEST(setToWarp, toWarp); TEST_END(); @@ -69,7 +70,7 @@ void Sigmod::MapWarp::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); - LOAD(coordinate); + LOAD(area); LOAD(type); LOAD(toMap); LOAD(toWarp); @@ -80,7 +81,7 @@ QDomElement Sigmod::MapWarp::save() const { SAVE_CREATE(); SAVE(name); - SAVE(coordinate); + SAVE(area); SAVE(type); SAVE(toMap); SAVE(toWarp); @@ -93,12 +94,15 @@ void Sigmod::MapWarp::setName(const QString& name) CHECK(name); } -void Sigmod::MapWarp::setCoordinate(const QPoint& coordinate) +void Sigmod::MapWarp::setArea(const QRect& area) { - if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) - emit(error(bounds("coordinate"))); + const Map* map = qobject_cast<const Map*>(parent()); + if ((map->width() <= area.x()) || (map->height() <= area.y())) + emit(error(bounds("area"))); + else if ((area.width() <= 0) || (area.height() <= 0)) + emit(error(bounds("area"))); else - CHECK(coordinate); + CHECK(area); } void Sigmod::MapWarp::setType(const Type type) @@ -108,7 +112,7 @@ void Sigmod::MapWarp::setType(const Type type) void Sigmod::MapWarp::setToMap(const int toMap) { - if (qobject_cast<const Sigmod*>(sigmod())->mapIndex(toMap) == INT_MAX) + if (!sigmod()->mapById(toMap)) emit(error(bounds("toMap"))); else CHECK(toMap); @@ -116,9 +120,10 @@ void Sigmod::MapWarp::setToMap(const int toMap) void Sigmod::MapWarp::setToWarp(const int toWarp) { - if (qobject_cast<const Sigmod*>(sigmod())->mapIndex(m_toMap) == INT_MAX) + const Map* map = sigmod()->mapById(m_toMap); + if (!map) emit(error(bounds("toMap"))); - else if (qobject_cast<const Sigmod*>(sigmod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) + else if (!map->warpById(toWarp)) emit(error(bounds("toWarp"))); else CHECK(toWarp); @@ -134,9 +139,9 @@ QString Sigmod::MapWarp::name() const return m_name; } -QPoint Sigmod::MapWarp::coordinate() const +QRect Sigmod::MapWarp::area() const { - return m_coordinate; + return m_area; } Sigmod::MapWarp::Type Sigmod::MapWarp::type() const @@ -164,7 +169,7 @@ Sigmod::MapWarp& Sigmod::MapWarp::operator=(const MapWarp& rhs) if (this == &rhs) return *this; COPY(name); - COPY(coordinate); + COPY(area); COPY(type); COPY(toMap); COPY(toWarp); diff --git a/sigmod/MapWarp.h b/sigmod/MapWarp.h index f99afdf3..dfdef6c3 100644 --- a/sigmod/MapWarp.h +++ b/sigmod/MapWarp.h @@ -25,7 +25,7 @@ #include "Object.h" // Qt includes -#include <QtCore/QPoint> +#include <QtCore/QRect> namespace Sigmod { @@ -58,14 +58,14 @@ class SIGMOD_EXPORT MapWarp : public Object QDomElement save() const; void setName(const QString& name); - void setCoordinate(const QPoint& coordinate); + void setArea(const QRect& area); void setType(const Type type); void setToMap(const int toMap); void setToWarp(const int toWarp); void setScript(const Sigcore::Script& script); QString name() const; - QPoint coordinate() const; + QRect area() const; Type type() const; int toMap() const; int toWarp() const; @@ -74,7 +74,7 @@ class SIGMOD_EXPORT MapWarp : public Object MapWarp& operator=(const MapWarp& rhs); private: QString m_name; - QPoint m_coordinate; + QRect m_area; Type m_type; int m_toMap; int m_toWarp; diff --git a/sigmod/MapWildList.cpp b/sigmod/MapWildList.cpp index 1f8b9c17..1a385632 100644 --- a/sigmod/MapWildList.cpp +++ b/sigmod/MapWildList.cpp @@ -97,14 +97,16 @@ QString Sigmod::MapWildList::name() const const Sigmod::MapWildListEncounter* Sigmod::MapWildList::encounter(const int index) const { - Q_ASSERT(index < encounterCount()); - return m_encounters.at(index); + if (index < encounterCount()) + return m_encounters.at(index); + return NULL; } Sigmod::MapWildListEncounter* Sigmod::MapWildList::encounter(const int index) { - Q_ASSERT(index < encounterCount()); - return m_encounters[index]; + if (index < encounterCount()) + return m_encounters[index]; + return NULL; } const Sigmod::MapWildListEncounter* Sigmod::MapWildList::encounterById(const int id) const @@ -155,9 +157,11 @@ Sigmod::MapWildListEncounter* Sigmod::MapWildList::newEncounter(MapWildListEncou void Sigmod::MapWildList::deleteEncounter(const int index) { - Q_ASSERT(index < encounterCount()); - delete m_encounters[index]; - m_encounters.removeAt(index); + if (index < encounterCount()) + { + delete m_encounters[index]; + m_encounters.removeAt(index); + } } void Sigmod::MapWildList::deleteEncounterById(const int id) diff --git a/sigmod/MapWildListEncounter.cpp b/sigmod/MapWildListEncounter.cpp index 17482f4f..0fb44e02 100644 --- a/sigmod/MapWildListEncounter.cpp +++ b/sigmod/MapWildListEncounter.cpp @@ -80,7 +80,7 @@ QDomElement Sigmod::MapWildListEncounter::save() const void Sigmod::MapWildListEncounter::setSpecies(const int species) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(species) == INT_MAX) + if (!sigmod()->speciesById(species)) emit(error(bounds("species"))); else CHECK(species); @@ -88,7 +88,7 @@ void Sigmod::MapWildListEncounter::setSpecies(const int species) void Sigmod::MapWildListEncounter::setLevel(const int level) { - if (!level || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() <= level)) + if (!level || (sigmod()->rules()->maxLevel() <= level)) emit(error(bounds("level"))); else CHECK(level); diff --git a/sigmod/Move.cpp b/sigmod/Move.cpp index 6f309eb4..6d7a3aa0 100644 --- a/sigmod/Move.cpp +++ b/sigmod/Move.cpp @@ -129,7 +129,7 @@ void Sigmod::Move::setPower(const int power) void Sigmod::Move::setType(const int type) { - if (qobject_cast<const Sigmod*>(sigmod())->typeIndex(type) == INT_MAX) + if (!sigmod()->typeById(type)) emit(error(bounds("type"))); else CHECK(type); diff --git a/sigmod/Nature.cpp b/sigmod/Nature.cpp index 5df36bc3..3238ba9d 100644 --- a/sigmod/Nature.cpp +++ b/sigmod/Nature.cpp @@ -91,7 +91,7 @@ void Sigmod::Nature::setStat(const Stat stat, const Sigcore::Fraction& multiplie switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: break; default: @@ -119,7 +119,7 @@ Sigcore::Fraction Sigmod::Nature::stat(const Stat stat) const switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_Attack ... ST_Special: return m_stat[stat - ST_Attack]; default: diff --git a/sigmod/Sigmod.cpp b/sigmod/Sigmod.cpp index 11915177..26895d08 100644 --- a/sigmod/Sigmod.cpp +++ b/sigmod/Sigmod.cpp @@ -91,9 +91,10 @@ void Sigmod::Sigmod::validate() emit(warning("Description is empty")); if (m_singlePlayer) { - if (mapIndex(m_startMap) == INT_MAX) + const Map* map = mapById(m_startMap); + if (!map) emit(error("Invalid starting map")); - else if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX) + else if (!map->warpById(m_startWarp)) emit(error("Invalid starting warp")); } if ((m_typechart.width() != typeCount()) || (m_typechart.height() != typeCount())) @@ -371,7 +372,7 @@ void Sigmod::Sigmod::setStartMap(const int startMap) { if (!m_singlePlayer) emit(error(unused("startMap"))); - if (mapIndex(startMap) == INT_MAX) + if (!mapById(startMap)) emit(error(bounds("startMap"))); else CHECK(startMap); @@ -381,9 +382,10 @@ void Sigmod::Sigmod::setStartWarp(const int startWarp) { if (!m_singlePlayer) emit(error(unused("startWarp"))); - if (mapIndex(m_startMap) == INT_MAX) + const Map* map = mapById(m_startMap); + if (!map) emit(error(bounds("startMap"))); - else if (mapById(m_startMap)->warpIndex(startWarp) == INT_MAX) + else if (!map->warpById(startWarp)) emit(error(bounds("startWarp"))); else CHECK(startWarp); @@ -461,14 +463,16 @@ Sigmod::Rules* Sigmod::Sigmod::rules() const Sigmod::Ability* Sigmod::Sigmod::ability(const int index) const { - Q_ASSERT(index < abilityCount()); - return m_abilities.at(index); + if (index < abilityCount()) + return m_abilities.at(index); + return NULL; } Sigmod::Ability* Sigmod::Sigmod::ability(const int index) { - Q_ASSERT(index < abilityCount()); - return m_abilities[index]; + if (index < abilityCount()) + return m_abilities[index]; + return NULL; } const Sigmod::Ability* Sigmod::Sigmod::abilityById(const int id) const @@ -519,9 +523,11 @@ Sigmod::Ability* Sigmod::Sigmod::newAbility(Ability* ability) void Sigmod::Sigmod::deleteAbility(const int index) { - Q_ASSERT(index < abilityCount()); - delete m_abilities[index]; - m_abilities.removeAt(index); + if (index < abilityCount()) + { + delete m_abilities[index]; + m_abilities.removeAt(index); + } } void Sigmod::Sigmod::deleteAbilityById(const int id) @@ -539,14 +545,16 @@ int Sigmod::Sigmod::newAbilityId() const const Sigmod::Author* Sigmod::Sigmod::author(const int index) const { - Q_ASSERT(index < authorCount()); - return m_authors.at(index); + if (index < authorCount()) + return m_authors.at(index); + return NULL; } Sigmod::Author* Sigmod::Sigmod::author(const int index) { - Q_ASSERT(index < authorCount()); - return m_authors[index]; + if (index < authorCount()) + return m_authors[index]; + return NULL; } const Sigmod::Author* Sigmod::Sigmod::authorById(const int id) const @@ -597,9 +605,11 @@ Sigmod::Author* Sigmod::Sigmod::newAuthor(Author* author) void Sigmod::Sigmod::deleteAuthor(const int index) { - Q_ASSERT(index < authorCount()); - delete m_authors[index]; - m_authors.removeAt(index); + if (index < authorCount()) + { + delete m_authors[index]; + m_authors.removeAt(index); + } } void Sigmod::Sigmod::deleteAuthorById(const int id) @@ -617,14 +627,16 @@ int Sigmod::Sigmod::newAuthorId() const const Sigmod::Badge* Sigmod::Sigmod::badge(const int index) const { - Q_ASSERT(index < badgeCount()); - return m_badges.at(index); + if (index < badgeCount()) + return m_badges.at(index); + return NULL; } Sigmod::Badge* Sigmod::Sigmod::badge(const int index) { - Q_ASSERT(index < badgeCount()); - return m_badges[index]; + if (index < badgeCount()) + return m_badges[index]; + return NULL; } const Sigmod::Badge* Sigmod::Sigmod::badgeById(const int id) const @@ -675,9 +687,11 @@ Sigmod::Badge* Sigmod::Sigmod::newBadge(Badge* badge) void Sigmod::Sigmod::deleteBadge(const int index) { - Q_ASSERT(index < badgeCount()); - delete m_badges[index]; - m_badges.removeAt(index); + if (index < badgeCount()) + { + delete m_badges[index]; + m_badges.removeAt(index); + } } void Sigmod::Sigmod::deleteBadgeById(const int id) @@ -695,14 +709,16 @@ int Sigmod::Sigmod::newBadgeId() const const Sigmod::CoinList* Sigmod::Sigmod::coinList(const int index) const { - Q_ASSERT(index < coinListCount()); - return m_coinLists.at(index); + if (index < coinListCount()) + return m_coinLists.at(index); + return NULL; } Sigmod::CoinList* Sigmod::Sigmod::coinList(const int index) { - Q_ASSERT(index < coinListCount()); - return m_coinLists[index]; + if (index < coinListCount()) + return m_coinLists[index]; + return NULL; } const Sigmod::CoinList* Sigmod::Sigmod::coinListById(const int id) const @@ -753,9 +769,11 @@ Sigmod::CoinList* Sigmod::Sigmod::newCoinList(CoinList* coinList) void Sigmod::Sigmod::deleteCoinList(const int index) { - Q_ASSERT(index < coinListCount()); - delete m_coinLists[index]; - m_coinLists.removeAt(index); + if (index < coinListCount()) + { + delete m_coinLists[index]; + m_coinLists.removeAt(index); + } } void Sigmod::Sigmod::deleteCoinListById(const int id) @@ -773,14 +791,16 @@ int Sigmod::Sigmod::newCoinListId() const const Sigmod::EggGroup* Sigmod::Sigmod::eggGroup(const int index) const { - Q_ASSERT(index < eggGroupCount()); - return m_eggGroups.at(index); + if (index < eggGroupCount()) + return m_eggGroups.at(index); + return NULL; } Sigmod::EggGroup* Sigmod::Sigmod::eggGroup(const int index) { - Q_ASSERT(index < eggGroupCount()); - return m_eggGroups[index]; + if (index < eggGroupCount()) + return m_eggGroups[index]; + return NULL; } const Sigmod::EggGroup* Sigmod::Sigmod::eggGroupById(const int id) const @@ -831,9 +851,11 @@ Sigmod::EggGroup* Sigmod::Sigmod::newEggGroup(EggGroup* eggGroup) void Sigmod::Sigmod::deleteEggGroup(const int index) { - Q_ASSERT(index < eggGroupCount()); - delete m_eggGroups[index]; - m_eggGroups.removeAt(index); + if (index < eggGroupCount()) + { + delete m_eggGroups[index]; + m_eggGroups.removeAt(index); + } } void Sigmod::Sigmod::deleteEggGroupById(const int id) @@ -851,14 +873,16 @@ int Sigmod::Sigmod::newEggGroupId() const const Sigmod::GlobalScript* Sigmod::Sigmod::globalScript(const int index) const { - Q_ASSERT(index < globalScriptCount()); - return m_globalScripts.at(index); + if (index < globalScriptCount()) + return m_globalScripts.at(index); + return NULL; } Sigmod::GlobalScript* Sigmod::Sigmod::globalScript(const int index) { - Q_ASSERT(index < globalScriptCount()); - return m_globalScripts[index]; + if (index < globalScriptCount()) + return m_globalScripts[index]; + return NULL; } const Sigmod::GlobalScript* Sigmod::Sigmod::globalScriptById(const int id) const @@ -909,9 +933,11 @@ Sigmod::GlobalScript* Sigmod::Sigmod::newGlobalScript(GlobalScript* globalScript void Sigmod::Sigmod::deleteGlobalScript(const int index) { - Q_ASSERT(index < globalScriptCount()); - delete m_globalScripts[index]; - m_globalScripts.removeAt(index); + if (index < globalScriptCount()) + { + delete m_globalScripts[index]; + m_globalScripts.removeAt(index); + } } void Sigmod::Sigmod::deleteGlobalScriptById(const int id) @@ -929,14 +955,16 @@ int Sigmod::Sigmod::newGlobalScriptId() const const Sigmod::Item* Sigmod::Sigmod::item(const int index) const { - Q_ASSERT(index < itemCount()); - return m_items.at(index); + if (index < itemCount()) + return m_items.at(index); + return NULL; } Sigmod::Item* Sigmod::Sigmod::item(const int index) { - Q_ASSERT(index < itemCount()); - return m_items[index]; + if (index < itemCount()) + return m_items[index]; + return NULL; } const Sigmod::Item* Sigmod::Sigmod::itemById(const int id) const @@ -987,9 +1015,11 @@ Sigmod::Item* Sigmod::Sigmod::newItem(Item* item) void Sigmod::Sigmod::deleteItem(const int index) { - Q_ASSERT(index < itemCount()); - delete m_items[index]; - m_items.removeAt(index); + if (index < itemCount()) + { + delete m_items[index]; + m_items.removeAt(index); + } } void Sigmod::Sigmod::deleteItemById(const int id) @@ -1000,21 +1030,23 @@ void Sigmod::Sigmod::deleteItemById(const int id) int Sigmod::Sigmod::newItemId() const { int i = 0; - for (; (i < itemCount()) && (itemIndex(i) != INT_MAX); ++i) - ; + while ((i < itemCount()) && (itemIndex(i) != INT_MAX)) + ++i; return i; } const Sigmod::ItemType* Sigmod::Sigmod::itemType(const int index) const { - Q_ASSERT(index < itemTypeCount()); - return m_itemTypes.at(index); + if (index < itemTypeCount()) + return m_itemTypes.at(index); + return NULL; } Sigmod::ItemType* Sigmod::Sigmod::itemType(const int index) { - Q_ASSERT(index < itemTypeCount()); - return m_itemTypes[index]; + if (index < itemTypeCount()) + return m_itemTypes[index]; + return NULL; } const Sigmod::ItemType* Sigmod::Sigmod::itemTypeById(const int id) const @@ -1065,9 +1097,11 @@ Sigmod::ItemType* Sigmod::Sigmod::newItemType(ItemType* itemType) void Sigmod::Sigmod::deleteItemType(const int index) { - Q_ASSERT(index < itemTypeCount()); - delete m_itemTypes[index]; - m_itemTypes.removeAt(index); + if (index < itemTypeCount()) + { + delete m_itemTypes[index]; + m_itemTypes.removeAt(index); + } } void Sigmod::Sigmod::deleteItemTypeById(const int id) @@ -1085,14 +1119,16 @@ int Sigmod::Sigmod::newItemTypeId() const const Sigmod::Map* Sigmod::Sigmod::map(const int index) const { - Q_ASSERT(index < mapCount()); - return m_maps.at(index); + if (index < mapCount()) + return m_maps.at(index); + return NULL; } Sigmod::Map* Sigmod::Sigmod::map(const int index) { - Q_ASSERT(index < mapCount()); - return m_maps[index]; + if (index < mapCount()) + return m_maps[index]; + return NULL; } const Sigmod::Map* Sigmod::Sigmod::mapById(const int id) const @@ -1143,9 +1179,11 @@ Sigmod::Map* Sigmod::Sigmod::newMap(Map* map) void Sigmod::Sigmod::deleteMap(const int index) { - Q_ASSERT(index < mapCount()); - delete m_maps[index]; - m_maps.removeAt(index); + if (index < mapCount()) + { + delete m_maps[index]; + m_maps.removeAt(index); + } } void Sigmod::Sigmod::deleteMapById(const int id) @@ -1163,14 +1201,16 @@ int Sigmod::Sigmod::newMapId() const const Sigmod::Move* Sigmod::Sigmod::move(const int index) const { - Q_ASSERT(index < moveCount()); - return m_moves.at(index); + if (index < moveCount()) + return m_moves.at(index); + return NULL; } Sigmod::Move* Sigmod::Sigmod::move(const int index) { - Q_ASSERT(index < moveCount()); - return m_moves[index]; + if (index < moveCount()) + return m_moves[index]; + return NULL; } const Sigmod::Move* Sigmod::Sigmod::moveById(const int id) const @@ -1221,9 +1261,11 @@ Sigmod::Move* Sigmod::Sigmod::newMove(Move* move) void Sigmod::Sigmod::deleteMove(const int index) { - Q_ASSERT(index < moveCount()); - delete m_moves[index]; - m_moves.removeAt(index); + if (index < moveCount()) + { + delete m_moves[index]; + m_moves.removeAt(index); + } } void Sigmod::Sigmod::deleteMoveById(const int id) @@ -1241,14 +1283,16 @@ int Sigmod::Sigmod::newMoveId() const const Sigmod::Nature* Sigmod::Sigmod::nature(const int index) const { - Q_ASSERT(index < natureCount()); - return m_natures.at(index); + if (index < natureCount()) + return m_natures.at(index); + return NULL; } Sigmod::Nature* Sigmod::Sigmod::nature(const int index) { - Q_ASSERT(index < natureCount()); - return m_natures[index]; + if (index < natureCount()) + return m_natures[index]; + return NULL; } const Sigmod::Nature* Sigmod::Sigmod::natureById(const int id) const @@ -1299,9 +1343,11 @@ Sigmod::Nature* Sigmod::Sigmod::newNature(Nature* nature) void Sigmod::Sigmod::deleteNature(const int index) { - Q_ASSERT(index < natureCount()); - delete m_natures[index]; - m_natures.removeAt(index); + if (index < natureCount()) + { + delete m_natures[index]; + m_natures.removeAt(index); + } } void Sigmod::Sigmod::deleteNatureById(const int id) @@ -1319,14 +1365,16 @@ int Sigmod::Sigmod::newNatureId() const const Sigmod::Skin* Sigmod::Sigmod::skin(const int index) const { - Q_ASSERT(index < skinCount()); - return m_skins.at(index); + if (index < skinCount()) + return m_skins.at(index); + return NULL; } Sigmod::Skin* Sigmod::Sigmod::skin(const int index) { - Q_ASSERT(index < skinCount()); - return m_skins[index]; + if (index < skinCount()) + return m_skins[index]; + return NULL; } const Sigmod::Skin* Sigmod::Sigmod::skinById(const int id) const @@ -1377,9 +1425,11 @@ Sigmod::Skin* Sigmod::Sigmod::newSkin(Skin* skin) void Sigmod::Sigmod::deleteSkin(const int index) { - Q_ASSERT(index < skinCount()); - delete m_skins[index]; - m_skins.removeAt(index); + if (index < skinCount()) + { + delete m_skins[index]; + m_skins.removeAt(index); + } } void Sigmod::Sigmod::deleteSkinById(const int id) @@ -1397,14 +1447,16 @@ int Sigmod::Sigmod::newSkinId() const const Sigmod::Sound* Sigmod::Sigmod::sound(const int index) const { - Q_ASSERT(index < soundCount()); - return m_sounds.at(index); + if (index < soundCount()) + return m_sounds.at(index); + return NULL; } Sigmod::Sound* Sigmod::Sigmod::sound(const int index) { - Q_ASSERT(index < soundCount()); - return m_sounds[index]; + if (index < soundCount()) + return m_sounds[index]; + return NULL; } const Sigmod::Sound* Sigmod::Sigmod::soundById(const int id) const @@ -1455,9 +1507,11 @@ Sigmod::Sound* Sigmod::Sigmod::newSound(Sound* sound) void Sigmod::Sigmod::deleteSound(const int index) { - Q_ASSERT(index < soundCount()); - delete m_sounds[index]; - m_sounds.removeAt(index); + if (index < soundCount()) + { + delete m_sounds[index]; + m_sounds.removeAt(index); + } } void Sigmod::Sigmod::deleteSoundById(const int id) @@ -1475,14 +1529,16 @@ int Sigmod::Sigmod::newSoundId() const const Sigmod::Species* Sigmod::Sigmod::species(const int index) const { - Q_ASSERT(index < speciesCount()); - return m_species.at(index); + if (index < speciesCount()) + return m_species.at(index); + return NULL; } Sigmod::Species* Sigmod::Sigmod::species(const int index) { - Q_ASSERT(index < speciesCount()); - return m_species[index]; + if (index < speciesCount()) + return m_species[index]; + return NULL; } const Sigmod::Species* Sigmod::Sigmod::speciesById(const int id) const @@ -1533,9 +1589,11 @@ Sigmod::Species* Sigmod::Sigmod::newSpecies(Species* species) void Sigmod::Sigmod::deleteSpecies(const int index) { - Q_ASSERT(index < speciesCount()); - delete m_species[index]; - m_species.removeAt(index); + if (index < speciesCount()) + { + delete m_species[index]; + m_species.removeAt(index); + } } void Sigmod::Sigmod::deleteSpeciesById(const int id) @@ -1553,14 +1611,16 @@ int Sigmod::Sigmod::newSpeciesId() const const Sigmod::Sprite* Sigmod::Sigmod::sprite(const int index) const { - Q_ASSERT(index < spriteCount()); - return m_sprites.at(index); + if (index < spriteCount()) + return m_sprites.at(index); + return NULL; } Sigmod::Sprite* Sigmod::Sigmod::sprite(const int index) { - Q_ASSERT(index < spriteCount()); - return m_sprites[index]; + if (index < spriteCount()) + return m_sprites[index]; + return NULL; } const Sigmod::Sprite* Sigmod::Sigmod::spriteById(const int id) const @@ -1611,9 +1671,11 @@ Sigmod::Sprite* Sigmod::Sigmod::newSprite(Sprite* sprite) void Sigmod::Sigmod::deleteSprite(const int index) { - Q_ASSERT(index < spriteCount()); - delete m_sprites[index]; - m_sprites.removeAt(index); + if (index < spriteCount()) + { + delete m_sprites[index]; + m_sprites.removeAt(index); + } } void Sigmod::Sigmod::deleteSpriteById(const int id) @@ -1631,14 +1693,16 @@ int Sigmod::Sigmod::newSpriteId() const const Sigmod::Status* Sigmod::Sigmod::status(const int index) const { - Q_ASSERT(index < statusCount()); - return m_status.at(index); + if (index < statusCount()) + return m_status.at(index); + return NULL; } Sigmod::Status* Sigmod::Sigmod::status(const int index) { - Q_ASSERT(index < statusCount()); - return m_status[index]; + if (index < statusCount()) + return m_status[index]; + return NULL; } const Sigmod::Status* Sigmod::Sigmod::statusById(const int id) const @@ -1689,9 +1753,11 @@ Sigmod::Status* Sigmod::Sigmod::newStatus(Status* status) void Sigmod::Sigmod::deleteStatus(const int index) { - Q_ASSERT(index < statusCount()); - delete m_status[index]; - m_status.removeAt(index); + if (index < statusCount()) + { + delete m_status[index]; + m_status.removeAt(index); + } } void Sigmod::Sigmod::deleteStatusById(const int id) @@ -1709,14 +1775,16 @@ int Sigmod::Sigmod::newStatusId() const const Sigmod::Store* Sigmod::Sigmod::store(const int index) const { - Q_ASSERT(index < storeCount()); - return m_stores.at(index); + if (index < storeCount()) + return m_stores.at(index); + return NULL; } Sigmod::Store* Sigmod::Sigmod::store(const int index) { - Q_ASSERT(index < storeCount()); - return m_stores[index]; + if (index < storeCount()) + return m_stores[index]; + return NULL; } const Sigmod::Store* Sigmod::Sigmod::storeById(const int id) const @@ -1767,9 +1835,11 @@ Sigmod::Store* Sigmod::Sigmod::newStore(Store* store) void Sigmod::Sigmod::deleteStore(const int index) { - Q_ASSERT(index < storeCount()); - delete m_stores[index]; - m_stores.removeAt(index); + if (index < storeCount()) + { + delete m_stores[index]; + m_stores.removeAt(index); + } } void Sigmod::Sigmod::deleteStoreById(const int id) @@ -1787,14 +1857,16 @@ int Sigmod::Sigmod::newStoreId() const const Sigmod::Tile* Sigmod::Sigmod::tile(const int index) const { - Q_ASSERT(index < tileCount()); - return m_tiles.at(index); + if (index < tileCount()) + return m_tiles.at(index); + return NULL; } Sigmod::Tile* Sigmod::Sigmod::tile(const int index) { - Q_ASSERT(index < tileCount()); - return m_tiles[index]; + if (index < tileCount()) + return m_tiles[index]; + return NULL; } const Sigmod::Tile* Sigmod::Sigmod::tileById(const int id) const @@ -1845,9 +1917,11 @@ Sigmod::Tile* Sigmod::Sigmod::newTile(Tile* tile) void Sigmod::Sigmod::deleteTile(const int index) { - Q_ASSERT(index < tileCount()); - delete m_tiles[index]; - m_tiles.removeAt(index); + if (index < tileCount()) + { + delete m_tiles[index]; + m_tiles.removeAt(index); + } } void Sigmod::Sigmod::deleteTileById(const int id) @@ -1865,14 +1939,16 @@ int Sigmod::Sigmod::newTileId() const const Sigmod::Time* Sigmod::Sigmod::time(const int index) const { - Q_ASSERT(index < timeCount()); - return m_times.at(index); + if (index < timeCount()) + return m_times.at(index); + return NULL; } Sigmod::Time* Sigmod::Sigmod::time(const int index) { - Q_ASSERT(index < timeCount()); - return m_times[index]; + if (index < timeCount()) + return m_times[index]; + return NULL; } const Sigmod::Time* Sigmod::Sigmod::timeById(const int id) const @@ -1923,9 +1999,11 @@ Sigmod::Time* Sigmod::Sigmod::newTime(Time* time) void Sigmod::Sigmod::deleteTime(const int index) { - Q_ASSERT(index < timeCount()); - delete m_times[index]; - m_times.removeAt(index); + if (index < timeCount()) + { + delete m_times[index]; + m_times.removeAt(index); + } } void Sigmod::Sigmod::deleteTimeById(const int id) @@ -1943,14 +2021,16 @@ int Sigmod::Sigmod::newTimeId() const const Sigmod::Trainer* Sigmod::Sigmod::trainer(const int index) const { - Q_ASSERT(index < trainerCount()); - return m_trainers.at(index); + if (index < trainerCount()) + return m_trainers.at(index); + return NULL; } Sigmod::Trainer* Sigmod::Sigmod::trainer(const int index) { - Q_ASSERT(index < trainerCount()); - return m_trainers[index]; + if (index < trainerCount()) + return m_trainers[index]; + return NULL; } const Sigmod::Trainer* Sigmod::Sigmod::trainerById(const int id) const @@ -2001,9 +2081,11 @@ Sigmod::Trainer* Sigmod::Sigmod::newTrainer(Trainer* trainer) void Sigmod::Sigmod::deleteTrainer(const int index) { - Q_ASSERT(index < trainerCount()); - delete m_trainers[index]; - m_trainers.removeAt(index); + if (index < trainerCount()) + { + delete m_trainers[index]; + m_trainers.removeAt(index); + } } void Sigmod::Sigmod::deleteTrainerById(const int id) @@ -2021,14 +2103,16 @@ int Sigmod::Sigmod::newTrainerId() const const Sigmod::Type* Sigmod::Sigmod::type(const int index) const { - Q_ASSERT(index < typeCount()); - return m_types.at(index); + if (index < typeCount()) + return m_types.at(index); + return NULL; } Sigmod::Type* Sigmod::Sigmod::type(const int index) { - Q_ASSERT(index < typeCount()); - return m_types[index]; + if (index < typeCount()) + return m_types[index]; + return NULL; } const Sigmod::Type* Sigmod::Sigmod::typeById(const int id) const @@ -2080,10 +2164,12 @@ Sigmod::Type* Sigmod::Sigmod::newType(Type* type) void Sigmod::Sigmod::deleteType(const int index) { - Q_ASSERT(index < typeCount()); - delete m_types[index]; - m_types.removeAt(index); - m_typechart.resize(typeCount(), typeCount(), Sigcore::Fraction(1, 1)); + if (index < typeCount()) + { + delete m_types[index]; + m_types.removeAt(index); + m_typechart.resize(typeCount(), typeCount(), Sigcore::Fraction(1, 1)); + } } void Sigmod::Sigmod::deleteTypeById(const int id) @@ -2101,14 +2187,16 @@ int Sigmod::Sigmod::newTypeId() const const Sigmod::Weather* Sigmod::Sigmod::weather(const int index) const { - Q_ASSERT(index < weatherCount()); - return m_weathers.at(index); + if (index < weatherCount()) + return m_weathers.at(index); + return NULL; } Sigmod::Weather* Sigmod::Sigmod::weather(const int index) { - Q_ASSERT(index < weatherCount()); - return m_weathers[index]; + if (index < weatherCount()) + return m_weathers[index]; + return NULL; } const Sigmod::Weather* Sigmod::Sigmod::weatherById(const int id) const @@ -2159,9 +2247,11 @@ Sigmod::Weather* Sigmod::Sigmod::newWeather(Weather* weather) void Sigmod::Sigmod::deleteWeather(const int index) { - Q_ASSERT(index < weatherCount()); - delete m_weathers[index]; - m_weathers.removeAt(index); + if (index < weatherCount()) + { + delete m_weathers[index]; + m_weathers.removeAt(index); + } } void Sigmod::Sigmod::deleteWeatherById(const int id) diff --git a/sigmod/Species.cpp b/sigmod/Species.cpp index 0340abd0..f7884170 100644 --- a/sigmod/Species.cpp +++ b/sigmod/Species.cpp @@ -111,13 +111,14 @@ void Sigmod::Species::validate() if ((m_encyclopediaNumber != INT_MAX) && m_encyclopediaEntry.isEmpty()) emit(error("Encyclopedia entry is empty")); TEST(setGenderFactor, genderFactor); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->breedingAllowed()) + if (sigmod()->rules()->breedingAllowed()) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(m_eggSpecies) == INT_MAX) + const Species* eggSpecies = sigmod()->speciesById(m_eggSpecies); + if (!eggSpecies) emit(error(bounds("egg species"))); else { - if (qobject_cast<const Sigmod*>(sigmod())->species(m_eggSpecies)->growth() != m_growth) + if (eggSpecies->growth() != m_growth) emit(error("Growth mismatch with egg species")); TEST(setEggSteps, eggSteps); } @@ -126,7 +127,7 @@ void Sigmod::Species::validate() TEST_LIST(setEggGroup, eggGroup); QSet<int> idChecker; QSet<int> valueChecker; - if (abilityCount() < qobject_cast<const Sigmod*>(sigmod())->rules()->maxAbilities()) + if (abilityCount() < sigmod()->rules()->maxAbilities()) emit(warning("There are too few abilities")); TEST_SUB_BEGIN(SpeciesAbility, abilities); TEST_SUB("ability", id); @@ -134,7 +135,7 @@ void Sigmod::Species::validate() TEST_SUB_END(); idChecker.clear(); valueChecker.clear(); - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxHeldItems() && !itemCount()) + if (sigmod()->rules()->maxHeldItems() && !itemCount()) emit(warning("There are no items")); TEST_SUB_BEGIN(SpeciesItem, items); TEST_SUB("item", id); @@ -228,7 +229,7 @@ void Sigmod::Species::setBaseStat(const Stat stat, const int baseStat) switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: break; default: @@ -240,14 +241,14 @@ void Sigmod::Species::setBaseStat(const Stat stat, const int baseStat) void Sigmod::Species::setEffortValue(const Stat stat, const int effortValue) { - if (!qobject_cast<const Sigmod*>(sigmod())->rules()->effortValuesAllowed()) + if (!sigmod()->rules()->effortValuesAllowed()) emit(error("Effort Values not allowed")); - else if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxEVPerStat() < effortValue) + else if (sigmod()->rules()->maxEVPerStat() < effortValue) emit(error(bounds("effortValue"))); switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: break; default: @@ -259,7 +260,7 @@ void Sigmod::Species::setEffortValue(const Stat stat, const int effortValue) void Sigmod::Species::setEffortValue(const int effortValue) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->effortValuesAllowed() && qobject_cast<const Sigmod*>(sigmod())->rules()->maxEVPerStat() < effortValue) + if (sigmod()->rules()->effortValuesAllowed() && sigmod()->rules()->maxEVPerStat() < effortValue) emit(error(bounds("effortValue"))); } @@ -334,7 +335,7 @@ void Sigmod::Species::setFrontMaleSprite(const int frontMaleSprite) { if (m_genderFactor.numerator() == m_genderFactor.denominator()) emit(error("Cannot be male")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(frontMaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(frontMaleSprite)) emit(error(bounds("frontMaleSprite"))); else CHECK(frontMaleSprite); @@ -344,7 +345,7 @@ void Sigmod::Species::setBackMaleSprite(const int backMaleSprite) { if (m_genderFactor.numerator() == m_genderFactor.denominator()) emit(error("Cannot be male")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(backMaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(backMaleSprite)) emit(error(bounds("backMaleSprite"))); else CHECK(backMaleSprite); @@ -352,13 +353,13 @@ void Sigmod::Species::setBackMaleSprite(const int backMaleSprite) void Sigmod::Species::setFrontFemaleSprite(const int frontFemaleSprite) { - if (!qobject_cast<const Sigmod*>(sigmod())->rules()->genderAllowed()) + if (!sigmod()->rules()->genderAllowed()) emit(error("Gender is not allowed")); else if (!m_genderFactor.numerator()) emit(error("Cannot be female")); else if (1 < m_genderFactor) emit(error("Genderless uses male sprites")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(frontFemaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(frontFemaleSprite)) emit(error(bounds("frontFemaleSprite"))); else CHECK(frontFemaleSprite); @@ -366,13 +367,13 @@ void Sigmod::Species::setFrontFemaleSprite(const int frontFemaleSprite) void Sigmod::Species::setBackFemaleSprite(const int backFemaleSprite) { - if (!qobject_cast<const Sigmod*>(sigmod())->rules()->genderAllowed()) + if (!sigmod()->rules()->genderAllowed()) emit(error("Gender is not allowed")); else if (!m_genderFactor.numerator()) emit(error("Cannot be female")); else if (1 < m_genderFactor) emit(error("Genderless uses male sprites")); - else if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(backFemaleSprite) == INT_MAX) + else if (!sigmod()->spriteById(backFemaleSprite)) emit(error(bounds("backFemaleSprite"))); else CHECK(backFemaleSprite); @@ -380,7 +381,7 @@ void Sigmod::Species::setBackFemaleSprite(const int backFemaleSprite) void Sigmod::Species::setSkin(const int skin) { - if (qobject_cast<const Sigmod*>(sigmod())->skinIndex(skin) == INT_MAX) + if (!sigmod()->skinById(skin)) emit(error(bounds("skin"))); else CHECK(skin); @@ -393,7 +394,7 @@ void Sigmod::Species::setGenderFactor(const Sigcore::Fraction& genderFactor) void Sigmod::Species::setEggSpecies(const int eggSpecies) { - if (qobject_cast<const Sigmod*>(sigmod())->speciesIndex(eggSpecies) == INT_MAX) + if (!sigmod()->speciesById(eggSpecies)) emit(error(bounds("eggSpecies"))); else CHECK(eggSpecies); @@ -406,7 +407,7 @@ void Sigmod::Species::setEggSteps(const int eggSteps) void Sigmod::Species::setType(const int type, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->typeIndex(type) == INT_MAX) + if (!sigmod()->typeById(type)) emit(error(bounds("type"))); else if (state && !m_type.contains(type)) { @@ -422,7 +423,7 @@ void Sigmod::Species::setType(const int type, const bool state) void Sigmod::Species::setEggGroup(const int eggGroup, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->eggGroupIndex(eggGroup) == INT_MAX) + if (!sigmod()->eggGroupById(eggGroup)) emit(error(bounds("egg group"))); else if (state && !m_eggGroup.contains(eggGroup)) { @@ -451,7 +452,7 @@ int Sigmod::Species::baseStat(const Stat stat) const switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: return m_effortValue[stat]; default: @@ -465,7 +466,7 @@ int Sigmod::Species::effortValue(const Stat stat) const switch (stat) { case ST_SpecialDefense: - if (qobject_cast<const Sigmod*>(sigmod())->rules()->specialSplit()) + if (sigmod()->rules()->specialSplit()) case ST_HP ... ST_Special: return m_effortValue[stat]; default: @@ -596,14 +597,16 @@ Sigcore::Script Sigmod::Species::evolution() const const Sigmod::SpeciesAbility* Sigmod::Species::ability(const int index) const { - Q_ASSERT(index < abilityCount()); - return m_abilities.at(index); + if (index < abilityCount()) + return m_abilities.at(index); + return NULL; } Sigmod::SpeciesAbility* Sigmod::Species::ability(const int index) { - Q_ASSERT(index < abilityCount()); - return m_abilities[index]; + if (index < abilityCount()) + return m_abilities[index]; + return NULL; } const Sigmod::SpeciesAbility* Sigmod::Species::abilityById(const int id) const @@ -654,9 +657,11 @@ Sigmod::SpeciesAbility* Sigmod::Species::newAbility(SpeciesAbility* ability) void Sigmod::Species::deleteAbility(const int index) { - Q_ASSERT(index < abilityCount()); - delete m_abilities[index]; - m_abilities.removeAt(index); + if (index < abilityCount()) + { + delete m_abilities[index]; + m_abilities.removeAt(index); + } } void Sigmod::Species::deleteAbilityById(const int id) @@ -674,14 +679,16 @@ int Sigmod::Species::newAbilityId() const const Sigmod::SpeciesItem* Sigmod::Species::item(const int index) const { - Q_ASSERT(index < itemCount()); - return m_items.at(index); + if (index < itemCount()) + return m_items.at(index); + return NULL; } Sigmod::SpeciesItem* Sigmod::Species::item(const int index) { - Q_ASSERT(index < itemCount()); - return m_items[index]; + if (index < itemCount()) + return m_items[index]; + return NULL; } const Sigmod::SpeciesItem* Sigmod::Species::itemById(const int id) const @@ -732,9 +739,11 @@ Sigmod::SpeciesItem* Sigmod::Species::newItem(SpeciesItem* item) void Sigmod::Species::deleteItem(const int index) { - Q_ASSERT(index < itemCount()); - delete m_items[index]; - m_items.removeAt(index); + if (index < itemCount()) + { + delete m_items[index]; + m_items.removeAt(index); + } } void Sigmod::Species::deleteItemById(const int id) @@ -752,14 +761,16 @@ int Sigmod::Species::newItemId() const const Sigmod::SpeciesMove* Sigmod::Species::move(const int index) const { - Q_ASSERT(index < moveCount()); - return m_moves.at(index); + if (index < moveCount()) + return m_moves.at(index); + return NULL; } Sigmod::SpeciesMove* Sigmod::Species::move(const int index) { - Q_ASSERT(index < moveCount()); - return m_moves[index]; + if (index < moveCount()) + return m_moves[index]; + return NULL; } const Sigmod::SpeciesMove* Sigmod::Species::moveById(const int id) const @@ -810,9 +821,11 @@ Sigmod::SpeciesMove* Sigmod::Species::newMove(SpeciesMove* move) void Sigmod::Species::deleteMove(const int index) { - Q_ASSERT(index < moveCount()); - delete m_moves[index]; - m_moves.removeAt(index); + if (index < moveCount()) + { + delete m_moves[index]; + m_moves.removeAt(index); + } } void Sigmod::Species::deleteMoveById(const int id) diff --git a/sigmod/SpeciesAbility.cpp b/sigmod/SpeciesAbility.cpp index 4afc6785..355394ed 100644 --- a/sigmod/SpeciesAbility.cpp +++ b/sigmod/SpeciesAbility.cpp @@ -74,7 +74,7 @@ QDomElement Sigmod::SpeciesAbility::save() const void Sigmod::SpeciesAbility::setAbility(const int ability) { - if (qobject_cast<const Sigmod*>(sigmod())->abilityIndex(ability) == INT_MAX) + if (!sigmod()->abilityById(ability)) emit(error(bounds("ability"))); else CHECK(ability); diff --git a/sigmod/SpeciesItem.cpp b/sigmod/SpeciesItem.cpp index ba7733f2..db832470 100644 --- a/sigmod/SpeciesItem.cpp +++ b/sigmod/SpeciesItem.cpp @@ -74,7 +74,7 @@ QDomElement Sigmod::SpeciesItem::save() const void Sigmod::SpeciesItem::setItem(const int item) { - if (qobject_cast<const Sigmod*>(sigmod())->itemIndex(item) == INT_MAX) + if (!sigmod()->itemById(item)) emit(error(bounds("item"))); else CHECK(item); diff --git a/sigmod/SpeciesMove.cpp b/sigmod/SpeciesMove.cpp index 1764ba99..f2b81dcf 100644 --- a/sigmod/SpeciesMove.cpp +++ b/sigmod/SpeciesMove.cpp @@ -79,7 +79,7 @@ QDomElement Sigmod::SpeciesMove::save() const void Sigmod::SpeciesMove::setMove(const int move) { - if (qobject_cast<const Sigmod*>(sigmod())->moveIndex(move) == INT_MAX) + if (!sigmod()->moveById(move)) emit(error(bounds("move"))); else CHECK(move); @@ -87,7 +87,7 @@ void Sigmod::SpeciesMove::setMove(const int move) void Sigmod::SpeciesMove::setLevel(const int level) { - if (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() <= level) + if (sigmod()->rules()->maxLevel() <= level) emit(error(bounds("level"))); else CHECK(level); @@ -95,7 +95,7 @@ void Sigmod::SpeciesMove::setLevel(const int level) void Sigmod::SpeciesMove::setWild(const int wild) { - if (!wild || (qobject_cast<const Sigmod*>(sigmod())->rules()->maxLevel() <= wild)) + if (!wild || (sigmod()->rules()->maxLevel() <= wild)) emit(error(bounds("wild"))); else CHECK(wild); diff --git a/sigmod/Store.cpp b/sigmod/Store.cpp index bee0cd36..96558cc0 100644 --- a/sigmod/Store.cpp +++ b/sigmod/Store.cpp @@ -79,7 +79,7 @@ void Sigmod::Store::setName(const QString& name) void Sigmod::Store::setItem(const int item, const bool state) { - if (qobject_cast<const Sigmod*>(sigmod())->itemIndex(item) == INT_MAX) + if (!sigmod()->itemById(item)) emit(error(bounds("item"))); else if (state && !m_item.contains(item)) { diff --git a/sigmod/Tile.cpp b/sigmod/Tile.cpp index 56215332..3646dbd3 100644 --- a/sigmod/Tile.cpp +++ b/sigmod/Tile.cpp @@ -21,7 +21,6 @@ // Sigmod includes #include "Macros.h" #include "Sigmod.h" -#include "Sprite.h" Sigmod::Tile::Tile(const Tile& tile) : Object(tile.parent(), tile.id()) @@ -32,24 +31,18 @@ Sigmod::Tile::Tile(const Tile& tile) : Sigmod::Tile::Tile(const Sigmod* parent, const int id) : Object(parent, id), m_name(""), - m_sprite(-1), - m_from(D_Right - D_Up + 1), m_script("", "") { - for (int i = 0; i < m_from.size(); ++i) - m_from[i] = false; } Sigmod::Tile::Tile(const Tile& tile, const Sigmod* parent, const int id) : - Object(parent, id), - m_from(D_Right - D_Up + 1) + Object(parent, id) { *this = tile; } Sigmod::Tile::Tile(const QDomElement& xml, const Sigmod* parent, const int id) : - Object(parent, id), - m_from(D_Right - D_Up + 1) + Object(parent, id) { LOAD_ID(); load(xml); @@ -60,7 +53,6 @@ void Sigmod::Tile::validate() TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); - TEST(setSprite, sprite); TEST_END(); } @@ -68,8 +60,6 @@ void Sigmod::Tile::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); - LOAD(sprite); - LOAD_ARRAY(from); LOAD(script); } @@ -77,8 +67,6 @@ QDomElement Sigmod::Tile::save() const { SAVE_CREATE(); SAVE(name); - SAVE(sprite); - SAVE_ARRAY(from); SAVE(script); return xml; } @@ -88,19 +76,6 @@ void Sigmod::Tile::setName(const QString& name) CHECK(name); } -void Sigmod::Tile::setSprite(const int sprite) -{ - if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(sprite) == INT_MAX) - emit(error(bounds("sprite"))); - else - CHECK(sprite); -} - -void Sigmod::Tile::setFrom(const Direction direction, const bool state) -{ - CHECK_ARRAY(from[direction], state); -} - void Sigmod::Tile::setScript(const Sigcore::Script& script) { CHECK(script); @@ -111,16 +86,6 @@ QString Sigmod::Tile::name() const return m_name; } -int Sigmod::Tile::sprite() const -{ - return m_sprite; -} - -bool Sigmod::Tile::from(const Direction direction) const -{ - return m_from[direction]; -} - Sigcore::Script Sigmod::Tile::script() const { return m_script; @@ -131,8 +96,6 @@ Sigmod::Tile& Sigmod::Tile::operator=(const Tile& rhs) if (this == &rhs) return *this; COPY(name); - COPY(sprite); - COPY(from); COPY(script); return *this; } diff --git a/sigmod/Tile.h b/sigmod/Tile.h index 47ccb161..c873f785 100644 --- a/sigmod/Tile.h +++ b/sigmod/Tile.h @@ -45,20 +45,14 @@ class SIGMOD_EXPORT Tile : public Object QDomElement save() const; void setName(const QString& name); - void setSprite(const int sprite); - void setFrom(const Direction direction, const bool state); void setScript(const Sigcore::Script& script); QString name() const; - int sprite() const; - bool from(const Direction direction) const; Sigcore::Script script() const; Tile& operator=(const Tile& rhs); private: QString m_name; - int m_sprite; - QVarLengthArray<bool, D_Right - D_Up + 1> m_from; Sigcore::Script m_script; }; } diff --git a/sigmod/Trainer.cpp b/sigmod/Trainer.cpp index d169d2d6..b67a932b 100644 --- a/sigmod/Trainer.cpp +++ b/sigmod/Trainer.cpp @@ -111,7 +111,7 @@ void Sigmod::Trainer::setMoneyFactor(const int moneyFactor) void Sigmod::Trainer::setSkin(const int skin) { - if (qobject_cast<const Sigmod*>(sigmod())->skinIndex(skin) == INT_MAX) + if (!sigmod()->skinById(skin)) emit(error(bounds("skin"))); else CHECK(skin); diff --git a/sigmodr/CMakeLists.txt b/sigmodr/CMakeLists.txt index 558c6916..626ad0ea 100644 --- a/sigmodr/CMakeLists.txt +++ b/sigmodr/CMakeLists.txt @@ -9,10 +9,6 @@ INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR} ) -SET(sigmodr_RESOURCES - overlays/overlays.qrc -) -QT4_ADD_RESOURCES(sigmodr_RESOURCE_SRCS ${sigmodr_RESOURCES}) SET(sigmodr_FORMS gui/ability.ui gui/author.ui @@ -33,7 +29,6 @@ SET(sigmodr_FORMS gui/mapwildlistencounter.ui gui/move.ui gui/nature.ui - gui/point.ui gui/rules.ui gui/script.ui gui/sigmod.ui @@ -164,16 +159,20 @@ SET(sigmodr_MODEL_HEADERS models/WeatherModel.h ) SET(sigmodr_MAIN_HEADERS + EffectItem.h FractionWidget.h - PointWidget.h + MapEditor.h + MapScene.h ScriptWidget.h SigmodTree.h SigmodTreeModel.h SigmodrPreferences.h SigmodrUI.h - TilemapModel.h + TileItem.h + TrainerItem.h TypechartModel.h ValidationDialog.h + WarpItem.h ) SET(sigmodr_HEADERS ${sigmodr_WIDGET_HEADERS} @@ -290,17 +289,21 @@ SET(sigmodr_MODEL_SRCS models/WeatherModel.cpp ) SET(sigmodr_MAIN_SRCS + EffectItem.cpp FractionWidget.cpp - PointWidget.cpp + MapEditor.cpp + MapScene.cpp ScriptWidget.cpp SigmodTree.cpp SigmodTreeModel.cpp Sigmodr.cpp SigmodrPreferences.cpp SigmodrUI.cpp - TilemapModel.cpp + TileItem.cpp + TrainerItem.cpp TypechartModel.cpp ValidationDialog.cpp + WarpItem.cpp ) SET(sigmodr_SRCS ${sigmodr_WIDGET_SRCS} @@ -320,7 +323,6 @@ SET(sigmodr_DESKTOP_FILES KDE4_ADD_EXECUTABLE(sigmodr ${sigmodr_SRCS} ${sigmodr_UI_HEADERS} - ${sigmodr_RESOURCE_SRCS} ) SET_TARGET_PROPERTIES(sigmodr PROPERTIES diff --git a/sigmodr/EffectItem.cpp b/sigmodr/EffectItem.cpp new file mode 100644 index 00000000..9b6c3327 --- /dev/null +++ b/sigmodr/EffectItem.cpp @@ -0,0 +1,116 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "EffectItem.h" + +// Sigmod includes +#include "../sigmod/MapEffect.h" +#include "../sigmod/Sigmod.h" +#include "../sigmod/Sprite.h" + +// KDE includes +#include <KColorScheme> + +// Qt includes +#include <QtGui/QPainter> +#include <QtGui/QStyle> +#include <QtGui/QStyleOptionGraphicsItem> + +Sigmodr::EffectItem::EffectItem(Sigmod::MapEffect* effect, QObject* parent) : + QObject(parent), + m_effect(effect) +{ + connect(m_effect, SIGNAL(changed()), this, SLOT(effectChanged())); + effectChanged(); + setZValue(INT_MAX); + setAcceptHoverEvents(true); +} + +QRectF Sigmodr::EffectItem::boundingRect() const +{ + return m_pixmap.rect(); +} + +void Sigmodr::EffectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_pixmap.size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->drawPixmap(0, 0, m_pixmap); + if (option->state & QStyle::State_MouseOver) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); + painter->drawText(m_pixmap.rect(), Qt::AlignHCenter | Qt::AlignVCenter, m_effect->name()); + } + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } +} + +void Sigmodr::EffectItem::changeSprite(const int spriteId) +{ + const Sigmod::Sprite* sprite = m_effect->sigmod()->spriteById(spriteId); + if (sprite) + m_pixmap.loadFromData(sprite->sprite()); + update(); +} + +void Sigmodr::EffectItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::EffectItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseMoveEvent(event); + m_effect->setCoordinate(scenePos().toPoint()); +} + +void Sigmodr::EffectItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::EffectItem::effectChanged() +{ + setPos(m_effect->coordinate()); + update(); +} diff --git a/sigmodr/EffectItem.h b/sigmodr/EffectItem.h new file mode 100644 index 00000000..b13ffda1 --- /dev/null +++ b/sigmodr/EffectItem.h @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMODR_EFFECTITEM +#define SIGMODR_EFFECTITEM + +// Qt includes +#include <QtGui/QGraphicsItem> + +// Forward declarations +namespace Sigmod +{ +class MapEffect; +} + +namespace Sigmodr +{ +class EffectItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + EffectItem(Sigmod::MapEffect* effect, QObject* parent); + + QRectF boundingRect() const; + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + public slots: + void changeSprite(const int spriteId); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + protected slots: + void effectChanged(); + private: + QPixmap m_pixmap; + Sigmod::MapEffect* m_effect; +}; +} + +#endif diff --git a/sigmodr/ItemUI.cpp b/sigmodr/ItemUI.cpp index 03788a16..76412886 100644 --- a/sigmodr/ItemUI.cpp +++ b/sigmodr/ItemUI.cpp @@ -60,9 +60,9 @@ void Sigmodr::ItemUI::setGui() varSellPrice->setValue(qobject_cast<Sigmod::Item*>(modified())->sellPrice()); if (resetWeight) { - const int itemTypeIndex = sigmod()->itemTypeIndex(qobject_cast<Sigmod::Item*>(modified())->type()); - if (itemTypeIndex != INT_MAX) - varWeight->setMaximum(sigmod()->itemType(itemTypeIndex)->maxWeight()); + const Sigmod::ItemType* itemType = sigmod()->itemTypeById(qobject_cast<Sigmod::Item*>(modified())->type()); + if (itemType) + varWeight->setMaximum(itemType->maxWeight()); } varWeight->setValue(qobject_cast<Sigmod::Item*>(modified())->weight()); varDescription->setText(qobject_cast<Sigmod::Item*>(modified())->description()); diff --git a/sigmodr/MapEditor.cpp b/sigmodr/MapEditor.cpp new file mode 100644 index 00000000..de168803 --- /dev/null +++ b/sigmodr/MapEditor.cpp @@ -0,0 +1,49 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapEditor.h" + +// Sigmodr includes +#include "MapScene.h" + +// Qt includes +#include <QtGui/QGraphicsView> +#include <QtGui/QGridLayout> + +Sigmodr::MapEditor::MapEditor(QWidget* parent) : + QWidget(parent) +{ + QGridLayout* layout = new QGridLayout; + + m_view = new QGraphicsView; + layout->addWidget(m_view, 0, 0, 2, 0); + + setLayout(layout); +} + +void Sigmodr::MapEditor::setMap(Sigmod::Map* map) +{ + m_map = map; + m_scene = new MapScene(map, this); + connect(m_scene, SIGNAL(changed()), this, SIGNAL(changed())); + m_view->setScene(m_scene); +} + +void Sigmodr::MapEditor::reset() +{ +} diff --git a/sigmodr/MapEditor.h b/sigmodr/MapEditor.h new file mode 100644 index 00000000..cf628f38 --- /dev/null +++ b/sigmodr/MapEditor.h @@ -0,0 +1,67 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMODR_MAPEDITOR +#define SIGMODR_MAPEDITOR + +// Qt includes +#include <QtGui/QWidget> + +// Forward declarations +class KComboBox; +class KPushButton; +class QGraphicsView; + +namespace Sigmod +{ +class Map; +} + +namespace Sigmodr +{ +class MapScene; + +class MapEditor : public QWidget +{ + Q_OBJECT + + public: + MapEditor(QWidget* parent); + + void setMap(Sigmod::Map* map); + + void reset(); + signals: + void changed(); + private: + Sigmod::Map* m_map; + MapScene* m_scene; + + QGraphicsView* m_view; + + KPushButton* m_addTile; + KPushButton* m_removeTile; + KPushButton* m_moveUp; + KPushButton* m_moveDown; + KPushButton* m_moveToTop; + KPushButton* m_moveToBottom; + + KComboBox* m_types; +}; +} + +#endif diff --git a/sigmodr/MapEffectUI.cpp b/sigmodr/MapEffectUI.cpp index 87f79509..4708683a 100644 --- a/sigmodr/MapEffectUI.cpp +++ b/sigmodr/MapEffectUI.cpp @@ -20,7 +20,6 @@ // Sigmod includes #include "../sigmod/Item.h" -#include "../sigmod/Map.h" #include "../sigmod/MapEffect.h" #include "../sigmod/Sigmod.h" #include "../sigmod/Skin.h" @@ -38,8 +37,6 @@ Sigmodr::MapEffectUI::~MapEffectUI() void Sigmodr::MapEffectUI::refreshGui() { - const Sigmod::Map* map = qobject_cast<const Sigmod::Map*>(original()->parent()); - varCoordinate->setMaximum(QPoint(map->width(), map->height())); for (int i = 0; i < sigmod()->skinCount(); ++i) { const Sigmod::Skin* skin = sigmod()->skin(i); @@ -50,7 +47,6 @@ void Sigmodr::MapEffectUI::refreshGui() void Sigmodr::MapEffectUI::setGui() { varName->setText(qobject_cast<Sigmod::MapEffect*>(modified())->name()); - varCoordinate->setValue(qobject_cast<Sigmod::MapEffect*>(modified())->coordinate()); varSkin->setCurrentIndex(varSkin->findData(qobject_cast<Sigmod::MapEffect*>(modified())->skin())); varScript->setValue(qobject_cast<Sigmod::MapEffect*>(modified())->script()); varIsGhost->setChecked(qobject_cast<Sigmod::MapEffect*>(modified())->isGhost() ? Qt::Checked : Qt::Unchecked); @@ -76,11 +72,6 @@ void Sigmodr::MapEffectUI::on_varName_textChanged(const QString& name) varName->setCursorPosition(cursor); } -void Sigmodr::MapEffectUI::on_varCoordinate_valueChanged(const QPoint& coordinate) -{ - qobject_cast<Sigmod::MapEffect*>(modified())->setCoordinate(coordinate); -} - void Sigmodr::MapEffectUI::on_varSkin_currentIndexChanged(const int skin) { qobject_cast<Sigmod::MapEffect*>(modified())->setSkin(varSkin->itemData(skin).toInt()); diff --git a/sigmodr/MapEffectUI.h b/sigmodr/MapEffectUI.h index 15005ed9..8c8f2277 100644 --- a/sigmodr/MapEffectUI.h +++ b/sigmodr/MapEffectUI.h @@ -44,7 +44,6 @@ class MapEffectUI : public ObjectUI, private Ui::formMapEffect void discard(); protected slots: void on_varName_textChanged(const QString& name); - void on_varCoordinate_valueChanged(const QPoint& coordinate); void on_varSkin_currentIndexChanged(const int skin); void on_varScript_valueChanged(const Sigcore::Script& script); void on_varIsGhost_clicked(const bool isGhost); diff --git a/sigmodr/MapScene.cpp b/sigmodr/MapScene.cpp new file mode 100644 index 00000000..45a96dd7 --- /dev/null +++ b/sigmodr/MapScene.cpp @@ -0,0 +1,115 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapScene.h" + +// Sigmodr includes +#include "EffectItem.h" +#include "TileItem.h" +#include "TrainerItem.h" +#include "WarpItem.h" + +// Sigmod includes +#include "../sigmod/Map.h" +#include "../sigmod/MapEffect.h" +#include "../sigmod/MapTile.h" +#include "../sigmod/MapTrainer.h" +#include "../sigmod/MapWarp.h" + +Sigmodr::MapScene::MapScene(Sigmod::Map* map, QObject* parent) : + QGraphicsScene(parent), + m_map(map) +{ + connect(this, SIGNAL(changed(QList<QRectF>)), this, SIGNAL(changed())); + for (int i = 0; i < m_map->effectCount(); ++i) + addItem(new EffectItem(m_map->effect(i), this)); + for (int i = 0; i < m_map->tileCount(); ++i) + addItem(new TileItem(m_map->tile(i), this)); + for (int i = 0; i < m_map->trainerCount(); ++i) + addItem(new TrainerItem(m_map->trainer(i), this)); + for (int i = 0; i < m_map->warpCount(); ++i) + addItem(new WarpItem(m_map->warp(i), this)); + typeChanged("Warps"); +} + +void Sigmodr::MapScene::addTile(Sigmod::MapTile* tile) +{ + if (!tile) + tile = m_map->newTile(); + addItem(new TileItem(tile, this)); +} + +void Sigmodr::MapScene::removeTiles() +{ + QList<QGraphicsItem*> items = selectedItems(); + foreach (QGraphicsItem* item, items) + { + if (m_effects.key(static_cast<EffectItem*>(item))) + { + Sigmod::MapEffect* effect = m_effects.key(static_cast<EffectItem*>(item)); + m_map->deleteEffectById(effect->id()); + delete m_effects[effect]; + m_effects.remove(effect); + } + else if (m_tiles.key(static_cast<TileItem*>(item))) + { + Sigmod::MapTile* tile = m_tiles.key(static_cast<TileItem*>(item)); + m_map->deleteTileById(tile->id()); + delete m_tiles[tile]; + m_tiles.remove(tile); + } + else if (m_trainers.key(static_cast<TrainerItem*>(item))) + { + Sigmod::MapTrainer* trainer = m_trainers.key(static_cast<TrainerItem*>(item)); + m_map->deleteTrainerById(trainer->id()); + delete m_trainers[trainer]; + m_trainers.remove(trainer); + } + else if (m_warps.key(static_cast<WarpItem*>(item))) + { + Sigmod::MapWarp* warp = m_warps.key(static_cast<WarpItem*>(item)); + m_map->deleteWarpById(warp->id()); + delete m_warps[warp]; + m_warps.remove(warp); + } + } +} + +void Sigmodr::MapScene::typeChanged(const QString& type) +{ + QGraphicsItem::GraphicsItemFlags effectFlags = 0; + QGraphicsItem::GraphicsItemFlags tileFlags = 0; + QGraphicsItem::GraphicsItemFlags trainerFlags = 0; + QGraphicsItem::GraphicsItemFlags warpFlags = 0; + if (type == "Effects") + effectFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + else if (type == "Tiles") + tileFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + else if (type == "Trainers") + trainerFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + else if (type == "Warps") + warpFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + foreach (EffectItem* effect, m_effects) + effect->setFlags(effectFlags); + foreach (TileItem* tile, m_tiles) + tile->setFlags(tileFlags); + foreach (TrainerItem* trainer, m_trainers) + trainer->setFlags(trainerFlags); + foreach (WarpItem* warp, m_warps) + warp->setFlags(warpFlags); +} diff --git a/sigmodr/MapScene.h b/sigmodr/MapScene.h new file mode 100644 index 00000000..4d8a6204 --- /dev/null +++ b/sigmodr/MapScene.h @@ -0,0 +1,64 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMODR_MAPSCENE +#define SIGMODR_MAPSCENE + +// Qt includes +#include <QtCore/QMap> +#include <QtGui/QGraphicsScene> + +// Forward declarations +namespace Sigmod +{ +class Map; +class MapEffect; +class MapTile; +class MapTrainer; +class MapWarp; +} + +namespace Sigmodr +{ +class EffectItem; +class TileItem; +class TrainerItem; +class WarpItem; + +class MapScene : public QGraphicsScene +{ + Q_OBJECT + + public: + MapScene(Sigmod::Map* map, QObject* parent); + public slots: + void addTile(Sigmod::MapTile* tile = NULL); + void removeTiles(); + + void typeChanged(const QString& type); + signals: + void changed(); + private: + Sigmod::Map* m_map; + QMap<Sigmod::MapEffect*, EffectItem*> m_effects; + QMap<Sigmod::MapTile*, TileItem*> m_tiles; + QMap<Sigmod::MapTrainer*, TrainerItem*> m_trainers; + QMap<Sigmod::MapWarp*, WarpItem*> m_warps; +}; +} + +#endif diff --git a/sigmodr/MapTrainerUI.cpp b/sigmodr/MapTrainerUI.cpp index e18e7900..73a79537 100644 --- a/sigmodr/MapTrainerUI.cpp +++ b/sigmodr/MapTrainerUI.cpp @@ -19,7 +19,6 @@ #include "MapTrainerUI.h" // Sigmod includes -#include "../sigmod/Map.h" #include "../sigmod/MapTrainer.h" #include "../sigmod/MapTrainerTeamMember.h" #include "../sigmod/Rules.h" @@ -48,8 +47,6 @@ void Sigmodr::MapTrainerUI::refreshGui() varTrainerClass->addItem(trainer->name(), trainer->id()); } varTrainerClass->blockSignals(blockedTrainerClass); - const Sigmod::Map* map = qobject_cast<const Sigmod::Map*>(original()->parent()); - varCoordinate->setMaximum(QPoint(map->width(), map->height())); varNumberFight->setMaximum(sigmod()->rules()->maxFight()); const bool blockedLeadTeamMember = varLeadTeamMember->blockSignals(true); varLeadTeamMember->clear(); @@ -67,7 +64,6 @@ void Sigmodr::MapTrainerUI::setGui() { varName->setText(qobject_cast<Sigmod::MapTrainer*>(modified())->name()); varTrainerClass->setCurrentIndex(varTrainerClass->findData(qobject_cast<Sigmod::MapTrainer*>(modified())->trainerClass())); - varCoordinate->setValue(qobject_cast<Sigmod::MapTrainer*>(modified())->coordinate()); varNumberFight->setValue(qobject_cast<Sigmod::MapTrainer*>(modified())->numberFight()); varScript->setValue(qobject_cast<Sigmod::MapTrainer*>(modified())->script()); varLeadTeamMember->setCurrentIndex(varLeadTeamMember->findData(qobject_cast<Sigmod::MapTrainer*>(modified())->leadTeamMember())); @@ -98,11 +94,6 @@ void Sigmodr::MapTrainerUI::on_varTrainerClass_activated(const int trainerClass) qobject_cast<Sigmod::MapTrainer*>(modified())->setTrainerClass(varTrainerClass->itemData(trainerClass).toInt()); } -void Sigmodr::MapTrainerUI::on_varCoordinate_valueChanged(const QPoint& coordinate) -{ - qobject_cast<Sigmod::MapTrainer*>(modified())->setCoordinate(coordinate); -} - void Sigmodr::MapTrainerUI::on_varNumberFight_valueChanged(const int numberFight) { qobject_cast<Sigmod::MapTrainer*>(modified())->setNumberFight(numberFight); diff --git a/sigmodr/MapTrainerUI.h b/sigmodr/MapTrainerUI.h index 30efd35b..c213a1a0 100644 --- a/sigmodr/MapTrainerUI.h +++ b/sigmodr/MapTrainerUI.h @@ -45,7 +45,6 @@ class MapTrainerUI : public ObjectUI, private Ui::formMapTrainer protected slots: void on_varName_textChanged(const QString& name); void on_varTrainerClass_activated(const int trainerClass); - void on_varCoordinate_valueChanged(const QPoint& coordinate); void on_varNumberFight_valueChanged(const int numberFight); void on_varScript_valueChanged(const Sigcore::Script& script); void on_varLeadTeamMember_activated(const int leadTeamMember); diff --git a/sigmodr/MapUI.cpp b/sigmodr/MapUI.cpp index a6b575e4..204f93a4 100644 --- a/sigmodr/MapUI.cpp +++ b/sigmodr/MapUI.cpp @@ -18,9 +18,6 @@ // Header include #include "MapUI.h" -// Sigmodr includes -#include "TilemapModel.h" - // Sigmod includes #include "../sigmod/Map.h" #include "../sigmod/MapWarp.h" @@ -28,14 +25,13 @@ #include "../sigmod/Sprite.h" #include "../sigmod/Tile.h" -// Qt includes -#include <QtGui/QHeaderView> - Sigmodr::MapUI::MapUI(Sigmod::Map* map, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(map, new Sigmod::Map(*map)); + varMap->setMap(map); + connect(varMap, SIGNAL(changed()), this, SIGNAL(changed())); } Sigmodr::MapUI::~MapUI() @@ -47,11 +43,6 @@ void Sigmodr::MapUI::initGui() varType->addItem(Sigmod::Map::TypeStr[Sigmod::Map::Outdoor], QVariant::fromValue(Sigmod::Map::Outdoor)); varType->addItem(Sigmod::Map::TypeStr[Sigmod::Map::Dungeon], QVariant::fromValue(Sigmod::Map::Dungeon)); varType->addItem(Sigmod::Map::TypeStr[Sigmod::Map::Building], QVariant::fromValue(Sigmod::Map::Building)); - varTilemap->horizontalHeader()->setResizeMode(QHeaderView::Fixed); - varTilemap->verticalHeader()->setResizeMode(QHeaderView::Fixed); - varTilemap->horizontalHeader()->setDefaultSectionSize(64); - varTilemap->verticalHeader()->setDefaultSectionSize(64); - varTilemap->setModel(new TilemapModel(qobject_cast<Sigmod::Map*>(modified())->map(), sigmod())); } void Sigmodr::MapUI::refreshGui() @@ -64,22 +55,6 @@ void Sigmodr::MapUI::refreshGui() varFlyWarp->addItem(warp->name(), warp->id()); } varFlyWarp->blockSignals(blockedFlyWarp); - const bool blockedTile = varTile->blockSignals(true); - varTile->clear(); - for (int i = 0; i < sigmod()->tileCount(); ++i) - { - const Sigmod::Tile* tile = sigmod()->tile(i); - if (sigmod()->spriteIndex(tile->sprite()) == INT_MAX) - varTile->addItem(tile->name(), tile->id()); - else - { - QPixmap icon; - icon.loadFromData(sigmod()->spriteById(tile->sprite())->sprite()); - varTile->addItem(icon, tile->name(), tile->id()); - } - } - varTile->blockSignals(blockedTile); - varTile->setEnabled(false); } void Sigmodr::MapUI::setGui() @@ -88,8 +63,7 @@ void Sigmodr::MapUI::setGui() boxFlyWarp->setChecked((qobject_cast<Sigmod::Map*>(modified())->flyWarp() == -1) ? Qt::Unchecked : Qt::Checked); varFlyWarp->setCurrentIndex(varFlyWarp->findData(qobject_cast<Sigmod::Map*>(modified())->flyWarp())); varType->setCurrentIndex(qobject_cast<Sigmod::Map*>(modified())->type()); - buttonDeleteColumn->setEnabled(0 < varTilemap->model()->columnCount()); - buttonDeleteRow->setEnabled(0 < varTilemap->model()->rowCount()); + varMap->reset(); } void Sigmodr::MapUI::apply() @@ -126,53 +100,3 @@ void Sigmodr::MapUI::on_varType_activated(const int type) { qobject_cast<Sigmod::Map*>(modified())->setType(varType->itemData(type).value<Sigmod::Map::Type>()); } - -void Sigmodr::MapUI::on_varTilemap_clicked(const QModelIndex& index) -{ - m_index = index; - varTile->setEnabled(true); - varTile->setCurrentIndex(varTile->findData(varTilemap->model()->data(m_index, Qt::EditRole))); -} - -void Sigmodr::MapUI::on_buttonAddColumn_pressed() -{ - varTilemap->model()->insertColumns(varTilemap->model()->columnCount(), 1); - emit(changed(true)); -} - -void Sigmodr::MapUI::on_buttonAddRow_pressed() -{ - varTilemap->model()->insertRows(varTilemap->model()->rowCount(), 1); - emit(changed(true)); -} - -void Sigmodr::MapUI::on_buttonDeleteColumn_pressed() -{ - varTilemap->model()->removeColumns(m_index.column(), 1); - emit(changed(true)); -} - -void Sigmodr::MapUI::on_buttonDeleteRow_pressed() -{ - varTilemap->model()->removeRows(m_index.row(), 1); - emit(changed(true)); -} - -void Sigmodr::MapUI::on_buttonInsertColumn_pressed() -{ - varTilemap->model()->insertColumns(m_index.column(), 1); - emit(changed(true)); -} - -void Sigmodr::MapUI::on_buttonInsertRow_pressed() -{ - varTilemap->model()->insertRows(m_index.row(), 1); - emit(changed(true)); -} - -void Sigmodr::MapUI::on_varTile_activated(const int tile) -{ - varTilemap->model()->setData(m_index, varTile->itemData(tile), Qt::EditRole); - emit(changed(true)); - setGui(); -} diff --git a/sigmodr/MapUI.h b/sigmodr/MapUI.h index d57ae934..3ac48bf9 100644 --- a/sigmodr/MapUI.h +++ b/sigmodr/MapUI.h @@ -49,16 +49,6 @@ class MapUI : public ObjectUI, private Ui::formMap void on_boxFlyWarp_toggled(); void on_varFlyWarp_activated(const int flyWarp); void on_varType_activated(const int type); - void on_varTilemap_clicked(const QModelIndex& index); - void on_buttonAddColumn_pressed(); - void on_buttonAddRow_pressed(); - void on_buttonDeleteColumn_pressed(); - void on_buttonDeleteRow_pressed(); - void on_buttonInsertColumn_pressed(); - void on_buttonInsertRow_pressed(); - void on_varTile_activated(const int tile); - private: - QModelIndex m_index; private slots: void initGui(); void refreshGui(); diff --git a/sigmodr/MapWarpUI.cpp b/sigmodr/MapWarpUI.cpp index 304467b2..ffb054b5 100644 --- a/sigmodr/MapWarpUI.cpp +++ b/sigmodr/MapWarpUI.cpp @@ -45,8 +45,6 @@ void Sigmodr::MapWarpUI::initGui() void Sigmodr::MapWarpUI::refreshGui() { - const Sigmod::Map* map = qobject_cast<const Sigmod::Map*>(original()->parent()); - varCoordinate->setMaximum(QPoint(map->width(), map->height())); const bool blocked = varToMap->blockSignals(true); varToMap->clear(); for (int i = 0; i < sigmod()->mapCount(); ++i) @@ -61,7 +59,6 @@ void Sigmodr::MapWarpUI::setGui() { const bool resetWarps = (qobject_cast<Sigmod::MapWarp*>(modified())->toMap() != m_lastMap); varName->setText(qobject_cast<Sigmod::MapWarp*>(modified())->name()); - varCoordinate->setValue(qobject_cast<Sigmod::MapWarp*>(modified())->coordinate()); varType->setCurrentIndex(qobject_cast<Sigmod::MapWarp*>(modified())->type()); varToMap->setCurrentIndex(varToMap->findData(qobject_cast<Sigmod::MapWarp*>(modified())->toMap())); m_lastMap = qobject_cast<Sigmod::MapWarp*>(modified())->toMap(); @@ -104,11 +101,6 @@ void Sigmodr::MapWarpUI::on_varName_textChanged(const QString& name) varName->setCursorPosition(cursor); } -void Sigmodr::MapWarpUI::on_varCoordinate_valueChanged(const QPoint& coordinate) -{ - qobject_cast<Sigmod::MapWarp*>(modified())->setCoordinate(coordinate); -} - void Sigmodr::MapWarpUI::on_varType_activated(const int type) { qobject_cast<Sigmod::MapWarp*>(modified())->setType(varType->itemData(type).value<Sigmod::MapWarp::Type>()); diff --git a/sigmodr/MapWarpUI.h b/sigmodr/MapWarpUI.h index 5a065c69..eb8582d2 100644 --- a/sigmodr/MapWarpUI.h +++ b/sigmodr/MapWarpUI.h @@ -44,7 +44,6 @@ class MapWarpUI : public ObjectUI, private Ui::formMapWarp void discard(); protected slots: void on_varName_textChanged(const QString& name); - void on_varCoordinate_valueChanged(const QPoint& coordinate); void on_varType_activated(const int type); void on_varToMap_activated(const int toMap); void on_varToWarp_activated(const int toWarp); diff --git a/sigmodr/ObjectUI.cpp b/sigmodr/ObjectUI.cpp index e9559921..a7743bb8 100644 --- a/sigmodr/ObjectUI.cpp +++ b/sigmodr/ObjectUI.cpp @@ -61,7 +61,7 @@ bool Sigmodr::ObjectUI::isChanged() const const Sigmod::Sigmod* Sigmodr::ObjectUI::sigmod() const { - return qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod()); + return m_object->sigmod(); } const Sigmod::Sigmod::Object* Sigmodr::ObjectUI::original() const diff --git a/sigmodr/PointWidget.cpp b/sigmodr/PointWidget.cpp deleted file mode 100644 index 9153160d..00000000 --- a/sigmodr/PointWidget.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -// Header include -#include "PointWidget.h" - -Sigmodr::PointWidget::PointWidget(QWidget* parent, const QPoint& value) : - QWidget(parent), - m_value(value) -{ - setupUi(this); -} - -QPoint Sigmodr::PointWidget::value() const -{ - return m_value; -} - -void Sigmodr::PointWidget::setValue(const QPoint& value) -{ - if (m_value == value) - return; - m_value = value; - varX->setValue(m_value.x()); - varY->setValue(m_value.y()); - emit(valueChanged(m_value)); -} - -void Sigmodr::PointWidget::setMaximum(const QPoint& maximum) -{ - varX->setMaximum(maximum.x()); - varY->setMaximum(maximum.y()); -} - -void Sigmodr::PointWidget::on_varX_valueChanged(const int x) -{ - m_value.setX(x); - emit(valueChanged(m_value)); -} - -void Sigmodr::PointWidget::on_varY_valueChanged(const int y) -{ - m_value.setY(y); - emit(valueChanged(m_value)); -} diff --git a/sigmodr/SigmodTree.cpp b/sigmodr/SigmodTree.cpp index cdcb548b..9437a0e6 100644 --- a/sigmodr/SigmodTree.cpp +++ b/sigmodr/SigmodTree.cpp @@ -69,7 +69,7 @@ const Sigmod::Sigmod* Sigmodr::SigmodTree::currentSigmod() const { const Sigmod::Object* object = static_cast<BaseModel*>(index.internalPointer())->object(); if (object) - return qobject_cast<const Sigmod::Sigmod*>(object->sigmod()); + return object->sigmod(); } return NULL; } @@ -152,9 +152,7 @@ bool Sigmodr::SigmodTree::dirty() const void Sigmodr::SigmodTree::setDirty(const Sigmod::Sigmod* sigmod, const bool dirty) { if (m_sigmods.contains(sigmod)) - { m_sigmods[sigmod].second = dirty; - } } void Sigmodr::SigmodTree::setDirty() diff --git a/sigmodr/SigmodUI.cpp b/sigmodr/SigmodUI.cpp index 8128707a..0ff3388f 100644 --- a/sigmodr/SigmodUI.cpp +++ b/sigmodr/SigmodUI.cpp @@ -75,10 +75,9 @@ void Sigmodr::SigmodUI::setGui() { const bool blocked = varWarp->blockSignals(true); varWarp->clear(); - const int mapIndex = qobject_cast<Sigmod::Sigmod*>(original())->mapIndex(qobject_cast<Sigmod::Sigmod*>(modified())->startMap()); - if (mapIndex != INT_MAX) + const Sigmod::Map* map = qobject_cast<Sigmod::Sigmod*>(original())->mapById(qobject_cast<Sigmod::Sigmod*>(modified())->startMap()); + if (map) { - const Sigmod::Map* map = qobject_cast<Sigmod::Sigmod*>(original())->map(mapIndex); for (int i = 0; i < map->warpCount(); ++i) { const Sigmod::MapWarp* warp = map->warp(i); diff --git a/sigmodr/SigmodrUI.cpp b/sigmodr/SigmodrUI.cpp index 5505c45e..6e7c2923 100644 --- a/sigmodr/SigmodrUI.cpp +++ b/sigmodr/SigmodrUI.cpp @@ -152,7 +152,7 @@ void Sigmodr::SigmodrUI::setChangedTitle(const bool changed) void Sigmodr::SigmodrUI::setDirty(const bool dirty) { - const Sigmod::Sigmod* sigmod = qobject_cast<const Sigmod::Sigmod*>(static_cast<Sigmod::Object*>(treeSigmod->currentIndex().internalPointer())->sigmod()); + const Sigmod::Sigmod* sigmod = static_cast<Sigmod::Object*>(treeSigmod->currentIndex().internalPointer())->sigmod(); treeSigmod->setDirty(sigmod, dirty); setChangedTitle(dirty); actionCollection()->action("file_save")->setEnabled(dirty); diff --git a/sigmodr/TileItem.cpp b/sigmodr/TileItem.cpp new file mode 100644 index 00000000..e97c09d7 --- /dev/null +++ b/sigmodr/TileItem.cpp @@ -0,0 +1,121 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "TileItem.h" + +// Sigmod includes +#include "../sigmod/MapTile.h" +#include "../sigmod/Sigmod.h" +#include "../sigmod/Sprite.h" +#include "../sigmod/Tile.h" + +// KDE includes +#include <KColorScheme> + +// Qt includes +#include <QtGui/QPainter> +#include <QtGui/QStyle> +#include <QtGui/QStyleOptionGraphicsItem> + +Sigmodr::TileItem::TileItem(Sigmod::MapTile* tile, QObject* parent) : + QObject(parent), + m_tile(tile) +{ + connect(m_tile, SIGNAL(changed()), this, SLOT(tileChanged())); + tileChanged(); + setAcceptHoverEvents(true); +} + +QRectF Sigmodr::TileItem::boundingRect() const +{ + return m_pixmap.rect(); +} + +void Sigmodr::TileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (m_pixmap.isNull()) + return; + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_pixmap.size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->drawPixmap(0, 0, m_pixmap); + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } +} + +void Sigmodr::TileItem::setZIndex(const int zIndex) +{ + if (zIndex < INT_MAX) + m_tile->setZIndex(zIndex); +} + +void Sigmodr::TileItem::changeSprite(const int spriteId) +{ + const Sigmod::Sprite* sprite = m_tile->sigmod()->spriteById(spriteId); + if (sprite) + m_pixmap.loadFromData(sprite->sprite()); + update(); +} + +void Sigmodr::TileItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::TileItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseMoveEvent(event); + m_tile->setPosition(scenePos().toPoint()); +} + +void Sigmodr::TileItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::TileItem::tileChanged() +{ + m_tileInfo = m_tile->sigmod()->tileById(m_tile->tile()); + setPos(m_tile->position()); + setZValue(m_tile->zIndex()); + update(); +} diff --git a/sigmodr/TileItem.h b/sigmodr/TileItem.h new file mode 100644 index 00000000..5cf3f35f --- /dev/null +++ b/sigmodr/TileItem.h @@ -0,0 +1,60 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMODR_TILEITEM +#define SIGMODR_TILEITEM + +// Qt includes +#include <QtGui/QGraphicsItem> + +// Forward declarations +namespace Sigmod +{ +class MapTile; +class Tile; +} + +namespace Sigmodr +{ +class TileItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + TileItem(Sigmod::MapTile* tile, QObject* parent); + + QRectF boundingRect() const; + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + + void setZIndex(const int zIndex); + public slots: + void changeSprite(const int spriteId); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + protected slots: + void tileChanged(); + private: + QPixmap m_pixmap; + Sigmod::MapTile* m_tile; + const Sigmod::Tile* m_tileInfo; +}; +} + +#endif diff --git a/sigmodr/TileUI.cpp b/sigmodr/TileUI.cpp index efa428e3..1c3410c2 100644 --- a/sigmodr/TileUI.cpp +++ b/sigmodr/TileUI.cpp @@ -34,45 +34,9 @@ Sigmodr::TileUI::~TileUI() { } -void Sigmodr::TileUI::initGui() -{ - QListWidgetItem* item; - item = new QListWidgetItem(Sigmod::DirectionStr[Sigmod::D_Up], varAccessibility); - item->setData(Qt::UserRole, QVariant::fromValue(Sigmod::D_Up)); - item = new QListWidgetItem(Sigmod::DirectionStr[Sigmod::D_Down], varAccessibility); - item->setData(Qt::UserRole, QVariant::fromValue(Sigmod::D_Down)); - item = new QListWidgetItem(Sigmod::DirectionStr[Sigmod::D_Left], varAccessibility); - item->setData(Qt::UserRole, QVariant::fromValue(Sigmod::D_Left)); - item = new QListWidgetItem(Sigmod::DirectionStr[Sigmod::D_Right], varAccessibility); - item->setData(Qt::UserRole, QVariant::fromValue(Sigmod::D_Right)); -} - -void Sigmodr::TileUI::refreshGui() -{ - int maxHeight = 0; - int maxWidth = 0; - const bool blocked = varSprite->blockSignals(true); - varSprite->clear(); - for (int i = 0; i < sigmod()->spriteCount(); ++i) - { - const Sigmod::Sprite* sprite = sigmod()->sprite(i); - QPixmap icon; - icon.loadFromData(sprite->sprite()); - maxHeight = qMax(maxHeight, icon.height()); - maxWidth = qMax(maxWidth, icon.width()); - varSprite->addItem(icon, sprite->name(), sprite->id()); - } - varSprite->blockSignals(blocked); - const QSize maxSize(maxWidth, maxHeight); - varSprite->setIconSize(maxSize); -} - void Sigmodr::TileUI::setGui() { varName->setText(qobject_cast<Sigmod::Tile*>(modified())->name()); - varSprite->setCurrentIndex(varSprite->findData(qobject_cast<Sigmod::Tile*>(modified())->sprite())); - for (int i = 0; i < varAccessibility->count(); ++i) - varAccessibility->item(i)->setSelected(qobject_cast<Sigmod::Tile*>(modified())->from(QVariant(i).value<Sigmod::Direction>())); varScript->setValue(qobject_cast<Sigmod::Tile*>(modified())->script()); } @@ -96,16 +60,6 @@ void Sigmodr::TileUI::on_varName_textChanged(const QString& name) varName->setCursorPosition(cursor); } -void Sigmodr::TileUI::on_varSprite_currentIndexChanged(const int sprite) -{ - qobject_cast<Sigmod::Tile*>(modified())->setSprite(varSprite->itemData(sprite).toInt()); -} - -void Sigmodr::TileUI::on_varAccessibility_itemClicked(QListWidgetItem* item) -{ - qobject_cast<Sigmod::Tile*>(modified())->setFrom(item->data(Qt::UserRole).value<Sigmod::Direction>(), item->isSelected()); -} - void Sigmodr::TileUI::on_varScript_valueChanged(const Sigcore::Script& script) { qobject_cast<Sigmod::Tile*>(modified())->setScript(script); diff --git a/sigmodr/TileUI.h b/sigmodr/TileUI.h index b387f89c..d72d4d28 100644 --- a/sigmodr/TileUI.h +++ b/sigmodr/TileUI.h @@ -44,12 +44,8 @@ class TileUI : public ObjectUI, private Ui::formTile void discard(); protected slots: void on_varName_textChanged(const QString& name); - void on_varSprite_currentIndexChanged(const int sprite); - void on_varAccessibility_itemClicked(QListWidgetItem* item); void on_varScript_valueChanged(const Sigcore::Script& script); private slots: - void initGui(); - void refreshGui(); void setGui(); }; } diff --git a/sigmodr/TilemapModel.cpp b/sigmodr/TilemapModel.cpp deleted file mode 100644 index 093b2389..00000000 --- a/sigmodr/TilemapModel.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -// Header include -#include "TilemapModel.h" - -// Sigmod includes -#include "../sigmod/Sigmod.h" -#include "../sigmod/Sprite.h" -#include "../sigmod/Tile.h" - -// Qt includes -#include <QtGui/QPixmap> - -Sigmodr::TilemapModel::TilemapModel(Sigcore::Matrix<int>* tilemap, const Sigmod::Sigmod* sigmod) : - QAbstractTableModel(), - m_tilemap(*tilemap), - m_sigmod(sigmod) -{ -} - -QVariant Sigmodr::TilemapModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - return QVariant(); - if (role == Qt::DisplayRole) - { - const int tileIndex = m_sigmod->tileIndex(m_tilemap(index.row(), index.column())); - if (tileIndex != INT_MAX) - { - const Sigmod::Tile* tile = m_sigmod->tile(tileIndex); - if (m_sigmod->spriteIndex(tile->sprite()) == INT_MAX) - return QPixmap(); - else - { - QPixmap icon; - icon.loadFromData(m_sigmod->spriteById(tile->sprite())->sprite()); - return icon; - } - } - } - else if (role == Qt::EditRole) - return m_tilemap(index.row(), index.column()); - return QVariant(); -} - -QVariant Sigmodr::TilemapModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_UNUSED(orientation) - if (role == Qt::DisplayRole) - return section; - return QVariant(); -} - -int Sigmodr::TilemapModel::rowCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return m_tilemap.height(); -} - -int Sigmodr::TilemapModel::columnCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return m_tilemap.width(); -} - -bool Sigmodr::TilemapModel::insertRows(int row, int count, const QModelIndex& parent) -{ - emit(beginInsertRows(parent, row, row + count - 1)); - for (int i = 0; i < count; ++i) - m_tilemap.insertRow(row); - emit(endInsertRows()); - if (m_tilemap.height() == 1) - reset(); - return true; -} - -bool Sigmodr::TilemapModel::insertColumns(int column, int count, const QModelIndex& parent) -{ - emit(beginInsertColumns(parent, column, column + count - 1)); - for (int i = 0; i < count; ++i) - m_tilemap.insertColumn(column); - emit(endInsertColumns()); - if (m_tilemap.width() == 1) - reset(); - return true; -} - -bool Sigmodr::TilemapModel::removeRows(int row, int count, const QModelIndex& parent) -{ - emit(beginRemoveRows(parent, row, row + count - 1)); - for (int i = 0; i < count; ++i) - m_tilemap.deleteRow(row); - emit(endRemoveRows()); - if (!m_tilemap.height()) - reset(); - return true; -} - -bool Sigmodr::TilemapModel::removeColumns(int column, int count, const QModelIndex& parent) -{ - emit(beginRemoveColumns(parent, column, column + count - 1)); - for (int i = 0; i < count; ++i) - m_tilemap.deleteColumn(column); - emit(endRemoveColumns()); - if (!m_tilemap.width()) - reset(); - return true; -} - -Qt::ItemFlags Sigmodr::TilemapModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - return 0; - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; -} - -bool Sigmodr::TilemapModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid()) - return false; - if (role == Qt::EditRole) - { - m_tilemap(index.row(), index.column()) = value.toInt(); - emit(dataChanged(index, index)); - return true; - } - return false; -} diff --git a/sigmodr/TilemapModel.h b/sigmodr/TilemapModel.h deleted file mode 100644 index a63a43da..00000000 --- a/sigmodr/TilemapModel.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef SIGMODR_TILEMAPMODEL -#define SIGMODR_TILEMAPMODEL - -// Sigcore includes -#include "../sigcore/Matrix.h" - -// Qt includes -#include <QtCore/QAbstractTableModel> -#include <QtCore/QVariant> - -// Forward declarations -namespace Sigmod -{ -class Sigmod; -} - -namespace Sigmodr -{ -class TilemapModel : public QAbstractTableModel -{ - Q_OBJECT - - public: - TilemapModel(Sigcore::Matrix<int>* tilemap, const Sigmod::Sigmod* sigmod); - - QVariant data(const QModelIndex& index, int role) const; - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - - int rowCount(const QModelIndex& parent) const; - int columnCount(const QModelIndex& parent) const; - - bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()); - bool insertColumns(int column, int count, const QModelIndex& parent = QModelIndex()); - bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()); - bool removeColumns(int column, int count, const QModelIndex& parent = QModelIndex()); - - Qt::ItemFlags flags(const QModelIndex& index) const; - - bool setData(const QModelIndex& index, const QVariant& value, int role); - private: - Sigcore::Matrix<int>& m_tilemap; - const Sigmod::Sigmod* m_sigmod; -}; -} - -#endif diff --git a/sigmodr/TrainerItem.cpp b/sigmodr/TrainerItem.cpp new file mode 100644 index 00000000..b23856be --- /dev/null +++ b/sigmodr/TrainerItem.cpp @@ -0,0 +1,118 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "TrainerItem.h" + +// Sigmod includes +#include "../sigmod/MapTrainer.h" +#include "../sigmod/Sigmod.h" +#include "../sigmod/Sprite.h" + +// KDE includes +#include <KColorScheme> + +// Qt includes +#include <QtGui/QPainter> +#include <QtGui/QStyle> +#include <QtGui/QStyleOptionGraphicsItem> + +Sigmodr::TrainerItem::TrainerItem(Sigmod::MapTrainer* trainer, QObject* parent) : + QObject(parent), + m_trainer(trainer) +{ + connect(m_trainer, SIGNAL(changed()), this, SLOT(trainerChanged())); + trainerChanged(); + setZValue(INT_MAX); + setAcceptHoverEvents(true); +} + +QRectF Sigmodr::TrainerItem::boundingRect() const +{ + return m_pixmap.rect(); +} + +void Sigmodr::TrainerItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (m_pixmap.isNull()) + return; + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_pixmap.size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->drawPixmap(0, 0, m_pixmap); + if (option->state & QStyle::State_MouseOver) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); + painter->drawText(m_pixmap.rect(), Qt::AlignHCenter | Qt::AlignVCenter, m_trainer->name()); + } + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } +} + +void Sigmodr::TrainerItem::changeSprite(const int spriteId) +{ + const Sigmod::Sprite* sprite = m_trainer->sigmod()->spriteById(spriteId); + if (sprite) + m_pixmap.loadFromData(sprite->sprite()); + update(); +} + +void Sigmodr::TrainerItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::TrainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseMoveEvent(event); + m_trainer->setCoordinate(scenePos().toPoint()); +} + +void Sigmodr::TrainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::TrainerItem::trainerChanged() +{ + setPos(m_trainer->coordinate()); + update(); +} diff --git a/sigmodr/TrainerItem.h b/sigmodr/TrainerItem.h new file mode 100644 index 00000000..5733194b --- /dev/null +++ b/sigmodr/TrainerItem.h @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGMODR_TRAINERITEM +#define SIGMODR_TRAINERITEM + +// Qt includes +#include <QtGui/QGraphicsItem> + +// Forward declarations +namespace Sigmod +{ +class MapTrainer; +} + +namespace Sigmodr +{ +class TrainerItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + TrainerItem(Sigmod::MapTrainer* trainer, QObject* parent); + + QRectF boundingRect() const; + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + public slots: + void changeSprite(const int spriteId); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + protected slots: + void trainerChanged(); + private: + QPixmap m_pixmap; + Sigmod::MapTrainer* m_trainer; +}; +} + +#endif diff --git a/sigmodr/WarpItem.cpp b/sigmodr/WarpItem.cpp new file mode 100644 index 00000000..bf1f2385 --- /dev/null +++ b/sigmodr/WarpItem.cpp @@ -0,0 +1,123 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "WarpItem.h" + +// Sigmod includes +#include "../sigmod/MapWarp.h" +#include "../sigmod/Sigmod.h" + +// KDE includes +#include <KColorScheme> + +// Qt includes +#include <QtGui/QGraphicsSceneMouseEvent> +#include <QtGui/QPainter> +#include <QtGui/QStyle> +#include <QtGui/QStyleOptionGraphicsItem> + +Sigmodr::WarpItem::WarpItem(Sigmod::MapWarp* warp, QObject* parent) : + QObject(parent), + m_warp(warp) +{ + connect(m_warp, SIGNAL(changed()), this, SLOT(warpChanged())); + warpChanged(); + setZValue(INT_MAX); + setAcceptHoverEvents(true); +} + +QRectF Sigmodr::WarpItem::boundingRect() const +{ + return m_warp->area(); +} + +void Sigmodr::WarpItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (m_warp->area().size().isValid()) + return; + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_warp->area().size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->setBrush(KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground).brush(QPalette::Active)); + painter->drawRect(m_warp->area()); + if (option->state & QStyle::State_MouseOver) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); + painter->drawText(m_warp->area(), Qt::AlignHCenter | Qt::AlignVCenter, m_warp->name()); + } + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_warp->area()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_warp->area()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_warp->area()); + } +} + +void Sigmodr::WarpItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::WarpItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + if (event->modifiers() & Qt::ShiftModifier) + { + QRect rect = m_warp->area(); + QPointF diff = event->scenePos() - event->lastScenePos(); + rect.setSize(rect.size() + QSize(diff.x(), diff.y())); + m_warp->setArea(rect); + } + else + { + QGraphicsItem::mouseMoveEvent(event); + QRect rect = m_warp->area(); + rect.setTopLeft(scenePos().toPoint()); + m_warp->setArea(rect); + } +} + +void Sigmodr::WarpItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::WarpItem::warpChanged() +{ + setPos(m_warp->area().topLeft()); + update(); +} diff --git a/sigmodr/PointWidget.h b/sigmodr/WarpItem.h index be50d0d5..c9bf9eb2 100644 --- a/sigmodr/PointWidget.h +++ b/sigmodr/WarpItem.h @@ -15,36 +15,38 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SIGMODR_POINTWIDGET -#define SIGMODR_POINTWIDGET +#ifndef SIGMODR_WARPITEM +#define SIGMODR_WARPITEM // Qt includes -#include <QtCore/QPoint> -#include <QtGui/QWidget> +#include <QtGui/QGraphicsItem> -// Form include -#include "ui_point.h" +// Forward declarations +namespace Sigmod +{ +class MapWarp; +} namespace Sigmodr { -class PointWidget : public QWidget, private Ui::formPoint +class WarpItem : public QObject, public QGraphicsItem { Q_OBJECT public: - explicit PointWidget(QWidget* parent, const QPoint& value = QPoint(0, 0)); + WarpItem(Sigmod::MapWarp* warp, QObject* parent); + + QRectF boundingRect() const; - QPoint value() const; - public slots: - void setValue(const QPoint& value); - void setMaximum(const QPoint& maximum); - signals: - void valueChanged(const QPoint&); + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); protected slots: - void on_varX_valueChanged(const int x); - void on_varY_valueChanged(const int y); + void warpChanged(); private: - QPoint m_value; + Sigmod::MapWarp* m_warp; }; } diff --git a/sigmodr/gui/map.ui b/sigmodr/gui/map.ui index 4fe79161..1797e7aa 100644 --- a/sigmodr/gui/map.ui +++ b/sigmodr/gui/map.ui @@ -4,9 +4,6 @@ <layout class="QVBoxLayout" > <item> <widget class="QGroupBox" name="boxName" > - <property name="title" > - <string>Name</string> - </property> <property name="toolTip" > <string>Name of the map (internal use only)</string> </property> @@ -16,6 +13,9 @@ <property name="whatsThis" > <string>Name of the map (internal use only)</string> </property> + <property name="title" > + <string>Name</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KLineEdit" name="varName" > @@ -29,15 +29,6 @@ </item> <item> <widget class="QGroupBox" name="boxFlyWarp" > - <property name="title" > - <string>Fly Warp</string> - </property> - <property name="checkable" > - <bool>true</bool> - </property> - <property name="checked" > - <bool>false</bool> - </property> <property name="toolTip" > <string>The destination when flown to the map</string> </property> @@ -47,19 +38,24 @@ <property name="whatsThis" > <string>The destination when flown to the map</string> </property> + <property name="title" > + <string>Fly Warp</string> + </property> + <property name="checkable" > + <bool>true</bool> + </property> + <property name="checked" > + <bool>false</bool> + </property> <layout class="QHBoxLayout" > <item> - <widget class="KComboBox" name="varFlyWarp" > - </widget> + <widget class="KComboBox" name="varFlyWarp" /> </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="boxType" > - <property name="title" > - <string>Type</string> - </property> <property name="toolTip" > <string>They type of map</string> </property> @@ -69,6 +65,9 @@ <property name="whatsThis" > <string>They type of map</string> </property> + <property name="title" > + <string>Type</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KComboBox" name="varType" /> @@ -77,141 +76,13 @@ </widget> </item> <item> - <widget class="QGroupBox" name="boxTilemap" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Expanding" hsizetype="Preferred" > - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> + <widget class="QGroupBox" name="boxMap" > <property name="title" > - <string>Tilemap</string> + <string>Map</string> </property> - <layout class="QGridLayout" > - <item rowspan="7" row="0" column="0" > - <widget class="QTableView" name="varTilemap" > - <property name="toolTip" > - <string>The tilemap of the map</string> - </property> - <property name="statusTip" > - <string>The tilemap of the map</string> - </property> - <property name="whatsThis" > - <string>The tilemap of the map</string> - </property> - <property name="selectionMode" > - <enum>QAbstractItemView::SingleSelection</enum> - </property> - </widget> - </item> - <item row="6" column="1" > - <widget class="KComboBox" name="varTile" > - <property name="toolTip" > - <string>The tile for the current position</string> - </property> - <property name="statusTip" > - <string>The tile for the current position</string> - </property> - <property name="whatsThis" > - <string>The tile for the current position</string> - </property> - </widget> - </item> - <item row="5" column="1" > - <widget class="KPushButton" name="buttonDeleteColumn" > - <property name="text" > - <string>Delete Column</string> - </property> - <property name="toolTip" > - <string>Delete the current column</string> - </property> - <property name="statusTip" > - <string>Delete the current column</string> - </property> - <property name="whatsThis" > - <string>Delete the current column</string> - </property> - </widget> - </item> - <item row="4" column="1" > - <widget class="KPushButton" name="buttonInsertColumn" > - <property name="text" > - <string>Insert Column</string> - </property> - <property name="toolTip" > - <string>Insert a new column at the current position</string> - </property> - <property name="statusTip" > - <string>Insert a new column at the current position</string> - </property> - <property name="whatsThis" > - <string>Insert a new column at the current position</string> - </property> - </widget> - </item> - <item row="3" column="1" > - <widget class="KPushButton" name="buttonAddColumn" > - <property name="text" > - <string>Add Column</string> - </property> - <property name="toolTip" > - <string>Add a new column</string> - </property> - <property name="statusTip" > - <string>Add a new column</string> - </property> - <property name="whatsThis" > - <string>Add a new column</string> - </property> - </widget> - </item> - <item row="2" column="1" > - <widget class="KPushButton" name="buttonDeleteRow" > - <property name="text" > - <string>Delete Row</string> - </property> - <property name="toolTip" > - <string>Delete the current row</string> - </property> - <property name="statusTip" > - <string>Delete the current row</string> - </property> - <property name="whatsThis" > - <string>Delete the current row</string> - </property> - </widget> - </item> - <item row="1" column="1" > - <widget class="KPushButton" name="buttonInsertRow" > - <property name="text" > - <string>Insert Row</string> - </property> - <property name="toolTip" > - <string>Insert a new row at the current position</string> - </property> - <property name="statusTip" > - <string>Insert a new row at the current position</string> - </property> - <property name="whatsThis" > - <string>Insert a new row at the current position</string> - </property> - </widget> - </item> - <item row="0" column="1" > - <widget class="KPushButton" name="buttonAddRow" > - <property name="text" > - <string>Add Row</string> - </property> - <property name="toolTip" > - <string>Add a new row</string> - </property> - <property name="statusTip" > - <string>Add a new row</string> - </property> - <property name="whatsThis" > - <string>Add a new row</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout" > + <item> + <widget class="Sigmodr::MapEditor" name="varMap" /> </item> </layout> </widget> @@ -225,14 +96,20 @@ <header location="global" >KComboBox</header> </customwidget> <customwidget> + <class>KIntNumInput</class> + <extends>QWidget</extends> + <header location="global" >KIntNumInput</header> + </customwidget> + <customwidget> <class>KLineEdit</class> <extends>QLineEdit</extends> <header location="global" >KLineEdit</header> </customwidget> <customwidget> - <class>KPushButton</class> - <extends>QPushButton</extends> - <header location="global" >KPushButton</header> + <class>Sigmodr::MapEditor</class> + <extends>QWidget</extends> + <header>MapEditor.h</header> + <container>1</container> </customwidget> </customwidgets> <resources/> diff --git a/sigmodr/gui/mapeffect.ui b/sigmodr/gui/mapeffect.ui index 96efbab9..ec3ec03d 100644 --- a/sigmodr/gui/mapeffect.ui +++ b/sigmodr/gui/mapeffect.ui @@ -4,9 +4,6 @@ <layout class="QVBoxLayout" > <item> <widget class="QGroupBox" name="boxName" > - <property name="title" > - <string>Name</string> - </property> <property name="toolTip" > <string>Name of the effect</string> </property> @@ -16,6 +13,9 @@ <property name="whatsThis" > <string>Name of the effect</string> </property> + <property name="title" > + <string>Name</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KLineEdit" name="varName" > @@ -28,31 +28,7 @@ </widget> </item> <item> - <widget class="QGroupBox" name="boxCoordinate" > - <property name="title" > - <string>Coordinate</string> - </property> - <property name="toolTip" > - <string>The coordinate of the effect</string> - </property> - <property name="statusTip" > - <string>The coordinate of the effect</string> - </property> - <property name="whatsThis" > - <string>The coordinate of the effect</string> - </property> - <layout class="QHBoxLayout" > - <item> - <widget class="Sigmodr::PointWidget" name="varCoordinate" /> - </item> - </layout> - </widget> - </item> - <item> <widget class="QGroupBox" name="boxSkin" > - <property name="title" > - <string>Skin</string> - </property> <property name="toolTip" > <string>Skin of the effect</string> </property> @@ -62,6 +38,9 @@ <property name="whatsThis" > <string>Skin of the effect</string> </property> + <property name="title" > + <string>Skin</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KComboBox" name="varSkin" /> @@ -71,15 +50,6 @@ </item> <item> <widget class="QGroupBox" name="varIsGhost" > - <property name="title" > - <string>Is Transparent</string> - </property> - <property name="checkable" > - <bool>true</bool> - </property> - <property name="checked" > - <bool>false</bool> - </property> <property name="toolTip" > <string>If checked, the effect does not block movement</string> </property> @@ -89,14 +59,20 @@ <property name="whatsThis" > <string>If checked, the effect does not block movement</string> </property> + <property name="title" > + <string>Is Transparent</string> + </property> + <property name="checkable" > + <bool>true</bool> + </property> + <property name="checked" > + <bool>false</bool> + </property> <layout class="QHBoxLayout" /> </widget> </item> <item> <widget class="QGroupBox" name="boxScript" > - <property name="title" > - <string>Script</string> - </property> <property name="toolTip" > <string>The script for the effect</string> </property> @@ -106,9 +82,12 @@ <property name="whatsThis" > <string>The script for the effect</string> </property> + <property name="title" > + <string>Script</string> + </property> <layout class="QHBoxLayout" > <item> - <widget class="Sigmodr::ScriptWidget" name="varScript" /> + <widget class="Sigmodr::ScriptWidget" native="1" name="varScript" /> </item> </layout> </widget> @@ -117,24 +96,19 @@ </widget> <customwidgets> <customwidget> - <class>KLineEdit</class> - <extends>QLineEdit</extends> - <header location="global" >KLineEdit</header> - </customwidget> - <customwidget> <class>KComboBox</class> <extends>QComboBox</extends> <header location="global" >KComboBox</header> </customwidget> <customwidget> - <class>Sigmodr::ScriptWidget</class> - <extends>QWidget</extends> - <header>ScriptWidget.h</header> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header location="global" >KLineEdit</header> </customwidget> <customwidget> - <class>Sigmodr::PointWidget</class> + <class>Sigmodr::ScriptWidget</class> <extends>QWidget</extends> - <header>PointWidget.h</header> + <header>ScriptWidget.h</header> </customwidget> </customwidgets> <resources/> diff --git a/sigmodr/gui/maptrainer.ui b/sigmodr/gui/maptrainer.ui index f2eb5d3b..6f4421fd 100644 --- a/sigmodr/gui/maptrainer.ui +++ b/sigmodr/gui/maptrainer.ui @@ -4,9 +4,6 @@ <layout class="QVBoxLayout" > <item> <widget class="QGroupBox" name="boxName" > - <property name="title" > - <string>Name</string> - </property> <property name="toolTip" > <string>Name of the trainer</string> </property> @@ -16,6 +13,9 @@ <property name="whatsThis" > <string>Name of the trainer</string> </property> + <property name="title" > + <string>Name</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KLineEdit" name="varName" > @@ -29,9 +29,6 @@ </item> <item> <widget class="QGroupBox" name="boxTrainerClass" > - <property name="title" > - <string>Trainer Class</string> - </property> <property name="toolTip" > <string>The base class of the trainer</string> </property> @@ -41,39 +38,18 @@ <property name="whatsThis" > <string>The base class of the trainer</string> </property> - <layout class="QHBoxLayout" > - <item> - <widget class="KComboBox" name="varTrainerClass" /> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="boxCoordinate" > <property name="title" > - <string>Coordinate</string> - </property> - <property name="toolTip" > - <string>The coordinate of the trainer</string> - </property> - <property name="statusTip" > - <string>The coordinate of the trainer</string> - </property> - <property name="whatsThis" > - <string>The coordinate of the trainer</string> + <string>Trainer Class</string> </property> - <layout class="QVBoxLayout" > + <layout class="QHBoxLayout" > <item> - <widget class="Sigmodr::PointWidget" name="varCoordinate" /> + <widget class="KComboBox" name="varTrainerClass" /> </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="boxNumberFight" > - <property name="title" > - <string>Number Fight</string> - </property> <property name="toolTip" > <string>How many team members from each side fight at a time</string> </property> @@ -83,6 +59,9 @@ <property name="whatsThis" > <string>How many team members from each side fight at a time</string> </property> + <property name="title" > + <string>Number Fight</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KIntNumInput" name="varNumberFight" > @@ -96,9 +75,6 @@ </item> <item> <widget class="QGroupBox" name="boxScript" > - <property name="title" > - <string>Script</string> - </property> <property name="toolTip" > <string>The script for the trainer</string> </property> @@ -108,18 +84,18 @@ <property name="whatsThis" > <string>The script for the trainer</string> </property> + <property name="title" > + <string>Script</string> + </property> <layout class="QHBoxLayout" name="horizontalLayout" > <item> - <widget class="Sigmodr::ScriptWidget" name="varScript" /> + <widget class="Sigmodr::ScriptWidget" native="1" name="varScript" /> </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="boxLeadTeamMember" > - <property name="title" > - <string>Lead Team Member</string> - </property> <property name="toolTip" > <string>The lead team member</string> </property> @@ -129,6 +105,9 @@ <property name="whatsThis" > <string>The lead team member</string> </property> + <property name="title" > + <string>Lead Team Member</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KComboBox" name="varLeadTeamMember" /> @@ -159,11 +138,6 @@ <extends>QWidget</extends> <header>ScriptWidget.h</header> </customwidget> - <customwidget> - <class>Sigmodr::PointWidget</class> - <extends>QWidget</extends> - <header>PointWidget.h</header> - </customwidget> </customwidgets> <resources/> <connections/> diff --git a/sigmodr/gui/mapwarp.ui b/sigmodr/gui/mapwarp.ui index 4fb9ad26..c6bdbf9f 100644 --- a/sigmodr/gui/mapwarp.ui +++ b/sigmodr/gui/mapwarp.ui @@ -4,9 +4,6 @@ <layout class="QVBoxLayout" > <item> <widget class="QGroupBox" name="boxName" > - <property name="title" > - <string>Name</string> - </property> <property name="toolTip" > <string>Name of the warp (internal use only)</string> </property> @@ -16,6 +13,9 @@ <property name="whatsThis" > <string>Name of the warp (internal use only)</string> </property> + <property name="title" > + <string>Name</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KLineEdit" name="varName" > @@ -28,31 +28,7 @@ </widget> </item> <item> - <widget class="QGroupBox" name="boxCoordinate" > - <property name="title" > - <string>Coordinate</string> - </property> - <property name="toolTip" > - <string>The coordinate of the warp</string> - </property> - <property name="statusTip" > - <string>The coordinate of the warp</string> - </property> - <property name="whatsThis" > - <string>The coordinate of the warp</string> - </property> - <layout class="QVBoxLayout" > - <item> - <widget class="Sigmodr::PointWidget" name="varCoordinate" /> - </item> - </layout> - </widget> - </item> - <item> <widget class="QGroupBox" name="boxType" > - <property name="title" > - <string>Type</string> - </property> <property name="toolTip" > <string>The type of warp</string> </property> @@ -62,6 +38,9 @@ <property name="whatsThis" > <string>The type of warp</string> </property> + <property name="title" > + <string>Type</string> + </property> <layout class="QHBoxLayout" > <item> <widget class="KComboBox" name="varType" /> @@ -71,9 +50,6 @@ </item> <item> <widget class="QGroupBox" name="boxDestination" > - <property name="title" > - <string>Destination Map</string> - </property> <property name="toolTip" > <string>The destination for the warp</string> </property> @@ -83,6 +59,9 @@ <property name="whatsThis" > <string>The destination for the warp</string> </property> + <property name="title" > + <string>Destination Map</string> + </property> <layout class="QVBoxLayout" > <item> <widget class="KComboBox" name="varToMap" > @@ -124,9 +103,6 @@ </item> <item> <widget class="QGroupBox" name="boxScript" > - <property name="title" > - <string>Script</string> - </property> <property name="toolTip" > <string>The script that is executed when the warp is activated</string> </property> @@ -136,9 +112,12 @@ <property name="whatsThis" > <string>The script that is executed when the warp is activated</string> </property> + <property name="title" > + <string>Script</string> + </property> <layout class="QHBoxLayout" > <item> - <widget class="Sigmodr::ScriptWidget" name="varScript" /> + <widget class="Sigmodr::ScriptWidget" native="1" name="varScript" /> </item> </layout> </widget> @@ -161,11 +140,6 @@ <extends>QWidget</extends> <header>ScriptWidget.h</header> </customwidget> - <customwidget> - <class>Sigmodr::PointWidget</class> - <extends>QWidget</extends> - <header>PointWidget.h</header> - </customwidget> </customwidgets> <resources/> <connections/> diff --git a/sigmodr/gui/point.ui b/sigmodr/gui/point.ui deleted file mode 100644 index 2337800f..00000000 --- a/sigmodr/gui/point.ui +++ /dev/null @@ -1,54 +0,0 @@ -<ui version="4.0" > - <class>formPoint</class> - <widget class="QWidget" name="formPoint" > - <layout class="QHBoxLayout" > - <item> - <widget class="KIntNumInput" name="varX" > - <property name="label" > - <string>x</string> - </property> - <property name="toolTip" > - <string>The x coordinate of the point</string> - </property> - <property name="statusTip" > - <string>The x coordinate of the point</string> - </property> - <property name="whatsThis" > - <string>The x coordinate of the point</string> - </property> - <property name="minimum" > - <number>0</number> - </property> - </widget> - </item> - <item> - <widget class="KIntNumInput" name="varY" > - <property name="label" > - <string>y</string> - </property> - <property name="toolTip" > - <string>The y coordinate of the point</string> - </property> - <property name="statusTip" > - <string>The y coordinate of the point</string> - </property> - <property name="whatsThis" > - <string>The y coordinate of the point</string> - </property> - <property name="minimum" > - <number>0</number> - </property> - </widget> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>KIntNumInput</class> - <extends>QWidget</extends> - <header location="global" >KIntNumInput</header> - </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> diff --git a/sigmodr/gui/tile.ui b/sigmodr/gui/tile.ui index 5419ef1e..5b87332e 100644 --- a/sigmodr/gui/tile.ui +++ b/sigmodr/gui/tile.ui @@ -28,52 +28,6 @@ </widget> </item> <item> - <widget class="QGroupBox" name="boxSprite" > - <property name="title" > - <string>Image</string> - </property> - <property name="toolTip" > - <string>Image of the tile</string> - </property> - <property name="statusTip" > - <string>Image of the tile</string> - </property> - <property name="whatsThis" > - <string>Image of the tile</string> - </property> - <layout class="QVBoxLayout" > - <item> - <widget class="KComboBox" name="varSprite" /> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="boxAccessibility" > - <property name="title" > - <string>Accessibility</string> - </property> - <property name="toolTip" > - <string>Directions into the tile</string> - </property> - <property name="statusTip" > - <string>Directions into the tile</string> - </property> - <property name="whatsThis" > - <string>Directions into the tile</string> - </property> - <layout class="QHBoxLayout" > - <item> - <widget class="KListWidget" name="varAccessibility" > - <property name="selectionMode" > - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> <widget class="QGroupBox" name="boxScript" > <property name="title" > <string>Script</string> @@ -103,16 +57,6 @@ <header location="global" >KLineEdit</header> </customwidget> <customwidget> - <class>KListWidget</class> - <extends>QListWidget</extends> - <header location="global" >KListWidget</header> - </customwidget> - <customwidget> - <class>KComboBox</class> - <extends>QComboBox</extends> - <header location="global" >KComboBox</header> - </customwidget> - <customwidget> <class>Sigmodr::ScriptWidget</class> <extends>QWidget</extends> <header>ScriptWidget.h</header> diff --git a/sigmodr/models/CoinListObjectModel.cpp b/sigmodr/models/CoinListObjectModel.cpp index ee74e2e4..8264e272 100644 --- a/sigmodr/models/CoinListObjectModel.cpp +++ b/sigmodr/models/CoinListObjectModel.cpp @@ -50,15 +50,15 @@ QVariant Sigmodr::CoinListObjectModel::data(int role) const Sigmod::CoinListObject* object = qobject_cast<Sigmod::CoinListObject*>(m_object); if (object->type() == Sigmod::CoinListObject::Item) { - const int index = qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->itemIndex(object->object()); - if (index != INT_MAX) - return qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->item(index)->name(); + const Sigmod::Item* item = m_object->sigmod()->itemById(object->object()); + if (item) + return item->name(); } else if (object->type() == Sigmod::CoinListObject::Species) { - const int index = qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->speciesIndex(object->object()); - if (index != INT_MAX) - return qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->species(index)->name(); + const Sigmod::Species* species = m_object->sigmod()->speciesById(object->object()); + if (species) + return species->name(); } return ""; } diff --git a/sigmodr/models/MapTrainerTeamMemberModel.cpp b/sigmodr/models/MapTrainerTeamMemberModel.cpp index 80395d5c..eeaf3377 100644 --- a/sigmodr/models/MapTrainerTeamMemberModel.cpp +++ b/sigmodr/models/MapTrainerTeamMemberModel.cpp @@ -46,7 +46,7 @@ QVariant Sigmodr::MapTrainerTeamMemberModel::data(int role) const { if (role == Qt::DisplayRole) { - const Sigmod::Species* species = qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->speciesById(qobject_cast<Sigmod::MapTrainerTeamMember*>(m_object)->species()); + const Sigmod::Species* species = m_object->sigmod()->speciesById(qobject_cast<Sigmod::MapTrainerTeamMember*>(m_object)->species()); if (species) return species->name(); return ""; diff --git a/sigmodr/models/MapWildListEncounterModel.cpp b/sigmodr/models/MapWildListEncounterModel.cpp index e5130c10..9f5cb801 100644 --- a/sigmodr/models/MapWildListEncounterModel.cpp +++ b/sigmodr/models/MapWildListEncounterModel.cpp @@ -46,7 +46,7 @@ QVariant Sigmodr::MapWildListEncounterModel::data(int role) const { if (role == Qt::DisplayRole) { - const Sigmod::Species* species = qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->speciesById(qobject_cast<Sigmod::MapWildListEncounter*>(m_object)->species()); + const Sigmod::Species* species = m_object->sigmod()->speciesById(qobject_cast<Sigmod::MapWildListEncounter*>(m_object)->species()); if (species) return species->name(); return ""; diff --git a/sigmodr/models/SpeciesAbilityModel.cpp b/sigmodr/models/SpeciesAbilityModel.cpp index 3aefd6fd..9e5ee6c2 100644 --- a/sigmodr/models/SpeciesAbilityModel.cpp +++ b/sigmodr/models/SpeciesAbilityModel.cpp @@ -46,9 +46,9 @@ QVariant Sigmodr::SpeciesAbilityModel::data(int role) const { if (role == Qt::DisplayRole) { - const int index = qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->abilityIndex(qobject_cast<Sigmod::SpeciesAbility*>(m_object)->ability()); - if (index != INT_MAX) - return qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->ability(index)->name(); + const Sigmod::Ability* ability = m_object->sigmod()->abilityById(qobject_cast<Sigmod::SpeciesAbility*>(m_object)->ability()); + if (ability) + return ability->name(); return ""; } else if (role == Sigmodr::BaseModel::XmlRole) diff --git a/sigmodr/models/SpeciesItemModel.cpp b/sigmodr/models/SpeciesItemModel.cpp index 2d26bde5..28ec11df 100644 --- a/sigmodr/models/SpeciesItemModel.cpp +++ b/sigmodr/models/SpeciesItemModel.cpp @@ -46,9 +46,9 @@ QVariant Sigmodr::SpeciesItemModel::data(int role) const { if (role == Qt::DisplayRole) { - const int index = qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->itemIndex(qobject_cast<Sigmod::SpeciesItem*>(m_object)->item()); - if (index != INT_MAX) - return qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->item(index)->name(); + const Sigmod::Item* item = m_object->sigmod()->itemById(qobject_cast<Sigmod::SpeciesItem*>(m_object)->item()); + if (item) + return item->name(); return ""; } else if (role == Sigmodr::BaseModel::XmlRole) diff --git a/sigmodr/models/SpeciesMoveModel.cpp b/sigmodr/models/SpeciesMoveModel.cpp index b2441a45..8357a261 100644 --- a/sigmodr/models/SpeciesMoveModel.cpp +++ b/sigmodr/models/SpeciesMoveModel.cpp @@ -46,9 +46,9 @@ QVariant Sigmodr::SpeciesMoveModel::data(int role) const { if (role == Qt::DisplayRole) { - const int index = qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->moveIndex(qobject_cast<Sigmod::SpeciesMove*>(m_object)->move()); - if (index != INT_MAX) - return qobject_cast<const Sigmod::Sigmod*>(m_object->sigmod())->move(index)->name(); + const Sigmod::Move* move = m_object->sigmod()->move(qobject_cast<Sigmod::SpeciesMove*>(m_object)->move()); + if (move) + return move->name(); return ""; } else if (role == Sigmodr::BaseModel::XmlRole) diff --git a/sigmodr/overlays/effect.png b/sigmodr/overlays/effect.png Binary files differdeleted file mode 100644 index 6d4c38a1..00000000 --- a/sigmodr/overlays/effect.png +++ /dev/null diff --git a/sigmodr/overlays/no-walk.png b/sigmodr/overlays/no-walk.png Binary files differdeleted file mode 100644 index 11b15e81..00000000 --- a/sigmodr/overlays/no-walk.png +++ /dev/null diff --git a/sigmodr/overlays/overlays.qrc b/sigmodr/overlays/overlays.qrc deleted file mode 100644 index 265ada6d..00000000 --- a/sigmodr/overlays/overlays.qrc +++ /dev/null @@ -1,9 +0,0 @@ -<RCC> - <qresource prefix="overlays/" > - <file alias="effects" >effect.png</file> - <file alias="no-walk" >no-walk.png</file> - <file alias="trainer" >trainer.png</file> - <file alias="walk" >walk.png</file> - <file alias="warp" >warp.png</file> - </qresource> -</RCC> diff --git a/sigmodr/overlays/trainer.png b/sigmodr/overlays/trainer.png Binary files differdeleted file mode 100644 index e0d23cae..00000000 --- a/sigmodr/overlays/trainer.png +++ /dev/null diff --git a/sigmodr/overlays/walk.png b/sigmodr/overlays/walk.png Binary files differdeleted file mode 100644 index f4e69557..00000000 --- a/sigmodr/overlays/walk.png +++ /dev/null diff --git a/sigmodr/overlays/warp.png b/sigmodr/overlays/warp.png Binary files differdeleted file mode 100644 index 20baeb10..00000000 --- a/sigmodr/overlays/warp.png +++ /dev/null diff --git a/sigmodr/sigmodr.pro b/sigmodr/sigmodr.pro index 3f9ce5fe..8d86cabc 100644 --- a/sigmodr/sigmodr.pro +++ b/sigmodr/sigmodr.pro @@ -40,11 +40,13 @@ SOURCES += AbilityUI.cpp \ BadgeUI.cpp \ CoinListUI.cpp \ CoinListObjectUI.cpp \ + EffectItem.cpp \ EggGroupUI.cpp \ FractionWidget.cpp \ GlobalScriptUI.cpp \ ItemUI.cpp \ ItemTypeUI.cpp \ + MapEditor.cpp \ MapUI.cpp \ MapEffectUI.cpp \ MapTrainerUI.cpp \ @@ -55,7 +57,6 @@ SOURCES += AbilityUI.cpp \ MoveUI.cpp \ NatureUI.cpp \ ObjectUI.cpp \ - PointWidget.cpp \ RulesUI.cpp \ ScriptWidget.cpp \ SigmodTree.cpp \ @@ -73,13 +74,16 @@ SOURCES += AbilityUI.cpp \ SpriteUI.cpp \ StatusUI.cpp \ StoreUI.cpp \ - TilemapModel.cpp \ + TileItem.cpp \ + TilemapScene.cpp \ TileUI.cpp \ TimeUI.cpp \ + TrainerItem.cpp \ TrainerUI.cpp \ TypechartModel.cpp \ TypeUI.cpp \ ValidationDialog.cpp \ + WarpItem.cpp \ WeatherUI.cpp \ models/AbilityGroupModel.cpp \ models/AbilityModel.cpp \ @@ -157,11 +161,13 @@ HEADERS += AbilityUI.h \ BadgeUI.h \ CoinListUI.h \ CoinListObjectUI.h \ + EffectItem.h \ EggGroupUI.h \ FractionWidget.h \ GlobalScriptUI.h \ ItemUI.h \ ItemTypeUI.h \ + MapEditor.h \ MapUI.h \ MapEffectUI.h \ MapTrainerUI.h \ @@ -172,7 +178,6 @@ HEADERS += AbilityUI.h \ MoveUI.h \ NatureUI.h \ ObjectUI.h \ - PointWidget.h \ RulesUI.h \ ScriptWidget.h \ SigmodTree.h \ @@ -189,13 +194,16 @@ HEADERS += AbilityUI.h \ SpriteUI.h \ StatusUI.h \ StoreUI.h \ - TilemapModel.h \ + TileItem.h \ + TilemapScene.h \ TileUI.h \ TimeUI.h \ - TypechartModel.h \ + TrainerItem.h \ TrainerUI.h \ + TypechartModel.h \ TypeUI.h \ ValidationDialog.h \ + WarpItem.h \ WeatherUI.h \ models/AbilityGroupModel.h \ models/AbilityModel.h \ @@ -287,7 +295,6 @@ FORMS += gui/ability.ui \ gui/mapwildlistencounter.ui \ gui/move.ui \ gui/nature.ui \ - gui/point.ui \ gui/rules.ui \ gui/script.ui \ gui/sigmod.ui \ @@ -307,6 +314,4 @@ FORMS += gui/ability.ui \ gui/type.ui \ gui/weather.ui -RESOURCES += overlays/overlays.qrc - include(../headers.pri) diff --git a/sigscript/CMakeLists.txt b/sigscript/CMakeLists.txt index bbfcd8b4..32185aa8 100644 --- a/sigscript/CMakeLists.txt +++ b/sigscript/CMakeLists.txt @@ -17,6 +17,7 @@ SET(sigscript_HEADERS ItemTypeWrapper.h MapWrapper.h MapEffectWrapper.h + MapTileWrapper.h MapTrainerWrapper.h MapTrainerTeamMemberWrapper.h MapWarpWrapper.h @@ -55,6 +56,7 @@ SET(sigscript_SRCS ItemTypeWrapper.cpp MapWrapper.cpp MapEffectWrapper.cpp + MapTileWrapper.cpp MapTrainerWrapper.cpp MapTrainerTeamMemberWrapper.cpp MapWarpWrapper.cpp diff --git a/sigscript/Config.cpp b/sigscript/Config.cpp index 0340d741..3c88728b 100644 --- a/sigscript/Config.cpp +++ b/sigscript/Config.cpp @@ -19,7 +19,8 @@ #include "Config.h" Sigscript::Config::Config(QObject* parent) : - QObject(parent) + QObject(parent), + m_lock(QReadWriteLock::Recursive) { } @@ -34,6 +35,7 @@ void Sigscript::Config::addValue(const QString& name, const QVariant& value, con void Sigscript::Config::setValue(const QString& name, const QVariant& value, const Options options) { + QWriteLocker locker(&m_lock); QVariant oldValue = m_values[name].first; m_values[name] = Value(value, options); emit(valueChanged(name, oldValue, value)); @@ -41,6 +43,7 @@ void Sigscript::Config::setValue(const QString& name, const QVariant& value, con void Sigscript::Config::setOptions(const QString& name, const Options options) { + QWriteLocker locker(&m_lock); const Options oldOptions = m_values[name].second; m_values[name].second |= options; emit(optionsChanged(name, oldOptions, options)); @@ -48,6 +51,7 @@ void Sigscript::Config::setOptions(const QString& name, const Options options) void Sigscript::Config::unsetOptions(const QString& name, const Options options) { + QWriteLocker locker(&m_lock); const Options oldOptions = m_values[name].second; m_values[name].second |= ~options; emit(optionsChanged(name, oldOptions, options)); @@ -55,6 +59,7 @@ void Sigscript::Config::unsetOptions(const QString& name, const Options options) void Sigscript::Config::removeValue(const QString& name, const bool shadow) { + QWriteLocker locker(&m_lock); if (shadow) m_values[name].second |= Deleted; else @@ -64,6 +69,7 @@ void Sigscript::Config::removeValue(const QString& name, const bool shadow) QVariant Sigscript::Config::value(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (m_values.contains(name)) { if (m_values[name].second & (Deleted | Hidden)) @@ -85,6 +91,7 @@ QVariant Sigscript::Config::value(const QString& name, const bool recursive) con bool Sigscript::Config::hasValue(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (m_values.contains(name)) return !(m_values[name].second & (Deleted | Hidden)); if (recursive && qobject_cast<Config*>(parent())) @@ -94,6 +101,7 @@ bool Sigscript::Config::hasValue(const QString& name, const bool recursive) cons void Sigscript::Config::clean() { + QWriteLocker locker(&m_lock); for (QMutableMapIterator<QString, Value> i(m_values); i.hasNext(); i.next()) { if (i.value().second & Temporary) @@ -107,4 +115,5 @@ void Sigscript::Config::clean() void Sigscript::Config::writeBack() { + QWriteLocker locker(&m_lock); } diff --git a/sigscript/Config.h b/sigscript/Config.h index 3ca15f84..309220c2 100644 --- a/sigscript/Config.h +++ b/sigscript/Config.h @@ -25,6 +25,7 @@ #include <QtCore/QMap> #include <QtCore/QObject> #include <QtCore/QPair> +#include <QtCore/QReadWriteLock> #include <QtCore/QString> #include <QtCore/QStringList> #include <QtCore/QVariant> @@ -76,11 +77,13 @@ class SIGSCRIPT_EXPORT Config : public QObject virtual void writeBack(); private: + mutable QReadWriteLock m_lock; QMap<QString, Value> m_values; }; template<typename T> T Config::valueOfType(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (hasValueOfType<T>(name)) return m_values[name].first.value<T>(); if (recursive) @@ -98,6 +101,7 @@ template<typename T> T Config::valueOfType(const QString& name, const bool recur template<typename T> bool Config::hasValueOfType(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (hasValue(name) && m_values[name].first.canConvert<T>()) return true; if (recursive && qobject_cast<Config*>(parent())) diff --git a/sigscript/MapTileWrapper.cpp b/sigscript/MapTileWrapper.cpp new file mode 100644 index 00000000..2ca2abbe --- /dev/null +++ b/sigscript/MapTileWrapper.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapTileWrapper.h" + +// Sigscript includes +#include "MapWrapper.h" +#include "SigmodWrapper.h" + +Sigscript::MapTileWrapper* Sigscript::MapTileWrapper::create(const Sigmod::MapTile* tile, MapWrapper* parent) +{ + Signature sig = Signature(parent, Subsignature(tile->className(), tile->id())); + if (!m_instances.contains(sig)) + m_instances[sig] = new MapTileWrapper(tile, parent); + return qobject_cast<MapTileWrapper*>(m_instances[sig]); +} + +Sigscript::MapTileWrapper::MapTileWrapper(const Sigmod::MapTile* tile, MapWrapper* parent) : + ObjectWrapper(tile, parent), + m_tile(tile) +{ +} + +Sigscript::TileWrapper* Sigscript::MapTileWrapper::tile() +{ + return sigmod()->tile(m_tile->tile()); +} + +QPoint Sigscript::MapTileWrapper::position() const +{ + if (sigmod()->singlePlayer() && hasValueOfType<QPoint>("position")) + return valueOfType<QPoint>("position"); + return m_tile->position(); +} + +int Sigscript::MapTileWrapper::zIndex() const +{ + if (sigmod()->singlePlayer() && hasValueOfType<int>("zIndex")) + return valueOfType<int>("zIndex"); + return m_tile->zIndex(); +} diff --git a/sigscript/MapTileWrapper.h b/sigscript/MapTileWrapper.h new file mode 100644 index 00000000..26dbcf09 --- /dev/null +++ b/sigscript/MapTileWrapper.h @@ -0,0 +1,52 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGSCRIPT_MAPTILEWRAPPER +#define SIGSCRIPT_MAPTILEWRAPPER + +// Sigscript includes +#include "ObjectWrapper.h" + +// Sigmod includes +#include "../sigmod/MapTile.h" + +namespace Sigscript +{ +// Forward declarations +class MapWrapper; +class TileWrapper; + +class SIGSCRIPT_EXPORT MapTileWrapper : public ObjectWrapper +{ + Q_OBJECT + + public: + static MapTileWrapper* create(const Sigmod::MapTile* tile, MapWrapper* parent); + + Q_SCRIPTABLE TileWrapper* tile(); + Q_SCRIPTABLE QPoint position() const; + Q_SCRIPTABLE int zIndex() const; + private: + MapTileWrapper(const Sigmod::MapTile* tile, MapWrapper* parent); + MapTileWrapper& operator=(const MapTileWrapper& rhs); + + const Sigmod::MapTile* m_tile; +}; +} +Q_DECLARE_METATYPE(Sigscript::MapTileWrapper*) + +#endif diff --git a/sigscript/MapWarpWrapper.cpp b/sigscript/MapWarpWrapper.cpp index dfa581c6..4af106a9 100644 --- a/sigscript/MapWarpWrapper.cpp +++ b/sigscript/MapWarpWrapper.cpp @@ -54,11 +54,11 @@ QString Sigscript::MapWarpWrapper::name() const return m_warp->name(); } -QPoint Sigscript::MapWarpWrapper::coordinate() const +QRect Sigscript::MapWarpWrapper::area() const { - if (sigmod()->singlePlayer() && hasValueOfType<QPoint>("coordinate")) - return valueOfType<QPoint>("coordinate"); - return m_warp->coordinate(); + if (sigmod()->singlePlayer() && hasValueOfType<QRect>("area")) + return valueOfType<QRect>("area"); + return m_warp->area(); } Sigmod::MapWarp::Type Sigscript::MapWarpWrapper::type() const diff --git a/sigscript/MapWarpWrapper.h b/sigscript/MapWarpWrapper.h index f1c3f9e9..14c5cb81 100644 --- a/sigscript/MapWarpWrapper.h +++ b/sigscript/MapWarpWrapper.h @@ -39,7 +39,7 @@ class SIGSCRIPT_EXPORT MapWarpWrapper : public ObjectWrapper Q_SCRIPTABLE Sigmod::MapWarp::Type type(const QString& name) const; Q_SCRIPTABLE QString name() const; - Q_SCRIPTABLE QPoint coordinate() const; + Q_SCRIPTABLE QRect area() const; Q_SCRIPTABLE Sigmod::MapWarp::Type type() const; Q_SCRIPTABLE MapWarpWrapper* toWarp(); Q_SCRIPTABLE Sigcore::Script script() const; diff --git a/sigscript/MapWrapper.cpp b/sigscript/MapWrapper.cpp index 09167f68..30e2a6d3 100644 --- a/sigscript/MapWrapper.cpp +++ b/sigscript/MapWrapper.cpp @@ -20,6 +20,7 @@ // Sigscript includes #include "MapEffectWrapper.h" +#include "MapTileWrapper.h" #include "MapTrainerWrapper.h" #include "MapWarpWrapper.h" #include "MapWildListWrapper.h" @@ -44,6 +45,11 @@ Sigscript::MapEffectWrapper* Sigscript::MapWrapper::effect(const int id) return MapEffectWrapper::create(m_map->effectById(id), this); } +Sigscript::MapTileWrapper* Sigscript::MapWrapper::tile(const int id) +{ + return MapTileWrapper::create(m_map->tileById(id), this); +} + Sigscript::MapTrainerWrapper* Sigscript::MapWrapper::trainer(const int id) { return MapTrainerWrapper::create(m_map->trainerById(id), this); @@ -85,9 +91,14 @@ Sigmod::Map::Type Sigscript::MapWrapper::type() const return m_map->type(); } -Sigscript::TileWrapper* Sigscript::MapWrapper::tile(const int row, const int column) +int Sigscript::MapWrapper::width() const { - return sigmod()->tile(m_map->tile(row, column)); + return m_map->width(); +} + +int Sigscript::MapWrapper::height() const +{ + return m_map->height(); } Sigscript::MapEffectWrapper* Sigscript::MapWrapper::effect(const QString& name) @@ -100,6 +111,14 @@ Sigscript::MapEffectWrapper* Sigscript::MapWrapper::effect(const QString& name) return NULL; } +QList<Sigscript::MapTileWrapper*> Sigscript::MapWrapper::tiles() +{ + QList<MapTileWrapper*> tiles; + for (int i = 0; i < m_map->tileCount(); ++i) + tiles.append(MapTileWrapper::create(m_map->tile(i), this)); + return tiles; +} + Sigscript::MapTrainerWrapper* Sigscript::MapWrapper::trainer(const QString& name) { for (int i = 0; i < m_map->trainerCount(); ++i) diff --git a/sigscript/MapWrapper.h b/sigscript/MapWrapper.h index 029109cc..b6cdaae5 100644 --- a/sigscript/MapWrapper.h +++ b/sigscript/MapWrapper.h @@ -28,6 +28,7 @@ namespace Sigscript { // Forward declarations class MapEffectWrapper; +class MapTileWrapper; class MapTrainerWrapper; class MapWarpWrapper; class MapWildListWrapper; @@ -41,6 +42,7 @@ class SIGSCRIPT_EXPORT MapWrapper : public ObjectWrapper static MapWrapper* create(const Sigmod::Map* map, SigmodWrapper* parent); MapEffectWrapper* effect(const int id); + MapTileWrapper* tile(const int id); MapTrainerWrapper* trainer(const int id); MapWarpWrapper* warp(const int id); MapWildListWrapper* wildList(const int id); @@ -50,9 +52,11 @@ class SIGSCRIPT_EXPORT MapWrapper : public ObjectWrapper Q_SCRIPTABLE QString name() const; Q_SCRIPTABLE MapWarpWrapper* flyWarp(); Q_SCRIPTABLE Sigmod::Map::Type type() const; - Q_SCRIPTABLE TileWrapper* tile(const int row, const int column); + Q_SCRIPTABLE int width() const; + Q_SCRIPTABLE int height() const; Q_SCRIPTABLE MapEffectWrapper* effect(const QString& name); + Q_SCRIPTABLE QList<MapTileWrapper*> tiles(); Q_SCRIPTABLE MapTrainerWrapper* trainer(const QString& name); Q_SCRIPTABLE MapWarpWrapper* warp(const QString& name); Q_SCRIPTABLE MapWildListWrapper* wildList(const QString& name); diff --git a/sigscript/TileWrapper.cpp b/sigscript/TileWrapper.cpp index 37c10601..720824fa 100644 --- a/sigscript/TileWrapper.cpp +++ b/sigscript/TileWrapper.cpp @@ -20,7 +20,6 @@ // Sigscript includes #include "SigmodWrapper.h" -#include "SpriteWrapper.h" Sigscript::TileWrapper* Sigscript::TileWrapper::create(const Sigmod::Tile* tile, SigmodWrapper* parent) { @@ -41,24 +40,6 @@ QString Sigscript::TileWrapper::name() const return m_tile->name(); } -Sigscript::SpriteWrapper* Sigscript::TileWrapper::sprite() -{ - if (sigmod()->singlePlayer() && hasValueOfType<QString>("sprite")) - { - SpriteWrapper* sprite = sigmod()->sprite(valueOfType<QString>("sprite")); - if (sprite && sprite->sprite().size() == QSize(64, 64)) - return sprite; - } - return sigmod()->sprite(m_tile->sprite()); -} - -bool Sigscript::TileWrapper::from(const Sigmod::Direction direction) const -{ - if (sigmod()->singlePlayer() && hasValueOfType<bool>(QString("direction-%1").arg(direction))) - return valueOfType<bool>(QString("direction-%1").arg(direction)); - return m_tile->from(direction); -} - Sigcore::Script Sigscript::TileWrapper::script() const { return m_tile->script(); diff --git a/sigscript/TileWrapper.h b/sigscript/TileWrapper.h index 26d03957..ef082ce8 100644 --- a/sigscript/TileWrapper.h +++ b/sigscript/TileWrapper.h @@ -26,9 +26,6 @@ namespace Sigscript { -// Forward declarations -class SpriteWrapper; - class SIGSCRIPT_EXPORT TileWrapper : public ObjectWrapper { Q_OBJECT @@ -37,8 +34,6 @@ class SIGSCRIPT_EXPORT TileWrapper : public ObjectWrapper static TileWrapper* create(const Sigmod::Tile* tile, SigmodWrapper* parent); Q_SCRIPTABLE QString name() const; - Q_SCRIPTABLE SpriteWrapper* sprite(); - Q_SCRIPTABLE bool from(const Sigmod::Direction direction) const; Q_SCRIPTABLE Sigcore::Script script() const; private: TileWrapper(const Sigmod::Tile* tile, SigmodWrapper* parent); |