diff --git a/maps/pirates/gui/crew.lua b/maps/pirates/gui/crew.lua index 3dbcbe29..6e35e33b 100644 --- a/maps/pirates/gui/crew.lua +++ b/maps/pirates/gui/crew.lua @@ -1,6 +1,5 @@ -- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/danielmartin0/ComfyFactorio-Pirates. - local Memory = require 'maps.pirates.memory' local Common = require 'maps.pirates.common' local Utils = require 'maps.pirates.utils_local' @@ -11,30 +10,36 @@ local CoreData = require 'maps.pirates.coredata' local Server = require 'utils.server' local Public = {} - local window_name = 'crew' local function get_selected_player_index(flow) - if flow.members.body.members_listbox.selected_index ~= 0 then - return tonumber(flow.members.body.members_listbox.get_item(flow.members.body.members_listbox.selected_index)[2]) - else - return nil - end + if flow.members.body.members_listbox.selected_index ~= 0 then + return tonumber(flow.members.body.members_listbox.get_item(flow.members.body.members_listbox.selected_index)[2]) + else + return nil + end end function Public.toggle_window(player) - local memory = Memory.get_crew_memory() - local flow, flow2, flow3 - local window + local memory = Memory.get_crew_memory() + local get_global_memory = Memory.get_global_memory() + local flow, flow2, flow3 + local window - --*** OVERALL FLOW ***-- - if player.gui.screen[window_name .. '_piratewindow'] then player.gui.screen[window_name .. '_piratewindow'].destroy() return end + --*** OVERALL FLOW ***-- + if player.gui.screen[window_name .. '_piratewindow'] then + player.gui.screen[window_name .. '_piratewindow'].destroy() + return + end - if not Common.is_id_valid(memory.id) then return end + if not Common.is_id_valid(memory.id) then + return + end - window = GuiCommon.new_window(player, window_name) + window = GuiCommon.new_window(player, window_name) - flow = window.add { + flow = + window.add { type = 'scroll-pane', name = 'scroll_pane', direction = 'vertical', @@ -42,502 +47,570 @@ function Public.toggle_window(player) vertical_scroll_policy = 'auto' } flow.style.maximal_height = 500 - flow.style.bottom_padding = 20 + flow.style.bottom_padding = 20 - --*** PARAMETERS OF RUN ***-- + --*** PARAMETERS OF RUN ***-- - flow2 = flow.add({ - name = 'crew_capacity_and_difficulty', - type = 'label', - }) - flow2.style.left_margin = 5 - flow2.style.top_margin = 0 - flow2.style.bottom_margin = -3 - flow2.style.single_line = false - flow2.style.maximal_width = 190 - flow2.style.font = 'default' + flow2 = + flow.add( + { + name = 'crew_capacity_and_difficulty', + type = 'label' + } + ) + flow2.style.left_margin = 5 + flow2.style.top_margin = 0 + flow2.style.bottom_margin = -3 + flow2.style.single_line = false + flow2.style.maximal_width = 190 + flow2.style.font = 'default' - flow2 = flow.add({ - name = 'crew_age', - type = 'label', - }) - flow2.style.left_margin = 5 - flow2.style.top_margin = -3 - flow2.style.bottom_margin = 0 - flow2.style.single_line = true - flow2.style.maximal_width = 200 - flow2.style.font = 'default' + flow2 = + flow.add( + { + name = 'crew_age', + type = 'label' + } + ) + flow2.style.left_margin = 5 + flow2.style.top_margin = -3 + flow2.style.bottom_margin = 0 + flow2.style.single_line = true + flow2.style.maximal_width = 200 + flow2.style.font = 'default' - -- flow2 = flow.add({ - -- name = 'crew_difficulty', - -- type = 'label', - -- }) - -- flow2.style.left_margin = 5 - -- flow2.style.top_margin = -3 - -- flow2.style.bottom_margin = 0 - -- flow2.style.single_line = false - -- flow2.style.maximal_width = 190 - -- flow2.style.font = 'default' + -- flow2 = flow.add({ + -- name = 'crew_difficulty', + -- type = 'label', + -- }) + -- flow2.style.left_margin = 5 + -- flow2.style.top_margin = -3 + -- flow2.style.bottom_margin = 0 + -- flow2.style.single_line = false + -- flow2.style.maximal_width = 190 + -- flow2.style.font = 'default' + --*** MEMBERSHIP BUTTONS ***-- - --*** MEMBERSHIP BUTTONS ***-- + flow2 = + flow.add( + { + name = 'membership_buttons', + type = 'flow', + direction = 'horizontal' + } + ) - flow2 = flow.add({ - name = 'membership_buttons', - type = 'flow', - direction = 'horizontal', - }) + flow3 = + flow2.add( + { + name = 'leave_crew', + type = 'button', + caption = {'pirates.gui_crew_window_buttons_quit_crew'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_buttons_quit_crew_tooltip'} - flow3 = flow2.add({ - name = 'leave_crew', - type = 'button', - caption = {'pirates.gui_crew_window_buttons_quit_crew'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_buttons_quit_crew_tooltip'} + flow3 = + flow2.add( + { + name = 'leave_spectators', + type = 'button', + caption = {'pirates.gui_crew_window_buttons_quit_spectators'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} - flow3 = flow2.add({ - name = 'leave_spectators', - type = 'button', - caption = {'pirates.gui_crew_window_buttons_quit_spectators'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} + flow3 = + flow2.add( + { + name = 'spectator_join_crew', + type = 'button', + caption = {'pirates.gui_crew_window_buttons_join_crew'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} - flow3 = flow2.add({ - name = 'spectator_join_crew', - type = 'button', - caption = {'pirates.gui_crew_window_buttons_join_crew'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} + flow3 = + flow2.add( + { + name = 'crewmember_join_spectators', + type = 'button', + caption = {'pirates.gui_crew_window_buttons_join_spectators'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_buttons_join_spectators_tooltip'} - flow3 = flow2.add({ - name = 'crewmember_join_spectators', - type = 'button', - caption = {'pirates.gui_crew_window_buttons_join_spectators'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_buttons_join_spectators_tooltip'} + --*** MEMBERS AND SPECTATORS ***-- - --*** MEMBERS AND SPECTATORS ***-- + flow2 = GuiCommon.flow_add_section(flow, 'members', {'pirates.gui_crew_window_crewmembers'}) - flow2 = GuiCommon.flow_add_section(flow, 'members', {'pirates.gui_crew_window_crewmembers'}) + flow3 = + flow2.add( + { + name = 'members_listbox', + type = 'list-box' + } + ) + flow3.style.margin = 2 + flow3.style.maximal_height = 350 - flow3 = flow2.add({ - name = 'members_listbox', - type = 'list-box', - }) - flow3.style.margin = 2 - flow3.style.maximal_height = 350 + flow3 = + flow2.add( + { + name = 'officer_resign', + type = 'button', + caption = {'pirates.gui_crew_window_crewmembers_resign_as_officer'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_crewmembers_resign_as_officer_tooltip'} - flow3 = flow2.add({ - name = 'officer_resign', - type = 'button', - caption = {'pirates.gui_crew_window_crewmembers_resign_as_officer'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_crewmembers_resign_as_officer_tooltip'} + flow2 = GuiCommon.flow_add_section(flow, 'spectators', {'pirates.gui_crew_window_spectators'}) - flow2 = GuiCommon.flow_add_section(flow, 'spectators', {'pirates.gui_crew_window_spectators'}) + flow3 = + flow2.add( + { + name = 'spectators_listbox', + type = 'list-box' + } + ) + flow3.style.margin = 2 + flow3.style.maximal_height = 150 + --*** DIFFICULTY VOTE ***-- - flow3 = flow2.add({ - name = 'spectators_listbox', - type = 'list-box', - }) - flow3.style.margin = 2 - flow3.style.maximal_height = 150 + flow2 = GuiCommon.flow_add_section(flow, 'difficulty_vote', {'pirates.gui_crew_window_vote_for_difficulty'}) - --*** DIFFICULTY VOTE ***-- + for i, o in ipairs(CoreData.difficulty_options) do + flow3 = + flow2.add( + { + name = 'difficulty_option_' .. i, + type = 'button', + caption = o.text + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + end - flow2 = GuiCommon.flow_add_section(flow, 'difficulty_vote', {'pirates.gui_crew_window_vote_for_difficulty'}) + --*** CAPTAIN's ACTIONS ***-- - for i, o in ipairs(CoreData.difficulty_options) do - flow3 = flow2.add({ - name = 'difficulty_option_' .. i, - type = 'button', - caption = o.text, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - end + flow2 = GuiCommon.flow_add_section(flow, 'captain', {'pirates.gui_crew_window_captains_actions'}) - --*** CAPTAIN's ACTIONS ***-- + if get_global_memory.disband_crews then + flow3 = + flow2.add( + { + name = 'capn_disband_crew', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_disband_crew'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_disband_crew_tooltip'} - flow2 = GuiCommon.flow_add_section(flow, 'captain', {'pirates.gui_crew_window_captains_actions'}) + flow3 = + flow2.add( + { + name = 'capn_disband_are_you_sure', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_disband_crew_check'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_disband_crew_check_tooltip'} + end - flow3 = flow2.add({ - name = 'capn_disband_crew', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_disband_crew'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_disband_crew_tooltip'} + flow3 = + flow2.add( + { + name = 'capn_renounce', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_renounce_title'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_renounce_title_tooltip'} - flow3 = flow2.add({ - name = 'capn_disband_are_you_sure', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_disband_crew_check'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_disband_crew_check_tooltip'} + flow3 = + flow2.add( + { + name = 'capn_pass', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_pass_title'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_pass_title_tooltip'} - flow3 = flow2.add({ - name = 'capn_renounce', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_renounce_title'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_renounce_title_tooltip'} + flow3 = + flow2.add( + { + name = 'capn_plank', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_plank'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_plank_tooltip'} - flow3 = flow2.add({ - name = 'capn_pass', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_pass_title'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_pass_title_tooltip'} - - flow3 = flow2.add({ - name = 'capn_plank', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_plank'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_plank_tooltip'} - - flow3 = flow2.add({ - name = 'line', - type = 'line', - }) + flow3 = + flow2.add( + { + name = 'line', + type = 'line' + } + ) flow3.style.width = 50 flow3.style.left_margin = 20 flow3.style.top_margin = 4 flow3.style.bottom_margin = 4 - -- flow3 = flow2.add({ - -- name = 'capn_undock_normal', - -- type = 'button', - -- caption = 'Undock Boat', - -- }) - -- flow3.style.minimal_width = 95 - -- flow3.style.font = 'default-bold' - -- flow3.style.font_color = {r=0.10, g=0.10, b=0.10} + -- flow3 = flow2.add({ + -- name = 'capn_undock_normal', + -- type = 'button', + -- caption = 'Undock Boat', + -- }) + -- flow3.style.minimal_width = 95 + -- flow3.style.font = 'default-bold' + -- flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3 = flow2.add({ - name = 'make_officer', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_make_officer'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_make_officer_tooltip'} + flow3 = + flow2.add( + { + name = 'make_officer', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_make_officer'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_make_officer_tooltip'} - flow3 = flow2.add({ - name = 'unmake_officer', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_unmake_officer'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_unmake_officer_tooltip'} + flow3 = + flow2.add( + { + name = 'unmake_officer', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_unmake_officer'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_unmake_officer_tooltip'} - flow3 = flow2.add({ - name = 'capn_summon_crew', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_summon_crew'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_summon_crew_tooltip'} + flow3 = + flow2.add( + { + name = 'capn_summon_crew', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_summon_crew'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_summon_crew_tooltip'} - flow3 = flow2.add({ - name = 'capn_requisition', - type = 'button', - caption = {'pirates.gui_crew_window_captains_actions_tax'}, - }) - flow3.style.minimal_width = 95 - flow3.style.font = 'default-bold' - flow3.style.font_color = {r=0.10, g=0.10, b=0.10} - flow3.tooltip = {'pirates.gui_crew_window_captains_actions_tax_tooltip', Common.coin_tax_percentage} + flow3 = + flow2.add( + { + name = 'capn_requisition', + type = 'button', + caption = {'pirates.gui_crew_window_captains_actions_tax'} + } + ) + flow3.style.minimal_width = 95 + flow3.style.font = 'default-bold' + flow3.style.font_color = {r = 0.10, g = 0.10, b = 0.10} + flow3.tooltip = {'pirates.gui_crew_window_captains_actions_tax_tooltip', Common.coin_tax_percentage} + flow2 = + flow.add( + { + name = 'undock_tip', + type = 'label' + } + ) + flow2.style.left_margin = 5 + flow2.style.top_margin = -8 + flow2.style.bottom_margin = 7 + flow2.style.single_line = false + flow2.style.maximal_width = 190 + flow2.style.font = 'default' + flow2.caption = {'pirates.gui_crew_window_captains_actions_undock_tip'} - flow2 = flow.add({ - name = 'undock_tip', - type = 'label', - }) - flow2.style.left_margin = 5 - flow2.style.top_margin = -8 - flow2.style.bottom_margin = 7 - flow2.style.single_line = false - flow2.style.maximal_width = 190 - flow2.style.font = 'default' - flow2.caption = {'pirates.gui_crew_window_captains_actions_undock_tip'} - - - GuiCommon.flow_add_close_button(window, window_name .. '_piratebutton') + GuiCommon.flow_add_close_button(window, window_name .. '_piratebutton') end - - - - -- function Public.regular_update(player) -- end function Public.full_update(player) - if Public.regular_update then Public.regular_update(player) end + if Public.regular_update then + Public.regular_update(player) + end - if not player.gui.screen[window_name .. '_piratewindow'] then return end - local window = player.gui.screen[window_name .. '_piratewindow'] - local flow = window.scroll_pane + if not player.gui.screen[window_name .. '_piratewindow'] then + return + end + local window = player.gui.screen[window_name .. '_piratewindow'] + local flow = window.scroll_pane + local memory = Memory.get_crew_memory() + local playercrew_status = GuiCommon.crew_overall_state_bools(player.index) - local memory = Memory.get_crew_memory() - local playercrew_status = GuiCommon.crew_overall_state_bools(player.index) + --*** WHAT TO SHOW ***-- + flow.difficulty_vote.visible = memory.overworldx and memory.overworldx == 0 - --*** WHAT TO SHOW ***-- + flow.members.body.officer_resign.visible = Common.is_officer(player.index) - flow.difficulty_vote.visible = memory.overworldx and memory.overworldx == 0 + local selected_player_index = get_selected_player_index(flow) + local other_player_selected = flow.members.body.members_listbox.selected_index ~= 0 and selected_player_index ~= player.index - flow.members.body.officer_resign.visible = Common.is_officer(player.index) + flow.captain.visible = Common.is_captain(player) + flow.undock_tip.visible = Common.is_captain(player) + flow.captain.body.capn_pass.visible = other_player_selected + flow.captain.body.capn_plank.visible = other_player_selected - local selected_player_index = get_selected_player_index(flow) - local other_player_selected = flow.members.body.members_listbox.selected_index ~= 0 and selected_player_index ~= player.index + flow.captain.body.make_officer.visible = other_player_selected and (not Common.is_officer(selected_player_index)) + flow.captain.body.unmake_officer.visible = other_player_selected and Common.is_officer(selected_player_index) - flow.captain.visible = Common.is_captain(player) - flow.undock_tip.visible = Common.is_captain(player) + -- flow.captain.body.capn_undock_normal.visible = memory.boat and memory.boat.state and ((memory.boat.state == Boats.enum_state.LANDED) or (memory.boat.state == Boats.enum_state.APPROACHING) or (memory.boat.state == Boats.enum_state.DOCKED)) - flow.captain.body.capn_pass.visible = other_player_selected - flow.captain.body.capn_plank.visible = other_player_selected + flow.captain.body.capn_summon_crew.visible = false + flow.captain.body.capn_requisition.visible = true + -- flow.captain.body.capn_summon_crew.visible = memory.boat and memory.boat.state and (memory.boat.state == Boats.enum_state.RETREATING or memory.boat.state == Boats.enum_state.LEAVING_DOCK) - flow.captain.body.make_officer.visible = other_player_selected and (not Common.is_officer(selected_player_index)) - flow.captain.body.unmake_officer.visible = other_player_selected and Common.is_officer(selected_player_index) + local get_global_memory = Memory.get_global_memory() - -- flow.captain.body.capn_undock_normal.visible = memory.boat and memory.boat.state and ((memory.boat.state == Boats.enum_state.LANDED) or (memory.boat.state == Boats.enum_state.APPROACHING) or (memory.boat.state == Boats.enum_state.DOCKED)) + if get_global_memory.disband_crews then + flow.captain.body.capn_disband_are_you_sure.visible = memory.disband_are_you_sure_ticks and memory.disband_are_you_sure_ticks[player.index] and memory.disband_are_you_sure_ticks[player.index] > game.tick - 60 * 2 + flow.captain.body.capn_disband_crew.visible = not flow.captain.body.capn_disband_are_you_sure.visible + end - flow.captain.body.capn_summon_crew.visible = false - flow.captain.body.capn_requisition.visible = true - -- flow.captain.body.capn_summon_crew.visible = memory.boat and memory.boat.state and (memory.boat.state == Boats.enum_state.RETREATING or memory.boat.state == Boats.enum_state.LEAVING_DOCK) + flow.members.visible = true + flow.spectators.visible = (#memory.spectatorplayerindices > 0) + -- flow.crew_age.visible = true + -- -- flow.crew_age.visible = memory.mode and memory.mode == 'speedrun' + -- flow.crew_difficulty.visible = true - flow.captain.body.capn_disband_are_you_sure.visible = memory.disband_are_you_sure_ticks and memory.disband_are_you_sure_ticks[player.index] and memory.disband_are_you_sure_ticks[player.index] > game.tick - 60*2 - flow.captain.body.capn_disband_crew.visible = not flow.captain.body.capn_disband_are_you_sure.visible + local count = 0 + if playercrew_status.spectating then + for _, v in pairs(memory.crewplayerindices) do + if Common.validate_player(game.players[v]) then + count = count + 1 + end + end + end + flow.membership_buttons.spectator_join_crew.visible = playercrew_status.spectating and (not (count >= memory.capacity)) - flow.members.visible = true - flow.spectators.visible = (#memory.spectatorplayerindices > 0) - -- flow.crew_age.visible = true - -- -- flow.crew_age.visible = memory.mode and memory.mode == 'speedrun' - -- flow.crew_difficulty.visible = true + flow.membership_buttons.leave_crew.visible = playercrew_status.adventuring + -- flow.membership_buttons.crewmember_join_spectators.visible = playercrew_status.adventuring + flow.membership_buttons.crewmember_join_spectators.visible = false --disabled spectators for now... might not play well with maze world + flow.membership_buttons.leave_spectators.visible = playercrew_status.spectating - local count = 0 - if playercrew_status.spectating then - for _, v in pairs(memory.crewplayerindices) do - if Common.validate_player(game.players[v]) then count = count + 1 end - end - end - flow.membership_buttons.spectator_join_crew.visible = playercrew_status.spectating and (not (count >= memory.capacity)) + flow.membership_buttons.spectator_join_crew.visible = + flow.membership_buttons.spectator_join_crew.visible and (not (memory.tempbanned_from_joining_data[player.index] and game.tick < memory.tempbanned_from_joining_data[player.index] + Common.ban_from_rejoining_crew_ticks)) - flow.membership_buttons.leave_crew.visible = playercrew_status.adventuring - -- flow.membership_buttons.crewmember_join_spectators.visible = playercrew_status.adventuring - flow.membership_buttons.crewmember_join_spectators.visible = false --disabled spectators for now... might not play well with maze world - flow.membership_buttons.leave_spectators.visible = playercrew_status.spectating + --== UPDATE CONTENT ==-- - flow.membership_buttons.spectator_join_crew.visible = flow.membership_buttons.spectator_join_crew.visible and (not (memory.tempbanned_from_joining_data[player.index] and game.tick < memory.tempbanned_from_joining_data[player.index] + Common.ban_from_rejoining_crew_ticks)) + if Common.is_id_valid(memory.id) then + window.caption = memory.name + flow.crew_age.caption = {'pirates.gui_crew_window_crew_age', Utils.time_mediumform((memory.age or 0) / 60)} + flow.crew_capacity_and_difficulty.caption = {'pirates.gui_crew_window_crew_capacity_and_difficulty', CoreData.difficulty_options[memory.difficulty_option].text, CoreData.capacity_options[memory.capacity_option].text3} + end + if flow.members.visible then + local wrappedcrew = {} + for _, index in pairs(memory.crewplayerindices) do + local player2 = game.players[index] + local tag_text = Roles.tag_text(player2) - --== UPDATE CONTENT ==-- + wrappedcrew[#wrappedcrew + 1] = {'pirates.crewmember_displayform', index, player2.color.r, player2.color.g, player2.color.b, player2.name, tag_text} + end + GuiCommon.update_listbox(flow.members.body.members_listbox, wrappedcrew) - if Common.is_id_valid(memory.id) then - window.caption = memory.name + flow.members.header.caption = {'pirates.gui_crew_window_crew_count', (#memory.crewplayerindices or 0)} + end - flow.crew_age.caption = {'pirates.gui_crew_window_crew_age', Utils.time_mediumform((memory.age or 0)/60)} - flow.crew_capacity_and_difficulty.caption = {'pirates.gui_crew_window_crew_capacity_and_difficulty', CoreData.difficulty_options[memory.difficulty_option].text, CoreData.capacity_options[memory.capacity_option].text3} - end + if flow.spectators.visible then + local wrappedspectators = {} + for _, index in pairs(memory.spectatorplayerindices) do + local player2 = game.players[index] + wrappedspectators[#wrappedspectators + 1] = {'pirates.crewmember_displayform', index, player2.color.r, player2.color.g, player2.color.b, player2.name, ''} + end + GuiCommon.update_listbox(flow.spectators.body.spectators_listbox, wrappedspectators) + end - if flow.members.visible then - local wrappedcrew = {} - for _, index in pairs(memory.crewplayerindices) do - local player2 = game.players[index] - local tag_text = Roles.tag_text(player2) - - wrappedcrew[#wrappedcrew + 1] = {'pirates.crewmember_displayform', index, player2.color.r, player2.color.g, player2.color.b, player2.name, tag_text} - end - GuiCommon.update_listbox(flow.members.body.members_listbox, wrappedcrew) - - flow.members.header.caption = {'pirates.gui_crew_window_crew_count', (#memory.crewplayerindices or 0)} - end - - if flow.spectators.visible then - local wrappedspectators = {} - for _, index in pairs(memory.spectatorplayerindices) do - local player2 = game.players[index] - - wrappedspectators[#wrappedspectators + 1] = {'pirates.crewmember_displayform', index, player2.color.r, player2.color.g, player2.color.b, player2.name, ''} - end - GuiCommon.update_listbox(flow.spectators.body.spectators_listbox, wrappedspectators) - end - - -- if flow.captain.body.capn_undock_normal.visible then - -- flow.captain.body.capn_undock_normal.enabled = ((memory.boat.state == Boats.enum_state.LANDED) and Common.query_can_pay_cost_to_leave()) or (memory.boat.state == Boats.enum_state.DOCKED) - -- end + -- if flow.captain.body.capn_undock_normal.visible then + -- flow.captain.body.capn_undock_normal.enabled = ((memory.boat.state == Boats.enum_state.LANDED) and Common.query_can_pay_cost_to_leave()) or (memory.boat.state == Boats.enum_state.DOCKED) + -- end end - function Public.click(event) - -- This is only needed since we call click on every single GUI element and if element gets destroyed, it's no good (these checks wouldn't be needed (I think) if GUI was purely event driven) - if not event.element then return end - if not event.element.valid then return end + -- This is only needed since we call click on every single GUI element and if element gets destroyed, it's no good (these checks wouldn't be needed (I think) if GUI was purely event driven) + if not event.element then + return + end + if not event.element.valid then + return + end - local player = game.players[event.element.player_index] + local player = game.players[event.element.player_index] - local eventname = event.element.name + local eventname = event.element.name - if not player.gui.screen[window_name .. '_piratewindow'] then return end - local window = player.gui.screen[window_name .. '_piratewindow'] - local flow = window.scroll_pane + if not player.gui.screen[window_name .. '_piratewindow'] then + return + end + local window = player.gui.screen[window_name .. '_piratewindow'] + local flow = window.scroll_pane - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() + if eventname == 'crewmember_join_spectators' then + Crew.join_spectators(player, memory.id) + return + end - if eventname == 'crewmember_join_spectators' then - Crew.join_spectators(player, memory.id) - return - end + if eventname == 'leave_spectators' then + Crew.leave_spectators(player) + return + end - if eventname == 'leave_spectators' then - Crew.leave_spectators(player) - return - end + if eventname == 'spectator_join_crew' then + Crew.join_crew(player, memory.id) + return + end - if eventname == 'spectator_join_crew' then - Crew.join_crew(player, memory.id) - return - end + if eventname == 'leave_crew' then + Crew.leave_crew(player, true) + return + end - if eventname == 'leave_crew' then - Crew.leave_crew(player, true) - return - end + -- if eventname == 'promote_officer' then + -- Roles.promote_to_officer(player) + -- return + -- end + -- if eventname == 'demote_officer' then + -- Roles.demote_to_officer(player) + -- return + -- end - -- if eventname == 'promote_officer' then - -- Roles.promote_to_officer(player) - -- return - -- end + if string.sub(eventname, 1, 18) and string.sub(eventname, 1, 18) == 'difficulty_option_' then + Crew.difficulty_vote(player.index, tonumber(string.sub(eventname, 19, -1))) + return + end - -- if eventname == 'demote_officer' then - -- Roles.demote_to_officer(player) - -- return - -- end + if eventname == 'capn_summon_crew' then + --double check: + if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then + Crew.summon_crew() + end + return + end - if string.sub(eventname, 1, 18) and string.sub(eventname, 1, 18) == 'difficulty_option_' then - Crew.difficulty_vote(player.index, tonumber(string.sub(eventname, 19, -1))) - return - end + if eventname == 'capn_requisition' then + --double check: + if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then + Roles.captain_tax(memory.playerindex_captain) + end + return + end + if eventname == 'capn_renounce' then + Roles.renounce_captainhood(player) + return + end - if eventname == 'capn_summon_crew' then - --double check: - if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then - Crew.summon_crew() - end - return - end + if eventname == 'officer_resign' then + Roles.resign_as_officer(player) + return + end - if eventname == 'capn_requisition' then - --double check: - if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then - Roles.captain_tax(memory.playerindex_captain) - end - return - end + if eventname == 'capn_disband_crew' then + --double check: + if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then + if not memory.disband_are_you_sure_ticks then + memory.disband_are_you_sure_ticks = {} + end + memory.disband_are_you_sure_ticks[player.index] = game.tick + end + return + end - if eventname == 'capn_renounce' then - Roles.renounce_captainhood(player) - return - end + if eventname == 'capn_disband_are_you_sure' then + --double check: + if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then + local force = memory.force + if force and force.valid then + local message = {'pirates.crew_disbanded', player.name, memory.name, Utils.time_longform((memory.real_age or 0) / 60)} + Common.notify_game(message) + Server.to_discord_embed_raw({'', CoreData.comfy_emojis.trashbin .. '[' .. memory.name .. '] ', message}, true) + end + Crew.disband_crew(true) + end + return + end - if eventname == 'officer_resign' then - Roles.resign_as_officer(player) - return - end + if eventname == 'capn_pass' then + local other_id = get_selected_player_index(flow) + Roles.pass_captainhood(player, game.players[other_id]) + return + end - if eventname == 'capn_disband_crew' then - --double check: - if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then - if not memory.disband_are_you_sure_ticks then memory.disband_are_you_sure_ticks = {} end - memory.disband_are_you_sure_ticks[player.index] = game.tick - end - return - end + if eventname == 'make_officer' then + local other_id = get_selected_player_index(flow) + Roles.make_officer(player, game.players[other_id]) + return + end - if eventname == 'capn_disband_are_you_sure' then - --double check: - if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then - local force = memory.force - if force and force.valid then - local message = {'pirates.crew_disbanded', player.name, memory.name, Utils.time_longform((memory.real_age or 0)/60)} - Common.notify_game(message) - Server.to_discord_embed_raw({'',CoreData.comfy_emojis.trashbin .. '[' .. memory.name .. '] ',message}, true) - end - Crew.disband_crew(true) - end - return - end + if eventname == 'unmake_officer' then + local other_id = get_selected_player_index(flow) + Roles.unmake_officer(player, game.players[other_id]) + return + end - if eventname == 'capn_pass' then - local other_id = get_selected_player_index(flow) - Roles.pass_captainhood(player, game.players[other_id]) - return - end - - if eventname == 'make_officer' then - local other_id = get_selected_player_index(flow) - Roles.make_officer(player, game.players[other_id]) - return - end - - if eventname == 'unmake_officer' then - local other_id = get_selected_player_index(flow) - Roles.unmake_officer(player, game.players[other_id]) - return - end - - if eventname == 'capn_plank' then - local other_id = get_selected_player_index(flow) - - Crew.plank(player, game.players[other_id]) - return - end + if eventname == 'capn_plank' then + local other_id = get_selected_player_index(flow) + Crew.plank(player, game.players[other_id]) + return + end end -return Public \ No newline at end of file +return Public diff --git a/maps/pirates/memory.lua b/maps/pirates/memory.lua index ce2000cf..9c5af97e 100644 --- a/maps/pirates/memory.lua +++ b/maps/pirates/memory.lua @@ -1,6 +1,5 @@ -- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/danielmartin0/ComfyFactorio-Pirates. - local Global = require 'utils.global' -- local CoreData = require 'maps.pirates.coredata' local pirates_global_memory = {} @@ -8,10 +7,10 @@ local Public = {} -- register only this Global.register( - pirates_global_memory, - function(tbl) - pirates_global_memory = tbl - end + pirates_global_memory, + function(tbl) + pirates_global_memory = tbl + end ) function Public.global_reset_memory() @@ -19,121 +18,119 @@ function Public.global_reset_memory() pirates_global_memory[k] = nil end - pirates_global_memory.config = {} - pirates_global_memory.afk_player_indices = {} - pirates_global_memory.playerindex_to_time_played_continuously = {} - pirates_global_memory.playerindex_to_captainhood_priority = {} - pirates_global_memory.player_gui_memories = {} - pirates_global_memory.crew_memories = {} - pirates_global_memory.crew_active_ids = {} - pirates_global_memory.working_id = nil --should only ever be nil, 1, 2 or 3 + pirates_global_memory.config = {} + pirates_global_memory.disband_crews = true + pirates_global_memory.afk_player_indices = {} + pirates_global_memory.playerindex_to_time_played_continuously = {} + pirates_global_memory.playerindex_to_captainhood_priority = {} + pirates_global_memory.player_gui_memories = {} + pirates_global_memory.crew_memories = {} + pirates_global_memory.crew_active_ids = {} + pirates_global_memory.working_id = nil --should only ever be nil, 1, 2 or 3 - pirates_global_memory.lobby_boats = {} + pirates_global_memory.lobby_boats = {} - pirates_global_memory.active_crews_cap = nil - pirates_global_memory.crew_capacity_min = nil + pirates_global_memory.active_crews_cap = nil + pirates_global_memory.crew_capacity_min = nil - pirates_global_memory.crewproposals = {} + pirates_global_memory.crewproposals = {} - pirates_global_memory.global_delayed_tasks = {} - pirates_global_memory.global_buffered_tasks = {} + pirates_global_memory.global_delayed_tasks = {} + pirates_global_memory.global_buffered_tasks = {} - pirates_global_memory.last_players_health = {} --used to make damage reduction work somewhat properly + pirates_global_memory.last_players_health = {} --used to make damage reduction work somewhat properly end - - - function Public.initialise_crew_memory(id) --mostly serves as a dev reference of memory entries - -- but not _everything_ is stored here, it's just a guide to the most important things + -- but not _everything_ is stored here, it's just a guide to the most important things - pirates_global_memory.crew_memories[id] = {} - local memory = pirates_global_memory.crew_memories[id] + pirates_global_memory.crew_memories[id] = {} + local memory = pirates_global_memory.crew_memories[id] - memory.secs_id = nil + memory.secs_id = nil - memory.id = nil - memory.age = nil - memory.real_age = nil - memory.completion_time = nil + memory.id = nil + memory.age = nil + memory.real_age = nil + memory.completion_time = nil - memory.force_name = nil - memory.enemy_force_name = nil + memory.force_name = nil + memory.enemy_force_name = nil - memory.original_proposal = nil - memory.name = nil - memory.difficulty_option = nil - memory.capacity_option = nil - -- memory.mode_option = nil - memory.difficulty = nil - memory.capacity = nil - -- memory.mode = nil + memory.original_proposal = nil + memory.name = nil + memory.difficulty_option = nil + memory.capacity_option = nil + -- memory.mode_option = nil + memory.difficulty = nil + memory.capacity = nil + -- memory.mode = nil - memory.destinations = nil - memory.currentdestination_index = nil + memory.destinations = nil + memory.currentdestination_index = nil - memory.hold_surface_count = nil - memory.merchant_ships_unlocked = nil + memory.hold_surface_count = nil + memory.merchant_ships_unlocked = nil - memory.boat = nil + memory.boat = nil - memory.available_classes_pool = nil - -- Duplicating unlocked classes data for consistency reasons (this way, entries will remain in the same order when unlocked class data changes) - -- @TODO Might have to consider sacrificing consistency(or find a way to retain consistency) to reduce the chance of contradicting data which results in weird bugs (this happened once already) - memory.unlocked_classes = nil + memory.available_classes_pool = nil + -- Duplicating unlocked classes data for consistency reasons (this way, entries will remain in the same order when unlocked class data changes) + -- @TODO Might have to consider sacrificing consistency(or find a way to retain consistency) to reduce the chance of contradicting data which results in weird bugs (this happened once already) + memory.unlocked_classes = nil - memory.seconds_until_alert_sound_can_be_played_again = 0 - memory.crewplayerindices = nil - memory.spectatorplayerindices = nil - memory.tempbanned_from_joining_data = nil - memory.playerindex_captain = nil - memory.captain_accrued_time_data = nil - memory.max_players_recorded = nil - memory.temporarily_logged_off_characters = nil + memory.seconds_until_alert_sound_can_be_played_again = 0 + memory.crewplayerindices = nil + memory.spectatorplayerindices = nil + memory.tempbanned_from_joining_data = nil + memory.playerindex_captain = nil + memory.captain_accrued_time_data = nil + memory.max_players_recorded = nil + memory.temporarily_logged_off_characters = nil - memory.speed_boost_characters = nil + memory.speed_boost_characters = nil - memory.enemyboats = nil - memory.overworld_krakens = nil - memory.active_sea_enemies = nil - memory.kraken_stream_registrations = nil + memory.enemyboats = nil + memory.overworld_krakens = nil + memory.active_sea_enemies = nil + memory.kraken_stream_registrations = nil - memory.mainshop_availability_bools = nil + memory.mainshop_availability_bools = nil - memory.delayed_tasks = nil - memory.buffered_tasks = nil - memory.game_lost = false - memory.game_won = false - memory.crew_disband_tick = nil - memory.destinationsvisited_indices = nil - memory.overworldx = nil - memory.overworldy = nil - memory.mapbeingloadeddestination_index = nil - memory.loadingticks = nil - memory.stored_fuel = nil - memory.spawnpoint = nil + memory.delayed_tasks = nil + memory.buffered_tasks = nil + memory.game_lost = false + memory.game_won = false + memory.crew_disband_tick = nil + memory.destinationsvisited_indices = nil + memory.overworldx = nil + memory.overworldy = nil + memory.mapbeingloadeddestination_index = nil + memory.loadingticks = nil + memory.stored_fuel = nil + memory.spawnpoint = nil - memory.evolution_factor = nil - memory.scripted_biters = nil - memory.scripted_unit_groups = nil - memory.floating_pollution = nil + memory.evolution_factor = nil + memory.scripted_biters = nil + memory.scripted_unit_groups = nil + memory.floating_pollution = nil - memory.playtesting_stats = nil + memory.playtesting_stats = nil - memory.cliff_explosives_acquired_once = false -- used to give tip by parrot what to do with them(only triggers from buying it in captain's cabin) - memory.hold_surface_destroyable_wooden_chests = nil + memory.cliff_explosives_acquired_once = false -- used to give tip by parrot what to do with them(only triggers from buying it in captain's cabin) + memory.hold_surface_destroyable_wooden_chests = nil end function Public.fallthrough_crew_memory() --could make this a metatable, but metatables and factorio global seem not to play nicely - return { - id = 0, - difficulty = 1, - force_name = 'player', - boat = {}, - destinations = {}, - spectatorplayerindices = {}, - crewplayerindices = {}, - --[[boat = { + return { + id = 0, + difficulty = 1, + force_name = 'player', + boat = {}, + destinations = {}, + spectatorplayerindices = {}, + crewplayerindices = {} + --[[boat = { type = nil, state = nil, speed = nil, @@ -151,24 +148,23 @@ function Public.fallthrough_crew_memory() --could make this a metatable, but met dockedposition = nil, surface_name = nil, }]] - } + } end - function Public.get_crew_memory() - if pirates_global_memory.working_id and pirates_global_memory.working_id > 0 then - return pirates_global_memory.crew_memories[pirates_global_memory.working_id] or Public.fallthrough_crew_memory() - else - return Public.fallthrough_crew_memory() - end + if pirates_global_memory.working_id and pirates_global_memory.working_id > 0 then + return pirates_global_memory.crew_memories[pirates_global_memory.working_id] or Public.fallthrough_crew_memory() + else + return Public.fallthrough_crew_memory() + end end function Public.get_global_memory() - return pirates_global_memory + return pirates_global_memory end function Public.set_working_id(id) - pirates_global_memory.working_id = id + pirates_global_memory.working_id = id end return Public diff --git a/utils/gui/config.lua b/utils/gui/config.lua index 6a88b4aa..130e3a7f 100644 --- a/utils/gui/config.lua +++ b/utils/gui/config.lua @@ -401,6 +401,32 @@ local fortress_functions = { end } +local pirates_functions = { + ['toggle_disband'] = function(event) + local players = game.players + local Memory = global.tokens.maps_pirates_memory + if event.element.switch_state == 'left' then + Memory.disband_crews = true + for _, player in pairs(players) do + local gui = player.gui.screen['crew_piratewindow'] + if gui and gui.valid then + gui.destroy() + end + end + get_actor(event, '[Pirates]', 'has enabled the ability to disband crews.') + else + Memory.disband_crews = false + for _, player in pairs(players) do + local gui = player.gui.screen['crew_piratewindow'] + if gui and gui.valid then + gui.destroy() + end + end + get_actor(event, '[Pirates]', 'has disabled the ability to disband crews.') + end + end +} + local function add_switch(element, switch_state, name, description_main, description) local t = element.add({type = 'table', column_count = 5}) local on_label = t.add({type = 'label', caption = 'ON'}) @@ -718,6 +744,24 @@ local function build_config_gui(data) add_switch(scroll_pane, switch_state, 'christmas_mode', 'Wintery Mode', 'On = Enables wintery mode.\nOff = Disables wintery mode.') scroll_pane.add({type = 'line'}) end + + if global.tokens.maps_pirates_memory then + label = scroll_pane.add({type = 'label', caption = 'Pirates Settings'}) + label.style.font = 'default-bold' + label.style.padding = 0 + label.style.left_padding = 10 + label.style.top_padding = 10 + label.style.horizontal_align = 'left' + label.style.vertical_align = 'bottom' + label.style.font_color = Color.green + + local Memory = global.tokens.maps_pirates_memory + switch_state = 'right' + if Memory.disband_crews then + switch_state = 'left' + end + add_switch(scroll_pane, switch_state, 'toggle_disband', 'Disband Crews', 'On = Enables crew disband.\nOff = Disables crew disband.') + end end for _, e in pairs(scroll_pane.children) do if e.type == 'line' then @@ -763,6 +807,13 @@ local function on_gui_switch_state_changed(event) end fortress_functions[event.element.name](event) return + elseif pirates_functions[event.element.name] then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Pirates Elem') + if is_spamming then + return + end + pirates_functions[event.element.name](event) + return elseif is_loaded('utils.gui.poll') then local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Poll Elem') if is_spamming then