hl2sb-src icon indicating copy to clipboard operation
hl2sb-src copied to clipboard

"OnCommand" Hook problem.

Open Dim1xs opened this issue 1 year ago • 3 comments

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

Dim1xs avatar Mar 27 '24 08:03 Dim1xs

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

andrewmcwatters avatar Mar 27 '24 15:03 andrewmcwatters

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)

Dim1xs avatar Mar 27 '24 16:03 Dim1xs

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 avatar Mar 27 '24 17:03 andrewmcwatters