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
|
/////////////////////////////////////////////////////////////////////////////
// Name: pokegen/TrainerUI.cpp
// Purpose: Trainer UI form handling
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sun Mar 9 18:41:24 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 <QSize>
#include <BugCatcher.h>
#include <Exception.h>
#include <ImageCache.h>
#include "FileDialog.h"
#include "TrainerUI.h"
TrainerUI::TrainerUI(Trainer * t, QWidget * parent) :
ObjectUI(parent),
trainer(t),
trainer_mod(new Trainer(t->getPokemod(), *t, t->getId()))
{
setupUi(this);
QMetaObject::connectSlotsByName(this);
setObjects(trainer, trainer_mod);
connect(this, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool)));
init();
}
void TrainerUI::setGui()
{
varName->setText(trainer_mod->getName());
varMoneyFactor->setValue(trainer_mod->getMoneyFactor());
try
{
varSkin->setIcon(ImageCache::open(trainer_mod->getSkin()));
}
catch (OpenException& e)
{
}
varAI->setText(QFile::exists(trainer_mod->getAi()) ? "Valid" : "Invalid");
}
void TrainerUI::on_buttonApply_clicked()
{
*trainer = *trainer_mod;
emit(changed(false));
}
void TrainerUI::on_buttonDiscard_clicked()
{
*trainer_mod = *trainer;
emit(changed(false));
}
void TrainerUI::on_varName_textChanged(const QString & n)
{
trainer_mod->setName(n);
emit(changed(true));
}
void TrainerUI::on_varMoneyFactor_valueChaged(const int m)
{
try
{
trainer_mod->setMoneyFactor(m);
emit(changed(true));
}
catch (BoundsException& e)
{
BugCatcher::report(e);
setGui();
}
}
void TrainerUI::on_varSkin_pressed()
{
FileDialog dlg("*.png", QSize(192, 168));
if (dlg.show())
{
try
{
trainer_mod->setSkin(dlg.selectedUrl());
}
catch (SaveException& e)
{
BugCatcher::report(e);
}
setGui();
}
}
void TrainerUI::on_varAI_pressed()
{
FileDialog dlg(QString::fromUtf8("*.pai|PokéMod AI Files"));
if (dlg.show())
{
try
{
trainer_mod->setAi(dlg.selectedUrl());
}
catch (SaveException& e)
{
BugCatcher::report(e);
}
setGui();
}
}
|