inv: render held items on top

isolation_bkp/dynres
Dominik Madarász 2022-08-09 17:32:58 +02:00
parent a2810b2a18
commit ca2ded9554
8 changed files with 33 additions and 4 deletions

BIN
art/gen/chest.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -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) },

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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);