Add new settings
This commit is contained in:
parent
0d745a7789
commit
b6a4cd59bf
@ -17,38 +17,20 @@ offset_bottom = 112.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="label" type="Label" parent="." unique_id=2036746921]
|
|
||||||
layout_mode = 0
|
|
||||||
offset_left = 57.0
|
|
||||||
offset_right = 357.0
|
|
||||||
offset_bottom = 23.0
|
|
||||||
text = "Settings"
|
|
||||||
horizontal_alignment = 1
|
|
||||||
|
|
||||||
[node name="grid" type="GridContainer" parent="." unique_id=833231169]
|
[node name="grid" type="GridContainer" parent="." unique_id=833231169]
|
||||||
custom_minimum_size = Vector2(400, 0)
|
custom_minimum_size = Vector2(400, 0)
|
||||||
custom_maximum_size = Vector2(400, -1)
|
custom_maximum_size = Vector2(400, -1)
|
||||||
layout_mode = 1
|
layout_mode = 2
|
||||||
anchors_preset = 8
|
|
||||||
anchor_left = 0.5
|
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 0.5
|
|
||||||
anchor_bottom = 0.5
|
|
||||||
offset_left = -145.0
|
|
||||||
offset_top = -74.0
|
|
||||||
offset_right = 155.0
|
|
||||||
offset_bottom = 67.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
columns = 2
|
columns = 2
|
||||||
|
|
||||||
[node name="button" type="Button" parent="." unique_id=1301469030]
|
[node name="label" type="Label" parent="grid" unique_id=2036746921]
|
||||||
layout_mode = 0
|
layout_mode = 2
|
||||||
offset_left = 182.0
|
text = "Settings"
|
||||||
offset_top = 192.0
|
horizontal_alignment = 1
|
||||||
offset_right = 232.0
|
|
||||||
offset_bottom = 223.0
|
[node name="button" type="Button" parent="grid" unique_id=1301469030]
|
||||||
|
layout_mode = 2
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
text = "Close"
|
text = "Close"
|
||||||
|
|
||||||
[connection signal="pressed" from="button" to="." method="close"]
|
[connection signal="pressed" from="grid/button" to="." method="close"]
|
||||||
|
|||||||
@ -17,6 +17,15 @@ pub struct GameSettings {
|
|||||||
pub fov: f64,
|
pub fov: f64,
|
||||||
pub default_name: String,
|
pub default_name: String,
|
||||||
pub recent_servers: Vec<RecentServer>,
|
pub recent_servers: Vec<RecentServer>,
|
||||||
|
pub volume: VolumeSettings,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct VolumeSettings {
|
||||||
|
pub master_volume: f64,
|
||||||
|
pub sfx_volume: f64,
|
||||||
|
pub music_volume: f64,
|
||||||
|
pub announcer_volume: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
@ -31,6 +40,12 @@ impl Default for GameSettings {
|
|||||||
fov: 90.,
|
fov: 90.,
|
||||||
default_name: "Default McGee".to_owned(),
|
default_name: "Default McGee".to_owned(),
|
||||||
recent_servers: Vec::new(),
|
recent_servers: Vec::new(),
|
||||||
|
volume: VolumeSettings {
|
||||||
|
master_volume: 100.,
|
||||||
|
sfx_volume: 100.,
|
||||||
|
music_volume: 100.,
|
||||||
|
announcer_volume: 100.,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use godot::{
|
use godot::{
|
||||||
classes::{Control, GridContainer, IPanel, Label, LineEdit, Panel, control::SizeFlags},
|
classes::{
|
||||||
|
Control, GridContainer, IPanel, IPanelContainer, Label, LineEdit, Panel, PanelContainer,
|
||||||
|
control::SizeFlags,
|
||||||
|
},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -11,6 +14,10 @@ use crate::{game_settings::GameSettingsManager, ui::slider::SliderContainer};
|
|||||||
pub enum Setting {
|
pub enum Setting {
|
||||||
FoV,
|
FoV,
|
||||||
DefaultName,
|
DefaultName,
|
||||||
|
MasterVolume,
|
||||||
|
SfxVolume,
|
||||||
|
MusicVolume,
|
||||||
|
AnnouncerVolume,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Setting {
|
impl ToString for Setting {
|
||||||
@ -18,6 +25,10 @@ impl ToString for Setting {
|
|||||||
match self {
|
match self {
|
||||||
Setting::FoV => "Field of View",
|
Setting::FoV => "Field of View",
|
||||||
Setting::DefaultName => "Default Name",
|
Setting::DefaultName => "Default Name",
|
||||||
|
Setting::MasterVolume => "Master volume",
|
||||||
|
Setting::SfxVolume => "Sfx Volume",
|
||||||
|
Setting::MusicVolume => "Music Volume",
|
||||||
|
Setting::AnnouncerVolume => "Announcer Volume",
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
@ -37,7 +48,7 @@ pub struct SliderValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Panel, init)]
|
#[class(base=PanelContainer, init)]
|
||||||
pub struct SettingsPanel {
|
pub struct SettingsPanel {
|
||||||
#[export]
|
#[export]
|
||||||
settings_grid: Option<Gd<GridContainer>>,
|
settings_grid: Option<Gd<GridContainer>>,
|
||||||
@ -46,11 +57,11 @@ pub struct SettingsPanel {
|
|||||||
|
|
||||||
settings: HashMap<Setting, SettingValue>,
|
settings: HashMap<Setting, SettingValue>,
|
||||||
|
|
||||||
base: Base<Panel>,
|
base: Base<PanelContainer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[godot_api]
|
#[godot_api]
|
||||||
impl IPanel for SettingsPanel {
|
impl IPanelContainer for SettingsPanel {
|
||||||
fn ready(&mut self) {
|
fn ready(&mut self) {
|
||||||
let singleton = GameSettingsManager::singleton();
|
let singleton = GameSettingsManager::singleton();
|
||||||
let settings = &singleton.bind().settings;
|
let settings = &singleton.bind().settings;
|
||||||
@ -66,6 +77,38 @@ impl IPanel for SettingsPanel {
|
|||||||
Setting::DefaultName,
|
Setting::DefaultName,
|
||||||
SettingValue::String(settings.default_name.clone()),
|
SettingValue::String(settings.default_name.clone()),
|
||||||
);
|
);
|
||||||
|
self.settings.insert(
|
||||||
|
Setting::MasterVolume,
|
||||||
|
SettingValue::SliderNumber(SliderValue {
|
||||||
|
min: 0.,
|
||||||
|
max: 100.,
|
||||||
|
value: settings.volume.master_volume,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
self.settings.insert(
|
||||||
|
Setting::SfxVolume,
|
||||||
|
SettingValue::SliderNumber(SliderValue {
|
||||||
|
min: 0.,
|
||||||
|
max: 100.,
|
||||||
|
value: settings.volume.sfx_volume,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
self.settings.insert(
|
||||||
|
Setting::MusicVolume,
|
||||||
|
SettingValue::SliderNumber(SliderValue {
|
||||||
|
min: 0.,
|
||||||
|
max: 100.,
|
||||||
|
value: settings.volume.music_volume,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
self.settings.insert(
|
||||||
|
Setting::AnnouncerVolume,
|
||||||
|
SettingValue::SliderNumber(SliderValue {
|
||||||
|
min: 0.,
|
||||||
|
max: 100.,
|
||||||
|
value: settings.volume.announcer_volume,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(mut grid) = self.settings_grid.clone() {
|
if let Some(mut grid) = self.settings_grid.clone() {
|
||||||
for (setting, value) in &self.settings {
|
for (setting, value) in &self.settings {
|
||||||
@ -141,6 +184,18 @@ impl SettingsPanel {
|
|||||||
(Setting::DefaultName, SettingValue::String(value)) => {
|
(Setting::DefaultName, SettingValue::String(value)) => {
|
||||||
new_settings.default_name = value.clone()
|
new_settings.default_name = value.clone()
|
||||||
}
|
}
|
||||||
|
(Setting::MasterVolume, SettingValue::SliderNumber(value)) => {
|
||||||
|
new_settings.volume.master_volume = value.value;
|
||||||
|
}
|
||||||
|
(Setting::SfxVolume, SettingValue::SliderNumber(value)) => {
|
||||||
|
new_settings.volume.sfx_volume = value.value;
|
||||||
|
}
|
||||||
|
(Setting::MusicVolume, SettingValue::SliderNumber(value)) => {
|
||||||
|
new_settings.volume.music_volume = value.value;
|
||||||
|
}
|
||||||
|
(Setting::AnnouncerVolume, SettingValue::SliderNumber(value)) => {
|
||||||
|
new_settings.volume.announcer_volume = value.value;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user