Better code reuse with info.lua

develop
Ryan Dwyer 2023-11-10 13:56:14 -08:00
parent 7ba3ebe7a0
commit de727d04d0
2 changed files with 7 additions and 31 deletions

@ -364,7 +364,7 @@ function InfoOverlay:get_key()
end end
end end
local function resize_overlay(self) function resize_overlay(self)
local sw = dfhack.screen.getWindowSize() local sw = dfhack.screen.getWindowSize()
local overlay_width = math.min(40, sw-(self.frame_rect.x1 + 30)) local overlay_width = math.min(40, sw-(self.frame_rect.x1 + 30))
if overlay_width ~= self.frame.w then if overlay_width ~= self.frame.w then
@ -377,7 +377,7 @@ local function is_tabs_in_two_rows()
return dfhack.screen.readTile(64, 6, false).ch == 0 return dfhack.screen.readTile(64, 6, false).ch == 0
end end
local function get_panel_offsets() function get_panel_offsets()
local tabs_in_two_rows = is_tabs_in_two_rows() local tabs_in_two_rows = is_tabs_in_two_rows()
local shift_right = info.current_mode == df.info_interface_mode_type.ARTIFACTS or local shift_right = info.current_mode == df.info_interface_mode_type.ARTIFACTS or
info.current_mode == df.info_interface_mode_type.LABOR info.current_mode == df.info_interface_mode_type.LABOR
@ -386,7 +386,8 @@ local function get_panel_offsets()
if tabs_in_two_rows then if tabs_in_two_rows then
t_offset = shift_right and 0 or 3 t_offset = shift_right and 0 or 3
end end
if info.current_mode == df.info_interface_mode_type.JOBS then if info.current_mode == df.info_interface_mode_type.JOBS or
info.current_mode == df.info_interface_mode_type.BUILDINGS then
t_offset = t_offset - 1 t_offset = t_offset - 1
end end
return l_offset, t_offset return l_offset, t_offset

@ -2,6 +2,7 @@ local _ENV = mkmodule('plugins.sort.places')
local sortoverlay = require('plugins.sort.sortoverlay') local sortoverlay = require('plugins.sort.sortoverlay')
local locationselector = require('plugins.sort.locationselector') local locationselector = require('plugins.sort.locationselector')
local info_overlay = require('plugins.sort.info')
local widgets = require('gui.widgets') local widgets = require('gui.widgets')
local utils = require('utils') local utils = require('utils')
@ -155,35 +156,9 @@ function PlacesOverlay:get_key()
end end
end end
local function resize_overlay(self)
local sw = dfhack.screen.getWindowSize()
local overlay_width = math.min(40, sw-(self.frame_rect.x1 + 30))
if overlay_width ~= self.frame.w then
self.frame.w = overlay_width
return true
end
end
local function is_tabs_in_two_rows()
return dfhack.screen.readTile(64, 6, false).ch == 0
end
local function get_panel_offsets()
local tabs_in_two_rows = is_tabs_in_two_rows()
local l_offset = (not tabs_in_two_rows) and 4 or 0
local t_offset = 1
if tabs_in_two_rows then
t_offset = shift_right and 0 or 3
end
if info.current_mode == df.info_interface_mode_type.BUILDINGS then
t_offset = t_offset - 1
end
return l_offset, t_offset
end
function PlacesOverlay:updateFrames() function PlacesOverlay:updateFrames()
local ret = resize_overlay(self) local ret = info_overlay.resize_overlay(self)
local l, t = get_panel_offsets() local l, t = info_overlay.get_panel_offsets()
local frame = self.subviews.panel.frame local frame = self.subviews.panel.frame
if frame.l == l and frame.t == t then return ret end if frame.l == l and frame.t == t then return ret end
frame.l, frame.t = l, t frame.l, frame.t = l, t