diff --git a/comfy_panel/admin.lua b/comfy_panel/admin.lua index 461e55e5..bf5da96b 100644 --- a/comfy_panel/admin.lua +++ b/comfy_panel/admin.lua @@ -5,8 +5,10 @@ local Jailed = require 'utils.datastore.jail_data' local Tabs = require 'comfy_panel.main' local AntiGrief = require 'antigrief' local SpamProtection = require 'utils.spam_protection' +local Token = require 'utils.token' local lower = string.lower +local module_name = 'Admin' local function admin_only_message(str) for _, player in pairs(game.connected_players) do @@ -324,7 +326,7 @@ local function text_changed(event) if not frame then return end - if frame.name ~= 'Admin' then + if frame.name ~= module_name then return end @@ -342,7 +344,9 @@ local function text_changed(event) draw_events(data) end -local create_admin_panel = (function(player, frame) +local function create_admin_panel(data) + local player = data.player + local frame = data.frame local antigrief = AntiGrief.get() frame.clear() @@ -513,13 +517,15 @@ local create_admin_panel = (function(player, frame) drop_down_2.style.right_padding = 12 drop_down_2.style.left_padding = 12 - local data = { + local datas = { frame = frame, antigrief = antigrief } - draw_events(data) -end) + draw_events(datas) +end + +local create_admin_panel_token = Token.register(create_admin_panel) local admin_functions = { ['jail'] = jail, @@ -608,25 +614,32 @@ local function get_position_from_string(str) end local function on_gui_click(event) - local player = game.players[event.player_index] + local element = event.element + if not element or not element.valid then + return + end + local player = game.get_player(event.player_index) + + local name = event.element.name + + if name == 'tab_Admin' then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin tab_Admin') + if is_spamming then + return + end + end local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end - if not event.element.valid then - return - end - - local name = event.element.name - if name == 'mini_camera' or name == 'mini_cam_element' then player.gui.center['mini_camera'].destroy() return end - if frame.name ~= 'Admin' then + if frame.name ~= module_name then return end @@ -659,27 +672,27 @@ local function on_gui_click(event) if not frame then return end - if not event.element.caption then + if not element.caption then return end - local position = get_position_from_string(event.element.caption) + local position = get_position_from_string(element.caption) if not position then return end - local surface = get_surface_from_string(event.element.caption) + local surface = get_surface_from_string(element.caption) if not surface then return end if player.gui.center['mini_camera'] then - if player.gui.center['mini_camera'].caption == event.element.caption then + if player.gui.center['mini_camera'].caption == element.caption then player.gui.center['mini_camera'].destroy() return end end - create_mini_camera_gui(player, event.element.caption, position, surface) + create_mini_camera_gui(player, element.caption, position, surface) end local function on_gui_selection_state_changed(event) @@ -696,7 +709,7 @@ local function on_gui_selection_state_changed(event) if not frame then return end - if frame.name ~= 'Admin' then + if frame.name ~= module_name then return end @@ -704,8 +717,8 @@ local function on_gui_selection_state_changed(event) if is_spamming then return end - - create_admin_panel(player, frame) + local data = {player = player, frame = frame} + create_admin_panel(data) end if name == 'admin_player_select' then if not global.admin_panel_selected_player_index then @@ -717,7 +730,7 @@ local function on_gui_selection_state_changed(event) if not frame then return end - if frame.name ~= 'Admin' then + if frame.name ~= module_name then return end @@ -726,11 +739,12 @@ local function on_gui_selection_state_changed(event) return end - create_admin_panel(player, frame) + local data = {player = player, frame = frame} + create_admin_panel(data) end end -comfy_panel_tabs['Admin'] = {gui = create_admin_panel, admin = true} +Tabs.add_tab_to_gui({name = module_name, id = create_admin_panel_token, admin = true}) Event.add(defines.events.on_gui_text_changed, text_changed) Event.add(defines.events.on_gui_click, on_gui_click) diff --git a/comfy_panel/config.lua b/comfy_panel/config.lua index 224727f7..9787ddfb 100644 --- a/comfy_panel/config.lua +++ b/comfy_panel/config.lua @@ -4,8 +4,12 @@ local Antigrief = require 'antigrief' local Color = require 'utils.color_presets' local SessionData = require 'utils.datastore.session_data' local Utils = require 'utils.core' +local Tabs = require 'comfy_panel.main' local SpamProtection = require 'utils.spam_protection' local BottomFrame = require 'comfy_panel.bottom_frame' +local Token = require 'utils.token' + +local module_name = 'Config' local spaghett_entity_blacklist = { ['logistic-chest-requester'] = true, @@ -299,7 +303,10 @@ local function add_switch(element, switch_state, name, description_main, descrip return switch end -local build_config_gui = (function(player, frame) +local function build_config_gui(data) + local player = data.player + local frame = data.frame + local AG = Antigrief.get() local switch_state local label @@ -577,7 +584,9 @@ local build_config_gui = (function(player, frame) e.style.margin = 0 end end -end) +end + +local build_config_gui_token = Token.register(build_config_gui) local function on_gui_switch_state_changed(event) local player = game.players[event.player_index] @@ -645,7 +654,7 @@ local function on_init() global.comfy_panel_disable_antigrief = false end -comfy_panel_tabs['Config'] = {gui = build_config_gui, admin = false} +Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = false}) local Event = require 'utils.event' Event.on_init(on_init) diff --git a/comfy_panel/group.lua b/comfy_panel/group.lua index dd1bf9c1..38b688ad 100644 --- a/comfy_panel/group.lua +++ b/comfy_panel/group.lua @@ -3,6 +3,9 @@ local Tabs = require 'comfy_panel.main' local Global = require 'utils.global' local SpamProtection = require 'utils.spam_protection' +local Token = require 'utils.token' + +local module_name = 'Groups' local this = { player_group = {}, @@ -20,7 +23,9 @@ Global.register( local Public = {} -local build_group_gui = (function(player, frame) +local function build_group_gui(data) + local player = data.player + local frame = data.frame local group_name_width = 150 local description_width = 240 local members_width = 90 @@ -142,17 +147,20 @@ local build_group_gui = (function(player, frame) local b = t.add({type = 'button', name = 'create_new_group', caption = 'Create'}) b.style.minimal_width = 150 b.style.font = 'default-bold' -end) +end + +local build_group_gui_token = Token.register(build_group_gui) local function refresh_gui() for _, p in pairs(game.connected_players) do local frame = Tabs.comfy_panel_get_active_frame(p) if frame then - if frame.name == 'Groups' then + if frame.name == module_name then local new_group_name = frame.frame2.group_table.new_group_name.text local new_group_description = frame.frame2.group_table.new_group_description.text - build_group_gui(p, frame) + local data = {player = p, frame = frame} + build_group_gui(data) frame = Tabs.comfy_panel_get_active_frame(p) frame.frame2.group_table.new_group_name.text = new_group_name @@ -179,24 +187,26 @@ local function alphanumeric(str) end local function on_gui_click(event) - if not event then - return - end - - if not event.element then - return - end - if not event.element.valid then + local element = event.element + if not element or not element.valid then return end + local player = game.get_player(event.player_index) local name = event.element.name - local player = game.players[event.player_index] + + if name == 'tab_Groups' then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Groups tab_Groups') + if is_spamming then + return + end + end + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end - if frame.name ~= 'Groups' then + if frame.name ~= module_name then return end @@ -254,7 +264,7 @@ local function on_gui_click(event) end end - local p = event.element.parent + local p = element.parent if p then p = p.parent end @@ -266,9 +276,9 @@ local function on_gui_click(event) return end - if event.element.type == 'button' and event.element.caption == 'Join' then - this.player_group[player.name] = event.element.parent.name - local str = '[' .. event.element.parent.name + if element.type == 'button' and element.caption == 'Join' then + this.player_group[player.name] = element.parent.name + local str = '[' .. element.parent.name str = str .. ']' player.tag = str if game.tick - this.join_spam_protection[player.name] > 600 then @@ -278,29 +288,29 @@ local function on_gui_click(event) b = player.color.b * 0.7 + 0.3, a = 1 } - game.print(player.name .. ' has joined group "' .. event.element.parent.name .. '"', color) + game.print(player.name .. ' has joined group "' .. element.parent.name .. '"', color) this.join_spam_protection[player.name] = game.tick end refresh_gui() return end - if event.element.type == 'button' and event.element.caption == 'Delete' then + if element.type == 'button' and element.caption == 'Delete' then for _, players in pairs(game.players) do if this.player_group[players.name] then - if this.player_group[players.name] == event.element.parent.name then + if this.player_group[players.name] == element.parent.name then this.player_group[players.name] = '[Group]' players.tag = '' end end end - game.print(player.name .. ' deleted group "' .. event.element.parent.name .. '"') - this.tag_groups[event.element.parent.name] = nil + game.print(player.name .. ' deleted group "' .. element.parent.name .. '"') + this.tag_groups[element.parent.name] = nil refresh_gui() return end - if event.element.type == 'button' and event.element.caption == 'Leave' then + if element.type == 'button' and element.caption == 'Leave' then this.player_group[player.name] = '[Group]' player.tag = '' refresh_gui() @@ -328,7 +338,7 @@ function Public.reset_groups() this.tag_groups = {} end -comfy_panel_tabs['Groups'] = {gui = build_group_gui, admin = false} +Tabs.add_tab_to_gui({name = module_name, id = build_group_gui_token, admin = false}) local event = require 'utils.event' event.add(defines.events.on_gui_click, on_gui_click) diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index 493b832b..76f46558 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -1,9 +1,9 @@ --[[ Comfy Panel -To add a tab, insert into the "comfy_panel_tabs" table. +To add a tab, insert into the "main_gui_tabs" table. -Example: comfy_panel_tabs["mapscores"] = {gui = draw_map_scores, admin = false} +Example: main_gui_tabs["mapscores"] = {gui = draw_map_scores, admin = false} if admin = true, then tab is visible only for admins (usable for map-specific settings) draw_map_scores would be a function with the player and the frame as arguments @@ -12,19 +12,47 @@ draw_map_scores would be a function with the player and the frame as arguments local Event = require 'utils.event' local Server = require 'utils.server' local SpamProtection = require 'utils.spam_protection' +local Token = require 'utils.token' -comfy_panel_tabs = {} - +local main_gui_tabs = {} local Public = {} local screen_elements = {} +--- This adds the given gui to the main gui. +---@param tbl +function Public.add_tab_to_gui(tbl) + if not tbl then + return + end + if not tbl.name then + return + end + if not tbl.id then + return + end + local admin = tbl.admin or false + local only_server_sided = tbl.only_server_sided or false + + if not main_gui_tabs[tbl.name] then + main_gui_tabs[tbl.name] = {id = tbl.id, admin = admin, only_server_sided = only_server_sided} + else + error('Given name: ' .. tbl.name .. ' already exists in table.') + end +end + function Public.screen_to_bypass(elem) screen_elements[elem] = true return screen_elements end -function Public.get_tabs() - return comfy_panel_tabs +--- Fetches the main gui tabs. You are forbidden to write as this is local. +---@param key +function Public.get(key) + if key then + return main_gui_tabs[key] + else + return main_gui_tabs + end end function Public.comfy_panel_clear_left_gui(player) @@ -70,7 +98,23 @@ function Public.comfy_panel_refresh_active_tab(player) if not frame then return end - comfy_panel_tabs[frame.name].gui(player, frame) + + local tab = main_gui_tabs[frame.name] + if not tab then + return + end + local id = tab.id + if not id then + return + end + local func = Token.get(id) + + local data = { + player = player, + frame = frame + } + + return func(data) end local function top_button(player) @@ -85,7 +129,7 @@ local function top_button(player) end local function main_frame(player) - local tabs = comfy_panel_tabs + local tabs = main_gui_tabs Public.comfy_panel_clear_left_gui(player) local frame = player.gui.left.add({type = 'frame', name = 'comfy_panel'}) @@ -97,7 +141,7 @@ local function main_frame(player) if func.only_server_sided then local secs = Server.get_current_time() if secs then - local tab = tabbed_pane.add({type = 'tab', caption = name}) + local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name}) local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) name_frame.style.minimal_height = 480 name_frame.style.maximal_height = 480 @@ -107,7 +151,7 @@ local function main_frame(player) end elseif func.admin == true then if player.admin then - local tab = tabbed_pane.add({type = 'tab', caption = name}) + local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name}) local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) name_frame.style.minimal_height = 480 name_frame.style.maximal_height = 480 @@ -116,7 +160,7 @@ local function main_frame(player) tabbed_pane.add_tab(tab, name_frame) end else - local tab = tabbed_pane.add({type = 'tab', caption = name}) + local tab = tabbed_pane.add({type = 'tab', caption = name, name = 'tab_' .. name}) local name_frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) name_frame.style.minimal_height = 480 name_frame.style.maximal_height = 480 @@ -156,20 +200,16 @@ local function on_player_joined_game(event) end local function on_gui_click(event) - if not event then + local element = event.element + if not element or not element.valid then return end local player = game.players[event.player_index] - if not event.element then - return - end - if not event.element.valid then - return - end + local name = element.name - if event.element.name == 'comfy_panel_top_button' then + if name == 'comfy_panel_top_button' then local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main GUI Click') if is_spamming then return @@ -186,7 +226,7 @@ local function on_gui_click(event) end end - if event.element.caption == 'X' and event.element.name == 'comfy_panel_close' then + if element.caption == 'X' and name == 'comfy_panel_close' then local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main Gui Close Button') if is_spamming then return @@ -196,16 +236,13 @@ local function on_gui_click(event) return end - if not event.element.caption then + if not element.caption then return end - if event.element.type ~= 'tab' then - return - end - local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main Gui No Func') - if is_spamming then + if element.type ~= 'tab' then return end + Public.comfy_panel_refresh_active_tab(player) end diff --git a/comfy_panel/map_score.lua b/comfy_panel/map_score.lua index b3d0318e..e846d630 100644 --- a/comfy_panel/map_score.lua +++ b/comfy_panel/map_score.lua @@ -1,3 +1,8 @@ +local Tabs = require 'comfy_panel.main' +local Token = require 'utils.token' + +local module_name = 'Map Scores' + local Public = {} local function get_sorted_score() @@ -18,7 +23,8 @@ local function get_sorted_score() return list end -local score_list = (function(_, frame) +local function score_list(data) + local frame = data.frame frame.clear() frame.style.padding = 4 frame.style.margin = 0 @@ -59,7 +65,9 @@ local score_list = (function(_, frame) points_label.style.font = 'heading-2' points_label.style.padding = 1 end -end) +end + +local score_list_token = Token.register(score_list) function Public.set_score_description(str) global.custom_highscore.description = str @@ -92,7 +100,7 @@ local function on_init() } end -comfy_panel_tabs['Map Scores'] = {gui = score_list, admin = false} +Tabs.add_tab_to_gui({name = module_name, id = score_list_token, admin = false}) local event = require 'utils.event' event.on_init(on_init) diff --git a/comfy_panel/player_list.lua b/comfy_panel/player_list.lua index 8b6d046c..bbbc9b57 100644 --- a/comfy_panel/player_list.lua +++ b/comfy_panel/player_list.lua @@ -19,9 +19,12 @@ local Jailed = require 'utils.datastore.jail_data' local Tabs = require 'comfy_panel.main' local Global = require 'utils.global' local SpamProtection = require 'utils.spam_protection' +local Token = require 'utils.token' local Public = {} +local module_name = 'Players' + local this = { player_list = { last_poke_tick = {}, @@ -387,7 +390,10 @@ local function get_sorted_list(sort_by) return player_list end -local function player_list_show(player, frame, sort_by) +local function player_list_show(data) + local player = data.player + local frame = data.frame + local sort_by = data.sort_by -- Frame management frame.clear() frame.style.padding = 8 @@ -448,6 +454,10 @@ local function player_list_show(player, frame, sort_by) sort_by = this.player_list.sorting_method[player.index] end + if not sort_by then + sort_by = 'total_time_played_desc' + end + header_modifier[sort_by](headers) for k, v in ipairs(headers) do @@ -579,58 +589,67 @@ local function player_list_show(player, frame, sort_by) end end +local player_list_show_token = Token.register(player_list_show) + local function on_gui_click(event) - if not event then + local element = event.element + if not element or not element.valid then return end - if not event.element then - return - end - if not event.element.valid then - return - end - if not event.element.name then - return + local name = element.name + local player = game.get_player(event.player_index) + + if name == 'tab_Players' then + local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList tab_Players') + if is_spamming then + return + end end - local player = game.players[event.player_index] local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end - if frame.name ~= 'Players' then + if frame.name ~= module_name then return end - local name = event.element.name local actions = { ['player_list_panel_header_2'] = function() - if string.find(event.element.caption, symbol_desc) then - player_list_show(player, frame, 'name_asc') + if string.find(element.caption, symbol_desc) then + local data = {player = player, frame = frame, sort_by = 'name_asc'} + player_list_show(data) else - player_list_show(player, frame, 'name_desc') + local data = {player = player, frame = frame, sort_by = 'name_desc'} + player_list_show(data) end end, ['player_list_panel_header_3'] = function() - if string.find(event.element.caption, symbol_desc) then - player_list_show(player, frame, 'total_time_played_asc') + if string.find(element.caption, symbol_desc) then + local data = {player = player, frame = frame, sort_by = 'total_time_played_asc'} + player_list_show(data) else - player_list_show(player, frame, 'total_time_played_desc') + local data = {player = player, frame = frame, sort_by = 'total_time_played_desc'} + player_list_show(data) end end, ['player_list_panel_header_4'] = function() - if string.find(event.element.caption, symbol_desc) then - player_list_show(player, frame, 'time_played_asc') + if string.find(element.caption, symbol_desc) then + local data = {player = player, frame = frame, sort_by = 'time_played_asc'} + player_list_show(data) else - player_list_show(player, frame, 'time_played_desc') + local data = {player = player, frame = frame, sort_by = 'time_played_desc'} + player_list_show(data) end end, ['player_list_panel_header_5'] = function() - if string.find(event.element.caption, symbol_desc) then - player_list_show(player, frame, 'pokes_asc') + if string.find(element.caption, symbol_desc) then + local data = {player = player, frame = frame, sort_by = 'pokes_asc'} + player_list_show(data) else - player_list_show(player, frame, 'pokes_desc') + local data = {player = player, frame = frame, sort_by = 'pokes_desc'} + player_list_show(data) end end } @@ -645,11 +664,11 @@ local function on_gui_click(event) return end - if not event.element.valid then + if not element.valid then return end --Locate other players - local index = tonumber(event.element.name) + local index = tonumber(element.name) if index and game.players[index] and index == game.players[index].index then local target = game.players[index] if not target or not target.valid then @@ -658,12 +677,12 @@ local function on_gui_click(event) Where.create_mini_camera_gui(player, target.name, target.position, target.surface.index) end --Poke other players - if string.sub(event.element.name, 1, 11) == 'poke_player' then - local poked_player = string.sub(event.element.name, 13, string.len(event.element.name)) + if string.sub(element.name, 1, 11) == 'poke_player' then + local poked_player = string.sub(element.name, 13, string.len(element.name)) if player.name == poked_player then return end - if this.player_list.last_poke_tick[event.element.player_index] + 300 < game.tick then + if this.player_list.last_poke_tick[element.player_index] + 300 < game.tick then local str = '>> ' str = str .. player.name str = str .. ' has poked ' @@ -673,7 +692,7 @@ local function on_gui_click(event) str = str .. pokemessages[z] str = str .. ' <<' game.print(str) - this.player_list.last_poke_tick[event.element.player_index] = game.tick + this.player_list.last_poke_tick[element.player_index] = game.tick local p = game.players[poked_player] this.player_list.pokes[p.index] = this.player_list.pokes[p.index] + 1 end @@ -684,10 +703,11 @@ local function refresh() for _, player in pairs(game.connected_players) do local frame = Tabs.comfy_panel_get_active_frame(player) if frame then - if frame.name ~= 'Players' then + if frame.name ~= module_name then return end - player_list_show(player, frame, this.player_list.sorting_method[player.index]) + local data = {player = player, frame = frame, sort_by = 'this.player_list.sorting_method[player.index]'} + player_list_show(data) end end end @@ -715,7 +735,7 @@ function Public.show_roles_in_list(value) return this.show_roles_in_list end -comfy_panel_tabs['Players'] = {gui = player_list_show, admin = false} +Tabs.add_tab_to_gui({name = module_name, id = player_list_show_token, admin = false}) Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_left_game, on_player_left_game) diff --git a/comfy_panel/score.lua b/comfy_panel/score.lua index f434139b..5f1d1b59 100644 --- a/comfy_panel/score.lua +++ b/comfy_panel/score.lua @@ -4,6 +4,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' local Tabs = require 'comfy_panel.main' local SpamProtection = require 'utils.spam_protection' +local Token = require 'utils.token' local Public = {} local this = { @@ -11,6 +12,8 @@ local this = { sort_by = {} } +local module_name = 'Scoreboard' + Global.register( this, function(t) @@ -151,7 +154,9 @@ local function add_global_stats(frame, player) floatingScore_label.style.font_color = {r = 0.8, g = 0.8, b = 0.8} end -local show_score = (function(player, frame) +local function show_score(data) + local player = data.player + local frame = data.frame frame.clear() Public.init_player_table(player) @@ -251,14 +256,16 @@ local show_score = (function(player, frame) label.style.horizontal_align = 'right' end -- foreach column end -- foreach entry -end) -- show_score +end + +local show_score_token = Token.register(show_score) local function refresh_score_full() for _, player in pairs(game.connected_players) do local frame = Tabs.comfy_panel_get_active_frame(player) if frame then - if frame.name == 'Scoreboard' then - show_score(player, frame) + if frame.name == module_name then + show_score({player = player, frame = frame}) end end end @@ -279,23 +286,25 @@ local function on_player_joined_game(event) end local function on_gui_click(event) - if not event then + local element = event.element + if not element or not element.valid then return end + local player = game.get_player(event.player_index) + local name = event.element.name + + if name == 'tab_Scoreboard' then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Scoreboard tab_Scoreboard') + if is_spamming then + return + end + end - if not event.element then - return - end - if not event.element.valid then - return - end - - local player = game.players[event.player_index] local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return end - if frame.name ~= 'Scoreboard' then + if frame.name ~= module_name then return end @@ -304,11 +313,9 @@ local function on_gui_click(event) return end - local name = event.element.name - -- Handles click on the checkbox, for floating score if name == 'show_floating_killscore_texts' then - global.show_floating_killscore[player.name] = event.element.state + global.show_floating_killscore[player.name] = element.state return end @@ -328,7 +335,7 @@ local function on_gui_click(event) sorting_pref.method = 'descending' sorting_pref.column = column end - show_score(player, frame) + show_score({player = player, frame = frame}) return end @@ -485,7 +492,7 @@ local function on_built_entity(event) score.built_entities = 1 + (score.built_entities or 0) end -comfy_panel_tabs['Scoreboard'] = {gui = show_score, admin = false} +Tabs.add_tab_to_gui({name = module_name, id = show_score_token, admin = false}) Event.add(defines.events.on_player_mined_entity, on_player_mined_entity) Event.add(defines.events.on_player_died, on_player_died) diff --git a/maps/biter_battles_v2/difficulty_vote.lua b/maps/biter_battles_v2/difficulty_vote.lua index 333eb953..9239da1b 100644 --- a/maps/biter_battles_v2/difficulty_vote.lua +++ b/maps/biter_battles_v2/difficulty_vote.lua @@ -1,6 +1,4 @@ ---luacheck:ignore -local bb_config = require 'maps.biter_battles_v2.config' -local event = require 'utils.event' +local Event = require 'utils.event' local Server = require 'utils.server' local difficulties = { @@ -63,14 +61,18 @@ local function poll_difficulty(player) for i = 1, 7, 1 do local b = frame.add({type = 'button', name = tostring(i), caption = difficulties[i].name .. ' (' .. difficulties[i].str .. ')'}) b.style.font_color = difficulties[i].color - b.style.font = 'heading-2' - b.style.minimal_width = 180 + b.style.minimal_width = 190 + b.style.horizontal_align = 'center' + b.style.bottom_padding = 2 end - local b = frame.add({type = 'label', caption = '- - - - - - - - - - - - - - - - - - - -'}) + frame.add({type = 'label', caption = '- - - - - - - - - - - - - - - - - - - -'}) + local b = frame.add({type = 'button', name = 'close', caption = 'Close (' .. math.floor((timeout - tick) / 3600) .. ' minutes left)'}) b.style.font_color = {r = 0.66, g = 0.0, b = 0.66} b.style.font = 'heading-3' + b.style.horizontal_align = 'center' b.style.minimal_width = 96 + b.style = 'dialog_button' end local function set_difficulty() @@ -186,6 +188,6 @@ local function on_gui_click(event) event.element.parent.destroy() end -event.add(defines.events.on_gui_click, on_gui_click) -event.add(defines.events.on_player_left_game, on_player_left_game) -event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.add(defines.events.on_gui_click, on_gui_click) +Event.add(defines.events.on_player_left_game, on_player_left_game) +Event.add(defines.events.on_player_joined_game, on_player_joined_game) diff --git a/maps/biter_battles_v2/sciencelogs_tab.lua b/maps/biter_battles_v2/sciencelogs_tab.lua index 2c65a429..cbee5b8e 100644 --- a/maps/biter_battles_v2/sciencelogs_tab.lua +++ b/maps/biter_battles_v2/sciencelogs_tab.lua @@ -1,4 +1,4 @@ ---luacheck:ignore +--luacheck: ignore -- science logs tab -- local Tabs = require 'comfy_panel.main' @@ -12,6 +12,9 @@ local forces_list = tables.forces_list local science_list = tables.science_list local evofilter_list = tables.evofilter_list local food_value_table_version = tables.food_value_table_version +local Token = require 'utils.token' + +local module_name = 'MutagenLog' local function initialize_dropdown_users_choice() global.dropdown_users_choice_force = {} @@ -218,7 +221,7 @@ local function add_science_logs(player, element) end end -function comfy_panel_get_active_frame(player) +local function comfy_panel_get_active_frame(player) if not player.gui.left.comfy_panel then return false end @@ -228,14 +231,17 @@ function comfy_panel_get_active_frame(player) return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content end -local build_config_gui = (function(player, frame) +local function build_config_gui(data) + local player = data.player local frame_sciencelogs = comfy_panel_get_active_frame(player) if not frame_sciencelogs then return end frame_sciencelogs.clear() add_science_logs(player, frame_sciencelogs) -end) +end + +local build_config_gui_token = Token.register(build_config_gui) local function on_gui_selection_state_changed(event) local player = game.players[event.player_index] @@ -248,18 +254,18 @@ local function on_gui_selection_state_changed(event) end if name == 'dropdown-force' then global.dropdown_users_choice_force[player.name] = event.element.selected_index - build_config_gui(player, frame_sciencelogs) + build_config_gui({player = player}) end if name == 'dropdown-science' then global.dropdown_users_choice_science[player.name] = event.element.selected_index - build_config_gui(player, frame_sciencelogs) + build_config_gui({player = player}) end if name == 'dropdown-evofilter' then global.dropdown_users_choice_evo_filter[player.name] = event.element.selected_index - build_config_gui(player, frame_sciencelogs) + build_config_gui({player = player}) end end event.add(defines.events.on_gui_selection_state_changed, on_gui_selection_state_changed) -comfy_panel_tabs['MutagenLog'] = {gui = build_config_gui, admin = false} +Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = false}) diff --git a/maps/chronosphere/config_tab.lua b/maps/chronosphere/config_tab.lua index 19f3dca5..ef6f84dc 100644 --- a/maps/chronosphere/config_tab.lua +++ b/maps/chronosphere/config_tab.lua @@ -2,6 +2,10 @@ local Chrono_table = require 'maps.chronosphere.table' local Chrono = require 'maps.chronosphere.chrono' +local Token = require 'utils.token' +local Tabs = require 'comfy_panel.tabs' + +local module_name = 'ChronoTrain' local functions = { ['comfy_panel_offline_accidents'] = function(event) @@ -145,7 +149,8 @@ local function add_switch(element, switch_state, name, description_main, descrip label.style.font_color = {0.85, 0.85, 0.85} end -local build_config_gui = (function(_, frame) +local function build_config_gui(data) + local frame = data.frame local objective = Chrono_table.get_table() local switch_state frame.clear() @@ -208,7 +213,9 @@ local build_config_gui = (function(_, frame) frame['comfy_panel_game_lost_confirm_table'].visible = false line_elements[#line_elements + 1] = frame.add({type = 'line'}) -end) +end + +local build_config_gui_token = Token.register(build_config_gui) local function on_gui_click(event) if not event.element then @@ -223,7 +230,7 @@ local function on_gui_click(event) end end -comfy_panel_tabs['ChronoTrain'] = {gui = build_config_gui, admin = true} +Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = true}) local event = require 'utils.event' event.add(defines.events.on_gui_click, on_gui_click) diff --git a/maps/mountain_fortress_v3/highscore.lua b/maps/mountain_fortress_v3/highscore.lua index 015f5a66..e9c1321d 100644 --- a/maps/mountain_fortress_v3/highscore.lua +++ b/maps/mountain_fortress_v3/highscore.lua @@ -9,6 +9,7 @@ local WD = require 'modules.wave_defense.table' local Core = require 'utils.core' local SpamProtection = require 'utils.spam_protection' +local module_name = 'Highscore' local score_dataset = 'highscores' local score_key = 'mountain_fortress_v3_scores' local set_data = Server.set_data @@ -484,7 +485,9 @@ local function add_global_stats(frame) format_time_label.style.minimal_width = 100 end -local show_score = (function(player, frame) +local function show_score(data) + local player = data.player + local frame = data.frame frame.clear() local flow = frame.add {type = 'flow'} @@ -607,7 +610,9 @@ local show_score = (function(player, frame) label.style.horizontal_align = 'right' end -- foreach column end -- foreach entry -end) -- show_score +end + +local show_score_token = Token.register(show_score) local function on_gui_click(event) if not event then @@ -625,7 +630,7 @@ local function on_gui_click(event) if not frame then return end - if frame.name ~= 'Highscore' then + if frame.name ~= module_name then return end @@ -652,7 +657,7 @@ local function on_gui_click(event) sorting_pref.method = 'descending' sorting_pref.column = column end - show_score(player, frame) + show_score({player = player, frame = frame}) return end end @@ -682,7 +687,7 @@ Server.on_data_set_changed( end ) -comfy_panel_tabs['Highscore'] = {gui = show_score, admin = false, only_server_sided = true} +Tabs.add_tab_to_gui({name = module_name, id = show_score_token, admin = false, only_server_sided = true}) Event.on_init(on_init) Event.add(defines.events.on_player_left_game, on_player_left_game) diff --git a/modules/autostash.lua b/modules/autostash.lua index a101ee94..15e3cb5e 100644 --- a/modules/autostash.lua +++ b/modules/autostash.lua @@ -598,6 +598,9 @@ local function do_whitelist() end local function on_player_joined_game(event) + if is_loaded('maps.biter_battles_v2.main') then + return + end create_gui_button(game.players[event.player_index]) end diff --git a/modules/map_info.lua b/modules/map_info.lua index 50c0b105..3ed5c235 100644 --- a/modules/map_info.lua +++ b/modules/map_info.lua @@ -2,6 +2,9 @@ local Event = require 'utils.event' local Global = require 'utils.global' local Tabs = require 'comfy_panel.main' local SpamProtection = require 'utils.spam_protection' +local Token = require 'utils.token' + +local module_name = 'Map Info' local map_info = { localised_category = false, @@ -25,7 +28,8 @@ function Public.Pop_info() return map_info end -local create_map_intro = (function(_, frame) +local function create_map_intro(data) + local frame = data.frame frame.clear() frame.style.padding = 4 frame.style.margin = 0 @@ -89,7 +93,9 @@ local create_map_intro = (function(_, frame) b.style.left_margin = 333 b.style.horizontal_align = 'center' b.style.vertical_align = 'center' -end) +end + +local create_map_intro_token = Token.register(create_map_intro) local function on_player_joined_game(event) local player = game.players[event.player_index] @@ -124,7 +130,7 @@ local function on_gui_click(event) end end -comfy_panel_tabs['Map Info'] = {gui = create_map_intro, admin = false} +Tabs.add_tab_to_gui({name = module_name, id = create_map_intro_token, admin = false}) Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_gui_click, on_gui_click) diff --git a/utils/spam_protection.lua b/utils/spam_protection.lua index 43b96b72..24863fb4 100644 --- a/utils/spam_protection.lua +++ b/utils/spam_protection.lua @@ -4,7 +4,7 @@ local Public = {} local this = { prevent_spam = {}, -- the default table where all player indexes will be stored - default_tick = 10, -- this defines the default tick to check weather or not a user is spamming a button. + default_tick = 5, -- this defines the default tick to check weather or not a user is spamming a button. _DEBUG = false } @@ -57,7 +57,6 @@ function Public.is_spamming(player, value_to_compare, text) if this.prevent_spam[player.index] then if (tick - this.prevent_spam[player.index]) > value then Public.set_new_value(player) - debug_str(player.name .. ' is not spamming.') return false -- is not spamming else debug_str(player.name .. ' is spamming.')