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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha - I need to handle this case for DimensionsOverlay too. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem - I actually wanted to do that myself but for some reason it wouldn't work even though I'm sure I made almost the exact same change. Must've been a syntax error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after you made the edit, did you run :lua require('plugins.overlay').rescan()? changes to overlay widgets need to be reloaded at the framework level.

Copy link
Contributor Author

@nibirubingus nibirubingus Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, I can't remember if I did that after I'd added design.rightclick. But I definitely did restart my game

'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
Loading