Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alternative rightclick behavior overlay to gui/design #1345

Merged
merged 9 commits into from
Dec 6, 2024
Merged
15 changes: 15 additions & 0 deletions docs/fixrightclick.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fixrightclick
================

.. dfhack-tool::
:summary: Adjust properties of caravans on the map.
:tags: fort interface bugfix

This overlay changes the behavior of the right mouse button and other keys mapped to "Leave screen" to only reset the selection rectangle when painting designations, constructions, minecart tracks, zones, etc., instead of outright quitting the painting mode. It can be toggled in the UI Overlays tab of `gui/control-panel`.

Usage
-----

::

overlay enable|disable fixrightclick.selection
37 changes: 37 additions & 0 deletions fixrightclick.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--@ module = true

local overlay = require('plugins.overlay')

RightClickWidget = defclass(RightClickWidget, overlay.OverlayWidget)
RightClickWidget.ATTRS{
desc='When painting a rectangle, makes right click cancel selection instead of exiting.',
default_enabled=true,
viewscreens={
'dwarfmode/Building/Placement',
'dwarfmode/Designate',
'dwarfmode/Stockpile/Paint',
'dwarfmode/Zone/Paint',
'dwarfmode/Burrow/Paint'
},
}

local selection_rect = df.global.selection_rect
local buildreq = df.global.buildreq

function RightClickWidget:onInput(keys)
if keys._MOUSE_R or keys.LEAVESCREEN then
-- building mode, do not run if buildingplan.planner is enabled since it already provides this functionality
if buildreq.selection_pos.x >= 0 and not overlay.get_state().config['buildingplan.planner'].enabled then
myk002 marked this conversation as resolved.
Show resolved Hide resolved
buildreq.selection_pos:clear()
return true
-- all other modes
elseif selection_rect.start_x >= 0 then
selection_rect.start_x = -30000
selection_rect.start_y = -30000
selection_rect.start_z = -30000
return true
end
end
end

OVERLAY_WIDGETS = {selection=RightClickWidget}