You've already forked ComfyFactorio
mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-11-25 22:32:18 +02:00
Tweaks
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
--require "modules.rpg"
|
--require "modules.rpg"
|
||||||
|
|
||||||
local Public = require 'maps.fish_defender_v2.core'
|
local Public = require 'maps.fish_defender_v2.core'
|
||||||
|
local Gui = require 'utils.gui'
|
||||||
require 'modules.rocket_launch_always_yields_science'
|
require 'modules.rocket_launch_always_yields_science'
|
||||||
require 'modules.launch_fish_to_win'
|
require 'modules.launch_fish_to_win'
|
||||||
require 'modules.biters_yield_coins'
|
require 'modules.biters_yield_coins'
|
||||||
@@ -23,6 +24,9 @@ local random = math.random
|
|||||||
local insert = table.insert
|
local insert = table.insert
|
||||||
local enable_start_grace_period = true
|
local enable_start_grace_period = true
|
||||||
|
|
||||||
|
Gui.mod_gui_button_enabled = true
|
||||||
|
Gui.button_style = 'mod_gui_button'
|
||||||
|
|
||||||
local starting_items = {
|
local starting_items = {
|
||||||
['pistol'] = 1,
|
['pistol'] = 1,
|
||||||
['firearm-magazine'] = 20,
|
['firearm-magazine'] = 20,
|
||||||
@@ -103,7 +107,8 @@ local function create_wave_gui(player)
|
|||||||
if player.gui.top['fish_defense_waves'] then
|
if player.gui.top['fish_defense_waves'] then
|
||||||
player.gui.top['fish_defense_waves'].destroy()
|
player.gui.top['fish_defense_waves'].destroy()
|
||||||
end
|
end
|
||||||
local frame = player.gui.top.add({type = 'frame', name = 'fish_defense_waves'})
|
local frame = player.gui.top.add({type = 'frame', name = 'fish_defense_waves', style = 'finished_game_subheader_frame'})
|
||||||
|
frame.style.minimal_height = 38
|
||||||
frame.style.maximal_height = 38
|
frame.style.maximal_height = 38
|
||||||
|
|
||||||
local wave_count = 0
|
local wave_count = 0
|
||||||
@@ -215,7 +220,8 @@ local function add_fd_stats_button(player)
|
|||||||
player.gui.top.add {
|
player.gui.top.add {
|
||||||
type = 'sprite-button',
|
type = 'sprite-button',
|
||||||
name = button_id,
|
name = button_id,
|
||||||
sprite = 'item/submachine-gun'
|
sprite = 'item/submachine-gun',
|
||||||
|
style = Gui.button_style
|
||||||
}
|
}
|
||||||
b.style.maximal_height = 38
|
b.style.maximal_height = 38
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -120,9 +120,6 @@ local function get_sorted_list(column_name, score_list)
|
|||||||
for key, player in ipairs(score_list) do
|
for key, player in ipairs(score_list) do
|
||||||
sl[key] = player
|
sl[key] = player
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if i == 20 then
|
|
||||||
return sl
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return sl
|
return sl
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
-- launch fish into space to win the game -- by mewmew
|
-- launch fish into space to win the game -- by mewmew
|
||||||
|
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
|
local Gui = require 'utils.gui'
|
||||||
|
|
||||||
local function goals()
|
local function goals()
|
||||||
if not global.catplanet_goals then
|
if not global.catplanet_goals then
|
||||||
@@ -98,14 +99,9 @@ local function fish_in_space_toggle_button(player)
|
|||||||
if player.gui.top['fish_in_space_toggle'] then
|
if player.gui.top['fish_in_space_toggle'] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local button = player.gui.top.add {name = 'fish_in_space_toggle', type = 'sprite-button', sprite = 'item/raw-fish', tooltip = 'Fish in Space'}
|
local button = player.gui.top.add {name = 'fish_in_space_toggle', type = 'sprite-button', sprite = 'item/raw-fish', tooltip = 'Fish in Space', style = Gui.button_style}
|
||||||
button.style.font = 'default-bold'
|
|
||||||
button.style.minimal_height = 38
|
button.style.minimal_height = 38
|
||||||
button.style.minimal_width = 38
|
button.style.maximal_height = 38
|
||||||
button.style.top_padding = 2
|
|
||||||
button.style.left_padding = 4
|
|
||||||
button.style.right_padding = 4
|
|
||||||
button.style.bottom_padding = 2
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function level_up_popup(player)
|
local function level_up_popup(player)
|
||||||
@@ -138,6 +134,7 @@ local function fish_in_space_gui(player)
|
|||||||
local frame = player.gui.left.add({type = 'frame', name = 'fish_in_space'})
|
local frame = player.gui.left.add({type = 'frame', name = 'fish_in_space'})
|
||||||
local label = frame.add({type = 'label', caption = 'Fish rescued: '})
|
local label = frame.add({type = 'label', caption = 'Fish rescued: '})
|
||||||
label.style.font_color = {r = 0.11, g = 0.8, b = 0.44}
|
label.style.font_color = {r = 0.11, g = 0.8, b = 0.44}
|
||||||
|
frame.style.bottom_padding = -2
|
||||||
|
|
||||||
local progress = global.fish_in_space / global.catplanet_goals[i + 1].goal
|
local progress = global.fish_in_space / global.catplanet_goals[i + 1].goal
|
||||||
if progress > 1 then
|
if progress > 1 then
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ local Global = require 'utils.global'
|
|||||||
local Color = require 'utils.color_presets'
|
local Color = require 'utils.color_presets'
|
||||||
local SpamProtection = require 'utils.spam_protection'
|
local SpamProtection = require 'utils.spam_protection'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
|
local Gui = require 'utils.gui'
|
||||||
|
|
||||||
local this = {
|
local this = {
|
||||||
data = {},
|
data = {},
|
||||||
@@ -18,6 +19,8 @@ Global.register(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
local main_frame_name = Gui.uid_name()
|
||||||
|
|
||||||
local space = {
|
local space = {
|
||||||
minimal_height = 10,
|
minimal_height = 10,
|
||||||
top_padding = 0,
|
top_padding = 0,
|
||||||
@@ -143,7 +146,7 @@ local function close_player_inventory(player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local element = gui.inventory_gui
|
local element = gui[main_frame_name]
|
||||||
|
|
||||||
if not is_valid(element) then
|
if not is_valid(element) then
|
||||||
return
|
return
|
||||||
@@ -186,7 +189,7 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local inventory_gui = screen.inventory_gui
|
local inventory_gui = screen[main_frame_name]
|
||||||
inventory_gui.caption = 'Inventory of ' .. target.name
|
inventory_gui.caption = 'Inventory of ' .. target.name
|
||||||
|
|
||||||
for i = 1, #panel_type do
|
for i = 1, #panel_type do
|
||||||
@@ -271,7 +274,7 @@ local function open_inventory(source, target)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local inventory_gui = screen.inventory_gui
|
local inventory_gui = screen[main_frame_name]
|
||||||
if inventory_gui then
|
if inventory_gui then
|
||||||
close_player_inventory(source)
|
close_player_inventory(source)
|
||||||
end
|
end
|
||||||
@@ -282,7 +285,7 @@ local function open_inventory(source, target)
|
|||||||
type = 'frame',
|
type = 'frame',
|
||||||
caption = 'Inventory',
|
caption = 'Inventory',
|
||||||
direction = 'vertical',
|
direction = 'vertical',
|
||||||
name = 'inventory_gui'
|
name = main_frame_name
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -383,22 +386,6 @@ local function on_gui_click(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function gui_closed(event)
|
|
||||||
local player = game.get_player(event.player_index)
|
|
||||||
if not this.data[player.index] then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local type = event.gui_type
|
|
||||||
|
|
||||||
if type == defines.gui_type.custom then
|
|
||||||
local data = get_player_data(player)
|
|
||||||
if not data then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
close_player_inventory(player)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_pre_player_left_game(event)
|
local function on_pre_player_left_game(event)
|
||||||
local player = game.get_player(event.player_index)
|
local player = game.get_player(event.player_index)
|
||||||
@@ -466,11 +453,36 @@ commands.add_command(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
function Public.get_active_frame(player)
|
function Public.show_inventory(player, target_player)
|
||||||
if not player.gui.screen.inventory_gui then
|
if not player or not player.valid then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return player.gui.screen.inventory_gui.tabbed_pane.tabs[player.gui.screen.inventory_gui.tabbed_pane.selected_tab_index].content
|
if not target_player or not target_player.valid then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local valid, opened = player_opened(player)
|
||||||
|
if valid then
|
||||||
|
if target_player.index == opened then
|
||||||
|
player.print('You are already viewing this players inventory.', Color.warning)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if validate_player(target_player) then
|
||||||
|
open_inventory(player, target_player)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
player.print('[Inventory] Please type a name of a player who is connected.', Color.warning)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Public.get_active_frame(player)
|
||||||
|
if not player.gui.screen[main_frame_name] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return player.gui.screen[main_frame_name].tabbed_pane.tabs[player.gui.screen[main_frame_name].tabbed_pane.selected_tab_index].content
|
||||||
end
|
end
|
||||||
|
|
||||||
function Public.get(key)
|
function Public.get(key)
|
||||||
@@ -487,13 +499,26 @@ function Public.module_disabled(state)
|
|||||||
this.module_disabled = state or false
|
this.module_disabled = state or false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Gui.on_custom_close(
|
||||||
|
main_frame_name,
|
||||||
|
function(event)
|
||||||
|
local player = game.get_player(event.player_index)
|
||||||
|
if not this.data[player.index] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
close_player_inventory(player)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
Event.add(defines.events.on_player_main_inventory_changed, update_gui)
|
Event.add(defines.events.on_player_main_inventory_changed, update_gui)
|
||||||
Event.add(defines.events.on_player_gun_inventory_changed, update_gui)
|
Event.add(defines.events.on_player_gun_inventory_changed, update_gui)
|
||||||
Event.add(defines.events.on_player_ammo_inventory_changed, update_gui)
|
Event.add(defines.events.on_player_ammo_inventory_changed, update_gui)
|
||||||
Event.add(defines.events.on_player_armor_inventory_changed, update_gui)
|
Event.add(defines.events.on_player_armor_inventory_changed, update_gui)
|
||||||
Event.add(defines.events.on_player_trash_inventory_changed, update_gui)
|
Event.add(defines.events.on_player_trash_inventory_changed, update_gui)
|
||||||
Event.add(defines.events.on_gui_closed, gui_closed)
|
|
||||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||||
Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)
|
Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)
|
||||||
|
|
||||||
|
Public.close_player_inventory = close_player_inventory
|
||||||
|
|
||||||
return Public
|
return Public
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ local function create_mini_camera_gui(player, target, zoom, render, tooltip)
|
|||||||
end
|
end
|
||||||
local player_data
|
local player_data
|
||||||
|
|
||||||
if validate_player(target) then
|
if validate_player(target) or (target and target.valid and player.admin) then
|
||||||
player_data = create_player_data(player)
|
player_data = create_player_data(player)
|
||||||
player_data.target = target
|
player_data.target = target
|
||||||
else
|
else
|
||||||
@@ -107,6 +107,8 @@ local function create_mini_camera_gui(player, target, zoom, render, tooltip)
|
|||||||
frame = player.gui.screen.add({type = 'frame', name = locate_player_frame_name, caption = target.name})
|
frame = player.gui.screen.add({type = 'frame', name = locate_player_frame_name, caption = target.name})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
player.opened = frame
|
||||||
|
|
||||||
frame.force_auto_center()
|
frame.force_auto_center()
|
||||||
|
|
||||||
local surface = tonumber(target.surface.index)
|
local surface = tonumber(target.surface.index)
|
||||||
@@ -219,6 +221,17 @@ Gui.on_click(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Gui.on_custom_close(
|
||||||
|
locate_player_frame_name,
|
||||||
|
function(event)
|
||||||
|
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Where Locate Player')
|
||||||
|
if is_spamming then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
remove_camera_frame(event.player)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
Gui.on_click(
|
Gui.on_click(
|
||||||
player_frame_name,
|
player_frame_name,
|
||||||
function(event)
|
function(event)
|
||||||
@@ -226,7 +239,10 @@ Gui.on_click(
|
|||||||
if is_spamming then
|
if is_spamming then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
remove_camera_frame(event.player)
|
local type = event.gui_type
|
||||||
|
if type == defines.gui_type.custom then
|
||||||
|
remove_camera_frame(event.player)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
211
utils/gui.lua
211
utils/gui.lua
@@ -138,6 +138,57 @@ function Public.set_data_parent(parent, element, value)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Associates data with the LuaGuiElement along with the tag. If data is nil then removes the data
|
||||||
|
function Public.set_data_custom(tag, element, value)
|
||||||
|
if not tag then
|
||||||
|
return error('A tag is required', 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local player_index = element.player_index
|
||||||
|
local values = data[player_index]
|
||||||
|
|
||||||
|
if value == nil then
|
||||||
|
if not values then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local tags = values[tag]
|
||||||
|
if not tags then
|
||||||
|
if next(values) == nil then
|
||||||
|
data[player_index] = nil
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if element.remove then
|
||||||
|
values[tag] = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
tags[element.index] = nil
|
||||||
|
|
||||||
|
if next(tags) == nil then
|
||||||
|
values[tag] = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if not values then
|
||||||
|
values = {
|
||||||
|
[tag] = {}
|
||||||
|
}
|
||||||
|
data[player_index] = values
|
||||||
|
end
|
||||||
|
|
||||||
|
local tags = values[tag]
|
||||||
|
|
||||||
|
if not tags then
|
||||||
|
values[tag] = {}
|
||||||
|
tags = values[tag]
|
||||||
|
end
|
||||||
|
|
||||||
|
tags[element.index] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Gets the Associated data with this LuaGuiElement if any.
|
-- Gets the Associated data with this LuaGuiElement if any.
|
||||||
function Public.get_data(element)
|
function Public.get_data(element)
|
||||||
if not element then
|
if not element then
|
||||||
@@ -178,6 +229,30 @@ function Public.get_data_parent(parent, element)
|
|||||||
return values[element.index]
|
return values[element.index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Gets the Associated data with this LuaGuiElement if any.
|
||||||
|
function Public.get_data_custom(tag, element)
|
||||||
|
if not tag then
|
||||||
|
return error('A tag is required', 2)
|
||||||
|
end
|
||||||
|
if not element then
|
||||||
|
return error('An element is required', 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local player_index = element.player_index
|
||||||
|
|
||||||
|
local values = data[player_index]
|
||||||
|
if not values then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
values = values[tag]
|
||||||
|
if not values then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return values[element.index]
|
||||||
|
end
|
||||||
|
|
||||||
-- Adds a gui that is alike the factorio native gui.
|
-- Adds a gui that is alike the factorio native gui.
|
||||||
function Public.add_main_frame_with_toolbar(player, align, set_frame_name, set_settings_button_name, close_main_frame_name, name, info, inside_table_count)
|
function Public.add_main_frame_with_toolbar(player, align, set_frame_name, set_settings_button_name, close_main_frame_name, name, info, inside_table_count)
|
||||||
if not align then
|
if not align then
|
||||||
@@ -738,6 +813,7 @@ function Public.refresh(player)
|
|||||||
for _, tab in pairs(tabbed_pane.tabs) do
|
for _, tab in pairs(tabbed_pane.tabs) do
|
||||||
if tab.content.name ~= frame.name then
|
if tab.content.name ~= frame.name then
|
||||||
tab.content.clear()
|
tab.content.clear()
|
||||||
|
Event.raise(Public.events.on_gui_removal, {player_index = player.index})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -763,6 +839,9 @@ function Public.call_existing_tab(player, name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Public.get_button_flow = mod_gui.get_button_flow
|
||||||
|
Public.mod_button = mod_gui.get_button_flow
|
||||||
|
|
||||||
-- Register a handler for the on_gui_checked_state_changed event for LuaGuiElements with element_name.
|
-- Register a handler for the on_gui_checked_state_changed event for LuaGuiElements with element_name.
|
||||||
-- Can only have one handler per element name.
|
-- Can only have one handler per element name.
|
||||||
-- Guarantees that the element and the player are valid when calling the handler.
|
-- Guarantees that the element and the player are valid when calling the handler.
|
||||||
@@ -819,66 +898,6 @@ Public.on_player_show_top = custom_handler_factory(on_visible_handlers)
|
|||||||
-- Adds a player field to the event table.
|
-- Adds a player field to the event table.
|
||||||
Public.on_pre_player_hide_top = custom_handler_factory(on_pre_hidden_handlers)
|
Public.on_pre_player_hide_top = custom_handler_factory(on_pre_hidden_handlers)
|
||||||
|
|
||||||
if _DEBUG then
|
|
||||||
local concat = table.concat
|
|
||||||
|
|
||||||
local names = {}
|
|
||||||
Public.names = names
|
|
||||||
|
|
||||||
function Public.uid_name()
|
|
||||||
local info = debug.getinfo(2, 'Sl')
|
|
||||||
local filepath = info.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5)
|
|
||||||
local line = info.currentline
|
|
||||||
|
|
||||||
local token = tostring(Token.uid())
|
|
||||||
|
|
||||||
local name = concat {token, ' - ', filepath, ':line:', line}
|
|
||||||
names[token] = name
|
|
||||||
|
|
||||||
return token
|
|
||||||
end
|
|
||||||
|
|
||||||
function Public.set_data(element, value)
|
|
||||||
local player_index = element.player_index
|
|
||||||
local values = data[player_index]
|
|
||||||
|
|
||||||
if value == nil then
|
|
||||||
if not values then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local index = element.index
|
|
||||||
values[index] = nil
|
|
||||||
element_map[index] = nil
|
|
||||||
|
|
||||||
if next(values) == nil then
|
|
||||||
data[player_index] = nil
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if not values then
|
|
||||||
values = {}
|
|
||||||
data[player_index] = values
|
|
||||||
end
|
|
||||||
|
|
||||||
local index = element.index
|
|
||||||
values[index] = value
|
|
||||||
element_map[index] = element
|
|
||||||
end
|
|
||||||
end
|
|
||||||
set_data = Public.set_data
|
|
||||||
|
|
||||||
function Public.data()
|
|
||||||
return data
|
|
||||||
end
|
|
||||||
|
|
||||||
function Public.element_map()
|
|
||||||
return element_map
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Public.get_button_flow = mod_gui.get_button_flow
|
|
||||||
Public.mod_button = mod_gui.get_button_flow
|
|
||||||
|
|
||||||
Public.on_click(
|
Public.on_click(
|
||||||
main_button_name,
|
main_button_name,
|
||||||
function(event)
|
function(event)
|
||||||
@@ -891,6 +910,7 @@ Public.on_click(
|
|||||||
if frame then
|
if frame then
|
||||||
remove_data_recursively(frame)
|
remove_data_recursively(frame)
|
||||||
frame.destroy()
|
frame.destroy()
|
||||||
|
Event.raise(Public.events.on_gui_removal, {player_index = player.index})
|
||||||
else
|
else
|
||||||
draw_main_frame(player)
|
draw_main_frame(player)
|
||||||
end
|
end
|
||||||
@@ -963,22 +983,61 @@ Event.add(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
if _DEBUG then
|
||||||
Public.events.on_gui_removal,
|
local concat = table.concat
|
||||||
function(player)
|
|
||||||
local b =
|
local names = {}
|
||||||
Public.get_button_flow(player).add(
|
Public.names = names
|
||||||
{
|
|
||||||
type = 'sprite-button',
|
function Public.uid_name()
|
||||||
name = main_button_name,
|
local info = debug.getinfo(2, 'Sl')
|
||||||
sprite = 'utility/expand_dots',
|
local filepath = info.source:match('^.+/currently%-playing/(.+)$'):sub(1, -5)
|
||||||
style = Public.button_style,
|
local line = info.currentline
|
||||||
tooltip = 'The panel of all the goodies!'
|
|
||||||
}
|
local token = tostring(Token.uid())
|
||||||
)
|
|
||||||
b.style.padding = 2
|
local name = concat {token, ' - ', filepath, ':line:', line}
|
||||||
b.style.width = 20
|
names[token] = name
|
||||||
|
|
||||||
|
return token
|
||||||
end
|
end
|
||||||
)
|
|
||||||
|
function Public.set_data(element, value)
|
||||||
|
local player_index = element.player_index
|
||||||
|
local values = data[player_index]
|
||||||
|
|
||||||
|
if value == nil then
|
||||||
|
if not values then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local index = element.index
|
||||||
|
values[index] = nil
|
||||||
|
element_map[index] = nil
|
||||||
|
|
||||||
|
if next(values) == nil then
|
||||||
|
data[player_index] = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if not values then
|
||||||
|
values = {}
|
||||||
|
data[player_index] = values
|
||||||
|
end
|
||||||
|
|
||||||
|
local index = element.index
|
||||||
|
values[index] = value
|
||||||
|
element_map[index] = element
|
||||||
|
end
|
||||||
|
end
|
||||||
|
set_data = Public.set_data
|
||||||
|
|
||||||
|
function Public.data()
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
function Public.element_map()
|
||||||
|
return element_map
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return Public
|
return Public
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ local Token = require 'utils.token'
|
|||||||
local Vars = require 'utils.player_list_vars'
|
local Vars = require 'utils.player_list_vars'
|
||||||
local Utils = require 'utils.utils'
|
local Utils = require 'utils.utils'
|
||||||
local Core = require 'utils.core'
|
local Core = require 'utils.core'
|
||||||
|
local Inventory = require 'modules.show_inventory'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ local ranks = Vars.ranks
|
|||||||
local pokemessages = Vars.pokemessages
|
local pokemessages = Vars.pokemessages
|
||||||
local get_formatted_playtime = Utils.get_formatted_playtime
|
local get_formatted_playtime = Utils.get_formatted_playtime
|
||||||
local get_comparator = Vars.get_comparator
|
local get_comparator = Vars.get_comparator
|
||||||
|
local tag = 'Players'
|
||||||
|
|
||||||
local this = {
|
local this = {
|
||||||
player_list = {
|
player_list = {
|
||||||
@@ -248,23 +250,35 @@ Gui.on_click(
|
|||||||
local player = event.player
|
local player = event.player
|
||||||
local element = event.element
|
local element = event.element
|
||||||
|
|
||||||
local data = Gui.get_data(element)
|
local button = event.button
|
||||||
|
local data = Gui.get_data_custom(tag, element)
|
||||||
if not data then
|
if not data then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Locate Player')
|
if button == defines.mouse_button_type.left then
|
||||||
if is_spamming then
|
local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Locate Player')
|
||||||
return
|
if is_spamming then
|
||||||
end
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local target = game.get_player(data)
|
local target = game.get_player(data)
|
||||||
if not target or not target.valid then
|
if not target or not target.valid then
|
||||||
Gui.set_data(element, nil)
|
return
|
||||||
return
|
end
|
||||||
|
Where.create_mini_camera_gui(player, target)
|
||||||
|
elseif defines.mouse_button_type.right then
|
||||||
|
local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Show Inventory')
|
||||||
|
if is_spamming then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local target = game.get_player(data)
|
||||||
|
if not target or not target.valid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
Inventory.show_inventory(player, target)
|
||||||
end
|
end
|
||||||
Gui.set_data(element, nil)
|
|
||||||
Where.create_mini_camera_gui(player, target)
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -274,14 +288,13 @@ Gui.on_click(
|
|||||||
local player = event.player
|
local player = event.player
|
||||||
local element = event.element
|
local element = event.element
|
||||||
|
|
||||||
local data = Gui.get_data(element)
|
local data = Gui.get_data_custom(tag, element)
|
||||||
if not data then
|
if not data then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local target = game.get_player(data)
|
local target = game.get_player(data)
|
||||||
|
|
||||||
if player.index == target.index then
|
if player.index == target.index then
|
||||||
Gui.set_data(element, nil)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -297,7 +310,6 @@ Gui.on_click(
|
|||||||
game.print(str)
|
game.print(str)
|
||||||
this.player_list.last_poke_tick[player.index] = game.tick
|
this.player_list.last_poke_tick[player.index] = game.tick
|
||||||
this.player_list.pokes[target.index] = this.player_list.pokes[target.index] + 1
|
this.player_list.pokes[target.index] = this.player_list.pokes[target.index] + 1
|
||||||
Gui.set_data(element, nil)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@@ -306,7 +318,7 @@ local function refresh()
|
|||||||
for _, player in pairs(game.connected_players) do
|
for _, player in pairs(game.connected_players) do
|
||||||
local frame = Gui.get_player_active_frame(player)
|
local frame = Gui.get_player_active_frame(player)
|
||||||
if frame then
|
if frame then
|
||||||
if frame.name ~= 'Players' then
|
if frame.name ~= tag then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local data = {player = player, frame = frame, sort_by = this.player_list.sorting_method[player.index]}
|
local data = {player = player, frame = frame, sort_by = this.player_list.sorting_method[player.index]}
|
||||||
@@ -342,12 +354,13 @@ function Public.rpg_enabled(value)
|
|||||||
return this.rpg_enabled
|
return this.rpg_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
Gui.add_tab_to_gui({name = module_name, caption = 'Players', id = player_list_show_token, admin = false})
|
Gui.add_tab_to_gui({name = module_name, caption = tag, id = player_list_show_token, admin = false})
|
||||||
|
|
||||||
Gui.on_click(
|
Gui.on_click(
|
||||||
module_name,
|
module_name,
|
||||||
function(event)
|
function(event)
|
||||||
local player = event.player
|
local player = event.player
|
||||||
|
Gui.set_data_custom(tag, {player_index = player.index, remove = true}, nil)
|
||||||
Gui.reload_active_tab(player)
|
Gui.reload_active_tab(player)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@@ -370,7 +383,7 @@ Gui.on_click(
|
|||||||
if not frame then
|
if not frame then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if frame.name ~= 'Players' then
|
if frame.name ~= tag then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -390,5 +403,11 @@ Gui.on_click(
|
|||||||
|
|
||||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||||
|
Event.add(
|
||||||
|
Gui.events.on_gui_removal,
|
||||||
|
function(event)
|
||||||
|
Gui.set_data_custom(tag, {player_index = event.player_index, remove = true}, nil)
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
return Public
|
return Public
|
||||||
|
|||||||
@@ -413,6 +413,8 @@ Public.gui_data = function(data)
|
|||||||
tooltip = 'This player is not trusted.' .. minimap .. tooltip
|
tooltip = 'This player is not trusted.' .. minimap .. tooltip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tooltip = tooltip .. '\nRight-click to view their inventory!'
|
||||||
|
|
||||||
local caption
|
local caption
|
||||||
if show_roles_in_list or player.admin then
|
if show_roles_in_list or player.admin then
|
||||||
caption = player.name .. ' ' .. trusted
|
caption = player.name .. ' ' .. trusted
|
||||||
@@ -435,7 +437,7 @@ Public.gui_data = function(data)
|
|||||||
tooltip = tooltip
|
tooltip = tooltip
|
||||||
}
|
}
|
||||||
|
|
||||||
Gui.set_data(name_label, player.index)
|
Gui.set_data_custom('Players', name_label, player.index)
|
||||||
|
|
||||||
name_label.style.font = 'default'
|
name_label.style.font = 'default'
|
||||||
name_label.style.font_color = {
|
name_label.style.font_color = {
|
||||||
@@ -589,7 +591,7 @@ Public.gui_data = function(data)
|
|||||||
poke_flow.style.right_padding = 20
|
poke_flow.style.right_padding = 20
|
||||||
local poke_label = poke_flow.add {type = 'label', name = 'button_spacer_' .. index, caption = ''}
|
local poke_label = poke_flow.add {type = 'label', name = 'button_spacer_' .. index, caption = ''}
|
||||||
local poke_button = poke_flow.add {type = 'button', name = poke_player_frame_name, caption = player.pokes}
|
local poke_button = poke_flow.add {type = 'button', name = poke_player_frame_name, caption = player.pokes}
|
||||||
Gui.set_data(poke_button, player.index)
|
Gui.set_data_custom('Players', poke_button, player.index)
|
||||||
poke_button.style.font = 'default'
|
poke_button.style.font = 'default'
|
||||||
poke_button.tooltip = 'Poke ' .. player.name .. ' with a random message!\nDoes not work poking yourself :<'
|
poke_button.tooltip = 'Poke ' .. player.name .. ' with a random message!\nDoes not work poking yourself :<'
|
||||||
poke_label.style.font_color = {r = 0.83, g = 0.83, b = 0.83}
|
poke_label.style.font_color = {r = 0.83, g = 0.83, b = 0.83}
|
||||||
|
|||||||
Reference in New Issue
Block a user