11-- Show tooltips on units and/or mouse
22
3+ -- @ module = true
4+
35local RELOAD = false -- set to true when actively working on this script
46
57local gui = require (' gui' )
68local widgets = require (' gui.widgets' )
9+ local overlay = require (' plugins.overlay' )
710local ResizingPanel = require (' gui.widgets.containers.resizing_panel' )
811
912---- ----------------------------------------------------------------------------
1013
11- local follow_units = true ;
12- local follow_mouse = true ;
14+ config = config or {
15+ follow_units = true ,
16+ follow_mouse = true ,
17+ }
1318local function change_follow_units (new , old )
14- follow_units = new
19+ config . follow_units = new
1520end
1621local function change_follow_mouse (new , old )
17- follow_mouse = new
22+ config . follow_mouse = new
1823end
1924
2025local shortenings = {
@@ -25,6 +30,22 @@ local shortenings = {
2530
2631local TITLE = " Tooltips"
2732
33+ if RELOAD then TooltipControlScreen = nil end
34+ TooltipControlScreen = defclass (TooltipControlScreen , gui .ZScreen )
35+ TooltipControlScreen .ATTRS {
36+ focus_path = " TooltipControlScreen" ,
37+ pass_movement_keys = true ,
38+ }
39+
40+ function TooltipControlScreen :init ()
41+ local controls = TooltipControlWindow {view_id = ' controls' }
42+ self :addviews {controls }
43+ end
44+
45+ function TooltipControlScreen :onDismiss ()
46+ view = nil
47+ end
48+
2849if RELOAD then TooltipControlWindow = nil end
2950TooltipControlWindow = defclass (TooltipControlWindow , widgets .Window )
3051TooltipControlWindow .ATTRS {
@@ -130,7 +151,7 @@ function MouseTooltip:init()
130151end
131152
132153function MouseTooltip :render (dc )
133- if not follow_mouse then return end
154+ if not config . follow_mouse then return end
134155
135156 local x , y = dfhack .screen .getMousePos ()
136157 if not x then return end
@@ -149,22 +170,25 @@ function MouseTooltip:render(dc)
149170end
150171
151172---- ----------------------------------------------------------------------------
152-
153- if RELOAD then TooltipsVizualizer = nil end
154- TooltipsVizualizer = defclass (TooltipsVizualizer , gui .ZScreen )
155- TooltipsVizualizer .ATTRS {
156- focus_path = ' TooltipsVizualizer' ,
157- pass_movement_keys = true ,
173+ if RELOAD then TooltipsOverlay = nil end
174+ TooltipsOverlay = defclass (TooltipsOverlay , overlay .OverlayWidget )
175+ TooltipsOverlay .ATTRS {
176+ desc = ' Adds tooltips with some info to units.' ,
177+ default_pos = {x = 1 ,y = 1 },
178+ default_enabled = true ,
179+ fullscreen = true , -- not player-repositionable
180+ viewscreens = {
181+ ' dwarfmode/Default' ,
182+ },
158183}
159184
160- function TooltipsVizualizer :init ()
161- local controls = TooltipControlWindow {view_id = ' controls' }
185+ function TooltipsOverlay :init ()
162186 local tooltip = MouseTooltip {view_id = ' tooltip' }
163- self :addviews {controls , tooltip }
187+ self :addviews {tooltip }
164188end
165189
166190-- map coordinates -> interface layer coordinates
167- function GetScreenCoordinates (map_coord )
191+ local function GetScreenCoordinates (map_coord )
168192 if not map_coord then return end
169193 -- -> map viewport offset
170194 local vp = df .global .world .viewport
@@ -195,10 +219,10 @@ function GetScreenCoordinates(map_coord)
195219 end
196220end
197221
198- function TooltipsVizualizer : onRenderFrame (dc , rect )
199- TooltipsVizualizer .super .onRenderFrame (self , dc , rect )
222+ function TooltipsOverlay : render (dc )
223+ TooltipsOverlay .super .render (self , dc )
200224
201- if not follow_units then return end
225+ if not config . follow_units then return end
202226
203227 if not dfhack .screen .inGraphicsMode () and not gui .blink_visible (500 ) then
204228 return
@@ -282,12 +306,21 @@ function TooltipsVizualizer:onRenderFrame(dc, rect)
282306 end
283307end
284308
285- function TooltipsVizualizer :onDismiss ()
286- view = nil
309+ function TooltipsOverlay :preUpdateLayout (parent_rect )
310+ self .frame .w = parent_rect .width
311+ self .frame .h = parent_rect .height
287312end
288313
289314---- ------------------------------------------------------------
290315
316+ OVERLAY_WIDGETS = {
317+ tooltips = TooltipsOverlay ,
318+ }
319+
320+ if dfhack_flags .module then
321+ return
322+ end
323+
291324if not dfhack .isMapLoaded () then
292325 qerror (' gui/tooltips requires a map to be loaded' )
293326end
@@ -297,4 +330,4 @@ if RELOAD and view then
297330 -- view is nil now
298331end
299332
300- view = view and view :raise () or TooltipsVizualizer {}:show ()
333+ view = view and view :raise () or TooltipControlScreen {}:show ()
0 commit comments