summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelik Houij <houijmelik08@protonmail.com>2022-08-31 18:17:43 +0200
committerMelik Houij <houijmelik08@protonmail.com>2022-08-31 18:17:43 +0200
commitfde10b7e32bde1ffe8a77620a338100a29cefc85 (patch)
tree6b1f692c5bb7c7c5dc68f6c9b721e26df709f957
parent720b156ee59bf8f4c7d862b43cd065990105242d (diff)
got a working UI element with scene switching!!!
-rw-r--r--UI.hpp71
-rw-r--r--main.cpp5
-rw-r--r--scene.h30
3 files changed, 76 insertions, 30 deletions
diff --git a/UI.hpp b/UI.hpp
index 5b3ea7d..94fae17 100644
--- a/UI.hpp
+++ b/UI.hpp
@@ -10,23 +10,29 @@
enum uiMenus {
PAUSE,
EXIT
-};
+} currentMenu = PAUSE;
class UI
{
private:
- unsigned int VBO, VAO, EBO;
- Shader *uiShader = new Shader("resources/shaders/uishader.vert", "resources/shaders/uishader.frag");
- Text textObj;
- int selectedUI = 0;
- std::vector<std::string> drawnUI = {"Resume","Exit", "Print" };
+ unsigned int VBO, VAO, EBO;
+ Shader *uiShader = new Shader("resources/shaders/uishader.vert", "resources/shaders/uishader.frag");
+ Text textObj;
+ int selectedUI = 0;
+ // TODO maybe use arrays instead?
+ std::vector<std::string> pauseMenu = {"Resume","Exit", "Print" };
+ std::vector<std::string> exitMenu = {"Quit Game", "Cancel"};
+ std::vector<std::string> *drawnUI = &pauseMenu;
+ bool *paused;
+ bool *kill;
+
public:
// NOTE the current UI will be a box
// i can add in a picture or smthn to it later
// NOTE current UI will work by using a vector of strings for displaying the text
// the selectedUI element will be used to have the selected UI be chosen, have it be accessed by both the draw code and the function code to select the correct function
- UI()
+ UI(bool *pausedPass,bool *killScene)
{
float vertices[] {
0.9f, 0.9f, 0.0f,
@@ -59,7 +65,8 @@ class UI
//std::vector<int> (*fcnPtrs)();
/* std::vector<void(*)(int)> vec;
vec.push_back(&foo);*/
-
+ this->paused = pausedPass;
+ this->kill = killScene;
}
void draw(std::array<inGameInput,8> ginputs)
@@ -69,16 +76,48 @@ class UI
this->uiShader->use();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
- if (ginputs[0].bState == PRESSED) {
+ if (ginputs[7].bState == PRESSED)
+ {
+ switch (currentMenu)
+ {
+ case PAUSE:
+ switch (selectedUI)
+ {
+ case 0:
+ *paused = false;
+ break;
+ case 1:
+ currentMenu = EXIT;
+ drawnUI = &exitMenu;
+ break;
+ case 2:
+ printf("Printing successful!!!\n");
+ break;
+ }
+ break;
+ case EXIT:
+ switch (selectedUI)
+ {
+ case 0:
+ *kill = true;
+ break;
+ case 1:
+ currentMenu = PAUSE;
+ drawnUI = &pauseMenu;
+ break;
+ }
+ }
+ }
+ else if (ginputs[0].bState == PRESSED) {
if (selectedUI == 0) {
- selectedUI = drawnUI.size();
+ selectedUI = drawnUI->size() - 1;
}
else {
selectedUI--;
}
}
- if (ginputs[1].bState == PRESSED) {
- if (selectedUI == drawnUI.size())
+ else if (ginputs[1].bState == PRESSED) {
+ if (selectedUI == drawnUI->size() - 1)
{
selectedUI = 0;
}
@@ -86,18 +125,18 @@ class UI
{
selectedUI++;
}
-
}
+
// NOTE draws the text itself
- for (unsigned int i = 0; i < drawnUI.size(); i++) {
+ for (unsigned int i = 0; i < drawnUI->size(); i++) {
if(i == selectedUI)
{
- textObj.Render(drawnUI.at(i), 25.0f, 800.0f - (120.0f * i), 2.5f, glm::vec3(1.0, 0.5f, 0.5f));
+ textObj.Render(drawnUI->at(i), 25.0f, 800.0f - (120.0f * i), 2.5f, glm::vec3(1.0, 0.5f, 0.5f));
}
else {
- textObj.Render(drawnUI.at(i), 25.0f, 800.0f - (120.0f * i), 2.0f, glm::vec3(1.0, 0.8f, 0.2f));
+ textObj.Render(drawnUI->at(i), 25.0f, 800.0f - (120.0f * i), 2.0f, glm::vec3(1.0, 0.8f, 0.2f));
}
//
}
diff --git a/main.cpp b/main.cpp
index f909424..d348c3e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -76,7 +76,10 @@ int main()
double lasttime = glfwGetTime();
while(!glfwWindowShouldClose(window))
{
- current->update();
+ if(current->update())
+ {
+ current = (current->kill());
+ }
glfwSwapBuffers(window);
glfwPollEvents();
diff --git a/scene.h b/scene.h
index ffa4799..eb0ec01 100644
--- a/scene.h
+++ b/scene.h
@@ -25,6 +25,8 @@ class Scene
private:
std::array<inGameInput,8> buttons;
+ std::array<int, 8> bConfig = {GLFW_KEY_W, GLFW_KEY_S, GLFW_KEY_A, GLFW_KEY_D,
+ GLFW_KEY_I, GLFW_KEY_O, GLFW_KEY_P, GLFW_KEY_N};
// TODO reform code, use structs instead of bitset;
void pollGInputs(){
@@ -32,14 +34,10 @@ class Scene
// TODO change code around to be able to work off of any input
// NOTE boilerplate dump, will make a proper loop or smthn later lmao
- buttons[0].pressed(glfwGetKey(window, GLFW_KEY_W));
- buttons[1].pressed(glfwGetKey(window, GLFW_KEY_S));
- buttons[2].pressed(glfwGetKey(window, GLFW_KEY_A));
- buttons[3].pressed(glfwGetKey(window, GLFW_KEY_D));
- buttons[4].pressed(glfwGetKey(window, GLFW_KEY_I));
- buttons[5].pressed(glfwGetKey(window, GLFW_KEY_O));
- buttons[6].pressed(glfwGetKey(window, GLFW_KEY_P));
- buttons[7].pressed(glfwGetKey(window, GLFW_KEY_N));
+ //
+ //
+ for (unsigned int i = 0; i < 8; i++ )
+ buttons[i].pressed(glfwGetKey(window, bConfig[i]));
};
public:
std::vector<gobject> objects;
@@ -47,13 +45,15 @@ class Scene
// DONE i have to Figure out how Pausing the game should work
bool paused = false;
bool pressed = false;
+ bool killNow = false;
unsigned int VBO, VAO, EBO;
// DONE add more sound buffers
sf::SoundBuffer buffer;
sf::Sound sound;
Text texty;
Shader *shade = new Shader("resources/shaders/shader.vert", "resources/shaders/shader.frag");
- UI *uiObj = new UI();
+ // NOTE for some reason cant point itself
+ UI *uiObj = new UI(&paused, &killNow);
//enum buttonState {OFF, PRESSED, HELD};
//buttonState state = OFF;
bool pausePressed = false;
@@ -109,7 +109,7 @@ class Scene
}
- void update()
+ bool update()
{
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
@@ -159,27 +159,31 @@ class Scene
uiObj->draw(buttons);
}
// NOTE to test audio playback
-
+ return killNow;
// NOTE testing Text Rendering
//texty.Render("SDSDSD", 25.0f, 25.0f, 2.0f, glm::vec3(1.0, 0.8f, 0.2f));
}
- void kill()
+ Scene* kill()
{
// NOTE Destroy all buffers then destroy the Scene
// TODO properly make a text Destructor
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &EBO);
- //this->~Text();
this->~Scene();
+ Scene *second = new Scene(window);
+ return second;
}
~Scene()
{
printf("scene killed successfully\n");
+ glfwWindowShouldClose(window);
}
+
private:
};
+
#endif