aboutsummaryrefslogtreecommitdiff
path: root/gamemode/hud/draw_wepswap.lua
blob: 40c23100afe8d505e240ee338a22413f546cc86c (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
local Num = 0
local MCO = Color(0,0,0,150)

local max = math.max
local min = math.min
local cos = math.cos
local sin = math.sin
local rad = math.rad

local h = ScrH()
local s = 65
local B = s+5

function DrawWepSwap()
	local pl = LocalPlayer()
	if (pl:IsPigeon()) then return end
	if (GetRecentSwapTime() < CurTime()-3 and !IsInventoryOpen()) then return end
	
	local Slot = GetWeaponSlot()
	
	Num = Num+math.Clamp((Slot-Num)/6,-1,1)
	
	if (!IsInventoryOpen()) then MCO.a = 150*min(1,GetRecentSwapTime()-(CurTime()-3))
	else MCO.a = 150 end
	
	local Ib = input.MousePress(MOUSE_LEFT,"Unequip")
	
	for i = 0,9 do
		local r = Num-i
		local x = max(0,B*r)
		local y = max(0,B*-r)
		
		if (Slot == i) then MCO.b = 150
		else MCO.b = 0 end
		
		DrawRect(x+10,h-s-y-10,s,s,MCO)
		
		if (pl.Weapons and pl.Weapons[i]) then
			if (pl.Weapons[i].Item.Icon) then DrawMaterialRect(x+10,h-s-y-10,s,s,MAIN_WHITECOLOR,pl.Weapons[i].Item.Icon) end
			
			if (input.IsMouseInBox(x+10,h-s-y-10,s,s) and Ib) then
				RequestUnEquip(i)
				timer.Simple(0.05,function() ReloadInventory() end)
			end
		end
	end
end

function IsMouseInSlot()
	local mx,my = gui.MousePos()
	
	for i = 0,9 do
		local r = Num-i
		local x = max(0,B*r)
		local y = max(0,B*-r)
		
		if (input.IsMouseInBox(x+10,h-s-y-10,s,s)) then
			return i
		end
	end
	
	return false
end