-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathicon_registry.lua
112 lines (78 loc) · 2.09 KB
/
icon_registry.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
-- Copyright 2014 David Mentler
include( "circular_queue.lua" )
tshop.IconQueue = tshop.IconQueue or CircularQueue()
tshop.IconHash = tshop.IconHash or {}
local queue = tshop.IconQueue
local hash = tshop.IconHash
local function getIconPath( model )
return string.format( "spawnicons/tshop/%s.png", model:match( "(.+).mdl" ) )
end
local function getIconUID( model )
return "tshop/" .. model:lower()
end
function tshop.RequestIcon( model, panel )
local iconID = getIconUID( model )
local pending = hash[iconID]
if pending then
table.insert( pending, panel )
return
end
-- Check if the icon exists
local path = getIconPath( model )
if file.Exists( "materials/" .. path, "MOD" ) then
panel.Icon = Material( path )
return
end
hash[iconID] = { panel }
queue:Add( model )
end
do
tshop.rIcon = tshop.rIcon or vgui.Create( "ModelImage" )
tshop.rModel = tshop.rModel or ClientsideModel( "error" )
local rIcon = tshop.rIcon
local rModel = tshop.rModel
local rTable = {
ent = rModel,
cam_pos = Vector(),
cam_ang = Angle(),
cam_fov = 90
}
local rTexture
rIcon:SetVisible( false )
rIcon:SetSize( 64, 64 )
rModel:SetNoDraw( true )
function rModel:RenderOverride()
if not rTexture then return end
cam.Start2D()
surface.SetMaterial( rTexture )
surface.SetDrawColor( 255, 255, 255 )
surface.DrawTexturedRect( 0, 0, 128, 128 )
cam.End2D()
end
hook.Add( "HUDPaint", "TShop: ProcessIconQueue", function()
if queue:IsEmpty() then
return
end
-- Render icon
local model = queue:Pop()
rTexture = tshop.RenderModelIcon(model)
rIcon:SetModel( getIconUID(model) )
rIcon:RebuildSpawnIconEx( rTable )
end )
hook.Add( "SpawniconGenerated", "TShop: IconPopulate", function( model, image )
local pending = hash[model]
if pending then
local path = image:gsub( "materials\\", "" )
local icon = Material( path )
-- Force the icon to refresh
icon:GetTexture( "$basetexture" ):Download()
for index, panel in ipairs( pending ) do
panel.Icon = icon
end
hash[model] = nil
end
if !pending then
print( model )
end
end )
end