Add default name config
This commit is contained in:
parent
820a57f609
commit
812a3d69b1
@ -10,11 +10,15 @@ pub const NETWORK_SINGLETON_NAME: &str = "GameSettingsGlobal";
|
|||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct GameSettings {
|
pub struct GameSettings {
|
||||||
pub fov: f64,
|
pub fov: f64,
|
||||||
|
pub default_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GameSettings {
|
impl Default for GameSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { fov: 90. }
|
Self {
|
||||||
|
fov: 90.,
|
||||||
|
default_name: "Default McGee".to_owned(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use godot::{
|
use godot::{
|
||||||
classes::{Control, GridContainer, IPanel, Label, Panel, control::SizeFlags},
|
classes::{Control, GridContainer, IPanel, Label, Panel, TextEdit, control::SizeFlags},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -13,20 +13,23 @@ use crate::{
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Hash)]
|
||||||
pub enum Setting {
|
pub enum Setting {
|
||||||
FoV,
|
FoV,
|
||||||
|
DefaultName,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Setting {
|
impl ToString for Setting {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Setting::FoV => "Field of View",
|
Setting::FoV => "Field of View",
|
||||||
|
Setting::DefaultName => "Default Name",
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone)]
|
||||||
pub enum SettingValue {
|
pub enum SettingValue {
|
||||||
SliderNumber(SliderValue),
|
SliderNumber(SliderValue),
|
||||||
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
@ -62,6 +65,10 @@ impl IPanel for SettingsPanel {
|
|||||||
value: settings.fov,
|
value: settings.fov,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
self.settings.insert(
|
||||||
|
Setting::DefaultName,
|
||||||
|
SettingValue::String(settings.default_name.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
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 {
|
||||||
@ -98,6 +105,27 @@ impl IPanel for SettingsPanel {
|
|||||||
|
|
||||||
slider.upcast::<Control>()
|
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);
|
grid.add_child(&node);
|
||||||
@ -118,6 +146,10 @@ impl SettingsPanel {
|
|||||||
(Setting::FoV, SettingValue::SliderNumber(value)) => {
|
(Setting::FoV, SettingValue::SliderNumber(value)) => {
|
||||||
new_settings.fov = value.value;
|
new_settings.fov = value.value;
|
||||||
}
|
}
|
||||||
|
(Setting::DefaultName, SettingValue::String(value)) => {
|
||||||
|
new_settings.default_name = value.clone()
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameSettingsManager::singleton()
|
GameSettingsManager::singleton()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user