From 77e9006d39efefe39fb3c50d348158fd1d6dd191 Mon Sep 17 00:00:00 2001
From: nibirubingus <127212797+nibirubingus@users.noreply.github.com>
Date: Wed, 4 Dec 2024 17:00:26 +0700
Subject: [PATCH 1/9] Add files via upload

---
 docs/fixrightclick.rst | 15 +++++++++++++++
 fixrightclick.lua      | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 docs/fixrightclick.rst
 create mode 100644 fixrightclick.lua

diff --git a/docs/fixrightclick.rst b/docs/fixrightclick.rst
new file mode 100644
index 000000000..abd5e0068
--- /dev/null
+++ b/docs/fixrightclick.rst
@@ -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
\ No newline at end of file
diff --git a/fixrightclick.lua b/fixrightclick.lua
new file mode 100644
index 000000000..8bad9c192
--- /dev/null
+++ b/fixrightclick.lua
@@ -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
+            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}
\ No newline at end of file

From a568a42949bf8c4240c2edd01d73307b5e575d16 Mon Sep 17 00:00:00 2001
From: maksim verkhov <127212797+nibirubingus@users.noreply.github.com>
Date: Wed, 4 Dec 2024 17:57:31 +0500
Subject: [PATCH 2/9] Update fixrightclick.rst

---
 docs/fixrightclick.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/fixrightclick.rst b/docs/fixrightclick.rst
index abd5e0068..931ab91f6 100644
--- a/docs/fixrightclick.rst
+++ b/docs/fixrightclick.rst
@@ -12,4 +12,4 @@ Usage
 
 ::
 
-    overlay enable|disable fixrightclick
\ No newline at end of file
+    overlay enable|disable fixrightclick.selection

From 231b970f13ae212e833fc9d38e1316362cb6237b Mon Sep 17 00:00:00 2001
From: maksim verkhov <127212797+nibirubingus@users.noreply.github.com>
Date: Wed, 4 Dec 2024 23:13:21 +0500
Subject: [PATCH 3/9] Delete docs/fixrightclick.rst

---
 docs/fixrightclick.rst | 15 ---------------
 1 file changed, 15 deletions(-)
 delete mode 100644 docs/fixrightclick.rst

diff --git a/docs/fixrightclick.rst b/docs/fixrightclick.rst
deleted file mode 100644
index 931ab91f6..000000000
--- a/docs/fixrightclick.rst
+++ /dev/null
@@ -1,15 +0,0 @@
-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

From 643796d11e41479427131126a33336f5f4e144aa Mon Sep 17 00:00:00 2001
From: maksim verkhov <127212797+nibirubingus@users.noreply.github.com>
Date: Wed, 4 Dec 2024 23:15:18 +0500
Subject: [PATCH 4/9] Delete fixrightclick.lua

---
 fixrightclick.lua | 37 -------------------------------------
 1 file changed, 37 deletions(-)
 delete mode 100644 fixrightclick.lua

diff --git a/fixrightclick.lua b/fixrightclick.lua
deleted file mode 100644
index 8bad9c192..000000000
--- a/fixrightclick.lua
+++ /dev/null
@@ -1,37 +0,0 @@
---@ 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
-            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}
\ No newline at end of file

From a903e829921fab4ad910286da1f0c916d78a0467 Mon Sep 17 00:00:00 2001
From: maksim verkhov <127212797+nibirubingus@users.noreply.github.com>
Date: Thu, 5 Dec 2024 00:07:52 +0500
Subject: [PATCH 5/9] Update overlay info in design.rst

---
 docs/gui/design.rst | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/docs/gui/design.rst b/docs/gui/design.rst
index 29d46dfeb..ac6c14e9c 100644
--- a/docs/gui/design.rst
+++ b/docs/gui/design.rst
@@ -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.
@@ -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 mousecursor.
+
+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.

From c5a6501779356327a77f1c18c2435e6591110980 Mon Sep 17 00:00:00 2001
From: maksim verkhov <127212797+nibirubingus@users.noreply.github.com>
Date: Thu, 5 Dec 2024 00:09:37 +0500
Subject: [PATCH 6/9] add RightClickOverlay

---
 gui/design.lua | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/gui/design.lua b/gui/design.lua
index 5e90a4797..8166a8395 100644
--- a/gui/design.lua
+++ b/gui/design.lua
@@ -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
 }
 
 ---

From 946cf3a4dd1acfbe918f6003752ec0146be72b9c Mon Sep 17 00:00:00 2001
From: maksim verkhov <127212797+nibirubingus@users.noreply.github.com>
Date: Thu, 5 Dec 2024 01:15:33 +0500
Subject: [PATCH 7/9] `gui/design`: new overlay ``gui/design.rightclick``

---
 changelog.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/changelog.txt b/changelog.txt
index fd18b433e..93ead4a43 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -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 overlay ``gui/design.rightclick`` that prevents right click from closing designation mode when drawing rectangles 
 
 ## Removed
 - `modtools/force`: merged into `force`

From 0f1eef52caf2b19fd7d987582e489007b3afa154 Mon Sep 17 00:00:00 2001
From: maksim verkhov <127212797+nibirubingus@users.noreply.github.com>
Date: Thu, 5 Dec 2024 01:24:46 +0500
Subject: [PATCH 8/9] slightly better wording on ``gui/design.rightclick``

---
 changelog.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/changelog.txt b/changelog.txt
index 93ead4a43..771ba18df 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -51,7 +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 overlay ``gui/design.rightclick`` that prevents right click from closing designation mode when drawing rectangles 
+- `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`

From 0beb896a89f70f00215964b2feb5d7e130277233 Mon Sep 17 00:00:00 2001
From: Myk <myk.taylor@gmail.com>
Date: Thu, 5 Dec 2024 18:46:36 -0800
Subject: [PATCH 9/9] Apply suggestions from code review

---
 docs/gui/design.rst | 2 +-
 gui/design.lua      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/gui/design.rst b/docs/gui/design.rst
index ac6c14e9c..5518af6c9 100644
--- a/docs/gui/design.rst
+++ b/docs/gui/design.rst
@@ -26,7 +26,7 @@ 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 mousecursor.
+The dimensions show up in a tooltip that follows the mouse cursor.
 
 rightclick
 ~~~~~~~~~~
diff --git a/gui/design.lua b/gui/design.lua
index 8166a8395..dac68bd5f 100644
--- a/gui/design.lua
+++ b/gui/design.lua
@@ -155,7 +155,7 @@ end
 
 OVERLAY_WIDGETS = {
     dimensions=DimensionsOverlay,
-    rightclick=RightClickOverlay
+    rightclick=RightClickOverlay,
 }
 
 ---