Skip to content

Commit 0a6378d

Browse files
committed
Periodic orders change detection
1 parent 5cfb0c7 commit 0a6378d

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

plugins/lua/orders.lua

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,10 @@ end
715715
--
716716

717717
local search_cursor_visible = false
718-
local order_count_at_highlight = 0
719718
local search_matched_indices = {}
720719
local search_current_match_idx = 0
720+
local order_names_checksum = nil
721+
local search_overlay_instance = nil
721722

722723
local function perform_search(text)
723724
local matches = {}
@@ -738,6 +739,19 @@ local function perform_search(text)
738739
return matches
739740
end
740741

742+
local function calculate_order_names_checksum()
743+
local orders = df.global.world.manager_orders.all
744+
if #orders == 0 then return "" end
745+
746+
local names = {}
747+
for i = 0, #orders - 1 do
748+
local name = dfhack.job.getManagerOrderName(orders[i])
749+
table.insert(names, name or "")
750+
end
751+
752+
return table.concat(names, "|")
753+
end
754+
741755
OrdersSearchOverlay = defclass(OrdersSearchOverlay, overlay.OverlayWidget)
742756
OrdersSearchOverlay.ATTRS{
743757
desc='Adds a search box to find and navigate to matching manager orders.',
@@ -814,15 +828,16 @@ function OrdersSearchOverlay:init()
814828
}
815829

816830
self.minimized = false
831+
search_overlay_instance = self
817832
end
818833

819-
function OrdersSearchOverlay:update_filter(text)
834+
function OrdersSearchOverlay:update_filter()
835+
local text = self.subviews.filter.text
820836
search_matched_indices = perform_search(text)
821837
search_current_match_idx = 0
822838

823839
if #search_matched_indices > 0 then
824840
search_cursor_visible = true
825-
order_count_at_highlight = #df.global.world.manager_orders.all
826841
else
827842
search_cursor_visible = false
828843
end
@@ -872,7 +887,6 @@ function OrdersSearchOverlay:cycle_match(direction)
872887
local order_idx = search_matched_indices[search_current_match_idx]
873888
mi.info.work_orders.scroll_position_work_orders = order_idx
874889
search_cursor_visible = true
875-
order_count_at_highlight = #df.global.world.manager_orders.all
876890

877891
self.subviews.main_panel.frame_title = 'Search' .. self:get_match_text()
878892
end
@@ -953,6 +967,8 @@ local LIST_START_Y_ONE_TABS_ROW = 8
953967
local LIST_START_Y_TWO_TABS_ROWS = 10
954968
local BOTTOM_MARGIN = 9
955969
local ARROW_X = 10
970+
local CHECK_FRAME_INTERVAL = 50
971+
local check_frame_counter = 0
956972

957973
local function getListStartY()
958974
local rect = gui.get_interface_rect()
@@ -1024,11 +1040,20 @@ function OrderHighlightOverlay:render(dc)
10241040

10251041
if mi.job_details.open or not search_cursor_visible then return end
10261042

1027-
-- Hide cursor when order list changes (orders added or removed)
1028-
local current_order_count = #df.global.world.manager_orders.all
1029-
if order_count_at_highlight ~= current_order_count then
1030-
search_cursor_visible = false
1031-
return
1043+
-- Periodic check for order name changes
1044+
check_frame_counter = check_frame_counter + 1
1045+
if check_frame_counter >= CHECK_FRAME_INTERVAL then
1046+
check_frame_counter = 0
1047+
1048+
local new_checksum = calculate_order_names_checksum()
1049+
if new_checksum ~= order_names_checksum then
1050+
order_names_checksum = new_checksum
1051+
1052+
-- Auto re-run search if active
1053+
if search_overlay_instance and not search_overlay_instance.minimized then
1054+
search_overlay_instance:update_filter()
1055+
end
1056+
end
10321057
end
10331058

10341059
-- Draw highlight arrows for all matches in viewport

0 commit comments

Comments
 (0)