From 341040abc2e7dca8a2c8ece7bfe25ae973f0b7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Mon, 16 Jan 2023 13:11:27 +0100 Subject: [PATCH] embedded tooltips --- code/foundation/src/gui/inventory.c | 8 +++++++- code/foundation/src/gui/tooltip.c | 28 +++++++++++++++++++++------- code/foundation/src/platform/arch.h | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/code/foundation/src/gui/inventory.c b/code/foundation/src/gui/inventory.c index 7c9ede1..6046382 100644 --- a/code/foundation/src/gui/inventory.c +++ b/code/foundation/src/gui/inventory.c @@ -95,8 +95,14 @@ inv_draw_result inventory_draw_crafting_btn(float xpos, float ypos, const char * recipe rp = craft_get_recipe_data(craft_get_recipe_id_from_product(id)); int num_reagents = 0; for (int i = 0; rp.reagents[i].id; i++) num_reagents++; - if (nk_begin(game_ui , name, nk_rect(mpos.x+15, mpos.y+15, name_width+5, 600), + if (nk_begin(game_ui , name, nk_rect(mpos.x+15, mpos.y+15, name_width+5, 1200), NK_WINDOW_BORDER | NK_WINDOW_NO_INPUT | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_DYNAMIC)) { + if (nk_tree_push_id(game_ui, NK_TREE_NODE, "Overview", NK_MAXIMIZED, id)) { + { + tooltip_draw_contents(tooltip_find_desc(name)); + } + nk_tree_pop(game_ui); + } if (nk_tree_push_id(game_ui, NK_TREE_NODE, "Reagents", NK_MAXIMIZED, id)) { for (asset_id i = 0; rp.reagents[i].id; i++) { nk_label(game_ui, asset_names[rp.reagents[i].id], NK_TEXT_LEFT); diff --git a/code/foundation/src/gui/tooltip.c b/code/foundation/src/gui/tooltip.c index 9113f0f..9786082 100644 --- a/code/foundation/src/gui/tooltip.c +++ b/code/foundation/src/gui/tooltip.c @@ -59,6 +59,7 @@ void tooltip_register_defaults(void) { tooltip_register( (tooltip) { .name = "ASSET_FURNACE", .content = "Producer used to smelt ASSET_IRON_ORE into ASSET_IRON_INGOT." } ); tooltip_register( (tooltip) { .name = "ASSET_IRON_ORE", .content = "Natural resource that can be smelted in ASSET_FURNACE." } ); tooltip_register( (tooltip) { .name = "ASSET_IRON_INGOT", .content = "Used as a building material. It is smelted from ASSET_IRON_ORE" } ); + tooltip_register( (tooltip) { .name = "ASSET_SCREWS", .content = "Used as a building material. It is crafted from ASSET_IRON_PLATES" } ); } //~ rendering @@ -74,7 +75,7 @@ typedef struct _tooltip_node { static tooltip_node main_tooltip = { 0 }; static bool tooltip__should_stay_open = false; -tooltip *tooltip__find_desc(const char *name) { +tooltip *tooltip_find_desc(const char *name) { for (zpl_isize i = 0; i < zpl_array_count(tooltips); ++i) { tooltip *tp = (tooltips + i); @@ -90,7 +91,7 @@ void tooltip_clear(void); void tooltip_show(const char* name, float xpos, float ypos) { if (!tooltips) return; - tooltip *desc = tooltip__find_desc(name); + tooltip *desc = tooltip_find_desc(name); if (!name) return; tooltip_clear(); @@ -120,16 +121,22 @@ void tooltip_clear(void) { main_tooltip = (tooltip_node) {0}; } +inline void tooltip_draw_contents(tooltip *desc) { + if (!desc) return; + + nk_layout_row_dynamic(game_ui, 30, 1); + nk_label_wrap(game_ui, desc->content); +} + void tooltip__draw_node(tooltip_node *node) { if (!node) return; tooltip *desc = node->desc; Vector2 mpos = GetMousePosition(); - if (nk_begin_titled(game_ui, zpl_bprintf("%d%s", (int)node->xpos, desc->name), desc->name, nk_rect(node->xpos, node->ypos, 300, 1200), + if (nk_begin_titled(game_ui, zpl_bprintf("%d%s", (int)node->xpos, desc->name), desc->name, nk_rect(node->xpos, node->ypos, 400, 3200), NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_DYNAMIC | NK_WINDOW_TITLE | NK_WINDOW_MOVABLE)) { - nk_layout_row_dynamic(game_ui, 30, 1); - nk_label_wrap(game_ui, desc->content); + tooltip_draw_contents(desc); if (desc->links) { nk_label(game_ui, "See Also:", NK_TEXT_LEFT); @@ -143,7 +150,7 @@ void tooltip__draw_node(tooltip_node *node) { *node->next = (tooltip_node) { .xpos = mpos.x+15, .ypos = mpos.y+15, - .desc = tooltip__find_desc(desc->links[i]), + .desc = tooltip_find_desc(desc->links[i]), .next = 0 }; } @@ -152,11 +159,18 @@ void tooltip__draw_node(tooltip_node *node) { // suggest closing tooltip struct nk_vec2 wpos = nk_window_get_position(game_ui); - Vector2 tp_pos = (Vector2) { .x = wpos.x, .y = wpos.y }; + struct nk_vec2 wsize = nk_window_get_content_region_size(game_ui); + Vector2 tp_pos = (Vector2) { .x = wpos.x + wsize.x/2.0f, .y = wpos.y }; if (Vector2Distance(mpos, tp_pos) <= TOOLTIP_MOUSE_DIST) { tooltip__should_stay_open = true; } +#if 0 + { + DrawCircleV(tp_pos, TOOLTIP_MOUSE_DIST, BLUE); + } +#endif + nk_end(game_ui); // draw nested tooltip diff --git a/code/foundation/src/platform/arch.h b/code/foundation/src/platform/arch.h index 71e0177..371ddf6 100644 --- a/code/foundation/src/platform/arch.h +++ b/code/foundation/src/platform/arch.h @@ -71,7 +71,7 @@ void platform_create_window(const char *title) { InitWindow(screenWidth, screenHeight, title); uint32_t flags = /*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT; #if !defined(PLATFORM_WEB) - //flags |= FLAG_VSYNC_HINT; + // flags |= FLAG_VSYNC_HINT; #endif SetWindowState(flags);