aboutsummaryrefslogtreecommitdiff
path: root/gamemode/hud/draw_account.lua
blob: 861445c15cc20821eef8d4fca5ae2e0a572c00c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
local SCO = Color(0,0,0,250)
local MCO = Color(0,0,0,150)
local x,y = ScrW()-200,30

local AccountMenu = nil
local Info = nil

hook.Add("Tick","AccountInventory",function()
	if (input.KeyPress(KEY_F2)) then
		if IsAccountMenuOpen() then
			AccountMenu:SetVisible(false)
		else
			OpenAccountMenu()
		end
	end
end)


function ReloadAccountMenu()
	if (!IsAccountMenuOpen()) then return end
	AccountMenu.List:Clear()

	for k,v in pairs(LocalPlayer():GetAccountInventory()) do
		local a = AccountMenu.List:Add("DPanel")
		a:SetSize(64,64)
		a.Item = GetItemByName(v.Name)
		a.Quantity = v.Quantity
		a:Droppable("ACCOUNT")
		a.Paint = function(s,w,h)
			DrawRect(0,0,w,h,MCO)
			DrawMaterialRect(0,0,w,h,MAIN_WHITECOLOR,s.Item.Icon)

			DrawText("x"..v.Quantity,"ChatFont",1,h-18,MAIN_TEXTCOLOR)
		end

		a.OnCursorEntered = function(s)
			if (!Info) then
				Info = vgui.Create("DPanel")
				Info:SetPos(x-410,60)
				Info:SetSize(195,100)
				Info.Paint = function(s,w,h) DrawRect(0,0,w,h,SCO) end

				Info.Label = vgui.Create("DLabel",Info)
				Info.Label:SetPos(5,5)
				Info.Label:SetSize(185,20)

				Info.LabelDesc = vgui.Create("DLabel",Info)
				Info.LabelDesc:SetPos(5,30)
				Info.LabelDesc:SetSize(185,65)
				Info.LabelDesc:SetWrap(true)
				Info.LabelDesc:SetAutoStretchVertical(true)
			end

			Info.Label:SetText(v.Name)
			Info.LabelDesc:SetText(s.Item.Desc)

			Info:SetVisible(true)
		end

		a.OnCursorExited = function(s)
			Info:SetVisible(false)
		end

		a.OnStopDragging = function(s,a,b,c)
		end


		local Ab = a.OnMousePressed
		a.OnMousePressed = function(s,m)
			if (m == MOUSE_RIGHT) then
				local X,Y = gui.MousePos()

				local menu = DermaMenu()
				menu.Paint = function(s,w,h) DrawRect(0,0,w,h,MCO) end
				menu:AddOption( "Use", function() if (s.Item) then RequestUseItem(s.Item.Name,true) end end ):SetColor(MAIN_TEXTCOLOR)
				menu:AddOption( "Destroy", function() if (s.Item) then RequestDropItem(s.Item.Name,true) end end ):SetColor(MAIN_TEXTCOLOR)

				menu:Open()
				menu:SetPos(X,Y)
			end

			Ab(s,m)
		end
	end
end

function OpenAccountMenu()
	if (IsAccountMenuOpen()) then return end

	surface.PlaySound("wintersurvival2/hud/itemopen.wav")

	if (!AccountMenu) then
		--Inventory
		AccountMenu = vgui.Create("MBFrame")
		AccountMenu:SetPos(x-205,y+25)
		AccountMenu:SetSize(400,400)
		AccountMenu:SetTitle("Account")
		AccountMenu:SetDeleteOnClose(false)
		AccountMenu:MakePopup()
		AccountMenu.Paint = function(s,w,h)
			DrawRect(0,0,w,h,MCO)
			DrawRect(5,20,w-10,20,MCO)

			DrawText("Time spent: "..math.SecondsToTime(LocalPlayer():GetTimeSpent()),"Trebuchet18",8,21,MAIN_WHITECOLOR)
		end
		AccountMenu.OnClose = function(s) surface.PlaySound("wintersurvival2/hud/itemequip.wav") end

		local Pane = vgui.Create( "DScrollPanel", AccountMenu )
		Pane:SetPos(5,45)
		Pane:SetSize(AccountMenu:GetWide()-10,AccountMenu:GetTall()-50)
		Pane.Paint = function(s,w,h) DrawRect(0,0,w,h,MCO) end

		local l = vgui.Create("DIconLayout",Pane)
		l:SetSize(Pane:GetWide()-10,Pane:GetTall()-10)
		l:SetPos(5,5)
		l:SetSpaceY(5)
		l:SetSpaceX(5)

		AccountMenu.List = l
		AccountMenu:ShowCloseButton(false)
	end

	AccountMenu:SetVisible(true)

	ReloadAccountMenu()
end

function IsAccountMenuOpen()
	return (IsValid(AccountMenu) and AccountMenu:IsVisible())
end

function DrawAccountInventory()
	DrawRect(x,y,200,20,MCO)
	DrawText("F2 - Account","Trebuchet18",x+4,y+2,MAIN_TEXTCOLOR)
end