Skip to content
Snippets Groups Projects
Commit 10db25fc authored by hwinter's avatar hwinter
Browse files

buttons and popup window

parent 0daad435
No related branches found
No related tags found
1 merge request!9Resolve "Settings Button and Errorwindow"
......@@ -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)
......
assets/error.png

25.2 KiB

<?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>
......
......@@ -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();
}
......
//
// 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
//
// 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
......@@ -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();
}
......@@ -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);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment