/* * 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 "MoveUI.h" // Pokemod includes #include "../pokemod/Move.h" #include "../pokemod/Type.h" #include "../pokemod/Pokemod.h" MoveUI::MoveUI(Move* move, QWidget* parent) : ObjectUI(parent) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(move, new Move(*move)); init(); } MoveUI::~MoveUI() { } void MoveUI::initGui() { varTarget->addItems(Move::TargetStr); varTargetChoice->addItems(Move::ChoiceStr); } void MoveUI::refreshGui() { varType->clear(); for (int i = 0; i < static_cast(original()->pokemod())->typeCount(); ++i) { const Type* type = static_cast(original()->pokemod())->type(i); varType->addItem(type->name()); varType->setItemData(i, type->id()); } varNumTargets->setMaximum(static_cast(original()->pokemod())->rules()->maxFight()); } void MoveUI::setGui() { varName->setText(static_cast(modified())->name()); varAccuracy->setValue(static_cast(modified())->accuracy()); varType->setCurrentIndex(varType->findData(static_cast(modified())->type())); varTarget->setCurrentIndex(static_cast(modified())->target()); varNumTargets->setValue(static_cast(modified())->numTargets()); varTargetChoice->setCurrentIndex(static_cast(modified())->targetChoice()); varSpecial->setChecked(static_cast(modified())->special() ? Qt::Checked : Qt::Unchecked); varIgnoreAccuracy->setChecked(static_cast(modified())->ignoreAccuracy() ? Qt::Checked : Qt::Unchecked); varCanFlinch->setChecked(static_cast(modified())->canFlinch() ? Qt::Checked : Qt::Unchecked); varCanRandom->setChecked(static_cast(modified())->canRandom() ? Qt::Checked : Qt::Unchecked); varCanSnatch->setChecked(static_cast(modified())->canSnatch() ? Qt::Checked : Qt::Unchecked); varMakesSound->setChecked(static_cast(modified())->sound() ? Qt::Checked : Qt::Unchecked); varDescription->setText(static_cast(modified())->description()); } void MoveUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void MoveUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void MoveUI::on_varName_textChanged(const QString& name) { static_cast(modified())->setName(name); } void MoveUI::on_varAccuracy_valueChanged(const Fraction& accuracy) { static_cast(modified())->setAccuracy(accuracy); } void MoveUI::on_varType_currentIndexChanged(const int type) { static_cast(modified())->setType(varType->itemData(type).toInt()); } void MoveUI::on_varPowerPoints_valueChanged(const int powerPoints) { static_cast(modified())->setPowerPoints(powerPoints); } void MoveUI::on_varTarget_currentIndexChanged(const int target) { static_cast(modified())->setTarget(target); } void MoveUI::on_varNumTargets_valueChanged(const int numTargets) { static_cast(modified())->setNumTargets(numTargets); } void MoveUI::on_varTargetChoice_currentIndexChanged(const int targetChoice) { static_cast(modified())->setTargetChoice(targetChoice); } void MoveUI::on_varSpecial_toggled(const bool special) { static_cast(modified())->setSpecial(special); } void MoveUI::on_varIgnoreAccuracy_toggled(const bool ignoreAccuracy) { static_cast(modified())->setIgnoreAccuracy(ignoreAccuracy); } void MoveUI::on_varCanFlinch_toggled(const bool canFlinch) { static_cast(modified())->setCanFlinch(canFlinch); } void MoveUI::on_varCanRandom_toggled(const bool canRandom) { static_cast(modified())->setCanRandom(canRandom); } void MoveUI::on_varCanSnatch_toggled(const bool canSnatch) { static_cast(modified())->setCanSnatch(canSnatch); } void MoveUI::on_varSound_toggled(const bool sound) { static_cast(modified())->setSound(sound); } void MoveUI::on_varDescription_textChanged() { static_cast(modified())->setDescription(varDescription->toPlainText()); }