Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include('shared.lua')
- local function formatNumber(n)
- n = tonumber(n)
- if (!n) then
- return 0
- end
- if n >= 1e14 then return tostring(n) end
- n = tostring(n)
- sep = sep or ","
- local dp = string.find(n, "%.") or #n+1
- for i=dp-4, 1, -3 do
- n = n:sub(1, i) .. sep .. n:sub(i+1)
- end
- return n
- end
- timer.Simple(1, function()
- surface.CreateFont("UiBold", {
- font = "Tahoma",
- size = 13,
- weight = 700
- })
- surface.CreateFont("Trebuchet24", {
- font = "Trebuchet MS",
- size = 24,
- weight = 900
- })
- surface.CreateFont("Trebuchet22", {
- font = "Trebuchet MS",
- size = 22,
- weight = 900
- })
- surface.CreateFont("Trebuchet20", {
- font = "Trebuchet MS",
- size = 20,
- weight = 900
- })
- end)
- function NPC_ShopMenu()
- local ShopMenu = vgui.Create( "DFrame" )
- ShopMenu:SetSize( 570, 600 )
- ShopMenu:Center()
- ShopMenu:SetTitle( "" )
- ShopMenu:SetVisible( true )
- ShopMenu:SetDraggable( true )
- ShopMenu:ShowCloseButton( false )
- ShopMenu:MakePopup()
- ShopMenu:SizeToContents()
- ShopMenu.Paint = function(CHPaint)
- -- Draw the menu background color.
- draw.RoundedBox( 6, 0, 0, CHPaint:GetWide(), CHPaint:GetTall(), Color( 255, 255, 255, 150 ) )
- -- Draw the outline of the menu.
- surface.SetDrawColor(0,0,0,255)
- surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), CHPaint:GetTall())
- surface.SetDrawColor(0,0,0,255)
- surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), 25)
- --surface.DrawOutlinedRect(1, 1, CHPaint:GetWide(), 25)
- -- Draw the top title.
- draw.SimpleText("NPC Store", "UiBold", 35,12.5, Color(70,70,70,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- end
- local GUI_Main_Exit = vgui.Create("DButton", ShopMenu)
- GUI_Main_Exit:SetSize(16,16)
- GUI_Main_Exit:SetPos(550,5)
- GUI_Main_Exit:SetText("")
- GUI_Main_Exit.Paint = function()
- surface.SetMaterial(Material("icon16/cross.png"))
- surface.SetDrawColor(200,200,0,200)
- surface.DrawTexturedRect(0,0,GUI_Main_Exit:GetWide(),GUI_Main_Exit:GetTall())
- end
- GUI_Main_Exit.DoClick = function()
- ShopMenu:Remove()
- net.Start("CH_CloseShopMenu")
- net.SendToServer()
- end
- local TheListPanel = vgui.Create( "DPanelList", ShopMenu )
- TheListPanel:SetTall( 565 )
- TheListPanel:SetWide( 560 )
- TheListPanel:SetPos( 5, 30 )
- TheListPanel:EnableVerticalScrollbar( true )
- TheListPanel:EnableHorizontal( true )
- for k, v in pairs( NPCShop_Items ) do
- if v.Name then
- local ItemList = vgui.Create("DPanelList")
- ItemList:SetTall( 150 )
- ItemList:SetWide( 560 )
- ItemList:SetPos( 10, 30 )
- ItemList:SetSpacing( 5 )
- ItemList.Paint = function()
- draw.RoundedBox(8,0,2,ItemList:GetWide(),ItemList:GetTall(),Color( 20, 20, 20, 180 ))
- end
- local ItemBackground = vgui.Create( "DPanel", ItemList )
- ItemBackground:SetPos( 0, 10 )
- ItemBackground:SetSize( 560, 132.5 )
- ItemBackground.Paint = function() -- Paint function
- draw.RoundedBoxEx(8,1,1,ItemBackground:GetWide()-2,ItemBackground:GetTall()-2,Color(70, 70, 70, 200), false, false, false, false)
- end
- local ItemDisplay = vgui.Create( "SpawnIcon", ItemBackground )
- ItemDisplay:SetPos( 5, 5 )
- ItemDisplay:SetModel( v.Model )
- ItemDisplay:SetToolTip(false)
- ItemDisplay:SetSize(120,120)
- ItemDisplay.PaintOver = function()
- return
- end
- ItemDisplay.OnMousePressed = function()
- return false
- end
- ZoomButton = vgui.Create("DImageButton", ItemDisplay)
- ZoomButton:SetMaterial( "icon16/magnifier_zoom_in.png" )
- ZoomButton:SetPos(2.5,2.5)
- ZoomButton:SetSize(16,16)
- ZoomButton.DoClick = function()
- ShopMenu:Remove()
- NPCStore_DisplayMenu( k )
- end
- local ItemName = vgui.Create( "DLabel", ItemBackground )
- ItemName:SetPos( 125, 10 )
- ItemName:SetFont( "Trebuchet24" )
- ItemName:SetColor( Color(255,255,255,255) )
- ItemName:SetText( v.Name )
- ItemName:SizeToContents()
- local ItemPrice = vgui.Create( "DLabel", ItemBackground )
- ItemPrice:SetPos( 125, 30 )
- ItemPrice:SetFont( "Trebuchet20" )
- if LocalPlayer().DarkRPVars.money >= v.Price then
- ItemPrice:SetColor( Color(0,150,0,255) )
- else
- ItemPrice:SetColor( Color(150,0,0,255) )
- end
- ItemPrice:SetText( "Price: $"..formatNumber(v.Price) )
- ItemPrice:SizeToContents()
- local ItemDescription = vgui.Create( "DLabel", ItemBackground )
- ItemDescription:SetPos( 125, 50 )
- ItemDescription:SetFont( "UiBold" )
- ItemDescription:SetColor( Color(255,255,255,255) )
- ItemDescription:SetText( v.Description )
- ItemDescription:SetSize(440, 30)
- ItemDescription:SetWrap(true)
- local BuyItem = vgui.Create("DButton", ItemBackground)
- BuyItem:SetSize( 200, 30 )
- BuyItem:SetPos( 360, 95 )
- BuyItem:SetText("")
- if LocalPlayer().DarkRPVars.money < v.Price then
- BuyItem:SetDisabled( true )
- BuyItem:SetToolTip("You cannot afford this item!")
- end
- BuyItem.Paint = function(panel)
- draw.RoundedBoxEx(8,1,1,BuyItem:GetWide()-2,BuyItem:GetTall()-2,Color(0, 0, 0, 130), true, false, true, false)
- local struc = {}
- struc.pos = {}
- struc.pos[1] = 100
- struc.pos[2] = 15
- if LocalPlayer().DarkRPVars.money >= v.Price then
- struc.color = Color(255,255,255,255)
- else
- struc.color = Color(150,150,150,255)
- end
- struc.text = "Purchase"
- struc.font = "Trebuchet22"
- struc.xalign = TEXT_ALIGN_CENTER
- struc.yalign = TEXT_ALIGN_CENTER
- draw.Text( struc )
- end
- BuyItem.DoClick = function()
- ShopMenu:Remove()
- net.Start("CH_CloseShopMenu")
- net.SendToServer()
- net.Start("NPCShop_BuyItem")
- net.WriteString(k)
- net.SendToServer()
- end
- TheListPanel:AddItem( ItemList )
- end
- end
- end
- usermessage.Hook("CH_ShopMenu", NPC_ShopMenu)
- function NPCStore_DisplayMenu( item )
- local DisplayMenu = vgui.Create( "DFrame" )
- DisplayMenu:SetSize( 400, 400 )
- DisplayMenu:Center()
- DisplayMenu:SetTitle( "" )
- DisplayMenu:SetVisible( true )
- DisplayMenu:SetDraggable( true )
- DisplayMenu:ShowCloseButton( false )
- DisplayMenu:MakePopup()
- DisplayMenu:SizeToContents()
- DisplayMenu.Paint = function(CHPaint)
- -- Draw the menu background color.
- draw.RoundedBox( 6, 0, 0, CHPaint:GetWide(), CHPaint:GetTall(), Color( 255, 255, 255, 150 ) )
- -- Draw the outline of the menu.
- surface.SetDrawColor(0,0,0,255)
- surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), CHPaint:GetTall())
- surface.SetDrawColor(0,0,0,255)
- surface.DrawOutlinedRect(0, 0, CHPaint:GetWide(), 25)
- --surface.DrawOutlinedRect(1, 1, CHPaint:GetWide(), 25)
- -- Draw the top title.
- draw.SimpleText("NPC Store - Item Display", "UiBold", 75,12.5, Color(70,70,70,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- end
- local DisplayBackground = vgui.Create( "DPanel", DisplayMenu )
- DisplayBackground:SetPos( 5, 30 )
- DisplayBackground:SetSize( 390, 335 )
- DisplayBackground.Paint = function() -- Paint function
- draw.RoundedBox(8,1,1,DisplayBackground:GetWide()-2,DisplayBackground:GetTall()-2,Color(70, 70, 70, 200))
- draw.SimpleText(NPCShop_Items[item].Name, "Trebuchet24", 195,15, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- if LocalPlayer().DarkRPVars.money >= NPCShop_Items[item].Price then
- draw.SimpleText("Price: $".. formatNumber(NPCShop_Items[item].Price), "Trebuchet22", 195,30, Color( 0, 200, 0, 220 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- else
- draw.SimpleText("Price: $".. formatNumber(NPCShop_Items[item].Price), "Trebuchet22", 195,30, Color( 200, 0, 0, 220 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- draw.SimpleText("You cannot afford this item", "UiBold", 195,45, Color( 255, 255, 255, 220 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- end
- end
- local DisplayModel = vgui.Create("DModelPanel", DisplayBackground)
- DisplayModel:SetModel( NPCShop_Items[item].Model )
- DisplayModel:SetPos( -120, -350 )
- DisplayModel:SetSize( 640, 640 )
- DisplayModel:GetEntity():SetAngles(Angle(255, 255, 100))
- local ReturnToStore = vgui.Create("DButton", DisplayMenu)
- ReturnToStore:SetSize( 200, 30 )
- ReturnToStore:SetPos( 100, 370 )
- ReturnToStore:SetText("")
- ReturnToStore.Paint = function(panel)
- draw.RoundedBoxEx(8,1,1,ReturnToStore:GetWide()-2,ReturnToStore:GetTall()-2,Color(0, 0, 0, 130), true, true, false, false)
- local struc = {}
- struc.pos = {}
- struc.pos[1] = 100
- struc.pos[2] = 15
- struc.color = Color(255,255,255,255)
- struc.text = "Return To Store"
- struc.font = "Trebuchet22"
- struc.xalign = TEXT_ALIGN_CENTER
- struc.yalign = TEXT_ALIGN_CENTER
- draw.Text( struc )
- end
- ReturnToStore.DoClick = function()
- DisplayMenu:Remove()
- NPC_ShopMenu()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement