Rudimentary support for inputting game mode through GUI instead of command-line
The only thing that 'works' right now is the skeleton GUI structure. The buttons don't actually do anything.
This commit is contained in:
49
main.cpp
49
main.cpp
@@ -19,6 +19,11 @@
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include "includes/raylib-cpp/raylib-cpp.hpp"
|
||||
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
#include "includes/raygui/raygui.h"
|
||||
#include "includes/raygui/style_dark.h"
|
||||
|
||||
#include "includes/paddle.hpp"
|
||||
#include "includes/ball.hpp"
|
||||
#include "includes/easysock.hpp"
|
||||
@@ -217,6 +222,50 @@ int main(int argc, char** argv) {
|
||||
bool game_started = false;
|
||||
srand(std::time(NULL));
|
||||
|
||||
|
||||
|
||||
/* Display a drop-down menu, to allow user to pick between Single player, server and client. This section of the code uses the raygui library, and is written in C. */
|
||||
|
||||
GuiLoadStyleDark(); // Load the dark theme style
|
||||
/* Modify the default style, by changing font size and spacing */
|
||||
int font_size = 25;
|
||||
int font_spacing = 2;
|
||||
GuiSetStyle(DEFAULT, TEXT_SIZE, font_size);
|
||||
GuiSetStyle(DEFAULT, TEXT_SPACING, font_spacing);
|
||||
|
||||
/* Set variables to position objects on screen */
|
||||
int selected_item = 0; // variable to hold the index of the selected item
|
||||
char* game_mode_txt = "Select Game Mode"; // Text to display
|
||||
/* Size of the label, drop down box and button */
|
||||
Vector2 label_size = MeasureTextEx(GetFontDefault(), game_mode_txt, font_size, font_spacing); // Set the size based on the width of the string to print, the font size and the text spacing. I added 1 to font_size and font_spacing, to account for any possible rounding errors, since the function expects floats.
|
||||
Vector2 box_size = (Vector2){label_size.x, HEIGHT / 20};
|
||||
bool is_being_edited = false; // Indicates whether the drop-down menu is being 'edited' i.e. whether an option is being selected
|
||||
bool button_pressed = false; // Indicates whether the submit button has been pressed
|
||||
|
||||
while (button_pressed == false) {
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
GuiLabel((Rectangle){(WIDTH/2)-(label_size.x/2), (HEIGHT/8), label_size.x, label_size.y}, game_mode_txt);
|
||||
if (is_being_edited) {
|
||||
GuiLock();
|
||||
}
|
||||
|
||||
/* Button that allows user to proceed */
|
||||
button_pressed = GuiButton((Rectangle){(WIDTH/2)-(box_size.x/2), (HEIGHT/2) + (HEIGHT/8), box_size.x, box_size.y}, "Continue");
|
||||
|
||||
/* Drop-down menu, that allows user to select game mode */
|
||||
if (GuiDropdownBox((Rectangle){(WIDTH/2) - (box_size.x/2), (HEIGHT/2) - (HEIGHT/8), box_size.x, box_size.y}, "SINGLE;CLIENT;SERVER", &selected_item, is_being_edited)) { // This function returns != 0 if there was a mouse click inside the dropdown area
|
||||
is_being_edited = !is_being_edited; // If the dropdown menu was selected, then it is being edited (or not being edited, if it previously was).
|
||||
}
|
||||
|
||||
// printf("%d\n", selected_item);
|
||||
GuiUnlock();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Variable to store the response given by the other player */
|
||||
std::string response;
|
||||
Serial_Data response_data;
|
||||
|
Reference in New Issue
Block a user