mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-26 03:52:22 +02:00
Merge pull request #86 from MaemiKozue/master
Biter Battles: Added technology view for spectators
This commit is contained in:
commit
950aa6febe
@ -2,6 +2,8 @@ local event = require 'utils.event'
|
||||
local spy_fish = require "maps.biter_battles_v2.spy_fish"
|
||||
local feed_the_biters = require "maps.biter_battles_v2.feeding"
|
||||
|
||||
require "maps.biter_battles_v2.spec_spy"
|
||||
|
||||
local food_names = {
|
||||
["automation-science-pack"] = true,
|
||||
["logistic-science-pack"] = true,
|
||||
@ -15,11 +17,13 @@ local food_names = {
|
||||
local gui_values = {
|
||||
["north"] = {force = "north", biter_force = "north_biters", c1 = bb_config.north_side_team_name, c2 = "JOIN ", n1 = "join_north_button",
|
||||
t1 = "Evolution of the North side biters. Can go beyond 100% for endgame modifiers.",
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.55, g = 0.55, b = 0.99}, color2 = {r = 0.66, g = 0.66, b = 0.99}},
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.55, g = 0.55, b = 0.99}, color2 = {r = 0.66, g = 0.66, b = 0.99},
|
||||
tech_spy = "spy-north-tech", prod_spy = "spy-north-prod"},
|
||||
["south"] = {force = "south", biter_force = "south_biters", c1 = bb_config.south_side_team_name, c2 = "JOIN ", n1 = "join_south_button",
|
||||
t1 = "Evolution of the South side biters. Can go beyond 100% for endgame modifiers.",
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.99, g = 0.33, b = 0.33}, color2 = {r = 0.99, g = 0.44, b = 0.44}}
|
||||
}
|
||||
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.99, g = 0.33, b = 0.33}, color2 = {r = 0.99, g = 0.44, b = 0.44},
|
||||
tech_spy = "spy-south-tech", prod_spy = "spy-south-prod"}
|
||||
}
|
||||
|
||||
local map_gen_messages = {
|
||||
"Map is still generating, please get comfy.",
|
||||
@ -91,7 +95,28 @@ local function create_first_join_gui(player)
|
||||
end
|
||||
end
|
||||
|
||||
local function add_tech_button(elem, gui_value)
|
||||
local tech_button = elem.add {
|
||||
type = "sprite-button",
|
||||
name = gui_value.tech_spy,
|
||||
sprite = "item/space-science-pack"
|
||||
}
|
||||
tech_button.style.height = 25
|
||||
tech_button.style.width = 25
|
||||
end
|
||||
|
||||
local function add_prod_button(elem, gui_value)
|
||||
local prod_button = elem.add {
|
||||
type = "sprite-button",
|
||||
name = gui_value.prod_spy,
|
||||
sprite = "item/assembling-machine-3"
|
||||
}
|
||||
prod_button.style.height = 25
|
||||
prod_button.style.width = 25
|
||||
end
|
||||
|
||||
local function create_main_gui(player)
|
||||
local is_spec = player.force.name == "spectator"
|
||||
if player.gui.left["bb_main_gui"] then player.gui.left["bb_main_gui"].destroy() end
|
||||
|
||||
if global.bb_game_won_by_team then return end
|
||||
@ -104,7 +129,8 @@ local function create_main_gui(player)
|
||||
|
||||
local frame = player.gui.left.add { type = "frame", name = "bb_main_gui", direction = "vertical" }
|
||||
|
||||
if player.force.name ~= "spectator" then
|
||||
-- Science sending GUI
|
||||
if not is_spec then
|
||||
frame.add { type = "table", name = "biter_battle_table", column_count = 4 }
|
||||
local t = frame.biter_battle_table
|
||||
local foods = {"automation-science-pack","logistic-science-pack","military-science-pack","chemical-science-pack","production-science-pack","utility-science-pack","space-science-pack","raw-fish"}
|
||||
@ -123,8 +149,19 @@ local function create_main_gui(player)
|
||||
end
|
||||
end
|
||||
|
||||
local first_team = true
|
||||
for _, gui_value in pairs(gui_values) do
|
||||
-- Line separator
|
||||
if not first_team then
|
||||
frame.add { type = "line", caption = "this line", direction = "horizontal" }
|
||||
else
|
||||
first_team = false
|
||||
end
|
||||
|
||||
-- Team name & Player count
|
||||
local t = frame.add { type = "table", column_count = 3 }
|
||||
|
||||
-- Team name
|
||||
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}
|
||||
@ -134,6 +171,7 @@ local function create_main_gui(player)
|
||||
--l.style.minimal_width = 100
|
||||
l.style.maximal_width = 102
|
||||
|
||||
-- Number of players
|
||||
local l = t.add { type = "label", caption = " - "}
|
||||
local c = #game.forces[gui_value.force].connected_players .. " Player"
|
||||
if #game.forces[gui_value.force].connected_players ~= 1 then c = c .. "s" end
|
||||
@ -141,6 +179,7 @@ local function create_main_gui(player)
|
||||
l.style.font = "default"
|
||||
l.style.font_color = { r=0.22, g=0.88, b=0.22}
|
||||
|
||||
-- Player list
|
||||
if global.bb_view_players[player.name] == true then
|
||||
local t = frame.add { type = "table", column_count = 4 }
|
||||
for _, p in pairs(game.forces[gui_value.force].connected_players) do
|
||||
@ -149,7 +188,10 @@ local function create_main_gui(player)
|
||||
end
|
||||
end
|
||||
|
||||
local t = frame.add { type = "table", name = "stats_" .. gui_value.force, column_count = 4 }
|
||||
-- Statistics
|
||||
local t = frame.add { type = "table", name = "stats_" .. gui_value.force, column_count = 6 }
|
||||
|
||||
-- Evolution
|
||||
local l = t.add { type = "label", caption = "Evo:"}
|
||||
--l.style.minimal_width = 25
|
||||
l.tooltip = gui_value.t1
|
||||
@ -160,30 +202,43 @@ local function create_main_gui(player)
|
||||
l.style.font = "default-bold"
|
||||
l.tooltip = gui_value.t1
|
||||
|
||||
-- Threat
|
||||
local l = t.add {type = "label", caption = "Threat: "}
|
||||
l.style.minimal_width = 25
|
||||
l.tooltip = gui_value.t2
|
||||
local l = t.add {type = "label", name = "threat_" .. gui_value.force, caption = math.floor(global.bb_threat[gui_value.biter_force])}
|
||||
l.style.font_color = gui_value.color2
|
||||
l.style.font = "default-bold"
|
||||
l.style.minimal_width = 25
|
||||
l.style.width = 50
|
||||
l.tooltip = gui_value.t2
|
||||
|
||||
frame.add { type = "label", caption = string.rep("-", 29)}
|
||||
-- Tech button
|
||||
if is_spec then
|
||||
add_tech_button(t, gui_value)
|
||||
-- add_prod_button(t, gui_value)
|
||||
end
|
||||
end
|
||||
|
||||
-- Action frame
|
||||
local t = frame.add { type = "table", column_count = 2 }
|
||||
if player.force.name == "spectator" then
|
||||
|
||||
-- Spectate / Rejoin team
|
||||
if is_spec then
|
||||
local b = t.add { type = "sprite-button", name = "bb_leave_spectate", caption = "Join Team" }
|
||||
else
|
||||
local b = t.add { type = "sprite-button", name = "bb_spectate", caption = "Spectate" }
|
||||
end
|
||||
|
||||
-- Playerlist button
|
||||
if global.bb_view_players[player.name] == true then
|
||||
local b = t.add { type = "sprite-button", name = "bb_hide_players", caption = "Playerlist" }
|
||||
else
|
||||
local b = t.add { type = "sprite-button", name = "bb_view_players", caption = "Playerlist" }
|
||||
end
|
||||
|
||||
|
||||
local b_width = is_spec and 97 or 86
|
||||
-- 111 when prod_spy button will be there
|
||||
for _, b in pairs(t.children) do
|
||||
b.style.font = "default-bold"
|
||||
b.style.font_color = { r=0.98, g=0.66, b=0.22}
|
||||
@ -192,7 +247,7 @@ local function create_main_gui(player)
|
||||
b.style.right_padding = 1
|
||||
b.style.bottom_padding = 1
|
||||
b.style.maximal_height = 30
|
||||
b.style.minimal_width = 86
|
||||
b.style.width = b_width
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -129,7 +129,6 @@ local function init_forces()
|
||||
defines.input_action.edit_permission_group,
|
||||
defines.input_action.toggle_show_entity_info,
|
||||
defines.input_action.rotate_entity,
|
||||
defines.input_action.start_research
|
||||
}
|
||||
for _, d in pairs(defs) do p.set_allows_action(d, true) end
|
||||
|
||||
@ -196,6 +195,7 @@ end
|
||||
event.on_init(on_init)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
require "maps.biter_battles_v2.spec_spy"
|
||||
require "maps.biter_battles_v2.on_tick"
|
||||
require "maps.biter_battles_v2.terrain"
|
||||
require "maps.biter_battles_v2.biters_landfill"
|
||||
|
103
maps/biter_battles_v2/spec_spy.lua
Executable file
103
maps/biter_battles_v2/spec_spy.lua
Executable file
@ -0,0 +1,103 @@
|
||||
local Global = require "utils.global"
|
||||
|
||||
local this = {
|
||||
-- map player <> force
|
||||
initialForce = {}
|
||||
}
|
||||
|
||||
Global.register(this, function (t) this = t end)
|
||||
|
||||
local function is_spying(player)
|
||||
return this.initialForce[player.index] ~= nil
|
||||
end
|
||||
|
||||
local function switch_force(player, force)
|
||||
this.initialForce[player.index] = player.force
|
||||
player.force = force
|
||||
end
|
||||
|
||||
local function spy_production(player, force)
|
||||
if is_spying(player) then
|
||||
return
|
||||
end
|
||||
switch_force(player, force)
|
||||
player.opened = defines.gui_type.production
|
||||
end
|
||||
|
||||
local function spy_tech_tree(player, force)
|
||||
if is_spying(player) then
|
||||
return
|
||||
end
|
||||
switch_force(player, force)
|
||||
player.open_technology_gui()
|
||||
end
|
||||
|
||||
local function restore_force(player)
|
||||
if not is_spying(player) then
|
||||
return
|
||||
end
|
||||
player.force = this.initialForce[player.index]
|
||||
this.initialForce[player.index] = nil
|
||||
end
|
||||
|
||||
-- When a player clicks on a spying prod LuaGuiElement
|
||||
local function spy_prod_handler(event)
|
||||
if not event.element.valid then
|
||||
return
|
||||
end
|
||||
local elementToForce = {
|
||||
["spy-north-prod"] = "north",
|
||||
["spy-south-prod"] = "south"
|
||||
}
|
||||
local force = elementToForce[event.element.name]
|
||||
if force then
|
||||
local player = game.players[event.player_index]
|
||||
spy_production(player, force)
|
||||
end
|
||||
end
|
||||
|
||||
-- When a player clicks on a spying tech LuaGuiElement
|
||||
local function spy_tech_handler(event)
|
||||
if not event.element.valid then
|
||||
return
|
||||
end
|
||||
local elementToForce = {
|
||||
["spy-north-tech"] = "north",
|
||||
["spy-south-tech"] = "south"
|
||||
}
|
||||
local force = elementToForce[event.element.name]
|
||||
if force then
|
||||
local player = game.players[event.player_index]
|
||||
spy_tech_tree(player, force)
|
||||
end
|
||||
end
|
||||
|
||||
-- When a player closes the prod view while spying
|
||||
local function close_prod_handler(event)
|
||||
if event.gui_type ~= defines.gui_type.production then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
-- If the player was spying
|
||||
if is_spying(player) then
|
||||
restore_force(player)
|
||||
end
|
||||
end
|
||||
|
||||
-- When a player closes the tech view while spying
|
||||
local function close_tech_handler(event)
|
||||
if event.gui_type ~= defines.gui_type.research then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
-- If the player was spying
|
||||
if is_spying(player) then
|
||||
restore_force(player)
|
||||
end
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.add(defines.events.on_gui_click, spy_prod_handler)
|
||||
Event.add(defines.events.on_gui_click, spy_tech_handler)
|
||||
Event.add(defines.events.on_gui_closed, close_prod_handler)
|
||||
Event.add(defines.events.on_gui_closed, close_tech_handler)
|
Loading…
x
Reference in New Issue
Block a user