|
@@ -10,11 +10,13 @@
|
|
|
#include "game_common.h"
|
|
#include "game_common.h"
|
|
|
#include "scufeng/text.h"
|
|
#include "scufeng/text.h"
|
|
|
|
|
|
|
|
-#define SE_RESULT_CHECK(res) \
|
|
|
|
|
- if (res != SE_SUCCESS) { \
|
|
|
|
|
- return res; \
|
|
|
|
|
|
|
+#define SE_RESULT_CHECK(res) \
|
|
|
|
|
+ if ((res) != SE_SUCCESS) { \
|
|
|
|
|
+ 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 });
|
|
|
vec2 bg_dims = { screen_w * 0.75f, screen_h * 0.75f };
|
|
vec2 bg_dims = { screen_w * 0.75f, screen_h * 0.75f };
|
|
@@ -26,49 +28,75 @@ static SEResult LoginPrompt_alloc(LoginPrompt *const lp, const unsigned int scre
|
|
|
vec4 bg_bbox;
|
|
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);
|
|
|
|
|
|
|
+ SEResult res = SEMesh_string_alloc(&lp->exit_text, "X", 1, GLM_VEC3_ONE);
|
|
|
SE_RESULT_CHECK(res);
|
|
SE_RESULT_CHECK(res);
|
|
|
|
|
+ SEMesh_rect_textured_scale_set(&lp->exit_text, bg_dims[0] * 0.05f, 0.0f);
|
|
|
|
|
+ lp->exit_text.transform.pos[0] = bg_bbox[0] + lp->exit_text.transform.scale[0] / 2.0f;
|
|
|
|
|
+ lp->exit_text.transform.pos[1] = bg_bbox[1] + lp->exit_text.transform.scale[1] / 2.0f;
|
|
|
|
|
+ glm_vec3_print(lp->exit_text.transform.pos, stdout);
|
|
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
|
+ const float label_w = bg_dims[0] * 0.25f;
|
|
|
|
|
+
|
|
|
|
|
+ res = SEMesh_string_alloc(&lp->login_button, "Login", strlen("Login"), GLM_VEC3_ONE);
|
|
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
|
|
+ SEMesh_rect_textured_scale_set(&lp->login_button, label_w, 0.0f);
|
|
|
|
|
+ lp->login_button.transform.pos[0] = bg_pos[0];
|
|
|
|
|
+ lp->login_button.transform.pos[1] = bg_bbox[3] - lp->login_button.transform.scale[1];
|
|
|
|
|
+
|
|
|
|
|
+ res = SEMesh_string_alloc(&lp->username_text, "Username:", strlen("Username:"), GLM_VEC3_ONE);
|
|
|
|
|
+ SE_RESULT_CHECK(res);
|
|
|
|
|
+ SEMesh_rect_textured_scale_set(&lp->username_text, label_w, 0.0f);
|
|
|
|
|
+ lp->username_text.transform.pos[0] = bg_bbox[0] + lp->username_text.transform.scale[0] / 2.0f;
|
|
|
|
|
+ lp->username_text.transform.pos[1] = bg_bbox[1] + bg_dims[1] / 3.0f;
|
|
|
|
|
+ float name_right, name_bottom;
|
|
|
|
|
+ SEMesh_bbox_get_2d(&lp->username_text, nullptr, nullptr, &name_right, &name_bottom);
|
|
|
|
|
|
|
|
res = SEMesh_string_alloc(&lp->password_text, "Password:", strlen("Password:"), GLM_VEC3_ONE);
|
|
res = SEMesh_string_alloc(&lp->password_text, "Password:", strlen("Password:"), GLM_VEC3_ONE);
|
|
|
SE_RESULT_CHECK(res);
|
|
SE_RESULT_CHECK(res);
|
|
|
|
|
+ SEMesh_rect_textured_scale_set(&lp->password_text, label_w, 0.0f);
|
|
|
|
|
+ lp->password_text.transform.pos[0] = bg_bbox[0] + lp->password_text.transform.scale[0] / 2.0f;
|
|
|
|
|
+ lp->password_text.transform.pos[1] = name_bottom + lp->password_text.transform.scale[1];
|
|
|
|
|
+ float pw_right;
|
|
|
|
|
+ SEMesh_bbox_get_2d(&lp->password_text, nullptr, nullptr, &pw_right, nullptr);
|
|
|
|
|
|
|
|
- lp->password_input = SETextInput_alloc(
|
|
|
|
|
- "",
|
|
|
|
|
- 0,
|
|
|
|
|
- 0,
|
|
|
|
|
- 0,
|
|
|
|
|
|
|
+ lp->username_input = SETextInput_alloc(
|
|
|
|
|
+ "username",
|
|
|
|
|
+ strlen("username"),
|
|
|
GLM_VEC3_ONE,
|
|
GLM_VEC3_ONE,
|
|
|
- (vec4) { 0.0025f, 0.0025f, 0.0025f, 1.0f },
|
|
|
|
|
- TI_FIXED_WIDTH
|
|
|
|
|
|
|
+ (vec4) { 0.0025f, 0.0025f, 0.0025f, 1.0f }
|
|
|
);
|
|
);
|
|
|
- SETextInput_fixed_width_set(&lp->password_input, bg_dims[0] * 0.25f);
|
|
|
|
|
|
|
+ SETextInput_scale_set(&lp->username_input,
|
|
|
|
|
+ (vec2) {
|
|
|
|
|
+ lp->bg.transform.scale[0] - lp->username_text.transform.scale[0],
|
|
|
|
|
+ lp->username_text.transform.scale[1],
|
|
|
|
|
+ });
|
|
|
|
|
+ SETextInput_pos_set(&lp->username_input,
|
|
|
|
|
+ (vec2) {
|
|
|
|
|
+ name_right + SETextInput_scale(lp->username_input)[0] / 2.0f,
|
|
|
|
|
+ lp->username_text.transform.pos[1],
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- puts("bg_dims");
|
|
|
|
|
- glm_vec2_print(bg_dims, stdout);
|
|
|
|
|
- puts("bg_pos");
|
|
|
|
|
- glm_vec2_print(bg_pos, stdout);
|
|
|
|
|
- puts("bg_bbox");
|
|
|
|
|
- glm_vec4_print(bg_bbox, 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);
|
|
|
|
|
|
|
+ lp->password_input = SETextInput_alloc(
|
|
|
|
|
+ "password",
|
|
|
|
|
+ strlen("password"),
|
|
|
|
|
+ GLM_VEC3_ONE,
|
|
|
|
|
+ (vec4) { 0.0025f, 0.0025f, 0.0025f, 1.0f }
|
|
|
|
|
+ );
|
|
|
|
|
+ SETextInput_scale_set(&lp->password_input, SETextInput_scale(lp->username_input));
|
|
|
|
|
+ SETextInput_pos_set(
|
|
|
|
|
+ &lp->password_input,
|
|
|
|
|
+ (vec2) {
|
|
|
|
|
+ pw_right + SETextInput_scale(lp->password_input)[0] / 2.0f,
|
|
|
|
|
+ lp->password_text.transform.pos[1],
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- res = SEMesh_string_alloc(&lp->login_text, "Login", strlen("Login"), GLM_VEC3_ONE);
|
|
|
|
|
- SE_RESULT_CHECK(res);
|
|
|
|
|
|
|
+ // puts("bg_dims");
|
|
|
|
|
+ // glm_vec2_print(bg_dims, stdout);
|
|
|
|
|
+ // puts("bg_pos");
|
|
|
|
|
+ // glm_vec2_print(bg_pos, stdout);
|
|
|
|
|
+ // puts("bg_bbox");
|
|
|
|
|
+ // glm_vec4_print(bg_bbox, stdout);
|
|
|
|
|
|
|
|
return SE_SUCCESS;
|
|
return SE_SUCCESS;
|
|
|
}
|
|
}
|
|
@@ -79,7 +107,7 @@ static void LoginPrompt_render(LoginPrompt *const lp) {
|
|
|
&lp->username_text,
|
|
&lp->username_text,
|
|
|
&lp->password_text,
|
|
&lp->password_text,
|
|
|
&lp->exit_text,
|
|
&lp->exit_text,
|
|
|
- &lp->login_text
|
|
|
|
|
|
|
+ &lp->login_button,
|
|
|
};
|
|
};
|
|
|
SETextInput *const tis[] = {
|
|
SETextInput *const tis[] = {
|
|
|
&lp->username_input,
|
|
&lp->username_input,
|
|
@@ -136,19 +164,43 @@ static Screen MainMenu_input_handle(MainMenu *const mm) {
|
|
|
double x, y;
|
|
double x, y;
|
|
|
se_get_mouse_pos(&x, &y);
|
|
se_get_mouse_pos(&x, &y);
|
|
|
|
|
|
|
|
- if (SEMesh_rect_is_pos_inside(&mm->sp_text, x, y)) {
|
|
|
|
|
- SE_LOG("SP");
|
|
|
|
|
- return PONG_SINGLEPLAYER;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (SEMesh_rect_is_pos_inside(&mm->mp_text, x, y)) {
|
|
|
|
|
- SE_LOG("MP");
|
|
|
|
|
- return PONG_MULTIPLAYER;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (SEMesh_rect_is_pos_inside(&mm->quit_text, x, y)) {
|
|
|
|
|
- SE_LOG("Quit");
|
|
|
|
|
- se_window_close();
|
|
|
|
|
|
|
+ if (!login_render) {
|
|
|
|
|
+ if (SEMesh_rect_is_pos_inside(&mm->sp_text, x, y)) {
|
|
|
|
|
+ SE_LOG("SP");
|
|
|
|
|
+ return PONG_SINGLEPLAYER;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (SEMesh_rect_is_pos_inside(&mm->mp_text, x, y)) {
|
|
|
|
|
+ SE_LOG("MP");
|
|
|
|
|
+ return PONG_MULTIPLAYER;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (SEMesh_rect_is_pos_inside(&mm->quit_text, x, y)) {
|
|
|
|
|
+ SE_LOG("Quit");
|
|
|
|
|
+ se_window_close();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (SEMesh_rect_is_pos_inside(&mm->login_text, x, y)) {
|
|
|
|
|
+ login_render = true;
|
|
|
|
|
+ return PONG_MAIN_MENU;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (SEMesh_rect_is_pos_inside(&mm->login_prompt.exit_text, x, y)) {
|
|
|
|
|
+ login_render = false;
|
|
|
|
|
+ return PONG_MAIN_MENU;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ SETextInput *const tis[] = {
|
|
|
|
|
+ &mm->login_prompt.username_input,
|
|
|
|
|
+ &mm->login_prompt.password_input,
|
|
|
|
|
+ };
|
|
|
|
|
+ SETextInput_deactivate();
|
|
|
|
|
+ for (size_t i = 0; i < sizeof(tis) / sizeof(tis[0]); i++) {
|
|
|
|
|
+ if (SETextInput_is_pos_inside(tis[i], x, y)) {
|
|
|
|
|
+ SETextInput_activate(tis[i]);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -168,8 +220,13 @@ Screen MainMenu_tick(MainMenu *const mm) {
|
|
|
&mm->login_text
|
|
&mm->login_text
|
|
|
};
|
|
};
|
|
|
SEMesh_render_multiple_2d(meshes, sizeof(meshes) / sizeof(meshes[0]));
|
|
SEMesh_render_multiple_2d(meshes, sizeof(meshes) / sizeof(meshes[0]));
|
|
|
|
|
+ for (size_t i = 0; i < sizeof(meshes) / sizeof(meshes[0]); i++) {
|
|
|
|
|
+ SEMesh_bbox_render_2d(meshes[i]);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // LoginPrompt_render(&mm->login_prompt);
|
|
|
|
|
|
|
+ if (login_render) {
|
|
|
|
|
+ LoginPrompt_render(&mm->login_prompt);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return PONG_MAIN_MENU;
|
|
return PONG_MAIN_MENU;
|
|
|
}
|
|
}
|