merge develop into plugin_preservetombs

develop
Najeeb Al-Shabibi 2023-10-03 19:32:03 +01:00
commit 2a842c0df6
15 changed files with 52 additions and 52 deletions

@ -20,7 +20,7 @@ repos:
args: ['--fix=lf'] args: ['--fix=lf']
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema - repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.26.3 rev: 0.27.0
hooks: hooks:
- id: check-github-workflows - id: check-github-workflows
- repo: https://github.com/Lucas-C/pre-commit-hooks - repo: https://github.com/Lucas-C/pre-commit-hooks

@ -222,9 +222,6 @@ local function click_top_title_button(scr)
df.global.gps.mouse_y = (sh // 2) + 3 df.global.gps.mouse_y = (sh // 2) + 3
end end
df.global.gps.precise_mouse_y = df.global.gps.mouse_y * df.global.gps.tile_pixel_y df.global.gps.precise_mouse_y = df.global.gps.mouse_y * df.global.gps.tile_pixel_y
df.global.enabler.tracking_on = 1
df.global.enabler.mouse_lbut = 1
df.global.enabler.mouse_lbut_down = 1
gui.simulateInput(scr, '_MOUSE_L') gui.simulateInput(scr, '_MOUSE_L')
end end

@ -52,6 +52,7 @@ Template for new versions:
# Future # Future
## New Tools ## New Tools
- `spectate`: automatically follow productive dwarves (returned to availability)
- `preserve-tombs`: tracks tomb assignments to living units and ensures that the tomb stays assigned to them when they die. - `preserve-tombs`: tracks tomb assignments to living units and ensures that the tomb stays assigned to them when they die.
## New Features ## New Features

@ -3952,6 +3952,14 @@ Misc
of keycodes to *true* or *false*. For instance, it is possible to use the of keycodes to *true* or *false*. For instance, it is possible to use the
table passed as argument to ``onInput``. table passed as argument to ``onInput``.
You can send mouse clicks as will by setting the ``_MOUSE_L`` key or other
mouse-related pseudo-keys documented with the ``screen:onInput(keys)``
function above. Note that if you are simulating a click at a specific spot on
the screen, you must set ``df.global.gps.mouse_x`` and
``df.global.gps.mouse_y`` if you are clicking on the interface layer or
``df.global.gps.precise_mouse_x`` and ``df.global.gps.precise_mouse_y`` if
you are clicking on the map.
* ``mkdims_xy(x1,y1,x2,y2)`` * ``mkdims_xy(x1,y1,x2,y2)``
Returns a table containing the arguments as fields, and also ``width`` and Returns a table containing the arguments as fields, and also ``width`` and

@ -3,7 +3,7 @@ spectate
.. dfhack-tool:: .. dfhack-tool::
:summary: Automatically follow productive dwarves. :summary: Automatically follow productive dwarves.
:tags: unavailable fort interface :tags: fort interface
Usage Usage
----- -----

@ -391,6 +391,7 @@ namespace DFHack
virtual ~dfhack_lua_viewscreen(); virtual ~dfhack_lua_viewscreen();
static df::viewscreen *get_pointer(lua_State *L, int idx, bool make); static df::viewscreen *get_pointer(lua_State *L, int idx, bool make);
static void markInputAsHandled();
virtual bool is_lua_screen() { return true; } virtual bool is_lua_screen() { return true; }
virtual bool isFocused() { return !defocused; } virtual bool isFocused() { return !defocused; }

@ -15,8 +15,8 @@ TRANSPARENT_PEN = to_pen{tile=0, ch=0}
KEEP_LOWER_PEN = to_pen{ch=32, fg=0, bg=0, keep_lower=true} KEEP_LOWER_PEN = to_pen{ch=32, fg=0, bg=0, keep_lower=true}
local MOUSE_KEYS = { local MOUSE_KEYS = {
_MOUSE_L = true, _MOUSE_L = function(is_set) df.global.enabler.mouse_lbut = is_set and 1 or 0 end,
_MOUSE_R = true, _MOUSE_R = function(is_set) df.global.enabler.mouse_rbut = is_set and 1 or 0 end,
_MOUSE_M = true, _MOUSE_M = true,
_MOUSE_L_DOWN = true, _MOUSE_L_DOWN = true,
_MOUSE_R_DOWN = true, _MOUSE_R_DOWN = true,
@ -27,7 +27,7 @@ local FAKE_INPUT_KEYS = copyall(MOUSE_KEYS)
FAKE_INPUT_KEYS._STRING = true FAKE_INPUT_KEYS._STRING = true
function simulateInput(screen,...) function simulateInput(screen,...)
local keys = {} local keys, enabled_mouse_keys = {}, {}
local function push_key(arg) local function push_key(arg)
local kv = arg local kv = arg
if type(arg) == 'string' then if type(arg) == 'string' then
@ -35,6 +35,10 @@ function simulateInput(screen,...)
if kv == nil and not FAKE_INPUT_KEYS[arg] then if kv == nil and not FAKE_INPUT_KEYS[arg] then
error('Invalid keycode: '..arg) error('Invalid keycode: '..arg)
end end
if MOUSE_KEYS[arg] then
df.global.enabler.tracking_on = 1
enabled_mouse_keys[arg] = true
end
end end
if type(kv) == 'number' then if type(kv) == 'number' then
keys[#keys+1] = kv keys[#keys+1] = kv
@ -57,6 +61,11 @@ function simulateInput(screen,...)
end end
end end
end end
for mk, fn in pairs(MOUSE_KEYS) do
if type(fn) == 'function' then
fn(enabled_mouse_keys[mk])
end
end
dscreen._doSimulateInput(screen, keys) dscreen._doSimulateInput(screen, keys)
end end
@ -696,17 +705,6 @@ end
DEFAULT_INITIAL_PAUSE = true DEFAULT_INITIAL_PAUSE = true
-- ensure underlying DF screens don't also react to handled clicks
function markMouseClicksHandled(keys)
if keys._MOUSE_L then
df.global.enabler.mouse_lbut = 0
end
if keys._MOUSE_R then
df.global.enabler.mouse_rbut_down = 0
df.global.enabler.mouse_rbut = 0
end
end
ZScreen = defclass(ZScreen, Screen) ZScreen = defclass(ZScreen, Screen)
ZScreen.ATTRS{ ZScreen.ATTRS{
defocusable=true, defocusable=true,
@ -791,23 +789,17 @@ function ZScreen:onInput(keys)
self:raise() self:raise()
else else
self:sendInputToParent(keys) self:sendInputToParent(keys)
return return true
end end
end end
if ZScreen.super.onInput(self, keys) then if ZScreen.super.onInput(self, keys) then
markMouseClicksHandled(keys) -- noop
return elseif self.pass_mouse_clicks and keys._MOUSE_L and not has_mouse then
end
if self.pass_mouse_clicks and keys._MOUSE_L and not has_mouse then
self.defocused = self.defocusable self.defocused = self.defocusable
self:sendInputToParent(keys) self:sendInputToParent(keys)
return
elseif keys.LEAVESCREEN or keys._MOUSE_R then elseif keys.LEAVESCREEN or keys._MOUSE_R then
self:dismiss() self:dismiss()
markMouseClicksHandled(keys)
return
else else
local passit = self.pass_pause and keys.D_PAUSE local passit = self.pass_pause and keys.D_PAUSE
if not passit and self.pass_mouse_clicks then if not passit and self.pass_mouse_clicks then
@ -829,8 +821,8 @@ function ZScreen:onInput(keys)
if passit then if passit then
self:sendInputToParent(keys) self:sendInputToParent(keys)
end end
return
end end
return true
end end
function ZScreen:raise() function ZScreen:raise()

@ -64,13 +64,9 @@ function MessageBox:onInput(keys)
elseif (keys.LEAVESCREEN or keys._MOUSE_R) and self.on_cancel then elseif (keys.LEAVESCREEN or keys._MOUSE_R) and self.on_cancel then
self.on_cancel() self.on_cancel()
end end
gui.markMouseClicksHandled(keys)
return true
end
if self:inputToSubviews(keys) then
gui.markMouseClicksHandled(keys)
return true return true
end end
return self:inputToSubviews(keys)
end end
function showMessage(title, text, tcolor, on_close) function showMessage(title, text, tcolor, on_close)
@ -137,13 +133,9 @@ function InputBox:onInput(keys)
if self.on_cancel then if self.on_cancel then
self.on_cancel() self.on_cancel()
end end
gui.markMouseClicksHandled(keys)
return true
end
if self:inputToSubviews(keys) then
gui.markMouseClicksHandled(keys)
return true return true
end end
return self:inputToSubviews(keys)
end end
function showInputPrompt(title, text, tcolor, input, on_input, on_cancel, min_width) function showInputPrompt(title, text, tcolor, input, on_input, on_cancel, min_width)
@ -242,13 +234,9 @@ function ListBox:onInput(keys)
if self.on_cancel then if self.on_cancel then
self.on_cancel() self.on_cancel()
end end
gui.markMouseClicksHandled(keys)
return true
end
if self:inputToSubviews(keys) then
gui.markMouseClicksHandled(keys)
return true return true
end end
return self:inputToSubviews(keys)
end end
function showListPrompt(title, text, tcolor, choices, on_select, on_cancel, min_width, filter) function showListPrompt(title, text, tcolor, choices, on_select, on_cancel, min_width, filter)

@ -956,6 +956,18 @@ int dfhack_lua_viewscreen::do_notify(lua_State *L)
return 1; return 1;
} }
void dfhack_lua_viewscreen::markInputAsHandled() {
if (!enabler)
return;
// clear text buffer
enabler->last_text_input[0] = '\0';
// mark clicked mouse buttons as handled
enabler->mouse_lbut = 0;
enabler->mouse_rbut = 0;
}
int dfhack_lua_viewscreen::do_input(lua_State *L) int dfhack_lua_viewscreen::do_input(lua_State *L)
{ {
auto self = get_self(L); auto self = get_self(L);
@ -977,7 +989,11 @@ int dfhack_lua_viewscreen::do_input(lua_State *L)
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
Lua::PushInterfaceKeys(L, Screen::normalize_text_keys(*keys)); Lua::PushInterfaceKeys(L, Screen::normalize_text_keys(*keys));
lua_call(L, 2, 0); lua_call(L, 2, 1);
if (lua_toboolean(L, -1))
markInputAsHandled();
lua_pop(L, 1);
self->update_focus(L, -1); self->update_focus(L, -1);
return 0; return 0;
} }

@ -1 +1 @@
Subproject commit f38f3c4955d604f2b5a8e0d952e676a0ab05c053 Subproject commit aeab463a0d35ac9ff896db840735cabfa12df712

@ -159,7 +159,7 @@ if(BUILD_SUPPORTED)
#dfhack_plugin(siege-engine siege-engine.cpp LINK_LIBRARIES lua) #dfhack_plugin(siege-engine siege-engine.cpp LINK_LIBRARIES lua)
dfhack_plugin(sort sort.cpp LINK_LIBRARIES lua) dfhack_plugin(sort sort.cpp LINK_LIBRARIES lua)
#dfhack_plugin(steam-engine steam-engine.cpp) #dfhack_plugin(steam-engine steam-engine.cpp)
#add_subdirectory(spectate) add_subdirectory(spectate)
#dfhack_plugin(stockflow stockflow.cpp LINK_LIBRARIES lua) #dfhack_plugin(stockflow stockflow.cpp LINK_LIBRARIES lua)
add_subdirectory(stockpiles) add_subdirectory(stockpiles)
#dfhack_plugin(stocks stocks.cpp) #dfhack_plugin(stocks stocks.cpp)

@ -280,14 +280,12 @@ function Menu:onInput(keys)
local x = list:getMousePos() local x = list:getMousePos()
if x == 0 then -- clicked on icon if x == 0 then -- clicked on icon
self:onSubmit2(list:getSelected()) self:onSubmit2(list:getSelected())
gui.markMouseClicksHandled(keys)
return true return true
end end
if not self:getMouseFramePos() then if not self:getMouseFramePos() then
self.parent_view:dismiss() self.parent_view:dismiss()
return true return true
end end
gui.markMouseClicksHandled(keys)
end end
self:inputToSubviews(keys) self:inputToSubviews(keys)
return true -- we're modal return true -- we're modal

@ -506,7 +506,6 @@ function feed_viewscreen_widgets(vs_name, vs, keys)
not _feed_viewscreen_widgets('all', nil, keys) then not _feed_viewscreen_widgets('all', nil, keys) then
return false return false
end end
gui.markMouseClicksHandled(keys)
return true return true
end end

@ -86,7 +86,7 @@ struct viewscreen_overlay : T {
if (!input_is_handled) if (!input_is_handled)
INTERPOSE_NEXT(feed)(input); INTERPOSE_NEXT(feed)(input);
else else
enabler->last_text_input[0] = '\0'; dfhack_lua_viewscreen::markInputAsHandled();
} }
DEFINE_VMETHOD_INTERPOSE(void, render, ()) { DEFINE_VMETHOD_INTERPOSE(void, render, ()) {
INTERPOSE_NEXT(render)(); INTERPOSE_NEXT(render)();

@ -1 +1 @@
Subproject commit d2ad86165e89dc3b0f262eea00db8e2347cc4421 Subproject commit 28bcd6e313ea6f87ffd805c8cf40360da5f21509