|
|
@@ -1,49 +1,58 @@
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
#include "scufeng/engine.h"
|
|
|
#include "scufeng/Mesh.h"
|
|
|
#include "scufeng/log.h"
|
|
|
#include "cglm/vec3.h"
|
|
|
-#include "cglm/call/vec3.h"
|
|
|
#include "cglm/io.h"
|
|
|
|
|
|
#include "MainMenu.h"
|
|
|
#include "game_common.h"
|
|
|
#include "scufeng/text.h"
|
|
|
|
|
|
-static LoginPrompt LoginPrompt_alloc(const unsigned int screen_w, const unsigned int screen_h) {
|
|
|
- LoginPrompt lp = {
|
|
|
- .bg = SEMesh_rect_color_alloc((vec4) { 0.05f, 0.05f, 0.05f, 1.0f }),
|
|
|
- .username_text = SEMesh_string_alloc("Username:", GLM_VEC3_ONE),
|
|
|
- .username_input = SETextInput_alloc(
|
|
|
- "",
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- GLM_VEC3_ONE,
|
|
|
- (vec4) { 0.0025f, 0.0025f, 0.0025f, 1.0f },
|
|
|
- TI_FIXED_WIDTH
|
|
|
- ),
|
|
|
- .password_text = SEMesh_string_alloc("Password:", GLM_VEC3_ONE),
|
|
|
- .password_input = SETextInput_alloc(
|
|
|
- "",
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- GLM_VEC3_ONE,
|
|
|
- (vec4) { 0.0025f, 0.0025f, 0.0025f, 1.0f },
|
|
|
- TI_FIXED_WIDTH
|
|
|
- ),
|
|
|
- .exit_text = SEMesh_string_alloc("X", GLM_VEC3_ONE),
|
|
|
- .login_text = SEMesh_string_alloc("Login", GLM_VEC3_ONE)
|
|
|
- };
|
|
|
+#define SE_RESULT_CHECK(res) \
|
|
|
+ if (res != SE_SUCCESS) { \
|
|
|
+ return res; \
|
|
|
+ }
|
|
|
|
|
|
+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 });
|
|
|
vec2 bg_dims = { screen_w * 0.75f, screen_h * 0.75f };
|
|
|
vec2 bg_pos = { screen_w * 0.5f, screen_h * 0.5f };
|
|
|
- lp.bg.transform.scale[0] = bg_dims[0];
|
|
|
- lp.bg.transform.scale[1] = bg_dims[1];
|
|
|
- lp.bg.transform.pos[0] = bg_pos[0];
|
|
|
- lp.bg.transform.pos[1] = bg_pos[1];
|
|
|
+ lp->bg.transform.scale[0] = bg_dims[0];
|
|
|
+ lp->bg.transform.scale[1] = bg_dims[1];
|
|
|
+ lp->bg.transform.pos[0] = bg_pos[0];
|
|
|
+ lp->bg.transform.pos[1] = bg_pos[1];
|
|
|
vec4 bg_bbox;
|
|
|
- SEMesh_bbox_get_2d_v(&lp.bg, bg_bbox);
|
|
|
+ SEMesh_bbox_get_2d_v(&lp->bg, bg_bbox);
|
|
|
+
|
|
|
+ SEResult res = SEMesh_string_alloc(&lp->username_text, "Username:", strlen("Username:"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+
|
|
|
+ lp->username_input = SETextInput_alloc(
|
|
|
+ "",
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ GLM_VEC3_ONE,
|
|
|
+ (vec4) { 0.0025f, 0.0025f, 0.0025f, 1.0f },
|
|
|
+ TI_FIXED_WIDTH
|
|
|
+ ),
|
|
|
+ SETextInput_fixed_width_set(&lp->username_input, bg_dims[0] * 0.25f);
|
|
|
+
|
|
|
+ res = SEMesh_string_alloc(&lp->password_text, "Password:", strlen("Password:"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+
|
|
|
+ lp->password_input = SETextInput_alloc(
|
|
|
+ "",
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ GLM_VEC3_ONE,
|
|
|
+ (vec4) { 0.0025f, 0.0025f, 0.0025f, 1.0f },
|
|
|
+ TI_FIXED_WIDTH
|
|
|
+ );
|
|
|
+ SETextInput_fixed_width_set(&lp->password_input, bg_dims[0] * 0.25f);
|
|
|
|
|
|
puts("bg_dims");
|
|
|
glm_vec2_print(bg_dims, stdout);
|
|
|
@@ -52,14 +61,16 @@ static LoginPrompt LoginPrompt_alloc(const unsigned int screen_w, const unsigned
|
|
|
puts("bg_bbox");
|
|
|
glm_vec4_print(bg_bbox, stdout);
|
|
|
|
|
|
- lp.exit_text.transform.pos[0] = bg_bbox[0] + bg_dims[0] * 0.025f;
|
|
|
- lp.exit_text.transform.pos[1] = bg_bbox[1] + bg_dims[1] * 0.05f;
|
|
|
- glm_vec3_print(lp.exit_text.transform.pos, stdout);
|
|
|
+ res = SEMesh_string_alloc(&lp->exit_text, "X", 1, GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+ lp->exit_text.transform.pos[0] = bg_bbox[0] + bg_dims[0] * 0.025f;
|
|
|
+ lp->exit_text.transform.pos[1] = bg_bbox[1] + bg_dims[1] * 0.05f;
|
|
|
+ glm_vec3_print(lp->exit_text.transform.pos, stdout);
|
|
|
|
|
|
- SETextInput_fixed_width_set(&lp.username_input, bg_dims[0] * 0.25f);
|
|
|
- SETextInput_fixed_width_set(&lp.password_input, bg_dims[0] * 0.25f);
|
|
|
+ res = SEMesh_string_alloc(&lp->login_text, "Login", strlen("Login"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
|
|
|
- return lp;
|
|
|
+ return SE_SUCCESS;
|
|
|
}
|
|
|
|
|
|
static void LoginPrompt_render(LoginPrompt *const lp) {
|
|
|
@@ -79,37 +90,45 @@ static void LoginPrompt_render(LoginPrompt *const lp) {
|
|
|
SETextInput_render_multiple_2d(tis, sizeof(tis) / sizeof(tis[0]));
|
|
|
}
|
|
|
|
|
|
-MainMenu MainMenu_alloc(const unsigned int screen_w, const unsigned int screen_h) {
|
|
|
- MainMenu mm;
|
|
|
-
|
|
|
- mm.title_text = SEMesh_string_alloc("Pong", GLM_VEC3_ONE);
|
|
|
- SEMesh_rect_textured_scale_set(&mm.title_text, screen_w * 0.16f, 0.0f);
|
|
|
- mm.title_text.transform.pos[0] = screen_w / 2.0f;
|
|
|
- mm.title_text.transform.pos[1] = screen_h * 0.1f;
|
|
|
-
|
|
|
- mm.login_text = SEMesh_string_alloc("Login", GLM_VEC3_ONE);
|
|
|
- SEMesh_rect_textured_scale_set(&mm.login_text, screen_w * 0.06f, 0.0f);
|
|
|
- mm.login_text.transform.pos[0] = screen_w / 6.0f;
|
|
|
- mm.login_text.transform.pos[1] = screen_h * 0.2f;
|
|
|
-
|
|
|
- mm.sp_text = SEMesh_string_alloc("Singleplayer", GLM_VEC3_ONE);
|
|
|
- SEMesh_rect_textured_scale_set(&mm.sp_text, screen_w * 0.25f, 0.0f);
|
|
|
- mm.sp_text.transform.pos[0] = screen_w * 0.25f;
|
|
|
- mm.sp_text.transform.pos[1] = screen_h * 0.5f;
|
|
|
-
|
|
|
- mm.mp_text = SEMesh_string_alloc("Multiplayer", GLM_VEC3_ONE);
|
|
|
- SEMesh_rect_textured_scale_set(&mm.mp_text, mm.sp_text.transform.scale[0], 0.0f);
|
|
|
- mm.mp_text.transform.pos[0] = screen_w - mm.sp_text.transform.pos[0];
|
|
|
- mm.mp_text.transform.pos[1] = mm.sp_text.transform.pos[1];
|
|
|
-
|
|
|
- mm.quit_text = SEMesh_string_alloc("Quit", GLM_VEC3_ONE);
|
|
|
- SEMesh_rect_textured_scale_set(&mm.quit_text, 0.0f, mm.title_text.transform.scale[1] / 2.0f);
|
|
|
- mm.quit_text.transform.pos[0] = screen_w / 2.0f;
|
|
|
- mm.quit_text.transform.pos[1] = screen_h * 0.8f;
|
|
|
-
|
|
|
- mm.login_prompt = LoginPrompt_alloc(screen_w, screen_h);
|
|
|
-
|
|
|
- return mm;
|
|
|
+SEResult MainMenu_alloc(
|
|
|
+ MainMenu *const mm,
|
|
|
+ const unsigned int screen_w,
|
|
|
+ const unsigned int screen_h
|
|
|
+) {
|
|
|
+ SEResult res = SEMesh_string_alloc(&mm->title_text, "Pong", strlen("Pong"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+ SEMesh_rect_textured_scale_set(&mm->title_text, screen_w * 0.16f, 0.0f);
|
|
|
+ mm->title_text.transform.pos[0] = screen_w / 2.0f;
|
|
|
+ mm->title_text.transform.pos[1] = screen_h * 0.1f;
|
|
|
+
|
|
|
+ res = SEMesh_string_alloc(&mm->login_text, "Login", strlen("Login"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+ SEMesh_rect_textured_scale_set(&mm->login_text, screen_w * 0.1f, 0.0f);
|
|
|
+ mm->login_text.transform.pos[0] = screen_w / 6.0f;
|
|
|
+ mm->login_text.transform.pos[1] = screen_h * 0.2f;
|
|
|
+
|
|
|
+ res = SEMesh_string_alloc(&mm->sp_text, "Singleplayer", strlen("Singleplayer"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+ SEMesh_rect_textured_scale_set(&mm->sp_text, screen_w * 0.30f, 0.0f);
|
|
|
+ mm->sp_text.transform.pos[0] = screen_w * 0.25f;
|
|
|
+ mm->sp_text.transform.pos[1] = screen_h * 0.5f;
|
|
|
+
|
|
|
+ res = SEMesh_string_alloc(&mm->mp_text, "Multiplayer", strlen("Multiplayer"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+ SEMesh_rect_textured_scale_set(&mm->mp_text, mm->sp_text.transform.scale[0], 0.0f);
|
|
|
+ mm->mp_text.transform.pos[0] = screen_w - mm->sp_text.transform.pos[0];
|
|
|
+ mm->mp_text.transform.pos[1] = mm->sp_text.transform.pos[1];
|
|
|
+
|
|
|
+ res = SEMesh_string_alloc(&mm->quit_text, "Quit", strlen("Quit"), GLM_VEC3_ONE);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+ SEMesh_rect_textured_scale_set(&mm->quit_text, mm->title_text.transform.scale[0] * 0.6f, 0.0f);
|
|
|
+ mm->quit_text.transform.pos[0] = screen_w / 2.0f;
|
|
|
+ mm->quit_text.transform.pos[1] = screen_h * 0.8f;
|
|
|
+
|
|
|
+ res = LoginPrompt_alloc(&mm->login_prompt, screen_w, screen_h);
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
+
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
static Screen MainMenu_input_handle(MainMenu *const mm) {
|