Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a button for FARL #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions GUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ function endsWith(haystack,needle)--luacheck: allow defined top
return needle=='' or string.sub(haystack,-string.len(needle))==needle
end


require("mod-gui")
local modGui = _G.mod_gui

GUI = {--luacheck: allow defined top

ccWires = {
Expand Down Expand Up @@ -102,7 +106,28 @@ GUI = {--luacheck: allow defined top
end
end,

createButton = function(player)
local buttons = modGui.get_button_flow(player)
if not buttons.farl_button then
buttons.add({
type = "sprite-button",
name = "farl_button",
sprite = "item/farl",
style = modGui.button_style,
tooltip = {"farl_tooltip_button"}
})
end
end,

destroyButton = function(player)
local buttons = modGui.get_button_flow(player)
if buttons.farl_button then
buttons.farl_button.destroy()
end
end,

createGui = function(player)

if player.gui.left.farl ~= nil then return end
local psettings = Settings.loadByPlayer(player)
--GUI.init(player)
Expand Down
41 changes: 32 additions & 9 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ require "Settings"
require "FARL"
require "GUI"


require("mod-gui")
local modGui = _G.mod_gui

local v = require 'semver'

MOD_NAME = "FARL"--luacheck: allow defined top
Expand Down Expand Up @@ -429,6 +433,11 @@ local function on_force_created(event)
end

local function on_gui_click(event)
if event.element.name == "farl_button" then
farl_button_click(event)
return
end

local status, err = pcall(function()
local index = event.player_index
local player = game.players[index]
Expand Down Expand Up @@ -476,21 +485,35 @@ end
function on_player_driving_changed_state(event)--luacheck: allow defined top
local player = game.players[event.player_index]
if isFARLLocomotive(player.vehicle) then
if player.gui.left.farl == nil then
local farl = FARL.onPlayerEnter(player)
GUI.createGui(player)
if farl then
GUI.updateGui(farl)
end
end
if modGui.get_button_flow(player).farl_button == nil then
GUI.createButton(player)
end
end
if player.vehicle == nil and player.gui.left.farl ~= nil then
if player.vehicle == nil and (modGui.get_button_flow(player).farl_button ~= nil) then
FARL.onPlayerLeave(player)
debugDump("onPlayerLeave (driving state changed)")
GUI.destroyGui(player)
if player.gui.left.farl ~= nil then
GUI.destroyGui(player)
end
GUI.destroyButton(player)
end
end


function farl_button_click (event)
local player = game.players[event.player_index]
if player.gui.left.farl == nil then
local farl = FARL.onPlayerEnter(player)
GUI.createGui(player)
if farl then
GUI.updateGui(farl)
end
else
GUI.destroyGui(player)
end
end


--function on_player_placed_equipment(event)
-- local player = game.players[event.player_index]
-- if event.equipment.name == "farl-roboport" and isFARLLocomotive(player.vehicle) then
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FARL",
"version": "1.1.7",
"version": "1.1.8",
"factorio_version": "0.15",
"title": "Fully Automated Rail Layer",
"author": "Choumiko",
Expand Down
4 changes: 3 additions & 1 deletion locale/de/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Platziert Zugsignale mit jedem Strommast. Ignoriert die "Abstand zwischen Zugsignalen" Option
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL
4 changes: 3 additions & 1 deletion locale/en/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Places signals with every pole. Ignores the "Distance between rail signals" setting
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL
4 changes: 3 additions & 1 deletion locale/es-ES/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Places signals with every pole. Ignores the "Distance between rail signals" setting
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL
4 changes: 3 additions & 1 deletion locale/fr/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Place des signaux ferroviaires avec chaque poteau électrique. Ignore l'option "Distance entre les signaux ferroviaires".
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL
4 changes: 3 additions & 1 deletion locale/he/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Places signals with every pole. Ignores the "Distance between rail signals" setting
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL
4 changes: 3 additions & 1 deletion locale/no/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Places signals with every pole. Ignores the "Distance between rail signals" setting
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL
4 changes: 3 additions & 1 deletion locale/ru/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Places signals with every pole. Ignores the "Distance between rail signals" setting
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL
4 changes: 3 additions & 1 deletion locale/se/tooltips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ farl_tooltip_bridge=Use landfill to fill water when needed
farl_tooltip_signalEveryPole=Places signals with every pole. Ignores the "Distance between rail signals" setting
farl_tooltip_place_ghosts=Places ghosts when the item is missing in the train\n Does not place rails and concrete
farl_tooltip_place_pole_entities=Places additional entities (poles, assemblers, inserters, etc..) whenever a pole is placed.\n Does not place walls or concrete
farl_tooltip_place_walls=Places walls whenever a rail is built.
farl_tooltip_place_walls=Places walls whenever a rail is built.

farl_tooltip_button=FARL