/* * Copyright 2008-2009 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 "NatureUI.h" // Sigmod includes #include "../sigmod/Nature.h" #include "../sigmod/Rules.h" #include "../sigmod/Sigmod.h" // Qt includes #include Sigmodr::NatureUI::NatureUI(Sigmod::Nature* nature, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(nature, new Sigmod::Nature(*nature)); } Sigmodr::NatureUI::~NatureUI() { } void Sigmodr::NatureUI::initGui() { varStat->horizontalHeader()->setResizeMode(QHeaderView::Stretch); } void Sigmodr::NatureUI::refreshGui() { const bool isSplit = sigmod()->rules()->specialSplit(); varStat->clear(); varStat->setRowCount((isSplit ? Sigmod::ST_SpecialDefense : Sigmod::ST_Special) - Sigmod::ST_Attack + 1); varStat->setVerticalHeaderLabels((isSplit ? Sigmod::StatGSCStr : Sigmod::StatRBYStr).mid(Sigmod::ST_Attack, (isSplit ? Sigmod::ST_SpecialDefense : Sigmod::ST_Special) - Sigmod::ST_Attack + 1)); varStat->setColumnCount(1); varStat->setHorizontalHeaderLabels(QStringList() << "Multiplier"); varStat->verticalHeaderItem(Sigmod::ST_Attack - Sigmod::ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(Sigmod::ST_Attack)); varStat->verticalHeaderItem(Sigmod::ST_Defense - Sigmod::ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(Sigmod::ST_Defense)); varStat->verticalHeaderItem(Sigmod::ST_Speed - Sigmod::ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(Sigmod::ST_Speed)); if (isSplit) { varStat->verticalHeaderItem(Sigmod::ST_SpecialAttack - Sigmod::ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(Sigmod::ST_SpecialAttack)); varStat->verticalHeaderItem(Sigmod::ST_SpecialDefense - Sigmod::ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(Sigmod::ST_SpecialDefense)); } else varStat->verticalHeaderItem(Sigmod::ST_Special - Sigmod::ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(Sigmod::ST_Special)); varStat->setItem(Sigmod::ST_Attack - Sigmod::ST_Attack, 0, new QTableWidgetItem); varStat->setItem(Sigmod::ST_Defense- Sigmod::ST_Attack, 0, new QTableWidgetItem); varStat->setItem(Sigmod::ST_Speed - Sigmod::ST_Attack, 0, new QTableWidgetItem); if (isSplit) { varStat->setItem(Sigmod::ST_SpecialAttack - Sigmod::ST_Attack, 0, new QTableWidgetItem); varStat->setItem(Sigmod::ST_SpecialDefense - Sigmod::ST_Attack, 0, new QTableWidgetItem); } else varStat->setItem(Sigmod::ST_Special - Sigmod::ST_Attack, 0, new QTableWidgetItem); QTableWidgetItem* item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); varStat->setItem(Sigmod::ST_Attack - Sigmod::ST_Attack, 0, item); varStat->setCurrentItem(item); item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); varStat->setItem(Sigmod::ST_Defense- Sigmod::ST_Attack, 0, item); item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); varStat->setItem(Sigmod::ST_Speed - Sigmod::ST_Attack, 0, item); if (isSplit) { item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); varStat->setItem(Sigmod::ST_SpecialAttack - Sigmod::ST_Attack, 0, item); item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); varStat->setItem(Sigmod::ST_SpecialDefense - Sigmod::ST_Attack, 0, item); } else { item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); varStat->setItem(Sigmod::ST_Special - Sigmod::ST_Attack, 0, item); } } void Sigmodr::NatureUI::setGui() { varName->setText(qobject_cast(modified())->name()); varStat->item(Sigmod::ST_Attack - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(Sigmod::ST_Attack), 'g', 7)); varStat->item(Sigmod::ST_Defense - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(Sigmod::ST_Defense), 'g', 7)); varStat->item(Sigmod::ST_Speed - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(Sigmod::ST_Speed), 'g', 7)); if (sigmod()->rules()->specialSplit()) { varStat->item(Sigmod::ST_SpecialAttack - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(Sigmod::ST_SpecialAttack), 'g', 7)); varStat->item(Sigmod::ST_SpecialDefense - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(Sigmod::ST_SpecialDefense), 'g', 7)); } else varStat->item(Sigmod::ST_Special - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(Sigmod::ST_Special), 'g', 7)); varStatMultiplier->setValue(qobject_cast(modified())->stat(varStat->verticalHeaderItem(varStat->currentRow())->data(Qt::UserRole).value())); varWeight->setValue(qobject_cast(modified())->weight()); } void Sigmodr::NatureUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::NatureUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void Sigmodr::NatureUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); qobject_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void Sigmodr::NatureUI::on_varStat_currentCellChanged(const int row) { varStatMultiplier->setValue(qobject_cast(modified())->stat(varStat->verticalHeaderItem(row)->data(Qt::UserRole).value())); } void Sigmodr::NatureUI::on_varStatMultiplier_valueChanged(const Sigcore::Fraction& multiplier) { qobject_cast(modified())->setStat(varStat->verticalHeaderItem(varStat->currentRow())->data(Qt::UserRole).value(), multiplier); } void Sigmodr::NatureUI::on_varWeight_valueChanged(const int weight) { qobject_cast(modified())->setWeight(weight); }