/* * Copyright 2008 Ben Boeckel * * 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 . */ // KDE includes #include #include // Qt includes #include #include // Pokemod includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // PokeModr includes #include "AbilityUI.h" // #include "AbilityEffectUI.h" #include "AuthorUI.h" #include "BadgeUI.h" #include "CoinListUI.h" #include "CoinListObjectUI.h" // #include "DialogUI.h" #include "EggGroupUI.h" #include "ItemUI.h" // #include "ItemEffectUI.h" #include "ItemTypeUI.h" #include "MapUI.h" // #include "MapEffectUI.h" // #include "MapTrainerUI.h" #include "MapTrainerTeamMemberUI.h" #include "MapWarpUI.h" #include "MapWildListUI.h" #include "MapWildListEncounterUI.h" #include "MoveUI.h" // #include "MoveEffectUI.h" #include "NatureUI.h" #include "PokemodUI.h" #include "RulesUI.h" #include "SpeciesUI.h" #include "SpeciesAbilityUI.h" #include "SpeciesEvolutionUI.h" #include "SpeciesItemUI.h" #include "SpeciesMoveUI.h" #include "StoreUI.h" #include "TileUI.h" #include "TimeUI.h" #include "TrainerUI.h" #include "TypeUI.h" // Header include #include "PokeModTreeItem.h" // FIXME: scrap for a better solution /* void PokeModTreeItem::update() { if (text(0).isEmpty()) { QString name(m_object->className()); if (name == "Ability") new PokeModTreeItem(this, m_object, "Effects"); else if (name == "CoinList") new PokeModTreeItem(this, m_object, "Objects"); else if (name == "Item") new PokeModTreeItem(this, m_object, "Effects"); else if (name == "Map") { new PokeModTreeItem(this, m_object, "Effects"); new PokeModTreeItem(this, m_object, "Trainers"); new PokeModTreeItem(this, m_object, "Warps"); new PokeModTreeItem(this, m_object, "Wild Lists"); } else if (name == "MapTrainer") new PokeModTreeItem(this, m_object, "Team Members"); else if (name == "MapWildList") new PokeModTreeItem(this, m_object, "Encounters"); else if (name == "Move") new PokeModTreeItem(this, m_object, "Effects"); else if (name == "Pokemod") { new PokeModTreeItem(this, static_cast(m_object)->rules()); new PokeModTreeItem(this, m_object, "Abilities"); new PokeModTreeItem(this, m_object, "Authors"); new PokeModTreeItem(this, m_object, "Badges"); new PokeModTreeItem(this, m_object, "Coin Lists"); new PokeModTreeItem(this, m_object, "Dialogs"); new PokeModTreeItem(this, m_object, "Egg Groups"); new PokeModTreeItem(this, m_object, "Items"); new PokeModTreeItem(this, m_object, "Item Types"); new PokeModTreeItem(this, m_object, "Maps"); new PokeModTreeItem(this, m_object, "Moves"); new PokeModTreeItem(this, m_object, "Natures"); new PokeModTreeItem(this, m_object, "Species"); new PokeModTreeItem(this, m_object, "Stores"); new PokeModTreeItem(this, m_object, "Tiles"); new PokeModTreeItem(this, m_object, "Times"); new PokeModTreeItem(this, m_object, "Trainers"); new PokeModTreeItem(this, m_object, "Types"); } else if (name == "Species") { new PokeModTreeItem(this, m_object, "Abilities"); new PokeModTreeItem(this, m_object, "Evolutions"); new PokeModTreeItem(this, m_object, "Items"); new PokeModTreeItem(this, m_object, "Moves"); } } else { QString name(obj->className()); if (name == "Ability") { Ability* ability = static_cast(m_object); for (int i = 0; i < ability->effectCount(); ++i) new PokeModTreeItem(this, ability->effect(i)); } else if (name == "CoinList") { CoinList* coinList = static_cast(m_object); for (int i = 0; i < coinList->itemCount(); ++i) new PokeModTreeItem(this, coinList->item(i)); } else if (name == "Item") { Item* item = static_cast(m_object); for (int i = 0; i < item->effectCount(); ++i) new PokeModTreeItem(this, item->effect(i)); } else if (name == "Map") { Map* map = static_cast(m_object); if (text(0) == "Effects") { for (int i = 0; i < map->effectCount(); ++i) new PokeModTreeItem(this, map->effect(i)); } else if (text(0) == "Trainers") { for (int i = 0; i < map->trainerCount(); ++i) new PokeModTreeItem(this, map->trainer(i)); } else if (text(0) == "Warps") { for (int i = 0; i < m->warpCount(); ++i) new PokeModTreeItem(this, m->warp(i)); } else if (text(0) == "Wild Lists") { for (int i = 0; i < m->wildListCount(); ++i) new PokeModTreeItem(this, m->wildList(i)); } } else if (name == "MapTrainer") { MapTrainer* t = static_cast(obj); for (int i = 0; i < t->teamMemberCount(); ++i) new PokeModTreeItem(this, t->teamMember(i)); } else if (name == "MapWildList") { MapWildList* w = static_cast(obj); for (int i = 0; i < w->encounterCount(); ++i) new PokeModTreeItem(this, w->encounter(i)); } else if (name == "Move") { Move* m = static_cast(obj); for (int i = 0; i < m->effectCount(); ++i) new PokeModTreeItem(this, m->effect(i)); } else if (name == "Pokemod") { Pokemod* p = static_cast(obj); if (text(0) == "Abilities") { for (int i = 0; i < p->abilityCount(); ++i) new PokeModTreeItem(this, p->ability(i)); } else if (text(0) == "Authors") { for (int i = 0; i < p->authorCount(); ++i) new PokeModTreeItem(this, p->author(i)); } else if (text(0) == "Badges") { for (int i = 0; i < p->badgeCount(); ++i) new PokeModTreeItem(this, p->badge(i)); } else if (text(0) == "Coin Lists") { for (int i = 0; i < p->coinListCount(); ++i) new PokeModTreeItem(this, p->coinList(i)); } else if (text(0) == "Dialogs") { for (int i = 0; i < p->dialogCount(); ++i) new PokeModTreeItem(this, p->dialog(i)); } else if (text(0) == "Egg Groups") { for (int i = 0; i < p->eggGroupCount(); ++i) new PokeModTreeItem(this, p->eggGroup(i)); } else if (text(0) == "Items") { for (int i = 0; i < p->itemCount(); ++i) new PokeModTreeItem(this, p->item(i)); } else if (text(0) == "Item Types") { for (int i = 0; i < p->itemTypeCount(); ++i) new PokeModTreeItem(this, p->itemType(i)); } else if (text(0) == "Maps") { for (int i = 0; i < p->mapCount(); ++i) new PokeModTreeItem(this, p->map(i)); } else if (text(0) == "Moves") { for (int i = 0; i < p->moveCount(); ++i) new PokeModTreeItem(this, p->move(i)); } else if (text(0) == "Natures") { for (int i = 0; i < p->natureCount(); ++i) new PokeModTreeItem(this, p->nature(i)); } else if (text(0) == "Species") { for (int i = 0; i < p->speciesCount(); ++i) new PokeModTreeItem(this, p->species(i)); } else if (text(0) == "Stores") { for (int i = 0; i < p->storeCount(); ++i) new PokeModTreeItem(this, p->store(i)); } else if (text(0) == "Tiles") { for (int i = 0; i < p->tileCount(); ++i) new PokeModTreeItem(this, p->tile(i)); } else if (text(0) == "Times") { for (int i = 0; i < p->timeCount(); ++i) new PokeModTreeItem(this, p->time(i)); } else if (text(0) == "Trainers") { for (int i = 0; i < p->trainerCount(); ++i) new PokeModTreeItem(this, p->trainer(i)); } else if (text(0) == "Types") { for (int i = 0; i < p->typeCount(); ++i) new PokeModTreeItem(this, p->type(i)); } } else if (name == "Species") { Species* s = static_cast(obj); if (text(0) == "Abilities") { for (int i = 0; i < s->abilityCount(); ++i) new PokeModTreeItem(this, s->ability(i)); } else if (text(0) == "Evolutions") { for (int i = 0; i < s->evolutionCount(); ++i) new PokeModTreeItem(this, s->evolution(i)); } else if (text(0) == "Items") { for (int i = 0; i < s->itemCount(); ++i) new PokeModTreeItem(this, s->item(i)); } else if (text(0) == "Moves") { for (int i = 0; i < s->moveCount(); ++i) new PokeModTreeItem(this, s->move(i)); } } obj = NULL; } } void PokeModTreeItem::init(QWidget* pnt) { update(); setExpanded(true); setChildIndicatorPolicy(QTreeWidgetItem::QTreeWidgetItem::DontShowIndicatorWhenChildless); if (obj) { QString name(obj->className()); #define IF_IS_CLASS(class) if (name == #class) ui = new class##UI(static_cast< ::class* >(obj), pnt); IF_IS_CLASS(Ability) // else IF_IS_CLASS(AbilityEffect) else IF_IS_CLASS(Author) else IF_IS_CLASS(Badge) else IF_IS_CLASS(CoinList) else IF_IS_CLASS(CoinListObject) // else IF_IS_CLASS(Dialog) else IF_IS_CLASS(EggGroup) else IF_IS_CLASS(Item) // else IF_IS_CLASS(ItemEffect) else IF_IS_CLASS(ItemType) else IF_IS_CLASS(Map) // else IF_IS_CLASS(MapEffect) // else IF_IS_CLASS(MapTrainer) else IF_IS_CLASS(MapTrainerTeamMember) else IF_IS_CLASS(MapWarp) else IF_IS_CLASS(MapWildList) else IF_IS_CLASS(MapWildListEncounter) else IF_IS_CLASS(Move) // else IF_IS_CLASS(MoveEffect) else IF_IS_CLASS(Nature) else IF_IS_CLASS(Pokemod) else IF_IS_CLASS(Rules) else IF_IS_CLASS(Species) else IF_IS_CLASS(SpeciesAbility) else IF_IS_CLASS(SpeciesEvolution) else IF_IS_CLASS(SpeciesItem) else IF_IS_CLASS(SpeciesMove) else IF_IS_CLASS(Store) else IF_IS_CLASS(Tile) else IF_IS_CLASS(Time) // else IF_IS_CLASS(Trainer) else IF_IS_CLASS(Type) connect(ui, SIGNAL(changed(bool)), this, SLOT(changed(bool))); connect(ui, SIGNAL(changed(bool)), this, SLOT(updateName())); } #undef IF_IS_CLASS updateName(); } void PokeModTreeItem::updateName() { if (!obj) return; QString name(obj->className()); QString text; if (name == "Ability") text = static_cast(obj)->name(); else if (name == "AbilityEffect") text = AbilityEffect::EffectStr.at(static_cast(obj)->effect()); else if (name == "Author") text = static_cast(obj)->name(); else if (name == "Badge") text = static_cast(obj)->name(); else if (name == "CoinList") text = static_cast(obj)->name(); else if (name == "CoinListObject") { const CoinListObject* o = static_cast(obj); if (o->type() == CoinListObject::Item) text = obj->pokemod()->item(o->object())->name(); else text = obj->pokemod()->species(o->object())->name(); } else if (name == "Dialog") text = static_cast(obj)->dialog().mid(0, 25); else if (name == "EggGroup") text = static_cast(obj)->name(); else if (name == "Item") text = static_cast(obj)->name(); else if (name == "ItemEffect") text = ItemEffect::EffectStr.at(static_cast(obj)->effect()); else if (name == "ItemType") text = static_cast< ::ItemType* >(obj)->name(); else if (name == "Map") text = static_cast(obj)->name(); else if (name == "MapEffect") text = static_cast(obj)->name(); else if (name == "MapTrainer") text = static_cast(obj)->name(); else if (name == "MapTrainerTeamMember") { const MapTrainerTeamMember* t = static_cast(obj); text = QString("Lv. %1 %2").arg(t->level()).arg(obj->pokemod()->species(t->species())->name()); } else if (name == "MapWarp") text = static_cast(obj)->name(); else if (name == "MapWildList") text = MapWildList::ControlStr.at(static_cast(obj)->control()); else if (name == "MapWildListEncounter") { const MapWildListEncounter* e = static_cast(obj); text = QString("Lv. %1 %2").arg(e->level()).arg(obj->pokemod()->species(e->species())->name()); } else if (name == "Move") text = static_cast(obj)->name(); else if (name == "MoveEffect") text = MoveEffect::EffectStr.at(static_cast(obj)->effect()); else if (name == "Nature") text = static_cast(obj)->name(); else if (name == "Pokemod") text = static_cast(obj)->title(); else if (name == "Rules") text = "Rules"; else if (name == "Species") text = static_cast(obj)->name(); else if (name == "SpeciesAbility") text = obj->pokemod()->ability(static_cast(obj)->ability())->name(); else if (name == "SpeciesEvolution") text = obj->pokemod()->species(static_cast(obj)->species())->name(); else if (name == "SpeciesItem") text = obj->pokemod()->item(static_cast(obj)->item())->name(); else if (name == "SpeciesMove") text = obj->pokemod()->move(static_cast(obj)->move())->name(); else if (name == "Store") text = static_cast(obj)->name(); else if (name == "Tile") text = static_cast(obj)->name(); else if (name == "Time") text = static_cast(obj)->name(); else if (name == "Trainer") text = static_cast(obj)->name(); else if (name == "Type") text = static_cast< ::Type* >(obj)->name(); setText(0, text); } void PokeModTreeItem::makeMenu(const QPoint& pos) { } Object* PokeModTreeItem::copy() { if (obj) { QString name(obj->className()); #define IF_IS_CLASS(class) if (name == #class) return new ::class(obj->pokemod(), *static_cast< ::class* >(obj), obj->id()); IF_IS_CLASS(Ability) else IF_IS_CLASS(AbilityEffect) else IF_IS_CLASS(Author) else IF_IS_CLASS(Badge) else IF_IS_CLASS(CoinList) else IF_IS_CLASS(CoinListObject) else IF_IS_CLASS(Dialog) else IF_IS_CLASS(EggGroup) else IF_IS_CLASS(Item) else IF_IS_CLASS(ItemEffect) else IF_IS_CLASS(ItemType) else IF_IS_CLASS(Map) else IF_IS_CLASS(MapEffect) else IF_IS_CLASS(MapTrainer) else IF_IS_CLASS(MapTrainerTeamMember) else IF_IS_CLASS(MapWarp) else IF_IS_CLASS(MapWildList) else IF_IS_CLASS(MapWildListEncounter) else IF_IS_CLASS(Move) else IF_IS_CLASS(MoveEffect) else IF_IS_CLASS(Nature) else if (name == "Pokemod") return new Pokemod(*static_cast(obj)); else if (name == "Rules") return new Rules(obj->pokemod()); else IF_IS_CLASS(Species) else IF_IS_CLASS(SpeciesAbility) else IF_IS_CLASS(SpeciesEvolution) else IF_IS_CLASS(SpeciesItem) else IF_IS_CLASS(SpeciesMove) else IF_IS_CLASS(Store) else IF_IS_CLASS(Tile) else IF_IS_CLASS(Time) else IF_IS_CLASS(Trainer) else IF_IS_CLASS(Type) #undef IF_IS_CLASS } return NULL; } Object* PokeModTreeItem::cut() { // TODO: actually cut the item if (obj) { QString name(obj->className()); #define IF_IS_CLASS(class) if (name == #class) return new ::class(obj->pokemod(), *static_cast< ::class* >(obj), obj->id()); IF_IS_CLASS(Ability) else IF_IS_CLASS(AbilityEffect) else IF_IS_CLASS(Author) else IF_IS_CLASS(Badge) else IF_IS_CLASS(CoinList) else IF_IS_CLASS(CoinListObject) else IF_IS_CLASS(Dialog) else IF_IS_CLASS(EggGroup) else IF_IS_CLASS(Item) else IF_IS_CLASS(ItemEffect) else IF_IS_CLASS(ItemType) else IF_IS_CLASS(Map) else IF_IS_CLASS(MapEffect) else IF_IS_CLASS(MapTrainer) else IF_IS_CLASS(MapTrainerTeamMember) else IF_IS_CLASS(MapWarp) else IF_IS_CLASS(MapWildList) else IF_IS_CLASS(MapWildListEncounter) else IF_IS_CLASS(Move) else IF_IS_CLASS(MoveEffect) else IF_IS_CLASS(Nature) else if (name == "Pokemod") return new Pokemod(*static_cast(obj)); else if (name == "Rules") return new Rules(obj->pokemod()); else IF_IS_CLASS(Species) else IF_IS_CLASS(SpeciesAbility) else IF_IS_CLASS(SpeciesEvolution) else IF_IS_CLASS(SpeciesItem) else IF_IS_CLASS(SpeciesMove) else IF_IS_CLASS(Store) else IF_IS_CLASS(Tile) else IF_IS_CLASS(Time) else IF_IS_CLASS(Trainer) else IF_IS_CLASS(Type) #undef IF_IS_CLASS } return NULL; }*/