1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

pvp option init

This commit is contained in:
Laserlicht
2024-04-29 23:55:02 +02:00
parent a5361abe16
commit f4d1442a86
4 changed files with 84 additions and 25 deletions

View File

@@ -15,6 +15,7 @@
#include "PlayerLocalState.h" #include "PlayerLocalState.h"
#include "globalLobby/GlobalLobbyClient.h" #include "globalLobby/GlobalLobbyClient.h"
#include "lobby/CLobbyScreen.h" #include "lobby/CLobbyScreen.h"
#include "lobby/CSelectionBase.h"
#include "adventureMap/CInGameConsole.h" #include "adventureMap/CInGameConsole.h"
@@ -73,8 +74,8 @@ void GameChatHandler::onNewLobbyMessageReceived(const std::string & senderName,
formatted.replaceRawString(messageText); formatted.replaceRawString(messageText);
lobby->card->chat->addNewMessage(formatted.toString()); lobby->card->chat->addNewMessage(formatted.toString());
if (!lobby->card->showChat) if (lobby->card->chatMode != InfoCard::ChatMode::Enabled)
lobby->toggleChat(); lobby->card->setChat(InfoCard::ChatMode::Enabled);
} }
chatHistory.push_back({senderName, messageText, TextOperations::getCurrentFormattedTimeLocal()}); chatHistory.push_back({senderName, messageText, TextOperations::getCurrentFormattedTimeLocal()});

View File

@@ -221,11 +221,21 @@ void CLobbyScreen::toggleMode(bool host)
void CLobbyScreen::toggleChat() void CLobbyScreen::toggleChat()
{ {
card->toggleChat(); switch(card->chatMode)
if(card->showChat) {
case InfoCard::ChatMode::Enabled:
card->setChat(InfoCard::ChatMode::PvP);
buttonChat->setTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL, Colors::WHITE); buttonChat->setTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL, Colors::WHITE);
else break;
case InfoCard::ChatMode::Disabled:
card->setChat(InfoCard::ChatMode::Enabled);
buttonChat->setTextOverlay("PvP actions", FONT_SMALL, Colors::WHITE);
break;
case InfoCard::ChatMode::PvP:
card->setChat(InfoCard::ChatMode::Disabled);
buttonChat->setTextOverlay(CGI->generaltexth->allTexts[532], FONT_SMALL, Colors::WHITE); buttonChat->setTextOverlay(CGI->generaltexth->allTexts[532], FONT_SMALL, Colors::WHITE);
break;
}
} }
void CLobbyScreen::updateAfterStateChange() void CLobbyScreen::updateAfterStateChange()

View File

@@ -123,7 +123,7 @@ void CSelectionBase::toggleTab(std::shared_ptr<CIntObject> tab)
} }
InfoCard::InfoCard() InfoCard::InfoCard()
: showChat(true) : chatMode(ChatMode::Enabled)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
setRedrawParent(true); setRedrawParent(true);
@@ -137,6 +137,7 @@ InfoCard::InfoCard()
mapDescription = std::make_shared<CTextBox>("", descriptionRect, 1); mapDescription = std::make_shared<CTextBox>("", descriptionRect, 1);
playerListBg = std::make_shared<CPicture>(ImagePath::builtin("CHATPLUG.bmp"), 16, 276); playerListBg = std::make_shared<CPicture>(ImagePath::builtin("CHATPLUG.bmp"), 16, 276);
chat = std::make_shared<CChatBox>(Rect(18, 126, 335, 143)); chat = std::make_shared<CChatBox>(Rect(18, 126, 335, 143));
pvpBox = std::make_shared<PvPBox>(Rect(18, 126, 335, 262));
buttonInvitePlayers = std::make_shared<CButton>(Point(20, 365), AnimationPath::builtin("pregameInvitePlayers"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateRoomInviteInterface(); } ); buttonInvitePlayers = std::make_shared<CButton>(Point(20, 365), AnimationPath::builtin("pregameInvitePlayers"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateRoomInviteInterface(); } );
buttonOpenGlobalLobby = std::make_shared<CButton>(Point(188, 365), AnimationPath::builtin("pregameReturnToLobby"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateInterface(); }); buttonOpenGlobalLobby = std::make_shared<CButton>(Point(188, 365), AnimationPath::builtin("pregameReturnToLobby"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateInterface(); });
@@ -193,9 +194,9 @@ InfoCard::InfoCard()
labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE); labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
disableLabelRedraws(); disableLabelRedraws();
} }
setChat(false); setChat(ChatMode::Disabled);
if (CSH->inLobbyRoom()) if (CSH->inLobbyRoom())
setChat(true); // FIXME: less ugly version? setChat(ChatMode::Enabled); // FIXME: less ugly version?
} }
void InfoCard::disableLabelRedraws() void InfoCard::disableLabelRedraws()
@@ -249,7 +250,7 @@ void InfoCard::changeSelection()
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
// FIXME: We recreate them each time because CLabelGroup don't use smart pointers // FIXME: We recreate them each time because CLabelGroup don't use smart pointers
labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE); labelGroupPlayers = std::make_shared<CLabelGroup>(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
if(!showChat) if(chatMode != ChatMode::Enabled)
labelGroupPlayers->disable(); labelGroupPlayers->disable();
for(const auto & p : CSH->playerNames) for(const auto & p : CSH->playerNames)
@@ -266,18 +267,14 @@ void InfoCard::changeSelection()
} }
} }
void InfoCard::toggleChat() void InfoCard::setChat(ChatMode setMode)
{ {
setChat(!showChat); if(chatMode == setMode)
}
void InfoCard::setChat(bool activateChat)
{
if(showChat == activateChat)
return; return;
if(activateChat) switch(setMode)
{ {
case InfoCard::ChatMode::Enabled:
if(SEL->screenType == ESelectionScreen::campaignList) if(SEL->screenType == ESelectionScreen::campaignList)
{ {
labelCampaignDescription->disable(); labelCampaignDescription->disable();
@@ -300,14 +297,15 @@ void InfoCard::setChat(bool activateChat)
} }
mapDescription->disable(); mapDescription->disable();
chat->enable(); chat->enable();
pvpBox->disable();
playerListBg->enable(); playerListBg->enable();
} break;
else case InfoCard::ChatMode::Disabled:
{
buttonInvitePlayers->disable(); buttonInvitePlayers->disable();
buttonOpenGlobalLobby->disable(); buttonOpenGlobalLobby->disable();
mapDescription->enable(); mapDescription->enable();
chat->disable(); chat->disable();
pvpBox->disable();
playerListBg->disable(); playerListBg->disable();
if(SEL->screenType == ESelectionScreen::campaignList) if(SEL->screenType == ESelectionScreen::campaignList)
@@ -325,9 +323,34 @@ void InfoCard::setChat(bool activateChat)
labelLossConditionText->enable(); labelLossConditionText->enable();
labelGroupPlayers->disable(); labelGroupPlayers->disable();
} }
break;
case InfoCard::ChatMode::PvP:
buttonInvitePlayers->disable();
buttonOpenGlobalLobby->disable();
mapDescription->disable();
chat->disable();
pvpBox->enable();
playerListBg->enable();
if(SEL->screenType == ESelectionScreen::campaignList)
{
labelCampaignDescription->disable();
}
else
{
labelScenarioDescription->disable();
labelVictoryCondition->disable();
labelLossCondition->disable();
iconsVictoryCondition->disable();
iconsLossCondition->disable();
labelVictoryConditionText->disable();
labelLossConditionText->disable();
labelGroupPlayers->disable();
}
break;
} }
showChat = activateChat; chatMode = setMode;
GH.windows().totalRedraw(); GH.windows().totalRedraw();
} }
@@ -373,6 +396,16 @@ void CChatBox::addNewMessage(const std::string & text)
chatHistory->slider->scrollToMax(); chatHistory->slider->scrollToMax();
} }
PvPBox::PvPBox(const Rect & rect)
{
OBJ_CONSTRUCTION;
pos += rect.topLeft();
setRedrawParent(true);
buttonFlipCoin = std::make_shared<CButton>(Point(17, 160), AnimationPath::builtin("GSPBUT2.DEF"), CButton::tooltip("flip coin"), [](){ std::cout << "coin flip"; }, EShortcut::NONE);
buttonFlipCoin->setTextOverlay("Flip coin2", EFonts::FONT_SMALL, Colors::WHITE);
}
CFlagBox::CFlagBox(const Rect & rect) CFlagBox::CFlagBox(const Rect & rect)
: CIntObject(SHOW_POPUP) : CIntObject(SHOW_POPUP)
{ {

View File

@@ -31,6 +31,7 @@ class ExtraOptionsTab;
class SelectionTab; class SelectionTab;
class InfoCard; class InfoCard;
class CChatBox; class CChatBox;
class PvPBox;
class CLabel; class CLabel;
class CFlagBox; class CFlagBox;
class CLabelGroup; class CLabelGroup;
@@ -107,9 +108,16 @@ class InfoCard : public CIntObject
std::shared_ptr<CLabelGroup> labelGroupPlayers; std::shared_ptr<CLabelGroup> labelGroupPlayers;
std::shared_ptr<CButton> buttonInvitePlayers; std::shared_ptr<CButton> buttonInvitePlayers;
std::shared_ptr<CButton> buttonOpenGlobalLobby; std::shared_ptr<CButton> buttonOpenGlobalLobby;
public:
bool showChat; std::shared_ptr<PvPBox> pvpBox;
public:
enum ChatMode {
Disabled,
Enabled,
PvP
};
ChatMode chatMode;
std::shared_ptr<CChatBox> chat; std::shared_ptr<CChatBox> chat;
std::shared_ptr<CFlagBox> flagbox; std::shared_ptr<CFlagBox> flagbox;
@@ -118,8 +126,7 @@ public:
InfoCard(); InfoCard();
void disableLabelRedraws(); void disableLabelRedraws();
void changeSelection(); void changeSelection();
void toggleChat(); void setChat(ChatMode setMode);
void setChat(bool activateChat);
}; };
class CChatBox : public CIntObject class CChatBox : public CIntObject
@@ -136,6 +143,14 @@ public:
void addNewMessage(const std::string & text); void addNewMessage(const std::string & text);
}; };
class PvPBox : public CIntObject
{
public:
std::shared_ptr<CButton> buttonFlipCoin;
PvPBox(const Rect & rect);
};
class CFlagBox : public CIntObject class CFlagBox : public CIntObject
{ {
std::shared_ptr<CAnimation> iconsTeamFlags; std::shared_ptr<CAnimation> iconsTeamFlags;