z_mirror/TaskList
git clone https://git.raiguard.me/z_mirror/TaskList
fa77a7d
task-details-gui
1local table =require ( "__flib__.table" ) 2 3local util ={} 4 5--- Create a local flying text with an error sound. 6--- @param player LuaPlayer 7--- @param text LocalisedString 8function util . error_text ( player , text ) 9player . create_local_flying_text ( { create_at_cursor =true , text =text } ) 10player . play_sound ( { path ="utility/cannot_build" } ) 11end 12 13--- @class GuiIdent 14--- @field name string 15--- @field id string|number 16 17--- Safely retrieve the GUI for the given player. 18--- @param player_index number 19--- @param gui_ident string|GuiIdent 20--- @return TasksGui 21function util . get_gui ( player_index , gui_ident ) 22local player_table =global . players [ player_index ] 23if player_table then 24local Gui 25if type ( gui_ident ) == "table" then 26Gui =player_table . guis [ gui_ident . name ][ gui_ident . id ] 27else 28Gui =player_table . guis [ gui_ident ] 29end 30if Gui and Gui . refs . window . valid then 31return Gui 32end 33end 34end 35 36--- Update completed visibility for all subtasks 37--- @param flow LuaGuiElement 38--- @param to_state boolean 39function util . recursive_show_completed ( flow , to_state ) 40for _ , row in pairs ( flow . incompleted . children ) do --- @diagnostic disable-line 41util . recursive_show_completed ( row . details_flow . subtasks_flow , to_state ) 42end 43 44local completed_flow =flow . completed --- @diagnostic disable-line 45if to_state and # completed_flow . children > 0 then 46completed_flow . visible =true 47 48for _ , row in pairs ( completed_flow . children ) do 49util . recursive_show_completed ( row . details_flow . subtasks_flow , to_state ) 50end 51else 52completed_flow . visible =false 53end 54end 55 56function util . remove_task ( source , task_id ) 57table . remove ( source , table . find ( source , task_id )) 58end 59 60return util