Skip to content

Commit 0f6aeba

Browse files
authored
fix GetScreenCoordinates for ASCII mode
Also, simplify GetUnitJob
1 parent 0ca5a9a commit 0f6aeba

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

gui/tooltips.lua

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ local function GetUnitHappiness(unit)
7070
end
7171

7272
local function GetUnitJob(unit)
73-
local job = unit.job
74-
if job and job.current_job then
75-
return dfhack.job.getName(job.current_job)
76-
end
77-
return nil
73+
local job = unit.job.current_job
74+
return job and dfhack.job.getName(job)
7875
end
7976

8077
local function GetUnitNameAndJob(unit)
@@ -169,7 +166,6 @@ end
169166
-- map coordinates -> interface layer coordinates
170167
function GetScreenCoordinates(map_coord)
171168
if not map_coord then return end
172-
173169
-- -> map viewport offset
174170
local vp = df.global.world.viewport
175171
local vp_Coord = vp.window_x -- is actually coord
@@ -178,20 +174,25 @@ function GetScreenCoordinates(map_coord)
178174
y = map_coord.y - vp_Coord.y,
179175
z = map_coord.z - vp_Coord.z,
180176
}
181-
-- -> pixel offset
182-
local gps = df.global.gps
183-
local map_tile_pixels = gps.viewport_zoom_factor // 4;
184-
local screen_coord_px = {
185-
x = map_tile_pixels * map_offset_by_vp.x,
186-
y = map_tile_pixels * map_offset_by_vp.y,
187-
}
188-
-- -> interface layer coordinates
189-
local screen_coord_text = {
190-
x = math.ceil( screen_coord_px.x / gps.tile_pixel_x ),
191-
y = math.ceil( screen_coord_px.y / gps.tile_pixel_y ),
192-
}
193177

194-
return screen_coord_text
178+
if not dfhack.screen.inGraphicsMode() then
179+
return map_offset_by_vp
180+
else
181+
-- -> pixel offset
182+
local gps = df.global.gps
183+
local map_tile_pixels = gps.viewport_zoom_factor // 4;
184+
local screen_coord_px = {
185+
x = map_tile_pixels * map_offset_by_vp.x,
186+
y = map_tile_pixels * map_offset_by_vp.y,
187+
}
188+
-- -> interface layer coordinates
189+
local screen_coord_text = {
190+
x = math.ceil( screen_coord_px.x / gps.tile_pixel_x ),
191+
y = math.ceil( screen_coord_px.y / gps.tile_pixel_y ),
192+
}
193+
194+
return screen_coord_text
195+
end
195196
end
196197

197198
function TooltipsVizualizer:onRenderFrame(dc, rect)

0 commit comments

Comments
 (0)