mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-17 20:58:13 +02:00
Custom team names via Team Manager
This commit is contained in:
parent
9dee0c699b
commit
693cd10fa0
@ -18,10 +18,7 @@ local enemy_team_of = {
|
||||
["south"] = "north"
|
||||
}
|
||||
|
||||
local team_strings = {
|
||||
["north"] = table.concat({"[color=120, 120, 255]", bb_config.north_side_team_name, "'s[/color]"}),
|
||||
["south"] = table.concat({"[color=255, 65, 65]", bb_config.south_side_team_name, "'s[/color]"})
|
||||
}
|
||||
|
||||
|
||||
local minimum_modifier = 125
|
||||
local maximum_modifier = 250
|
||||
@ -49,6 +46,33 @@ local function set_biter_endgame_modifiers(force)
|
||||
global.bb_evasion[force.name] = evasion_mod
|
||||
end
|
||||
|
||||
local function print_feeding_msg(player, food, flask_amount)
|
||||
if not enemy_team_of[player.force.name] then return end
|
||||
|
||||
local n = bb_config.north_side_team_name
|
||||
local s = bb_config.south_side_team_name
|
||||
if global.tm_custom_name["north"] then n = global.tm_custom_name["north"] end
|
||||
if global.tm_custom_name["south"] then s = global.tm_custom_name["south"] end
|
||||
local team_strings = {
|
||||
["north"] = table.concat({"[color=120, 120, 255]", n, "'s[/color]"}),
|
||||
["south"] = table.concat({"[color=255, 65, 65]", s, "'s[/color]"})
|
||||
}
|
||||
|
||||
local colored_player_name = table.concat({"[color=", player.color.r * 0.6 + 0.35, ",", player.color.g * 0.6 + 0.35, ",", player.color.b * 0.6 + 0.35, "]", player.name, "[/color]"})
|
||||
local formatted_food = table.concat({"[color=", food_values[food].color, "]", food_values[food].name, " juice[/color]", "[img=item/", food, "]"})
|
||||
local formatted_amount = table.concat({"[font=heading-1][color=255,255,255]" .. flask_amount .. "[/color][/font]"})
|
||||
|
||||
if flask_amount >= 20 then
|
||||
game.print(colored_player_name .. " fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to team " .. team_strings[enemy_team_of[player.force.name]] .. " biters!", {r = 0.9, g = 0.9, b = 0.9})
|
||||
else
|
||||
if flask_amount == 1 then
|
||||
player.print("You fed one flask of " .. formatted_food .. " to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
else
|
||||
player.print("You fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function set_evo_and_threat(flask_amount, food, biter_force_name)
|
||||
local decimals = 12
|
||||
local math_round = math.round
|
||||
@ -100,19 +124,7 @@ local function feed_biters(player, food)
|
||||
|
||||
i.remove({name = food, count = flask_amount})
|
||||
|
||||
local colored_player_name = table.concat({"[color=", player.color.r * 0.6 + 0.35, ",", player.color.g * 0.6 + 0.35, ",", player.color.b * 0.6 + 0.35, "]", player.name, "[/color]"})
|
||||
local formatted_food = table.concat({"[color=", food_values[food].color, "]", food_values[food].name, " juice[/color]", "[img=item/", food, "]"})
|
||||
local formatted_amount = table.concat({"[font=heading-1][color=255,255,255]" .. flask_amount .. "[/color][/font]"})
|
||||
|
||||
if flask_amount >= 20 then
|
||||
game.print(colored_player_name .. " fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to team " .. team_strings[enemy_force_name] .. " biters!", {r = 0.9, g = 0.9, b = 0.9})
|
||||
else
|
||||
if flask_amount == 1 then
|
||||
player.print("You fed one flask of " .. formatted_food .. " to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
else
|
||||
player.print("You fed " .. formatted_amount .. " flasks of " .. formatted_food .. " to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
end
|
||||
end
|
||||
print_feeding_msg(player, food, flask_amount)
|
||||
|
||||
set_evo_and_threat(flask_amount, food, biter_force_name)
|
||||
end
|
||||
|
@ -57,8 +57,10 @@ local function create_first_join_gui(player)
|
||||
frame.add { type = "label", caption = "-----------------------------------------------------------"}
|
||||
|
||||
for _, gui_value in pairs(gui_values) do
|
||||
local t = frame.add { type = "table", column_count = 3 }
|
||||
local l = t.add { type = "label", caption = gui_value.c1}
|
||||
local t = frame.add { type = "table", column_count = 3 }
|
||||
local c = gui_value.c1
|
||||
if global.tm_custom_name[gui_value.force] then c = global.tm_custom_name[gui_value.force] end
|
||||
local l = t.add { type = "label", caption = c}
|
||||
l.style.font = "heading-2"
|
||||
l.style.font_color = gui_value.color1
|
||||
l.style.single_line = false
|
||||
@ -123,7 +125,9 @@ local function create_main_gui(player)
|
||||
|
||||
for _, gui_value in pairs(gui_values) do
|
||||
local t = frame.add { type = "table", column_count = 3 }
|
||||
local l = t.add { type = "label", caption = gui_value.c1}
|
||||
local c = gui_value.c1
|
||||
if global.tm_custom_name[gui_value.force] then c = global.tm_custom_name[gui_value.force] end
|
||||
local l = t.add { type = "label", caption = c}
|
||||
l.style.font = "default-bold"
|
||||
l.style.font_color = gui_value.color1
|
||||
l.style.single_line = false
|
||||
|
@ -134,7 +134,9 @@ local function draw_manager_gui(player)
|
||||
local i2 = 1
|
||||
for i = 1, #forces * 2 - 1, 1 do
|
||||
if i % 2 == 1 then
|
||||
local l = t.add({type = "label", caption = string.upper(forces[i2].name)})
|
||||
local l = t.add({type = "sprite-button", caption = string.upper(forces[i2].name), name = forces[i2].name})
|
||||
l.style.minimal_width = 160
|
||||
l.style.maximal_width = 160
|
||||
l.style.font_color = forces[i2].color
|
||||
l.style.font = "heading-1"
|
||||
i2 = i2 + 1
|
||||
@ -223,20 +225,47 @@ local function draw_manager_gui(player)
|
||||
button.style.font = "heading-2"
|
||||
end
|
||||
|
||||
local function on_gui_click(event)
|
||||
if not event.element then return end
|
||||
if not event.element.valid then return end
|
||||
local function set_custom_team_name(force_name, team_name)
|
||||
if team_name == "" then global.tm_custom_name[force_name] = nil return end
|
||||
if not team_name then global.tm_custom_name[force_name] = nil return end
|
||||
global.tm_custom_name[force_name] = tostring(team_name)
|
||||
end
|
||||
|
||||
local function custom_team_name_gui(player, force_name)
|
||||
if player.gui.center["custom_team_name_gui"] then player.gui.center["custom_team_name_gui"].destroy() return end
|
||||
local frame = player.gui.center.add({type = "frame", name = "custom_team_name_gui", caption = "Set custom team name:", direction = "vertical"})
|
||||
local text = force_name
|
||||
if global.tm_custom_name[force_name] then text = global.tm_custom_name[force_name] end
|
||||
|
||||
local textfield = frame.add({ type = "textfield", name = force_name, text = text })
|
||||
local t = frame.add({type = "table", column_count = 2})
|
||||
local button = t.add({
|
||||
type = "button",
|
||||
name = "custom_team_name_gui_set",
|
||||
caption = "Set",
|
||||
tooltip = "Set custom team name."
|
||||
})
|
||||
button.style.font = "heading-2"
|
||||
|
||||
local button = t.add({
|
||||
type = "button",
|
||||
name = "custom_team_name_gui_close",
|
||||
caption = "Close",
|
||||
tooltip = "Close this window."
|
||||
})
|
||||
button.style.font = "heading-2"
|
||||
end
|
||||
|
||||
local function team_manager_gui_click(event)
|
||||
local player = game.players[event.player_index]
|
||||
local name = event.element.name
|
||||
|
||||
if name == "team_manager_toggle_button" then
|
||||
if player.gui.center["team_manager_gui"] then player.gui.center["team_manager_gui"].destroy() return end
|
||||
draw_manager_gui(player)
|
||||
if game.forces[name] then
|
||||
custom_team_name_gui(player, name)
|
||||
player.gui.center["team_manager_gui"].destroy()
|
||||
return
|
||||
end
|
||||
|
||||
if not player.gui.center["team_manager_gui"] then return end
|
||||
|
||||
if name == "team_manager_close" then
|
||||
player.gui.center["team_manager_gui"].destroy()
|
||||
return
|
||||
@ -300,10 +329,45 @@ local function on_gui_click(event)
|
||||
draw_manager_gui(player)
|
||||
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]
|
||||
local name = event.element.name
|
||||
|
||||
if name == "team_manager_toggle_button" then
|
||||
if player.gui.center["team_manager_gui"] then player.gui.center["team_manager_gui"].destroy() return end
|
||||
draw_manager_gui(player)
|
||||
return
|
||||
end
|
||||
|
||||
if player.gui.center["team_manager_gui"] then team_manager_gui_click(event) end
|
||||
|
||||
if player.gui.center["custom_team_name_gui"] then
|
||||
if name == "custom_team_name_gui_set" then
|
||||
local custom_name = player.gui.center["custom_team_name_gui"].children[1].text
|
||||
local force_name = player.gui.center["custom_team_name_gui"].children[1].name
|
||||
set_custom_team_name(force_name, custom_name)
|
||||
player.gui.center["custom_team_name_gui"].destroy()
|
||||
draw_manager_gui(player)
|
||||
end
|
||||
if name == "custom_team_name_gui_close" then
|
||||
player.gui.center["custom_team_name_gui"].destroy()
|
||||
draw_manager_gui(player)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
draw_manager_button(game.players[event.player_index])
|
||||
end
|
||||
|
||||
local function on_init(surface)
|
||||
global.tm_custom_name = {}
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
Loading…
x
Reference in New Issue
Block a user