This is a script intended to be loaded into local variable as module with dfhack.script_environment("gui/indicator_screen"), originally created to support a front-end for
relations-indicator, to be saved in /hack/scripts/gui as indicator_screen.lua.
There are two functions for that purpose. isWideView(), which returns true if the side menu is wide, false if it is thin and nil if neither apply.
And getScreen, which accepts the following arguments:
1: A table with 1 to N tables ([] values being optional) of
{text[, color][,onclick ][, onrclick][, notEndOfLine]
[, onhovertext][, onhoverfunction]},
where text is text or function that returns text, color is
number/pen or function that returns it, onclick and onrclick
are functions to be called when the text is (right-)clicked,
notEndOfLine being true continues next text on same line,
onhovertext being a table with text and color used on hover,
and onhoverfunction is function called on hover. Table can
be changed after creation, and color/onclick/onrclick
/onhoverfunction can also be applied to whole table.
2: Optional table that optionally contains x, y, width and
height for text display. Places the text by upper left
corner at x,y. Calculates height and width from 1 if not set.
3: Optional table like the above for frame boundary.
If width or height are not set, uses DF's height and width.
If left out, then frame boundary is not drawn.
:lua dfhack.script_environment("gui/indicator_screen").getScreen({{text = "Hello ", color = function() return 2 end, onclick = function() print("clicked") end, onrclick = function() print("right-clicked") end, notEndOfLine = true}, {text =function() return "Everyone" end, onhovertext = {text = "World", color = 12}, onhoverfunction = function() print("hovered") end }}, {x = 5, y= 15}, {x = 4, y = 14, width=16, height = 3}):show()
getScreen will return a gui.FramedScreen element with some additional functions:
adjustDims(affectsText,x,y,w,h) - meant for resizing
onHelp() - dismisses the screen on ?
removeFromView([dissmiss_when]) - [dismisses in n ticks]
And also internally implements beyond default FramedScreen:
inheritBindings()
clearBindings()
onDestroy()
onGetSelectedJob()
onGetSelectedUnit()
onInput(keys)
onRenderBody()
onRenderFrame()
onResize()
onShow()
setRects(textrect, framerect)
The screen will also have public values affecting behaviour:
signature: false will not paint, nil will paint light gray on light gray, true is default
signature_text: Text used as signature if there's no frame
binding_inherit:
How it inherits keybindings on parent viewscreen. Options are "hook", "keybinding", "none".
dismiss_on_zoom: false will instead append screen to grandparent and dismiss parent screen on most keys that leave view.
dismiss_ordered: to be set in other scripts to dismiss screen when viewsceen changes and nonblinky_dismiss is true
nonblinky_dismiss: default evaluates by fps/gfps > 1+number stacked screens and does nothing
onStateChangeKey: dfhack.onStateChange function key to dismiss screen on viewscreen change.
indicator_screen_version: numerical value of current version.
The whole script can also accepts arguments: help/? to explain itself or execute_hook <valid dfhack command>.
The second basically takes bottom indicator screen, removes it, waits a frame, executes command, and then places bottom indicator screen back on top. Used when binding_inherit = "hook" (default) as a mediator for keybinding in screen context, due most scripts and plugins refusing to work when screen is on top (even if they could).
There are still some (potential) issues with the script:
- It can't indicate things unpaused, nor can it remain present when one escapes to save menu in main screen.
- The recognized zooming keys list might be incomplete.
- I forgot where, but I think there were some menus where +,-,*,/ affecting cursor/view wasn't countered.
- Some gui plugins, such as auto-melt and automaterial, will not display their gui elements or work when the screen is up. Others, such as search and tweak, work. Not that you can't access, say, auto-melt's backend data to duplicate functionality if you wish.
- onhovertext doesn't natively expand the clip area if it will not fit, though you can use onhoverfunction to expand it by the difference between #text and #onhovertext.text.
Changelogs Removed isDismissed() sanity check on inactive window, as that wasn't permitted (though dismissing was).
isWideView() changed to detect whether game uses two-element array under menu width or separate map width and menu width variables (needed to support 44.09).
1) Fixed +- scrolling moving around cursor in build/material menu
2) For generating width from data, converts text values tostring if they're not functions - this allows numerical entries.
3) Moved whole-body onhoverfunc from attribute of self to attribute of dynamic_text_table and made it to be called only once per frame.
4) added internal versioning, available at indicator_screen_version variable.
Old versions~
1.2 ~
~
1.1 ~
~
1.0 ~