z_mirror/BlueprintTools

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

Caleb HeuerUpdate to Factorio 2.1bf73278

trunk
2.1 KiB70 linesraw
1local gui = require("gui")
2local mod_gui = require("__core__.lualib.mod-gui")
3
4local buttons_gui = {}
5
6local function mod_gui_button(player_settings, color, action)
7  local internal_name = string.gsub(string.gsub(action, "bpt_", ""), "_", "-")
8
9  local setting = player_settings["show_" .. action]
10  if setting then
11    return {
12      type = "sprite-button",
13      style = "bpt_mod_gui_button_" .. color,
14      sprite = "bpt_" .. action .. "_white",
15      tooltip = { "gui.bpt-" .. internal_name .. "-tooltip" },
16      elem_mods = { visible = false },
17      actions = {
18        on_click = { gui = "buttons", action = action },
19      },
20      ref = { action },
21    }
22  else
23    return {}
24  end
25end
26
27function buttons_gui.refresh(player, player_table)
28  local button_flow = mod_gui.get_button_flow(player)
29
30  local player_settings = player_table.settings
31
32  for _, button in pairs(player_table.guis.blueprint_buttons or {}) do
33    button.destroy()
34  end
35  player_table.guis.blueprint_buttons = gui.build(button_flow, {
36    mod_gui_button(player_settings, "blue", "swap_wire_colors"),
37    mod_gui_button(player_settings, "blue", "set_tiles"),
38    mod_gui_button(player_settings, "blue", "configure"),
39  })
40
41  for _, button in pairs(player_table.guis.upgrade_planner_buttons or {}) do
42    button.destroy()
43  end
44  player_table.guis.upgrade_planner_buttons = gui.build(button_flow, {
45    mod_gui_button(player_settings, "green", "configure"),
46  })
47
48  for _, button in pairs(player_table.guis.deconstruction_planner_buttons or {}) do
49    button.destroy()
50  end
51  player_table.guis.deconstruction_planner_buttons = gui.build(button_flow, {
52    mod_gui_button(player_settings, "red", "configure"),
53  })
54end
55
56function buttons_gui.show(player_table, button_type)
57  for _, button in pairs(player_table.guis[button_type .. "_buttons"]) do
58    button.visible = true
59  end
60  player_table.flags[button_type .. "_buttons_shown"] = true
61end
62
63function buttons_gui.hide(player_table, button_type)
64  for _, button in pairs(player_table.guis[button_type .. "_buttons"]) do
65    button.visible = false
66  end
67  player_table.flags[button_type .. "_buttons_shown"] = false
68end
69
70return buttons_gui