z_mirror/TaskList

git clone https://git.raiguard.me/z_mirror/TaskList

raiguardStart adding task details GUIbbcaa7a

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