Skip to content

Commit f8e9af5

Browse files
committed
Move periodic order change detection to SearchOverlay using overlay_onupdate
1 parent 8c8d3fc commit f8e9af5

1 file changed

Lines changed: 11 additions & 23 deletions

File tree

plugins/lua/orders.lua

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ end
717717
local search_matched_indices = {}
718718
local search_current_match_idx = 0
719719
local order_names_checksum = nil
720-
local search_overlay_instance = nil
721720

722721
local function perform_search(text)
723722
local matches = {}
@@ -758,6 +757,7 @@ OrdersSearchOverlay.ATTRS{
758757
default_enabled=true,
759758
viewscreens='dwarfmode/Info/WORK_ORDERS/Default',
760759
frame={w=26, h=4},
760+
overlay_onupdate_max_freq_seconds=1,
761761
}
762762

763763
function OrdersSearchOverlay:init()
@@ -827,7 +827,16 @@ function OrdersSearchOverlay:init()
827827
}
828828

829829
self.minimized = false
830-
search_overlay_instance = self
830+
end
831+
832+
function OrdersSearchOverlay:overlay_onupdate()
833+
if self.minimized then return end
834+
835+
local new_checksum = calculate_order_names_checksum()
836+
if new_checksum ~= order_names_checksum then
837+
order_names_checksum = new_checksum
838+
self:update_filter()
839+
end
831840
end
832841

833842
function OrdersSearchOverlay:update_filter()
@@ -958,8 +967,6 @@ local LIST_START_Y_ONE_TABS_ROW = 8
958967
local LIST_START_Y_TWO_TABS_ROWS = 10
959968
local BOTTOM_MARGIN = 9
960969
local ARROW_X = 10
961-
local CHECK_FRAME_INTERVAL = 50
962-
local check_frame_counter = 0
963970

964971
local function getListStartY()
965972
local rect = gui.get_interface_rect()
@@ -1031,25 +1038,6 @@ function OrderHighlightOverlay:render(dc)
10311038

10321039
if mi.job_details.open or #search_matched_indices == 0 then return end
10331040

1034-
-- Periodic check for order name changes
1035-
check_frame_counter = check_frame_counter + 1
1036-
if check_frame_counter >= CHECK_FRAME_INTERVAL then
1037-
check_frame_counter = 0
1038-
1039-
local new_checksum = calculate_order_names_checksum()
1040-
if new_checksum ~= order_names_checksum then
1041-
order_names_checksum = new_checksum
1042-
1043-
-- Auto re-run search if active
1044-
if search_overlay_instance and not search_overlay_instance.minimized then
1045-
search_overlay_instance:update_filter()
1046-
end
1047-
end
1048-
end
1049-
1050-
-- Draw highlight arrows for all matches in viewport
1051-
if #search_matched_indices == 0 then return end
1052-
10531041
local selected_pen = dfhack.pen.parse{
10541042
fg=COLOR_BLACK,
10551043
bg=COLOR_WHITE,

0 commit comments

Comments
 (0)