Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.60 KB | None | 0 0
  1. include('shared.lua')
  2.  
  3. local function formatNumber(n)
  4. n = tonumber(n)
  5. if (!n) then
  6. return 0
  7. end
  8. if n >= 1e14 then return tostring(n) end
  9. n = tostring(n)
  10. sep = sep or ","
  11. local dp = string.find(n, "%.") or #n+1
  12. for i=dp-4, 1, -3 do
  13. n = n:sub(1, i) .. sep .. n:sub(i+1)
  14. end
  15. return n
  16. end
  17. timer.Simple(1, function()
  18.  
  19. surface.CreateFont("UiBold", {
  20. font = "Tahoma",
  21. size = 13,
  22. weight = 700
  23. })
  24.  
  25. surface.CreateFont("Trebuchet24", {
  26. font = "Trebuchet MS",
  27. size = 24,
  28. weight = 900
  29. })
  30.  
  31. surface.CreateFont("Trebuchet22", {
  32. font = "Trebuchet MS",
  33. size = 22,
  34. weight = 900
  35. })
  36.  
  37. surface.CreateFont("Trebuchet20", {
  38. font = "Trebuchet MS",
  39. size = 20,
  40. weight = 900
  41. })
  42.  
  43. end)
  44.  
  45. function NPC_ShopMenu()
  46. local ShopMenu = vgui.Create( "DFrame" )
  47. ShopMenu:SetSize( 570, 600 )
  48. ShopMenu:Center()
  49. ShopMenu:SetTitle( "" )
  50. ShopMenu:SetVisible( true )
  51. ShopMenu:SetDraggable( true )
  52. ShopMenu:ShowCloseButton( false )
  53. ShopMenu:MakePopup()
  54. ShopMenu:SizeToContents()
  55. ShopMenu.Paint = function(CHPaint)
  56. -- Draw the menu background color.
  57. draw.RoundedBox( 6, 0, 0, CHPaint:GetWide(), CHPaint:GetTall(), Color( 255, 255, 255, 150 ) )
  58.  
  59. -- Draw the outline of the menu.
  60. surface.SetDrawColor(0,0,0,255)
  61. surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), CHPaint:GetTall())
  62.  
  63. surface.SetDrawColor(0,0,0,255)
  64. surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), 25)
  65. --surface.DrawOutlinedRect(1, 1, CHPaint:GetWide(), 25)
  66.  
  67. -- Draw the top title.
  68. draw.SimpleText("NPC Store", "UiBold", 35,12.5, Color(70,70,70,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  69. end
  70.  
  71. local GUI_Main_Exit = vgui.Create("DButton", ShopMenu)
  72. GUI_Main_Exit:SetSize(16,16)
  73. GUI_Main_Exit:SetPos(550,5)
  74. GUI_Main_Exit:SetText("")
  75. GUI_Main_Exit.Paint = function()
  76. surface.SetMaterial(Material("icon16/cross.png"))
  77. surface.SetDrawColor(200,200,0,200)
  78. surface.DrawTexturedRect(0,0,GUI_Main_Exit:GetWide(),GUI_Main_Exit:GetTall())
  79. end
  80. GUI_Main_Exit.DoClick = function()
  81. ShopMenu:Remove()
  82. net.Start("CH_CloseShopMenu")
  83. net.SendToServer()
  84. end
  85.  
  86. local TheListPanel = vgui.Create( "DPanelList", ShopMenu )
  87. TheListPanel:SetTall( 565 )
  88. TheListPanel:SetWide( 560 )
  89. TheListPanel:SetPos( 5, 30 )
  90. TheListPanel:EnableVerticalScrollbar( true )
  91. TheListPanel:EnableHorizontal( true )
  92.  
  93. for k, v in pairs( NPCShop_Items ) do
  94. if v.Name then
  95. local ItemList = vgui.Create("DPanelList")
  96. ItemList:SetTall( 150 )
  97. ItemList:SetWide( 560 )
  98. ItemList:SetPos( 10, 30 )
  99. ItemList:SetSpacing( 5 )
  100. ItemList.Paint = function()
  101. draw.RoundedBox(8,0,2,ItemList:GetWide(),ItemList:GetTall(),Color( 20, 20, 20, 180 ))
  102. end
  103.  
  104. local ItemBackground = vgui.Create( "DPanel", ItemList )
  105. ItemBackground:SetPos( 0, 10 )
  106. ItemBackground:SetSize( 560, 132.5 )
  107. ItemBackground.Paint = function() -- Paint function
  108. draw.RoundedBoxEx(8,1,1,ItemBackground:GetWide()-2,ItemBackground:GetTall()-2,Color(70, 70, 70, 200), false, false, false, false)
  109. end
  110.  
  111. local ItemDisplay = vgui.Create( "SpawnIcon", ItemBackground )
  112. ItemDisplay:SetPos( 5, 5 )
  113. ItemDisplay:SetModel( v.Model )
  114. ItemDisplay:SetToolTip(false)
  115. ItemDisplay:SetSize(120,120)
  116. ItemDisplay.PaintOver = function()
  117. return
  118. end
  119. ItemDisplay.OnMousePressed = function()
  120. return false
  121. end
  122.  
  123. ZoomButton = vgui.Create("DImageButton", ItemDisplay)
  124. ZoomButton:SetMaterial( "icon16/magnifier_zoom_in.png" )
  125. ZoomButton:SetPos(2.5,2.5)
  126. ZoomButton:SetSize(16,16)
  127. ZoomButton.DoClick = function()
  128. ShopMenu:Remove()
  129. NPCStore_DisplayMenu( k )
  130. end
  131.  
  132. local ItemName = vgui.Create( "DLabel", ItemBackground )
  133. ItemName:SetPos( 125, 10 )
  134. ItemName:SetFont( "Trebuchet24" )
  135. ItemName:SetColor( Color(255,255,255,255) )
  136. ItemName:SetText( v.Name )
  137. ItemName:SizeToContents()
  138.  
  139. local ItemPrice = vgui.Create( "DLabel", ItemBackground )
  140. ItemPrice:SetPos( 125, 30 )
  141. ItemPrice:SetFont( "Trebuchet20" )
  142. if LocalPlayer().DarkRPVars.money >= v.Price then
  143. ItemPrice:SetColor( Color(0,150,0,255) )
  144. else
  145. ItemPrice:SetColor( Color(150,0,0,255) )
  146. end
  147. ItemPrice:SetText( "Price: $"..formatNumber(v.Price) )
  148. ItemPrice:SizeToContents()
  149.  
  150. local ItemDescription = vgui.Create( "DLabel", ItemBackground )
  151. ItemDescription:SetPos( 125, 50 )
  152. ItemDescription:SetFont( "UiBold" )
  153. ItemDescription:SetColor( Color(255,255,255,255) )
  154. ItemDescription:SetText( v.Description )
  155. ItemDescription:SetSize(440, 30)
  156. ItemDescription:SetWrap(true)
  157.  
  158. local BuyItem = vgui.Create("DButton", ItemBackground)
  159. BuyItem:SetSize( 200, 30 )
  160. BuyItem:SetPos( 360, 95 )
  161. BuyItem:SetText("")
  162. if LocalPlayer().DarkRPVars.money < v.Price then
  163. BuyItem:SetDisabled( true )
  164. BuyItem:SetToolTip("You cannot afford this item!")
  165. end
  166. BuyItem.Paint = function(panel)
  167. draw.RoundedBoxEx(8,1,1,BuyItem:GetWide()-2,BuyItem:GetTall()-2,Color(0, 0, 0, 130), true, false, true, false)
  168.  
  169. local struc = {}
  170. struc.pos = {}
  171. struc.pos[1] = 100
  172. struc.pos[2] = 15
  173. if LocalPlayer().DarkRPVars.money >= v.Price then
  174. struc.color = Color(255,255,255,255)
  175. else
  176. struc.color = Color(150,150,150,255)
  177. end
  178. struc.text = "Purchase"
  179. struc.font = "Trebuchet22"
  180. struc.xalign = TEXT_ALIGN_CENTER
  181. struc.yalign = TEXT_ALIGN_CENTER
  182. draw.Text( struc )
  183. end
  184. BuyItem.DoClick = function()
  185. ShopMenu:Remove()
  186. net.Start("CH_CloseShopMenu")
  187. net.SendToServer()
  188.  
  189. net.Start("NPCShop_BuyItem")
  190. net.WriteString(k)
  191. net.SendToServer()
  192. end
  193.  
  194. TheListPanel:AddItem( ItemList )
  195. end
  196. end
  197. end
  198. usermessage.Hook("CH_ShopMenu", NPC_ShopMenu)
  199.  
  200. function NPCStore_DisplayMenu( item )
  201. local DisplayMenu = vgui.Create( "DFrame" )
  202. DisplayMenu:SetSize( 400, 400 )
  203. DisplayMenu:Center()
  204. DisplayMenu:SetTitle( "" )
  205. DisplayMenu:SetVisible( true )
  206. DisplayMenu:SetDraggable( true )
  207. DisplayMenu:ShowCloseButton( false )
  208. DisplayMenu:MakePopup()
  209. DisplayMenu:SizeToContents()
  210. DisplayMenu.Paint = function(CHPaint)
  211. -- Draw the menu background color.
  212. draw.RoundedBox( 6, 0, 0, CHPaint:GetWide(), CHPaint:GetTall(), Color( 255, 255, 255, 150 ) )
  213.  
  214. -- Draw the outline of the menu.
  215. surface.SetDrawColor(0,0,0,255)
  216. surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), CHPaint:GetTall())
  217.  
  218. surface.SetDrawColor(0,0,0,255)
  219. surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), 25)
  220. --surface.DrawOutlinedRect(1, 1, CHPaint:GetWide(), 25)
  221.  
  222. -- Draw the top title.
  223. draw.SimpleText("NPC Store - Item Display", "UiBold", 75,12.5, Color(70,70,70,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  224. end
  225.  
  226. local DisplayBackground = vgui.Create( "DPanel", DisplayMenu )
  227. DisplayBackground:SetPos( 5, 30 )
  228. DisplayBackground:SetSize( 390, 335 )
  229. DisplayBackground.Paint = function() -- Paint function
  230. draw.RoundedBox(8,1,1,DisplayBackground:GetWide()-2,DisplayBackground:GetTall()-2,Color(70, 70, 70, 200))
  231.  
  232. draw.SimpleText(NPCShop_Items[item].Name, "Trebuchet24", 195,15, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  233.  
  234. if LocalPlayer().DarkRPVars.money >= NPCShop_Items[item].Price then
  235. draw.SimpleText("Price: $".. formatNumber(NPCShop_Items[item].Price), "Trebuchet22", 195,30, Color( 0, 200, 0, 220 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  236. else
  237. draw.SimpleText("Price: $".. formatNumber(NPCShop_Items[item].Price), "Trebuchet22", 195,30, Color( 200, 0, 0, 220 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  238. draw.SimpleText("You cannot afford this item", "UiBold", 195,45, Color( 255, 255, 255, 220 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  239. end
  240. end
  241.  
  242. local DisplayModel = vgui.Create("DModelPanel", DisplayBackground)
  243. DisplayModel:SetModel( NPCShop_Items[item].Model )
  244. DisplayModel:SetPos( -120, -350 )
  245. DisplayModel:SetSize( 640, 640 )
  246. DisplayModel:GetEntity():SetAngles(Angle(255, 255, 100))
  247.  
  248. local ReturnToStore = vgui.Create("DButton", DisplayMenu)
  249. ReturnToStore:SetSize( 200, 30 )
  250. ReturnToStore:SetPos( 100, 370 )
  251. ReturnToStore:SetText("")
  252. ReturnToStore.Paint = function(panel)
  253. draw.RoundedBoxEx(8,1,1,ReturnToStore:GetWide()-2,ReturnToStore:GetTall()-2,Color(0, 0, 0, 130), true, true, false, false)
  254.  
  255. local struc = {}
  256. struc.pos = {}
  257. struc.pos[1] = 100
  258. struc.pos[2] = 15
  259. struc.color = Color(255,255,255,255)
  260. struc.text = "Return To Store"
  261. struc.font = "Trebuchet22"
  262. struc.xalign = TEXT_ALIGN_CENTER
  263. struc.yalign = TEXT_ALIGN_CENTER
  264. draw.Text( struc )
  265. end
  266. ReturnToStore.DoClick = function()
  267. DisplayMenu:Remove()
  268. NPC_ShopMenu()
  269. end
  270. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement