summaryrefslogtreecommitdiffstats
path: root/pokemodr/NatureUI.cpp
blob: b09823a3ba4203479d8e1d6e9eb90a8cd70722ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/////////////////////////////////////////////////////////////////////////////
// Name:        pokegen/NatureUI.cpp
// Purpose:     Nature UI form handling
// Author:      Ben Boeckel
// Modified by: Ben Boeckel
// Created:     Fri Jan 25 15:19:04 2008
// Copyright:   ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
//    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/>.
/////////////////////////////////////////////////////////////////////////////

#include <QMetaObject>
#include <QStringList>

#include <BugCatcher.h>
#include <Exception.h>
#include <Ref.h>

#include <Pokemod.h>

#include "NatureUI.h"

NatureUI::NatureUI(Nature* n, QWidget* parent) :
        ObjectUI(parent),
        nature(n),
        nature_mod(new Nature(n->getPokemod(), *n, n->getId()))
{
    setupUi(this);
    QMetaObject::connectSlotsByName(this);
    setObjects(nature, nature_mod);
    const bool isSplit = nature->getPokemod()->getRules()->getSpecialSplit();
    varStat->addItems((isSplit ? StatRBYStr : StatGSCStr).mid(0, isSplit ? ST_End_RBY : ST_End_GSC));
    setGui();
}

// KToolbar NatureUI::getToolbar(QWidget* parent)
// {
// }

void NatureUI::setGui()
{
    varName->setText(nature_mod->getName());
    varStatMultiplierNum->setValue(nature_mod->getStat(varStat->currentIndex()).getNum());
    varStatMultiplierDenom->setValue(nature_mod->getStat(varStat->currentIndex()).getDenom());
    varStatMultiplierNum->setMaximum(nature_mod->getStat(varStat->currentIndex()).getDenom());
    varStatMultiplier->setText(QString::number(nature_mod->getStat(varStat->currentIndex()), 'g', DBL_PREC));
    varWeight->setValue(nature_mod->getWeight());
}

void NatureUI::on_buttonApply_clicked()
{
    *nature = *nature_mod;
    emit(setChanged(false));
}

void NatureUI::on_buttonDiscard_clicked()
{
    *nature_mod = *nature;
    emit(setChanged(false));
    setGui();
}

void NatureUI::on_varName_textChanged(const QString& n)
{
    nature_mod->setName(n);
    emit(setChanged(true));
}

void NatureUI::on_varStatMultiplier_currentIndexChanged()
{
    emit(setChanged(true));
    setGui();
}

void NatureUI::on_varStatMultiplierNum_valueChanged(const int s)
{
    try
    {
        nature_mod->setStatNum(varStat->currentIndex(), s);
        emit(setChanged(true));
    }
    catch (Exception& e)
    {
        BugCatcher::report(e);
    }
    setGui();
}

void NatureUI::on_varStatMultiplierDenom_valueChanged(const int s)
{
    try
    {
        nature_mod->setStatDenom(varStat->currentIndex(), s);
        emit(setChanged(true));
    }
    catch (Exception& e)
    {
        BugCatcher::report(e);
    }
    setGui();
}

void NatureUI::on_varWeight_valueChanged(const int w)
{
    try
    {
        nature_mod->setWeight(w);
        emit(setChanged(true));
    }
    catch (BoundsException& e)
    {
        BugCatcher::report(e);
        setGui();
    }
}