Facepunch / garrysmod-issues

Garry's Mod issue tracker
139 stars 56 forks source link

GM:PlayerBindPress hook not called when TextEntry focused but +binds are activated #2888

Open mandrewpowers opened 7 years ago

mandrewpowers commented 7 years ago

Details

Working on a text editor to rule them all and it is based on a TextEntry as to capture pasting. When working on shortcuts I pressed my +showscores bind and the scoreboard popped up over my DFrame. The PlayerBindPress hook I have is suppose to prevent this (will post hook below). The weird thing I noticed is that when the DFrame is focused the hook isn't called either (this is probably because why would binds be called when vgui has focus). I'm guessing this is a workaround gone wrong, but obviously I have no idea.

Hook I use that doesn't get called when my vgui is open:```lua function dgp.PlayerBindPress(ply, bind, pressed) print(ply, bind, pressed) if IsValid(dgp.SuiteFrame) and dgp.SuiteFrame:IsVisible() then dgp.util.log('info', 'dgp.PlayerBindPress: Preventing %s from running while editor open', bind) return true end end hook.Add('PlayerBindPress', 'dgp.PlayerBindPress', dgp.PlayerBindPress)


### Steps to reproduce
Here is some code that works every time. Bind `+showscores` to F5 if you want to match my setup.
```lua
local FRAME = vgui.Create('DFrame')
FRAME:SetSize(400, 300)
FRAME:Center()

local ENTRY = vgui.Create('DTextEntry', FRAME)
ENTRY:Center()

FRAME:MakePopup()

hook.Add('PlayerBindPress', 'DTextEntryThings', print)
  1. Bind F5 to +showscores.
  2. Execute code above.
  3. Before focusing the DTextEntry press your +showscores bind and notice nothing happens.
  4. Focus DTextEntry.
  5. Press your +showscores bind and notice the scoreboard shows (and the hook will print) but does not go away.
willox commented 7 years ago

It's intentional that the F1-F12 keys always run binds regardless of any elements having text focus. Although this only actually happens if the keys are bound to something.

Do you need it to work differently for some reason? I don't think anything is going to change because it seems like a useful feature to always have the bindings run.

mandrewpowers commented 7 years ago

@willox I'm writing a text editor (see: http://i.imgur.com/6RG4k7A.png) and the editor is based off TextEntry so that I may catch clipboard pasting. When I started implementing shortcuts such as F5 for compile and execute I realized that it triggered my binds causing menus to popup over my DFrame / editor.

Not that it really matters, but why is this behavior particularly useful? I've never heard of a case where someone has a TextEntry focused and wants to use a function key bind to open something.

tl;dr: More importantly I'd suggest making sure this behavior still triggers GM:PlayerBindPress so that it can be blocked as needed so this oddness in cases like mine can be avoided.

Side note: The -BIND is not executed for the function keys in this case, so menus get stuck open such as the scoreboard.

robotboy655 commented 7 years ago

I think its meant for the F10 console default bind.

robotboy655 commented 7 years ago

Also why are you using TextEntry and not RichText? Not saying it will be better with your problem, but it just seems weird to me.

mandrewpowers commented 7 years ago

Sorry @robotboy655 I had not been able to work on GMod projects for a while, but anyway...

F10? That use to be disconnect. I thought console was always tilde/grave? Also RichText does not provide anything of use as far as I know. The first time I tried to use it for an editor years ago it was basically just garbage and unnecessarily obnoxious to use from Lua. Writing my own gave me massive control over every aspect in comparison. Why do you think I should use it?

mandrewpowers commented 7 years ago

Anymore thoughts on this? Am I just going to have to avoid the function keys? I'd be nice if something like this was more controllable. I still don't feel like some buttons should have weird special handling. They should all act the same.

Kefta commented 5 years ago

Would be nice to have this to avoid networking to the client from ShowHelp and ShowTeam for custom functional menus.