/* * 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 . */ // Header include #include "MapTrainerTeamMemberUI.h" // Sigmod includes #include "../sigmod/Ability.h" #include "../sigmod/Item.h" #include "../sigmod/MapTrainerTeamMember.h" #include "../sigmod/Move.h" #include "../sigmod/Nature.h" #include "../sigmod/Rules.h" #include "../sigmod/Sigmod.h" #include "../sigmod/Species.h" Sigmodr::MapTrainerTeamMemberUI::MapTrainerTeamMemberUI(Sigmod::MapTrainerTeamMember* teamMember, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(teamMember, new Sigmod::MapTrainerTeamMember(*teamMember)); } Sigmodr::MapTrainerTeamMemberUI::~MapTrainerTeamMemberUI() { } void Sigmodr::MapTrainerTeamMemberUI::refreshGui() { const bool blockedSpecies = varSpecies->blockSignals(true); varSpecies->clear(); for (int i = 0; i < sigmod()->speciesCount(); ++i) { const Sigmod::Species* species = sigmod()->species(i); varSpecies->addItem(species->name(), species->id()); } varSpecies->blockSignals(blockedSpecies); varLevel->setMaximum(sigmod()->rules()->maxLevel()); const bool blockedAbilities = varAbilities->blockSignals(true); varAbilities->clear(); for (int i = 0; i < sigmod()->abilityCount(); ++i) { const Sigmod::Ability* ability = sigmod()->ability(i); QListWidgetItem* widgetItem = new QListWidgetItem(ability->name(), varAbilities); widgetItem->setData(Qt::UserRole, ability->id()); } varAbilities->blockSignals(blockedAbilities); boxAbilities->setEnabled(sigmod()->rules()->maxAbilities()); const bool blockedItems = varItems->blockSignals(true); varItems->clear(); for (int i = 0; i < sigmod()->itemCount(); ++i) { const Sigmod::Item* item = sigmod()->item(i); QListWidgetItem* widgetItem = new QListWidgetItem(item->name(), varItems); widgetItem->setData(Qt::UserRole, item->id()); } varItems->blockSignals(blockedItems); boxItems->setEnabled(sigmod()->rules()->maxHeldItems()); const bool blockedMoves = varMoves->blockSignals(true); varMoves->clear(); for (int i = 0; i < sigmod()->abilityCount(); ++i) { const Sigmod::Move* move = sigmod()->move(i); QListWidgetItem* widgetItem = new QListWidgetItem(move->name(), varMoves); widgetItem->setData(Qt::UserRole, move->id()); } varMoves->blockSignals(blockedMoves); const bool blockedNatures = varNatures->blockSignals(true); varNatures->clear(); for (int i = 0; i < sigmod()->natureCount(); ++i) { const Sigmod::Nature* nature = sigmod()->nature(i); QListWidgetItem* widgetItem = new QListWidgetItem(nature->name(), varNatures); widgetItem->setData(Qt::UserRole, nature->id()); } varNatures->blockSignals(blockedNatures); boxNatures->setEnabled(sigmod()->rules()->maxNatures()); } void Sigmodr::MapTrainerTeamMemberUI::setGui() { varSpecies->setCurrentIndex(varSpecies->findData(qobject_cast(modified())->species())); varLevel->setValue(qobject_cast(modified())->level()); for (int i = 0; i < varAbilities->count(); ++i) { QListWidgetItem* widgetItem = varAbilities->item(i); widgetItem->setSelected(qobject_cast(modified())->ability(widgetItem->data(Qt::UserRole).toInt())); } for (int i = 0; i < varItems->count(); ++i) { QListWidgetItem* widgetItem = varItems->item(i); widgetItem->setSelected(qobject_cast(modified())->item(widgetItem->data(Qt::UserRole).toInt())); } for (int i = 0; i < varMoves->count(); ++i) { QListWidgetItem* widgetItem = varMoves->item(i); widgetItem->setSelected(qobject_cast(modified())->move(widgetItem->data(Qt::UserRole).toInt())); } for (int i = 0; i < varNatures->count(); ++i) { QListWidgetItem* widgetItem = varNatures->item(i); widgetItem->setSelected(qobject_cast(modified())->nature(widgetItem->data(Qt::UserRole).toInt())); } } void Sigmodr::MapTrainerTeamMemberUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::MapTrainerTeamMemberUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void Sigmodr::MapTrainerTeamMemberUI::on_varSpecies_activated(const int species) { qobject_cast(modified())->setSpecies(varSpecies->itemData(species).toInt()); } void Sigmodr::MapTrainerTeamMemberUI::on_varLevel_valueChanged(const int level) { qobject_cast(modified())->setLevel(level); } void Sigmodr::MapTrainerTeamMemberUI::on_varAbilities_itemClicked(QListWidgetItem* item) { qobject_cast(modified())->setAbility(item->data(Qt::UserRole).toInt(), item->isSelected()); } void Sigmodr::MapTrainerTeamMemberUI::on_varItems_itemClicked(QListWidgetItem* item) { qobject_cast(modified())->setItem(item->data(Qt::UserRole).toInt(), item->isSelected()); } void Sigmodr::MapTrainerTeamMemberUI::on_varMoves_itemClicked(QListWidgetItem* item) { qobject_cast(modified())->setMove(item->data(Qt::UserRole).toInt(), item->isSelected()); } void Sigmodr::MapTrainerTeamMemberUI::on_varNatures_itemClicked(QListWidgetItem* item) { qobject_cast(modified())->setNature(item->data(Qt::UserRole).toInt(), item->isSelected()); }