local mod_gui = require("__core__.lualib.mod-gui") local roster = {} local PLANETS = {"nauvis", "vulcanus", "fulgora", "gleba"} local function format_playtime(ticks) local total_seconds = math.floor((ticks or 0) / 60) local hours = math.floor(total_seconds / 3600) local minutes = math.floor((total_seconds % 3600) / 60) return string.format("%d:%02d", hours, minutes) end function roster.create_button(player) if not (player and player.valid) then return end local flow = mod_gui.get_button_flow(player) if flow.pvp_roster_button then return end flow.add{ type = "sprite-button", name = "pvp_roster_button", sprite = "entity/character", tooltip = "Team roster", } end local function build_window(player) if player.gui.screen.pvp_roster_frame then player.gui.screen.pvp_roster_frame.destroy() end local frame = player.gui.screen.add{type = "frame", name = "pvp_roster_frame", caption = "TEAM ROSTER", direction = "vertical"} frame.auto_center = true local any_team = false for _, planet in ipairs(PLANETS) do local force_name = storage.planet_teams and storage.planet_teams[planet] if force_name then any_team = true local color = storage.force_colors and storage.force_colors[force_name] local header = frame.add{type = "label", caption = force_name .. " (" .. planet .. ")", style = "caption_label"} if color then header.style.font_color = color end local found = false for _, target in pairs(game.players) do if target.force and target.force.name == force_name then found = true local status = target.connected and "" or " (offline)" local line = frame.add{type = "label", caption = " " .. target.name .. status .. " - " .. format_playtime(target.online_time)} if color then line.style.font_color = color end end end if not found then frame.add{type = "label", caption = " (no players)"} end end end if not any_team then frame.add{type = "label", caption = "No teams initialized yet."} end local buttons = frame.add{type = "flow", direction = "horizontal"} buttons.add{type = "button", name = "pvp_roster_refresh", caption = "Refresh"} buttons.add{type = "button", name = "pvp_roster_close", caption = "Close"} end function roster.on_gui_click(event) local element = event.element if not (element and element.valid) then return false end local player = game.get_player(event.player_index) if not (player and player.valid) then return false end if element.name == "pvp_roster_button" then if player.gui.screen.pvp_roster_frame then player.gui.screen.pvp_roster_frame.destroy() else build_window(player) end return true end if element.name == "pvp_roster_refresh" then build_window(player) return true end if element.name == "pvp_roster_close" then if player.gui.screen.pvp_roster_frame then player.gui.screen.pvp_roster_frame.destroy() end return true end return false end return roster