From 40c119d1c8ee96a29d710fc10b9f9453dcecf578 Mon Sep 17 00:00:00 2001 From: Sofia Date: Mon, 3 Aug 2026 20:33:40 +0300 Subject: [PATCH] Add possibility for alternate team colors --- godot/maps/precipice.tres | 2 -- godot/maps/teams/blue_team.tres | 1 - godot/maps/teams/red_ream.tres | 1 - godot/maps/two_towers.tres | 6 ++++-- godot/scenes/lobby.tscn | 6 ++++-- rust/src/chat.rs | 4 ++-- rust/src/game/mod.rs | 2 +- rust/src/goal.rs | 2 +- rust/src/lobby_world.rs | 11 ++++++++++- rust/src/map.rs | 2 +- rust/src/player/local_player.rs | 2 +- rust/src/player/menu_player.rs | 4 ++-- rust/src/replay.rs | 4 ++-- rust/src/team_resource.rs | 24 +++++++++++++++++++++++- rust/src/ui/game_finished_screen.rs | 2 +- rust/src/ui/lobby.rs | 6 ++++++ rust/src/ui/lobby_player_listing.rs | 6 +++--- rust/src/ui/player_listings.rs | 2 +- rust/src/ui/simple_score_view.rs | 2 +- 19 files changed, 63 insertions(+), 26 deletions(-) diff --git a/godot/maps/precipice.tres b/godot/maps/precipice.tres index 156b158..a37f72b 100644 --- a/godot/maps/precipice.tres +++ b/godot/maps/precipice.tres @@ -7,11 +7,9 @@ [sub_resource type="TeamResource" id="TeamResource_w4gl8"] name = "Copper Team" -color = Color(0.41, 0.82, 0.54666674, 1) [sub_resource type="TeamResource" id="TeamResource_iftcq"] name = "Silver Team" -color = Color(0.74, 0.7876666, 1, 1) [resource] name = "Precipice" diff --git a/godot/maps/teams/blue_team.tres b/godot/maps/teams/blue_team.tres index e896997..2f113bf 100644 --- a/godot/maps/teams/blue_team.tres +++ b/godot/maps/teams/blue_team.tres @@ -2,4 +2,3 @@ [resource] name = "Blue Team" -color = Color(0, 0.7411765, 1, 1) diff --git a/godot/maps/teams/red_ream.tres b/godot/maps/teams/red_ream.tres index 178e2ce..89d0bb6 100644 --- a/godot/maps/teams/red_ream.tres +++ b/godot/maps/teams/red_ream.tres @@ -2,4 +2,3 @@ [resource] name = "Red Team" -color = Color(1, 0.35686275, 0.3647059, 1) diff --git a/godot/maps/two_towers.tres b/godot/maps/two_towers.tres index b713609..0f7dc7d 100644 --- a/godot/maps/two_towers.tres +++ b/godot/maps/two_towers.tres @@ -8,11 +8,13 @@ [sub_resource type="TeamResource" id="TeamResource_64qm8"] name = "Shadow Team" -color = Color(0.5380128, 0.5138385, 1, 1) +primary_color = Color(0.05000019, 0, 1, 1) +alt_color = Color(0, 1, 0.0666666, 1) [sub_resource type="TeamResource" id="TeamResource_47vax"] name = "Sunshine Team" -color = Color(0.99999994, 0.83743095, 0.5094259, 1) +primary_color = Color(1, 0, 0, 1) +alt_color = Color(0.9333333, 1, 0, 1) [resource] name = "Two Towers" diff --git a/godot/scenes/lobby.tscn b/godot/scenes/lobby.tscn index 00994b4..4aa56d7 100644 --- a/godot/scenes/lobby.tscn +++ b/godot/scenes/lobby.tscn @@ -20,10 +20,11 @@ font_size = 32 [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbm04"] bg_color = Color(0.30692267, 0.3069227, 0.30692264, 1) -[node name="lobby_world" type="LobbyWorld" unique_id=129662054] +[node name="lobby_world" type="LobbyWorld" unique_id=129662054 node_paths=PackedStringArray("lobby")] menu_player_scene = ExtResource("3_q60fs") +lobby = NodePath("lobby") -[node name="lobby" type="LobbyPanel" parent="." unique_id=915192272 node_paths=PackedStringArray("players_list", "name_field", "ready_button", "map_selection", "options_panel", "options_grid")] +[node name="lobby" type="LobbyPanel" parent="." unique_id=915192272 node_paths=PackedStringArray("players_list", "name_field", "ready_button", "map_selection", "options_panel", "options_grid", "alt_colors")] players_list = NodePath("v_box_container/players_list") name_field = NodePath("v_box_container/h_box_container/text_edit") player_listing_prefab = ExtResource("1_o1atq") @@ -31,6 +32,7 @@ ready_button = NodePath("v_box_container3/ready_button") map_selection = NodePath("v_box_container2/option_button") options_panel = NodePath("options_panel") options_grid = NodePath("options_panel/h_box_container/options_grid") +alt_colors = NodePath("v_box_container/h_box_container/check_box") start_game_icon = ExtResource("3_oipnb") ready_icon = ExtResource("4_yad6j") not_ready_icon = ExtResource("5_ncsg4") diff --git a/rust/src/chat.rs b/rust/src/chat.rs index 7045a78..ba6c101 100644 --- a/rust/src/chat.rs +++ b/rust/src/chat.rs @@ -105,7 +105,7 @@ impl ChatMessage { if idx > 0 { label.add_text(" and "); } - label.push_color(team.bind().color); + label.push_color(team.bind().color()); label.add_text(&team.bind().name); label.pop(); } @@ -120,7 +120,7 @@ fn add_player(label: &mut Gd, player: &Player) { if let Some(game) = Game::singleton() && let Some(team) = game.bind().get_team(player.data.team) { - label.push_color(team.bind().color); + label.push_color(team.bind().color()); label.add_text(&player.data.name); label.pop(); } diff --git a/rust/src/game/mod.rs b/rust/src/game/mod.rs index 3c179f5..9645b24 100644 --- a/rust/src/game/mod.rs +++ b/rust/src/game/mod.rs @@ -1185,7 +1185,7 @@ impl Game { { chat.bind_mut().new_message(ChatMessage::ChatMessage( player.data.name.clone(), - team.bind().color, + team.bind().color(), message.clone(), )); } diff --git a/rust/src/goal.rs b/rust/src/goal.rs index 5063739..b75d0e6 100644 --- a/rust/src/goal.rs +++ b/rust/src/goal.rs @@ -44,7 +44,7 @@ impl Goal { if let Some(game) = Game::singleton() && let Some(team) = game.bind().get_team(self.team) { - mat.set_shader_parameter("goal_color", &team.bind().color.to_variant()); + mat.set_shader_parameter("goal_color", &team.bind().color().to_variant()); } else if let Some(playback) = &StandaloneReplayManager::singleton().bind().playback && let Some(team) = playback.bind().replay.teams.get(self.team as usize) { diff --git a/rust/src/lobby_world.rs b/rust/src/lobby_world.rs index 24b8208..06a4674 100644 --- a/rust/src/lobby_world.rs +++ b/rust/src/lobby_world.rs @@ -2,13 +2,15 @@ use std::{collections::HashMap, f32::consts::PI}; use godot::{classes::RandomNumberGenerator, prelude::*}; -use crate::{game::Game, player::menu_player::MenuPlayer}; +use crate::{game::Game, player::menu_player::MenuPlayer, ui::lobby::LobbyPanel}; #[derive(GodotClass)] #[class(base=Node3D, init)] pub struct LobbyWorld { #[export] menu_player_scene: Option>, + #[export] + lobby: Option>, rng: Gd, @@ -35,6 +37,13 @@ impl INode3D for LobbyWorld { .on_players_updated() .connect_other(self, Self::update_players); } + + if let Some(lobby) = &self.lobby { + lobby + .signals() + .on_alt_colors_changed() + .connect_other(self, |s| s.update_players()); + } } } diff --git a/rust/src/map.rs b/rust/src/map.rs index f0c51c3..0a87d0f 100644 --- a/rust/src/map.rs +++ b/rust/src/map.rs @@ -87,7 +87,7 @@ impl Map { && let Some(team) = game.bind().get_team(player.data.team) { node_clone.bind_mut().player_name = player.data.name.clone(); - node_clone.bind_mut().player_color = team.bind().color.clone(); + node_clone.bind_mut().player_color = team.bind().color().clone(); } }); } diff --git a/rust/src/player/local_player.rs b/rust/src/player/local_player.rs index 028b8d4..2fce198 100644 --- a/rust/src/player/local_player.rs +++ b/rust/src/player/local_player.rs @@ -459,7 +459,7 @@ impl ICharacterBody3D for LocalPlayer { && let Some(team) = game.bind().get_team(player.data.team) { if let Some(mesh) = &mut s.soldier_mesh { - mesh.bind_mut().set_color(team.bind().color); + mesh.bind_mut().set_color(team.bind().color()); } } }); diff --git a/rust/src/player/menu_player.rs b/rust/src/player/menu_player.rs index c64412a..935a6ad 100644 --- a/rust/src/player/menu_player.rs +++ b/rust/src/player/menu_player.rs @@ -42,10 +42,10 @@ impl MenuPlayer { { if let Some(name_label) = &mut self.name_label { name_label.set_text(&player.data.name); - name_label.set_modulate(team.bind().color); + name_label.set_modulate(team.bind().color()); } if let Some(mesh) = &mut self.mesh { - mesh.bind_mut().set_color(team.bind().color); + mesh.bind_mut().set_color(team.bind().color()); } } } diff --git a/rust/src/replay.rs b/rust/src/replay.rs index 687b7a9..469f2ee 100644 --- a/rust/src/replay.rs +++ b/rust/src/replay.rs @@ -525,7 +525,7 @@ impl INode for ReplayRecorder { ReplayPlayer { id: player.id(), name: player.data.name.clone(), - color: team.bind().color.into(), + color: team.bind().color().into(), team: player.data.team, stats: Default::default(), }, @@ -539,7 +539,7 @@ impl INode for ReplayRecorder { .iter_shared() .map(|t| ReplayTeam { name: t.bind().name.to_string(), - color: t.bind().color.into(), + color: t.bind().color().into(), }) .collect(); } diff --git a/rust/src/team_resource.rs b/rust/src/team_resource.rs index 45841dd..69e0806 100644 --- a/rust/src/team_resource.rs +++ b/rust/src/team_resource.rs @@ -1,15 +1,37 @@ use godot::prelude::*; +use crate::game::{Game, opts::PrivateGameOptions}; + #[derive(GodotClass)] #[class(base=Resource, init, tool)] pub struct TeamResource { #[export] pub name: GString, #[export] - pub color: Color, + pub primary_color: Color, + #[export] + pub alt_color: Color, base: Base, } #[godot_api] impl IResource for TeamResource {} + +impl TeamResource { + pub fn color_from(&self, opts: &PrivateGameOptions) -> Color { + match opts.use_alternate_team_colors { + true => self.alt_color, + false => self.primary_color, + } + } + + pub fn color(&self) -> Color { + godot_print!("Fetching color"); + if let Some(game) = Game::singleton() { + self.color_from(&game.bind().private_opts) + } else { + self.primary_color + } + } +} diff --git a/rust/src/ui/game_finished_screen.rs b/rust/src/ui/game_finished_screen.rs index 045a5cf..dab6f3a 100644 --- a/rust/src/ui/game_finished_screen.rs +++ b/rust/src/ui/game_finished_screen.rs @@ -101,7 +101,7 @@ impl GameFinishedScreen { for (idx, team) in winning_teams.iter().enumerate() { let mut label = Label::new_alloc(); label.set_text(&team.bind().name); - label.set_modulate(team.bind().color); + label.set_modulate(team.bind().color()); if idx > 0 { let mut and_label = Label::new_alloc(); and_label.set_text(" and "); diff --git a/rust/src/ui/lobby.rs b/rust/src/ui/lobby.rs index d5b43fb..43456f0 100644 --- a/rust/src/ui/lobby.rs +++ b/rust/src/ui/lobby.rs @@ -14,6 +14,7 @@ use crate::{ Game, GameManager, opts::{GameOption, GameOptionValue, GameOptions}, }, + lobby_world::LobbyWorld, net::network_manager::{NetworkManager, Package, PeerKind}, ui::lobby_player_listing::LobbyPlayerListing, }; @@ -96,6 +97,8 @@ impl IPanel for LobbyPanel { if let Some(alt_colors) = &s.alt_colors { s.use_alt_colors_changed(alt_colors.is_pressed()); } + s.update_players(false); + s.signals().on_alt_colors_changed().emit(); }); } @@ -245,6 +248,9 @@ impl IPanel for LobbyPanel { #[godot_api] impl LobbyPanel { + #[signal] + pub fn on_alt_colors_changed(); + #[func] fn open_options(&mut self) { if let Some(panel) = &mut self.options_panel { diff --git a/rust/src/ui/lobby_player_listing.rs b/rust/src/ui/lobby_player_listing.rs index ce7476b..1a95543 100644 --- a/rust/src/ui/lobby_player_listing.rs +++ b/rust/src/ui/lobby_player_listing.rs @@ -91,7 +91,7 @@ impl LobbyPlayerListing { )); if let Some(team) = game.bind().get_team(player.data.team) { - player_label.add_theme_color_override("font_color", team.bind().color); + player_label.add_theme_color_override("font_color", team.bind().color()); } } @@ -133,7 +133,7 @@ impl LobbyPlayerListing { && let Some(player_label) = &mut self.name_label && let Some(team) = game.bind().get_team(player.data.team) { - player_label.add_theme_color_override("font_color", team.bind().color); + player_label.add_theme_color_override("font_color", team.bind().color()); } } } @@ -148,7 +148,7 @@ impl LobbyPlayerListing { && let Some(player_label) = &mut self.name_label && let Some(team) = game.bind().get_team(player.data.team) { - player_label.add_theme_color_override("font_color", team.bind().color); + player_label.add_theme_color_override("font_color", team.bind().color()); } } } diff --git a/rust/src/ui/player_listings.rs b/rust/src/ui/player_listings.rs index 8cabb7c..9b0d200 100644 --- a/rust/src/ui/player_listings.rs +++ b/rust/src/ui/player_listings.rs @@ -52,7 +52,7 @@ impl PlayerListings { vbox.set_custom_minimum_size(Vector2::new(300., 0.)); let mut team_label = Label::new_alloc(); - team_label.set_modulate(team.bind().color); + team_label.set_modulate(team.bind().color()); team_label.set_text(&team.bind().name); team_label.set_horizontal_alignment(HorizontalAlignment::CENTER); vbox.add_child(&team_label); diff --git a/rust/src/ui/simple_score_view.rs b/rust/src/ui/simple_score_view.rs index 32dda55..7d9fcdc 100644 --- a/rust/src/ui/simple_score_view.rs +++ b/rust/src/ui/simple_score_view.rs @@ -21,7 +21,7 @@ impl IHBoxContainer for SimpleScoreView { if let Some(game) = Game::singleton() { for (id, team) in game.bind().get_teams().iter_shared().enumerate() { let mut goals_label = Label::new_alloc(); - goals_label.set_modulate(team.bind().color); + goals_label.set_modulate(team.bind().color()); goals_label.set_text("0"); if !s.team_goals.is_empty() { let mut dash = Label::new_alloc();