Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.23 KB | None | 0 0
  1. local SpawnList = {}
  2.  
  3. SpawnList = BaseWars.SpawnList
  4. local grenTimeNew = CurTime() + 30
  5.  
  6. local function LimitDeduct(self, ent, ply)
  7.  
  8.     self.o_OnRemove = self.OnRemove
  9.  
  10.     self.OnRemove = function(e)
  11.  
  12.         local ply = BaseWars.Ents:ValidPlayer(ply)
  13.  
  14.         if ply then
  15.             ply:GetTable()["limit_" .. ent] = ply:GetTable()["limit_" .. ent] - 1
  16.         end
  17.  
  18.         e:o_OnRemove()
  19.     end
  20.  
  21.     ply:GetTable()["limit_" .. ent] = ply:GetTable()["limit_" .. ent] + 1
  22.  
  23. end
  24.  
  25. if SERVER then
  26.  
  27.     local function Spawn(ply, cat, subcat, item)
  28.  
  29.         if ply.IsBanned and ply:IsBanned() then return end
  30.  
  31.         if not ply:Alive() then ply:Notify(BaseWars.LANG.DeadBuy, BASEWARS_NOTIFICATION_ERROR) return end
  32.  
  33.         local l = SpawnList and SpawnList
  34.  
  35.         if not l then return end
  36.  
  37.         if not cat or not item then return end
  38.  
  39.         local i = l[cat]
  40.  
  41.         if not i then return end
  42.  
  43.         i = i[subcat]
  44.  
  45.         if not i then return end
  46.  
  47.         i = i[item]
  48.  
  49.         if not i then return end
  50.  
  51.         local model, price, ent, sf, lim = i.Model, i.Price, i.ClassName, i.UseSpawnFunc, i.Limit
  52.         local gun, drug, ammo, ignore_raid = i.Gun, i.Drug, i.Ammo, i.IgnoreRaid
  53.  
  54.         local vip = i.VIP
  55.         local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, ply:GetUserGroup()) or ply:IsAdmin())
  56.  
  57.         local level = i.Level
  58.         if gun and (not level or level < BaseWars.Config.LevelSettings.BuyWeapons) then level = BaseWars.Config.LevelSettings.BuyWeapons end
  59.  
  60.         if (level and not ply:HasLevel(level)) or (vip and not HasVIP) then
  61.  
  62.             ply:EmitSound("buttons/button10.wav")
  63.  
  64.         return end
  65.  
  66.         local tr
  67.  
  68.         if ent then
  69.  
  70.             tr = {}
  71.  
  72.             tr.start = ply:EyePos()
  73.             tr.endpos = tr.start + ply:GetAimVector() * 85
  74.             tr.filter = ply
  75.  
  76.             tr = util.TraceLine(tr)
  77.  
  78.         else
  79.  
  80.             tr = ply:GetEyeTraceNoCursor()
  81.  
  82.             if not tr.Hit then return end
  83.  
  84.         end
  85.  
  86.         local SpawnPos = tr.HitPos + BaseWars.Config.SpawnOffset
  87.         local SpawnAng = ply:EyeAngles()
  88.         SpawnAng.p = 0
  89.         SpawnAng.y = SpawnAng.y + 180
  90.         SpawnAng.y = math.Round(SpawnAng.y / 45) * 45
  91.  
  92.         if not gun and not drug and not ignore_raid and not ammo and ply:InRaid() then
  93.  
  94.             ply:Notify(BaseWars.LANG.CannotPurchaseRaid, BASEWARS_NOTIFICATION_ERROR)
  95.  
  96.         return end
  97.        
  98.         if string.match(ent, "cw_flash_grenade") or string.match(ent, "cw_frag_grenade") or string.match(ent, "cw_smoke_grenade") then
  99.             if CurTime() < grenTimeNew then
  100.                 ply:Notify("You may purchase a grenade in " .. math.Round(grenTimeNew - CurTime()) .. " seconds.", BASEWARS_NOTIFICATION_ERROR)
  101.                 return false
  102.             else
  103.                 grenTimeNew = CurTime() + 30
  104.                 return true
  105.             end
  106.         end
  107.    
  108.        
  109.  
  110.         if ent and not ply:InRaid() then
  111.             if string.match(ent, "bw_weapon_c4") or string.match(ent, "bw_explosive_nuke") or string.match(ent, "bw_explosive_bigbomb") then
  112.                 ply:Notify("You cannot purchase these unless you're in an active raid!", BASEWARS_NOTIFICATION_ERROR)
  113.             return end
  114.         end
  115.  
  116.         if lim then
  117.  
  118.             local Amount = ply:GetTable()["limit_" .. ent] or 0
  119.             ply:GetTable()["limit_" .. ent] = Amount
  120.  
  121.             if lim and lim <= Amount then
  122.  
  123.                 ply:Notify(string.format(BaseWars.LANG.EntLimitReached, ent), BASEWARS_NOTIFICATION_ERROR)
  124.  
  125.             return end
  126.  
  127.         end
  128.  
  129.         local Res, Msg
  130.         if gun then
  131.  
  132.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyGun", ply, ent) -- Player, Gun class
  133.  
  134.         elseif drug then
  135.  
  136.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyDrug", ply, ent) -- Player, Drug type
  137.  
  138.         elseif ent then
  139.  
  140.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyEntity", ply, ent) -- Player, Entity class
  141.  
  142.         else
  143.  
  144.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyProp", ply, ent) -- Player, Entity class
  145.  
  146.         end
  147.  
  148.         if Res == false then
  149.  
  150.             if Msg then
  151.  
  152.                 ply:Notify(Msg, BASEWARS_NOTIFICATION_ERROR)
  153.  
  154.             end
  155.  
  156.         return end
  157.  
  158.         if price > 0 then
  159.  
  160.             local plyMoney = ply:GetMoney()
  161.  
  162.             if plyMoney < price then
  163.  
  164.                 ply:Notify(BaseWars.LANG.SpawnMenuMoney, BASEWARS_NOTIFICATION_ERROR)
  165.  
  166.             return end
  167.  
  168.             ply:SetMoney(plyMoney - price)
  169.             ply:EmitSound("mvm/mvm_money_pickup.wav")
  170.  
  171.             ply:Notify(string.format(BaseWars.LANG.SpawnMenuBuy, item, BaseWars.NumberFormat(price)), BASEWARS_NOTIFICATION_MONEY)
  172.  
  173.         end
  174.  
  175.         if gun then
  176.  
  177.             local Ent = ents.Create("bw_weapon")
  178.                 Ent.WeaponClass = ent
  179.                 Ent.Model = model
  180.                 Ent:SetPos(SpawnPos)
  181.                 Ent:SetAngles(SpawnAng)
  182.             Ent:Spawn()
  183.             Ent:Activate()
  184.             Ent:CPPISetOwner(ply)
  185.  
  186.             hook.Run("BaseWars_PlayerBuyGun", ply, Ent) -- Player, Gun entity
  187.  
  188.         return end
  189.  
  190.         if drug then
  191.  
  192.             local Rand = (ent == "Random")
  193.             local Ent = ents.Create("bw_drink_drug")
  194.                 if not Rand then
  195.  
  196.                     Ent:SetDrugEffect(ent)
  197.                     Ent.Random = false
  198.  
  199.                 end
  200.  
  201.                 Ent:SetPos(SpawnPos)
  202.                 Ent:SetAngles(SpawnAng)
  203.             Ent:Spawn()
  204.             Ent:Activate()
  205.             Ent:CPPISetOwner(ply)
  206.  
  207.             hook.Run("BaseWars_PlayerBuyDrug", ply, Ent) -- Player, Drug entity
  208.  
  209.         return end
  210.  
  211.         local prop
  212.         local noundo
  213.  
  214.         if ent then
  215.  
  216.             local newEnt = ents.Create(ent)
  217.  
  218.             if not newEnt then return end
  219.  
  220.             if newEnt.SpawnFunction and sf then
  221.  
  222.                 newEnt = newEnt:SpawnFunction(ply, tr, ent)
  223.  
  224.                 if newEnt.CPPISetOwner then
  225.  
  226.                     newEnt:CPPISetOwner(ply)
  227.  
  228.                 end
  229.  
  230.                 if newEnt.SetCreator then
  231.  
  232.                     newEnt:SetCreator(ply)
  233.  
  234.                 end
  235.  
  236.                 if lim then
  237.  
  238.                     LimitDeduct(newEnt, ent, ply)
  239.  
  240.                 end
  241.  
  242.                 newEnt.CurrentValue = price
  243.                 if newEnt.SetUpgradeCost then newEnt:SetUpgradeCost(price) end
  244.  
  245.                 newEnt.DoNotDuplicate = true
  246.  
  247.                 hook.Run("BaseWars_PlayerBuyEntity", ply, newEnt) -- Player, Entity
  248.  
  249.             return end
  250.  
  251.             if lim then
  252.  
  253.                 LimitDeduct(newEnt, ent, ply)
  254.  
  255.             end
  256.  
  257.             newEnt.CurrentValue = price
  258.             if newEnt.SetUpgradeCost then newEnt:SetUpgradeCost(price) end
  259.  
  260.             newEnt.DoNotDuplicate = true
  261.  
  262.             prop = newEnt
  263.             noundo = true
  264.  
  265.         end
  266.  
  267.         if not prop then prop = ents.Create(ent or "prop_physics") end
  268.         if not noundo then undo.Create("prop") end
  269.  
  270.         if not prop or not IsValid(prop) then return end
  271.  
  272.         prop:SetPos(SpawnPos)
  273.         prop:SetAngles(SpawnAng)
  274.  
  275.         if model and not ent then
  276.  
  277.             prop:SetModel(model)
  278.  
  279.         end
  280.  
  281.         if lim and not ent then
  282.  
  283.             LimitDeduct(prop, ent, ply)
  284.  
  285.         end
  286.  
  287.         local vname = i.VehicleName
  288.         local vt = list.Get("Vehicles")[vname]
  289.  
  290.         if vname and vt then
  291.             if prop.SetVehicleClass then prop:SetVehicleClass(vname) end
  292.  
  293.             prop.VehicleTable = vt
  294.             prop.ClassOverride = vt.Class
  295.             prop.VehicleName = vname
  296.  
  297.             if vt.KeyValues then
  298.                 for k, v in pairs(vt.KeyValues) do
  299.                     prop:SetKeyValue(k, v)
  300.                 end
  301.             end
  302.  
  303.             if vt.Members then
  304.                 table.Merge(prop, vt.Members)
  305.             end
  306.  
  307.             if vt.Model then
  308.                 prop:SetModel(vt.Model)
  309.             end
  310.         end
  311.  
  312.         prop:Spawn()
  313.         prop:Activate()
  314.  
  315.         if vname and vt then
  316.             hook.Run("PlayerSpawnedVehicle", ply, prop)
  317.         end
  318.  
  319.         prop:DropToFloor()
  320.  
  321.         local phys = prop:GetPhysicsObject()
  322.  
  323.         if IsValid(phys) then
  324.  
  325.             if i.ShouldFreeze then
  326.  
  327.                 phys:EnableMotion(false)
  328.  
  329.             else
  330.  
  331.                 phys:Wake()
  332.  
  333.             end
  334.  
  335.         end
  336.  
  337.         undo.AddEntity(prop)
  338.         undo.SetPlayer(ply)
  339.         undo.Finish()
  340.  
  341.         if prop.CPPISetOwner then
  342.  
  343.             prop:CPPISetOwner(ply)
  344.  
  345.         end
  346.  
  347.         if ent then
  348.  
  349.             hook.Run("BaseWars_PlayerBuyEntity", ply, prop) -- Player, Entity
  350.  
  351.         else
  352.  
  353.             hook.Run("BaseWars_PlayerBuyProp", ply, prop) -- Player, Prop
  354.  
  355.         end
  356.  
  357.     end
  358.  
  359.     concommand.Add("basewars_spawn",function(ply,_,args)
  360.  
  361.         if not IsValid(ply) then return end
  362.         Spawn(ply, args[1], args[2], args[3], args[4])
  363.  
  364.     end)
  365.  
  366.     local function Disallow_Spawning(ply, ...)
  367.  
  368.         --BaseWars.UTIL.Log(ply, ...)
  369.  
  370.         if not ply:IsAdmin()  then
  371.  
  372.             ply:Notify(BaseWars.LANG.UseSpawnMenu, BASEWARS_NOTIFICATION_ERROR)
  373.             return false
  374.  
  375.         end
  376.  
  377.     end
  378.  
  379.     local name = "BaseWars.Disallow_Spawning"
  380.  
  381.     if BaseWars.Config.RestrictProps then
  382.  
  383.         hook.Add("PlayerSpawnObject",   name, Disallow_Spawning)
  384.  
  385.     end
  386.  
  387.     hook.Add("PlayerSpawnSENT",         name, Disallow_Spawning)
  388.     hook.Add("PlayerGiveSWEP",          name, Disallow_Spawning)
  389.     hook.Add("PlayerSpawnSWEP",         name, Disallow_Spawning)
  390.     hook.Add("PlayerSpawnVehicle",  name, Disallow_Spawning)
  391.     hook.Add("PlayerSpawnNPC",          name, Disallow_Spawning)
  392.  
  393. return end
  394.  
  395. local overlayFont = "BaseWars.SpawnList.Overlay"
  396. surface.CreateFont(overlayFont,{
  397.  
  398.     font = "Roboto",
  399.     size = BaseWars.Config.PricesSize,
  400.     weight = 900,
  401.  
  402. })
  403.  
  404. local overlayFont2 = "BaseWars.SpawnList.Overlay.Small"
  405. surface.CreateFont(overlayFont2,{
  406.  
  407.     font = "Roboto",
  408.     size = 12,
  409.     weight = 800,
  410.  
  411. })
  412.  
  413. local PANEL = {}
  414.  
  415. function PANEL:Init()
  416.  
  417.     self.Panels = {}
  418.  
  419. end
  420.  
  421. function PANEL:AddPanel(name,pnl)
  422.  
  423.     self.Panels[name] = pnl
  424.  
  425.     if not self.CurrentPanel then
  426.  
  427.         pnl:Show()
  428.         self.CurrentPanel = pnl
  429.  
  430.     else
  431.  
  432.         pnl:Hide()
  433.  
  434.     end
  435.  
  436. end
  437.  
  438. function PANEL:SwitchTo(name,instant)
  439.  
  440.     local pnl = self.Panels[name]
  441.  
  442.     if not pnl then return end
  443.  
  444.     local oldpnl = self.CurrentPanel
  445.  
  446.     if pnl == oldpnl then return end
  447.  
  448.     if oldpnl then
  449.  
  450.         oldpnl:AlphaTo(0, instant and 0 or 0.2, 0, function(_,pnl) pnl:Hide() end)
  451.  
  452.     end
  453.  
  454.     pnl:Show()
  455.     pnl:AlphaTo(255, instant and 0 or 0.2, 0, function() end)
  456.  
  457.     self.CurrentPanel = pnl
  458.  
  459. end
  460.  
  461. vgui.Register("BaseWars.PanelCollection", PANEL, "Panel")
  462.  
  463. local PANEL = {}
  464.  
  465. local white = Color(255, 255, 255)
  466. local gray = Color(192, 192, 192)
  467. local black = Color(0, 0, 0)
  468. local errorcolor = Color(255, 100, 100)
  469. local highlight = Color(100, 100, 100, 200)
  470. local orange = Color (255, 165, 0, 200)
  471.  
  472. function PANEL:CheckError()
  473.  
  474.     return false
  475.  
  476. end
  477.  
  478. function PANEL:Paint(w, h)
  479.  
  480.     draw.RoundedBox(4, 0, 0, w, h, black)
  481.     draw.RoundedBox(4, 1, 1, w - 2, h - 2, self:CheckError() and errorcolor or white)
  482.  
  483.     self:DrawTextEntryText(black, highlight, gray)
  484.  
  485.     return false
  486.  
  487. end
  488.  
  489. vgui.Register("BaseWars.ErrorCheckTextEntry", PANEL, "DTextEntry")
  490.  
  491. local white = Color(255, 255, 255)
  492. local trans = Color(0, 0, 0, 0)
  493.  
  494. local blue  = Color(0, 90, 200, 180)
  495. local green = Color(90, 200, 0, 180)
  496. local grey  = Color(90, 90, 90, 180)
  497. local red   = Color(200, 0, 20, 180)
  498.  
  499. local shade = Color(0, 0, 0, 200)
  500.  
  501. local SpawnList = BaseWars.SpawnList
  502.  
  503. if not SpawnList then return end
  504.  
  505. local Models = SpawnList
  506.  
  507. local enable_popup = CreateClientConVar("bw_enable_popup", "1", true, false)
  508.  
  509. local function MakeTab(type)
  510.     return function(pnl)
  511.  
  512.         local cats = pnl:Add("DCategoryList")
  513.  
  514.         cats:Dock(FILL)
  515.  
  516.         function cats:Paint() end
  517.  
  518.         for catName, subT in SortedPairs(Models[type]) do
  519.  
  520.             if catName == "__inf" then continue end
  521.  
  522.             local cat = cats:Add(catName)
  523.  
  524.             local iLayout = vgui.Create("DIconLayout")
  525.  
  526.             iLayout:Dock(FILL)
  527.  
  528.             iLayout:SetSpaceX(4)
  529.             iLayout:SetSpaceY(4)
  530.  
  531.             for name, tab in SortedPairsByMemberValue(subT, "Price") do
  532.  
  533.                 local model = tab.Model
  534.                 local money = tab.Price
  535.                 local level = tab.Level
  536.                 local vip = tab.VIP
  537.  
  538.                 if tab.Gun and (not level or level < BaseWars.Config.LevelSettings.BuyWeapons) then level = BaseWars.Config.LevelSettings.BuyWeapons end
  539.  
  540.                 local icon = iLayout:Add("SpawnIcon")
  541.  
  542.                 icon:SetModel(model)
  543.                 icon:SetTooltip(name .. (money > 0 and " (" .. string.format(BaseWars.LANG.CURFORMER, BaseWars.NumberFormat(money)) .. ")" or ""))
  544.  
  545.                 local is = BaseWars.Config.IconSize
  546.                 icon:SetSize(is, is)
  547.  
  548.                 function icon:DoClick()
  549.  
  550.                     local HasLevel = not level or LocalPlayer():HasLevel(level)
  551.                     local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, LocalPlayer():GetUserGroup()) or LocalPlayer():IsAdmin())
  552.                     if not HasLevel or not HasVIP then
  553.  
  554.                         surface.PlaySound("buttons/button10.wav")
  555.  
  556.                     return end
  557.  
  558.                     local myMoney = LocalPlayer():GetMoney()
  559.  
  560.                     surface.PlaySound("ui/buttonclickrelease.wav")
  561.  
  562.                     local a1, a2, a3 = type, catName, name
  563.  
  564.                     local function DoIt()
  565.  
  566.                         RunConsoleCommand("basewars_spawn", type, catName, name)
  567.  
  568.                     end
  569.  
  570.                     if (money > 0) and not (myMoney / 100 > money) then
  571.  
  572.                         if myMoney < money then
  573.  
  574.                             Derma_Message(BaseWars.LANG.SpawnMenuMoney, "Error")
  575.  
  576.                         return end
  577.  
  578.                         if enable_popup:GetBool() then
  579.                             Derma_Query(string.format(BaseWars.LANG.SpawnMenuBuyConfirm, name, BaseWars.NumberFormat(money)),
  580.                                 BaseWars.LANG.SpawnMenuConf, "   " .. BaseWars.LANG.Yes .. "   ", DoIt, "   " .. BaseWars.LANG.No .. "   ")
  581.                         else
  582.                             DoIt()
  583.                         end
  584.  
  585.                     else
  586.  
  587.                         DoIt()
  588.  
  589.                     end
  590.  
  591.  
  592.                 end
  593.  
  594.                 function icon:Paint(w, h)
  595.  
  596.                     local myMoney = LocalPlayer():GetMoney()
  597.                     local HasLevel = not level or LocalPlayer():HasLevel(level)
  598.                     local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, LocalPlayer():GetUserGroup()) or LocalPlayer():IsAdmin())
  599.  
  600.                     local DrawCol = green
  601.  
  602.                     if not HasVIP then
  603.  
  604.                         DrawCol = orange
  605.  
  606.                     elseif not HasLevel then
  607.  
  608.                         DrawCol = grey
  609.  
  610.                     elseif money <= 0 then
  611.  
  612.                         DrawCol = trans
  613.  
  614.                     elseif money >= myMoney * 2 then
  615.  
  616.                         DrawCol = grey
  617.  
  618.                     elseif money > myMoney then
  619.  
  620.                         DrawCol = red
  621.  
  622.                     elseif money < myMoney / 100 then
  623.  
  624.                         DrawCol = blue
  625.  
  626.                     end
  627.  
  628.                     draw.RoundedBox(4, 1, 1, w - 2, h - 2, DrawCol)
  629.  
  630.                 end
  631.  
  632.                 --local pO = icon.PaintOver
  633.  
  634.                 function icon:PaintOver(w, h)
  635.  
  636.                     --pO(self, w, h)
  637.  
  638.                     local text
  639.  
  640.                     local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, LocalPlayer():GetUserGroup()) or LocalPlayer():IsAdmin())
  641.                     if not HasVIP then
  642.  
  643.                         text = "VIP ONLY"
  644.  
  645.                         draw.DrawText(text, overlayFont2, w / 2, h / 2, shade, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  646.                         draw.DrawText(text, overlayFont2, w / 2 - 2, h / 2 - 2, white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  647.  
  648.                     return end
  649.  
  650.                     local HasLevel = not level or LocalPlayer():HasLevel(level)
  651.                     if not HasLevel then
  652.  
  653.                         text = "LVL " .. level
  654.  
  655.                         draw.DrawText(text, overlayFont2, w / 2, h / 2, shade, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  656.                         draw.DrawText(text, overlayFont2, w / 2 - 2, h / 2 - 2, white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  657.  
  658.                     return end
  659.  
  660.                     if money > 0 then
  661.  
  662.                         text = string.format(BaseWars.LANG.CURFORMER, BaseWars.NumberFormat(money))
  663.  
  664.                         draw.DrawText(text, overlayFont, w - 2, h - 14, shade, TEXT_ALIGN_RIGHT)
  665.                         draw.DrawText(text, overlayFont, w - 4, h - 16, white, TEXT_ALIGN_RIGHT)
  666.  
  667.                     end
  668.  
  669.                     text = (utf8.sub and utf8.sub(name, 1, 11) or string.sub(name, 1, 11)) .. ((utf8.len and utf8.len(name) or string.len(name)) <= 11 and "" or "...")
  670.  
  671.                     draw.DrawText(text, overlayFont2, 4, 4, shade, TEXT_ALIGN_LEFT)
  672.                     draw.DrawText(text, overlayFont2, 2, 2, white, TEXT_ALIGN_LEFT)
  673.  
  674.                 end
  675.  
  676.             end
  677.  
  678.             cat:SetContents(iLayout)
  679.             cat:SetExpanded(true)
  680.  
  681.         end
  682.  
  683.     end
  684.  
  685. end
  686.  
  687. local Panels = {
  688.  
  689.     Default = function(pnl)
  690.  
  691.         local lbl = pnl:Add("ContentHeader")
  692.  
  693.         lbl:SetPos(16, 0)
  694.  
  695.         lbl:SetText(BaseWars.LANG.BaseWarsSpawnlist)
  696.  
  697.         local lbl = pnl:Add("DLabel")
  698.  
  699.         lbl:SetPos(16, 64)
  700.  
  701.         lbl:SetFont("DermaLarge")
  702.         lbl:SetText(BaseWars.LANG.CategoryLeft)
  703.  
  704.         lbl:SetBright(true)
  705.  
  706.         lbl:SizeToContents()
  707.  
  708.     end,
  709.  
  710. }
  711.  
  712. local function MakeSpawnList()
  713.  
  714.     local pnl = vgui.Create("DPanel")
  715.  
  716.     function pnl:Paint(w,h) end
  717.  
  718.     local leftPanel = pnl:Add("DPanel")
  719.  
  720.     leftPanel:Dock(LEFT)
  721.     leftPanel:SetWide(256 - 64)
  722.     leftPanel:DockPadding(1, 1, 1, 1)
  723.  
  724.     local tree = leftPanel:Add("DTree")
  725.  
  726.     function tree:Paint() end
  727.  
  728.     tree:Dock(FILL)
  729.  
  730.     local rightPanel = pnl:Add("BaseWars.PanelCollection")
  731.  
  732.     rightPanel:Dock(FILL)
  733.  
  734.     rightPanel:SetMouseInputEnabled(true)
  735.     rightPanel:SetKeyboardInputEnabled(true)
  736.  
  737.     local defaultNode = tree:AddNode(BaseWars.LANG.BaseWarsSpawnlist)
  738.  
  739.     function defaultNode:OnNodeSelected()
  740.  
  741.         rightPanel:SwitchTo("Default")
  742.  
  743.     end
  744.  
  745.     defaultNode:SetIcon("icon16/application_view_tile.png")
  746.  
  747.     defaultNode:SetExpanded(true, true)
  748.  
  749.     defaultNode:GetRoot():SetSelectedItem(defaultNode)
  750.  
  751.     local i = 0
  752.     for key, build in SortedPairs(BaseWars.SpawnList) do
  753.         i = i + 1
  754.         local idx = tostring(i)
  755.  
  756.         local node = defaultNode:AddNode(build.__inf.name or "(UNNAMED)")
  757.  
  758.         local ico = build.__inf.icon or "icon16/cancel.png"
  759.         node:SetIcon(ico)
  760.  
  761.         local container = rightPanel:Add("DPanel")
  762.         function container:Paint() end
  763.         container:Dock(FILL)
  764.  
  765.         local ap = MakeTab(key)
  766.         pcall(ap, container)
  767.  
  768.         rightPanel:AddPanel(idx, container)
  769.  
  770.         function node:OnNodeSelected()
  771.             rightPanel:SwitchTo(idx)
  772.         end
  773.  
  774.     end
  775.  
  776.     for name, build in next, Panels do
  777.  
  778.         local container = rightPanel:Add("DPanel")
  779.         function container:Paint() end
  780.         container:Dock(FILL)
  781.  
  782.         pcall(build, container)
  783.         rightPanel:AddPanel(name, container)
  784.  
  785.     end
  786.  
  787.     rightPanel:SwitchTo("Default", true)
  788.  
  789.     return pnl
  790.  
  791. end
  792.  
  793. spawnmenu.AddCreationTab("#spawnmenu.category.basewars", MakeSpawnList, "icon16/building.png", BaseWars.Config.RestrictProps and -100 or 2)
  794.  
  795. spawnmenu.Reload = spawnmenu.Reload or concommand.GetTable().spawnmenu_reload
  796. concommand.Add("spawnmenu_reload", function(...)
  797.     spawnmenu.Reload(...)
  798.     if GetConVar("developer"):GetInt() < 2 then
  799.         local toRemove = {
  800.             "#spawnmenu.category.saves",
  801.             "#spawnmenu.category.dupes",
  802.             "#spawnmenu.category.postprocess",
  803.             "#spawnmenu.category.vehicles",
  804.             "#spawnmenu.category.weapons",
  805.             "#spawnmenu.category.npcs",
  806.             "#spawnmenu.category.entities"
  807.         }
  808.         local i = 1
  809.         for k, v in next, g_SpawnMenu.CreateMenu.Items do
  810.             if table.HasValue(toRemove, v.Name) then
  811.                 g_SpawnMenu.CreateMenu.tabScroller.Panels[i] = nil
  812.                 g_SpawnMenu.CreateMenu.Items[k] = nil
  813.                 v.Tab:Remove()
  814.             end
  815.             i = i + 1
  816.         end
  817.     end
  818. end)
  819.  
  820. BaseWars.SpawnMenuReload = BaseWars.SpawnMenuReload or concommand.GetTable().spawnmenu_reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement