diff --git a/LUA_API.rst b/LUA_API.rst index a59be7430..d6044c235 100644 --- a/LUA_API.rst +++ b/LUA_API.rst @@ -1219,21 +1219,26 @@ be feasibly used in the core context. Returns *x,y* of the tile the mouse is over. +* ``dfhack.screen.inGraphicsMode()`` + + Checks if [GRAPHICS:YES] was specified in init. + * ``dfhack.screen.paintTile(pen,x,y[,char,tile])`` Paints a tile using given parameters. Pen is a table with following possible fields: ``ch`` - Provides the ordinary tile character. Can be overridden with the ``char`` function parameter. + Provides the ordinary tile character, as either a 1-character string or a number. + Can be overridden with the ``char`` function parameter. ``fg`` - Foreground color for the ordinary tile. Defaults to 7. + Foreground color for the ordinary tile. Defaults to COLOR_GREY (7). ``bg`` - Background color for the ordinary tile. Defaults to 0. + Background color for the ordinary tile. Defaults to COLOR_BLACK (0). ``bold`` - Bright/bold text flag. If *nil*, computed based on (fg & 8); fg is reset to 7 bits. + Bright/bold text flag. If *nil*, computed based on (fg & 8); fg is masked to 3 bits. Otherwise should be *true/false*. ``tile`` - Graphical tile id. Ignored unless [GRAPHICS:YES] in init.txt. + Graphical tile id. Ignored unless [GRAPHICS:YES] was in init.txt. ``tile_color = true`` Specifies that the tile should be shaded with *fg/bg*. ``tile_fg, tile_bg`` @@ -1253,6 +1258,14 @@ be feasibly used in the core context. Fills the rectangle specified by the coordinates with the given pen. Returns *true* if painting at least one character succeeded. +* ``dfhack.screen.findGraphicsTile(pagename,x,y)`` + + Finds a tile from a graphics set (i.e. the raws used for creatures), + if in graphics mode and loaded. + + Returns: *tile, tile_grayscale*, or *nil* if not found. + The values can then be used for the *tile* field of *pen* structures. + * ``dfhack.screen.clear()`` Fills the screen with blank background. @@ -1319,6 +1332,14 @@ Supported callbacks and fields are: Note that this refers to logical keybingings computed from real keys via options; if multiple interpretations exist, the table will contain multiple keys. + The table also may contain special keys: + + ``_STRING`` + Maps to an integer in range 0-255. Duplicates a separate "STRING_A???" code for convenience. + + ``_MOUSE_L, _MOUSE_R`` + If the left or right mouse button is pressed. + If this method is omitted, the screen is dismissed on receival of the ``LEAVESCREEN`` key. diff --git a/Lua API.html b/Lua API.html index ebb8a14db..610202ce3 100644 --- a/Lua API.html +++ b/Lua API.html @@ -1398,24 +1398,28 @@ be feasibly used in the core context.
dfhack.screen.getMousePos()
Returns x,y of the tile the mouse is over.
dfhack.screen.inGraphicsMode()
+Checks if [GRAPHICS:YES] was specified in init.
+dfhack.screen.paintTile(pen,x,y[,char,tile])
Paints a tile using given parameters. Pen is a table with following possible fields:
Provides the ordinary tile character. Can be overridden with the char function parameter.
+Provides the ordinary tile character, as either a 1-character string or a number. +Can be overridden with the char function parameter.
Foreground color for the ordinary tile. Defaults to 7.
+Foreground color for the ordinary tile. Defaults to COLOR_GREY (7).
Background color for the ordinary tile. Defaults to 0.
+Background color for the ordinary tile. Defaults to COLOR_BLACK (0).
Bright/bold text flag. If nil, computed based on (fg & 8); fg is reset to 7 bits. +
Bright/bold text flag. If nil, computed based on (fg & 8); fg is masked to 3 bits. Otherwise should be true/false.
Graphical tile id. Ignored unless [GRAPHICS:YES] in init.txt.
+Graphical tile id. Ignored unless [GRAPHICS:YES] was in init.txt.
Specifies that the tile should be shaded with fg/bg.
@@ -1435,6 +1439,12 @@ in sequence to override the ch field of pen.Fills the rectangle specified by the coordinates with the given pen. Returns true if painting at least one character succeeded.
dfhack.screen.findGraphicsTile(pagename,x,y)
+Finds a tile from a graphics set (i.e. the raws used for creatures), +if in graphics mode and loaded.
+Returns: tile, tile_grayscale, or nil if not found. +The values can then be used for the tile field of pen structures.
+dfhack.screen.clear()
Fills the screen with blank background.
The table also may contain special keys:
+Maps to an integer in range 0-255. Duplicates a separate "STRING_A???" code for convenience.
+If the left or right mouse button is pressed.
+If this method is omitted, the screen is dismissed on receival of the LEAVESCREEN key.
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 0f3ed9357..112cc4fdc 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1075,6 +1075,7 @@ static const luaL_Reg dfhack_constructions_funcs[] = { /***** Screen module *****/ static const LuaWrapper::FunctionReg dfhack_screen_module[] = { + WRAPM(Screen, inGraphicsMode), WRAPM(Screen, clear), WRAPM(Screen, invalidate), { NULL, NULL } @@ -1133,6 +1134,25 @@ static int screen_fillRect(lua_State *L) return 1; } +static int screen_findGraphicsTile(lua_State *L) +{ + auto str = luaL_checkstring(L, 1); + int x = luaL_checkint(L, 2); + int y = luaL_checkint(L, 3); + int tile, tile_gs; + if (Screen::findGraphicsTile(str, x, y, &tile, &tile_gs)) + { + lua_pushinteger(L, tile); + lua_pushinteger(L, tile_gs); + return 2; + } + else + { + lua_pushnil(L); + return 1; + } +} + namespace { int screen_show(lua_State *L) @@ -1168,6 +1188,7 @@ static const luaL_Reg dfhack_screen_funcs[] = { { "paintTile", screen_paintTile }, { "paintString", screen_paintString }, { "fillRect", screen_fillRect }, + { "findGraphicsTile", screen_findGraphicsTile }, { "show", &Lua::CallWithCatchWrapper