-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcounter.ttslua
111 lines (100 loc) · 2.44 KB
/
counter.ttslua
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
CONFIG = {
MIN_VALUE = -99,
MAX_VALUE = 999,
FONT_COLOR = {0,0,0,95},
COLOR_HEX = "#000000",
TOOLTIP_SHOW = true,
VALUE = 0
}
INJECTED_COUNTER = true
function onload(saved_data)
if saved_data ~= "" then
local loaded_data = JSON.decode(saved_data)
CONFIG = loaded_data
end
createAll()
end
function updateSave()
saved_data = JSON.encode(CONFIG)
self.script_state = saved_data
end
function createAll()
if CONFIG.TOOLTIP_SHOW then
ttText = self.getName().. ": " .. CONFIG.VALUE
else
ttText = self.getName()
end
local scale = {x=1.5, y=1.5, z=1.5}
local thickness = self.getBoundsNormalized().size.y
if self.name == "Custom_Tile" then
thickness = thickness*2
scale = {0.75, 0.75, 0.75}
end
self.createButton({
label=tostring(CONFIG.VALUE),
click_function="add_subtract",
tooltip=ttText,
function_owner=self,
position={0, thickness/2, -0.2},
height=600,
width=1000,
alignment = 3,
scale=scale,
font_size=600,
font_color=CONFIG.FONT_COLOR,
color={0,0,0,0}
})
self.createInput({
value = self.getName(),
input_function = "editName",
tooltip=ttText,
label = "",
function_owner = self,
alignment = 3,
position = {0,thickness/2,1.7},
width = 1200,
height = 1000,
font_size = 200,
scale={x=1, y=1, z=1},
font_color= CONFIG.FONT_COLOR,
color = {0,0,0,0}
})
setTooltips()
end
function editName(_obj, _string, value)
self.setName(value)
setTooltips()
end
function add_subtract(_obj, _color, alt_click)
mod = alt_click and -1 or 1
new_value = math.min(math.max(CONFIG.VALUE + mod, CONFIG.MIN_VALUE), CONFIG.MAX_VALUE)
if CONFIG.VALUE ~= new_value then
CONFIG.VALUE = new_value
updateVal()
updateSave()
end
end
function updateVal()
self.editButton({
index = 0,
label = tostring(CONFIG.VALUE)
})
setTooltips()
end
function setTooltips()
if CONFIG.TOOLTIP_SHOW then
ttText = self.getName().. ": " .. CONFIG.VALUE
else
ttText = self.getName()
end
self.editInput({
index = 0,
value = self.getName(),
tooltip = ttText
})
self.editButton({
index = 0,
value = tostring(CONFIG.VALUE),
tooltip = ttText
})
end