Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: gui/indicator_screen [DFHack lua script] 1.21  (Read 2604 times)

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
gui/indicator_screen [DFHack lua script] 1.21
« on: September 15, 2017, 02:28:17 pm »

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.
 

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

Old versions
~ 1.2 ~
~ 1.1 ~
~ 1.0 ~
« Last Edit: July 06, 2018, 11:01:50 am by Fleeting Frames »
Logged