-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcounterv3.ttslua
157 lines (143 loc) · 3.52 KB
/
counterv3.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
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
CONFIG = {
MIN_VALUE = -99,
MAX_VALUE = 999,
FONT_COLOR = {0,0,0,95},
FONT_SIZE = 600,
COLOR_HEX = "#000000",
TOOLTIP_SHOW = true,
VALUE = 0,
CONTEXT_FIVE = true,
CONTEXT_TEN = true,
NUMBER_TYPED = true,
}
INJECTED_COUNTER = true
function onload(saved_data)
if saved_data ~= "" then
local loaded_data = JSON.decode(saved_data)
CONFIG = loaded_data
end
if CONFIG.CONTEXT_FIVE then
self.addContextMenuItem("+5", add_5, true)
self.addContextMenuItem("-5", sub_5, true)
end
if CONFIG.CONTEXT_TEN then
self.addContextMenuItem("+10", add_10, true)
self.addContextMenuItem("-10", sub_10, true)
end
if CONFIG.NUMBER_TYPED then
self.max_typed_number = CONFIG.MAX_VALUE
end
createAll()
end
function onNumberTyped(player_color, number_typed)
new_value = math.min(math.max(number_typed, CONFIG.MIN_VALUE), CONFIG.MAX_VALUE)
if CONFIG.VALUE ~= new_value then
CONFIG.VALUE = new_value
updateVal()
updateSave()
end
end
function add_10()
for x=1, 10 do
add_subtract(nil, nil, false)
end
end
function add_5()
for x=1, 5 do
add_subtract(nil, nil, false)
end
end
function sub_5()
for x=1, 5 do
add_subtract(nil, nil, true)
end
end
function sub_10()
for x=1, 10 do
add_subtract(nil, nil, true)
end
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=CONFIG.FONT_SIZE,
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 = CONFIG.FONT_SIZE/3,
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