Advertisement
BazZziliuS

New Interface HappyRP IGS

Nov 22nd, 2022
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 49.49 KB | None | 0 0
  1. IGS.sh("utf8.lua")
  2.  
  3. if SERVER then
  4.     resource.AddWorkshop("2874026722") -- иконки
  5.     return
  6. end
  7.  
  8. utf8.len = string.utf8len
  9.  
  10. local function pX(a)
  11.     return a / 1920 * ScrW()
  12. end // Главная штучка, чтобы перенести это без лишнего труда с картинки в код.
  13.  
  14. /* Шрифты и материалы */
  15. surface.CreateFont('NM.Tab', {
  16.     font = 'PT Root UI Bold',
  17.     size = pX(20),
  18.     antialias = true,
  19.     extended = true
  20. })
  21.  
  22. surface.CreateFont('NM.TabSmall', {
  23.     font = 'PT Root UI Bold',
  24.     size = pX(18),
  25.     antialias = true,
  26.     extended = true
  27. })
  28.  
  29. surface.CreateFont('NM.Category', {
  30.     font = 'PT Root UI Bold',
  31.     size = pX(28),
  32.     antialias = true,
  33.     extended = true
  34. })
  35.  
  36. surface.CreateFont('NM.ItemPurchased', {
  37.     font = 'PT Root UI Bold',
  38.     size = pX(10),
  39.     antialias = true,
  40.     extended = true
  41. })
  42.  
  43. surface.CreateFont('NM.ItemName', {
  44.     font = 'PT Root UI Bold',
  45.     size = pX(20),
  46.     antialias = true,
  47.     extended = true
  48. })
  49.  
  50. surface.CreateFont('NM.ItemPrice', {
  51.     font = 'PT Root UI Bold',
  52.     size = pX(18),
  53.     antialias = true,
  54.     extended = true
  55. })
  56.  
  57. surface.CreateFont('NM.ItemOldPrice', {
  58.     font = 'PT Root UI Bold',
  59.     size = pX(14),
  60.     antialias = true,
  61.     extended = true
  62. })
  63.  
  64. surface.CreateFont('NM.ItemDesc', {
  65.     font = 'PT Root UI Medium',
  66.     size = pX(14),
  67.     antialias = true,
  68.     extended = true
  69. })
  70.  
  71. surface.CreateFont('NM.OpenedDesc', {
  72.     font = 'PT Root UI Bold',
  73.     size = pX(20),
  74.     antialias = true,
  75.     extended = true
  76. })
  77.  
  78. surface.CreateFont('NM.OpenedText', {
  79.     font = 'PT Root UI',
  80.     size = pX(16),
  81.     antialias = true,
  82.     extended = true
  83. })
  84.  
  85. surface.CreateFont('NM.TopPanel', {
  86.     font = 'PT Root UI Medium',
  87.     size = pX(16),
  88.     antialias = true,
  89.     extended = true
  90. })
  91.  
  92. surface.CreateFont('NM.Table', {
  93.     font = 'PT Root UI Bold',
  94.     size = pX(16),
  95.     antialias = true,
  96.     extended = true
  97. })
  98.  
  99. surface.CreateFont('NM.LastDate', {
  100.     font = 'PT Root UI',
  101.     size = pX(17),
  102.     antialias = true,
  103.     extended = true
  104. })
  105.  
  106. surface.CreateFont('NM.LastSum', {
  107.     font = 'PT Root UI Bold',
  108.     size = pX(22),
  109.     antialias = true,
  110.     extended = true
  111. })
  112.  
  113. surface.CreateFont('NM.ProfileName', {
  114.     font = 'PT Root UI Bold',
  115.     size = pX(16),
  116.     antialias = true,
  117.     extended = true
  118. })
  119.  
  120. surface.CreateFont('NM.ProfileSID', {
  121.     font = 'PT Root UI',
  122.     size = pX(16),
  123.     antialias = true,
  124.     extended = true
  125. })
  126.  
  127. surface.CreateFont('NM.ProfileDonate', {
  128.     font = 'PT Root UI Bold',
  129.     size = pX(14),
  130.     antialias = true,
  131.     extended = true
  132. })
  133.  
  134. surface.CreateFont('NM.Buttons', {
  135.     font = 'PT Root UI Medium',
  136.     size = pX(18),
  137.     antialias = true,
  138.     extended = true
  139. })
  140.  
  141. surface.CreateFont('NM.TYText', {
  142.     font = 'PT Root UI Bold',
  143.     size = pX(26),
  144.     antialias = true,
  145.     extended = true
  146. })
  147.  
  148. surface.CreateFont('NM.LogText', {
  149.     font = 'PT Root UI',
  150.     size = pX(18),
  151.     antialias = true,
  152.     extended = true
  153. })
  154.  
  155. surface.CreateFont('NM.DonateButton', {
  156.     font = 'PT Root UI Medium',
  157.     size = pX(18),
  158.     antialias = true,
  159.     extended = true
  160. })
  161.  
  162. local function matsmooth(mat)
  163.     return Material(mat, 'smooth')
  164. end
  165.  
  166. local close_mat = matsmooth('hrp/gui/donate/close.png')
  167. local shop_mat = matsmooth('hrp/gui/donate/shop.png')
  168. local shop_unactive_mat = matsmooth('hrp/gui/donate/shop_unactive.png')
  169. local profile_mat = matsmooth('hrp/gui/donate/profile.png')
  170. local profile_unactive_mat = matsmooth('hrp/gui/donate/profile_unactive.png')
  171. local go_mat = matsmooth('hrp/gui/donate/go.png')
  172. local grad_mat = matsmooth('hrp/gui/donate/grad.png')
  173. local buy_mat = matsmooth('hrp/gui/donate/buy.png')
  174. local heart_mat = matsmooth('hrp/gui/donate/heart.png')
  175. local coupon_mat = matsmooth('hrp/gui/donate/coupon.png')
  176.  
  177. /* Полезные функции */
  178. NM = {}
  179.  
  180. NM.Tabs = {
  181.     ['shop'] = {
  182.         ID = 1,
  183.         Name = 'Услуги',
  184.         Mats = {shop_mat, shop_unactive_mat}
  185.     },
  186.     ['profile'] = {
  187.         ID = 2,
  188.         Name = 'Профиль',
  189.         Mats = {profile_mat, profile_unactive_mat}
  190.     }
  191. }
  192. // Тут понятен формат, нужно делать VGUI, с приставкой nm_ (vgui.Register)
  193. if IGS.C.Inv_Enabled then
  194.     NM.Tabs["inventory"] = {
  195.         ID = 3,
  196.         Name = "Инвентарь",
  197.         Mats = {shop_mat, shop_unactive_mat}
  198.     }
  199. end
  200.  
  201. NM.OpenFirstTab = "shop"
  202.  
  203. NM.Buttons = {
  204.     ['profile_purchases'] = {
  205.         ID = 1,
  206.         Name = 'Покупки'
  207.     },
  208.     ['profile_donate'] = {
  209.         ID = 2,
  210.         Name = 'Пополнить баланс'
  211.     }
  212. } // Тут так же само
  213.  
  214. NM.PathToRefill = {
  215.     [1] = 'profile',
  216.     [2] = 'profile_donate'
  217. } // Легкий путь к пополнению счета (1 - Tab, 2 - Button)
  218.  
  219. function NM.CreateUI(t, f, p)
  220.     local parent
  221.  
  222.     if (not isfunction(f)) and (f ~= nil) then
  223.         parent = f
  224.     elseif not isfunction(p) and (p ~= nil) then
  225.         parent = p
  226.     end
  227.  
  228.     local v = vgui.Create(t, parent)
  229.  
  230.     if isfunction(f) then
  231.         f(v, parent)
  232.     elseif isfunction(p) then
  233.         p(v, f)
  234.     end
  235.  
  236.     return v
  237. end // Облегчает работу
  238.  
  239. local tabfr
  240.  
  241. function NM.OpenTab(tab, frame)
  242.     if IsValid(tabfr) then
  243.         tabfr:Remove()
  244.     end
  245.  
  246.     tabfr = NM.CreateUI('nm_' .. tab, function(self)
  247.         self:SetSize(pX(978), pX(530) - pX(54))
  248.         self:SetPos(0, pX(54))
  249.     end, frame)
  250. end
  251.  
  252. local btnfr
  253.  
  254. function NM.OpenButton(btn, frame)
  255.     if IsValid(btnfr) then
  256.         btnfr:Remove()
  257.     end
  258.  
  259.     btnfr = NM.CreateUI('nm_' .. btn, function(self)
  260.         self:SetSize(pX(781), pX(530) - pX(54))
  261.         self:SetPos(0, 0)
  262.     end, frame)
  263. end
  264.  
  265. function NM.GetItems()
  266.     local allcats = {}
  267.  
  268.     for k, v in pairs(IGS.GetItems()) do
  269.         if k ~= 0 and v.hidden ~= true and not allcats[v.category or 'Разное'] then
  270.             allcats[v.category or 'Разное'] = true
  271.         end
  272.     end
  273.  
  274.     return allcats
  275. end
  276.  
  277. function NM.FancyTerm(item)
  278.     local term = IGS.TermToStr(item)
  279.  
  280.     if term == "бесконечно" then
  281.         return "Навсегда"
  282.     elseif term == "единоразово" then
  283.         return "Одноразово"
  284.     else
  285.         return "На " .. term
  286.     end
  287. end
  288.  
  289. /* Меню */
  290. local fr
  291.  
  292. function NM.Menu()
  293.     if IsValid(fr) then
  294.         fr:Close()
  295.  
  296.         return
  297.     end
  298.  
  299.     local w, h = pX(978), pX(530)
  300.  
  301.     fr = NM.CreateUI('DFrame', function(self)
  302.         self.lblTitle:SetText('')
  303.         self:SetSize(w, h)
  304.         self:MakePopup()
  305.         self:Center()
  306.         self.btnMaxim:SetVisible(false)
  307.         self.btnMinim:SetVisible(false)
  308.  
  309.         function self:Paint(w, h)
  310.             draw.RoundedBox(8, 0, 0, w, h, Color(31, 31, 31))
  311.             draw.RoundedBoxEx(8, 0, self:GetTitleHeight(), pX(781), pX(476), Color(47, 47, 47), false, false, true)
  312.             draw.RoundedBoxEx(8, w - pX(85), self:GetTitleHeight() / 2 - pX(11), pX(22), pX(22), Color(35, 108, 0), false, true, false, true)
  313.             draw.SimpleText('+', 'NM.TopPanel', w - pX(74), self:GetTitleHeight() / 2, Color(255, 255, 255), 1, 1)
  314.             draw.RoundedBoxEx(8, w - pX(147), self:GetTitleHeight() / 2 - pX(11), pX(62), pX(22), Color(55, 55, 55), true, false, true, false)
  315.             draw.SimpleText(string.Comma(LocalPlayer():IGSFunds()) .. ' ₽', 'NM.TopPanel', w - pX(116), self:GetTitleHeight() / 2, Color(255, 255, 255), 1, 1)
  316.             draw.RoundedBox(0, 0, self:GetTitleHeight(), w, 1, Color(47, 47, 47))
  317.         end
  318.  
  319.         function self:GetTitleHeight()
  320.             return pX(54)
  321.         end
  322.  
  323.         local cbtn = pX(17)
  324.  
  325.         function self.btnClose:Paint(w, h)
  326.             surface.SetDrawColor(255, 255, 255, 255)
  327.             surface.SetMaterial(close_mat)
  328.             surface.DrawTexturedRect(0, 0, cbtn, cbtn)
  329.         end
  330.  
  331.         function self:PerformLayout()
  332.             self.btnClose:SetPos(self:GetWide() - pX(28) - cbtn, self:GetTitleHeight() / 2 - cbtn / 2)
  333.             self.btnClose:SetSize(cbtn, cbtn)
  334.         end
  335.  
  336.         function self:SwitchTab(tab)
  337.             self.ActiveTab = NM.Tabs[tab]
  338.             self.OpenedTab = NM.OpenTab(tab, self)
  339.         end
  340.  
  341.         -- local tab = next(NM.Tabs)
  342.         self:SwitchTab(NM.OpenFirstTab)
  343.     end)
  344.  
  345.     NM.CreateUI('DButton', function(self)
  346.         self:SetText('')
  347.         self:SetSize(pX(22), pX(22))
  348.         self:SetPos(w - pX(85), fr:GetTitleHeight() / 2 - pX(11))
  349.  
  350.         self.DoClick = function()
  351.             fr:SwitchTab(NM.PathToRefill[1])
  352.             tabfr:SwitchButton(NM.PathToRefill[2])
  353.         end
  354.  
  355.         self.Paint = function() end
  356.     end, fr)
  357.  
  358.     local textx, texty, iconx, iconwh, iconwhun = pX(54), fr:GetTitleHeight() / 2, pX(16), pX(26), pX(22)
  359.  
  360.     for k, v in pairs(NM.Tabs) do
  361.         NM.CreateUI('DButton', function(self)
  362.             self:SetText('')
  363.             self:SetSize(pX(223), fr:GetTitleHeight())
  364.             self:SetPos(pX(29) + pX(237 * (v.ID - 1)), 0)
  365.             self.Tab = k
  366.  
  367.             self.DoClick = function(self)
  368.                 if fr.ActiveTab == NM.Tabs[self.Tab] then return end
  369.                 fr:SwitchTab(self.Tab)
  370.             end
  371.  
  372.             function self:Paint(w, h)
  373.                 if fr.ActiveTab == NM.Tabs[self.Tab] then
  374.                     draw.RoundedBoxEx(8, 0, 0, w, h, Color(62, 62, 62), true, true)
  375.                     draw.SimpleText(v.Name, 'NM.Tab', textx, texty, Color(200, 200, 200), 0, 1)
  376.                     surface.SetDrawColor(255, 255, 255)
  377.                     surface.SetMaterial(v.Mats[1])
  378.                     surface.DrawTexturedRect(iconx, texty - iconwh / 2, iconwh, iconwh)
  379.                 else
  380.                     draw.RoundedBoxEx(8, 0, h * .17, w, h * .83, Color(55, 55, 55), true, true)
  381.                     draw.SimpleText(v.Name, 'NM.TabSmall', textx - pX(4), texty + h * .085, Color(105, 105, 105), 0, 1)
  382.                     surface.SetDrawColor(255, 255, 255)
  383.                     surface.SetMaterial(v.Mats[2])
  384.                     surface.DrawTexturedRect(iconx, texty - iconwhun / 2 + h * .085, iconwhun, iconwhun)
  385.                 end
  386.             end
  387.         end, fr)
  388.     end
  389. end
  390.  
  391. /* Тут дальше VGUI */
  392. /* Для магазина */
  393. local PANEL = {}
  394.  
  395. function PANEL:Init()
  396.     self.parent = self:GetParent()
  397.     self.scrollButton = vgui.Create('Panel', self)
  398.  
  399.     self.scrollButton.OnMousePressed = function(s, mb)
  400.         if (mb == MOUSE_LEFT and not self:GetParent().ShouldHideScrollbar) then
  401.             local _, my = s:CursorPos()
  402.             s.scrolling = true
  403.             s.mouseOffset = my
  404.         end
  405.     end
  406.  
  407.     self.scrollButton.OnMouseReleased = function(s, mb)
  408.         if (mb == MOUSE_LEFT) then
  409.             s.scrolling = false
  410.             s.mouseOffset = nil
  411.         end
  412.     end
  413.  
  414.     self.height = 0
  415. end
  416.  
  417. function PANEL:Think()
  418.     if (self.scrollButton.scrolling) then
  419.         if (not input.IsMouseDown(MOUSE_LEFT)) then
  420.             self.scrollButton:OnMouseReleased(MOUSE_LEFT)
  421.  
  422.             return
  423.         end
  424.  
  425.         local mx, my = self.scrollButton:CursorPos()
  426.         local diff = my - self.scrollButton.mouseOffset
  427.         local maxOffset = self.parent:GetCanvas():GetTall() - self.parent:GetTall()
  428.         local perc = (self.scrollButton.y + diff) / (self:GetTall() - self.height)
  429.         self.parent.yOffset = math.Clamp(perc * maxOffset, 0, maxOffset)
  430.         self.parent:InvalidateLayout()
  431.     end
  432. end
  433.  
  434. function PANEL:PerformLayout()
  435.     local maxOffset = self.parent:GetCanvas():GetTall() - self.parent:GetTall()
  436.     self:SetSize(2, self.parent:GetTall())
  437.     self:SetPos(self.parent:GetWide() - self:GetWide(), 0)
  438.     self.heightRatio = self.parent:GetTall() / self.parent:GetCanvas():GetTall()
  439.     self.height = math.Clamp(math.ceil(self.heightRatio * self.parent:GetTall()), 20, math.huge)
  440.     self.scrollButton:SetSize(self:GetWide(), self.height)
  441.     self.scrollButton:SetPos(0, math.Clamp((self.parent.yOffset / maxOffset), 0, 1) * (self:GetTall() - self.height))
  442. end
  443.  
  444. function PANEL:Paint(w, h)
  445.     if (self:GetParent().ShouldHideScrollbar) then return end
  446.     derma.SkinHook('Paint', 'UIScrollBar', self, w, h)
  447. end
  448.  
  449. function PANEL:OnMouseWheeled(delta)
  450.     self.parent:OnMouseWheeled(delta)
  451. end
  452.  
  453. vgui.Register('nm_scrollbar', PANEL, 'Panel')
  454. PANEL = {}
  455.  
  456. function PANEL:Init()
  457.     self.contentContainer = vgui.Create('Panel', self)
  458.     self.scrollBar = vgui.Create('nm_scrollbar', self)
  459.     self.yOffset = 0
  460.     self.ySpeed = 0
  461.     self.scrollSize = 4
  462.     self.SpaceTop = 0
  463.     self.Padding = 0
  464.  
  465.     function self.contentContainer:OnChildRemoved(child)
  466.         self:GetParent():PerformLayout()
  467.     end
  468. end
  469.  
  470. function PANEL:Reset()
  471.     self:GetCanvas():Clear(true)
  472.     self.yOffset = 0
  473.     self.ySpeed = 0
  474.     self.scrollSize = 1
  475.     self:PerformLayout()
  476. end
  477.  
  478. function PANEL:AddItem(child)
  479.     child:SetParent(self:GetCanvas())
  480.     self:PerformLayout()
  481. end
  482.  
  483. function PANEL:SetSpacing(i)
  484.     self.SpaceTop = i
  485. end
  486.  
  487. function PANEL:SetPadding(i)
  488.     self.Padding = i
  489. end
  490.  
  491. function PANEL:GetCanvas()
  492.     return self.contentContainer
  493. end
  494.  
  495. function PANEL:SetScrollSize(int)
  496.     self.scrollSize = int
  497. end
  498.  
  499. function PANEL:ScrollTo(y)
  500.     self.yOffset = y
  501.     self:InvalidateLayout()
  502. end
  503.  
  504. function PANEL:OnMouseWheeled(delta)
  505.     if ((delta > 0 and self.ySpeed < 0) or (delta < 0 and self.ySpeed > 0)) then
  506.         self.ySpeed = 0
  507.     else
  508.         self.ySpeed = self.ySpeed + (delta * self.scrollSize)
  509.     end
  510.  
  511.     self:PerformLayout()
  512. end
  513.  
  514. function PANEL:SetOffset(offSet)
  515.     local maxOffset = (self:GetCanvas():GetTall() - self:GetTall())
  516.  
  517.     if (maxOffset < 0) then
  518.         maxOffset = 0
  519.     end
  520.  
  521.     self.yOffset = math.Clamp(offSet, 0, maxOffset)
  522.     self:PerformLayout()
  523.     if (self.yOffset == 0 or self.yOffset == maxOffset) then return true end
  524. end
  525.  
  526. function PANEL:Think()
  527.     if (self.ySpeed ~= 0) then
  528.         if (self:SetOffset(self.yOffset - self.ySpeed)) then
  529.             self.ySpeed = 0
  530.         else
  531.             if (self.ySpeed < 0) then
  532.                 self.ySpeed = math.Clamp(self.ySpeed + (FrameTime() * self.scrollSize * 4), self.ySpeed, 0)
  533.             else
  534.                 self.ySpeed = math.Clamp(self.ySpeed - (FrameTime() * self.scrollSize * 4), 0, self.ySpeed)
  535.             end
  536.         end
  537.     end
  538. end
  539.  
  540. function PANEL:PerformLayout()
  541.     local canvas = self:GetCanvas()
  542.  
  543.     if (canvas:GetWide() ~= self:GetWide()) then
  544.         canvas:SetWide(self:GetWide())
  545.     end
  546.  
  547.     local y = 0
  548.     local lastChild
  549.  
  550.     for k, v in ipairs(canvas:GetChildren()) do
  551.         local childY = y + self.SpaceTop
  552.  
  553.         if (v.x ~= self.Padding or v.y ~= childY) then
  554.             v:SetPos(math.max(0, self.Padding), y + self.SpaceTop)
  555.         end
  556.  
  557.         if (v:GetWide() ~= self:GetWide() - self.Padding * 2) then
  558.             v:SetWide(math.min(self:GetWide(), self:GetWide() - self.Padding * 2))
  559.         end
  560.  
  561.         y = v.y + v:GetTall() + self.SpaceTop + self.Padding
  562.         lastChild = v
  563.     end
  564.  
  565.     y = lastChild and lastChild.y + lastChild:GetTall() or y
  566.  
  567.     if (canvas:GetTall() ~= y) then
  568.         canvas:SetTall(y)
  569.     end
  570.  
  571.     if (canvas:GetTall() <= self:GetTall() and self.scrollBar:IsVisible()) then
  572.         canvas:SetTall(self:GetTall())
  573.         self.scrollBar:SetVisible(false)
  574.     elseif (canvas:GetTall() > self:GetTall() and not self.scrollBar:IsVisible()) then
  575.         self.scrollBar:SetVisible(true)
  576.     end
  577.  
  578.     local maxOffset = (self:GetCanvas():GetTall() - self:GetTall())
  579.  
  580.     if (self.yOffset > maxOffset) then
  581.         self.yOffset = maxOffset
  582.     end
  583.  
  584.     if (self.yOffset < 0) then
  585.         self.yOffset = 0
  586.     end
  587.  
  588.     if (canvas.x ~= 0 or canvas.y ~= -self.yOffset) then
  589.         canvas:SetPos(0, -self.yOffset)
  590.         self.scrollBar:InvalidateLayout()
  591.     end
  592. end
  593.  
  594. function PANEL:IsAtMaxOffset()
  595.     local maxOffset = math.Clamp(self:GetCanvas():GetTall() - self:GetTall(), 0, math.huge)
  596.  
  597.     return self.yOffset == maxOffset
  598. end
  599.  
  600. function PANEL:Paint(w, h)
  601. end
  602.  
  603. function PANEL:HideScrollbar(bool)
  604.     self.ShouldHideScrollbar = bool
  605. end
  606.  
  607. function PANEL:DockToFrame()
  608.     local p = self:GetParent()
  609.     local x, y = p:GetDockPos()
  610.     self:SetPos(x, y)
  611.     self:SetSize(p:GetWide() - 10, p:GetTall() - (y + 5))
  612. end
  613.  
  614. vgui.Register('nm_scrollpanel', PANEL, 'Panel')
  615. PANEL = {}
  616.  
  617. function PANEL:Init()
  618.     self.Rows = {}
  619.     self.HideInvisible = true
  620.     self.RowHeight = 25
  621.     self:SetPadding(-1)
  622.  
  623.     self.scrollBar.Paint = function(s, w, h)
  624.         draw.RoundedBox(0, 0, s.scrollButton.y, w, s.height, Color(255, 255, 255))
  625.     end
  626. end
  627.  
  628. function PANEL:SetRowHeight(height)
  629.     self.RowHeight = height
  630. end
  631.  
  632. function PANEL:AddCustomRow(row, disabled)
  633.     self:AddItem(row)
  634.     self.Rows[#self.Rows + 1] = row
  635.  
  636.     return row
  637. end
  638.  
  639. function PANEL:AddRow(value, disabled)
  640.     local row = NM.CreateUI('DButton', function(s)
  641.         s:SetText('')
  642.         s:SetTall(self.RowHeight)
  643.  
  644.         if (disabled == true) then
  645.             s:SetDisabled(true)
  646.         end
  647.  
  648.         s.Paint = function(s, w, h)
  649.             draw.SimpleText(tostring(value), 'NM.Category', pX(29), h / 2, Color(255, 255, 255, 255), 0, 1)
  650.         end
  651.     end)
  652.  
  653.     self:AddItem(row)
  654.     self.Rows[#self.Rows + 1] = row
  655.  
  656.     row.DoClick = function()
  657.         row.Active = true
  658.  
  659.         if IsValid(self.Selected) then
  660.             self.Selected.Active = false
  661.         end
  662.  
  663.         self.Selected = row
  664.     end
  665.  
  666.     return row
  667. end
  668.  
  669. function PANEL:AddSpacer(value)
  670.     return self:AddRow(value, true)
  671. end
  672.  
  673. function PANEL:GetSelected()
  674.     return self.Selected
  675. end
  676.  
  677. vgui.Register('nm_listview', PANEL, 'nm_scrollpanel')
  678. PANEL = {}
  679.  
  680. function PANEL:Init()
  681.     self:SetText('')
  682.     self.ButtonBuy = NM.CreateUI('DButton', self)
  683.     self.ModelIcon = NM.CreateUI('DModelPanel', self)
  684. end
  685.  
  686. function PANEL:PerformLayout()
  687.     local btnwh = pX(25)
  688.     self.ButtonBuy:SetPos(self:GetWide() - pX(12) - btnwh, self:GetTall() - btnwh - pX(12))
  689.     self.ButtonBuy:SetSize(btnwh, btnwh)
  690.     self.ButtonBuy:SetText('')
  691.  
  692.     self.ButtonBuy.Paint = function(s, w, h)
  693.         surface.SetDrawColor(255, 255, 255, 255)
  694.         surface.SetMaterial(buy_mat)
  695.         surface.DrawTexturedRect(0, 0, w, h)
  696.     end
  697.  
  698.     local iconwh = pX(80)
  699.     self.ModelIcon:SetPos(self:GetWide() / 2 - iconwh / 2, pX(6))
  700.     self.ModelIcon:SetSize(iconwh, iconwh)
  701. end
  702.  
  703. function PANEL:Paint(w, h)
  704.     draw.RoundedBox(8, 0, 0, w, h, self.MainFrame.ActiveItem == self.Item and Color(223, 223, 223) or Color(68, 68, 68))
  705.     draw.RoundedBox(8, 1, 1, w - 2, h - 2, Color(55, 55, 55))
  706.     local item = IGS.GetItem(self.Item)
  707.     local name = item.name
  708.  
  709.     if utf8.len(name) > 16 then
  710.         name = utf8.sub(name, 0, 14) .. '...'
  711.     end
  712.  
  713.     draw.SimpleText(name, 'NM.ItemName', pX(16), h - pX(60), Color(255, 255, 255), 0, 4)
  714.     local tw, th = draw.SimpleText('Открыть описание', 'NM.ItemDesc', pX(16), h - pX(45), Color(105, 105, 105), 0, 4)
  715.     surface.SetDrawColor(255, 255, 255, 255)
  716.     surface.SetMaterial(go_mat)
  717.     surface.DrawTexturedRect(pX(16) + tw + pX(10), h - pX(45) - th / 2 - pX(1), pX(4), pX(6))
  718.  
  719.     if item.discounted_from then
  720.         tw, th = draw.SimpleText(item.discounted_from .. ' ₽', 'NM.ItemOldPrice', pX(16), h - pX(30), Color(105, 105, 105), 0, 4)
  721.         local liney = h - pX(34)
  722.         surface.SetDrawColor(255, 255, 255, 255)
  723.         surface.DrawLine(pX(16), liney - th * .5, pX(16) + tw, liney)
  724.     end
  725.  
  726.     draw.SimpleText(item.price .. ' ₽', 'NM.ItemPrice', pX(16), h - pX(16), Color(255, 255, 255), 0, 4)
  727.  
  728.     if item.icon and not item.icon.isModel then
  729.         surface.SetDrawColor(255, 255, 255, 255)
  730.         surface.SetMaterial(texture.Get(item.uid) or close_mat)
  731.         local iconwh = pX(80)
  732.         surface.DrawTexturedRect(w / 2 - iconwh / 2, pX(6), iconwh, iconwh)
  733.         surface.SetDrawColor(255, 255, 255, 180)
  734.         surface.SetMaterial(grad_mat)
  735.         surface.DrawTexturedRect(pX(1), pX(12), w - pX(2), iconwh)
  736.     end
  737. end
  738.  
  739. function PANEL:SetInfo(uid, frame)
  740.     self.Item = uid
  741.     self.MainFrame = frame
  742.  
  743.     self.DoClick = function()
  744.         frame:OpenItem(uid)
  745.     end
  746.  
  747.     local item = IGS.GetItem(self.Item)
  748.  
  749.     self.ButtonBuy.DoClick = function()
  750.         IGS.BoolRequest('Подтверждение покупки', 'Вы действительно хотите купить ' .. item.name .. '?', function(a)
  751.             if a then
  752.                 frame:BuyItem(uid)
  753.             end
  754.         end)
  755.     end
  756.  
  757.     self.ModelIcon.DoClick = function()
  758.         frame:OpenItem(uid)
  759.     end
  760.  
  761.     if item.icon and not item.icon.isModel then
  762.         texture.Create(item.uid):Download(item.icon.icon)
  763.         self.ModelIcon:SetVisible(false)
  764.     elseif item.icon and item.icon.isModel then
  765.         self.ModelIcon:SetVisible(true)
  766.         self.ModelIcon:SetModel(item.icon.icon)
  767.         local mn, mx = self.ModelIcon.Entity:GetRenderBounds()
  768.         local size = 0
  769.         size = math.max(size, math.abs(mn.x) + math.abs(mx.x))
  770.         size = math.max(size, math.abs(mn.y) + math.abs(mx.y))
  771.         size = math.max(size, math.abs(mn.z) + math.abs(mx.z))
  772.         self.ModelIcon:SetFOV(30)
  773.         self.ModelIcon:SetCamPos(Vector(size, size, size))
  774.         self.ModelIcon:SetLookAt((mn + mx) * 0.5)
  775.     end
  776. end
  777.  
  778. vgui.Register('nm_shop_button', PANEL, 'DButton')
  779. PANEL = {}
  780. local btnwh = pX(168)
  781.  
  782. function PANEL:PerformLayout()
  783.     local c = 0
  784.     local o = 0
  785.  
  786.     for k, v in ipairs(self:GetChildren()) do
  787.         v:SetPos(pX(29) + (o * (btnwh + pX(20))), c * (btnwh + pX(20)))
  788.         v:SetSize(btnwh, btnwh)
  789.  
  790.         if k % 4 == 1 then
  791.             o = 1
  792.         elseif k % 4 == 2 then
  793.             o = 2
  794.         elseif k % 4 == 3 then
  795.             o = 3
  796.         elseif k % 4 == 0 then
  797.             c = c + 1
  798.             o = 0
  799.         end
  800.     end
  801. end
  802.  
  803. function PANEL:AddItem(uid, frame)
  804.     local btn = NM.CreateUI('nm_shop_button', self)
  805.     btn:SetInfo(uid, frame)
  806.     self:SetTall(math.ceil(#self:GetChildren() * (1 / 4)) * btnwh + math.ceil(#self:GetChildren() * (pX(20) / 4)))
  807. end
  808.  
  809. vgui.Register('nm_shop_category', PANEL, 'Panel')
  810.  
  811. /* Магазин */
  812. PANEL = {}
  813.  
  814. function PANEL:Init()
  815.     local cat
  816.     self.Cats = {}
  817.     self.List = NM.CreateUI('nm_listview', self)
  818.     self.List.Paint = function() end
  819.  
  820.     for catitem, _ in pairs(NM.GetItems()) do
  821.         self.List:AddSpacer(catitem):SetTall(pX(72))
  822.         cat = NM.CreateUI('nm_shop_category')
  823.  
  824.         for k, v in pairs(IGS.GetItems()) do
  825.             v.category = v.category or 'Разное'
  826.             if k ~= 0 and v.hidden ~= true and v.category == catitem then
  827.                 cat:AddItem(k, self)
  828.             end
  829.         end
  830.  
  831.         self.List:AddItem(cat)
  832.     end
  833.  
  834.     self:OpenItem(1)
  835. end
  836.  
  837. function PANEL:PerformLayout()
  838.     self.List:SetPos(0, 0)
  839.     self.List:SetSize(self:GetWide() - pX(197), self:GetTall())
  840. end
  841.  
  842. function PANEL:OpenItem(uid)
  843.     if self.ActiveItem == uid then return end
  844.     self.ActiveItem = uid
  845.  
  846.     if IsValid(self.OpenedItem) then
  847.         self.OpenedItem:Remove()
  848.         self.OpenedItemInfo:Remove()
  849.         self.OpenedItemInfo.Scroll:Remove()
  850.     end
  851.  
  852.     self.OpenedItem = NM.CreateUI('nm_shop_button', self)
  853.     self.OpenedItem:SetInfo(uid, self)
  854.     self.OpenedItem:SetPos(pX(978) - pX(14) - btnwh, pX(14))
  855.     self.OpenedItem:SetSize(btnwh, btnwh)
  856.  
  857.     local item = IGS.GetItem(uid)
  858.     self.OpenedItem.Paint = function(s, w, h)
  859.         draw.RoundedBox(8, 0, 0, w, h, Color(68, 68, 68))
  860.         draw.RoundedBox(8, 1, 1, w - 2, h - 2, Color(55, 55, 55))
  861.         local name = item.name
  862.  
  863.         if utf8.len(name) > 16 then
  864.             name = utf8.sub(name, 0, 14) .. '...'
  865.         end
  866.  
  867.         if s.Purchased then
  868.             draw.SimpleText('Куплено: ' .. s.Purchased, 'NM.ItemPurchased', w / 2, h - pX(160), Color(255, 255, 255), 1, 1)
  869.         end
  870.  
  871.         draw.SimpleText(name, 'NM.ItemName', pX(16), h - pX(60), Color(255, 255, 255), 0, 4)
  872.         draw.SimpleText('Действует ' .. IGS.TermToStr(item:Term()), 'NM.ItemDesc', pX(16), h - pX(45), Color(105, 105, 105), 0, 4)
  873.  
  874.         if item.discounted_from then
  875.             tw, th = draw.SimpleText(item.discounted_from .. ' ₽', 'NM.ItemOldPrice', pX(16), h - pX(30), Color(105, 105, 105), 0, 4)
  876.             local liney = h - pX(34)
  877.             surface.SetDrawColor(255, 255, 255, 255)
  878.             surface.DrawLine(pX(16), liney - th * .5, pX(16) + tw, liney)
  879.         end
  880.  
  881.         draw.SimpleText(item.price .. ' ₽', 'NM.ItemPrice', pX(16), h - pX(16), Color(255, 255, 255), 0, 4)
  882.  
  883.         if item.icon and not item.icon.isModel then
  884.             surface.SetDrawColor(255, 255, 255, 255)
  885.             surface.SetMaterial(texture.Get(item.uid) or close_mat)
  886.             local iconwh = pX(80)
  887.             surface.DrawTexturedRect(w / 2 - iconwh / 2, pX(6), iconwh, iconwh)
  888.             surface.SetDrawColor(255, 255, 255, 180)
  889.             surface.SetMaterial(grad_mat)
  890.             surface.DrawTexturedRect(pX(1), pX(12), w - pX(2), iconwh)
  891.         end
  892.     end
  893.  
  894.     self.OpenedItemInfo = NM.CreateUI('DPanel', self)
  895.     self.OpenedItemInfo:SetText('')
  896.     local oifw, oifh = pX(197), pX(280)
  897.     self.OpenedItemInfo:SetPos(pX(978) - oifw, pX(530) - pX(54) - oifh)
  898.     self.OpenedItemInfo:SetSize(oifw, oifh)
  899.  
  900.     self.OpenedItemInfo.Paint = function(s, w, h)
  901.         draw.RoundedBox(0, 0, 1, w, 1, Color(58, 58, 58))
  902.         draw.SimpleText('Описание', 'NM.OpenedDesc', pX(14), pX(14), Color(134, 134, 134))
  903.     end
  904.  
  905.     self.OpenedItemInfo.Scroll = NM.CreateUI('nm_listview', self)
  906.     self.OpenedItemInfo.Scroll:SetPos(pX(978) - oifw + pX(14), pX(530) - pX(10) - oifh)
  907.     self.OpenedItemInfo.Scroll:SetSize(oifw - pX(28), oifh - pX(60))
  908.     self.OpenedItemInfo.Scroll.Paint = function() end
  909.     local txt = string.Wrap('NM.OpenedText', item.description, self.OpenedItemInfo.Scroll:GetWide())
  910.  
  911.     for k, v in ipairs(txt) do
  912.         local lbl = NM.CreateUI('DLabel', function(s, p)
  913.             s:SetText(v)
  914.             s:SetFont('NM.OpenedText')
  915.             s:SizeToContents()
  916.         end)
  917.  
  918.         self.OpenedItemInfo.Scroll:AddItem(lbl)
  919.     end
  920.  
  921.     if (item.swep and LocalPlayer():HasPurchase(item:UID())) then
  922.         self.OpenedItemInfo.CheckBox = NM.CreateUI('DCheckBox', self.OpenedItem)
  923.         self.OpenedItemInfo.CheckBox:Dock(TOP)
  924.         self.OpenedItemInfo.CheckBox:DockMargin(0,5,0,0)
  925.         self.OpenedItemInfo.CheckBox:SetTall(pX(20))
  926.         local should_give = LocalPlayer():GetNWBool("igs.gos." .. item:ID())
  927.         self.OpenedItemInfo.CheckBox:SetValue(should_give)
  928.         self.OpenedItemInfo.CheckBox:SetText('')
  929.         self.OpenedItemInfo.CheckBox.OnChange = function(s, give)
  930.             net.Start("IGS.GiveOnSpawnWep")
  931.                 net.WriteIGSItem(item)
  932.                 net.WriteBool(give)
  933.             net.SendToServer()
  934.         end
  935.     end
  936. end
  937.  
  938. local function purchase(ITEM, msg)
  939.     IGS.Purchase(ITEM:UID(), function(errMsg, dbID)
  940.         if errMsg then
  941.             IGS.ShowNotify(errMsg, 'Ошибка покупки')
  942.             surface.PlaySound('ambient/voices/citizen_beaten1.wav')
  943.  
  944.             return
  945.         end
  946.  
  947.         msg.Purchased = msg.Purchased or 0
  948.         msg.Purchased = msg.Purchased + 1
  949.  
  950.         if not ITEM:IsStackable() then
  951.             if not IGS.C.Inv_Enabled then
  952.                 IGS.ShowNotify('Спасибо за покупку. Это было просто, правда? :)', 'Успешная покупка')
  953.  
  954.                 return
  955.             end
  956.  
  957.             IGS.BoolRequest('Успешная покупка', 'Спасибо за покупку. Она находится в вашем /donate инвентаре.\n\nАктивировать ее сейчас?', function(yes)
  958.                 if not yes then return end
  959.                 IGS.ProcessActivate(dbID)
  960.             end)
  961.         end
  962.  
  963.         surface.PlaySound('ambient/office/coinslot1.wav')
  964.     end)
  965. end
  966.  
  967. function PANEL:BuyItem(uid)
  968.     if self.ActiveItem ~= uid then
  969.         self:OpenItem(uid)
  970.     end
  971.  
  972.     purchase(IGS.GetItem(uid), self.OpenedItem)
  973. end
  974.  
  975. vgui.Register('nm_shop', PANEL, 'Panel')
  976.  
  977. /* Профиль */
  978. PANEL = {}
  979.  
  980. function PANEL:Init()
  981.     self.Avatar = NM.CreateUI('AvatarImage', function(s)
  982.         local size = pX(76)
  983.         s:SetSize(size, size)
  984.         s:SetPos(pX(844), pX(28))
  985.         s:SetPlayer(LocalPlayer(), size)
  986.     end, self)
  987.  
  988.     for k, v in pairs(NM.Buttons) do
  989.         NM.CreateUI('DButton', function(s)
  990.             s:SetText('')
  991.             s:SetSize(pX(167), pX(43))
  992.             s:SetPos(pX(796), pX(215) + pX(53 * (v.ID - 1)))
  993.             s.Button = k
  994.  
  995.             s.DoClick = function(s)
  996.                 if self.ActiveButton == NM.Buttons[s.Button] then return end
  997.                 self:SwitchButton(s.Button)
  998.             end
  999.  
  1000.             s.Paint = function(s, w, h)
  1001.                 if self.ActiveButton == NM.Buttons[s.Button] then
  1002.                     draw.RoundedBox(8, 0, 0, w, h, Color(255, 255, 255))
  1003.                     draw.SimpleText(v.Name, 'NM.Buttons', w / 2, h / 2, Color(31, 31, 31), 1, 1)
  1004.                 else
  1005.                     draw.RoundedBox(8, 0, 0, w, h, Color(255, 255, 255))
  1006.                     draw.RoundedBox(8, pX(1), pX(1), w - pX(2), h - pX(2), Color(31, 31, 31))
  1007.                     draw.SimpleText(v.Name, 'NM.Buttons', w / 2, h / 2, Color(255, 255, 255), 1, 1)
  1008.                 end
  1009.             end
  1010.         end, self)
  1011.     end
  1012.  
  1013.     local tab = next(NM.Buttons)
  1014.     self:SwitchButton(tab)
  1015. end
  1016.  
  1017. local box1, box2 = pX(167), pX(86)
  1018.  
  1019. function PANEL:Paint(w, h)
  1020.     local box1pos = w - box1 - pX(15)
  1021.     draw.RoundedBox(8, box1pos, pX(18), box1, box1, Color(47, 47, 47))
  1022.     draw.RoundedBox(8, box1pos + box2 / 2, pX(23), box2, box2, Color(31, 31, 31))
  1023.     local lp = LocalPlayer()
  1024.     local textx, texty = w - pX(197) / 2, pX(18) + box2
  1025.     draw.SimpleText(lp:GetName(), 'NM.ProfileName', textx, texty + pX(10), Color(255, 255, 255), 1, 3)
  1026.     local linew = pX(86)
  1027.     draw.RoundedBox(0, textx - linew / 2, texty + pX(28), linew, 1, Color(58, 58, 58))
  1028.     draw.SimpleText(lp:SteamID(), 'NM.ProfileSID', textx, texty + pX(30), Color(131, 131, 131), 1, 3)
  1029.     draw.RoundedBox(0, textx - linew / 2, texty + pX(48), linew, 1, Color(58, 58, 58))
  1030.     draw.SimpleText('Всего пополнено: ' .. string.Comma(IGS.TotalTransaction(lp)) .. ' ₽', 'NM.ProfileDonate', textx, texty + pX(56), Color(255, 255, 255), 1, 3)
  1031. end
  1032.  
  1033. function PANEL:SwitchButton(tab)
  1034.     self.ActiveButton = NM.Buttons[tab]
  1035.     self.OpenedButton = NM.OpenButton(tab, self, true)
  1036. end
  1037.  
  1038. vgui.Register('nm_profile', PANEL, 'Panel')
  1039.  
  1040. /* Покупки */
  1041. PANEL = {}
  1042.  
  1043. function PANEL:Init()
  1044.     self.List = NM.CreateUI('nm_listview', self)
  1045.     self.PanelList = NM.CreateUI('DPanel', self)
  1046.     self:GetParent().LastTransactions = {}
  1047.  
  1048.     self.PanelList.Paint = function(s, w, h)
  1049.         draw.RoundedBoxEx(8, 0, 0, pX(703), pX(34), Color(31, 31, 31), true, true)
  1050.         draw.SimpleText('Сервер', 'NM.Table', pX(30), pX(10), Color(105, 105, 105))
  1051.         draw.SimpleText('Предмет', 'NM.Table', pX(193), pX(10), Color(105, 105, 105))
  1052.         draw.SimpleText('Куплен', 'NM.Table', pX(359), pX(10), Color(105, 105, 105))
  1053.         draw.SimpleText('Истечет', 'NM.Table', pX(456), pX(10), Color(105, 105, 105))
  1054.         draw.SimpleText('Сумма', 'NM.Table', pX(556), pX(10), Color(105, 105, 105))
  1055.         draw.SimpleText('Баланс', 'NM.Table', pX(638), pX(10), Color(105, 105, 105))
  1056.         draw.RoundedBoxEx(8, 0, h - pX(17), pX(703), pX(17), Color(31, 31, 31), false, false, true, true)
  1057.     end
  1058.  
  1059.     self.PanelList:SetMouseInputEnabled(false)
  1060.  
  1061.     self.List.Paint = function(s, w, h)
  1062.         draw.RoundedBox(8, 0, 0, w, h, Color(31, 31, 31))
  1063.     end
  1064.  
  1065.     self.List:AddSpacer(''):SetTall(pX(37))
  1066.  
  1067.     self.List.scrollBar.Paint = function(s, w, h)
  1068.         draw.RoundedBox(0, 0, s.scrollButton.y, 2, s.height, Color(255, 255, 255))
  1069.     end
  1070.  
  1071.     local mybal = LocalPlayer():IGSFunds()
  1072.  
  1073.     IGS.GetMyTransactions(function(dat)
  1074.         if not IsValid(self.List) then return end
  1075.  
  1076.         for i, v in ipairs(dat) do
  1077.             v.note = v.note or '-'
  1078.  
  1079.             local function name_or_uid(sUid)
  1080.                 local ITEM = IGS.GetItemByUID(sUid)
  1081.  
  1082.                 return ITEM.isnull and sUid or ITEM:Name()
  1083.             end
  1084.  
  1085.             if i == #dat then
  1086.                 self.List:AddSpacer(''):SetTall(pX(20))
  1087.             end
  1088.  
  1089.             if v.note:StartWith('A: ') or v.note:StartWith('C: ') then
  1090.                 self:GetParent().LastTransactions[#self:GetParent().LastTransactions + 1] = v
  1091.                 continue
  1092.             end
  1093.  
  1094.             if not v.note:StartWith('P: ') then continue end
  1095.             mybal = mybal - v.sum
  1096.             local sv_name = IGS.ServerName(v.server)
  1097.             local ITEM = IGS.GetItemByUID(name_or_uid(v.note:sub(4)))
  1098.             local sName = ITEM.isnull and v.note:sub(4) or ITEM:Name()
  1099.             panel = NM.CreateUI('DPanel')
  1100.             panel:SetPos(0, pX(22) * i)
  1101.             panel:SetSize(pX(725), pX(20))
  1102.  
  1103.             panel.Paint = function(s, w, h)
  1104.                 draw.SimpleText(sv_name, 'NM.Table', pX(52), 0, Color(255, 255, 255), 1)
  1105.                 draw.SimpleText(sName, 'NM.Table', pX(218), 0, Color(255, 255, 255), 1)
  1106.                 draw.SimpleText(IGS.TimestampToDate(v.date) or 'Никогда', 'NM.Table', pX(380), 0, Color(255, 255, 255), 1)
  1107.                 draw.SimpleText(ITEM.termin ~= 0 and IGS.TimestampToDate(v.date + ITEM.termin * 86400) or 'Никогда', 'NM.Table', pX(480), 0, Color(255, 255, 255), 1)
  1108.                 draw.SimpleText(string.Comma(v.sum) .. ' ₽', 'NM.Table', pX(576), 0, Color(255, 255, 255), 1)
  1109.                 draw.SimpleText(string.Comma(mybal) .. ' ₽', 'NM.Table', pX(660), 0, Color(255, 255, 255), 1)
  1110.             end
  1111.  
  1112.             self.List:AddItem(panel)
  1113.         end
  1114.     end)
  1115. end
  1116.  
  1117. function PANEL:PerformLayout()
  1118.     self.List:SetSize(pX(725), pX(244))
  1119.     self.List:SetPos(pX(28), pX(63))
  1120.     self.PanelList:SetSize(pX(725), pX(244))
  1121.     self.PanelList:SetPos(pX(28), pX(63))
  1122. end
  1123.  
  1124. function PANEL:Paint(w, h)
  1125.     draw.SimpleText('Последние покупки', 'NM.Category', pX(29), pX(36), Color(255, 255, 255), 0, 1)
  1126.     draw.RoundedBox(0, 0, h - pX(150), w, 1, Color(58, 58, 58))
  1127.     draw.SimpleText('Ваши последние пополнения', 'NM.Category', pX(29), h - pX(125), Color(255, 255, 255), 0, 1)
  1128.  
  1129.     if self:GetParent().LastTransactions[1] then
  1130.         for k = 1, #self:GetParent().LastTransactions do
  1131.             local v = self:GetParent().LastTransactions[k]
  1132.             local x = pX(29) + ((k - 1) * pX(188))
  1133.             draw.RoundedBox(8, x, h - pX(100), pX(160), pX(70), Color(31, 31, 31))
  1134.             draw.RoundedBox(0, x + pX(28), h - pX(64), pX(100), pX(1), Color(49, 49, 49))
  1135.             draw.SimpleText(os.date('%d.%m.%Y - %H:%M', v.date), 'NM.LastDate', x + pX(80), h - pX(80), Color(255, 255, 255), 1, 1)
  1136.             draw.SimpleText(v.sum .. ' ₽', 'NM.LastSum', x + pX(80), h - pX(48), Color(255, 255, 255), 1, 1)
  1137.         end
  1138.     else
  1139.         draw.SimpleText('Вы еще не пополняли счет, или делали это давно!', 'NM.Category', w / 2, h - pX(70), Color(105, 105, 105), 1, 1)
  1140.     end
  1141. end
  1142.  
  1143. vgui.Register('nm_profile_purchases', PANEL, 'Panel')
  1144.  
  1145. /* Пополнение баланса */
  1146. PANEL = {}
  1147.  
  1148. local function niceSum(i, iFallback)
  1149.     return math.Truncate(tonumber(i) or iFallback, 2)
  1150. end
  1151.  
  1152. function PANEL:Init()
  1153.     self.Purchase = NM.CreateUI('DButton', function(s)
  1154.         s:SetText('')
  1155.         s.Text = 'Пополнить баланс на ? рублей'
  1156.         s:SetDisabled(true)
  1157.         s:SetSize(pX(277), pX(43))
  1158.         s:SetPos(pX(29), pX(236))
  1159.  
  1160.         s.DoClick = function()
  1161.             local want_money = niceSum(self.EntrySum:GetValue())
  1162.  
  1163.             if not want_money then
  1164.                 self.LogPanel:AddRecord('Указана некорректная сумма пополнения', false)
  1165.  
  1166.                 return
  1167.             elseif want_money < IGS.GetMinCharge() then
  1168.                 self.LogPanel:AddRecord('Минимальная сумма пополнения ' .. PL_MONEY(IGS.GetMinCharge()), false)
  1169.  
  1170.                 return
  1171.             end
  1172.  
  1173.             self.LogPanel:AddRecord('Запрос цифровой подписи запроса от сервера...')
  1174.  
  1175.             IGS.GetPaymentURL(want_money, function(url)
  1176.                 IGS.OpenURL(url, 'Процедура пополнения счета')
  1177.                 if not IsValid(self) then return end
  1178.                 self.LogPanel:AddRecord('Подпись получена. начинаем процесс оплаты')
  1179.  
  1180.                 timer.Simple(.7, function()
  1181.                     self.LogPanel:AddRecord('Счет пополнится моментально или после перезахода')
  1182.                 end)
  1183.             end)
  1184.         end
  1185.  
  1186.         s.Paint = function(s, w, h)
  1187.             draw.RoundedBox(4, 0, 0, w, h, s:GetDisabled() and Color(105, 105, 105) or Color(255, 255, 255))
  1188.             draw.SimpleText(s.Text, 'NM.DonateButton', w / 2, h / 2, Color(0, 0, 0), 1, 1)
  1189.         end
  1190.     end, self)
  1191.  
  1192.     NM.CreateUI('DButton', function(s)
  1193.         s:SetText('')
  1194.         s:SetSize(pX(43), pX(43))
  1195.         s:SetPos(pX(318), pX(236))
  1196.  
  1197.         s.DoClick = function()
  1198.             IGS.WIN.ActivateCoupon()
  1199.         end
  1200.  
  1201.         local matsize = pX(22)
  1202.  
  1203.         s.Paint = function(s, w, h)
  1204.             draw.RoundedBox(4, 0, 0, w, h, Color(255, 255, 255))
  1205.             draw.RoundedBox(4, pX(1), pX(1), w - pX(2), h - pX(2), Color(47, 47, 47))
  1206.             surface.SetDrawColor(255, 255, 255, 255)
  1207.             surface.SetMaterial(coupon_mat)
  1208.             surface.DrawTexturedRect(w / 2 - matsize / 2, h / 2 - matsize / 2, matsize, matsize)
  1209.         end
  1210.     end, self)
  1211.  
  1212.     self.EntrySum = NM.CreateUI('DTextEntry', function(s)
  1213.         s:SetSize(pX(332), pX(43))
  1214.         s:SetPos(pX(29), pX(185))
  1215.         s:SetNumeric(true)
  1216.  
  1217.         s.Paint = function(s, w, h)
  1218.             draw.RoundedBox(4, 0, 0, w, h, Color(255, 255, 255))
  1219.             draw.RoundedBox(4, pX(1), pX(1), w - pX(2), h - pX(2), Color(47, 47, 47))
  1220.             draw.SimpleText(s:GetValue() == '' and 'Сумма доната' or s:GetValue(), 'NM.LogText', pX(20), h / 2, s:GetValue() == '' and Color(140, 140, 140) or Color(255, 255, 255), 0, 1)
  1221.         end
  1222.  
  1223.         s.Think = function(s)
  1224.             local rub = tonumber(s:GetValue()) or '?'
  1225.             self.Purchase.Text = 'Пополнить баланс на ' .. rub .. ' рублей'
  1226.             self.Purchase:SetDisabled(rub == '?')
  1227.         end
  1228.     end, self)
  1229.  
  1230.     self.LogPanel = NM.CreateUI('nm_listview', function(log)
  1231.         log:SetSize(pX(330), pX(138))
  1232.         log:SetPos(pX(419), pX(170))
  1233.         log.Paint = function(s, w, h) end
  1234.  
  1235.         function log:AddRecord(text, pay)
  1236.             local col = (pay == true and IGS.col.LOG_SUCCESS) or (pay == false and IGS.col.LOG_ERROR) or IGS.col.LOG_NORMAL
  1237.             text = '> ' .. os.date('%H:%M:%S', os.time()) .. '\n' .. text
  1238.             local y = pX(2)
  1239.  
  1240.             for i, line in ipairs(string.Wrap('NM.LogText', text, log:GetWide())) do
  1241.                 log:AddItem(NM.CreateUI('DLabel', function(l)
  1242.                     l:SetPos(0, y)
  1243.                     l:SetText(line)
  1244.                     l:SetFont('NM.LogText')
  1245.                     l:SizeToContents()
  1246.                     l:SetTextColor(i == 1 and IGS.col.HIGHLIGHTING or col)
  1247.                     y = y + l:GetTall()
  1248.                 end, log))
  1249.             end
  1250.  
  1251.             log:ScrollTo(log:GetCanvas():GetTall())
  1252.         end
  1253.     end, self)
  1254.  
  1255.     local function log(delay, text, status)
  1256.         timer.Simple(delay, function()
  1257.             if not IsValid(self.LogPanel) then return end
  1258.             self.LogPanel:AddRecord(text, status)
  1259.         end)
  1260.     end
  1261.  
  1262.     log(0, 'Открыт диалог пополнения счета', nil)
  1263.     log(math.random(3), 'Соединение установлено!', true)
  1264.     log(math.random(20, 40), 'Деньги будут зачислены мгновенно и автоматически', nil)
  1265. end
  1266.  
  1267. function PANEL:Paint(w, h)
  1268.     draw.RoundedBox(8, pX(29), pX(13), w - pX(58), pX(100), Color(31, 31, 31))
  1269.     local heartsize = pX(27)
  1270.     surface.SetDrawColor(255, 255, 255, 255)
  1271.     surface.SetMaterial(heart_mat)
  1272.     surface.DrawTexturedRect(pX(36), pX(24), heartsize, heartsize)
  1273.     local txt = string.Wrap('NM.TYText', '       Все пожертвования материально помогают нам в продвижении и улучшении проекта. Пополняя баланс, вы делаете вклад в будущее наших серверов.', w - pX(58) - pX(11))
  1274.  
  1275.     for k, v in ipairs(txt) do
  1276.         draw.SimpleText(v, 'NM.TYText', pX(58) - pX(22), pX(25) + pX(25 * (k - 1)), Color(255, 255, 255))
  1277.     end
  1278.  
  1279.     draw.SimpleText('Пополнение баланса', 'NM.Category', pX(29), pX(145), Color(255, 255, 255), 0, 1)
  1280.     draw.RoundedBox(0, w / 2, h / 2 - pX(90), 1, pX(160), Color(58, 58, 58))
  1281.     draw.SimpleText('Лог операций', 'NM.Category', pX(419), pX(145), Color(255, 255, 255), 0, 1)
  1282.     draw.RoundedBox(0, 0, h - pX(150), w, 1, Color(58, 58, 58))
  1283.     draw.SimpleText('Ваши последние пополнения', 'NM.Category', pX(29), h - pX(125), Color(255, 255, 255), 0, 1)
  1284.  
  1285.     if self:GetParent().LastTransactions[1] then
  1286.         for k = 1, #self:GetParent().LastTransactions do
  1287.             local v = self:GetParent().LastTransactions[k]
  1288.             local x = pX(29) + ((k - 1) * pX(188))
  1289.             draw.RoundedBox(8, x, h - pX(100), pX(160), pX(70), Color(31, 31, 31))
  1290.             draw.RoundedBox(0, x + pX(28), h - pX(64), pX(100), pX(1), Color(49, 49, 49))
  1291.             draw.SimpleText(os.date('%d.%m.%Y - %H:%M', v.date), 'NM.LastDate', x + pX(80), h - pX(80), Color(255, 255, 255), 1, 1)
  1292.             draw.SimpleText(v.sum .. ' ₽', 'NM.LastSum', x + pX(80), h - pX(48), Color(255, 255, 255), 1, 1)
  1293.         end
  1294.     else
  1295.         draw.SimpleText('Вы еще не пополняли счет, или делали это давно!', 'NM.Category', w / 2, h - pX(70), Color(105, 105, 105), 1, 1)
  1296.     end
  1297. end
  1298.  
  1299. vgui.Register('nm_profile_donate', PANEL, 'Panel')
  1300.  
  1301. --[[ Инвентарь ]]
  1302. PANEL = {}
  1303.  
  1304. function PANEL:Init()
  1305.     local item = self.Item
  1306.  
  1307.     local function clearframe()
  1308.         local frame = self.MainFrame
  1309.  
  1310.         if IsValid(frame.OpenedItem) then
  1311.             frame.OpenedItem:Remove()
  1312.             frame.OpenedItemInfo:Remove()
  1313.             frame.OpenedItemInfo.Scroll:Remove()
  1314.         end
  1315.     end
  1316.  
  1317.     self:SetText("")
  1318.     self.ModelIcon = NM.CreateUI("DModelPanel", self)
  1319.     self.ActivationButton = NM.CreateUI("DButton", self)
  1320.     self.DropButton = NM.CreateUI("DButton", self)
  1321.  
  1322.     self.ActivationButton.DoClick = function(s)
  1323.         clearframe()
  1324.  
  1325.         IGS.ProcessActivate(self.ItemInv.id, function(ok)
  1326.             if not ok then return end
  1327.             self:Remove()
  1328.         end)
  1329.     end
  1330.  
  1331.     self.DropButton.DoClick = function(s)
  1332.         clearframe()
  1333.  
  1334.         IGS.DropItem(self.ItemInv.id, function()
  1335.             self:Remove()
  1336.         end)
  1337.     end
  1338. end
  1339.  
  1340. function PANEL:PerformLayout()
  1341.     local item = IGS.GetItem(self.Item)
  1342.     self.ActivationButton:SetPos(pX(600), pX(15))
  1343.     self.ActivationButton:SetSize(pX(140), pX(40))
  1344.     self.ActivationButton:SetText("")
  1345.  
  1346.     self.ActivationButton.Paint = function(s, w, h)
  1347.         draw.RoundedBox(8, 0, 0, w, h, self.MainFrame.ActiveItem == self.Item and Color(223, 223, 223) or Color(68, 68, 68))
  1348.         draw.RoundedBox(8, 1, 1, w - 2, h - 2, Color(55, 55, 55))
  1349.         draw.SimpleText("Активировать", "NM.ItemName", w / 2, h / 2, color_white, 1, 1)
  1350.     end
  1351.  
  1352.     self.DropButton:SetPos(pX(600), pX(60))
  1353.     self.DropButton:SetSize(pX(140), pX(20))
  1354.     self.DropButton:SetText("")
  1355.  
  1356.     self.DropButton.Paint = function(s, w, h)
  1357.         draw.SimpleText("Бросить на пол", "NM.LastDate", w / 2, h / 2, Color(105, 105, 105), 1, 1)
  1358.     end
  1359.  
  1360.     local iconwh = pX(70)
  1361.     self.ModelIcon:SetPos(pX(20), self:GetTall() / 2 - iconwh / 2)
  1362.     self.ModelIcon:SetSize(iconwh, iconwh)
  1363. end
  1364.  
  1365. function PANEL:Paint(w, h)
  1366.     draw.RoundedBox(8, pX(5), pX(5), w - pX(10), h - pX(10), Color(68, 68, 68))
  1367.     draw.RoundedBox(8, 1 + pX(5), 1 + pX(5), w - pX(10) - 2, h - pX(10) - 2, Color(55, 55, 55))
  1368.     draw.RoundedBox(8, pX(15), h / 2 - pX(40), pX(80), pX(80), Color(47, 47, 47))
  1369.     local item = IGS.GetItem(self.Item)
  1370.     draw.SimpleText(item.name, "NM.ItemName", pX(110), pX(50), item.highlight or Color(255, 255, 255), 0, 4)
  1371.     draw.SimpleText("Действует " .. IGS.TermToStr(item:Term()), "NM.TabSmall", pX(110), pX(70), Color(105, 105, 105), 0, 4)
  1372.  
  1373.     if item.icon and not item.icon.isModel then
  1374.         surface.SetDrawColor(255, 255, 255, 255)
  1375.         surface.SetMaterial(texture.Get(item.uid) or close_mat)
  1376.         local iconwh = pX(70)
  1377.         surface.DrawTexturedRect(pX(20), h / 2 - iconwh / 2, iconwh, iconwh)
  1378.     end
  1379. end
  1380.  
  1381. function PANEL:SetInfo(inv, uid, frame)
  1382.     self.Item = uid
  1383.     self.ItemInv = inv
  1384.     self.MainFrame = frame
  1385.  
  1386.     self.DoClick = function()
  1387.         frame:OpenItem(uid)
  1388.     end
  1389.  
  1390.     local item = IGS.GetItem(self.Item)
  1391.  
  1392.     self.ModelIcon.DoClick = function()
  1393.         frame:OpenItem(uid)
  1394.     end
  1395.  
  1396.     if item.icon and not item.icon.isModel then
  1397.         texture.Create(item.uid):Download(item.icon.icon)
  1398.         self.ModelIcon:SetVisible(false)
  1399.     elseif item.icon and item.icon.isModel then
  1400.         self.ModelIcon:SetVisible(true)
  1401.         self.ModelIcon:SetModel(item.icon.icon)
  1402.         local mn, mx = self.ModelIcon.Entity:GetRenderBounds()
  1403.         local size = 0
  1404.         size = math.max(size, math.abs(mn.x) + math.abs(mx.x))
  1405.         size = math.max(size, math.abs(mn.y) + math.abs(mx.y))
  1406.         size = math.max(size, math.abs(mn.z) + math.abs(mx.z))
  1407.         self.ModelIcon:SetFOV(30)
  1408.         self.ModelIcon:SetCamPos(Vector(size, size, size))
  1409.         self.ModelIcon:SetLookAt((mn + mx) * 0.5)
  1410.     end
  1411. end
  1412.  
  1413. vgui.Register("nm_inventory_button", PANEL, "DButton")
  1414. PANEL = {}
  1415.  
  1416. function PANEL:Init()
  1417.     self.Paint = function()
  1418.         if not IsValid(self.OpenedItem) then
  1419.             draw.SimpleText("Выберите предмет!", "NM.OpenedDesc", pX(877), pX(20), color_white, 1, 1)
  1420.         end
  1421.     end
  1422.  
  1423.     local btn
  1424.     self.Cats = {}
  1425.     self.List = NM.CreateUI("nm_listview", self)
  1426.     self.List.Paint = function(s, w, h)
  1427.         if not IsValid(self.List:GetCanvas():GetChild(0)) then
  1428.             draw.SimpleText("Инвентарь пуст!", "NM.Category", w / 2, h / 2, Color(105, 105, 105), 1, 1)
  1429.         end
  1430.     end
  1431.  
  1432.     IGS.GetInventory(function(items)
  1433.         for k, v in pairs(items) do
  1434.             btn = NM.CreateUI("nm_inventory_button")
  1435.             btn:SetSize(0, pX(100))
  1436.             btn:SetInfo(v, v.item.uid, self)
  1437.             self.List:AddItem(btn)
  1438.         end
  1439.     end)
  1440. end
  1441.  
  1442. function PANEL:PerformLayout()
  1443.     self.List:SetPos(0, 0)
  1444.     self.List:SetSize(self:GetWide() - pX(197), self:GetTall())
  1445. end
  1446.  
  1447. function PANEL:OpenItem(uid)
  1448.     if self.ActiveItem == uid then return end
  1449.     self.ActiveItem = uid
  1450.  
  1451.     if IsValid(self.OpenedItem) then
  1452.         self.OpenedItem:Remove()
  1453.         self.OpenedItemInfo:Remove()
  1454.         self.OpenedItemInfo.Scroll:Remove()
  1455.     end
  1456.  
  1457.     self.OpenedItem = NM.CreateUI("nm_shop_button", self)
  1458.     self.OpenedItem:SetInfo(uid, self)
  1459.     self.OpenedItem:SetPos(pX(978) - pX(14) - btnwh, pX(14))
  1460.     self.OpenedItem:SetSize(btnwh, btnwh)
  1461.     self.OpenedItem.ButtonBuy:SetVisible(false)
  1462.     local item = IGS.GetItem(uid)
  1463.     self:SetToolTip(item.name)
  1464.  
  1465.     self.OpenedItem.Paint = function(s, w, h)
  1466.         draw.RoundedBox(8, 0, 0, w, h, Color(68, 68, 68))
  1467.         draw.RoundedBox(8, 1, 1, w - 2, h - 2, Color(55, 55, 55))
  1468.         local name = item.name
  1469.  
  1470.         if utf8.len(name) > 16 then
  1471.             name = utf8.sub(name, 0, 14) .. "..."
  1472.         end
  1473.  
  1474.         draw.SimpleText(name, "NM.ItemName", pX(16), h - pX(60), item.highlight or Color(255, 255, 255), 0, 4)
  1475.         draw.SimpleText(NM.FancyTerm(item:Term()), "NM.ItemDesc", pX(16), h - pX(45), Color(105, 105, 105), 0, 4)
  1476.  
  1477.         if item.discounted_from then
  1478.             tw, th = draw.SimpleText(IGS.SignPrice(item.discounted_from), "NM.ItemOldPrice", pX(16), h - pX(30), Color(105, 105, 105), 0, 4)
  1479.             local liney = h - pX(34)
  1480.             surface.SetDrawColor(255, 255, 255, 255)
  1481.             surface.DrawLine(pX(16), liney - th * .5, pX(16) + tw, liney)
  1482.         end
  1483.  
  1484.         draw.SimpleText(IGS.SignPrice(item.price), "NM.ItemPrice", pX(16), h - pX(16), Color(255, 255, 255), 0, 4)
  1485.  
  1486.         if item.icon and not item.icon.isModel then
  1487.             surface.SetDrawColor(255, 255, 255, 255)
  1488.             surface.SetMaterial(texture.Get(item.uid) or close_mat)
  1489.             local iconwh = pX(80)
  1490.             surface.DrawTexturedRect(w / 2 - iconwh / 2, pX(6), iconwh, iconwh)
  1491.             surface.SetDrawColor(255, 255, 255, 180)
  1492.             surface.SetMaterial(grad_mat)
  1493.             surface.DrawTexturedRect(pX(1), pX(12), w - pX(2), iconwh)
  1494.         end
  1495.     end
  1496.  
  1497.     self.OpenedItemInfo = NM.CreateUI("DPanel", self)
  1498.     self.OpenedItemInfo:SetText("")
  1499.     local oifw, oifh = pX(197), pX(280)
  1500.     self.OpenedItemInfo:SetPos(pX(978) - oifw, pX(530) - pX(54) - oifh)
  1501.     self.OpenedItemInfo:SetSize(oifw, oifh)
  1502.  
  1503.     self.OpenedItemInfo.Paint = function(s, w, h)
  1504.         draw.RoundedBox(0, 0, 1, w, 1, Color(58, 58, 58))
  1505.         draw.SimpleText("Описание", "NM.OpenedDesc", pX(14), pX(14), Color(134, 134, 134))
  1506.     end
  1507.  
  1508.     self.OpenedItemInfo.Scroll = NM.CreateUI("nm_listview", self)
  1509.     self.OpenedItemInfo.Scroll:SetPos(pX(978) - oifw + pX(14), pX(530) - pX(10) - oifh)
  1510.     self.OpenedItemInfo.Scroll:SetSize(oifw - pX(28), oifh - pX(60))
  1511.     self.OpenedItemInfo.Scroll.Paint = function() end
  1512.     local txt = string.Wrap("NM.OpenedText", item.description, self.OpenedItemInfo.Scroll:GetWide())
  1513.  
  1514.     for k, v in ipairs(txt) do
  1515.         local lbl = NM.CreateUI("DLabel", function(s, p)
  1516.             s:SetText(v)
  1517.             s:SetFont("NM.OpenedText")
  1518.             s:SizeToContents()
  1519.         end)
  1520.  
  1521.         self.OpenedItemInfo.Scroll:AddItem(lbl)
  1522.     end
  1523. end
  1524.  
  1525. vgui.Register("nm_inventory", PANEL, "Panel")
  1526.  
  1527. concommand.Add('donate_menu', function()
  1528.     NM.Menu()
  1529. end)
  1530.  
  1531. concommand.Add('donate_menu_old', function()
  1532.     IGS.UI()
  1533. end)
  1534.  
  1535.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement