Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.04 KB | None | 0 0
  1. --[[-------------------------------------------------------
  2.  
  3. Fight to Survive: Stronghold by RoaringCow, TehBigA is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  4.  
  5. This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  6. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or send a letter to Creative Commons,
  7. 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
  8.  
  9. ---------------------------------------------------------]]
  10. local SND_PRIMARY = Sound( "weapons/mp5Navy/mp5_slideback.wav" )
  11. local SND_SECONDARY = Sound( "weapons/elite/elite_sliderelease.wav" )
  12. local SND_EXPLOSIVE = Sound( "weapons/pinpull.wav" )
  13. local SND_CONFIRM = Sound( "buttons/button9.wav" )
  14. local SND_FAIL = Sound( "buttons/button11.wav" )
  15.  
  16. local PANEL = {}
  17.  
  18. local function HandleMultiOption( pnl, tbl )
  19. if pnl:GetChecked() then
  20. if not tbl then return end
  21.  
  22. for _, v in pairs( tbl ) do
  23. if v ~= pnl then
  24. RunConsoleCommand( v.ConVar, "0" )
  25. v:SetChecked( false )
  26. end
  27. end
  28. end
  29. end
  30.  
  31. function PANEL:BuildCheckBoxes()
  32. local pw, sw = weapons.Get( self.CurrentPrimary ), weapons.Get( self.CurrentSecondary )
  33.  
  34. self.PAttachments:Clear()
  35. for k, t in pairs( GAMEMODE.WeaponAttachments ) do
  36. if pw then
  37. if not pw.VElements or not pw.VElements[k] then
  38. continue
  39. end
  40. end
  41.  
  42. if not self.Attachments.primary[t.type] then
  43. self.Attachments.primary[t.type] = {}
  44. end
  45.  
  46. local parent = vgui.Create( "DPanel", self )
  47. parent:SetTall( 15 )
  48.  
  49. local cbox = vgui.Create( "DCheckBoxLabel", parent )
  50. cbox:SetText( t.printname )
  51. cbox:SetConVar( "attach_".. k.. "_primary" )
  52. cbox.ConVar = "attach_".. k.. "_primary"
  53. cbox.OnChange = function(...) HandleMultiOption(..., self.Attachments.primary[t.type]) end
  54. cbox:SizeToContents()
  55.  
  56. cbox.buy = vgui.Create( "DButton", parent )
  57. cbox.buy:SetText( "BUY" )
  58. cbox.buy:SetSize( 35, 15 )
  59. cbox.buy.DoClick = function( pnl )
  60. if not self.CurrentPrimary then return end
  61. local w = weapons.Get( self.CurrentPrimary )
  62. if not w then return end
  63.  
  64. local dq = Derma_Query( "Purchase ".. t.printname.. " for your ".. w.PrintName.. "?\n\nPrice: $".. t.cost, "Purchase Attachment",
  65. "Yes", function() GAMEMODE.Net:SendBuyAttachmentRequest( 6, self.CurrentPrimary, k ) end,
  66. "No", function()end
  67. )
  68. dq.Paint = function( p )
  69. Derma_DrawBackgroundBlur( p, p.m_fCreateTime )
  70. p:GetSkin():DrawGenericBackground( 0, 0, p:GetWide(), p:GetTall(), Color( 40, 40, 40, 240 ), false, true )
  71. end
  72. end
  73.  
  74. cbox.Think = function( pnl )
  75. if not self.CurrentPrimary or not LocalPlayer():HasAttachment( 6, self.CurrentPrimary, k ) then
  76. pnl:SetDisabled( true )
  77. pnl:SetValue( false )
  78. else
  79. pnl:SetDisabled( false )
  80. end
  81. end
  82. cbox.buy.Think = function( pnl )
  83. if not self.CurrentPrimary or LocalPlayer():HasAttachment( 6, self.CurrentPrimary, k ) then
  84. pnl:SetDisabled( true )
  85. else
  86. pnl:SetDisabled( false )
  87. end
  88. end
  89.  
  90. parent.PerformLayout = function( pnl )
  91. cbox.buy:SetPos( parent:GetWide() -cbox.buy:GetWide(), 0 )
  92. end
  93.  
  94. self.PAttachments:AddItem( parent )
  95. table.insert( self.Attachments.primary[t.type], cbox )
  96. end
  97.  
  98. self.SAttachments:Clear()
  99. for k, t in pairs( GAMEMODE.WeaponAttachments ) do
  100. if sw then
  101. if not sw.VElements or not sw.VElements[k] then
  102. continue
  103. end
  104. end
  105.  
  106. if not self.Attachments.secondary[t.type] then
  107. self.Attachments.secondary[t.type] = {}
  108. end
  109.  
  110. local parent = vgui.Create( "DPanel", self )
  111. parent:SetTall( 15 )
  112.  
  113. local cbox = vgui.Create( "DCheckBoxLabel", parent )
  114. cbox:SetText( t.printname )
  115. cbox:SetConVar( "attach_".. k.. "_secondary" )
  116. cbox.ConVar = "attach_".. k.. "_secondary"
  117. cbox.OnChange = function(...) HandleMultiOption(..., self.Attachments.secondary[t.type]) end
  118. cbox:SizeToContents()
  119.  
  120. cbox.buy = vgui.Create( "DButton", parent )
  121. cbox.buy:SetText( "BUY" )
  122. cbox.buy:SetSize( 35, 15 )
  123. cbox.buy.DoClick = function( pnl )
  124. if not self.CurrentSecondary then return end
  125. local w = weapons.Get( self.CurrentSecondary )
  126. if not w then return end
  127.  
  128. local dq = Derma_Query( "Purchase ".. t.printname.. " for your ".. w.PrintName.. "?\n\nPrice: $".. t.cost, "Purchase Attachment",
  129. "Yes", function() GAMEMODE.Net:SendBuyAttachmentRequest( 7, self.CurrentSecondary, k ) end,
  130. "No", function()end
  131. )
  132. dq.Paint = function( p )
  133. Derma_DrawBackgroundBlur( p, p.m_fCreateTime )
  134. p:GetSkin():DrawGenericBackground( 0, 0, p:GetWide(), p:GetTall(), Color( 40, 40, 40, 240 ), false, true )
  135. end
  136. end
  137.  
  138. cbox.Think = function( pnl )
  139. if not self.CurrentSecondary or not LocalPlayer():HasAttachment( 7, self.CurrentSecondary, k ) then
  140. pnl:SetDisabled( true )
  141. pnl:SetValue( false )
  142. else
  143. pnl:SetDisabled( false )
  144. end
  145. end
  146. cbox.buy.Think = function( pnl )
  147. if not self.CurrentSecondary or LocalPlayer():HasAttachment( 7, self.CurrentSecondary, k ) then
  148. pnl:SetDisabled( true )
  149. else
  150. pnl:SetDisabled( false )
  151. end
  152. end
  153.  
  154. parent.PerformLayout = function( pnl )
  155. cbox.buy:SetPos( parent:GetWide() -cbox.buy:GetWide(), 0 )
  156. end
  157.  
  158. self.SAttachments:AddItem( parent )
  159. table.insert( self.Attachments.secondary[t.type], cbox )
  160. end
  161. end
  162.  
  163. function PANEL:Init()
  164. self.Attachments = { primary = {}, secondary = {} }
  165.  
  166. self.PAttachments = vgui.Create( "DPanelList", self )
  167. self.PAttachments:SetPadding( 5 )
  168. self.PAttachments:SetSpacing( 5 )
  169. self.PATitle = vgui.Create( "DButton", self )
  170. self.PATitle:SetText( "Primary Attachments")
  171.  
  172. self.SAttachments = vgui.Create( "DPanelList", self )
  173. self.SAttachments:SetPadding( 5 )
  174. self.SAttachments:SetSpacing( 5 )
  175. self.SATitle = vgui.Create( "DButton", self )
  176. self.SATitle:SetText( "Secondary Attachments" )
  177.  
  178. self:BuildCheckBoxes()
  179.  
  180. -- ----------
  181.  
  182. self.CurrentPrimary = ""
  183.  
  184. self.PrimaryModel = vgui.Create( "sh_itemmodel", self )
  185. self.PrimaryModel:Setup( "models/weapons/w_smg_mp5.mdl", "MP5-A4" )
  186.  
  187. self.PrimaryList = vgui.Create( "DListView", self )
  188. self.PrimaryList:SetMultiSelect( false )
  189. self.PrimaryList:AddColumn( "Primary" )
  190.  
  191. local column = self.PrimaryList:AddColumn( "Time left" )
  192. column:SetFixedWidth( 70 )
  193.  
  194. self.PrimaryQuickBuy = vgui.Create( "sh_quickbuy", self )
  195. self.PrimaryQuickBuy:Setup( "SMG Ammo", "smg1", 4 )
  196.  
  197. function self.PrimaryList.OnRowSelected( panel, lineid, line )
  198. local old_primary = self.CurrentPrimary
  199. self.CurrentPrimary = line.weaponclass or ""
  200.  
  201. if self.CurrentPrimary != "" and old_primary != self.CurrentPrimary then
  202. RunConsoleCommand( "sh_setprimary", self.CurrentPrimary )
  203. local tbl = GAMEMODE.PrimaryWeapons[self.CurrentPrimary]
  204. self.PrimaryModel:Setup( tbl.model, tbl.name, (tbl.fov or 90), tbl.offset, 4 )
  205. self.PrimaryQuickBuy:Setup( ((tbl.type=="smg1" and "SMG") or (tbl.type=="buckshot" and "Shotgun") or (tbl.type=="ar2" and "Rifle") or (tbl.type=="rpg_round" and "RPG")).." Ammo", tbl.type, 4 )
  206. surface.PlaySound( SND_PRIMARY )
  207.  
  208. self:BuildCheckBoxes()
  209. end
  210. end
  211.  
  212. self.PrimaryQBAmmoPrice = vgui.Create( "DLabel", self )
  213.  
  214. -- ----------
  215.  
  216. self.CurrentSecondary = ""
  217.  
  218. self.SecondaryModel = vgui.Create( "sh_itemmodel", self )
  219. self.SecondaryModel:Setup( "models/weapons/w_pist_p228.mdl", "SIG-SAUER P228", 60 )
  220.  
  221. self.SecondaryList = vgui.Create( "DListView", self )
  222. self.SecondaryList:SetMultiSelect( false )
  223. self.SecondaryList:AddColumn( "Secondary" )
  224. local column = self.SecondaryList:AddColumn( "Time left" )
  225. column:SetFixedWidth( 70 )
  226.  
  227. self.SecondaryQuickBuy = vgui.Create( "sh_quickbuy", self )
  228. self.SecondaryQuickBuy:Setup( "Pistol Ammo", "pistol", 4 )
  229.  
  230. function self.SecondaryList.OnRowSelected( panel, lineid, line )
  231. local old_secondary = self.CurrentSecondary
  232. self.CurrentSecondary = line.weaponclass or ""
  233. if self.CurrentSecondary != "" and old_secondary != self.CurrentSecondary then
  234. RunConsoleCommand( "sh_setsecondary", self.CurrentSecondary )
  235. local tbl = GAMEMODE.SecondaryWeapons[self.CurrentSecondary]
  236. self.SecondaryModel:Setup( tbl.model, tbl.name, (tbl.fov or 60), tbl.offset, 4 )
  237. self.SecondaryQuickBuy:Setup( ((tbl.type=="smg1" and "SMG") or (tbl.type=="pistol" and "Pistol") or (tbl.type=="buckshot" and "Shotgun") or (tbl.type=="ar2" and "Rifle") or (tbl.type=="rpg_round" and "RPG")).." Ammo", tbl.type, 4 )
  238. surface.PlaySound( SND_SECONDARY )
  239.  
  240. self:BuildCheckBoxes()
  241. end
  242. end
  243.  
  244. self.SecondaryQBAmmoPrice = vgui.Create( "DLabel", self )
  245.  
  246. -- ----------
  247.  
  248. self.CurrentExplosive = ""
  249.  
  250. self.ExplosiveModel = vgui.Create( "sh_itemmodel", self )
  251. self.ExplosiveModel:Setup( "models/weapons/w_eq_fraggrenade.mdl", "H.E. Grenade", 35 )
  252.  
  253. self.ExplosiveList = vgui.Create( "DListView", self )
  254. self.ExplosiveList:SetMultiSelect( false )
  255. self.ExplosiveList:AddColumn( "Explosives" )
  256. local column = self.ExplosiveList:AddColumn( "Count" )
  257. column:SetFixedWidth( 50 )
  258.  
  259. self.ExplosiveQuickBuy = vgui.Create( "sh_quickbuy", self )
  260. self.ExplosiveQuickBuy:Setup( "Grenade Ammo", "weapon_sh_grenade", 3 )
  261.  
  262. function self.ExplosiveList.OnRowSelected( panel, lineid, line )
  263. local old_explosive = self.CurrentExplosive
  264. self.CurrentExplosive = line.weaponclass or ""
  265. if self.CurrentExplosive != "" and old_explosive != self.CurrentExplosive then
  266. RunConsoleCommand( "sh_setexplosive", self.CurrentExplosive )
  267. local tbl = GAMEMODE.Explosives[self.CurrentExplosive]
  268. self.ExplosiveModel:Setup( tbl.model, tbl.name, (tbl.fov or 35), tbl.offset )
  269. self.ExplosiveQuickBuy:Setup(
  270. ((self.CurrentExplosive=="weapon_sh_grenade" and "H.E. Grenades") or
  271. (self.CurrentExplosive=="weapon_sh_smoke" and "Smoke Grenades") or
  272. (self.CurrentExplosive=="weapon_sh_flash" and "Flash Grenades") or
  273. (self.CurrentExplosive=="weapon_sh_c4" and "C4 Explosives")),
  274. self.CurrentExplosive, 3 )
  275. surface.PlaySound( SND_EXPLOSIVE )
  276. end
  277. end
  278.  
  279. self.ExplosiveQBAmmoPrice = vgui.Create( "DLabel", self )
  280.  
  281. -- ----------
  282.  
  283. self.SaveRequest = vgui.Create( "DFrame" )
  284. self.SaveRequest:SetDeleteOnClose( false )
  285. self.SaveRequest:SetTitle( "Save Loadout" )
  286. self.SaveRequest:SetDraggable( false )
  287. self.SaveRequest:ShowCloseButton( false )
  288. self.SaveRequest:SetSize( 150, 94 )
  289. self.SaveRequest:SetVisible( false )
  290. self.SaveRequest:SetSkin( "stronghold" )
  291.  
  292. function self.SaveRequest.Close( panel )
  293. GAMEMODE.LoadoutFrame:SetKeyboardInputEnabled( false )
  294. GAMEMODE.LoadoutFrame:SetMouseInputEnabled( false )
  295. panel:SetVisible( false )
  296. GAMEMODE.LoadoutFrame:MakePopup()
  297. end
  298.  
  299. local label = vgui.Create( "DLabel", self.SaveRequest )
  300. label:SetText( "Name:" )
  301. label:SizeToContents()
  302. label:SetTall( 22 )
  303. label:SetPos( 10, 30 )
  304.  
  305. local name = vgui.Create( "DTextEntry", self.SaveRequest )
  306. name:SetSize( 120-label:GetWide(), 22 )
  307. name:SetPos( label:GetWide()+20, 30 )
  308.  
  309. local cancel = vgui.Create( "DButton", self.SaveRequest )
  310. cancel:SetText( "Cancel" )
  311. cancel:SetSize( 60, 22 )
  312. cancel:SetPos( 10, 64 )
  313. function cancel.DoClick() self.SaveRequest:Close() end
  314.  
  315. local save = vgui.Create( "DButton", self.SaveRequest )
  316. save:SetText( "Save" )
  317. save:SetSize( 60, 22 )
  318. save:SetPos( 80, 64 )
  319. function save.DoClick() local ply = LocalPlayer()
  320. if name:GetValue() != "" then
  321. self:DoSaveLoadout( name:GetValue() ) self.SaveRequest:Close()
  322. else
  323. ply:SendMessage( "You must name your loadout." )
  324. surface.PlaySound( SND_FAIL )
  325. end
  326. end
  327. end
  328.  
  329. function PANEL:DoRefreshLicenses()
  330. local ply = LocalPlayer()
  331. local ostime = os.time()
  332.  
  333. -- Make sure these are checked for gamemode reloads
  334. local primary = ply:GetLoadoutPrimary()
  335. local secondary = ply:GetLoadoutSecondary()
  336. local explosive = ply:GetLoadoutExplosive()
  337.  
  338. self.PrimaryList:Clear()
  339. for class, time in pairs(ply:GetLicenses(1)) do
  340. local timeleft = (time == -1 and -1 or time-ostime)
  341. local tbl = GAMEMODE.PrimaryWeapons[class]
  342. if tbl and (timeleft == -1 or timeleft > 0) then
  343. local line = self.PrimaryList:AddLine( tbl.name, (timeleft != -1 and UTIL_FormatTime(timeleft,true) or "~") )
  344. line.weaponclass = class
  345. if class == primary then
  346. line:SetSelected( true )
  347. self.PrimaryList:OnRowSelected( _, line )
  348. end
  349. end
  350. end
  351. self.PrimaryList:SortByColumn( 1, false )
  352.  
  353. -- What does this do?
  354. --[[local selectedid = self.PrimaryList:GetSelectedLine() or 1
  355. if selectedid != nil then
  356. local line = self.PrimaryList:GetLine(selectedid)
  357. if line != nil then
  358. self.PrimaryList:OnClickLine( line )
  359. end
  360. end]]
  361.  
  362. self.SecondaryList:Clear()
  363. for class, time in pairs(ply:GetLicenses(2)) do
  364. local timeleft = (time == -1 and -1 or time-ostime)
  365. local tbl = GAMEMODE.SecondaryWeapons[class]
  366. if tbl and (timeleft == -1 or timeleft > 0) then
  367. local line = self.SecondaryList:AddLine( tbl.name, (timeleft != -1 and UTIL_FormatTime(timeleft,true) or "~") )
  368. line.weaponclass = class
  369. if class == secondary then
  370. line:SetSelected( true )
  371. self.SecondaryList:OnRowSelected( _, line )
  372. end
  373. end
  374. end
  375. self.SecondaryList:SortByColumn( 1, false )
  376.  
  377. -- What does this do?
  378. --[[local selectedid = self.SecondaryList:GetSelectedLine() or 1
  379. if selectedid != nil then
  380. local line = self.SecondaryList:GetLine(selectedid)
  381. if line != nil then
  382. self.SecondaryList:OnClickLine( line )
  383. end
  384. end]]
  385.  
  386. self.ExplosiveList:Clear()
  387. for class, tbl in pairs(GAMEMODE.Explosives) do
  388. local line = self.ExplosiveList:AddLine( tbl.name, ply:GetItemCount(class) )
  389. line.weaponclass = class
  390. if class == explosive then
  391. line:SetSelected( true )
  392. self.ExplosiveList:OnRowSelected( _, line )
  393. end
  394. end
  395. self.ExplosiveList:SortByColumn( 1, false )
  396.  
  397. -- What does this do?
  398. --[[local selectedid = self.ExplosiveList:GetSelectedLine() or 1
  399. if selectedid != nil then
  400. local line = self.ExplosiveList:GetLine(selectedid)
  401. if line != nil then
  402. self.ExplosiveList:OnClickLine( line )
  403. end
  404. end]]
  405.  
  406. self.PrimaryQuickBuy:Update()
  407. self.SecondaryQuickBuy:Update()
  408. self.ExplosiveQuickBuy:Update()
  409. end
  410.  
  411. function PANEL:DoSaveLoadout( name )
  412. local pri = self.CurrentPrimary or ""
  413. local sec = self.CurrentSecondary or ""
  414. local expl = self.CurrentExplosive or ""
  415. local ply = LocalPlayer()
  416. if name != "" and pri != "" and sec != "" and expl != "" then
  417. RunConsoleCommand( "sh_editloadout", name, pri, sec, expl )
  418. ply:EditLoadout( name, pri, sec, expl )
  419. self:DoRefreshLoadouts()
  420. surface.PlaySound( SND_CONFIRM )
  421. end
  422. end
  423.  
  424. function PANEL:Think()
  425. if !GAMEMODE.PrimaryWeapons then return end
  426. if not self.CurrentPrimary or self.CurrentPrimary == "" then return end
  427. if not self.CurrentSecondary or self.CurrentSecondary == "" then return end
  428. if not self.CurrentExplosive or self.CurrentExplosive == "" then return end
  429. local Atype = GAMEMODE.PrimaryWeapons[self.CurrentPrimary].type
  430. local price = GAMEMODE.Ammo[Atype].price
  431. local Atype2 = GAMEMODE.SecondaryWeapons[self.CurrentSecondary].type
  432. local price2 = GAMEMODE.Ammo[Atype2].price
  433. local Atype3 = GAMEMODE.Explosives[self.CurrentExplosive].price
  434. if !price then return end
  435. self.PrimaryQBAmmoPrice:SetText("Price: $"..self.PrimaryQuickBuy.Value:GetValue()*price)
  436. self.SecondaryQBAmmoPrice:SetText("Price: $"..self.SecondaryQuickBuy.Value:GetValue()*price2)
  437. self.ExplosiveQBAmmoPrice:SetText("Price: $"..self.ExplosiveQuickBuy.Value:GetValue()*Atype3)
  438. end
  439.  
  440. function PANEL:PerformLayout( w, h )
  441. local spacing = (w-30) * 0.25
  442.  
  443. self.PAttachments:SetSize( spacing, 150 )
  444. self.PAttachments:SetPos( 0, 14 )
  445. self.PATitle:SetPos(1,0)
  446. self.PATitle:SetSize(173,15)
  447.  
  448. self.SAttachments:SetSize( spacing, 150 )
  449. self.SAttachments:SetPos( 0, 164 )
  450. self.SATitle:SetPos( 1, 150 )
  451. self.SATitle:SetSize( 173, 15 )
  452.  
  453. self.PrimaryModel:SetSize( spacing, spacing )
  454. self.PrimaryModel:SetPos( spacing+10, 0 )
  455. self.PrimaryList:SetSize( spacing, h-54-spacing )
  456. self.PrimaryList:SetPos( spacing+10, 10+spacing )
  457. self.PrimaryQuickBuy:SetSize( spacing, 44 )
  458. self.PrimaryQuickBuy:SetPos( spacing+10, h-44 )
  459.  
  460. self.PrimaryQBAmmoPrice:SetSize( spacing, 44 )
  461. self.PrimaryQBAmmoPrice:SetPos( spacing+70, h-32 )
  462.  
  463.  
  464. self.SecondaryModel:SetSize( spacing, spacing )
  465. self.SecondaryModel:SetPos( (spacing+10)*2, 0 )
  466. self.SecondaryList:SetSize( spacing, h-54-spacing )
  467. self.SecondaryList:SetPos( (spacing+10)*2, 10+spacing )
  468. self.SecondaryQuickBuy:SetSize( spacing, 44 )
  469. self.SecondaryQuickBuy:SetPos( (spacing+10)*2, h-44 )
  470.  
  471. self.SecondaryQBAmmoPrice:SetSize( spacing, 44 )
  472. self.SecondaryQBAmmoPrice:SetPos( (spacing+40)*2, h-32 )
  473.  
  474. self.ExplosiveModel:SetSize( spacing, spacing )
  475. self.ExplosiveModel:SetPos( (spacing+10)*3, 0 )
  476. self.ExplosiveList:SetSize( spacing, h-54-spacing )
  477. self.ExplosiveList:SetPos( (spacing+10)*3, 10+spacing )
  478. self.ExplosiveQuickBuy:SetSize( spacing, 44 )
  479. self.ExplosiveQuickBuy:SetPos( (spacing+10)*3, h-44 )
  480.  
  481. self.ExplosiveQBAmmoPrice:SetSize( spacing, 44 )
  482. self.ExplosiveQBAmmoPrice:SetPos( (spacing+30)*3, h-32 )
  483.  
  484. self.SaveRequest:Center()
  485. end
  486.  
  487. vgui.Register( "sh_loadoutpanel", PANEL, "Panel" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement