z_mirror/TaskList
git clone https://git.raiguard.me/z_mirror/TaskList
c5cc477
trunk
1local constants =require ( "constants" ) 2 3local task =require ( "scripts.task" ) 4local util =require ( "scripts.util" ) 5 6local actions ={} 7 8--- @param Gui EditTaskGui 9function actions . close ( Gui ) 10if Gui . state . just_confirmed then 11Gui . state . just_confirmed =false 12Gui . player . opened =Gui . refs . window 13else 14Gui : destroy () 15end 16end 17 18--- @param Gui EditTaskGui 19function actions . recenter ( Gui ) 20Gui . refs . window . force_auto_center () 21end 22 23--- @param Gui EditTaskGui 24function actions . update_assignee_dropdown ( Gui ) 25local dropdown =Gui . refs . assignee_dropdown 26 27local is_private =Gui . refs . private_checkbox . state 28if is_private then 29dropdown . enabled =false 30dropdown . selected_index =Gui . state . player_selection_index --[[@as uint]] 31else 32dropdown . enabled =true 33end 34end 35 36--- @param Gui EditTaskGui 37--- @param e EventData.on_gui_confirmed|EventData.CustomInputEvent 38function actions . confirm ( Gui , _ , e ) 39local refs =Gui . refs 40local clicked =e . name == defines . events . on_gui_confirmed or e . name == defines . events . on_gui_click 41 42local title =refs . title_textfield . text 43if # title == 0 then 44util . error_text ( Gui . player , { "message.tlst-task-must-have-title" } ) 45if not clicked then 46Gui . state . just_confirmed =true 47end 48return 49end 50 51local assignee 52local assignee_dropdown =refs . assignee_dropdown 53local selected_index =assignee_dropdown . selected_index 54if selected_index > 1 then 55assignee =game . players [ assignee_dropdown . items [ selected_index ]] 56end 57 58local status_index =refs . status_dropdown . selected_index 59local status 60for status_name , status_info in pairs ( constants . task_status ) do 61if status_info . index == status_index then 62status =status_name 63end 64end 65 66local Task =Gui . state . task 67if Task then 68Task : update ( refs . title_textfield . text , refs . description_textfield . text , assignee , status ) 69else 70--- @type LuaForce|LuaPlayer|Task 71local owner =Gui . state . parent_task 72if not owner then 73local is_private =refs . private_checkbox . state 74owner =is_private and Gui . player or util . get_force ( Gui . player ) 75end 76 77task . new ( 78refs . title_textfield . text , 79refs . description_textfield . text , 80owner , 81assignee , 82status , 83refs . add_to_top_checkbox . state 84) 85end 86 87if clicked then 88Gui : destroy () 89end 90end 91 92--- @param Gui EditTaskGui 93function actions . delete ( Gui ) 94local Task =Gui . state . task 95if Task then 96Task : delete () 97end 98 99Gui : destroy () 100end 101 102return actions