-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqz_zoom.lua
More file actions
213 lines (163 loc) · 5.64 KB
/
Copy pathqz_zoom.lua
File metadata and controls
213 lines (163 loc) · 5.64 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
require "base/internal/ui/reflexcore"
qz_zoom =
{
canPosition = false
};
registerWidget("qz_zoom");
local DEBUG = false
---------------------------------------------
---------------------------------------------
local function DrawOptionsHeader(text, x, y, offsetx, lengthx)
uiLabel(text, x, y);
nvgBeginPath();
nvgMoveTo(x + offsetx, y + 33);
nvgLineTo(x + offsetx + lengthx, y + 33);
nvgStrokeWidth(1);
nvgStrokeColor(Color(150, 150, 150, 80));
nvgStroke();
end
---------------------------------------------
---------------------------------------------
function qz_zoom:initialize()
self.userData = loadUserData()
CheckSetDefaultValue(self, "userData", "table", {})
CheckSetDefaultValue(self.userData, "key", "string", "(unbound)")
CheckSetDefaultValue(self.userData, "default_fov", "number", consoleGetVariable("r_fov"))
CheckSetDefaultValue(self.userData, "default_sens", "number", consoleGetVariable("m_speed"))
CheckSetDefaultValue(self.userData, "zoom_fov", "number", 90)
CheckSetDefaultValue(self.userData, "animate", "boolean", true)
CheckSetDefaultValue(self.userData, "anim_speed", "number", 5)
CheckSetDefaultValue(self.userData, "auto_sens", "boolean", true)
CheckSetDefaultValue(self.userData, "sens_mult", "number", 1)
widgetCreateConsoleVariable("bind", "int", 0)
end
function qz_zoom:drawOptions(x, y)
local sliderWidth = 200
local sliderStart = 140
local user = self.userData
y = y + 20
---------------
---------------
DrawOptionsHeader("Input", x, y, -5, 560);
y = y + 40
local k = nil
local key = string.upper(user.key)
uiLabel("Zoom Key", x, y)
k = inputGrabRegion(x + sliderStart, y+3, 100, 30, "game")
local strCol
if k.focus then
strCol = Color(190, 40, 10, 190)
else strCol = Color(22,22,22,190)
end
nvgBeginPath()
nvgRoundedRect(x + sliderStart, y+3, 100, 30, 3)
nvgFillColor(Color(62,63,67,255))
nvgStrokeColor(strCol)
nvgFill()
nvgStroke()
-- text
nvgFontSize(20);
nvgFontFace(FONT_TEXT);
nvgFillColor(Color(142,142,142,255));
nvgTextAlign(NVG_ALIGN_LEFT, NVG_ALIGN_MIDDLE);
nvgText(x+sliderStart+5, y+30/2+3, key);
if k.nameKeyPressed ~= nil then
user.key = k.nameKeyPressed
end
y = y + 40
---------------
---------------
DrawOptionsHeader("FOV", x, y, -5, 560);
y = y + 40
uiLabel("Default FOV", x, y)
user.default_fov = round(uiSlider(x + sliderStart, y, sliderWidth, 20, 150, user.default_fov))
user.default_fov = round(uiEditBox(user.default_fov, x + sliderStart + sliderWidth + 10, y, 60))
y = y + 40
uiLabel("Zoom FOV", x, y)
user.zoom_fov = round(uiSlider(x + sliderStart, y, sliderWidth, 20, user.default_fov, user.zoom_fov))
user.zoom_fov = round(uiEditBox(user.zoom_fov, x + sliderStart + sliderWidth + 10, y, 60))
y = y + 40
---------------
---------------
y = y + 20
DrawOptionsHeader("Sensitivity", x, y, -5, 560);
y = y + 40
uiLabel("Default Sens", x, y)
user.default_sens = clampTo2Decimal(uiSlider(x + sliderStart, y, sliderWidth, 0.1, 30, user.default_sens))
user.default_sens = clampTo2Decimal(uiEditBox(user.default_sens, x + sliderStart + sliderWidth + 10, y, 60))
y = y + 40
user.auto_sens = uiCheckBox(user.auto_sens, "Auto multiplier", x, y);
y = y + 40
if not user.auto_sens then
uiLabel("Sens Multiplier", x, y)
user.sens_mult = clampTo2Decimal(uiSlider(x + sliderStart, y, sliderWidth, 0.1, 2, user.sens_mult))
user.sens_mult = clampTo2Decimal(uiEditBox(user.sens_mult, x + sliderStart + sliderWidth + 10, y, 60))
y = y + 40
end
---------------
---------------
y = y + 20
DrawOptionsHeader("Animation", x, y, -5, 560);
y = y + 40
user.animate = uiCheckBox(user.animate, "Animate", x, y);
y = y + 30;
if user.animate then
user.anim_speed = round(uiSlider(x + sliderStart, y, sliderWidth, 1, 10, user.anim_speed))
user.anim_speed = round(uiEditBox(user.anim_speed, x + sliderStart + sliderWidth + 10, y, 60))
y = y + 40
end
saveUserData(user);
end
local zoomed = false
local animating = false
local next_fov
function qz_zoom:draw()
-- Early out if HUD shouldn't be shown.
if not shouldShowHUD() then return end;
local default_fov = self.userData.default_fov
local zoom_fov = self.userData.zoom_fov
local default_sens = self.userData.default_sens
local sens_mult = self.userData.sens_mult
local nextSens
local animate = self.userData.animate
if next_fov == nil then next_fov = default_fov end
local curr_fov = consoleGetVariable("r_fov")
local zoom_sens
if self.userData.auto_sens then
zoom_sens = default_sens * (zoom_fov/default_fov)
else
zoom_sens = default_sens * sens_mult
end
local speed
if animate then speed = (deltaTime*self.userData.anim_speed/100)/(1/250)
else speed = 1
end
if widgetGetConsoleVariable("bind") == 1 then
next_fov = lerp(next_fov, zoom_fov, speed)
next_fov = math.floor(next_fov)
nextSens = zoom_sens
else
next_fov = lerp(next_fov, default_fov, speed)
next_fov = math.ceil(next_fov)
nextSens = default_sens
end
if curr_fov >= default_fov then zoomed = false
elseif curr_fov <= zoom_fov then zoomed = true
end
if zoomed then
consolePerformCommand("bind game " .. self.userData.key .. " ui_qz_zoom_bind 0")
else
consolePerformCommand("bind game " .. self.userData.key .. " ui_qz_zoom_bind 1")
end
if DEBUG then
nvgText(0, 50, widgetGetConsoleVariable("bind"))
nvgText(0, 60, curr_fov)
nvgText(0, 70, next_fov)
nvgText(0, 80, consoleGetVariable("m_speed"))
if zoomed then nvgText(0, 90, "zoomed")
else nvgText(0, 90, "not zoomed")
end
end
consolePerformCommand("r_fov " .. next_fov);
consolePerformCommand("m_speed " .. nextSens);
end