From 8d6aa814c9243cb11f70e649e108ea3cf600e6fd Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Thu, 25 Aug 2022 20:05:57 +0200 Subject: [PATCH] Optionally keep player tracker enabled when building (#36) --- changelog.txt | 3 +- locale/en/locale.cfg | 2 + migrations/tlbe.1.4.4.lua | 5 ++ scripts/gui.lua | 151 +++++++++++++++++++++----------------- scripts/main.lua | 3 +- scripts/tracker.lua | 2 + 6 files changed, 95 insertions(+), 71 deletions(-) diff --git a/changelog.txt b/changelog.txt index 4e4d8d2..5fb4e00 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,7 +3,8 @@ Version: 1.4.4 Date: 03-07-2022 Minor Features: - Store screenshots in a sub-directory if the camera name contains a slash. - - Added an always daylight toggle to cameras (Thanks drdozer) + - Added an always daylight toggle to cameras. (Thanks drdozer) + - Optionally keep player tracker enabled when building. Bugfixes: - Each camera must have its own sequential numbering when enabled. diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg index 0df93fa..2a8533d 100644 --- a/locale/en/locale.cfg +++ b/locale/en/locale.cfg @@ -30,6 +30,7 @@ label-smooth=Smooth camera movement label-speedgain=Speed gain: label-top-right=Top/Right: label-type=Type: +label-until-build=Follow until build label-zoom=Zoom: label-zoomperiod=Zoom period: item-add-tracker= @@ -56,6 +57,7 @@ tracker-enable=Enable/Disable tracker. (disabled trackers are skipped by the cam tracker-area-map=Use map marker with name '__1__' to fill in this corner. tracker-area-player=Use player coordinates to fill in this corner. tracker-smooth=Enable/Disable smooth behavior of the camera when this tracker is active. +tracker-until-build=Follow the player until an entity is build. tracker-wrong-surface=Tracker is disabled because tracker surface differs from camera surface. [controls] diff --git a/migrations/tlbe.1.4.4.lua b/migrations/tlbe.1.4.4.lua index 29b33d9..fd21fcb 100644 --- a/migrations/tlbe.1.4.4.lua +++ b/migrations/tlbe.1.4.4.lua @@ -3,6 +3,7 @@ if global.playerSettings == nil then end -- Set camera alwaysDay to true for backwards compability +-- Make tracker untilBuild available for all trackers for player_index, _ in pairs(game.players) do local playerSettings = global.playerSettings[player_index] if playerSettings == nil then @@ -11,6 +12,10 @@ for player_index, _ in pairs(game.players) do for _, camera in pairs(playerSettings.cameras) do camera.alwaysDay = true + + for _, tracker in pairs(camera.trackers) do + tracker.untilBuild = tracker.type == "player" + end end ::NextPlayer:: diff --git a/scripts/gui.lua b/scripts/gui.lua index 8ab15aa..0f7dd88 100644 --- a/scripts/gui.lua +++ b/scripts/gui.lua @@ -584,6 +584,8 @@ function GUI.onStateChanged(event) playerSettings.cameras[playerSettings.guiPersist.selectedCamera].alwaysDay = event.element.state elseif event.element.name == "tracker-smooth" then playerSettings.trackers[playerSettings.guiPersist.selectedTracker].smooth = event.element.state + elseif event.element.name == "tracker-untilbuild" then + playerSettings.trackers[playerSettings.guiPersist.selectedTracker].untilBuild = event.element.state end end @@ -1286,75 +1288,86 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker) state = false } - if tracker ~= nil and tracker.type == "area" then - trackerInfo.add { - type = "label", - caption = { "gui.label-top-right" }, - style = "description_property_name_label" - } - local trFlow = trackerInfo.add { type = "flow", name = "tracker-tr" } - trFlow.add { - type = "textfield", - name = "tlbe-tracker-top", - style = "tlbe_config_half_width_textfield", - numeric = true, - allow_negative = true - } - trFlow.add { type = "label", caption = "/", style = "tlbe_config_half_width_label" } - trFlow.add { - type = "textfield", - name = "tlbe-tracker-right", - style = "tlbe_config_half_width_textfield", - numeric = true, - allow_negative = true - } - trFlow.add { - type = "sprite-button", - name = "tlbe-tracker-tr-player", - tooltip = { "tooltip.tracker-area-player" }, - sprite = "utility/show_player_names_in_map_view_black", - style = "tlbe_config_button" - } - trFlow.add { - type = "sprite-button", - name = "tlbe-tracker-tr-map", - tooltip = { "tooltip.tracker-area-map", tracker.name .. "-tr" }, - sprite = "utility/station_name", - style = "tlbe_config_button" - } + if tracker ~= nil then + if tracker.type == "area" then + trackerInfo.add { + type = "label", + caption = { "gui.label-top-right" }, + style = "description_property_name_label" + } + local trFlow = trackerInfo.add { type = "flow", name = "tracker-tr" } + trFlow.add { + type = "textfield", + name = "tlbe-tracker-top", + style = "tlbe_config_half_width_textfield", + numeric = true, + allow_negative = true + } + trFlow.add { type = "label", caption = "/", style = "tlbe_config_half_width_label" } + trFlow.add { + type = "textfield", + name = "tlbe-tracker-right", + style = "tlbe_config_half_width_textfield", + numeric = true, + allow_negative = true + } + trFlow.add { + type = "sprite-button", + name = "tlbe-tracker-tr-player", + tooltip = { "tooltip.tracker-area-player" }, + sprite = "utility/show_player_names_in_map_view_black", + style = "tlbe_config_button" + } + trFlow.add { + type = "sprite-button", + name = "tlbe-tracker-tr-map", + tooltip = { "tooltip.tracker-area-map", tracker.name .. "-tr" }, + sprite = "utility/station_name", + style = "tlbe_config_button" + } - trackerInfo.add { type = "label", caption = { "gui.label-bottom-left" }, - style = "description_property_name_label" } - local blFlow = trackerInfo.add { type = "flow", name = "tracker-bl" } - blFlow.add { - type = "textfield", - name = "tlbe-tracker-bottom", - style = "tlbe_config_half_width_textfield", - numeric = true, - allow_negative = true - } - blFlow.add { type = "label", caption = "/", style = "tlbe_config_half_width_label" } - blFlow.add { - type = "textfield", - name = "tlbe-tracker-left", - style = "tlbe_config_half_width_textfield", - numeric = true, - allow_negative = true - } - blFlow.add { - type = "sprite-button", - name = "tlbe-tracker-bl-player", - tooltip = { "tooltip.tracker-area-player" }, - sprite = "utility/show_player_names_in_map_view_black", - style = "tlbe_config_button" - } - blFlow.add { - type = "sprite-button", - name = "tlbe-tracker-bl-map", - tooltip = { "tooltip.tracker-area-map", tracker.name .. "-bl" }, - sprite = "utility/station_name", - style = "tlbe_config_button" - } + trackerInfo.add { type = "label", caption = { "gui.label-bottom-left" }, + style = "description_property_name_label" } + local blFlow = trackerInfo.add { type = "flow", name = "tracker-bl" } + blFlow.add { + type = "textfield", + name = "tlbe-tracker-bottom", + style = "tlbe_config_half_width_textfield", + numeric = true, + allow_negative = true + } + blFlow.add { type = "label", caption = "/", style = "tlbe_config_half_width_label" } + blFlow.add { + type = "textfield", + name = "tlbe-tracker-left", + style = "tlbe_config_half_width_textfield", + numeric = true, + allow_negative = true + } + blFlow.add { + type = "sprite-button", + name = "tlbe-tracker-bl-player", + tooltip = { "tooltip.tracker-area-player" }, + sprite = "utility/show_player_names_in_map_view_black", + style = "tlbe_config_button" + } + blFlow.add { + type = "sprite-button", + name = "tlbe-tracker-bl-map", + tooltip = { "tooltip.tracker-area-map", tracker.name .. "-bl" }, + sprite = "utility/station_name", + style = "tlbe_config_button" + } + elseif tracker.type == "player" then + trackerInfo.add { type = "empty-widget" } + trackerInfo.add { + type = "checkbox", + name = "tracker-untilbuild", + caption = { "gui.label-until-build" }, + tooltip = { "tooltip.tracker-until-build" }, + state = tracker.untilBuild + } + end end trackerInfo.add { @@ -1414,6 +1427,8 @@ function GUI.updateTrackerConfig(trackerInfo, tracker) end trFlow["tlbe-tracker-right"].style = style blFlow["tlbe-tracker-left"].style = style + elseif tracker.type == "player" then + trackerInfo["tracker-untilbuild"].state = tracker.untilBuild end end end diff --git a/scripts/main.lua b/scripts/main.lua index 137c35b..5c18b3c 100644 --- a/scripts/main.lua +++ b/scripts/main.lua @@ -95,8 +95,7 @@ function Main.entity_built(event) goto nextTracker end - if tracker.type == "player" then - -- TODO only when tracker has setting set + if tracker.untilBuild then Tracker.moveToNextTracker(tracker) elseif tracker.type == "base" then if tracker.surfaceName ~= event.created_entity.surface.name then diff --git a/scripts/tracker.lua b/scripts/tracker.lua index beb66e4..9dc75b5 100644 --- a/scripts/tracker.lua +++ b/scripts/tracker.lua @@ -8,6 +8,7 @@ local Utils = require("scripts.utils") --- @field smooth boolean --- @field surfaceName string --- @field type string +--- @field untilBuild boolean --- @field userCanEnable boolean local Tracker = {} @@ -28,6 +29,7 @@ function Tracker.newTracker(trackerType, trackerList) userCanEnable = true, enabled = true, smooth = true, + untilBuild = false, lastChange = 0 }