mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
some gui code
This commit is contained in:
parent
cb9a2bf23a
commit
77f5ec29eb
37 changed files with 260 additions and 282 deletions
|
|
@ -51,8 +51,9 @@ ItemId_Event_SetActivePhase = 1049,
|
|||
ItemId_Event_DumpZone = 1050,
|
||||
ItemId_Event_StopDumpZone = 1051,
|
||||
ItemId_Event_ServerMessage = 1052,
|
||||
ItemId_Event_ChatJoinChannel = 1053,
|
||||
ItemId_Event_ChatLeaveChannel = 1054,
|
||||
ItemId_Event_ChatSay = 1055,
|
||||
ItemId_Other = 1056
|
||||
ItemId_Event_GameJoined = 1053,
|
||||
ItemId_Event_ChatJoinChannel = 1054,
|
||||
ItemId_Event_ChatLeaveChannel = 1055,
|
||||
ItemId_Event_ChatSay = 1056,
|
||||
ItemId_Other = 1057
|
||||
};
|
||||
|
|
|
|||
|
|
@ -561,6 +561,18 @@ void Event_ServerMessage::extractParameters()
|
|||
GenericEvent::extractParameters();
|
||||
message = parameters["message"];
|
||||
}
|
||||
Event_GameJoined::Event_GameJoined(int _gameId, bool _spectator)
|
||||
: GenericEvent("game_joined"), gameId(_gameId), spectator(_spectator)
|
||||
{
|
||||
setParameter("game_id", gameId);
|
||||
setParameter("spectator", spectator);
|
||||
}
|
||||
void Event_GameJoined::extractParameters()
|
||||
{
|
||||
GenericEvent::extractParameters();
|
||||
gameId = parameters["game_id"].toInt();
|
||||
spectator = (parameters["spectator"] == "1");
|
||||
}
|
||||
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
|
||||
: ChatEvent("chat_join_channel", _channel), playerName(_playerName)
|
||||
{
|
||||
|
|
@ -647,6 +659,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("game_eventdump_zone", Event_DumpZone::newItem);
|
||||
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
|
||||
itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::newItem);
|
||||
itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem);
|
||||
itemNameHash.insert("chat_eventchat_join_channel", Event_ChatJoinChannel::newItem);
|
||||
itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem);
|
||||
itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@
|
|||
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
|
||||
3:stop_dump_zone:i,zone_owner_id:s,zone
|
||||
4:server_message:s,message
|
||||
4:game_joined:i,game_id:b,spectator
|
||||
5:chat_join_channel:s,player_name
|
||||
5:chat_leave_channel:s,player_name
|
||||
5:chat_say:s,player_name:s,message
|
||||
|
|
@ -697,6 +697,20 @@ public:
|
|||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Event_GameJoined : public GenericEvent {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int gameId;
|
||||
bool spectator;
|
||||
public:
|
||||
Event_GameJoined(int _gameId = -1, bool _spectator = false);
|
||||
int getGameId() const { return gameId; }
|
||||
bool getSpectator() const { return spectator; }
|
||||
static ProtocolItem *newItem() { return new Event_GameJoined; }
|
||||
int getItemId() const { return ItemId_Event_GameJoined; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Event_ChatJoinChannel : public ChatEvent {
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, QObject *parent)
|
||||
: QObject(parent), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), spectatorsAllowed(_spectatorsAllowed)
|
||||
{
|
||||
creator = addPlayer(_creator, false);
|
||||
creator = addPlayer(_creator, false, false);
|
||||
}
|
||||
|
||||
Server_Game::~Server_Game()
|
||||
|
|
@ -90,7 +90,7 @@ ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator)
|
||||
Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate)
|
||||
{
|
||||
int playerId;
|
||||
if (!spectator) {
|
||||
|
|
@ -113,7 +113,8 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
|
|||
else
|
||||
players.insert(playerId, newPlayer);
|
||||
|
||||
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this);
|
||||
if (broadcastUpdate)
|
||||
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this);
|
||||
|
||||
return newPlayer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public:
|
|||
int getMaxPlayers() const { return maxPlayers; }
|
||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||
ResponseCode checkJoin(const QString &_password, bool spectator);
|
||||
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator);
|
||||
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
|
||||
void removePlayer(Server_Player *player);
|
||||
void startGameIfReady();
|
||||
int getActivePlayer() const { return activePlayer; }
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
|
|||
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
|
||||
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, game->getCreator()));
|
||||
|
||||
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), false));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
|
|
@ -212,6 +213,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
|
|||
Server_Player *player = g->addPlayer(this, cmd->getSpectator());
|
||||
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
|
||||
}
|
||||
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), cmd->getSpectator()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue