mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-13 21:40:00 -08:00
[Client] Lay out table and turn order dialog in seat order
This commit is contained in:
parent
00c0b2c96b
commit
6a25a2f15e
4 changed files with 96 additions and 2 deletions
|
|
@ -35,6 +35,7 @@
|
|||
#include <functional>
|
||||
#include <libcockatrice/game/abstract_game.h>
|
||||
#include <libcockatrice/game/board/arrow_data.h>
|
||||
#include <libcockatrice/game/game_state.h>
|
||||
#include <libcockatrice/game/player/player_actions.h>
|
||||
#include <libcockatrice/game/player/player_event_handler.h>
|
||||
#include <libcockatrice/game/player/player_info.h>
|
||||
|
|
@ -432,6 +433,37 @@ QList<PlayerLogic *> GameScene::collectActivePlayers(int &firstPlayerIndex) cons
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lay out the table in seat order rather than id order. Players missing
|
||||
// from the tracked order keep id order at the end.
|
||||
QList<int> seatOrder;
|
||||
for (auto *pgItem : playerViews.values()) {
|
||||
if (PlayerLogic *p = pgItem->getLogic()) {
|
||||
seatOrder = p->getGame()->getGameState()->getSeatOrder();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!seatOrder.isEmpty()) {
|
||||
std::sort(activePlayers.begin(), activePlayers.end(), [&](PlayerLogic *a, PlayerLogic *b) {
|
||||
int indexA = seatOrder.indexOf(a->getPlayerInfo()->getId());
|
||||
int indexB = seatOrder.indexOf(b->getPlayerInfo()->getId());
|
||||
if (indexA == -1) {
|
||||
indexA = seatOrder.size() + a->getPlayerInfo()->getId();
|
||||
}
|
||||
if (indexB == -1) {
|
||||
indexB = seatOrder.size() + b->getPlayerInfo()->getId();
|
||||
}
|
||||
return indexA < indexB;
|
||||
});
|
||||
// Recompute the local-player index after sorting.
|
||||
firstPlayerIndex = 0;
|
||||
for (int i = 0; i < activePlayers.size(); ++i) {
|
||||
if (activePlayers[i]->getPlayerInfo()->getLocal()) {
|
||||
firstPlayerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return activePlayers;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue