Merge pull request #459 from LookImEcho-Rick/codex/chat-arrow-history
Keep chat arrow keys from turning the camera
This commit is contained in:
@@ -163,3 +163,32 @@ fn locate_coordinates_fill_chat_with_teleport_without_submitting() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_arrows_recall_messages_and_restore_the_draft() {
|
||||
use winit::keyboard::KeyCode::{ArrowDown, ArrowUp};
|
||||
|
||||
let font = font();
|
||||
let m = Measure(&font);
|
||||
let registries = Registries::default();
|
||||
let commands = Commands {
|
||||
dispatcher: crate::command::vanilla::game_dispatcher(),
|
||||
registries: ®istries,
|
||||
};
|
||||
let history = vec!["first message".to_owned(), "latest message".to_owned()];
|
||||
let mut screen = ChatScreen::new(&m, &commands, "unfinished draft", history.len(), 640, 360);
|
||||
for (key, expected) in [
|
||||
(ArrowUp, "latest message"),
|
||||
(ArrowUp, "first message"),
|
||||
(ArrowUp, "first message"),
|
||||
(ArrowDown, "latest message"),
|
||||
(ArrowDown, "unfinished draft"),
|
||||
(ArrowDown, "unfinished draft"),
|
||||
] {
|
||||
assert_eq!(
|
||||
screen.key(&m, &commands, &history, key, false, false),
|
||||
ChatAction::None
|
||||
);
|
||||
assert_eq!(screen.value(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9400,14 +9400,22 @@ impl ApplicationHandler for Game<'_> {
|
||||
let elapsed = now.duration_since(self.previous);
|
||||
self.frame_ticks = elapsed.as_secs_f32() * 20.0;
|
||||
self.previous = now;
|
||||
// Arrow keys turn the camera (accessibility / scripted testing).
|
||||
let turn = |k| f32::from(u8::from(self.keys.contains(&k)));
|
||||
let secs = elapsed.as_secs_f32().min(0.1);
|
||||
self.yaw +=
|
||||
(turn(KeyCode::ArrowRight) - turn(KeyCode::ArrowLeft)) * 90.0 * secs;
|
||||
self.pitch = (self.pitch
|
||||
+ (turn(KeyCode::ArrowDown) - turn(KeyCode::ArrowUp)) * 90.0 * secs)
|
||||
.clamp(-90.0, 90.0);
|
||||
// Arrow-key camera controls belong to gameplay; chat and
|
||||
// other screens use the same keys for their own navigation.
|
||||
if self.screen == Screen::Playing
|
||||
&& self.title.is_none()
|
||||
&& self.sign_edit.is_none()
|
||||
&& self.book.is_none()
|
||||
&& !self.remote_chat_open()
|
||||
{
|
||||
let turn = |k| f32::from(u8::from(self.keys.contains(&k)));
|
||||
let secs = elapsed.as_secs_f32().min(0.1);
|
||||
self.yaw +=
|
||||
(turn(KeyCode::ArrowRight) - turn(KeyCode::ArrowLeft)) * 90.0 * secs;
|
||||
self.pitch = (self.pitch
|
||||
+ (turn(KeyCode::ArrowDown) - turn(KeyCode::ArrowUp)) * 90.0 * secs)
|
||||
.clamp(-90.0, 90.0);
|
||||
}
|
||||
self.update_backdrop()?;
|
||||
horizon_client::ui_theme::set_backdrop(self.backdrop_fade());
|
||||
if self.screen != Screen::Paused {
|
||||
|
||||
Reference in New Issue
Block a user