Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.03 KB | None | 0 0
  1. fcd.categories = {}
  2.  
  3. local curDealer
  4. local curDealerEnt
  5. local rpnl
  6. local rpnlList
  7. local bg
  8. local mbg
  9. local w, h
  10.  
  11. local vipMat = Material( 'icon16/award_star_bronze_1.png', 'noclamp smooth' )
  12.  
  13. function fcd.dealerMenu()
  14. curDealer = net.ReadString()
  15. if not fcd.getDealerByID( curDealer ) then return end
  16.  
  17. curDealerEnt = fcd.getDealerByID( curDealer )
  18.  
  19. local spawned = net.ReadBool() or false
  20.  
  21. w, h = ScrW() * 0.95, ScrH() * 0.95
  22.  
  23. if spawned then
  24. fcd.returnCheck()
  25. else
  26. fcd.openDealerMenu()
  27. end
  28. end
  29.  
  30. function fcd.returnCheck()
  31. local bg = vgui.Create( 'fcdCheck' )
  32. bg.question = 'Return current vehicle?'
  33.  
  34. bg.yes.onYesClicked = function()
  35. bg:Remove()
  36.  
  37. net.Start( 'fcd.returnVehicle' )
  38. net.WriteString( curDealer )
  39. net.SendToServer()
  40. end
  41. end
  42.  
  43. function fcd.openDealerMenu()
  44. local mw, mh = w / 10, h - 37
  45.  
  46. local lw, lh = mw * 1.5, mh
  47. local lx, ly = 5, 30
  48.  
  49. local rw, rh = mw * 8.5 - 15, mh
  50. local rx, ry = lx + lw + 5, 30
  51.  
  52. bg = vgui.Create( 'fcdDFrame' )
  53. bg:SetSize( w, h )
  54. bg:SetPos( ScrW() / 2 - ( w / 2 ), ScrH() / 2 - ( h / 2 ) )
  55. bg.title = fcd.getDealerName( curDealerEnt ) .. ' - Main Menu'
  56.  
  57. mbg = bg:Add( 'fcdDPanel' )
  58. mbg:SetSize( w, h )
  59. mbg:SetPos( 0, 0 )
  60.  
  61. bg:addCloseButton()
  62.  
  63. function mbg:Paint( w, h )
  64.  
  65. end
  66.  
  67. local lpnl = mbg:Add( 'fcdDPanel' )
  68. lpnl:SetSize( lw, lh )
  69. lpnl:SetPos( lx, ly )
  70. lpnl.drawTitle = true
  71. lpnl.title = 'Categories'
  72.  
  73. local lpnlList = lpnl:Add( 'DScrollPanel' )
  74. lpnlList:SetSize( lw, lh - 20 )
  75. lpnlList:SetPos( 0, 25 )
  76. lpnlList.VBar:SetWide( 0 )
  77.  
  78. local yPos = 0
  79.  
  80. local all = lpnlList:Add( 'fcdDButton' )
  81. all:SetSize( lw, 25 )
  82. all:SetPos( 0, yPos )
  83. all.text = 'Show all'
  84. all.id = 0
  85.  
  86. function all:DoClick()
  87. if not self.clickable then return end
  88.  
  89. fcd.displayCategory( self.id, curDealerEnt:GetisSpecific() )
  90. rpnl.title = 'Vehicles'
  91. end
  92.  
  93. yPos = yPos + 28
  94.  
  95. for k, v in pairs( fcd.categories or {} ) do
  96. local cat = lpnlList:Add( 'fcdDButton' )
  97. cat:SetSize( lw, 25 )
  98. cat:SetPos( 0, yPos )
  99. cat.text = v
  100. cat.id = k
  101.  
  102. function cat:DoClick()
  103. if not self.clickable then return end
  104.  
  105. fcd.displayCategory( self.id, curDealerEnt:GetisSpecific() )
  106. rpnl.title = 'Vehicles ( ' .. v .. ' )'
  107. end
  108.  
  109. yPos = yPos + 28
  110. end
  111.  
  112. rpnl = mbg:Add( 'fcdDPanel' )
  113. rpnl:SetSize( rw, rh )
  114. rpnl:SetPos( rx, ry )
  115. rpnl.drawTitle = true
  116. rpnl.title = 'Vehicles'
  117.  
  118. rpnlList = rpnl:Add( 'DScrollPanel' )
  119. rpnlList:SetSize( rw, rh - 25 )
  120. rpnlList:SetPos( 0, 25 )
  121. rpnlList.VBar:SetWide( 0 )
  122.  
  123. if curDealerEnt:GetisSpecific() then
  124. fcd.displayCategory( 'curDealer' )
  125. else
  126. fcd.displayCategory( 0 )
  127. end
  128. end
  129.  
  130. function fcd.displayCategory( id, specific )
  131. local data = {}
  132.  
  133. local w, h = rpnl:GetWide() / 2 - 7.5, 100
  134. local x, y = 5, 0
  135. local count = 0
  136.  
  137. if id == 0 then
  138. for k, v in pairs( fcd.dataVehicles or {} ) do
  139.  
  140. if specific then
  141. if v.specificDealer then
  142. if table.HasValue( v.specificDealer, curDealer ) then
  143. table.insert( data, v )
  144. end
  145. end
  146. else
  147. if v.specificDealer then continue end
  148. table.insert( data, v )
  149. end
  150. end
  151. elseif id == 'curDealer' then
  152. for k, v in pairs( fcd.dataVehicles or {} ) do
  153. if v.specificDealer then
  154. if table.HasValue( v.specificDealer, curDealer ) then
  155. table.insert( data, v )
  156. end
  157. end
  158. end
  159. else
  160. local category = fcd.categories[ id ]
  161. if not category then category = fcd.dataVehicles end
  162.  
  163. for k, v in pairs( fcd.dataVehicles or {} ) do
  164. if v.category then
  165. if v.category == category then
  166. if not specific then
  167. if v.specificDealer then continue end
  168. end
  169.  
  170. if specific then
  171. if v.specificDealer then
  172. if table.HasValue( v.specificDealer, curDealer ) then
  173. table.insert( data, v )
  174. end
  175. end
  176. else
  177. table.insert( data, v )
  178. end
  179. end
  180. end
  181. end
  182. end
  183.  
  184. rpnlList:Clear()
  185.  
  186. for k, v in pairs( data or {} ) do
  187. local purch = true
  188.  
  189. count = count + 1
  190.  
  191. local info = list.Get( 'Vehicles' )[ v.class ]
  192. if not info then continue end
  193.  
  194. local reg = fcd.registeredVehicles[ v.class ]
  195. if not reg then return end
  196.  
  197. if reg.rankRestrict then
  198. if reg.rankRestrict( LocalPlayer() ) then
  199. purch = true
  200. else
  201. purch = false
  202. end
  203. end
  204.  
  205. if reg.jobRestrict then
  206. if reg.jobRestrict( LocalPlayer() ) then
  207. purch = true
  208. else
  209. purch = false
  210. end
  211. end
  212.  
  213. v.owned = table.HasValue( fcd.owned, v.class )
  214.  
  215. local pnl = rpnlList:Add( 'fcdDPanel' )
  216. pnl:SetSize( w, h )
  217. pnl:SetPos( x, y )
  218. pnl.title = info.Name or ''
  219.  
  220. function pnl:PaintOver( w, h )
  221. draw.SimpleText( 'Price: ' .. DarkRP.formatMoney( v.price ) or 'nil', 'fcd_font_20', w / 4, 15, fcd.clientVal( 'mainTextColor' ) )
  222.  
  223. if v.owned then
  224. draw.SimpleText( 'Owned: Yes', 'fcd_font_20', w / 4, 40, fcd.clientVal( 'mainTextColor' ) )
  225. else
  226. draw.SimpleText( 'Owned: No', 'fcd_font_20', w / 4, 40, fcd.clientVal( 'mainTextColor' ) )
  227. end
  228.  
  229. if purch then
  230. draw.SimpleText( 'Purchasable: Yes', 'fcd_font_20', w / 4, 65, fcd.clientVal( 'mainTextColor' ) )
  231. else
  232. draw.SimpleText( 'Purchasable: No', 'fcd_font_20', w / 4, 65, fcd.clientVal( 'mainTextColor' ) )
  233. end
  234.  
  235. if v.isVip then
  236. surface.SetDrawColor( Color( 255, 255, 255 ) )
  237. surface.SetMaterial( vipMat )
  238. surface.DrawTexturedRect( w - ( w * 0.3 ) - 5 - 25, 5, 20, 25 )
  239. end
  240. end
  241.  
  242. local select = pnl:Add( 'fcdDButton' )
  243. select:SetSize( w * 0.3, h / 2 - 7.5 )
  244. select:SetPos( w - ( w * 0.3 ) - 5, 5 )
  245. select.text = 'Select'
  246. select.textSize = 20
  247.  
  248. function select:DoClick()
  249. fcd.displayVehicle( v.class )
  250. end
  251.  
  252. local quick = pnl:Add( 'fcdDButton' )
  253. quick:SetSize( w * 0.3, h / 2 - 7.5 )
  254. quick:SetPos( w - ( w * 0.3 ) - 5, 10 + h / 2 - 7.5 )
  255. quick.text = 'Quick Buy'
  256. quick.textSize = 20
  257.  
  258. function quick:DoClick()
  259. net.Start( 'fcd.purchaseVehicle' )
  260. net.WriteString( v.class )
  261. net.SendToServer()
  262.  
  263. bg:Remove()
  264. end
  265.  
  266. if v.owned then
  267. quick.text = 'Quick Spawn'
  268.  
  269. function quick:DoClick()
  270. net.Start( 'fcd.quickSpawnVehicle' )
  271. net.WriteString( v.class )
  272. net.WriteString( curDealer )
  273. net.SendToServer()
  274.  
  275. bg:Remove()
  276. end
  277. end
  278.  
  279. local mdl = pnl:Add( 'DModelPanel' )
  280. mdl:SetSize( w / 4, h )
  281. mdl:SetPos( 1, 1 )
  282. mdl:SetModel( info.Model )
  283.  
  284. fcd.fixMdlPos( mdl )
  285.  
  286. if count >= 2 then
  287. y = y + h + 5
  288. x = 5
  289. count = 0
  290. else
  291. x = x + w + 5
  292. end
  293. end
  294. end
  295.  
  296. function fcd.displayVehicle( class )
  297. if not class then return end
  298. if not fcd.dataVehicles[ class ] then return end
  299.  
  300. local vClr = Color( 255, 255, 255 )
  301.  
  302. local nW, nH = w - 10, h - 37
  303. local mW, mH = nW / 2 - 10, nH / 2 - 10
  304.  
  305. local sendData = {}
  306. sendData.dealerID = curDealer
  307. sendData.class = class
  308.  
  309. local data = list.Get( 'Vehicles' )[ class ]
  310. if not data then return end
  311.  
  312. mbg:SizeTo( 0, 0, fcd.clientVal( 'animationSpeed' ) )
  313.  
  314. local nbg = bg:Add( 'fcdDPanel' )
  315. nbg:SetSize( 0, 0 )
  316. nbg:SetPos( 5, 30 )
  317. nbg.drawTitle = true
  318. nbg.title = data.Name or ''
  319.  
  320. local back = nbg:Add( 'fcdDButton' )
  321. back:SetSize( 50, 20 )
  322. back:SetPos( nW - 50, 0 )
  323. back.text = 'Back'
  324. back.textSize = 18
  325.  
  326. function back:DoClick()
  327. nbg:SizeTo( 0, 0, fcd.clientVal( 'animationSpeed' ) )
  328.  
  329. timer.Simple( fcd.clientVal( 'animationSpeed' ), function()
  330. mbg:SizeTo( w, h, fcd.clientVal( 'animationSpeed' ) )
  331. nbg:Remove()
  332. end )
  333. end
  334.  
  335. timer.Simple( fcd.clientVal( 'animationSpeed' ), function()
  336. nbg:SizeTo( nW, nH, fcd.clientVal( 'animationSpeed' ) )
  337. end )
  338.  
  339. local mdlPnl = nbg:Add( 'fcdDPanel' )
  340. mdlPnl:SetSize( mW, mH )
  341. mdlPnl:SetPos( 5, 25 )
  342. mdlPnl.title = 'Model'
  343.  
  344. local mdl = mdlPnl:Add( 'DModelPanel' )
  345. mdl:SetSize( mW, mH )
  346. mdl:SetPos( 0, 0 )
  347. mdl:SetModel( data.Model or '' )
  348.  
  349. function mdl:Think()
  350. self:SetColor( vClr )
  351. end
  352.  
  353. fcd.fixMdlPos( mdl )
  354. mdl:SetFOV( 60 )
  355.  
  356. local modPnl = nbg:Add( 'fcdDPanel' )
  357. modPnl:SetSize( mW, mH )
  358. modPnl:SetPos( 15 + mW, 25 )
  359. modPnl.title = 'Modifications'
  360.  
  361. local cW, cH = mW / 2 - 10, mH / 2 - 25
  362.  
  363. local clr = modPnl:Add( 'DColorMixer' )
  364. clr:SetSize( cW, cH )
  365. clr:SetPos( 5, 20 )
  366. clr:SetWangs(false)
  367. clr:SetAlphaBar(false)
  368. clr:SetPalette(false)
  369.  
  370. function clr:ValueChanged()
  371. vClr = self:GetColor()
  372. sendData.clr = self:GetColor()
  373. end
  374.  
  375. local check = modPnl:Add( 'DCheckBoxLabel' )
  376. check:SetPos( 5, 25 + cH)
  377. check:SetSize( 20, 20 )
  378. check:SetFont( 'fcd_font_18' )
  379. check:SetText( 'Enable vehicle under lights?' )
  380.  
  381. local underClr = modPnl:Add( 'DColorMixer' )
  382. underClr:SetSize( cW, cH )
  383. underClr:SetPos( 5, 20 + cH + 25 )
  384. underClr:SetWangs(false)
  385. underClr:SetAlphaBar(false)
  386. underClr:SetPalette(false)
  387.  
  388. function underClr:ValueChanged()
  389. sendData.underLightColor = self:GetColor()
  390. end
  391.  
  392. function check:OnChange( bool )
  393. if bool then
  394. sendData.underLight = true
  395. sendData.underLightColor = underClr:GetColor()
  396. else
  397. sendData.underLight = false
  398. end
  399. end
  400.  
  401. if not fcd.cfg.underLights then
  402. local coverPnl = modPnl:Add( 'fcdDPanel' )
  403. coverPnl:SetSize( cW, cH + 30 )
  404. coverPnl:SetPos( 5, 25 + cH )
  405.  
  406. function coverPnl:Paint( w, h )
  407. fcd.drawBlur( self, 6 )
  408.  
  409. draw.SimpleText( 'Under Lights Disabled', 'fcd_font_19', w / 2, h / 2, fcd.clientVal( 'mainTextColor' ), 1, 1 )
  410. end
  411. end
  412.  
  413. local yPos = 20
  414.  
  415. local skinChoose = modPnl:Add( 'fcdDComboBox' )
  416. skinChoose:SetSize( cW, 25 )
  417. skinChoose:SetPos( 15 + cW, yPos )
  418. skinChoose:SetValue( 'Set Skin' )
  419.  
  420. for i = 0, mdl.Entity:SkinCount() do
  421. skinChoose:AddChoice( i )
  422. end
  423.  
  424. function skinChoose:OnSelect()
  425. mdl.Entity:SetSkin( self:GetValue() )
  426. sendData.skin = self:GetValue()
  427.  
  428. self:SetValue( 'Skin: ' .. self:GetValue() )
  429. end
  430.  
  431. yPos = yPos + 25 + 5
  432.  
  433. for _, bGroup in pairs( mdl.Entity:GetBodyGroups() ) do
  434. if not ( bGroup.num >= 2 ) then continue end
  435.  
  436. local bMod = modPnl:Add( 'fcdDComboBox' )
  437. bMod:SetSize( cW, 25 )
  438. bMod:SetPos( 15 + cW, yPos )
  439. bMod:SetValue( bGroup.name or '' )
  440.  
  441. for i = 0, bGroup.num - 1 do
  442. bMod:AddChoice( i )
  443. end
  444.  
  445. function bMod:OnSelect()
  446. mdl.Entity:SetBodygroup( bGroup.id, self:GetValue())
  447.  
  448. sendData.bGroups = sendData.bGroups or {}
  449. sendData.bGroups[ bGroup.id ] = tonumber( self:GetValue() )
  450.  
  451. self:SetValue( ( bGroup.name or '' ) .. ': ' .. self:GetValue() )
  452. end
  453.  
  454. yPos = yPos + 25 + 5
  455. end
  456.  
  457. if not fcd.cfg.Modules[ 'vehicleModifications' ] then
  458. local modPnlHide = modPnl:Add( 'fcdDPanel' )
  459. modPnlHide:SetSize( mW, mH )
  460. modPnlHide:SetPos( 0, 0 )
  461.  
  462. function modPnlHide:Paint( w, h )
  463. fcd.drawBlur( self, 6 )
  464.  
  465. draw.SimpleText( 'Modifications Disabled', 'fcd_font_19', w / 2, h / 2, fcd.clientVal( 'mainTextColor' ), 1, 1 )
  466. end
  467. end
  468.  
  469. local vehStats = nbg:Add( 'fcdDPanel' )
  470. vehStats:SetSize( mW, mH - 20 )
  471. vehStats:SetPos( 5, 35 + mH )
  472. vehStats.drawTitle = false
  473. vehStats.title = 'Data'
  474.  
  475. local vehData = fcd.dataVehicles[ class ]
  476.  
  477. local barAmt = mW / 25
  478. local barH = mH / 3 - 25 - 30
  479.  
  480. local spdBar = 130 / barAmt
  481. local rpmBar = 5000 / barAmt
  482. local horseBar = 1200 / barAmt
  483.  
  484. if vehData.maxSpeed and vehData.maxRPM and vehData.horsePower then
  485. local vehSpd = vehData.maxSpeed / spdBar
  486. local vehRPM = vehData.maxRPM / rpmBar
  487. local vehHorsePower = vehData.horsePower / horseBar
  488.  
  489. function vehStats:PaintOver( w, h )
  490. local yPos = 25
  491. local xPos = 5
  492.  
  493. local barX = 5
  494.  
  495. draw.SimpleText( 'Max Speed: ', 'fcd_font_25', 5, yPos, fcd.clientVal( 'mainTextColor' ) )
  496.  
  497. yPos = yPos + 30
  498.  
  499. for i = 1, barAmt do
  500.  
  501. local clr = Color( 10, 10, 10, 200 )
  502.  
  503. if i <= vehSpd then
  504. clr = Color( 25, 255, 25 )
  505. end
  506.  
  507. draw.RoundedBox( 0, barX, yPos, 15, barH, clr )
  508. barX = barX + 25
  509. end
  510.  
  511. yPos = yPos + barH + 5
  512.  
  513. draw.SimpleText( 'Max RPM: ', 'fcd_font_25', 5, yPos, fcd.clientVal( 'mainTextColor' ) )
  514.  
  515. yPos = yPos + 30
  516. barX = 5
  517.  
  518. for i = 1, barAmt do
  519.  
  520. local clr = Color( 10, 10, 10, 200 )
  521.  
  522. if i <= vehRPM then
  523. clr = Color( 25, 255, 25 )
  524. end
  525.  
  526. draw.RoundedBox( 0, barX, yPos, 15, barH, clr )
  527. barX = barX + 25
  528. end
  529.  
  530. yPos = yPos + barH + 5
  531.  
  532. draw.SimpleText( 'Horse Power: ', 'fcd_font_25', 5, yPos, fcd.clientVal( 'mainTextColor' ) )
  533.  
  534. yPos = yPos + 30
  535. barX = 5
  536.  
  537. for i = 1, barAmt do
  538.  
  539. local clr = Color( 10, 10, 10, 200 )
  540.  
  541. if i <= vehHorsePower then
  542. clr = Color( 25, 255, 25 )
  543. end
  544.  
  545. draw.RoundedBox( 0, barX, yPos, 15, barH, clr )
  546. barX = barX + 25
  547. end
  548. end
  549. else
  550. local vehStatsC = vehStats:Add( 'fcdDPanel' )
  551. vehStatsC:SetSize( mW, mH - 20 )
  552. vehStatsC:SetPos( 0, 0 )
  553.  
  554. function vehStatsC:Paint( w, h )
  555. fcd.drawBlur( self, 6 )
  556.  
  557. draw.SimpleText( 'Stats Not Available', 'fcd_font_19', w / 2, h / 2, fcd.clientVal( 'mainTextColor' ), 1, 1 )
  558. end
  559. end
  560.  
  561. local manage = nbg:Add( 'fcdDPanel' )
  562. manage:SetSize( mW, mH - 20 )
  563. manage:SetPos( 15 + mW, 35 + mH )
  564. manage.drawTitle = false
  565. manage.title = 'Manage'
  566.  
  567. local clicka = true
  568. if vehData.owned then
  569. clicka = false
  570. end
  571.  
  572. local btns = {}
  573.  
  574. btns[ 1 ] = {
  575. txt = 'Purchase',
  576. clickable = clicka,
  577. click = function()
  578. net.Start( 'fcd.purchaseVehicle' )
  579. net.WriteString( class )
  580. net.SendToServer()
  581. end
  582. }
  583. btns[ 2 ] = {
  584. txt = 'Sell',
  585. clickable = vehData.owned and true or false,
  586. click = function()
  587. net.Start( 'fcd.sellVehicle' )
  588. net.WriteString( class )
  589. net.SendToServer()
  590. end
  591. }
  592. btns[ 3 ] = {
  593. txt = 'Spawn',
  594. clickable = vehData.owned and true or false,
  595. click = function()
  596. net.Start( 'fcd.spawnVehicle' )
  597. net.WriteTable( sendData )
  598. net.SendToServer()
  599. end
  600. }
  601.  
  602. local yPos = 20
  603.  
  604. for i = 1, #btns do
  605. local data = btns[ i ]
  606.  
  607. local w, h = mW, ( mH - 15 ) / #btns - 7.5
  608.  
  609. local btn = manage:Add( 'fcdDButton' )
  610. btn:SetSize( w, h )
  611. btn:SetPos( 5, yPos)
  612. btn.text = data.txt
  613. btn.textSize = 20
  614. btn.clickable = data.clickable
  615.  
  616. function btn:DoClick()
  617. if not self.clickable then return end
  618.  
  619. data.click()
  620. bg:Remove()
  621. end
  622.  
  623. yPos = yPos + h + 5
  624. end
  625. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement