From 81cf0bf10f0d3f600633409841dd1e73f72da486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Sun, 16 May 2021 12:56:36 +0200 Subject: [PATCH] fix dropdown for locked ops --- art/demo.ecotex | Bin 155 -> 146 bytes art/test.ecotex | Bin 67 -> 69 bytes code/game/source/editors/texed_prj.c | 5 ++++- code/game/source/editors/texed_widgets.c | 21 +++++++++++++++++++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/art/demo.ecotex b/art/demo.ecotex index 3eeb349f08e96f5510c0602677b78358bf8ac702..683a36b0b9682ac8829377c6ffc75e5aabd55fb8 100644 GIT binary patch literal 146 zcmZQ(Ipxs6z%Z5J@S(|z%uIl2MH&<^9Xd31p}|4}sIUPTq@^)}giRKjEHX6%q7^V< zmcxgpZ75F6EyzhN)-OpdF3~HCn`L1`7?KqK3{UW|q!wZj3-tlZ7UW zOwE93g#j3(rLi8Gx;i5@CnsN_JijO>Ws#x5A`{bv7AuU5jex+-jpfj^4aJGM1v#n3 p`X#BwC3*#U>5B}^76J`10-_aeMnGub=Eint@?s-XGZ0>A004suHo^b^ diff --git a/art/test.ecotex b/art/test.ecotex index 346ae0094823019493cd874d152923b7ae0028c4..14753c6189df9a48c7ecffe35dd3058e665c108b 100644 GIT binary patch delta 37 mcmZ>Em1kx=<DmSti*<yCd#V;0Ktn3JOBUy diff --git a/code/game/source/editors/texed_prj.c b/code/game/source/editors/texed_prj.c index 4cc5e07..fd83ff4 100644 --- a/code/game/source/editors/texed_prj.c +++ b/code/game/source/editors/texed_prj.c @@ -1,7 +1,7 @@ //~ NOTE(zaklaus): DATA SERIALISATION -#define ECOTEX_VERSION 2 +#define ECOTEX_VERSION 3 #define UNPACK(kind) cw_unpack_next(&uc); assert(uc.item.type == kind); @@ -34,6 +34,8 @@ void texed_load(void) { texed_add_op(kind); td_op *op = zpl_array_end(ctx.ops); UNPACK(CWP_ITEM_BOOLEAN); + op->is_locked = uc.item.as.boolean; + UNPACK(CWP_ITEM_BOOLEAN); op->is_hidden = uc.item.as.boolean; UNPACK(CWP_ITEM_ARRAY); @@ -86,6 +88,7 @@ void texed_save(void) { for (int i = 0; i < zpl_array_count(ctx.ops); i += 1) { td_op *op = &ctx.ops[i]; cw_pack_unsigned(&pc, op->kind); + cw_pack_boolean(&pc, (bool)op->is_locked); cw_pack_boolean(&pc, (bool)op->is_hidden); cw_pack_array_size(&pc, op->num_params); for (int j = 0; j < op->num_params; j += 1) { diff --git a/code/game/source/editors/texed_widgets.c b/code/game/source/editors/texed_widgets.c index 802b8f7..883b7cf 100644 --- a/code/game/source/editors/texed_widgets.c +++ b/code/game/source/editors/texed_widgets.c @@ -74,7 +74,7 @@ void texed_draw_topbar(zpl_aabb2 r) { } static bool is_add_op_dropbox_open = false; -static int add_op_dropbox_selected = 1; +static int add_op_dropbox_selected = 0; static char add_op_list[2000] = {0}; void texed_draw_oplist_pane(zpl_aabb2 r) { @@ -145,6 +145,7 @@ void texed_draw_oplist_pane(zpl_aabb2 r) { zpl_aabb2 hidden_r = zpl_aabb2_cut_right(&op_item_r, 60.0f); + if (!default_ops[ctx.ops[i].kind].is_locked) GuiSetState(GUI_STATE_NORMAL); if (GuiButton(aabb2_ray(hidden_r), ctx.ops[i].is_hidden ? "SHOW" : "HIDE")) { ctx.ops[i].is_hidden = !ctx.ops[i].is_hidden; texed_repaint_preview(); @@ -159,6 +160,14 @@ void texed_draw_oplist_pane(zpl_aabb2 r) { } GuiSetState(GUI_STATE_NORMAL); + zpl_aabb2 lock_r = zpl_aabb2_cut_right(&op_item_r, 20.0f); + + if (default_ops[ctx.ops[i].kind].is_locked) GuiSetState(GUI_STATE_DISABLED); + if (GuiButton(aabb2_ray(lock_r), ctx.ops[i].is_locked ? "#138#" : "#137#")) { + ctx.ops[i].is_locked = !ctx.ops[i].is_locked; + } + GuiSetState(GUI_STATE_NORMAL); + GuiDrawText(zpl_bprintf("%s %s", ctx.ops[i].name, ctx.ops[i].is_locked ? "(locked)" : ""), GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha)); } @@ -167,7 +176,15 @@ void texed_draw_oplist_pane(zpl_aabb2 r) { if (is_add_op_dropbox_open && (op_dropdown_state = GuiDropdownBoxEco(aabb2_ray(add_op_r), add_op_list, "ADD OPERATION", &add_op_dropbox_selected, true)) > 0) { is_add_op_dropbox_open = false; if (op_dropdown_state < 2) { - texed_add_op(add_op_dropbox_selected); + int idx = 0; + for (int i = 0; i < DEF_OPS_LEN; i += 1) { + if (!default_ops[i].is_locked && idx == add_op_dropbox_selected) { + idx = i; + break; + } + else if (!default_ops[i].is_locked) idx += 1; + } + texed_add_op(idx); } } }