Skip to content

Commit 66b5fdb

Browse files
committed
model/entity "edit materials" quick setup
instead of load vmt, get some quick setups to auto add them and set them up in one click. the submenu root is clickable and deploys all submaterials but the sub-options are right clickable
1 parent 26ec84c commit 66b5fdb

File tree

1 file changed

+76
-41
lines changed

1 file changed

+76
-41
lines changed

lua/pac3/editor/client/parts.lua

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ do -- menu
13631363

13641364
function pace.ClearBulkList()
13651365
for _,v in ipairs(pace.BulkSelectList) do
1366-
if v.pace_tree_node ~= nil then v.pace_tree_node:SetAlpha( 255 ) end
1366+
if IsValid(v.pace_tree_node) then v.pace_tree_node:SetAlpha( 255 ) end
13671367
v:SetInfo()
13681368
end
13691369
pace.BulkSelectList = {}
@@ -2652,6 +2652,78 @@ function pace.AddQuickSetupsToPartMenu(menu, obj)
26522652
end):SetIcon("icon16/table_multiple.png")
26532653
end
26542654

2655+
local function install_submaterial_options(menu)
2656+
local mats = obj:GetOwner():GetMaterials()
2657+
local mats_str = table.concat(mats,"\n")
2658+
local dyn_props = obj:GetDynamicProperties()
2659+
local submat_togglers, pnl = main:AddSubMenu("create submaterial zone togglers (hide/show materials)", function()
2660+
Derma_StringRequest("submaterial togglers", "please input a submaterial name or a list of submaterial names with spaces\navailable materials:\n"..mats_str, "", function(str)
2661+
local event = pac.CreatePart("event") event:SetAffectChildrenOnly(true) event:SetEvent("command") event:SetArguments("materials_"..string.sub(obj.UniqueID,1,6))
2662+
local proxy = pac.CreatePart("proxy") proxy:SetAffectChildren(true) proxy:SetVariableName("no_draw") proxy:SetExpression("0") proxy:SetExpressionOnHide("1")
2663+
event:SetParent(obj) proxy:SetParent(event)
2664+
for i, kw in ipairs(string.Split(str, " ")) do
2665+
for id,mat2 in ipairs(mats) do
2666+
if string.GetFileFromFilename(mat2) == kw then
2667+
local mat = pac.CreatePart("material_3d") mat:SetParent(proxy)
2668+
mat:SetName("toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6))
2669+
mat:SetLoadVmt(mat2)
2670+
dyn_props[kw].set("toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6))
2671+
end
2672+
end
2673+
end
2674+
end)
2675+
end) pnl:SetImage("icon16/picture_delete.png") pnl:SetTooltip("The sub-options are right clickable")
2676+
2677+
local submat_toggler_proxy
2678+
local submat_toggler_event
2679+
local submaterials = {}
2680+
for i,mat2 in ipairs(mats) do
2681+
table.insert(submaterials,"")
2682+
local kw = string.GetFileFromFilename(mat2)
2683+
AddOptionRightClickable(kw, function()
2684+
if not submat_toggler_proxy then
2685+
local event = pac.CreatePart("event") event:SetAffectChildrenOnly(true) event:SetEvent("command") event:SetArguments("materials_"..string.sub(obj.UniqueID,1,6))
2686+
local proxy = pac.CreatePart("proxy") proxy:SetAffectChildren(true) proxy:SetVariableName("no_draw") proxy:SetExpression("0") proxy:SetExpressionOnHide("1")
2687+
event:SetParent(obj) proxy:SetParent(event)
2688+
submat_toggler_proxy = proxy
2689+
end
2690+
local mat = pac.CreatePart("material_3d") mat:SetParent(submat_toggler_proxy)
2691+
mat:SetName("toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6))
2692+
mat:SetLoadVmt(mat2)
2693+
2694+
submaterials[i] = "toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6)
2695+
obj:SetMaterials(table.concat(submaterials, ";"))
2696+
end, submat_togglers):SetIcon("icon16/paintcan.png")
2697+
end
2698+
2699+
local edit_materials, pnl = main:AddSubMenu("edit all materials", function()
2700+
local materials = ""
2701+
obj:SetMaterial("")
2702+
for i,mat2 in ipairs(mats) do
2703+
local kw = string.GetFileFromFilename(mat2)
2704+
local mat = pac.CreatePart("material_3d") mat:SetParent(obj)
2705+
mat:SetName(kw.."_"..string.sub(obj.UniqueID,1,6))
2706+
mat:SetLoadVmt(mat2)
2707+
submaterials[i] = kw.."_"..string.sub(obj.UniqueID,1,6)
2708+
2709+
end
2710+
obj:SetMaterials(table.concat(submaterials, ";"))
2711+
end) pnl:SetImage("icon16/paintcan.png")
2712+
2713+
for i,mat2 in ipairs(mats) do
2714+
local kw = string.GetFileFromFilename(mat2)
2715+
AddOptionRightClickable(kw, function()
2716+
obj:SetMaterial("")
2717+
2718+
local mat = pac.CreatePart("material_3d") mat:SetParent(obj)
2719+
mat:SetName(kw.."_"..string.sub(obj.UniqueID,1,6))
2720+
mat:SetLoadVmt(mat2)
2721+
2722+
submaterials[i] = kw.."_"..string.sub(obj.UniqueID,1,6)
2723+
obj:SetMaterials(table.concat(submaterials, ";"))
2724+
end, edit_materials):SetIcon("icon16/paintcan.png")
2725+
end
2726+
end
26552727
if obj.ClassName == "particles" then
26562728
main:AddOption("bare 3D setup", function()
26572729
obj:Set3D(true) obj:SetZeroAngle(false) obj:SetVelocity(0) obj:SetParticleAngleVelocity(Vector(0,0,0)) obj:SetGravity(Vector(0,0,0))
@@ -2928,26 +3000,8 @@ function pace.AddQuickSetupsToPartMenu(menu, obj)
29283000
end
29293001
end
29303002
end
2931-
main:AddOption("create submaterial zone togglers (hide/show materials)", function()
2932-
local mats = obj:GetOwner():GetMaterials()
2933-
local mats_str = table.concat(mats,"\n")
2934-
local dyn_props = obj:GetDynamicProperties()
2935-
Derma_StringRequest("submaterial togglers", "please input a submaterial name or a list of submaterial names with spaces\navailable materials:\n"..mats_str, "", function(str)
2936-
local event = pac.CreatePart("event") event:SetAffectChildrenOnly(true) event:SetEvent("command") event:SetArguments("materials_"..string.sub(obj.UniqueID,1,6))
2937-
local proxy = pac.CreatePart("proxy") proxy:SetAffectChildren(true) proxy:SetVariableName("no_draw") proxy:SetExpression("0") proxy:SetExpressionOnHide("1")
2938-
event:SetParent(obj) proxy:SetParent(event)
2939-
for i, kw in ipairs(string.Split(str, " ")) do
2940-
for id,mat2 in ipairs(mats) do
2941-
if string.GetFileFromFilename(mat2) == kw then
2942-
local mat = pac.CreatePart("material_3d") mat:SetParent(proxy)
2943-
mat:SetName("toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6))
2944-
mat:SetLoadVmt(mat2)
2945-
dyn_props[kw].set("toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6))
2946-
end
2947-
end
2948-
end
2949-
end)
2950-
end):SetIcon("icon16/picture_delete.png")
3003+
install_submaterial_options(main)
3004+
29513005
elseif obj.ClassName == "model2" then
29523006
local pm = pace.current_part:GetPlayerOwner():GetModel()
29533007
local pm_selected = player_manager.TranslatePlayerModel(GetConVar("cl_playermodel"):GetString())
@@ -2995,26 +3049,7 @@ function pace.AddQuickSetupsToPartMenu(menu, obj)
29953049
end
29963050
end
29973051

2998-
main:AddOption("create submaterial zone togglers (hide/show materials)", function()
2999-
local mats = obj:GetOwner():GetMaterials()
3000-
local mats_str = table.concat(mats,"\n")
3001-
local dyn_props = obj:GetDynamicProperties()
3002-
Derma_StringRequest("submaterial togglers", "please input a submaterial name or a list of submaterial names with spaces\navailable materials:\n"..mats_str, "", function(str)
3003-
local event = pac.CreatePart("event") event:SetAffectChildrenOnly(true) event:SetEvent("command") event:SetArguments("materials_"..string.sub(obj.UniqueID,1,6))
3004-
local proxy = pac.CreatePart("proxy") proxy:SetAffectChildren(true) proxy:SetVariableName("no_draw") proxy:SetExpression("0") proxy:SetExpressionOnHide("1")
3005-
event:SetParent(obj) proxy:SetParent(event)
3006-
for i, kw in ipairs(string.Split(str, " ")) do
3007-
for id,mat2 in ipairs(mats) do
3008-
if string.GetFileFromFilename(mat2) == kw then
3009-
local mat = pac.CreatePart("material_3d") mat:SetParent(proxy)
3010-
mat:SetName("toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6))
3011-
mat:SetLoadVmt(mat2)
3012-
dyn_props[kw].set("toggled_"..kw.."_"..string.sub(obj.UniqueID,1,6))
3013-
end
3014-
end
3015-
end
3016-
end)
3017-
end):SetIcon("icon16/picture_delete.png")
3052+
install_submaterial_options(main)
30183053

30193054
local collapses, pnl = main:AddSubMenu("bone collapsers") pnl:SetImage("icon16/compress.png")
30203055
collapses:AddOption("collapse arms", function()

0 commit comments

Comments
 (0)