Add default name config
This commit is contained in:
parent
407c8fc2d5
commit
8936f0ca24
@ -10,11 +10,15 @@ pub const NETWORK_SINGLETON_NAME: &str = "GameSettingsGlobal";
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct GameSettings {
|
||||
pub fov: f64,
|
||||
pub default_name: String,
|
||||
}
|
||||
|
||||
impl Default for GameSettings {
|
||||
fn default() -> Self {
|
||||
Self { fov: 90. }
|
||||
Self {
|
||||
fov: 90.,
|
||||
default_name: "Default McGee".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use godot::{
|
||||
classes::{Control, GridContainer, IPanel, Label, Panel, control::SizeFlags},
|
||||
classes::{Control, GridContainer, IPanel, Label, Panel, TextEdit, control::SizeFlags},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
@ -13,20 +13,23 @@ use crate::{
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Hash)]
|
||||
pub enum Setting {
|
||||
FoV,
|
||||
DefaultName,
|
||||
}
|
||||
|
||||
impl ToString for Setting {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Setting::FoV => "Field of View",
|
||||
Setting::DefaultName => "Default Name",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone)]
|
||||
pub enum SettingValue {
|
||||
SliderNumber(SliderValue),
|
||||
String(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@ -62,6 +65,10 @@ impl IPanel for SettingsPanel {
|
||||
value: settings.fov,
|
||||
}),
|
||||
);
|
||||
self.settings.insert(
|
||||
Setting::DefaultName,
|
||||
SettingValue::String(settings.default_name.clone()),
|
||||
);
|
||||
|
||||
if let Some(mut grid) = self.settings_grid.clone() {
|
||||
for (setting, value) in &self.settings {
|
||||
@ -98,6 +105,27 @@ impl IPanel for SettingsPanel {
|
||||
|
||||
slider.upcast::<Control>()
|
||||
}
|
||||
SettingValue::String(value) => {
|
||||
let mut text_edit = TextEdit::new_alloc();
|
||||
text_edit.set_custom_minimum_size(Vector2::new(100., -1.));
|
||||
text_edit.set_text(value);
|
||||
|
||||
let setting_clone = setting.clone();
|
||||
let text_edit_clone = text_edit.clone();
|
||||
text_edit
|
||||
.signals()
|
||||
.text_changed()
|
||||
.connect_other(self, move |s| {
|
||||
s.on_change(
|
||||
setting_clone,
|
||||
SettingValue::String(
|
||||
text_edit_clone.get_text().to_string(),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
text_edit.upcast()
|
||||
}
|
||||
};
|
||||
|
||||
grid.add_child(&node);
|
||||
@ -118,6 +146,10 @@ impl SettingsPanel {
|
||||
(Setting::FoV, SettingValue::SliderNumber(value)) => {
|
||||
new_settings.fov = value.value;
|
||||
}
|
||||
(Setting::DefaultName, SettingValue::String(value)) => {
|
||||
new_settings.default_name = value.clone()
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
GameSettingsManager::singleton()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user