/* * 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" // Sigmodr core widget includes #include // Sigmod includes #include #include #include // KDE includes #include #include // Qt includes #include #include #include #include #include using namespace Sigcore; using namespace Sigmod; using namespace Sigmodr::CoreWidgets; using namespace Sigmodr::Widgets; NatureUI::NatureUI(Nature* nature, QWidget* parent) : ObjectUI(parent) { setObjects(nature, new Nature(*nature)); } void NatureUI::initGui() { QFile file(":/gui/nature.ui"); file.open(QFile::ReadOnly); QWidget *formWidget = QUiLoader().load(&file, this); file.close(); ui_name = formWidget->findChild("varName"); ui_stat = formWidget->findChild("varStat"); ui_statMultiplier = formWidget->findChild("varStatMultiplier"); ui_weight = formWidget->findChild("varWeight"); connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); connect(ui_stat, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(statChanged(int))); connect(ui_statMultiplier, SIGNAL(valueChanged(Sigcore::Fraction)), this, SLOT(statMultiplierChanged(Sigcore::Fraction))); connect(ui_weight, SIGNAL(valueChanged(int)), this, SLOT(weightChanged(int))); QVBoxLayout* layout = new QVBoxLayout; layout->addWidget(formWidget); setLayout(layout); ui_stat->horizontalHeader()->setResizeMode(QHeaderView::Stretch); } void NatureUI::refreshGui() { const bool isSplit = game()->rules()->specialSplit(); ui_stat->clear(); ui_stat->setRowCount((isSplit ? ST_SpecialDefense : ST_Special) - ST_Attack + 1); ui_stat->setVerticalHeaderLabels((isSplit ? StatGSCStr : StatRBYStr).mid(ST_Attack, (isSplit ? ST_SpecialDefense : ST_Special) - ST_Attack + 1)); ui_stat->setColumnCount(1); ui_stat->setHorizontalHeaderLabels(QStringList() << "Multiplier"); ui_stat->verticalHeaderItem(ST_Attack - ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(ST_Attack)); ui_stat->verticalHeaderItem(ST_Defense - ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(ST_Defense)); ui_stat->verticalHeaderItem(ST_Speed - ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(ST_Speed)); if (isSplit) { ui_stat->verticalHeaderItem(ST_SpecialAttack - ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(ST_SpecialAttack)); ui_stat->verticalHeaderItem(ST_SpecialDefense - ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(ST_SpecialDefense)); } else ui_stat->verticalHeaderItem(ST_Special - ST_Attack)->setData(Qt::UserRole, QVariant::fromValue(ST_Special)); ui_stat->setItem(ST_Attack - ST_Attack, 0, new QTableWidgetItem); ui_stat->setItem(ST_Defense- ST_Attack, 0, new QTableWidgetItem); ui_stat->setItem(ST_Speed - ST_Attack, 0, new QTableWidgetItem); if (isSplit) { ui_stat->setItem(ST_SpecialAttack - ST_Attack, 0, new QTableWidgetItem); ui_stat->setItem(ST_SpecialDefense - ST_Attack, 0, new QTableWidgetItem); } else ui_stat->setItem(ST_Special - ST_Attack, 0, new QTableWidgetItem); QTableWidgetItem* item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); ui_stat->setItem(ST_Attack - ST_Attack, 0, item); ui_stat->setCurrentItem(item); item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); ui_stat->setItem(ST_Defense- ST_Attack, 0, item); item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); ui_stat->setItem(ST_Speed - ST_Attack, 0, item); if (isSplit) { item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); ui_stat->setItem(ST_SpecialAttack - ST_Attack, 0, item); item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); ui_stat->setItem(ST_SpecialDefense - ST_Attack, 0, item); } else { item = new QTableWidgetItem; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); ui_stat->setItem(ST_Special - ST_Attack, 0, item); } } void NatureUI::setGui() { ui_name->setText(qobject_cast(modified())->name()); ui_stat->item(ST_Attack - ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(ST_Attack), 'g', 7)); ui_stat->item(ST_Defense - ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(ST_Defense), 'g', 7)); ui_stat->item(ST_Speed - ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(ST_Speed), 'g', 7)); if (game()->rules()->specialSplit()) { ui_stat->item(ST_SpecialAttack - ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(ST_SpecialAttack), 'g', 7)); ui_stat->item(ST_SpecialDefense - ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(ST_SpecialDefense), 'g', 7)); } else ui_stat->item(ST_Special - ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast(modified())->stat(ST_Special), 'g', 7)); ui_statMultiplier->setValue(qobject_cast(modified())->stat(ui_stat->verticalHeaderItem(ui_stat->currentRow())->data(Qt::UserRole).value())); ui_weight->setValue(qobject_cast(modified())->weight()); } void NatureUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void NatureUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void NatureUI::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); qobject_cast(modified())->setName(name); ui_name->setCursorPosition(cursor); } void NatureUI::statChanged(const int row) { ui_statMultiplier->setValue(qobject_cast(modified())->stat(ui_stat->verticalHeaderItem(row)->data(Qt::UserRole).value())); } void NatureUI::statMultiplierChanged(const Fraction& multiplier) { qobject_cast(modified())->setStat(ui_stat->verticalHeaderItem(ui_stat->currentRow())->data(Qt::UserRole).value(), multiplier); } void NatureUI::weightChanged(const int weight) { qobject_cast(modified())->setWeight(weight); }