-
Notifications
You must be signed in to change notification settings - Fork 12
/
SetActiveDialog.cpp
87 lines (77 loc) · 2.69 KB
/
SetActiveDialog.cpp
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
#include "SetActiveDialog.h"
#include "ui_SetActiveDialog.h"
Q_DECLARE_METATYPE(authPlayer);
Q_DECLARE_METATYPE(QList<uint32_t>)
SetActiveDialog::SetActiveDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::SetActiveDialog)
{
qRegisterMetaType<QList<uint32_t> >();
qRegisterMetaType<authPlayer>("authPlayer");
m_ui->setupUi(this);
}
SetActiveDialog::~SetActiveDialog()
{
delete m_ui;
}
void SetActiveDialog::changeEvent(QEvent *e)
{
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
void SetActiveDialog::setPlayers(QList<authPlayer> plyrs) {
foreach(authPlayer plyr, plyrs) {
QListWidgetItem* player = new QListWidgetItem();
QVariant data;
data.setValue(plyr);
player->setData(Qt::UserRole, data);
player->setText(QString(ST::format("{} {} ({})", plyr.Name, plyr.avatar, plyr.ID).c_str()));
m_ui->playerList->addItem(player);
}
connect(this, SIGNAL(accepted()), this, SLOT(setActive()));
}
void SetActiveDialog::setFoundNodes(QList<uint32_t> nodes) {
foreach(uint32_t node, nodes) {
QListWidgetItem* item = new QListWidgetItem();
QVariant data;
data.setValue(node);
item->setData(Qt::UserRole, data);
item->setText(QString::number(node));
m_ui->playerList->addItem(item);
}
setWindowTitle("Fetch Found Nodes");
m_ui->playerList->setSelectionMode(QAbstractItemView::MultiSelection);
connect(this, SIGNAL(accepted()), this, SLOT(sendFetches()));
}
void SetActiveDialog::setAgeNodes(QList<qtVaultNode *>nodes) {
foreach(qtVaultNode* node, nodes) {
QListWidgetItem* item = new QListWidgetItem();
QVariant data;
data.setValue(node);
item->setData(Qt::UserRole, data);
item->setText(QString(node->displayName().c_str()));
m_ui->playerList->addItem(item);
}
setWindowTitle("Select Age to Join");
connect(this, SIGNAL(accepted()), this, SLOT(joinAge()));
}
void SetActiveDialog::joinAge() {
if(m_ui->playerList->selectedItems().count() == 1) {
qtVaultNode* age = m_ui->playerList->selectedItems()[0]->data(Qt::UserRole).value<qtVaultNode*>();
emit joinAge(age->getString64(1), age->getUuid(0));
}
}
void SetActiveDialog::setActive() {
if(m_ui->playerList->selectedItems().count() == 1)
emit setActive(m_ui->playerList->selectedItems()[0]->data(Qt::UserRole).value<authPlayer>().ID);
}
void SetActiveDialog::sendFetches() {
for(int i = 0; i < m_ui->playerList->selectedItems().count(); i++) {
emit fetchFound(m_ui->playerList->selectedItems()[i]->data(Qt::UserRole).value<uint32_t>());
}
}