Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RubisetCie
Copy link

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:

You shouldn't ever really be calling AddControl.
If you're writing new code - don't call AddControl!! Add stuff directly using the DForm member functions!

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 ;).

Copy link
Collaborator

@robotboy655 robotboy655 left a 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.

Comment on lines +52 to +53
CPanel:AddItem( control, nil )
self:InvalidateLayout()
Copy link
Collaborator

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" )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"#tool.forcelimit" .. ".help"

??

Copy link
Author

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.

Comment on lines +242 to +247
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
Copy link
Collaborator

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.

Copy link
Author

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?

Copy link
Collaborator

@robotboy655 robotboy655 Jan 14, 2025

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)

Comment on lines +225 to +231
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 )
Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Author

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 )
Copy link
Collaborator

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 )
Copy link
Collaborator

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 )
Copy link
Collaborator

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 )
Copy link
Collaborator

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 )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robotboy655 robotboy655 added the Enhancement The pull request enhances current functionality. label Jan 13, 2025
@RubisetCie
Copy link
Author

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.

Understood. I'll concentrate this very PR on the Sandbox tool changes for now.

That being said, this PR has plenty of issues that needs addressing before it can be merged.

Thank you for the return, I'll proceed to the changes tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement The pull request enhances current functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants