diff --git a/code/foundation/src/core/game.c b/code/foundation/src/core/game.c index bfd4967..3800b3b 100644 --- a/code/foundation/src/core/game.c +++ b/code/foundation/src/core/game.c @@ -22,12 +22,19 @@ #include "packets/pkt_01_welcome.h" #include "packets/pkt_switch_viewer.h" +#define RAYLIB_NUKLEAR_IMPLEMENTATION +ZPL_DIAGNOSTIC_PUSH_WARNLEVEL(0) +#include "raylib-nuklear.h" +ZPL_DIAGNOSTIC_POP + static uint8_t game_mode; static uint8_t game_should_close; static world_view *world_viewers; static world_view *active_viewer; +static struct nk_context *game_ui = 0; + static WORLD_PKT_READER(pkt_reader) { pkt_header header = {0}; uint32_t ok = pkt_header_decode(&header, data, datalen); @@ -148,6 +155,8 @@ void game_init(const char *ip, uint16_t port, game_kind play_mode, uint32_t num_ world_viewers_init(num_viewers); active_viewer = &world_viewers[0]; camera_reset(); + + game_ui = InitNuklear(12); } if (game_mode != GAMEKIND_SINGLE) { @@ -201,7 +210,9 @@ void game_shutdown() { // TODO(zaklaus): crashes on exit //platform_shutdown(); - } + UnloadNuklear(game_ui); + } + } uint8_t game_is_running() { @@ -219,6 +230,7 @@ game_kind game_get_kind(void) { void game_input() { if (game_mode != GAMEKIND_HEADLESS) { platform_input(); + UpdateNuklear(game_ui); } } @@ -247,6 +259,7 @@ void game_update() { void game_render() { if (game_mode != GAMEKIND_HEADLESS) { platform_render(); + DrawNuklear(game_ui); } } diff --git a/code/foundation/src/dev/debug_ui.c b/code/foundation/src/dev/debug_ui.c index 89e2a4b..3546367 100644 --- a/code/foundation/src/dev/debug_ui.c +++ b/code/foundation/src/dev/debug_ui.c @@ -9,8 +9,6 @@ #include "models/components.h" -#define RAYLIB_NUKLEAR_IMPLEMENTATION -#define NK_INCLUDE_STANDARD_VARARGS ZPL_DIAGNOSTIC_PUSH_WARNLEVEL(0) #include "raylib-nuklear.h" ZPL_DIAGNOSTIC_POP @@ -50,7 +48,7 @@ static uint8_t is_handle_ctrl_held; static float debug_xpos = DBG_START_XPOS; static float debug_ypos = DBG_START_YPOS; static zpl_u16 sel_item_id = 0; -static struct nk_context *nk_ctx = 0; +static struct nk_context *dev_ui = 0; typedef enum { L_NONE = 0, @@ -414,10 +412,10 @@ void debug_draw(void) { ActSpawnItemNext(); // Initialize Nuklear ctx - nk_ctx = InitNuklear(10); + dev_ui = InitNuklear(10); } - UpdateNuklear(nk_ctx); + UpdateNuklear(dev_ui); float xpos = debug_xpos; float ypos = debug_ypos; @@ -464,7 +462,7 @@ void debug_draw(void) { debug_draw_list(items, xpos, ypos, 0); } - DrawNuklear(nk_ctx); + DrawNuklear(dev_ui); } debug_area_status check_mouse_area(float xpos, float ypos, float w, float h) { diff --git a/code/foundation/src/dev/debug_ui_tools.c b/code/foundation/src/dev/debug_ui_tools.c index 0de3d7a..a631070 100644 --- a/code/foundation/src/dev/debug_ui_tools.c +++ b/code/foundation/src/dev/debug_ui_tools.c @@ -4,43 +4,43 @@ #include "models/items.h" void ToolAssetInspector(void) { - if (nk_begin(nk_ctx, "Asset Inspector", nk_rect(400, 100, 240, 800), + if (nk_begin(dev_ui, "Asset Inspector", nk_rect(400, 100, 240, 800), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_TITLE)) { for (int i = 0; i < MAX_ASSETS; i++) { uint16_t idx = assets_find(i); - if (idx != ASSET_INVALID && nk_tree_push_id(nk_ctx, NK_TREE_TAB, asset_names[i], NK_MINIMIZED, i)) { + if (idx != ASSET_INVALID && nk_tree_push_id(dev_ui, NK_TREE_TAB, asset_names[i], NK_MINIMIZED, i)) { { // draw kind const char *asset_kind_name = assets_get_kind_name(idx); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "kind: %s", asset_kind_name); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "spawnable entity: %s", entity_spawn_provided(i) ? "true" : "false"); + nk_labelf(dev_ui, NK_TEXT_LEFT, "kind: %s", asset_kind_name); + nk_labelf(dev_ui, NK_TEXT_LEFT, "spawnable entity: %s", entity_spawn_provided(i) ? "true" : "false"); // draw block block_id blk_id = blocks_find(i); if (blk_id != 0xF) { - if (nk_tree_push_id(nk_ctx, NK_TREE_NODE, "block", NK_MINIMIZED, i)) { + if (nk_tree_push_id(dev_ui, NK_TREE_NODE, "block", NK_MINIMIZED, i)) { { - nk_labelf(nk_ctx, NK_TEXT_LEFT, "symbol: %s", zpl_bprintf("%c", blocks_get_symbol(blk_id))); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "flags: %u", blocks_get_flags(blk_id)); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "drag: %f", blocks_get_drag(blk_id)); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "friction: %f", blocks_get_friction(blk_id)); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "bounce: %f", blocks_get_bounce(blk_id)); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "velx: %f", blocks_get_velx(blk_id)); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "vely: %f", blocks_get_vely(blk_id)); + nk_labelf(dev_ui, NK_TEXT_LEFT, "symbol: %s", zpl_bprintf("%c", blocks_get_symbol(blk_id))); + nk_labelf(dev_ui, NK_TEXT_LEFT, "flags: %u", blocks_get_flags(blk_id)); + nk_labelf(dev_ui, NK_TEXT_LEFT, "drag: %f", blocks_get_drag(blk_id)); + nk_labelf(dev_ui, NK_TEXT_LEFT, "friction: %f", blocks_get_friction(blk_id)); + nk_labelf(dev_ui, NK_TEXT_LEFT, "bounce: %f", blocks_get_bounce(blk_id)); + nk_labelf(dev_ui, NK_TEXT_LEFT, "velx: %f", blocks_get_velx(blk_id)); + nk_labelf(dev_ui, NK_TEXT_LEFT, "vely: %f", blocks_get_vely(blk_id)); } - nk_tree_pop(nk_ctx); + nk_tree_pop(dev_ui); } } // draw item item_id it_id = item_find_no_proxy(i); if (it_id != ASSET_INVALID) { - if (nk_tree_push_id(nk_ctx, NK_TREE_NODE, "item", NK_MINIMIZED, i)) { + if (nk_tree_push_id(dev_ui, NK_TREE_NODE, "item", NK_MINIMIZED, i)) { { item_desc it = item_get_desc(it_id); - if (nk_button_label(nk_ctx, "spawn")) { + if (nk_button_label(dev_ui, "spawn")) { ecs_entity_t e = item_spawn(i, it.max_quantity); ecs_entity_t plr = camera_get().ent_id; @@ -48,27 +48,27 @@ void ToolAssetInspector(void) { entity_set_position(e, origin->x, origin->y); } - nk_labelf(nk_ctx, NK_TEXT_LEFT, "usage: %d", it.usage); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "attachment: %d", it.attachment); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "max quantity: %d", it.max_quantity); - nk_labelf(nk_ctx, NK_TEXT_LEFT, "has storage: %s", it.has_storage ? "true" : "false"); + nk_labelf(dev_ui, NK_TEXT_LEFT, "usage: %d", it.usage); + nk_labelf(dev_ui, NK_TEXT_LEFT, "attachment: %d", it.attachment); + nk_labelf(dev_ui, NK_TEXT_LEFT, "max quantity: %d", it.max_quantity); + nk_labelf(dev_ui, NK_TEXT_LEFT, "has storage: %s", it.has_storage ? "true" : "false"); // todo: draw item-specific data } - nk_tree_pop(nk_ctx); + nk_tree_pop(dev_ui); } } } - nk_tree_pop(nk_ctx); + nk_tree_pop(dev_ui); } } - nk_end(nk_ctx); + nk_end(dev_ui); } } void ToolEntityInspector(void) { - if (nk_begin(nk_ctx, "Entity Inspector", nk_rect(660, 100, 240, 800), + if (nk_begin(dev_ui, "Entity Inspector", nk_rect(660, 100, 240, 800), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_TITLE)) { static ecs_query_t *q = 0; @@ -87,31 +87,31 @@ void ToolEntityInspector(void) { const Classify *c = ecs_field(&it, Classify, 2); for (int i = 0; i < it.count; i++) { - if (nk_tree_push_id(nk_ctx, NK_TREE_NODE, zpl_bprintf("%lld [%s]", it.entities[i], class_names[c[i].id]), NK_MINIMIZED, (int)it.entities[i])) { + if (nk_tree_push_id(dev_ui, NK_TREE_NODE, zpl_bprintf("%lld [%s]", it.entities[i], class_names[c[i].id]), NK_MINIMIZED, (int)it.entities[i])) { { - nk_label(nk_ctx, "position:", NK_TEXT_LEFT); - nk_property_float(nk_ctx, "#x:", ZPL_F32_MIN, &p[i].x, ZPL_F32_MAX, 0.1f, 0.2f); - nk_property_float(nk_ctx, "#y:", ZPL_F32_MIN, &p[i].y, ZPL_F32_MAX, 0.1f, 0.2f); + nk_label(dev_ui, "position:", NK_TEXT_LEFT); + nk_property_float(dev_ui, "#x:", ZPL_F32_MIN, &p[i].x, ZPL_F32_MAX, 0.1f, 0.2f); + nk_property_float(dev_ui, "#y:", ZPL_F32_MIN, &p[i].y, ZPL_F32_MAX, 0.1f, 0.2f); - if (nk_button_label(nk_ctx, "teleport to")) { + if (nk_button_label(dev_ui, "teleport to")) { ecs_entity_t plr = camera_get().ent_id; Position const* origin = ecs_get(world_ecs(), it.entities[i], Position); entity_set_position(plr, origin->x, origin->y); } - if (nk_button_label(nk_ctx, "teleport here")) { + if (nk_button_label(dev_ui, "teleport here")) { ecs_entity_t plr = camera_get().ent_id; Position const* origin = ecs_get(world_ecs(), plr, Position); entity_set_position(it.entities[i], origin->x, origin->y); } } - nk_tree_pop(nk_ctx); + nk_tree_pop(dev_ui); } } } - nk_end(nk_ctx); + nk_end(dev_ui); } } \ No newline at end of file diff --git a/code/foundation/src/gui/inventory.c b/code/foundation/src/gui/inventory.c index 0c54360..8f82fd2 100644 --- a/code/foundation/src/gui/inventory.c +++ b/code/foundation/src/gui/inventory.c @@ -105,9 +105,6 @@ bool inventory_draw_crafting_list(entity_view *e, float xpos, float ypos) { float start_xpos = xpos; float start_ypos = ypos; - if (!e->sel_ent) - return DAREA_OUTSIDE; - for (uint16_t i = 0; e->craftables[i]; ++i) { asset_id id = e->craftables[i]; inventory_draw_crafting_btn(start_xpos+1, ypos+1, asset_names[id], id, BLACK); diff --git a/code/foundation/src/platform/arch.h b/code/foundation/src/platform/arch.h index 184de4c..71e0177 100644 --- a/code/foundation/src/platform/arch.h +++ b/code/foundation/src/platform/arch.h @@ -35,6 +35,8 @@ static bool request_shutdown; static float temp_time = 0.0f; +extern struct nk_context *game_ui; + float get_cached_time(void) { return temp_time; }