Adds simple auto walk functionality. Toggleable or push to hold

This commit is contained in:
Joey Maher 2020-06-06 13:09:01 -05:00
parent 8c68d7aace
commit 458ac4af5e
8 changed files with 176 additions and 6 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Character name and level information to chat, social tab and `/players` command. - Character name and level information to chat, social tab and `/players` command.
- Added inventory, armour and weapon saving - Added inventory, armour and weapon saving
- Show where screenshots are saved to in the chat - Show where screenshots are saved to in the chat
- Added basic auto walk
### Changed ### Changed

View File

@ -264,6 +264,8 @@ magically infused items?"#,
"hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis", "hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis",
"hud.settings.enable_mouse_smoothing": "Camera Smoothing", "hud.settings.enable_mouse_smoothing": "Camera Smoothing",
"hud.settings.free_look_behavior": "Free look behavior", "hud.settings.free_look_behavior": "Free look behavior",
"hud.settings.auto_walk_behavior": "Auto walk behavior",
"hud.settings.stop_auto_walk_on_input": "Stop auto walk on movement",
"hud.settings.view_distance": "View Distance", "hud.settings.view_distance": "View Distance",
"hud.settings.sprites_view_distance": "Sprites View Distance", "hud.settings.sprites_view_distance": "Sprites View Distance",
@ -296,6 +298,7 @@ magically infused items?"#,
"hud.spell": "Spells", "hud.spell": "Spells",
"hud.free_look_indicator": "Free look active", "hud.free_look_indicator": "Free look active",
"hud.auto_walk_indicator": "Auto walk active",
/// End HUD section /// End HUD section
@ -348,6 +351,7 @@ magically infused items?"#,
"gameinput.togglewield": "Toggle Wield", "gameinput.togglewield": "Toggle Wield",
"gameinput.interact": "Interact", "gameinput.interact": "Interact",
"gameinput.freelook": "Free Look", "gameinput.freelook": "Free Look",
"gameinput.autowalk": "Auto Walk",
/// End GameInput section /// End GameInput section

View File

@ -184,6 +184,10 @@ widget_ids! {
free_look_txt, free_look_txt,
free_look_bg, free_look_bg,
// Auto walk indicator
auto_walk_txt,
auto_walk_bg,
// Example Quest // Example Quest
quest_bg, quest_bg,
q_headline_bg, q_headline_bg,
@ -255,6 +259,8 @@ pub enum Event {
ChangeLanguage(LanguageMetadata), ChangeLanguage(LanguageMetadata),
ChangeBinding(GameInput), ChangeBinding(GameInput),
ChangeFreeLookBehavior(PressBehavior), ChangeFreeLookBehavior(PressBehavior),
ChangeAutoWalkBehavior(PressBehavior),
ChangeStopAutoWalkOnInput(bool),
} }
// TODO: Are these the possible layouts we want? // TODO: Are these the possible layouts we want?
@ -319,6 +325,7 @@ pub struct Show {
want_grab: bool, want_grab: bool,
stats: bool, stats: bool,
free_look: bool, free_look: bool,
auto_walk: bool,
} }
impl Show { impl Show {
fn bag(&mut self, open: bool) { fn bag(&mut self, open: bool) {
@ -522,6 +529,7 @@ impl Hud {
ingame: true, ingame: true,
stats: false, stats: false,
free_look: false, free_look: false,
auto_walk: false,
}, },
to_focus: None, to_focus: None,
//never_show: false, //never_show: false,
@ -1677,6 +1685,12 @@ impl Hud {
settings_window::Event::ChangeFreeLookBehavior(behavior) => { settings_window::Event::ChangeFreeLookBehavior(behavior) => {
events.push(Event::ChangeFreeLookBehavior(behavior)); events.push(Event::ChangeFreeLookBehavior(behavior));
}, },
settings_window::Event::ChangeAutoWalkBehavior(behavior) => {
events.push(Event::ChangeAutoWalkBehavior(behavior));
},
settings_window::Event::ChangeStopAutoWalkOnInput(state) => {
events.push(Event::ChangeStopAutoWalkOnInput(state));
},
} }
} }
} }
@ -1795,6 +1809,25 @@ impl Hud {
.set(self.ids.free_look_txt, ui_widgets); .set(self.ids.free_look_txt, ui_widgets);
} }
// Auto walk indicator
if self.show.auto_walk {
Text::new(&self.voxygen_i18n.get("hud.auto_walk_indicator"))
.color(TEXT_BG)
.mid_top_with_margin_on(
ui_widgets.window,
if self.show.free_look { 128.0 } else { 100.0 },
)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(20))
.set(self.ids.auto_walk_bg, ui_widgets);
Text::new(&self.voxygen_i18n.get("hud.auto_walk_indicator"))
.color(KILL_COLOR)
.top_left_with_margins_on(self.ids.auto_walk_bg, -1.0, -1.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(20))
.set(self.ids.auto_walk_txt, ui_widgets);
}
// Maintain slot manager // Maintain slot manager
for event in self.slot_manager.maintain(ui_widgets) { for event in self.slot_manager.maintain(ui_widgets) {
use comp::slot::Slot; use comp::slot::Slot;
@ -2155,4 +2188,6 @@ impl Hud {
} }
pub fn free_look(&mut self, free_look: bool) { self.show.free_look = free_look; } pub fn free_look(&mut self, free_look: bool) { self.show.free_look = free_look; }
pub fn auto_walk(&mut self, auto_walk: bool) { self.show.auto_walk = auto_walk; }
} }

View File

@ -156,7 +156,11 @@ widget_ids! {
speech_bubble_dark_mode_text, speech_bubble_dark_mode_text,
speech_bubble_dark_mode_button, speech_bubble_dark_mode_button,
free_look_behavior_text, free_look_behavior_text,
free_look_behavior_list free_look_behavior_list,
auto_walk_behavior_text,
auto_walk_behavior_list,
stop_auto_walk_on_input_button,
stop_auto_walk_on_input_label,
} }
} }
@ -240,6 +244,8 @@ pub enum Event {
ChangeLanguage(LanguageMetadata), ChangeLanguage(LanguageMetadata),
ChangeBinding(GameInput), ChangeBinding(GameInput),
ChangeFreeLookBehavior(PressBehavior), ChangeFreeLookBehavior(PressBehavior),
ChangeAutoWalkBehavior(PressBehavior),
ChangeStopAutoWalkOnInput(bool),
} }
pub enum ScaleChange { pub enum ScaleChange {
@ -1344,6 +1350,69 @@ impl<'a> Widget for SettingsWindow<'a> {
_ => unreachable!(), _ => unreachable!(),
} }
} }
// Auto walk behavior
Text::new(
&self
.localized_strings
.get("hud.settings.auto_walk_behavior"),
)
.down_from(state.ids.mouse_zoom_invert_button, 10.0)
.right_from(state.ids.free_look_behavior_text, 150.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.auto_walk_behavior_text, ui);
let auto_walk_selected =
self.global_state.settings.gameplay.auto_walk_behavior as usize;
if let Some(clicked) = DropDownList::new(&mode_label_list, Some(auto_walk_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.auto_walk_behavior_text, 8.0)
.set(state.ids.auto_walk_behavior_list, ui)
{
match clicked {
0 => events.push(Event::ChangeAutoWalkBehavior(PressBehavior::Toggle)),
1 => events.push(Event::ChangeAutoWalkBehavior(PressBehavior::Hold)),
_ => unreachable!(),
}
}
// Stop autowalk on input toggle
let stop_auto_walk_on_input_toggle = ToggleButton::new(
self.global_state.settings.gameplay.stop_auto_walk_on_input,
self.imgs.checkbox,
self.imgs.checkbox_checked,
)
.w_h(18.0, 18.0)
.right_from(state.ids.auto_walk_behavior_text, 80.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.stop_auto_walk_on_input_button, ui);
if self.global_state.settings.gameplay.stop_auto_walk_on_input
!= stop_auto_walk_on_input_toggle
{
events.push(Event::ChangeStopAutoWalkOnInput(
!self.global_state.settings.gameplay.stop_auto_walk_on_input,
));
}
Text::new(
&self
.localized_strings
.get("hud.settings.stop_auto_walk_on_input"),
)
.right_from(state.ids.stop_auto_walk_on_input_button, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.graphics_for(state.ids.stop_auto_walk_on_input_button)
.color(TEXT_COLOR)
.set(state.ids.stop_auto_walk_on_input_label, ui);
} }
// 3) Controls Tab -------------------------------- // 3) Controls Tab --------------------------------

View File

@ -10,6 +10,7 @@ pub struct KeyState {
pub toggle_wield: bool, pub toggle_wield: bool,
pub toggle_sit: bool, pub toggle_sit: bool,
pub toggle_dance: bool, pub toggle_dance: bool,
pub auto_walk: bool,
pub swap_loadout: bool, pub swap_loadout: bool,
pub respawn: bool, pub respawn: bool,
pub analog_matrix: Vec2<f32>, pub analog_matrix: Vec2<f32>,
@ -27,6 +28,7 @@ impl KeyState {
toggle_wield: false, toggle_wield: false,
toggle_sit: false, toggle_sit: false,
toggle_dance: false, toggle_dance: false,
auto_walk: false,
swap_loadout: false, swap_loadout: false,
respawn: false, respawn: false,
analog_matrix: Vec2::zero(), analog_matrix: Vec2::zero(),
@ -37,7 +39,8 @@ impl KeyState {
let dir = if self.analog_matrix == Vec2::zero() { let dir = if self.analog_matrix == Vec2::zero() {
Vec2::<f32>::new( Vec2::<f32>::new(
if self.right { 1.0 } else { 0.0 } + if self.left { -1.0 } else { 0.0 }, if self.right { 1.0 } else { 0.0 } + if self.left { -1.0 } else { 0.0 },
if self.up { 1.0 } else { 0.0 } + if self.down { -1.0 } else { 0.0 }, if self.up || self.auto_walk { 1.0 } else { 0.0 }
+ if self.down { -1.0 } else { 0.0 },
) )
} else { } else {
self.analog_matrix self.analog_matrix

View File

@ -142,6 +142,13 @@ impl PlayState for SessionState {
let mut ori = self.scene.camera().get_orientation(); let mut ori = self.scene.camera().get_orientation();
let mut free_look = false; let mut free_look = false;
let mut auto_walk = false;
fn stop_auto_walk(auto_walk: &mut bool, key_state: &mut KeyState, hud: &mut Hud) {
*auto_walk = false;
hud.auto_walk(false);
key_state.auto_walk = false;
}
// Game loop // Game loop
let mut current_client_state = self.client.borrow().get_client_state(); let mut current_client_state = self.client.borrow().get_client_state();
@ -309,6 +316,7 @@ impl PlayState for SessionState {
{ {
self.key_state.toggle_sit = state; self.key_state.toggle_sit = state;
if state { if state {
stop_auto_walk(&mut auto_walk, &mut self.key_state, &mut self.hud);
self.client.borrow_mut().toggle_sit(); self.client.borrow_mut().toggle_sit();
} }
} }
@ -317,13 +325,34 @@ impl PlayState for SessionState {
{ {
self.key_state.toggle_dance = state; self.key_state.toggle_dance = state;
if state { if state {
stop_auto_walk(&mut auto_walk, &mut self.key_state, &mut self.hud);
self.client.borrow_mut().toggle_dance(); self.client.borrow_mut().toggle_dance();
} }
} }
Event::InputUpdate(GameInput::MoveForward, state) => self.key_state.up = state, Event::InputUpdate(GameInput::MoveForward, state) => {
Event::InputUpdate(GameInput::MoveBack, state) => self.key_state.down = state, if state && global_state.settings.gameplay.stop_auto_walk_on_input {
Event::InputUpdate(GameInput::MoveLeft, state) => self.key_state.left = state, stop_auto_walk(&mut auto_walk, &mut self.key_state, &mut self.hud);
Event::InputUpdate(GameInput::MoveRight, state) => self.key_state.right = state, }
self.key_state.up = state
},
Event::InputUpdate(GameInput::MoveBack, state) => {
if state && global_state.settings.gameplay.stop_auto_walk_on_input {
stop_auto_walk(&mut auto_walk, &mut self.key_state, &mut self.hud);
}
self.key_state.down = state
},
Event::InputUpdate(GameInput::MoveLeft, state) => {
if state && global_state.settings.gameplay.stop_auto_walk_on_input {
stop_auto_walk(&mut auto_walk, &mut self.key_state, &mut self.hud);
}
self.key_state.left = state
},
Event::InputUpdate(GameInput::MoveRight, state) => {
if state && global_state.settings.gameplay.stop_auto_walk_on_input {
stop_auto_walk(&mut auto_walk, &mut self.key_state, &mut self.hud);
}
self.key_state.right = state
},
Event::InputUpdate(GameInput::Glide, state) => { Event::InputUpdate(GameInput::Glide, state) => {
self.inputs.glide.set_state(state); self.inputs.glide.set_state(state);
}, },
@ -442,6 +471,21 @@ impl PlayState for SessionState {
_ => {}, _ => {},
}; };
}, },
Event::InputUpdate(GameInput::AutoWalk, state) => {
match (global_state.settings.gameplay.auto_walk_behavior, state) {
(PressBehavior::Toggle, true) => {
auto_walk = !auto_walk;
self.key_state.auto_walk = auto_walk;
self.hud.auto_walk(auto_walk);
},
(PressBehavior::Hold, state) => {
auto_walk = state;
self.key_state.auto_walk = auto_walk;
self.hud.auto_walk(auto_walk);
},
_ => {},
}
},
Event::AnalogGameInput(input) => match input { Event::AnalogGameInput(input) => match input {
AnalogGameInput::MovementX(v) => { AnalogGameInput::MovementX(v) => {
self.key_state.analog_matrix.x = v; self.key_state.analog_matrix.x = v;
@ -767,6 +811,12 @@ impl PlayState for SessionState {
HudEvent::ChangeFreeLookBehavior(behavior) => { HudEvent::ChangeFreeLookBehavior(behavior) => {
global_state.settings.gameplay.free_look_behavior = behavior; global_state.settings.gameplay.free_look_behavior = behavior;
}, },
HudEvent::ChangeAutoWalkBehavior(behavior) => {
global_state.settings.gameplay.auto_walk_behavior = behavior;
},
HudEvent::ChangeStopAutoWalkOnInput(state) => {
global_state.settings.gameplay.stop_auto_walk_on_input = state;
},
} }
} }

View File

@ -140,6 +140,7 @@ impl ControlSettings {
GameInput::ToggleWield => KeyMouse::Key(VirtualKeyCode::T), GameInput::ToggleWield => KeyMouse::Key(VirtualKeyCode::T),
//GameInput::Charge => KeyMouse::Key(VirtualKeyCode::Key1), //GameInput::Charge => KeyMouse::Key(VirtualKeyCode::Key1),
GameInput::FreeLook => KeyMouse::Key(VirtualKeyCode::L), GameInput::FreeLook => KeyMouse::Key(VirtualKeyCode::L),
GameInput::AutoWalk => KeyMouse::Key(VirtualKeyCode::Period),
GameInput::Slot1 => KeyMouse::Key(VirtualKeyCode::Key1), GameInput::Slot1 => KeyMouse::Key(VirtualKeyCode::Key1),
GameInput::Slot2 => KeyMouse::Key(VirtualKeyCode::Key2), GameInput::Slot2 => KeyMouse::Key(VirtualKeyCode::Key2),
GameInput::Slot3 => KeyMouse::Key(VirtualKeyCode::Key3), GameInput::Slot3 => KeyMouse::Key(VirtualKeyCode::Key3),
@ -200,6 +201,7 @@ impl Default for ControlSettings {
GameInput::ToggleWield, GameInput::ToggleWield,
//GameInput::Charge, //GameInput::Charge,
GameInput::FreeLook, GameInput::FreeLook,
GameInput::AutoWalk,
GameInput::Slot1, GameInput::Slot1,
GameInput::Slot2, GameInput::Slot2,
GameInput::Slot3, GameInput::Slot3,
@ -467,6 +469,8 @@ pub struct GameplaySettings {
pub bar_numbers: BarNumbers, pub bar_numbers: BarNumbers,
pub ui_scale: ScaleMode, pub ui_scale: ScaleMode,
pub free_look_behavior: PressBehavior, pub free_look_behavior: PressBehavior,
pub auto_walk_behavior: PressBehavior,
pub stop_auto_walk_on_input: bool,
} }
impl Default for GameplaySettings { impl Default for GameplaySettings {
@ -491,6 +495,8 @@ impl Default for GameplaySettings {
bar_numbers: BarNumbers::Off, bar_numbers: BarNumbers::Off,
ui_scale: ScaleMode::RelativeToWindow([1920.0, 1080.0].into()), ui_scale: ScaleMode::RelativeToWindow([1920.0, 1080.0].into()),
free_look_behavior: PressBehavior::Toggle, free_look_behavior: PressBehavior::Toggle,
auto_walk_behavior: PressBehavior::Toggle,
stop_auto_walk_on_input: true,
} }
} }
} }

View File

@ -63,6 +63,7 @@ pub enum GameInput {
//Charge, //Charge,
SwapLoadout, SwapLoadout,
FreeLook, FreeLook,
AutoWalk,
} }
impl GameInput { impl GameInput {
@ -104,6 +105,7 @@ impl GameInput {
GameInput::ToggleWield => "gameinput.togglewield", GameInput::ToggleWield => "gameinput.togglewield",
//GameInput::Charge => "gameinput.charge", //GameInput::Charge => "gameinput.charge",
GameInput::FreeLook => "gameinput.freelook", GameInput::FreeLook => "gameinput.freelook",
GameInput::AutoWalk => "gameinput.autowalk",
GameInput::Slot1 => "gameinput.slot1", GameInput::Slot1 => "gameinput.slot1",
GameInput::Slot2 => "gameinput.slot2", GameInput::Slot2 => "gameinput.slot2",
GameInput::Slot3 => "gameinput.slot3", GameInput::Slot3 => "gameinput.slot3",