configurable walking speed

This commit is contained in:
Isse 2023-10-13 21:28:56 +02:00
parent 8d35450d3f
commit 5320f83462
11 changed files with 139 additions and 5 deletions

View File

@ -75,3 +75,4 @@ gameinput-muteinactivemaster = Mute master volume (inactive window)
gameinput-mutemusic = Mute music volume
gameinput-mutesfx = Mute SFX volume
gameinput-muteambience = Mute ambience volume
gameinput-togglewalk = Toggle Walking

View File

@ -36,6 +36,7 @@ hud-diary = Diary
hud-free_look_indicator = Free look active. Press { $key } to disable.
hud-camera_clamp_indicator = Camera vertical clamp active. Press { $key } to disable.
hud-auto_walk_indicator = Auto walk/swim active
hud-walking_speed_indicator = Walking speed active
hud-zoom_lock_indicator-remind = Zoom locked
hud-zoom_lock_indicator-enable = Camera zoom locked
hud-zoom_lock_indicator-disable = Camera zoom unlocked

View File

@ -53,6 +53,8 @@ hud-settings-invert_controller_y_axis = Invert Controller Y Axis
hud-settings-enable_mouse_smoothing = Camera Smoothing
hud-settings-free_look_behavior = Free look behavior
hud-settings-auto_walk_behavior = Auto walk behavior
hud-settings-walking_speed_behavior = Walking speed behavior
hud-settings-walking_speed = Walking speed
hud-settings-camera_clamp_behavior = Camera clamp behavior
hud-settings-zoom_lock_behavior = Camera zoom lock behavior
hud-settings-player_physics_behavior = Player physics (experimental)

View File

@ -170,6 +170,8 @@ pub enum GameInput {
MuteSfx,
#[strum(serialize = "gameinput-muteambience")]
MuteAmbience,
#[strum(serialize = "gameinput-togglewalk")]
ToggleWalk,
}
impl GameInput {

View File

@ -342,6 +342,10 @@ widget_ids! {
auto_walk_txt,
auto_walk_bg,
// Walking speed indicator
walking_speed_txt,
walking_speed_bg,
// Temporal (fading) camera zoom lock indicator
zoom_lock_txt,
zoom_lock_bg,
@ -909,6 +913,7 @@ pub struct Show {
stats: bool,
free_look: bool,
auto_walk: bool,
walking_speed: bool,
zoom_lock: ChangeNotification,
camera_clamp: bool,
prompt_dialog: Option<PromptDialogSettings>,
@ -1416,6 +1421,7 @@ impl Hud {
stats: false,
free_look: false,
auto_walk: false,
walking_speed: false,
zoom_lock: ChangeNotification::default(),
camera_clamp: false,
prompt_dialog: None,
@ -3815,6 +3821,23 @@ impl Hud {
.set(self.ids.auto_walk_txt, ui_widgets);
}
// Walking speed indicator
if self.show.walking_speed {
Text::new(&i18n.get_msg("hud-walking_speed_indicator"))
.color(TEXT_BG)
.mid_top_with_margin_on(ui_widgets.window, indicator_offset)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(20))
.set(self.ids.walking_speed_bg, ui_widgets);
indicator_offset += 30.0;
Text::new(&i18n.get_msg("hud-walking_speed_indicator"))
.color(KILL_COLOR)
.top_left_with_margins_on(self.ids.walking_speed_bg, -1.0, -1.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(20))
.set(self.ids.walking_speed_txt, ui_widgets);
}
// Camera zoom lock
self.show.zoom_lock.update(dt);
@ -4915,6 +4938,10 @@ impl Hud {
pub fn auto_walk(&mut self, auto_walk: bool) { self.show.auto_walk = auto_walk; }
pub fn walking_speed(&mut self, walking_speed: bool) {
self.show.walking_speed = walking_speed;
}
pub fn camera_clamp(&mut self, camera_clamp: bool) { self.show.camera_clamp = camera_clamp; }
/// Remind the player camera zoom is currently locked, for example if they

View File

@ -31,6 +31,9 @@ widget_ids! {
camera_clamp_slider,
camera_clamp_label,
camera_clamp_value,
walking_speed_slider,
walking_speed_label,
walking_speed_value,
mouse_y_invert_button,
mouse_y_invert_label,
controller_y_invert_button,
@ -42,6 +45,8 @@ widget_ids! {
free_look_behavior_list,
auto_walk_behavior_text,
auto_walk_behavior_list,
walking_speed_behavior_text,
walking_speed_behavior_list,
camera_clamp_behavior_text,
camera_clamp_behavior_list,
zoom_lock_behavior_text,
@ -124,6 +129,7 @@ impl<'a> Widget for Gameplay<'a> {
let display_pan = self.global_state.settings.gameplay.pan_sensitivity;
let display_zoom = self.global_state.settings.gameplay.zoom_sensitivity;
let display_clamp = self.global_state.settings.gameplay.camera_clamp_angle;
let display_walking_speed = self.global_state.settings.gameplay.walking_speed;
// Mouse Pan Sensitivity
Text::new(
@ -233,6 +239,38 @@ impl<'a> Widget for Gameplay<'a> {
.color(TEXT_COLOR)
.set(state.ids.camera_clamp_value, ui);
// Walking speed
Text::new(&self.localized_strings.get_msg("hud-settings-walking_speed"))
.down_from(state.ids.camera_clamp_slider, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.walking_speed_label, ui);
if let Some(new_val) = ImageSlider::continuous(
display_walking_speed,
0.0,
1.0,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(550.0, 22.0)
.down_from(state.ids.walking_speed_label, 10.0)
.track_breadth(30.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.walking_speed_slider, ui)
{
events.push(AdjustWalkingSpeed(new_val));
}
Text::new(&format!("{:.2}", display_walking_speed))
.right_from(state.ids.walking_speed_slider, 8.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.walking_speed_value, ui);
// Zoom Inversion
let zoom_inverted = ToggleButton::new(
self.global_state.settings.gameplay.zoom_inversion,
@ -240,7 +278,7 @@ impl<'a> Widget for Gameplay<'a> {
self.imgs.checkbox_checked,
)
.w_h(18.0, 18.0)
.down_from(state.ids.camera_clamp_slider, 20.0)
.down_from(state.ids.walking_speed_slider, 20.0)
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.mouse_zoom_invert_button, ui);
@ -420,13 +458,43 @@ impl<'a> Widget for Gameplay<'a> {
}
}
// Walking speed behavior
Text::new(
&self
.localized_strings
.get_msg("hud-settings-walking_speed_behavior"),
)
.down_from(state.ids.free_look_behavior_list, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.walking_speed_behavior_text, ui);
let walking_speed_selected =
self.global_state.settings.gameplay.walking_speed_behavior as usize;
if let Some(clicked) = DropDownList::new(&mode_label_list, Some(walking_speed_selected))
.w_h(200.0, 30.0)
.color(MENU_BG)
.label_color(TEXT_COLOR)
.label_font_id(self.fonts.cyri.conrod_id)
.down_from(state.ids.walking_speed_behavior_text, 8.0)
.set(state.ids.walking_speed_behavior_list, ui)
{
match clicked {
0 => events.push(ChangeWalkingSpeedBehavior(PressBehavior::Toggle)),
1 => events.push(ChangeWalkingSpeedBehavior(PressBehavior::Hold)),
_ => unreachable!(),
}
}
// Camera clamp behavior
Text::new(
&self
.localized_strings
.get_msg("hud-settings-camera_clamp_behavior"),
)
.down_from(state.ids.free_look_behavior_list, 10.0)
.down_from(state.ids.auto_walk_behavior_list, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
@ -545,7 +613,7 @@ impl<'a> Widget for Gameplay<'a> {
.localized_strings
.get_msg("hud-settings-zoom_lock_behavior"),
)
.down_from(state.ids.auto_walk_behavior_list, 10.0)
.down_from(state.ids.walking_speed_behavior_list, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
@ -599,7 +667,7 @@ impl<'a> Widget for Gameplay<'a> {
.w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT)
.hover_image(self.imgs.button_hover)
.press_image(self.imgs.button_press)
.down_from(state.ids.camera_clamp_behavior_list, 12.0)
.down_from(state.ids.zoom_lock_behavior_list, 12.0)
.label(
&self
.localized_strings

View File

@ -11,6 +11,7 @@ pub struct KeyState {
pub swim_down: bool,
pub fly: bool,
pub auto_walk: bool,
pub speed_mul: f32,
pub trade: bool,
pub analog_matrix: Vec2<f32>,
}
@ -28,6 +29,7 @@ impl Default for KeyState {
swim_down: false,
fly: false,
auto_walk: false,
speed_mul: 1.0,
trade: false,
analog_matrix: Vec2::zero(),
}
@ -44,7 +46,7 @@ impl KeyState {
)
} else {
self.analog_matrix
};
} * self.speed_mul;
if dir.magnitude_squared() <= 1.0 {
dir

View File

@ -101,6 +101,7 @@ pub struct SessionState {
walk_right_dir: Vec2<f32>,
free_look: bool,
auto_walk: bool,
walking_speed: bool,
camera_clamp: bool,
zoom_lock: bool,
is_aiming: bool,
@ -171,6 +172,7 @@ impl SessionState {
walk_right_dir,
free_look: false,
auto_walk: false,
walking_speed: false,
camera_clamp: false,
zoom_lock: false,
is_aiming: false,
@ -1214,6 +1216,22 @@ impl PlayState for SessionState {
}
}
},
GameInput::ToggleWalk if state => {
let hud = &mut self.hud;
global_state
.settings
.gameplay
.walking_speed_behavior
.update(state, &mut self.walking_speed, |b| {
hud.walking_speed(b)
});
self.key_state.speed_mul = if self.walking_speed {
global_state.settings.gameplay.walking_speed
} else {
1.0
};
},
_ => {},
}
},

View File

@ -59,6 +59,7 @@ pub enum Gameplay {
AdjustMousePan(u32),
AdjustMouseZoom(u32),
AdjustCameraClamp(u32),
AdjustWalkingSpeed(f32),
ToggleControllerYInvert(bool),
ToggleMouseYInvert(bool),
@ -68,6 +69,7 @@ pub enum Gameplay {
ChangeFreeLookBehavior(PressBehavior),
ChangeAutoWalkBehavior(PressBehavior),
ChangeWalkingSpeedBehavior(PressBehavior),
ChangeCameraClampBehavior(PressBehavior),
ChangeZoomLockBehavior(AutoPressBehavior),
ChangeStopAutoWalkOnInput(bool),
@ -379,6 +381,9 @@ impl SettingsChange {
Gameplay::AdjustCameraClamp(angle) => {
settings.gameplay.camera_clamp_angle = angle;
},
Gameplay::AdjustWalkingSpeed(speed) => {
settings.gameplay.walking_speed = speed;
},
Gameplay::ToggleControllerYInvert(controller_y_inverted) => {
window.controller_settings.pan_invert_y = controller_y_inverted;
settings.controller.pan_invert_y = controller_y_inverted;
@ -400,6 +405,9 @@ impl SettingsChange {
Gameplay::ChangeAutoWalkBehavior(behavior) => {
settings.gameplay.auto_walk_behavior = behavior;
},
Gameplay::ChangeWalkingSpeedBehavior(behavior) => {
settings.gameplay.walking_speed_behavior = behavior;
},
Gameplay::ChangeCameraClampBehavior(behavior) => {
settings.gameplay.camera_clamp_behavior = behavior;
},

View File

@ -200,6 +200,7 @@ impl ControlSettings {
GameInput::MuteMusic => Some(KeyMouse::Key(VirtualKeyCode::F8)),
GameInput::MuteSfx => None,
GameInput::MuteAmbience => None,
GameInput::ToggleWalk => Some(KeyMouse::Key(VirtualKeyCode::I)),
}
}
}

View File

@ -8,11 +8,13 @@ pub struct GameplaySettings {
pub pan_sensitivity: u32,
pub zoom_sensitivity: u32,
pub camera_clamp_angle: u32,
pub walking_speed: f32,
pub zoom_inversion: bool,
pub mouse_y_inversion: bool,
pub smooth_pan_enable: bool,
pub free_look_behavior: PressBehavior,
pub auto_walk_behavior: PressBehavior,
pub walking_speed_behavior: PressBehavior,
pub camera_clamp_behavior: PressBehavior,
pub zoom_lock_behavior: AutoPressBehavior,
pub stop_auto_walk_on_input: bool,
@ -27,11 +29,13 @@ impl Default for GameplaySettings {
pan_sensitivity: 100,
zoom_sensitivity: 100,
camera_clamp_angle: 45,
walking_speed: 0.35,
zoom_inversion: false,
mouse_y_inversion: false,
smooth_pan_enable: false,
free_look_behavior: PressBehavior::Toggle,
auto_walk_behavior: PressBehavior::Toggle,
walking_speed_behavior: PressBehavior::Toggle,
camera_clamp_behavior: PressBehavior::Toggle,
zoom_lock_behavior: AutoPressBehavior::Auto,
stop_auto_walk_on_input: true,