-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated deprecated CPanel calls #2184
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really should not have done everything in 1 go. I'd encourage you to move the Sandbox tool changes to a separate Pull Request. It makes reviewing changes easier.
That being said, this PR has plenty of issues that needs addressing before it can be merged.
CPanel:AddItem( control, nil ) | ||
self:InvalidateLayout() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't feel like a necessary change.
-- Force limit | ||
local forceLimit = CPanel:NumSlider( "#tool.forcelimit", "axis_forcelimit", 0, 50000, 2 ) | ||
local forceLimitDefault = GetConVar( "axis_forcelimit" ) | ||
CPanel:ControlHelp( "#tool.forcelimit" .. ".help" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"#tool.forcelimit" .. ".help"
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous code equated to that, wasn't it?
I do agree there's an unnecessary concatenation, though.
local torqueLimit = CPanel:NumSlider( "#tool.torquelimit", "axis_torquelimit", 0, 50000, 2 ) | ||
local torqueLimitDefault = GetConVar( "axis_torquelimit" ) | ||
CPanel:ControlHelp( "#tool.torquelimit" .. ".help" ) | ||
if ( torqueLimitDefault ) then | ||
torqueLimit:SetDefaultValue( torqueLimitDefault:GetDefault() ) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you defining a variable, adding help, and only then using the defined variable?
Moreover, I think implementing the SetDefaultValue
call into DForm:NumSlider
makes a lot more sense, rather than duplicating the same code in every tool multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am defining the variable to avoid calling GetConVar
twice, but I do agree I should put it in a local function.
BTW, is calling SetDefaultValue
really necessary, or is it automatically set to the value of the convar on init?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the default value is not automatically set, but perhaps it should be. (Inside of DNumSlider:SetConvar)
local presets = vgui.Create( "ControlPresets", CPanel ) | ||
presets:SetPreset( "axis" ) | ||
presets:AddOption( "#preset.default", ConVarsDefault ) | ||
for k, v in pairs( table.GetKeys( ConVarsDefault ) ) do | ||
presets:AddConVar( v ) | ||
end | ||
CPanel:AddPanel( presets ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use CPanel:ToolPresets( group, cvarlist )
here.
|
||
CPanel:AddControl( "TextBox", { Label = "#tool.button.text", Command = "button_description", MaxLenth = "20" } ) | ||
-- Description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is up with these pointless comments being added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To better highlight what parameter is set up. This time, I think I'm right. :)
|
||
CPanel:AddControl( "Numpad", { Label = "#tool.button.key", Command = "button_keygroup" } ) | ||
-- Key | ||
local numpad = vgui.Create( "CtrlNumPad", CPanel ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CPanel:KeyBinder( label1, convar1, label2, convar2 )
|
||
CPanel:AddControl( "PropSelect", { Label = "#tool.button.model", ConVar = "button_model", Height = 0, Models = list.Get( "ButtonModels" ) } ) | ||
-- Model | ||
local model = vgui.Create( "PropSelect", CPanel ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a separate function for this in controlpanel.lua
|
||
CPanel:AddControl( "Button", { Text = "#tool.duplicator.showsaves", Command = "dupe_show" } ) | ||
local dupeShow = vgui.Create( "DButton", CPanel ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DForm:Button
|
||
local filter = CPanel:AddControl( "TextBox", { Label = "#spawnmenu.quick_filter_tool" } ) | ||
local filter = CPanel:TextEntry( "#spawnmenu.quick_filter_tool", nil ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely we can omit nil
from here, since omitting it would be identical to providing nil
.
invert:SetDefaultValue( invertDefault:GetDefault() ) | ||
end | ||
|
||
local colorAdd = vgui.Create( "CtrlColor", CPanel ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. I'll concentrate this very PR on the Sandbox tool changes for now.
Thank you for the return, I'll proceed to the changes tomorrow. |
Hello everyone, I hope you're doing fine. :)
I've noticed base Garry's Mod uses the
AddControl
function for the UI panel creation.To quote Garry himself in here:
Thus, I took the time to update all the
AddControl
calls with their non-deprecated counterparts (moreover, it should improve performance).I did an extensive testing to make sure it doesn't break anything, and it works flawlessly (but of course, feel free to check, I may have made mistakes ;).