From c60704303ffa3c1178df00978df5fc45279e03bf Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sat, 15 Aug 2020 13:32:47 +0200 Subject: [PATCH] minor fixes fixed gui bug where you had to click twice refactored rpg from .left to .screen --- comfy_panel/main.lua | 198 ++++++++++++--------- maps/dungeons/boss_arena.lua | 2 +- maps/mountain_fortress_v3/gui.lua | 2 +- maps/mountain_fortress_v3/ic/functions.lua | 3 +- modules/rpg/functions.lua | 14 +- modules/rpg/gui.lua | 8 +- modules/rpg/main.lua | 8 +- 7 files changed, 131 insertions(+), 104 deletions(-) diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index e3e1b014..58a2c6ba 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -9,135 +9,161 @@ if admin = true, then tab is visible only for admins (usable for map-specific se draw_map_scores would be a function with the player and the frame as arguments ]] - local event = require 'utils.event' comfy_panel_tabs = {} - local Public = {} function Public.get_tabs(data) - return comfy_panel_tabs + return comfy_panel_tabs end function Public.comfy_panel_clear_left_gui(player) - for _, child in pairs(player.gui.left.children) do - child.visible = false - end + for _, child in pairs(player.gui.left.children) do + child.destroy() + end end function Public.comfy_panel_restore_left_gui(player) - for _, child in pairs(player.gui.left.children) do - child.visible = true - end + for _, child in pairs(player.gui.left.children) do + child.visible = true + end +end + +function Public.comfy_panel_clear_screen_gui(player) + for _, child in pairs(player.gui.screen.children) do + child.destroy() + end +end + +function Public.comfy_panel_restore_screen_gui(player) + for _, child in pairs(player.gui.screen.children) do + child.visible = true + end end function Public.comfy_panel_get_active_frame(player) - if not player.gui.left.comfy_panel then return false end - if not player.gui.left.comfy_panel.tabbed_pane.selected_tab_index then return player.gui.left.comfy_panel.tabbed_pane.tabs[1].content end - return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content + if not player.gui.left.comfy_panel then + return false + end + if not player.gui.left.comfy_panel.tabbed_pane.selected_tab_index then + return player.gui.left.comfy_panel.tabbed_pane.tabs[1].content + end + return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content end function Public.comfy_panel_refresh_active_tab(player) - local frame = Public.comfy_panel_get_active_frame(player) - if not frame then return end - comfy_panel_tabs[frame.name].gui(player, frame) + local frame = Public.comfy_panel_get_active_frame(player) + if not frame then + return + end + comfy_panel_tabs[frame.name].gui(player, frame) end local function top_button(player) - if player.gui.top["comfy_panel_top_button"] then return end - local button = player.gui.top.add({type = "sprite-button", name = "comfy_panel_top_button", sprite = "item/raw-fish"}) - button.style.minimal_height = 38 - button.style.minimal_width = 38 - button.style.padding = -2 + if player.gui.top['comfy_panel_top_button'] then + return + end + local button = + player.gui.top.add({type = 'sprite-button', name = 'comfy_panel_top_button', sprite = 'item/raw-fish'}) + button.style.minimal_height = 38 + button.style.minimal_width = 38 + button.style.padding = -2 end local function main_frame(player) - local tabs = comfy_panel_tabs - Public.comfy_panel_clear_left_gui(player) + local tabs = comfy_panel_tabs + Public.comfy_panel_clear_left_gui(player) - local frame = player.gui.left.add({type = "frame", name = "comfy_panel"}) - frame.style.margin = 6 + local frame = player.gui.left.add({type = 'frame', name = 'comfy_panel'}) + frame.style.margin = 6 - local tabbed_pane = frame.add({type = "tabbed-pane", name = "tabbed_pane"}) + local tabbed_pane = frame.add({type = 'tabbed-pane', name = 'tabbed_pane'}) - for name, func in pairs(tabs) do - 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"}) - frame.style.minimal_height = 480 - frame.style.maximal_height = 480 - frame.style.minimal_width = 800 - frame.style.maximal_width = 800 - tabbed_pane.add_tab(tab, frame) - end - else - local tab = tabbed_pane.add({type = "tab", caption = name}) - local frame = tabbed_pane.add({type = "frame", name = name, direction = "vertical"}) - frame.style.minimal_height = 480 - frame.style.maximal_height = 480 - frame.style.minimal_width = 800 - frame.style.maximal_width = 800 - tabbed_pane.add_tab(tab, frame) - end - end + for name, func in pairs(tabs) do + 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'}) + frame.style.minimal_height = 480 + frame.style.maximal_height = 480 + frame.style.minimal_width = 800 + frame.style.maximal_width = 800 + tabbed_pane.add_tab(tab, frame) + end + else + local tab = tabbed_pane.add({type = 'tab', caption = name}) + local frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) + frame.style.minimal_height = 480 + frame.style.maximal_height = 480 + frame.style.minimal_width = 800 + frame.style.maximal_width = 800 + tabbed_pane.add_tab(tab, frame) + end + end - local tab = tabbed_pane.add({type = "tab", name = "comfy_panel_close", caption = "X"}) - tab.style.maximal_width = 32 - local frame = tabbed_pane.add({type = "frame", name = name, direction = "vertical"}) - tabbed_pane.add_tab(tab, frame) + local tab = tabbed_pane.add({type = 'tab', name = 'comfy_panel_close', caption = 'X'}) + tab.style.maximal_width = 32 + local frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'}) + tabbed_pane.add_tab(tab, frame) - for _, child in pairs(tabbed_pane.children) do - child.style.padding = 8 - child.style.left_padding = 2 - child.style.right_padding = 2 - end + for _, child in pairs(tabbed_pane.children) do + child.style.padding = 8 + child.style.left_padding = 2 + child.style.right_padding = 2 + end - Public.comfy_panel_refresh_active_tab(player) + Public.comfy_panel_refresh_active_tab(player) end function Public.comfy_panel_call_tab(player, name) - main_frame(player) - local tabbed_pane = player.gui.left.comfy_panel.tabbed_pane - for key, v in pairs(tabbed_pane.tabs) do - if v.tab.caption == name then - tabbed_pane.selected_tab_index = key - Public.comfy_panel_refresh_active_tab(player) - end - end + main_frame(player) + local tabbed_pane = player.gui.left.comfy_panel.tabbed_pane + for key, v in pairs(tabbed_pane.tabs) do + if v.tab.caption == name then + tabbed_pane.selected_tab_index = key + Public.comfy_panel_refresh_active_tab(player) + end + end end local function on_player_joined_game(event) - top_button(game.players[event.player_index]) + top_button(game.players[event.player_index]) end local function on_gui_click(event) - if not event.element then return end - if not event.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 player = game.players[event.player_index] - if event.element.name == "comfy_panel_top_button" then - if player.gui.left.comfy_panel then - player.gui.left.comfy_panel.destroy() - Public.comfy_panel_restore_left_gui(player) - return - else - main_frame(player) - return - end - end + if event.element.name == 'comfy_panel_top_button' then + if player.gui.left.comfy_panel then + player.gui.left.comfy_panel.destroy() + return + else + Public.comfy_panel_clear_screen_gui(player) + main_frame(player) + return + end + end - if event.element.caption == "X" and event.element.name == "comfy_panel_close" then - player.gui.left.comfy_panel.destroy() - Public.comfy_panel_restore_left_gui(player) - return - end + if event.element.caption == 'X' and event.element.name == 'comfy_panel_close' then + player.gui.left.comfy_panel.destroy() + return + end - if not event.element.caption then return end - if event.element.type ~= "tab" then return end - Public.comfy_panel_refresh_active_tab(player) + if not event.element.caption then + return + end + if event.element.type ~= 'tab' then + return + end + Public.comfy_panel_refresh_active_tab(player) end event.add(defines.events.on_player_joined_game, on_player_joined_game) diff --git a/maps/dungeons/boss_arena.lua b/maps/dungeons/boss_arena.lua index 509c9572..b6608241 100644 --- a/maps/dungeons/boss_arena.lua +++ b/maps/dungeons/boss_arena.lua @@ -127,7 +127,7 @@ local function hide_rpg(player, show) local rpg_settings = RPG_T.settings_frame_name local rpg_b = player.gui.top[rpg_button] - local rpg_f = player.gui.left[rpg_frame] + local rpg_f = player.gui.screen[rpg_frame] local rpg_s = player.gui.screen[rpg_settings] if show then diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index 6b7a8de4..9d8bbdf5 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -214,7 +214,7 @@ local function on_player_changed_surface(event) local info = player.gui.top[main_button_name] local wd = player.gui.top['wave_defense'] local rpg_b = player.gui.top[rpg_button] - local rpg_f = player.gui.left[rpg_frame] + local rpg_f = player.gui.screen[rpg_frame] local rpg_s = player.gui.screen[rpg_settings] local diff = player.gui.top['difficulty_gui'] local charging = player.gui.top['charging_station'] diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index 27914406..b29f2804 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -560,7 +560,8 @@ function Public.validate_owner(ic, player, entity) local p = game.players[car.owner] if p then if car.owner ~= player.index and player.driving then - return Utils.print_to(nil, '{Car} ' .. player.name .. ' is driving ' .. p.name .. '´s car.') + player.driving = false + return Utils.print_to(nil, '{Car} ' .. player.name .. ' tried to drive ' .. p.name .. '´s car.') end end end diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index 4304e5cf..247526d0 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -121,7 +121,7 @@ local function level_up(player) rpg_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute + distribute_points_gain RPG_GUI.update_char_button(player) table.shuffle_table(rpg_frame_icons) - if player.gui.left[main_frame_name] then + if player.gui.screen[main_frame_name] then RPG_GUI.toggle(player, true) end Public.level_up_effects(player) @@ -225,8 +225,8 @@ function Public.update_mana(player) return end - if player.gui.left[main_frame_name] then - local f = player.gui.left[main_frame_name] + if player.gui.screen[main_frame_name] then + local f = player.gui.screen[main_frame_name] local data = Gui.get_data(f) if data.mana and data.mana.valid then data.mana.caption = rpg_t[player.index].mana @@ -271,8 +271,8 @@ function Public.reward_mana(player, mana_to_add) return end - if player.gui.left[main_frame_name] then - local f = player.gui.left[main_frame_name] + if player.gui.screen[main_frame_name] then + local f = player.gui.screen[main_frame_name] local data = Gui.get_data(f) if data.mana and data.mana.valid then data.mana.caption = rpg_t[player.index].mana @@ -306,8 +306,8 @@ function Public.update_health(player) return end - if player.gui.left[main_frame_name] then - local f = player.gui.left[main_frame_name] + if player.gui.screen[main_frame_name] then + local f = player.gui.screen[main_frame_name] local data = Gui.get_data(f) if data.health and data.health.valid then data.health.caption = (math.round(player.character.health * 10) / 10) diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index acde8c91..21e7e9d9 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -169,7 +169,7 @@ local function draw_main_frame(player) end local main_frame = - player.gui.left.add( + player.gui.screen.add( { type = 'frame', name = main_frame_name, @@ -177,6 +177,7 @@ local function draw_main_frame(player) direction = 'vertical' } ) + main_frame.location = {x = 1, y = 40} local data = {} local rpg_extra = RPG.get('rpg_extra') @@ -533,9 +534,8 @@ function Public.update_player_stats(player) end function Public.toggle(player, recreate) - local left = player.gui.left local screen = player.gui.screen - local main_frame = left[main_frame_name] + local main_frame = screen[main_frame_name] if recreate and main_frame then remove_main_frame(main_frame, screen) @@ -672,7 +672,7 @@ Gui.on_click( remove_settings_frame(event.element) - if player.gui.left[main_frame_name] then + if player.gui.screen[main_frame_name] then toggle(player, true) end end diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 1dbcb0ef..44e2efd2 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -370,8 +370,8 @@ local function give_player_flameboots(player) if rpg_t[player.index].mana <= 0 then rpg_t[player.index].mana = 0 end - if player.gui.left[main_frame_name] then - local f = player.gui.left[main_frame_name] + if player.gui.screen[main_frame_name] then + local f = player.gui.screen[main_frame_name] local data = Gui.get_data(f) if data.mana and data.mana.valid then data.mana.caption = rpg_t[player.index].mana @@ -699,8 +699,8 @@ local function on_pre_player_mined_item(event) xp_amount = (1.5 + event.entity.prototype.max_health * 0.0035) * distance_multiplier end - if player.gui.left[main_frame_name] then - local f = player.gui.left[main_frame_name] + if player.gui.screen[main_frame_name] then + local f = player.gui.screen[main_frame_name] local data = Gui.get_data(f) if data.exp_gui and data.exp_gui.valid then data.exp_gui.caption = math.floor(rpg_t[player.index].xp)