Compare commits
2 Commits
v1
...
96da001734
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96da001734 | ||
|
|
943601bc3a |
92
src/luaapi.c
92
src/luaapi.c
@@ -1332,6 +1332,7 @@ static int game_camfocus(lua_State *L) {
|
|||||||
#define MENUITEM_LABEL 1
|
#define MENUITEM_LABEL 1
|
||||||
#define MENUITEM_TEXTBUTTON 2
|
#define MENUITEM_TEXTBUTTON 2
|
||||||
#define MENUITEM_TEXTINPUT 3
|
#define MENUITEM_TEXTINPUT 3
|
||||||
|
#define MENUITEM_OBJ 4
|
||||||
struct menuitem {
|
struct menuitem {
|
||||||
int type;
|
int type;
|
||||||
struct k3MObj *ptr;
|
struct k3MObj *ptr;
|
||||||
@@ -2021,6 +2022,14 @@ static int dagame_send(lua_State *L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int dagame_ui_obj(lua_State *L) {
|
||||||
|
struct menuitem *item = lua_newuserdata(L, sizeof(*item));
|
||||||
|
item->type = MENUITEM_OBJ;
|
||||||
|
item->ptr = (void*) k3MObj();
|
||||||
|
luaL_setmetatable(L, "k3menuitem");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int dagame_ui_screen(lua_State *L) {
|
static int dagame_ui_screen(lua_State *L) {
|
||||||
struct menuitem *item = lua_newuserdata(L, sizeof(*item));
|
struct menuitem *item = lua_newuserdata(L, sizeof(*item));
|
||||||
item->type = MENUITEM_SCREEN;
|
item->type = MENUITEM_SCREEN;
|
||||||
@@ -2182,11 +2191,13 @@ static int dagame_k3menuitem_get(lua_State *L) {
|
|||||||
static int dagame_k3menuitem_set(lua_State *L) {
|
static int dagame_k3menuitem_set(lua_State *L) {
|
||||||
struct menuitem *item = lua_touserdata(L, 1);
|
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);
|
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);
|
item->ptr->disabled = lua_toboolean(L, 3);
|
||||||
} else if(!strcmp(lua_tostring(L, 2), "text")) {
|
} else if(!strcmp(key, "text")) {
|
||||||
char **txt = NULL;
|
char **txt = NULL;
|
||||||
|
|
||||||
if(item->type == MENUITEM_LABEL) {
|
if(item->type == MENUITEM_LABEL) {
|
||||||
@@ -2206,6 +2217,78 @@ static int dagame_k3menuitem_set(lua_State *L) {
|
|||||||
|
|
||||||
*txt = strdup(new ? new : "nil");
|
*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;
|
return 0;
|
||||||
@@ -2849,6 +2932,9 @@ void luaapi_init() {
|
|||||||
|
|
||||||
k3Log(k3_DEBUG, "Creating table game.ui");
|
k3Log(k3_DEBUG, "Creating table game.ui");
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
lua_pushcfunction(L, dagame_ui_obj);
|
||||||
|
lua_setfield(L, -2, "obj");
|
||||||
|
|
||||||
lua_pushcfunction(L, dagame_ui_screen);
|
lua_pushcfunction(L, dagame_ui_screen);
|
||||||
lua_setfield(L, -2, "screen");
|
lua_setfield(L, -2, "screen");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user