From d34238918e1412d7e3b5dd5c2c9d65ba7c2b3039 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 22 Jan 2023 22:10:17 -0800 Subject: [PATCH 1/6] move helpdb from autorefresh to explicit refresh this greatly speeds up the launch time of `gui/launcher` --- docs/changelog.txt | 3 +++ docs/dev/Lua API.rst | 15 +++++++++++---- library/Core.cpp | 1 + library/lua/helpdb.lua | 30 ++++++++++-------------------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 5e114c5e2..073837eff 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -40,6 +40,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Misc Improvements - A new cross-compile build script was added for building the Windows files from a Linux Docker builder (see the Compile instructions in the docs) - `hotkeys`: clicking on the DFHack logo no longer closes the popup menu +- `gui/launcher`: sped up initialization time for faster load of the UI - `orders`: orders plugin functionality is now offered via an overlay widget when the manager orders screen is open ## Documentation @@ -47,6 +48,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## API ## Lua +- `helpdb`: new function: ``helpdb.refresh()`` to force a refresh of the database. Call if you are a developer adding new scripts, loading new plugins, or changing help text during play +- `helpdb`: changed from auto-refreshing every 60 seconds to only refreshing on explicit call to ``helpdb.refresh()``. docs very rarely change during a play session, and the automatic database refreshes were slowing down the startup of `gui/launcher` - ``widgets.Label``: ``label.scroll()`` now understands ``home`` and ``end`` keywords for scrolling to the top or bottom ## Removed diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index c696248ab..cc590b179 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -3319,17 +3319,20 @@ function: argument specifies the indentation step size in spaces. For the other arguments see the original documentation link above. +.. _helpdb: + helpdb ====== Unified interface for DFHack tool help text. Help text is read from the rendered -text in ``hack/docs/docs/``. If no rendered text exists, help is read from the -script sources (for scripts) or the string passed to the ``PluginCommand`` +text in ``hack/docs/docs/tools``. If no rendered text exists, help is read from +the script sources (for scripts) or the string passed to the ``PluginCommand`` initializer (for plugins). See `documentation` for details on how DFHack's help system works. -The database is lazy-loaded when an API method is called. It rechecks its help -sources for updates if an API method has not been called in the last 60 seconds. +The database is loaded when DFHack initializes, but can be explicitly refreshed +with a call to ``helpdb.refresh()`` if docs are added/changed during a play +session. Each entry has several properties associated with it: @@ -3345,6 +3348,10 @@ Each entry has several properties associated with it: - Long help, the entire contents of the associated help file. - A list of tags that define the groups that the entry belongs to. +* ``helpdb.refresh()`` + + Scan for changes in available commands and their documentation. + * ``helpdb.is_entry(str)``, ``helpdb.is_entry(list)`` Returns whether the given string (or list of strings) is an entry (are all diff --git a/library/Core.cpp b/library/Core.cpp index e2c983116..bdd38799f 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2114,6 +2114,7 @@ void Core::onStateChange(color_ostream &out, state_change_event event) { auto L = Lua::Core::State; Lua::StackUnwinder top(L); + Lua::CallLuaModuleFunction(con, L, "helpdb", "refresh"); Lua::CallLuaModuleFunction(con, L, "script-manager", "reload"); } break; diff --git a/library/lua/helpdb.lua b/library/lua/helpdb.lua index 711555a78..df5482aec 100644 --- a/library/lua/helpdb.lua +++ b/library/lua/helpdb.lua @@ -1,23 +1,9 @@ -- The help text database and query interface. --- --- Help text is read from the rendered text in hack/docs/docs/. If no rendered --- text exists, it is read from the script sources (for scripts) or the string --- passed to the PluginCommand initializer (for plugins). --- --- There should be one help file for each plugin that contains a summary for the --- plugin itself and help for all the commands that plugin provides (if any). --- Each script should also have one documentation file. --- --- The database is lazy-loaded when an API method is called. It rechecks its --- help sources for updates if an API method has not been called in the last --- 60 seconds. local _ENV = mkmodule('helpdb') local argparse = require('argparse') -local MAX_STALE_MS = 60000 - -- paths local RENDERED_PATH = 'hack/docs/docs/tools/' local TAG_DEFINITIONS = 'hack/docs/docs/Tags.txt' @@ -415,13 +401,12 @@ local function index_tags() end end --- ensures the db is up to date by scanning all help sources. does not do --- anything if it has already been run within the last MAX_STALE_MS milliseconds -local last_refresh_ms = 0 +local needs_refresh = true + +-- ensures the db is loaded local function ensure_db() - local now_ms = dfhack.getTickCount() - if now_ms - last_refresh_ms <= MAX_STALE_MS then return end - last_refresh_ms = now_ms + if not needs_refresh then return end + needs_refresh = false local old_db = textdb textdb, entrydb, tag_index = {}, {}, {} @@ -433,6 +418,11 @@ local function ensure_db() index_tags() end +function refresh() + needs_refresh = true + ensure_db() +end + local function parse_blocks(text) local blocks = {} for line in text:gmatch('[^\n]*') do From 9aaa55cd7f22b0a0078dd7c2f283a9a84c373001 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 23 Jan 2023 02:25:16 -0800 Subject: [PATCH 2/6] add textures and frames for various use cases --- data/art/border-medium.png | Bin 0 -> 641 bytes data/art/border-panel.png | Bin 0 -> 446 bytes data/art/border-thin.png | Bin 0 -> 471 bytes data/art/border-window.png | Bin 0 -> 563 bytes docs/dev/Lua API.rst | 15 ++++++----- library/LuaApi.cpp | 4 +++ library/include/modules/Textures.h | 8 ++++++ library/lua/gui.lua | 39 +++++++++++++++++++++-------- library/modules/Textures.cpp | 28 +++++++++++++++++++++ plugins/lua/orders.lua | 2 +- 10 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 data/art/border-medium.png create mode 100644 data/art/border-panel.png create mode 100644 data/art/border-thin.png create mode 100644 data/art/border-window.png diff --git a/data/art/border-medium.png b/data/art/border-medium.png new file mode 100644 index 0000000000000000000000000000000000000000..529a60ee433fd2358d7252a8108ecef2cd4463d6 GIT binary patch literal 641 zcmV-{0)G98P)D}R6#sT*unh7LiB=un|9u))k zbP~IB^j1c{tVfSeK4D^lZ*2&i;t5LmGgnj!L$K^o&Kwa_w=kDfvnrrX_#;vSwO5|D z6s}Xj44)N`sB#f!anB(ars`ME>*aO`I|Hg}6%5L=U60Cr0{K8xuIh!JBgmAa;-q>r zSr#SfR|;r(#@{p0!j^#R$)15?W!SvuxN~rRKLu$7d7)aHN!6zkdsPT%nJnB7&|uc; z50XxtDKty&G^HZ_gf+w&p>FePp#O&JrFt2kOG{VQSbsC=+d9|lsuh|$@>zR|w0y;=*$cL;fQUN=@4Fbxi?zRx+)fy6=8ZN=s9au>TC)?Z@duziic2Ma6GnV{ zl#H4kYb_5~&q8Xukofi}sXcmJwLC;U3qAWiBcpf%h9Vutizx>H0R{j?e$peluCCPp o000hUSV?A0O#mtY000O800000007cclK=n!07*qoM6N<$f;ro-?N8mzF` z}nQwdY=6}2<~lv&oM5~dy;rB5$hOq^o{+Nm?O6)9pDh&Gy0 zkI|eiIto~E9Ti*AQXLfoTB@VM#YD$PaRqLUlC5Re72s`F7%0wW_g^KumRUC2945gJ z8A)NYo1+*Y7Wq`B&V=YIZbRjPdRttruS~^c@P!|`u>1I@rDe!!^Hx9FSTDW0sfc^0 zM!ozfv9pKz>ZzEGck!e2&YsfO(AP5g(QIcA<6iz?pHgvJ6iOotPrh3 zbjYMpNX7@oIFaQ5E(O7~4pB(y2uzo7LHy+!ONk4#nM6STVR9T2eS4hYaW7a%fL~ zB3AL0PAdrJNJy(-2!tpx>3iTqbjYMpJmoiXIZg8r?I9vX;wrz9%W0a2C}y<`v76MM z57it>>vjUw97<|?6jH$sfJ5=OM=@*mf-Nf`;*P=lE(Y^r?e8PE6POr=2pDzffM+IL z{c)WAbmD4uf;B!lnF(vvOniG3mrDF5P!#pRLYs^cD|(lsKqo>vu8^W0tsEtzX2)8~ z!_~8p+AhTEO04B5sXcmJwLC;U3wh~mZQsV@kKfU=drfB41B2g@ftRku6EGC%FkVbK z00=Mu`kfg#VkT>U0000EWmrjOO-%qQ00008000000002eQ Date: Mon, 23 Jan 2023 04:03:31 -0800 Subject: [PATCH 3/6] add compatibility frames --- library/lua/gui.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index e415000ae..4b6bf6517 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -833,11 +833,15 @@ local function make_frame(name, double_line) end WINDOW_FRAME = make_frame('Window', true) -GREY_LINE_FRAME = WINDOW_FRAME -- for compatibility with pre-steam code PANEL_FRAME = make_frame('Panel', false) MEDIUM_FRAME = make_frame('Medium', false) THIN_FRAME = make_frame('Thin', false) +-- for compatibility with pre-steam code +GREY_LINE_FRAME = WINDOW_FRAME +BOUNDARY_FRAME = PANEL_FRAME +GREY_FRAME = MEDIUM_FRAME + function paint_frame(dc,rect,style,title,show_pin,pinned,inactive) local pen = style.frame_pen local x1,y1,x2,y2 = dc.x1+rect.x1, dc.y1+rect.y1, dc.x1+rect.x2, dc.y1+rect.y2 From d7e0dcfcf860b476e77ffb4c82dfe685bd1ba03f Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 23 Jan 2023 04:03:41 -0800 Subject: [PATCH 4/6] use new frames for hotkey hotspot --- plugins/lua/hotkeys.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lua/hotkeys.lua b/plugins/lua/hotkeys.lua index a6eaf7d81..99ba08a05 100644 --- a/plugins/lua/hotkeys.lua +++ b/plugins/lua/hotkeys.lua @@ -170,7 +170,7 @@ function Menu:init() widgets.Panel{ view_id='list_panel', frame=list_frame, - frame_style=gui.GREY_LINE_FRAME, + frame_style=gui.PANEL_FRAME, frame_background=gui.CLEAR_PEN, subviews={ widgets.List{ @@ -197,7 +197,7 @@ function Menu:init() view_id='help_panel', autoarrange_subviews=true, frame=help_frame, - frame_style=gui.GREY_LINE_FRAME, + frame_style=gui.PANEL_FRAME, frame_background=gui.CLEAR_PEN, subviews={ widgets.WrappedLabel{ From 7329f6dee20be6a598b29c17e7f38d5e40893c97 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 23 Jan 2023 04:16:38 -0800 Subject: [PATCH 5/6] use new frame names --- library/lua/gui/dialogs.lua | 2 +- library/lua/gui/widgets.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/lua/gui/dialogs.lua b/library/lua/gui/dialogs.lua index 0b923e7c0..3b2470114 100644 --- a/library/lua/gui/dialogs.lua +++ b/library/lua/gui/dialogs.lua @@ -13,7 +13,7 @@ MessageBox = defclass(MessageBox, gui.FramedScreen) MessageBox.focus_path = 'MessageBox' MessageBox.ATTRS{ - frame_style = gui.GREY_LINE_FRAME, + frame_style = gui.WINDOW_FRAME, frame_inset = 1, -- new attrs on_accept = DEFAULT_NIL, diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index f0129ffe3..4538c39df 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -531,7 +531,7 @@ end Window = defclass(Window, Panel) Window.ATTRS { - frame_style = gui.GREY_LINE_FRAME, + frame_style = gui.WINDOW_FRAME, frame_background = gui.CLEAR_PEN, frame_inset = 1, draggable = true, From 38e6e0a747d8013e45e5b7c94284d61d73be1c70 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 23 Jan 2023 08:01:45 -0800 Subject: [PATCH 6/6] ensure orders overlay is on the correct panel even when the total screen size is very small --- plugins/lua/orders.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lua/orders.lua b/plugins/lua/orders.lua index 40c79fca4..282b5997d 100644 --- a/plugins/lua/orders.lua +++ b/plugins/lua/orders.lua @@ -47,7 +47,7 @@ end OrdersOverlay = defclass(OrdersOverlay, overlay.OverlayWidget) OrdersOverlay.ATTRS{ - default_pos={x=61,y=-6}, + default_pos={x=53,y=-6}, viewscreens='dwarfmode', frame={w=30, h=4}, frame_style=gui.MEDIUM_FRAME,