Crosshair transp slider

This commit is contained in:
Pfauenauge90 2019-07-07 02:15:22 +02:00
parent 3be2951029
commit 94acd0f437
4 changed files with 56 additions and 1 deletions

View File

@ -10,6 +10,7 @@ mod settings_window;
mod skillbar;
mod small_window;
use crate::hud::Event::CrosshairTransp;
use bag::Bag;
use buttons::Buttons;
use character_window::CharacterWindow;
@ -122,6 +123,7 @@ pub enum Event {
AdjustVolume(f32),
ChangeAudioDevice(String),
ChangeMaxFPS(u32),
CrosshairTransp(f32),
CharacterSelection,
Logout,
Quit,
@ -258,6 +260,7 @@ pub struct Hud {
fonts: Fonts,
new_messages: VecDeque<String>,
inventory_space: usize,
crosshair_transp: f32,
show: Show,
to_focus: Option<Option<widget::Id>>,
force_ungrab: bool,
@ -284,6 +287,7 @@ impl Hud {
ids,
new_messages: VecDeque::new(),
inventory_space: 8,
crosshair_transp: 0.6,
show: Show {
help: false,
debug: true,
@ -340,10 +344,11 @@ impl Hud {
let mut health_back_id_walker = self.ids.health_bar_backs.walk();
// Crosshair
let crosshair_transp = self.crosshair_transp;
Image::new(self.imgs.crosshair_outer)
.w_h(21.0 * 1.5, 21.0 * 1.5)
.middle_of(ui_widgets.window)
.color(Some(Color::Rgba(1.0, 1.0, 1.0, 0.2)))
.color(Some(Color::Rgba(1.0, 1.0, 1.0, self.crosshair_transp)))
.set(self.ids.crosshair_outer, ui_widgets);
Image::new(self.imgs.crosshair_inner)
.w_h(21.0 * 2.0, 21.0 * 2.0)
@ -624,6 +629,9 @@ impl Hud {
settings_window::Event::AdjustViewDistance(view_distance) => {
events.push(Event::AdjustViewDistance(view_distance));
}
settings_window::Event::CrosshairTransp(crosshair_transp) => {
events.push(Event::CrosshairTransp(crosshair_transp));
}
settings_window::Event::AdjustVolume(volume) => {
events.push(Event::AdjustVolume(volume));
}

View File

@ -42,6 +42,10 @@ widget_ids! {
mouse_zoom_slider,
mouse_zoom_label,
mouse_zoom_value,
ch_transp_slider,
ch_transp_label,
ch_transp_value,
ch_transp_text,
settings_bg,
sound,
test,
@ -113,6 +117,7 @@ pub enum Event {
AdjustVolume(f32),
ChangeAudioDevice(String),
MaximumFPS(u32),
CrosshairTransp(f32),
}
impl<'a> Widget for SettingsWindow<'a> {
@ -305,6 +310,7 @@ impl<'a> Widget for SettingsWindow<'a> {
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;
let crosshair_transp = self.global_state.settings.gameplay.crosshair_transp;
// Mouse Pan Sensitivity
Text::new("Pan Sensitivity")
@ -369,6 +375,38 @@ impl<'a> Widget for SettingsWindow<'a> {
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.mouse_zoom_value, ui);
// Crosshair Translucency
Text::new("Crosshair Transparency")
.down_from(state.ids.mouse_zoom_slider, 10.0)
.font_size(14)
.font_id(self.fonts.opensans)
.color(TEXT_COLOR)
.set(state.ids.ch_transp_text, 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!("{}", 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);
}
// 3) Controls Tab --------------------------------

View File

@ -282,6 +282,13 @@ impl PlayState for SessionState {
warn!("Failed to save settings: {:?}", err);
}
}
HudEvent::CrosshairTransp(crosshair_transp) => {
global_state.settings.gameplay.crosshair_transp = crosshair_transp;
global_state.settings.gameplay.crosshair_transp = crosshair_transp;
if let Err(err) = global_state.settings.save_to_file() {
warn!("Failed to save settings: {:?}", err);
}
}
HudEvent::AdjustVolume(volume) => {
global_state.audio.model.player.set_volume(volume);

View File

@ -75,6 +75,7 @@ impl Default for ControlSettings {
pub struct GameplaySettings {
pub pan_sensitivity: u32,
pub zoom_sensitivity: u32,
pub crosshair_transp: f32,
}
impl Default for GameplaySettings {
@ -82,6 +83,7 @@ impl Default for GameplaySettings {
Self {
pan_sensitivity: 100,
zoom_sensitivity: 100,
crosshair_transp: 0.6,
}
}
}