set-goal/control.lua

changeset 0
11962c90f1b8
child 3
b0344856f104
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/set-goal/control.lua	Sun Jun 29 16:11:41 2025 +0300
@@ -0,0 +1,72 @@
+local function open_gui(event)
+	local player = game.players[event.player_index]
+	if not player.gui.goal["set-goal"]
+	then
+		local frame = player.gui.goal.add{
+			type = "frame",
+			name = "set-goal",
+			caption = {"set-goal-gui.title"},
+			direction = "vertical"
+		}
+		frame.add{
+			type = "text-box",
+			text = player.get_goal_description(),
+			name = "goal-description",
+			style = "set-goal-gui-textbox",
+			icon_selector = true,
+		}
+		local buttons_flow = frame.add{
+			type = "flow",
+			name = "buttons-flow",
+			direction = "horizontal",
+		}
+		buttons_flow.add{
+			type = "sprite-button",
+			tooltip = {"set-goal-gui.close-tooltip"},
+			style = "tool_button_red",
+			sprite = 'utility.close',
+			name = "close-button",
+			tags = {["owner-mod"] = "set-goal", action="close"},
+		}
+		buttons_flow.add{
+			type = "sprite-button",
+			tooltip = {"set-goal-gui.confirm-tooltip"},
+			style = "confirm_button",
+			name = "confirm-button",
+			sprite = "utility.confirm_slot",	
+			tags = {["owner-mod"] = "set-goal", action="confirm"},
+		}
+	else
+		player.gui.goal["set-goal"].destroy()
+	end
+end
+
+script.on_event(defines.events.on_gui_click,
+	function(event)
+		local player = game.players[event.player_index]
+		if player.gui.goal["set-goal"]
+			and event.element.tags
+			and event.element.tags["owner-mod"] == "set-goal"
+		then
+			if event.element.tags.action == "confirm"
+			then
+				player.set_goal_description(player.gui.goal["set-goal"]["goal-description"].text)
+				player.gui.goal["set-goal"].destroy()
+			elseif event.element.tags.action == "close"
+			then
+				player.gui.goal["set-goal"].destroy()
+			end
+		end
+	end
+)
+
+script.on_event("open-set-goal-gui", open_gui)
+
+script.on_event(defines.events.on_lua_shortcut,
+	function(event)
+		if event.prototype_name == "open-set-goal-gui"
+		then
+			open_gui(event)
+		end
+	end
+)
\ No newline at end of file

mercurial