-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not hooked up yet, should handle the visual aspect correctly
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef PLAYER_PRESENCE_H | ||
#define PLAYER_PRESENCE_H | ||
|
||
#include <QDebug> | ||
#include <QListWidget> | ||
#include <QMap> | ||
|
||
class PlayerItem : public QListWidgetItem { | ||
public: | ||
PlayerItem(QListWidget *parent); | ||
|
||
void setID(int f_id); | ||
void setName(QString f_name); | ||
void setCharacter(QString f_character); | ||
void setIsSpecial(bool f_state); | ||
|
||
private: | ||
void styleEntry(); | ||
|
||
int id; | ||
QString name; | ||
QString character; | ||
bool isSpecial; | ||
}; | ||
|
||
class PlayerMenu : QListWidget { | ||
Q_OBJECT | ||
|
||
public: | ||
PlayerMenu(QWidget *parent = nullptr); | ||
~PlayerMenu() = default; | ||
|
||
public slots: | ||
void addPlayer(int f_id, QString f_name, QString f_character, | ||
bool f_isSpecial); | ||
void updatePlayer(PlayerItem *f_player, QString f_name, QString f_character, | ||
bool f_isSpecial); | ||
void removePlayer(int f_id); | ||
void resetList(); | ||
|
||
private: | ||
QMap<int, PlayerItem *> players; | ||
}; | ||
|
||
#endif // PLAYER_PRESENCE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "include/widgets/player_presence.h" | ||
|
||
PlayerItem::PlayerItem(QListWidget *parent) : QListWidgetItem(parent) {} | ||
|
||
void PlayerItem::setID(int f_id) { id = f_id; } | ||
|
||
void PlayerItem::setName(QString f_name) { name = f_name; } | ||
|
||
void PlayerItem::setCharacter(QString f_character) { character = f_character; } | ||
|
||
void PlayerItem::setIsSpecial(bool f_state) | ||
{ | ||
isSpecial = f_state; | ||
styleEntry(); | ||
} | ||
|
||
void PlayerItem::styleEntry() | ||
{ | ||
QIcon l_icon(character); | ||
setIcon(l_icon); | ||
|
||
QString label = ""; | ||
if (isSpecial) { | ||
label + "⭐"; | ||
} | ||
label + QString("[%1]%2").arg(QString::number(id), name); | ||
setText(label); | ||
} | ||
|
||
PlayerMenu::PlayerMenu(QWidget *parent) : QListWidget(parent) {} | ||
|
||
void PlayerMenu::addPlayer(int f_id, QString f_name, QString f_character, | ||
bool f_isSpecial) | ||
{ | ||
PlayerItem *l_player = players.value(f_id); | ||
if (l_player != nullptr) { | ||
updatePlayer(l_player, f_name, f_character, f_isSpecial); | ||
return; | ||
} | ||
|
||
l_player = new PlayerItem(this); | ||
l_player->setID(f_id); | ||
l_player->setName(f_name); | ||
l_player->setCharacter(f_character); | ||
l_player->setIsSpecial(f_isSpecial); | ||
|
||
players.insert(f_id, l_player); | ||
} | ||
|
||
void PlayerMenu::updatePlayer(PlayerItem *f_player, QString f_name, | ||
QString f_character, bool f_isSpecial) | ||
{ | ||
f_player->setName(f_name); | ||
f_player->setCharacter(f_character); | ||
f_player->setIsSpecial(f_isSpecial); | ||
} | ||
|
||
void PlayerMenu::removePlayer(int f_id) | ||
{ | ||
PlayerItem *f_player = players.value(f_id); | ||
if (f_player == nullptr) { | ||
qDebug() << "Attempted to remove non-existant player at" << f_id; | ||
return; | ||
} | ||
delete f_player; | ||
} | ||
|
||
void PlayerMenu::resetList() | ||
{ | ||
for (PlayerItem *player : qAsConst(players)) { | ||
delete player; | ||
} | ||
} |