embedded tooltips
parent
b9e29dd7ab
commit
341040abc2
|
@ -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));
|
recipe rp = craft_get_recipe_data(craft_get_recipe_id_from_product(id));
|
||||||
int num_reagents = 0;
|
int num_reagents = 0;
|
||||||
for (int i = 0; rp.reagents[i].id; i++) num_reagents++;
|
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)) {
|
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)) {
|
if (nk_tree_push_id(game_ui, NK_TREE_NODE, "Reagents", NK_MAXIMIZED, id)) {
|
||||||
for (asset_id i = 0; rp.reagents[i].id; i++) {
|
for (asset_id i = 0; rp.reagents[i].id; i++) {
|
||||||
nk_label(game_ui, asset_names[rp.reagents[i].id], NK_TEXT_LEFT);
|
nk_label(game_ui, asset_names[rp.reagents[i].id], NK_TEXT_LEFT);
|
||||||
|
|
|
@ -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_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_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_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
|
//~ rendering
|
||||||
|
@ -74,7 +75,7 @@ typedef struct _tooltip_node {
|
||||||
static tooltip_node main_tooltip = { 0 };
|
static tooltip_node main_tooltip = { 0 };
|
||||||
static bool tooltip__should_stay_open = false;
|
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) {
|
for (zpl_isize i = 0; i < zpl_array_count(tooltips); ++i) {
|
||||||
tooltip *tp = (tooltips + i);
|
tooltip *tp = (tooltips + i);
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ void tooltip_clear(void);
|
||||||
void tooltip_show(const char* name, float xpos, float ypos) {
|
void tooltip_show(const char* name, float xpos, float ypos) {
|
||||||
if (!tooltips) return;
|
if (!tooltips) return;
|
||||||
|
|
||||||
tooltip *desc = tooltip__find_desc(name);
|
tooltip *desc = tooltip_find_desc(name);
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
|
|
||||||
tooltip_clear();
|
tooltip_clear();
|
||||||
|
@ -120,16 +121,22 @@ void tooltip_clear(void) {
|
||||||
main_tooltip = (tooltip_node) {0};
|
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) {
|
void tooltip__draw_node(tooltip_node *node) {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
tooltip *desc = node->desc;
|
tooltip *desc = node->desc;
|
||||||
Vector2 mpos = GetMousePosition();
|
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_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_DYNAMIC | NK_WINDOW_TITLE | NK_WINDOW_MOVABLE)) {
|
||||||
nk_layout_row_dynamic(game_ui, 30, 1);
|
tooltip_draw_contents(desc);
|
||||||
nk_label_wrap(game_ui, desc->content);
|
|
||||||
|
|
||||||
if (desc->links) {
|
if (desc->links) {
|
||||||
nk_label(game_ui, "See Also:", NK_TEXT_LEFT);
|
nk_label(game_ui, "See Also:", NK_TEXT_LEFT);
|
||||||
|
@ -143,7 +150,7 @@ void tooltip__draw_node(tooltip_node *node) {
|
||||||
*node->next = (tooltip_node) {
|
*node->next = (tooltip_node) {
|
||||||
.xpos = mpos.x+15,
|
.xpos = mpos.x+15,
|
||||||
.ypos = mpos.y+15,
|
.ypos = mpos.y+15,
|
||||||
.desc = tooltip__find_desc(desc->links[i]),
|
.desc = tooltip_find_desc(desc->links[i]),
|
||||||
.next = 0
|
.next = 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -152,11 +159,18 @@ void tooltip__draw_node(tooltip_node *node) {
|
||||||
|
|
||||||
// suggest closing tooltip
|
// suggest closing tooltip
|
||||||
struct nk_vec2 wpos = nk_window_get_position(game_ui);
|
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) {
|
if (Vector2Distance(mpos, tp_pos) <= TOOLTIP_MOUSE_DIST) {
|
||||||
tooltip__should_stay_open = true;
|
tooltip__should_stay_open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
{
|
||||||
|
DrawCircleV(tp_pos, TOOLTIP_MOUSE_DIST, BLUE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
nk_end(game_ui);
|
nk_end(game_ui);
|
||||||
|
|
||||||
// draw nested tooltip
|
// draw nested tooltip
|
||||||
|
|
|
@ -71,7 +71,7 @@ void platform_create_window(const char *title) {
|
||||||
InitWindow(screenWidth, screenHeight, title);
|
InitWindow(screenWidth, screenHeight, title);
|
||||||
uint32_t flags = /*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT;
|
uint32_t flags = /*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT;
|
||||||
#if !defined(PLATFORM_WEB)
|
#if !defined(PLATFORM_WEB)
|
||||||
//flags |= FLAG_VSYNC_HINT;
|
// flags |= FLAG_VSYNC_HINT;
|
||||||
#endif
|
#endif
|
||||||
SetWindowState(flags);
|
SetWindowState(flags);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue