From 9fea55f75252462c1efbc90372ace45092fe6aca Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 28 Jul 2008 02:44:49 +0000 Subject: [FIX] Added a depth variable to Trainer [FIX] Fixed the Apply/Discard buttons [FIX] Added code to Config in Pokescripting [FIX] Memory leak with MapModel [FIX] FractionWidget was using uninitialized variables (behavior) [FIX] Connection in FileDialog fixed [FIX] Caption is now used for FileDialog [FIX] Main window now uses the KDE standard captioning [FIX] Script connection fixed git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@231 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- Changelog | 15 +++++++++++++++ pokemod/Move.cpp | 3 ++- pokemod/Trainer.cpp | 14 ++++++++++++++ pokemod/Trainer.h | 3 +++ pokemodr/FileDialog.cpp | 3 ++- pokemodr/FractionWidget.cpp | 37 ++++++++++++++++++++++++++----------- pokemodr/FractionWidget.h | 9 ++++++--- pokemodr/PokemodrUI.cpp | 8 ++++++-- pokemodr/ScriptWidget.cpp | 9 ++++++--- pokemodr/TrainerUI.cpp | 6 ++++++ pokemodr/TrainerUI.h | 1 + pokemodr/gui/move.ui | 2 +- pokemodr/gui/pokemodr.ui | 12 +++--------- pokemodr/gui/trainer.ui | 25 +++++++++++++++++++++++++ pokemodr/models/MapModel.cpp | 1 + pokescripting/Config.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ pokescripting/Config.h | 6 ++++++ pokescripting/TrainerWrapper.h | 6 ++++++ 18 files changed, 171 insertions(+), 31 deletions(-) diff --git a/Changelog b/Changelog index ddc56943..2d5ea8a5 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,18 @@ +----------------- +Rev: 231 +Date: 27 July 2008 +User: MathStuf +----------------- +[FIX] Added a depth variable to Trainer +[FIX] Fixed the Apply/Discard buttons +[FIX] Added code to Config in Pokescripting +[FIX] Memory leak with MapModel +[FIX] FractionWidget was using uninitialized variables (behavior) +[FIX] Connection in FileDialog fixed +[FIX] Caption is now used for FileDialog +[FIX] Main window now uses the KDE standard captioning +[FIX] Script connection fixed + ----------------- Rev: 230 Date: 26 July 2008 diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index aba2c897..11387f62 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -70,6 +70,7 @@ void Pokemod::Move::validate() TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); + TEST(setAccuracy, accuracy); TEST(setType, type); TEST(setPowerPoints, powerPoints); TEST_END(); @@ -115,7 +116,7 @@ void Pokemod::Move::setName(const QString& name) void Pokemod::Move::setAccuracy(const Fraction& accuracy) { - if (1 < accuracy) + if (!accuracy || (1 < accuracy)) { emit(error(bounds("accuracy"))); return; diff --git a/pokemod/Trainer.cpp b/pokemod/Trainer.cpp index ec918410..c24315a0 100644 --- a/pokemod/Trainer.cpp +++ b/pokemod/Trainer.cpp @@ -35,6 +35,7 @@ Pokemod::Trainer::Trainer(const Pokemod* parent, const int id) : m_name(""), m_moneyFactor(0), m_skin(192, 128), + m_depth(0), m_teamIntel(Remember), m_moveIntel(Remember), m_itemIntel(Remember), @@ -77,6 +78,7 @@ void Pokemod::Trainer::load(const QDomElement& xml) LOAD(QString, name); LOAD(int, moneyFactor); LOAD(QPixmap, skin); + LOAD(int, depth); LOAD(int, teamIntel); LOAD(int, moveIntel); LOAD(int, itemIntel); @@ -90,6 +92,7 @@ QDomElement Pokemod::Trainer::save() const SAVE(QString, name); SAVE(int, moneyFactor); SAVE(QPixmap, skin); + SAVE(int, depth); SAVE(int, teamIntel); SAVE(int, moveIntel); SAVE(int, itemIntel); @@ -124,6 +127,11 @@ void Pokemod::Trainer::setSkin(const QPixmap& skin) emit(changed()); } +void Pokemod::Trainer::setDepth(const int depth) +{ + CHECK(depth); +} + void Pokemod::Trainer::setTeamIntel(const int teamIntel) { if (End <= teamIntel) @@ -189,6 +197,11 @@ QPixmap Pokemod::Trainer::skin() const return m_skin; } +int Pokemod::Trainer::depth() const +{ + return m_depth; +} + int Pokemod::Trainer::teamIntel() const { return m_teamIntel; @@ -221,6 +234,7 @@ Pokemod::Trainer& Pokemod::Trainer::operator=(const Trainer& rhs) COPY(name); COPY(moneyFactor); COPY(skin); + COPY(depth); COPY(teamIntel); COPY(moveIntel); COPY(itemIntel); diff --git a/pokemod/Trainer.h b/pokemod/Trainer.h index 0437a577..921e0520 100644 --- a/pokemod/Trainer.h +++ b/pokemod/Trainer.h @@ -57,6 +57,7 @@ class POKEMOD_EXPORT Trainer : public Object void setName(const QString& name); void setMoneyFactor(const int moneyFactor); void setSkin(const QPixmap& skin); + void setDepth(const int depth); void setTeamIntel(const int teamIntel); void setMoveIntel(const int moveIntel); void setItemIntel(const int itemIntel); @@ -66,6 +67,7 @@ class POKEMOD_EXPORT Trainer : public Object QString name() const; int moneyFactor() const; QPixmap skin() const; + int depth() const; int teamIntel() const; int moveIntel() const; int itemIntel() const; @@ -77,6 +79,7 @@ class POKEMOD_EXPORT Trainer : public Object QString m_name; int m_moneyFactor; QPixmap m_skin; + int m_depth; int m_teamIntel; int m_moveIntel; int m_itemIntel; diff --git a/pokemodr/FileDialog.cpp b/pokemodr/FileDialog.cpp index 75288c36..c0ab7b16 100644 --- a/pokemodr/FileDialog.cpp +++ b/pokemodr/FileDialog.cpp @@ -31,12 +31,13 @@ Pokemodr::FileDialog::FileDialog(const QSize& size) : KFileDialog(KUrl("kfiledialog:///image"), "", NULL) { + setCaption("Open File"); m_size = size; setOperationMode(KFileDialog::Opening); if (m_size.isValid()) { setPreviewWidget(new KImageFilePreview); - connect(findChild(), SIGNAL(dirActivated(const KFileItem&)), this, SLOT(sizeFilter(const FileItem&))); + connect(findChild(), SIGNAL(dirActivated(const KFileItem&)), this, SLOT(sizeFilter(const KFileItem&))); } } diff --git a/pokemodr/FractionWidget.cpp b/pokemodr/FractionWidget.cpp index 16eac461..873bf567 100644 --- a/pokemodr/FractionWidget.cpp +++ b/pokemodr/FractionWidget.cpp @@ -19,12 +19,15 @@ #include "FractionWidget.h" Pokemodr::FractionWidget::FractionWidget(QWidget* parent, const Pokemod::Fraction& value) : - QWidget(parent) + QWidget(parent), + m_behavior(Any), + m_value(value) { setupUi(this); connect(this, SIGNAL(valueChanged(const Pokemod::Fraction&)), SLOT(updateValue())); connect(this, SIGNAL(valueChanged(const Pokemod::Fraction&)), SLOT(resetRanges())); - setValue(value); + connect(this, SIGNAL(behaviorChanged(const Behavior)), SLOT(resetRanges())); + resetRanges(); } Pokemodr::FractionWidget::Behavior Pokemodr::FractionWidget::behavior() const @@ -40,7 +43,7 @@ Pokemod::Fraction Pokemodr::FractionWidget::value() const void Pokemodr::FractionWidget::setBehavior(const Behavior behavior) { m_behavior = behavior; - resetRanges(); + emit(behaviorChanged(m_behavior)); } void Pokemodr::FractionWidget::setValue(const Pokemod::Fraction& value) @@ -71,13 +74,25 @@ void Pokemodr::FractionWidget::on_varDenominator_valueChanged(const int denomina void Pokemodr::FractionWidget::resetRanges() { varNumerator->setValue(m_value.numerator()); - if (m_behavior != Proper) - varNumerator->setMaximum(INT_MAX); - else - varNumerator->setMaximum(m_value.denominator()); varDenominator->setValue(m_value.denominator()); - if (m_behavior != Improper) - varDenominator->setMaximum(INT_MAX); - else - varDenominator->setMaximum(m_value.numerator()); + int numMin = 0; + int numMax = INT_MAX; + int denomMin = 1; + int denomMax = INT_MAX; + switch (m_behavior) + { + case NonZero: + numMin = 1; + case Proper: + numMax = m_value.denominator(); + break; + case Improper: + denomMax = m_value.numerator(); + case AnyButZero: + numMin = 1; + default: + break; + } + varNumerator->setRange(numMin, numMax); + varDenominator->setRange(denomMin, denomMax); } diff --git a/pokemodr/FractionWidget.h b/pokemodr/FractionWidget.h index 7829aaf1..0b6262e8 100644 --- a/pokemodr/FractionWidget.h +++ b/pokemodr/FractionWidget.h @@ -38,9 +38,11 @@ class FractionWidget : public QWidget, private Ui::formFraction public: enum Behavior { - Proper = -1, - Any = 0, - Improper = 1 + NonZero = 0, + Proper = 1, + AnyButZero = 2, + Any = 3, + Improper = 4 }; explicit FractionWidget(QWidget* parent, const Pokemod::Fraction& value = Pokemod::Fraction(1, 1)); @@ -49,6 +51,7 @@ class FractionWidget : public QWidget, private Ui::formFraction Pokemod::Fraction value() const; signals: void valueChanged(const Pokemod::Fraction&); + void behaviorChanged(const Behavior); public slots: void setBehavior(const Behavior behavior); void setValue(const Pokemod::Fraction& value); diff --git a/pokemodr/PokemodrUI.cpp b/pokemodr/PokemodrUI.cpp index 31c3567b..a1bd3170 100644 --- a/pokemodr/PokemodrUI.cpp +++ b/pokemodr/PokemodrUI.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,8 @@ Pokemodr::PokemodrUI::PokemodrUI(QWidget* parent) : { setupUi(this); setupActions(); + buttonApply->setIcon(KIcon("dialog-ok-apply")); + buttonReset->setIcon(KIcon("edit-undo")); splitter->setSizes(QList() << m_config.readEntry("treeWidth", 100) << m_config.readEntry("panelWidth", 100)); connect(buttonApply, SIGNAL(clicked()), this, SLOT(update())); KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); @@ -94,7 +97,8 @@ void Pokemodr::PokemodrUI::closeEvent(QCloseEvent* event) void Pokemodr::PokemodrUI::setChangedTitle(const bool changed) { - setWindowTitle(QString::fromUtf8("%1%2 - Pokémodr").arg(treePokemod->description(treePokemod->currentIndex()), changed ? "*" : "")); + setCaption(treePokemod->description(treePokemod->currentIndex()), changed); +// setWindowTitle(QString::fromUtf8("%1%2 - Pokémodr").arg(treePokemod->description(treePokemod->currentIndex()), changed ? "*" : "")); } void Pokemodr::PokemodrUI::setDirty(const bool dirty) @@ -338,7 +342,7 @@ void Pokemodr::PokemodrUI::on_treePokemod_clicked(const QModelIndex& index) connect(widget, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool))); connect(buttonApply, SIGNAL(clicked()), widget, SLOT(apply())); connect(buttonApply, SIGNAL(clicked()), treePokemod, SLOT(setDirty())); - connect(buttonDiscard, SIGNAL(clicked()), widget, SLOT(discard())); + connect(buttonReset, SIGNAL(clicked()), widget, SLOT(discard())); setChangedTitle(false); formPanel->setWidget(widget); formPanel->show(); diff --git a/pokemodr/ScriptWidget.cpp b/pokemodr/ScriptWidget.cpp index 456f5249..8bd2a138 100644 --- a/pokemodr/ScriptWidget.cpp +++ b/pokemodr/ScriptWidget.cpp @@ -76,7 +76,7 @@ Pokemodr::ScriptWidget::ScriptWidget(QWidget* parent, const Pokemod::Script& val // } layoutScript->addWidget(m_view); connect(m_document, SIGNAL(textChanged(KTextEditor::Document*)), this, SLOT(scriptChanged())); - connect(this, SIGNAL(valueChanged(Pokemod::Fraction)), SLOT(setGui())); + connect(this, SIGNAL(valueChanged(const Pokemod::Script&)), SLOT(setGui())); setGui(); } @@ -116,6 +116,9 @@ void Pokemodr::ScriptWidget::on_varInterpreter_activated() void Pokemodr::ScriptWidget::scriptChanged() { - m_value.setScript(m_document->text()); - emit(valueChanged(m_value)); + if (m_value.script() != m_document->text()) + { + m_value.setScript(m_document->text()); + emit(valueChanged(m_value)); + } } diff --git a/pokemodr/TrainerUI.cpp b/pokemodr/TrainerUI.cpp index ab9afe3e..dd8c5f82 100644 --- a/pokemodr/TrainerUI.cpp +++ b/pokemodr/TrainerUI.cpp @@ -57,6 +57,7 @@ void Pokemodr::TrainerUI::setGui() varName->setText(qobject_cast(modified())->name()); varMoneyFactor->setValue(qobject_cast(modified())->moneyFactor()); varSkin->setIcon(qobject_cast(modified())->skin()); + varDepth->setValue(qobject_cast(modified())->depth()); varTeamIntel->setCurrentIndex(qobject_cast(modified())->teamIntel()); varMoveIntel->setCurrentIndex(qobject_cast(modified())->moveIntel()); varItemIntel->setCurrentIndex(qobject_cast(modified())->itemIntel()); @@ -97,6 +98,11 @@ void Pokemodr::TrainerUI::on_varSkin_pressed() delete dialog; } +void Pokemodr::TrainerUI::on_varDepth_valueChanged(const int depth) +{ + qobject_cast(modified())->setDepth(depth); +} + void Pokemodr::TrainerUI::on_varTeamIntel_activated(const int teamIntel) { qobject_cast(modified())->setTeamIntel(teamIntel); diff --git a/pokemodr/TrainerUI.h b/pokemodr/TrainerUI.h index c75fbc41..ed19589b 100644 --- a/pokemodr/TrainerUI.h +++ b/pokemodr/TrainerUI.h @@ -46,6 +46,7 @@ class TrainerUI : public ObjectUI, private Ui::formTrainer void on_varName_textChanged(const QString& name); void on_varMoneyFactor_valueChanged(const int moneyFactor); void on_varSkin_pressed(); + void on_varDepth_valueChanged(const int depth); void on_varTeamIntel_activated(const int teamIntel); void on_varMoveIntel_activated(const int moveIntel); void on_varItemIntel_activated(const int itemIntel); diff --git a/pokemodr/gui/move.ui b/pokemodr/gui/move.ui index 68699499..71bf14ac 100644 --- a/pokemodr/gui/move.ui +++ b/pokemodr/gui/move.ui @@ -66,7 +66,7 @@ - Pokemodr::FractionWidget::Proper + Pokemodr::FractionWidget::NonZero diff --git a/pokemodr/gui/pokemodr.ui b/pokemodr/gui/pokemodr.ui index d75ae7f4..4a86da96 100644 --- a/pokemodr/gui/pokemodr.ui +++ b/pokemodr/gui/pokemodr.ui @@ -42,10 +42,7 @@ - &Apply - - - Ctrl+Return + Apply Apply the changes @@ -59,12 +56,9 @@ - + - &Discard - - - Esc + Reset Discard the changes diff --git a/pokemodr/gui/trainer.ui b/pokemodr/gui/trainer.ui index d445d699..c1c4a07c 100644 --- a/pokemodr/gui/trainer.ui +++ b/pokemodr/gui/trainer.ui @@ -112,6 +112,31 @@ AI rules + + + + Depth + + + How many rounds the AI will simulate to decide which move to make + + + How many rounds the AI will simulate to decide which move to make + + + How many rounds the AI will simulate to decide which move to make + + + + + + 0 + + + + + + diff --git a/pokemodr/models/MapModel.cpp b/pokemodr/models/MapModel.cpp index bbaabdd7..e2a8d2cd 100644 --- a/pokemodr/models/MapModel.cpp +++ b/pokemodr/models/MapModel.cpp @@ -44,6 +44,7 @@ Pokemodr::MapModel::MapModel(BaseModel* parent, Pokemod::Map* map) : Pokemodr::MapModel::~MapModel() { + clearData(); } QVariant Pokemodr::MapModel::data(int role) const diff --git a/pokescripting/Config.cpp b/pokescripting/Config.cpp index e69de29b..8e429fb8 100644 --- a/pokescripting/Config.cpp +++ b/pokescripting/Config.cpp @@ -0,0 +1,42 @@ +/* + * Copyright 2008 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 "Config.h" + +Pokescripting::Config::Config(QObject* parent) : + QObject(parent) +{ +} + +void Pokescripting::Config::addValue(const QString& name, const QVariant& value) +{ + if (!m_values.contains(name)) + m_values[name] = value; +} + +void Pokescripting::Config::setValue(const QString& name, const QVariant& value) +{ + m_values[name] = value; +} + +QVariant Pokescripting::Config::value(const QString& name) +{ + if (m_values.contains(name)) + return m_values[name]; + return QVariant(); +} diff --git a/pokescripting/Config.h b/pokescripting/Config.h index 071c6c77..21dab83f 100644 --- a/pokescripting/Config.h +++ b/pokescripting/Config.h @@ -37,7 +37,13 @@ class Config : public QObject Q_OBJECT public: + Config(QObject* parent); + public slots: + void addValue(const QString& name, const QVariant& value); + void setValue(const QString& name, const QVariant& value); + QVariant value(const QString& name); private: + QMap m_values; }; } diff --git a/pokescripting/TrainerWrapper.h b/pokescripting/TrainerWrapper.h index 3841bac3..766cc030 100644 --- a/pokescripting/TrainerWrapper.h +++ b/pokescripting/TrainerWrapper.h @@ -36,6 +36,7 @@ class POKESCRIPTING_EXPORT TrainerWrapper : public ObjectWrapper QString name() const; int moneyFactor() const; QPixmap skin() const; + int depth() const; int teamIntel() const; int moveIntel() const; int itemIntel() const; @@ -68,6 +69,11 @@ inline QPixmap TrainerWrapper::TrainerWrapper::skin() const return m_trainer->skin(); } +inline int TrainerWrapper::TrainerWrapper::depth() const +{ + return m_trainer->depth(); +} + inline int TrainerWrapper::TrainerWrapper::teamIntel() const { return m_trainer->teamIntel(); -- cgit