diff --git a/art/gen/chest.png b/art/gen/chest.png new file mode 100644 index 0000000..89b99b6 Binary files /dev/null and b/art/gen/chest.png differ 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);