diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-27 00:47:02 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-27 00:47:02 +0000 |
| commit | 00fecef0aebaa379dfc176ddc5d6488fae0e8272 (patch) | |
| tree | 2b77cc9c4a31f012bcddbf1fe8efa3f3ca1f6139 | |
| parent | c4a3724a2b981e8dbc20f5d319a80bf364f2c7b7 (diff) | |
| download | sigen-00fecef0aebaa379dfc176ddc5d6488fae0e8272.tar.gz sigen-00fecef0aebaa379dfc176ddc5d6488fae0e8272.tar.xz sigen-00fecef0aebaa379dfc176ddc5d6488fae0e8272.zip | |
[FIX] Status and Weather classes in pokemod instead of hardcoded
[FIX] Added a Sprite class to allow for animations and whatnot
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@178 6ecfd1a5-f3ed-3746-8530-beee90d26b22
46 files changed, 2216 insertions, 300 deletions
@@ -1,9 +1,18 @@ ----------------- +Rev: 178 +Date: 26 May 2008 +User: MathStuf +----------------- +[FIX] Status and Weather classes in pokemod instead of hardcoded +[FIX] Added a Sprite class to allow for animations and whatnot + +----------------- Rev: 177 Date: 26 May 2008 User: MathStuf ----------------- [FIX] GroupModels will now add an item to itself if pasted to +[FIX] Actions are now correctly done ----------------- Rev: 176 diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp index dc07ce48..1afbf2f7 100644 --- a/pokemod/Ability.cpp +++ b/pokemod/Ability.cpp @@ -20,7 +20,6 @@ // Pokemod includes #include "Pokemod.h" -#include "Script.h" Ability::Ability(const Ability& ability) : Object("Ability", ability.parent(), ability.id()) diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index 8e76362c..d238807d 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -21,7 +21,6 @@ // Pokemod includes #include "CoinListObject.h" #include "Pokemod.h" -#include "Script.h" // Qt includes #include <QSet> diff --git a/pokemod/GlobalScript.cpp b/pokemod/GlobalScript.cpp index 770ea269..a49ac4ae 100644 --- a/pokemod/GlobalScript.cpp +++ b/pokemod/GlobalScript.cpp @@ -20,7 +20,6 @@ // Pokemod includes #include "Pokemod.h" -#include "Script.h" GlobalScript::GlobalScript(const GlobalScript& globalScript) : Object("GlobalScript", globalScript.parent(), globalScript.id()) diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 895366e1..6a76b081 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -33,11 +33,14 @@ #include "Rules.h" #include "Sound.h" #include "Species.h" +#include "Sprite.h" +#include "Status.h" #include "Store.h" #include "Tile.h" #include "Time.h" #include "Trainer.h" #include "Type.h" +#include "Weather.h" // Qt includes #include <QBuffer> @@ -45,12 +48,8 @@ const QStringList Pokemod::StatRBYStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special" << "Special" << "Accuracy" << "Evasion"; const QStringList Pokemod::StatGSCStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special Attack" << "Special Defense" << "Accuracy" << "Evasion"; -const QStringList Pokemod::BattleMemberStr = QStringList() << "Player" << "Enemy"; -const QStringList Pokemod::WeatherStr = QStringList() << "Ice" << "Rain" << "Sun" << "Sand" << "All"; const QStringList Pokemod::DirectionStr = QStringList() << "Up" << "Down" << "Left" << "Right" << "None"; const QStringList Pokemod::RelativeStr = QStringList() << "Less" << "Less or Equal" << "Greater or Equal" << "Greater" << "Equal" << "Not Equal"; -const QStringList Pokemod::StatusStr = QStringList() << "Freeze" << "Paralyze" << "Sleep" << "Poison" << "Toxic Poison" << "Burn" << "Any"; -const QStringList Pokemod::HMStr = QStringList() << "Cut" << "Fly" << "Surf" << "Strength" << "Flash" << "Whirlpool" << "Waterfall" << "Dive" << "Headbutt" << "Rock Smash" << "Defog" << "Rock Climb" << "Heal" << "Escape"; Pokemod::Pokemod() : Object("Pokemod", NULL, 0), @@ -302,6 +301,20 @@ void Pokemod::validate() } idChecker.clear(); nameChecker.clear(); + if (!statusCount()) + emit(error("There are no status effects")); + foreach (Status* status, m_status) + { + status->validate(); + if (idChecker.contains(status->id())) + emit(error(subclass("status effect", status->id()))); + idChecker.insert(status->id()); + if (nameChecker.contains(status->name())) + emit(error(subclass("status effect", status->name()))); + nameChecker.insert(status->name()); + } + idChecker.clear(); + nameChecker.clear(); if (!storeCount()) emit(warning("There are no stores")); foreach (Store* store, m_stores) @@ -373,6 +386,20 @@ void Pokemod::validate() emit(error(subclass("type", type->name()))); nameChecker.insert(type->name()); } + idChecker.clear(); + nameChecker.clear(); + if (!weatherCount()) + emit(error("There are no weathers")); + foreach (Weather* weather, m_weathers) + { + weather->validate(); + if (idChecker.contains(weather->id())) + emit(error(subclass("weather", weather->id()))); + idChecker.insert(weather->id()); + if (nameChecker.contains(weather->name())) + emit(error(subclass("weather", weather->name()))); + nameChecker.insert(weather->name()); + } } void Pokemod::load(const QDomElement& xml, const int) @@ -403,11 +430,14 @@ void Pokemod::load(const QDomElement& xml, const int) LOAD_SUB(newNature, Nature); LOAD_SUB(newSound, Sound); LOAD_SUB(newSpecies, Species); + LOAD_SUB(newSprite, Sprite); + LOAD_SUB(newStatus, Status); LOAD_SUB(newStore, Store); LOAD_SUB(newTile, Tile); LOAD_SUB(newTime, Time); LOAD_SUB(newTrainer, Trainer); LOAD_SUB(newType, Type); + LOAD_SUB(newWeather, Weather); LOAD_MATRIX(setTypeChart, Fraction, typeChart); } @@ -440,11 +470,14 @@ QDomElement Pokemod::save() const SAVE_SUB(Nature, natures); SAVE_SUB(Sound, sounds); SAVE_SUB(Species, species); + SAVE_SUB(Sprite, sprites); + SAVE_SUB(Status, status); SAVE_SUB(Store, stores); SAVE_SUB(Tile, tiles); SAVE_SUB(Time, times); SAVE_SUB(Trainer, trainers); SAVE_SUB(Type, types); + SAVE_SUB(Weather, weathers); return xml; } @@ -1707,6 +1740,168 @@ int Pokemod::newSpeciesId() const return i; } +const Sprite* Pokemod::sprite(const int index) const +{ + if (spriteCount() <= index) + return NULL; + return m_sprites.at(index); +} + +Sprite* Pokemod::sprite(const int index) +{ + if (spriteCount() <= index) + return NULL; + return m_sprites[index]; +} + +const Sprite* Pokemod::spriteById(const int id) const +{ + return sprite(spriteIndex(id)); +} + +Sprite* Pokemod::spriteById(const int id) +{ + return sprite(spriteIndex(id)); +} + +int Pokemod::spriteIndex(const int id) const +{ + for (int i = 0; i < spriteCount(); ++i) + { + if (m_sprites[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::spriteCount() const +{ + return m_sprites.size(); +} + +Sprite* Pokemod::newSprite() +{ + return newSprite(new Sprite(this, newSpriteId())); +} + +Sprite* Pokemod::newSprite(const QDomElement& xml) +{ + return newSprite(new Sprite(xml, this, newSpriteId())); +} + +Sprite* Pokemod::newSprite(const Sprite& sprite) +{ + return newSprite(new Sprite(sprite, this, newSpriteId())); +} + +Sprite* Pokemod::newSprite(Sprite* sprite) +{ + m_sprites.append(sprite); + return sprite; +} + +void Pokemod::deleteSprite(const int index) +{ + if (spriteCount() <= index) + return; + delete m_sprites[index]; + m_sprites.removeAt(index); +} + +void Pokemod::deleteSpriteById(const int id) +{ + deleteSprite(spriteIndex(id)); +} + +int Pokemod::newSpriteId() const +{ + int i = 0; + while ((i < spriteCount()) && (spriteIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Status* Pokemod::status(const int index) const +{ + if (statusCount() <= index) + return NULL; + return m_status.at(index); +} + +Status* Pokemod::status(const int index) +{ + if (statusCount() <= index) + return NULL; + return m_status[index]; +} + +const Status* Pokemod::statusById(const int id) const +{ + return status(statusIndex(id)); +} + +Status* Pokemod::statusById(const int id) +{ + return status(statusIndex(id)); +} + +int Pokemod::statusIndex(const int id) const +{ + for (int i = 0; i < statusCount(); ++i) + { + if (m_status[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::statusCount() const +{ + return m_status.size(); +} + +Status* Pokemod::newStatus() +{ + return newStatus(new Status(this, newStatusId())); +} + +Status* Pokemod::newStatus(const QDomElement& xml) +{ + return newStatus(new Status(xml, this, newStatusId())); +} + +Status* Pokemod::newStatus(const Status& status) +{ + return newStatus(new Status(status, this, newStatusId())); +} + +Status* Pokemod::newStatus(Status* status) +{ + m_status.append(status); + return status; +} + +void Pokemod::deleteStatus(const int index) +{ + if (statusCount() <= index) + return; + delete m_status[index]; + m_status.removeAt(index); +} + +void Pokemod::deleteStatusById(const int id) +{ + deleteStatus(statusIndex(id)); +} + +int Pokemod::newStatusId() const +{ + int i = 0; + while ((i < statusCount()) && (statusIndex(i) != INT_MAX)) + ++i; + return i; +} + const Store* Pokemod::store(const int index) const { if (storeCount() <= index) @@ -2126,6 +2321,87 @@ int Pokemod::newTypeId() const return i; } +const Weather* Pokemod::weather(const int index) const +{ + if (weatherCount() <= index) + return NULL; + return m_weathers.at(index); +} + +Weather* Pokemod::weather(const int index) +{ + if (weatherCount() <= index) + return NULL; + return m_weathers[index]; +} + +const Weather* Pokemod::weatherById(const int id) const +{ + return weather(weatherIndex(id)); +} + +Weather* Pokemod::weatherById(const int id) +{ + return weather(weatherIndex(id)); +} + +int Pokemod::weatherIndex(const int id) const +{ + for (int i = 0; i < weatherCount(); ++i) + { + if (m_weathers[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::weatherCount() const +{ + return m_weathers.size(); +} + +Weather* Pokemod::newWeather() +{ + return newWeather(new Weather(this, newWeatherId())); +} + +Weather* Pokemod::newWeather(const QDomElement& xml) +{ + return newWeather(new Weather(xml, this, newWeatherId())); +} + +Weather* Pokemod::newWeather(const Weather& weather) +{ + return newWeather(new Weather(weather, this, newWeatherId())); +} + +Weather* Pokemod::newWeather(Weather* weather) +{ + m_weathers.append(weather); + return weather; +} + +void Pokemod::deleteWeather(const int index) +{ + if (weatherCount() <= index) + return; + delete m_weathers[index]; + m_weathers.removeAt(index); +} + +void Pokemod::deleteWeatherById(const int id) +{ + deleteWeather(weatherIndex(id)); +} + +int Pokemod::newWeatherId() const +{ + int i = 0; + while ((i < weatherCount()) && (weatherIndex(i) != INT_MAX)) + ++i; + return i; +} + Pokemod& Pokemod::operator=(const Pokemod& rhs) { if (this == &rhs) @@ -2151,11 +2427,14 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs) COPY_SUB(Nature, natures); COPY_SUB(Sound, sounds); COPY_SUB(Species, species); + COPY_SUB(Sprite, sprites); + COPY_SUB(Status, status); COPY_SUB(Store, stores); COPY_SUB(Tile, tiles); COPY_SUB(Time, times); COPY_SUB(Trainer, trainers); COPY_SUB(Type, types); + COPY_SUB(Weather, weathers); return *this; } @@ -2188,6 +2467,10 @@ void Pokemod::clear() deleteSound(0); while (speciesCount()) deleteSpecies(0); + while (spriteCount()) + deleteSprite(0); + while (statusCount()) + deleteStatus(0); while (storeCount()) deleteStore(0); while (tileCount()) @@ -2198,4 +2481,6 @@ void Pokemod::clear() deleteTrainer(0); while (typeCount()) deleteType(0); + while (weatherCount()) + deleteWeather(0); } diff --git a/pokemod/Pokemod.h b/pokemod/Pokemod.h index 9f4c1d08..e2e2b11b 100644 --- a/pokemod/Pokemod.h +++ b/pokemod/Pokemod.h @@ -45,11 +45,14 @@ class Nature; class Rules; class Sound; class Species; +class Sprite; +class Status; class Store; class Tile; class Time; class Trainer; class Type; +class Weather; class Pokemod : public Object { @@ -74,27 +77,7 @@ class Pokemod : public Object }; static const QStringList StatRBYStr; static const QStringList StatGSCStr; - - enum BattleMember - { - BM_Player = 0, - BM_Enemy = 1, - BM_End = 2 - }; - static const QStringList BattleMemberStr; - - enum Weather - { - W_Ice = 0, - W_Rain = 1, - W_Sun = 2, - W_Sand = 3, - W_End_Real = 4, - W_All = 4, - W_End_All = 5 - }; - static const QStringList WeatherStr; - + enum Direction { D_Up = 0, @@ -106,7 +89,7 @@ class Pokemod : public Object D_End_None = 5 }; static const QStringList DirectionStr; - + enum Relative { REL_Less = 0, @@ -118,40 +101,6 @@ class Pokemod : public Object REL_End = 6 }; static const QStringList RelativeStr; - - enum Status - { - STS_Freeze = 0, - STS_Paralyze = 1, - STS_Sleep = 2, - STS_Poison = 3, - STS_ToxicPoison = 4, - STS_Burn = 5, - STS_Any = 6, - STS_End = 7 - }; - static const QStringList StatusStr; - - enum HMMove - { - HM_Cut = 0, - HM_Fly = 1, - HM_Surf = 2, - HM_Strength = 3, - HM_Whirlpool = 4, - HM_Waterfall = 5, - HM_Dive = 6, - HM_Headbutt = 7, - HM_RockSmash = 8, - HM_RockClimb = 9, - HM_End = 10, - HM_Defog = 10, - HM_Flash = 11, - HM_Heal = 12, - HM_Escape = 13, - HM_End_All = 14 - }; - static const QStringList HMStr; Pokemod(); Pokemod(const Pokemod& pokemod); @@ -351,6 +300,30 @@ class Pokemod : public Object void deleteSpecies(const int index); void deleteSpeciesById(const int id); + const Sprite* sprite(const int index) const; + Sprite* sprite(const int index); + const Sprite* spriteById(const int id) const; + Sprite* spriteById(const int id); + int spriteIndex(const int id) const; + int spriteCount() const; + Sprite* newSprite(); + Sprite* newSprite(const QDomElement& xml); + Sprite* newSprite(const Sprite& sprite); + void deleteSprite(const int index); + void deleteSpriteById(const int id); + + const Status* status(const int index) const; + Status* status(const int index); + const Status* statusById(const int id) const; + Status* statusById(const int id); + int statusIndex(const int id) const; + int statusCount() const; + Status* newStatus(); + Status* newStatus(const QDomElement& xml); + Status* newStatus(const Status& status); + void deleteStatus(const int index); + void deleteStatusById(const int id); + const Store* store(const int index) const; Store* store(const int index); const Store* storeById(const int id) const; @@ -411,6 +384,18 @@ class Pokemod : public Object void deleteType(const int index); void deleteTypeById(const int id); + const Weather* weather(const int index) const; + Weather* weather(const int index); + const Weather* weatherById(const int id) const; + Weather* weatherById(const int id); + int weatherIndex(const int id) const; + int weatherCount() const; + Weather* newWeather(); + Weather* newWeather(const QDomElement& xml); + Weather* newWeather(const Weather& weather); + void deleteWeather(const int index); + void deleteWeatherById(const int id); + Pokemod& operator=(const Pokemod& rhs); private: void validate(); @@ -454,6 +439,12 @@ class Pokemod : public Object int newSpeciesId() const; Species* newSpecies(Species* species); + int newSpriteId() const; + Sprite* newSprite(Sprite* sprite); + + int newStatusId() const; + Status* newStatus(Status* status); + int newStoreId() const; Store* newStore(Store* store); @@ -469,6 +460,9 @@ class Pokemod : public Object int newTypeId() const; Type* newType(Type* type); + int newWeatherId() const; + Weather* newWeather(Weather* weather); + void clear(); QString m_title; @@ -497,11 +491,14 @@ class Pokemod : public Object QList<Nature*> m_natures; QList<Sound*> m_sounds; QList<Species*> m_species; + QList<Sprite*> m_sprites; + QList<Status*> m_status; QList<Store*> m_stores; QList<Tile*> m_tiles; QList<Time*> m_times; QList<Trainer*> m_trainers; QList<Type*> m_types; + QList<Weather*> m_weathers; }; #endif diff --git a/pokemod/Sprite.cpp b/pokemod/Sprite.cpp new file mode 100644 index 00000000..df3c5bd5 --- /dev/null +++ b/pokemod/Sprite.cpp @@ -0,0 +1,105 @@ +/* + * Copyright 2007-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 "Sprite.h" + +// Pokemod includes +#include "Pokemod.h" + +// Qt includes +#include <QBuffer> + +Sprite::Sprite(const Sprite& sprite) : + Object("Sprite", sprite.parent(), sprite.id()) +{ + *this = sprite; +} + +Sprite::Sprite(const Pokemod* parent, const int id) : + Object("Sprite", parent, id), + m_name(""), + m_sprite() +{ +} + +Sprite::Sprite(const Sprite& sprite, const Pokemod* parent, const int id) : + Object("Sprite", parent, id) +{ + *this = sprite; +} + +Sprite::Sprite(const QDomElement& xml, const Pokemod* parent, const int id) : + Object("Sprite", parent, id) +{ + load(xml, id); +} + +Sprite::~Sprite() +{ +} + +void Sprite::validate() +{ + if (m_name.isEmpty()) + emit(error("Name is empty")); +} + +void Sprite::load(const QDomElement& xml, int id) +{ + LOAD_ID(); + LOAD(QString, name); + LOAD(QPixmap, sprite); +} + +QDomElement Sprite::save() const +{ + SAVE_CREATE(); + SAVE(QString, name); + SAVE(QPixmap, sprite); + return xml; +} + +void Sprite::setName(const QString& name) +{ + CHECK(name); +} + +void Sprite::setSprite(const QPixmap& sprite) +{ + m_sprite = sprite; + emit(changed()); +} + +QString Sprite::name() const +{ + return m_name; +} + +QPixmap Sprite::sprite() const +{ + return m_sprite; +} + +Sprite& Sprite::operator=(const Sprite& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(sprite); + return *this; +} diff --git a/pokemod/Sprite.h b/pokemod/Sprite.h new file mode 100644 index 00000000..b5d58100 --- /dev/null +++ b/pokemod/Sprite.h @@ -0,0 +1,58 @@ +/* + * Copyright 2007-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 __POKEMOD_SPRITE__ +#define __POKEMOD_SPRITE__ + +// Pokemod includes +#include "Object.h" + +// Qt includes +#include <QPixmap> + +// Forward declarations +class Pokemod; + +class Sprite : public Object +{ + Q_OBJECT + + public: + Sprite(const Sprite& sprite); + Sprite(const Pokemod* parent, const int id); + Sprite(const Sprite& sprite, const Pokemod* parent, const int id); + Sprite(const QDomElement& xml, const Pokemod* parent, const int id = INT_MAX); + ~Sprite(); + + void validate(); + + void load(const QDomElement& xml, int id = INT_MAX); + QDomElement save() const; + + void setName(const QString& name); + void setSprite(const QPixmap& sprite); + + QString name() const; + QPixmap sprite() const; + + Sprite& operator=(const Sprite& rhs); + private: + QString m_name; + QPixmap m_sprite; +}; + +#endif diff --git a/pokemod/Status.cpp b/pokemod/Status.cpp new file mode 100644 index 00000000..8c9922d2 --- /dev/null +++ b/pokemod/Status.cpp @@ -0,0 +1,102 @@ +/* + * 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 "Status.h" + +// Pokemod includes +#include "Pokemod.h" +#include "Script.h" + +Status::Status(const Status& status) : + Object("Status", status.parent(), status.id()) +{ + *this = status; +} + +Status::Status(const Pokemod* parent, const int id) : + Object("Status", parent, id), + m_name(""), + m_script("", "") +{ +} + +Status::Status(const Status& status, const Pokemod* parent, const int id) : + Object("Status", parent, id) +{ + *this = status; +} + +Status::Status(const QDomElement& xml, const Pokemod* parent, const int id) : + Object("Status", parent, id) +{ + load(xml, id); +} + +Status::~Status() +{ +} + +void Status::validate() +{ + if (m_name.isEmpty()) + emit(error("Name is empty")); +} + +void Status::load(const QDomElement& xml, int id) +{ + LOAD_ID(); + LOAD(QString, name); + LOAD(Script, script); +} + +QDomElement Status::save() const +{ + SAVE_CREATE(); + SAVE(QString, name); + SAVE(Script, script); + return xml; +} + +void Status::setName(const QString& name) +{ + CHECK(name); +} + +void Status::setScript(const Script& script) +{ + CHECK(script); +} + +QString Status::name() const +{ + return m_name; +} + +Script Status::script() const +{ + return m_script; +} + +Status& Status::operator=(const Status& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(script); + return *this; +} diff --git a/pokemod/Status.h b/pokemod/Status.h new file mode 100644 index 00000000..3b8ab7f4 --- /dev/null +++ b/pokemod/Status.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 __POKEMOD_STATUS__ +#define __POKEMOD_STATUS__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +// Forward declarations +class Pokemod; + +class Status : public Object +{ + Q_OBJECT + + public: + Status(const Status& status); + Status(const Pokemod* parent, const int id); + Status(const Status& status, const Pokemod* parent, const int id); + Status(const QDomElement& xml, const Pokemod* parent, const int id = INT_MAX); + ~Status(); + + void validate(); + + void load(const QDomElement& xml, int id = INT_MAX); + QDomElement save() const; + + void setName(const QString& name); + void setScript(const Script& script); + + QString name() const; + Script script() const; + + Status& operator=(const Status& rhs); + private: + QString m_name; + Script m_script; +}; + +#endif diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp index 46363a27..91dd59d6 100644 --- a/pokemod/Tile.cpp +++ b/pokemod/Tile.cpp @@ -37,8 +37,6 @@ Tile::Tile(const Pokemod* parent, const int id) : m_name(""), m_sprite(64, 64), m_wildChance(1, 1), - m_hmType(INT_MAX), - m_under(INT_MAX), m_forceType(INT_MAX), m_forceDirection(INT_MAX) { @@ -64,8 +62,6 @@ void Tile::validate() emit(error("Name is empty")); TEST(setSprite, sprite); TEST(setWildChance, wildChance); - TEST(setHmType, hmType); - TEST(setUnder, under); TEST(setForceType, forceType); TEST(setForceDirection, forceDirection); } @@ -77,8 +73,6 @@ void Tile::load(const QDomElement& xml, int id) LOAD(QPixmap, sprite); LOAD_ARRAY(bool, from, Pokemod::D_End); LOAD(Fraction, wildChance); - LOAD(int, hmType); - LOAD(int, under); LOAD(int, forceType); LOAD(int, forceDirection); } @@ -90,8 +84,6 @@ QDomElement Tile::save() const SAVE(QPixmap, sprite); SAVE_ARRAY(bool, from, Pokemod::D_End); SAVE(Fraction, wildChance); - SAVE(int, hmType); - SAVE(int, under); SAVE(int, forceType); SAVE(int, forceDirection); return xml; @@ -133,39 +125,6 @@ void Tile::setWildChance(const Fraction& wildChance) CHECK(wildChance); } -void Tile::setHmType(const int hmType) -{ - if (Pokemod::HM_End <= hmType) - { - emit(error(bounds("hmType"))); - return; - } - if (((hmType == Pokemod::HM_Waterfall) || (hmType == Pokemod::HM_RockClimb)) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) - { - emit(error("Accessibility for HM type")); - return; - } - CHECK(hmType); -} - -void Tile::setUnder(const int under) -{ - if (m_hmType != INT_MAX) - { - if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash)) - { - emit(warning(unused("under"))); - return; - } - if ((under == id()) || (static_cast<const Pokemod*>(pokemod())->tileIndex(under) == INT_MAX)) - { - emit(error(bounds("under"))); - return; - } - } - CHECK(under); -} - void Tile::setForceType(const int forceType) { if (End <= forceType) @@ -219,16 +178,6 @@ Fraction Tile::wildChance() const return m_wildChance; } -int Tile::hmType() const -{ - return m_hmType; -} - -int Tile::under() const -{ - return m_under; -} - int Tile::forceType() const { return m_forceType; @@ -246,8 +195,6 @@ Tile& Tile::operator=(const Tile& rhs) COPY(name); COPY_ARRAY(from, Pokemod::D_End); COPY(wildChance); - COPY(hmType); - COPY(under); COPY(forceType); COPY(forceDirection); return *this; diff --git a/pokemod/Tile.h b/pokemod/Tile.h index 12efe6f5..120e0fd3 100644 --- a/pokemod/Tile.h +++ b/pokemod/Tile.h @@ -55,8 +55,6 @@ class Tile : public Object void setSprite(const QPixmap& sprite); void setFrom(const int direction, const bool state); void setWildChance(const Fraction& wildChance); - void setHmType(const int hmType); - void setUnder(const int under); void setForceType(const int forceType); void setForceDirection(const int forceDirection); @@ -64,8 +62,6 @@ class Tile : public Object QPixmap sprite() const; bool from(const int direction) const; Fraction wildChance() const; - int hmType() const; - int under() const; int forceType() const; int forceDirection() const; @@ -75,8 +71,6 @@ class Tile : public Object QPixmap m_sprite; bool m_from[Pokemod::D_End]; Fraction m_wildChance; - int m_hmType; - int m_under; int m_forceType; int m_forceDirection; }; diff --git a/pokemod/Type.cpp b/pokemod/Type.cpp index 54c7350c..24ff76e8 100644 --- a/pokemod/Type.cpp +++ b/pokemod/Type.cpp @@ -32,10 +32,6 @@ Type::Type(const Pokemod* parent, const int id) : m_name(""), m_stab(1, 1) { - for (int i = 0; i < Pokemod::STS_End; ++i) - m_statusImmunity[i] = false; - for (int i = 0; i < Pokemod::W_End_All; ++i) - m_weatherImmunity[i] = false; } Type::Type(const Type& type, const Pokemod* parent, const int id) : @@ -61,8 +57,6 @@ void Type::load(const QDomElement& xml, int id) LOAD_ID(); LOAD(QString, name); LOAD(Fraction, stab); - LOAD_ARRAY(bool, statusImmunity, Pokemod::STS_End); - LOAD_ARRAY(bool, weatherImmunity, Pokemod::W_End_Real); } QDomElement Type::save() const @@ -70,8 +64,6 @@ QDomElement Type::save() const SAVE_CREATE(); SAVE(QString, name); SAVE(Fraction, stab); - SAVE_ARRAY(bool, statusImmunity, Pokemod::STS_End); - SAVE_ARRAY(bool, weatherImmunity, Pokemod::W_End_Real); return xml; } @@ -90,26 +82,6 @@ void Type::setStab(const Fraction& stab) CHECK(stab); } -void Type::setStatusImmunity(const int status, const bool immune) -{ - if (Pokemod::STS_End <= status) - { - emit(error(bounds("statusImmunity"))); - return; - } - CHECK_ARRAY(statusImmunity[status], immune); -} - -void Type::setWeatherImmunity(const int weather, const bool immune) -{ - if (Pokemod::W_End_Real <= weather) - { - emit(error(bounds("weatherImmunity"))); - return; - } - CHECK_ARRAY(weatherImmunity[weather], immune); -} - QString Type::name() const { return m_name; @@ -120,33 +92,11 @@ Fraction Type::stab() const return m_stab; } -bool Type::statusImmunity(const int status) const -{ - if (Pokemod::STS_End <= status) - { - emit(warning(bounds("statusImmunity"))); - return false; - } - return m_statusImmunity[status]; -} - -bool Type::weatherImmunity(const int weather) const -{ - if (Pokemod::W_End_Real <= weather) - { - emit(warning(bounds("weatherImmunity"))); - return false; - } - return m_weatherImmunity[weather]; -} - Type& Type::operator=(const Type& rhs) { if (this == &rhs) return *this; COPY(name); COPY(stab); - COPY_ARRAY(statusImmunity, Pokemod::STS_End); - COPY_ARRAY(weatherImmunity, Pokemod::W_End_Real); return *this; } diff --git a/pokemod/Type.h b/pokemod/Type.h index 06a7cdaf..6c9a0cdf 100644 --- a/pokemod/Type.h +++ b/pokemod/Type.h @@ -21,7 +21,6 @@ // Pokemod includes #include "Fraction.h" #include "Object.h" -#include "Pokemod.h" // Forward declarations class Pokemod; @@ -43,20 +42,14 @@ class Type : public Object void setName(const QString& name); void setStab(const Fraction& stab); - void setStatusImmunity(const int status, const bool immune); - void setWeatherImmunity(const int weather, const bool immune); QString name() const; Fraction stab() const; - bool statusImmunity(const int status) const; - bool weatherImmunity(const int weather) const; Type& operator=(const Type& rhs); private: QString m_name; Fraction m_stab; - bool m_statusImmunity[Pokemod::STS_End]; - bool m_weatherImmunity[Pokemod::W_End_All]; }; #endif diff --git a/pokemod/Weather.cpp b/pokemod/Weather.cpp new file mode 100644 index 00000000..59ff9135 --- /dev/null +++ b/pokemod/Weather.cpp @@ -0,0 +1,102 @@ +/* + * 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 "Weather.h" + +// Pokemod includes +#include "Pokemod.h" +#include "Script.h" + +Weather::Weather(const Weather& weather) : + Object("Weather", weather.parent(), weather.id()) +{ + *this = weather; +} + +Weather::Weather(const Pokemod* parent, const int id) : + Object("Weather", parent, id), + m_name(""), + m_script("", "") +{ +} + +Weather::Weather(const Weather& weather, const Pokemod* parent, const int id) : + Object("Weather", parent, id) +{ + *this = weather; +} + +Weather::Weather(const QDomElement& xml, const Pokemod* parent, const int id) : + Object("Weather", parent, id) +{ + load(xml, id); +} + +Weather::~Weather() +{ +} + +void Weather::validate() +{ + if (m_name.isEmpty()) + emit(error("Name is empty")); +} + +void Weather::load(const QDomElement& xml, int id) +{ + LOAD_ID(); + LOAD(QString, name); + LOAD(Script, script); +} + +QDomElement Weather::save() const +{ + SAVE_CREATE(); + SAVE(QString, name); + SAVE(Script, script); + return xml; +} + +void Weather::setName(const QString& name) +{ + CHECK(name); +} + +void Weather::setScript(const Script& script) +{ + CHECK(script); +} + +QString Weather::name() const +{ + return m_name; +} + +Script Weather::script() const +{ + return m_script; +} + +Weather& Weather::operator=(const Weather& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(script); + return *this; +} diff --git a/pokemod/Weather.h b/pokemod/Weather.h new file mode 100644 index 00000000..da727344 --- /dev/null +++ b/pokemod/Weather.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 __POKEMOD_WEATHER__ +#define __POKEMOD_WEATHER__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +// Forward declarations +class Pokemod; + +class Weather : public Object +{ + Q_OBJECT + + public: + Weather(const Weather& weather); + Weather(const Pokemod* parent, const int id); + Weather(const Weather& weather, const Pokemod* parent, const int id); + Weather(const QDomElement& xml, const Pokemod* parent, const int id = INT_MAX); + ~Weather(); + + void validate(); + + void load(const QDomElement& xml, int id = INT_MAX); + QDomElement save() const; + + void setName(const QString& name); + void setScript(const Script& script); + + QString name() const; + Script script() const; + + Weather& operator=(const Weather& rhs); + private: + QString m_name; + Script m_script; +}; + +#endif diff --git a/pokemod/pokemod.pro b/pokemod/pokemod.pro index 56e54ce7..cd95027f 100644 --- a/pokemod/pokemod.pro +++ b/pokemod/pokemod.pro @@ -40,11 +40,14 @@ SOURCES += Ability.cpp \ SpeciesAbility.cpp \ SpeciesItem.cpp \ SpeciesMove.cpp \ + Sprite.cpp \ + Status.cpp \ Store.cpp \ Tile.cpp \ Time.cpp \ Trainer.cpp \ - Type.cpp + Type.cpp \ + Weather.cpp HEADERS += Ability.h \ Author.h \ @@ -77,11 +80,14 @@ HEADERS += Ability.h \ SpeciesAbility.h \ SpeciesItem.h \ SpeciesMove.h \ + Sprite.h \ + Status.h \ Store.h \ Tile.h \ Time.h \ Trainer.h \ - Type.h + Type.h \ + Weather.h isEmpty(PREFIX) { PREFIX = $$(PREFIX) diff --git a/pokemodr/FileDialog.cpp b/pokemodr/FileDialog.cpp index 6b7bb103..f14f3a2a 100644 --- a/pokemodr/FileDialog.cpp +++ b/pokemodr/FileDialog.cpp @@ -35,7 +35,7 @@ FileDialog::FileDialog(const QSize& size) : setOperationMode(KFileDialog::Opening); if (m_size.isValid()) { - setPreviewWidget(new KImageFilePreview()); + setPreviewWidget(new KImageFilePreview); // FIXME: KDirOperator is failing here on linking :( // connect(findChild<KDirOperator*>(), SIGNAL(dirActivated(const KFileItem&)), this, SLOT(sizeFilter(const FileItem&))); } diff --git a/pokemodr/SpriteUI.cpp b/pokemodr/SpriteUI.cpp new file mode 100644 index 00000000..5175a80f --- /dev/null +++ b/pokemodr/SpriteUI.cpp @@ -0,0 +1,77 @@ +/* + * 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 "SpriteUI.h" + +// Pokemod includes +#include "../pokemod/Pokemod.h" +#include "../pokemod/Sprite.h" + +// KDE includes +#include <KFileDialog> +#include <KImageFilePreview> + +SpriteUI::SpriteUI(Sprite* sprite, QWidget* parent) : + ObjectUI(parent) +{ + setupUi(this); + setObjects(sprite, new Sprite(*sprite)); +} + +SpriteUI::~SpriteUI() +{ +} + +void SpriteUI::setGui() +{ + varName->setText(static_cast<Sprite*>(modified())->name()); + varSprite->setIcon(static_cast<Sprite*>(modified())->sprite()); +} + +void SpriteUI::apply() +{ + *static_cast<Sprite*>(original()) = *static_cast<Sprite*>(modified()); + emit(changed(false)); +} + +void SpriteUI::discard() +{ + *static_cast<Sprite*>(modified()) = *static_cast<Sprite*>(original()); + setGui(); + emit(changed(false)); +} + +void SpriteUI::on_varName_textChanged(const QString& name) +{ + const int cursor = varName->cursorPosition(); + static_cast<Sprite*>(modified())->setName(name); + varName->setCursorPosition(cursor); +} + +void SpriteUI::on_varSprite_pressed() +{ + KFileDialog* dialog = new KFileDialog(KUrl("kfiledialog:///image"), "*.jpg *.jpeg *.png|Image files", NULL); + dialog->setOperationMode(KFileDialog::Opening); + dialog->setPreviewWidget(new KImageFilePreview); + if (dialog->exec() == QDialog::Accepted) + { + static_cast<Sprite*>(modified())->setSprite(QPixmap(dialog->selectedFile())); + setGui(); + } + delete dialog; +} diff --git a/pokemodr/SpriteUI.h b/pokemodr/SpriteUI.h new file mode 100644 index 00000000..8dda7ce0 --- /dev/null +++ b/pokemodr/SpriteUI.h @@ -0,0 +1,47 @@ +/* + * 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 __POKEMODR_SPRITEUI__ +#define __POKEMODR_SPRITEUI__ + +// PokeModr includes +#include "ObjectUI.h" + +// Form include +#include "ui_sprite.h" + +// Forward declarations +class Sprite; + +class SpriteUI : public ObjectUI, private Ui::formSprite +{ + Q_OBJECT + + public: + SpriteUI(Sprite* sprite, QWidget* parent); + ~SpriteUI(); + public slots: + void apply(); + void discard(); + protected slots: + void on_varName_textChanged(const QString& name); + void on_varSprite_pressed(); + private slots: + void setGui(); +}; + +#endif diff --git a/pokemodr/StatusUI.cpp b/pokemodr/StatusUI.cpp new file mode 100644 index 00000000..2806c294 --- /dev/null +++ b/pokemodr/StatusUI.cpp @@ -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/>. + */ + +// Header include +#include "StatusUI.h" + +// Pokemod includes +#include "../pokemod/Status.h" + +StatusUI::StatusUI(Status* status, QWidget* parent) : + ObjectUI(parent) +{ + setupUi(this); + setObjects(status, new Status(*status)); +} + +StatusUI::~StatusUI() +{ +} + +void StatusUI::setGui() +{ + varName->setText(static_cast<Status*>(modified())->name()); + varScript->setValue(static_cast<Status*>(modified())->script()); +} + +void StatusUI::apply() +{ + *static_cast<Status*>(original()) = *static_cast<Status*>(modified()); + emit(changed(false)); +} + +void StatusUI::discard() +{ + *static_cast<Status*>(modified()) = *static_cast<Status*>(original()); + setGui(); + emit(changed(false)); +} + +void StatusUI::on_varName_textChanged(const QString& name) +{ + const int cursor = varName->cursorPosition(); + static_cast<Status*>(modified())->setName(name); + varName->setCursorPosition(cursor); +} + +void StatusUI::on_varScript_valueChanged(const Script& script) +{ + static_cast<Status*>(modified())->setScript(script); +} diff --git a/pokemodr/StatusUI.h b/pokemodr/StatusUI.h new file mode 100644 index 00000000..dac6aaf9 --- /dev/null +++ b/pokemodr/StatusUI.h @@ -0,0 +1,47 @@ +/* + * 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 __POKEMODR_STATUSUI__ +#define __POKEMODR_STATUSUI__ + +// PokeModr includes +#include "ObjectUI.h" + +// Form include +#include "ui_status.h" + +// Forward declarations +class Status; + +class StatusUI : public ObjectUI, private Ui::formStatus +{ + Q_OBJECT + + public: + StatusUI(Status* status, QWidget* parent); + ~StatusUI(); + public slots: + void apply(); + void discard(); + protected slots: + void on_varName_textChanged(const QString& name); + void on_varScript_valueChanged(const Script& script); + private slots: + void setGui(); +}; + +#endif diff --git a/pokemodr/TileUI.cpp b/pokemodr/TileUI.cpp index 8dd1036f..302564c2 100644 --- a/pokemodr/TileUI.cpp +++ b/pokemodr/TileUI.cpp @@ -39,22 +39,10 @@ TileUI::~TileUI() void TileUI::initGui() { varAccessibility->addItems(Pokemod::DirectionStr.mid(0, Pokemod::D_End)); - varHMType->addItems(Pokemod::HMStr); varForce->addItems(Tile::ForceStr); varDirection->addItems(Pokemod::DirectionStr.mid(0, Pokemod::D_End)); } -void TileUI::refreshGui() -{ - varHMUnder->clear(); - for (int i = 0; i < pokemod()->tileCount(); ++i) - { - const Tile* tile = pokemod()->tile(i); - if (tile->id() != static_cast<Tile*>(original())->id()) - varHMUnder->addItem(tile->sprite(), tile->name(), tile->id()); - } -} - void TileUI::setGui() { varName->setText(static_cast<Tile*>(modified())->name()); @@ -62,10 +50,6 @@ void TileUI::setGui() for (int i = 0; i < varAccessibility->count(); ++i) varAccessibility->item(i)->setSelected(static_cast<Tile*>(modified())->from(i)); varWildChance->setValue(static_cast<Tile*>(modified())->wildChance()); - boxHMs->setChecked((static_cast<Tile*>(modified())->hmType() == INT_MAX) ? Qt::Unchecked : Qt::Checked); - varHMType->setCurrentIndex(static_cast<Tile*>(modified())->hmType()); - varHMUnder->setCurrentIndex(varHMUnder->findData(static_cast<Tile*>(modified())->under())); - varHMUnder->setEnabled((static_cast<Tile*>(modified())->hmType() == Pokemod::HM_Whirlpool) || (static_cast<Tile*>(modified())->hmType() == Pokemod::HM_Cut) || (static_cast<Tile*>(modified())->hmType() == Pokemod::HM_RockSmash)); boxForces->setChecked((static_cast<Tile*>(modified())->forceType() == INT_MAX) ? Qt::Unchecked : Qt::Checked); varForce->setCurrentIndex(static_cast<Tile*>(modified())->forceType()); varDirection->setCurrentIndex(static_cast<Tile*>(modified())->forceDirection()); @@ -117,27 +101,6 @@ void TileUI::on_varAccessibility_itemSelectionChanged() } } -void TileUI::on_boxHMs_toggled(const bool hm) -{ - if (!hm) - { - varHMType->setCurrentIndex(-1); - varHMUnder->setCurrentIndex(-1); - setGui(); - emit(changed(true)); - } -} - -void TileUI::on_varHMType_activated(const int hmType) -{ - static_cast<Tile*>(modified())->setHmType(hmType); -} - -void TileUI::on_varHMUnder_activated(const int hmUnder) -{ - static_cast<Tile*>(modified())->setUnder(varHMUnder->itemData(hmUnder, Qt::UserRole).toInt()); -} - void TileUI::on_boxForces_toggled(const bool forces) { if (!forces) diff --git a/pokemodr/TileUI.h b/pokemodr/TileUI.h index 09f711ca..a9007040 100644 --- a/pokemodr/TileUI.h +++ b/pokemodr/TileUI.h @@ -42,15 +42,11 @@ class TileUI : public ObjectUI, private Ui::formTile void on_varSprite_pressed(); void on_varAccessibility_itemSelectionChanged(); void on_varWildChance_valueChanged(const Fraction& wild); - void on_boxHMs_toggled(const bool hm); - void on_varHMType_activated(const int hmType); - void on_varHMUnder_activated(const int hmUnder); void on_boxForces_toggled(const bool forces); void on_varForce_activated(const int force); void on_varDirection_activated(const int direction); private slots: void initGui(); - void refreshGui(); void setGui(); }; diff --git a/pokemodr/TypeUI.cpp b/pokemodr/TypeUI.cpp index 8880e2bc..97c8bf23 100644 --- a/pokemodr/TypeUI.cpp +++ b/pokemodr/TypeUI.cpp @@ -32,26 +32,10 @@ TypeUI::~TypeUI() { } -void TypeUI::initGui() -{ - varStatusImmunity->addItems(Pokemod::StatusStr); - varWeatherImmunity->addItems(Pokemod::WeatherStr); -} - void TypeUI::setGui() { varName->setText(static_cast<Type*>(modified())->name()); varSTAB->setValue(static_cast<Type*>(modified())->stab()); - for (int i = 0; i < varStatusImmunity->count(); ++i) - { - QListWidgetItem* widgetItem = varStatusImmunity->item(i); - widgetItem->setSelected(static_cast<Type*>(modified())->statusImmunity(widgetItem->data(Qt::UserRole).toInt())); - } - for (int i = 0; i < varWeatherImmunity->count(); ++i) - { - QListWidgetItem* widgetItem = varWeatherImmunity->item(i); - widgetItem->setSelected(static_cast<Type*>(modified())->weatherImmunity(widgetItem->data(Qt::UserRole).toInt())); - } } void TypeUI::apply() @@ -78,21 +62,3 @@ void TypeUI::on_varSTAB_valueChanged(const Fraction& stab) { static_cast<Type*>(modified())->setStab(stab); } - -void TypeUI::on_varStatusImmunity_itemSelectionChanged() -{ - for (int i = 0; i < varStatusImmunity->count(); ++i) - { - const QListWidgetItem* widgetItem = varStatusImmunity->item(i); - static_cast<Type*>(modified())->setStatusImmunity(widgetItem->data(Qt::UserRole).toInt(), widgetItem->isSelected()); - } -} - -void TypeUI::on_varWeatherImmunity_itemSelectionChanged() -{ - for (int i = 0; i < varStatusImmunity->count(); ++i) - { - const QListWidgetItem* widgetItem = varWeatherImmunity->item(i); - static_cast<Type*>(modified())->setWeatherImmunity(widgetItem->data(Qt::UserRole).toInt(), widgetItem->isSelected()); - } -} diff --git a/pokemodr/TypeUI.h b/pokemodr/TypeUI.h index 831bb905..2e3c9632 100644 --- a/pokemodr/TypeUI.h +++ b/pokemodr/TypeUI.h @@ -40,10 +40,7 @@ class TypeUI : public ObjectUI, private Ui::formType protected slots: void on_varName_textChanged(const QString& name); void on_varSTAB_valueChanged(const Fraction& stab); - void on_varStatusImmunity_itemSelectionChanged(); - void on_varWeatherImmunity_itemSelectionChanged(); private slots: - void initGui(); void setGui(); }; diff --git a/pokemodr/WeatherUI.cpp b/pokemodr/WeatherUI.cpp new file mode 100644 index 00000000..e80d5016 --- /dev/null +++ b/pokemodr/WeatherUI.cpp @@ -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/>. + */ + +// Header include +#include "WeatherUI.h" + +// Pokemod includes +#include "../pokemod/Weather.h" + +WeatherUI::WeatherUI(Weather* weather, QWidget* parent) : + ObjectUI(parent) +{ + setupUi(this); + setObjects(weather, new Weather(*weather)); +} + +WeatherUI::~WeatherUI() +{ +} + +void WeatherUI::setGui() +{ + varName->setText(static_cast<Weather*>(modified())->name()); + varScript->setValue(static_cast<Weather*>(modified())->script()); +} + +void WeatherUI::apply() +{ + *static_cast<Weather*>(original()) = *static_cast<Weather*>(modified()); + emit(changed(false)); +} + +void WeatherUI::discard() +{ + *static_cast<Weather*>(modified()) = *static_cast<Weather*>(original()); + setGui(); + emit(changed(false)); +} + +void WeatherUI::on_varName_textChanged(const QString& name) +{ + const int cursor = varName->cursorPosition(); + static_cast<Weather*>(modified())->setName(name); + varName->setCursorPosition(cursor); +} + +void WeatherUI::on_varScript_valueChanged(const Script& script) +{ + static_cast<Weather*>(modified())->setScript(script); +} diff --git a/pokemodr/WeatherUI.h b/pokemodr/WeatherUI.h new file mode 100644 index 00000000..49ea17dd --- /dev/null +++ b/pokemodr/WeatherUI.h @@ -0,0 +1,47 @@ +/* + * 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 __POKEMODR_WEATHERUI__ +#define __POKEMODR_WEATHERUI__ + +// PokeModr includes +#include "ObjectUI.h" + +// Form include +#include "ui_weather.h" + +// Forward declarations +class Weather; + +class WeatherUI : public ObjectUI, private Ui::formWeather +{ + Q_OBJECT + + public: + WeatherUI(Weather* weather, QWidget* parent); + ~WeatherUI(); + public slots: + void apply(); + void discard(); + protected slots: + void on_varName_textChanged(const QString& name); + void on_varScript_valueChanged(const Script& script); + private slots: + void setGui(); +}; + +#endif diff --git a/pokemodr/gui/sprite.ui b/pokemodr/gui/sprite.ui new file mode 100644 index 00000000..94630b76 --- /dev/null +++ b/pokemodr/gui/sprite.ui @@ -0,0 +1,78 @@ +<ui version="4.0" > + <class>formSprite</class> + <widget class="QWidget" name="formSprite" > + <layout class="QVBoxLayout" > + <item> + <widget class="QGroupBox" name="boxName" > + <property name="title" > + <string>Name</string> + </property> + <layout class="QHBoxLayout" > + <item> + <widget class="KLineEdit" name="varName" > + <property name="toolTip" > + <string>The name of the sprite</string> + </property> + <property name="showClearButton" stdset="0" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="boxSprite" > + <property name="title" > + <string>Sprite</string> + </property> + <layout class="QHBoxLayout" > + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="KPushButton" name="varSprite" /> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> + <customwidget> + <class>KPushButton</class> + <extends>QPushButton</extends> + <header>kpushbutton.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/pokemodr/gui/status.ui b/pokemodr/gui/status.ui new file mode 100644 index 00000000..f6fe358e --- /dev/null +++ b/pokemodr/gui/status.ui @@ -0,0 +1,52 @@ +<ui version="4.0" > + <class>formStatus</class> + <widget class="QWidget" name="formStatus" > + <layout class="QVBoxLayout" > + <item> + <widget class="QGroupBox" name="boxName" > + <property name="title" > + <string>Name</string> + </property> + <layout class="QHBoxLayout" > + <item> + <widget class="KLineEdit" name="varName" > + <property name="toolTip" > + <string>Name of the status</string> + </property> + <property name="showClearButton" stdset="0" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="boxScript" > + <property name="title" > + <string>Script</string> + </property> + <layout class="QHBoxLayout" > + <item> + <widget class="ScriptWidget" name="varScript" /> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> + <customwidget> + <class>ScriptWidget</class> + <extends>QWidget</extends> + <header>../ScriptWidget.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/pokemodr/gui/type.ui b/pokemodr/gui/type.ui index 71dc8903..8327759b 100644 --- a/pokemodr/gui/type.ui +++ b/pokemodr/gui/type.ui @@ -40,38 +40,6 @@ </layout> </widget> </item> - <item> - <widget class="QGroupBox" name="boxStatusImmunity" > - <property name="title" > - <string>Status Immunity</string> - </property> - <layout class="QVBoxLayout" > - <item> - <widget class="KListWidget" name="varStatusImmunity" > - <property name="selectionMode" > - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="boxWeatherImmunity" > - <property name="title" > - <string>Weather Immunity</string> - </property> - <layout class="QVBoxLayout" > - <item> - <widget class="KListWidget" name="varWeatherImmunity" > - <property name="selectionMode" > - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - </widget> - </item> - </layout> - </widget> - </item> </layout> </widget> <customwidgets> @@ -81,11 +49,6 @@ <header>klineedit.h</header> </customwidget> <customwidget> - <class>KListWidget</class> - <extends>QListWidget</extends> - <header>klistwidget.h</header> - </customwidget> - <customwidget> <class>FractionWidget</class> <extends>QWidget</extends> <header>../FractionWidget.h</header> diff --git a/pokemodr/gui/weather.ui b/pokemodr/gui/weather.ui new file mode 100644 index 00000000..529c17b7 --- /dev/null +++ b/pokemodr/gui/weather.ui @@ -0,0 +1,52 @@ +<ui version="4.0" > + <class>formWeather</class> + <widget class="QWidget" name="formWeather" > + <layout class="QVBoxLayout" > + <item> + <widget class="QGroupBox" name="boxName" > + <property name="title" > + <string>Name</string> + </property> + <layout class="QHBoxLayout" > + <item> + <widget class="KLineEdit" name="varName" > + <property name="toolTip" > + <string>Name of the weather</string> + </property> + <property name="showClearButton" stdset="0" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="boxScript" > + <property name="title" > + <string>Script</string> + </property> + <layout class="QHBoxLayout" > + <item> + <widget class="ScriptWidget" name="varScript" /> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> + <customwidget> + <class>ScriptWidget</class> + <extends>QWidget</extends> + <header>../ScriptWidget.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/pokemodr/models/PokemodModel.cpp b/pokemodr/models/PokemodModel.cpp index 90ccb868..dab58947 100644 --- a/pokemodr/models/PokemodModel.cpp +++ b/pokemodr/models/PokemodModel.cpp @@ -33,11 +33,14 @@ #include "RulesModel.h" #include "SoundGroupModel.h" #include "SpeciesGroupModel.h" +#include "SpriteGroupModel.h" +#include "StatusGroupModel.h" #include "StoreGroupModel.h" #include "TileGroupModel.h" #include "TimeGroupModel.h" #include "TrainerGroupModel.h" #include "TypeGroupModel.h" +#include "WeatherGroupModel.h" // PokeModr includes #include "../PokemodUI.h" @@ -143,9 +146,12 @@ void PokemodModel::setupData() m_objects.append(new NatureGroupModel(this, pokemod)); m_objects.append(new SoundGroupModel(this, pokemod)); m_objects.append(new SpeciesGroupModel(this, pokemod)); + m_objects.append(new SpriteGroupModel(this, pokemod)); + m_objects.append(new StatusGroupModel(this, pokemod)); m_objects.append(new StoreGroupModel(this, pokemod)); m_objects.append(new TileGroupModel(this, pokemod)); m_objects.append(new TimeGroupModel(this, pokemod)); m_objects.append(new TrainerGroupModel(this, pokemod)); m_objects.append(new TypeGroupModel(this, pokemod)); + m_objects.append(new WeatherGroupModel(this, pokemod)); } diff --git a/pokemodr/models/SpriteGroupModel.cpp b/pokemodr/models/SpriteGroupModel.cpp new file mode 100644 index 00000000..fc31dacc --- /dev/null +++ b/pokemodr/models/SpriteGroupModel.cpp @@ -0,0 +1,95 @@ +/* + * 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 "SpriteGroupModel.h" + +// Model includes +#include "SpriteModel.h" + +// Pokemod includes +#include "../../pokemod/Sprite.h" +#include "../../pokemod/Pokemod.h" + +// Qt includes +#include <QFile> + +// KDE includes +#include <KMenu> + +SpriteGroupModel::SpriteGroupModel(BaseModel* parent, Pokemod* pokemod) : + GroupModel(parent, pokemod, "Sprites") +{ + for (int i = 0; i < pokemod->spriteCount(); ++i) + addObject(pokemod->sprite(i)); +} + +SpriteGroupModel::~SpriteGroupModel() +{ +} + +QVariant SpriteGroupModel::data(const int role) const +{ + if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Add Sprite", this, SLOT(addObject())); + return QVariant::fromValue(static_cast<void*>(menu)); + } + return GroupModel::data(role); +} + +bool SpriteGroupModel::setData(const QVariant& value, int role) +{ + if (role == BaseModel::XmlRole) + { + if (value.canConvert<QString>()) + { + QFile file(value.toString()); + QDomDocument xml; + if ((file.open(QIODevice::ReadOnly) && xml.setContent(&file)) || xml.setContent(value.toString())) + { + if (xml.doctype().name() == "Sprite") + { + addObject(static_cast<Pokemod*>(m_object)->newSprite(xml.documentElement())); + return true; + } + file.close(); + } + } + } + return false; +} + +void SpriteGroupModel::addObject(Object* object) +{ + if (!object) + object = static_cast<Pokemod*>(m_object)->newSprite(); + if (object->className() == "Sprite") + m_objects.append(new SpriteModel(this, static_cast<Sprite*>(object))); +} + +void SpriteGroupModel::deleteObject(BaseObjectModel* model) +{ + const int index = m_objects.indexOf(model); + if (0 <= index) + { + static_cast<Pokemod*>(m_object)->deleteSprite(index); + m_objects[index]->deleteLater(); + m_objects.removeAt(index); + } +} diff --git a/pokemodr/models/SpriteGroupModel.h b/pokemodr/models/SpriteGroupModel.h new file mode 100644 index 00000000..ae6cb468 --- /dev/null +++ b/pokemodr/models/SpriteGroupModel.h @@ -0,0 +1,42 @@ +/* + * 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 __POKEMODR_SPRITEGROUPMODEL__ +#define __POKEMODR_SPRITEGROUPMODEL__ + +// Model includes +#include "GroupModel.h" + +// Forward declarations +class Pokemod; + +class SpriteGroupModel : public GroupModel +{ + Q_OBJECT + + public: + SpriteGroupModel(BaseModel* parent, Pokemod* pokemod); + ~SpriteGroupModel(); + + QVariant data(const int role = Qt::DisplayRole) const; + bool setData(const QVariant& value, int role = Qt::EditRole); + public slots: + void addObject(Object* object = NULL); + void deleteObject(BaseObjectModel* model); +}; + +#endif diff --git a/pokemodr/models/SpriteModel.cpp b/pokemodr/models/SpriteModel.cpp new file mode 100644 index 00000000..1a2a66f4 --- /dev/null +++ b/pokemodr/models/SpriteModel.cpp @@ -0,0 +1,94 @@ +/* + * 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 "SpriteModel.h" + +// Model includes +#include "GroupModel.h" + +// PokeModr includes +#include "../SpriteUI.h" + +// Pokemod includes +#include "../../pokemod/Sprite.h" + +// Qt includes +#include <QFile> + +// KDE includes +#include <KMenu> + +SpriteModel::SpriteModel(BaseModel* parent, Sprite* sprite) : + ObjectModel(parent, sprite) +{ +} + +SpriteModel::~SpriteModel() +{ +} + +QVariant SpriteModel::data(int role) const +{ + if (role == Qt::DisplayRole) + return static_cast<Sprite*>(m_object)->name(); + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) + { + QWidget* widget = new SpriteUI(static_cast<Sprite*>(m_object), NULL); + return QVariant::fromValue(widget); + } + else if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Delete Sprite", this, SLOT(deleteSelf())); + return QVariant::fromValue(static_cast<void*>(menu)); + } + return ObjectModel::data(role); +} + +bool SpriteModel::setData(const QVariant& value, int role) +{ + if (role == BaseModel::XmlRole) + { + if (value.canConvert<QString>()) + { + QFile file(value.toString()); + QDomDocument xml; + if ((file.open(QIODevice::ReadOnly) && xml.setContent(&file)) || xml.setContent(value.toString())) + { + if (xml.doctype().name() == m_object->className()) + { + m_object->load(xml.documentElement()); + return true; + } + file.close(); + } + } + } + return false; +} + +void SpriteModel::deleteSelf() +{ +// static_cast<GroupModel*>(m_parent)->deleteObject(this); +} diff --git a/pokemodr/models/SpriteModel.h b/pokemodr/models/SpriteModel.h new file mode 100644 index 00000000..3066365d --- /dev/null +++ b/pokemodr/models/SpriteModel.h @@ -0,0 +1,42 @@ +/* + * 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 __POKEMODR_SPRITEMODEL__ +#define __POKEMODR_SPRITEMODEL__ + +// Model includes +#include "ObjectModel.h" + +// Forward declarations +class Sprite; + +class SpriteModel : public ObjectModel +{ + Q_OBJECT + + public: + SpriteModel(BaseModel* parent, Sprite* sprite); + ~SpriteModel(); + + QVariant data(int role = Qt::DisplayRole) const; + + bool setData(const QVariant& value, int role = Qt::EditRole); + public slots: + void deleteSelf(); +}; + +#endif diff --git a/pokemodr/models/StatusGroupModel.cpp b/pokemodr/models/StatusGroupModel.cpp new file mode 100644 index 00000000..7a5ee0d8 --- /dev/null +++ b/pokemodr/models/StatusGroupModel.cpp @@ -0,0 +1,95 @@ +/* + * 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 "StatusGroupModel.h" + +// Model includes +#include "StatusModel.h" + +// Pokemod includes +#include "../../pokemod/Status.h" +#include "../../pokemod/Pokemod.h" + +// Qt includes +#include <QFile> + +// KDE includes +#include <KMenu> + +StatusGroupModel::StatusGroupModel(BaseModel* parent, Pokemod* pokemod) : + GroupModel(parent, pokemod, "Status Effects") +{ + for (int i = 0; i < pokemod->statusCount(); ++i) + addObject(pokemod->status(i)); +} + +StatusGroupModel::~StatusGroupModel() +{ +} + +QVariant StatusGroupModel::data(const int role) const +{ + if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Add Status", this, SLOT(addObject())); + return QVariant::fromValue(static_cast<void*>(menu)); + } + return GroupModel::data(role); +} + +bool StatusGroupModel::setData(const QVariant& value, int role) +{ + if (role == BaseModel::XmlRole) + { + if (value.canConvert<QString>()) + { + QFile file(value.toString()); + QDomDocument xml; + if ((file.open(QIODevice::ReadOnly) && xml.setContent(&file)) || xml.setContent(value.toString())) + { + if (xml.doctype().name() == "Status") + { + addObject(static_cast<Pokemod*>(m_object)->newStatus(xml.documentElement())); + return true; + } + file.close(); + } + } + } + return false; +} + +void StatusGroupModel::addObject(Object* object) +{ + if (!object) + object = static_cast<Pokemod*>(m_object)->newStatus(); + if (object->className() == "Status") + m_objects.append(new StatusModel(this, static_cast<Status*>(object))); +} + +void StatusGroupModel::deleteObject(BaseObjectModel* model) +{ + const int index = m_objects.indexOf(model); + if (0 <= index) + { + static_cast<Pokemod*>(m_object)->deleteStatus(index); + m_objects[index]->deleteLater(); + m_objects.removeAt(index); + } +} diff --git a/pokemodr/models/StatusGroupModel.h b/pokemodr/models/StatusGroupModel.h new file mode 100644 index 00000000..7c916e31 --- /dev/null +++ b/pokemodr/models/StatusGroupModel.h @@ -0,0 +1,42 @@ +/* + * 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 __POKEMODR_STATUSGROUPMODEL__ +#define __POKEMODR_STATUSGROUPMODEL__ + +// Model includes +#include "GroupModel.h" + +// Forward declarations +class Pokemod; + +class StatusGroupModel : public GroupModel +{ + Q_OBJECT + + public: + StatusGroupModel(BaseModel* parent, Pokemod* pokemod); + ~StatusGroupModel(); + + QVariant data(const int role = Qt::DisplayRole) const; + bool setData(const QVariant& value, int role = Qt::EditRole); + public slots: + void addObject(Object* object = NULL); + void deleteObject(BaseObjectModel* model); +}; + +#endif diff --git a/pokemodr/models/StatusModel.cpp b/pokemodr/models/StatusModel.cpp new file mode 100644 index 00000000..c049c79f --- /dev/null +++ b/pokemodr/models/StatusModel.cpp @@ -0,0 +1,94 @@ +/* + * 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 "StatusModel.h" + +// Model includes +#include "GroupModel.h" + +// PokeModr includes +#include "../StatusUI.h" + +// Pokemod includes +#include "../../pokemod/Status.h" + +// Qt includes +#include <QFile> + +// KDE includes +#include <KMenu> + +StatusModel::StatusModel(BaseModel* parent, Status* status) : + ObjectModel(parent, status) +{ +} + +StatusModel::~StatusModel() +{ +} + +QVariant StatusModel::data(int role) const +{ + if (role == Qt::DisplayRole) + return static_cast<Status*>(m_object)->name(); + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) + { + QWidget* widget = new StatusUI(static_cast<Status*>(m_object), NULL); + return QVariant::fromValue(widget); + } + else if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Delete Status", this, SLOT(deleteSelf())); + return QVariant::fromValue(static_cast<void*>(menu)); + } + return ObjectModel::data(role); +} + +bool StatusModel::setData(const QVariant& value, int role) +{ + if (role == BaseModel::XmlRole) + { + if (value.canConvert<QString>()) + { + QFile file(value.toString()); + QDomDocument xml; + if ((file.open(QIODevice::ReadOnly) && xml.setContent(&file)) || xml.setContent(value.toString())) + { + if (xml.doctype().name() == m_object->className()) + { + m_object->load(xml.documentElement()); + return true; + } + file.close(); + } + } + } + return false; +} + +void StatusModel::deleteSelf() +{ +// static_cast<GroupModel*>(m_parent)->deleteObject(this); +} diff --git a/pokemodr/models/StatusModel.h b/pokemodr/models/StatusModel.h new file mode 100644 index 00000000..429da25a --- /dev/null +++ b/pokemodr/models/StatusModel.h @@ -0,0 +1,42 @@ +/* + * 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 __POKEMODR_STATUSMODEL__ +#define __POKEMODR_STATUSMODEL__ + +// Model includes +#include "ObjectModel.h" + +// Forward declarations +class Status; + +class StatusModel : public ObjectModel +{ + Q_OBJECT + + public: + StatusModel(BaseModel* parent, Status* status); + ~StatusModel(); + + QVariant data(int role = Qt::DisplayRole) const; + + bool setData(const QVariant& value, int role = Qt::EditRole); + public slots: + void deleteSelf(); +}; + +#endif diff --git a/pokemodr/models/WeatherGroupModel.cpp b/pokemodr/models/WeatherGroupModel.cpp new file mode 100644 index 00000000..4faf3bf2 --- /dev/null +++ b/pokemodr/models/WeatherGroupModel.cpp @@ -0,0 +1,95 @@ +/* + * 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 "WeatherGroupModel.h" + +// Model includes +#include "WeatherModel.h" + +// Pokemod includes +#include "../../pokemod/Weather.h" +#include "../../pokemod/Pokemod.h" + +// Qt includes +#include <QFile> + +// KDE includes +#include <KMenu> + +WeatherGroupModel::WeatherGroupModel(BaseModel* parent, Pokemod* pokemod) : + GroupModel(parent, pokemod, "Weathers") +{ + for (int i = 0; i < pokemod->weatherCount(); ++i) + addObject(pokemod->weather(i)); +} + +WeatherGroupModel::~WeatherGroupModel() +{ +} + +QVariant WeatherGroupModel::data(const int role) const +{ + if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Add Weather", this, SLOT(addObject())); + return QVariant::fromValue(static_cast<void*>(menu)); + } + return GroupModel::data(role); +} + +bool WeatherGroupModel::setData(const QVariant& value, int role) +{ + if (role == BaseModel::XmlRole) + { + if (value.canConvert<QString>()) + { + QFile file(value.toString()); + QDomDocument xml; + if ((file.open(QIODevice::ReadOnly) && xml.setContent(&file)) || xml.setContent(value.toString())) + { + if (xml.doctype().name() == "Weather") + { + addObject(static_cast<Pokemod*>(m_object)->newWeather(xml.documentElement())); + return true; + } + file.close(); + } + } + } + return false; +} + +void WeatherGroupModel::addObject(Object* object) +{ + if (!object) + object = static_cast<Pokemod*>(m_object)->newWeather(); + if (object->className() == "Weather") + m_objects.append(new WeatherModel(this, static_cast<Weather*>(object))); +} + +void WeatherGroupModel::deleteObject(BaseObjectModel* model) +{ + const int index = m_objects.indexOf(model); + if (0 <= index) + { + static_cast<Pokemod*>(m_object)->deleteWeather(index); + m_objects[index]->deleteLater(); + m_objects.removeAt(index); + } +} diff --git a/pokemodr/models/WeatherGroupModel.h b/pokemodr/models/WeatherGroupModel.h new file mode 100644 index 00000000..75baa607 --- /dev/null +++ b/pokemodr/models/WeatherGroupModel.h @@ -0,0 +1,42 @@ +/* + * 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 __POKEMODR_WEATHERGROUPMODEL__ +#define __POKEMODR_WEATHERGROUPMODEL__ + +// Model includes +#include "GroupModel.h" + +// Forward declarations +class Pokemod; + +class WeatherGroupModel : public GroupModel +{ + Q_OBJECT + + public: + WeatherGroupModel(BaseModel* parent, Pokemod* pokemod); + ~WeatherGroupModel(); + + QVariant data(const int role = Qt::DisplayRole) const; + bool setData(const QVariant& value, int role = Qt::EditRole); + public slots: + void addObject(Object* object = NULL); + void deleteObject(BaseObjectModel* model); +}; + +#endif diff --git a/pokemodr/models/WeatherModel.cpp b/pokemodr/models/WeatherModel.cpp new file mode 100644 index 00000000..85e97100 --- /dev/null +++ b/pokemodr/models/WeatherModel.cpp @@ -0,0 +1,94 @@ +/* + * 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 "WeatherModel.h" + +// Model includes +#include "GroupModel.h" + +// PokeModr includes +#include "../WeatherUI.h" + +// Pokemod includes +#include "../../pokemod/Weather.h" + +// Qt includes +#include <QFile> + +// KDE includes +#include <KMenu> + +WeatherModel::WeatherModel(BaseModel* parent, Weather* weather) : + ObjectModel(parent, weather) +{ +} + +WeatherModel::~WeatherModel() +{ +} + +QVariant WeatherModel::data(int role) const +{ + if (role == Qt::DisplayRole) + return static_cast<Weather*>(m_object)->name(); + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) + { + QWidget* widget = new WeatherUI(static_cast<Weather*>(m_object), NULL); + return QVariant::fromValue(widget); + } + else if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Delete Weather", this, SLOT(deleteSelf())); + return QVariant::fromValue(static_cast<void*>(menu)); + } + return ObjectModel::data(role); +} + +bool WeatherModel::setData(const QVariant& value, int role) +{ + if (role == BaseModel::XmlRole) + { + if (value.canConvert<QString>()) + { + QFile file(value.toString()); + QDomDocument xml; + if ((file.open(QIODevice::ReadOnly) && xml.setContent(&file)) || xml.setContent(value.toString())) + { + if (xml.doctype().name() == m_object->className()) + { + m_object->load(xml.documentElement()); + return true; + } + file.close(); + } + } + } + return false; +} + +void WeatherModel::deleteSelf() +{ +// static_cast<GroupModel*>(m_parent)->deleteObject(this); +} diff --git a/pokemodr/models/WeatherModel.h b/pokemodr/models/WeatherModel.h new file mode 100644 index 00000000..9c8007b7 --- /dev/null +++ b/pokemodr/models/WeatherModel.h @@ -0,0 +1,42 @@ +/* + * 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 __POKEMODR_WEATHERMODEL__ +#define __POKEMODR_WEATHERMODEL__ + +// Model includes +#include "ObjectModel.h" + +// Forward declarations +class Weather; + +class WeatherModel : public ObjectModel +{ + Q_OBJECT + + public: + WeatherModel(BaseModel* parent, Weather* weather); + ~WeatherModel(); + + QVariant data(int role = Qt::DisplayRole) const; + + bool setData(const QVariant& value, int role = Qt::EditRole); + public slots: + void deleteSelf(); +}; + +#endif diff --git a/pokemodr/pokemodr.pro b/pokemodr/pokemodr.pro index 49e47332..82b652cb 100644 --- a/pokemodr/pokemodr.pro +++ b/pokemodr/pokemodr.pro @@ -66,6 +66,8 @@ SOURCES += AbilityUI.cpp \ SpeciesAbilityUI.cpp \ SpeciesItemUI.cpp \ SpeciesMoveUI.cpp \ + SpriteUI.cpp \ + StatusUI.cpp \ StoreUI.cpp \ TileDelegate.cpp \ TilemapModel.cpp \ @@ -73,6 +75,7 @@ SOURCES += AbilityUI.cpp \ TimeUI.cpp \ TrainerUI.cpp \ TypeUI.cpp \ + WeatherUI.cpp \ models/AbilityGroupModel.cpp \ models/AbilityModel.cpp \ models/AuthorGroupModel.cpp \ @@ -124,6 +127,10 @@ SOURCES += AbilityUI.cpp \ models/SpeciesItemModel.cpp \ models/SpeciesMoveGroupModel.cpp \ models/SpeciesMoveModel.cpp \ + models/SpriteGroupModel.cpp \ + models/SpriteModel.cpp \ + models/StatusGroupModel.cpp \ + models/StatusModel.cpp \ models/StoreGroupModel.cpp \ models/StoreModel.cpp \ models/TileGroupModel.cpp \ @@ -133,7 +140,9 @@ SOURCES += AbilityUI.cpp \ models/TrainerGroupModel.cpp \ models/TrainerModel.cpp \ models/TypeGroupModel.cpp \ - models/TypeModel.cpp + models/TypeModel.cpp \ + models/WeatherGroupModel.cpp \ + models/WeatherModel.cpp HEADERS += AbilityUI.h \ AuthorUI.h \ @@ -169,6 +178,8 @@ HEADERS += AbilityUI.h \ SpeciesAbilityUI.h \ SpeciesItemUI.h \ SpeciesMoveUI.h \ + SpriteUI.h \ + StatusUI.h \ StoreUI.h \ TileDelegate.h \ TilemapModel.h \ @@ -177,6 +188,7 @@ HEADERS += AbilityUI.h \ TypechartWidgetItem.h \ TrainerUI.h \ TypeUI.h \ + WeatherUI.h \ models/AbilityGroupModel.h \ models/AbilityModel.h \ models/AuthorGroupModel.h \ @@ -228,6 +240,10 @@ HEADERS += AbilityUI.h \ models/SpeciesItemModel.h \ models/SpeciesMoveGroupModel.h \ models/SpeciesMoveModel.h \ + models/SpriteGroupModel.h \ + models/SpriteModel.h \ + models/StatusGroupModel.h \ + models/StatusModel.h \ models/StoreGroupModel.h \ models/StoreModel.h \ models/TileGroupModel.h \ @@ -237,7 +253,9 @@ HEADERS += AbilityUI.h \ models/TrainerGroupModel.h \ models/TrainerModel.h \ models/TypeGroupModel.h \ - models/TypeModel.h + models/TypeModel.h \ + models/WeatherGroupModel.h \ + models/WeatherModel.h FORMS += gui/ability.ui \ gui/author.ui \ @@ -268,11 +286,14 @@ FORMS += gui/ability.ui \ gui/speciesability.ui \ gui/speciesitem.ui \ gui/speciesmove.ui \ + gui/sprite.ui \ + gui/status.ui \ gui/store.ui \ gui/tile.ui \ gui/time.ui \ gui/trainer.ui \ - gui/type.ui + gui/type.ui \ + gui/weather.ui LATEX += pokemodr.tex |
