From 2527a40231fa0c861f5b6cf11215a462ac64eb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sun, 16 Oct 2022 11:09:51 +0200 Subject: [PATCH] build mode ui improvements --- code/foundation/src/gui/build_mode.c | 13 +++++++++---- code/foundation/src/models/items.c | 2 -- code/foundation/src/systems/modules/system_items.c | 8 +++++--- code/foundation/src/utils/raylib_helpers.h | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/code/foundation/src/gui/build_mode.c b/code/foundation/src/gui/build_mode.c index dd3f960..4b53320 100644 --- a/code/foundation/src/gui/build_mode.c +++ b/code/foundation/src/gui/build_mode.c @@ -47,7 +47,7 @@ void buildmode_draw(void) { Item *item = &e->items[e->selected_item]; - if (e->has_items && !e->inside_vehicle && item->quantity > 0 && (!is_outside_range || build_is_deletion_mode)) { + if (e->has_items && !e->inside_vehicle && (build_is_deletion_mode || (item->quantity > 0 && !is_outside_range))) { item_usage usage = 0; uint16_t item_id = 0; if (!build_is_deletion_mode){ @@ -71,6 +71,7 @@ void buildmode_draw(void) { world_block_lookup l = world_block_from_realpos((float)cam.x, (float)cam.y); if (build_is_deletion_mode && !l.is_outer){ + renderer_draw_single((float)cam.x, (float)cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(RED, 0.4f)); goto build_skip_placements; } @@ -104,8 +105,12 @@ void buildmode_draw(void) { } - if (!is_outside_range) - renderer_draw_single((float)cam.x, (float)cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : WHITE, 0.2f)); + if (!is_outside_range) { + if (build_is_deletion_mode) + renderer_draw_single((float)cam.x, (float)cam.y, ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(RED, 0.2f)); + else + renderer_draw_single((float)cam.x, (float)cam.y, item->kind, ColorAlpha(WHITE, 0.2f)); + } build_skip_placements: build_num_placements = zpl_min(build_num_placements, qty); @@ -114,7 +119,7 @@ void buildmode_draw(void) { for (size_t i = 0; i < build_num_placements; i++) { item_placement *it = &build_placements[i]; - renderer_draw_single(it->x, it->y, !build_is_deletion_mode ? item->kind : ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : WHITE, 0.4f)); + renderer_draw_single(it->x, it->y, !build_is_deletion_mode ? item->kind : ASSET_BUILDMODE_HIGHLIGHT, ColorAlpha(build_is_deletion_mode ? RED : RAYWHITE, 0.6f)); } if (build_is_in_draw_mode) { diff --git a/code/foundation/src/models/items.c b/code/foundation/src/models/items.c index 9e102b7..8b9e649 100644 --- a/code/foundation/src/models/items.c +++ b/code/foundation/src/models/items.c @@ -79,8 +79,6 @@ item_id item_find(asset_id kind) { Item *item_get_data(uint64_t ent) { if (!world_entity_valid(ent)) return NULL; - // if (ecs_get(world_ecs(), ent, ItemAlreadyEdited)) return NULL; - // ecs_add(world_ecs(), ent, ItemAlreadyEdited); return ecs_get_mut_if_ex(world_ecs(), ent, Item); } diff --git a/code/foundation/src/systems/modules/system_items.c b/code/foundation/src/systems/modules/system_items.c index 217a3cb..e13bfb6 100644 --- a/code/foundation/src/systems/modules/system_items.c +++ b/code/foundation/src/systems/modules/system_items.c @@ -267,12 +267,14 @@ void UseItem(ecs_iter_t *it) { continue; } - ecs_entity_t item_ent = inv[i].items[in[i].selected_item]; - Item *item = item_get_data(item_ent); + ecs_entity_t item_ent = 0; + Item *item = NULL; uint16_t item_id = 0; item_usage usage = UKIND_DELETE; if (!in[i].deletion_mode){ + item_ent = inv[i].items[in[i].selected_item]; + item = item_get_data(item_ent); item_id = item ? item_find(item->kind) : ASSET_EMPTY; usage = item_get_usage(item_id); if (!item || item->quantity <= 0) continue; @@ -313,7 +315,7 @@ void UseItem(ecs_iter_t *it) { entity_wake(it->entities[i]); - if (item->quantity == 0) { + if (usage != UKIND_DELETE && item->quantity == 0) { item_despawn(item_ent); inv[i].items[in[i].selected_item] = 0; } diff --git a/code/foundation/src/utils/raylib_helpers.h b/code/foundation/src/utils/raylib_helpers.h index 7486443..c41a85e 100644 --- a/code/foundation/src/utils/raylib_helpers.h +++ b/code/foundation/src/utils/raylib_helpers.h @@ -43,7 +43,7 @@ Texture2D Image2TexEco(Image image) { static inline Texture2D GenColorEco(Color color) { - Image img = GenImageColor(1, 1, color); + Image img = GenImageColor(64, 64, color); return Image2TexEco(img); }