Add goals needed to win option
This commit is contained in:
parent
15a898b477
commit
ffa3f3166c
@ -111,6 +111,7 @@ impl Default for GameOptions {
|
|||||||
opts.insert(GameOption::AllowAnyMap, GameOptionValue::Boolean(false));
|
opts.insert(GameOption::AllowAnyMap, GameOptionValue::Boolean(false));
|
||||||
opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false));
|
opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false));
|
||||||
opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true));
|
opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true));
|
||||||
|
opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(10.));
|
||||||
Self { values: opts }
|
Self { values: opts }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,6 +138,8 @@ pub enum GameOption {
|
|||||||
AllowAnyTeam,
|
AllowAnyTeam,
|
||||||
/// Allow anyone to shoot anyone, not just other team's members
|
/// Allow anyone to shoot anyone, not just other team's members
|
||||||
FriendlyFire,
|
FriendlyFire,
|
||||||
|
/// The number of goals needed to win a match
|
||||||
|
GoalsNeededToWin,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for GameOption {
|
impl ToString for GameOption {
|
||||||
@ -145,6 +148,7 @@ impl ToString for GameOption {
|
|||||||
GameOption::AllowAnyMap => "Allow anyone to select the map",
|
GameOption::AllowAnyMap => "Allow anyone to select the map",
|
||||||
GameOption::AllowAnyTeam => "Allow anyone to select any teams",
|
GameOption::AllowAnyTeam => "Allow anyone to select any teams",
|
||||||
GameOption::FriendlyFire => "Friendly fire",
|
GameOption::FriendlyFire => "Friendly fire",
|
||||||
|
GameOption::GoalsNeededToWin => "Goals needed to win",
|
||||||
}
|
}
|
||||||
.to_owned()
|
.to_owned()
|
||||||
}
|
}
|
||||||
@ -153,6 +157,7 @@ impl ToString for GameOption {
|
|||||||
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
|
||||||
pub enum GameOptionValue {
|
pub enum GameOptionValue {
|
||||||
Boolean(bool),
|
Boolean(bool),
|
||||||
|
Number(f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
@ -599,7 +604,16 @@ impl Game {
|
|||||||
}
|
}
|
||||||
if NetworkManager::singleton().bind().is_host() {
|
if NetworkManager::singleton().bind().is_host() {
|
||||||
let max_goals = s.goals.values().max().copied().unwrap_or(0);
|
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();
|
s.finish_game();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,8 +2,8 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use godot::{
|
use godot::{
|
||||||
classes::{
|
classes::{
|
||||||
Button, CheckBox, Control, GridContainer, IPanel, Label, OptionButton, Panel, TextEdit,
|
Button, CheckBox, Control, GridContainer, IPanel, Label, OptionButton, Panel, SpinBox,
|
||||||
VBoxContainer,
|
TextEdit, VBoxContainer,
|
||||||
},
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
@ -162,6 +162,22 @@ impl IPanel for LobbyPanel {
|
|||||||
|
|
||||||
checkbox.upcast::<Control>()
|
checkbox.upcast::<Control>()
|
||||||
}
|
}
|
||||||
|
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);
|
nodes.push(value_node);
|
||||||
}
|
}
|
||||||
@ -209,6 +225,11 @@ impl LobbyPanel {
|
|||||||
checkbox.set_pressed(*value);
|
checkbox.set_pressed(*value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GameOptionValue::Number(value) => {
|
||||||
|
if let Ok(mut spinbox) = control.try_cast::<SpinBox>() {
|
||||||
|
spinbox.set_value(*value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user