allow getMousePos to return out of bounds coordinates

develop
Myk Taylor 2023-11-06 06:01:15 -08:00
parent 9660ba5b83
commit 4572ec3d09
No known key found for this signature in database
5 changed files with 12 additions and 7 deletions

@ -80,10 +80,12 @@ Template for new versions:
- ``Maps::getWalkableGroup``: get the walkability group of a tile - ``Maps::getWalkableGroup``: get the walkability group of a tile
- ``Units::getReadableName``: now returns the *untranslated* name - ``Units::getReadableName``: now returns the *untranslated* name
- ``Burrows::setAssignedUnit``: now properly handles inactive burrows - ``Burrows::setAssignedUnit``: now properly handles inactive burrows
- ``Gui::getMousePos``: now takes an optional ``allow_out_of_bounds`` parameter so coordinates can be returned for mouse positions outside of the game map (i.e. in the blank space around the map)
## Lua ## Lua
- ``dfhack.gui.revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target - ``dfhack.gui.revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target
- ``dfhack.maps.getWalkableGroup``: get the walkability group of a tile - ``dfhack.maps.getWalkableGroup``: get the walkability group of a tile
- ``dfhack.gui.getMousePos``: support new optional ``allow_out_of_bounds`` parameter
- ``gui.FRAME_THIN``: a panel frame suitable for floating tooltips - ``gui.FRAME_THIN``: a panel frame suitable for floating tooltips
## Removed ## Removed

@ -1140,10 +1140,12 @@ Announcements
If you want a guaranteed announcement without parsing, use ``dfhack.gui.showAutoAnnouncement`` instead. If you want a guaranteed announcement without parsing, use ``dfhack.gui.showAutoAnnouncement`` instead.
* ``dfhack.gui.getMousePos()`` * ``dfhack.gui.getMousePos([allow_out_of_bounds])``
Returns the map coordinates of the map tile the mouse is over as a table of Returns the map coordinates of the map tile the mouse is over as a table of
``{x, y, z}``. If the cursor is not over the map, returns ``nil``. ``{x, y, z}``. If the cursor is not over a valid tile, returns ``nil``. To
allow the function to return coordinates outside of the map, set
``allow_out_of_bounds`` to ``true``.
Other Other
~~~~~ ~~~~~

@ -1505,8 +1505,9 @@ static int gui_getDwarfmodeViewDims(lua_State *state)
static int gui_getMousePos(lua_State *L) static int gui_getMousePos(lua_State *L)
{ {
auto pos = Gui::getMousePos(); bool allow_out_of_bounds = lua_toboolean(L, 1);
if (pos.isValid()) df::coord pos = Gui::getMousePos(allow_out_of_bounds);
if ((allow_out_of_bounds && pos.z >= 0) || pos.isValid())
Lua::Push(L, pos); Lua::Push(L, pos);
else else
lua_pushnil(L); lua_pushnil(L);

@ -150,7 +150,7 @@ namespace DFHack
*/ */
DFHACK_EXPORT df::coord getViewportPos(); DFHACK_EXPORT df::coord getViewportPos();
DFHACK_EXPORT df::coord getCursorPos(); DFHACK_EXPORT df::coord getCursorPos();
DFHACK_EXPORT df::coord getMousePos(); DFHACK_EXPORT df::coord getMousePos(bool allow_out_of_bounds = false);
static const int AREA_MAP_WIDTH = 23; static const int AREA_MAP_WIDTH = 23;
static const int MENU_WIDTH = 30; static const int MENU_WIDTH = 30;

@ -2257,7 +2257,7 @@ bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t
} }
// returns the map coordinates that the mouse cursor is over // returns the map coordinates that the mouse cursor is over
df::coord Gui::getMousePos() df::coord Gui::getMousePos(bool allow_out_of_bounds)
{ {
df::coord pos; df::coord pos;
if (gps && gps->precise_mouse_x > -1) { if (gps && gps->precise_mouse_x > -1) {
@ -2271,7 +2271,7 @@ df::coord Gui::getMousePos()
pos.y += gps->mouse_y; pos.y += gps->mouse_y;
} }
} }
if (!Maps::isValidTilePos(pos.x, pos.y, pos.z)) if (!allow_out_of_bounds && !Maps::isValidTilePos(pos.x, pos.y, pos.z))
return df::coord(); return df::coord();
return pos; return pos;
} }