Friks12829

stalker_inv

Sep 14th, 2022 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.60 KB | None | 0 0
  1. -- The queue for the rendered icons.
  2. ICON_RENDER_QUEUE = ICON_RENDER_QUEUE or {}
  3.  
  4. -- To make making inventory variant, This must be followed up.
  5. local function RenderNewIcon(panel, itemTable)
  6. local model = itemTable:GetModel()
  7.  
  8. -- re-render icons
  9. if ((itemTable.iconCam and !ICON_RENDER_QUEUE[string.lower(model)]) or itemTable.forceRender) then
  10. local iconCam = itemTable.iconCam
  11. iconCam = {
  12. cam_pos = iconCam.pos,
  13. cam_ang = iconCam.ang,
  14. cam_fov = iconCam.fov,
  15. }
  16. ICON_RENDER_QUEUE[string.lower(model)] = true
  17.  
  18. panel.Icon:RebuildSpawnIconEx(
  19. iconCam
  20. )
  21. end
  22. end
  23.  
  24. local function InventoryAction(action, itemID, invID, data)
  25. net.Start("ixInventoryAction")
  26. net.WriteString(action)
  27. net.WriteUInt(itemID, 32)
  28. net.WriteUInt(invID, 32)
  29. net.WriteTable(data or {})
  30. net.SendToServer()
  31. end
  32.  
  33. /*timer.Simple(0, function()
  34. netstream.Hook("dc_updateinventory", function(data)
  35. LocalPlayer().
  36. end)
  37. end)*/
  38.  
  39. local PANEL = {}
  40.  
  41. local bgMat = Material("dc_inventory/inventoryBG3.png")
  42. local lockArtMat = Material("dc_inventory/lockartefact.png")
  43.  
  44. local hClr3 = Color(200,0,0)
  45. local hClr2 = Color(122, 78, 2)
  46. local hClr1 = Color(0, 200, 0)
  47.  
  48. local function createSlot(frame, item, hp, showbar)
  49. local pnl = vgui.Create("ixSpawnIcon", frame)
  50. pnl.OnMousePressed = function(s)
  51. local derma = DermaMenu(false, s)
  52. derma:AddOption(L("unequip"), function()
  53. netstream.Start("dc_unequipitem", item.Type)
  54. end)
  55. derma:Open()
  56. end
  57.  
  58. if (showbar == nil) or (showbar == true) then
  59. local health = vgui.Create("DPanel", pnl)
  60. health:Dock(BOTTOM)
  61. --health:DockMargin(21, 0, 16.5, 0)
  62. --health:SetPos(pnl:GetWide()/2, pnl:GetTall()-5)
  63. health:SetTall(4)
  64. health:TDLib():ClearPaint()
  65. --:Background(Color(10,10,10,250), 5)
  66. local maxHp = item:GetMaxHealth()
  67. local val = (hp/maxHp)
  68.  
  69. health:On("Paint", function(s,w,h)
  70.  
  71. val = (hp/maxHp)
  72. surface.SetDrawColor(((val > .6) and hClr1) or ((val >= .4) and hClr2) or hClr3)
  73.  
  74. local x = w/2-w*.25
  75. //local off = 2 / (hp/maxHp)
  76. for i=1, math.Clamp(30*(hp/maxHp), 0, maxHp) do
  77. surface.DrawRect(x, -10, 1, h+20)
  78. x = x + 3
  79. end
  80.  
  81. x= nil
  82. end)
  83. end
  84.  
  85. return pnl
  86. end
  87.  
  88. local stats = {
  89. "Radiation",
  90. "Chemical",
  91. "Electrical",
  92. "Burn",
  93. "nil",
  94. "Rupture",
  95. "Bulletproof",
  96. "Stamina"
  97. }
  98.  
  99. local camData = {
  100. pos = Vector(23.560106, 0.150427, 62.174870),
  101. ang = Angle(-2.404, -179.307, 0.000),
  102. fov = 50
  103. }
  104.  
  105. local lPress = -1
  106. DC_FastSlots = DC_FastSlots or {}
  107. local rColor = Color(200,0,0)
  108. function PANEL:Init()
  109. self:SetDraggable(false)
  110. self:SetSizable(false)
  111. self:MakePopup()
  112. self:SetTitle("")
  113. self:ShowCloseButton(false)
  114. surface.PlaySound("dc_inventory/inv_open.ogg")
  115. self.InitTime = CurTime() + .5
  116. end
  117.  
  118. function PANEL:Load()
  119. gui.EnableScreenClicker(true)
  120.  
  121. local char = LocalPlayer():GetCharacter()
  122. local facName = ix.faction.Get(LocalPlayer():Team()).name
  123.  
  124. local icon = ikon:GetIcon(string.Replace(LocalPlayer():GetModel(), "/", "_"))
  125.  
  126. self:TDLib():ClearPaint()
  127. :Material(bgMat)
  128. :On("Paint", function(s,w,h)
  129. local w2, h2 = draw.SimpleText(char:GetName(), "ixMenuButtonFont", w*.45, h*.015, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  130. draw.SimpleText(char:GetMoney().." RUB", "ixMonoMediumFont", w*.66, h*.092, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP)
  131. draw.SimpleText(facName, "ixMenuButtonFontSmall", w*.45, h*.015 + h2 + 1, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
  132. w2,h2 = nil, nil
  133. --w22, h22 = nil, nil
  134. --s:SetCursor("arrow")
  135.  
  136. if not icon or icon:IsError() then
  137. icon = ikon:GetIcon(string.Replace(LocalPlayer():GetModel(), "/", "_"))
  138. end
  139.  
  140.  
  141. if (icon) then
  142. surface.SetMaterial(icon)
  143. surface.SetDrawColor(color_white)
  144. surface.DrawTexturedRect(w-w*.3, 15, 100,80)
  145. else
  146. ikon:renderIcon(
  147. string.Replace(LocalPlayer():GetModel(), "/", "_"),
  148. 2,
  149. 2,
  150. LocalPlayer():GetModel(),
  151. camData
  152. )
  153. end
  154.  
  155. local carry = char:GetData("carry", 0)
  156. local max = ix.weight.BaseWeight(char)
  157. draw.SimpleText(carry, "ixMonoMediumFont", w-(w*.33), h-(h*.017), carry >= max-10 and rColor or color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
  158. draw.SimpleText(max, "ixMonoMediumFont", w-(w*.242), h-(h*.017), color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM)
  159. carry, max = nil, nil
  160. end)
  161.  
  162. local bglPanel = vgui.Create("DPanel", self)
  163. --bglPanel:TDLib():ClearPaint()
  164. bglPanel:SetPos(0,0)
  165. bglPanel:SetTall(self:GetTall()*.498)
  166. bglPanel:SetWide(self:GetWide()*.42)
  167. bglPanel:TDLib():ClearPaint()
  168.  
  169. local statsData = char:GetData("dc_stats", nil)
  170. statsData = statsData ~= nil and util.JSONToTable(statsData) or {}
  171.  
  172. local weapon1, weapon2, body, head, knife, ll, rr
  173. local function updateSlots()
  174. if IsValid(ll) then ll:Remove() end
  175. if IsValid(rr) then rr:Remove() end
  176. --local char = LocalPlayer():GetCharacter()
  177. local data = char:GetData("dc_inventory", nil)
  178. data = data ~= nil and util.JSONToTable(data) or nil
  179.  
  180. statsData = char:GetData("dc_stats", nil)
  181. statsData = statsData ~= nil and util.JSONToTable(statsData) or {}
  182.  
  183. // Weapon 1
  184. if not data or not data.weapon1 or (data.weapon1.id == "") then
  185. weapon1 = vgui.Create("DPanel", bglPanel)
  186. weapon1:Dock(LEFT)
  187. weapon1:SetWide(bglPanel:GetWide()*.35)
  188. weapon1:DockPadding(bglPanel:GetWide()*.035,0,bglPanel:GetWide()*.035,0)
  189. weapon1.Paint = function() end
  190. else
  191. local i = ix.item.Get(data.weapon1.id)
  192. weapon1 = createSlot(bglPanel, i, data.weapon1.health)
  193. weapon1:SetModel(ix.item.Get(data.weapon1.id).model)
  194. weapon1:Dock(LEFT)
  195. weapon1:SetWide(bglPanel:GetWide()*.3)
  196. weapon1:DockPadding(bglPanel:GetWide()*.035,0,bglPanel:GetWide()*.035,0)
  197.  
  198. if i.iconCam then
  199. weapon1:SetCamPos(i.iconCam.pos)
  200. weapon1:SetFOV(i.iconCam.fov)
  201. weapon1:SetLookAng(i.iconCam.ang)
  202. end
  203. end
  204.  
  205. // Weapon 2
  206. if not data or not data.weapon2 or (data.weapon2.id == "") then
  207. weapon2 = vgui.Create("DPanel", bglPanel)
  208. weapon2:Dock(RIGHT)
  209. weapon2:SetWide(bglPanel:GetWide()*.32)
  210. weapon2:DockPadding(0, 0, bglPanel:GetWide()*.07, 0)
  211. weapon2.Paint = function() end
  212. else
  213. local i = ix.item.Get(data.weapon2.id)
  214. weapon2 = createSlot(bglPanel, i, data.weapon2.health)
  215. weapon2:SetModel(i.model)
  216. weapon2:Dock(RIGHT)
  217. weapon2:SetWide(bglPanel:GetWide()*.32)
  218. weapon2:DockPadding(0, 0, bglPanel:GetWide()*.07, 0)
  219.  
  220. if i.iconCam then
  221. weapon2:SetCamPos(i.iconCam.pos)
  222. weapon2:SetFOV(i.iconCam.fov)
  223. weapon2:SetLookAng(i.iconCam.ang)
  224. end
  225. end
  226.  
  227. // Knife
  228. if not data or not data.knife or (data.knife.id == "") then
  229. knife = vgui.Create("DPanel", bglPanel)
  230. knife:Dock(BOTTOM)
  231. knife:SetTall(bglPanel:GetTall()*.17)
  232. knife.Paint = function() end
  233. else
  234. local i = ix.item.Get(data.knife.id)
  235. knife = createSlot(bglPanel, i, data.knife.health, false)
  236. knife:SetModel(i.model)
  237. knife:Dock(BOTTOM)
  238. knife:SetTall(bglPanel:GetTall()*.17)
  239. --knife:DockPadding(12, 10, 9, 30)
  240.  
  241. if i.iconCam then
  242. knife:SetCamPos(i.iconCam.pos)
  243. knife:SetFOV(i.iconCam.fov)
  244. knife:SetLookAng(i.iconCam.ang)
  245. end
  246. end
  247.  
  248. // Head
  249. if not data or not data.head or (data.head.id == "") then
  250. head = vgui.Create("DPanel", bglPanel)
  251. head:Dock(TOP)
  252. head:SetTall(bglPanel:GetWide()*.34)
  253. head.Paint = function() end
  254. else
  255. local i = ix.item.Get(data.head.id)
  256. head = createSlot(bglPanel, i, data.head.health)
  257. head:SetModel(i.model)
  258. head:Dock(TOP)
  259. head:SetTall(bglPanel:GetWide()*.34)
  260. --head:DockPadding(12, 10, 9, 10)
  261. if i.iconCam then
  262. head:SetCamPos(i.iconCam.pos)
  263. head:SetFOV(i.iconCam.fov)
  264. head:SetLookAng(i.iconCam.ang)
  265. end
  266. head:DockMargin(10, 10, 10, 10)
  267. end
  268.  
  269. // Body
  270. if not data or not data.body or (data.body.id == "") then
  271. body = vgui.Create("DPanel", bglPanel)
  272. body:Dock(FILL)
  273. body.Paint = function() end
  274. --body:DockMargin(39, 0, 30, 7)
  275. else
  276. body = createSlot(bglPanel, ix.item.Get(data.body.id), data.body.health)
  277.  
  278. ll = vgui.Create("DPanel", bglPanel)
  279. ll:Dock(LEFT)
  280. ll:SetWide(bglPanel:GetWide()*.05)
  281. ll.Paint = function() end
  282.  
  283. rr = vgui.Create("DPanel", bglPanel)
  284. rr:Dock(RIGHT)
  285. rr:SetWide(bglPanel:GetWide()*.05)
  286. rr.Paint = function() end
  287.  
  288. local i = ix.item.Get(data.body.id)
  289. body:SetModel(i.model)
  290. if i.iconCam then
  291. body:SetCamPos(i.iconCam.pos)
  292. body:SetFOV(i.iconCam.fov)
  293. body:SetLookAng(i.iconCam.ang)
  294. end
  295. body:Dock(FILL)
  296. --body:SetTall(bglPanel:GetTall()*.1)
  297. body:DockMargin(0, 0, bglPanel:GetWide()*.03, bglPanel:GetTall()*.016)
  298. end
  299. end
  300.  
  301. -- Быстрые слоты
  302. local fastSlotsBG = vgui.Create("DPanel", self)
  303. fastSlotsBG:SetPos(15,bglPanel:GetTall()+2)
  304. fastSlotsBG:SetTall(self:GetTall()*.1)
  305. fastSlotsBG:SetWide(self:GetWide()*.4)
  306. fastSlotsBG:TDLib():ClearPaint()
  307.  
  308. -- Артефакты
  309. local artBG = vgui.Create("DPanel", self)
  310. artBG:SetPos(bglPanel:GetWide()*.03,bglPanel:GetTall()+2 + fastSlotsBG:GetTall() + (self:GetTall() * 0.01))
  311. artBG:SetTall(self:GetTall()*.085)
  312. artBG:SetWide(self:GetWide()*.4)
  313. artBG:TDLib():ClearPaint()
  314.  
  315. local slots = {}
  316. local function UpdateFastSlots()
  317. for k, v in ipairs(slots) do
  318. if IsValid(v) then v:Remove() end
  319. end
  320.  
  321. local charid = char:GetID()
  322. if not DC_FastSlots[charid] and file.Exists("dc_fastslots.json", "DATA") then
  323. DC_FastSlots = util.JSONToTable(file.Read("dc_fastslots.json", "DATA"))
  324. end
  325.  
  326. if not DC_FastSlots[charid] then
  327. DC_FastSlots[charid] = {
  328. [1] = {model = "", itemid = ""},
  329. [2] = {model = "", itemid = ""},
  330. [3] = {model = "", itemid = ""},
  331. [4] = {model = "", itemid = ""},
  332. }
  333. end
  334.  
  335. -- Быстрые слоты
  336. for i,v in ipairs(DC_FastSlots[charid]) do
  337. slots[i] = v.model ~= "" and vgui.Create("ixSpawnIcon", fastSlotsBG) or vgui.Create("DPanel", fastSlotsBG)
  338. slots[i]:Dock(LEFT)
  339. slots[i]:DockMargin(i ~= 1 and 4 or 0, 0, 0, 0)
  340. slots[i]:SetWide(fastSlotsBG:GetWide()*.24)
  341.  
  342. if v.model ~= "" then
  343. slots[i]:SetModel(v.model)
  344. slots[i].OnMousePressed = function(s)
  345. local derma = DermaMenu(false, s)
  346. derma:AddOption(L("unequip"), function()
  347. DC_FastSlots[charid][i] = {model = "", itemid = ""}
  348. file.Write("dc_fastslots.json", util.TableToJSON(DC_FastSlots))
  349. UpdateFastSlots()
  350. end)
  351. derma:Open()
  352. end
  353. else
  354. slots[i].Paint = function() end
  355. end
  356.  
  357. slots[i]:Receiver("ixInventoryItem", function(s, panels, bDropped, menuIndex, x, y)
  358. local panel = panels[1]
  359.  
  360. if (!IsValid(panel)) then
  361. return
  362. end
  363.  
  364. if (bDropped) then
  365. local data = panel.itemTable
  366. if not data.canFastSlot then return end
  367.  
  368. DC_FastSlots[charid][i] = {model = data.model, itemid = data.uniqueID}
  369. file.Write("dc_fastslots.json", util.TableToJSON(DC_FastSlots))
  370. UpdateFastSlots()
  371. end
  372. end)
  373. end
  374. end
  375.  
  376. -- Артефакты функция
  377. local artSlots = {}
  378. local function UpdateArtSlots()
  379. if not IsValid(self) then return end
  380.  
  381. local data = char:GetData("dc_inventory", nil)
  382. data = data ~= nil and util.JSONToTable(data) or nil
  383. local slotCount = data.body.id ~= "" and ix.item.Get(data.body.id).info.Arts or 0
  384. local artData = char:GetData("dc_arts", {})
  385. --local filtredArt = {}
  386.  
  387. statsData = char:GetData("dc_stats", nil)
  388. statsData = statsData ~= nil and util.JSONToTable(statsData) or {}
  389.  
  390. /*for k, v in pairs(artData) do
  391. if (v == nil) or (v == "") then continue end
  392.  
  393. local item = ix.item.Get(v)
  394. if not item then continue end
  395.  
  396. table.insert(filtredArt, {model = item.model})
  397. end*/
  398.  
  399.  
  400.  
  401. local artKeys = {}
  402.  
  403. local i2 = 1
  404. for k, v in pairs(artData) do
  405. artKeys[i2] = v == nil and {} or {id = k, class = v}
  406. i2 = i2 + 1
  407. end
  408.  
  409. for i=1, 5 do
  410. if IsValid(artSlots[i]) then artSlots[i]:Remove() end
  411.  
  412. local notEmpty = artKeys[i] ~= nil and artKeys[i].class ~= nil
  413.  
  414. artSlots[i] = slotCount >= i and notEmpty and vgui.Create("ixSpawnIcon", artBG) or vgui.Create("DPanel", artBG)
  415. artSlots[i]:Dock(LEFT)
  416. artSlots[i]:DockMargin(i ~= 1 and 4 or 1, 3, 1, 1)
  417. artSlots[i]:SetWide(artBG:GetWide()*.19)
  418. artSlots[i].OnMousePressed = function(s)
  419. if not artKeys[i].class then return end
  420.  
  421. local derma = DermaMenu(false, s)
  422. derma:AddOption(L("unequip"), function()
  423. netstream.Start("dc_unequipart", artKeys[i].id)
  424. end)
  425. derma:Open()
  426. end
  427.  
  428. if slotCount >= i then
  429. if notEmpty then
  430. local art = ix.item.Get(artKeys[i].class)
  431.  
  432. if art then
  433. artSlots[i]:SetModel(art.model)
  434. --artSlots[i].itemid = artKeys[i].id
  435. end
  436. else
  437. artSlots[i]:TDLib():ClearPaint()
  438. end
  439. else
  440. artSlots[i]:TDLib():ClearPaint()
  441. :Material(lockArtMat)
  442. end
  443. end
  444. end
  445.  
  446. UpdateFastSlots()
  447. updateSlots()
  448. UpdateArtSlots()
  449.  
  450. -- Здоровье
  451. local healthBG = vgui.Create("DPanel", self)
  452. healthBG:SetPos(bglPanel:GetWide()*.038,bglPanel:GetTall()+2 + fastSlotsBG:GetTall() + 2 + artBG:GetTall() )
  453. healthBG:SetTall(self:GetTall()*.085)
  454. healthBG:SetWide(self:GetWide()*.39)
  455. healthBG:TDLib():ClearPaint()
  456.  
  457. -- Полоса здоровья
  458. local health = vgui.Create("DPanel", healthBG)
  459. health:SetPos(0, healthBG:GetTall() - (healthBG:GetTall()*.38))
  460. health:SetSize(healthBG:GetWide()*.68, healthBG:GetTall()*.3)
  461.  
  462. local lp = LocalPlayer()
  463. local off = 2 /// (lp:Health()/lp:GetMaxHealth())
  464. health.Paint = function(s,w,h)
  465. surface.SetDrawColor(hClr3)
  466.  
  467. local x = 1
  468. local hp = lp:Health()
  469.  
  470. for i=1, hp do
  471. surface.DrawRect(x, 4, off, h-4)
  472.  
  473. x = x + off + 2
  474. end
  475.  
  476. x, hp = nil, nil
  477. end
  478.  
  479.  
  480. -- Радиация
  481. local radiation = vgui.Create("DPanel", healthBG)
  482. radiation:Dock(RIGHT)
  483. radiation:DockMargin(20, 20, -10, 10)
  484. radiation:SetWide(healthBG:GetWide()*.14)
  485. radiation:TDLib():ClearPaint()
  486.  
  487.  
  488. -- кровотечение
  489. local blooding = vgui.Create("DPanel", healthBG)
  490. blooding:Dock(RIGHT)
  491. blooding:DockMargin(20, 20, -10, 10)
  492. blooding:SetWide(healthBG:GetWide()*.145)
  493. blooding:TDLib():ClearPaint()
  494.  
  495.  
  496. -- Статистика
  497. local statsBG = vgui.Create("DPanel", self)
  498. statsBG:SetPos(bglPanel:GetWide()*.105,bglPanel:GetTall() + fastSlotsBG:GetTall() + artBG:GetTall() + healthBG:GetTall() + (healthBG:GetTall()*.31))
  499. statsBG:SetTall(self:GetTall()*.143)
  500. statsBG:SetWide(self:GetWide()*.42)
  501. --statsBG:TDLib():ClearPaint()
  502. local wide = statsBG:GetWide()*.36
  503. local tall = statsBG:GetTall() * .15
  504. local statLen = #stats
  505.  
  506. --statsBG:SetTooltip( "" )
  507.  
  508. --local str = ""
  509. --statsBG:SetTooltip( str )
  510.  
  511. statsBG:SetHelixTooltip(function(tooltip)
  512.  
  513. local name2 = tooltip:AddRow(L"statistic")
  514. name2:SetImportant()
  515. name2:SetText(L"statistic")
  516.  
  517. name2:SizeToContents()
  518.  
  519. local name = tooltip:AddRow(2)
  520. --name:SetImportant()
  521.  
  522. local str = ""
  523. for i=1, statLen do
  524. if L(stats[i]) == "nil" then continue end
  525. str = str..L(stats[i])..": "..(statsData[stats[i]] ~= nil and statsData[stats[i]]*100 or "0").."%"..(i ~= statLen and "\n" or "")
  526.  
  527. --name:SetText(L(stats[i])..": "..(statsData[stats[i]] ~= nil and statsData[stats[i]]*100 or "0").."%")
  528. --name:SetBackgroundColor(color_white)
  529. -- name:SizeToContents()
  530. end
  531.  
  532. name:SetText(str)
  533. name:SizeToContents()
  534. tooltip:SizeToContents()
  535. end)
  536.  
  537. statsBG.Paint = function(s,w,h)
  538. if s:IsHovered() then s:SetCursor('hand') end
  539. surface.SetDrawColor(color_white)
  540.  
  541. local x, y = 5, 6
  542. for i=1, statLen do
  543. if (statsData[stats[i]] ~= nil) and statsData[stats[i]] ~= 0 then
  544. if statsData[stats[i]] < 0 then
  545. surface.SetDrawColor(hClr3)
  546. end
  547.  
  548. local len = statsData[stats[i]]*100
  549. local absLen = math.abs(len)
  550.  
  551. local off = 2//.02 / (absLen/1200)
  552. local x2 = x
  553.  
  554. for i=1, math.Clamp(absLen, 0, 100) do
  555. surface.DrawRect(x2, y, off, tall)
  556. x2 = x2 + off + 1
  557. end
  558. end
  559. y = y + tall + tall * .71
  560.  
  561. if i == 4 then
  562. y = 6
  563. x = x + wide + wide*.3
  564. end
  565. end
  566. end
  567.  
  568. netstream.Hook("dc_artefactupdate", function()
  569. UpdateArtSlots()
  570. end)
  571.  
  572. netstream.Hook("DC_OnItemEquipped", function()
  573. if not IsValid(weapon1) then return end
  574.  
  575. weapon1:Remove()
  576. weapon2:Remove()
  577. body:Remove()
  578. head:Remove()
  579. knife:Remove()
  580. updateSlots()
  581. UpdateArtSlots()
  582. end)
  583.  
  584. local bgPanel = vgui.Create("DPanel", self)
  585. bgPanel:TDLib():ClearPaint()
  586. timer.Simple(0.01, function()
  587. if not IsValid(self) then return end
  588.  
  589. bgPanel:SetPos(self:GetWide()*.448, self:GetTall()*.15)
  590. bgPanel:SetSize(self:GetWide()*.45,self:GetTall()*.77)
  591.  
  592.  
  593. local canvas = bgPanel:Add("DScrollPanel")
  594. local canvasLayout = canvas.PerformLayout
  595. canvas.PerformLayout = nil -- we'll layout after we add the panels instead of each time one is added
  596. canvas:Dock(FILL)
  597. canvas:MoveToFront()
  598.  
  599. ix.gui.menuInventoryContainer = canvas
  600.  
  601. local panel = canvas:Add("ixInventory")
  602. panel:SetPos(0, 0)
  603. panel:MoveToFront()
  604. panel:SetDraggable(false)
  605. panel:SetSizable(false)
  606. panel:SetTitle(nil)
  607. panel.bNoBackgroundBlur = true
  608. panel.childPanels = {}
  609. panel:TDLib():ClearPaint()
  610. panel.iconSize = ScrW()*.0347
  611.  
  612. local inventory = LocalPlayer():GetCharacter():GetInventory()
  613.  
  614. if (inventory) then
  615. panel:SetInventory(inventory)
  616. end
  617.  
  618. ix.gui.inv1 = panel
  619.  
  620. if (ix.option.Get("openBags", true)) then
  621. for _, v in pairs(inventory:GetItems()) do
  622. if (!v.isBag) then
  623. continue
  624. end
  625.  
  626. v.functions.View.OnClick(v)
  627. end
  628. end
  629.  
  630. canvas.PerformLayout = canvasLayout
  631. end)
  632. end
  633.  
  634. function PANEL:Think()
  635. if self.InitTime >= CurTime() then return end
  636.  
  637. if input.IsKeyDown(KEY_I) or input.IsKeyDown(KEY_ESCAPE) then
  638. surface.PlaySound("dc_inventory/inv_close.ogg")
  639. self:Remove()
  640. lPress = CurTime() + .5
  641. end
  642. end
  643.  
  644. function PANEL:OnRemove()
  645. gui.EnableScreenClicker(false)
  646. end
  647.  
  648. vgui.Register("dc_inventory", PANEL, "DFrame")
  649.  
  650. local inv
  651. local function openInv()
  652. if IsValid(inv) then lPress = CurTime() + 1 return end
  653. if LocalPlayer():GetCharacter() == nil then return end
  654.  
  655. inv = vgui.Create("dc_inventory")
  656. inv:SetPos(ScrW()-ScrW()*.62, 0)
  657. inv:SetSize(ScrW()*.62, ScrH())
  658. inv:Load()
  659. lPress = CurTime() + 1
  660. end
  661.  
  662. local function InventoryAction(action, itemID, invID, data)
  663. net.Start("ixInventoryAction")
  664. net.WriteString(action)
  665. net.WriteUInt(itemID, 32)
  666. net.WriteUInt(invID, 32)
  667. net.WriteTable(data or {})
  668. net.SendToServer()
  669. end
  670.  
  671. function PLUGIN:PlayerButtonDown( ply, btn )
  672. if ply ~= LocalPlayer() then return end
  673.  
  674. if btn == KEY_I and (lPress < CurTime()) then
  675. --lPress = CurTime() + .35
  676. openInv()
  677. end
  678.  
  679. if (btn == KEY_F1) then
  680. local char = ply:GetCharacter()
  681. local charID = char:GetID()
  682. if DC_FastSlots[charID] and DC_FastSlots[charID][1] and DC_FastSlots[charID][1].model ~= "" then
  683. local item = char:GetInventory():HasItem(DC_FastSlots[charID][1].itemid)
  684. if item then
  685. InventoryAction("use", item.id, char:GetInventory():GetID())
  686. end
  687. end
  688. end
  689.  
  690. if (btn == KEY_F2) then
  691. local char = ply:GetCharacter()
  692. local charID = char:GetID()
  693. if DC_FastSlots[charID] and DC_FastSlots[charID][2] and DC_FastSlots[charID][2].model ~= "" then
  694. local item = char:GetInventory():HasItem(DC_FastSlots[charID][2].itemid)
  695. if item then
  696. InventoryAction("use", item.id, char:GetInventory():GetID())
  697. end
  698. end
  699. end
  700.  
  701. if (btn == KEY_F3) then
  702. local char = ply:GetCharacter()
  703. local charID = char:GetID()
  704. if DC_FastSlots[charID] and DC_FastSlots[charID][3] and DC_FastSlots[charID][3].model ~= "" then
  705. local item = char:GetInventory():HasItem(DC_FastSlots[charID][1].itemid)
  706. if item then
  707. InventoryAction("use", item.id, char:GetInventory():GetID())
  708. end
  709. end
  710. end
  711.  
  712. if (btn == KEY_F4) then
  713. local char = ply:GetCharacter()
  714. local charID = char:GetID()
  715. if DC_FastSlots[charID] and DC_FastSlots[charID][4] and DC_FastSlots[charID][4].model ~= "" then
  716. local item = char:GetInventory():HasItem(DC_FastSlots[charID][4].itemid)
  717. if item then
  718. InventoryAction("use", item.id, char:GetInventory():GetID())
  719. end
  720. end
  721. end
  722. end
  723.  
  724. do
  725. local COMMAND = {
  726. description = "Открыть инвентарь.",
  727. superAdminOnly = false
  728. }
  729.  
  730. function COMMAND:OnRun(client)
  731. openInv()
  732. end
  733.  
  734. ix.command.Add("openinventory", COMMAND)
  735. end
Add Comment
Please, Sign In to add comment