-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customselectorv1.ttslua
168 lines (155 loc) · 6.53 KB
/
Customselectorv1.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
158
159
160
161
162
163
164
165
166
167
168
function change_section(player, value, id)
self.UI.setAttribute(id.." Villains", "active", value)
end
function select_villain(player, value, id)
switchCharacter(self.UI.getAttribute(id, "section"), id, player.color)
end
function random_villain(player, value, id)
local chosen = ALL_VILLAINS[math.random(1, #ALL_VILLAINS)]
switchCharacter(chosen[1], chosen[2], player.color)
end
function getChar(section, char)
local objects = {}
if EVERYTHING[section][char] ~= nil then
objects=EVERYTHING[section][char].data
end
if #objects==0 then
print("Character not found")
end
return objects
end
function switchCharacter(section, character, color)
local my_rot = self.getRotation()
local objects = getChar(section, character)
local scale = self.getScale()
scale.x = 1/scale.x
scale.z = 1/scale.z
self.destruct()
function callback(o)
o.setRotation({o.getRotation().x, o.getRotation().y+my_rot.y, o.getRotation().z})
end
for _,v in ipairs(objects) do
local new_pos = self.positionToWorld(Vector(v.move_to) * scale)
spawnObjectJSON({
json = v.json,
position = new_pos,
callback_function = callback
})
end
local direction = Vector(0, 4, 12)
direction:rotateOver("y", my_rot.y)
-- forward = forward*2
Player[color].setHandTransform({
position = self.getPosition()+direction,
rotation = {0, my_rot.y+180, 0},
scale = {8, 6, 4}
})
end
function create_UI()
local assets = {
{
name="header-background",
url="http://cloud-3.steamusercontent.com/ugc/1028454670709160530/243DE2833443E033AC8F1EC4731C2F8519C65A45/"
},
}
local toggles = {}
local total_toggles = 50
local table_layouts = {}
ALL_VILLAINS = {}
for section, villains in pairs(EVERYTHING) do
if section ~= "Official" then
local tmp = {tag="ToggleButton", attributes={class="section-button", text=section, id=section}}
if section == "Playtesting" then
table.insert(toggles, {tag="Panel", attributes={height=498-total_toggles-50, flexibleHeight=false, preferredHeight=498-total_toggles}})
end
table.insert(toggles, tmp)
total_toggles = total_toggles + 50
table.insert(table_layouts, {tag="TableLayout", attributes={class="villains", id=section.." Villains", active=false}, children={}})
local this_villains={}
for villain, info in pairs(villains) do
table.insert(this_villains, {villain, info.tooltip})
table.insert(ALL_VILLAINS, {section, villain})
table.insert(assets, {name=villain, url=info.image})
end
local table_layout = {}
for y=1, 3 do
local row = {tag="Row", children={}}
for x=1, 5 do
local cell = {}
if #this_villains > 0 then
local vil = table.remove(this_villains, 1)
cell = {tag="Cell", children={
{tag="Button", attributes={id=vil[1], section=section, class="villain-button", image=vil[1]}},
{tag="text", attributes={class="Villain-tooltip", text=vil[2]}},
}}
else
cell = {tag="Cell"}
end
table.insert(row.children, cell)
end
table.insert(table_layout, row)
end
table_layouts[#table_layouts].children = table_layout
end
end
table_layouts[1].attributes.active=true
toggles[1].attributes.isOn=True
table.insert(toggles, {tag="ToggleButton", attributes={class="section-button", text="Random Custom", id="Random", onClick="random_villain"}})
local ui ={
{tag="Defaults", children={
{tag="ToggleButton", attributes={
class="section-button",
Height=50,
flexibleHeight=false,
preferredHeight=50,
resizeTextForBestFit=true,
image="header-background",
textAlignment="MiddleCenter",
padding="2 2 3 3",
textColor="White",
onValueChanged="change_section"}},
{tag="Button", attributes={
class="villain-button",
preserveAspect=true,
onClick="select_villain",
preferredHeight=50,
ignoreLayout=True}},
{tag="Text", attributes={
class="Villain-tooltip",
color="White",
rectAlignment="LowerCenter",
height="30%",
ignoreLayout=true,
fontSize=20,
resizeTextForBestFit=true}},
{tag="TableLayout", attributes={
class="villains",
position="-19 15 -3",
scale=".25 .25 .25",
Rotation="0 0 180",
width=660,
height=530,
cellSpacing=12,
cellBackgroundColor="rgba(0,0,0,0)"}},
}},
{tag="ToggleGroup", attributes={id="sections"}, children={
{tag="VerticalLayout", attributes={Rotation="180 180 0", position="86 14 -3", width=121, height=498, scale=".25 .25 .25", spacing=10}, children=toggles}
}},
}
for _, layout in ipairs(table_layouts) do
table.insert(ui, layout)
end
self.UI.setCustomAssets(assets)
Wait.frames(||self.UI.setXmlTable(ui), 2)
end
function onLoad()
log("Setting everything on "..self.guid)
EVERYTHING = find_object_by_name("The keeper of information").getTable('EVERYTHING')
create_UI()
end
function find_object_by_name(name)
for _, obj in ipairs(getAllObjects()) do
if obj.getName() == name then return obj end
end
return nil
end