diff --git a/assets/fonts/6809_chargen.ttf b/assets/fonts/6809_chargen.ttf new file mode 100644 index 0000000..bb81608 Binary files /dev/null and b/assets/fonts/6809_chargen.ttf differ diff --git a/assets/scenes/scene_1.symtres b/assets/scenes/scene_1.symtres index 6919499..4c001d5 100755 --- a/assets/scenes/scene_1.symtres +++ b/assets/scenes/scene_1.symtres @@ -12,17 +12,16 @@ Scene_Config debug_draw_enabled : false debug_draw_mode : 0 ambient_light : 0.100 0.100 0.100 - next_scene : scene_2 } Player { type : 2 scale : 1.000 1.000 1.000 - rotation : 0.000 -0.612 0.000 0.792 + rotation : 0.000 -0.956 0.000 0.298 active : true player_key_mask : 0 - position : -33.501 2.167 -45.463 + position : -31.232 2.167 -49.335 player_health : 100 name : Player bounding_box_min : -1.500 -1.500 -1.000 diff --git a/assets/textures/gui_skin.tga b/assets/textures/gui_skin.tga new file mode 100644 index 0000000..e064619 Binary files /dev/null and b/assets/textures/gui_skin.tga differ diff --git a/src/common/version.h b/src/common/version.h index f5fe498..33e0877 100755 --- a/src/common/version.h +++ b/src/common/version.h @@ -4,7 +4,7 @@ /* Auto generated version file. DO NOT MODIFY */ #define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MINOR 1 -#define SYMMETRY_VERSION_REVISION 353 +#define SYMMETRY_VERSION_REVISION 354 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/console.c b/src/game/console.c index 58807de..0d79e2e 100755 --- a/src/game/console.c +++ b/src/game/console.c @@ -41,7 +41,7 @@ void console_init(struct Console* console) console->visible = false; console->scroll_to_bottom = true; - console->text_region_height = 22.f; + console->text_region_height = 30.f; console->line_height = 20.f; console->current_message_index = -1; console->current_history_index = 0; diff --git a/src/game/door.c b/src/game/door.c index ff81f39..3b0b566 100644 --- a/src/game/door.c +++ b/src/game/door.c @@ -5,6 +5,7 @@ #include "transform.h" #include "trigger.h" #include "event.h" +#include "gui_game.h" #include "sound_source.h" #include "../common/log.h" #include "../common/parser.h" @@ -13,10 +14,10 @@ static void door_on_scene_loaded(struct Event* event, void* door_ptr); static void door_on_trigger(struct Event* event, void* door_ptr); -static const vec4 KEY_INDICATOR_COLOR_RED = { 0.87, 0.32, 0.40, 1.0f }; -static const vec4 KEY_INDICATOR_COLOR_GREEN = { 0.53, 0.67, 0.28, 1.0f }; -static const vec4 KEY_INDICATOR_COLOR_BLUE = { 0.47, 0.67, 0.89, 1.0f }; -static const vec4 KEY_INDICATOR_COLOR_DISABLED = { 0.1, 0.1, 0.1, 1.0f }; +vec4 KEY_INDICATOR_COLOR_RED = { 0.87, 0.32, 0.40, 1.0f }; +vec4 KEY_INDICATOR_COLOR_GREEN = { 0.53, 0.67, 0.28, 1.0f }; +vec4 KEY_INDICATOR_COLOR_BLUE = { 0.47, 0.67, 0.89, 1.0f }; +vec4 KEY_INDICATOR_COLOR_DISABLED = { 0.1, 0.1, 0.1, 1.0f }; void door_init(struct Door* door, int mask) { @@ -93,6 +94,7 @@ void door_update(struct Door* door, struct Scene* scene, float dt) sound_source_play(game_state->sound, door->sound); door->lock_sound_played = true; } + gui_game_show_door_locked_dialog(game_state->gui_game, door); } } break; diff --git a/src/game/door.h b/src/game/door.h index 5d47a41..49c4f7c 100644 --- a/src/game/door.h +++ b/src/game/door.h @@ -1,6 +1,8 @@ #ifndef DOOR_H #define DOOR_H +#include "../common/linmath.h" + struct Door; struct Static_Mesh; struct Sound_Source; @@ -16,6 +18,11 @@ enum Door_State DOOR_STATE_MAX }; +extern vec4 KEY_INDICATOR_COLOR_RED; +extern vec4 KEY_INDICATOR_COLOR_GREEN; +extern vec4 KEY_INDICATOR_COLOR_BLUE; +extern vec4 KEY_INDICATOR_COLOR_DISABLED; + void door_init(struct Door* door, int mask); void door_reset(struct Door* door); void door_update(struct Door* door, struct Scene* scene, float dt); diff --git a/src/game/game.c b/src/game/game.c index 4d47b58..f751810 100755 --- a/src/game/game.c +++ b/src/game/game.c @@ -113,7 +113,6 @@ bool game_init(struct Window* window, struct Hashmap* cvars) texture_init(); framebuffer_init(); gui_init(game_state->gui_editor); - gui_init(game_state->gui_game); gui_game_init(game_state->gui_game); console_init(game_state->console); geom_init(); @@ -538,7 +537,7 @@ bool game_run(void) if(frame_time > MAX_FRAME_TIME) frame_time = (1.f / 60.f); /* To deal with resuming from breakpoint we artificially set delta time */ accumulator += frame_time; - struct Gui* gui = game_state->game_mode == GAME_MODE_EDITOR ? game_state->gui_editor : game_state->gui_game; + struct Gui* gui = game_state->game_mode == GAME_MODE_EDITOR ? game_state->gui_editor : game_state->gui_game->gui; gui_input_begin(gui); event_manager_poll_events(game_state->event_manager); gui_input_end(gui); @@ -595,7 +594,7 @@ void game_update(float dt) //game_debug(dt); //game_debug_gui(dt); - console_update(game_state->console, game_state->game_mode == GAME_MODE_EDITOR ? game_state->gui_editor : game_state->gui_game, dt); + console_update(game_state->console, game_state->game_mode == GAME_MODE_EDITOR ? game_state->gui_editor : game_state->gui_game->gui, dt); if(game_state->update_scene) scene_update(game_state->scene, dt); @@ -1983,7 +1982,6 @@ void game_cleanup(void) renderer_cleanup(game_state->renderer); gui_game_cleanup(game_state->gui_game); gui_cleanup(game_state->gui_editor); - gui_cleanup(game_state->gui_game); console_destroy(game_state->console); geom_cleanup(); framebuffer_cleanup(); diff --git a/src/game/game.h b/src/game/game.h index bbddc0a..7f9763c 100755 --- a/src/game/game.h +++ b/src/game/game.h @@ -14,6 +14,7 @@ struct Event_Manager; struct Editor; struct Hashmap; struct Sound; +struct Game_Gui; enum Game_Mode { @@ -34,7 +35,7 @@ struct Game_State struct Scene* scene; struct Console* console; struct Gui* gui_editor; - struct Gui* gui_game; + struct Game_Gui* gui_game; struct Event_Manager* event_manager; struct Editor* editor; struct Hashmap* cvars; diff --git a/src/game/gui.c b/src/game/gui.c index 8937af6..3ef5be0 100755 --- a/src/game/gui.c +++ b/src/game/gui.c @@ -12,6 +12,7 @@ #include "../system/platform.h" #include "../system/file_io.h" #include "event.h" +#include "gui_game.h" #include #include @@ -156,7 +157,7 @@ void gui_render(struct Gui* gui, enum nk_anti_aliasing AA) scale.y = (float)display_height/(float)height; /* setup global state */ - glViewport(0,0,display_width,display_height); + glViewport(0, 0, display_width, display_height); glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -189,7 +190,7 @@ void gui_render(struct Gui* gui, enum nk_anti_aliasing AA) /* fill convert configuration */ struct nk_convert_config config; static const struct nk_draw_vertex_layout_element vertex_layout[] = - { + { {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct Gui_Vertex, pos)}, {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct Gui_Vertex, uv)}, {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct Gui_Vertex, col)}, @@ -271,7 +272,7 @@ void gui_on_key(const struct Event* event) struct Game_State* game_state = game_state_get(); int key = event->key.key; bool mod_ctrl = event->key.mod_ctrl; - struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context; + struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->gui->context; int down = event->type == EVT_KEY_PRESSED ? 1 : 0; @@ -345,7 +346,7 @@ void gui_on_mousebutton(const struct Event* event) int x = event->mousebutton.x; int y = event->mousebutton.y; int down = event->type == EVT_MOUSEBUTTON_PRESSED ? 1 : 0; - struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context; + struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->gui->context; if(button == MSB_LEFT) nk_input_button(ctx, NK_BUTTON_LEFT, x, y, down); if(button == MSB_MIDDLE) nk_input_button(ctx, NK_BUTTON_MIDDLE, x, y, down); @@ -359,7 +360,7 @@ void gui_on_mousemotion(const struct Event* event) int y = event->mousemotion.y; int xrel = event->mousemotion.xrel; int yrel = event->mousemotion.yrel; - struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context; + struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->gui->context; if(ctx->input.mouse.grabbed) { @@ -375,7 +376,7 @@ void gui_on_mousemotion(const struct Event* event) void gui_on_textinput(const struct Event* event) { struct Game_State* game_state = game_state_get(); - struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context; + struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->gui->context; nk_glyph glyph; memcpy(glyph, event->text_input.text, NK_UTF_SIZE); nk_input_glyph(ctx, glyph); @@ -386,7 +387,7 @@ void gui_on_mousewheel(const struct Event* event) int x = event->mousewheel.x; int y = event->mousewheel.y; struct Game_State* game_state = game_state_get(); - struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->context; + struct nk_context* ctx = game_state->game_mode == GAME_MODE_EDITOR ? &game_state->gui_editor->context : &game_state->gui_game->gui->context; nk_input_scroll(ctx, nk_vec2(x, y)); } diff --git a/src/game/gui_game.c b/src/game/gui_game.c index ee948c7..eab0e4c 100644 --- a/src/game/gui_game.c +++ b/src/game/gui_game.c @@ -1,14 +1,18 @@ #include "gui_game.h" -#include "gui.h" #include "game.h" #include "scene.h" #include "../common/log.h" #include "../system/platform.h" #include "event.h" #include "input.h" +#include "texture.h" +#include "door.h" -static bool show_next_level_dialog = false; -static bool show_restart_level_dialog = false; +#define SKIN_TEXTURE_WIDTH 256 +#define SKIN_TEXTURE_HEIGHT 256 + +static float key_opacity_full = 1.f; +static float key_opacity_reduced = 0.3f; static void gui_game_pause_menu(struct nk_context* context); static void gui_game_next_level_dialog(struct nk_context* context); @@ -16,41 +20,91 @@ static void gui_game_restart_level_dialog(struct nk_context* context); static void gui_game_on_player_death(struct Event* event); static void gui_game_on_scene_cleared(struct Event* event); -void gui_game_init(struct Gui* game_gui) +void gui_game_init(struct Game_Gui* game_gui) { - gui_theme_set(game_state_get()->gui_game, GT_RED); + game_gui->gui = calloc(1, sizeof(*game_gui->gui)); + gui_init(game_gui->gui); + game_gui->show_next_level_dialog = false; + game_gui->show_restart_level_dialog = false; + game_gui->skin.skin_texture = texture_create_from_file("gui_skin.tga", TU_DIFFUSE); + game_gui->skin.button = nk_subimage_id(game_gui->skin.skin_texture, SKIN_TEXTURE_WIDTH, SKIN_TEXTURE_HEIGHT, nk_recti(32, 32, 128, 48)); + game_gui->skin.button_active = nk_subimage_id(game_gui->skin.skin_texture, SKIN_TEXTURE_WIDTH, SKIN_TEXTURE_HEIGHT, nk_recti(32, 32, 128, 48)); + game_gui->skin.button_hover = nk_subimage_id(game_gui->skin.skin_texture, SKIN_TEXTURE_WIDTH, SKIN_TEXTURE_HEIGHT, nk_recti(32, 32, 128, 48)); + game_gui->skin.hp = nk_subimage_id(game_gui->skin.skin_texture, SKIN_TEXTURE_WIDTH, SKIN_TEXTURE_HEIGHT, nk_recti(32, 0, 32, 32)); + game_gui->skin.key = nk_subimage_id(game_gui->skin.skin_texture, SKIN_TEXTURE_WIDTH, SKIN_TEXTURE_HEIGHT, nk_recti(0, 32, 32, 32)); + + struct nk_context* context = &game_gui->gui->context; + context->style.button.normal = nk_style_item_image(game_gui->skin.button); + context->style.button.active = nk_style_item_image(game_gui->skin.button_active); + context->style.button.hover = nk_style_item_image(game_gui->skin.button_hover); + + context->style.window.border_color = nk_rgba_f(0.f, 0.f, 0.f, 1.f); + context->style.window.background = nk_rgba_f(0.f, 0.f, 0.f, 1.f); + context->style.window.fixed_background = nk_style_item_image(nk_subimage_id(game_gui->skin.skin_texture, + SKIN_TEXTURE_WIDTH, SKIN_TEXTURE_HEIGHT, + nk_recti(32, 32, 128, 48))); + //context->style.window.fixed_background = nk_style_item_color(nk_rgba_f(0.f, 0.f, 0.f, 0.05f)); + + gui_font_set(game_gui->gui, "6809_chargen.ttf", 30.f); + struct Event_Manager* event_manager = game_state_get()->event_manager; event_manager_subscribe(event_manager, EVT_PLAYER_DIED, &gui_game_on_player_death); event_manager_subscribe(event_manager, EVT_SCENE_CLEARED, &gui_game_on_scene_cleared); } -void gui_game_cleanup(struct Gui* game_gui) +void gui_game_cleanup(struct Game_Gui* game_gui) { + texture_remove(game_gui->skin.skin_texture); + gui_cleanup(game_gui->gui); + free(game_gui->gui); + struct Event_Manager* event_manager = game_state_get()->event_manager; event_manager_unsubscribe(event_manager, EVT_PLAYER_DIED, &gui_game_on_player_death); event_manager_unsubscribe(event_manager, EVT_SCENE_CLEARED, &gui_game_on_scene_cleared); } -void gui_game_update(struct Gui* gui_game, float dt) +void gui_game_update(struct Game_Gui* game_gui, float dt) { - struct nk_context* context = &gui_game->context; + struct nk_context* context = &game_gui->gui->context; struct Game_State* game_state = game_state_get(); if(game_state->game_mode == GAME_MODE_GAME) { // HUD + int hud_offset_x = 50; + int hud_offset_y = 50; + int hp_gui_width = 130; + int hp_gui_height = 48; struct Player* player = &game_state->scene->player; - if(nk_begin(context, "Game Gui", nk_rect(50, 50, 200, 100), NK_WINDOW_CLOSABLE)) + if(nk_begin(context, "HP Gui", nk_recti(hud_offset_x, hud_offset_y, hp_gui_width, hp_gui_height), NK_WINDOW_BACKGROUND | NK_WINDOW_NO_SCROLLBAR)) + { + nk_layout_row_dynamic(context, 40, 2); + nk_image_color(context, game_gui->skin.hp, nk_rgba_f(1.f, 1.f, 1.f, 1.f)); + nk_labelf(context, NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE, "%d", player->health); + nk_end(context); + } + + int key_gui_width = 192; + int key_gui_height = 48; + int display_width = 0; + int display_height = 0; + window_get_drawable_size(game_state_get()->window, &display_width, &display_height); + int key_gui_pos_x = display_width - (key_gui_width + hud_offset_x); + int key_gui_pos_y = hud_offset_y; + if(nk_begin(context, "Key Gui", nk_recti(key_gui_pos_x, key_gui_pos_y, key_gui_width, key_gui_height), NK_WINDOW_BACKGROUND | NK_WINDOW_NO_SCROLLBAR)) { - nk_layout_row_dynamic(context, 30, 1); - nk_labelf(context, NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE, "HP: %d", player->health); + nk_layout_row_dynamic(context, 40, 3); + nk_image_color(context, game_gui->skin.key, nk_rgba_f(KEY_INDICATOR_COLOR_RED.x, KEY_INDICATOR_COLOR_RED.y, KEY_INDICATOR_COLOR_RED.z, (player->key_mask & DOOR_KEY_MASK_RED) == DOOR_KEY_MASK_RED ? key_opacity_full : key_opacity_reduced)); + nk_image_color(context, game_gui->skin.key, nk_rgba_f(KEY_INDICATOR_COLOR_GREEN.x, KEY_INDICATOR_COLOR_GREEN.y, KEY_INDICATOR_COLOR_GREEN.z, (player->key_mask & DOOR_KEY_MASK_GREEN) == DOOR_KEY_MASK_GREEN ? key_opacity_full : key_opacity_reduced)); + nk_image_color(context, game_gui->skin.key, nk_rgba_f(KEY_INDICATOR_COLOR_BLUE.x, KEY_INDICATOR_COLOR_BLUE.y, KEY_INDICATOR_COLOR_BLUE.z, (player->key_mask & DOOR_KEY_MASK_BLUE) == DOOR_KEY_MASK_BLUE ? key_opacity_full : key_opacity_reduced)); + nk_end(context); } - if(show_next_level_dialog) + if(game_gui->show_next_level_dialog) gui_game_next_level_dialog(context); - if(show_restart_level_dialog) + if(game_gui->show_restart_level_dialog) gui_game_restart_level_dialog(context); } else if(game_state->game_mode == GAME_MODE_PAUSE) @@ -60,6 +114,84 @@ void gui_game_update(struct Gui* gui_game, float dt) } +void gui_game_show_door_locked_dialog(struct Game_Gui* game_gui, struct Door* door) +{ + struct nk_context* context = &game_gui->gui->context; + struct Game_State* game_state = game_state_get(); + if(game_state->game_mode == GAME_MODE_GAME) + { + struct Player* player = &game_state->scene->player; + int label_flags = NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE; + int key_needed_gui_width = 300; + int key_needed_gui_height = 48; + int display_width = 0; + int display_height = 0; + window_get_drawable_size(game_state->window, &display_width, &display_height); + int key_needed_gui_y = 50; + int keys_needed = 0; + bool red_needed = false; + bool green_needed = false; + bool blue_needed = false; + float starting_ratio = 0.65f; + + if((player->key_mask & DOOR_KEY_MASK_RED) != DOOR_KEY_MASK_RED && (door->mask & DOOR_KEY_MASK_RED) == DOOR_KEY_MASK_RED) + { + red_needed = true; + keys_needed++; + key_needed_gui_width += 100; + starting_ratio -= 0.1f; + } + + if((player->key_mask & DOOR_KEY_MASK_GREEN) != DOOR_KEY_MASK_GREEN && (door->mask & DOOR_KEY_MASK_GREEN) == DOOR_KEY_MASK_GREEN) + { + green_needed = true; + keys_needed++; + key_needed_gui_width += 100; + starting_ratio -= 0.1f; + } + + if((player->key_mask & DOOR_KEY_MASK_BLUE) != DOOR_KEY_MASK_BLUE && (door->mask & DOOR_KEY_MASK_BLUE) == DOOR_KEY_MASK_BLUE) + { + blue_needed = true; + keys_needed++; + key_needed_gui_width += 100; + starting_ratio -= 0.1f; + } + int key_needed_gui_x = (display_width / 2) - (key_needed_gui_width / 2); + + if(nk_begin(context, "Key Needed Gui", nk_recti(key_needed_gui_x, key_needed_gui_y, key_needed_gui_width, key_needed_gui_height), NK_WINDOW_BACKGROUND | NK_WINDOW_NO_SCROLLBAR)) + { + nk_layout_row_begin(context, NK_DYNAMIC, 40, keys_needed + 2); + nk_layout_row_push(context, starting_ratio); + nk_label(context, "YOU NEED THE", label_flags); + + if(red_needed) + { + nk_layout_row_push(context, 0.15f); + nk_label_colored(context, "RED", label_flags, nk_rgba_fv(&KEY_INDICATOR_COLOR_RED)); + } + + if(green_needed) + { + nk_layout_row_push(context, 0.15f); + nk_label_colored(context, "GREEN", label_flags, nk_rgba_fv(&KEY_INDICATOR_COLOR_GREEN)); + keys_needed++; + } + + if(blue_needed) + { + nk_layout_row_push(context, 0.15f); + nk_label_colored(context, "BLUE", label_flags, nk_rgba_fv(&KEY_INDICATOR_COLOR_BLUE)); + keys_needed++; + } + + nk_layout_row_push(context, 0.25f); + nk_label(context, keys_needed > 1 ? "KEYS" : "KEY", label_flags); + nk_end(context); + } + } +} + void gui_game_pause_menu(struct nk_context* context) { struct Game_State* game_state = game_state_get(); @@ -76,8 +208,6 @@ void gui_game_pause_menu(struct nk_context* context) popup_y = (display_height / 2) - (popup_height / 2); int background_window_flags = NK_WINDOW_BACKGROUND; - int previous_opacity = context->style.window.fixed_background.data.color.a; - context->style.window.fixed_background.data.color.a = 120; if(nk_begin(context, "Pause Gui", nk_rect(0, 0, display_width, display_height), background_window_flags)) { nk_window_set_focus(context, "Pause Gui"); @@ -104,12 +234,12 @@ void gui_game_pause_menu(struct nk_context* context) nk_end(context); } - context->style.window.fixed_background.data.color.a = previous_opacity; } static void gui_game_next_level_dialog(struct nk_context* context) { struct Game_State* game_state = game_state_get(); + struct Game_Gui* game_gui = game_state->gui_game; struct Scene* scene = game_state->scene; int row_height = 30; int popup_x = 0; @@ -124,8 +254,6 @@ static void gui_game_next_level_dialog(struct nk_context* context) popup_y = (display_height / 2) - (popup_height / 2); int background_window_flags = NK_WINDOW_BACKGROUND; - int previous_opacity = context->style.window.fixed_background.data.color.a; - context->style.window.fixed_background.data.color.a = 120; if(nk_begin(context, "Scene Cleared", nk_rect(0, 0, display_width, display_height), background_window_flags)) { nk_window_set_focus(context, "Scene Cleared"); @@ -139,7 +267,7 @@ static void gui_game_next_level_dialog(struct nk_context* context) if(!scene_load(game_state->scene, filename, DIRT_INSTALL)) log_error("gui_game:next_level_dialog", "Failed to reload Level"); else - show_next_level_dialog = false; + game_gui->show_next_level_dialog = false; } if(nk_button_label(context, "Next Level")) @@ -151,7 +279,7 @@ static void gui_game_next_level_dialog(struct nk_context* context) if(!scene_load(game_state->scene, filename, DIRT_INSTALL)) log_error("gui_game:next_level_dialog", "Failed to load new Level"); else - show_next_level_dialog = false; + game_gui->show_next_level_dialog = false; } else { @@ -167,12 +295,12 @@ static void gui_game_next_level_dialog(struct nk_context* context) nk_end(context); } - context->style.window.fixed_background.data.color.a = previous_opacity; } static void gui_game_restart_level_dialog(struct nk_context* context) { struct Game_State* game_state = game_state_get(); + struct Game_Gui* game_gui = game_state->gui_game; int row_height = 30; int popup_x = 0; int popup_y = 0; @@ -186,8 +314,6 @@ static void gui_game_restart_level_dialog(struct nk_context* context) popup_y = (display_height / 2) - (popup_height / 2); int background_window_flags = NK_WINDOW_BACKGROUND; - int previous_opacity = context->style.window.fixed_background.data.color.a; - context->style.window.fixed_background.data.color.a = 120; if(nk_begin(context, "Player Died Gui", nk_rect(0, 0, display_width, display_height), background_window_flags)) { nk_window_set_focus(context, "Player Died Gui"); @@ -201,7 +327,7 @@ static void gui_game_restart_level_dialog(struct nk_context* context) if(!scene_load(game_state->scene, filename, DIRT_INSTALL)) log_error("gui_game:pause_menu", "Failed to reload Level"); else - show_restart_level_dialog = false; + game_gui->show_restart_level_dialog = false; } if(nk_button_label(context, "Quit")) @@ -212,18 +338,17 @@ static void gui_game_restart_level_dialog(struct nk_context* context) nk_end(context); } - context->style.window.fixed_background.data.color.a = previous_opacity; } void gui_game_on_player_death(struct Event* event) { struct Player_Death_Event* player_death_event = (struct Player_Death_Event*)event; - show_restart_level_dialog = true; + game_state_get()->gui_game->show_restart_level_dialog = true; input_mouse_mode_set(MM_NORMAL); } void gui_game_on_scene_cleared(struct Event* event) { - show_next_level_dialog = true; + game_state_get()->gui_game->show_next_level_dialog = true; input_mouse_mode_set(MM_NORMAL); } diff --git a/src/game/gui_game.h b/src/game/gui_game.h index 8b2dc06..b3a3edf 100644 --- a/src/game/gui_game.h +++ b/src/game/gui_game.h @@ -1,10 +1,32 @@ #ifndef GUI_GAME_H #define GUI_GAME_H -struct Gui; +#include "gui.h" -void gui_game_init(struct Gui* game_gui); -void gui_game_cleanup(struct Gui* game_gui); -void gui_game_update(struct Gui* gui_game, float dt); +struct Game_Gui +{ + struct Gui* gui; + bool show_next_level_dialog; + bool show_restart_level_dialog; + + struct + { + int skin_texture; + struct nk_image button; + struct nk_image button_hover; + struct nk_image button_active; + struct nk_image check; + struct nk_image check_cursor; + struct nk_image hp; + struct nk_image key; + } skin; +}; + +struct Door; + +void gui_game_init(struct Game_Gui* game_gui); +void gui_game_cleanup(struct Game_Gui* game_gui); +void gui_game_update(struct Game_Gui* gui_game, float dt); +void gui_game_show_door_locked_dialog(struct Game_Gui* game_gui, struct Door* door); #endif \ No newline at end of file diff --git a/src/game/renderer.c b/src/game/renderer.c index eb8b67e..5bf37c1 100755 --- a/src/game/renderer.c +++ b/src/game/renderer.c @@ -26,6 +26,7 @@ #include "scene.h" #include "event.h" #include "debug_vars.h" +#include "gui_game.h" #include #include @@ -297,7 +298,7 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene) /* Render UI */ gui_render(game_state->gui_editor, NK_ANTI_ALIASING_ON); - gui_render(game_state->gui_game, NK_ANTI_ALIASING_ON); + gui_render(game_state->gui_game->gui, NK_ANTI_ALIASING_ON); } void renderer_cleanup(struct Renderer* renderer) diff --git a/src/game/scene.c b/src/game/scene.c index d5770b6..7e6319a 100755 --- a/src/game/scene.c +++ b/src/game/scene.c @@ -159,9 +159,7 @@ bool scene_load(struct Scene* scene, const char* filename, int directory_type) scene->cleanup = hashmap_value_exists(scene_data, "cleanup_func") ? hashmap_ptr_get(game_state->scene_cleanup_func_table, hashmap_str_get(scene_data, "cleanup_func")) : &scene_init_stub; if(hashmap_value_exists(scene_data, "next_scene")) - strncpy(scene->next_level_filename, hashmap_str_get(scene_data, "next_scene"), MAX_FILENAME_LEN); - else - memcpy(scene->next_level_filename, '\0', MAX_FILENAME_LEN); + strncpy(scene->next_level_filename, hashmap_value_exists(scene_data, "next_scene") ? hashmap_str_get(scene_data, "next_scene") : "NONE", MAX_FILENAME_LEN); num_objects_loaded++; } @@ -275,6 +273,7 @@ bool scene_save(struct Scene* scene, const char* filename, int directory_type) hashmap_bool_set(scene_data, "debug_draw_physics", render_settings->debug_draw_physics); if(scene->init) hashmap_str_set(scene_data, "init_func", filename); if(scene->cleanup) hashmap_str_set(scene_data, "cleanup_func", filename); + hashmap_str_set(scene_data, "next_scene", scene->next_level_filename != '\0' ? scene->next_level_filename : "NONE"); // Player struct Parser_Object* player_object = parser_object_new(parser, PO_PLAYER); diff --git a/todo.txt b/todo.txt index 15f9e2e..8653622 100644 --- a/todo.txt +++ b/todo.txt @@ -1,9 +1,4 @@ Todo: - - In-Game Gui - x Player Death Screen - x Proceed to next level Screen - - Key Required Screen - - HUD showing health, keys currently acquired - Save case sensitive file names when scene entity entries - Disbale all player actions when scene cleared dialog or scene restart dialog are active - Enemies getting hit by bullets @@ -428,4 +423,5 @@ Done: * Visual indicator on doors corresponding to their key masks * Audio cues when player does not have the right key combination to open a particular door * Added saving scene init/cleanup funcs if there are any assigned when saving scene - * Win/fail States \ No newline at end of file + * Win/fail States + x In-Game Gui \ No newline at end of file