Skip to content
Snippets Groups Projects
Commit 2f42f1c9 authored by jaberger's avatar jaberger
Browse files

connection panel

parent 0daad435
No related branches found
No related tags found
1 merge request!7Resolve "Connection_Panel"
assets/Wiz.png

712 KiB

assets/Wizard_big.png

728 KiB

assets/Wizard_round.png

604 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/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexRemoved" />
<option name="/Default/Environment/Hierarchy/GeneratedFilesCacheKey/Timestamp/@EntryValue" value="3" type="long" />
</component>
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
......
#include "ConnectionPanel.h"
#include <wx/image.h>
#include "../uiElements/ImagePanel.h"
#include "../../common/network/default.conf"
#include "../GameController.h"
#include <wx/dcbuffer.h>
ConnectionPanel::ConnectionPanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) {
wxColor white = wxColor(255, 255, 255);
this->SetBackgroundColour(white);
// Load the background image
_backgroundImage.LoadFile("./assets/Wizard_big.png", wxBITMAP_TYPE_ANY);
// Set background paint style and bind paint/resize events
this->SetBackgroundStyle(wxBG_STYLE_PAINT);
this->Bind(wxEVT_PAINT, &ConnectionPanel::OnPaint, this);
this->Bind(wxEVT_SIZE, &ConnectionPanel::OnSize, this);
// Main vertical layout for input fields and button
wxBoxSizer* verticalLayout = new wxBoxSizer(wxVERTICAL);
ImagePanel* logo = new ImagePanel(this, "assets/wizard_logo.png", wxBITMAP_TYPE_ANY, wxDefaultPosition, wxSize(200, 250));
verticalLayout->Add(logo, 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 10);
this->_serverAddressField = new InputField(
this, // parent element
"Server address:", // label
100, // width of label
default_server_host, // default value (variable from "default.conf")
240 // width of field
);
verticalLayout->Add(this->_serverAddressField, 0, wxTOP | wxLEFT | wxRIGHT, 10);
this->_serverPortField = new InputField(
this, // parent element
"Server port:", // label
100, // width of label
wxString::Format("%i", default_port), // default value (variable from "default.conf")
240 // width of field
);
verticalLayout->Add(this->_serverPortField, 0, wxTOP | wxLEFT | wxRIGHT, 10);
this->_playerNameField = new InputField(
this, // parent element
"Player name:", // label
100, // width of label
"", // default value
240 // width of field
);
verticalLayout->Add(this->_playerNameField, 0, wxTOP | wxLEFT | wxRIGHT, 10);
wxButton* connectButton = new wxButton(this, wxID_ANY, "Connect", wxDefaultPosition, wxSize(100, 40));
int fieldSpacing = 10; // 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->SetLabelTextColour(wxColour(255, 255, 255)); // Set label text color to white
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->SetLabelTextColour(wxColour(255, 255, 255)); // Set label text color to white
verticalLayout->Add(this->_serverPortField, 0, wxALL | wxEXPAND, fieldSpacing);
// Player Name Input Field
this->_playerNameField = new InputField(this, "Player name:", 100, "", 240);
this->_playerNameField->SetLabelTextColour(wxColour(255, 255, 255)); // Set label text color to white
verticalLayout->Add(this->_playerNameField, 0, wxALL | wxEXPAND, fieldSpacing);
// Connect Button with custom style
wxButton* connectButton = new wxButton(this, wxID_ANY, "Connect", wxDefaultPosition, wxDefaultSize);
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
connectButton->Bind(wxEVT_BUTTON, [](wxCommandEvent& event) {
GameController::connectToServer();
GameController::connectToServer(); // Call the connect method when clicked
});
verticalLayout->Add(connectButton, 0, wxALIGN_RIGHT | wxALL, 10);
verticalLayout->Add(connectButton, 0, wxALIGN_CENTER | wxALL, fieldSpacing);
this->SetSizerAndFit(verticalLayout);
// Create a centered layout to ensure everything is vertically and horizontally centered
wxBoxSizer* centeredLayout = new wxBoxSizer(wxVERTICAL);
centeredLayout->AddStretchSpacer(1); // Add flexible space above the vertical layout
centeredLayout->Add(verticalLayout, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
centeredLayout->AddStretchSpacer(1); // Add flexible space below the vertical layout
// Set the centered layout as the sizer for this panel
this->SetSizer(centeredLayout);
}
void ConnectionPanel::OnPaint(wxPaintEvent& event) {
wxAutoBufferedPaintDC dc(this);
wxSize panelSize = this->GetClientSize();
if (_backgroundImage.IsOk()) {
// Scale the background image to match the panel size
wxImage image = _backgroundImage.ConvertToImage();
wxImage scaledImage = image.Scale(panelSize.GetWidth(), panelSize.GetHeight(), wxIMAGE_QUALITY_HIGH);
wxBitmap scaledBitmap(scaledImage);
// Draw the scaled background image
dc.DrawBitmap(scaledBitmap, 0, 0, true);
} else {
// Fallback: Draw a light blue background if the image is not loaded
dc.SetBrush(wxBrush(wxColour(200, 200, 255)));
dc.DrawRectangle(wxPoint(0, 0), panelSize);
}
}
void ConnectionPanel::OnSize(wxSizeEvent& event) {
wxSize panelSize = this->GetClientSize();
// Update the layout to adjust widget positions and sizes
this->Layout();
event.Skip(); // Pass the resize event to allow further processing
}
// Retrieve the server address entered by the user
wxString ConnectionPanel::getServerAddress() {
return this->_serverAddressField->getValue();
}
// Retrieve the server port entered by the user
wxString ConnectionPanel::getServerPort() {
return this->_serverPortField->getValue();
}
// Retrieve the player name entered by the user
wxString ConnectionPanel::getPlayerName() {
return this->_playerNameField->getValue();
}
}
\ No newline at end of file
......@@ -15,6 +15,10 @@ public:
wxString getPlayerName();
private:
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
wxBitmap _backgroundImage;
InputField* _serverAddressField;
InputField* _serverPortField;
InputField* _playerNameField;
......
......@@ -29,7 +29,6 @@ void MainGamePanel::buildGameState(game_state* gameState, player* me) {
double anglePerPlayer = MainGamePanel::twoPi / (double) numberOfPlayers;
// show all other players
for(int i = 1; i < numberOfPlayers; i++) {
// get player at i-th position after myself
......@@ -196,8 +195,14 @@ void MainGamePanel::buildCardPiles(game_state* gameState, player *me) {
} else {
// if the game did not start yet, show a back side of a card in the center (only for the mood)
wxPoint cardPosition = MainGamePanel::tableCenter - (MainGamePanel::cardSize / 2);
new ImagePanel(this, "assets/wizard_back.png", wxBITMAP_TYPE_ANY, cardPosition, MainGamePanel::cardSize);
//wxPoint cardPosition = MainGamePanel::tableCenter - (MainGamePanel::cardSize / 2);
// Definieren Sie eine neue Kartengröße, die größer ist
wxSize largerCardSize = MainGamePanel::cardSize ; // Verdoppelt die Größe
//Berechnen Sie die neue Position basierend auf der größeren Kartengröße
wxPoint cardPosition = MainGamePanel::tableCenter - (largerCardSize );
new ImagePanel(this, "../assets/Wizard_round.png", wxBITMAP_TYPE_ANY, cardPosition, MainGamePanel::cardSize);
}
}
......@@ -239,6 +244,7 @@ void MainGamePanel::buildThisPlayer(game_state* gameState, player* me) {
wxALIGN_CENTER,
true
);
playerName->SetForegroundColour(wxColour(0, 206, 209));
innerLayout->Add(playerName, 0, wxALIGN_CENTER);
// if the game has not yet started we say so
......@@ -250,10 +256,13 @@ void MainGamePanel::buildThisPlayer(game_state* gameState, player* me) {
wxSize(200, 18),
wxALIGN_CENTER
);
playerPoints->SetForegroundColour(wxColour(0, 206, 209));
innerLayout->Add(playerPoints, 0, wxALIGN_CENTER | wxBOTTOM, 8);
// show button that allows our player to start the game
wxButton* startGameButton = new wxButton(this, wxID_ANY, "Start Game!", wxDefaultPosition, wxSize(160, 64));
startGameButton->SetBackgroundColour(wxColour(0, 206, 209));
startGameButton->SetForegroundColour(wxColour(102, 0, 51));
startGameButton->Bind(wxEVT_BUTTON, [](wxCommandEvent& event) {
GameController::startGame();
});
......
......@@ -26,8 +26,13 @@ InputField::InputField(wxWindow* parent, const wxString& labelText, int labelWid
this->SetSizerAndFit(horizontalLayout);
}
void InputField::SetLabelTextColour(const wxColour& colour) {
_label->SetForegroundColour(colour);
_label->Refresh();
}
wxString InputField::getValue() {
return this->_field->GetValue();
}
\ No newline at end of file
}
......@@ -9,11 +9,11 @@ class InputField : public wxPanel {
public:
InputField(wxWindow* parent, const wxString& labelText, int labelWidth, const wxString& fieldValue, int fieldWidth);
wxString getValue();
void SetLabelTextColour(const wxColour& colour);
private:
wxStaticText* _label;
wxTextCtrl* _field;
};
......
......@@ -7,7 +7,7 @@ GameWindow::GameWindow(const wxString& title, const wxPoint& pos, const wxSize&
this->_mainLayout = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* outerLayout = new wxBoxSizer(wxHORIZONTAL);
outerLayout->Add(this->_mainLayout, 1, wxCENTER);
outerLayout->Add(this->_mainLayout, 1, wxEXPAND | wxALL, 20);
this->SetSizerAndFit(outerLayout);
this->_currentPanel = nullptr;
......@@ -15,7 +15,7 @@ GameWindow::GameWindow(const wxString& title, const wxPoint& pos, const wxSize&
this->_statusBar = this->CreateStatusBar(1);
// Set background
wxColor lightBlue = wxColor(213, 231, 239);
wxColor lightBlue = wxColor(102, 0, 51);
this->SetBackgroundColour(lightBlue);
// Set the minimum size of the window. The user won't be able to resize the window to a size smaller than this
......@@ -39,7 +39,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); // Verwenden von wxEXPAND
panel->Show(true);
this->_currentPanel = panel;
......
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