From 75cdc40f30cbadc54c593d9c65b578ff5321500c Mon Sep 17 00:00:00 2001 From: notnotmelon Date: Mon, 15 Apr 2024 11:58:08 -0500 Subject: [PATCH] Frozen (#242) * Frozen (#240) * make smart farms flora possitive * version and changelog * fix that collectors mk02-mk04 didnt get reset fixes pyanodon/pybugreports#461 * i blame theros ass * Smart farm fixes * https://github.com/pyanodon/pybugreports/issues/458 * TURD balance & migrations * Fixed that subcritical-water-01 was not localised when pyAE is missing * Fixed that the alpha dingrits from dingrit turd path 1 could not be used as modules inside the reproductive complex. * Energy drink qol improvements * Fixed several bugs involved with biofluid vessel underground pipes * Fixed several bugs involved with biofluid vessel underground pipes * remove print statements * Reduce earlygame manual wood requirement grind. --------- Co-authored-by: kingarthur91 * Fixed returned cages (#235) * Add files via upload * Fixed returned cages * Fixed returned cages * Fixed returned cages * Returned cages fixed * Fixed cage return * Global Caravan handling GUI (#222) * list of clickables everything is broken though * click opens the thing * moved to a new file-> todo prevent item stealing list by outpost scrollpane * outpost gui * status icon * less loc * new state idle * pasting untested stuff from chatgpt * ho * more stuff that will certainly work nocap * connected gui works * lets try this migrations thingy * fixed the migration * use the migration * fixed the close button... * cleanup code a bit * fixed the esc key * localization * localization * ship it * new rule I like open better * wuuups * I broke esc again... * Apply pyanodon code formatting standard * Remove references to stdlib functions as part of an ongoing effort to remove stdlib. * Streamline the amount of code needed to handle GUI closing events * Make the GUI expand to the container instead of having a hardcoded size * Improve the relative GUI type guessing algorithm * Move hotkey based GUI to pycodex and add a camera * Add more buttons and finalize styling --------- Co-authored-by: notnotmelon * Add a rename button to the original caravan GUI * Add some randomly generated placeholder names for caravans. --------- Co-authored-by: kingarthur91 Co-authored-by: Wisey <44213571+Wiseyuk@users.noreply.github.com> Co-authored-by: TheGoesen <31041434+TheGoesen@users.noreply.github.com> --- control.lua | 1 + locale/en/caravan.cfg | 14 + locale/en/tips.cfg | 1 + migrations/caravan_gui.lua | 8 + scripts/caravan/caravan-connected-gui.lua | 72 +++ scripts/caravan/caravan-global-gui.lua | 33 ++ scripts/caravan/caravan-gui-shared.lua | 303 +++++++++++ scripts/caravan/caravan-gui.lua | 95 +++- scripts/caravan/caravan.lua | 30 +- scripts/caravan/italian-names.lua | 634 ++++++++++++++++++++++ scripts/wiki/text-pages.lua | 6 + 11 files changed, 1154 insertions(+), 43 deletions(-) create mode 100644 migrations/caravan_gui.lua create mode 100644 scripts/caravan/caravan-connected-gui.lua create mode 100644 scripts/caravan/caravan-global-gui.lua create mode 100644 scripts/caravan/caravan-gui-shared.lua create mode 100644 scripts/caravan/italian-names.lua diff --git a/control.lua b/control.lua index 5eca7cd2..feadf9c3 100644 --- a/control.lua +++ b/control.lua @@ -178,6 +178,7 @@ script.on_event(defines.events.on_player_removed_equipment, function(event) end) script.on_event(defines.events.on_gui_opened, function(event) + Caravan.events.on_gui_opened_connected(event) Oculua.events.on_gui_opened(event) Digosaurus.events.on_gui_opened(event) Slaughterhouse.events.on_gui_opened(event) diff --git a/locale/en/caravan.cfg b/locale/en/caravan.cfg index 43a06683..7a386188 100644 --- a/locale/en/caravan.cfg +++ b/locale/en/caravan.cfg @@ -16,6 +16,18 @@ outpost-aerial=Item and food storage for aerial caravans. healthy=Healthy starved=Starved wounded=Wounded +idle=Idle + +[caravan-shared] +open=Open __1__ +view-on-map=View on map +current-action=Current action: __1__ +current-destination=__1__m from __2__ + +[caravan-global-gui] +caption=Caravan manager +empty=This is the caravan manager. It will display all placed caravans and their current status. +empty-2=Currently you have no caravans. [caravan-gui] add-outpost=+ Add destination @@ -26,6 +38,7 @@ refocus=Refocus favorite-foods-main=Favorite foods:\n__1__ favorite-foods-sub=__1__ __2__ → __3__ actions wait=Wait until fulfilled +hello-my-name-is=[font=default-bold]Hello, my name is: [color=255,210,73]__1__[/color][/font] [caravan-actions] time-passed=Wait @@ -37,6 +50,7 @@ inverse-item-count=Until target has exactly N items detonate=Detonate circuit-condition=Circuit condition empty-autotrash=Collect all autotrash +traveling=Traveling [item-name] caravan-control=Caravan control diff --git a/locale/en/tips.cfg b/locale/en/tips.cfg index 1c9b9939..8428f65e 100644 --- a/locale/en/tips.cfg +++ b/locale/en/tips.cfg @@ -2,6 +2,7 @@ alienlife=Alien life farming=[item=native-flora] Farming caravans=[item=caravan] Caravans +caravan-manager=[item=caravan-control] Caravan manager mounts=[item=crawdad] Mounts digosaurus=[item=digosaurus] Dig-o-saurus mega-farm=[item=replicator-bioreserve] Automated smart farms diff --git a/migrations/caravan_gui.lua b/migrations/caravan_gui.lua new file mode 100644 index 00000000..933cc58c --- /dev/null +++ b/migrations/caravan_gui.lua @@ -0,0 +1,8 @@ +for _,player in pairs(game.players) do + local gui = player.gui.relative.caravan_gui + if gui then + gui.destroy() + end --it lives in a flow now +end + + diff --git a/scripts/caravan/caravan-connected-gui.lua b/scripts/caravan/caravan-connected-gui.lua new file mode 100644 index 00000000..a0fb6905 --- /dev/null +++ b/scripts/caravan/caravan-connected-gui.lua @@ -0,0 +1,72 @@ +require 'caravan-gui-shared' + +local relative_gui_types = { + ['electric-pole'] = 'electric_network_gui', + ['character'] = 'other_player_gui', + ['unit'] = 'script_inventory_gui' +} + +local function guess(entity) + local entity_type = entity.type + local relative_gui_type = relative_gui_types[entity_type] or entity_type:gsub('%-', '_') .. '_gui' + return defines.relative_gui_type[relative_gui_type] or defines.relative_gui_type.generic_on_off_entity_gui +end + +--anchor is optional +local function instantiate_main_frame(gui, anchor) + if anchor then + return gui.relative.add{ + type = 'frame', + name = 'py_global_caravan_gui', + caption = {'caravan-global-gui.caption'}, + direction = 'vertical', + anchor = anchor + } + end + if not gui.relative.caravan_flow then return end + return gui.relative.caravan_flow.add{ + type = 'frame', + name = 'py_global_caravan_gui', + caption = {'caravan-global-gui.caption'}, + direction = 'vertical', + } +end + +function Caravan.has_any_caravan(entity) + for _, caravan_data in pairs(global.caravans) do + if has_schedule(caravan_data, entity) then return true end + end + return false +end + +--anchor is optional +Caravan.build_gui_connected = function(player, entity, anchor) + if not entity then return end + if not Caravan.has_any_caravan(entity) then return end + local main_frame = instantiate_main_frame(player.gui, anchor) + if not main_frame then return end + main_frame.style.minimal_width = 300 + main_frame.tags = {unit_number = entity.unit_number} + + local scroll_pane = main_frame.add{type = 'scroll-pane'} + scroll_pane.style.top_margin = -6 + + for key, caravan_data in pairs(global.caravans) do + if has_schedule(caravan_data, entity) then + scroll_pane.add{type = 'empty-widget'}.style.height = 3 + Caravan.add_gui_row(caravan_data, key, scroll_pane) + end + end +end + +Caravan.events.on_gui_opened_connected = function(event) + local player = game.get_player(event.player_index) + local entity = event.entity + if not entity then return end + if player.gui.relative.connected_caravan_gui then return end + local anchor = { + gui = guess(entity), + position = defines.relative_gui_position.right + } + Caravan.build_gui_connected(player, entity, anchor) +end \ No newline at end of file diff --git a/scripts/caravan/caravan-global-gui.lua b/scripts/caravan/caravan-global-gui.lua new file mode 100644 index 00000000..6b4e58c1 --- /dev/null +++ b/scripts/caravan/caravan-global-gui.lua @@ -0,0 +1,33 @@ +require 'caravan-gui-shared' + +function Caravan.has_any_caravan_at_all() + for _, caravan in pairs(global.caravans) do + if Caravan.validity_check(caravan) then return true end + end + return false +end + +local function create_gui(gui, player) + if not Caravan.has_any_caravan_at_all() then + gui = gui.add{type = 'flow', direction = 'vertical'} + gui.style.horizontal_align = 'center' + gui.style.horizontally_stretchable = true + gui.add{type = 'label', caption = ''} + gui.add{type = 'label', caption = {'caravan-global-gui.empty'}}.style.single_line = false + gui.add{type = 'label', caption = {'caravan-global-gui.empty-2'}}.style.single_line = false + return + end + local table = gui.add{ + type = 'table', + column_count = 4 + } + for key, caravan_data in pairs(global.caravans) do + if Caravan.validity_check(caravan_data) and caravan_data.entity.force_index == player.force_index then + Caravan.add_gui_row(caravan_data, key, table) + end + end +end + +remote.add_interface('pywiki_caravan_manager', { + create_gui = create_gui +}) \ No newline at end of file diff --git a/scripts/caravan/caravan-gui-shared.lua b/scripts/caravan/caravan-gui-shared.lua new file mode 100644 index 00000000..a3ac17de --- /dev/null +++ b/scripts/caravan/caravan-gui-shared.lua @@ -0,0 +1,303 @@ +local prototypes = require 'caravan-prototypes' + +function has_schedule(caravan_data, entity) + if not Caravan.validity_check(caravan_data) then return end + if not caravan_data.schedule then return end + for _, schedule in pairs(caravan_data.schedule) do + if schedule.entity == entity then return true end + end + return false +end + +function Caravan.status_img(caravan_data) + local entity = caravan_data.entity + if caravan_data.is_aerial then + return {'entity-status.working'}, 'utility/status_working' + elseif caravan_data.fuel_bar == 0 and caravan_data.fuel_inventory.is_empty() then + return {'entity-status.starved'}, 'utility/status_not_working' + elseif entity.health ~= entity.prototype.max_health then + return {'entity-status.wounded'}, 'utility/status_yellow' + elseif not Caravan.is_automated(caravan_data) then + return {'entity-status.idle'}, 'utility/status_yellow' + else + return {'entity-status.healthy'}, 'utility/status_working' + end +end + +local function convert_to_tooltip_row(name, count) + return {'', '\n[item=' .. name .. '] ', game.item_prototypes[name].localised_name, ' ×', count} +end + +function Caravan.get_inventory_tooltip(caravan_data) + local has_anything = false + local entity = caravan_data.entity + + local schedule = caravan_data.schedule[caravan_data.schedule_id] + local current_action = '' + if schedule then + has_anything = true + local action_id = caravan_data.action_id + local action = schedule.actions[action_id] + current_action = {'', {'caravan-shared.current-action', action and action.localised_name or {'caravan-actions.traveling'}}, '\n'} + + local destination = schedule.position + local localised_destination_name + if destination then + localised_destination_name = {'caravan-gui.map-position', math.floor(destination.x), math.floor(destination.y)} + else + local destination_entity = schedule.entity + if destination_entity and destination_entity.valid then + destination = destination_entity.position + localised_destination_name = { + 'caravan-gui.entity-position', + destination_entity.prototype.localised_name, + math.floor(destination.x), + math.floor(destination.y) + } + end + end + + if localised_destination_name then + local distance = math.sqrt((entity.position.x - destination.x) ^ 2 + (entity.position.y - destination.y) ^ 2) + distance = math.floor(distance * 10) / 10 + current_action[#current_action + 1] = {'caravan-shared.current-destination', distance, localised_destination_name} + end + end + + local fuel_inventory = caravan_data.fuel_inventory + local fuel_inventory_contents = {''} + if fuel_inventory and fuel_inventory.valid then + local i = 0 + for name, count in pairs(fuel_inventory.get_contents()) do + has_anything = true + if i == 0 then fuel_inventory_contents[#fuel_inventory_contents + 1] = '\n' end + fuel_inventory_contents[#fuel_inventory_contents + 1] = convert_to_tooltip_row(name, count) + i = i + 1 + if i == 10 then break end + end + end + + local inventory = caravan_data.inventory + local inventory_contents = {''} + if inventory and inventory.valid then + local sorted_contents = {} + for name, count in pairs(inventory.get_contents()) do + has_anything = true + sorted_contents[#sorted_contents + 1] = {name = name, count = count} + end + table.sort(sorted_contents, function(a, b) return a.count > b.count end) + + local i = 0 + for _, item in pairs(sorted_contents) do + if i == 0 then inventory_contents[#inventory_contents + 1] = '\n' end + local name, count = item.name, item.count + inventory_contents[#inventory_contents + 1] = convert_to_tooltip_row(name, count) + i = i + 1 + if i == 10 then + if #sorted_contents > 10 then + inventory_contents[#inventory_contents + 1] = {'', '\n [font=default-semibold]...[/font]'} + end + break + end + end + end + + return has_anything, {'', current_action, fuel_inventory_contents, inventory_contents} +end + +function Caravan.add_gui_row(caravan_data, key, table) + local entity = caravan_data.entity + local prototype = prototypes[entity.name] + + table = table.add{type = 'frame', style = 'inside_shallow_frame_with_padding', direction = 'vertical'} + + local button_flow = table.add{type = 'flow', direction = 'horizontal'} + button_flow.style.vertical_align = 'top' + button_flow.style.height = 30 + + local caption_flow = button_flow.add{type = 'flow', direction = 'horizontal'} + + local title = caption_flow.add{ + name = 'title', + type = 'label', + caption = Caravan.get_name(caravan_data), + style = 'frame_title', + ignored_by_interaction = true + } + title.style.maximal_width = 150 + + local rename_button = caption_flow.add{ + type = 'sprite-button', + name = 'py_rename_caravan_button', + style = 'frame_action_button', + sprite = 'utility/rename_icon_small_white', + hovered_sprite = 'utility/rename_icon_small_black', + clicked_sprite = 'utility/rename_icon_small_black', + tags = {unit_number = key, maximal_width = 150} + } + + button_flow.add{type = 'empty-widget'}.style.horizontally_stretchable = true + + local has_anything, tooltip = Caravan.get_inventory_tooltip(caravan_data) + local view_inventory_button = button_flow.add{ + type = 'sprite-button', + name = 'py_view_inventory_button', + style = 'frame_action_button', + sprite = 'utility/expand_dots_white', + hovered_sprite = 'utility/expand_dots', + clicked_sprite = 'utility/expand_dots', + tooltip = tooltip, + tags = {unit_number = caravan_data.unit_number} + } + view_inventory_button.visible = has_anything + + local open_caravan_button = button_flow.add{ + type = 'sprite-button', + name = 'py_click_caravan', + style = 'frame_action_button', + sprite = 'utility/logistic_network_panel_white', + hovered_sprite = 'utility/logistic_network_panel_black', + clicked_sprite = 'utility/logistic_network_panel_black', + tooltip = {'caravan-shared.open', {'entity-name.' .. entity.name}}, + tags = {unit_number = caravan_data.unit_number} + } + + local open_map_button = button_flow.add{ + type = 'sprite-button', + name = 'py_open_map_button', + style = 'frame_action_button', + sprite = 'utility/search_white', + hovered_sprite = 'utility/search_black', + clicked_sprite = 'utility/search_black', + tooltip = {'caravan-shared.view-on-map'}, + tags = {unit_number = caravan_data.unit_number} + } + + for _, button in pairs{rename_button, open_caravan_button, view_inventory_button, open_map_button} do + button.style.size = {26, 26} + button.style.top_margin = -2 + button.style.bottom_margin = -4 + end + + local camera_frame = table.add{type = 'frame', name = 'camera_frame', style = 'py_nice_frame'} + local camera = camera_frame.add{type = 'camera', name = 'camera', style = 'py_caravan_camera', position = entity.position, surface_index = entity.surface.index} + camera.entity = entity + camera.visible = true + camera.style.height = 155 + camera.zoom = (prototype.camera_zoom or 1) / 2 + + local status_flow = table.add{type = 'flow', direction = 'horizontal'} + status_flow.style.height = 0 + status_flow.style.top_margin = -26 + status_flow.style.bottom_margin = 6 + status_flow.style.left_margin = 5 + local status_sprite = status_flow.add{type = 'sprite'} + status_sprite.resize_to_sprite = false + status_sprite.style.size = {16, 16} + local status_text = status_flow.add{type = 'label'} + local state, img = Caravan.status_img(caravan_data) + status_text.caption = {'', '[font=default-bold]', state, '[/font]'} + status_sprite.sprite = img + status_text.style.right_margin = 4 +end + +gui_events[defines.events.on_gui_click]['py_click_caravan'] = function(event) + local player = game.get_player(event.player_index) + local element = event.element + local tags = element.tags + local caravan_data = global.caravans[tags.unit_number] + if Caravan.validity_check(caravan_data) then + Caravan.build_gui(player, caravan_data.entity, true) + end +end + +gui_events[defines.events.on_gui_click]['py_view_inventory_button'] = function(event) + local element = event.element + local tags = element.tags + local caravan_data = global.caravans[tags.unit_number] + local has_anything, tooltip = Caravan.get_inventory_tooltip(caravan_data) + element.tooltip = tooltip + element.visible = has_anything +end + +gui_events[defines.events.on_gui_click]['py_open_map_button'] = function(event) + local player = game.get_player(event.player_index) + local element = event.element + local tags = element.tags + local caravan_data = global.caravans[tags.unit_number] + local entity = caravan_data.entity + + player.opened = nil + player.zoom_to_world(entity.position, 0.5, entity) +end + +local function title_edit_mode(caption_flow, caravan_data) + local title = caption_flow.title + local index = title.get_index_in_parent() + title.destroy() + + local textfield = caption_flow.add{ + type = 'textfield', + name = 'py_rename_caravan_textfield', + text = Caravan.get_name(caravan_data), + tags = {index = caravan_data.entity.unit_number}, + index = index + } + textfield.focus() + textfield.select_all() + textfield.style.top_margin = -5 + textfield.style.maximal_width = 150 + local button = caption_flow.py_rename_caravan_button + button.style = 'item_and_count_select_confirm' + button.sprite = 'utility/check_mark' + button.hovered_sprite = 'utility/check_mark' + button.clicked_sprite = 'utility/check_mark' + button.style.size = {26, 26} + button.style.top_margin = -2 + button.style.bottom_margin = -4 +end + +local function title_display_mode(caption_flow, caravan_data) + local textfield = caption_flow.py_rename_caravan_textfield + local index = textfield.get_index_in_parent() + textfield.destroy() + + local title = caption_flow.add{ + type = 'label', + name = 'title', + caption = Caravan.get_name(caravan_data), + style = 'frame_title', + ignored_by_interaction = true, + index = index + } + local button = caption_flow.py_rename_caravan_button + button.style = 'frame_action_button' + button.sprite = 'utility/rename_icon_small_white' + button.hovered_sprite = 'utility/rename_icon_small_black' + button.clicked_sprite = 'utility/rename_icon_small_black' + + title.style.maximal_width = button.tags.maximal_width or error('No maximal width') +end + +gui_events[defines.events.on_gui_click]['py_rename_caravan_button'] = function(event) + local element = event.element + local caravan_data = global.caravans[element.tags.unit_number] + local caption_flow = element.parent + if caption_flow.title then + title_edit_mode(caption_flow, caravan_data) + else + title_display_mode(caption_flow, caravan_data) + end +end + +gui_events[defines.events.on_gui_text_changed]['py_rename_caravan_textfield'] = function(event) + local element = event.element + local caravan_data = global.caravans[element.tags.index] + caravan_data.name = element.text +end + +gui_events[defines.events.on_gui_confirmed]['py_rename_caravan_textfield'] = function(event) + local element = event.element + local caravan_data = global.caravans[element.tags.index] + title_display_mode(element.parent, caravan_data) +end \ No newline at end of file diff --git a/scripts/caravan/caravan-gui.lua b/scripts/caravan/caravan-gui.lua index fec8f82a..7ab8b91c 100644 --- a/scripts/caravan/caravan-gui.lua +++ b/scripts/caravan/caravan-gui.lua @@ -2,6 +2,7 @@ local prototypes = require 'caravan-prototypes' local Table = require('__stdlib__/stdlib/utils/table') local Position = require('__stdlib__/stdlib/area/position') local FUN = require '__pycoalprocessing__/prototypes/functions/functions' +require 'caravan-gui-shared' local function generate_button_status(caravan_data, schedule_id, action_id) local style = 'train_schedule_action_button' @@ -136,29 +137,62 @@ function Caravan.build_schedule_gui(gui, caravan_data) gui.add{type = 'button', name = 'py_add_outpost', style = 'train_schedule_add_station_button', caption = {'caravan-gui.add-outpost'}} end -function Caravan.build_gui(player, entity) +function Caravan.build_gui(player, entity, from_remote_manager) local caravan_data = global.caravans[entity.unit_number] local prototype = prototypes[entity.name] local main_frame - if prototype.opens_player_inventory then + if from_remote_manager then + player.opened = nil + main_frame = player.gui.screen.add{type = 'frame', name = 'caravan_gui', direction = 'vertical'} + main_frame.auto_center = true + player.opened = main_frame + else player.opened = caravan_data.inventory - main_frame = player.gui.relative.add{ - type = 'frame', name = 'caravan_gui', caption = entity.prototype.localised_name, direction = 'vertical', + local flow = player.gui.relative.add { + type = 'flow', name = 'caravan_flow', anchor = { gui = defines.relative_gui_type.script_inventory_gui, position = defines.relative_gui_position.right - } + }, + + } + flow.style.horizontal_spacing = 0 + main_frame = flow.add { + type = 'frame', name = 'caravan_gui', direction = 'vertical' } - else - 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 end main_frame.style.width = 436 main_frame.style.minimal_height = 710 + main_frame.style.margin = 0 main_frame.tags = {unit_number = entity.unit_number} + local caption_flow = main_frame.add{type = 'flow', direction = 'horizontal'} + + local title = caption_flow.add{ + name = 'title', + type = 'label', + caption = Caravan.get_name(caravan_data), + style = 'frame_title', + ignored_by_interaction = true + } + title.style.maximal_width = 300 + + local rename_button = caption_flow.add{ + type = 'sprite-button', + name = 'py_rename_caravan_button', + style = 'frame_action_button', + sprite = 'utility/rename_icon_small_white', + hovered_sprite = 'utility/rename_icon_small_black', + clicked_sprite = 'utility/rename_icon_small_black', + tags = {unit_number = entity.unit_number, maximal_width = 300} + } + + local caption_spacing = caption_flow.add{type = 'empty-widget', style = 'draggable_space_header', ignored_by_interaction = true} + caption_spacing.style.height = 24 + caption_spacing.style.right_margin = 4 + caption_spacing.style.horizontally_stretchable = true + local content_frame = main_frame.add{type = 'frame', name = 'content_frame', 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', direction = 'vertical'} @@ -207,6 +241,7 @@ function Caravan.build_gui(player, entity) schedule_pane.style.horizontally_stretchable = true schedule_pane.style.vertically_stretchable = true Caravan.update_gui(main_frame) + Caravan.build_gui_connected(player, entity) end Caravan.events.on_open_gui = function(event) @@ -235,25 +270,9 @@ function Caravan.update_gui(gui, weak) local caravan_data = global.caravans[gui.tags.unit_number] if not Caravan.validity_check(caravan_data) then gui.destroy() return end local content_flow = gui.content_frame.content_flow - local entity = caravan_data.entity - - local status, img - if caravan_data.is_aerial then - status = {'entity-status.working'} - img = 'utility/status_working' - elseif caravan_data.fuel_bar == 0 and caravan_data.fuel_inventory.is_empty() then - status = {'entity-status.starved'} - img = 'utility/status_not_working' - elseif entity.health ~= entity.prototype.max_health then - status = {'entity-status.wounded'} - img = 'utility/status_yellow' - else - status = {'entity-status.healthy'} - img = 'utility/status_working' - end - content_flow.status_flow.status_text.caption = status + local state, img = Caravan.status_img(caravan_data) + content_flow.status_flow.status_text.caption = state content_flow.status_flow.status_sprite.sprite = img - if caravan_data.fuel_inventory then for i = 1, #caravan_data.fuel_inventory do local stack = caravan_data.fuel_inventory[i] @@ -278,13 +297,31 @@ end Caravan.events.close_gui = function(event) local player = game.get_player(event.player_index) + + if player.gui.relative.py_global_caravan_gui then + player.gui.relative.py_global_caravan_gui.destroy() + end + if player.gui.screen.py_global_caravan_gui then + player.gui.screen.py_global_caravan_gui.destroy() + end + if event.gui_type == defines.gui_type.script_inventory or event.gui_type == defines.gui_type.custom then local gui = Caravan.get_caravan_gui(player) if gui then gui.destroy() end + if player.gui.relative.caravan_flow then + player.gui.relative.caravan_flow.destroy() + end + end +end + +local function get_caravan_gui_in_flow(player) + if player.gui.relative.caravan_flow then + return player.gui.relative.caravan_flow.caravan_gui end end function Caravan.get_caravan_gui(player) - local gui = player.gui.relative.caravan_gui or player.gui.screen.caravan_gui + local gui = get_caravan_gui_in_flow(player) or player.gui.screen.caravan_gui if gui then return gui end -end \ No newline at end of file +end + diff --git a/scripts/caravan/caravan.lua b/scripts/caravan/caravan.lua index f47ade81..163a133e 100644 --- a/scripts/caravan/caravan.lua +++ b/scripts/caravan/caravan.lua @@ -1,7 +1,10 @@ Caravan = {} Caravan.events = {} +require 'italian-names' require 'caravan-gui' +require 'caravan-global-gui' +require 'caravan-connected-gui' local prototypes = require 'caravan-prototypes' local Position = require('__stdlib__/stdlib/area/position') local Table = require('__stdlib__/stdlib/utils/table') @@ -99,6 +102,10 @@ Caravan.events.used_capsule = function(event) Caravan.build_gui(player, caravan_data.entity) end +Caravan.is_automated = function(caravan_data) + return caravan_data.schedule_id and caravan_data.schedule_id >= 0 +end + local function eat(caravan_data) if caravan_data.fuel_bar == 0 then local fuel = caravan_data.fuel_inventory @@ -464,20 +471,6 @@ Caravan.events[60] = function(event) local entity = caravan_data.entity local needs_fuel = caravan_data.fuel_inventory and caravan_data.fuel_bar == 0 and caravan_data.fuel_inventory.is_empty() - -- this was causing too much lag. waiting on a new API feature that will help - --[[local icon - if needs_fuel then icon = no_fuel_map_tag else icon = prototypes[entity.name].map_tag end - local map_tag = caravan_data.map_tag - if map_tag and map_tag.valid then - if icon == map_tag.icon and map_tag.position.x == entity.position.x and map_tag.position.y == entity.position.y then goto didnt_move end - map_tag.destroy() - end - caravan_data.map_tag = entity.force.add_chart_tag(entity.surface, { - position = entity.position, - icon = icon - }) - ::didnt_move::--]] - if needs_fuel then draw_error_sprite(entity, 'utility.fuel_icon', 30) goto continue @@ -602,6 +595,15 @@ Caravan.events.on_destroyed = function(event) local buffer = event.buffer if buffer then buffer[1].tags = {unit_number = entity.unit_number} + local caravan_data = global.caravans[entity.unit_number] + if caravan_data then + buffer[1].custom_description = { + '', + {'caravan-gui.hello-my-name-is', Caravan.get_name(caravan_data)}, + '\n', + entity.prototype.localised_description + } + end end global.caravan_queue = nil end diff --git a/scripts/caravan/italian-names.lua b/scripts/caravan/italian-names.lua new file mode 100644 index 00000000..ab571732 --- /dev/null +++ b/scripts/caravan/italian-names.lua @@ -0,0 +1,634 @@ +-- taken from +-- https://en.wikipedia.org/wiki/Category:Italian_masculine_given_names +-- https://en.wikipedia.org/wiki/Category:Italian_feminine_given_names + +local names = { + 'Achille', + 'Adamo', + 'Adelmo', + 'Adeodatus', + 'Adriano', + 'Afonso', + 'Agnolo', + 'Agostino', + 'Alberico', + 'Alberto', + 'Alderano', + 'Aldo', + 'Alessandro', + 'Alessio', + 'Alfeo', + 'Alfio', + 'Alfredo', + 'Alphons', + 'Amadeo', + 'Amedeo', + 'Amleto', + 'Angelo', + 'Annibale', + 'Ansaldo', + 'Antonello', + 'Antonino', + 'Antonio', + 'Arcangelo', + 'Ariosto', + 'Armando', + 'Arnaldo', + 'Arnoldo', + 'Arnulfo', + 'Arrigo', + 'Arsenio', + 'Arturo', + 'Atanasio', + 'Atenolfo', + 'Atenulfo', + 'Attilio', + 'Augusto', + 'Aurelio', + 'Azeglio', + 'Baccio', + 'Baldassare', + 'Bartolomeo', + 'Benedetto', + 'Benito', + 'Benvenuto', + 'Beppe', + 'Bernardo', + 'Bertoldo', + 'Biagio', + 'Bonifacio', + 'Bortolo', + 'Brunello', + 'Bruno', + 'Calcedonio', + 'Calogero', + 'Camillo', + 'Candido', + 'Carlo', + 'Carmelo', + 'Carmine', + 'Cesare', + 'Cipriano', + 'Cirillo', + 'Ciro', + 'Claudio', + 'Cola', + 'Coluccio', + 'Constanzo', + 'Coriolano', + 'Cornelio', + 'Corrado', + 'Cosmo', + 'Costante', + 'Costantino', + 'Costanzo', + 'Cristoforo', + 'Curzio', + 'Danilo', + 'Damiano', + 'Daniele', + 'Daniello', + 'Dante', + 'Dario', + 'Davide', + 'Decio', + 'Delfino', + 'Dino', + 'Dionigi', + 'Domenico', + 'Donatello', + 'Donato', + 'Durante', + 'Edgardo', + 'Edmondo', + 'Edoardo', + 'Egidio', + 'Eligio', + 'Elio', + 'Elladio', + 'Elmo', + 'Elpidio', + 'Elvio', + 'Emanuele', + 'Emidio', + 'Emiliano', + 'Emilio', + 'Ennio', + 'Enrico', + 'Enzio', + 'Enzo', + 'Eraldo', + 'Ercole', + 'Ermanno', + 'Ermenegildo', + 'Ermes', + 'Erminio', + 'Ernesto', + 'Esterino', + 'Ettore', + 'Eugenio', + 'Ezio', + 'Fabio', + 'Fabrizio', + 'Faustino', + 'Fausto', + 'Fazio', + 'Fedele', + 'Federico', + 'Federigo', + 'Ferdinando', + 'Ferruccio', + 'Filiberto', + 'Filippino', + 'Filippo', + 'Filomeno', + 'Fiorentino', + 'Fiorenzo', + 'Fiorino', + 'Flavio', + 'Fosco', + 'Francesco', + 'Franco', + 'Fredo', + 'Fulgenzio', + 'Fulvio', + 'Furio', + 'Gabriele', + 'Gabrio', + 'Gaetano', + 'Galasso', + 'Galeazzo', + 'Gaspare', + 'Gastone', + 'Gaudenzio', + 'Gavino', + 'Gennaro', + 'Geppetto', + 'Germano', + 'Geronimo', + 'Giacinto', + 'Giacobbe', + 'Giacomo', + 'Giammaria', + 'Giampaolo', + 'Giampiero', + 'Gian', + 'Gian Carlo', + 'Gianantonio', + 'Giancarlo', + 'Gianfrancesco', + 'Gianfranco', + 'Gianluca', + 'Gianluigi', + 'Gianmarco', + 'Gianmaria', + 'Giannantonio', + 'Gianni', + 'Giannino', + 'Gianpaolo', + 'Gianpietro', + 'Gilberto', + 'Gino', + 'Gioacchino', + 'Gioachino', + 'Gioele', + 'Gioffre', + 'Giona', + 'Gionata', + 'Giornio', + 'Giulio', + 'Giordano', + 'Giorgio', + 'Giosuè', + 'Giovanni', + 'Giovanni Battista', + 'Girolamo', + 'Giuliano', + 'Giulio', + 'Giuseppe', + 'Giustino', + 'Goffredo', + 'Graziano', + 'Greco', + 'Gregorio', + 'Gualtiero', + 'Guarino', + 'Guerino', + 'Guglielmo', + 'Guido', + 'Gustavo', + 'Hugo', + 'Iacopo', + 'Ignazio', + 'Ilario', + 'Ippazio', + 'Ippolito', + 'Isidoro', + 'Italo', + 'Ivano', + 'Ivo', + 'Jacopo', + 'Lamberto', + 'Lando', + 'Laureano', + 'Lazzaro', + 'Lelio', + 'Leonardo', + 'Leone', + 'Leopoldo', + 'Liberato', + 'Liberto', + 'Livio', + 'Lodovico', + 'Lorenzo', + 'Lotario', + 'Luca', + 'Luchino', + 'Luciano', + 'Lucio', + 'Ludovico', + 'Luigi', + 'Macario', + 'Manlio', + 'Manuel', + 'Marcantonio', + 'Marcello', + 'Marco', + 'Mariano', + 'Mario', + 'Martino', + 'Massimiliano', + 'Massimo', + 'Matteo', + 'Mattia', + 'Maurilio', + 'Maurizio', + 'Mauro', + 'Michelangelo', + 'Michele', + 'Micheletto', + 'Michelotto', + 'Milo', + 'Mino', + 'Mirco', + 'Mirko', + 'Moreno', + 'Nanni', + 'Napoleone', + 'Natale', + 'Nazario', + 'Nevio', + 'Niccolò', + 'Nico', + 'Nicola', + 'Nicolao', + 'Nicolò', + 'Nino', + 'Noe', + 'Nunzio', + 'Oberdan', + 'Odoardo', + 'Oliviero', + 'Omero', + 'Onorato', + 'Onorio', + 'Orazio', + 'Oreste', + 'Orlando', + 'Osvaldo', + 'Ottavio', + 'Ottone', + 'Palmiro', + 'Pandulf', + 'Panfilo', + 'Paolo', + 'Paride', + 'Pasqual', + 'Pasquale', + 'Patrizio', + 'Pellegrino', + 'Peppino', + 'Pier', + 'Pierangelo', + 'Pierdomenico', + 'Piergiorgio', + 'Piergiuseppe', + 'Pierino', + 'Pierluigi', + 'Piermaria', + 'Piero', + 'Pierpaolo', + 'Piersanti', + 'Pietro', + 'Pompeo', + 'Pomponio', + 'Puccio', + 'Quinto', + 'Quirico', + 'Quirino', + 'Raffaele', + 'Raffaellino', + 'Raffaello', + 'Raimondo', + 'Ranieri', + 'Renato', + 'Renzo', + 'Riccardo', + 'Ricciotti', + 'Rino', + 'Roberto', + 'Rocco', + 'Rodolfo', + 'Rolando', + 'Roman', + 'Romeo', + 'Romolo', + 'Ronaldo', + 'Rosario', + 'Rossano', + 'Ruggero', + 'Ruggiero', + 'Sabatino', + 'Salvatore', + 'Salvi', + 'Samuele', + 'Sandro', + 'Sante', + 'Santino', + 'Saverio', + 'Sebastiano', + 'Sergius', + 'Severino', + 'Severo', + 'Silvano', + 'Silvestro', + 'Silvio', + 'Simone', + 'Siro', + 'Stanislao', + 'Stefano', + 'Taddeo', + 'Tarcisio', + 'Tazio', + 'Telemaco', + 'Temistocle', + 'Teodoro', + 'Tiberio', + 'Timoteo', + 'Tiziano', + 'Tobia', + 'Tommaso', + 'Toni', + 'Tonino', + 'Tonio', + 'Torquato', + 'Tullio', + 'Ubaldo', + 'Uberto', + 'Ugo', + 'Ugolino', + 'Umberto', + 'Valerio', + 'Venancio', + 'Vespasiano', + 'Vincentio', + 'Vincenzo', + 'Vinicio', + 'Virgilio', + 'Vito', + 'Vittorio', + 'Vladimiro', + 'Wladimiro', + 'Zanobi', + 'Adelasia', + 'Adele', + 'Adriana', + 'Agnese', + 'Albina', + 'Alessandra', + 'Alessia', + 'Alina', + 'Allegra', + 'Amalia', + 'Amelia', + 'Angelica', + 'Angelina', + 'Anita', + 'Annalisa', + 'Annamaria', + 'Annetta', + 'Annina', + 'Annunziata', + 'Antonella', + 'Antonia', + 'Antonietta', + 'Antonina', + 'Assunta', + 'Aurora', + 'Azzurra', + 'Barbara', + 'Beatrice', + 'Bettina', + 'Bianca', + 'Bianca Maria', + 'Bridgetta', + 'Carlina', + 'Carlotta', + 'Carolina', + 'Caterina', + 'Catiuscia', + 'Cecilia', + 'Charlotte', + 'Chiara', + 'Claudia', + 'Clelia', + 'Concetta', + 'Costanza', + 'Cristiana', + 'Cristina', + 'Danila', + 'Daria', + 'Diana', + 'Diletta', + 'Dina', + 'Donatella', + 'Donna', + 'Dora', + 'Eleanora', + 'Elena', + 'Eliana', + 'Elisa', + 'Elisabetta', + 'Elvira', + 'Emilia', + 'Emma', + 'Enrica', + 'Erika', + 'Ersilia', + 'Etta', + 'Eugenia', + 'Eva', + 'Evangelista', + 'Evelina', + 'Fabia', + 'Fabrizia', + 'Federica', + 'Fernanda', + 'Fiammetta', + 'Filippa', + 'Fiorella', + 'Fiorenza', + 'Flavia', + 'Fortunata', + 'Franca', + 'Francesca', + 'Gelsomina', + 'Gemma', + 'Germana', + 'Gessica', + 'Gia', + 'Giada', + 'Gianna', + 'Gigliola', + 'Gina', + 'Ginevra', + 'Giorgia', + 'Giovanna', + 'Gisela', + 'Gisella', + 'Giulia', + 'Giuliana', + 'Giulietta', + 'Giuseppina', + 'Gloria', + 'Gloriana', + 'Graziella', + 'Greca', + 'Griselda', + 'Ida', + 'Ilaria', + 'Imelda', + 'Iolanda', + 'Ippolita', + 'Irene', + 'Irma', + 'Isa', + 'Isabella', + 'Italia', + 'Jolanda', + 'Lara', + 'Larissa', + 'Laura', + 'Lauretta', + 'Letizia', + 'Licia', + 'Lidia', + 'Liliana', + 'Lilla', + 'Lina', + 'Lisa', + 'Livia', + 'Lolita', + 'Loredana', + 'Lorena', + 'Loretta', + 'Lucia', + 'Luciana', + 'Lucrezia', + 'Ludovica', + 'Luigina', + 'Luisa', + 'Manila', + 'Marcella', + 'Margherita', + 'Maria', + 'Maria Antonietta', + 'Maria Sole', + 'Mariana', + 'Mariella', + 'Marina', + 'Marisa', + 'Marta', + 'Martina', + 'Matilda', + 'Maura', + 'Melania', + 'Melina', + 'Melissa', + 'Michela', + 'Milena', + 'Monica', + 'Morena', + 'Nadia', + 'Natalia', + 'Nedda', + 'Nicoletta', + 'Nina', + 'Ninetta', + 'Nunzia', + 'Olga', + 'Ornella', + 'Ottavia', + 'Paloma', + 'Paola', + 'Paoletta', + 'Patrizia', + 'Paulina', + 'Piera', + 'Pierina', + 'Pina', + 'Raffaella', + 'Ramona', + 'Renata', + 'Rita', + 'Roberta', + 'Romana', + 'Romilda', + 'Romina', + 'Rosa', + 'Rosalba', + 'Rosalia', + 'Rosaria', + 'Rosetta', + 'Rosina', + 'Rossana', + 'Rossella', + 'Santina', + 'Serafina', + 'Serena', + 'Sibilla', + 'Silvia', + 'Simonetta', + 'Sonia', + 'Sophia', + 'Stefania', + 'Stella', + 'Susanna', + 'Sylvia', + 'Tatiana', + 'Teresa', + 'Tiziana', + 'Tonia', + 'Tonina', + 'Valentina', + 'Valeria', + 'Vanessa', + 'Vanna', + 'Verona', + 'Veronica', + 'Vincenza', + 'Virginia', + 'Viridiana', + 'Vitalia', + 'Vittoria', + 'Zita' +} + +function Caravan.get_name(caravan_data) + local name = caravan_data.name + if name and name ~= '' then return name end + local random_name = caravan_data.random_name or names[math.random(1, #names)] + caravan_data.random_name = random_name + caravan_data.name = random_name + return random_name +end \ No newline at end of file diff --git a/scripts/wiki/text-pages.lua b/scripts/wiki/text-pages.lua index d21338d9..dab0bd08 100644 --- a/scripts/wiki/text-pages.lua +++ b/scripts/wiki/text-pages.lua @@ -16,6 +16,12 @@ Wiki.events.on_init = function() text_only = true }) + remote.call('pywiki', 'add_page', { + name = 'caravan-manager', + section = 'alienlife', + remote = {'pywiki_caravan_manager', 'create_gui'}, + }) + remote.call('pywiki', 'add_page', { name = 'mounts', section = 'alienlife',