diff --git a/CMakeLists.txt b/CMakeLists.txt index d19dc91e71251f0e28cda5db5c223b88b6c388ad..a98a8e546e6c95d334be7014979bbe00420f2106 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,9 @@ set(CLIENT_SOURCE_FILES src/common/serialization/serializable_value.h src/common/serialization/json_utils.h src/common/serialization/uuid_generator.h - src/common/serialization/unique_serializable.cpp src/common/serialization/unique_serializable.h) + src/common/serialization/unique_serializable.cpp src/common/serialization/unique_serializable.h + src/client/messageBoxes/ErrorDialog.cpp + src/client/messageBoxes/ErrorDialog.h) # define a variable SERVER_SOURCE_FILES that contains the paths to all source files required to compile the server executable set(SERVER_SOURCE_FILES @@ -101,6 +103,8 @@ target_compile_definitions(Wizard-server PRIVATE WIZARD_SERVER=1 RAPIDJSON_HAS_S # Comment out if you don't want to print network-related messages into the console target_compile_definitions(Wizard-server PRIVATE PRINT_NETWORK_MESSAGES=1) +# Copy all files from the assets folder to the binary directory +file(COPY ${CMAKE_SOURCE_DIR}/assets/ DESTINATION ${CMAKE_BINARY_DIR}/assets/) # linking to sockpp if(WIN32) diff --git a/assets/error.png b/assets/error.png new file mode 100644 index 0000000000000000000000000000000000000000..e8fcf98588f32c6c91d4def84739038c8686db2c Binary files /dev/null and b/assets/error.png differ diff --git a/sockpp/.idea/misc.xml b/sockpp/.idea/misc.xml index 7c97963d2d1a016ddd8c06b1c90e8fabc2eb002d..6a6aa90234d31cd5d51f594dd7aec423dea399ad 100644 --- a/sockpp/.idea/misc.xml +++ b/sockpp/.idea/misc.xml @@ -1,5 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> + <component name="BackendCodeEditorMiscSettings"> + <option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" /> + <option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" /> + <option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexedValue" value="true" type="bool" /> + <option name="/Default/Environment/Hierarchy/GeneratedFilesCacheKey/Timestamp/@EntryValue" value="4" type="long" /> + </component> <component name="CMakePythonSetting"> <option name="pythonIntegrationState" value="YES" /> </component> diff --git a/src/client/GameController.cpp b/src/client/GameController.cpp index 651bcecdd19104a64eefc09b92d9a940bfc448e7..cc348ff835c001ab86fff748b0c9a1051fe071bc 100644 --- a/src/client/GameController.cpp +++ b/src/client/GameController.cpp @@ -4,6 +4,7 @@ #include "../common/network/requests/draw_card_request.h" #include "../common/network/requests/fold_request.h" #include "../common/network/requests/play_card_request.h" +#include "../client/messageBoxes/ErrorDialog.h" #include "network/ClientNetworkManager.h" @@ -143,8 +144,18 @@ wxEvtHandler* GameController::getMainThreadEventHandler() { } +//void GameController::showError(const std::string& title, const std::string& message) { +// wxMessageBox(message, title, wxICON_ERROR); +//} + void GameController::showError(const std::string& title, const std::string& message) { - wxMessageBox(message, title, wxICON_ERROR); + // Load a custom image for the error dialog + wxString fullpath = "assets/error.png"; + + wxBitmap errorImage(fullpath, wxBITMAP_TYPE_ANY); + // Create and show the custom error dialog + ErrorDialog errorDialog(nullptr, title, message, errorImage); + errorDialog.ShowModal(); } diff --git a/src/client/messageBoxes/ErrorDialog.cpp b/src/client/messageBoxes/ErrorDialog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2722237adccfa4173ec0ea3c5236bf763bae82d --- /dev/null +++ b/src/client/messageBoxes/ErrorDialog.cpp @@ -0,0 +1,36 @@ +// +// Created by hannah on 11/9/24. +// + +#include "ErrorDialog.h" + +ErrorDialog::ErrorDialog(wxWindow* parent, const std::string& title, const std::string& message, const wxBitmap& image) + : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxSize(400, 250), wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) { + + // Set custom background color (for example, red for error dialogs) + SetBackgroundColour(*wxBLACK); + + // Create a vertical sizer for layout + wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); + + // Display the custom image (if it’s valid) + if (image.IsOk()) { + wxImage resizedImage = image.ConvertToImage(); + resizedImage.Rescale(100, 100); + + imageCtrl = new wxStaticBitmap(this, wxID_ANY, wxBitmap(resizedImage)); + sizer->Add(imageCtrl, 0, wxALIGN_CENTER | wxALL, 20); + } + + // Display the error message + messageCtrl = new wxStaticText(this, wxID_ANY, message); + messageCtrl->SetForegroundColour(*wxWHITE); // Set text color to white for better contrast + sizer->Add(messageCtrl, 0, wxALIGN_CENTER | wxALL, 10); + + // Add an OK button to close the dialog + okButton = new wxButton(this, wxID_OK, "OK"); + sizer->Add(okButton, 0, wxALIGN_CENTER | wxALL, 10); + + SetSizerAndFit(sizer); + Centre(); // Center the dialog on the screen +} \ No newline at end of file diff --git a/src/client/messageBoxes/ErrorDialog.h b/src/client/messageBoxes/ErrorDialog.h new file mode 100644 index 0000000000000000000000000000000000000000..b55a0ff30285375485f4160c3170ced118fdc451 --- /dev/null +++ b/src/client/messageBoxes/ErrorDialog.h @@ -0,0 +1,21 @@ +// +// Created by hannah on 11/9/24. +// + +#ifndef ERRORDIALOG_H +#define ERRORDIALOG_H + +#include <wx/wx.h> +#include <wx/statbmp.h> + +class ErrorDialog : public wxDialog{ + public: ErrorDialog(wxWindow* parent, const std::string& title, const std::string& message, const wxBitmap& image); + + private: + wxStaticBitmap* imageCtrl; + wxStaticText* messageCtrl; + wxButton* okButton; + +}; + +#endif //ERRORDIALOG_H diff --git a/src/client/windows/GameWindow.cpp b/src/client/windows/GameWindow.cpp index 2ae355986977023fc72f3015e6443606024adbf2..53fff8eb658f0157f4cad2085edd978d12555d62 100644 --- a/src/client/windows/GameWindow.cpp +++ b/src/client/windows/GameWindow.cpp @@ -4,7 +4,6 @@ GameWindow::GameWindow(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(nullptr, wxID_ANY, title, pos, size) { // Set up layout that will contain and center all content - this->_mainLayout = new wxBoxSizer(wxVERTICAL); wxBoxSizer* outerLayout = new wxBoxSizer(wxHORIZONTAL); outerLayout->Add(this->_mainLayout, 1, wxCENTER); @@ -14,12 +13,34 @@ GameWindow::GameWindow(const wxString& title, const wxPoint& pos, const wxSize& // Set up status bar this->_statusBar = this->CreateStatusBar(1); + // Add "Rules" button directly to the status bar + _rulesButton = new wxButton(_statusBar, wxID_ANY, "Rules"); + _settingsButton = new wxButton(_statusBar, wxID_ANY, "Settings"); + + // Set minimum height of status bar based on the button's height with padding + _statusBar->SetMinHeight(_rulesButton->GetSize().GetHeight() + 10); + + // Create a horizontal sizer for the status bar and add the button to it + wxBoxSizer* statusSizer = new wxBoxSizer(wxHORIZONTAL); + + // Add stretchable space to fill space in statusbar + statusSizer->AddStretchSpacer(1); + + statusSizer->Add(_settingsButton, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL | wxALL, 5); + statusSizer->Add(_rulesButton, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL | wxALL, 5); + _statusBar->SetSizer(statusSizer); + _statusBar->Layout(); + + // Bind the button click event to showRules method + _rulesButton->Bind(wxEVT_BUTTON, &GameWindow::showRules, this); + _settingsButton->Bind(wxEVT_BUTTON, &GameWindow::show_settings, this); + // Set background - wxColor lightBlue = wxColor(213, 231, 239); - this->SetBackgroundColour(lightBlue); + wxColor darkred = wxColor(102, 0, 51); + this->SetBackgroundColour(darkred); // Set the minimum size of the window. The user won't be able to resize the window to a size smaller than this - this->SetMinSize(wxSize(1000, 720)); + this->SetMinSize(wxSize(50, 50)); } @@ -39,7 +60,7 @@ void GameWindow::showPanel(wxPanel* panel) { } // add new panel - this->_mainLayout->Add(panel, 0, wxALIGN_CENTER | wxALL, 20); // 20 pixel spacing + this->_mainLayout->Add(panel, 1, wxEXPAND | wxALL, 20); // 20 pixel spacing panel->Show(true); this->_currentPanel = panel; @@ -55,3 +76,17 @@ void GameWindow::setStatus(const std::string& message) { this->_statusBar->SetStatusText(message, 0); } +void GameWindow::showRules(wxCommandEvent& event){ + wxString rules = "Game Rules:\n" + "Do not cheat!"; + + wxMessageDialog rulesDialog(this, rules, "Game Rules", wxOK | wxICON_INFORMATION); + rulesDialog.ShowModal(); +} + +void GameWindow::show_settings(wxCommandEvent& event){ + wxString settings = "Not implemented yet"; + + wxMessageDialog rulesDialog(this, settings, "Game Rules", wxOK | wxICON_INFORMATION); + rulesDialog.ShowModal(); +} diff --git a/src/client/windows/GameWindow.h b/src/client/windows/GameWindow.h index 2efbcfc7a25035553d2f547d783b0abfd38eaead..b02b19d19760f2703d4cf42999e102cd548aab9b 100644 --- a/src/client/windows/GameWindow.h +++ b/src/client/windows/GameWindow.h @@ -15,9 +15,13 @@ public: private: wxBoxSizer* _mainLayout; wxStatusBar* _statusBar; + wxButton* _rulesButton; + wxButton* _settingsButton; wxPanel* _currentPanel; + void showRules(wxCommandEvent& event); + void show_settings(wxCommandEvent& event); };