-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.lua
More file actions
249 lines (225 loc) · 5.81 KB
/
options.lua
File metadata and controls
249 lines (225 loc) · 5.81 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include "keys.lua"
#include "util.lua"
#include "counter.lua"
local EXTRA_SPACE = 10
local verticalSize
local lastVerticalSize
local firstDraw = true
verticalSizeSmooth = 0
local showHideKeybindSlider
local distanceFromCornerSlider
local updateFreqSlider
local numDecimalFiguresSlider
local sizeSlider
function translate(x, y)
UiTranslate(x, y)
verticalSize = verticalSize + y
end
function init()
showHideKeybindSlider = ALPHABET:find(getShowHideKeybind()) * 8 - 1
distanceFromCornerSlider = getDistanceFromCorner() * 2
updateFreqSlider = getUpdateFrequency() * 100
numDecimalFiguresSlider = getNumDecimalFigures() * 40
sizeSlider = getSize() * 2
initCounter()
end
function drawSlider(value, mapSliderValueFunc, formatLabelFunc, doneFunc)
-- Translate down by the height of the current font ('I' would work instead of 'O')
translate(0, select(2, UiGetTextSize("O")))
UiRect(200, 5)
UiPush()
translate(-100, 0)
local sliderValue, done = UiSlider("ui/common/dot.png", "x", value, 0, 200)
local mappedValue = mapSliderValueFunc(sliderValue)
translate(100, -22)
local textWidth, textHeight = UiText(formatLabelFunc(mappedValue))
UiPop()
if done then doneFunc(mappedValue) end
translate(0, textHeight + EXTRA_SPACE)
end
function drawCheckbox(checked, label, clickedFunc)
local image = "ui/common/box-"..(checked and "solid-6.png" or "outline-6.png")
local boxSize = 24
local textWidth, textHeight = UiGetTextSize(label or "O")
local width = textWidth + boxSize
UiPush()
UiAlign("left middle")
translate(-width / 2, 0)
UiButtonImageBox()
if UiImageButton(image, boxSize, boxSize) then
clickedFunc()
end
translate(boxSize, 0)
UiText(label)
UiPop()
translate(0, textHeight + EXTRA_SPACE - 2)
end
function draw()
UiPush()
drawOptions()
UiPop()
-- Calculate delta from FPS, which is funny
tickCounter(1 / math.max(GetFps(), 0.001))
-- Only update appearance of counter after potential change
if InputReleased("lmb") then
initCounter()
end
drawCounter()
end
function drawOptions()
-- Aligns all options so they are always centred
-- Recalculates height every draw() call to account for not always visible elements
-- The alignment is also smoothed
if verticalSize ~= lastVerticalSize then
SetValue("verticalSizeSmooth", verticalSize, "easeout", firstDraw and 0 or 0.2)
firstDraw = false
end
lastVerticalSize = verticalSize
verticalSize = 0
UiTranslate(UiCenter(), UiMiddle() - verticalSizeSmooth / 2)
UiAlign("center middle")
-- Title
UiFont("bold.ttf", 48)
UiText("FPSCounter Options")
-- Extra information
UiFont("regular.ttf", 22)
UiTranslate(0, 36)
UiText("(Finally! All FPS values, including those below 30, are now shown accurately. (Thanks devs!))")
UiFont("regular.ttf", 26)
UiTranslate(0, -36-22)
translate(0, 96)
-- Show prefix
drawCheckbox(
getShowPrefix(),
"Show \"FPS: \" Prefix",
function()
setShowPrefix(not getShowPrefix())
end
)
-- High contrast colour
drawCheckbox(
getHighContrast(),
"High Contrast Colour",
function()
setHighContrast(not getHighContrast())
end
)
-- Enable show/hide keybind
drawCheckbox(
getEnableShowHideKeybind(),
"Enable Show/Hide Keybind",
function()
setEnableShowHideKeybind(not getEnableShowHideKeybind())
end
)
if getEnableShowHideKeybind() then
drawSlider(
showHideKeybindSlider,
function(sliderValue)
showHideKeybindSlider = sliderValue
local index = sliderValue / 8 + 1
return ALPHABET:sub(index, index)
end,
function(mappedValue)
return "Show/Hide Keybind: "..mappedValue
end,
function(mappedValue)
setShowHideKeybind(mappedValue)
end
)
end
-- Alignment
UiPush()
UiFont("bold.ttf", 26)
UiText("Alignment")
UiPop()
translate(0, 24)
local currentAlignment = getAlignment()
UiPush()
for i, alignment in ipairs({ "Top Left", "Bottom Left", "Top Right", "Bottom Right" }) do
if i == 1 then translate(-100, 0) end
if i == 3 then translate(200, -19 - EXTRA_SPACE) end
-- Probably faster than an unnecessary modulo
local isBottom = i == 2 or i == 4
if isBottom then UiPush() end
drawCheckbox(
currentAlignment == alignment:lower(),
alignment,
function()
setAlignment(alignment:lower())
end
)
if isBottom then UiPop() end
end
UiPop()
translate(0, 65 + EXTRA_SPACE)
-- Distance from corner
drawSlider(
distanceFromCornerSlider,
function(sliderValue)
distanceFromCornerSlider = sliderValue
return roundToNearest(sliderValue / 2, 1)
end,
function(mappedValue)
return "Distance From Corner: "..mappedValue
end,
function(mappedValue)
setDistanceFromCorner(mappedValue)
end
)
-- Update frequency
drawSlider(
updateFreqSlider,
function(sliderValue)
updateFreqSlider = sliderValue
return roundToNearest(sliderValue / 100, 0.1)
end,
function(mappedValue)
return "Update Frequency: "..mappedValue.." seconds"
end,
function(mappedValue)
setUpdateFrequency(mappedValue)
end
)
-- Number of decimal figures
drawSlider(
numDecimalFiguresSlider,
function(sliderValue)
numDecimalFiguresSlider = sliderValue
return roundToNearest(sliderValue / 40, 1)
end,
function(mappedValue)
return "Decimal Places: "..mappedValue
end,
function(mappedValue)
setNumDecimalFigures(mappedValue)
end
)
-- Size
drawSlider(
sizeSlider,
function(sliderValue)
sizeSlider = sliderValue
return roundToNearest(sliderValue / 2, 1)
end,
function(mappedValue)
return "Size: "..mappedValue
end,
function(mappedValue)
setSize(mappedValue)
end
)
-- Reset to default button
translate(0, 20)
UiButtonImageBox("ui/common/box-outline-6.png", 6, 6, 0.7, 0.2, 0.2)
if UiTextButton("Reset to Default", 200, 40) then
resetKeysToDefault()
init()
end
-- Close button
translate(0, 45)
UiButtonImageBox("ui/common/box-outline-6.png", 6, 6)
if UiTextButton("Close", 200, 40) then
Menu()
end
end