From 8145a04944a13c33bad92589d99e2bde08743cde Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 15 Jun 2015 13:42:29 -0400 Subject: [PATCH] dwarfmonitor: Add mouse cursor widget Suggested by @ragundo --- NEWS | 1 + Readme.rst | 44 +++++++++++++++++++++++++++--------- plugins/lua/dwarfmonitor.lua | 18 +++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index f81f394b6..e82aa5157 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,7 @@ DFHack Future Misc Improvements dwarfmonitor widgets' positions, formats, etc. are now customizable (see Readme) dwarfmonitor weather display now separated from the date display + dwarfmonitor: New mouse cursor widget gui/gm-editor: Pointers can now be displaced gui/hack-wish: renamed to gui/create-item "keybinding list" accepts a context diff --git a/Readme.rst b/Readme.rst index 29fdad350..21f41e708 100644 --- a/Readme.rst +++ b/Readme.rst @@ -1693,8 +1693,10 @@ Options: ``dwarfmonitor enable ``: Start monitoring ``mode``. ``mode`` can be "work", "misery", "weather", or "all". + This will enable all corresponding widgets, if applicable. ``dwarfmonitor disable ``: Stop monitoring ``mode`` (see above) + This will disable all corresponding widgets, if applicable. ``dwarfmonitor stats``: Show statistics summary ``dwarfmonitor prefs``: @@ -1704,16 +1706,23 @@ Options: Widget configuration: +The following types of widgets (defined in ``hack/lua/plugins/dwarfmonitor.lua``) +can be displayed on the main fortress mode screen: + +* ``date``: Shows the in-game date +* ``misery``: Shows overall happiness levels of all dwarves +* ``weather``: Shows current weather (rain/snow) +* ``cursor``: Shows the current mouse cursor position + The file ``dfhack-config/dwarfmonitor.json`` can be edited to control the -positions and settings of all widgets displayed on the main fortress mode screen -(currently weather, misery, and date indicators). This file should contain a +positions and settings of all widgets displayed. This file should contain a JSON object with the key ``widgets`` containing an array of objects - see the included file in the ``dfhack-config`` folder for an example:: { "widgets": [ { - "type": "widget type (weather, misery, or date)", + "type": "widget type (weather, misery, etc.)", "x": X coordinate, "y": Y coordinate <...additional options...> @@ -1730,16 +1739,29 @@ By default, the x and y coordinates given correspond to the leftmost tile of the widget. Including an ``anchor`` option set to ``right`` will cause the rightmost tile of the widget to be located at this position instead. -The date widget supports an additional option, ``format``, which replaces the -following characters (all others, such as punctuation, are not modified): +Some widgets support additional options: + +* ``date`` widget: + + * ``format``: specifies the format of the date. The following characters + are replaced (all others, such as punctuation, are not modified) + + * ``Y`` or ``y``: The current year + * ``M``: The current month, zero-padded if necessary + * ``m``: The current month, *not* zero-padded + * ``D``: The current day, zero-padded if necessary + * ``d``: The current day, *not* zero-padded + + The default date format is ``Y-M-D``. -* ``Y`` or ``y``: The current year -* ``M``: The current month, zero-padded if necessary -* ``m``: The current month, *not* zero-padded -* ``D``: The current day, zero-padded if necessary -* ``d``: The current day, *not* zero-padded +* ``cursor`` widget: -The default date format is ``Y-M-D``. + * ``format``: Specifies the format. ``X``, ``x``, ``Y``, and ``y`` are + replaced with the corresponding cursor cordinates, while all other + characters are unmodified. + * ``show_invalid``: If set to ``true``, the mouse coordinates will both be + displayed as ``-1`` when the cursor is outside of the DF window; otherwise, + nothing will be displayed. seedwatch --------- diff --git a/plugins/lua/dwarfmonitor.lua b/plugins/lua/dwarfmonitor.lua index 6768335f6..35a667bd4 100644 --- a/plugins/lua/dwarfmonitor.lua +++ b/plugins/lua/dwarfmonitor.lua @@ -128,6 +128,24 @@ function Widget_misery:render_body(p) end end +Widget_cursor = defclass(Widget_cursor, Widget) + +function Widget_cursor:update() + if gps.mouse_x == -1 and not self.opts.show_invalid then + self.output = '' + return + end + self.output = (self.opts.format or '(x,y)'):gsub('[xX]', gps.mouse_x):gsub('[yY]', gps.mouse_y) +end + +function Widget_cursor:get_width() + return #self.output +end + +function Widget_cursor:render_body(p) + p:string(self.output) +end + function render_all() for _, w in pairs(widgets) do w:render()