-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTradingPanel.lua
More file actions
230 lines (197 loc) · 6.49 KB
/
TradingPanel.lua
File metadata and controls
230 lines (197 loc) · 6.49 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
-- Trading Panel Mockup
local lookupSZ = function(string)
local SZ = Vector(0,0,0)
if string.lower(string) == "melon" then SZ = Vector(15,15,0) end
if string.lower(string) == "crate" then SZ = Vector(50,50,50) end
if string.lower(string) == "fish" then SZ = Vector(13,13,5) end
if string.lower(string) == "pizza" then SZ = Vector(13,13,13) end
if string.lower(string) == "coffee" then SZ = Vector(7,7,2) end
if string.lower(string) == "cookie" then SZ = Vector(3,3,0) end
if string.lower(string) == "coke" then SZ = Vector(6,8,2) end
if string.lower(string) == "bar" then SZ = Vector(25,25,25) end
if string.lower(string) == "orange" then SZ = Vector(9,9,0) end
return SZ
end
local MakePanel = function(From,To,ENTMDL,ITM,HT,C,SZ)
local ColorBG1 = Color(64,64,64)
local ColorBG2 = Color(32,32,32)
local II = vgui.Create("DPanel")
II:SetSize(525/6,525/6)
II:SetBackgroundColor(ColorBG2)
local IMI = vgui.Create("DModelPanel",II)
IMI:SetPos(0,0)
IMI:SetSize(525/6,525/6)
IMI:SetModel(ENTMDL)
IMI:SetFOV(25)
IMI:SetCamPos(SZ*Vector(2,2,1))
IMI:SetLookAt(SZ*Vector(0.5,0.5,0.5))
IMI:SetTooltip(ITM.."\n\n".. HT .. " (tradeable) \n\n Count:" .. C)
IMI:SetTooltipDelay(0)
function IMI:LayoutEntity(ent)
end
return {Main=II,Internal=IMI}
end
local MakePanelRemovable = function(From,ENTMDL,ITM,HT,C,SZ)
local ColorBG1 = Color(64,64,64)
local ColorBG2 = Color(32,32,32)
local II = vgui.Create("DPanel")
II:SetSize(525/6,525/6)
II:SetBackgroundColor(ColorBG2)
local IMI = vgui.Create("DModelPanel",II)
IMI:SetPos(0,0)
IMI:SetSize(525/6,525/6)
IMI:SetModel(ENTMDL)
IMI:SetFOV(25)
IMI:SetCamPos(SZ*Vector(2,2,1))
IMI:SetLookAt(SZ*Vector(0.5,0.5,0.5))
IMI:SetTooltip(ITM.."\n\n".. HT .. " (tradeable) \n\n Count:" .. C)
IMI:SetTooltipDelay(0)
function IMI:LayoutEntity(ent)
end
function IMI:DoClick()
From:RemoveItem(II)
end
return {Main=II,Internal=IMI}
end
local function ConfirmSendItem(Panel,Info)
local A,B,C,D,E = unpack(Info)
local Max = tonumber(D,10)
local ConfPanel=vgui.Create("DFrame")
ConfPanel:MoveToFront()
ConfPanel:SetSize(256,128)
ConfPanel:Center()
ConfPanel:SetBackgroundBlur(true)
ConfPanel:SetDraggable(false)
ConfPanel:ShowCloseButton(false)
ConfPanel:SetTitle("Amount to set")
ConfPanel:MakePopup()
local Amount = vgui.Create("DTextEntry",ConfPanel)
Amount:SetNumeric(true)
Amount:SetEnterAllowed(false)
Amount:SetPos((256-196)/2,32)
Amount:SetSize(196,32)
Amount:SetContentAlignment(5)
Amount:SetText(0)
function Amount:OnChange()
if Amount:GetInt() > Max then
Amount:SetText(Max)
end
end
local SetAmount = vgui.Create("DButton",ConfPanel)
SetAmount:Dock(BOTTOM)
SetAmount:SetSize(32,24)
SetAmount:SetText("Ok")
function SetAmount:DoClick()
local Cn = Amount:GetInt()
if Cn > 0 then
local SET2 = MakePanelRemovable(Panel,A,B,C,Cn,E)
Panel:AddItem(SET2.Main)
end
ConfPanel:Close()
end
end
msitems.OpenTradePanel = function()
local ColorBG1 = Color(64,64,64)
local ColorBG2 = Color(32,32,32)
local Main = vgui.Create("DFrame")
Main:SetPos((ScrW()/2)-600,ScrH()-650)
Main:SetSize(1200,600)
Main:SetTitle("Trading Prototype")
Main:MakePopup()
local You = vgui.Create("DLabel",Main)
You:SetPos(5,25)
You:SetSize(300,20)
You:SetText("You (".. LocalPlayer():Nick() ..")")
local TradeWith = vgui.Create("DComboBox" , Main)
TradeWith:SetPos(1200-300,25)
TradeWith:SetSize(300,20)
TradeWith:SetValue( "No Player" )
for k,v in pairs(player.GetAll()) do
TradeWith:AddChoice(v:Nick())
end
TradeWith.OnSelect = function( self, index, value )
TradePartner = player.GetAll()[index]
end
local Inventory1 = vgui.Create("DPanel",Main)
Inventory1:SetSize(550,500/2)
Inventory1:SetPos(5,45)
Inventory1:SetBackgroundColor(ColorBG1)
local Inventory2 = vgui.Create("DPanel",Main)
Inventory2:SetSize(550,500/2)
Inventory2:SetPos(1200-550,45)
Inventory2:SetBackgroundColor(ColorBG1)
local TradePanel1 = vgui.Create("DPanel",Main)
TradePanel1:SetSize(550,500/2)
TradePanel1:SetPos(5,300)
TradePanel1:SetBackgroundColor(ColorBG1)
local TradePanel2 = vgui.Create("DPanel",Main)
TradePanel2:SetSize(550,500/2)
TradePanel2:SetPos(1200-550,300)
TradePanel2:SetBackgroundColor(ColorBG1)
local Items1 = vgui.Create("DGrid",Inventory1)
Items1:SetPos(5,5)
Items1:SetCols(6)
Items1:SetColWide(550/6)
Items1:SetRowHeight(550/6)
local Items1Send = vgui.Create("DGrid",TradePanel1)
Items1Send:SetPos(5,5)
Items1Send:SetCols(6)
Items1Send:SetColWide(550/6)
Items1Send:SetRowHeight(550/6)
local INV = LocalPlayer():GetInventory()
for k,v in pairs(INV) do
if v.untradable == false then
local GetInfo = msitems.Classes[v.data.class]
local Item = GetInfo.Inventory.name
local HoverText = GetInfo.Inventory.info
local Count = v.count
local GetInfo = msitems.Classes[v.data.class]
local ModelRef = string.split(Item," ")[#string.split(Item," ")]
local ModelStr = GetInfo.WorldModel
local ModelSZ = lookupSZ(ModelRef)
local Packed = {ModelStr,Item,HoverText,Count,ModelSZ}
local SET=MakePanel(Items1,Items1Send,ModelStr,Item,HoverText,Count,ModelSZ)
function SET.Internal:DoClick()
ConfirmSendItem(Items1Send,Packed)
end
Items1:AddItem(SET.Main)
end
end
local ConfirmClientside = vgui.Create("DButton",Main)
ConfirmClientside:SetPos(5,600-45)
ConfirmClientside:SetSize(240,40)
ConfirmClientside:SetText("")
function ConfirmClientside:Paint(BH,BW)
surface.SetDrawColor(0,0,0,128)
surface.DrawRect(0,0,BH,BW)
if ConfirmClientside:IsHovered() then
surface.SetDrawColor(0,255,0,64)
surface.DrawRect(0,0,BH,BW)
end
draw.DrawText("Confirm Trade",
"hdrdemotext",
BH/2,
BW/4,
Color( 255, 255, 255, 52 ),
TEXT_ALIGN_CENTER )
end
local AbortClientside = vgui.Create("DButton",Main)
AbortClientside:SetPos(550-235,600-45)
AbortClientside:SetSize(240,40)
AbortClientside:SetText("")
function AbortClientside:Paint(BH,BW)
surface.SetDrawColor(0,0,0,128)
surface.DrawRect(0,0,BH,BW)
if AbortClientside:IsHovered() then
surface.SetDrawColor(255,0,0,64)
surface.DrawRect(0,0,BH,BW)
end
draw.DrawText("Abort",
"hdrdemotext",
BH/2,
BW/4,
Color( 255, 255, 255, 52 ),
TEXT_ALIGN_CENTER )
end
end
msitems.OpenTradePanel()