diff --git a/changelog.txt b/changelog.txt index 6bcec1b704..15fe6d24c7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -30,6 +30,7 @@ Template for new versions: - `sync-windmills`: synchronize or randomize movement of active windmills ## New Features +- `gui/design`: show selected dimensions next to the mouse cursor when designating with vanilla tools, for example when painting a burrow or designating digging ## Fixes - `gui/unit-syndromes`: show the syndrome names properly in the UI diff --git a/docs/gui/design.rst b/docs/gui/design.rst index 2c2e2feb8b..139ef7a7c6 100644 --- a/docs/gui/design.rst +++ b/docs/gui/design.rst @@ -15,3 +15,10 @@ Usage :: gui/design + +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. diff --git a/gui/design.lua b/gui/design.lua index a0a215d4ad..72f592e6b3 100644 --- a/gui/design.lua +++ b/gui/design.lua @@ -1,5 +1,5 @@ -- A GUI front-end for creating designs ---@ module = false +--@ module = true -- TODOS ==================== @@ -38,6 +38,7 @@ local gui = require("gui") local textures = require("gui.textures") local guidm = require("gui.dwarfmode") local widgets = require("gui.widgets") +local overlay = require('plugins.overlay') local quickfort = reqscript("quickfort") local shapes = reqscript("internal/design/shapes") local util = reqscript("internal/design/util") @@ -1771,6 +1772,67 @@ function DesignScreen:onDismiss() view = nil end +-- ----------------- -- +-- DimensionsOverlay -- +-- ----------------- -- + +local DIMENSION_LABEL_WIDTH = 15 +local DIMENSION_LABEL_HEIGHT = 1 + +DimensionsOverlay = defclass(DimensionsOverlay, overlay.OverlayWidget) +DimensionsOverlay.ATTRS{ + default_pos={x=1,y=1}, + default_enabled=true, + viewscreens={ + 'dwarfmode/Designate', + 'dwarfmode/Burrow/Paint', + 'dwarfmode/Stockpile/Paint', + }, + frame={w=DIMENSION_LABEL_WIDTH, h=DIMENSION_LABEL_HEIGHT}, +} + +local selection_rect = df.global.selection_rect + +local function is_choosing_area() + return selection_rect.start_x >= 0 and dfhack.gui.getMousePos() +end + +local function get_cur_area_dims() + local pos1 = dfhack.gui.getMousePos() + local pos2 = xyz2pos(selection_rect.start_x, selection_rect.start_y, selection_rect.start_z) + return math.abs(pos1.x - pos2.x) + 1, + math.abs(pos1.y - pos2.y) + 1, + math.abs(pos1.z - pos2.z) + 1 +end + +function DimensionsOverlay:init() + self:addviews{ + widgets.Label{ + view_id='label', + frame={t=0, l=0, h=DIMENSION_LABEL_HEIGHT}, + text={ + {text=function() return ('%dx%dx%d'):format(get_cur_area_dims()) end}, + }, + visible=is_choosing_area, + }, + } +end + +function DimensionsOverlay:onRenderFrame(dc, rect) + DimensionsOverlay.super.onRenderFrame(self, dc, rect) + local sw, sh = dfhack.screen.getWindowSize() + local x, y = dfhack.screen.getMousePos() + x = math.min(x + 3, sw - DIMENSION_LABEL_WIDTH) + y = math.min(y + 3, sh - DIMENSION_LABEL_HEIGHT) + self.frame.w = x + DIMENSION_LABEL_WIDTH + self.frame.h = y + DIMENSION_LABEL_HEIGHT + self.subviews.label.frame = {t=y, l=x} +end + +OVERLAY_WIDGETS = { + dimensions=DimensionsOverlay, +} + if dfhack_flags.module then return end if not dfhack.isMapLoaded() then