/* * 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 "MapTrainerUI.h" // Sigmod includes #include "../sigmod/MapTrainer.h" #include "../sigmod/MapTrainerTeamMember.h" #include "../sigmod/Rules.h" #include "../sigmod/Sigmod.h" #include "../sigmod/Species.h" #include "../sigmod/Trainer.h" Sigmodr::MapTrainerUI::MapTrainerUI(Sigmod::MapTrainer* trainer, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(trainer, new Sigmod::MapTrainer(*trainer)); } Sigmodr::MapTrainerUI::~MapTrainerUI() { } void Sigmodr::MapTrainerUI::refreshGui() { const bool blockedTrainerClass = varTrainerClass->blockSignals(true); varTrainerClass->clear(); for (int i = 0; i < sigmod()->trainerCount(); ++i) { const Sigmod::Trainer* trainer = sigmod()->trainer(i); varTrainerClass->addItem(trainer->name(), trainer->id()); } varTrainerClass->blockSignals(blockedTrainerClass); varNumberFight->setMaximum(sigmod()->rules()->maxFight()); const bool blockedLeadTeamMember = varLeadTeamMember->blockSignals(true); varLeadTeamMember->clear(); for (int i = 0; i < qobject_cast(original())->teamMemberCount(); ++i) { const Sigmod::MapTrainerTeamMember* teamMember = qobject_cast(original())->teamMember(i); const Sigmod::Species* species = sigmod()->species(teamMember->species()); if (species) varLeadTeamMember->addItem(species->name(), teamMember->id()); } varLeadTeamMember->blockSignals(blockedLeadTeamMember); } void Sigmodr::MapTrainerUI::setGui() { varName->setText(qobject_cast(modified())->name()); varTrainerClass->setCurrentIndex(varTrainerClass->findData(qobject_cast(modified())->trainerClass())); varNumberFight->setValue(qobject_cast(modified())->numberFight()); varScript->setValue(qobject_cast(modified())->script()); varLeadTeamMember->setCurrentIndex(varLeadTeamMember->findData(qobject_cast(modified())->leadTeamMember())); } void Sigmodr::MapTrainerUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::MapTrainerUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void Sigmodr::MapTrainerUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); qobject_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void Sigmodr::MapTrainerUI::on_varTrainerClass_activated(const int trainerClass) { qobject_cast(modified())->setTrainerClass(varTrainerClass->itemData(trainerClass).toInt()); } void Sigmodr::MapTrainerUI::on_varNumberFight_valueChanged(const int numberFight) { qobject_cast(modified())->setNumberFight(numberFight); } void Sigmodr::MapTrainerUI::on_varScript_valueChanged(const Sigcore::Script& script) { qobject_cast(modified())->setScript(script); } void Sigmodr::MapTrainerUI::on_varLeadTeamMember_activated(const int leadTeamMember) { qobject_cast(modified())->setLeadTeamMember(leadTeamMember); }