Skip to content

Commit 99d8290

Browse files
committed
Remove old autogen menu terribleness
This all sucked. I was hoping for better feedback on it at the time and I never got it. It's a very small part of cruft I can remove to get started.
1 parent 6cf411c commit 99d8290

4 files changed

Lines changed: 86 additions & 181 deletions

File tree

lua/acf/core/classes/entities/registration.lua

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,6 @@ function NumberType.Validator(Ctx, Value)
124124
return Value
125125
end
126126

127-
function NumberType.CreateMenuItem(ACF_Panel, Ctx, Text)
128-
local Min, Max = Ctx:HasSpec("Min") and Ctx:GetSpec("Min") or nil, Ctx:HasSpec("Max") and Ctx:GetSpec("Max") or nil
129-
local Decimals = Ctx:HasSpec("Decimals") and Ctx:GetSpec("Decimals") or nil
130-
local Slider = ACF_Panel:AddSlider(Text, Min, Max, Decimals)
131-
132-
local VarName = Ctx.VarName
133-
134-
Slider:SetClientData(VarName, "OnValueChanged")
135-
Slider:DefineSetter(function(Panel, _, _, Value)
136-
if Decimals then
137-
Value = math.Round(Value, Decimals)
138-
end
139-
if Min then Value = math.max(Min, Value) end
140-
if Max then Value = math.min(Max, Value) end
141-
142-
Panel:SetValue(Value)
143-
if IsValid(ACF_Panel) then
144-
ACF_Panel:SendUserVarChangedSignal(Panel, VarName, Value)
145-
end
146-
147-
return Value
148-
end)
149-
150-
return Slider
151-
end
152-
153127
local StringType = Entities.AddUserArgumentType("String")
154128
function StringType.Validator(Ctx, Value)
155129
local Specs = Ctx:GetSpecs()
@@ -160,23 +134,6 @@ function StringType.Validator(Ctx, Value)
160134
return Value
161135
end
162136

163-
function StringType.CreateMenuItem(ACF_Panel, Ctx, Text)
164-
local TextBox = ACF_Panel:AddTextEntry(Text)
165-
local VarName = Ctx.VarName
166-
167-
TextBox:SetClientData(VarName, "OnChange")
168-
TextBox:DefineSetter(function(Panel, _, _, Value)
169-
Panel:SetValue(Value)
170-
if IsValid(ACF_Panel) then
171-
ACF_Panel:SendUserVarChangedSignal(Panel, VarName, Value)
172-
end
173-
174-
return Value
175-
end)
176-
177-
return TextBox
178-
end
179-
180137
local BooleanType = Entities.AddUserArgumentType("Boolean")
181138
function BooleanType.Validator(Ctx, Value)
182139
local Specs = Ctx:GetSpecs()
@@ -187,24 +144,6 @@ function BooleanType.Validator(Ctx, Value)
187144
return Value
188145
end
189146

190-
191-
function BooleanType.CreateMenuItem(ACF_Panel, Ctx, Text)
192-
local CheckBox = ACF_Panel:AddCheckBox(Text)
193-
local VarName = Ctx.VarName
194-
195-
CheckBox:SetClientData(VarName, "OnChange")
196-
CheckBox:DefineSetter(function(Panel, _, _, Value)
197-
Panel:SetValue(Value)
198-
if IsValid(ACF_Panel) then
199-
ACF_Panel:SendUserVarChangedSignal(Panel, VarName, Value)
200-
end
201-
202-
return Value
203-
end)
204-
205-
return CheckBox
206-
end
207-
208147
-- These should be removed in a future class rewrite
209148
local SimpleClassType = Entities.AddUserArgumentType("SimpleClass")
210149
function SimpleClassType.Validator(Ctx, Value)
@@ -228,38 +167,6 @@ function SimpleClassType.Getter(self, Ctx, Key)
228167
return ACF.Classes[Specs.ClassName].Get(Key)
229168
end
230169

231-
function SimpleClassType.CreateMenuItem(ACF_Panel, Ctx, _, NameKey, IconKey)
232-
local VarName = Ctx.VarName
233-
local Entries = ACF.Classes[Ctx:GetSpec("ClassName")].GetEntries()
234-
local List = ACF_Panel:AddComboBox()
235-
236-
function List:OnSelect(Index, _, Data)
237-
if self.Selected == Data then return end
238-
239-
self.ListData.Index = Index
240-
self.Selected = Data
241-
242-
if IsValid(ACF_Panel) then
243-
ACF_Panel:SendUserVarChangedSignal(self, VarName, Data)
244-
end
245-
246-
ACF.SetClientData(VarName, Data.ID)
247-
end
248-
249-
local Default = Ctx:GetSpec("Default")
250-
ACF_Panel:EnqueuePostBuildFn(function()
251-
ACF.LoadSortedList(List, Entries, NameKey or "Name", IconKey or "Icon")
252-
for K, Option in ipairs(List.Data) do
253-
if Option.ID == Default then
254-
List:ChooseOptionID(K)
255-
break
256-
end
257-
end
258-
end)
259-
260-
return List
261-
end
262-
263170
local GroupClassType = Entities.AddUserArgumentType("GroupClass")
264171
function GroupClassType.Validator(Ctx, Value)
265172
local Specs = Ctx:GetSpecs()
@@ -493,7 +400,6 @@ local function VerificationContext(Class)
493400
Restrictions = Entity.Restrictions
494401
}, VerificationContext_MT)
495402
end
496-
ACF.Classes.Entities.VerificationContext = VerificationContext
497403

498404
--[[
499405

lua/acf/menu/items_cl/baseplates.lua

Lines changed: 86 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,112 @@ local function CreateMenu(Menu)
66
ACF.SetClientData("PrimaryClass", "acf_baseplate")
77
ACF.SetClientData("SecondaryClass", "N/A")
88

9-
local VerificationCtx = ACF.Classes.Entities.VerificationContext("acf_baseplate")
10-
VerificationCtx:StartClientData(ACF.GetAllClientData(true))
11-
129
Menu:AddTitle("#acf.menu.baseplates.settings")
1310

1411
Menu:AddWikiLink("Baseplates", "docs/getting_started/first_tank/baseplate_aio.html")
1512

1613
Menu:AddLabel("#acf.menu.baseplates.desc")
1714

18-
Menu:AddSimpleClassUserVar(VerificationCtx, "", "BaseplateType", "Name", "Icon")
19-
local SizeX = Menu:AddNumberUserVar( VerificationCtx, "#acf.menu.baseplates.plate_width", "Width")
20-
local SizeY = Menu:AddNumberUserVar( VerificationCtx, "#acf.menu.baseplates.plate_length", "Length")
21-
local SizeZ = Menu:AddNumberUserVar( VerificationCtx, "#acf.menu.baseplates.plate_thickness", "Thickness")
22-
Menu:AddBooleanUserVar( VerificationCtx, "#acf.menu.baseplates.disable_alt_e", "DisableAltE")
23-
local ExplodeCollide = Menu:AddBooleanUserVar( VerificationCtx, "#acf.menu.baseplates.explode_on_collisions", "ExplodeOnCollisions")
24-
local ExplodeCollideInfo = Menu:AddHelp("#acf.menu.baseplates.explode_on_collisions_info")
25-
local GForceTicks = Menu:AddNumberUserVar( VerificationCtx, "#acf.menu.baseplates.gforce_ticks", "GForceTicks")
26-
local GForceTicksInfo = Menu:AddHelp("#acf.menu.baseplates.gforce_ticks_info")
15+
local ClassList = Menu:AddComboBox()
16+
17+
-- Set default baseplate size values before creating sliders to prevent nil value errors
18+
local DefaultWidth = ACF.GetClientNumber("Width", 36)
19+
local DefaultLength = ACF.GetClientNumber("Length", 36)
20+
local DefaultThickness = ACF.GetClientNumber("Thickness", 1.5)
21+
local DefaultGForceTicks = ACF.GetClientNumber("GForceTicks", 4)
22+
23+
ACF.SetClientData("Width", DefaultWidth, true)
24+
ACF.SetClientData("Length", DefaultLength, true)
25+
ACF.SetClientData("Thickness", DefaultThickness, true)
26+
ACF.SetClientData("GForceTicks", DefaultGForceTicks, true)
27+
28+
local SizeX = Menu:AddSlider("#acf.menu.baseplates.plate_width", 36, 240, 2)
29+
local SizeY = Menu:AddSlider("#acf.menu.baseplates.plate_length", 36, 420, 2)
30+
local SizeZ = Menu:AddSlider("#acf.menu.baseplates.plate_thickness", 0.5, 3, 2)
31+
local DisableAltE = Menu:AddCheckBox("#acf.menu.baseplates.disable_alt_e")
32+
local ExplodeCollide = Menu:AddCheckBox("#acf.menu.baseplates.explode_on_collisions")
33+
local ExplodeCollideInfo = Menu:AddHelp("#acf.menu.baseplates.explode_on_collisions_info")
34+
local GForceTicks = Menu:AddSlider("#acf.menu.baseplates.gforce_ticks", 1, 7, 0)
35+
local GForceTicksInfo = Menu:AddHelp("#acf.menu.baseplates.gforce_ticks_info")
2736

2837
local BaseplateBase = Menu:AddCollapsible("#acf.menu.baseplates.baseplate_info", nil, "icon16/shape_square_edit.png")
2938
local BaseplateName = BaseplateBase:AddTitle()
3039
local BaseplateDesc = BaseplateBase:AddLabel()
3140

41+
function ClassList:OnSelect(Index, _, Data)
42+
if self.Selected == Data then return end
43+
44+
self.ListData.Index = Index
45+
self.Selected = Data
46+
47+
BaseplateName:SetText(Data.Name)
48+
BaseplateDesc:SetText(Data.Description)
49+
50+
local IsAircraft = Data.ID == "Aircraft"
51+
local IsRecreational = Data.ID == "Recreational"
52+
53+
ExplodeCollide:SetVisible(IsRecreational)
54+
ExplodeCollideInfo:SetVisible(IsRecreational)
55+
GForceTicks:SetVisible(IsAircraft)
56+
GForceTicksInfo:SetVisible(IsAircraft)
57+
58+
ACF.SetClientData("BaseplateType", Data.ID)
59+
end
60+
3261
local PreviewSettings = {
3362
FOV = 120,
3463
Height = 120,
3564
AngOffset = Angle(0, -90, 0),
3665
}
66+
3767
local BaseplatePreview = BaseplateBase:AddModelPreview("models/holograms/cube.mdl", true, "Primary")
3868
BaseplatePreview:UpdateSettings(PreviewSettings)
3969
BaseplatePreview:UpdateModel("models/holograms/cube.mdl", "hunter/myplastic")
4070

41-
BaseplateName.ACF_OnUpdate = function(self, KeyChanged, _, Value) if KeyChanged == "BaseplateType" then self:SetText(Value.Name) end end
42-
BaseplateDesc.ACF_OnUpdate = function(self, KeyChanged, _, Value) if KeyChanged == "BaseplateType" then self:SetText(Value.Description) end end
43-
44-
ExplodeCollide.ACF_OnUpdate = function(self, KeyChanged, _, Value)
45-
if KeyChanged == "BaseplateType" then
46-
self:SetVisible(Value == BaseplateTypes.Get("Recreational"))
47-
self:GetParent():InvalidateLayout()
48-
end
49-
end
50-
ExplodeCollideInfo.ACF_OnUpdate = ExplodeCollide.ACF_OnUpdate
51-
52-
GForceTicks.ACF_OnUpdate = function(self, KeyChanged, _, Value)
53-
if KeyChanged == "BaseplateType" then
54-
self:SetVisible(Value == BaseplateTypes.Get("Aircraft"))
55-
self:GetParent():InvalidateLayout()
56-
end
57-
end
58-
GForceTicksInfo.ACF_OnUpdate = GForceTicks.ACF_OnUpdate
59-
6071
local function UpdatePreviewSize()
6172
local X, Y, Z = SizeX:GetValue(), SizeY:GetValue(), SizeZ:GetValue()
6273
BaseplatePreview:SetModelScale(Vector(Y, X, Z)) -- Yes, X and Y are swapped on purpose...
6374
end
64-
local function ProducerSelfUpdate(Self, _, Producer) if Self == Producer then UpdatePreviewSize() end end
65-
SizeX.ACF_OnUpdate = ProducerSelfUpdate
66-
SizeY.ACF_OnUpdate = ProducerSelfUpdate
67-
SizeZ.ACF_OnUpdate = ProducerSelfUpdate
75+
76+
SizeX:SetClientData("Width", "OnValueChanged")
77+
SizeX:DefineSetter(function(Panel, _, _, Value)
78+
local X = math.Round(Value, 2)
79+
80+
Panel:SetValue(X)
81+
UpdatePreviewSize()
82+
return X
83+
end)
84+
85+
SizeY:SetClientData("Length", "OnValueChanged")
86+
SizeY:DefineSetter(function(Panel, _, _, Value)
87+
local Y = math.Round(Value, 2)
88+
89+
Panel:SetValue(Y)
90+
UpdatePreviewSize()
91+
return Y
92+
end)
93+
94+
SizeZ:SetClientData("Thickness", "OnValueChanged")
95+
SizeZ:DefineSetter(function(Panel, _, _, Value)
96+
local Z = math.Round(Value, 2)
97+
98+
Panel:SetValue(Z)
99+
UpdatePreviewSize()
100+
return Z
101+
end)
102+
103+
GForceTicks:SetClientData("GForceTicks", "OnValueChanged")
104+
GForceTicks:DefineSetter(function(Panel, _, _, Value)
105+
local Ticks = math.Round(Value, 0)
106+
107+
Panel:SetValue(Ticks)
108+
109+
return Ticks
110+
end)
111+
112+
DisableAltE:SetClientData("DisableAltE", "OnChange")
113+
ExplodeCollide:SetClientData("ExplodeOnCollisions", "OnChange")
114+
68115
UpdatePreviewSize()
69116

70117
local BaseplateConvertInfo = Menu:AddCollapsible("#acf.menu.baseplates.convert")
@@ -73,6 +120,10 @@ local function CreateMenu(Menu)
73120
BaseplateConvertText = BaseplateConvertText .. language.GetPhrase("acf.menu.baseplates.convert_info" .. I)
74121
end
75122
BaseplateConvertInfo:AddLabel(BaseplateConvertText)
123+
124+
local Entries = BaseplateTypes.GetEntries()
125+
ACF.LoadSortedList(ClassList, Entries, "Name", "Icon")
126+
ClassList:ChooseOptionID(2)
76127
end
77128

78129
ACF.AddMenuItem(50, "#acf.menu.entities", "#acf.menu.baseplates", "shape_square", CreateMenu)

lua/acf/menu/spawn_menu_cl.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,13 @@ do -- ACF Menu context panel
277277
ACF.SetToolMode("acf_menu", "Main", "Idle")
278278
ACF.SetClientData("Destiny")
279279

280-
Menu:ClearPostBuildFns()
281280
Menu:ClearTemporal()
282281
Menu:StartTemporal()
283282

284283
-- Fixes menu errors just killing everything
285284
xpcall(function() Node.Action(Menu) end, function(err) ErrorNoHaltWithStack(err) end)
286285

287286
Menu:EndTemporal()
288-
Menu:ExecutePostBuildFns()
289287
end
290288

291289
PopulateTree(Tree)

lua/vgui/acf_panel.lua

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,54 +1242,4 @@ function PANEL:AddTable(Width, Height, BorderColor, BorderWidth)
12421242
return TablePanel
12431243
end
12441244

1245-
for TypeName, TypeDef in ACF.Classes.Entities.IterateTypes() do
1246-
if TypeDef.CreateMenuItem then
1247-
PANEL["Add" .. TypeName .. "UserVar"] = function(self, Ctx, Text, VarName, ...)
1248-
Ctx:SetCurrentVar(VarName) -- Initialize the variable for the validation context now so
1249-
-- the specs calls just work in CreateMenuItem. If the consumer wants VarName, it's available
1250-
-- in the context...
1251-
local Panel = TypeDef.CreateMenuItem(self, Ctx, Text, ...)
1252-
return Panel
1253-
end
1254-
else
1255-
PANEL["Add" .. TypeName .. "UserVar"] = function() error("ACF auto-register type '" .. TypeName .. "' does not contain a CreateMenuItem method") end
1256-
end
1257-
end
1258-
1259-
-- Called after a menu item has been fully built (ie. something in menu/items_cl)
1260-
-- Was designed because class views wait until all elements are available, but I'm trying to flesh
1261-
-- out a less annoying API with autoregister
1262-
function PANEL:EnqueuePostBuildFn(PostBuildFn)
1263-
if not self.PostBuildFnQueue then
1264-
self.PostBuildFnQueue = {PostBuildFn}
1265-
else
1266-
self.PostBuildFnQueue[#self.PostBuildFnQueue + 1] = PostBuildFn
1267-
end
1268-
end
1269-
1270-
function PANEL:ClearPostBuildFns()
1271-
self.PostBuildFnQueue = nil
1272-
end
1273-
1274-
function PANEL:ExecutePostBuildFns()
1275-
local Enqueued = self.PostBuildFnQueue
1276-
if not Enqueued then return end
1277-
for _, Fn in ipairs(Enqueued) do
1278-
Fn(self)
1279-
end
1280-
self:ClearPostBuildFns()
1281-
end
1282-
1283-
function PANEL:SendUserVarChangedSignal(Producer, KeyChanged, Value)
1284-
if self == Producer and self.ACF_OnUpdate then
1285-
self:ACF_OnUpdate(KeyChanged, Producer, Value)
1286-
end
1287-
for _, Panel in ipairs(self:GetChildren()) do
1288-
if Panel ~= Producer and Panel.ACF_OnUpdate then
1289-
Panel.ACF_OnUpdate(Panel, KeyChanged, Producer, Value)
1290-
end
1291-
PANEL.SendUserVarChangedSignal(Panel, Producer, KeyChanged, Value)
1292-
end
1293-
end
1294-
12951245
derma.DefineControl("ACF_Panel", "", PANEL, "Panel")

0 commit comments

Comments
 (0)