add device progress bar

isolation
Dominik Madarász 2022-09-29 18:06:08 +02:00
parent ed5fd927ab
commit 24e30dd90a
8 changed files with 66 additions and 41 deletions

View File

@ -148,6 +148,10 @@ typedef struct {
typedef struct {
uint16_t asset;
// progress bar
uint8_t progress_active;
float progress_value;
} Device;
typedef struct {

View File

@ -19,7 +19,7 @@ void ProduceItems(ecs_iter_t *it) {
continue;
}
// if (producer[i].burn_time <= 0.0f) continue; TODO
// if (producer[i].energy_level <= 0.0f) continue;
if (producer[i].process_time < game_time()) {
if (producer[i].processed_item > 0) {
uint64_t e = item_spawn(producer[i].processed_item, 1);
@ -41,6 +41,9 @@ void ProduceItems(ecs_iter_t *it) {
}
}
}
d[i].progress_active = (producer[i].processed_item > 0);
d[i].progress_value = 1.0f-((producer[i].process_time - game_time()) / game_rules.furnace_cook_time);
}
}

View File

@ -32,8 +32,10 @@ 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_KEEP_IF(entity_view, kind, EKIND_DEVICE, 3) },
{ PKT_UINT(entity_view, asset) },
{ PKT_UINT(entity_view, progress_active) },
{ PKT_HALF(entity_view, progress_value) },
{ PKT_KEEP_IF(entity_view, has_items, true, 3) },
{ PKT_UINT(entity_view, has_items) },

View File

@ -63,6 +63,10 @@ typedef struct entity_view {
asset_id asset;
uint32_t quantity;
// NOTE(zaklaus): device progress bar
uint32_t progress_active;
float progress_value;
// NOTE(zaklaus): inventory
uint8_t has_items;
Item items[ITEMS_INVENTORY_SIZE];

View File

@ -68,6 +68,8 @@ entity_view *world_build_entity_view(int64_t e) {
if (ecs_get(world_ecs(), e, Device)) {
Device const* dev = ecs_get(world_ecs(), e, Device);
view.asset = dev->asset;
view.progress_active = dev->progress_active;
view.progress_value = dev->progress_value;
}
view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false;

View File

@ -132,6 +132,16 @@ void DEBUG_draw_entities_low(uint64_t key, entity_view * data) {
float x = data->x - 32.f;
float y = data->y - 32.f;
DrawTexturePro(GetSpriteTexture2D(assets_find(data->asset)), ASSET_SRC_RECT(), ASSET_DST_RECT(x,y), (Vector2){0.5f,0.5f}, 0.0f, ALPHA(WHITE));
if (data->progress_active) {
float w = 64.f;
float h = 8.f;
float p = data->progress_value;
float x = data->x - w/2.f;
float y = data->y - 32.f - h;
DrawRectangleEco(x, y, w, h, ColorAlpha(BLACK, data->tran_time));
DrawRectangleEco(x, y, w*p, h, ColorAlpha(GREEN, data->tran_time));
}
}break;
default:break;
}