mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add baby steps for audio device choice support
Former-commit-id: 8c1d623b2a28997e7705ba2775b382b38e9a34ed
This commit is contained in:
parent
7cfd3ad1cd
commit
50fc7549b9
@ -92,6 +92,7 @@ pub enum Event {
|
|||||||
SendMessage(String),
|
SendMessage(String),
|
||||||
AdjustViewDistance(u32),
|
AdjustViewDistance(u32),
|
||||||
AdjustVolume(f32),
|
AdjustVolume(f32),
|
||||||
|
ChangeAudioDevice(String),
|
||||||
Logout,
|
Logout,
|
||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
@ -212,10 +213,13 @@ pub struct Hud {
|
|||||||
// TODO: move to settings
|
// TODO: move to settings
|
||||||
current_vd: u32,
|
current_vd: u32,
|
||||||
current_volume: f32,
|
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()));
|
||||||
@ -385,6 +389,8 @@ impl Hud {
|
|||||||
&self.fonts,
|
&self.fonts,
|
||||||
self.current_vd,
|
self.current_vd,
|
||||||
self.current_volume,
|
self.current_volume,
|
||||||
|
self.audio_devices,
|
||||||
|
self.current_audio_device,
|
||||||
)
|
)
|
||||||
.set(self.ids.settings_window, ui_widgets)
|
.set(self.ids.settings_window, ui_widgets)
|
||||||
{
|
{
|
||||||
@ -403,6 +409,10 @@ impl Hud {
|
|||||||
self.current_volume = volume;
|
self.current_volume = volume;
|
||||||
events.push(Event::AdjustVolume(volume));
|
events.push(Event::AdjustVolume(volume));
|
||||||
}
|
}
|
||||||
|
settings_window::Event::ChangeAudioDevice(name) => {
|
||||||
|
self.current_audio_device = name;
|
||||||
|
events.push(Event::ChangeAudioDevice(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
color,
|
color,
|
||||||
widget::{self, Button, Image, Rectangle, Scrollbar, Text},
|
widget::{self, Button, Image, List, Rectangle, Scrollbar, Text},
|
||||||
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
};
|
};
|
||||||
widget_ids! {
|
widget_ids! {
|
||||||
@ -45,6 +45,8 @@ widget_ids! {
|
|||||||
vd_slider_text,
|
vd_slider_text,
|
||||||
audio_volume_slider,
|
audio_volume_slider,
|
||||||
audio_volume_text,
|
audio_volume_text,
|
||||||
|
audio_device_list,
|
||||||
|
audio_device_text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +67,8 @@ pub struct SettingsWindow<'a> {
|
|||||||
|
|
||||||
current_vd: u32,
|
current_vd: u32,
|
||||||
current_volume: f32,
|
current_volume: f32,
|
||||||
|
audio_devices: Vec<String>,
|
||||||
|
current_audio_device: String,
|
||||||
|
|
||||||
#[conrod(common_builder)]
|
#[conrod(common_builder)]
|
||||||
common: widget::CommonBuilder,
|
common: widget::CommonBuilder,
|
||||||
@ -77,6 +81,8 @@ impl<'a> SettingsWindow<'a> {
|
|||||||
fonts: &'a Fonts,
|
fonts: &'a Fonts,
|
||||||
current_vd: u32,
|
current_vd: u32,
|
||||||
current_volume: f32,
|
current_volume: f32,
|
||||||
|
audio_devices: Vec<String>,
|
||||||
|
current_audio_device: String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
show,
|
show,
|
||||||
@ -84,6 +90,8 @@ impl<'a> SettingsWindow<'a> {
|
|||||||
fonts,
|
fonts,
|
||||||
current_vd,
|
current_vd,
|
||||||
current_volume,
|
current_volume,
|
||||||
|
audio_devices,
|
||||||
|
current_audio_device,
|
||||||
common: widget::CommonBuilder::default(),
|
common: widget::CommonBuilder::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,6 +110,7 @@ pub enum Event {
|
|||||||
Close,
|
Close,
|
||||||
AdjustViewDistance(u32),
|
AdjustViewDistance(u32),
|
||||||
AdjustVolume(f32),
|
AdjustVolume(f32),
|
||||||
|
ChangeAudioDevice(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for SettingsWindow<'a> {
|
impl<'a> Widget for SettingsWindow<'a> {
|
||||||
@ -535,6 +544,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
}
|
}
|
||||||
// Contents
|
// Contents
|
||||||
if let SettingsTab::Sound = state.settings_tab {
|
if let SettingsTab::Sound = state.settings_tab {
|
||||||
|
// Volume Slider ----------------------------------------------------
|
||||||
Text::new("Volume")
|
Text::new("Volume")
|
||||||
.top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0)
|
.top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0)
|
||||||
.font_size(14)
|
.font_size(14)
|
||||||
@ -558,6 +568,63 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
{
|
{
|
||||||
events.push(Event::AdjustVolume(new_val));
|
events.push(Event::AdjustVolume(new_val));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Audio Device Selector --------------------------------------------
|
||||||
|
Text::new("Volume")
|
||||||
|
.down_from(state.ids.audio_volume_slider, 10.0)
|
||||||
|
.font_size(14)
|
||||||
|
.font_id(self.fonts.opensans)
|
||||||
|
.color(TEXT_COLOR)
|
||||||
|
.set(state.ids.audio_device_text, ui);
|
||||||
|
|
||||||
|
// TODO: Draw scroll bar or remove it.
|
||||||
|
let (mut items, scrollbar) = List::flow_down(self.audio_devices.len())
|
||||||
|
.down_from(state.ids.audio_device_text, 10.0)
|
||||||
|
.w_h(400.0, 300.0)
|
||||||
|
.scrollbar_next_to()
|
||||||
|
.scrollbar_thickness(18.0)
|
||||||
|
.scrollbar_color(TEXT_COLOR)
|
||||||
|
.set(state.ids.audio_device_list, ui);
|
||||||
|
|
||||||
|
while let Some(item) = items.next(ui) {
|
||||||
|
let mut text = "".to_string();
|
||||||
|
if &self.audio_devices[item.i] == &self.current_audio_device {
|
||||||
|
text.push_str("* ")
|
||||||
|
} else {
|
||||||
|
text.push_str(" ")
|
||||||
|
}
|
||||||
|
text.push_str(&self.audio_devices[item.i]);
|
||||||
|
|
||||||
|
// TODO: Use buttons to allow changing audio devices
|
||||||
|
item.set(
|
||||||
|
Text::new(&text)
|
||||||
|
.down_from(state.ids.audio_device_text, 10.0)
|
||||||
|
.font_size(14)
|
||||||
|
.font_id(self.fonts.opensans)
|
||||||
|
.color(TEXT_COLOR),
|
||||||
|
ui,
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if item
|
||||||
|
.set(
|
||||||
|
Button::image(self.imgs.button)
|
||||||
|
.w_h(100.0, 53.0)
|
||||||
|
.mid_bottom_with_margin_on(self.ids.servers_frame, 5.0)
|
||||||
|
.hover_image(self.imgs.button_hover)
|
||||||
|
.press_image(self.imgs.button_press)
|
||||||
|
.label_y(Relative::Scalar(2.0))
|
||||||
|
.label(&text)
|
||||||
|
.label_font_size(20)
|
||||||
|
.label_color(TEXT_COLOR),
|
||||||
|
ui,
|
||||||
|
)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
events.push(Event::ChangeAudioDevice(self.audio_devices[item.i]));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
events
|
events
|
||||||
|
Loading…
Reference in New Issue
Block a user