summaryrefslogtreecommitdiffstats
path: root/sigmodr/SpeciesUI.cpp
blob: a020c2d8f93250b16c0a395bc9b40772f7dc1e6a (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
 * 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 "SpeciesUI.h"

// Sigmod includes
#include "../sigmod/EggGroup.h"
#include "../sigmod/Rules.h"
#include "../sigmod/Sigmod.h"
#include "../sigmod/Skin.h"
#include "../sigmod/Species.h"
#include "../sigmod/Sprite.h"
#include "../sigmod/Type.h"

Sigmodr::SpeciesUI::SpeciesUI(Sigmod::Species* species, QWidget* parent) :
        ObjectUI(parent)
{
    setupUi(this);
    setObjects(species, new Sigmod::Species(*species));
}

Sigmodr::SpeciesUI::~SpeciesUI()
{
}

void Sigmodr::SpeciesUI::initGui()
{
    connect(varBaseStat, SIGNAL(activated(const int)), this, SLOT(setGui()));
    connect(varEVStat, SIGNAL(activated(const int)), this, SLOT(setGui()));
    varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Fluctuating], QVariant::fromValue(Sigmod::Species::Fluctuating));
    varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Fading], QVariant::fromValue(Sigmod::Species::Fading));
    varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Slow], QVariant::fromValue(Sigmod::Species::Slow));
    varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Normal], QVariant::fromValue(Sigmod::Species::Normal));
    varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Fast], QVariant::fromValue(Sigmod::Species::Fast));
    varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Erratic], QVariant::fromValue(Sigmod::Species::Erratic));
    varEffortValue->setMaximum(sigmod()->rules()->maxEVPerStat() ? sigmod()->rules()->maxEVPerStat() : INT_MAX);
}

void Sigmodr::SpeciesUI::refreshGui()
{
    varBaseStat->clear();
    varEVStat->clear();
    const bool isSplit = sigmod()->rules()->specialSplit();
    const QStringList& statNames = (isSplit ? Sigmod::StatGSCStr : Sigmod::StatRBYStr);
    varBaseStat->addItem(statNames[Sigmod::ST_HP], QVariant::fromValue(Sigmod::ST_HP));
    varBaseStat->addItem(statNames[Sigmod::ST_Attack], QVariant::fromValue(Sigmod::ST_Attack));
    varBaseStat->addItem(statNames[Sigmod::ST_Defense], QVariant::fromValue(Sigmod::ST_Defense));
    varBaseStat->addItem(statNames[Sigmod::ST_Speed], QVariant::fromValue(Sigmod::ST_Speed));
    if (isSplit)
    {
        varBaseStat->addItem(statNames[Sigmod::ST_SpecialAttack], QVariant::fromValue(Sigmod::ST_SpecialAttack));
        varBaseStat->addItem(statNames[Sigmod::ST_SpecialDefense], QVariant::fromValue(Sigmod::ST_SpecialDefense));
    }
    else
        varBaseStat->addItem(statNames[Sigmod::ST_Special], QVariant::fromValue(Sigmod::ST_Special));
    if (sigmod()->rules()->effortValuesAllowed())
    {
        varEVStat->addItem(statNames[Sigmod::ST_HP], QVariant::fromValue(Sigmod::ST_HP));
        varEVStat->addItem(statNames[Sigmod::ST_Attack], QVariant::fromValue(Sigmod::ST_Attack));
        varEVStat->addItem(statNames[Sigmod::ST_Defense], QVariant::fromValue(Sigmod::ST_Defense));
        varEVStat->addItem(statNames[Sigmod::ST_Speed], QVariant::fromValue(Sigmod::ST_Speed));
        if (isSplit)
        {
            varEVStat->addItem(statNames[Sigmod::ST_SpecialAttack], QVariant::fromValue(Sigmod::ST_SpecialAttack));
            varEVStat->addItem(statNames[Sigmod::ST_SpecialDefense], QVariant::fromValue(Sigmod::ST_SpecialDefense));
        }
        else
            varEVStat->addItem(statNames[Sigmod::ST_Special], QVariant::fromValue(Sigmod::ST_Special));
    }
    else
        boxEffortValues->setEnabled(false);
    if (!sigmod()->rules()->maxHeldItems())
        boxItemChance->setEnabled(false);
    int maxHeight = 0;
    int maxWidth = 0;
    const bool blockedMaleFront = varMaleFront->blockSignals(true);
    varMaleFront->clear();
    const bool blockedMaleBack = varMaleBack->blockSignals(true);
    varMaleBack->clear();
    const bool blockedFemaleFront = varFemaleFront->blockSignals(true);
    varFemaleFront->clear();
    const bool blockedFemaleBack = varFemaleBack->blockSignals(true);
    varFemaleBack->clear();
    for (int i = 0; i < sigmod()->spriteCount(); ++i)
    {
        const Sigmod::Sprite* sprite = sigmod()->sprite(i);
        QPixmap icon;
        icon.loadFromData(sprite->sprite());
        maxHeight = qMax(maxHeight, icon.height());
        maxWidth = qMax(maxWidth, icon.width());
        varMaleFront->addItem(icon, sprite->name(), sprite->id());
        varMaleBack->addItem(icon, sprite->name(), sprite->id());
        varFemaleFront->addItem(icon, sprite->name(), sprite->id());
        varFemaleBack->addItem(icon, sprite->name(), sprite->id());
    }
    varMaleFront->blockSignals(blockedMaleFront);
    varMaleBack->blockSignals(blockedMaleBack);
    varFemaleFront->blockSignals(blockedFemaleFront);
    varFemaleBack->blockSignals(blockedFemaleBack);
    const QSize maxSize(maxWidth, maxHeight);
    varMaleFront->setIconSize(maxSize);
    varMaleBack->setIconSize(maxSize);
    varFemaleFront->setIconSize(maxSize);
    varFemaleBack->setIconSize(maxSize);
    const bool blockedSkin = varSkin->blockSignals(true);
    varSkin->clear();
    for (int i = 0; i < sigmod()->skinCount(); ++i)
    {
        const Sigmod::Skin* skin = sigmod()->skin(i);
        varSkin->addItem(skin->name(), skin->id());
    }
    varSkin->blockSignals(blockedSkin);
    if (sigmod()->rules()->genderAllowed())
    {
        const bool blockedEggSpecies = varEggSpecies->blockSignals(true);
        varEggSpecies->clear();
        const bool blockedEggGroups = varEggGroups->blockSignals(true);
        varEggGroups->clear();
        if (sigmod()->rules()->breedingAllowed())
        {
            for (int i = 0; i < sigmod()->speciesCount(); ++i)
            {
                const Sigmod::Species* species = sigmod()->species(i);
                varEggSpecies->addItem(species->name(), species->id());
            }
            for (int i = 0; i < sigmod()->eggGroupCount(); ++i)
            {
                const Sigmod::EggGroup* eggGroup = sigmod()->eggGroup(i);
                QListWidgetItem* widgetItem = new QListWidgetItem(eggGroup->name(), varEggGroups);
                widgetItem->setData(Qt::UserRole, eggGroup->id());
            }
        }
        else
        {
            boxEggSpecies->setEnabled(false);
            varEggSteps->setEnabled(false);
            boxEggGroups->setEnabled(false);
        }
        varEggSpecies->blockSignals(blockedEggSpecies);
        varEggGroups->blockSignals(blockedEggGroups);
    }
    else
    {
        tabGenetics->setEnabled(false);
        boxFemaleSprites->setEnabled(false);
    }
    const bool blockedTypes = varTypes->blockSignals(true);
    varTypes->clear();
    for (int i = 0; i < sigmod()->typeCount(); ++i)
    {
        const Sigmod::Type* type = sigmod()->type(i);
        QListWidgetItem* widgetItem = new QListWidgetItem(type->name(), varTypes);
        widgetItem->setData(Qt::UserRole, type->id());
    }
    varTypes->blockSignals(blockedTypes);
}

void Sigmodr::SpeciesUI::setGui()
{
    varName->setText(qobject_cast<Sigmod::Species*>(modified())->name());
    varBaseStatValue->setValue(qobject_cast<Sigmod::Species*>(modified())->baseStat(varBaseStat->itemData(varBaseStat->currentIndex()).value<Sigmod::Stat>()));
    varEffortValue->setValue(qobject_cast<Sigmod::Species*>(modified())->effortValue(varEVStat->itemData(varEVStat->currentIndex()).value<Sigmod::Stat>()));
    varGrowth->setCurrentIndex(qobject_cast<Sigmod::Species*>(modified())->growth());
    varExperienceValue->setValue(qobject_cast<Sigmod::Species*>(modified())->experienceValue());
    varCatchValue->setValue(qobject_cast<Sigmod::Species*>(modified())->catchValue());
    varMaxHoldWeight->setValue(qobject_cast<Sigmod::Species*>(modified())->maxHoldWeight());
    varRunChance->setValue(qobject_cast<Sigmod::Species*>(modified())->runChance());
    varItemChance->setValue(qobject_cast<Sigmod::Species*>(modified())->itemChance());
    varEncyclopediaNumber->setValue(qobject_cast<Sigmod::Species*>(modified())->encyclopediaNumber());
    varWeight->setValue(qobject_cast<Sigmod::Species*>(modified())->weight());
    varHeight->setValue(qobject_cast<Sigmod::Species*>(modified())->height());
    varEncyclopediaEntry->setText(qobject_cast<Sigmod::Species*>(modified())->encyclopediaEntry());
    varMaleFront->setCurrentIndex(varMaleFront->findData(qobject_cast<Sigmod::Species*>(modified())->frontMaleSprite()));
    varMaleBack->setCurrentIndex(varMaleBack->findData(qobject_cast<Sigmod::Species*>(modified())->backMaleSprite()));
    if (sigmod()->rules()->genderAllowed())
    {
        varFemaleFront->setCurrentIndex(varFemaleFront->findData(qobject_cast<Sigmod::Species*>(modified())->frontFemaleSprite()));
        varFemaleBack->setCurrentIndex(varFemaleBack->findData(qobject_cast<Sigmod::Species*>(modified())->backFemaleSprite()));
    }
    varSkin->setCurrentIndex(varSkin->findData(qobject_cast<Sigmod::Species*>(modified())->skin()));
    boxGenderChance->setChecked((qobject_cast<Sigmod::Species*>(modified())->genderFactor() < 0) ? Qt::Checked : Qt::Unchecked);
    varGenderChance->setValue(qobject_cast<Sigmod::Species*>(modified())->genderFactor());
    varEggSpecies->setCurrentIndex(varEggSpecies->findData(qobject_cast<Sigmod::Species*>(modified())->eggSpecies()));
    varEggSteps->setValue(qobject_cast<Sigmod::Species*>(modified())->eggSteps());
    varEvolution->setValue(qobject_cast<Sigmod::Species*>(modified())->evolution());
    for (int i = 0; i < varTypes->count(); ++i)
    {
        QListWidgetItem* widgetItem = varTypes->item(i);
        widgetItem->setSelected(qobject_cast<Sigmod::Species*>(modified())->type(widgetItem->data(Qt::UserRole).toInt()));
    }
    for (int i = 0; i < varEggGroups->count(); ++i)
    {
        QListWidgetItem* widgetItem = varEggGroups->item(i);
        widgetItem->setSelected(qobject_cast<Sigmod::Species*>(modified())->eggGroup(widgetItem->data(Qt::UserRole).toInt()));
    }
}

void Sigmodr::SpeciesUI::apply()
{
    *qobject_cast<Sigmod::Species*>(original()) = *qobject_cast<Sigmod::Species*>(modified());
    emit(changed(false));
}

void Sigmodr::SpeciesUI::discard()
{
    *qobject_cast<Sigmod::Species*>(modified()) = *qobject_cast<Sigmod::Species*>(original());
    setGui();
    emit(changed(false));
}

void Sigmodr::SpeciesUI::on_varName_textChanged(const QString& name)
{
    const int cursor = varName->cursorPosition();
    qobject_cast<Sigmod::Species*>(modified())->setName(name);
    varName->setCursorPosition(cursor);
}

void Sigmodr::SpeciesUI::on_varBaseStatValue_valueChanged(const int baseStat)
{
    qobject_cast<Sigmod::Species*>(modified())->setBaseStat(varBaseStat->itemData(varBaseStat->currentIndex()).value<Sigmod::Stat>(), baseStat);
}

void Sigmodr::SpeciesUI::on_varEffortValue_valueChanged(const int effortValue)
{
    qobject_cast<Sigmod::Species*>(modified())->setEffortValue(varEVStat->itemData(varEVStat->currentIndex()).value<Sigmod::Stat>(), effortValue);
}

void Sigmodr::SpeciesUI::on_varGrowth_activated(const int growth)
{
    qobject_cast<Sigmod::Species*>(modified())->setGrowth(QVariant(growth).value<Sigmod::Species::Style>());
}

void Sigmodr::SpeciesUI::on_varExperienceValue_valueChanged(const int experienceValue)
{
    qobject_cast<Sigmod::Species*>(modified())->setExperienceValue(experienceValue);
}

void Sigmodr::SpeciesUI::on_varCatchValue_valueChanged(const int catchValue)
{
    qobject_cast<Sigmod::Species*>(modified())->setCatchValue(catchValue);
}

void Sigmodr::SpeciesUI::on_varMaxHoldWeight_valueChanged(const int maxHoldWeight)
{
    qobject_cast<Sigmod::Species*>(modified())->setMaxHoldWeight(maxHoldWeight);
}

void Sigmodr::SpeciesUI::on_varRunChance_valueChanged(const Sigcore::Fraction& runChance)
{
    qobject_cast<Sigmod::Species*>(modified())->setRunChance(runChance);
}

void Sigmodr::SpeciesUI::on_varItemChance_valueChanged(const Sigcore::Fraction& itemChance)
{
    qobject_cast<Sigmod::Species*>(modified())->setItemChance(itemChance);
}

void Sigmodr::SpeciesUI::on_varEncyclopediaNumber_valueChanged(const int encyclopediaNumber)
{
    qobject_cast<Sigmod::Species*>(modified())->setEncyclopediaNumber(encyclopediaNumber);
}

void Sigmodr::SpeciesUI::on_varWeight_valueChanged(const int weight)
{
    qobject_cast<Sigmod::Species*>(modified())->setWeight(weight);
}

void Sigmodr::SpeciesUI::on_varHeight_valueChanged(const int height)
{
    qobject_cast<Sigmod::Species*>(modified())->setHeight(height);
}

void Sigmodr::SpeciesUI::on_varEncyclopediaEntry_textChanged(const QString& encyclopediaEntry)
{
    qobject_cast<Sigmod::Species*>(modified())->setEncyclopediaEntry(encyclopediaEntry);
}

void Sigmodr::SpeciesUI::on_varMaleFront_currentIndexChanged(const int maleFront)
{
    qobject_cast<Sigmod::Species*>(modified())->setFrontMaleSprite(varMaleFront->itemData(maleFront).toInt());
}

void Sigmodr::SpeciesUI::on_varMaleBack_currentIndexChanged(const int maleBack)
{
    qobject_cast<Sigmod::Species*>(modified())->setBackMaleSprite(varMaleBack->itemData(maleBack).toInt());
}

void Sigmodr::SpeciesUI::on_varFemaleFront_currentIndexChanged(const int femaleFront)
{
    qobject_cast<Sigmod::Species*>(modified())->setFrontFemaleSprite(varFemaleFront->itemData(femaleFront).toInt());
}

void Sigmodr::SpeciesUI::on_varFemaleBack_currentIndexChanged(const int femaleBack)
{
    qobject_cast<Sigmod::Species*>(modified())->setBackFemaleSprite(varFemaleBack->itemData(femaleBack).toInt());
}

void Sigmodr::SpeciesUI::on_varSkin_currentIndexChanged(const int skin)
{
    qobject_cast<Sigmod::Species*>(modified())->setSkin(varSkin->itemData(skin).toInt());
}

void Sigmodr::SpeciesUI::on_boxGenderChance_clicked(const bool genderChance)
{
    qobject_cast<Sigmod::Species*>(modified())->setGenderFactor(Sigcore::Fraction((genderChance ? 1 : -1), 1));
}

void Sigmodr::SpeciesUI::on_varGenderChance_valueChanged(const Sigcore::Fraction& genderChance)
{
    qobject_cast<Sigmod::Species*>(modified())->setGenderFactor(genderChance);
}

void Sigmodr::SpeciesUI::on_varEggSpecies_activated(const int eggSpecies)
{
    qobject_cast<Sigmod::Species*>(modified())->setEggSpecies(varEggSpecies->itemData(eggSpecies).toInt());
}

void Sigmodr::SpeciesUI::on_varEggSteps_valueChanged(const int eggSteps)
{
    qobject_cast<Sigmod::Species*>(modified())->setEggSteps(eggSteps);
}

void Sigmodr::SpeciesUI::on_varEvolution_valueChanged(const Sigcore::Script& evolution)
{
    qobject_cast<Sigmod::Species*>(modified())->setEvolution(evolution);
}

void Sigmodr::SpeciesUI::on_varTypes_itemClicked(QListWidgetItem* item)
{
    qobject_cast<Sigmod::Species*>(modified())->setType(item->data(Qt::UserRole).toInt(), item->isSelected());
}

void Sigmodr::SpeciesUI::on_varEggGroups_itemClicked(QListWidgetItem* item)
{
    qobject_cast<Sigmod::Species*>(modified())->setEggGroup(item->data(Qt::UserRole).toInt(), !item->isSelected());
}