Basic property editor

This commit is contained in:
2024-01-05 08:36:05 +01:00
parent 852dc43556
commit dbc0ce5981
5 changed files with 73 additions and 31 deletions

View File

@@ -77,3 +77,38 @@ void initComponentIDs(ecs_world_t *ecs) {
ECS_TAG_DEFINE(ecs, Attackable);
}
#include <rlImGui.h>
void igTagCheckbox(const char *label, ecs_world_t *ecs,
ecs_entity_t entity, ecs_entity_t tag) {
bool hasTag = ecs_has_id(ecs, entity, tag);
igCheckbox(label, &hasTag);
if (hasTag)
ecs_add_id(ecs, entity, tag);
else
ecs_remove_id(ecs, entity, tag);
}
void igResource(const char *label, ecs_world_t *ecs,
ecs_entity_t entity, ecs_entity_t comp) {
if (!ecs_has_id(ecs, entity, comp)) return;
igSeparatorText(label);
Resource *res = ecs_get_mut_id(ecs, entity, comp);
const char *resStrings[RES_COUNT];
for (i32 i = 0; i < RES_COUNT; i++) {
resStrings[i] = getResourceTypePrettyName(i);
}
int curType = res->type;
igCombo_Str_arr("Type", &curType, resStrings, RES_COUNT, -1);
res->type = curType;
igInputInt("Amount", &res->amount, 1, 10, 0);
}
void igVec2(const char *label, ecs_world_t *ecs,
ecs_entity_t entity, ecs_entity_t comp) {
if (!ecs_has_id(ecs, entity, comp)) return;
igSeparatorText(label);
Vector2 *vec = ecs_get_mut_id(ecs, entity, comp);
igPushID_Str(label);
igInputFloat("X", &vec->x, 1.0f, 10.0f, "%.2f", 0);
igInputFloat("Y", &vec->y, 1.0f, 10.0f, "%.2f", 0);
igPopID();
}