Hook up playerListWidget.

Took 1 hour 2 minutes

Took 10 seconds
This commit is contained in:
Lukas Brübach 2025-09-07 18:20:04 +02:00
parent 5d564e3b91
commit cf6120628d
6 changed files with 50 additions and 17 deletions

View file

@ -120,6 +120,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor,
createCardInfoDock(); createCardInfoDock();
createPlayerListDock(); createPlayerListDock();
connectPlayerListToGameEventHandler();
createMessageDock(); createMessageDock();
connectMessageLogToGameEventHandler(); connectMessageLogToGameEventHandler();
createPlayAreaWidget(); createPlayAreaWidget();
@ -189,6 +190,16 @@ void TabGame::connectMessageLogToGameEventHandler()
connect(gameEventHandler, &GameEventHandler::logGameClosed, messageLog, &MessageLogWidget::logGameClosed); connect(gameEventHandler, &GameEventHandler::logGameClosed, messageLog, &MessageLogWidget::logGameClosed);
} }
void TabGame::connectPlayerListToGameEventHandler()
{
connect(gameState, &GameState::playerAdded, playerListWidget, &PlayerListWidget::addPlayer);
connect(gameEventHandler, &GameEventHandler::playerLeft, playerListWidget, &PlayerListWidget::removePlayer);
connect(gameEventHandler, &GameEventHandler::spectatorJoined, playerListWidget, &PlayerListWidget::addSpectator);
connect(gameEventHandler, &GameEventHandler::spectatorLeft, playerListWidget, &PlayerListWidget::removePlayer);
connect(gameEventHandler, &GameEventHandler::playerPropertiesChanged, playerListWidget,
&PlayerListWidget::updatePlayerProperties);
}
void TabGame::loadReplay(GameReplay *replay) void TabGame::loadReplay(GameReplay *replay)
{ {
gameMetaInfo->setFromProto(replay->game_info()); gameMetaInfo->setFromProto(replay->game_info());
@ -526,7 +537,7 @@ void TabGame::removePlayerFromAutoCompleteList(QString playerName)
void TabGame::addSpectator(ServerInfo_PlayerProperties prop) void TabGame::addSpectator(ServerInfo_PlayerProperties prop)
{ {
playerListWidget->addPlayer(prop); playerListWidget->addSpectator(prop);
} }
void TabGame::removeSpectator(int spectatorId, ServerInfo_User spectator) void TabGame::removeSpectator(int spectatorId, ServerInfo_User spectator)
@ -534,8 +545,6 @@ void TabGame::removeSpectator(int spectatorId, ServerInfo_User spectator)
Q_UNUSED(spectator); Q_UNUSED(spectator);
QString playerName = "@" + gameState->getSpectatorName(spectatorId); QString playerName = "@" + gameState->getSpectatorName(spectatorId);
removePlayerFromAutoCompleteList(playerName); removePlayerFromAutoCompleteList(playerName);
playerListWidget->removePlayer(spectatorId);
} }
void TabGame::actPhaseAction() void TabGame::actPhaseAction()
@ -623,7 +632,7 @@ void TabGame::processPlayerLeave(Player *leavingPlayer)
{ {
QString playerName = "@" + leavingPlayer->getName(); QString playerName = "@" + leavingPlayer->getName();
removePlayerFromAutoCompleteList(playerName); removePlayerFromAutoCompleteList(playerName);
playerListWidget->removePlayer(leavingPlayer->getId());
scene->removePlayer(leavingPlayer); scene->removePlayer(leavingPlayer);
} }
@ -632,9 +641,6 @@ Player *TabGame::addPlayer(Player *newPlayer)
QString newPlayerName = "@" + newPlayer->getName(); QString newPlayerName = "@" + newPlayer->getName();
addPlayerToAutoCompleteList(newPlayerName); addPlayerToAutoCompleteList(newPlayerName);
// TODO
// playerListWidget->addPlayer(newPlayer);
scene->addPlayer(newPlayer); scene->addPlayer(newPlayer);
connect(newPlayer, &Player::newCardAdded, this, &TabGame::newCardAdded); connect(newPlayer, &Player::newCardAdded, this, &TabGame::newCardAdded);

View file

@ -173,6 +173,7 @@ public:
const Event_GameJoined &event, const Event_GameJoined &event,
const QMap<int, QString> &_roomGameTypes); const QMap<int, QString> &_roomGameTypes);
void connectMessageLogToGameEventHandler(); void connectMessageLogToGameEventHandler();
void connectPlayerListToGameEventHandler();
void loadReplay(GameReplay *replay); void loadReplay(GameReplay *replay);
TabGame(TabSupervisor *_tabSupervisor, GameReplay *replay); TabGame(TabSupervisor *_tabSupervisor, GameReplay *replay);
~TabGame() override; ~TabGame() override;

View file

@ -237,6 +237,8 @@ void GameEventHandler::eventSpectatorLeave(const Event_Leave &event,
{ {
emit logSpectatorLeave(gameState->getSpectatorName(eventPlayerId), getLeaveReason(event.reason())); emit logSpectatorLeave(gameState->getSpectatorName(eventPlayerId), getLeaveReason(event.reason()));
emit spectatorLeft(eventPlayerId);
gameState->removeSpectator(eventPlayerId); gameState->removeSpectator(eventPlayerId);
game->emitUserEvent(); game->emitUserEvent();
@ -322,7 +324,7 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
if (!player) if (!player)
return; return;
const ServerInfo_PlayerProperties &prop = event.player_properties(); const ServerInfo_PlayerProperties &prop = event.player_properties();
// playerListWidget->updatePlayerProperties(prop, eventPlayerId); emit playerPropertiesChanged(prop, eventPlayerId);
const auto contextType = static_cast<GameEventContext::ContextType>(getPbExtension(context)); const auto contextType = static_cast<GameEventContext::ContextType>(getPbExtension(context));
switch (contextType) { switch (contextType) {
@ -395,11 +397,13 @@ void GameEventHandler::eventJoin(const Event_Join &event, int /*eventPlayerId*/,
if (playerInfo.spectator()) { if (playerInfo.spectator()) {
gameState->addSpectator(playerId, playerInfo); gameState->addSpectator(playerId, playerInfo);
emit logJoinSpectator(playerName); emit logJoinSpectator(playerName);
emit spectatorJoined(playerInfo);
} else { } else {
Player *newPlayer = gameState->addPlayer(playerId, playerInfo.user_info(), game); Player *newPlayer = gameState->addPlayer(playerId, playerInfo.user_info(), game);
emit logJoinPlayer(newPlayer); emit logJoinPlayer(newPlayer);
emit playerJoined(playerInfo);
} }
// playerListWidget->addPlayer(playerInfo);
game->emitUserEvent(); game->emitUserEvent();
} }
@ -427,7 +431,7 @@ void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, c
if (!player) if (!player)
return; return;
emit playerLeft(player); emit playerLeft(eventPlayerId);
emit logLeave(player, getLeaveReason(event.reason())); emit logLeave(player, getLeaveReason(event.reason()));

View file

@ -92,8 +92,12 @@ signals:
void localPlayerReadyStateChanged(int playerId, bool ready); void localPlayerReadyStateChanged(int playerId, bool ready);
void gameStopped(); void gameStopped();
void gameClosed(); void gameClosed();
void playerLeft(Player *leavingPlayer); void playerPropertiesChanged(const ServerInfo_PlayerProperties &prop, int playerId);
void playerJoined(const ServerInfo_PlayerProperties &playerInfo);
void playerLeft(int leavingPlayerId);
void playerKicked(); void playerKicked();
void spectatorJoined(const ServerInfo_PlayerProperties &spectatorInfo);
void spectatorLeft(int leavingSpectatorId);
void gameFlooded(); void gameFlooded();
void containerProcessingStarted(GameEventContext context); void containerProcessingStarted(GameEventContext context);
void setContextJudgeName(QString judgeName); void setContextJudgeName(QString judgeName);

View file

@ -97,11 +97,24 @@ void PlayerListWidget::retranslateUi()
{ {
} }
void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player) void PlayerListWidget::addPlayer(const Player *player)
{ {
QTreeWidgetItem *newPlayer = new PlayerListTWI; QTreeWidgetItem *newPlayer = new PlayerListTWI;
players.insert(player.player_id(), newPlayer); players.insert(player->getId(), newPlayer);
updatePlayerProperties(player); // updatePlayerProperties(player->getUserInfo());
addTopLevelItem(newPlayer);
sortItems(1, Qt::AscendingOrder);
resizeColumnToContents(4);
resizeColumnToContents(5);
}
void PlayerListWidget::addSpectator(const ServerInfo_PlayerProperties &spectator)
{
QTreeWidgetItem *newPlayer = new PlayerListTWI;
players.insert(spectator.player_id(), newPlayer);
updatePlayerProperties(spectator);
addTopLevelItem(newPlayer); addTopLevelItem(newPlayer);
sortItems(1, Qt::AscendingOrder); sortItems(1, Qt::AscendingOrder);
resizeColumnToContents(4); resizeColumnToContents(4);

View file

@ -1,6 +1,8 @@
#ifndef PLAYERLISTWIDGET_H #ifndef PLAYERLISTWIDGET_H
#define PLAYERLISTWIDGET_H #define PLAYERLISTWIDGET_H
#include "player.h"
#include <QIcon> #include <QIcon>
#include <QMap> #include <QMap>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
@ -47,12 +49,15 @@ signals:
public: public:
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = nullptr); PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = nullptr);
void retranslateUi(); void retranslateUi();
void addPlayer(const ServerInfo_PlayerProperties &player);
void removePlayer(int playerId);
void setActivePlayer(int playerId); void setActivePlayer(int playerId);
void updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId = -1);
void setGameStarted(bool _gameStarted, bool resuming); void setGameStarted(bool _gameStarted, bool resuming);
void showContextMenu(const QPoint &pos, const QModelIndex &index); void showContextMenu(const QPoint &pos, const QModelIndex &index);
public slots:
void addPlayer(const Player *player);
void addSpectator(const ServerInfo_PlayerProperties &spectator);
void removePlayer(int playerId);
void updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId = -1);
}; };
#endif #endif