Commit 1b1fb664 authored by nanahira's avatar nanahira Committed by GitHub

fix chat player name display (#2542)

* fix after change side chat reverse

* fix

* fix

* fix

* Update replay_mode.cpp

* fix tag

* simplify

* fix
parent 7de2a00d
......@@ -210,6 +210,7 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) {
mainGame->closeDoneSignal.Wait();
mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = false;
mainGame->is_building = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler);
......@@ -371,6 +372,7 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
case STOC_CHANGE_SIDE: {
mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dField.Clear();
mainGame->is_building = true;
mainGame->is_siding = true;
......@@ -401,6 +403,7 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_WAITING_SIDE: {
mainGame->dInfo.isInDuel = false;
mainGame->gMutex.lock();
mainGame->dField.Clear();
mainGame->stHintMsg->setText(dataManager.GetSysString(1409));
......@@ -663,6 +666,7 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
mainGame->closeDoneSignal.Wait();
mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = true;
mainGame->is_building = false;
mainGame->wDeckEdit->setVisible(false);
......@@ -741,28 +745,17 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
case STOC_CHAT: {
STOC_Chat* pkt = (STOC_Chat*)pdata;
int player = pkt->player;
auto play_sound = false;
if(player < 4) {
if(mainGame->chkIgnore1->isChecked())
break;
if(!mainGame->dInfo.isTag) {
if(mainGame->dInfo.isStarted)
player = mainGame->LocalPlayer(player);
} else {
if(mainGame->dInfo.isStarted && !mainGame->dInfo.isFirst)
player ^= 2;
if(player == 0)
player = 0;
else if(player == 1)
player = 2;
else if(player == 2)
player = 1;
else if(player == 3)
player = 3;
else
player = 10;
}
auto localplayer = mainGame->ChatLocalPlayer(player);
player = localplayer & 0xf;
if(!(localplayer & 0x10))
play_sound = true;
} else {
if(player == 8) { //system custom message.
play_sound = true;
if(mainGame->chkIgnore1->isChecked())
break;
} else if(player < 11 || player > 19) {
......@@ -774,7 +767,7 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
wchar_t msg[256];
BufferIO::CopyWStr(pkt->msg, msg, 256);
mainGame->gMutex.lock();
mainGame->AddChatMsg(msg, player);
mainGame->AddChatMsg(msg, player, play_sound);
mainGame->gMutex.unlock();
break;
}
......@@ -984,6 +977,7 @@ int DuelClient::ClientAnalyze(unsigned char* msg, unsigned int len) {
mainGame->closeDoneSignal.Wait();
mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = false;
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
......@@ -1190,6 +1184,7 @@ int DuelClient::ClientAnalyze(unsigned char* msg, unsigned int len) {
mainGame->showcard = 0;
mainGame->gMutex.lock();
mainGame->dField.Clear();
mainGame->dInfo.isInDuel = true;
int playertype = BufferIO::ReadUInt8(pbuf);
mainGame->dInfo.isFirst = (playertype & 0xf) ? false : true;
if(playertype & 0xf0)
......
......@@ -23,7 +23,6 @@ private:
static unsigned char response_buf[SIZE_RETURN_VALUE];
static unsigned int response_len;
static unsigned int watching;
static unsigned char selftype;
static bool is_host;
static event_base* client_base;
static bufferevent* client_bev;
......@@ -39,6 +38,7 @@ private:
static wchar_t event_string[256];
static mt19937 rnd;
public:
static unsigned char selftype;
static bool StartClient(unsigned int ip, unsigned short port, bool create_game = true);
static void ConnectTimeout(evutil_socket_t fd, short events, void* arg);
static void StopClient(bool is_exiting = false);
......
......@@ -127,6 +127,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(mainGame->dInfo.player_type == 7) {
DuelClient::StopClient();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->CloseDuelWindow();
......
......@@ -18,6 +18,7 @@ Game* mainGame;
void DuelInfo::Clear() {
isStarted = false;
isInDuel = false;
isFinished = false;
isReplay = false;
isReplaySkiping = false;
......@@ -1650,7 +1651,7 @@ void Game::AddLog(const wchar_t* msg, int param) {
lstLog->setSelected(-1);
}
}
void Game::AddChatMsg(const wchar_t* msg, int player) {
void Game::AddChatMsg(const wchar_t* msg, int player, bool play_sound) {
for(int i = 7; i > 0; --i) {
chatMsg[i] = chatMsg[i - 1];
chatTiming[i] = chatTiming[i - 1];
......@@ -1661,23 +1662,22 @@ void Game::AddChatMsg(const wchar_t* msg, int player) {
chatType[0] = player;
if(gameConf.hide_player_name && player < 4)
player = 10;
if(play_sound)
soundManager.PlaySoundEffect(SOUND_CHAT);
switch(player) {
case 0: //from host
chatMsg[0].append(dInfo.hostname);
chatMsg[0].append(L": ");
break;
case 1: //from client
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.clientname);
chatMsg[0].append(L": ");
break;
case 2: //host tag
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.hostname_tag);
chatMsg[0].append(L": ");
break;
case 3: //client tag
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(dInfo.clientname_tag);
chatMsg[0].append(L": ");
break;
......@@ -1686,7 +1686,6 @@ void Game::AddChatMsg(const wchar_t* msg, int player) {
chatMsg[0].append(L": ");
break;
case 8: //system custom message, no prefix.
soundManager.PlaySoundEffect(SOUND_CHAT);
chatMsg[0].append(L"[System]: ");
break;
case 9: //error message
......@@ -1797,6 +1796,38 @@ int Game::LocalPlayer(int player) const {
int pid = player ? 1 : 0;
return dInfo.isFirst ? pid : 1 - pid;
}
int Game::OppositePlayer(int player) {
auto player_side_bit = dInfo.isTag ? 0x2 : 0x1;
return player ^ player_side_bit;
}
int Game::ChatLocalPlayer(int player) {
if(player > 3)
return player;
bool is_self;
if(dInfo.isStarted || is_siding) {
if(dInfo.isInDuel)
// when in duel
player = mainGame->dInfo.isFirst ? player : OppositePlayer(player);
else {
// when changing side or waiting tp result
auto selftype_boundary = dInfo.isTag ? 2 : 1;
if(DuelClient::selftype >= selftype_boundary && DuelClient::selftype < 4)
player = OppositePlayer(player);
}
if(dInfo.isTag) {
is_self = (player & 0x2) == 0 && (player & 0x1) == (DuelClient::selftype & 0x1);
} else {
is_self = player == 0;
}
} else {
// when in lobby
is_self = player == DuelClient::selftype;
}
if(dInfo.isTag && (player == 1 || player == 2)) {
player = 3 - player;
}
return player | (is_self ? 0x10 : 0);
}
const wchar_t* Game::LocalName(int local_player) {
return local_player == 0 ? dInfo.hostname : dInfo.clientname;
}
......
......@@ -69,7 +69,8 @@ struct Config {
struct DuelInfo {
bool isStarted{ false };
bool isFinished{ false };
bool isInDuel{ false };
bool isFinished{false};
bool isReplay{ false };
bool isReplaySkiping{ false };
bool isFirst{ false };
......@@ -158,7 +159,7 @@ public:
void ShowCardInfo(int code, bool resize = false);
void ClearCardInfo(int player = 0);
void AddLog(const wchar_t* msg, int param = 0);
void AddChatMsg(const wchar_t* msg, int player);
void AddChatMsg(const wchar_t* msg, int player, bool play_sound = false);
void ClearChatMsg();
void AddDebugMsg(const char* msgbuf);
void ErrorLog(const char* msgbuf);
......@@ -168,6 +169,8 @@ public:
void CloseDuelWindow();
int LocalPlayer(int player) const;
int OppositePlayer(int player);
int ChatLocalPlayer(int player);
const wchar_t* LocalName(int local_player);
bool HasFocus(EGUI_ELEMENT_TYPE type) const {
......
......@@ -254,6 +254,7 @@ void ReplayMode::EndDuel() {
mainGame->actionSignal.Wait();
mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = true;
mainGame->dInfo.isReplay = false;
mainGame->dInfo.isSingleMode = false;
......@@ -273,6 +274,7 @@ void ReplayMode::EndDuel() {
void ReplayMode::Restart(bool refresh) {
end_duel(pduel);
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = true;
mainGame->dField.Clear();
//mainGame->device->setEventReceiver(&mainGame->dField);
......
......@@ -159,6 +159,7 @@ int SingleMode::SinglePlayThread() {
if(!is_closing) {
mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = true;
mainGame->dInfo.isSingleMode = false;
mainGame->gMutex.unlock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment