Skip to content
Snippets Groups Projects
Commit 90f80aa5 authored by Andreas Blakli's avatar Andreas Blakli
Browse files

Improved GUI, added comfirm action with enter key

parent fe1ec209
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@
#include <imgui/imgui_impl_opengl3.h>
class ui {
private:
ImVec4 colorYellow = ImVec4(1, 1, 0, 1); // Yellow color for text
public:
void inGameStats(int points, int lives);
void mainMenu();
......@@ -15,5 +17,6 @@ public:
void gameOverDisp(int points);
void victoryDisp(int points);
void levelSelector(ImGuiWindowFlags window_flags);
bool detectEnterPress();
bool lvlSelect = false;
};
......@@ -18,9 +18,9 @@
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
2 0 0 0 0 0 c 0 0 b 1 1 1 1 1 0 1 1 b 0 0 c 0 0 0 0 0 0
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 0 1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 a 0 0 0 0 0 b 0 0 b 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1 1 1 0 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1
1 3 0 0 0 0 c 0 0 8 0 0 4 1 1 3 0 0 8 0 0 c 0 0 0 0 4 1
1 7 1 1 1 1 7 1 1 1 1 1 7 1 1 7 1 1 1 1 1 7 1 1 1 1 7 1
......
......@@ -128,12 +128,12 @@ void game::loopHandler() {
ui.pauseMenu(); // calls the pause menu
}
if (restart) {
std::string s = "resources/levels/level" + std::to_string(mainMenuLvlSel);
char const* pchar = s.c_str(); //use char const* as target type
loader.loadLevel(pchar);
std::string lvlPath = "resources/levels/level" + std::to_string(mainMenuLvlSel); // Game level path, adds int from ui::levelSelector()
char const* lvlPchar = lvlPath.c_str(); // String to char
loader.loadLevel(lvlPchar); // Loads game level
pacMan = new pacman;
restart = false;
//pacMan->points = 298; // remove commenting if "quick testing" victory display
//pacMan->points = loader.floorObjects.size() - 1; // remove commenting if "quick testing" victory display
}
myWindow.swapBuffers(); //<-- SWAP BUFFERS
glfwPollEvents(); //<-- LISTEN FOR WINDOW EVENTS
......@@ -145,6 +145,6 @@ void game::loopHandler() {
// Resets the ingame stats, so that a new object isnt required
void game::resetStatValues(pacman pacman){
pacman.points = 0;
pacman.lives = 3;
// pacman.points = 0;
// pacman.lives = 3;
}
\ No newline at end of file
......@@ -5,76 +5,61 @@
void ui::inGameStats(int points, int lives) {
ImGuiWindowFlags window_flags = 0; // Sets the window flags that is to be used
window_flags |= ImGuiWindowFlags_NoMove;
// window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoCollapse;
window_flags |= ImGuiWindowFlags_AlwaysAutoResize;
window_flags |= ImGuiWindowFlags_NoInputs;
window_flags |= ImGuiWindowFlags_NoBackground;
window_flags |= ImGuiWindowFlags_NoDecoration;
// GUI
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
std::string pointsBuffer = "Score: " + std::to_string(points); // score
std::string livesBuffer = "HP: " + std::to_string(lives); // HP
// data that is to be displayed
ImGui::Begin("Stats", NULL, window_flags);
ImGui::Text(pointsBuffer.c_str());
ImGui::Text(livesBuffer.c_str());
ImGui::TextColored(colorYellow, pointsBuffer.c_str());
ImGui::TextColored(colorYellow, livesBuffer.c_str());
ImGui::SetWindowFontScale(2.0f);
ImGui::End();
// Display
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
// Displays the main menu
void ui::mainMenu() {
ImGuiWindowFlags window_flags = 0; // Sets the window flags that is to be used
window_flags |= ImGuiWindowFlags_NoMove;
//window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoCollapse;
window_flags |= ImGuiWindowFlags_AlwaysAutoResize;
window_flags |= ImGuiWindowFlags_NoDecoration;
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// GUI
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Position menu center of screen
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f),\
ImGuiCond_Always, ImVec2(0.5f, 0.5f));
// data that is to be displayed
ImGui::Begin("Main Menu", NULL, window_flags);
if (ImGui::Button("Start game")) { // Creates button. If clicked sets bools val
/* startGame = true; // Enables the main game loop
exitMenu = true; // Disables the menu loop
mainMenuChoice = 2; // Testing ------------------
restart = true;
//victory = false;
*/
ImGui::PushStyleColor(ImGuiCol_Text, colorYellow);
ImGui::Text("Main Menu");
if (ImGui::Button("Start game") || detectEnterPress()) { // Creates button. If clicked sets bools val
lvlSelect = true;
}
if (ImGui::Button("Quit game")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Quit game") || detectEnterPress()) { // Creates button. If clicked sets bools val
quitGameComf = true; // Disables the render loop to terminate the application
startGame = false; // Disables the main game loop
exitMenu = true; // Disables the menu loop
//mainMenuChoice = 1; // Testing-----------------------
}
if (lvlSelect) {
levelSelector(window_flags);
}
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(2.0f);
ImGui::End();
// Display
......@@ -96,34 +81,35 @@ void ui::pauseMenu() {
window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoCollapse;
window_flags |= ImGuiWindowFlags_AlwaysAutoResize;
window_flags |= ImGuiWindowFlags_NoDecoration;
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
// GUI
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Position menu center of screen
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), \
ImGuiCond_Always, ImVec2(0.5f, 0.5f));
// data that is to be displayed
ImGui::Begin("Pause Menu", NULL, window_flags);
if (ImGui::Button("Resume game")) { // Creates button. If clicked sets bools val
ImGui::PushStyleColor(ImGuiCol_Text, colorYellow);
ImGui::Text("Pause Menu");
if (ImGui::Button("Resume game") || detectEnterPress()) { // Creates button. If clicked sets bools val
pauseGame = false; // Stops the pause game loop
startGame = true; // Enables the main game loop
}
if (ImGui::Button("Quit to main menu")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Return to main menu") || detectEnterPress()) { // Creates button. If clicked sets bools val
startGame = false; // Stops the main game loop
exitMenu = false; // Enables the menu loop
pauseGame = false; // Stops the pause game loop
}
if (ImGui::Button("Quit game")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Quit game") || detectEnterPress()) { // Creates button. If clicked sets bools val
quitGameComf = true; // Disables the render loop to terminate the application
pauseGame = false; // Stops the pauseGame loop
}
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(2.0f);
ImGui::End();
// Display
......@@ -135,39 +121,39 @@ void ui::pauseMenu() {
void ui::gameOverDisp(int points) {
ImGuiWindowFlags window_flags = 0; // Sets the window flags that is to be used
window_flags |= ImGuiWindowFlags_NoMove;
//window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoCollapse;
window_flags |= ImGuiWindowFlags_AlwaysAutoResize;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus;
window_flags |= ImGuiWindowFlags_NoDecoration;
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
// GUI
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Position menu center of screen
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), \
ImGuiCond_Always, ImVec2(0.5f, 0.5f));
std::string pointsBuffer = "Total score: " + std::to_string(points); // Total score
// data that is to be displayed
ImGui::Begin("GAME OVER", NULL, window_flags);
ImGui::PushStyleColor(ImGuiCol_Text, colorYellow);
ImGui::Text("GAME OVER");
ImGui::Text(pointsBuffer.c_str());
if (ImGui::Button("Try again")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Try again") || detectEnterPress()) { // Creates button. If clicked sets bools val
gameIsOver = false; // Stops the game over loop
startGame = true; // Enables the main game loop
restart = true; // Testing---------------------------
}
if (ImGui::Button("Return to main menu")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Return to main menu") || detectEnterPress()) { // Creates button. If clicked sets bools val
startGame = false; // Stops the main game loop
exitMenu = false; // Enables main menu
}
if (ImGui::Button("Quit game")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Quit game") || detectEnterPress()) { // Creates button. If clicked sets bools val
quitGameComf = true; // Disables the render loop to terminate the application
}
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(2.0f);
ImGui::End();
// Display
......@@ -175,39 +161,39 @@ void ui::gameOverDisp(int points) {
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
// Displays the victory menu
void ui::victoryDisp(int points) {
ImGuiWindowFlags window_flags = 0; // Sets the window flags that is to be used
window_flags |= ImGuiWindowFlags_NoMove;
//window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoCollapse;
window_flags |= ImGuiWindowFlags_AlwaysAutoResize;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus;
window_flags |= ImGuiWindowFlags_NoDecoration;
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
// GUI
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Position menu center of screen
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), \
ImGuiCond_Always, ImVec2(0.5f, 0.5f));
std::string pointsBuffer = "Total score: " + std::to_string(points); // Total score
// data that is to be displayed
ImGui::Begin("VICTORY", NULL, window_flags);
ImGui::PushStyleColor(ImGuiCol_Text, colorYellow);
ImGui::Text("VICTORY");
ImGui::Text(pointsBuffer.c_str());
if (ImGui::Button("Return to main menu")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Return to main menu") || detectEnterPress()) { // Creates button. If clicked sets bools val
startGame = false; // Stops the main game loop
exitMenu = false; // Enables main menu
victory = false; // Stops victory loop
}
if (ImGui::Button("Quit game")) { // Creates button. If clicked sets bools val
if (ImGui::Button("Quit game") || detectEnterPress()) { // Creates button. If clicked sets bools val
quitGameComf = true; // Disables the render loop to terminate the application
}
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(2.0f);
ImGui::End();
// Display
......@@ -215,6 +201,7 @@ void ui::victoryDisp(int points) {
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
// Displays the level selector menu
void ui::levelSelector(ImGuiWindowFlags window_flags) {
window_flags |= ImGuiWindowFlags_NoDecoration;
......@@ -223,22 +210,34 @@ void ui::levelSelector(ImGuiWindowFlags window_flags) {
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.7f), \
ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::Begin("Select level", NULL, window_flags);
ImGui::PushStyleColor(ImGuiCol_Text, colorYellow);
ImGui::Text("Select Level");
if (ImGui::Button("Level 0")) {
if (ImGui::Button("Level 0") || detectEnterPress()) { //ImGuiCol_ButtonHovered
mainMenuLvlSel = 0;
startGame = true; // Enables the main game loop
exitMenu = true; // Disables the menu loop
restart = true;
lvlSelect = false;
}
if (ImGui::Button("Level 1")) {
if (ImGui::Button("Level 1") || detectEnterPress()) {
mainMenuLvlSel = 1;
startGame = true; // Enables the main game loop
exitMenu = true; // Disables the menu loop
restart = true;
lvlSelect = false;
}
//ImGui::SetItemDefaultFocus();
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(2.0f);
ImGui::End();
}
// Returns true if ENTER key is pressed
bool ui::detectEnterPress() {
if (ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly) && ImGui::IsKeyPressed(GLFW_KEY_ENTER)){
return true;
}
else {
return false;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment