Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Ready for first release
Browse files Browse the repository at this point in the history
  • Loading branch information
simwir committed Apr 15, 2016
1 parent abe2868 commit 2dd7c0f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 22 deletions.
131 changes: 109 additions & 22 deletions control.lua
Expand Up @@ -7,7 +7,8 @@ function init()
end

script.on_init(init)

currentPage = 1
stations = {}

script.on_event(defines.events.on_player_driving_changed_state, function(event)
local player = game.players[event.player_index]
Expand All @@ -24,7 +25,22 @@ end)
script.on_event(defines.events.on_gui_click, function(event)
local player = game.players[event.player_index]
if(player.gui.left.shuttleTrain==nil)then return end
if(event.element.parent == player.gui.left.shuttleTrain)then

if(event.element.name == "nextPage")then
currentPage = currentPage +1
addStations(player, currentPage)
end

if(event.element.name == "prevPage")then
if(currentPage > 1) then
currentPage = currentPage -1
addStations(player, currentPage)
end
end

--if(event.element.parent == player.gui.left.shuttleTrain)then

if(event.element.parent == player.gui.left.shuttleTrain.flow)then

for key, station in pairs(global.trainStations)do
if(event.element.name == station.backer_name)then
Expand All @@ -35,24 +51,6 @@ script.on_event(defines.events.on_gui_click, function(event)
end
end
end
--TODO: Debug remove
if(event.element == player.gui.left.shuttleTrain.bStop1)then
player.print("Stop 1 button pressed")
if(player.vehicle ~= nil and player.vehicle.name == "shuttleTrain") then
local schedule = {current=1, records={[1]={time_to_wait=30,station="Stop1"}} }
player.vehicle.train.schedule= schedule
player.vehicle.train.manual_mode = false
end
end
if(event.element == player.gui.left.shuttleTrain.bStop2)then
player.print("Stop 2 button pressed")
if(player.vehicle ~= nil and player.vehicle.name == "shuttleTrain") then
local schedule = {current=1, records={[1]={time_to_wait=30,station="Stop2"}} }
player.vehicle.train.schedule= schedule
player.vehicle.train.manual_mode = false
end
end
--Debug end
end
end)

Expand All @@ -70,7 +68,7 @@ entityDestroyed = function(event)
local entity = event.entity
if(entity.type=="train-stop" and global.trainStations ~= nil)then
for key, value in pairs(global.trainStations)do
if(entity.backer_name==value.backer_name)then
if(entity==value)then
table.remove(global.trainStations, key)
end
end
Expand All @@ -84,14 +82,103 @@ script.on_event(defines.events.on_robot_pre_mined, entityDestroyed)
createGui = function(player)
if player.gui.left.shuttleTrain ~= nil then return end
player.gui.left.add{type="frame", name="shuttleTrain", direction="vertical" }
player.gui.left.shuttleTrain.add{type="flow", name="header", direction="horizontal"}
player.gui.left.shuttleTrain.add{type="label", name="label", caption="Shuttle Train" }
player.gui.left.shuttleTrain.header.add{type="button", name="prevPage", caption="<"}
player.gui.left.shuttleTrain.header.add{type="button", name="pageNumber", caption="1" }
player.gui.left.shuttleTrain.header.add{type="button", name="nextPage", caption=">"}
--player.gui.left.shuttleTrain.add{type="flow", name="flow", direction="vertical" }

currentPage = 1
prevStations = {}

indexStations(player)
addStations(player, 1)

end

nextPage = function(player)

end

indexStations = function(player)
if(global.trainStations~=nil)then
stations = {}
for key, station in pairs(global.trainStations)do
player.gui.left.shuttleTrain.add{type="button", name=station.backer_name, caption=station.backer_name}
local stationAlreadyAdded = false
--for key2, value in pairs(player.gui.left.shuttleTrain.children_names)do
for key2, value in pairs(stations)do
if(station.backer_name == value.backer_name )then
stationAlreadyAdded = true
end
end
--for key2, value in pairs(prevStations)do
-- if(station.backer_name == value.backer_name)then
-- stationAlreadyAdded = true
-- end
--end
if(stationAlreadyAdded ==false)then
--player.gui.left.shuttleTrain.add{type="button", name=station.backer_name, caption=station.backer_name }
--table.insert(prevStations, station)
--player.gui.left.shuttleTrain.flow.add{type="button", name=station.backer_name, caption=station.backer_name }
table.insert(stations, station)
end

end

end
--player.print(table.tostring(stations))
end

addStations = function(player, page)
local stationsAdded = 0

player.gui.left.shuttleTrain.header.pageNumber.caption = page

if(player.gui.left.shuttleTrain.flow ~= nil) then
player.gui.left.shuttleTrain.flow.destroy()
end

player.gui.left.shuttleTrain.add{type="flow", name="flow", direction="vertical" }

if(stations ~= nil or stations ~= {})then
local startIndex = 10*page-9
while stationsAdded < 10 do
if( stations[startIndex+stationsAdded]~=nil)then
local name = stations[startIndex+stationsAdded].backer_name
player.gui.left.shuttleTrain.flow.add{type="button", name=name, caption=name }
end
stationsAdded = stationsAdded+1
end
end

--if(global.trainStations~=nil)then
-- for key, station in pairs(global.trainStations)do
-- local stationAlreadyAdded = false
-- --for key2, value in pairs(player.gui.left.shuttleTrain.children_names)do
-- for key2, value in pairs(player.gui.left.shuttleTrain.flow.children_names)do
-- if(station.backer_name == value )then
-- stationAlreadyAdded = true
-- end
-- end
-- for key2, value in pairs(prevStations)do
-- if(station.backer_name == value.backer_name)then
-- stationAlreadyAdded = true
-- end
-- end
-- if(stationAlreadyAdded ==false)then
--player.gui.left.shuttleTrain.add{type="button", name=station.backer_name, caption=station.backer_name }
-- table.insert(prevStations, station)
-- player.gui.left.shuttleTrain.flow.add{type="button", name=station.backer_name, caption=station.backer_name }
-- stationsAdded = stationsAdded+1
-- end
-- if(stationsAdded>9)then
-- currentPageFull = true
-- break
-- end
-- end
-- currentPageFull = false
-- end
end

findAllStations = function()
Expand Down
Binary file modified graphics/icon_shuttleTrain_tech.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed graphics/icon_shuttleTrain_tech2.png
Binary file not shown.
1 change: 1 addition & 0 deletions prototypes/technology.lua
Expand Up @@ -3,6 +3,7 @@ data:extend({
type = "technology",
name = "shuttleTrain_tech",
icon = "__ShuttleTrain__/graphics/icon_shuttleTrain_tech.png",
icon_size = 128,
effects =
{
{
Expand Down

0 comments on commit 2dd7c0f

Please sign in to comment.