From ca2ded95540487180e41348b10893b7ef442533b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Tue, 9 Aug 2022 17:32:58 +0200 Subject: [PATCH] inv: render held items on top --- art/gen/chest.png | Bin 0 -> 2936 bytes code/game/src/entity_view.c | 3 +++ code/game/src/gen/texgen.c | 3 +++ code/game/src/gui/inventory.c | 16 ++++++++++++---- code/game/src/storage.c | 3 +++ code/game/src/world/world.c | 5 +++++ code/modules/modules/components.c | 2 ++ code/modules/modules/components.h | 5 +++++ 8 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 art/gen/chest.png diff --git a/art/gen/chest.png b/art/gen/chest.png new file mode 100644 index 0000000000000000000000000000000000000000..89b99b654548e6ef1bd814484f0aa0c019f41504 GIT binary patch literal 2936 zcmcgu4Nw&48Q$YZM1cV!NC0)aOc^lj?d~1N-K`$-b0|zXM7R(n9c9_w;}-62kKF|h zv@HrXVl^hTMhX64Eh#9*CPhb^LNGBwA~b}G6^(#Vv=vckBqnV%-8+txWOQODo!-sv ze&4t6_df5>^Sb=ZN>iOv#Y=@V2I|L+DWihFypcV1pavLrxFw+77+RP>kkJ~hmLoY6l?aK%RIz)tG z4U}jH1aoznU^2_mpi+v#B#NS-QY}@JBpFN5F`x{U$q-bIV6iZU;j%a!Q-jVQB*Jl& z0ngH|bb^U94P+DqD~=%L<>k_Hxs>G!5lpRCBd83K$zV|e<|`}$VS_Dv#Eb?l&66Bs z6&Th6+BFgdY^k7uL{q1IFk4+}Exa>MV#E*|VMQ=0YWK+@NRci%Ybj@PfKwzwn`kp_ z5qMD+bIDqbtibX{_6e$8ufGK###X0uVLa9rv)Ki~3n^uy8_s|{R+`sWSZO4S=Gjt? zq*Ka7Gb3ia;e{;vQ9PewyD0A1Y{io~nhCSMCTbZQAi_JOCbchLW(D|CYBR{MeF1a zD|9+M&B6m0`!jy3^twxnfrOKdC%ITT? zT9z!eXW71gn(-7%iaH*ll7w7FC=@g-SH&4%xhz%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WjL1 U*|4_S{%xF=lA(PwDSz{S0HpmhrvLx| literal 0 HcmV?d00001 diff --git a/code/game/src/entity_view.c b/code/game/src/entity_view.c index 685bc0d..312b46e 100644 --- a/code/game/src/entity_view.c +++ b/code/game/src/entity_view.c @@ -31,6 +31,9 @@ pkt_desc pkt_entity_view_desc[] = { { PKT_UINT(entity_view, asset) }, { PKT_UINT(entity_view, quantity) }, + { PKT_KEEP_IF(entity_view, kind, EKIND_DEVICE, 1) }, + { PKT_UINT(entity_view, asset) }, + { PKT_KEEP_IF(entity_view, has_items, true, 3) }, { PKT_UINT(entity_view, has_items) }, { PKT_UINT(entity_view, selected_item) }, diff --git a/code/game/src/gen/texgen.c b/code/game/src/gen/texgen.c index 81e2994..be11a19 100644 --- a/code/game/src/gen/texgen.c +++ b/code/game/src/gen/texgen.c @@ -68,6 +68,9 @@ Texture2D texgen_build_sprite(asset_id id) { case ASSET_BELT_UP: return LoadTexEco("belt_up"); case ASSET_BELT_DOWN: return LoadTexEco("belt_down"); + // NOTE(zaklaus): devices + case ASSET_CHEST: return LoadTexEco("chest"); + default: return GenColorEco(PINK); break; } } diff --git a/code/game/src/gui/inventory.c b/code/game/src/gui/inventory.c index ca91b00..7d6423b 100644 --- a/code/game/src/gui/inventory.c +++ b/code/game/src/gui/inventory.c @@ -95,6 +95,15 @@ void inventory_draw_panel(entity_view *e, bool is_player, float sx, float sy){ } } + // NOTE(zaklaus): switch it off if is_player + if (is_player) + inv_is_storage_action = false; +} + +void inventory_render_held_item(bool is_player){ + inv_keystate *inv = (!is_player) ? &storage_inv : &player_inv; + inv_keystate *inv2 = (is_player) ? &storage_inv : &player_inv; + if (inv->item_is_held) { Vector2 mpos = GetMousePosition(); mpos.x -= 32; @@ -108,10 +117,6 @@ void inventory_draw_panel(entity_view *e, bool is_player, float sx, float sy){ inv_is_storage_action = true; } } - - // NOTE(zaklaus): switch it off if is_player - if (is_player) - inv_is_storage_action = false; } void inventory_reset_states(inv_keystate *ik) { @@ -140,4 +145,7 @@ void inventory_draw() { inventory_draw_panel(e, true, screenWidth/2.0f + 128, screenHeight/2.0f - 96); inventory_draw_panel(e, false, screenWidth/2.0f - 384, screenHeight/2.0f - 128); + + inventory_render_held_item(true); + inventory_render_held_item(false); } diff --git a/code/game/src/storage.c b/code/game/src/storage.c index a4e265e..c6b13d6 100644 --- a/code/game/src/storage.c +++ b/code/game/src/storage.c @@ -8,6 +8,9 @@ uint64_t storage_spawn(void) { ecs_entity_t e = entity_spawn(EKIND_DEVICE); + Device *dev = ecs_get_mut(world_ecs(), e, Device); + dev->asset = ASSET_CHEST; + ItemContainer *storage = ecs_get_mut(world_ecs(), e, ItemContainer); *storage = (ItemContainer){0}; return (uint64_t)e; diff --git a/code/game/src/world/world.c b/code/game/src/world/world.c index a879930..8329031 100644 --- a/code/game/src/world/world.c +++ b/code/game/src/world/world.c @@ -60,6 +60,11 @@ entity_view world_build_entity_view(int64_t e) { view.quantity = dr->quantity; } + if (ecs_get(world_ecs(), e, Device)) { + Device const* dev = ecs_get(world_ecs(), e, Device); + view.asset = dev->asset; + } + view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false; Inventory *inv = 0; diff --git a/code/modules/modules/components.c b/code/modules/modules/components.c index 0a9ec7c..609f25f 100644 --- a/code/modules/modules/components.c +++ b/code/modules/modules/components.c @@ -14,6 +14,7 @@ ECS_COMPONENT_DECLARE(IsInVehicle); ECS_COMPONENT_DECLARE(ItemDrop); ECS_COMPONENT_DECLARE(Inventory); ECS_COMPONENT_DECLARE(ItemContainer); +ECS_COMPONENT_DECLARE(Device); ECS_COMPONENT_DECLARE(DemoNPC); ECS_COMPONENT_DECLARE(StreamInfo); @@ -34,6 +35,7 @@ void ComponentsImport(ecs_world_t *ecs) { ECS_COMPONENT_DEFINE(ecs, ItemDrop); ECS_COMPONENT_DEFINE(ecs, Inventory); ECS_COMPONENT_DEFINE(ecs, ItemContainer); + ECS_COMPONENT_DEFINE(ecs, Device); ECS_COMPONENT_DEFINE(ecs, DemoNPC); ECS_COMPONENT_DEFINE(ecs, StreamInfo); } diff --git a/code/modules/modules/components.h b/code/modules/modules/components.h index a60e4fa..4659d5a 100644 --- a/code/modules/modules/components.h +++ b/code/modules/modules/components.h @@ -110,6 +110,10 @@ typedef struct { ItemDrop items[ITEMS_CONTAINER_SIZE]; } ItemContainer; +typedef struct { + uint16_t asset; +} Device; + typedef struct { double last_update; double tick_delay; @@ -131,6 +135,7 @@ extern ECS_COMPONENT_DECLARE(IsInVehicle); extern ECS_COMPONENT_DECLARE(ItemDrop); extern ECS_COMPONENT_DECLARE(Inventory); extern ECS_COMPONENT_DECLARE(ItemContainer); +extern ECS_COMPONENT_DECLARE(Device); extern ECS_COMPONENT_DECLARE(DemoNPC); extern ECS_COMPONENT_DECLARE(StreamInfo);