Skip to content

Commit

Permalink
outpost gui
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGoesen committed Jan 7, 2024
1 parent f14e650 commit 40e68c6
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
4 changes: 4 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ script.on_event(on_destroyed, function(event)
end)

script.on_event(defines.events.on_gui_opened, function(event)
Caravan.events.on_gui_opened_outpost(event)
Oculua.events.on_gui_opened(event)
Digosaurus.events.on_gui_opened(event)
Slaughterhouse.events.on_gui_opened(event)
Expand All @@ -178,13 +179,15 @@ end)
script.on_event(defines.events.on_gui_closed, function(event)
Caravan.events.close_gui(event)
Caravan.events.on_close_global_gui(event)
Caravan.events.on_close_outpost_gui(event)
Digosaurus.events.close_gui(event)
Slaughterhouse.events.on_gui_closed(event)
Biofluid.events.on_gui_closed(event)
end)

script.on_event(defines.events.on_player_changed_surface, function(event)
Caravan.events.close_gui(event)
Caravan.events.on_close_outpost_gui(event)
Digosaurus.events.close_gui(event)
Slaughterhouse.events.on_gui_closed(event)
Biofluid.events.on_gui_closed(event)
Expand Down Expand Up @@ -229,6 +232,7 @@ script.on_nth_tick(7, function()
end)

script.on_event('open-gui', function(event)
Caravan.events.on_gui_opened_outpost(event)
Caravan.events.on_open_gui(event)
Caravan.events.used_capsule(event)
end)
Expand Down
16 changes: 10 additions & 6 deletions scripts/caravan/caravan-global-gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ Caravan.events.on_open_global_gui = function(event)
end
local frame = player.gui.screen.add { type = 'frame', name = 'caravan_gui_global', caption = { 'caravan-global-gui.caption' }, direction = 'vertical' }
frame.auto_center = true
local table = frame.add {
type = "table",
name = "my_table",
local scroll_pane = frame.add {
type = 'scroll-pane',
name = 'global-caravan-pane'
}
local table = scroll_pane.add {
type = 'table',
name = 'my_table',
column_count = 2
}
table.add { type = "label", caption = "Key" }
table.add { type = "label", caption = "Value" }
table.add { type = 'label', caption = 'Key' }
table.add { type = 'label', caption = 'Value' }
for key, value in pairs(global.caravans) do
if Caravan.validity_check(value) then
table.add { type = 'label', name = 'click_caravan_.' .. tostring(key),
style = 'clickable_squashable_label',
tags = { unit_number = key, entity = value },
caption = tostring(key) }
table.add { type = "label", caption = tostring(value.entity.name) }
table.add { type = 'label', caption = tostring(value.entity.name) }
end
end
end
Expand Down
96 changes: 96 additions & 0 deletions scripts/caravan/caravan-outpost-gui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
local function hasSchedule(caravan_data, entity)
if not Caravan.validity_check(caravan_data) then
return false
end
if not caravan_data.schedule then
return false
end
for _, schedule in pairs(caravan_data.schedule) do
if schedule.entity == entity then
return true
end
end
return false
end

local function any_caravan(entity)
for key, value in pairs(global.caravans) do
if hasSchedule(value, entity) then
return true
end
end
return false
end

Caravan.events.on_gui_opened_outpost = function(event)
local player = game.get_player(event.player_index)
local entity = event.entity
if not entity then
return
end
if entity.name ~= 'aerial-outpost' and entity.name ~= 'outpost' then
return
end
Caravan.events.on_close_outpost_gui(event)
if not any_caravan(entity) then
return
end
local main_frame
if false then
main_frame = player.gui.screen.add { type = 'frame', name = 'caravan_gui', caption = entity.prototype.localised_name, direction = 'vertical' }
main_frame.auto_center = true
player.opened = main_frame
else
main_frame = player.gui.relative.add {
type = 'frame',
name = 'outpost_caravan_gui',
caption = entity.prototype.localised_name,
direction = 'vertical',
anchor = {
gui = defines.relative_gui_type.container_gui,
position = defines.relative_gui_position.right
}
}
end
main_frame.style.width = 436
main_frame.style.minimal_height = 710
main_frame.tags = { unit_number = entity.unit_number }

local content_frame = main_frame.add { type = 'frame', name = 'content_frame_outpost', direction = 'vertical',
style = 'inside_shallow_frame_with_padding' }
content_frame.style.vertically_stretchable = true
local content_flow = content_frame.add { type = 'flow', name = 'content_flow_outpost', direction = 'vertical' }
content_flow.style.vertical_spacing = 8
content_flow.style.margin = { -4, 0, -4, 0 }
content_flow.style.vertical_align = 'center'
local scroll_pane = content_flow.add {
type = 'scroll-pane',
name = 'outpost-caravan-pane'
}
local table = scroll_pane.add {
type = 'table',
name = 'my_table',
column_count = 2
}
table.add { type = 'label', caption = 'Key' }
table.add { type = 'label', caption = 'Value' }
for key, value in pairs(global.caravans) do
if hasSchedule(value, entity) then
table.add { type = 'label', name = 'click_caravan_.' .. tostring(key),
style = 'clickable_squashable_label',
tags = { unit_number = key, entity = value },
caption = tostring(key) }
table.add { type = 'label', caption = tostring(value.entity.name) }
end
end
game.print('it shoudl')
end

Caravan.events.on_close_outpost_gui = function(event)
local player = game.get_player(event.player_index)
if player.gui.relative.outpost_caravan_gui then
player.gui.relative.outpost_caravan_gui.destroy()
return true
end
return false
end
1 change: 1 addition & 0 deletions scripts/caravan/caravan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Caravan.events = {}

require 'caravan-gui'
require 'caravan-global-gui'
require 'caravan-outpost-gui'
local prototypes = require 'caravan-prototypes'
local Position = require('__stdlib__/stdlib/area/position')
local Table = require('__stdlib__/stdlib/utils/table')
Expand Down

0 comments on commit 40e68c6

Please sign in to comment.