-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.h
More file actions
191 lines (167 loc) · 5.86 KB
/
Menu.h
File metadata and controls
191 lines (167 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
Menu.h
Author: [Your Name]
Roll Number: [Your Roll Number]
Project Title: Xonix Game - DSA Project
Description:
This file contains the Menu class which handles all menu states and UI elements.
*/
#ifndef MENU_H
#define MENU_H
#include <SFML/Graphics.hpp>
#include <string>
#include "MinHeap.h"
#include "Leaderboard.h"
#include "Auth.h"
#include "Game.h"
#include "LinkedList.h"
#include "PriorityQueue.h"
using namespace sf;
// Menu states
enum class MenuState {
MAIN_MENU,
LOGIN,
LOGIN_PLAYER2, // New state for player 2 login
REGISTER,
SINGLE_PLAYER,
MULTIPLAYER,
MATCHMAKING, // New state for matchmaking queue
LEVEL_SELECT,
LEADERBOARD,
PROFILE,
FRIEND_LIST, // View friends and manage requests
FRIEND_SEARCH, // Search for players to add as friends
OPTIONS,
SAVE_GAME, // New state for save game menu
LOAD_GAME, // New state for load game menu
EXIT
};
class Menu {
private:
RenderWindow* window;
MenuState currentState;
Auth* auth;
Game* game;
Leaderboard leaderboard;
PriorityQueue matchmakingQueue;
// Add this struct to Menu.h
struct MatchHistory {
char date[32]; // Date or description of the match
bool isWin; // Whether the player won
};
// UI Elements
Font font;
std::vector<Text> menuItems;
std::vector<RectangleShape> buttons;
std::vector<Text> hints;
// Menu-specific data
int selectedItem;
bool isLoggedIn;
std::string currentUser;
std::string player2Username; // Store second player's username
std::string errorMessage;
float errorTimer;
// Save/Load game data
LinkedList<std::string> savesList;
int selectedSaveIndex;
bool showConfirmationDialog;
std::string confirmationMessage;
bool isSaveOperation;
// Login/Register form data
std::string username;
std::string password;
std::string confirmPassword;
std::string passwordDisplay;
std::string confirmPasswordDisplay;
bool isUsernameSelected;
bool isPasswordSelected;
bool isConfirmPasswordSelected;
bool showPassword;
Text usernameText;
Text passwordText;
Text confirmPasswordText;
RectangleShape usernameBox;
RectangleShape passwordBox;
RectangleShape confirmPasswordBox;
Text cursor;
float cursorBlinkTime;
bool showCursor;
// Constants
static const int MIN_PASSWORD_LENGTH = 8;
static const int MAX_PASSWORD_LENGTH = 20;
static const int MAX_USERNAME_LENGTH = 20;
// Helper functions
void initializeMainMenu();
void initializeLoginMenu();
void initializeRegisterMenu();
void initializeMultiplayerLogin1(); // First player login
void initializeMultiplayerLogin2(); // Second player login
void initializeLevelSelect();
void initializeLeaderboard();
void initializeProfile();
void initializeOptions();
void initializeSaveGame(); // Initialize save game menu
void initializeLoadGame(); // Initialize load game menu
void initializeMatchmaking(); // Initialize matchmaking UI
void handleMainMenuInput(Event& event);
void handleLoginInput(Event& event);
void handleRegisterInput(Event& event);
void handleMultiplayerLogin1Input(Event& event); // First player login
void handleMultiplayerLogin2Input(Event& event); // Second player login
void handleLevelSelectInput(Event& event);
void handleLeaderboardInput(Event& event);
void handleProfileInput(Event& event);
void handleOptionsInput(Event& event);
void handleSaveGameInput(Event& event); // Handle save game menu input
void handleLoadGameInput(Event& event); // Handle load game menu input
void handleMatchmakingInput(Event& event); // Handle matchmaking input
void updateLoginForm();
void updateRegisterForm();
void updateCursor();
void addFieldHint(const std::string& text, float x, float y);
bool validatePassword(const std::string& pass);
void togglePasswordVisibility();
void showErrorMessage(const std::string& message);
void showSuccessMessage(const std::string& message);
void showConfirmation(const std::string& message, bool isSave);
// Display functions
void displayMainMenu();
void displayLoginMenu();
void displayRegisterMenu();
void displayMultiplayerLogin1(); // First player login
void displayMultiplayerLogin2(); // Second player login
void displayLevelSelect();
void displayLeaderboard();
void displayProfile();
void displayOptions();
void displaySaveGame(); // Display save game menu
void displayLoadGame(); // Display load game menu
void displayConfirmationDialog(); // Display confirmation dialog
void displayMatchmaking(); // Display matchmaking UI
// Matchmaking methods
void enterMatchmakingQueue(const std::string& username, int score);
void removeFromMatchmakingQueue(const std::string& username);
bool processMatchmaking(); // Process the matchmaking queue
public:
Menu(RenderWindow* window, Auth* auth);
~Menu();
// Core menu functions
void initialize();
void processInput(Event& event);
void display();
void update(float deltaTime);
// State management
MenuState getState() const;
void setState(MenuState newState);
// Save/Load game functions
void refreshSavesList();
bool saveGame();
bool loadGame(const std::string& saveID);
bool deleteSave(const std::string& saveID);
// Getters
bool getIsLoggedIn() const;
std::string getCurrentUser() const;
std::string getPlayer2Username() const { return player2Username; }
void updateLeaderboard(const std::string& username, int score);
};
#endif // MENU_H