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
|
#include "createinstancedialog.h"
#include "ui_createinstancedialog.h"
#include "instancemanager.h"
namespace cid
{
class Page
{
public:
Page(CreateInstanceDialog& dlg, std::size_t i)
: ui(dlg.getUI()), m_dlg(dlg), m_index(i)
{
}
virtual bool ready() const
{
return true;
}
void next()
{
m_dlg.next();
}
protected:
Ui::CreateInstanceDialog* ui;
private:
CreateInstanceDialog& m_dlg;
std::size_t m_index;
};
class TypePage : public Page
{
public:
TypePage(CreateInstanceDialog& dlg, std::size_t i)
: Page(dlg, i)
{
ui->createGlobal->setDescription(
ui->createGlobal->description()
.arg(InstanceManager::instance().instancesPath()));
ui->createPortable->setDescription(
ui->createPortable->description()
.arg(qApp->applicationDirPath()));
QObject::connect(
ui->createGlobal, &QAbstractButton::clicked, [&]{ global(); });
QObject::connect(
ui->createPortable, &QAbstractButton::clicked, [&]{ portable(); });
}
bool ready() const override
{
return m_global.has_value();
}
void global()
{
m_global = true;
ui->createGlobal->setChecked(true);
ui->createPortable->setChecked(false);
next();
}
void portable()
{
m_global = false;
ui->createGlobal->setChecked(false);
ui->createPortable->setChecked(true);
next();
}
private:
std::optional<bool> m_global;
};
class GamePage : public Page
{
public:
GamePage(CreateInstanceDialog& dlg, std::size_t i)
: Page(dlg, i)
{
}
};
class NamePage : public Page
{
public:
NamePage(CreateInstanceDialog& dlg, std::size_t i)
: Page(dlg, i)
{
}
};
class PathsPage : public Page
{
public:
PathsPage(CreateInstanceDialog& dlg, std::size_t i)
: Page(dlg, i)
{
}
};
} // namespace
CreateInstanceDialog::CreateInstanceDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::CreateInstanceDialog)
{
using namespace cid;
ui->setupUi(this);
m_pages.push_back(std::make_unique<TypePage>(*this, 0));
m_pages.push_back(std::make_unique<GamePage>(*this, 1));
m_pages.push_back(std::make_unique<NamePage>(*this, 2));
m_pages.push_back(std::make_unique<PathsPage>(*this, 3));
ui->pages->setCurrentIndex(0);
updateNavigationButtons();
connect(ui->next, &QPushButton::clicked, [&]{ next(); });
connect(ui->back, &QPushButton::clicked, [&]{ back(); });
//
//SelectionDialog games(tr("Select a game to manage."));
//
//for (auto* game : m_pc.plugins<MOBase::IPluginGame>()) {
// if (game->isInstalled()) {
// games.addChoice(game->gameName(), game->gameDirectory().path(), {});
// } else {
// games.addChoice(game->gameName(), "", {});
// }
//}
//
//games.exec();
}
CreateInstanceDialog::~CreateInstanceDialog() = default;
Ui::CreateInstanceDialog* CreateInstanceDialog::getUI()
{
return ui.get();
}
void CreateInstanceDialog::next()
{
ui->pages->setCurrentIndex(ui->pages->currentIndex() + 1);
updateNavigationButtons();
}
void CreateInstanceDialog::back()
{
ui->pages->setCurrentIndex(ui->pages->currentIndex() - 1);
updateNavigationButtons();
}
void CreateInstanceDialog::updateNavigationButtons()
{
const auto i = ui->pages->currentIndex();
const auto last = (i == (ui->pages->count() - 1));
ui->next->setEnabled(m_pages[i]->ready() && !last);
ui->back->setEnabled(i > 0);
}
|