z_mirror/TaskList

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

Caleb HeuerUpdate to Factorio 2.1083a3ed

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