Skip to content

Commit

Permalink
Optionally keep player tracker enabled when building (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
veger committed Aug 25, 2022
1 parent 34d3977 commit 8d6aa81
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 71 deletions.
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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=<Add Tracker>
Expand All @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions migrations/tlbe.1.4.4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::
Expand Down
151 changes: 83 additions & 68 deletions scripts/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions scripts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/tracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -28,6 +29,7 @@ function Tracker.newTracker(trackerType, trackerList)
userCanEnable = true,
enabled = true,
smooth = true,
untilBuild = false,
lastChange = 0
}

Expand Down

0 comments on commit 8d6aa81

Please sign in to comment.