diff --git a/scripts/caravan/caravan-enable-gui.lua b/scripts/caravan/caravan-enable-gui.lua new file mode 100644 index 00000000..b33e608d --- /dev/null +++ b/scripts/caravan/caravan-enable-gui.lua @@ -0,0 +1,26 @@ +require 'caravan-gui-shared' +local Table = require('__stdlib__/stdlib/utils/table') + +Caravan.events.on_gui_opened_enable = 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' or entity.name == 'outpost' then + return + end + -- Caravan.events.on_close_outpost_gui(event) + if not Caravan.has_any_caravan(entity) then + return + end + local main_frame = player.gui.center + main_frame.add { + type = "sprite-button", + name = "open-caravan-list", + sprite = "utility/close_white", + style = "frame_action_button", + tags = { entity = entity } + } +end + diff --git a/scripts/caravan/caravan-gui-shared.lua b/scripts/caravan/caravan-gui-shared.lua index d75946ab..9e71aa70 100644 --- a/scripts/caravan/caravan-gui-shared.lua +++ b/scripts/caravan/caravan-gui-shared.lua @@ -1,3 +1,25 @@ +local function has_schedule(caravan_data, entity) + if not Caravan.validity_check(caravan_data) then + return + end + if not caravan_data.schedule then + return + end + return Table.any(caravan_data.schedule, function(schedule) + return schedule.entity == entity + end) +end + +-- probably bad if you have 10 k caravans... but is that even remotely relevant? +function Caravan.has_any_caravan(entity) + return Table.any(global.caravans, function(caravan_data) + return has_schedule(caravan_data, entity) + end) +end + + + + function Caravan.status_img(caravan_data) local entity = caravan_data.entity if caravan_data.is_aerial then diff --git a/scripts/caravan/caravan-outpost-gui.lua b/scripts/caravan/caravan-outpost-gui.lua index 0a7f42da..48ced9a2 100644 --- a/scripts/caravan/caravan-outpost-gui.lua +++ b/scripts/caravan/caravan-outpost-gui.lua @@ -1,24 +1,7 @@ require 'caravan-gui-shared' local Table = require('__stdlib__/stdlib/utils/table') -local function has_schedule(caravan_data, entity) - if not Caravan.validity_check(caravan_data) then - return - end - if not caravan_data.schedule then - return - end - return Table.any(caravan_data.schedule, function(schedule) - return schedule.entity == entity - end) -end --- probably bad if you have 10 k caravans... but is that even remotely relevant? -local function has_any_caravan(entity) - return Table.any(global.caravans, function(caravan_data) - return has_schedule(caravan_data, entity) - end) -end Caravan.events.on_gui_opened_outpost = function(event) local player = game.get_player(event.player_index)