From 56deb5919f4e73c9e02ccfec89960c5103dd6443 Mon Sep 17 00:00:00 2001 From: hqurve Date: Tue, 13 Apr 2021 20:55:52 -0400 Subject: [PATCH] cleaned up settings_change.rs --- voxygen/src/session/settings_change.rs | 606 +++++++++++-------------- 1 file changed, 273 insertions(+), 333 deletions(-) diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index 7b566e680f..6d31303996 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -145,360 +145,300 @@ settings_change_from!(Networking); impl SettingsChange { pub fn process(self, global_state: &mut GlobalState, session_state: &mut SessionState) { - // let mut settings = &mut global_state.settings; - // let mut window = &mut global_state.window; + let mut settings = &mut global_state.settings; match self { - SettingsChange::Audio(audio_change) => match audio_change { - Audio::AdjustMusicVolume(music_volume) => { - global_state.audio.set_music_volume(music_volume); + SettingsChange::Audio(audio_change) => { + match audio_change { + Audio::AdjustMusicVolume(music_volume) => { + global_state.audio.set_music_volume(music_volume); - global_state.settings.audio.music_volume = music_volume; - global_state.settings.save_to_file_warn(); - }, - Audio::AdjustSfxVolume(sfx_volume) => { - global_state.audio.set_sfx_volume(sfx_volume); + settings.audio.music_volume = music_volume; + }, + Audio::AdjustSfxVolume(sfx_volume) => { + global_state.audio.set_sfx_volume(sfx_volume); - global_state.settings.audio.sfx_volume = sfx_volume; - global_state.settings.save_to_file_warn(); - }, - //Audio::ChangeAudioDevice(name) => { - // global_state.audio.set_device(name.clone()); + settings.audio.sfx_volume = sfx_volume; + }, + //Audio::ChangeAudioDevice(name) => { + // global_state.audio.set_device(name.clone()); - // global_state.settings.audio.output = AudioOutput::Device(name); - // global_state.settings.save_to_file_warn(); - //}, - Audio::ResetAudioSettings => { - global_state.settings.audio = AudioSettings::default(); - global_state.settings.save_to_file_warn(); - let audio = &global_state.settings.audio; - global_state.audio.set_music_volume(audio.music_volume); - global_state.audio.set_sfx_volume(audio.sfx_volume); - }, + // settings.audio.output = AudioOutput::Device(name); + //}, + Audio::ResetAudioSettings => { + settings.audio = AudioSettings::default(); + let audio = &settings.audio; + global_state.audio.set_music_volume(audio.music_volume); + global_state.audio.set_sfx_volume(audio.sfx_volume); + }, + } + settings.save_to_file_warn(); }, SettingsChange::Control(control_change) => match control_change { Control::ChangeBinding(game_input) => { global_state.window.set_keybinding_mode(game_input); }, Control::ResetKeyBindings => { - global_state.settings.controls = ControlSettings::default(); - global_state.settings.save_to_file_warn(); + settings.controls = ControlSettings::default(); + settings.save_to_file_warn(); }, }, SettingsChange::Gamepad(gamepad_change) => match gamepad_change {}, - SettingsChange::Gameplay(gameplay_change) => match gameplay_change { - Gameplay::AdjustMousePan(sensitivity) => { - global_state.window.pan_sensitivity = sensitivity; - global_state.settings.gameplay.pan_sensitivity = sensitivity; - global_state.settings.save_to_file_warn(); - }, - Gameplay::AdjustMouseZoom(sensitivity) => { - global_state.window.zoom_sensitivity = sensitivity; - global_state.settings.gameplay.zoom_sensitivity = sensitivity; - global_state.settings.save_to_file_warn(); - }, - Gameplay::AdjustCameraClamp(angle) => { - global_state.settings.gameplay.camera_clamp_angle = angle; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ToggleControllerYInvert(controller_y_inverted) => { - global_state.window.controller_settings.pan_invert_y = controller_y_inverted; - global_state.settings.controller.pan_invert_y = controller_y_inverted; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ToggleMouseYInvert(mouse_y_inverted) => { - global_state.window.mouse_y_inversion = mouse_y_inverted; - global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ToggleZoomInvert(zoom_inverted) => { - global_state.window.zoom_inversion = zoom_inverted; - global_state.settings.gameplay.zoom_inversion = zoom_inverted; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ToggleSmoothPan(smooth_pan_enabled) => { - global_state.settings.gameplay.smooth_pan_enable = smooth_pan_enabled; - global_state.settings.save_to_file_warn(); - }, - - Gameplay::ChangeFreeLookBehavior(behavior) => { - global_state.settings.gameplay.free_look_behavior = behavior; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ChangeAutoWalkBehavior(behavior) => { - global_state.settings.gameplay.auto_walk_behavior = behavior; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ChangeCameraClampBehavior(behavior) => { - global_state.settings.gameplay.camera_clamp_behavior = behavior; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ChangeStopAutoWalkOnInput(state) => { - global_state.settings.gameplay.stop_auto_walk_on_input = state; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ChangeAutoCamera(state) => { - global_state.settings.gameplay.auto_camera = state; - global_state.settings.save_to_file_warn(); - }, - Gameplay::ResetGameplaySettings => { - // Reset Gameplay Settings - global_state.settings.gameplay = GameplaySettings::default(); - // Reset Gamepad and Controller Settings - global_state.settings.controller = GamepadSettings::default(); - global_state.window.controller_settings = - ControllerSettings::from(&global_state.settings.controller); - // Pan Sensitivity - global_state.window.pan_sensitivity = - global_state.settings.gameplay.pan_sensitivity; - // Zoom Sensitivity - global_state.window.zoom_sensitivity = - global_state.settings.gameplay.zoom_sensitivity; - // Invert Scroll Zoom - global_state.window.zoom_inversion = - global_state.settings.gameplay.zoom_inversion; - // Invert Mouse Y Axis - global_state.window.mouse_y_inversion = - global_state.settings.gameplay.mouse_y_inversion; - // Save to File - global_state.settings.save_to_file_warn(); - }, + SettingsChange::Gameplay(gameplay_change) => { + let mut window = &mut global_state.window; + match gameplay_change { + Gameplay::AdjustMousePan(sensitivity) => { + window.pan_sensitivity = sensitivity; + settings.gameplay.pan_sensitivity = sensitivity; + }, + Gameplay::AdjustMouseZoom(sensitivity) => { + window.zoom_sensitivity = sensitivity; + settings.gameplay.zoom_sensitivity = sensitivity; + }, + Gameplay::AdjustCameraClamp(angle) => { + settings.gameplay.camera_clamp_angle = angle; + }, + Gameplay::ToggleControllerYInvert(controller_y_inverted) => { + window.controller_settings.pan_invert_y = controller_y_inverted; + settings.controller.pan_invert_y = controller_y_inverted; + }, + Gameplay::ToggleMouseYInvert(mouse_y_inverted) => { + window.mouse_y_inversion = mouse_y_inverted; + settings.gameplay.mouse_y_inversion = mouse_y_inverted; + }, + Gameplay::ToggleZoomInvert(zoom_inverted) => { + window.zoom_inversion = zoom_inverted; + settings.gameplay.zoom_inversion = zoom_inverted; + }, + Gameplay::ToggleSmoothPan(smooth_pan_enabled) => { + settings.gameplay.smooth_pan_enable = smooth_pan_enabled; + }, + Gameplay::ChangeFreeLookBehavior(behavior) => { + settings.gameplay.free_look_behavior = behavior; + }, + Gameplay::ChangeAutoWalkBehavior(behavior) => { + settings.gameplay.auto_walk_behavior = behavior; + }, + Gameplay::ChangeCameraClampBehavior(behavior) => { + settings.gameplay.camera_clamp_behavior = behavior; + }, + Gameplay::ChangeStopAutoWalkOnInput(state) => { + settings.gameplay.stop_auto_walk_on_input = state; + }, + Gameplay::ChangeAutoCamera(state) => { + settings.gameplay.auto_camera = state; + }, + Gameplay::ResetGameplaySettings => { + // Reset Gameplay Settings + settings.gameplay = GameplaySettings::default(); + // Reset Gamepad and Controller Settings + settings.controller = GamepadSettings::default(); + window.controller_settings = ControllerSettings::from(&settings.controller); + // Pan Sensitivity + window.pan_sensitivity = settings.gameplay.pan_sensitivity; + // Zoom Sensitivity + window.zoom_sensitivity = settings.gameplay.zoom_sensitivity; + // Invert Scroll Zoom + window.zoom_inversion = settings.gameplay.zoom_inversion; + // Invert Mouse Y Axis + window.mouse_y_inversion = settings.gameplay.mouse_y_inversion; + }, + } + settings.save_to_file_warn(); }, - SettingsChange::Graphics(graphics_change) => match graphics_change { - Graphics::AdjustViewDistance(view_distance) => { - session_state - .client - .borrow_mut() - .set_view_distance(view_distance); + SettingsChange::Graphics(graphics_change) => { + match graphics_change { + Graphics::AdjustViewDistance(view_distance) => { + session_state + .client + .borrow_mut() + .set_view_distance(view_distance); - global_state.settings.graphics.view_distance = view_distance; - global_state.settings.save_to_file_warn(); - }, - Graphics::AdjustLodDetail(lod_detail) => { - session_state.scene.lod.set_detail(lod_detail); + settings.graphics.view_distance = view_distance; + }, + Graphics::AdjustLodDetail(lod_detail) => { + session_state.scene.lod.set_detail(lod_detail); - global_state.settings.graphics.lod_detail = lod_detail; - global_state.settings.save_to_file_warn(); - }, - Graphics::AdjustSpriteRenderDistance(sprite_render_distance) => { - global_state.settings.graphics.sprite_render_distance = sprite_render_distance; - global_state.settings.save_to_file_warn(); - }, - Graphics::AdjustFigureLoDRenderDistance(figure_lod_render_distance) => { - global_state.settings.graphics.figure_lod_render_distance = - figure_lod_render_distance; - global_state.settings.save_to_file_warn(); - }, - Graphics::ChangeMaxFPS(fps) => { - global_state.settings.graphics.max_fps = fps; - global_state.settings.save_to_file_warn(); - }, - Graphics::ChangeFOV(new_fov) => { - global_state.settings.graphics.fov = new_fov; - global_state.settings.save_to_file_warn(); - session_state.scene.camera_mut().set_fov_deg(new_fov); - session_state - .scene - .camera_mut() - .compute_dependents(&*session_state.client.borrow().state().terrain()); - }, - Graphics::ChangeGamma(new_gamma) => { - global_state.settings.graphics.gamma = new_gamma; - global_state.settings.save_to_file_warn(); - }, - Graphics::ChangeExposure(new_exposure) => { - global_state.settings.graphics.exposure = new_exposure; - global_state.settings.save_to_file_warn(); - }, - Graphics::ChangeAmbiance(new_ambiance) => { - global_state.settings.graphics.ambiance = new_ambiance; - global_state.settings.save_to_file_warn(); - }, - Graphics::ChangeRenderMode(new_render_mode) => { - // Do this first so if it crashes the setting isn't saved :) - global_state - .window - .renderer_mut() - .set_render_mode((&*new_render_mode).clone()) - .unwrap(); - global_state.settings.graphics.render_mode = *new_render_mode; - global_state.settings.save_to_file_warn(); - }, - Graphics::ChangeFullscreenMode(new_fullscreen_settings) => { - global_state - .window - .set_fullscreen_mode(new_fullscreen_settings); - global_state.settings.graphics.fullscreen = new_fullscreen_settings; - global_state.settings.save_to_file_warn(); - }, - Graphics::ToggleParticlesEnabled(particles_enabled) => { - global_state.settings.graphics.particles_enabled = particles_enabled; - global_state.settings.save_to_file_warn(); - }, - Graphics::AdjustWindowSize(new_size) => { - global_state.window.set_size(new_size.into()); - global_state.settings.graphics.window_size = new_size; - global_state.settings.save_to_file_warn(); - }, - Graphics::ResetGraphicsSettings => { - global_state.settings.graphics = GraphicsSettings::default(); - global_state.settings.save_to_file_warn(); - let graphics = &global_state.settings.graphics; - // View distance - session_state - .client - .borrow_mut() - .set_view_distance(graphics.view_distance); - // FOV - session_state.scene.camera_mut().set_fov_deg(graphics.fov); - session_state - .scene - .camera_mut() - .compute_dependents(&*session_state.client.borrow().state().terrain()); - // LoD - session_state.scene.lod.set_detail(graphics.lod_detail); - // Render mode - global_state - .window - .renderer_mut() - .set_render_mode(graphics.render_mode.clone()) - .unwrap(); - // Fullscreen mode - global_state.window.set_fullscreen_mode(graphics.fullscreen); - // Window size - global_state.window.set_size(graphics.window_size.into()); - }, + settings.graphics.lod_detail = lod_detail; + }, + Graphics::AdjustSpriteRenderDistance(sprite_render_distance) => { + settings.graphics.sprite_render_distance = sprite_render_distance; + }, + Graphics::AdjustFigureLoDRenderDistance(figure_lod_render_distance) => { + settings.graphics.figure_lod_render_distance = figure_lod_render_distance; + }, + Graphics::ChangeMaxFPS(fps) => { + settings.graphics.max_fps = fps; + }, + Graphics::ChangeFOV(new_fov) => { + settings.graphics.fov = new_fov; + session_state.scene.camera_mut().set_fov_deg(new_fov); + session_state + .scene + .camera_mut() + .compute_dependents(&*session_state.client.borrow().state().terrain()); + }, + Graphics::ChangeGamma(new_gamma) => { + settings.graphics.gamma = new_gamma; + }, + Graphics::ChangeExposure(new_exposure) => { + settings.graphics.exposure = new_exposure; + }, + Graphics::ChangeAmbiance(new_ambiance) => { + settings.graphics.ambiance = new_ambiance; + }, + Graphics::ChangeRenderMode(new_render_mode) => { + // Do this first so if it crashes the setting isn't saved :) + global_state + .window + .renderer_mut() + .set_render_mode((&*new_render_mode).clone()) + .unwrap(); + settings.graphics.render_mode = *new_render_mode; + }, + Graphics::ChangeFullscreenMode(new_fullscreen_settings) => { + global_state + .window + .set_fullscreen_mode(new_fullscreen_settings); + settings.graphics.fullscreen = new_fullscreen_settings; + }, + Graphics::ToggleParticlesEnabled(particles_enabled) => { + settings.graphics.particles_enabled = particles_enabled; + }, + Graphics::AdjustWindowSize(new_size) => { + global_state.window.set_size(new_size.into()); + settings.graphics.window_size = new_size; + }, + Graphics::ResetGraphicsSettings => { + settings.graphics = GraphicsSettings::default(); + let graphics = &settings.graphics; + // View distance + session_state + .client + .borrow_mut() + .set_view_distance(graphics.view_distance); + // FOV + session_state.scene.camera_mut().set_fov_deg(graphics.fov); + session_state + .scene + .camera_mut() + .compute_dependents(&*session_state.client.borrow().state().terrain()); + // LoD + session_state.scene.lod.set_detail(graphics.lod_detail); + // Render mode + global_state + .window + .renderer_mut() + .set_render_mode(graphics.render_mode.clone()) + .unwrap(); + // Fullscreen mode + global_state.window.set_fullscreen_mode(graphics.fullscreen); + // Window size + global_state.window.set_size(graphics.window_size.into()); + }, + } + settings.save_to_file_warn(); }, - SettingsChange::Interface(interface_change) => match interface_change { - Interface::Sct(sct) => { - global_state.settings.interface.sct = sct; - global_state.settings.save_to_file_warn(); - }, - Interface::SctPlayerBatch(sct_player_batch) => { - global_state.settings.interface.sct_player_batch = sct_player_batch; - global_state.settings.save_to_file_warn(); - }, - Interface::SctDamageBatch(sct_damage_batch) => { - global_state.settings.interface.sct_damage_batch = sct_damage_batch; - global_state.settings.save_to_file_warn(); - }, - Interface::SpeechBubbleDarkMode(sbdm) => { - global_state.settings.interface.speech_bubble_dark_mode = sbdm; - global_state.settings.save_to_file_warn(); - }, - Interface::SpeechBubbleIcon(sbi) => { - global_state.settings.interface.speech_bubble_icon = sbi; - global_state.settings.save_to_file_warn(); - }, - Interface::ToggleHelp(_) => { - // implemented in hud - }, - Interface::ToggleDebug(toggle_debug) => { - global_state.settings.interface.toggle_debug = toggle_debug; - global_state.settings.save_to_file_warn(); - }, - Interface::ToggleTips(loading_tips) => { - global_state.settings.interface.loading_tips = loading_tips; - global_state.settings.save_to_file_warn(); - }, - - Interface::CrosshairTransp(crosshair_transp) => { - global_state.settings.interface.crosshair_transp = crosshair_transp; - global_state.settings.save_to_file_warn(); - }, - Interface::ChatTransp(chat_transp) => { - global_state.settings.interface.chat_transp = chat_transp; - global_state.settings.save_to_file_warn(); - }, - Interface::ChatCharName(chat_char_name) => { - global_state.settings.interface.chat_character_name = chat_char_name; - global_state.settings.save_to_file_warn(); - }, - Interface::CrosshairType(crosshair_type) => { - global_state.settings.interface.crosshair_type = crosshair_type; - global_state.settings.save_to_file_warn(); - }, - Interface::Intro(intro_show) => { - global_state.settings.interface.intro_show = intro_show; - global_state.settings.save_to_file_warn(); - }, - Interface::ToggleXpBar(xp_bar) => { - global_state.settings.interface.xp_bar = xp_bar; - global_state.settings.save_to_file_warn(); - }, - Interface::ToggleBarNumbers(bar_numbers) => { - global_state.settings.interface.bar_numbers = bar_numbers; - global_state.settings.save_to_file_warn(); - }, - Interface::ToggleShortcutNumbers(shortcut_numbers) => { - global_state.settings.interface.shortcut_numbers = shortcut_numbers; - global_state.settings.save_to_file_warn(); - }, - Interface::BuffPosition(buff_position) => { - global_state.settings.interface.buff_position = buff_position; - global_state.settings.save_to_file_warn(); - }, - - Interface::UiScale(scale_change) => { - global_state.settings.interface.ui_scale = - session_state.hud.scale_change(scale_change); - global_state.settings.save_to_file_warn(); - }, - Interface::MapZoom(map_zoom) => { - global_state.settings.interface.map_zoom = map_zoom; - global_state.settings.save_to_file_warn(); - }, - Interface::MapDrag(map_drag) => { - global_state.settings.interface.map_drag = map_drag; - global_state.settings.save_to_file_warn(); - }, - Interface::MapShowTopoMap(map_show_topo_map) => { - global_state.settings.interface.map_show_topo_map = map_show_topo_map; - global_state.settings.save_to_file_warn(); - }, - Interface::MapShowDifficulty(map_show_difficulty) => { - global_state.settings.interface.map_show_difficulty = map_show_difficulty; - global_state.settings.save_to_file_warn(); - }, - Interface::MapShowTowns(map_show_towns) => { - global_state.settings.interface.map_show_towns = map_show_towns; - global_state.settings.save_to_file_warn(); - }, - Interface::MapShowDungeons(map_show_dungeons) => { - global_state.settings.interface.map_show_dungeons = map_show_dungeons; - global_state.settings.save_to_file_warn(); - }, - Interface::MapShowCastles(map_show_castles) => { - global_state.settings.interface.map_show_castles = map_show_castles; - global_state.settings.save_to_file_warn(); - }, - Interface::MapShowCaves(map_show_caves) => { - global_state.settings.interface.map_show_caves = map_show_caves; - global_state.settings.save_to_file_warn(); - }, - Interface::MapShowTrees(map_show_trees) => { - global_state.settings.interface.map_show_trees = map_show_trees; - global_state.settings.save_to_file_warn(); - }, - Interface::ResetInterfaceSettings => { - // Reset Interface Settings - let tmp = global_state.settings.interface.intro_show; - global_state.settings.interface = InterfaceSettings::default(); - global_state.settings.interface.intro_show = tmp; - // Update Current Scaling Mode - session_state - .hud - .set_scaling_mode(global_state.settings.interface.ui_scale); - - // Save to File - global_state.settings.save_to_file_warn(); - }, + SettingsChange::Interface(interface_change) => { + match interface_change { + Interface::Sct(sct) => { + settings.interface.sct = sct; + }, + Interface::SctPlayerBatch(sct_player_batch) => { + settings.interface.sct_player_batch = sct_player_batch; + }, + Interface::SctDamageBatch(sct_damage_batch) => { + settings.interface.sct_damage_batch = sct_damage_batch; + }, + Interface::SpeechBubbleDarkMode(sbdm) => { + settings.interface.speech_bubble_dark_mode = sbdm; + }, + Interface::SpeechBubbleIcon(sbi) => { + settings.interface.speech_bubble_icon = sbi; + }, + Interface::ToggleHelp(_) => { + // implemented in hud + }, + Interface::ToggleDebug(toggle_debug) => { + settings.interface.toggle_debug = toggle_debug; + }, + Interface::ToggleTips(loading_tips) => { + settings.interface.loading_tips = loading_tips; + }, + Interface::CrosshairTransp(crosshair_transp) => { + settings.interface.crosshair_transp = crosshair_transp; + }, + Interface::ChatTransp(chat_transp) => { + settings.interface.chat_transp = chat_transp; + }, + Interface::ChatCharName(chat_char_name) => { + settings.interface.chat_character_name = chat_char_name; + }, + Interface::CrosshairType(crosshair_type) => { + settings.interface.crosshair_type = crosshair_type; + }, + Interface::Intro(intro_show) => { + settings.interface.intro_show = intro_show; + }, + Interface::ToggleXpBar(xp_bar) => { + settings.interface.xp_bar = xp_bar; + }, + Interface::ToggleBarNumbers(bar_numbers) => { + settings.interface.bar_numbers = bar_numbers; + }, + Interface::ToggleShortcutNumbers(shortcut_numbers) => { + settings.interface.shortcut_numbers = shortcut_numbers; + }, + Interface::BuffPosition(buff_position) => { + settings.interface.buff_position = buff_position; + }, + Interface::UiScale(scale_change) => { + settings.interface.ui_scale = session_state.hud.scale_change(scale_change); + }, + Interface::MapZoom(map_zoom) => { + settings.interface.map_zoom = map_zoom; + }, + Interface::MapDrag(map_drag) => { + settings.interface.map_drag = map_drag; + }, + Interface::MapShowTopoMap(map_show_topo_map) => { + settings.interface.map_show_topo_map = map_show_topo_map; + }, + Interface::MapShowDifficulty(map_show_difficulty) => { + settings.interface.map_show_difficulty = map_show_difficulty; + }, + Interface::MapShowTowns(map_show_towns) => { + settings.interface.map_show_towns = map_show_towns; + }, + Interface::MapShowDungeons(map_show_dungeons) => { + settings.interface.map_show_dungeons = map_show_dungeons; + }, + Interface::MapShowCastles(map_show_castles) => { + settings.interface.map_show_castles = map_show_castles; + }, + Interface::MapShowCaves(map_show_caves) => { + settings.interface.map_show_caves = map_show_caves; + }, + Interface::MapShowTrees(map_show_trees) => { + settings.interface.map_show_trees = map_show_trees; + }, + Interface::ResetInterfaceSettings => { + // Reset Interface Settings + let tmp = settings.interface.intro_show; + settings.interface = InterfaceSettings::default(); + settings.interface.intro_show = tmp; + // Update Current Scaling Mode + session_state + .hud + .set_scaling_mode(settings.interface.ui_scale); + }, + } + settings.save_to_file_warn(); }, SettingsChange::Language(language_change) => match language_change { Language::ChangeLanguage(new_language) => { - global_state.settings.language.selected_language = - new_language.language_identifier; + settings.language.selected_language = new_language.language_identifier; global_state.i18n = Localization::load_expect(&i18n_asset_key( - &global_state.settings.language.selected_language, + &settings.language.selected_language, )); global_state.i18n.read().log_missing_entries(); session_state.hud.update_fonts(&global_state.i18n.read());