diff --git a/assets/JunicodeBold.ttf b/assets/JunicodeBold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..62d497d80a84929bf6baf7954e00b25b4c2df36a Binary files /dev/null and b/assets/JunicodeBold.ttf differ diff --git a/assets/MagicSchoolOne.ttf b/assets/MagicSchoolOne.ttf new file mode 100644 index 0000000000000000000000000000000000000000..80430c0aaff35b1455a708b99ea00fcd44a84593 Binary files /dev/null and b/assets/MagicSchoolOne.ttf differ diff --git a/src/client/GameController.cpp b/src/client/GameController.cpp index 74cbdc1b6eadfb9b7326e012788366c6c174d0a8..d90ba6062e4c4efa3dc923816de1d82699b97c40 100644 --- a/src/client/GameController.cpp +++ b/src/client/GameController.cpp @@ -19,7 +19,6 @@ player* GameController::_me = nullptr; game_state* GameController::_currentGameState = nullptr; - void GameController::init(GameWindow* gameWindow) { //TODO: panels need to be adapted @@ -77,6 +76,13 @@ void GameController::connectToServer() { // convert player name from wxString to std::string std::string playerName = inputPlayerName.ToStdString(); + //player name length check + if (playerName.size() > 15) + { + GameController::showError("Connection error", "Invalid player name length. Please enter a player name between 1 and 15 characters."); + return; + } + // connect to network ClientNetworkManager::init(host, port); @@ -86,6 +92,7 @@ void GameController::connectToServer() { join_game_request request = join_game_request(GameController::_me->get_id(), GameController::_me->get_player_name()); ClientNetworkManager::sendRequest(request); + } @@ -146,6 +153,7 @@ void GameController::updateGameState(game_state* newGameState) { void GameController::startGame() { start_game_request request = start_game_request(GameController::_currentGameState->get_id(), GameController::_me->get_id()); ClientNetworkManager::sendRequest(request); + } void GameController::estimateTricks(int nof_tricks) { @@ -249,6 +257,7 @@ void GameController::showNewRoundMessage(game_state* oldGameState, game_state* n //dialogBox.ShowModal(); auto* dialog = new ScoreDialog(GameController::_gameWindow, title, message); + dialog->ShowModal(); } @@ -301,6 +310,7 @@ void GameController::showGameOverMessage() { wxMessageDialog dialogBox = wxMessageDialog(nullptr, message, title, wxICON_NONE); dialogBox.SetOKLabel(wxMessageDialog::ButtonLabel(buttonLabel)); int buttonClicked = dialogBox.ShowModal(); + if(buttonClicked == wxID_OK) { GameController::_gameWindow->Close(); } diff --git a/src/client/panels/ConnectionPanel.cpp b/src/client/panels/ConnectionPanel.cpp index 0a1a16c13499acf5320a7c2254d04a689869c24a..16ebca94937214f630c33e0c755537751d0d8575 100644 --- a/src/client/panels/ConnectionPanel.cpp +++ b/src/client/panels/ConnectionPanel.cpp @@ -7,6 +7,10 @@ ConnectionPanel::ConnectionPanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) { + // font for buttons + wxFont magicalFont = wxFont(wxFontInfo(20).FaceName("Magic School One")); + //font for regular text + wxFont regularFont = wxFont(wxFontInfo(12).FaceName("Junicode")); // Load the background image _backgroundImage.LoadFile("./assets/Wizard_big.png", wxBITMAP_TYPE_ANY); @@ -18,29 +22,40 @@ ConnectionPanel::ConnectionPanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) { // Main vertical layout for input fields and button wxBoxSizer* verticalLayout = new wxBoxSizer(wxVERTICAL); - int fieldSpacing = 10; // Space between input fields and button + int fieldSpacing = 12; // Space between input fields and button // Default values for server host and port wxString default_server_host = "127.0.0.1"; int default_port = 50505; // Server Address Input Field - this->_serverAddressField = new InputField(this, "Server address:", 100, default_server_host, 240); + this->_serverAddressField = new InputField(this, "Server address:", 100, default_server_host, 240); //field width is the width of the white text field + //label width is the width of the label text + this->_serverAddressField->SetFont(regularFont); //set font this->_serverAddressField->SetLabelTextColour(wxColour(255, 255, 255)); // Set label text color to white + this->_serverAddressField->SetMinSize(wxSize(-1, 27)); verticalLayout->Add(this->_serverAddressField, 0, wxALL | wxEXPAND, fieldSpacing); + + // Server Port Input Field this->_serverPortField = new InputField(this, "Server port:", 100, wxString::Format("%i", default_port), 240); + this->_serverPortField->SetFont(regularFont); this->_serverPortField->SetLabelTextColour(wxColour(255, 255, 255)); // Set label text color to white + this->_serverPortField->SetMinSize(wxSize(-1, 27)); verticalLayout->Add(this->_serverPortField, 0, wxALL | wxEXPAND, fieldSpacing); // Player Name Input Field this->_playerNameField = new InputField(this, "Player name:", 100, "", 240); + this->_playerNameField->SetFont(regularFont); this->_playerNameField->SetLabelTextColour(wxColour(255, 255, 255)); // Set label text color to white + this->_playerNameField->SetMinSize(wxSize(-1, 27)); verticalLayout->Add(this->_playerNameField, 0, wxALL | wxEXPAND, fieldSpacing); + // Connect Button with custom style - wxButton* connectButton = new wxButton(this, wxID_ANY, "Connect", wxDefaultPosition, wxDefaultSize); + wxButton* connectButton = new wxButton(this, wxID_ANY, "Connect", wxDefaultPosition, wxSize(80, 37)); //changed size to make margins between text and button smaller + connectButton->SetFont(magicalFont); connectButton->SetForegroundColour(wxColour(225, 225, 225)); // Set button text color connectButton->SetBackgroundColour(wxColour(102, 0, 51)); // Set button background color connectButton->SetWindowStyleFlag(wxBORDER_SIMPLE); // Set border style diff --git a/src/client/panels/MainGamePanelWizard.cpp b/src/client/panels/MainGamePanelWizard.cpp index 672ba92c9133f8933c3cedc0018d81eafdad414b..39ab8276210ed1ef9c997dd5a6950cd938be42ae 100644 --- a/src/client/panels/MainGamePanelWizard.cpp +++ b/src/client/panels/MainGamePanelWizard.cpp @@ -5,8 +5,23 @@ #include <wx/grid.h> #include "../messageBoxes/ScoreBoardDialog.h" + + +// font for buttons +wxFont magicalFont = wxFont(wxFontInfo(20).FaceName("Magic School One")); + +//font for general text +wxFont regularFont = wxFont(wxFontInfo(12).FaceName("Junicode")); //requires yy:20 + +//font for player names +wxFont regularFontBig = wxFont(wxFontInfo(16).FaceName("Junicode")); //requires yy:35, xx:150 + +//font for round announcement +wxFont magicalFontGigantic = wxFont(wxFontInfo(70).FaceName("Magic School One")); + + MainGamePanelWizard::MainGamePanelWizard(wxWindow* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(960, 680)) { - this->SetMinSize(wxSize(960, 680)); + this->SetMinSize(wxSize(1000, 680)); } @@ -156,7 +171,11 @@ void MainGamePanelWizard::buildScoreBoardButton(wxGridBagSizer *sizer, game_stat wxBoxSizer *sizer_vert = new wxBoxSizer(wxVERTICAL); panel->SetSizer(sizer_vert); - wxButton *scoreBoardButton = new wxButton(panel, wxID_ANY, "ScoreBoard"); + wxButton* scoreBoardButton = new wxButton(panel, wxID_ANY, "Scoreboard", wxDefaultPosition, wxSize(110, 43));//size wxSize(110, 43)) for 10 characters; + // wxButton* startGameButton = new wxButton(mePanel, wxID_ANY, "Start Game!", wxDefaultPosition, wxSize(110, 43)); + scoreBoardButton->SetFont(magicalFont); + scoreBoardButton->SetForegroundColour(wxColour(225, 225, 225)); // Set button text color + scoreBoardButton->SetBackgroundColour(wxColour(50, 0, 51)); //same shade of purple as start game button and estimation panel sizer_vert->Add(scoreBoardButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); scoreBoardButton->Bind(wxEVT_BUTTON, [gameState](wxCommandEvent &event) { @@ -210,30 +229,28 @@ void MainGamePanelWizard::buildOtherPlayers(wxGridBagSizer* sizer, game_state* g // Lobby: display names if(!gameState->is_started()) { - wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, otherPlayer->get_player_name(),wxDefaultPosition, wxSize(panel->GetMinSize().GetWidth(), 25), wxALIGN_CENTER); + wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, otherPlayer->get_player_name(),wxDefaultPosition, wxSize(150, 35), wxALIGN_CENTER); playerNameText->SetForegroundColour(*wxWHITE); - - // increase font size of the player name - wxFont font = playerNameText->GetFont(); // Get the current font of the wxStaticText - font.SetPointSize(14); - playerNameText->SetFont(font); + playerNameText->SetFont(regularFontBig); wxStaticText* statusText = new wxStaticText(panel, wxID_ANY, "waiting...",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); statusText->SetForegroundColour(*wxWHITE); - + statusText->SetFont(regularFont); playerSizer_vert->Add(playerNameText,0,wxALIGN_CENTER|wxTOP, 5); playerSizer_vert->Add(statusText,0,wxALIGN_CENTER); } // game started: display names, predicted and scored tricks else { - wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, otherPlayer->get_player_name(),wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + // 15 characters for player name + wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, otherPlayer->get_player_name(),wxDefaultPosition, wxSize(150, 35), wxALIGN_CENTER); playerNameText->SetForegroundColour(*wxWHITE); + playerNameText->SetFont(regularFontBig); - wxStaticText* trickText = new wxStaticText(panel, wxID_ANY, std::to_string(otherPlayer->get_nof_tricks()) + "/" + std::to_string(otherPlayer->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* trickText = new wxStaticText(panel, wxID_ANY, std::to_string(otherPlayer->get_nof_tricks()) + "/" + std::to_string(otherPlayer->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxSize(100, 20), wxALIGN_CENTER); trickText->SetForegroundColour(*wxWHITE); - + trickText->SetFont(regularFont); playerSizer_vert->Add(playerNameText,0,wxALIGN_CENTER|wxTOP,5); playerSizer_vert->Add(trickText,0,wxALIGN_CENTER); } @@ -252,7 +269,7 @@ void MainGamePanelWizard::buildTrumpCard(wxGridBagSizer* sizer, game_state* game { wxStaticText* trumpText = new wxStaticText(trumpPanel, wxID_ANY, "TRUMP CARD",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); trumpText->SetForegroundColour(*wxWHITE); - + trumpText->SetFont(regularFont); int trumpColor = gameState->get_trump_color(); std::string cardImage = "assets/card_" + std::to_string(trumpColor) + ".png"; @@ -294,12 +311,45 @@ void MainGamePanelWizard::buildTrickPile(wxGridBagSizer* sizer, game_state* game trickPanelSizer_hor->Add(wizardLogo, 0, wxALIGN_CENTER ); } } +/* +// TODO: round announcement shown at the beginning of every new round +void MainGamePanelWizard::showRoundOverlay(int roundNumber) { //obtain round number with std::to_string(gameState->get_round_number()+1) + // Create a panel to act as the overlay + wxPanel* overlayPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, this->GetSize()); //create panel the size of the main game panel + overlayPanel->SetBackgroundColour(wxColour(0, 0, 0, 70)); // make current game panel opaque + + // Create the text + wxString roundText = wxString::Format("ROUND %d", roundNumber); + wxStaticText* roundLabel = new wxStaticText(overlayPanel, wxID_ANY, roundText, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + roundLabel->SetFont(magicalFontGigantic); + roundLabel->SetForegroundColour(*wxWHITE); + + // center text + wxBoxSizer* overlaySizer = new wxBoxSizer(wxVERTICAL); + overlaySizer->AddStretchSpacer(1); + overlaySizer->Add(roundLabel, 0, wxALIGN_CENTER_HORIZONTAL); + overlaySizer->AddStretchSpacer(1); + + overlayPanel->SetSizer(overlaySizer); + + // Show the overlay + overlayPanel->Raise(); + overlayPanel->Show(); + + // Set a timer to remove the overlay after 1 second + wxTimer* timer = new wxTimer(this, wxID_ANY); + timer->Bind(wxEVT_TIMER, [this, overlayPanel](wxTimerEvent& event) { + overlayPanel->Destroy(); // Remove the overlay panel + }); + timer->Start(1000, wxTIMER_ONE_SHOT); // 1-second delay +} +*/ void MainGamePanelWizard::buildTurnIndicator(wxGridBagSizer* sizer, game_state* gameState, player* me) { wxGBSizerItem* turnItem = sizer->FindItemAtPosition(wxGBPosition(2,0)); wxPanel* turnPanel = dynamic_cast<wxPanel*>(turnItem->GetWindow()); - turnPanel->SetMinSize(wxSize(10,20)); + turnPanel->SetMinSize(wxSize(50,25)); //make turn display panel a bit more wide // add sizer to center the text auto turnIndicatorPanelSizer_vert = new wxBoxSizer(wxVERTICAL); @@ -314,15 +364,17 @@ void MainGamePanelWizard::buildTurnIndicator(wxGridBagSizer* sizer, game_state* if (gameState->get_current_player() == me) { turnIndicatorText = "It is your turn!"; + } else { turnIndicatorText = "It is " + gameState->get_current_player()->get_player_name() + "'s turn!"; } - wxStaticText* turnText = new wxStaticText(turnPanel, wxID_ANY, turnIndicatorText,wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* turnText = new wxStaticText(turnPanel, wxID_ANY, turnIndicatorText,wxDefaultPosition, wxSize(270, 50), wxALIGN_CENTER); + // width 12 + 15 player name --> 27 characters turnText->SetForegroundColour(*wxWHITE); - + turnText->SetFont(regularFontBig); turnIndicatorPanelSizer_hor->Add(turnText, 0, wxALIGN_CENTER); } @@ -341,13 +393,10 @@ void MainGamePanelWizard::buildThisPlayer(wxGridBagSizer* sizer, game_state* gam meSizer_hor->Add(meSizer, 1, wxALIGN_BOTTOM); // add player name to the panel - wxStaticText* playerName = new wxStaticText(mePanel, wxID_ANY, me->get_player_name(),wxDefaultPosition, wxSize(mePanel->GetMinSize().GetWidth(), 25), wxALIGN_CENTER); + wxStaticText* playerName = new wxStaticText(mePanel, wxID_ANY, me->get_player_name(),wxDefaultPosition, wxSize(mePanel->GetMinSize().GetWidth(), 35), wxALIGN_CENTER); playerName->SetForegroundColour(*wxWHITE); + playerName->SetFont(regularFontBig); - // increase font size of the player - wxFont font = playerName->GetFont(); // Get the current font of the wxStaticText - font.SetPointSize(14); - playerName->SetFont(font); meSizer->Add(playerName, 0, wxALIGN_CENTER); @@ -355,11 +404,15 @@ void MainGamePanelWizard::buildThisPlayer(wxGridBagSizer* sizer, game_state* gam { // add status text (waiting) wxStaticText* playerScore = new wxStaticText(mePanel, wxID_ANY, "Waiting for the game to start",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + //playerScore->SetFont(regularFont); playerScore->SetForegroundColour(*wxWHITE); + playerScore->SetFont(regularFont); meSizer->Add(playerScore, 0, wxALIGN_CENTER|wxALL,5); // show button that allows our player to start the game - wxButton* startGameButton = new wxButton(mePanel, wxID_ANY, "Start Game!", wxDefaultPosition, wxSize(100, 32)); + wxButton* startGameButton = new wxButton(mePanel, wxID_ANY, "Start Game!", wxDefaultPosition, wxSize(110, 43)); //110 pixels wide, 43 high + startGameButton->SetFont(magicalFont); + startGameButton->Bind(wxEVT_BUTTON, [](wxCommandEvent& event) { GameController::startGame(); }); @@ -369,8 +422,9 @@ void MainGamePanelWizard::buildThisPlayer(wxGridBagSizer* sizer, game_state* gam int numberOfPlayers = players.size(); if (numberOfPlayers >= 3) { - startGameButton->SetBackgroundColour(wxColor(34,139,34)); - startGameButton->SetForegroundColour(*wxWHITE); + //make button same as connect button once enough players + startGameButton->SetForegroundColour(wxColour(225, 225, 225)); // Set button text color + startGameButton->SetBackgroundColour(wxColour(50, 0, 51)); //make button same purple as estimation panel once clickable } meSizer->Add(startGameButton,0,wxALIGN_CENTER|wxALL, 5); @@ -378,9 +432,9 @@ void MainGamePanelWizard::buildThisPlayer(wxGridBagSizer* sizer, game_state* gam else { // show estimated and scored tricks instead of status text - wxStaticText* playerScore = new wxStaticText(mePanel, wxID_ANY, std::to_string(me->get_nof_tricks()) + "/" + std::to_string(me->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* playerScore = new wxStaticText(mePanel, wxID_ANY, std::to_string(me->get_nof_tricks()) + "/" + std::to_string(me->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxSize(100, 20), wxALIGN_CENTER); playerScore->SetForegroundColour(*wxWHITE); - + playerScore->SetFont(regularFont); meSizer->Add(playerScore, 0, wxALIGN_CENTER); // display our hand diff --git a/src/client/panels/MainGamePanelWizard.h b/src/client/panels/MainGamePanelWizard.h index cd1e7cf7ed88f351adca7d09b7d5dd0b86cda7db..696a26a56c1c65e6ab3eef8e406ca145ced6684a 100644 --- a/src/client/panels/MainGamePanelWizard.h +++ b/src/client/panels/MainGamePanelWizard.h @@ -16,7 +16,7 @@ private: void buildThisPlayer(wxGridBagSizer* sizer, game_state* gameState, player* me); void buildTurnIndicator(wxGridBagSizer* sizer, game_state* gameState, player* me); void buildOtherPlayers(wxGridBagSizer* sizer, game_state* gameState, player *me, int myPosition); - + void showRoundOverlay(int roundNumber); void buildTrickPile(wxGridBagSizer* sizer, game_state* gameState, player *me); void buildTrumpCard(wxGridBagSizer* sizer, game_state* gameState); diff --git a/src/client/panels/TrickEstimationPanel.cpp b/src/client/panels/TrickEstimationPanel.cpp index 34cb20d7efb8b49a76627b6890181de1cbdfcce0..0f3d5519826da9dff7378a69795e6cab0968bf05 100644 --- a/src/client/panels/TrickEstimationPanel.cpp +++ b/src/client/panels/TrickEstimationPanel.cpp @@ -3,6 +3,9 @@ #include "../GameController.h" #include "../messageBoxes/ScoreBoardDialog.h" +wxFont magicalFontTrick = wxFont(wxFontInfo(20).FaceName("Magic School One")); +wxFont regularFontTrick = wxFont(wxFontInfo(12).FaceName("Junicode")); +wxFont regularFontTrickBig = wxFont(wxFontInfo(18).FaceName("Junicode")); TrickEstimationPanel::TrickEstimationPanel(wxWindow* parent): wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(960, 680)){} @@ -22,7 +25,7 @@ void TrickEstimationPanel::buildGameState(game_state* gameState, player* me) wxPanel *panel = new wxPanel(this, wxID_ANY); this->SetBackgroundColour(wxColour(102,0,51)); - this->SetMinSize(wxSize(960, 680)); + this->SetMinSize(wxSize(1000, 680)); // a bit wider to make scoreboard button fit fully //create 3x3 Grid auto sizer = new wxGridBagSizer(4,3); @@ -113,7 +116,11 @@ void TrickEstimationPanel::buildScoreBoardButton(wxGridBagSizer *sizer, game_sta wxBoxSizer* sizer_vert = new wxBoxSizer(wxVERTICAL); panel->SetSizer(sizer_vert); - wxButton* scoreBoardButton = new wxButton(panel, wxID_ANY, "ScoreBoard"); + wxButton* scoreBoardButton = new wxButton(panel, wxID_ANY, "Scoreboard", wxDefaultPosition, wxSize(110, 43)); + scoreBoardButton->SetFont(magicalFontTrick); + scoreBoardButton->SetForegroundColour(wxColour(225, 225, 225)); // Set button text color + scoreBoardButton->SetBackgroundColour(wxColour(50, 0, 51)); //make button same purple as estimation panel once clickable + sizer_vert->Add(scoreBoardButton, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); scoreBoardButton->Bind(wxEVT_BUTTON, [gameState](wxCommandEvent& event) { @@ -132,11 +139,7 @@ void TrickEstimationPanel::buildTrumpColor(wxGridBagSizer *sizer, game_state *ga wxStaticText* trumpText = new wxStaticText(trumpPanel, wxID_ANY, "TRUMP CARD",wxDefaultPosition, wxSize(120, 20), wxALIGN_CENTER); trumpText->SetForegroundColour(*wxWHITE); - - // increase font size of trump card text - wxFont font = trumpText->GetFont(); // Get the current font of the wxStaticText - font.SetPointSize(14); - trumpText->SetFont(font); + trumpText->SetFont(regularFontTrickBig); int trumpColor = gameState->get_trump_color(); @@ -211,9 +214,11 @@ void TrickEstimationPanel::buildCenter(wxGridBagSizer* sizer, game_state* gameSt // add round number wxStaticText* roundNumber = new wxStaticText(centerPanel, wxID_ANY, "Round: " + std::to_string(gameState->get_round_number()+1),wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); roundNumber->SetForegroundColour(*wxWHITE); + roundNumber->SetFont(regularFontTrick); wxStaticText* trickSum = new wxStaticText(centerPanel, wxID_ANY, "Current prediction sum: " + std::to_string(gameState->get_trick_estimate_sum()),wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); trickSum->SetForegroundColour(*wxWHITE); + trickSum->SetFont(regularFontTrick); centerPanelSizer_vert2->Add(roundNumber, 0, wxALIGN_CENTER); @@ -232,13 +237,9 @@ void TrickEstimationPanel::buildThisPlayer(wxGridBagSizer* sizer, game_state* ga mePanel->SetBackgroundColour(wxColour(120,0,51)); // add our name - wxStaticText* playerName = new wxStaticText(mePanel, wxID_ANY, me->get_player_name(),wxDefaultPosition, wxSize(120, 20), wxALIGN_CENTER); + wxStaticText* playerName = new wxStaticText(mePanel, wxID_ANY, me->get_player_name(),wxDefaultPosition, wxSize(150, 35), wxALIGN_CENTER); playerName->SetForegroundColour(*wxWHITE); - - // increase font size of the player name - wxFont font = playerName->GetFont(); // Get the current font of the wxStaticText - font.SetPointSize(14); - playerName->SetFont(font); + playerName->SetFont(regularFontTrickBig); mePanelSizer_vert->Add(playerName, 0, wxALIGN_CENTER); @@ -250,8 +251,9 @@ void TrickEstimationPanel::buildThisPlayer(wxGridBagSizer* sizer, game_state* ga mePanel->SetBackgroundColour(wxColour(50,0,51)); // add input field for trick estimate - wxStaticText* inputLabel = new wxStaticText(mePanel, wxID_ANY, "Trick Estimate:",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* inputLabel = new wxStaticText(mePanel, wxID_ANY, "Trick Estimate:",wxDefaultPosition, wxSize(130, 20), wxALIGN_CENTER); inputLabel->SetForegroundColour(*wxWHITE); + inputLabel->SetFont(regularFontTrick); mePanelSizer_vert->Add(inputLabel, 0, wxALIGN_CENTER); @@ -260,7 +262,12 @@ void TrickEstimationPanel::buildThisPlayer(wxGridBagSizer* sizer, game_state* ga mePanelSizer_vert->Add(_trickEstimateField, 0, wxALIGN_CENTER|wxALL, 10); // show button that allows our player to start the game - wxButton* submitEstimateButton = new wxButton(mePanel, wxID_ANY, "Submit", wxDefaultPosition, wxSize(80, 32)); + wxButton* submitEstimateButton = new wxButton(mePanel, wxID_ANY, "Submit", wxDefaultPosition, wxSize(80, 43)); + submitEstimateButton->SetFont(magicalFontTrick); + submitEstimateButton->SetWindowStyleFlag(wxBORDER_SIMPLE); + submitEstimateButton->SetForegroundColour(wxColour(225, 225, 225)); // Set button text color + submitEstimateButton->SetBackgroundColour(wxColour(102, 0, 51)); // Set button background color + //make button the same as the connect button in the connection panel since the background is red submitEstimateButton->Bind(wxEVT_BUTTON, [](wxCommandEvent& event) { GameController::estimateTrick(); }); @@ -268,8 +275,10 @@ void TrickEstimationPanel::buildThisPlayer(wxGridBagSizer* sizer, game_state* ga } else { - wxStaticText* playerName = new wxStaticText(mePanel, wxID_ANY, "waiting...",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* playerName = new wxStaticText(mePanel, wxID_ANY, "waiting...",wxDefaultPosition, wxSize(110, 20), wxALIGN_CENTER); + //large enough for a 15 character name playerName->SetForegroundColour(*wxWHITE); + playerName->SetFont(regularFontTrick); mePanelSizer_vert->Add(playerName, 0, wxALIGN_CENTER); } } @@ -278,8 +287,9 @@ void TrickEstimationPanel::buildThisPlayer(wxGridBagSizer* sizer, game_state* ga else { // display the number of tricks - wxStaticText* estimatedTricks = new wxStaticText(mePanel, wxID_ANY, std::to_string(me->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* estimatedTricks = new wxStaticText(mePanel, wxID_ANY, std::to_string(me->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxSize(110, 20), wxALIGN_CENTER); estimatedTricks->SetForegroundColour(*wxWHITE); + estimatedTricks->SetFont(regularFontTrick); mePanelSizer_vert->Add(estimatedTricks, 0, wxALIGN_CENTER); } // mePanel->SetSizer(mePanelSizer_hor); @@ -316,19 +326,16 @@ void TrickEstimationPanel::buildOtherPlayers(wxGridBagSizer* sizer, game_state* wxPanel* panel = dynamic_cast<wxPanel*>(item->GetWindow()); wxBoxSizer* playerSizer_vert = new wxBoxSizer(wxVERTICAL); panel->SetSizer(playerSizer_vert); + panel->SetFont(regularFontTrick); panel->SetBackgroundColour(wxColour(120,0,51)); player* otherPlayer = players.at((myPosition + i +1) % numberOfPlayers); // display name - wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, otherPlayer->get_player_name(),wxDefaultPosition, wxSize(panel->GetMinSize().GetWidth(), 25), wxALIGN_CENTER); + wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, otherPlayer->get_player_name(),wxDefaultPosition, wxSize(panel->GetMinSize().GetWidth(), 35), wxALIGN_CENTER); playerNameText->SetForegroundColour(*wxWHITE); - - // increase font size of the player name - wxFont font = playerNameText->GetFont(); // Get the current font of the wxStaticText - font.SetPointSize(14); - playerNameText->SetFont(font); + playerNameText->SetFont(regularFontTrickBig); playerSizer_vert->Add(playerNameText, 0, wxALIGN_CENTER|wxTOP, 5); @@ -340,19 +347,23 @@ void TrickEstimationPanel::buildOtherPlayers(wxGridBagSizer* sizer, game_state* if (otherPlayer == gameState->get_current_player()){ statusText = "estimating..."; panel->SetBackgroundColour(wxColour(50,0,51)); + } else{ statusText = "waiting..."; } - wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, statusText,wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, statusText,wxDefaultPosition, wxSize(150, 30), wxALIGN_CENTER); playerNameText->SetForegroundColour(*wxWHITE); + playerNameText->SetFont(regularFontTrick); playerSizer_vert->Add(playerNameText, 0, wxALIGN_CENTER); } else { - wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, std::to_string(otherPlayer->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); + wxStaticText* playerNameText = new wxStaticText(panel, wxID_ANY, std::to_string(otherPlayer->get_nof_predicted()) + " Tricks",wxDefaultPosition, wxSize(80, 20), wxALIGN_CENTER); + //8 characters, width 80 playerNameText->SetForegroundColour(*wxWHITE); + playerNameText->SetFont(regularFontTrick); playerSizer_vert->Add(playerNameText, 0, wxALIGN_CENTER); } diff --git a/src/common/game_state/game_state.cpp b/src/common/game_state/game_state.cpp index 484cc973265615a540e017fbbc9240f63a0f84b6..dbadead893ab62b04be85f6d36113e0ef58af288 100644 --- a/src/common/game_state/game_state.cpp +++ b/src/common/game_state/game_state.cpp @@ -48,7 +48,28 @@ game_state::game_state(const std::string& id, const std::vector<player*>& player _current_player_idx(current_player_idx), _trump_color(trump_color), _trick_estimate_sum(trick_estimate_sum) -{ } +{ + //checks if all player names are unique. if not, add _1, _2 etc. to the duplicate names + std::unordered_map<std::string, int> name_counts; // track occurrences of names + + for (player* p : _players) { + std::string original_name = p->get_player_name(); + std::string unique_name = original_name; + if (name_counts[original_name] > 0) { + // Assign a unique suffix based on the current count + unique_name = original_name + "_" + std::to_string(name_counts[original_name]); + } + + // Increment count for new and original name + name_counts[original_name]++; + name_counts[unique_name]++; + + // update player's name if modified + if (unique_name != original_name) { + p->set_player_name(unique_name); + } + } +} // public constructor game_state::game_state() : unique_serializable() @@ -69,6 +90,8 @@ game_state::game_state() : unique_serializable() _current_player_idx = new serializable_value<int>(0); _trump_color = new serializable_value<int>(0); _trick_estimate_sum = new serializable_value<int>(0); + + } // destructor diff --git a/src/common/game_state/player/player.cpp b/src/common/game_state/player/player.cpp index 479aff727e8cb2922a3bb6618fadcd148e5d617c..2efef60fb69299dd3d84775c1eac903826a4460e 100644 --- a/src/common/game_state/player/player.cpp +++ b/src/common/game_state/player/player.cpp @@ -100,12 +100,18 @@ void player::set_nof_predicted(const int nof_predicted) const } -// other getters +// getter and setter for player name std::string player::get_player_name() const noexcept { return this->_player_name->get_value(); } +void player::set_player_name(const std::string& new_name) +{ + _player_name->set_value(new_name); +} + +// other getters hand* player::get_hand() const noexcept { return this->_hand; diff --git a/src/common/game_state/player/player.h b/src/common/game_state/player/player.h index 439a665a7bb503a757f8f5e62e32ff54fbe5a875..1eb41bde7cb0d4741d76bbc93656aaaf6343ccda 100644 --- a/src/common/game_state/player/player.h +++ b/src/common/game_state/player/player.h @@ -139,6 +139,15 @@ public: */ [[nodiscard]] std::string get_player_name() const noexcept; + /** + * @brief Sets the player's name to the given input. + * @param new_name The new player name. + * + * This function is used to change the player's name in case duplicate names appear within one game. + */ + + void set_player_name(const std::string& new_name); + #ifdef WIZARD_SERVER // state update functions /**