summaryrefslogtreecommitdiffstats
path: root/sigmodr/widgets/NatureUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-02-23 11:20:47 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-02-23 11:20:47 -0500
commit7aff48012c3040a675543a0ff3d23af6cb8a8638 (patch)
tree6dd17b90d1f1c6ba9b0b7c5ddc40c2a849c25286 /sigmodr/widgets/NatureUI.cpp
parent25ec942048336dde5e1a17e6c75e15e4f8d8290d (diff)
downloadsigen-7aff48012c3040a675543a0ff3d23af6cb8a8638.tar.gz
sigen-7aff48012c3040a675543a0ff3d23af6cb8a8638.tar.xz
sigen-7aff48012c3040a675543a0ff3d23af6cb8a8638.zip
Started restructuring how sigmodr is built and moving things into libraries
Diffstat (limited to 'sigmodr/widgets/NatureUI.cpp')
-rw-r--r--sigmodr/widgets/NatureUI.cpp150
1 files changed, 150 insertions, 0 deletions
diff --git a/sigmodr/widgets/NatureUI.cpp b/sigmodr/widgets/NatureUI.cpp
new file mode 100644
index 00000000..44f340d6
--- /dev/null
+++ b/sigmodr/widgets/NatureUI.cpp
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+// Header include
+#include "NatureUI.h"
+
+// Sigmod includes
+#include "../sigmod/Nature.h"
+#include "../sigmod/Rules.h"
+#include "../sigmod/Sigmod.h"
+
+// Qt includes
+#include <QtGui/QHeaderView>
+
+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<Sigmod::Nature*>(modified())->name());
+ varStat->item(Sigmod::ST_Attack - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast<Sigmod::Nature*>(modified())->stat(Sigmod::ST_Attack), 'g', 7));
+ varStat->item(Sigmod::ST_Defense - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast<Sigmod::Nature*>(modified())->stat(Sigmod::ST_Defense), 'g', 7));
+ varStat->item(Sigmod::ST_Speed - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast<Sigmod::Nature*>(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<Sigmod::Nature*>(modified())->stat(Sigmod::ST_SpecialAttack), 'g', 7));
+ varStat->item(Sigmod::ST_SpecialDefense - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast<Sigmod::Nature*>(modified())->stat(Sigmod::ST_SpecialDefense), 'g', 7));
+ }
+ else
+ varStat->item(Sigmod::ST_Special - Sigmod::ST_Attack, 0)->setData(Qt::DisplayRole, QString::number(qobject_cast<Sigmod::Nature*>(modified())->stat(Sigmod::ST_Special), 'g', 7));
+ varStatMultiplier->setValue(qobject_cast<Sigmod::Nature*>(modified())->stat(varStat->verticalHeaderItem(varStat->currentRow())->data(Qt::UserRole).value<Sigmod::Stat>()));
+ varWeight->setValue(qobject_cast<Sigmod::Nature*>(modified())->weight());
+}
+
+void Sigmodr::NatureUI::apply()
+{
+ *qobject_cast<Sigmod::Nature*>(original()) = *qobject_cast<Sigmod::Nature*>(modified());
+ emit(changed(false));
+}
+
+void Sigmodr::NatureUI::discard()
+{
+ *qobject_cast<Sigmod::Nature*>(modified()) = *qobject_cast<Sigmod::Nature*>(original());
+ setGui();
+ emit(changed(false));
+}
+
+void Sigmodr::NatureUI::on_varName_textChanged(const QString& name)
+{
+ const int cursor = varName->cursorPosition();
+ qobject_cast<Sigmod::Nature*>(modified())->setName(name);
+ varName->setCursorPosition(cursor);
+}
+
+void Sigmodr::NatureUI::on_varStat_currentCellChanged(const int row)
+{
+ varStatMultiplier->setValue(qobject_cast<Sigmod::Nature*>(modified())->stat(varStat->verticalHeaderItem(row)->data(Qt::UserRole).value<Sigmod::Stat>()));
+}
+
+void Sigmodr::NatureUI::on_varStatMultiplier_valueChanged(const Sigcore::Fraction& multiplier)
+{
+ qobject_cast<Sigmod::Nature*>(modified())->setStat(varStat->verticalHeaderItem(varStat->currentRow())->data(Qt::UserRole).value<Sigmod::Stat>(), multiplier);
+}
+
+void Sigmodr::NatureUI::on_varWeight_valueChanged(const int weight)
+{
+ qobject_cast<Sigmod::Nature*>(modified())->setWeight(weight);
+}