From aaa87601f976c0678428f90a926f47933a016d2a Mon Sep 17 00:00:00 2001 From: James Gillham Date: Mon, 14 Sep 2020 21:14:15 +0100 Subject: [PATCH] change close buttons --- control.lua | 17 ++++---- features/gui/autofill.lua | 3 +- features/gui/blueprint_helper.lua | 23 ++++++---- features/gui/evolution_progress.lua | 35 +++++++++------- features/gui/info.lua | 8 ++-- features/gui/paint.lua | 23 ++++++---- features/gui/player_list.lua | 42 +++++++------------ features/gui/poll.lua | 56 ++++++++++++++++--------- features/gui/redmew_settings.lua | 2 +- features/gui/score.lua | 65 ++++++++++++++++------------- features/gui/tag_group.lua | 17 ++++---- features/gui/tasklist.lua | 51 ++++++++++++++-------- features/server_commands.lua | 20 ++++++--- locale/en/redmew_gui.cfg | 1 - 14 files changed, 210 insertions(+), 153 deletions(-) diff --git a/control.lua b/control.lua index 9ce1a242..60b1ce8e 100644 --- a/control.lua +++ b/control.lua @@ -106,9 +106,6 @@ end if config.turret_active_delay.enabled then require 'features.turret_active_delay' end -if config.autofill.enabled then - require 'features.gui.autofill' -end if config.research_printer.enabled then require 'features.research_printer' end @@ -124,6 +121,12 @@ end if config.player_list.enabled then require 'features.gui.player_list' end +if config.redmew_settings.enabled then + require 'features.gui.redmew_settings' +end +if config.autofill.enabled then + require 'features.gui.autofill' +end if config.evolution_progress.enabled then require 'features.gui.evolution_progress' end @@ -142,9 +145,6 @@ end if config.paint.enabled then require 'features.gui.paint' end -if config.score.enabled then - require 'features.gui.score' -end if config.popup.enabled then require 'features.gui.popup' end @@ -154,8 +154,9 @@ end if config.radio.enabled or _DEBUG then require 'features.gui.radio' end -if config.redmew_settings.enabled then - require 'features.gui.redmew_settings' + +if config.score.enabled then + require 'features.gui.score' end --require 'features.snake.control' diff --git a/features/gui/autofill.lua b/features/gui/autofill.lua index 972ffe00..9b5914b8 100644 --- a/features/gui/autofill.lua +++ b/features/gui/autofill.lua @@ -18,7 +18,6 @@ local enabled_ammo_button = Gui.uid_name() local function player_created(event) local player = game.get_player(event.player_index) - if not player or not player.valid then return end @@ -94,7 +93,7 @@ local function toggle_main_frame(event) Gui.set_data(button, name) end - frame.add {type = 'button', name = main_button_name, caption = {'common.close_button'}} + frame.add {type = 'button', name = main_button_name, caption = {'common.close_button'}, style = 'back_button'} local data = { enabled_checkbox = enabled_checkbox, diff --git a/features/gui/blueprint_helper.lua b/features/gui/blueprint_helper.lua index 1d9b702c..d77d8262 100644 --- a/features/gui/blueprint_helper.lua +++ b/features/gui/blueprint_helper.lua @@ -269,16 +269,12 @@ local filter_table_close_button_name = Gui.uid_name() local filter_table_clear_name = Gui.uid_name() local clear_all_filters_name = Gui.uid_name() -local function player_joined(event) +local function player_created(event) local player = game.get_player(event.player_index) if not player or not player.valid then return end - if player.gui.top[main_button_name] ~= nil then - return - end - player.gui.top.add( { name = main_button_name, @@ -325,7 +321,13 @@ local function draw_filters_table(event) local flow = frame.add {type = 'flow'} - local close = flow.add {type = 'button', name = filter_table_close_button_name, caption = {'common.close_button'}} + local close = + flow.add { + type = 'button', + name = filter_table_close_button_name, + caption = {'common.close_button'}, + style = 'back_button' + } Gui.set_data(close, frame) local clear = @@ -492,7 +494,12 @@ local function toggle(event) } Gui.set_data(filter_button, filters) - main_frame.add {type = 'button', name = main_button_name, caption = {'common.close_button'}} + main_frame.add { + type = 'button', + name = main_button_name, + caption = {'common.close_button'}, + style = 'back_button' + } Gui.set_data(main_frame, filters) end end @@ -631,4 +638,4 @@ Gui.on_custom_close( Gui.allow_player_to_toggle_top_element_visibility(main_button_name) -Event.add(defines.events.on_player_joined_game, player_joined) +Event.add(defines.events.on_player_created, player_created) diff --git a/features/gui/evolution_progress.lua b/features/gui/evolution_progress.lua index e8dffd78..fe59fd63 100644 --- a/features/gui/evolution_progress.lua +++ b/features/gui/evolution_progress.lua @@ -79,28 +79,34 @@ local function update_gui(player) end end -local function player_joined(event) +local function player_created(event) local player = game.get_player(event.player_index) if not player or not player.valid then return end - if player.gui.top[main_button_name] ~= nil then - update_gui(player) - return - end - local evolution_factor = get_evolution_percentage() local alien_name = get_alien_name(evolution_factor) - player.gui.top.add({ - name = main_button_name, - type = 'sprite-button', - sprite = 'entity/' .. alien_name, - number = evolution_factor * 100, - tooltip = {'evolution_progress.tooltip'}, - enabled = false - }) + player.gui.top.add( + { + name = main_button_name, + type = 'sprite-button', + sprite = 'entity/' .. alien_name, + number = evolution_factor * 100, + tooltip = {'evolution_progress.tooltip'}, + enabled = false + } + ) +end + +local function player_joined(event) + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + + update_gui(player) end local function on_nth_tick() @@ -140,5 +146,6 @@ end Gui.allow_player_to_toggle_top_element_visibility(main_button_name) +Event.add(defines.events.on_player_created, player_created) Event.add(defines.events.on_player_joined_game, player_joined) Event.on_nth_tick(207, on_nth_tick) diff --git a/features/gui/info.lua b/features/gui/info.lua index a66fdfa6..8c74a135 100644 --- a/features/gui/info.lua +++ b/features/gui/info.lua @@ -222,8 +222,7 @@ local pages = { discord_textbox_flow_style.horizontal_align = 'center' discord_textbox_flow_style.horizontally_stretchable = true discord_textbox_flow.add({type = 'label', caption = 'Discord: '}).style.font = 'default-bold' - local discord_textbox = - discord_textbox_flow.add {type = 'text-box', text = 'https://redmew.com/discord '} + local discord_textbox = discord_textbox_flow.add {type = 'text-box', text = 'https://redmew.com/discord '} discord_textbox.read_only = true discord_textbox.style.width = 235 discord_textbox.style.height = 28 @@ -629,7 +628,7 @@ local function draw_main_frame(center, player) bottom_flow_style.top_padding = 8 bottom_flow_style.horizontally_stretchable = true - bottom_flow.add {type = 'button', name = main_button_name, caption = {'common.close_button'}} + bottom_flow.add {type = 'button', name = main_button_name, caption = {'common.close_button'}, style = 'back_button'} player.opened = frame end @@ -688,8 +687,7 @@ local function player_created(event) return end - local gui = player.gui - gui.top.add( + player.gui.top.add( { type = 'sprite-button', name = main_button_name, diff --git a/features/gui/paint.lua b/features/gui/paint.lua index 4d1d4cab..5f93df13 100644 --- a/features/gui/paint.lua +++ b/features/gui/paint.lua @@ -187,16 +187,12 @@ local function get_tile_localised_name(tile_name) end end -local function player_joined(event) +local function player_created(event) local player = game.get_player(event.player_index) if not player or not player.valid then return end - if player.gui.top[main_button_name] ~= nil then - return - end - player.gui.top.add( { name = main_button_name, @@ -236,7 +232,13 @@ local function draw_filters_table(event) local flow = frame.add {type = 'flow'} - local close = flow.add {type = 'button', name = filter_table_close_button_name, caption = {'common.close_button'}} + local close = + flow.add { + type = 'button', + name = filter_table_close_button_name, + caption = {'common.close_button'}, + style = 'back_button' + } Gui.set_data(close, frame) event.player.opened = frame @@ -289,7 +291,12 @@ local function toggle(event) local buttons_flow = main_frame.add {type = 'flow', direction = 'horizontal'} - buttons_flow.add {type = 'button', name = main_button_name, caption = {'common.close_button'}} + buttons_flow.add { + type = 'button', + name = main_button_name, + caption = {'common.close_button'}, + style = 'back_button' + } local clear_brush = buttons_flow.add {type = 'button', name = filter_clear_name, caption = {'paint.clear_brush'}} @@ -364,6 +371,6 @@ Gui.on_custom_close( Gui.allow_player_to_toggle_top_element_visibility(main_button_name) -Event.add(defines.events.on_player_joined_game, player_joined) +Event.add(defines.events.on_player_created, player_created) Event.add(defines.events.on_player_built_tile, player_build_tile) Event.add(defines.events.on_robot_built_tile, robot_built_tile) diff --git a/features/gui/player_list.lua b/features/gui/player_list.lua index 82065e6f..137c05f3 100644 --- a/features/gui/player_list.lua +++ b/features/gui/player_list.lua @@ -612,7 +612,7 @@ local function draw_main_frame(left, player) tooltip = {'player_list.poke_notify_tooltip'} } - frame.add {type = 'button', name = main_button_name, caption = {'player_list.close_caption'}} + frame.add {type = 'button', name = main_button_name, caption = {'common.close_button'}, style = 'back_button'} local settings = player_settings[player_index] or get_default_player_settings() local data = { @@ -668,38 +668,23 @@ local function tick() end end -local function player_joined(event) +local function player_created(event) local player = game.get_player(event.player_index) if not player or not player.valid then return end - local gui = player.gui - local top = gui.top - - if not top[main_button_name] then - top.add( - { - type = 'sprite-button', - name = main_button_name, - sprite = 'entity/character', - tooltip = {'player_list.tooltip'} - } - ) - end - - for _, p in ipairs(game.connected_players) do - local frame = p.gui.left[main_frame_name] - - if frame and frame.valid then - local data = Gui.get_data(frame) - redraw_title(data) - redraw_cells(data) - end - end + player.gui.top.add( + { + type = 'sprite-button', + name = main_button_name, + sprite = 'entity/character', + tooltip = {'player_list.tooltip'} + } + ) end -local function player_left() +local function update_player_list(event) for _, p in ipairs(game.connected_players) do local frame = p.gui.left[main_frame_name] @@ -712,8 +697,9 @@ local function player_left() end Event.on_nth_tick(1800, tick) -Event.add(defines.events.on_player_joined_game, player_joined) -Event.add(defines.events.on_player_left_game, player_left) +Event.add(defines.events.on_player_created, player_created) +Event.add(defines.events.on_player_joined_game, update_player_list) +Event.add(defines.events.on_player_left_game, update_player_list) Gui.on_click(main_button_name, toggle) diff --git a/features/gui/poll.lua b/features/gui/poll.lua index dc215868..9cc3c036 100644 --- a/features/gui/poll.lua +++ b/features/gui/poll.lua @@ -382,7 +382,13 @@ local function draw_main_frame(left, player) left_flow.style.horizontal_align = 'left' left_flow.style.horizontally_stretchable = true - local close_button = left_flow.add {type = 'button', name = main_button_name, caption = 'Close'} + local close_button = + left_flow.add { + type = 'button', + name = main_button_name, + caption = {'common.close_button'}, + style = 'back_button' + } apply_button_style(close_button) local right_flow = bottom_flow.add {type = 'flow'} @@ -626,7 +632,13 @@ local function draw_create_poll_frame(parent, player, previous_data) left_flow.style.horizontal_align = 'left' left_flow.style.horizontally_stretchable = true - local close_button = left_flow.add {type = 'button', name = create_poll_close_name, caption = 'Close'} + local close_button = + left_flow.add { + type = 'button', + name = create_poll_close_name, + caption = {'common.close_button'}, + style = 'back_button' + } apply_button_style(close_button) Gui.set_data(close_button, frame) @@ -638,7 +650,8 @@ local function draw_create_poll_frame(parent, player, previous_data) right_flow.style.horizontal_align = 'right' if edit_mode then - local delete_button = right_flow.add {type = 'button', name = create_poll_delete_name, caption = 'Delete'} + local delete_button = + right_flow.add {type = 'button', name = create_poll_delete_name, caption = {'common.delete'}} apply_button_style(delete_button) Gui.set_data(delete_button, data) end @@ -812,28 +825,32 @@ local function vote(event) end end +local function player_created(event) + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + + player.gui.top.add( + { + type = 'sprite-button', + name = main_button_name, + sprite = 'item/programmable-speaker', + tooltip = {'poll.tooltip'} + } + ) +end + local function player_joined(event) local player = game.get_player(event.player_index) if not player or not player.valid then return end - local gui = player.gui - if gui.top[main_button_name] ~= nil then - local frame = gui.left[main_frame_name] - if frame and frame.valid then - local data = Gui.get_data(frame) - update_poll_viewer(data) - end - else - gui.top.add( - { - type = 'sprite-button', - name = main_button_name, - sprite = 'item/programmable-speaker', - tooltip = {'poll.tooltip'} - } - ) + local frame = player.gui.left[main_frame_name] + if frame and frame.valid then + local data = Gui.get_data(frame) + update_poll_viewer(data) end end @@ -856,6 +873,7 @@ local function tick() end end +Event.add(defines.events.on_player_created, player_created) Event.add(defines.events.on_player_joined_game, player_joined) Event.on_nth_tick(60, tick) diff --git a/features/gui/redmew_settings.lua b/features/gui/redmew_settings.lua index df98f8d4..345adfa2 100644 --- a/features/gui/redmew_settings.lua +++ b/features/gui/redmew_settings.lua @@ -40,7 +40,7 @@ local function player_joined(event) local main_frame = player.gui.center[main_frame_name] - if main_frame then + if main_frame and main_frame.valid then close_main_frame(main_frame, player) end end diff --git a/features/gui/score.lua b/features/gui/score.lua index d486b87a..20b1086d 100644 --- a/features/gui/score.lua +++ b/features/gui/score.lua @@ -20,7 +20,12 @@ local memory = { player_death_causes = {} } -Global.register(memory, function(tbl) memory = tbl end) +Global.register( + memory, + function(tbl) + memory = tbl + end +) ---Creates a map of score name => {captain, tooltip} local function get_global_score_labels() @@ -38,24 +43,27 @@ local function get_global_score_labels() return score_labels end -local do_redraw_score = Token.register(function() - local players = game.connected_players - local scores = get_global_score_labels() +local do_redraw_score = + Token.register( + function() + local players = game.connected_players + local scores = get_global_score_labels() - for i = 1, #players do - local player = players[i] - local frame = player.gui.top[main_frame_name] + for i = 1, #players do + local player = players[i] + local frame = player.gui.top[main_frame_name] - if frame and frame.valid then - local score_table = frame.score_table - for score_name, textual_display in pairs(scores) do - score_table[score_name].caption = textual_display.caption + if frame and frame.valid then + local score_table = frame.score_table + for score_name, textual_display in pairs(scores) do + score_table[score_name].caption = textual_display.caption + end end end - end - memory.redraw_score_scheduled = false -end) + memory.redraw_score_scheduled = false + end +) local function schedule_redraw_score() if memory.redraw_score_scheduled then @@ -67,22 +75,20 @@ local function schedule_redraw_score() memory.redraw_score_scheduled = true end -local function player_joined_game(event) +local function player_created(event) local player = game.get_player(event.player_index) if not player then return end - local top = player.gui.top - - if not top[main_button_name] then - top.add({ + player.gui.top.add( + { type = 'sprite-button', name = main_button_name, sprite = 'achievement/there-is-no-spoon', tooltip = {'score.tooltip'} - }) - end + } + ) end local function score_label_style(label, color) @@ -100,12 +106,15 @@ local function score_show(top) style.horizontal_spacing = 16 for score_name, textual_display in pairs(scores) do - local label = score_table.add({ - type = 'label', - name = score_name, - caption = textual_display.caption, - tooltip = textual_display.tooltip - }) + local label = + score_table.add( + { + type = 'label', + name = score_name, + caption = textual_display.caption, + tooltip = textual_display.tooltip + } + ) score_label_style(label, Color.white) end end @@ -162,5 +171,5 @@ Gui.on_click( Gui.allow_player_to_toggle_top_element_visibility(main_button_name) -Event.add(defines.events.on_player_joined_game, player_joined_game) +Event.add(defines.events.on_player_created, player_created) Event.add(ScoreTracker.events.on_global_score_changed, global_score_changed) diff --git a/features/gui/tag_group.lua b/features/gui/tag_group.lua index 5caf0302..4f6d7f09 100644 --- a/features/gui/tag_group.lua +++ b/features/gui/tag_group.lua @@ -136,16 +136,12 @@ local confirm_create_tag_name = Gui.uid_name() local delete_tag_name = Gui.uid_name() local close_create_tag_name = Gui.uid_name() -local function player_joined(event) +local function player_created(event) local player = game.get_player(event.player_index) if not player or not player.valid then return end - if player.gui.top[main_button_name] ~= nil then - return - end - player.gui.top.add( { name = main_button_name, @@ -264,7 +260,7 @@ local function draw_main_frame(player) left_flow.style.horizontal_align = 'left' left_flow.style.horizontally_stretchable = true - left_flow.add {type = 'button', name = main_button_name, caption = {'common.close_button'}} + left_flow.add {type = 'button', name = main_button_name, caption = {'common.close_button'}, style = 'back_button'} local right_flow = bottom_flow.add {type = 'flow', direction = 'horizontal'} right_flow.style.horizontal_align = 'right' @@ -450,7 +446,12 @@ local function draw_create_tag_frame(event, tag_data) left_flow.style.horizontally_stretchable = true local close_button = - left_flow.add {type = 'button', name = close_create_tag_name, caption = {'common.close_button'}} + left_flow.add { + type = 'button', + name = close_create_tag_name, + caption = {'common.close_button'}, + style = 'back_button' + } Gui.set_data(close_button, frame) local right_flow = bottom_flow.add {type = 'flow', direction = 'horizontal'} @@ -786,7 +787,7 @@ Event.add( end ) -Event.add(defines.events.on_player_joined_game, player_joined) +Event.add(defines.events.on_player_created, player_created) local function tag_command(args) local target_player = game.players[args.player] diff --git a/features/gui/tasklist.lua b/features/gui/tasklist.lua index 2a807e78..8016dd58 100644 --- a/features/gui/tasklist.lua +++ b/features/gui/tasklist.lua @@ -414,7 +414,7 @@ local function draw_main_frame(left, player) } data.notify_checkbox = notify_checkbox - frame.add {type = 'button', name = main_button_name, caption = 'Close'} + frame.add {type = 'button', name = main_button_name, caption = {'common.close_button'}, style = 'back_button'} end local function close_edit_announcements_frame(frame) @@ -595,7 +595,13 @@ local function draw_create_task_frame(left, previous_task) local bottom_flow = frame.add {type = 'flow'} - local close_button = bottom_flow.add {type = 'button', name = create_task_close_button_name, caption = 'Close'} + local close_button = + bottom_flow.add { + type = 'button', + name = create_task_close_button_name, + caption = {'common.close_button'}, + style = 'back_button' + } Gui.set_data(close_button, frame) local clear_button = bottom_flow.add {type = 'button', name = create_task_clear_button_name, caption = 'Clear'} Gui.set_data(clear_button, textbox) @@ -605,15 +611,29 @@ local function draw_create_task_frame(left, previous_task) Gui.set_data(confirm_button, {frame = frame, textbox = textbox, previous_task = previous_task}) end +local function player_created(event) + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + + player.gui.top.add( + { + type = 'sprite-button', + name = main_button_name, + sprite = 'item/repair-pack', + tooltip = {'tasklist.tooltip'} + } + ) +end + local function player_joined(event) local player = game.get_player(event.player_index) if not player or not player.valid then return end - local gui = player.gui - - local frame = gui.left[main_frame_name] + local frame = player.gui.left[main_frame_name] if frame and frame.valid then local text = announcements.edit_text local last_edit_message = get_announcements_updated_by_message() @@ -644,18 +664,6 @@ local function player_joined(event) end end end - - local top = gui.top - if not top[main_button_name] then - top.add( - { - type = 'sprite-button', - name = main_button_name, - sprite = 'item/repair-pack', - tooltip = {'tasklist.tooltip'} - } - ) - end end local function player_left(event) @@ -686,6 +694,7 @@ local function on_tick() end end +Event.add(defines.events.on_player_created, player_created) Event.add(defines.events.on_player_joined_game, player_joined) Event.add(defines.events.on_player_left_game, player_left) Event.on_nth_tick(3600, on_tick) @@ -731,7 +740,13 @@ Gui.on_click( local bottom_flow = frame.add {type = 'flow'} - local close_button = bottom_flow.add {type = 'button', name = edit_close_button_name, caption = 'Close'} + local close_button = + bottom_flow.add { + type = 'button', + name = edit_close_button_name, + caption = {'common.close_button'}, + style = 'back_button' + } local clear_button = bottom_flow.add {type = 'button', name = edit_clear_button_name, caption = 'Clear'} local reset_button = bottom_flow.add {type = 'button', name = edit_reset_button_name, caption = 'Reset'} bottom_flow.add({type = 'flow'}).style.horizontally_stretchable = true diff --git a/features/server_commands.lua b/features/server_commands.lua index c0536a1c..5408dcad 100644 --- a/features/server_commands.lua +++ b/features/server_commands.lua @@ -1,13 +1,23 @@ -local Poll = {send_poll_result_to_discord = function () end} -if global.config.poll.enabled then - Poll = require 'features.gui.poll' -end - +local Poll = {send_poll_result_to_discord = function() end} local Rank = require 'features.rank_system' local Token = require 'utils.token' local Server = require 'features.server' local Donator = require 'features.donator' +if global.config.poll.enabled then + local Event = require 'utils.event' + + local function set_poll() + -- Hack to prevent poll being required before control.lua finishes. + -- This is so that the top gui buttons are in the order they are + -- required in control.lua. + Poll = _G.package.loaded['features.gui.poll'] + end + + Event.on_init(set_poll) + Event.on_load(set_poll) +end + --- This module is for the web server to call functions and raise events. -- Not intended to be called by scripts. -- Needs to be in the _G table so it can be accessed by the web server. diff --git a/locale/en/redmew_gui.cfg b/locale/en/redmew_gui.cfg index e9054548..07943206 100644 --- a/locale/en/redmew_gui.cfg +++ b/locale/en/redmew_gui.cfg @@ -64,7 +64,6 @@ poke_caption=Poke __1__ report_caption=Report __1__ report_tooltip=Report player to the admin team for griefing or breaking the rules. report_button_tooltip=Report __1__ -close_caption=Close poke_notify_caption=Notify me when pokes happen. poke_notify_caption_short=Notify pokes. poke_notify_tooltip=Receive a message when a player pokes another player.