From f4d1442a8621fc852f3c64611ad6d3558ae8561b Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Mon, 29 Apr 2024 23:55:02 +0200 Subject: [PATCH] pvp option init --- client/GameChatHandler.cpp | 5 ++- client/lobby/CLobbyScreen.cpp | 16 ++++++-- client/lobby/CSelectionBase.cpp | 65 +++++++++++++++++++++++++-------- client/lobby/CSelectionBase.h | 23 ++++++++++-- 4 files changed, 84 insertions(+), 25 deletions(-) diff --git a/client/GameChatHandler.cpp b/client/GameChatHandler.cpp index cadace179..bae869aca 100644 --- a/client/GameChatHandler.cpp +++ b/client/GameChatHandler.cpp @@ -15,6 +15,7 @@ #include "PlayerLocalState.h" #include "globalLobby/GlobalLobbyClient.h" #include "lobby/CLobbyScreen.h" +#include "lobby/CSelectionBase.h" #include "adventureMap/CInGameConsole.h" @@ -73,8 +74,8 @@ void GameChatHandler::onNewLobbyMessageReceived(const std::string & senderName, formatted.replaceRawString(messageText); lobby->card->chat->addNewMessage(formatted.toString()); - if (!lobby->card->showChat) - lobby->toggleChat(); + if (lobby->card->chatMode != InfoCard::ChatMode::Enabled) + lobby->card->setChat(InfoCard::ChatMode::Enabled); } chatHistory.push_back({senderName, messageText, TextOperations::getCurrentFormattedTimeLocal()}); diff --git a/client/lobby/CLobbyScreen.cpp b/client/lobby/CLobbyScreen.cpp index fcaba8307..9cc436777 100644 --- a/client/lobby/CLobbyScreen.cpp +++ b/client/lobby/CLobbyScreen.cpp @@ -221,11 +221,21 @@ void CLobbyScreen::toggleMode(bool host) void CLobbyScreen::toggleChat() { - card->toggleChat(); - if(card->showChat) + switch(card->chatMode) + { + case InfoCard::ChatMode::Enabled: + card->setChat(InfoCard::ChatMode::PvP); 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); + break; + } } void CLobbyScreen::updateAfterStateChange() diff --git a/client/lobby/CSelectionBase.cpp b/client/lobby/CSelectionBase.cpp index e90b5b5cd..eabec4017 100644 --- a/client/lobby/CSelectionBase.cpp +++ b/client/lobby/CSelectionBase.cpp @@ -123,7 +123,7 @@ void CSelectionBase::toggleTab(std::shared_ptr tab) } InfoCard::InfoCard() - : showChat(true) + : chatMode(ChatMode::Enabled) { OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; setRedrawParent(true); @@ -137,6 +137,7 @@ InfoCard::InfoCard() mapDescription = std::make_shared("", descriptionRect, 1); playerListBg = std::make_shared(ImagePath::builtin("CHATPLUG.bmp"), 16, 276); chat = std::make_shared(Rect(18, 126, 335, 143)); + pvpBox = std::make_shared(Rect(18, 126, 335, 262)); buttonInvitePlayers = std::make_shared(Point(20, 365), AnimationPath::builtin("pregameInvitePlayers"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateRoomInviteInterface(); } ); buttonOpenGlobalLobby = std::make_shared(Point(188, 365), AnimationPath::builtin("pregameReturnToLobby"), CGI->generaltexth->zelp[105], [](){ CSH->getGlobalLobby().activateInterface(); }); @@ -193,9 +194,9 @@ InfoCard::InfoCard() labelGroupPlayers = std::make_shared(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE); disableLabelRedraws(); } - setChat(false); + setChat(ChatMode::Disabled); if (CSH->inLobbyRoom()) - setChat(true); // FIXME: less ugly version? + setChat(ChatMode::Enabled); // FIXME: less ugly version? } void InfoCard::disableLabelRedraws() @@ -249,7 +250,7 @@ void InfoCard::changeSelection() OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; // FIXME: We recreate them each time because CLabelGroup don't use smart pointers labelGroupPlayers = std::make_shared(FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE); - if(!showChat) + if(chatMode != ChatMode::Enabled) labelGroupPlayers->disable(); for(const auto & p : CSH->playerNames) @@ -266,18 +267,14 @@ void InfoCard::changeSelection() } } -void InfoCard::toggleChat() +void InfoCard::setChat(ChatMode setMode) { - setChat(!showChat); -} - -void InfoCard::setChat(bool activateChat) -{ - if(showChat == activateChat) + if(chatMode == setMode) return; - if(activateChat) + switch(setMode) { + case InfoCard::ChatMode::Enabled: if(SEL->screenType == ESelectionScreen::campaignList) { labelCampaignDescription->disable(); @@ -300,14 +297,15 @@ void InfoCard::setChat(bool activateChat) } mapDescription->disable(); chat->enable(); + pvpBox->disable(); playerListBg->enable(); - } - else - { + break; + case InfoCard::ChatMode::Disabled: buttonInvitePlayers->disable(); buttonOpenGlobalLobby->disable(); mapDescription->enable(); chat->disable(); + pvpBox->disable(); playerListBg->disable(); if(SEL->screenType == ESelectionScreen::campaignList) @@ -325,9 +323,34 @@ void InfoCard::setChat(bool activateChat) labelLossConditionText->enable(); 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(); } @@ -373,6 +396,16 @@ void CChatBox::addNewMessage(const std::string & text) chatHistory->slider->scrollToMax(); } +PvPBox::PvPBox(const Rect & rect) +{ + OBJ_CONSTRUCTION; + pos += rect.topLeft(); + setRedrawParent(true); + + buttonFlipCoin = std::make_shared(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) : CIntObject(SHOW_POPUP) { diff --git a/client/lobby/CSelectionBase.h b/client/lobby/CSelectionBase.h index 29b7ec911..f12a8da84 100644 --- a/client/lobby/CSelectionBase.h +++ b/client/lobby/CSelectionBase.h @@ -31,6 +31,7 @@ class ExtraOptionsTab; class SelectionTab; class InfoCard; class CChatBox; +class PvPBox; class CLabel; class CFlagBox; class CLabelGroup; @@ -107,9 +108,16 @@ class InfoCard : public CIntObject std::shared_ptr labelGroupPlayers; std::shared_ptr buttonInvitePlayers; std::shared_ptr buttonOpenGlobalLobby; -public: - bool showChat; + std::shared_ptr pvpBox; +public: + enum ChatMode { + Disabled, + Enabled, + PvP + }; + + ChatMode chatMode; std::shared_ptr chat; std::shared_ptr flagbox; @@ -118,8 +126,7 @@ public: InfoCard(); void disableLabelRedraws(); void changeSelection(); - void toggleChat(); - void setChat(bool activateChat); + void setChat(ChatMode setMode); }; class CChatBox : public CIntObject @@ -136,6 +143,14 @@ public: void addNewMessage(const std::string & text); }; +class PvPBox : public CIntObject +{ +public: + std::shared_ptr buttonFlipCoin; + + PvPBox(const Rect & rect); +}; + class CFlagBox : public CIntObject { std::shared_ptr iconsTeamFlags;