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