z_mirror/TaskList
git clone https://git.raiguard.me/z_mirror/TaskList
125cb06
fix/blueprint-sandboxes-force
1local gui =require ( "__flib__/gui" ) 2local mod_gui =require ( "__core__/lualib/mod-gui" ) 3 4local active_task_button ={} 5 6--- @param player LuaPlayer 7--- @param player_table PlayerTable 8function active_task_button . build ( player , player_table ) 9local button =player_table . guis . active_task_button 10if not button or not button . valid then 11button =gui . add ( mod_gui . get_button_flow ( player ), { 12type ="button" , 13style =mod_gui . button_style , 14style_mods ={ left_padding =8 , right_padding =8 } , 15actions ={ 16on_click ={ gui ="tasks" , action ="toggle" } , 17} , 18} ) 19 20player_table . guis . active_task_button =button 21end 22 23active_task_button . update ( player , player_table ) 24end 25 26--- @param player LuaPlayer 27--- @param Task Task 28--- @return boolean 29local function can_show_task ( player , Task ) 30if not Task then 31return false 32end 33if Task . status ~= "in_progress" then 34return false 35end 36if player . mod_settings [ "tlst-active-filter-assigned" ]. value then 37if Task . assignee == nil then 38return false 39end 40return Task . assignee . index == player . index 41end 42 43return true 44end 45 46--- @param player LuaPlayer 47--- @param player_table PlayerTable 48function active_task_button . update ( player , player_table ) 49local button =player_table . guis . active_task_button 50if button and button . valid then 51local tasks 52if player . mod_settings [ "tlst-show-active-task" ]. value == "force" then 53tasks =global . forces [ player . force . index ]. tasks 54else 55tasks =player_table . tasks 56end 57-- The "active" task is the first top-level active task we come across 58for _ , task_id in pairs ( tasks ) do 59local Task =global . tasks [ task_id ] 60if can_show_task ( player , Task ) then 61button . caption =Task . title 62return 63end 64end 65button . caption ={ "gui.tlst-no-active-task" } 66end 67end 68 69--- @param player_table PlayerTable 70function active_task_button . destroy ( player_table ) 71local button =player_table . guis . active_task_button 72if button then 73if button . valid then 74button . destroy () 75end 76player_table . guis . active_task_button =nil 77end 78end 79 80return active_task_button