/* * 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" // Pokemod includes #include "../pokemod/Item.h" #include "../pokemod/MapTrainerTeamMember.h" #include "../pokemod/Nature.h" #include "../pokemod/Pokemod.h" #include "../pokemod/Species.h" MapTrainerTeamMemberUI::MapTrainerTeamMemberUI(MapTrainerTeamMember* teamMember, QWidget* parent) : ObjectUI(parent) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(teamMember, new MapTrainerTeamMember(*teamMember)); connect(modified(), SIGNAL(error(const QString&)), this, SLOT(setGui())); connect(modified(), SIGNAL(error(const QString&)), this, SLOT(errorMessage(const QString&))); connect(modified(), SIGNAL(warning(const QString&)), this, SLOT(warningMessage(const QString&))); connect(modified(), SIGNAL(changed()), this, SLOT(setChanged())); init(); } MapTrainerTeamMemberUI::~MapTrainerTeamMemberUI() { } void MapTrainerTeamMemberUI::refreshGui() { varSpecies->clear(); for (int i = 0; i < static_cast(original()->pokemod())->speciesCount(); ++i) { const Species* species = static_cast(original()->pokemod())->species(i); varSpecies->addItem(species->name()); varSpecies->setItemData(i, species->id()); } varLevel->setMaximum(static_cast(original()->pokemod())->rules()->maxLevel()); } void MapTrainerTeamMemberUI::setGui() { varSpecies->setCurrentIndex(varSpecies->findData(static_cast(modified())->species())); varLevel->setValue(static_cast(modified())->level()); varNature->setCurrentIndex(varNature->findData(static_cast(modified())->nature())); for (int i = 0; i < varItems->count(); ++i) { QListWidgetItem* widgetItem = varItems->item(i); widgetItem->setSelected(static_cast(modified())->item(widgetItem->data(Qt::UserRole).toInt())); } varNature->clear(); if (static_cast(original()->pokemod())->rules()->natureAllowed()) { for (int i = 0; i < static_cast(original()->pokemod())->natureCount(); ++i) { const Nature* nature = static_cast(original()->pokemod())->nature(i); varNature->addItem(nature->name()); varNature->setItemData(i, nature->id()); } } else boxNature->setEnabled(false); varItems->clear(); if (static_cast(original()->pokemod())->rules()->holdItems()) { for (int i = 0; i < static_cast(original()->pokemod())->itemCount(); ++i) { const Item* item = static_cast(original()->pokemod())->item(i); QListWidgetItem* widgetItem = new QListWidgetItem(item->name(), varItems); widgetItem->setData(Qt::UserRole, item->id()); } } else boxItems->setEnabled(false); } void MapTrainerTeamMemberUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void MapTrainerTeamMemberUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void MapTrainerTeamMemberUI::on_varSpecies_currentIndexChanged(const int species) { static_cast(modified())->setSpecies(varSpecies->itemData(species).toInt()); } void MapTrainerTeamMemberUI::on_varLevel_valueChanged(const int level) { static_cast(modified())->setLevel(level); } void MapTrainerTeamMemberUI::on_varNature_currentIndexChanged(const int nature) { static_cast(modified())->setNature(varNature->itemData(nature).toInt()); } void MapTrainerTeamMemberUI::on_varItems_itemSelectionChanged() { for (int i = 0; i < varItems->count(); ++i) { const QListWidgetItem* widgetItem = varItems->item(i); static_cast(modified())->setItem(widgetItem->data(Qt::UserRole).toInt(), widgetItem->isSelected()); } }