Skip to content

Commit

Permalink
Merge pull request #1345 from nibirubingus/verkhov-fixrightclick
Browse files Browse the repository at this point in the history
Add alternative rightclick behavior overlay to `gui/design`
  • Loading branch information
myk002 authored Dec 6, 2024
2 parents c2d1b9e + 0beb896 commit 9fd678d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Template for new versions:
- `gui/gm-editor`: automatic display of semantic values for language_name fields
- `fix/stuck-worship`: reduced console output by default. Added ``--verbose`` and ``--quiet`` options.
- `necronomicon`: new ``--world`` option to list all secret-containing items in the entire world
- `gui/design`: new ``gui/design.rightclick`` overlay that prevents right click from closing designation mode when drawing boxes and minecart tracks

## Removed
- `modtools/force`: merged into `force`
Expand Down
21 changes: 16 additions & 5 deletions docs/gui/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gui/design

.. dfhack-tool::
:summary: Design designation utility with shapes.
:tags: fort design productivity map
:tags: fort design productivity interface map

This tool provides a point and click interface to make designating shapes
and patterns easier. Supports both digging designations and placing constructions.
Expand All @@ -19,7 +19,18 @@ Usage
Overlay
-------

This script provides an overlay that shows the selected dimensions when
designating something with vanilla tools, for example when painting a burrow or
designating digging. The dimensions show up in a tooltip that follows the mouse
cursor.
This tool also provides two overlays that are managed by the `overlay` framework.

dimensions
~~~~~~~~~~

The ``gui/design.dimensions`` overlay shows the selected dimensions when designating
with vanilla tools, for example when painting a burrow or designating digging.
The dimensions show up in a tooltip that follows the mouse cursor.

rightclick
~~~~~~~~~~

The ``gui/design.rightclick`` overlay prevents the right mouse button and other keys
bound to "Leave screen" from exiting out of designation mode when drawing a box with
vanilla tools, instead making it cancel the designation first.
34 changes: 34 additions & 0 deletions gui/design.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,42 @@ function DimensionsOverlay:preUpdateLayout(parent_rect)
self.frame.h = parent_rect.height
end

---
--- RightClickOverlay
---

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

function RightClickOverlay:onInput(keys)
if keys._MOUSE_R or keys.LEAVESCREEN then
-- building mode
if uibs.selection_pos.x >= 0 then
uibs.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 = {
dimensions=DimensionsOverlay,
rightclick=RightClickOverlay,
}

---
Expand Down

0 comments on commit 9fd678d

Please sign in to comment.