diff --git a/src/luaapi.c b/src/luaapi.c index cdb470d..e8b3de9 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -2182,11 +2182,13 @@ static int dagame_k3menuitem_get(lua_State *L) { static int dagame_k3menuitem_set(lua_State *L) { struct menuitem *item = lua_touserdata(L, 1); - if(!strcmp(lua_tostring(L, 2), "invisible")) { + const char *key = lua_tostring(L, 2); + + if(!strcmp(key, "invisible")) { item->ptr->invisible = lua_toboolean(L, 3); - } else if(!strcmp(lua_tostring(L, 2), "disabled")) { + } else if(!strcmp(key, "disabled")) { item->ptr->disabled = lua_toboolean(L, 3); - } else if(!strcmp(lua_tostring(L, 2), "text")) { + } else if(!strcmp(key, "text")) { char **txt = NULL; if(item->type == MENUITEM_LABEL) { @@ -2206,6 +2208,78 @@ static int dagame_k3menuitem_set(lua_State *L) { *txt = strdup(new ? new : "nil"); } + } else if(strstr(key, "prop_") == key) { + const char *propname = key + 5; + + enum CommonType { + NONE, COL4, INT4 + } typ; + + struct k3MProperty prop; + + if(!strcmp(propname, "bg_color")) { + prop.type = k3M_PROP_BG_COLOR; + typ = COL4; + } else if(!strcmp(propname, "border_radius")) { + prop.type = k3M_PROP_BORDER_RADIUS; + typ = INT4; + } else if(!strcmp(propname, "margin")) { + prop.type = k3M_PROP_MARGIN; + typ = INT4; + } else if(!strcmp(propname, "horizontal_alignment")) { + prop.type = k3M_PROP_HORIZONTAL_ALIGNMENT; + if(!strcmp(lua_tostring(L, 3), "left")) { + prop.si[0] = k3M_ALIGN_LEFT; + } else if(!strcmp(lua_tostring(L, 3), "right")) { + prop.si[0] = k3M_ALIGN_RIGHT; + } else { + prop.si[0] = k3M_ALIGN_CENTER; + } + } + + if(typ == COL4) { + if(lua_type(L, 3) == LUA_TTABLE) { + lua_geti(L, 3, 4); + if(lua_type(L, -1) == LUA_TNIL) { + prop.si[3] = 255; + } + lua_pop(L, 1); + + lua_geti(L, 3, 1); + lua_geti(L, 3, 2); + lua_geti(L, 3, 3); + prop.si[0] = lua_tonumber(L, -3) * 255; + prop.si[1] = lua_tonumber(L, -2) * 255; + prop.si[2] = lua_tonumber(L, -1) * 255; + + lua_pop(L, 3); + } else if(lua_isnumber(L, 3)) { + prop.si[0] = lua_tonumber(L, 3); + prop.si[1] = lua_tonumber(L, 3); + prop.si[2] = lua_tonumber(L, 3); + prop.si[3] = 255; + } + } else if(typ == INT4) { + if(lua_type(L, 3) == LUA_TTABLE) { + lua_geti(L, 3, 1); + lua_geti(L, 3, 2); + lua_geti(L, 3, 3); + lua_geti(L, 3, 4); + prop.si[0] = lua_tonumber(L, -4) * 255; + prop.si[1] = lua_tonumber(L, -3) * 255; + prop.si[2] = lua_tonumber(L, -2) * 255; + prop.si[3] = lua_tonumber(L, -1) * 255; + + lua_pop(L, 4); + } else if(lua_isnumber(L, 3)) { + prop.si[0] = lua_tonumber(L, 3); + prop.si[1] = lua_tonumber(L, 3); + prop.si[2] = lua_tonumber(L, 3); + prop.si[3] = lua_tonumber(L, 4); + } + } + + k3MOverrideProperty(item->ptr, prop); } return 0;