summaryrefslogtreecommitdiffstats
path: root/pokemodr/MapTrainerUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-05-15 03:12:36 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-05-15 03:12:36 +0000
commit3e72425d8566687631cb7b7fc1b299efd8a4877e (patch)
tree6bbd08723dd89d021ccebd07f4e96fbde1f44646 /pokemodr/MapTrainerUI.cpp
parente445583ac47ef5416565c91142eec38a09f731cc (diff)
downloadsigen-3e72425d8566687631cb7b7fc1b299efd8a4877e.tar.gz
sigen-3e72425d8566687631cb7b7fc1b299efd8a4877e.tar.xz
sigen-3e72425d8566687631cb7b7fc1b299efd8a4877e.zip
[FIX] Added the MapTrainer code (forgot to commit)
[FIX] Signal and slots in the main window class git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@131 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/MapTrainerUI.cpp')
-rw-r--r--pokemodr/MapTrainerUI.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/pokemodr/MapTrainerUI.cpp b/pokemodr/MapTrainerUI.cpp
new file mode 100644
index 00000000..8ad8a32c
--- /dev/null
+++ b/pokemodr/MapTrainerUI.cpp
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2008 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 "MapTrainerUI.h"
+
+// Pokemod includes
+#include "../pokemod/Dialog.h"
+#include "../pokemod/Map.h"
+#include "../pokemod/MapTrainer.h"
+#include "../pokemod/MapTrainerTeamMember.h"
+#include "../pokemod/Pokemod.h"
+#include "../pokemod/Species.h"
+#include "../pokemod/Trainer.h"
+
+MapTrainerUI::MapTrainerUI(MapTrainer* trainer, QWidget* parent) :
+ ObjectUI(parent)
+{
+ setupUi(this);
+ QMetaObject::connectSlotsByName(this);
+ setObjects(trainer, new MapTrainer(*trainer));
+ connect(this, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool)));
+ connect(modified(), SIGNAL(error(const QString&)), this, SLOT(setGui()));
+ connect(modified(), SIGNAL(error(const QString&)), this, SLOT(errorMessage(const QString&)));
+ connect(modified(), SIGNAL(warning(const QString&)), this, SLOT(warningMessage(const QString&)));
+ connect(modified(), SIGNAL(changed()), this, SLOT(setChanged()));
+ init();
+}
+
+MapTrainerUI::~MapTrainerUI()
+{
+}
+
+void MapTrainerUI::initGui()
+{
+ varDirection->addItems(Pokemod::DirectionStr.mid(0, Pokemod::D_End));
+}
+
+void MapTrainerUI::refreshGui()
+{
+ varTrainerClass->clear();
+ for (int i = 0; i < static_cast<const Pokemod*>(original()->pokemod())->trainerCount(); ++i)
+ {
+ const Trainer* trainer = static_cast<const Pokemod*>(original()->pokemod())->trainer(i);
+ varTrainerClass->addItem(trainer->name());
+ varTrainerClass->setItemData(i, trainer->id());
+ }
+ varCoordinate->setMaximum(static_cast<const Map*>(original()->parent())->size());
+ varNumberFight->setMaximum(static_cast<const Pokemod*>(original()->pokemod())->rules()->maxFight());
+ varDialog->clear();
+ for (int i = 0; i < static_cast<const Pokemod*>(original()->pokemod())->dialogCount(); ++i)
+ {
+ const Dialog* dialog = static_cast<const Pokemod*>(original()->pokemod())->dialog(i);
+ varDialog->addItem(dialog->dialog().mid(0, 25));
+ varDialog->setItemData(i, dialog->id());
+ }
+ varLeadTeamMember->clear();
+ for (int i = 0; i < static_cast<MapTrainer*>(original())->teamMemberCount(); ++i)
+ {
+ const MapTrainerTeamMember* teamMember = static_cast<MapTrainer*>(original())->teamMember(i);
+ const Species* species = static_cast<const Pokemod*>(original()->pokemod())->species(teamMember->species());
+ if (species)
+ varLeadTeamMember->addItem(species->name());
+ else
+ varLeadTeamMember->addItem("Invalid Species");
+ varLeadTeamMember->setItemData(i, teamMember->id());
+ }
+}
+
+void MapTrainerUI::setGui()
+{
+ varName->setText(static_cast<MapTrainer*>(modified())->name());
+ varTrainerClass->setCurrentIndex(varTrainerClass->findData(static_cast<MapTrainer*>(modified())->trainerClass()));
+ varCoordinate->setValue(static_cast<MapTrainer*>(modified())->coordinate());
+ varSight->setValue(static_cast<MapTrainer*>(modified())->sight());
+ varDirection->setCurrentIndex(static_cast<MapTrainer*>(modified())->direction());
+ varNumberFight->setValue(static_cast<MapTrainer*>(modified())->numberFight());
+ boxFlag->setChecked((static_cast<MapTrainer*>(modified())->flag().status() == Flag::Ignore) ? Qt::Unchecked : Qt::Checked);
+ if (boxFlag->isChecked())
+ {
+ varFlag->setValue(static_cast<MapTrainer*>(modified())->flag().flag());
+ varState->setCheckState((static_cast<MapTrainer*>(modified())->flag().status() == Flag::On) ? Qt::Checked : Qt::Unchecked);
+ }
+ varDialog->setCurrentIndex(varDialog->findData(static_cast<MapTrainer*>(modified())->dialog()));
+ varLeadTeamMember->setCurrentIndex(varLeadTeamMember->findData(static_cast<MapTrainer*>(modified())->leadTeamMember()));
+}
+
+void MapTrainerUI::on_buttonApply_clicked()
+{
+ *static_cast<MapTrainer*>(original()) = *static_cast<MapTrainer*>(modified());
+ emit(changed(false));
+}
+
+void MapTrainerUI::on_buttonDiscard_clicked()
+{
+ *static_cast<MapTrainer*>(modified()) = *static_cast<MapTrainer*>(original());
+ setGui();
+ emit(changed(false));
+}
+
+void MapTrainerUI::on_varName_textChanged(const QString& name)
+{
+ static_cast<MapTrainer*>(modified())->setName(name);
+}
+
+void MapTrainerUI::on_varTrainerClass_currentIndexChanged(const int trainerClass)
+{
+ static_cast<MapTrainer*>(modified())->setTrainerClass(varTrainerClass->itemData(trainerClass).toInt());
+}
+
+void MapTrainerUI::on_varCoordinate_valueChanged(const Point& coordinate)
+{
+ static_cast<MapTrainer*>(modified())->setCoordinate(coordinate);
+}
+
+void MapTrainerUI::on_varSight_valueChanged(const int sight)
+{
+ static_cast<MapTrainer*>(modified())->setSight(sight);
+}
+
+void MapTrainerUI::on_varDirection_currentIndexChanged(const int direction)
+{
+ static_cast<MapTrainer*>(modified())->setDirection(direction);
+}
+
+void MapTrainerUI::on_varNumberFight_valueChanged(const int numberFight)
+{
+ static_cast<MapTrainer*>(modified())->setNumberFight(numberFight);
+}
+
+void MapTrainerUI::on_boxFlag_toggled(const bool flagUsed)
+{
+ if (!flagUsed)
+ static_cast<MapTrainer*>(modified())->setFlag(Flag(varFlag->value(), Flag::Ignore));
+}
+
+void MapTrainerUI::on_varFlag_valueChanged(const int flag)
+{
+ static_cast<MapTrainer*>(modified())->setFlag(Flag(flag, boxFlag->isChecked() ? Flag::Ignore : (varState->isChecked() ? Flag::On : Flag::Off)));
+}
+
+void MapTrainerUI::on_varState_toggled(const bool status)
+{
+ static_cast<MapTrainer*>(modified())->setFlag(Flag(varFlag->value(), status ? Flag::On : Flag::Off));
+}
+
+void MapTrainerUI::on_varDialog_currentIndexChanged(const int dialog)
+{
+ static_cast<MapTrainer*>(modified())->setDialog(varDialog->itemData(dialog).toInt());
+}
+
+void MapTrainerUI::on_varLeadTeamMember_currentIndexChanged(const int leadTeamMember)
+{
+ static_cast<MapTrainer*>(modified())->setLeadTeamMember(leadTeamMember);
+}