set-goal/control.lua

changeset 3
b0344856f104
parent 0
11962c90f1b8
equal deleted inserted replaced
2:415dcf69f5f5 3:b0344856f104
6 type = "frame", 6 type = "frame",
7 name = "set-goal", 7 name = "set-goal",
8 caption = {"set-goal-gui.title"}, 8 caption = {"set-goal-gui.title"},
9 direction = "vertical" 9 direction = "vertical"
10 } 10 }
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
11 frame.add{ 22 frame.add{
12 type = "text-box", 23 type = "text-box",
13 text = player.get_goal_description(), 24 text = goal_description_text,
14 name = "goal-description", 25 name = "goal-description",
15 style = "set-goal-gui-textbox", 26 style = "set-goal-gui-textbox",
16 icon_selector = true, 27 icon_selector = true,
17 } 28 }
18 local buttons_flow = frame.add{ 29 local buttons_flow = frame.add{
48 and event.element.tags 59 and event.element.tags
49 and event.element.tags["owner-mod"] == "set-goal" 60 and event.element.tags["owner-mod"] == "set-goal"
50 then 61 then
51 if event.element.tags.action == "confirm" 62 if event.element.tags.action == "confirm"
52 then 63 then
53 player.set_goal_description(player.gui.goal["set-goal"]["goal-description"].text) 64 player.set_goal_description(player.gui.goal["set-goal"]["goal-description"].text, player.get_goal_description() ~= "")
54 player.gui.goal["set-goal"].destroy() 65 player.gui.goal["set-goal"].destroy()
55 elseif event.element.tags.action == "close" 66 elseif event.element.tags.action == "close"
56 then 67 then
57 player.gui.goal["set-goal"].destroy() 68 player.gui.goal["set-goal"].destroy()
58 end 69 end
68 then 79 then
69 open_gui(event) 80 open_gui(event)
70 end 81 end
71 end 82 end
72 ) 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
98 )

mercurial