From 7a4ad099ff0cb51d9a86855005a10536290a3efc Mon Sep 17 00:00:00 2001 From: Monty Marz Date: Tue, 23 Jul 2019 01:02:57 +0000 Subject: [PATCH] Crosshair variations --- assets/voxygen/element/misc_bg/crosshair.vox | 3 - .../voxygen/element/misc_bg/crosshair_bg.vox | 3 + .../element/misc_bg/crosshair_bg_hover.vox | 3 + .../element/misc_bg/crosshair_bg_press.vox | 3 + .../element/misc_bg/crosshair_bg_pressed.vox | 3 + .../element/misc_bg/crosshair_outer.vox | 3 - .../element/misc_bg/crosshair_outer_1.vox | 3 + .../element/misc_bg/crosshair_outer_2.vox | 3 + .../element/misc_bg/crosshair_outer_3.vox | 3 + voxygen/src/hud/img_ids.rs | 11 +- voxygen/src/hud/mod.rs | 42 +++- voxygen/src/hud/settings_window.rs | 229 +++++++++++++++--- voxygen/src/session.rs | 8 +- voxygen/src/settings.rs | 4 +- 14 files changed, 262 insertions(+), 59 deletions(-) delete mode 100644 assets/voxygen/element/misc_bg/crosshair.vox create mode 100644 assets/voxygen/element/misc_bg/crosshair_bg.vox create mode 100644 assets/voxygen/element/misc_bg/crosshair_bg_hover.vox create mode 100644 assets/voxygen/element/misc_bg/crosshair_bg_press.vox create mode 100644 assets/voxygen/element/misc_bg/crosshair_bg_pressed.vox delete mode 100644 assets/voxygen/element/misc_bg/crosshair_outer.vox create mode 100644 assets/voxygen/element/misc_bg/crosshair_outer_1.vox create mode 100644 assets/voxygen/element/misc_bg/crosshair_outer_2.vox create mode 100644 assets/voxygen/element/misc_bg/crosshair_outer_3.vox diff --git a/assets/voxygen/element/misc_bg/crosshair.vox b/assets/voxygen/element/misc_bg/crosshair.vox deleted file mode 100644 index 6031040ab2..0000000000 --- a/assets/voxygen/element/misc_bg/crosshair.vox +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0776f8ad7b9a0f252335c5b75fe08b75a7f39ca5a30571a52bff934e7b83d366 -size 55912 diff --git a/assets/voxygen/element/misc_bg/crosshair_bg.vox b/assets/voxygen/element/misc_bg/crosshair_bg.vox new file mode 100644 index 0000000000..50a630ea8b --- /dev/null +++ b/assets/voxygen/element/misc_bg/crosshair_bg.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4df925b34c651de59460ce65f4a5f58b0efa007bbbb1eb5d0caa67c271579182 +size 45788 diff --git a/assets/voxygen/element/misc_bg/crosshair_bg_hover.vox b/assets/voxygen/element/misc_bg/crosshair_bg_hover.vox new file mode 100644 index 0000000000..4a082df963 --- /dev/null +++ b/assets/voxygen/element/misc_bg/crosshair_bg_hover.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3d3b6596f41c6c14ddd0c3d3eb22d6c6b60fa24284b37da5a183026e249ac0b +size 47372 diff --git a/assets/voxygen/element/misc_bg/crosshair_bg_press.vox b/assets/voxygen/element/misc_bg/crosshair_bg_press.vox new file mode 100644 index 0000000000..ac2e8bc838 --- /dev/null +++ b/assets/voxygen/element/misc_bg/crosshair_bg_press.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aadd59f55c03b2e2118e6e403c5a62c4d0a2eb8e1d0aad37149092cc4179cc61 +size 46076 diff --git a/assets/voxygen/element/misc_bg/crosshair_bg_pressed.vox b/assets/voxygen/element/misc_bg/crosshair_bg_pressed.vox new file mode 100644 index 0000000000..e70733523f --- /dev/null +++ b/assets/voxygen/element/misc_bg/crosshair_bg_pressed.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9edb64c9fcb5caf520e222d846b6ba466c1ba5bbc7c590aa741b2db37ec8070 +size 46076 diff --git a/assets/voxygen/element/misc_bg/crosshair_outer.vox b/assets/voxygen/element/misc_bg/crosshair_outer.vox deleted file mode 100644 index 8bf3d60dc2..0000000000 --- a/assets/voxygen/element/misc_bg/crosshair_outer.vox +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f5151fb769cfac65218cc64f3a366b65016a7894270753dc58b12fe2a2981dda -size 1464 diff --git a/assets/voxygen/element/misc_bg/crosshair_outer_1.vox b/assets/voxygen/element/misc_bg/crosshair_outer_1.vox new file mode 100644 index 0000000000..224e2b7e1d --- /dev/null +++ b/assets/voxygen/element/misc_bg/crosshair_outer_1.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5f40e4407038e9bc7a348c62eae1d9874981351b5c42443a56ba419a1dc9181 +size 44572 diff --git a/assets/voxygen/element/misc_bg/crosshair_outer_2.vox b/assets/voxygen/element/misc_bg/crosshair_outer_2.vox new file mode 100644 index 0000000000..149e46946e --- /dev/null +++ b/assets/voxygen/element/misc_bg/crosshair_outer_2.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b53e188972c97eb42520b4801d97e79187ae82386202f03df07ed124ed7b0c4d +size 1560 diff --git a/assets/voxygen/element/misc_bg/crosshair_outer_3.vox b/assets/voxygen/element/misc_bg/crosshair_outer_3.vox new file mode 100644 index 0000000000..5ac4f4167c --- /dev/null +++ b/assets/voxygen/element/misc_bg/crosshair_outer_3.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9e8d27e0b86ce1c0b14fc8447c59abbf7bb5297da27448e4eef9f2ad332733f +size 1656 diff --git a/voxygen/src/hud/img_ids.rs b/voxygen/src/hud/img_ids.rs index 14abc02cae..959eeeff82 100644 --- a/voxygen/src/hud/img_ids.rs +++ b/voxygen/src/hud/img_ids.rs @@ -54,14 +54,19 @@ image_ids! { chat_arrow_press: "voxygen/element/buttons/arrow_down_press.vox", // Crosshair - crosshair: "voxygen/element/misc_bg/crosshair.vox", - //crosshair_outer: "voxygen/element/misc_bg/crosshair_outer.vox", crosshair_inner: "voxygen/element/misc_bg/crosshair_inner.vox", //////////////////////////////////////////////////////////////////////// - crosshair_outer: "voxygen/element/misc_bg/crosshair_outer.vox", + crosshair_outer_round: "voxygen/element/misc_bg/crosshair_outer_1.vox", + crosshair_outer_round_edges: "voxygen/element/misc_bg/crosshair_outer_2.vox", + crosshair_outer_edges: "voxygen/element/misc_bg/crosshair_outer_3.vox", + + crosshair_bg: "voxygen/element/misc_bg/crosshair_bg.vox", + crosshair_bg_hover: "voxygen/element/misc_bg/crosshair_bg_hover.vox", + crosshair_bg_press: "voxygen/element/misc_bg/crosshair_bg_press.vox", + crosshair_bg_pressed: "voxygen/element/misc_bg/crosshair_bg_pressed.vox", // Buttons mmap_closed: "voxygen/element/buttons/button_mmap_closed.vox", diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index c63425e18e..c257a13bb5 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -18,6 +18,7 @@ use esc_menu::EscMenu; use img_ids::Imgs; use map::Map; use minimap::MiniMap; +use serde::{Deserialize, Serialize}; use settings_window::{SettingsTab, SettingsWindow}; use skillbar::Skillbar; use small_window::{SmallWindow, SmallWindowType}; @@ -116,7 +117,7 @@ pub struct DebugInfo { pub ping_ms: f64, pub coordinates: Option, } - +#[derive(Serialize, Deserialize)] pub enum Event { SendMessage(String), AdjustMousePan(u32), @@ -126,6 +127,7 @@ pub enum Event { ChangeAudioDevice(String), ChangeMaxFPS(u32), CrosshairTransp(f32), + CrosshairType(CrosshairType), //UiScale(f32), CharacterSelection, Logout, @@ -143,6 +145,13 @@ pub enum Windows { None, } +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum CrosshairType { + Round, + RoundEdges, + Edges, +} + pub struct Show { ui: bool, help: bool, @@ -155,7 +164,6 @@ pub struct Show { mini_map: bool, ingame: bool, settings_tab: SettingsTab, - want_grab: bool, } impl Show { @@ -345,16 +353,23 @@ impl Hud { let mut health_back_id_walker = self.ids.health_bar_backs.walk(); // Crosshair - 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, - global_state.settings.gameplay.crosshair_transp, - ))) - .set(self.ids.crosshair_outer, ui_widgets); + Image::new( + // TODO: Do we want to match on this every frame? + match global_state.settings.gameplay.crosshair_type { + CrosshairType::Round => self.imgs.crosshair_outer_round, + CrosshairType::RoundEdges => self.imgs.crosshair_outer_round_edges, + CrosshairType::Edges => self.imgs.crosshair_outer_edges, + }, + ) + .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, + global_state.settings.gameplay.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) .middle_of(self.ids.crosshair_outer) @@ -646,6 +661,9 @@ impl Hud { settings_window::Event::ChangeAudioDevice(name) => { events.push(Event::ChangeAudioDevice(name)); } + settings_window::Event::CrosshairType(crosshair_type) => { + events.push(Event::CrosshairType(crosshair_type)); + } } } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index cd622cba44..ddd085565e 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -1,4 +1,4 @@ -use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR}; +use super::{img_ids::Imgs, CrosshairType, Fonts, Show, TEXT_COLOR}; use crate::{ audio::base::{AudioDevice, Genre}, settings::AudioSettings, @@ -8,7 +8,7 @@ use crate::{ use conrod_core::{ color, widget::{self, Button, DropDownList, Image, Rectangle, Scrollbar, Text}, - widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, + widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, }; const FPS_CHOICES: [u32; 11] = [15, 30, 40, 50, 60, 90, 120, 144, 240, 300, 500]; @@ -31,6 +31,7 @@ widget_ids! { gameplay, controls, rectangle, + general_txt, debug_button, debug_button_label, interface, @@ -42,10 +43,20 @@ widget_ids! { mouse_zoom_slider, mouse_zoom_label, mouse_zoom_value, + ch_title, ch_transp_slider, ch_transp_label, ch_transp_value, ch_transp_text, + 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, @@ -118,6 +129,7 @@ pub enum Event { ChangeAudioDevice(String), MaximumFPS(u32), CrosshairTransp(f32), + CrosshairType(CrosshairType), } impl<'a> Widget for SettingsWindow<'a> { @@ -212,11 +224,21 @@ impl<'a> Widget for SettingsWindow<'a> { // Contents if let SettingsTab::Interface = self.show.settings_tab { + let crosshair_transp = self.global_state.settings.gameplay.crosshair_transp; + let crosshair_type = self.global_state.settings.gameplay.crosshair_type; + + 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) - .top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0) + .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); @@ -277,6 +299,174 @@ impl<'a> Widget for SettingsWindow<'a> { .graphics_for(state.ids.debug_button) .color(TEXT_COLOR) .set(state.ids.debug_button_label, ui); + + // Crosshair Options + // Crosshair Transparency + Text::new("Crosshair") + .down_from(state.ids.debug_button, 15.0) + .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 -------------------------------- @@ -310,7 +500,6 @@ 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") @@ -375,38 +564,6 @@ 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!("{:.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); } // 3) Controls Tab -------------------------------- diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 5221971b7c..445626f347 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -290,12 +290,18 @@ impl PlayState for SessionState { } } 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::CrosshairType(crosshair_type) => { + global_state.settings.gameplay.crosshair_type = crosshair_type; + 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); diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 0be167d7b6..aaf49895f8 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -1,4 +1,4 @@ -use crate::window::KeyMouse; +use crate::{hud::CrosshairType, window::KeyMouse}; use directories::ProjectDirs; use glutin::{MouseButton, VirtualKeyCode}; use serde_derive::{Deserialize, Serialize}; @@ -76,6 +76,7 @@ pub struct GameplaySettings { pub pan_sensitivity: u32, pub zoom_sensitivity: u32, pub crosshair_transp: f32, + pub crosshair_type: CrosshairType, } impl Default for GameplaySettings { @@ -84,6 +85,7 @@ impl Default for GameplaySettings { pan_sensitivity: 100, zoom_sensitivity: 100, crosshair_transp: 0.6, + crosshair_type: CrosshairType::Round, } } }