codecat / tm-better-chat

A better chat for Trackmania using Openplanet.
https://openplanet.dev/plugin/betterchat
22 stars 7 forks source link

When drafting a chat msg and the input loses focus, the draft msg is lost #44

Closed XertroV closed 1 year ago

XertroV commented 2 years ago

Sometimes the game steals focus while you're typing a chat message -- for example the "stay"/"leave" prompts at the end of COTD, Royal, etc. If you're drafting a chat msg at this point, the text input loses focus and the msg is lost. Additionally, if you hit Esc while typing (e.g. b/c the match is about to start) any msg that isn't sent is also lost.

codecat commented 2 years ago

Not sure how the game can steal focus from Openplanet, generally that shouldn't be possible unless you click on something in the game yourself.

Additionally, pressing escape is considered a "cancellation" of input, so it would be expected to clear the text.

Not sure what the best solution would be to be honest. Maybe as a setting?

XertroV commented 2 years ago

Not sure how the game can steal focus from Openplanet, generally that shouldn't be possible unless you click on something in the game yourself.

I'll try to record a sample today. It's repeatable but only happens for certain events/menus.

Additionally, pressing escape is considered a "cancellation" of input, so it would be expected to clear the text.

I agree this would be standard. I'm happy to implement a setting for it if you're okay with that.

I think the feature is valuable and worth doing, even though it's something non-standard -- basically because there's no good alternative.

codecat commented 2 years ago

I agree, having it as a setting would be a good solution. If you add a setting for it in #45 I'll review it asap 😄

XertroV commented 2 years ago

Here are some recorded samples of the game stealing focus. the clips are long enough to show the chat msg is saved. (also, apologies for the frame rate -- OBS encoding issue)

https://user-images.githubusercontent.com/1046448/169506726-3a71e499-ab61-46b1-b030-269668d6d319.mp4

https://user-images.githubusercontent.com/1046448/169506734-f41402ba-0525-4c02-b65d-32650cef3056.mp4

I also discovered that if you click (instead of pressing esc) that will defocus the chat, too. My implementation idea for putting the cache-on-escape feature behind a setting (and that setting is false) would, by default, save chat if you defocused via clicked but forget the cache if you defocused via escape. that feels more intuitive to me as default behavior.

Also, for like 1 frame in the second clip a weird thing is shown in the chat box just before it defocuses around 0:15.

XertroV commented 2 years ago

I've added the save-draft-on-escape function behind a setting. I wasn't sure if you meant that only that part of the PR should be behind a setting or all of it should be.

I haven't moved the rest of the functionality behind a setting because I think, when the game steals focus, draft msgs should be cached. Additionally, it'd probably double the number of lines of code changed, so this is much cleaner. (otherwise m_input gets reset to "" in 2 different places, each behind the true/false cases of the setting, which seems like needless complexity if you agree with my reasoning.)

codecat commented 2 years ago

Ah I see, focus is only "lost" because Better Chat decides to hide itself because it is no longer in a server. (Server switch, you can see the chat is cleared because of the server switch too.)

Not sure about the second clip, or the weird text in the second clip. Might that weird text thing have something to do with your PR?

XertroV commented 2 years ago

Not sure about the second clip, or the weird text in the second clip. Might that weird text thing have something to do with your PR?

I think it happens in ranked, royal, and super royal, too. (It's always a stay/leave prompt, excepting the map-change case)

Edit: That was just responding to the main point, not the bit about weird text. IDK about the text. One reason it seemed significant is that it starts with a ? and there was something in discord about that recently.

XertroV commented 2 years ago

(It's always a stay/leave prompt, excepting the map-change case)

My guess with the stay/leave thing, btw, is that it has something to do with the user moving from a player to a spectator. That maybe doesn't work with ranked (since the round ends anyway), but it makes sense for royal and COTD.