1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-12 02:28:02 +02:00

fixed issue where the tag window wouldn't open if a player had a custom tag.

Also implemented /tag
This commit is contained in:
Valansch 2017-07-21 01:29:49 +02:00
parent 8706bb6ce2
commit bbbcd5f38d
3 changed files with 72 additions and 86 deletions

133
band.lua
View File

@ -28,7 +28,7 @@ local expand_band_gui
local local_role
local function create_band_gui(event)
local player = game.players[event.player_index]
local player = game.players[event.player_index]
global.band_last_change[event.player_index] = game.tick
if player.gui.top.band_toggle_btn == nil then
local button = player.gui.top.add { name = "band_toggle_btn", type = "sprite-button", caption = "Tag", style = "dialog_button_style" }
@ -48,17 +48,17 @@ end
-- Make a list of random names with roles
local function test_fake_players( t )
local limit = math.random(20,120)
local roles_ind = {}
for role in pairs(roles) do
table.insert( roles_ind, role)
end
for i = 1,limit do
local rolei = math.random(1, #roles_ind)
local role = roles_ind[rolei]
table.insert(t[role],
table.insert(t[role],
{
"Fake#" .. (tostring(math.random())):sub(3,-math.random(1,10)),
{
@ -79,17 +79,17 @@ local function subgui_update_role_counter(gui_parent, count_diff)
local count_label
if gui_parent["role_counter"] then
count_label = gui_parent["role_counter"]
else
else
count_label = gui_parent.add {type = "label", caption = 0, name = "role_counter", single_line = false}
count_label.style.font = "default-small-bold"
count_label.style.maximal_height = 10
count_label.style.maximal_height = 10
count_label.style.top_padding = 0
count_label.style.left_padding = 0
count_label.style.right_padding = 0
count_label.style.bottom_padding = 0
count_label.style.font_color = {r=.55,g=.55,b=.55}
end
local new_count = tonumber(count_label.caption) + count_diff
count_label.caption = new_count
if new_count == 0 then
@ -126,7 +126,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
local frame = player.gui.left["band_panel"]
if (frame) then
frame.destroy()
if player.gui.center["textfield_item_icon_frame"] then
player.gui.center["textfield_item_icon_frame"].destroy()
end
@ -138,16 +138,15 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
end
return
end
local player_role = player.tag:sub(2,-2)
local player_role = player.tag:sub(2,-2)
-- Will be filled: { roleN = {{name,color},...} , ...}
local players_by_role = {}
for role in pairs(roles) do
players_by_role[role] = {}
end
if right_click then
for _, oplayer in pairs(game.players) do
local prole = oplayer.tag:sub(2,-2)
@ -162,24 +161,24 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
else
for _, oplayer in pairs(game.connected_players) do
local prole = oplayer.tag:sub(2,-2)
if prole ~= "" then
if players_by_role[prole] ~= nil then
table.insert( players_by_role[prole], {oplayer.name, oplayer.color})
end
end
end
if dev_addfakes then
test_fake_players(players_by_role)
end
player.gui.top.band_toggle_btn.tooltip = ""
local button--reusable variable :D
local frame = player.gui.left.add { type = "frame", direction = "vertical", name = "band_panel", caption = "Choose your role:"}
frame.style.font = "default-listbox"
frame.style.font_color = { r=0.98, g=0.66, b=0.22}
if dev_icons then
local choose
local chooselist = frame.add { type = "flow", direction = "horizontal" }
@ -194,25 +193,25 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
choose.style.bottom_padding = 2
end
end
local scroll = frame.add{type = "scroll-pane", name = "scroll", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"}
scroll.style.maximal_height = 600
scroll.style.minimal_width = 250
scroll.style.bottom_padding = 10
local table_roles = scroll.add{type = "table", name = "table_roles", colspan = 2}
table_roles.style.horizontal_spacing = 15
table_roles.style.vertical_spacing = 4
local name_label
local pname
local pcolor
local show_role_tooltip = math.random() > .5
for role, role_icons in pairs(roles) do
local role_line = table_roles.add { type = "flow", direction = "horizontal" }
button = role_line.add { type = "sprite-button", sprite = get_random_from_table(role_icons), name = "band_role_"..role, style = "recipe_slot_button_style"}
@ -223,14 +222,14 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
if show_role_tooltip and role_icons.tooltip then
button.tooltip = get_random_from_table( role_icons.tooltip )
end
local role_cap_line = role_line.add { type = "flow", name = "role_cap_line", direction = "horizontal" }
role_cap_line.style.max_on_row = 1
local role_label = role_cap_line.add { type = "label", caption = role, single_line = true}
-- role_label.style.minimal_width = 0
role_label.style.minimal_height = 0
role_label.style.maximal_height = 12
role_label.style.maximal_height = 12
role_label.style.top_padding = 0
role_label.style.left_padding = 0
role_label.style.right_padding = 0
@ -239,7 +238,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
if role == player_role then
role_label.style.font_color = {r=.7,g=1,b=.7}
end
subgui_update_role_counter(role_cap_line, #players_by_role[role])
local list_players = table_roles.add { type = "flow", direction = "horizontal" }
@ -255,7 +254,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
end
end
end
local close_btn_flow = frame.add { type = "flow", direction = "horizontal" }
button = close_btn_flow.add { type = "button", caption = "Close", name = "band_close" }
button.style.font = "default-bold"
@ -265,7 +264,7 @@ expand_band_gui = function(player, dev_icons, dev_addfakes, right_click)
button.style.left_padding = 2
button.style.right_padding = 2
button.style.bottom_padding = 0
button = close_btn_flow.add { type = "button", caption = "Clear tag", name = "band_clear" }
button.style.font = "default-bold"
button.style.font_color = {r=1, g=.7, b=.7}
@ -292,7 +291,7 @@ local function print_role_change(name, role)
str = str .. " (["..local_role.."] squad will miss you)."
end]]--
end
if str then
str = str:gsub('%%name', name)
game.print(str)
@ -304,54 +303,17 @@ local function update_player_role(player, role)
global.update_player_name = player
global.update_player_role_name = role
if global.update_player_role_name then
global.update_player_name.tag = "[" .. global.update_player_role_name .. "]"
else
global.update_player_name.tag = ""
end
-- update other player gui (counter & label)
--[[
for _,cplayer in pairs( game.connected_players ) do
if cplayer.gui.left.band_panel then
local troles = cplayer.gui.left.band_panel.scroll.table_roles
if local_role then
local player_label = troles.children[roles[local_role].index*2]["list_players_" .. cplayer.name]
if player_label then
player_label.destroy()
end
end
if global.update_player_role_name then
subgui_add_player_label( troles.children[roles[global.update_player_role_name].index*2], cplayer.name, cplayer.color)
subgui_update_role_counter( troles.children[roles[global.update_player_role_name].index*2 - 1].role_cap_line, 1)
end
if local_role then
subgui_update_role_counter( troles.children[roles[local_role].index*2 - 1].role_cap_line, -1)
end
end
end
-- update local player gui (role label color)
local troles_local = player.gui.left.band_panel.scroll.table_roles
if local_role then
troles_local.children[roles[local_role].index*2 - 1].children[2].children[1].style.font_color = {r=1,g=1,b=1}
end
if global.update_player_role_name then
troles_local.children[roles[global.update_player_role_name].index*2 - 1].children[2].children[1].style.font_color = {r=.7,g=1,b=.7}
end
--]]
print_role_change(global.update_player_name.name, global.update_player_role_name)
expand_band_gui(player)
expand_band_gui(player)
local_role = role
end
@ -359,11 +321,11 @@ local function on_gui_click(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.element.player_index]
local name = event.element.name
if (name == "band_toggle_btn") then
--player, dev_icons, dev_addfakes
expand_band_gui(player,
player.admin and event.control,
expand_band_gui(player,
player.admin and event.control,
player.admin and event.alt,
event.button == defines.mouse_button_type.right)
end
@ -372,18 +334,17 @@ local function on_gui_click(event)
expand_band_gui(player)
return
end
if (name == "band_clear") then
update_player_role(player, nil)
player.gui.top.band_toggle_btn.caption = "Tag"
player.gui.top.band_toggle_btn.tooltip = ""
player.gui.top.band_toggle_btn.sprite = ""
-- expand_band_gui(player)
return
end
--role button clicked
if name:find("band_role_") == 1 then
if not player.admin and event.tick - global.band_last_change[event.player_index] < option_band_change_interval then
@ -392,20 +353,20 @@ local function on_gui_click(event)
end
local _,role_ind_start = name:find("band_role_")
local name_role = name:sub(role_ind_start + 1)
if player.tag:find(name_role) then
-- current tag = new tag
return
end
for role, role_icons in pairs(roles) do
if (name_role == role) then
global.band_last_change[event.player_index] = event.tick
player.gui.top.band_toggle_btn.caption = ""
player.gui.top.band_toggle_btn.sprite = event.element.sprite --get_random_from_table(role_icons)
update_player_role(player, role)
update_player_role(player, role)
-- expand_band_gui(player)
end
end
@ -424,18 +385,18 @@ local function on_gui_elem_changed(event)
if event.element.elem_type and event.element.elem_value then
local frame = player.gui.center.add{ type = "frame", name = "textfield_item_icon_frame", caption = "SpritePath"}
frame.style.minimal_width = 310
local textfield
local textfield
-- if type(event.element.elem_value ) == 'table' then
-- textfield = frame.add { name = "textfield_item_icon", type = "textfield", text = "virtual-signal/" .. event.element.elem_value.name }
-- else
textfield = frame.add { name = "textfield_item_icon", type = "textfield", text = event.element.elem_type .. "/" .. event.element.elem_value }
-- end
--buggy
textfield.style.minimal_width = 300
end
end
end
Event.register(defines.events.on_gui_elem_changed, on_gui_elem_changed)

View File

@ -12,6 +12,10 @@ Event.register(-1, function()
}
global.scenario.variables.regulars = {
helpower2 = "",
rorror = "",
Medival3 = "",
dpoba = "",
settdigger = ""
}
global.scenario.variables.player_positions = {}
global.scenario.variables.player_walk_distances = {}

View File

@ -242,6 +242,26 @@ local function afk()
end
end
local function tag(cmd)
if not game.player.admin then
cant_run(cmd.name)
return
end
local params = {}
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
if #params ~= 2 then
game.player.print("Two arguments expect failed. Usage: <player> <tag> Sets a players tag.")
elseif game.players[params[1]] == nil then
game.player.print("Player does not exist.")
else
game.players[params[1]].tag = "[" .. params[2] .. "]"
game.print(params[1] .. " joined [" .. params[2] .. "].")
end
end
commands.add_command("kill", "Will kill you.", kill)
commands.add_command("detrain", "<player> - Kicks the player off a train. (Admins and moderators)", detrain)
commands.add_command("tpplayer", "<player> - Teleports you to the player. (Admins and moderators)", teleport_player)
@ -256,3 +276,4 @@ commands.add_command("regular", '<promote, demote>, <player> Change regular stat
commands.add_command("mods", 'Prints a list of game mods.', print_mods)
commands.add_command("mod", '<promote, demote>, <player> Changes moderator status of a player. (Admins only)', mod)
commands.add_command("afktime", 'Shows how long players have been afk.', afk)
commands.add_command("tag", '<player> <tag> Sets a players tag. (Admins only)', tag)