-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathcl_hooks.lua
252 lines (202 loc) · 6 KB
/
cl_hooks.lua
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
local PLUGIN = PLUGIN
local function DrawTextBackground(x, y, text, font, backgroundColor, padding)
font = font or "ixSubTitleFont"
padding = padding or 8
backgroundColor = backgroundColor or Color(88, 88, 88, 255)
surface.SetFont(font)
local textWidth, textHeight = surface.GetTextSize(text)
local width, height = textWidth + padding * 2, textHeight + padding * 2
ix.util.DrawBlurAt(x, y, width, height)
surface.SetDrawColor(0, 0, 0, 40)
surface.DrawRect(x, y, width, height)
derma.SkinFunc("DrawImportantBackground", x, y, width, height, backgroundColor)
surface.SetTextColor(color_white)
surface.SetTextPos(x + padding, y + padding)
surface.DrawText(text)
return height
end
function PLUGIN:InitPostEntity()
hook.Run("SetupAreaProperties")
end
function PLUGIN:ChatboxCreated()
if (IsValid(self.panel)) then
self.panel:Remove()
end
self.panel = vgui.Create("ixArea")
end
function PLUGIN:ChatboxPositionChanged(x, y, width, height)
if (!IsValid(self.panel)) then
return
end
self.panel:SetSize(width, y)
self.panel:SetPos(32, 0)
end
function PLUGIN:ShouldDrawCrosshair()
if (ix.area.bEditing) then
return true
end
end
function PLUGIN:PlayerBindPress(client, bind, bPressed)
if (!ix.area.bEditing) then
return
end
if ((bind:find("invnext") or bind:find("invprev")) and bPressed) then
return true
elseif (bind:find("attack2") and bPressed) then
self:EditRightClick()
return true
elseif (bind:find("attack") and bPressed) then
self:EditClick()
return true
elseif (bind:find("reload") and bPressed) then
self:EditReload()
return true
end
end
function PLUGIN:HUDPaint()
if (!ix.area.bEditing) then
return
end
local id = LocalPlayer():GetArea()
local area = ix.area.stored[id]
local height = ScrH()
local y = 64
y = y + DrawTextBackground(64, y, L("areaEditMode"), nil, ix.config.Get("color"))
if (!self.editStart) then
y = y + DrawTextBackground(64, y, L("areaEditTip"), "ixSmallTitleFont")
DrawTextBackground(64, y, L("areaRemoveTip"), "ixSmallTitleFont")
else
DrawTextBackground(64, y, L("areaFinishTip"), "ixSmallTitleFont")
end
if (area) then
DrawTextBackground(64, height - 64 - ScreenScale(12), id, "ixSmallTitleFont", area.properties.color)
end
end
function PLUGIN:PostDrawTranslucentRenderables(bDepth, bSkybox)
if (bSkybox or !ix.area.bEditing) then
return
end
-- draw all areas
for k, v in pairs(ix.area.stored) do
local center, min, max = self:GetLocalAreaPosition(v.startPosition, v.endPosition)
local color = ColorAlpha(v.properties.color or ix.config.Get("color"), 255)
render.DrawWireframeBox(center, angle_zero, min, max, color)
cam.Start2D()
local centerScreen = center:ToScreen()
local _, textHeight = draw.SimpleText(
k, "BudgetLabel", centerScreen.x, centerScreen.y, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
if (v.type != "area") then
draw.SimpleText(
"(" .. L(v.type) .. ")", "BudgetLabel",
centerScreen.x, centerScreen.y + textHeight, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER
)
end
cam.End2D()
end
-- draw currently edited area
if (self.editStart) then
local center, min, max = self:GetLocalAreaPosition(self.editStart, self:GetPlayerAreaTrace().HitPos)
local color = Color(255, 255, 255, 25 + (1 + math.sin(SysTime() * 6)) * 115)
render.DrawWireframeBox(center, angle_zero, min, max, color)
cam.Start2D()
local centerScreen = center:ToScreen()
draw.SimpleText(L("areaNew"), "BudgetLabel",
centerScreen.x, centerScreen.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
cam.End2D()
end
end
function PLUGIN:EditRightClick()
if (self.editStart) then
self.editStart = nil
else
self:StopEditing()
end
end
function PLUGIN:EditClick()
if (!self.editStart) then
self.editStart = LocalPlayer():GetEyeTraceNoCursor().HitPos
elseif (self.editStart and !self.editProperties) then
self.editProperties = true
local panel = vgui.Create("ixAreaEdit")
panel:MakePopup()
end
end
function PLUGIN:EditReload()
if (self.editStart) then
return
end
local id = LocalPlayer():GetArea()
local area = ix.area.stored[id]
if (!area) then
return
end
Derma_Query(L("areaDeleteConfirm", id), L("areaDelete"),
L("no"), nil,
L("yes"), function()
net.Start("ixAreaRemove")
net.WriteString(id)
net.SendToServer()
end
)
end
function PLUGIN:ShouldDisplayArea(id)
if (ix.area.bEditing) then
return false
end
end
function PLUGIN:OnAreaChanged(oldID, newID)
local client = LocalPlayer()
client.ixArea = newID
local area = ix.area.stored[newID]
if not area then
client.ixInArea = false
hook.Run("OnLeaveArea", oldID)
return
end
client.ixInArea = true
if hook.Run("ShouldDisplayArea", newID) == false or not area.properties.display then return end
local format = newID .. (ix.option.Get("24hourTime", false) and ", %H:%M." or ", %I:%M %p.")
format = ix.date.GetFormatted(format)
self.panel:AddEntry(format, area.properties.color)
end
net.Receive("ixAreaEditStart", function()
PLUGIN:StartEditing()
end)
net.Receive("ixAreaEditEnd", function()
PLUGIN:StopEditing()
end)
net.Receive("ixAreaAdd", function()
local name = net.ReadString()
local type = net.ReadString()
local startPosition, endPosition = net.ReadVector(), net.ReadVector()
local properties = net.ReadTable()
if (name != "") then
ix.area.stored[name] = {
type = type,
startPosition = startPosition,
endPosition = endPosition,
properties = properties
}
end
end)
net.Receive("ixAreaRemove", function()
local name = net.ReadString()
if (ix.area.stored[name]) then
ix.area.stored[name] = nil
end
end)
net.Receive("ixAreaSync", function()
local length = net.ReadUInt(32)
local data = net.ReadData(length)
local uncompressed = util.Decompress(data)
if (!uncompressed) then
ErrorNoHalt("[Helix] Unable to decompress area data!\n")
return
end
-- Set the list of texts to the ones provided by the server.
ix.area.stored = util.JSONToTable(uncompressed)
end)
net.Receive("ixAreaChanged", function()
local oldID, newID = net.ReadString(), net.ReadString()
hook.Run("OnAreaChanged", oldID, newID)
end)