set-goal/control.lua

changeset 3
b0344856f104
parent 0
11962c90f1b8
--- a/set-goal/control.lua	Sun Jun 29 18:27:00 2025 +0300
+++ b/set-goal/control.lua	Sun Jun 29 18:27:23 2025 +0300
@@ -8,9 +8,20 @@
 			caption = {"set-goal-gui.title"},
 			direction = "vertical"
 		}
+		local goal_description_text = player.get_goal_description()
+		if type(goal_description_text) == "table"
+		then
+			local translation_request_id = player.request_translation(goal_description_text)
+			goal_description_text = ""
+			if not storage.translation_requests
+			then
+				storage.translation_requests = {}
+			end
+			storage.translation_requests[translation_request_id] = {player_index=event.player_index, type = "goal-description"}
+		end
 		frame.add{
 			type = "text-box",
-			text = player.get_goal_description(),
+			text = goal_description_text,
 			name = "goal-description",
 			style = "set-goal-gui-textbox",
 			icon_selector = true,
@@ -50,7 +61,7 @@
 		then
 			if event.element.tags.action == "confirm"
 			then
-				player.set_goal_description(player.gui.goal["set-goal"]["goal-description"].text)
+				player.set_goal_description(player.gui.goal["set-goal"]["goal-description"].text, player.get_goal_description() ~= "")
 				player.gui.goal["set-goal"].destroy()
 			elseif event.element.tags.action == "close"
 			then
@@ -69,4 +80,19 @@
 			open_gui(event)
 		end
 	end
+)
+
+script.on_event(defines.events.on_string_translated,
+	function(event)
+		local player = game.players[event.player_index]
+		if storage.translation_requests
+		then
+			local request_data = storage.translation_requests[event.id]
+			if request_data and request_data.type == "goal-description" and player.gui.goal["set-goal"] and player.gui.goal["set-goal"]["goal-description"]
+			then
+				player.gui.goal["set-goal"]["goal-description"].text = event.result
+			end
+			storage.translation_requests[event.id] = nil
+		end
+	end
 )
\ No newline at end of file

mercurial