"OnCommand" Hook problem.
I noticed one bug, that "OnCommand" method/hook doesn't works on Scripted Frame, it works only on Scripted PropertyDialog.
Interesting. Can you provide some example code of your issue? I'll see what causes this if I can.
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)
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