@@ -59,6 +59,16 @@ function TooltipControlWindow:init()
5959 }
6060end
6161
62+ local function GetUnitHappiness (unit )
63+ -- keep in mind, this will look differently with game's font
64+ local mapToEmoticon = {[0 ] = " =C" , " :C" , " :(" , " :]" , " :)" , " :D" , " =D" }
65+ -- same as in ASCII mode, but for then middle (3), which is GREY instead of WHITE
66+ local mapToColor = {[0 ] = COLOR_RED , COLOR_LIGHTRED , COLOR_YELLOW , COLOR_GREY , COLOR_GREEN , COLOR_LIGHTGREEN , COLOR_LIGHTCYAN }
67+ local stressCat = dfhack .units .getStressCategory (unit )
68+ if stressCat > 6 then stressCat = 6 end
69+ return mapToEmoticon [stressCat ], mapToColor [stressCat ]
70+ end
71+
6272local function GetUnitJob (unit )
6373 local job = unit .job
6474 if job and job .current_job then
@@ -208,14 +218,17 @@ function TooltipsVizualizer:onRenderFrame(dc, rect)
208218 local used_tiles = {}
209219 for i = # units , 1 , - 1 do
210220 local unit = units [i ]
211- local txt = GetUnitJob (unit )
212- if not txt then goto continue end
213221
214- txt = shortenings [txt ] or txt
222+ local happiness , happyPen = GetUnitHappiness (unit )
223+ local job = GetUnitJob (unit )
224+ job = shortenings [job ] or job
225+ if not job and not happiness then goto continue end
215226
216227 local pos = xyz2pos (dfhack .units .getPosition (unit ))
217228 if not pos then goto continue end
218229
230+ local txt = table.concat ({happiness , job }, " " )
231+
219232 local scrPos = GetScreenCoordinates (pos )
220233 local y = scrPos .y - 1 -- subtract 1 to move the text over the heads
221234 local x = scrPos .x + oneTileOffset .x - 1 -- subtract 1 to move the text inside the map tile
@@ -249,10 +262,15 @@ function TooltipsVizualizer:onRenderFrame(dc, rect)
249262
250263 -- in case there isn't enough space, cut the text off
251264 if usedAt > 0 then
252- txt = txt :sub (0 , usedAt - 1 ) .. ' _'
265+ local s = happiness and # happiness + 1 or 0
266+ job = job :sub (0 , usedAt - s - 1 ) .. ' _'
267+ txt = txt :sub (0 , usedAt - 1 ) .. ' _' -- for marking
253268 end
254269
255- dc :seek (x , y + dy ):pen (pen ):string (txt )
270+ dc :seek (x , y + dy )
271+ :pen (happyPen ):string (happiness or " " )
272+ :string ((happiness and job ) and " " or " " )
273+ :pen (pen ):string (job or " " )
256274
257275 -- mark coordinates as used
258276 for j = 0 , # txt - 1 do
0 commit comments