mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Continue implementing audio device selection
Former-commit-id: 6b92cbdb2e93653f43c0ed4d04e1b8fc35cfe8cf
This commit is contained in:
@ -210,16 +210,10 @@ pub struct Hud {
|
|||||||
to_focus: Option<Option<widget::Id>>,
|
to_focus: Option<Option<widget::Id>>,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
force_ungrab: bool,
|
force_ungrab: bool,
|
||||||
// TODO: move to settings
|
|
||||||
current_vd: u32,
|
|
||||||
current_volume: f32,
|
|
||||||
audio_devices: Vec<String>,
|
|
||||||
current_audio_device: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hud {
|
impl Hud {
|
||||||
pub fn new(window: &mut Window, settings: Settings) -> Self {
|
pub fn new(window: &mut Window, settings: Settings) -> Self {
|
||||||
let settings = global_state.settings;
|
|
||||||
let mut ui = Ui::new(window).unwrap();
|
let mut ui = Ui::new(window).unwrap();
|
||||||
// TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality.
|
// TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality.
|
||||||
ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into()));
|
ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into()));
|
||||||
@ -252,8 +246,6 @@ impl Hud {
|
|||||||
to_focus: None,
|
to_focus: None,
|
||||||
settings,
|
settings,
|
||||||
force_ungrab: false,
|
force_ungrab: false,
|
||||||
current_vd: 5,
|
|
||||||
current_volume: 0.5,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,16 +375,8 @@ impl Hud {
|
|||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
if let Windows::Settings = self.show.open_windows {
|
if let Windows::Settings = self.show.open_windows {
|
||||||
for event in SettingsWindow::new(
|
for event in SettingsWindow::new(&self.show, &self.imgs, &self.fonts, &self.settings)
|
||||||
&self.show,
|
.set(self.ids.settings_window, ui_widgets)
|
||||||
&self.imgs,
|
|
||||||
&self.fonts,
|
|
||||||
self.current_vd,
|
|
||||||
self.current_volume,
|
|
||||||
self.audio_devices,
|
|
||||||
self.current_audio_device,
|
|
||||||
)
|
|
||||||
.set(self.ids.settings_window, ui_widgets)
|
|
||||||
{
|
{
|
||||||
match event {
|
match event {
|
||||||
settings_window::Event::ToggleHelp => self.show.toggle_help(),
|
settings_window::Event::ToggleHelp => self.show.toggle_help(),
|
||||||
@ -402,15 +386,15 @@ impl Hud {
|
|||||||
settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug,
|
settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug,
|
||||||
settings_window::Event::Close => self.show.open_windows = Windows::None,
|
settings_window::Event::Close => self.show.open_windows = Windows::None,
|
||||||
settings_window::Event::AdjustViewDistance(view_distance) => {
|
settings_window::Event::AdjustViewDistance(view_distance) => {
|
||||||
self.current_vd = view_distance;
|
self.settings.graphics.view_distance = view_distance;
|
||||||
events.push(Event::AdjustViewDistance(view_distance));
|
events.push(Event::AdjustViewDistance(view_distance));
|
||||||
}
|
}
|
||||||
settings_window::Event::AdjustVolume(volume) => {
|
settings_window::Event::AdjustVolume(volume) => {
|
||||||
self.current_volume = volume;
|
self.settings.audio.music_volume = volume;
|
||||||
events.push(Event::AdjustVolume(volume));
|
events.push(Event::AdjustVolume(volume));
|
||||||
}
|
}
|
||||||
settings_window::Event::ChangeAudioDevice(name) => {
|
settings_window::Event::ChangeAudioDevice(name) => {
|
||||||
self.current_audio_device = name;
|
self.settings.audio.audio_device = name.clone();
|
||||||
events.push(Event::ChangeAudioDevice(name));
|
events.push(Event::ChangeAudioDevice(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ use crate::{
|
|||||||
ImageSlider, ScaleMode, ToggleButton, Ui,
|
ImageSlider, ScaleMode, ToggleButton, Ui,
|
||||||
},
|
},
|
||||||
window::Window,
|
window::Window,
|
||||||
|
Settings,
|
||||||
};
|
};
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
@ -65,33 +66,19 @@ pub struct SettingsWindow<'a> {
|
|||||||
imgs: &'a Imgs,
|
imgs: &'a Imgs,
|
||||||
fonts: &'a Fonts,
|
fonts: &'a Fonts,
|
||||||
|
|
||||||
current_vd: u32,
|
settings: &'a Settings,
|
||||||
current_volume: f32,
|
|
||||||
audio_devices: Vec<String>,
|
|
||||||
current_audio_device: String,
|
|
||||||
|
|
||||||
#[conrod(common_builder)]
|
#[conrod(common_builder)]
|
||||||
common: widget::CommonBuilder,
|
common: widget::CommonBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SettingsWindow<'a> {
|
impl<'a> SettingsWindow<'a> {
|
||||||
pub fn new(
|
pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts, settings: &'a Settings) -> Self {
|
||||||
show: &'a Show,
|
|
||||||
imgs: &'a Imgs,
|
|
||||||
fonts: &'a Fonts,
|
|
||||||
current_vd: u32,
|
|
||||||
current_volume: f32,
|
|
||||||
audio_devices: Vec<String>,
|
|
||||||
current_audio_device: String,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
show,
|
show,
|
||||||
imgs,
|
imgs,
|
||||||
fonts,
|
fonts,
|
||||||
current_vd,
|
settings,
|
||||||
current_volume,
|
|
||||||
audio_devices,
|
|
||||||
current_audio_device,
|
|
||||||
common: widget::CommonBuilder::default(),
|
common: widget::CommonBuilder::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -499,7 +486,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
.set(state.ids.vd_slider_text, ui);
|
.set(state.ids.vd_slider_text, ui);
|
||||||
|
|
||||||
if let Some(new_val) = ImageSlider::discrete(
|
if let Some(new_val) = ImageSlider::discrete(
|
||||||
self.current_vd,
|
self.settings.graphics.view_distance,
|
||||||
1,
|
1,
|
||||||
25,
|
25,
|
||||||
self.imgs.slider_indicator,
|
self.imgs.slider_indicator,
|
||||||
@ -553,7 +540,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
.set(state.ids.audio_volume_text, ui);
|
.set(state.ids.audio_volume_text, ui);
|
||||||
|
|
||||||
if let Some(new_val) = ImageSlider::continuous(
|
if let Some(new_val) = ImageSlider::continuous(
|
||||||
self.current_volume,
|
self.settings.audio.music_volume,
|
||||||
0.0,
|
0.0,
|
||||||
1.0,
|
1.0,
|
||||||
self.imgs.slider_indicator,
|
self.imgs.slider_indicator,
|
||||||
@ -578,7 +565,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
.set(state.ids.audio_device_text, ui);
|
.set(state.ids.audio_device_text, ui);
|
||||||
|
|
||||||
// TODO: Draw scroll bar or remove it.
|
// TODO: Draw scroll bar or remove it.
|
||||||
let (mut items, scrollbar) = List::flow_down(self.audio_devices.len())
|
let (mut items, scrollbar) = List::flow_down(self.settings.audio.audio_devices.len())
|
||||||
.down_from(state.ids.audio_device_text, 10.0)
|
.down_from(state.ids.audio_device_text, 10.0)
|
||||||
.w_h(400.0, 300.0)
|
.w_h(400.0, 300.0)
|
||||||
.scrollbar_next_to()
|
.scrollbar_next_to()
|
||||||
@ -588,12 +575,12 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
|
|
||||||
while let Some(item) = items.next(ui) {
|
while let Some(item) = items.next(ui) {
|
||||||
let mut text = "".to_string();
|
let mut text = "".to_string();
|
||||||
if &self.audio_devices[item.i] == &self.current_audio_device {
|
if &self.settings.audio.audio_devices[item.i] == &self.settings.audio.audio_device {
|
||||||
text.push_str("* ")
|
text.push_str("* ")
|
||||||
} else {
|
} else {
|
||||||
text.push_str(" ")
|
text.push_str(" ")
|
||||||
}
|
}
|
||||||
text.push_str(&self.audio_devices[item.i]);
|
text.push_str(&self.settings.audio.audio_devices[item.i]);
|
||||||
|
|
||||||
// TODO: Use buttons to allow changing audio devices
|
// TODO: Use buttons to allow changing audio devices
|
||||||
item.set(
|
item.set(
|
||||||
|
@ -166,7 +166,9 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Load volume from audio file
|
// Load volume from audio file
|
||||||
global_state.audio.set_volume(settings.audio.music_volume);
|
global_state
|
||||||
|
.audio
|
||||||
|
.set_volume(global_state.settings.audio.music_volume);
|
||||||
|
|
||||||
global_state.settings.audio.audio_devices = global_state.audio.get_devices();
|
global_state.settings.audio.audio_devices = global_state.audio.get_devices();
|
||||||
|
|
||||||
@ -175,7 +177,7 @@ fn main() {
|
|||||||
if global_state.settings.audio.audio_device != "" {
|
if global_state.settings.audio.audio_device != "" {
|
||||||
global_state
|
global_state
|
||||||
.audio
|
.audio
|
||||||
.set_device(global_state.settings.audio.audio_device);
|
.set_device(global_state.settings.audio.audio_device.clone());
|
||||||
} else {
|
} else {
|
||||||
global_state.settings.audio.audio_device = global_state.audio.get_device();
|
global_state.settings.audio.audio_device = global_state.audio.get_device();
|
||||||
global_state.settings.save_to_file();
|
global_state.settings.save_to_file();
|
||||||
|
@ -196,6 +196,9 @@ impl PlayState for SessionState {
|
|||||||
HudEvent::AdjustVolume(volume) => {
|
HudEvent::AdjustVolume(volume) => {
|
||||||
global_state.audio.set_volume(volume);
|
global_state.audio.set_volume(volume);
|
||||||
}
|
}
|
||||||
|
HudEvent::ChangeAudioDevice(name) => {
|
||||||
|
global_state.audio.set_device(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ pub struct Settings {
|
|||||||
pub controls: ControlSettings,
|
pub controls: ControlSettings,
|
||||||
pub networking: NetworkingSettings,
|
pub networking: NetworkingSettings,
|
||||||
pub log: Log,
|
pub log: Log,
|
||||||
|
pub graphics: GraphicsSettings,
|
||||||
pub audio: AudioSettings,
|
pub audio: AudioSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +54,11 @@ pub struct Log {
|
|||||||
pub file: PathBuf,
|
pub file: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct GraphicsSettings {
|
||||||
|
pub view_distance: u32,
|
||||||
|
}
|
||||||
|
|
||||||
/// AudioSettings controls the volume of different audio subsystems and which
|
/// AudioSettings controls the volume of different audio subsystems and which
|
||||||
/// which device is used.
|
/// which device is used.
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
@ -104,6 +110,7 @@ impl Default for Settings {
|
|||||||
log: Log {
|
log: Log {
|
||||||
file: "voxygen.log".into(),
|
file: "voxygen.log".into(),
|
||||||
},
|
},
|
||||||
|
graphics: GraphicsSettings { view_distance: 5 },
|
||||||
audio: AudioSettings {
|
audio: AudioSettings {
|
||||||
music_volume: 0.5,
|
music_volume: 0.5,
|
||||||
sfx_volume: 0.5,
|
sfx_volume: 0.5,
|
||||||
|
Reference in New Issue
Block a user