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