From 771e5e7aeb63ad0d6137c6fea970e02389a8792c Mon Sep 17 00:00:00 2001 From: hanakocz Date: Tue, 17 Mar 2020 04:07:33 +0100 Subject: [PATCH] Change comfy panel to allow multiple admin tabs --- comfy_panel/admin.lua | 2 +- comfy_panel/config.lua | 2 +- comfy_panel/group.lua | 2 +- comfy_panel/main.lua | 7 ++++--- comfy_panel/player_list.lua | 2 +- comfy_panel/poll.lua | 2 +- comfy_panel/score.lua | 2 +- maps/chronosphere/main.lua | 1 + modules/map_info.lua | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/comfy_panel/admin.lua b/comfy_panel/admin.lua index e0506045..ee0966f5 100644 --- a/comfy_panel/admin.lua +++ b/comfy_panel/admin.lua @@ -390,7 +390,7 @@ local function on_gui_selection_state_changed(event) end end -comfy_panel_tabs["Admin"] = create_admin_panel +comfy_panel_tabs["Admin"] = {gui = create_admin_panel, admin = true} diff --git a/comfy_panel/config.lua b/comfy_panel/config.lua index 22fcfc67..16352cfd 100644 --- a/comfy_panel/config.lua +++ b/comfy_panel/config.lua @@ -82,7 +82,7 @@ local function on_gui_click(event) end end -comfy_panel_tabs["Config"] = build_config_gui +comfy_panel_tabs["Config"] = {gui = build_config_gui, admin = false} local event = require 'utils.event' diff --git a/comfy_panel/group.lua b/comfy_panel/group.lua index 82f20c87..19b395ee 100644 --- a/comfy_panel/group.lua +++ b/comfy_panel/group.lua @@ -214,7 +214,7 @@ local function on_gui_click(event) end end -comfy_panel_tabs["Groups"] = build_group_gui +comfy_panel_tabs["Groups"] = {gui = build_group_gui, admin = false} local event = require 'utils.event' diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index 66142024..0c1f7c79 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -3,7 +3,8 @@ Comfy Panel To add a tab, insert into the "comfy_panel_tabs" table. -Example: comfy_panel_tabs["mapscores"] = draw_map_scores +Example: comfy_panel_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 @@ -62,7 +63,7 @@ local function main_frame(player) local tabbed_pane = frame.add({type = "tabbed-pane", name = "tabbed_pane"}) for name, func in pairs(tabs) do - if name == "Admin" then + if func.admin == true then if player.admin then local tab = tabbed_pane.add({type = "tab", caption = name}) local frame = tabbed_pane.add({type = "frame", name = name, direction = "vertical"}) @@ -142,4 +143,4 @@ end event.add(defines.events.on_player_joined_game, on_player_joined_game) event.add(defines.events.on_gui_click, on_gui_click) -return Public \ No newline at end of file +return Public diff --git a/comfy_panel/player_list.lua b/comfy_panel/player_list.lua index 1544b702..a6a20ede 100644 --- a/comfy_panel/player_list.lua +++ b/comfy_panel/player_list.lua @@ -388,7 +388,7 @@ local on_init = function() global.player_list.sorting_method = {} end -comfy_panel_tabs["Players"] = player_list_show +comfy_panel_tabs["Players"] = {gui = player_list_show, admin = false} event.on_init(on_init) event.add(defines.events.on_player_joined_game, on_player_joined_game) diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index 34fd21a5..6f6f0ecd 100644 --- a/comfy_panel/poll.lua +++ b/comfy_panel/poll.lua @@ -1297,6 +1297,6 @@ function Class.send_poll_result_to_discord(id) Server.to_discord_embed(message) end -comfy_panel_tabs["Polls"] = draw_main_frame +comfy_panel_tabs["Polls"] = {gui = draw_main_frame, admin = false} return Class diff --git a/comfy_panel/score.lua b/comfy_panel/score.lua index 6ec815c8..5cef514b 100644 --- a/comfy_panel/score.lua +++ b/comfy_panel/score.lua @@ -358,7 +358,7 @@ local function tick(event) refresh_score_full() end ]] -comfy_panel_tabs["Scoreboard"] = show_score +comfy_panel_tabs["Scoreboard"] = {gui = show_score, admin = false} --event.on_nth_tick(300, tick) event.add(defines.events.on_player_mined_entity, on_player_mined_entity) diff --git a/maps/chronosphere/main.lua b/maps/chronosphere/main.lua index 1a76bbb4..b6c71b97 100644 --- a/maps/chronosphere/main.lua +++ b/maps/chronosphere/main.lua @@ -30,6 +30,7 @@ global.objective.config = {} global.flame_boots = {} global.comfylatron = nil global.lab_cells = {} +require "maps.chronosphere.config_tab" local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 32, ['grenade'] = 4, ['raw-fish'] = 4, ['rail'] = 16, ['wood'] = 16} diff --git a/modules/map_info.lua b/modules/map_info.lua index ce08da91..d5fb2556 100644 --- a/modules/map_info.lua +++ b/modules/map_info.lua @@ -104,7 +104,7 @@ local function on_gui_click(event) if event.element.name == "close_map_intro" then game.players[event.player_index].gui.left.comfy_panel.destroy() return end end -comfy_panel_tabs["Map Info"] = create_map_intro +comfy_panel_tabs["Map Info"] = {gui = create_map_intro, admin = false} local event = require 'utils.event' event.add(defines.events.on_player_joined_game, on_player_joined_game)