Wrapped settings changes from the ui into a single enum and handling moved to session/settings_change.rs

This commit is contained in:
hqurve 2021-04-13 20:43:11 -04:00
parent 732fe3bb40
commit df38dfbaf8
11 changed files with 724 additions and 768 deletions

View File

@ -5,6 +5,7 @@ use super::{
};
use crate::{
i18n::Localization,
session::settings_change::{Interface as InterfaceChange, SettingsChange},
ui::{fonts::Fonts, img_ids, ImageFrame, Tooltip, TooltipManager, Tooltipable},
GlobalState,
};
@ -117,18 +118,15 @@ pub struct State {
}
pub enum Event {
MapZoom(f64),
MapDrag(Vec2<f64>),
ShowDifficulties(bool),
ShowTowns(bool),
ShowCastles(bool),
ShowDungeons(bool),
ShowCaves(bool),
ShowTrees(bool),
ShowTopoMap(bool),
SettingsChange(SettingsChange),
Close,
RequestSiteInfo(SiteId),
}
impl From<InterfaceChange> for Event {
fn from(interface_change: InterfaceChange) -> Self {
Event::SettingsChange(interface_change.into())
}
}
fn get_site_economy(site_rich: &SiteInfoRich) -> String {
if SHOW_ECONOMY {
@ -315,7 +313,7 @@ impl<'a> Widget for Map<'a> {
.sum();
// Drag represents offset of view from the player_pos in chunk coords
let drag_new = drag + dragged / map_size / zoom * max_zoom;
events.push(Event::MapDrag(drag_new));
events.push(InterfaceChange::MapDrag(drag_new).into());
let rect_src = position::Rect::from_xy_dim(
[
@ -366,7 +364,7 @@ impl<'a> Widget for Map<'a> {
let new_zoom_lvl = (self.global_state.settings.interface.map_zoom
* (scrolled * 0.05 * -1.0).exp2())
.clamped(1.25, max_zoom / 64.0);
events.push(Event::MapZoom(new_zoom_lvl as f64));
events.push(InterfaceChange::MapZoom(new_zoom_lvl as f64).into());
// Icon settings
// Alignment
Rectangle::fill_with([150.0, 200.0], color::TRANSPARENT)
@ -398,7 +396,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.show_difficulty_box, ui)
.was_clicked()
{
events.push(Event::ShowDifficulties(!show_difficulty));
events.push(InterfaceChange::MapShowDifficulty(!show_difficulty).into());
}
Text::new(i18n.get("hud.map.difficulty"))
.right_from(state.ids.show_difficulty_box, 10.0)
@ -432,7 +430,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.show_towns_box, ui)
.was_clicked()
{
events.push(Event::ShowTowns(!show_towns));
events.push(InterfaceChange::MapShowTowns(!show_towns).into());
}
Text::new(i18n.get("hud.map.towns"))
.right_from(state.ids.show_towns_box, 10.0)
@ -466,7 +464,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.show_castles_box, ui)
.was_clicked()
{
events.push(Event::ShowCastles(!show_castles));
events.push(InterfaceChange::MapShowCastles(!show_castles).into());
}
Text::new(i18n.get("hud.map.castles"))
.right_from(state.ids.show_castles_box, 10.0)
@ -500,7 +498,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.show_dungeons_box, ui)
.was_clicked()
{
events.push(Event::ShowDungeons(!show_dungeons));
events.push(InterfaceChange::MapShowDungeons(!show_dungeons).into());
}
Text::new(i18n.get("hud.map.dungeons"))
.right_from(state.ids.show_dungeons_box, 10.0)
@ -534,7 +532,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.show_caves_box, ui)
.was_clicked()
{
events.push(Event::ShowCaves(!show_caves));
events.push(InterfaceChange::MapShowCaves(!show_caves).into());
}
Text::new(i18n.get("hud.map.caves"))
.right_from(state.ids.show_caves_box, 10.0)
@ -568,7 +566,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.show_trees_box, ui)
.was_clicked()
{
events.push(Event::ShowTrees(!show_trees));
events.push(InterfaceChange::MapShowTrees(!show_trees).into());
}
Text::new(i18n.get("hud.map.trees"))
.right_from(state.ids.show_trees_box, 10.0)
@ -898,7 +896,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.recenter_button, ui)
.was_clicked()
{
events.push(Event::MapDrag(Vec2::zero()));
events.push(InterfaceChange::MapDrag(Vec2::zero()).into());
};
Image::new(self.imgs.m_move_ico)
@ -942,7 +940,7 @@ impl<'a> Widget for Map<'a> {
.set(state.ids.map_mode_btn, ui)
.was_clicked()
{
events.push(Event::ShowTopoMap(!show_topo_map));
events.push(InterfaceChange::MapShowTopoMap(!show_topo_map).into());
};
Button::image(self.imgs.map_mode_overlay)
.w_h(92.0, icon_size.y)

View File

@ -50,15 +50,17 @@ use trade::Trade;
use crate::{
ecs::{comp as vcomp, comp::HpFloaterList},
hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent},
i18n::{LanguageMetadata, Localization},
render::{Consts, Globals, RenderMode, Renderer},
i18n::Localization,
render::{Consts, Globals, Renderer},
scene::camera::{self, Camera},
session::Interactable,
settings::Fps,
session::{
settings_change::{Interface as InterfaceChange, SettingsChange},
Interactable,
},
ui::{
fonts::Fonts, img_ids::Rotations, slot, slot::SlotKey, Graphic, Ingameable, ScaleMode, Ui,
},
window::{Event as WinEvent, FullScreenSettings, GameInput},
window::{Event as WinEvent, GameInput},
GlobalState,
};
use client::Client;
@ -351,55 +353,8 @@ pub struct HudInfo {
#[derive(Clone)]
pub enum Event {
ToggleTips(bool),
SendMessage(String),
AdjustMousePan(u32),
AdjustMouseZoom(u32),
AdjustCameraClamp(u32),
ToggleZoomInvert(bool),
ToggleMouseYInvert(bool),
ToggleControllerYInvert(bool),
ToggleSmoothPan(bool),
AdjustViewDistance(u32),
AdjustLodDetail(u32),
AdjustSpriteRenderDistance(u32),
AdjustFigureLoDRenderDistance(u32),
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
//ChangeAudioDevice(String),
ChangeMaxFPS(Fps),
ChangeFOV(u16),
ChangeGamma(f32),
ChangeExposure(f32),
ChangeAmbiance(f32),
MapZoom(f64),
MapDrag(Vec2<f64>),
MapShowTopoMap(bool),
MapShowDifficulty(bool),
MapShowTowns(bool),
MapShowDungeons(bool),
MapShowCastles(bool),
MapShowCaves(bool),
MapShowTrees(bool),
AdjustWindowSize([u16; 2]),
ChangeFullscreenMode(FullScreenSettings),
ToggleParticlesEnabled(bool),
CrosshairTransp(f32),
ChatTransp(f32),
ChatCharName(bool),
CrosshairType(CrosshairType),
BuffPosition(BuffPosition),
ToggleXpBar(XpBar),
Intro(Intro),
ToggleBarNumbers(BarNumbers),
ToggleShortcutNumbers(ShortcutNumbers),
Sct(bool),
SctPlayerBatch(bool),
SctDamageBatch(bool),
SpeechBubbleDarkMode(bool),
SpeechBubbleIcon(bool),
ToggleDebug(bool),
UiScale(ScaleChange),
CharacterSelection,
UseSlot {
slot: comp::slot::Slot,
@ -423,19 +378,7 @@ pub enum Event {
Ability4(bool),
Logout,
Quit,
ChangeLanguage(Box<LanguageMetadata>),
ChangeBinding(GameInput),
ResetInterfaceSettings,
ResetGameplaySettings,
ResetKeyBindings,
ResetGraphicsSettings,
ResetAudioSettings,
ChangeFreeLookBehavior(PressBehavior),
ChangeRenderMode(Box<RenderMode>),
ChangeAutoWalkBehavior(PressBehavior),
ChangeCameraClampBehavior(PressBehavior),
ChangeStopAutoWalkOnInput(bool),
ChangeAutoCamera(bool),
CraftRecipe(String),
InviteMember(Uid),
AcceptInvite,
@ -448,6 +391,8 @@ pub enum Event {
MinimapShow(bool),
MinimapFaceNorth(bool),
RequestSiteInfo(SiteId),
SettingsChange(SettingsChange),
}
// TODO: Are these the possible layouts we want?
@ -1878,7 +1823,9 @@ impl Hud {
.was_clicked()
{
self.show.intro = false;
events.push(Event::Intro(Intro::Never));
events.push(Event::SettingsChange(
InterfaceChange::Intro(Intro::Never).into(),
));
self.show.want_grab = true;
}
if !self.show.crafting && !self.show.bag {
@ -2556,29 +2503,6 @@ impl Hud {
.set(self.ids.settings_window, ui_widgets)
{
match event {
settings_window::Event::SpeechBubbleDarkMode(sbdm) => {
events.push(Event::SpeechBubbleDarkMode(sbdm));
},
settings_window::Event::SpeechBubbleIcon(sbi) => {
events.push(Event::SpeechBubbleIcon(sbi));
},
settings_window::Event::Sct(sct) => {
events.push(Event::Sct(sct));
},
settings_window::Event::SctPlayerBatch(sct_player_batch) => {
events.push(Event::SctPlayerBatch(sct_player_batch));
},
settings_window::Event::SctDamageBatch(sct_damage_batch) => {
events.push(Event::SctDamageBatch(sct_damage_batch));
},
settings_window::Event::ToggleHelp => self.show.help = !self.show.help,
settings_window::Event::ToggleDebug => {
self.show.debug = !self.show.debug;
events.push(Event::ToggleDebug(self.show.debug));
},
settings_window::Event::ToggleTips(loading_tips) => {
events.push(Event::ToggleTips(loading_tips));
},
settings_window::Event::ChangeTab(tab) => self.show.open_setting_tab(tab),
settings_window::Event::Close => {
// Unpause the game if we are on singleplayer so that we can logout
@ -2589,136 +2513,21 @@ impl Hud {
self.show.settings(false)
},
settings_window::Event::AdjustMousePan(sensitivity) => {
events.push(Event::AdjustMousePan(sensitivity));
},
settings_window::Event::AdjustMouseZoom(sensitivity) => {
events.push(Event::AdjustMouseZoom(sensitivity));
},
settings_window::Event::AdjustCameraClamp(sensitivity) => {
events.push(Event::AdjustCameraClamp(sensitivity));
},
settings_window::Event::ChatTransp(chat_transp) => {
events.push(Event::ChatTransp(chat_transp));
},
settings_window::Event::ChatCharName(chat_char_name) => {
events.push(Event::ChatCharName(chat_char_name));
},
settings_window::Event::ToggleZoomInvert(zoom_inverted) => {
events.push(Event::ToggleZoomInvert(zoom_inverted));
},
settings_window::Event::BuffPosition(buff_position) => {
events.push(Event::BuffPosition(buff_position));
},
settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => {
events.push(Event::ToggleMouseYInvert(mouse_y_inverted));
},
settings_window::Event::ToggleControllerYInvert(controller_y_inverted) => {
events.push(Event::ToggleControllerYInvert(controller_y_inverted));
},
settings_window::Event::ToggleSmoothPan(smooth_pan_enabled) => {
events.push(Event::ToggleSmoothPan(smooth_pan_enabled));
},
settings_window::Event::AdjustViewDistance(view_distance) => {
events.push(Event::AdjustViewDistance(view_distance));
},
settings_window::Event::AdjustLodDetail(lod_detail) => {
events.push(Event::AdjustLodDetail(lod_detail));
},
settings_window::Event::AdjustSpriteRenderDistance(view_distance) => {
events.push(Event::AdjustSpriteRenderDistance(view_distance));
},
settings_window::Event::AdjustFigureLoDRenderDistance(view_distance) => {
events.push(Event::AdjustFigureLoDRenderDistance(view_distance));
},
settings_window::Event::CrosshairTransp(crosshair_transp) => {
events.push(Event::CrosshairTransp(crosshair_transp));
},
settings_window::Event::AdjustMusicVolume(music_volume) => {
events.push(Event::AdjustMusicVolume(music_volume));
},
settings_window::Event::AdjustSfxVolume(sfx_volume) => {
events.push(Event::AdjustSfxVolume(sfx_volume));
},
settings_window::Event::MaximumFPS(max_fps) => {
events.push(Event::ChangeMaxFPS(max_fps));
},
//settings_window::Event::ChangeAudioDevice(name) => {
// events.push(Event::ChangeAudioDevice(name));
//},
settings_window::Event::CrosshairType(crosshair_type) => {
events.push(Event::CrosshairType(crosshair_type));
},
settings_window::Event::ToggleBarNumbers(bar_numbers) => {
events.push(Event::ToggleBarNumbers(bar_numbers));
},
settings_window::Event::ToggleShortcutNumbers(shortcut_numbers) => {
events.push(Event::ToggleShortcutNumbers(shortcut_numbers));
},
settings_window::Event::UiScale(scale_change) => {
events.push(Event::UiScale(scale_change));
},
settings_window::Event::AdjustFOV(new_fov) => {
events.push(Event::ChangeFOV(new_fov));
},
settings_window::Event::AdjustGamma(new_gamma) => {
events.push(Event::ChangeGamma(new_gamma));
},
settings_window::Event::AdjustExposure(new_exposure) => {
events.push(Event::ChangeExposure(new_exposure));
},
settings_window::Event::AdjustAmbiance(new_ambiance) => {
events.push(Event::ChangeAmbiance(new_ambiance));
},
settings_window::Event::ChangeRenderMode(new_render_mode) => {
events.push(Event::ChangeRenderMode(new_render_mode));
},
settings_window::Event::ChangeLanguage(language) => {
events.push(Event::ChangeLanguage(language));
},
settings_window::Event::ChangeFullscreenMode(new_fullscreen_settings) => {
events.push(Event::ChangeFullscreenMode(new_fullscreen_settings));
},
settings_window::Event::ToggleParticlesEnabled(particles_enabled) => {
events.push(Event::ToggleParticlesEnabled(particles_enabled));
},
settings_window::Event::AdjustWindowSize(new_size) => {
events.push(Event::AdjustWindowSize(new_size));
},
settings_window::Event::ChangeBinding(game_input) => {
events.push(Event::ChangeBinding(game_input));
},
settings_window::Event::ChangeFreeLookBehavior(behavior) => {
events.push(Event::ChangeFreeLookBehavior(behavior));
},
settings_window::Event::ChangeAutoWalkBehavior(behavior) => {
events.push(Event::ChangeAutoWalkBehavior(behavior));
},
settings_window::Event::ChangeCameraClampBehavior(behavior) => {
events.push(Event::ChangeCameraClampBehavior(behavior));
},
settings_window::Event::ChangeStopAutoWalkOnInput(state) => {
events.push(Event::ChangeStopAutoWalkOnInput(state));
},
settings_window::Event::ChangeAutoCamera(state) => {
events.push(Event::ChangeAutoCamera(state));
},
settings_window::Event::ResetInterfaceSettings => {
self.show.help = false;
self.show.debug = false;
events.push(Event::ResetInterfaceSettings);
},
settings_window::Event::ResetGameplaySettings => {
events.push(Event::ResetGameplaySettings);
},
settings_window::Event::ResetKeyBindings => {
events.push(Event::ResetKeyBindings);
},
settings_window::Event::ResetGraphicsSettings => {
events.push(Event::ResetGraphicsSettings);
},
settings_window::Event::ResetAudioSettings => {
events.push(Event::ResetAudioSettings);
settings_window::Event::SettingsChange(settings_change) => {
match &settings_change {
SettingsChange::Interface(interface_change) => match interface_change {
InterfaceChange::ToggleHelp(toggle_help) => {
self.show.help = *toggle_help;
},
InterfaceChange::ResetInterfaceSettings => {
self.show.help = false;
self.show.debug = false;
},
_ => {},
},
_ => {},
}
events.push(Event::SettingsChange(settings_change));
},
}
}
@ -2818,32 +2627,8 @@ impl Hud {
self.show.want_grab = true;
self.force_ungrab = false;
},
map::Event::ShowTopoMap(map_show_topo_map) => {
events.push(Event::MapShowTopoMap(map_show_topo_map));
},
map::Event::ShowDifficulties(map_show_difficulties) => {
events.push(Event::MapShowDifficulty(map_show_difficulties));
},
map::Event::ShowTowns(map_show_towns) => {
events.push(Event::MapShowTowns(map_show_towns));
},
map::Event::ShowCastles(map_show_castles) => {
events.push(Event::MapShowCastles(map_show_castles));
},
map::Event::ShowDungeons(map_show_dungeons) => {
events.push(Event::MapShowDungeons(map_show_dungeons));
},
map::Event::MapZoom(map_zoom) => {
events.push(Event::MapZoom(map_zoom));
},
map::Event::MapDrag(map_drag) => {
events.push(Event::MapDrag(map_drag));
},
map::Event::ShowCaves(map_show_caves) => {
events.push(Event::MapShowCaves(map_show_caves));
},
map::Event::ShowTrees(map_show_trees) => {
events.push(Event::MapShowTrees(map_show_trees));
map::Event::SettingsChange(settings_change) => {
events.push(Event::SettingsChange(settings_change));
},
map::Event::RequestSiteInfo(id) => {
events.push(Event::RequestSiteInfo(id));
@ -2854,7 +2639,9 @@ impl Hud {
// Reset the map position when it's not showing
let drag = &global_state.settings.interface.map_drag;
if drag.x != 0.0 || drag.y != 0.0 {
events.push(Event::MapDrag(Vec2::zero()))
events.push(Event::SettingsChange(
InterfaceChange::MapDrag(Vec2::zero()).into(),
))
}
}

View File

@ -1,8 +1,9 @@
use super::{Event, RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use super::{RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use crate::{
hud::{img_ids::Imgs, ERROR_COLOR, TEXT_BIND_CONFLICT_COLOR, TEXT_COLOR},
i18n::Localization,
session::settings_change::Control as ControlChange,
ui::fonts::Fonts,
window::GameInput,
GlobalState,
@ -57,7 +58,7 @@ pub struct State {
}
impl<'a> Widget for Controls<'a> {
type Event = Vec<Event>;
type Event = Vec<ControlChange>;
type State = State;
type Style = ();
@ -167,7 +168,7 @@ impl<'a> Widget for Controls<'a> {
.set(button_id, ui)
.was_clicked()
{
events.push(Event::ChangeBinding(game_input));
events.push(ControlChange::ChangeBinding(game_input));
}
// Set the previous id to the current one for the next cycle
previous_element_id = Some(text_id);
@ -188,7 +189,7 @@ impl<'a> Widget for Controls<'a> {
.set(state.ids.reset_controls_button, ui)
.was_clicked()
{
events.push(Event::ResetKeyBindings);
events.push(ControlChange::ResetKeyBindings);
}
previous_element_id = Some(state.ids.reset_controls_button)
}

View File

@ -1,8 +1,9 @@
use super::{Event, RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use super::{RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use crate::{
hud::{img_ids::Imgs, PressBehavior, MENU_BG, TEXT_COLOR},
i18n::Localization,
session::settings_change::Gameplay as GameplayChange,
ui::{fonts::Fonts, ImageSlider, ToggleButton},
GlobalState,
};
@ -81,7 +82,7 @@ pub struct State {
}
impl<'a> Widget for Gameplay<'a> {
type Event = Vec<Event>;
type Event = Vec<GameplayChange>;
type State = State;
type Style = ();
@ -140,7 +141,7 @@ impl<'a> Widget for Gameplay<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.mouse_pan_slider, ui)
{
events.push(Event::AdjustMousePan(new_val));
events.push(GameplayChange::AdjustMousePan(new_val));
}
Text::new(&format!("{}", display_pan))
@ -172,7 +173,7 @@ impl<'a> Widget for Gameplay<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.mouse_zoom_slider, ui)
{
events.push(Event::AdjustMouseZoom(new_val));
events.push(GameplayChange::AdjustMouseZoom(new_val));
}
Text::new(&format!("{}", display_zoom))
@ -208,7 +209,7 @@ impl<'a> Widget for Gameplay<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.camera_clamp_slider, ui)
{
events.push(Event::AdjustCameraClamp(new_val));
events.push(GameplayChange::AdjustCameraClamp(new_val));
}
Text::new(&format!("{}", display_clamp))
@ -231,7 +232,7 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.mouse_zoom_invert_button, ui);
if self.global_state.settings.gameplay.zoom_inversion != zoom_inverted {
events.push(Event::ToggleZoomInvert(
events.push(GameplayChange::ToggleZoomInvert(
!self.global_state.settings.gameplay.zoom_inversion,
));
}
@ -261,7 +262,7 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.mouse_y_invert_button, ui);
if self.global_state.settings.gameplay.mouse_y_inversion != mouse_y_inverted {
events.push(Event::ToggleMouseYInvert(
events.push(GameplayChange::ToggleMouseYInvert(
!self.global_state.settings.gameplay.mouse_y_inversion,
));
}
@ -291,7 +292,7 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.controller_y_invert_button, ui);
if self.global_state.settings.controller.pan_invert_y != controller_y_inverted {
events.push(Event::ToggleControllerYInvert(
events.push(GameplayChange::ToggleControllerYInvert(
!self.global_state.settings.controller.pan_invert_y,
));
}
@ -321,7 +322,7 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.smooth_pan_toggle_button, ui);
if self.global_state.settings.gameplay.smooth_pan_enable != smooth_pan_enabled {
events.push(Event::ToggleSmoothPan(
events.push(GameplayChange::ToggleSmoothPan(
!self.global_state.settings.gameplay.smooth_pan_enable,
));
}
@ -371,8 +372,10 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.free_look_behavior_list, ui)
{
match clicked {
0 => events.push(Event::ChangeFreeLookBehavior(PressBehavior::Toggle)),
1 => events.push(Event::ChangeFreeLookBehavior(PressBehavior::Hold)),
0 => events.push(GameplayChange::ChangeFreeLookBehavior(
PressBehavior::Toggle,
)),
1 => events.push(GameplayChange::ChangeFreeLookBehavior(PressBehavior::Hold)),
_ => unreachable!(),
}
}
@ -401,8 +404,10 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.auto_walk_behavior_list, ui)
{
match clicked {
0 => events.push(Event::ChangeAutoWalkBehavior(PressBehavior::Toggle)),
1 => events.push(Event::ChangeAutoWalkBehavior(PressBehavior::Hold)),
0 => events.push(GameplayChange::ChangeAutoWalkBehavior(
PressBehavior::Toggle,
)),
1 => events.push(GameplayChange::ChangeAutoWalkBehavior(PressBehavior::Hold)),
_ => unreachable!(),
}
}
@ -431,8 +436,12 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.camera_clamp_behavior_list, ui)
{
match clicked {
0 => events.push(Event::ChangeCameraClampBehavior(PressBehavior::Toggle)),
1 => events.push(Event::ChangeCameraClampBehavior(PressBehavior::Hold)),
0 => events.push(GameplayChange::ChangeCameraClampBehavior(
PressBehavior::Toggle,
)),
1 => events.push(GameplayChange::ChangeCameraClampBehavior(
PressBehavior::Hold,
)),
_ => unreachable!(),
}
}
@ -452,7 +461,7 @@ impl<'a> Widget for Gameplay<'a> {
if self.global_state.settings.gameplay.stop_auto_walk_on_input
!= stop_auto_walk_on_input_toggle
{
events.push(Event::ChangeStopAutoWalkOnInput(
events.push(GameplayChange::ChangeStopAutoWalkOnInput(
!self.global_state.settings.gameplay.stop_auto_walk_on_input,
));
}
@ -482,7 +491,7 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.auto_camera_button, ui);
if self.global_state.settings.gameplay.auto_camera != auto_camera_toggle {
events.push(Event::ChangeAutoCamera(
events.push(GameplayChange::ChangeAutoCamera(
!self.global_state.settings.gameplay.auto_camera,
));
}
@ -509,7 +518,7 @@ impl<'a> Widget for Gameplay<'a> {
.set(state.ids.reset_gameplay_button, ui)
.was_clicked()
{
events.push(Event::ResetGameplaySettings);
events.push(GameplayChange::ResetGameplaySettings);
}
events

View File

@ -1,10 +1,11 @@
use super::{Event, ScaleChange, RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use super::{ScaleChange, RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use crate::{
hud::{
img_ids::Imgs, BarNumbers, BuffPosition, CrosshairType, ShortcutNumbers, Show, TEXT_COLOR,
},
i18n::Localization,
session::settings_change::Interface as InterfaceChange,
ui::{fonts::Fonts, ImageSlider, ScaleMode, ToggleButton},
GlobalState,
};
@ -126,7 +127,7 @@ pub struct State {
}
impl<'a> Widget for Interface<'a> {
type Event = Vec<Event>;
type Event = Vec<InterfaceChange>;
type State = State;
type Style = ();
@ -185,7 +186,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.button_help, ui);
if self.show.help != show_help {
events.push(Event::ToggleHelp);
events.push(InterfaceChange::ToggleHelp(show_help));
}
Text::new(&self.localized_strings.get("hud.settings.help_window"))
@ -209,7 +210,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.load_tips_button, ui);
if self.global_state.settings.interface.loading_tips != show_tips {
events.push(Event::ToggleTips(
events.push(InterfaceChange::ToggleTips(
!self.global_state.settings.interface.loading_tips,
));
}
@ -234,7 +235,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.debug_button, ui);
if self.show.debug != show_debug {
events.push(Event::ToggleDebug);
events.push(InterfaceChange::ToggleDebug(show_debug));
}
Text::new(&self.localized_strings.get("hud.settings.debug_info"))
@ -277,7 +278,7 @@ impl<'a> Widget for Interface<'a> {
.was_clicked()
&& !relative_selected
{
events.push(Event::UiScale(ScaleChange::ToRelative));
events.push(InterfaceChange::UiScale(ScaleChange::ToRelative));
}
Text::new(self.localized_strings.get("hud.settings.relative_scaling"))
@ -312,7 +313,7 @@ impl<'a> Widget for Interface<'a> {
.was_clicked()
&& !absolute_selected
{
events.push(Event::UiScale(ScaleChange::ToAbsolute));
events.push(InterfaceChange::UiScale(ScaleChange::ToAbsolute));
}
Text::new(self.localized_strings.get("hud.settings.custom_scaling"))
@ -339,7 +340,9 @@ impl<'a> Widget for Interface<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.ui_scale_slider, ui)
{
events.push(Event::UiScale(ScaleChange::Adjust(2.0f64.powf(new_val))));
events.push(InterfaceChange::UiScale(ScaleChange::Adjust(
2.0f64.powf(new_val),
)));
}
// Custom Scaling Text
Text::new(&format!("{:.2}", scale))
@ -384,7 +387,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.ch_1_bg, ui)
.was_clicked()
{
events.push(Event::CrosshairType(CrosshairType::Round));
events.push(InterfaceChange::CrosshairType(CrosshairType::Round));
}
// Crosshair
@ -427,7 +430,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.ch_2_bg, ui)
.was_clicked()
{
events.push(Event::CrosshairType(CrosshairType::RoundEdges));
events.push(InterfaceChange::CrosshairType(CrosshairType::RoundEdges));
}
// Crosshair
@ -470,7 +473,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.ch_3_bg, ui)
.was_clicked()
{
events.push(Event::CrosshairType(CrosshairType::Edges));
events.push(InterfaceChange::CrosshairType(CrosshairType::Edges));
}
// Crosshair
@ -519,7 +522,7 @@ impl<'a> Widget for Interface<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.ch_transp_slider, ui)
{
events.push(Event::CrosshairTransp(new_val));
events.push(InterfaceChange::CrosshairTransp(new_val));
}
Text::new(&format!("{:.2}", crosshair_transp,))
@ -563,10 +566,10 @@ impl<'a> Widget for Interface<'a> {
{
match self.global_state.settings.interface.shortcut_numbers {
ShortcutNumbers::On => {
events.push(Event::ToggleShortcutNumbers(ShortcutNumbers::Off))
events.push(InterfaceChange::ToggleShortcutNumbers(ShortcutNumbers::Off))
},
ShortcutNumbers::Off => {
events.push(Event::ToggleShortcutNumbers(ShortcutNumbers::On))
events.push(InterfaceChange::ToggleShortcutNumbers(ShortcutNumbers::On))
},
}
}
@ -596,7 +599,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.buff_pos_bar_button, ui)
.was_clicked()
{
events.push(Event::BuffPosition(BuffPosition::Bar))
events.push(InterfaceChange::BuffPosition(BuffPosition::Bar))
}
Text::new(&self.localized_strings.get("hud.settings.buffs_skillbar"))
.right_from(state.ids.buff_pos_bar_button, 10.0)
@ -623,7 +626,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.buff_pos_map_button, ui)
.was_clicked()
{
events.push(Event::BuffPosition(BuffPosition::Map))
events.push(InterfaceChange::BuffPosition(BuffPosition::Map))
}
Text::new(&self.localized_strings.get("hud.settings.buffs_mmap"))
.right_from(state.ids.buff_pos_map_button, 10.0)
@ -669,7 +672,9 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.sct_show_radio, ui);
if self.global_state.settings.interface.sct != show_sct {
events.push(Event::Sct(!self.global_state.settings.interface.sct))
events.push(InterfaceChange::Sct(
!self.global_state.settings.interface.sct,
))
}
Text::new(
&self
@ -719,7 +724,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.sct_show_batch_radio, ui);
if self.global_state.settings.interface.sct_damage_batch != show_sct_damage_batch {
events.push(Event::SctDamageBatch(
events.push(InterfaceChange::SctDamageBatch(
!self.global_state.settings.interface.sct_damage_batch,
))
}
@ -762,7 +767,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.sct_batch_inc_radio, ui);
if self.global_state.settings.interface.sct_player_batch != show_sct_player_batch {
events.push(Event::SctPlayerBatch(
events.push(InterfaceChange::SctPlayerBatch(
!self.global_state.settings.interface.sct_player_batch,
))
}
@ -806,7 +811,9 @@ impl<'a> Widget for Interface<'a> {
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.speech_bubble_dark_mode_button, ui);
if self.global_state.settings.interface.speech_bubble_dark_mode != speech_bubble_dark_mode {
events.push(Event::SpeechBubbleDarkMode(speech_bubble_dark_mode));
events.push(InterfaceChange::SpeechBubbleDarkMode(
speech_bubble_dark_mode,
));
}
Text::new(
&self
@ -830,7 +837,7 @@ impl<'a> Widget for Interface<'a> {
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.speech_bubble_icon_button, ui);
if self.global_state.settings.interface.speech_bubble_icon != speech_bubble_icon {
events.push(Event::SpeechBubbleIcon(speech_bubble_icon));
events.push(InterfaceChange::SpeechBubbleIcon(speech_bubble_icon));
}
Text::new(
&self
@ -873,7 +880,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.show_bar_numbers_none_button, ui)
.was_clicked()
{
events.push(Event::ToggleBarNumbers(BarNumbers::Off))
events.push(InterfaceChange::ToggleBarNumbers(BarNumbers::Off))
}
Text::new(&self.localized_strings.get("hud.settings.none"))
.right_from(state.ids.show_bar_numbers_none_button, 10.0)
@ -904,7 +911,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.show_bar_numbers_values_button, ui)
.was_clicked()
{
events.push(Event::ToggleBarNumbers(BarNumbers::Values))
events.push(InterfaceChange::ToggleBarNumbers(BarNumbers::Values))
}
Text::new(&self.localized_strings.get("hud.settings.values"))
.right_from(state.ids.show_bar_numbers_values_button, 10.0)
@ -935,7 +942,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.show_bar_numbers_percentage_button, ui)
.was_clicked()
{
events.push(Event::ToggleBarNumbers(BarNumbers::Percent))
events.push(InterfaceChange::ToggleBarNumbers(BarNumbers::Percent))
}
Text::new(&self.localized_strings.get("hud.settings.percentages"))
.right_from(state.ids.show_bar_numbers_percentage_button, 10.0)
@ -977,7 +984,7 @@ impl<'a> Widget for Interface<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.chat_transp_slider, ui)
{
events.push(Event::ChatTransp(new_val));
events.push(InterfaceChange::ChatTransp(new_val));
}
// "Show character names in chat" toggle button
@ -992,7 +999,7 @@ impl<'a> Widget for Interface<'a> {
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.chat_char_name_button, ui);
if self.global_state.settings.interface.chat_character_name != chat_char_name {
events.push(Event::ChatCharName(
events.push(InterfaceChange::ChatCharName(
!self.global_state.settings.interface.chat_character_name,
));
}
@ -1023,7 +1030,7 @@ impl<'a> Widget for Interface<'a> {
.set(state.ids.reset_interface_button, ui)
.was_clicked()
{
events.push(Event::ResetInterfaceSettings);
events.push(InterfaceChange::ResetInterfaceSettings);
}
events

View File

@ -1,8 +1,7 @@
use super::Event;
use crate::{
hud::{img_ids::Imgs, TEXT_COLOR},
i18n::list_localizations,
session::settings_change::Language as LanguageChange,
ui::fonts::Fonts,
GlobalState,
};
@ -45,7 +44,7 @@ pub struct State {
}
impl<'a> Widget for Language<'a> {
type Event = Vec<Event>;
type Event = Vec<LanguageChange>;
type State = State;
type Style = ();
@ -114,7 +113,9 @@ impl<'a> Widget for Language<'a> {
.set(state.ids.language_list[i], ui)
.was_clicked()
{
events.push(Event::ChangeLanguage(Box::new(language.to_owned())));
events.push(LanguageChange::ChangeLanguage(Box::new(
language.to_owned(),
)));
}
}

View File

@ -6,15 +6,10 @@ mod sound;
mod video;
use crate::{
hud::{
img_ids::Imgs, BarNumbers, BuffPosition, CrosshairType, PressBehavior, ShortcutNumbers,
Show, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN,
},
i18n::{LanguageMetadata, Localization},
render::RenderMode,
settings::Fps,
hud::{img_ids::Imgs, Show, TEXT_COLOR, UI_HIGHLIGHT_0, UI_MAIN},
i18n::Localization,
session::settings_change::SettingsChange,
ui::fonts::Fonts,
window::{FullScreenSettings, GameInput},
GlobalState,
};
use conrod_core::{
@ -120,59 +115,9 @@ pub struct State {
}
pub enum Event {
ToggleHelp,
ToggleDebug,
ToggleTips(bool),
ToggleBarNumbers(BarNumbers),
ToggleShortcutNumbers(ShortcutNumbers),
BuffPosition(BuffPosition),
ChangeTab(SettingsTab),
Close,
AdjustMousePan(u32),
AdjustMouseZoom(u32),
AdjustCameraClamp(u32),
ToggleZoomInvert(bool),
ToggleMouseYInvert(bool),
ToggleControllerYInvert(bool),
ToggleSmoothPan(bool),
AdjustViewDistance(u32),
AdjustSpriteRenderDistance(u32),
AdjustFigureLoDRenderDistance(u32),
AdjustFOV(u16),
AdjustLodDetail(u32),
AdjustGamma(f32),
AdjustExposure(f32),
AdjustAmbiance(f32),
AdjustWindowSize([u16; 2]),
ChangeFullscreenMode(FullScreenSettings),
ToggleParticlesEnabled(bool),
ChangeRenderMode(Box<RenderMode>),
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
//ChangeAudioDevice(String),
MaximumFPS(Fps),
CrosshairTransp(f32),
CrosshairType(CrosshairType),
UiScale(ScaleChange),
ChatTransp(f32),
ChatCharName(bool),
Sct(bool),
SctPlayerBatch(bool),
SctDamageBatch(bool),
SpeechBubbleDarkMode(bool),
SpeechBubbleIcon(bool),
ChangeLanguage(Box<LanguageMetadata>),
ChangeBinding(GameInput),
ResetInterfaceSettings,
ResetGameplaySettings,
ResetKeyBindings,
ResetGraphicsSettings,
ResetAudioSettings,
ChangeFreeLookBehavior(PressBehavior),
ChangeAutoWalkBehavior(PressBehavior),
ChangeCameraClampBehavior(PressBehavior),
ChangeStopAutoWalkOnInput(bool),
ChangeAutoCamera(bool),
SettingsChange(SettingsChange),
}
#[derive(Clone)]
@ -294,41 +239,63 @@ impl<'a> Widget for SettingsWindow<'a> {
let imgs = self.imgs;
let fonts = self.fonts;
let localized_strings = self.localized_strings;
for event in match self.show.settings_tab {
match self.show.settings_tab {
SettingsTab::Interface => {
interface::Interface::new(global_state, show, imgs, fonts, localized_strings)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.interface, ui)
for change in
interface::Interface::new(global_state, show, imgs, fonts, localized_strings)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.interface, ui)
{
events.push(Event::SettingsChange(change.into()));
}
},
SettingsTab::Gameplay => {
gameplay::Gameplay::new(global_state, imgs, fonts, localized_strings)
for change in gameplay::Gameplay::new(global_state, imgs, fonts, localized_strings)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.gameplay, ui)
{
events.push(Event::SettingsChange(change.into()));
}
},
SettingsTab::Controls => {
controls::Controls::new(global_state, imgs, fonts, localized_strings)
for change in controls::Controls::new(global_state, imgs, fonts, localized_strings)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.controls, ui)
{
events.push(Event::SettingsChange(change.into()));
}
},
SettingsTab::Video => {
video::Video::new(global_state, imgs, fonts, localized_strings, self.fps)
for change in
video::Video::new(global_state, imgs, fonts, localized_strings, self.fps)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.video, ui)
{
events.push(Event::SettingsChange(change.into()));
}
},
SettingsTab::Sound => {
for change in sound::Sound::new(global_state, imgs, fonts, localized_strings)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.video, ui)
.set(state.ids.sound, ui)
{
events.push(Event::SettingsChange(change.into()));
}
},
SettingsTab::Lang => {
for change in language::Language::new(global_state, imgs, fonts)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.language, ui)
{
events.push(Event::SettingsChange(change.into()));
}
},
SettingsTab::Sound => sound::Sound::new(global_state, imgs, fonts, localized_strings)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.sound, ui),
SettingsTab::Lang => language::Language::new(global_state, imgs, fonts)
.top_left_with_margins_on(state.ids.settings_content_align, 0.0, 0.0)
.wh_of(state.ids.settings_content_align)
.set(state.ids.language, ui),
} {
events.push(event);
}
events

View File

@ -1,8 +1,9 @@
use super::{Event, RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use super::{RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use crate::{
hud::{img_ids::Imgs, TEXT_COLOR},
i18n::Localization,
session::settings_change::Audio as AudioChange,
ui::{fonts::Fonts, ImageSlider},
GlobalState,
};
@ -59,7 +60,7 @@ pub struct State {
}
impl<'a> Widget for Sound<'a> {
type Event = Vec<Event>;
type Event = Vec<AudioChange>;
type State = State;
type Style = ();
@ -114,7 +115,7 @@ impl<'a> Widget for Sound<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.audio_volume_slider, ui)
{
events.push(Event::AdjustMusicVolume(new_val));
events.push(AudioChange::AdjustMusicVolume(new_val));
}
// SFX Volume -------------------------------------------------------
@ -143,7 +144,7 @@ impl<'a> Widget for Sound<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.sfx_volume_slider, ui)
{
events.push(Event::AdjustSfxVolume(new_val));
events.push(AudioChange::AdjustSfxVolume(new_val));
}
// Audio Device Selector
@ -170,7 +171,7 @@ impl<'a> Widget for Sound<'a> {
// .set(state.ids.audio_device_list, ui)
//{
// let new_val = device_list[clicked].clone();
// events.push(Event::ChangeAudioDevice(new_val));
// events.push(AudioChange::ChangeAudioDevice(new_val));
//}
// Reset the sound settings to the default settings
@ -187,7 +188,7 @@ impl<'a> Widget for Sound<'a> {
.set(state.ids.reset_sound_button, ui)
.was_clicked()
{
events.push(Event::ResetAudioSettings);
events.push(AudioChange::ResetAudioSettings);
}
events

View File

@ -1,4 +1,4 @@
use super::{Event, RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use super::{RESET_BUTTONS_HEIGHT, RESET_BUTTONS_WIDTH};
use crate::{
hud::{
@ -10,6 +10,7 @@ use crate::{
AaMode, CloudMode, FluidMode, LightingMode, RenderMode, ShadowMapMode, ShadowMode,
UpscaleMode,
},
session::settings_change::Graphics as GraphicsChange,
settings::Fps,
ui::{fonts::Fonts, ImageSlider, ToggleButton},
window::{FullScreenSettings, FullscreenMode},
@ -145,7 +146,7 @@ const FPS_CHOICES: [Fps; 12] = [
];
impl<'a> Widget for Video<'a> {
type Event = Vec<Event>;
type Event = Vec<GraphicsChange>;
type State = State;
type Style = ();
@ -226,7 +227,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.vd_slider, ui)
{
events.push(Event::AdjustViewDistance(new_val));
events.push(GraphicsChange::AdjustViewDistance(new_val));
}
Text::new(&format!(
@ -264,7 +265,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.max_fps_slider, ui)
{
events.push(Event::MaximumFPS(FPS_CHOICES[which]));
events.push(GraphicsChange::ChangeMaxFPS(FPS_CHOICES[which]));
}
Text::new(&self.global_state.settings.graphics.max_fps.to_string())
@ -296,7 +297,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.fov_slider, ui)
{
events.push(Event::AdjustFOV(new_val));
events.push(GraphicsChange::ChangeFOV(new_val));
}
Text::new(&format!("{}", self.global_state.settings.graphics.fov))
@ -329,7 +330,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.lod_detail_slider, ui)
{
events.push(Event::AdjustLodDetail(
events.push(GraphicsChange::AdjustLodDetail(
(5.0f32.powf(new_val as f32 / 10.0) * 100.0) as u32,
));
}
@ -366,7 +367,9 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.gamma_slider, ui)
{
events.push(Event::AdjustGamma(2.0f32.powf(new_val as f32 / 8.0)));
events.push(GraphicsChange::ChangeGamma(
2.0f32.powf(new_val as f32 / 8.0),
));
}
Text::new(&format!("{:.2}", self.global_state.settings.graphics.gamma))
@ -391,7 +394,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.exposure_slider, ui)
{
events.push(Event::AdjustExposure(new_val as f32 / 16.0));
events.push(GraphicsChange::ChangeExposure(new_val as f32 / 16.0));
}
Text::new(&self.localized_strings.get("hud.settings.exposure"))
@ -429,7 +432,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.ambiance_slider, ui)
{
events.push(Event::AdjustAmbiance(new_val as f32));
events.push(GraphicsChange::ChangeAmbiance(new_val as f32));
}
Text::new(&self.localized_strings.get("hud.settings.ambiance"))
.up_from(state.ids.ambiance_slider, 8.0)
@ -465,7 +468,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.sprite_dist_slider, ui)
{
events.push(Event::AdjustSpriteRenderDistance(new_val));
events.push(GraphicsChange::AdjustSpriteRenderDistance(new_val));
}
Text::new(
&self
@ -505,7 +508,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.figure_dist_slider, ui)
{
events.push(Event::AdjustFigureLoDRenderDistance(new_val));
events.push(GraphicsChange::AdjustFigureLoDRenderDistance(new_val));
}
Text::new(
&self
@ -569,7 +572,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.aa_mode_text, 8.0)
.set(state.ids.aa_mode_list, ui)
{
events.push(Event::ChangeRenderMode(Box::new(RenderMode {
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
aa: mode_list[clicked],
..render_mode.clone()
})));
@ -609,7 +612,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.upscale_factor_text, 8.0)
.set(state.ids.upscale_factor_list, ui)
{
events.push(Event::ChangeRenderMode(Box::new(RenderMode {
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
upscale_mode: UpscaleMode {
factor: upscale_factors[clicked],
},
@ -667,7 +670,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.cloud_mode_text, 8.0)
.set(state.ids.cloud_mode_list, ui)
{
events.push(Event::ChangeRenderMode(Box::new(RenderMode {
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
cloud: mode_list[clicked],
..render_mode.clone()
})));
@ -706,7 +709,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.fluid_mode_text, 8.0)
.set(state.ids.fluid_mode_list, ui)
{
events.push(Event::ChangeRenderMode(Box::new(RenderMode {
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
fluid: mode_list[clicked],
..render_mode.clone()
})));
@ -752,7 +755,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.lighting_mode_text, 8.0)
.set(state.ids.lighting_mode_list, ui)
{
events.push(Event::ChangeRenderMode(Box::new(RenderMode {
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
lighting: mode_list[clicked],
..render_mode.clone()
})));
@ -799,7 +802,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.shadow_mode_text, 8.0)
.set(state.ids.shadow_mode_list, ui)
{
events.push(Event::ChangeRenderMode(Box::new(RenderMode {
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
shadow: mode_list[clicked],
..render_mode.clone()
})));
@ -832,7 +835,7 @@ impl<'a> Widget for Video<'a> {
.pad_track((5.0, 5.0))
.set(state.ids.shadow_mode_map_resolution_slider, ui)
{
events.push(Event::ChangeRenderMode(Box::new(RenderMode {
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
shadow: ShadowMode::Map(ShadowMapMode {
resolution: 2.0f32.powf(f32::from(new_val) / 4.0),
}),
@ -870,7 +873,7 @@ impl<'a> Widget for Video<'a> {
.set(state.ids.particles_button, ui);
if self.global_state.settings.graphics.particles_enabled != particles_enabled {
events.push(Event::ToggleParticlesEnabled(particles_enabled));
events.push(GraphicsChange::ToggleParticlesEnabled(particles_enabled));
}
// Resolution
@ -907,7 +910,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.resolution_label, 10.0)
.set(state.ids.resolution, ui)
{
events.push(Event::ChangeFullscreenMode(FullScreenSettings {
events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings {
resolution: resolutions[clicked],
..self.global_state.settings.graphics.fullscreen
}));
@ -971,7 +974,7 @@ impl<'a> Widget for Video<'a> {
.right_from(state.ids.resolution, 8.0)
.set(state.ids.bit_depth, ui)
{
events.push(Event::ChangeFullscreenMode(FullScreenSettings {
events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings {
bit_depth: if clicked == 0 {
None
} else {
@ -1025,7 +1028,7 @@ impl<'a> Widget for Video<'a> {
.right_from(state.ids.bit_depth, 8.0)
.set(state.ids.refresh_rate, ui)
{
events.push(Event::ChangeFullscreenMode(FullScreenSettings {
events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings {
refresh_rate: if clicked == 0 {
None
} else {
@ -1055,7 +1058,7 @@ impl<'a> Widget for Video<'a> {
.set(state.ids.fullscreen_button, ui);
if self.global_state.settings.graphics.fullscreen.enabled != enabled {
events.push(Event::ChangeFullscreenMode(FullScreenSettings {
events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings {
enabled,
..self.global_state.settings.graphics.fullscreen
}));
@ -1092,7 +1095,7 @@ impl<'a> Widget for Video<'a> {
.down_from(state.ids.fullscreen_mode_text, 8.0)
.set(state.ids.fullscreen_mode_list, ui)
{
events.push(Event::ChangeFullscreenMode(FullScreenSettings {
events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings {
mode: mode_list[clicked],
..self.global_state.settings.graphics.fullscreen
}));
@ -1112,7 +1115,7 @@ impl<'a> Widget for Video<'a> {
.set(state.ids.save_window_size_button, ui)
.was_clicked()
{
events.push(Event::AdjustWindowSize(
events.push(GraphicsChange::AdjustWindowSize(
self.global_state
.window
.logical_size()
@ -1136,7 +1139,7 @@ impl<'a> Widget for Video<'a> {
.set(state.ids.reset_graphics_button, ui)
.was_clicked()
{
events.push(Event::ResetGraphicsSettings);
events.push(GraphicsChange::ResetGraphicsSettings);
}
events

View File

@ -1,3 +1,5 @@
pub mod settings_change;
use std::{cell::RefCell, collections::HashSet, rc::Rc, time::Duration};
use ordered_float::OrderedFloat;
@ -7,7 +9,6 @@ use vek::*;
use client::{self, Client};
use common::{
assets::AssetExt,
comp,
comp::{
inventory::slot::{EquipSlot, Slot},
@ -33,20 +34,16 @@ use common_net::{
use crate::{
audio::sfx::SfxEvent,
controller::ControllerSettings,
hud::{DebugInfo, Event as HudEvent, Hud, HudInfo, PromptDialogSettings},
i18n::{i18n_asset_key, Localization},
key_state::KeyState,
menu::char_selection::CharSelectionState,
render::Renderer,
scene::{camera, CameraMode, Scene, SceneData},
settings::{
AudioSettings, ControlSettings, GamepadSettings, GameplaySettings, GraphicsSettings,
InterfaceSettings, Settings,
},
settings::Settings,
window::{AnalogGameInput, Event, GameInput},
Direction, Error, GlobalState, PlayState, PlayStateResult,
};
use settings_change::Language::ChangeLanguage;
/// The action to perform after a tick
enum TickAction {
@ -903,9 +900,9 @@ impl PlayState for SessionState {
// Look for changes in the localization files
if global_state.i18n.reloaded() {
hud_events.push(HudEvent::ChangeLanguage(Box::new(
global_state.i18n.read().metadata.clone(),
)));
hud_events.push(HudEvent::SettingsChange(
ChangeLanguage(Box::new(global_state.i18n.read().metadata.clone())).into(),
));
}
// Maintain the UI.
@ -925,153 +922,7 @@ impl PlayState for SessionState {
HudEvent::Quit => {
return PlayStateResult::Shutdown;
},
HudEvent::AdjustMousePan(sensitivity) => {
global_state.window.pan_sensitivity = sensitivity;
global_state.settings.gameplay.pan_sensitivity = sensitivity;
global_state.settings.save_to_file_warn();
},
HudEvent::AdjustMouseZoom(sensitivity) => {
global_state.window.zoom_sensitivity = sensitivity;
global_state.settings.gameplay.zoom_sensitivity = sensitivity;
global_state.settings.save_to_file_warn();
},
HudEvent::AdjustCameraClamp(angle) => {
global_state.settings.gameplay.camera_clamp_angle = angle;
global_state.settings.save_to_file_warn();
},
HudEvent::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();
},
HudEvent::Sct(sct) => {
global_state.settings.interface.sct = sct;
global_state.settings.save_to_file_warn();
},
HudEvent::SctPlayerBatch(sct_player_batch) => {
global_state.settings.interface.sct_player_batch = sct_player_batch;
global_state.settings.save_to_file_warn();
},
HudEvent::ToggleTips(loading_tips) => {
global_state.settings.interface.loading_tips = loading_tips;
global_state.settings.save_to_file_warn();
},
HudEvent::SctDamageBatch(sct_damage_batch) => {
global_state.settings.interface.sct_damage_batch = sct_damage_batch;
global_state.settings.save_to_file_warn();
},
HudEvent::SpeechBubbleDarkMode(sbdm) => {
global_state.settings.interface.speech_bubble_dark_mode = sbdm;
global_state.settings.save_to_file_warn();
},
HudEvent::SpeechBubbleIcon(sbi) => {
global_state.settings.interface.speech_bubble_icon = sbi;
global_state.settings.save_to_file_warn();
},
HudEvent::ToggleDebug(toggle_debug) => {
global_state.settings.interface.toggle_debug = toggle_debug;
global_state.settings.save_to_file_warn();
},
HudEvent::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();
},
HudEvent::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();
},
HudEvent::ToggleSmoothPan(smooth_pan_enabled) => {
global_state.settings.gameplay.smooth_pan_enable = smooth_pan_enabled;
global_state.settings.save_to_file_warn();
},
HudEvent::AdjustViewDistance(view_distance) => {
self.client.borrow_mut().set_view_distance(view_distance);
global_state.settings.graphics.view_distance = view_distance;
global_state.settings.save_to_file_warn();
},
HudEvent::AdjustLodDetail(lod_detail) => {
self.scene.lod.set_detail(lod_detail);
global_state.settings.graphics.lod_detail = lod_detail;
global_state.settings.save_to_file_warn();
},
HudEvent::AdjustSpriteRenderDistance(sprite_render_distance) => {
global_state.settings.graphics.sprite_render_distance =
sprite_render_distance;
global_state.settings.save_to_file_warn();
},
HudEvent::AdjustFigureLoDRenderDistance(figure_lod_render_distance) => {
global_state.settings.graphics.figure_lod_render_distance =
figure_lod_render_distance;
global_state.settings.save_to_file_warn();
},
HudEvent::CrosshairTransp(crosshair_transp) => {
global_state.settings.interface.crosshair_transp = crosshair_transp;
global_state.settings.save_to_file_warn();
},
HudEvent::ChatTransp(chat_transp) => {
global_state.settings.interface.chat_transp = chat_transp;
global_state.settings.save_to_file_warn();
},
HudEvent::ChatCharName(chat_char_name) => {
global_state.settings.interface.chat_character_name = chat_char_name;
global_state.settings.save_to_file_warn();
},
HudEvent::CrosshairType(crosshair_type) => {
global_state.settings.interface.crosshair_type = crosshair_type;
global_state.settings.save_to_file_warn();
},
HudEvent::Intro(intro_show) => {
global_state.settings.interface.intro_show = intro_show;
global_state.settings.save_to_file_warn();
},
HudEvent::ToggleXpBar(xp_bar) => {
global_state.settings.interface.xp_bar = xp_bar;
global_state.settings.save_to_file_warn();
},
HudEvent::ToggleBarNumbers(bar_numbers) => {
global_state.settings.interface.bar_numbers = bar_numbers;
global_state.settings.save_to_file_warn();
},
HudEvent::ToggleShortcutNumbers(shortcut_numbers) => {
global_state.settings.interface.shortcut_numbers = shortcut_numbers;
global_state.settings.save_to_file_warn();
},
HudEvent::BuffPosition(buff_position) => {
global_state.settings.interface.buff_position = buff_position;
global_state.settings.save_to_file_warn();
},
HudEvent::UiScale(scale_change) => {
global_state.settings.interface.ui_scale =
self.hud.scale_change(scale_change);
global_state.settings.save_to_file_warn();
},
HudEvent::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();
},
HudEvent::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();
},
//HudEvent::ChangeAudioDevice(name) => {
// global_state.audio.set_device(name.clone());
// global_state.settings.audio.output = AudioOutput::Device(name);
// global_state.settings.save_to_file_warn();
//},
HudEvent::ChangeMaxFPS(fps) => {
global_state.settings.graphics.max_fps = fps;
global_state.settings.save_to_file_warn();
},
HudEvent::RemoveBuff(buff_id) => {
let mut client = self.client.borrow_mut();
client.remove_buff(buff_id);
@ -1317,124 +1168,12 @@ impl PlayState for SessionState {
target_entity.map(|t| t.0),
);
},
HudEvent::ChangeFOV(new_fov) => {
global_state.settings.graphics.fov = new_fov;
global_state.settings.save_to_file_warn();
self.scene.camera_mut().set_fov_deg(new_fov);
self.scene
.camera_mut()
.compute_dependents(&*self.client.borrow().state().terrain());
},
HudEvent::MapZoom(map_zoom) => {
global_state.settings.interface.map_zoom = map_zoom;
global_state.settings.save_to_file_warn();
},
HudEvent::MapDrag(map_drag) => {
global_state.settings.interface.map_drag = map_drag;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowTopoMap(map_show_topo_map) => {
global_state.settings.interface.map_show_topo_map = map_show_topo_map;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowDifficulty(map_show_difficulty) => {
global_state.settings.interface.map_show_difficulty = map_show_difficulty;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowTowns(map_show_towns) => {
global_state.settings.interface.map_show_towns = map_show_towns;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowDungeons(map_show_dungeons) => {
global_state.settings.interface.map_show_dungeons = map_show_dungeons;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowCastles(map_show_castles) => {
global_state.settings.interface.map_show_castles = map_show_castles;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowCaves(map_show_caves) => {
global_state.settings.interface.map_show_caves = map_show_caves;
global_state.settings.save_to_file_warn();
},
HudEvent::MapShowTrees(map_show_trees) => {
global_state.settings.interface.map_show_trees = map_show_trees;
global_state.settings.save_to_file_warn();
},
HudEvent::RequestSiteInfo(id) => {
let mut client = self.client.borrow_mut();
client.request_site_economy(id);
},
HudEvent::ChangeGamma(new_gamma) => {
global_state.settings.graphics.gamma = new_gamma;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeExposure(new_exposure) => {
global_state.settings.graphics.exposure = new_exposure;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeAmbiance(new_ambiance) => {
global_state.settings.graphics.ambiance = new_ambiance;
global_state.settings.save_to_file_warn();
},
HudEvent::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();
},
HudEvent::ChangeLanguage(new_language) => {
global_state.settings.language.selected_language =
new_language.language_identifier;
global_state.i18n = Localization::load_expect(&i18n_asset_key(
&global_state.settings.language.selected_language,
));
global_state.i18n.read().log_missing_entries();
self.hud.update_fonts(&global_state.i18n.read());
},
HudEvent::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();
},
HudEvent::ToggleParticlesEnabled(particles_enabled) => {
global_state.settings.graphics.particles_enabled = particles_enabled;
global_state.settings.save_to_file_warn();
},
HudEvent::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();
},
HudEvent::ChangeBinding(game_input) => {
global_state.window.set_keybinding_mode(game_input);
},
HudEvent::ChangeFreeLookBehavior(behavior) => {
global_state.settings.gameplay.free_look_behavior = behavior;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeAutoWalkBehavior(behavior) => {
global_state.settings.gameplay.auto_walk_behavior = behavior;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeCameraClampBehavior(behavior) => {
global_state.settings.gameplay.camera_clamp_behavior = behavior;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeStopAutoWalkOnInput(state) => {
global_state.settings.gameplay.stop_auto_walk_on_input = state;
global_state.settings.save_to_file_warn();
},
HudEvent::ChangeAutoCamera(state) => {
global_state.settings.gameplay.auto_camera = state;
global_state.settings.save_to_file_warn();
},
HudEvent::CraftRecipe(r) => {
self.client.borrow_mut().craft_recipe(&r);
},
@ -1464,75 +1203,8 @@ impl PlayState for SessionState {
global_state.settings.interface.minimap_face_north = state;
global_state.settings.save_to_file_warn();
},
HudEvent::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
self.hud
.set_scaling_mode(global_state.settings.interface.ui_scale);
// Save to File
global_state.settings.save_to_file_warn();
},
HudEvent::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();
},
HudEvent::ResetKeyBindings => {
global_state.settings.controls = ControlSettings::default();
global_state.settings.save_to_file_warn();
},
HudEvent::ResetGraphicsSettings => {
global_state.settings.graphics = GraphicsSettings::default();
global_state.settings.save_to_file_warn();
let graphics = &global_state.settings.graphics;
// View distance
self.client
.borrow_mut()
.set_view_distance(graphics.view_distance);
// FOV
self.scene.camera_mut().set_fov_deg(graphics.fov);
self.scene
.camera_mut()
.compute_dependents(&*self.client.borrow().state().terrain());
// LoD
self.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());
},
HudEvent::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);
HudEvent::SettingsChange(settings_change) => {
settings_change.process(global_state, self);
},
}
}

View File

@ -0,0 +1,510 @@
use super::SessionState;
use crate::{
controller::ControllerSettings,
hud::{
BarNumbers, BuffPosition, CrosshairType, Intro, PressBehavior, ScaleChange,
ShortcutNumbers, XpBar,
},
i18n::{i18n_asset_key, LanguageMetadata, Localization},
render::RenderMode,
settings::{
AudioSettings, ControlSettings, Fps, GamepadSettings, GameplaySettings, GraphicsSettings,
InterfaceSettings,
},
window::{FullScreenSettings, GameInput},
GlobalState,
};
use common::assets::AssetExt;
use vek::*;
#[derive(Clone)]
pub enum Audio {
AdjustMusicVolume(f32),
AdjustSfxVolume(f32),
//ChangeAudioDevice(String),
ResetAudioSettings,
}
#[derive(Clone)]
pub enum Control {
ChangeBinding(GameInput),
ResetKeyBindings,
}
#[derive(Clone)]
pub enum Gamepad {}
#[derive(Clone)]
pub enum Gameplay {
AdjustMousePan(u32),
AdjustMouseZoom(u32),
AdjustCameraClamp(u32),
ToggleControllerYInvert(bool),
ToggleMouseYInvert(bool),
ToggleZoomInvert(bool),
ToggleSmoothPan(bool),
ChangeFreeLookBehavior(PressBehavior),
ChangeAutoWalkBehavior(PressBehavior),
ChangeCameraClampBehavior(PressBehavior),
ChangeStopAutoWalkOnInput(bool),
ChangeAutoCamera(bool),
ResetGameplaySettings,
}
#[derive(Clone)]
pub enum Graphics {
AdjustViewDistance(u32),
AdjustLodDetail(u32),
AdjustSpriteRenderDistance(u32),
AdjustFigureLoDRenderDistance(u32),
ChangeMaxFPS(Fps),
ChangeFOV(u16),
ChangeGamma(f32),
ChangeExposure(f32),
ChangeAmbiance(f32),
ChangeRenderMode(Box<RenderMode>),
ChangeFullscreenMode(FullScreenSettings),
ToggleParticlesEnabled(bool),
AdjustWindowSize([u16; 2]),
ResetGraphicsSettings,
}
#[derive(Clone)]
pub enum Interface {
Sct(bool),
SctPlayerBatch(bool),
SctDamageBatch(bool),
SpeechBubbleDarkMode(bool),
SpeechBubbleIcon(bool),
ToggleHelp(bool),
ToggleDebug(bool),
ToggleTips(bool),
CrosshairTransp(f32),
ChatTransp(f32),
ChatCharName(bool),
CrosshairType(CrosshairType),
Intro(Intro),
ToggleXpBar(XpBar),
ToggleBarNumbers(BarNumbers),
ToggleShortcutNumbers(ShortcutNumbers),
BuffPosition(BuffPosition),
UiScale(ScaleChange),
//Map settings
MapZoom(f64),
MapDrag(Vec2<f64>),
MapShowTopoMap(bool),
MapShowDifficulty(bool),
MapShowTowns(bool),
MapShowDungeons(bool),
MapShowCastles(bool),
MapShowCaves(bool),
MapShowTrees(bool),
ResetInterfaceSettings,
}
#[derive(Clone)]
pub enum Language {
ChangeLanguage(Box<LanguageMetadata>),
}
#[derive(Clone)]
pub enum Networking {}
#[derive(Clone)]
pub enum SettingsChange {
Audio(Audio),
Control(Control),
Gamepad(Gamepad),
Gameplay(Gameplay),
Graphics(Graphics),
Interface(Interface),
Language(Language),
Networking(Networking),
}
macro_rules! settings_change_from {
($i: ident) => {
impl From<$i> for SettingsChange {
fn from(change: $i) -> Self { SettingsChange::$i(change) }
}
};
}
settings_change_from!(Audio);
settings_change_from!(Control);
settings_change_from!(Gamepad);
settings_change_from!(Gameplay);
settings_change_from!(Graphics);
settings_change_from!(Interface);
settings_change_from!(Language);
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;
match self {
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);
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());
// 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);
},
},
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();
},
},
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::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);
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());
},
},
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::Language(language_change) => match language_change {
Language::ChangeLanguage(new_language) => {
global_state.settings.language.selected_language =
new_language.language_identifier;
global_state.i18n = Localization::load_expect(&i18n_asset_key(
&global_state.settings.language.selected_language,
));
global_state.i18n.read().log_missing_entries();
session_state.hud.update_fonts(&global_state.i18n.read());
},
},
SettingsChange::Networking(networking_change) => match networking_change {},
}
}
}