Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select character with keyboard #152

Merged

Conversation

sorokya
Copy link
Contributor

@sorokya sorokya commented Mar 26, 2022

Seemed like a fun feature to implement and get my hands dirty with the client.

No idea if this is the "correct" way to deal with adding keyboard handling to a component.

Let me know if there's a better way and I can fix it :)

@@ -168,6 +174,12 @@ protected virtual async Task DeleteButtonClick()
protected virtual void DoUpdateLogic(GameTime gameTime)
{
_characterControl.Update(gameTime);

var keyboardState = _userInputProvider.CurrentKeyState;
if (keyboardState.IsKeyDown((Microsoft.Xna.Framework.Input.Keys)49+_characterIndex))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to check currentState.KeyUp and previousState.KeyDown for this, otherwise holding the key will spawn a bunch of tasks. The interlocked guard happens in LoginButtonClick so it won't stop the tasks from being started (and then immediately exiting).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to using IsKeyPressedOnce

@@ -168,6 +174,12 @@ protected virtual async Task DeleteButtonClick()
protected virtual void DoUpdateLogic(GameTime gameTime)
{
_characterControl.Update(gameTime);

var keyboardState = _userInputProvider.CurrentKeyState;
if (keyboardState.IsKeyDown((Microsoft.Xna.Framework.Input.Keys)49+_characterIndex))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do Keys.D1+_characterIndex? I think C# is pretty flexible with adding values to enums in this way.

Also, just add the using statement instead of fully qualifying the type here. FYI you can easily add the using Microsoft.Xna.Framework.Input via the keyboard shortcut CTRL+. in VS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sorokya sorokya force-pushed the select-character-with-keyboard branch from 58eb7f7 to 73a7efc Compare March 27, 2022 10:29
@sorokya sorokya force-pushed the select-character-with-keyboard branch from 73a7efc to e727b88 Compare March 27, 2022 10:32
@ethanmoffat ethanmoffat merged commit dfe4ec6 into ethanmoffat:master Mar 27, 2022
@sorokya sorokya deleted the select-character-with-keyboard branch March 27, 2022 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants