QoL improvements, replace deprecated control panel functions (#38)

* Add "Classic Visclip" mode for people used to old visclip

* QoL improvements, rename "Classic" mode to "Pitch and Yaw"

* Add reset button to zero out sliders

* Fix undo checkbox not working

GetConVar -> GetClientBool

* Don't show preview on brush based entities

* Add new convars to readme

* Fix nil value error on undo while looking at entity

* styling

---------

Co-authored-by: Sevii <sevii@sevii.dev>
This commit is contained in:
Matt 2023-06-04 11:56:23 -04:00 committed by GitHub
parent c610f0bfe7
commit 1d5515dc4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 123 additions and 56 deletions

View File

@ -34,6 +34,9 @@ Client Convars:
- proper_clipping_mode
- proper_clipping_offset
- proper_clipping_physics
- proper_clipping_pitch
- proper_clipping_yaw
- proper_clipping_undo
---
@ -50,4 +53,4 @@ Hooks:
---
[Available on the Steam Workshop](https://steamcommunity.com/sharedfiles/filedetails/?id=2256491552)
[Available on the Steam Workshop](https://steamcommunity.com/sharedfiles/filedetails/?id=2256491552)

View File

@ -5,6 +5,9 @@ TOOL.ClientConVar.mode = "0" -- int
TOOL.ClientConVar.offset = "0" -- float
TOOL.ClientConVar.physics = "0" -- bool
TOOL.ClientConVar.keepmass = "0" -- bool
TOOL.ClientConVar.pitch = "0" -- float
TOOL.ClientConVar.yaw = "0" -- float
TOOL.ClientConVar.undo = "1" -- bool
if CLIENT then
local function updateInfo()
@ -18,6 +21,7 @@ if CLIENT then
language.Add("Tool.proper_clipping.mode.0", "Hitplane")
language.Add("Tool.proper_clipping.mode.1", "Point to Point")
language.Add("Tool.proper_clipping.mode.2", "2 Hitplanes intersection")
language.Add("Tool.proper_clipping.mode.3", "Pitch and Yaw")
updateInfo()
language.Add("Tool.proper_clipping.right", "Clip entity")
@ -27,7 +31,7 @@ if CLIENT then
language.Add("Tool.proper_clipping.left_op1_stage0", "Define start point")
language.Add("Tool.proper_clipping.left_op1_stage1", "Define end point")
language.Add("Tool.proper_clipping.left_op2", "Define intersecting planes. The last 2 of them are used to calculate intersection")
TOOL.Information = {
@ -45,54 +49,112 @@ if CLIENT then
{stage = 0, name = "right"}
}
function TOOL.BuildCPanel(panel)
local cvar_visual = GetConVar("proper_clipping_max_visual")
panel:AddControl("Slider", {
label = "Max Visual Clips",
command = "proper_clipping_max_visual",
min = cvar_visual:GetMin(),
max = cvar_visual:GetMax()
})
local function makeSlider(panel, label, cvar, min, max, decimals)
local slider = vgui.Create("DNumSlider", panel)
slider:SetText(label)
slider:SetMin(min)
slider:SetMax(max)
slider:SetDecimals(decimals)
slider:SetConVar(cvar)
slider:SetDark(true)
slider:DockMargin(10, 5, 5, 0)
slider:Dock(TOP)
panel:AddControl("ListBox", {
Label = "Mode",
Options = {
["#Tool.proper_clipping.mode.0"] = {proper_clipping_mode = 0},
["#Tool.proper_clipping.mode.1"] = {proper_clipping_mode = 1},
["#Tool.proper_clipping.mode.2"] = {proper_clipping_mode = 2}
}
})
panel:AddControl("Slider", {
label = "Offset",
type = "float",
command = "proper_clipping_offset",
min = -50,
max = 50
})
panel:AddControl("Checkbox", {
label = "Physics",
command = "proper_clipping_physics"
})
panel:AddControl("Checkbox", {
label = "Keep Mass",
command = "proper_clipping_keepmass"
})
return slider
end
local function makeCheckbox(panel, label, cvar)
local checkbox = vgui.Create("DCheckBoxLabel", panel)
checkbox:SetText(label)
checkbox:SetConVar(cvar)
checkbox:DockMargin(10, 5, 5, 10)
checkbox:Dock(TOP)
checkbox:SetDark(true)
return checkbox
end
function TOOL.BuildCPanel(panel)
local cvar_visual = GetConVar("proper_clipping_max_visual")
local cvar_mode = GetConVar("proper_clipping_mode")
local cvar_mode_val = cvar_mode:GetInt()
makeSlider(panel, "Max Visual Clips", "proper_clipping_max_visual", cvar_visual:GetMin(), cvar_visual:GetMax(), 0)
makeCheckbox(panel, "Physical clip", "proper_clipping_physics")
makeCheckbox(panel, "Keep mass when physics clipping", "proper_clipping_keepmass")
makeCheckbox(panel, "Add clips to undo list", "proper_clipping_undo")
local pitch, yaw
local mode = vgui.Create("DComboBox", panel)
mode:AddChoice("#Tool.proper_clipping.mode.0", 0, true)
mode:AddChoice("#Tool.proper_clipping.mode.1", 1)
mode:AddChoice("#Tool.proper_clipping.mode.2", 2)
mode:AddChoice("#Tool.proper_clipping.mode.3", 3)
mode:SetText("#Tool.proper_clipping.mode." .. cvar_mode_val)
function mode:OnSelect(_, _, val)
cvar_mode:SetInt(val)
if val == 3 then
pitch:SetVisible(true)
yaw:SetVisible(true)
else
pitch:SetVisible(false)
yaw:SetVisible(false)
end
panel:InvalidateLayout()
end
mode:DockMargin(10, 10, 5, 0)
mode:Dock(TOP)
local offset = makeSlider(panel, "Offset", "proper_clipping_offset", -100, 100, 2)
pitch = makeSlider(panel, "Pitch", "proper_clipping_pitch", -180, 180, 2)
pitch:SetVisible(cvar_mode_val == 3)
yaw = makeSlider(panel, "Yaw", "proper_clipping_yaw", -180, 180, 2)
yaw:SetVisible(cvar_mode_val == 3)
local reset = vgui.Create("DButton", panel)
reset:SetText("Reset Values")
reset:SetDark(true)
reset:DockMargin(10, 5, 5, 0)
reset:Dock(TOP)
reset.DoClick = function()
offset:SetValue(0)
pitch:SetValue(0)
yaw:SetValue(0)
end
end
TOOL.Deploy = updateInfo
end
----------------------------------------
function TOOL:Think()
local new = math.floor(self:GetClientNumber("mode"))
local op = math.floor(self:GetClientNumber("mode"))
local ply = self:GetOwner()
if new == self:GetOperation() then return end
if op == 3 then
local ent = ply:GetEyeTrace().Entity
if not IsValid(ent) then return end
if ent:IsPlayer() or ent:IsWorld() then return end
local ang = Angle(self:GetClientNumber("pitch"), self:GetClientNumber("yaw"), 0)
local dir = ang:Forward()
local dist = self:GetClientNumber("offset")
self.norm = dir
self.origin = ent:GetPos() + dir * dist
end
self:SetOperation(new)
if op == self:GetOperation() then return end
self:SetOperation(op)
self:SetStage(0)
end
@ -219,17 +281,19 @@ function TOOL:RightClick(tr)
ProperClipping.AddClip(ent, norm, dist, owner:KeyDown(IN_SPEED), physics, keepmass)
undo.Create("Proper Clip")
undo.AddFunction(function(_, ent, norm, dist, keepmass)
if not ent or not ent:IsValid() then return end
local exists, index = ProperClipping.ClipExists(ent, norm, dist)
if exists then
ProperClipping.RemoveClip(ent, index, keepmass)
end
end, ent, norm, dist, keepmass)
undo.SetPlayer(owner)
undo.Finish()
if self:GetClientNumber("undo") ~= 0 then
undo.Create("Proper Clip")
undo.AddFunction(function(_, ent, norm, dist, keepmass)
if not ent or not ent:IsValid() then return end
local exists, index = ProperClipping.ClipExists(ent, norm, dist)
if exists then
ProperClipping.RemoveClip(ent, index, keepmass)
end
end, ent, norm, dist, keepmass)
undo.SetPlayer(owner)
undo.Finish()
end
return true
end
@ -260,9 +324,9 @@ if CLIENT then
model2:SetMaterial("models/debug/debugwhite")
model1:SetNoDraw(true)
model2:SetNoDraw(true)
local debugwhite = Material("models/debug/debugwhite")
local function DrawPreviewModel(self)
if isentity(self.GetRenderMesh) then
render.ModelMaterialOverride(debugwhite)
@ -270,10 +334,10 @@ if CLIENT then
render.ModelMaterialOverride(nil)
return
end
self:DrawModel()
end
local last_ent
hook.Add("PostDrawOpaqueRenderables", "proper_clipping", function(depth, skybox)
@ -320,7 +384,7 @@ if CLIENT then
if not norm then return end
-- Preview
if ent and ent:IsValid() and not ent:IsPlayer() then
if ent and ent:IsValid() and not ent:IsPlayer() and not ent:GetBrushSurfaces() then
if ent ~= last_ent then
local mdl = ent:GetModel()
model1:SetModel(mdl)
@ -340,7 +404,7 @@ if CLIENT then
model1:SetBodygroup(id, val)
model2:SetBodygroup(id, val)
end
model1.GetRenderMesh = isfunction(ent.GetRenderMesh) and ent or nil
model2.GetRenderMesh = isfunction(ent.GetRenderMesh) and ent or nil
end