You've already forked ComfyFactorio
mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-09-16 09:06:21 +02:00
minor fixes
fixed gui bug where you had to click twice refactored rpg from .left to .screen
This commit is contained in:
@@ -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
|
draw_map_scores would be a function with the player and the frame as arguments
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local event = require 'utils.event'
|
local event = require 'utils.event'
|
||||||
|
|
||||||
comfy_panel_tabs = {}
|
comfy_panel_tabs = {}
|
||||||
|
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
function Public.get_tabs(data)
|
function Public.get_tabs(data)
|
||||||
return comfy_panel_tabs
|
return comfy_panel_tabs
|
||||||
end
|
end
|
||||||
|
|
||||||
function Public.comfy_panel_clear_left_gui(player)
|
function Public.comfy_panel_clear_left_gui(player)
|
||||||
for _, child in pairs(player.gui.left.children) do
|
for _, child in pairs(player.gui.left.children) do
|
||||||
child.visible = false
|
child.destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Public.comfy_panel_restore_left_gui(player)
|
function Public.comfy_panel_restore_left_gui(player)
|
||||||
for _, child in pairs(player.gui.left.children) do
|
for _, child in pairs(player.gui.left.children) do
|
||||||
child.visible = true
|
child.visible = true
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function Public.comfy_panel_get_active_frame(player)
|
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 then
|
||||||
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 false
|
||||||
return player.gui.left.comfy_panel.tabbed_pane.tabs[player.gui.left.comfy_panel.tabbed_pane.selected_tab_index].content
|
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
|
end
|
||||||
|
|
||||||
function Public.comfy_panel_refresh_active_tab(player)
|
function Public.comfy_panel_refresh_active_tab(player)
|
||||||
local frame = Public.comfy_panel_get_active_frame(player)
|
local frame = Public.comfy_panel_get_active_frame(player)
|
||||||
if not frame then return end
|
if not frame then
|
||||||
comfy_panel_tabs[frame.name].gui(player, frame)
|
return
|
||||||
|
end
|
||||||
|
comfy_panel_tabs[frame.name].gui(player, frame)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function top_button(player)
|
local function top_button(player)
|
||||||
if player.gui.top["comfy_panel_top_button"] then return end
|
if player.gui.top['comfy_panel_top_button'] then
|
||||||
local button = player.gui.top.add({type = "sprite-button", name = "comfy_panel_top_button", sprite = "item/raw-fish"})
|
return
|
||||||
button.style.minimal_height = 38
|
end
|
||||||
button.style.minimal_width = 38
|
local button =
|
||||||
button.style.padding = -2
|
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
|
end
|
||||||
|
|
||||||
local function main_frame(player)
|
local function main_frame(player)
|
||||||
local tabs = comfy_panel_tabs
|
local tabs = comfy_panel_tabs
|
||||||
Public.comfy_panel_clear_left_gui(player)
|
Public.comfy_panel_clear_left_gui(player)
|
||||||
|
|
||||||
local frame = player.gui.left.add({type = "frame", name = "comfy_panel"})
|
local frame = player.gui.left.add({type = 'frame', name = 'comfy_panel'})
|
||||||
frame.style.margin = 6
|
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
|
for name, func in pairs(tabs) do
|
||||||
if func.admin == true then
|
if func.admin == true then
|
||||||
if player.admin then
|
if player.admin then
|
||||||
local tab = tabbed_pane.add({type = "tab", caption = name})
|
local tab = tabbed_pane.add({type = 'tab', caption = name})
|
||||||
local frame = tabbed_pane.add({type = "frame", name = name, direction = "vertical"})
|
local frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
|
||||||
frame.style.minimal_height = 480
|
frame.style.minimal_height = 480
|
||||||
frame.style.maximal_height = 480
|
frame.style.maximal_height = 480
|
||||||
frame.style.minimal_width = 800
|
frame.style.minimal_width = 800
|
||||||
frame.style.maximal_width = 800
|
frame.style.maximal_width = 800
|
||||||
tabbed_pane.add_tab(tab, frame)
|
tabbed_pane.add_tab(tab, frame)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local tab = tabbed_pane.add({type = "tab", caption = name})
|
local tab = tabbed_pane.add({type = 'tab', caption = name})
|
||||||
local frame = tabbed_pane.add({type = "frame", name = name, direction = "vertical"})
|
local frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
|
||||||
frame.style.minimal_height = 480
|
frame.style.minimal_height = 480
|
||||||
frame.style.maximal_height = 480
|
frame.style.maximal_height = 480
|
||||||
frame.style.minimal_width = 800
|
frame.style.minimal_width = 800
|
||||||
frame.style.maximal_width = 800
|
frame.style.maximal_width = 800
|
||||||
tabbed_pane.add_tab(tab, frame)
|
tabbed_pane.add_tab(tab, frame)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local tab = tabbed_pane.add({type = "tab", name = "comfy_panel_close", caption = "X"})
|
local tab = tabbed_pane.add({type = 'tab', name = 'comfy_panel_close', caption = 'X'})
|
||||||
tab.style.maximal_width = 32
|
tab.style.maximal_width = 32
|
||||||
local frame = tabbed_pane.add({type = "frame", name = name, direction = "vertical"})
|
local frame = tabbed_pane.add({type = 'frame', name = name, direction = 'vertical'})
|
||||||
tabbed_pane.add_tab(tab, frame)
|
tabbed_pane.add_tab(tab, frame)
|
||||||
|
|
||||||
for _, child in pairs(tabbed_pane.children) do
|
for _, child in pairs(tabbed_pane.children) do
|
||||||
child.style.padding = 8
|
child.style.padding = 8
|
||||||
child.style.left_padding = 2
|
child.style.left_padding = 2
|
||||||
child.style.right_padding = 2
|
child.style.right_padding = 2
|
||||||
end
|
end
|
||||||
|
|
||||||
Public.comfy_panel_refresh_active_tab(player)
|
Public.comfy_panel_refresh_active_tab(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Public.comfy_panel_call_tab(player, name)
|
function Public.comfy_panel_call_tab(player, name)
|
||||||
main_frame(player)
|
main_frame(player)
|
||||||
local tabbed_pane = player.gui.left.comfy_panel.tabbed_pane
|
local tabbed_pane = player.gui.left.comfy_panel.tabbed_pane
|
||||||
for key, v in pairs(tabbed_pane.tabs) do
|
for key, v in pairs(tabbed_pane.tabs) do
|
||||||
if v.tab.caption == name then
|
if v.tab.caption == name then
|
||||||
tabbed_pane.selected_tab_index = key
|
tabbed_pane.selected_tab_index = key
|
||||||
Public.comfy_panel_refresh_active_tab(player)
|
Public.comfy_panel_refresh_active_tab(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_player_joined_game(event)
|
local function on_player_joined_game(event)
|
||||||
top_button(game.players[event.player_index])
|
top_button(game.players[event.player_index])
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_gui_click(event)
|
local function on_gui_click(event)
|
||||||
if not event.element then return end
|
if not event.element then
|
||||||
if not event.element.valid then return end
|
return
|
||||||
local player = game.players[event.player_index]
|
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 event.element.name == 'comfy_panel_top_button' then
|
||||||
if player.gui.left.comfy_panel then
|
if player.gui.left.comfy_panel then
|
||||||
player.gui.left.comfy_panel.destroy()
|
player.gui.left.comfy_panel.destroy()
|
||||||
Public.comfy_panel_restore_left_gui(player)
|
return
|
||||||
return
|
else
|
||||||
else
|
Public.comfy_panel_clear_screen_gui(player)
|
||||||
main_frame(player)
|
main_frame(player)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.element.caption == "X" and event.element.name == "comfy_panel_close" then
|
if event.element.caption == 'X' and event.element.name == 'comfy_panel_close' then
|
||||||
player.gui.left.comfy_panel.destroy()
|
player.gui.left.comfy_panel.destroy()
|
||||||
Public.comfy_panel_restore_left_gui(player)
|
return
|
||||||
return
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if not event.element.caption then return end
|
if not event.element.caption then
|
||||||
if event.element.type ~= "tab" then return end
|
return
|
||||||
Public.comfy_panel_refresh_active_tab(player)
|
end
|
||||||
|
if event.element.type ~= 'tab' then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
Public.comfy_panel_refresh_active_tab(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||||
|
@@ -127,7 +127,7 @@ local function hide_rpg(player, show)
|
|||||||
local rpg_settings = RPG_T.settings_frame_name
|
local rpg_settings = RPG_T.settings_frame_name
|
||||||
|
|
||||||
local rpg_b = player.gui.top[rpg_button]
|
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 rpg_s = player.gui.screen[rpg_settings]
|
||||||
|
|
||||||
if show then
|
if show then
|
||||||
|
@@ -214,7 +214,7 @@ local function on_player_changed_surface(event)
|
|||||||
local info = player.gui.top[main_button_name]
|
local info = player.gui.top[main_button_name]
|
||||||
local wd = player.gui.top['wave_defense']
|
local wd = player.gui.top['wave_defense']
|
||||||
local rpg_b = player.gui.top[rpg_button]
|
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 rpg_s = player.gui.screen[rpg_settings]
|
||||||
local diff = player.gui.top['difficulty_gui']
|
local diff = player.gui.top['difficulty_gui']
|
||||||
local charging = player.gui.top['charging_station']
|
local charging = player.gui.top['charging_station']
|
||||||
|
@@ -560,7 +560,8 @@ function Public.validate_owner(ic, player, entity)
|
|||||||
local p = game.players[car.owner]
|
local p = game.players[car.owner]
|
||||||
if p then
|
if p then
|
||||||
if car.owner ~= player.index and player.driving 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
|
end
|
||||||
end
|
end
|
||||||
|
@@ -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_t[player.index].points_to_distribute = rpg_t[player.index].points_to_distribute + distribute_points_gain
|
||||||
RPG_GUI.update_char_button(player)
|
RPG_GUI.update_char_button(player)
|
||||||
table.shuffle_table(rpg_frame_icons)
|
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)
|
RPG_GUI.toggle(player, true)
|
||||||
end
|
end
|
||||||
Public.level_up_effects(player)
|
Public.level_up_effects(player)
|
||||||
@@ -225,8 +225,8 @@ function Public.update_mana(player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if player.gui.left[main_frame_name] then
|
if player.gui.screen[main_frame_name] then
|
||||||
local f = player.gui.left[main_frame_name]
|
local f = player.gui.screen[main_frame_name]
|
||||||
local data = Gui.get_data(f)
|
local data = Gui.get_data(f)
|
||||||
if data.mana and data.mana.valid then
|
if data.mana and data.mana.valid then
|
||||||
data.mana.caption = rpg_t[player.index].mana
|
data.mana.caption = rpg_t[player.index].mana
|
||||||
@@ -271,8 +271,8 @@ function Public.reward_mana(player, mana_to_add)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if player.gui.left[main_frame_name] then
|
if player.gui.screen[main_frame_name] then
|
||||||
local f = player.gui.left[main_frame_name]
|
local f = player.gui.screen[main_frame_name]
|
||||||
local data = Gui.get_data(f)
|
local data = Gui.get_data(f)
|
||||||
if data.mana and data.mana.valid then
|
if data.mana and data.mana.valid then
|
||||||
data.mana.caption = rpg_t[player.index].mana
|
data.mana.caption = rpg_t[player.index].mana
|
||||||
@@ -306,8 +306,8 @@ function Public.update_health(player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if player.gui.left[main_frame_name] then
|
if player.gui.screen[main_frame_name] then
|
||||||
local f = player.gui.left[main_frame_name]
|
local f = player.gui.screen[main_frame_name]
|
||||||
local data = Gui.get_data(f)
|
local data = Gui.get_data(f)
|
||||||
if data.health and data.health.valid then
|
if data.health and data.health.valid then
|
||||||
data.health.caption = (math.round(player.character.health * 10) / 10)
|
data.health.caption = (math.round(player.character.health * 10) / 10)
|
||||||
|
@@ -169,7 +169,7 @@ local function draw_main_frame(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local main_frame =
|
local main_frame =
|
||||||
player.gui.left.add(
|
player.gui.screen.add(
|
||||||
{
|
{
|
||||||
type = 'frame',
|
type = 'frame',
|
||||||
name = main_frame_name,
|
name = main_frame_name,
|
||||||
@@ -177,6 +177,7 @@ local function draw_main_frame(player)
|
|||||||
direction = 'vertical'
|
direction = 'vertical'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
main_frame.location = {x = 1, y = 40}
|
||||||
|
|
||||||
local data = {}
|
local data = {}
|
||||||
local rpg_extra = RPG.get('rpg_extra')
|
local rpg_extra = RPG.get('rpg_extra')
|
||||||
@@ -533,9 +534,8 @@ function Public.update_player_stats(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Public.toggle(player, recreate)
|
function Public.toggle(player, recreate)
|
||||||
local left = player.gui.left
|
|
||||||
local screen = player.gui.screen
|
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
|
if recreate and main_frame then
|
||||||
remove_main_frame(main_frame, screen)
|
remove_main_frame(main_frame, screen)
|
||||||
@@ -672,7 +672,7 @@ Gui.on_click(
|
|||||||
|
|
||||||
remove_settings_frame(event.element)
|
remove_settings_frame(event.element)
|
||||||
|
|
||||||
if player.gui.left[main_frame_name] then
|
if player.gui.screen[main_frame_name] then
|
||||||
toggle(player, true)
|
toggle(player, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -370,8 +370,8 @@ local function give_player_flameboots(player)
|
|||||||
if rpg_t[player.index].mana <= 0 then
|
if rpg_t[player.index].mana <= 0 then
|
||||||
rpg_t[player.index].mana = 0
|
rpg_t[player.index].mana = 0
|
||||||
end
|
end
|
||||||
if player.gui.left[main_frame_name] then
|
if player.gui.screen[main_frame_name] then
|
||||||
local f = player.gui.left[main_frame_name]
|
local f = player.gui.screen[main_frame_name]
|
||||||
local data = Gui.get_data(f)
|
local data = Gui.get_data(f)
|
||||||
if data.mana and data.mana.valid then
|
if data.mana and data.mana.valid then
|
||||||
data.mana.caption = rpg_t[player.index].mana
|
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
|
xp_amount = (1.5 + event.entity.prototype.max_health * 0.0035) * distance_multiplier
|
||||||
end
|
end
|
||||||
|
|
||||||
if player.gui.left[main_frame_name] then
|
if player.gui.screen[main_frame_name] then
|
||||||
local f = player.gui.left[main_frame_name]
|
local f = player.gui.screen[main_frame_name]
|
||||||
local data = Gui.get_data(f)
|
local data = Gui.get_data(f)
|
||||||
if data.exp_gui and data.exp_gui.valid then
|
if data.exp_gui and data.exp_gui.valid then
|
||||||
data.exp_gui.caption = math.floor(rpg_t[player.index].xp)
|
data.exp_gui.caption = math.floor(rpg_t[player.index].xp)
|
||||||
|
Reference in New Issue
Block a user