|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
#include "scufeng/engine.h"
|
|
#include "scufeng/engine.h"
|
|
|
#include "scufeng/Mesh.h"
|
|
#include "scufeng/Mesh.h"
|
|
|
|
|
+#include "scufeng/keys.h"
|
|
|
#include "scufeng/log.h"
|
|
#include "scufeng/log.h"
|
|
|
#include "cglm/vec3.h"
|
|
#include "cglm/vec3.h"
|
|
|
#include "cglm/io.h"
|
|
#include "cglm/io.h"
|
|
@@ -15,7 +16,6 @@
|
|
|
return (res); \
|
|
return (res); \
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static bool login_render = false;
|
|
|
|
|
|
|
|
|
|
static SEResult LoginPrompt_alloc(LoginPrompt *const lp, const unsigned int screen_w, const unsigned int screen_h) {
|
|
static SEResult LoginPrompt_alloc(LoginPrompt *const lp, const unsigned int screen_w, const unsigned int screen_h) {
|
|
|
lp->bg = SEMesh_rect_color_alloc((vec4) { 0.05f, 0.05f, 0.05f, 1.0f });
|
|
lp->bg = SEMesh_rect_color_alloc((vec4) { 0.05f, 0.05f, 0.05f, 1.0f });
|
|
@@ -123,6 +123,9 @@ SEResult MainMenu_alloc(
|
|
|
const unsigned int screen_w,
|
|
const unsigned int screen_w,
|
|
|
const unsigned int screen_h
|
|
const unsigned int screen_h
|
|
|
) {
|
|
) {
|
|
|
|
|
+ mm->next_screen = PONG_MAIN_MENU;
|
|
|
|
|
+ mm->login_render = false;
|
|
|
|
|
+
|
|
|
SEResult res = SEMesh_string_alloc(&mm->title_text, "Pong", strlen("Pong"), GLM_VEC3_ONE);
|
|
SEResult res = SEMesh_string_alloc(&mm->title_text, "Pong", strlen("Pong"), GLM_VEC3_ONE);
|
|
|
SE_RESULT_CHECK(res);
|
|
SE_RESULT_CHECK(res);
|
|
|
SEMesh_rect_textured_scale_set(&mm->title_text, screen_w * 0.16f, 0.0f);
|
|
SEMesh_rect_textured_scale_set(&mm->title_text, screen_w * 0.16f, 0.0f);
|
|
@@ -159,35 +162,44 @@ SEResult MainMenu_alloc(
|
|
|
return res;
|
|
return res;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static Screen MainMenu_input_handle(MainMenu *const mm) {
|
|
|
|
|
- if (se_get_mouse_button(SE_MOUSE_BUTTON_LEFT) == SE_KEY_ACTION_PRESS) {
|
|
|
|
|
|
|
+static void MainMenu_mouse_button_callback(SEMouseButton button, SEKeyAction action, SEKeyMod mods, void *data) {
|
|
|
|
|
+ (void) mods;
|
|
|
|
|
+
|
|
|
|
|
+ if (button == SE_MOUSE_BUTTON_LEFT && action == SE_KEY_ACTION_PRESS) {
|
|
|
|
|
+ MainMenu *const mm = (MainMenu *) data;
|
|
|
|
|
+
|
|
|
double x, y;
|
|
double x, y;
|
|
|
se_get_mouse_pos(&x, &y);
|
|
se_get_mouse_pos(&x, &y);
|
|
|
|
|
|
|
|
- if (!login_render) {
|
|
|
|
|
|
|
+ if (!mm->login_render) {
|
|
|
if (SEMesh_rect_is_pos_inside(&mm->sp_text, x, y)) {
|
|
if (SEMesh_rect_is_pos_inside(&mm->sp_text, x, y)) {
|
|
|
SE_LOG("SP");
|
|
SE_LOG("SP");
|
|
|
- return PONG_SINGLEPLAYER;
|
|
|
|
|
|
|
+ mm->next_screen = PONG_SINGLEPLAYER;
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (SEMesh_rect_is_pos_inside(&mm->mp_text, x, y)) {
|
|
if (SEMesh_rect_is_pos_inside(&mm->mp_text, x, y)) {
|
|
|
SE_LOG("MP");
|
|
SE_LOG("MP");
|
|
|
- return PONG_MULTIPLAYER;
|
|
|
|
|
|
|
+ mm->next_screen = PONG_MULTIPLAYER;
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (SEMesh_rect_is_pos_inside(&mm->quit_text, x, y)) {
|
|
if (SEMesh_rect_is_pos_inside(&mm->quit_text, x, y)) {
|
|
|
SE_LOG("Quit");
|
|
SE_LOG("Quit");
|
|
|
se_window_close();
|
|
se_window_close();
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (SEMesh_rect_is_pos_inside(&mm->login_text, x, y)) {
|
|
if (SEMesh_rect_is_pos_inside(&mm->login_text, x, y)) {
|
|
|
- login_render = true;
|
|
|
|
|
- return PONG_MAIN_MENU;
|
|
|
|
|
|
|
+ mm->login_render = true;
|
|
|
|
|
+ mm->next_screen = PONG_MAIN_MENU;
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if (SEMesh_rect_is_pos_inside(&mm->login_prompt.exit_text, x, y)) {
|
|
if (SEMesh_rect_is_pos_inside(&mm->login_prompt.exit_text, x, y)) {
|
|
|
- login_render = false;
|
|
|
|
|
- return PONG_MAIN_MENU;
|
|
|
|
|
|
|
+ mm->login_render = false;
|
|
|
|
|
+ mm->next_screen = PONG_MAIN_MENU;
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SETextInput *const tis[] = {
|
|
SETextInput *const tis[] = {
|
|
@@ -203,15 +215,18 @@ static Screen MainMenu_input_handle(MainMenu *const mm) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- return PONG_MAIN_MENU;
|
|
|
|
|
|
|
+void MainMenu_callbacks_set(MainMenu *const mm) {
|
|
|
|
|
+ se_set_mouse_button_callback(MainMenu_mouse_button_callback, (void *) mm);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void MainMenu_callbacks_unset(MainMenu *const mm) {
|
|
|
|
|
+ se_set_mouse_button_callback(nullptr, nullptr);
|
|
|
|
|
+ mm->next_screen = PONG_MAIN_MENU;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Screen MainMenu_tick(MainMenu *const mm) {
|
|
Screen MainMenu_tick(MainMenu *const mm) {
|
|
|
- const Screen screen = MainMenu_input_handle(mm);
|
|
|
|
|
- if (screen != PONG_MAIN_MENU) {
|
|
|
|
|
- return screen;
|
|
|
|
|
- }
|
|
|
|
|
SEMesh *meshes[] = {
|
|
SEMesh *meshes[] = {
|
|
|
&mm->title_text,
|
|
&mm->title_text,
|
|
|
&mm->sp_text,
|
|
&mm->sp_text,
|
|
@@ -224,9 +239,9 @@ Screen MainMenu_tick(MainMenu *const mm) {
|
|
|
SEMesh_bbox_render_2d(meshes[i]);
|
|
SEMesh_bbox_render_2d(meshes[i]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (login_render) {
|
|
|
|
|
|
|
+ if (mm->login_render) {
|
|
|
LoginPrompt_render(&mm->login_prompt);
|
|
LoginPrompt_render(&mm->login_prompt);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return PONG_MAIN_MENU;
|
|
|
|
|
|
|
+ return mm->next_screen; // Possiby modified by callback
|
|
|
}
|
|
}
|