veloren/voxygen/src/hud/settings_window.rs

1074 lines
36 KiB
Rust
Raw Normal View History

2019-07-23 01:02:57 +00:00
use super::{img_ids::Imgs, CrosshairType, Fonts, Show, TEXT_COLOR};
use crate::{
audio::base::Genre,
2019-07-26 02:28:53 +00:00
ui::{ImageSlider, ScaleMode, ToggleButton},
GlobalState,
};
use conrod_core::{
color,
widget::{self, Button, DropDownList, Image, Rectangle, Scrollbar, Text},
2019-07-23 01:02:57 +00:00
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
};
2019-06-06 19:11:39 +00:00
const FPS_CHOICES: [u32; 11] = [15, 30, 40, 50, 60, 90, 120, 144, 240, 300, 500];
2019-06-06 19:11:39 +00:00
widget_ids! {
struct Ids {
settings_content,
settings_icon,
settings_button_mo,
settings_close,
settings_title,
settings_r,
settings_l,
settings_scrollbar,
controls_text,
controls_controls,
button_help,
button_help2,
show_help_label,
2019-07-26 02:28:53 +00:00
ui_scale_label,
ui_scale_slider,
2019-07-26 16:34:00 +00:00
ui_scale_slider_2,
2019-07-26 02:28:53 +00:00
ui_scale_button,
2019-07-26 07:56:57 +00:00
ui_scale_value,
relative_to_win_button,
relative_to_win_text,
absolute_scale_button,
absolute_scale_text,
gameplay,
controls,
rectangle,
2019-07-23 01:02:57 +00:00
general_txt,
debug_button,
debug_button_label,
interface,
inventory_test_button,
inventory_test_button_label,
mouse_pan_slider,
mouse_pan_label,
mouse_pan_value,
mouse_zoom_slider,
mouse_zoom_label,
mouse_zoom_value,
2019-07-23 01:02:57 +00:00
ch_title,
2019-07-07 00:15:22 +00:00
ch_transp_slider,
ch_transp_label,
ch_transp_value,
ch_transp_text,
2019-07-23 01:02:57 +00:00
ch_1_bg,
ch_2_bg,
ch_3_bg,
crosshair_outer_1,
crosshair_inner_1,
crosshair_outer_2,
crosshair_inner_2,
crosshair_outer_3,
crosshair_inner_3,
settings_bg,
sound,
test,
video,
vd_slider,
2019-06-06 19:11:39 +00:00
vd_text,
vd_value,
2019-06-06 17:54:11 +00:00
max_fps_slider,
max_fps_text,
max_fps_value,
audio_volume_slider,
audio_volume_text,
audio_device_list,
audio_device_text,
}
}
pub enum SettingsTab {
Interface,
Video,
Sound,
Gameplay,
Controls,
}
#[derive(WidgetCommon)]
pub struct SettingsWindow<'a> {
global_state: &'a GlobalState,
show: &'a Show,
imgs: &'a Imgs,
2019-07-26 21:05:39 +00:00
fonts: &'a Fonts,
2019-07-26 07:56:57 +00:00
#[conrod(common_builder)]
common: widget::CommonBuilder,
}
impl<'a> SettingsWindow<'a> {
pub fn new(
global_state: &'a GlobalState,
show: &'a Show,
imgs: &'a Imgs,
2019-07-27 17:06:25 +00:00
fonts: &'a Fonts,
) -> Self {
Self {
global_state,
show,
imgs,
fonts,
2019-07-26 21:05:39 +00:00
common: widget::CommonBuilder::default(),
}
}
}
pub struct State {
ids: Ids,
}
pub enum Event {
ToggleHelp,
ToggleInventoryTestButton,
ToggleDebug,
ChangeTab(SettingsTab),
Close,
AdjustMousePan(u32),
AdjustMouseZoom(u32),
AdjustViewDistance(u32),
AdjustVolume(f32),
ChangeAudioDevice(String),
2019-06-06 17:54:11 +00:00
MaximumFPS(u32),
2019-07-07 00:15:22 +00:00
CrosshairTransp(f32),
2019-07-23 01:02:57 +00:00
CrosshairType(CrosshairType),
2019-07-26 02:28:53 +00:00
UiScale(ScaleChange),
}
pub enum ScaleChange {
ToAbsolute,
ToRelative,
Adjust(f64),
}
impl<'a> Widget for SettingsWindow<'a> {
type State = State;
type Style = ();
type Event = Vec<Event>;
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
State {
ids: Ids::new(id_gen),
}
}
fn style(&self) -> Self::Style {
()
}
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs { state, ui, .. } = args;
let mut events = Vec::new();
// Frame Alignment
Rectangle::fill_with([824.0, 488.0], color::TRANSPARENT)
.middle_of(ui.window)
.set(state.ids.settings_bg, ui);
// Frame
Image::new(self.imgs.settings_frame_l)
.top_left_with_margins_on(state.ids.settings_bg, 0.0, 0.0)
.w_h(412.0, 488.0)
.set(state.ids.settings_l, ui);
Image::new(self.imgs.settings_frame_r)
.right_from(state.ids.settings_l, 0.0)
.parent(state.ids.settings_bg)
.w_h(412.0, 488.0)
.set(state.ids.settings_r, ui);
// Content Alignment
Rectangle::fill_with([198.0 * 4.0, 97.0 * 4.0], color::TRANSPARENT)
.top_right_with_margins_on(state.ids.settings_r, 21.0 * 4.0, 4.0 * 4.0)
.scroll_kids()
.scroll_kids_vertically()
.set(state.ids.settings_content, ui);
Scrollbar::y_axis(state.ids.settings_content)
.thickness(5.0)
.rgba(0.33, 0.33, 0.33, 1.0)
.set(state.ids.settings_scrollbar, ui);
// X-Button
if Button::image(self.imgs.close_button)
.w_h(28.0, 28.0)
.hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press)
.top_right_with_margins_on(state.ids.settings_r, 0.0, 0.0)
.set(state.ids.settings_close, ui)
.was_clicked()
{
events.push(Event::Close);
}
// Title
Text::new("Settings")
.mid_top_with_margin_on(state.ids.settings_bg, 5.0)
.font_size(14)
.color(TEXT_COLOR)
.set(state.ids.settings_title, ui);
// 1) Interface Tab -------------------------------
if Button::image(if let SettingsTab::Interface = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button
})
.w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Interface = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_hover
})
.press_image(if let SettingsTab::Interface = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_press
})
.top_left_with_margins_on(state.ids.settings_l, 8.0 * 4.0, 2.0 * 4.0)
.label("Interface")
.label_font_size(14)
.label_color(TEXT_COLOR)
.set(state.ids.interface, ui)
.was_clicked()
{
events.push(Event::ChangeTab(SettingsTab::Interface));
}
// Contents
if let SettingsTab::Interface = self.show.settings_tab {
2019-07-23 01:02:57 +00:00
let crosshair_transp = self.global_state.settings.gameplay.crosshair_transp;
let crosshair_type = self.global_state.settings.gameplay.crosshair_type;
2019-07-26 21:05:39 +00:00
let ui_scale = self.global_state.settings.gameplay.ui_scale;
2019-07-23 01:02:57 +00:00
Text::new("General")
.top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0)
.font_size(18)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.general_txt, ui);
// Help
let show_help =
ToggleButton::new(self.show.help, self.imgs.check, self.imgs.check_checked)
.w_h(288.0 / 24.0, 288.0 / 24.0)
2019-07-23 01:02:57 +00:00
.down_from(state.ids.general_txt, 20.0)
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.press_images(self.imgs.check_press, self.imgs.check_press)
.set(state.ids.button_help, ui);
if self.show.help != show_help {
events.push(Event::ToggleHelp);
}
Text::new("Show Help")
.right_from(state.ids.button_help, 10.0)
2019-05-31 19:14:20 +00:00
.font_size(14)
.font_id(self.fonts.opensans)
.graphics_for(state.ids.button_help)
.color(TEXT_COLOR)
.set(state.ids.show_help_label, ui);
// Inventory test
let inventory_test_button = ToggleButton::new(
self.show.inventory_test_button,
self.imgs.check,
self.imgs.check_checked,
)
.w_h(288.0 / 24.0, 288.0 / 24.0)
.down_from(state.ids.button_help, 7.0)
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.press_images(self.imgs.check_press, self.imgs.check_press)
.set(state.ids.inventory_test_button, ui);
if self.show.inventory_test_button != inventory_test_button {
events.push(Event::ToggleInventoryTestButton);
}
Text::new("Show Inventory Test Button")
.right_from(state.ids.inventory_test_button, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.graphics_for(state.ids.inventory_test_button)
.color(TEXT_COLOR)
.set(state.ids.inventory_test_button_label, ui);
// Debug
let show_debug =
ToggleButton::new(self.show.debug, self.imgs.check, self.imgs.check_checked)
.w_h(288.0 / 24.0, 288.0 / 24.0)
.down_from(state.ids.inventory_test_button, 7.0)
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo)
.press_images(self.imgs.check_press, self.imgs.check_press)
.set(state.ids.debug_button, ui);
if self.show.debug != show_debug {
events.push(Event::ToggleDebug);
}
Text::new("Show Debug Window")
.right_from(state.ids.debug_button, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.graphics_for(state.ids.debug_button)
.color(TEXT_COLOR)
.set(state.ids.debug_button_label, ui);
2019-07-23 01:02:57 +00:00
2019-07-26 02:28:53 +00:00
// Ui Scale
2019-07-26 07:56:57 +00:00
Text::new("UI-Scale")
.down_from(state.ids.debug_button, 20.0)
.font_size(18)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.ui_scale_label, ui);
2019-07-26 16:34:00 +00:00
// Relative Scaling Button
2019-07-26 21:05:39 +00:00
if Button::image(match ui_scale {
2019-07-26 16:34:00 +00:00
ScaleMode::Absolute(_) => self.imgs.check,
ScaleMode::RelativeToWindow(_) => self.imgs.check_checked,
ScaleMode::DpiFactor => self.imgs.check_checked,
2019-07-26 21:05:39 +00:00
})
2019-07-26 16:34:00 +00:00
.w_h(288.0 / 24.0, 288.0 / 24.0)
.down_from(state.ids.ui_scale_label, 20.0)
2019-07-26 21:05:39 +00:00
.hover_image(match ui_scale {
2019-07-26 16:34:00 +00:00
ScaleMode::Absolute(_) => self.imgs.check_mo,
ScaleMode::RelativeToWindow(_) => self.imgs.check_checked,
ScaleMode::DpiFactor => self.imgs.check_checked,
2019-07-26 21:05:39 +00:00
})
.press_image(match ui_scale {
2019-07-26 16:34:00 +00:00
ScaleMode::Absolute(_) => self.imgs.check_press,
ScaleMode::RelativeToWindow(_) => self.imgs.check_checked,
ScaleMode::DpiFactor => self.imgs.check_checked,
2019-07-26 21:05:39 +00:00
})
2019-07-26 16:34:00 +00:00
.set(state.ids.relative_to_win_button, ui)
.was_clicked()
{
2019-07-26 21:05:39 +00:00
events.push(Event::UiScale(ScaleChange::ToRelative));
2019-07-26 02:28:53 +00:00
}
2019-07-26 16:34:00 +00:00
Text::new("Relative Scaling")
2019-07-26 07:56:57 +00:00
.right_from(state.ids.relative_to_win_button, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.graphics_for(state.ids.relative_to_win_button)
.color(TEXT_COLOR)
.set(state.ids.relative_to_win_text, ui);
2019-07-26 16:34:00 +00:00
// Absolute Scaling Button
2019-07-26 21:05:39 +00:00
if Button::image(match ui_scale {
2019-07-26 16:34:00 +00:00
ScaleMode::Absolute(_) => self.imgs.check_checked,
ScaleMode::RelativeToWindow(_) => self.imgs.check,
ScaleMode::DpiFactor => self.imgs.check,
2019-07-26 21:05:39 +00:00
})
2019-07-26 16:34:00 +00:00
.w_h(288.0 / 24.0, 288.0 / 24.0)
.down_from(state.ids.relative_to_win_button, 20.0)
2019-07-26 21:05:39 +00:00
.hover_image(match ui_scale {
2019-07-26 16:34:00 +00:00
ScaleMode::Absolute(_) => self.imgs.check_checked,
ScaleMode::RelativeToWindow(_) => self.imgs.check_mo,
ScaleMode::DpiFactor => self.imgs.check_mo,
2019-07-26 21:05:39 +00:00
})
.press_image(match ui_scale {
2019-07-26 16:34:00 +00:00
ScaleMode::Absolute(_) => self.imgs.check_checked,
ScaleMode::RelativeToWindow(_) => self.imgs.check_press,
ScaleMode::DpiFactor => self.imgs.check_press,
2019-07-26 21:05:39 +00:00
})
2019-07-26 16:34:00 +00:00
.set(state.ids.absolute_scale_button, ui)
.was_clicked()
{
2019-07-26 21:05:39 +00:00
events.push(Event::UiScale(ScaleChange::ToAbsolute));
2019-07-26 07:56:57 +00:00
}
2019-07-26 16:34:00 +00:00
Text::new("Custom Scaling")
2019-07-26 07:56:57 +00:00
.right_from(state.ids.absolute_scale_button, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.graphics_for(state.ids.absolute_scale_button)
.color(TEXT_COLOR)
.set(state.ids.absolute_scale_text, ui);
// Slider -> Inactive when "Relative to window" is selected
2019-07-26 02:28:53 +00:00
if let ScaleMode::Absolute(scale) = ui_scale {
if let Some(new_val) = ImageSlider::continuous(
scale.log(2.0),
2019-07-27 17:06:25 +00:00
0.5f64.log(2.0),
1.2f64.log(2.0),
2019-07-26 02:28:53 +00:00
self.imgs.slider_indicator,
self.imgs.slider,
)
2019-07-26 07:56:57 +00:00
.w_h(208.0, 22.0)
2019-07-27 17:06:25 +00:00
.right_from(state.ids.absolute_scale_text, 12.0)
2019-07-26 02:28:53 +00:00
.track_breadth(30.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.ui_scale_slider, ui)
{
events.push(Event::UiScale(ScaleChange::Adjust(2.0f64.powf(new_val))));
}
2019-07-26 21:05:39 +00:00
Text::new(&format!("{:.2}", scale))
.up_from(state.ids.ch_transp_value, 75.0)
2019-07-26 21:05:39 +00:00
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.ui_scale_value, ui);
2019-07-26 07:56:57 +00:00
} else {
if let Some(_val) =
ImageSlider::continuous(5.0, 0.0, 10.0, self.imgs.nothing, self.imgs.slider)
2019-07-26 21:05:39 +00:00
.w_h(210.0, 22.0)
2019-07-26 07:56:57 +00:00
.right_from(state.ids.absolute_scale_text, 10.0)
2019-07-26 16:34:00 +00:00
.track_breadth(12.0)
2019-07-26 07:56:57 +00:00
.slider_length(10.0)
2019-07-26 16:34:00 +00:00
.track_color(Color::Rgba(1.0, 1.0, 1.0, 0.2))
.slider_color(Color::Rgba(1.0, 1.0, 1.0, 0.2))
2019-07-26 07:56:57 +00:00
.pad_track((5.0, 5.0))
2019-07-26 16:34:00 +00:00
.set(state.ids.ui_scale_slider_2, ui)
2019-07-26 07:56:57 +00:00
{}
2019-07-26 02:28:53 +00:00
}
2019-07-23 01:02:57 +00:00
// Crosshair Options
// Crosshair Transparency
Text::new("Crosshair")
2019-07-26 07:56:57 +00:00
.down_from(state.ids.absolute_scale_button, 20.0)
2019-07-23 01:02:57 +00:00
.font_size(18)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.ch_title, ui);
if let Some(new_val) = ImageSlider::continuous(
crosshair_transp,
0.0,
1.0,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(104.0, 22.0)
.down_from(state.ids.ch_transp_text, 8.0)
.track_breadth(12.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.ch_transp_slider, ui)
{
events.push(Event::CrosshairTransp(new_val));
}
Text::new(&format!("{:.2}", crosshair_transp,))
.right_from(state.ids.ch_transp_slider, 8.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.ch_transp_value, ui);
Text::new("Transparency")
.right_from(state.ids.ch_3_bg, 20.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.ch_transp_text, ui);
// Crosshair Types
// Round
if Button::image(if let CrosshairType::Round = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg
})
.w_h(15.0 * 4.0, 15.0 * 4.0)
.hover_image(if let CrosshairType::Round = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg_hover
})
.press_image(if let CrosshairType::Round = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg_press
})
.down_from(state.ids.ch_title, 20.0)
.set(state.ids.ch_1_bg, ui)
.was_clicked()
{
events.push(Event::CrosshairType(CrosshairType::Round));
}
// Crosshair
Image::new(self.imgs.crosshair_outer_round)
.w_h(20.0 * 1.5, 20.0 * 1.5)
.middle_of(state.ids.ch_1_bg)
.color(Some(Color::Rgba(
1.0,
1.0,
1.0,
self.global_state.settings.gameplay.crosshair_transp,
)))
.graphics_for(state.ids.ch_1_bg)
.set(state.ids.crosshair_outer_1, ui);
Image::new(self.imgs.crosshair_inner)
.w_h(21.0 * 2.0, 21.0 * 2.0)
.middle_of(state.ids.crosshair_outer_1)
.color(Some(Color::Rgba(1.0, 1.0, 1.0, 0.6)))
.graphics_for(state.ids.ch_1_bg)
.set(state.ids.crosshair_inner_1, ui);
// Rounded Edges
if Button::image(if let CrosshairType::RoundEdges = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg
})
.w_h(15.0 * 4.0, 15.0 * 4.0)
.hover_image(if let CrosshairType::RoundEdges = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg_hover
})
.press_image(if let CrosshairType::RoundEdges = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg_press
})
.right_from(state.ids.ch_1_bg, 20.0)
.set(state.ids.ch_2_bg, ui)
.was_clicked()
{
events.push(Event::CrosshairType(CrosshairType::RoundEdges));
}
// Crosshair
Image::new(self.imgs.crosshair_outer_round_edges)
.w_h(21.0 * 1.5, 21.0 * 1.5)
.middle_of(state.ids.ch_2_bg)
.color(Some(Color::Rgba(
1.0,
1.0,
1.0,
self.global_state.settings.gameplay.crosshair_transp,
)))
.graphics_for(state.ids.ch_2_bg)
.set(state.ids.crosshair_outer_2, ui);
Image::new(self.imgs.crosshair_inner)
.w_h(21.0 * 2.0, 21.0 * 2.0)
.middle_of(state.ids.crosshair_outer_2)
.color(Some(Color::Rgba(1.0, 1.0, 1.0, 0.6)))
.graphics_for(state.ids.ch_2_bg)
.set(state.ids.crosshair_inner_2, ui);
// Edges
if Button::image(if let CrosshairType::Edges = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg
})
.w_h(15.0 * 4.0, 15.0 * 4.0)
.hover_image(if let CrosshairType::Edges = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg_hover
})
.press_image(if let CrosshairType::Edges = crosshair_type {
self.imgs.crosshair_bg_pressed
} else {
self.imgs.crosshair_bg_press
})
.right_from(state.ids.ch_2_bg, 20.0)
.set(state.ids.ch_3_bg, ui)
.was_clicked()
{
events.push(Event::CrosshairType(CrosshairType::Edges));
}
// Crosshair
Image::new(self.imgs.crosshair_outer_edges)
.w_h(21.0 * 1.5, 21.0 * 1.5)
.middle_of(state.ids.ch_3_bg)
.color(Some(Color::Rgba(
1.0,
1.0,
1.0,
self.global_state.settings.gameplay.crosshair_transp,
)))
.graphics_for(state.ids.ch_3_bg)
.set(state.ids.crosshair_outer_3, ui);
Image::new(self.imgs.crosshair_inner)
.w_h(21.0 * 2.0, 21.0 * 2.0)
.middle_of(state.ids.crosshair_outer_3)
.color(Some(Color::Rgba(1.0, 1.0, 1.0, 0.6)))
.graphics_for(state.ids.ch_3_bg)
.set(state.ids.crosshair_inner_3, ui);
}
// 2) Gameplay Tab --------------------------------
if Button::image(if let SettingsTab::Gameplay = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button
})
.w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Gameplay = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_hover
})
.press_image(if let SettingsTab::Gameplay = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_press
})
.right_from(state.ids.interface, 0.0)
.label("Gameplay")
.label_font_size(14)
.label_color(TEXT_COLOR)
.set(state.ids.gameplay, ui)
.was_clicked()
{
events.push(Event::ChangeTab(SettingsTab::Gameplay));
}
// Contents
if let SettingsTab::Gameplay = self.show.settings_tab {
let display_pan = self.global_state.settings.gameplay.pan_sensitivity;
let display_zoom = self.global_state.settings.gameplay.zoom_sensitivity;
2019-06-06 19:11:39 +00:00
// Mouse Pan Sensitivity
Text::new("Pan Sensitivity")
.top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.mouse_pan_label, ui);
if let Some(new_val) = ImageSlider::discrete(
display_pan,
1,
200,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(550.0, 22.0)
.down_from(state.ids.mouse_pan_label, 10.0)
.track_breadth(30.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.mouse_pan_slider, ui)
{
events.push(Event::AdjustMousePan(new_val));
}
Text::new(&format!("{}", display_pan))
.right_from(state.ids.mouse_pan_slider, 8.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.mouse_pan_value, ui);
2019-06-06 19:11:39 +00:00
// Mouse Zoom Sensitivity
Text::new("Zoom Sensitivity")
.down_from(state.ids.mouse_pan_slider, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.mouse_zoom_label, ui);
if let Some(new_val) = ImageSlider::discrete(
display_zoom,
1,
200,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(550.0, 22.0)
.down_from(state.ids.mouse_zoom_label, 10.0)
.track_breadth(30.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.mouse_zoom_slider, ui)
{
events.push(Event::AdjustMouseZoom(new_val));
}
Text::new(&format!("{}", display_zoom))
.right_from(state.ids.mouse_zoom_slider, 8.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.mouse_zoom_value, ui);
}
// 3) Controls Tab --------------------------------
if Button::image(if let SettingsTab::Controls = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button
})
.w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Controls = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_hover
})
.press_image(if let SettingsTab::Controls = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_press
})
.right_from(state.ids.gameplay, 0.0)
.label("Controls")
.label_font_size(14)
.label_color(TEXT_COLOR)
.set(state.ids.controls, ui)
.was_clicked()
{
events.push(Event::ChangeTab(SettingsTab::Controls));
}
// Contents
if let SettingsTab::Controls = self.show.settings_tab {
Text::new(
"Free Cursor\n\
Toggle Help Window\n\
Toggle Interface\n\
Toggle FPS and Debug Info\n\
Take Screenshot\n\
Toggle Nametags\n\
Toggle Fullscreen\n\
\n\
\n\
Move Forward\n\
Move Left\n\
Move Right\n\
Move Backwards\n\
\n\
Jump\n\
\n\
Glider
\n\
Dodge\n\
\n\
Auto Walk\n\
\n\
Sheathe/Draw Weapons\n\
\n\
Put on/Remove Helmet\n\
\n\
Sit\n\
\n\
\n\
Basic Attack\n\
Secondary Attack/Block/Aim\n\
\n\
\n\
Skillbar Slot 1\n\
Skillbar Slot 2\n\
Skillbar Slot 3\n\
Skillbar Slot 4\n\
Skillbar Slot 5\n\
Skillbar Slot 6\n\
Skillbar Slot 7\n\
Skillbar Slot 8\n\
Skillbar Slot 9\n\
Skillbar Slot 10\n\
\n\
\n\
Pause Menu\n\
Settings\n\
Social\n\
Map\n\
Spellbook\n\
Character\n\
Questlog\n\
Bag\n\
\n\
\n\
\n\
Send Chat Message\n\
Scroll Chat\n\
\n\
\n\
Chat commands: \n\
\n\
/alias [Name] - Change your Chat Name \n\
/tp [Name] - Teleports you to another player \n\
/jump <dx> <dy> <dz> - Offset your position \n\
/goto <x> <y> <z> - Teleport to a position \n\
/kill - Kill yourself \n\
/pig - Spawn pig NPC \n\
/wolf - Spawn wolf NPC \n\
/help - Display chat commands
",
)
.color(TEXT_COLOR)
.top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0)
.font_id(self.fonts.opensans)
.font_size(18)
.set(state.ids.controls_text, ui);
// TODO: Replace with buttons that show actual keybinds and allow the user to change them.
Text::new(
"TAB\n\
F1\n\
F2\n\
F3\n\
F4\n\
F6\n\
F11\n\
\n\
\n\
W\n\
A\n\
S\n\
D\n\
\n\
SPACE\n\
\n\
L-Shift\n\
\n\
??\n\
\n\
??\n\
\n\
??\n\
\n\
??\n\
\n\
??\n\
\n\
\n\
L-Click\n\
R-Click\n\
\n\
\n\
1\n\
2\n\
3\n\
4\n\
5\n\
6\n\
7\n\
8\n\
9\n\
0\n\
\n\
\n\
ESC\n\
N\n\
O\n\
M\n\
P\n\
C\n\
L\n\
B\n\
\n\
\n\
\n\
ENTER\n\
Mousewheel\n\
\n\
\n\
\n\
\n\
\n\
\n\
",
)
.color(TEXT_COLOR)
.right_from(state.ids.controls_text, 0.0)
.font_id(self.fonts.opensans)
.font_size(18)
.set(state.ids.controls_controls, ui);
}
// 4) Video Tab -----------------------------------
if Button::image(if let SettingsTab::Video = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button
})
.w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Video = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_hover
})
.press_image(if let SettingsTab::Video = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_press
})
.right_from(state.ids.controls, 0.0)
.label("Video")
.parent(state.ids.settings_r)
.label_font_size(14)
.label_color(TEXT_COLOR)
.set(state.ids.video, ui)
.was_clicked()
{
events.push(Event::ChangeTab(SettingsTab::Video));
}
// Contents
if let SettingsTab::Video = self.show.settings_tab {
2019-06-06 19:11:39 +00:00
// View Distance
2019-05-31 19:14:20 +00:00
Text::new("View Distance")
.top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
2019-06-06 19:11:39 +00:00
.set(state.ids.vd_text, ui);
if let Some(new_val) = ImageSlider::discrete(
self.global_state.settings.graphics.view_distance,
1,
25,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(104.0, 22.0)
2019-06-06 19:11:39 +00:00
.down_from(state.ids.vd_text, 8.0)
.track_breadth(12.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.vd_slider, ui)
{
events.push(Event::AdjustViewDistance(new_val));
}
2019-06-06 19:11:39 +00:00
Text::new(&format!(
"{}",
self.global_state.settings.graphics.view_distance
))
.right_from(state.ids.vd_slider, 8.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.vd_value, ui);
// Max FPS
2019-06-06 17:54:11 +00:00
Text::new("Maximum FPS")
2019-06-06 19:11:39 +00:00
.down_from(state.ids.vd_slider, 10.0)
2019-06-06 17:54:11 +00:00
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.max_fps_text, ui);
2019-06-06 19:11:39 +00:00
if let Some(which) = ImageSlider::discrete(
FPS_CHOICES
.iter()
.position(|&x| x == self.global_state.settings.graphics.max_fps)
.unwrap_or(5),
0,
2019-06-06 19:11:39 +00:00
10,
2019-06-06 17:54:11 +00:00
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(104.0, 22.0)
.down_from(state.ids.max_fps_text, 8.0)
.track_breadth(12.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.max_fps_slider, ui)
{
2019-06-06 19:11:39 +00:00
events.push(Event::MaximumFPS(FPS_CHOICES[which]));
2019-06-06 17:54:11 +00:00
}
2019-06-06 19:11:39 +00:00
Text::new(&format!("{}", self.global_state.settings.graphics.max_fps))
.right_from(state.ids.max_fps_slider, 8.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.max_fps_value, ui);
}
// 5) Sound Tab -----------------------------------
if Button::image(if let SettingsTab::Sound = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button
})
.w_h(31.0 * 4.0, 12.0 * 4.0)
.hover_image(if let SettingsTab::Sound = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_hover
})
.press_image(if let SettingsTab::Sound = self.show.settings_tab {
self.imgs.settings_button_pressed
} else {
self.imgs.settings_button_press
})
.right_from(state.ids.video, 0.0)
.parent(state.ids.settings_r)
.label("Sound")
.label_font_size(14)
.label_color(TEXT_COLOR)
.set(state.ids.sound, ui)
.was_clicked()
{
events.push(Event::ChangeTab(SettingsTab::Sound));
}
// Contents
if let SettingsTab::Sound = self.show.settings_tab {
Text::new("Volume")
.top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.audio_volume_text, ui);
if let Some(new_val) = ImageSlider::continuous(
self.global_state.settings.audio.music_volume,
0.0,
1.0,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(104.0, 22.0)
.down_from(state.ids.audio_volume_text, 10.0)
.track_breadth(12.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.audio_volume_slider, ui)
{
events.push(Event::AdjustVolume(new_val));
}
// Audio Device Selector --------------------------------------------
match self.global_state.audio.model.get_genre() {
Genre::Bgm => {
let device = &self.global_state.audio.default_device;
let device_list = &self.global_state.audio.device_list;
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);
// Get which device is currently selected
let selected = device_list.iter().position(|x| x.contains(device));
if let Some(clicked) = DropDownList::new(&device_list, selected)
.w_h(400.0, 22.0)
.down_from(state.ids.audio_device_text, 10.0)
.label_font_id(self.fonts.opensans)
.set(state.ids.audio_device_list, ui)
{
let new_val = device_list[clicked].clone();
events.push(Event::ChangeAudioDevice(new_val));
}
}
Genre::Sfx => unimplemented!(),
Genre::None => {
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);
}
}
}
events
}
}