Skip to content
New issue

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

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

Already on GitHub? # to your account

"OnCommand" Hook problem. #4

Open
Dim1xs opened this issue Mar 27, 2024 · 3 comments
Open

"OnCommand" Hook problem. #4

Dim1xs opened this issue Mar 27, 2024 · 3 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Dim1xs
Copy link

Dim1xs commented Mar 27, 2024

I noticed one bug, that "OnCommand" method/hook doesn't works on Scripted Frame, it works only on Scripted PropertyDialog.

@andrewmcwatters
Copy link
Member

Interesting. Can you provide some example code of your issue? I'll see what causes this if I can.

@Dim1xs
Copy link
Author

Dim1xs commented Mar 27, 2024

Interesting. Can you provide some example code of your issue? I'll see what causes this if I can.

Yeah, here the code.

local PANEL = {}

local ImAFrame = false -- Switch this to true, for creating Frame.

function PANEL:Init(parent, name)
    self:SetBounds(UTIL.ScreenWidth() / 2, UTIL.ScreenHeight() / 2, 350, 150)
    self:SetTitle("Panel with button.", true)

    self.Button = vgui.Button(self, "button", "Kill me!", self, "pKill")
    self.Button:SetPos(50, 50)
end

function PANEL:OnCommand(pCmd)
    if pCmd == "pKill" then
        engine.ClientCmd("kill")
    end
end

if ImAFrame == true then 
    vgui.register(PANEL, "SimplePanel_Frame", "Frame") -- Register as Frame
else
    vgui.register(PANEL, "SimplePanel_Dialog", "PropertyDialog") -- Register as PropertyDialog
end

local function open()
    if ( ToPanel( Panel ) == INVALID_PANEL ) then
        if ImAFrame == true then 
            Panel = vgui.SimplePanel_Frame(VGui_GetClientLuaRootPanel(), "SimplePanel");
        else
            Panel = vgui.SimplePanel_Dialog(VGui_GetClientLuaRootPanel(), "SimplePanel");
        end
    end
    Panel:Activate();
end

concommand.Create("open_panel", open)

@andrewmcwatters
Copy link
Member

andrewmcwatters commented Mar 27, 2024

Bingo, thanks you found the issue, @Dim1xs.

When I wrote the bindings 11 years ago or so, I didn't create a method on the C++ end to listen to OnCommand hooks for scripted frames:

https://github.com/Planimeter/hl2sb-src/blob/master/src/game/client/scripted_controls/lFrame.cpp

https://github.com/Planimeter/hl2sb-src/blob/master/src/game/client/scripted_controls/lPropertyDialog.cpp#L58-L72

@andrewmcwatters andrewmcwatters self-assigned this Apr 29, 2024
@andrewmcwatters andrewmcwatters added good first issue Good for newcomers bug Something isn't working labels Apr 29, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants