-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerspopup.cpp
145 lines (134 loc) · 4.99 KB
/
playerspopup.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
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
#include "playerspopup.h"
#include "ui_playerspopup.h"
static PlayersPopup* SystemPopup = 0;
PlayersPopup::PlayersPopup(QWidget *parent) :
QWidget(parent),
ui(new Ui::PlayersPopup)
{
ui->setupUi(this);
this->setFocusPolicy(Qt::NoFocus);
this->setAttribute(Qt::WA_ShowWithoutActivating, true);
this->setWindowFlags(Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint|Qt::WindowDoesNotAcceptFocus|Qt::WindowTransparentForInput|Qt::ToolTip);
}
void PlayersPopup::updateFromServer(const Server& server)
{
setUpdatesEnabled(false);
ui->svlabel_GameMode->setText(server.GameModeString);
// time
if (server.TimeLimit > 0)
{
ui->svlabel_Time->setText(QString("%1/%2").arg(QString::number(server.TimeLimit-server.TimeLeft),
QString::number(server.TimeLimit)));
}
else
{
ui->svlabel_Time->setText("unlimited");
}
// frags
QString frgType = server.getPointsName();
if (frgType == "Frags" || frgType == "Points" || frgType == "Wins")
{
ui->svlabel_PointsName->setText(frgType+":");
int limit = 0;
if (frgType == "Frags") limit = server.FragLimit;
else if (frgType == "Points") limit = server.PointLimit;
else if (frgType == "Wins") limit = server.WinLimit;
if (limit > 0)
{
// find top point team or player
int topPts = 0;
if (!server.Teams.isEmpty())
{
topPts = -32768;
for (int i = 0; i < server.Teams.size(); i++)
{
//qDebug("%s = %d", server.Teams[i].NameClean.toUtf8().data(), server.Teams[i].Points);
if (server.Teams[i].Points > topPts)
topPts = server.Teams[i].Points;
}
}
else
{
topPts = -32768;
for (int i = 0; i < server.Players.size(); i++)
{
if (server.Players[i].Points > topPts)
topPts = server.Players[i].Points;
}
}
ui->svlabel_Points->setText(QString("%1/%2").arg(QString::number(topPts),
QString::number(limit)));
}
else
{
ui->svlabel_Points->setText("unlimited");
}
}
else // simulating IDE behavior. although IMO in this case we should just hide the points counter.
{
ui->svlabel_PointsName->setText("Frags:");
ui->svlabel_Points->setText("unlimited");
}
// players
int canjoin = server.MaxPlayers-server.PlayerCount;
// sometimes canjoin can be negative. for example when an admin forces their join into a nospec server.
// let's keep it negative to amuse users ;)
QString ptext = QString("%1/%2").arg(QString::number(server.PlayerCount+server.BotCount),
QString::number(server.MaxClients));
if (canjoin != 0)
ptext += QString(" (")+QString::number(canjoin)+QString(" can join)");
ui->svlabel_Players->setText(ptext);
// teams
// first, remove all old labels
for (int i = 0; i < teams.size(); i++)
delete teams[i];
teams.clear();
for (int i = 0; i < server.Teams.size(); i++)
{
QLabel* teamlabel = new QLabel(ui->frame_2);
teamlabel->setText(QString("%1: %2").arg(server.Teams[i].NameClean, QString::number(server.Teams[i].Points)));
QFont nf = teamlabel->font();
nf.setBold(true);
teamlabel->setFont(nf);
// now adjust label background
QPalette np = teamlabel->palette();
QColor lbg = server.Teams[i].Color;
np.setColor(QPalette::Background, lbg);
float luminance = 0.299*lbg.redF() + 0.587*lbg.greenF() + 0.114*lbg.blueF();
if (luminance > 0.5)
np.setColor(QPalette::WindowText, QColor(0, 0, 0, 255));
else np.setColor(QPalette::WindowText, QColor(255, 255, 255, 255));
teamlabel->setPalette(np);
teamlabel->setAutoFillBackground(true);
teamlabel->setMargin(2);
ui->svlayout_teams->addWidget(teamlabel);
teams.append(teamlabel);
}
ui->svlayout_teams->activate();
setUpdatesEnabled(true);
}
// static
void PlayersPopup::showFromServer(const Server& server, int absx, int absy)
{
if (!SystemPopup) SystemPopup = new PlayersPopup(0);
else SystemPopup->hide();
SystemPopup->setGeometry(absx, absy, SystemPopup->width(), SystemPopup->height());
SystemPopup->updateFromServer(server);
if (!server.isNA())
SystemPopup->show();
}
void PlayersPopup::hideStatic()
{
if (SystemPopup)
SystemPopup->hide();
}
void PlayersPopup::freeStatic()
{
if (SystemPopup)
delete SystemPopup;
SystemPopup = 0;
}
PlayersPopup::~PlayersPopup()
{
delete ui;
}