summaryrefslogtreecommitdiffstats
path: root/sigmodr/widgets/GameUI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigmodr/widgets/GameUI.cpp')
-rw-r--r--sigmodr/widgets/GameUI.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/sigmodr/widgets/GameUI.cpp b/sigmodr/widgets/GameUI.cpp
new file mode 100644
index 00000000..fd8551e0
--- /dev/null
+++ b/sigmodr/widgets/GameUI.cpp
@@ -0,0 +1,125 @@
+/*
+ * 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 "SigmodUI.h"
+
+// Sigmodr widget includes
+#include "TypechartModel.h"
+
+// Sigmod includes
+#include <sigmod/Map.h>
+#include <sigmod/MapWarp.h>
+#include <sigmod/Sigmod.h>
+#include <sigmod/Type.h>
+
+Sigmodr::Widgets::SigmodUI::SigmodUI(Sigmod::Sigmod* sigmod, QWidget* parent) :
+ ObjectUI(parent),
+ m_changingMult(true)
+{
+ setupUi(this);
+ setObjects(sigmod, new Sigmod::Sigmod(*sigmod));
+}
+
+Sigmodr::Widgets::SigmodUI::~SigmodUI()
+{
+}
+
+void Sigmodr::Widgets::SigmodUI::initGui()
+{
+ QStringList types;
+ for (int i = 0; i < qobject_cast<Sigmod::Sigmod*>(original())->typeCount(); ++i)
+ types << qobject_cast<Sigmod::Sigmod*>(original())->type(i)->name();
+ varTypechart->setModel(new TypechartModel(qobject_cast<Sigmod::Sigmod*>(modified())->typechart(), types));
+}
+
+void Sigmodr::Widgets::SigmodUI::refreshGui()
+{
+ varEffectiveness->setEnabled(false);
+}
+
+void Sigmodr::Widgets::SigmodUI::setGui()
+{
+ varTitle->setText(qobject_cast<Sigmod::Sigmod*>(modified())->title());
+ varVersion->setText(qobject_cast<Sigmod::Sigmod*>(modified())->version());
+ varDescription->setText(qobject_cast<Sigmod::Sigmod*>(modified())->description());
+ varSinglePlayer->setCheckState(qobject_cast<Sigmod::Sigmod*>(modified())->singlePlayer() ? Qt::Checked : Qt::Unchecked);
+ varStartScript->setValue(qobject_cast<Sigmod::Sigmod*>(modified())->startScript());
+}
+
+void Sigmodr::Widgets::SigmodUI::apply()
+{
+ *qobject_cast<Sigmod::Sigmod*>(original()) = *qobject_cast<Sigmod::Sigmod*>(modified());
+ emit(changed(false));
+}
+
+void Sigmodr::Widgets::SigmodUI::discard()
+{
+ *qobject_cast<Sigmod::Sigmod*>(modified()) = *qobject_cast<Sigmod::Sigmod*>(original());
+ setGui();
+ qobject_cast<TypechartModel*>(varTypechart->model())->discarded();
+ emit(changed(false));
+}
+
+void Sigmodr::Widgets::SigmodUI::on_varTitle_textChanged(const QString& title)
+{
+ const int cursor = varTitle->cursorPosition();
+ qobject_cast<Sigmod::Sigmod*>(modified())->setTitle(title);
+ varTitle->setCursorPosition(cursor);
+}
+
+void Sigmodr::Widgets::SigmodUI::on_varVersion_textChanged(const QString& version)
+{
+ const int cursor = varVersion->cursorPosition();
+ qobject_cast<Sigmod::Sigmod*>(modified())->setVersion(version);
+ varVersion->setCursorPosition(cursor);
+}
+
+void Sigmodr::Widgets::SigmodUI::on_varDescription_textChanged(const QString& description)
+{
+ const int cursor = varDescription->cursorPosition();
+ qobject_cast<Sigmod::Sigmod*>(modified())->setDescription(description);
+ varDescription->setCursorPosition(cursor);
+}
+
+void Sigmodr::Widgets::SigmodUI::on_varSinglePlayer_clicked(const bool singlePlayer)
+{
+ qobject_cast<Sigmod::Sigmod*>(modified())->setSinglePlayer(singlePlayer);
+}
+
+void Sigmodr::Widgets::SigmodUI::on_varStartScript_valueChanged(const Sigcore::Script& startScript)
+{
+ qobject_cast<Sigmod::Sigmod*>(modified())->setStartScript(startScript);
+}
+
+void Sigmodr::Widgets::SigmodUI::on_varTypechart_clicked(const QModelIndex& index)
+{
+ m_index = index;
+ m_changingMult = true;
+ varEffectiveness->setEnabled(true);
+ labelTypes->setText(QString("%1 vs. %2").arg(varTypechart->model()->headerData(index.row(), Qt::Vertical, Qt::DisplayRole).toString()).arg(varTypechart->model()->headerData(index.column(), Qt::Horizontal, Qt::DisplayRole).toString()));
+ varEffectiveness->setValue(varTypechart->model()->data(m_index, Qt::EditRole).value<Sigcore::Fraction>());
+}
+
+void Sigmodr::Widgets::SigmodUI::on_varEffectiveness_valueChanged(const Sigcore::Fraction& multiplier)
+{
+ varTypechart->model()->setData(m_index, QVariant::fromValue(multiplier), Qt::EditRole);
+ if (!m_changingMult)
+ emit(changed());
+ m_changingMult = false;
+ setGui();
+}