z_mirror/BlueprintTools

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

raiguardSet tiles textfield is numericd05887e

clipboards
4.2 KiB129 linesraw
1local gui = require("__flib__.gui-beta")
2
3local set_tiles = require("scripts.processors.set-tiles")
4
5local set_tiles_gui = {}
6
7function set_tiles_gui.build(player, player_table)
8  local refs = gui.build(player.gui.screen, {
9    {
10      type = "frame",
11      direction = "vertical",
12      ref = {"window"},
13      actions = {
14        on_closed = {gui = "set_tiles", action = "close"},
15      },
16      children = {
17        {type = "flow", ref = {"titlebar_flow"}, children = {
18          {type = "label", style = "frame_title", caption = {"controls.bpt-set-tiles"}, ignored_by_interaction = true},
19          {type = "empty-widget", style = "flib_dialog_titlebar_drag_handle", ignored_by_interaction = true}
20        }},
21        {type = "frame", style = "inside_shallow_frame_with_padding", children = {
22          {
23            type = "choose-elem-button",
24            style = "slot_button_in_shallow_frame",
25            elem_type = "tile",
26            elem_filters = {{filter = "blueprintable"}},
27            actions = {
28              on_elem_changed = {gui = "set_tiles", action = "update_tile"}
29            },
30            ref = {"tile_button"}
31          },
32          {type = "line", style_mods = {left_margin = 8, vertically_stretchable = true}, direction = "vertical"},
33          {type = "flow", style_mods = {left_margin = 8}, direction = "vertical", children = {
34            {
35              type = "checkbox",
36              caption = {"bpt-gui.fill-gaps"},
37              tooltip = {"bpt-gui.fill-gaps-description"},
38              state = true,
39              ref = {"fill_gaps_checkbox"}
40            },
41            {type = "flow", style_mods = {vertical_align = "center"}, ref = {"margin_flow"}, children = {
42              {
43                type = "label",
44                style_mods = {right_margin = 8},
45                caption = {"bpt-gui.margin"},
46                tooltip = {"bpt-gui.margin-description"}
47              },
48              {
49                type = "textfield",
50                style_mods = {width = 50, horizontal_align = "center"},
51                text = "0",
52                numeric = true,
53                ref = {"margin_textfield"}
54              }
55            }}
56          }}
57        }},
58        {type = "flow", style = "dialog_buttons_horizontal_flow", children = {
59          {
60            type = "button",
61            style = "back_button",
62            caption = {"gui.cancel"},
63            actions = {
64              on_click = {gui = "set_tiles", action = "close"}
65            }
66          },
67          {
68            type = "empty-widget",
69            style = "flib_dialog_footer_drag_handle",
70            style_mods = {minimal_width = 24},
71            ref = {"footer_drag_handle"}
72          },
73          {
74            type = "button",
75            style = "confirm_button",
76            caption = {"gui.confirm"},
77            elem_mods = {enabled = false},
78            ref = {"confirm_button"},
79            actions = {
80              on_click = {gui = "set_tiles", action = "confirm"}
81            }
82          }
83        }}
84      }
85    }
86  })
87
88  refs.titlebar_flow.drag_target = refs.window
89  refs.footer_drag_handle.drag_target = refs.window
90  refs.window.force_auto_center()
91
92  player.opened = refs.window
93
94  player_table.guis.set_tiles = {
95    refs = refs
96  }
97end
98
99function set_tiles_gui.destroy(player_table)
100  local gui_data = player_table.guis.set_tiles
101  gui_data.refs.window.destroy()
102  player_table.guis.set_tiles = nil
103end
104
105function set_tiles_gui.handle_action(e, msg)
106  local player = game.get_player(e.player_index)
107  local player_table = global.players[e.player_index]
108  local gui_data = player_table.guis.set_tiles
109  local refs = gui_data.refs
110
111  if msg.action == "close" then
112    set_tiles_gui.destroy(player_table)
113  elseif msg.action == "confirm" then
114    local tile_name = refs.tile_button.elem_value
115    if tile_name then
116      set_tiles(player, tile_name, refs.fill_gaps_checkbox.state, tonumber(refs.margin_textfield.text))
117      set_tiles_gui.destroy(player_table)
118    end
119  elseif msg.action == "update_tile" then
120    local tile_name = refs.tile_button.elem_value
121    if tile_name then
122      refs.confirm_button.enabled = true
123    else
124      refs.confirm_button.enabled = false
125    end
126  end
127end
128
129return set_tiles_gui