Add set-goal mod set-goal-v1.0.0

Sun, 29 Jun 2025 16:11:41 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sun, 29 Jun 2025 16:11:41 +0300
changeset 0
11962c90f1b8
child 1
52f07c580b85

Add set-goal mod

set-goal/control.lua file | annotate | diff | comparison | revisions
set-goal/data.lua file | annotate | diff | comparison | revisions
set-goal/info.json file | annotate | diff | comparison | revisions
set-goal/locale/en/set-goal.cfg file | annotate | diff | comparison | revisions
set-goal/thumbnail.png file | annotate | diff | comparison | revisions
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/set-goal/data.lua	Sun Jun 29 16:11:41 2025 +0300
@@ -0,0 +1,29 @@
+data:extend{
+    {
+		type = "custom-input",
+		name = "open-set-goal-gui",
+		order = "open-set-goal-gui",
+		key_sequence = "Shift + G"
+	},
+	{
+		type = "shortcut",
+		name = "open-set-goal-gui",
+		action = "lua",
+		icon = "__base__/graphics/icons/signal/signal-white-flag.png",
+		icon_size = 64,
+		small_icon = "__base__/graphics/icons/signal/signal-white-flag.png",
+		small_icon_size = 64,
+		associated_control_input = "open-set-goal-gui"
+	},
+}
+
+data.raw["gui-style"].default["set-goal-gui-textbox"] = {
+    type = "textbox_style",
+    minimal_width = 300,
+    --maximal_width = 1200,
+    minimal_height = 200,
+    --maximal_height = 1200,
+    horizontally_stretchable = "on",
+    vertically_stretchable = "on",
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/set-goal/info.json	Sun Jun 29 16:11:41 2025 +0300
@@ -0,0 +1,9 @@
+{
+    "name": "set-goal",
+    "title": "Set goal",
+    "description": "Adds a simple GUI to change your objective description.",
+    "author": "teemu",
+    "version": "1.0.0",
+    "factorio_version": "2.0",
+    "dependencies": ["base"]
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/set-goal/locale/en/set-goal.cfg	Sun Jun 29 16:11:41 2025 +0300
@@ -0,0 +1,6 @@
+[set-goal-gui]
+title=Set your objective
+close-tooltip=Close this window and discard any changes.
+confirm-tooltip=Confirm changes.
+[shortcut-name]
+open-set-goal-gui=Change your objective
\ No newline at end of file
Binary file set-goal/thumbnail.png has changed

mercurial