Wed, 02 Jul 2025 14:28:57 +0300
Add fusion lab (currently v1.2.3)
0 | 1 | local function open_gui(event) |
2 | local player = game.players[event.player_index] | |
3 | if not player.gui.goal["set-goal"] | |
4 | then | |
5 | local frame = player.gui.goal.add{ | |
6 | type = "frame", | |
7 | name = "set-goal", | |
8 | caption = {"set-goal-gui.title"}, | |
9 | direction = "vertical" | |
10 | } | |
3 | 11 | local goal_description_text = player.get_goal_description() |
12 | if type(goal_description_text) == "table" | |
13 | then | |
14 | local translation_request_id = player.request_translation(goal_description_text) | |
15 | goal_description_text = "" | |
16 | if not storage.translation_requests | |
17 | then | |
18 | storage.translation_requests = {} | |
19 | end | |
20 | storage.translation_requests[translation_request_id] = {player_index=event.player_index, type = "goal-description"} | |
21 | end | |
0 | 22 | frame.add{ |
23 | type = "text-box", | |
3 | 24 | text = goal_description_text, |
0 | 25 | name = "goal-description", |
26 | style = "set-goal-gui-textbox", | |
27 | icon_selector = true, | |
28 | } | |
29 | local buttons_flow = frame.add{ | |
30 | type = "flow", | |
31 | name = "buttons-flow", | |
32 | direction = "horizontal", | |
33 | } | |
34 | buttons_flow.add{ | |
35 | type = "sprite-button", | |
36 | tooltip = {"set-goal-gui.close-tooltip"}, | |
37 | style = "tool_button_red", | |
38 | sprite = 'utility.close', | |
39 | name = "close-button", | |
40 | tags = {["owner-mod"] = "set-goal", action="close"}, | |
41 | } | |
42 | buttons_flow.add{ | |
43 | type = "sprite-button", | |
44 | tooltip = {"set-goal-gui.confirm-tooltip"}, | |
45 | style = "confirm_button", | |
46 | name = "confirm-button", | |
47 | sprite = "utility.confirm_slot", | |
48 | tags = {["owner-mod"] = "set-goal", action="confirm"}, | |
49 | } | |
50 | else | |
51 | player.gui.goal["set-goal"].destroy() | |
52 | end | |
53 | end | |
54 | ||
55 | script.on_event(defines.events.on_gui_click, | |
56 | function(event) | |
57 | local player = game.players[event.player_index] | |
58 | if player.gui.goal["set-goal"] | |
59 | and event.element.tags | |
60 | and event.element.tags["owner-mod"] == "set-goal" | |
61 | then | |
62 | if event.element.tags.action == "confirm" | |
63 | then | |
3 | 64 | player.set_goal_description(player.gui.goal["set-goal"]["goal-description"].text, player.get_goal_description() ~= "") |
0 | 65 | player.gui.goal["set-goal"].destroy() |
66 | elseif event.element.tags.action == "close" | |
67 | then | |
68 | player.gui.goal["set-goal"].destroy() | |
69 | end | |
70 | end | |
71 | end | |
72 | ) | |
73 | ||
74 | script.on_event("open-set-goal-gui", open_gui) | |
75 | ||
76 | script.on_event(defines.events.on_lua_shortcut, | |
77 | function(event) | |
78 | if event.prototype_name == "open-set-goal-gui" | |
79 | then | |
80 | open_gui(event) | |
81 | end | |
82 | end | |
3 | 83 | ) |
84 | ||
85 | script.on_event(defines.events.on_string_translated, | |
86 | function(event) | |
87 | local player = game.players[event.player_index] | |
88 | if storage.translation_requests | |
89 | then | |
90 | local request_data = storage.translation_requests[event.id] | |
91 | if request_data and request_data.type == "goal-description" and player.gui.goal["set-goal"] and player.gui.goal["set-goal"]["goal-description"] | |
92 | then | |
93 | player.gui.goal["set-goal"]["goal-description"].text = event.result | |
94 | end | |
95 | storage.translation_requests[event.id] = nil | |
96 | end | |
97 | end | |
0 | 98 | ) |