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

Add Chat Commands #1165

Merged
merged 29 commits into from Nov 26, 2020
Merged

Add Chat Commands #1165

merged 29 commits into from Nov 26, 2020

Conversation

Gocnak
Copy link
Member

@Gocnak Gocnak commented Nov 24, 2020

Closes #278
Closes #1067
Closes #1167
Closes 2 cards in 0.8.7 release board

This PR adds initial command parsing and logic in the Chat panel. Chat commands are only being added as a more user-friendly and backwards-compatible way to do console commands. It is recommended that end users still do console commands or use the dedicated UI for things, and we will not be adding every command, but most power users may find them useful. (A fear I have is that people make "say" binds instead of command binds.)

Added:

  • Initial anti-spam logic for chat and "spec spawn" ("X is now spectating" / "X has respawned") messages
  • Filter for "spec spawn" messages to filter them completely from the chat
  • Chat history to chat input, press up arrow to go to recently sent message to older, down arrow to go to oldest message to newer
  • New convar mom_run_safeguard_warning_delay that controls how long between warnings that a command is safeguarded

Added the following chat commands:
Note that all command triggers are prefixed with either "/" or "!"

  • BonusTeleportCommand
    • Triggers: "b", "bonus"
    • Functionality equivalent to: mom_restart <bonus> (or "!r <bonus>")
  • TrackTeleportCommand:
    • Triggers: "r", "restart"
    • Functionally equivalent to: mom_restart
  • StageTeleportCommand
    • Triggers: "s", "stage"
    • Functionally equivalent to: mom_restart_stage
  • SetStartMarkCommand
    • Triggers: "setstart"
    • Functionally equivalent to: mom_start_mark_create
  • ShowPlayerClipsCommand
    • Triggers: "clips", "showclips"
    • Functionally equivalent to: r_drawclipbrushes (0, 1, 2) (it cycles through these)
  • ShowTriggersCommand
    • Triggers: "triggers", "showtriggers"
    • Functionally equivalent to: showtriggers_toggle
  • SpectatePlayerCommand
    • Triggers: "spec", "spectate"
    • Functionally equivalent to: mom_spectate
  • StopSpecCommand
    • Triggers: "stopspec", "specstop", "spawn", "respawn"
    • Functionally equivalent to: mom_spectate_stop
  • GoToPlayerCommand
    • Triggers: "goto"
    • Functionally equivalent to: mom_lobby_teleport

Improved:

  • Improved typing members label to only update on typing status change and not every frame, now uses localized tokens for it
  • mom_spectate
    • Now takes in a partial name match for lobby member names (e.g. mom_spectate beet will spectate beetle179)
    • If spectating, will switch to spectating the matched player
  • mom_lobby_teleport
    • Now takes in a partial name match for lobby member names (e.g. mom_lobby_teleport beet will teleport you to beetle179)
    • If spectating, will switch to spectating the matched player

Checklist

  • I have thoroughly tested all of the code I have modified/added/removed to ensure something else did not break
  • If there is a localization token change, I have updated the momentum_english_ref.res file with the changes, ran tokenizer.py to generate an up-to-date localization file, and have committed both the .res file changes and the new localization .txt file
  • If I introduced new h/cpp files, I have added them to the appropriate project's VPC file (server_momentum.vpc / client_momentum.vpc / etc)
  • If I have added or modified any visual assets (models, materials, panels, effects, etc), I have taken screenshots / videos of them and attached them to this PR directly (screenshots uploaded through github, videos uploaded to youtube and linked)
  • If I have modified any console command, console variable, or momentum entity, I have opened an issue (or a PR) for it in the Momentum Mod documentation repository
  • My commits are relatively small and scoped to the best of my ability
  • My branch has a clear history of changes that can be easy to follow when being reviewed commit-by-commit
  • My branch is functionally complete; the only changes to be done will be those potentially requested in code review

@lvaness
Copy link
Member

lvaness commented Nov 24, 2020

One thing I noticed when checking this out was that when using the commands from the lobby panel's chat (is this even intended?) there is some strange behavior:

  • The commands get submitted to the console but the text doesn't clear and go to history
  • The command gets submitted twice (you hear two Cannot start timer messages for !r and triggers will flicker for a second before (dis)appearing again)

@SCell555
Copy link
Member

Ignore my previous comments, ILocalize was using templates in strange way. I refactored ILocalize's string construction, so it is more flexible and now covers all standard types. Should I make this a PR, or I can give you patch file.

@Gocnak
Copy link
Member Author

Gocnak commented Nov 24, 2020

Ignore my previous comments, ILocalize was using templates in strange way. I refactored ILocalize's string construction, so it is more flexible and now covers all standard types. Should I make this a PR, or I can give you patch file.

You can PR into this yeah.

@Gocnak
Copy link
Member Author

Gocnak commented Nov 24, 2020

there is some strange behavior:

* The commands get submitted to the console but the text doesn't clear and go to history

Are you using it from the main menu while not in a map? Which command are you doing? Is it during a run?

* The command gets submitted twice (you hear two Cannot start timer messages for !r and triggers will flicker for a second before (dis)appearing again)

This one's odd. I'll look into this more.

@lvaness
Copy link
Member

lvaness commented Nov 24, 2020

Regarding the first one: It happens both in the main menu and on a map, it happens with every valid command (for example, writing !abc submits to chat fine, while !b does invoke the concommand (although twice) but doesn't go into the history or chat panel) and being on a run has no effect on the issue. (But only for the drawer's chat panel, the hud chat works fine).

@SCell555
Copy link
Member

SCell555 commented Nov 24, 2020

I have enabled safeguards and they prevent commands from executing, ie when I type !r in chat while timer is running, it will not reset me. From lobby chat it will reset me.

@lvaness
Copy link
Member

lvaness commented Nov 24, 2020

This is what it looks like to me: https://streamable.com/vibiv9 , I disabled the blur for clarity but to be sure I did a clean build with a fresh checkout, checked GameUI was symlinked properly, but still the same. This can't be OS-dependent, can it?

@SCell555
Copy link
Member

SCell555 commented Nov 24, 2020

In ChatPanel::OnKeyCodeReleased, is sending second OnChatEntrySend. Once I removed that, it works normally. Except that it doesn't clear chat, but it did that before I changed that.

@Gocnak
Copy link
Member Author

Gocnak commented Nov 25, 2020

@SCell555 @bltech If you have time, try out the latest code and let me know if you're still seeing problems.

I think the safeguard case is just because there's no good safeguard warning, though I might just put it inside a ClientPrint instead of a console message...

@SCell555
Copy link
Member

Crash is gone now, and commands in lobby chat panel work correctly.

The warning in console is kind of annoying when restarting over and over. ClientPrint would be probably better, or print it somewhere where it doesn't stick around.

@lvaness
Copy link
Member

lvaness commented Nov 25, 2020

Yep, I no longer get double commands and it gets cleared correctly now.

Microsoft does some funky business with their widechar print functions so yay macros
Same code between server and client
Allows for commands that were using IDs to use partial name matching as well now
Brilliant 2014 code design to have it piggyback off of the Chat panel in the first place
This also allows for using partial string name matches for players in the lobby, and jumping to a new target if already spectating
Allows partial name matching
Attempts to spectate player if spectating
Kinda gross hack, not sure why clicking the close button doesn't relinquish the focus already on the drawer and its children
Users will be able to filter out the "X is now spectating" and "X has now respawned" messages with this
Now only updates on update from others when typing, instead of every single frame forever
Localized as well!
Saves the last 20 unique messages you input
Use up arrow when empty text to start from the most recent message you entered, and to iterate further into history
Use down arrow when empty text to start from the least recent message you entered, and to iterate towards the most recent message
You can do partial deletes and iteration will still work
Has some nice utility functions like Trim()
Chat messages are validated against a 0.66 sec spam delay both locally and for incoming messages
Specspawn ("X is spectating" / "X has respawned") are also on a 0.5 sec spam cooldown as well, and can now be filtered out in the chat as well
Gocnak and others added 14 commits November 25, 2020 23:19
And specspawn needs a string, gave it one too
Chat commands are only being added as a more user-friendly and backwards-compatible way to do console commands. It is recommended that end users still do console commands or use the dedicated UI for things, and we will not be adding every command, but most power users may find them useful.

A fear I have is that people make "say" binds instead of command binds...
Good catch SCell, only happened when there were public lobbies available to join though so I couldn't reproduce it locally at time of coding this
Closes #1167
Allows the menu chat to clear properly; the HUD one was just stopping message mode which automatically clears the input
Escape in the menu closes the menu drawer
Do not manually call OnKeyCodeTyped for parent
Change OnKeyCodeReleased -> OnKeyCodeTyped for consistency with the rest of the menu overrides
I don't think commands will ever overlap, and the Operate should just early return with a fail message if it fails
Although it uses the same as the !r command, it has a distinct requirement of passing the number of the bonus to go to. Restart still does it too.
Also print out a lovely usage command when it fails
Much more visible than the Warning console error message
Controlled by mom_run_safeguard_warning_delay
@Gocnak Gocnak merged commit 4ef61ab into develop Nov 26, 2020
@Gocnak Gocnak deleted the feature/chat-commands branch November 26, 2020 05:14
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.

Crash in main menu Chat doesn't filter out large amounts of blank space causing an error Chat commands
3 participants