z_mirror/TaskList
git clone https://git.raiguard.me/z_mirror/TaskList
fa77a7d
task-details-gui
1local constants =require ( "constants" ) 2 3local edit_task_gui =require ( "scripts.gui.edit-task.index" ) 4local util =require ( "scripts.util" ) 5 6local actions ={} 7 8--- @param Gui TaskGui 9function actions . close ( Gui ) 10Gui : destroy () 11end 12 13--- @param Gui TaskGui 14--- @param e on_gui_click 15function actions . recenter ( Gui , _ , e ) 16if e . button == defines . mouse_button_type . middle then 17Gui . refs . window . force_auto_center () 18end 19end 20 21--- @param Gui TasksGui 22--- @param e on_gui_checked_state_changed 23function actions . toggle_show_completed ( Gui , _ , e ) 24local state =Gui . state 25state . show_completed =not state . show_completed 26e . element . state =state . show_completed 27 28Gui : update_show_completed () 29end 30 31--- @param Gui TasksGui 32function actions . edit_task ( Gui , msg ) 33if not util . get_gui ( Gui . player . index , "edit_task" ) then 34local Task =msg . task_id and global . tasks [ msg . task_id ] or nil 35local ParentTask =msg . parent_task_id and global . tasks [ msg . parent_task_id ] or nil 36edit_task_gui . new ( Gui . player , Gui . player_table , { 37parent_gui =Gui , 38task =Task , 39parent_task =ParentTask , 40} ) 41end 42end 43 44--- @param Gui TasksGui 45--- @param msg table 46--- @param e on_gui_checked_state_changed 47function actions . toggle_task_completed ( Gui , msg , e ) 48local task_id =msg . task_id 49 50local Task =global . tasks [ task_id ] 51if Task then 52Task : toggle_completed () 53end 54end 55 56--- @param Gui TasksGui 57--- @param e on_gui_click 58function actions . expand_task ( Gui , _ , e ) 59local elem =e . element 60local details_flow =elem . parent . parent . details_flow 61 62if e . control or e . shift then 63local our_index =elem . parent . parent . get_index_in_parent () 64local delta =e . shift and 1 or - 1 65elem . parent . parent . parent . swap_children ( our_index + delta , our_index ) 66return 67end 68 69details_flow . visible =not details_flow . visible 70if details_flow . visible then 71elem . sprite ="tlst_arrow_down" 72else 73elem . sprite ="tlst_arrow_right" 74end 75end 76 77--- @param Gui TasksGui 78--- @param e on_gui_switch_state_changed 79function actions . toggle_tasks_mode ( Gui , _ , e ) 80local visible =e . element . switch_state == "left" and "force" or "private" 81 82Gui . refs . force_flow . visible =visible == "force" 83Gui . refs . private_flow . visible =visible == "private" 84end 85 86--- @param Gui TasksGui 87--- @param msg table 88--- @param e on_gui_click 89function actions . move_task ( Gui , msg , e ) 90local delta =msg . delta 91local task_id =msg . task_id 92 93local Task =global . tasks [ task_id ] 94if Task then 95Task : move ( delta ) 96end 97end 98 99--- @param Gui TasksGui 100--- @param msg table 101function actions . cycle_task_status ( Gui , msg ) 102local Task =global . tasks [ msg . task_id ] 103if Task then 104local current =Task . status 105local next =next ( constants . task_status , current ) or next ( constants . task_status ) 106Task . status =next 107 108Task : update_guis ( function ( Gui ) 109Gui : update_task ( Task ) 110end ) 111end 112end 113 114--- @param Gui TasksGui 115--- @param msg table 116function actions . open_task_gui ( Gui , msg ) 117local Task =global . tasks [ msg . task_id ] 118if Task then 119local TaskGui =Gui . player_table . guis . task [ msg . task_id ] 120if not TaskGui then 121game . ( "REQUIRE LOOP BABY" ) 122-- TaskGui = task_gui.new(Gui.player, Gui.player_table, Task) 123end 124-- TODO: 125end 126end 127 128return actions