From ffa3f3166cbf5c2f3f2f5630405b53218a008b94 Mon Sep 17 00:00:00 2001 From: Sofia Date: Wed, 22 Jul 2026 21:56:00 +0300 Subject: [PATCH] Add goals needed to win option --- rust/src/game_manager.rs | 16 +++++++++++++++- rust/src/ui/lobby.rs | 25 +++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index fe76c7e..0232414 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -111,6 +111,7 @@ impl Default for GameOptions { opts.insert(GameOption::AllowAnyMap, GameOptionValue::Boolean(false)); opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false)); opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true)); + opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(10.)); Self { values: opts } } } @@ -137,6 +138,8 @@ pub enum GameOption { AllowAnyTeam, /// Allow anyone to shoot anyone, not just other team's members FriendlyFire, + /// The number of goals needed to win a match + GoalsNeededToWin, } impl ToString for GameOption { @@ -145,6 +148,7 @@ impl ToString for GameOption { GameOption::AllowAnyMap => "Allow anyone to select the map", GameOption::AllowAnyTeam => "Allow anyone to select any teams", GameOption::FriendlyFire => "Friendly fire", + GameOption::GoalsNeededToWin => "Goals needed to win", } .to_owned() } @@ -153,6 +157,7 @@ impl ToString for GameOption { #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub enum GameOptionValue { Boolean(bool), + Number(f64), } #[derive(GodotClass)] @@ -599,7 +604,16 @@ impl Game { } if NetworkManager::singleton().bind().is_host() { let max_goals = s.goals.values().max().copied().unwrap_or(0); - if max_goals >= 1 { + let needed_goals = match s + .opts + .values + .get(&GameOption::GoalsNeededToWin) + .unwrap_or(&&GameOptionValue::Number(10.)) + { + GameOptionValue::Boolean(_) => 10, + GameOptionValue::Number(value) => *value as u16, + }; + if max_goals >= needed_goals { s.finish_game(); } } diff --git a/rust/src/ui/lobby.rs b/rust/src/ui/lobby.rs index b45e75e..97e4aa7 100644 --- a/rust/src/ui/lobby.rs +++ b/rust/src/ui/lobby.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use godot::{ classes::{ - Button, CheckBox, Control, GridContainer, IPanel, Label, OptionButton, Panel, TextEdit, - VBoxContainer, + Button, CheckBox, Control, GridContainer, IPanel, Label, OptionButton, Panel, SpinBox, + TextEdit, VBoxContainer, }, prelude::*, }; @@ -162,6 +162,22 @@ impl IPanel for LobbyPanel { checkbox.upcast::() } + GameOptionValue::Number(value) => { + let mut spinbox = SpinBox::new_alloc(); + spinbox.set_value(*value); + spinbox.set_editable(NetworkManager::singleton().bind().is_host()); + + let spinbox_clone = spinbox.clone(); + let option = option.clone(); + spinbox.signals().changed().connect_other(self, move |s| { + s.option_changed( + option, + GameOptionValue::Number(spinbox_clone.get_value()), + ); + }); + + spinbox.upcast() + } }; nodes.push(value_node); } @@ -209,6 +225,11 @@ impl LobbyPanel { checkbox.set_pressed(*value); } } + GameOptionValue::Number(value) => { + if let Ok(mut spinbox) = control.try_cast::() { + spinbox.set_value(*value); + } + } } } }