-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.lua
More file actions
145 lines (122 loc) · 3.9 KB
/
ui.lua
File metadata and controls
145 lines (122 loc) · 3.9 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
require "ui.inspector"
require "ui.inspector_actions"
require "ui.blueprints"
-- Start / stop
function Client:startUi()
self.updateCounts = setmetatable({}, { __mode = 'k' }) -- `actor` -> count to force UI updates
self.openComponentBehaviorId = nil -- `behaviorId` of open component section
self.selectedInspectorTab = 'general'
self.inspectorTabs = {
{
name = 'general',
behaviors = { 'Drawing', 'Text', 'Tags', 'Body' },
},
{
name = 'movement',
behaviors = { 'Moving', 'Solid', 'Falling', 'CircleShape', 'Bouncy', 'Sliding', 'Slowdown', 'Friction', 'SpeedLimit', 'RotatingMotion', 'Sling', 'Drag' },
},
{
name = 'rules',
},
}
self.saveBlueprintDatas = setmetatable({}, { __mode = 'k' }) -- `actor` -> data for "save blueprint" popover
end
-- UI
function Client:_textActorHasTapTrigger(actor)
for behaviorId, component in pairs(actor.components) do
local behavior = self.behaviors[behaviorId]
if behavior.name == 'Rules' then
return behavior.handlers.componentHasTrigger(component, 'tap')
end
end
end
function Client:uiTextActorsData()
local textActors = {}
local textActorsContent = self.behaviorsByName.Text:parseComponentsContent(self.performing)
for actorId, component in pairs(self.behaviorsByName.Text.components) do
local actor = self.actors[actorId]
local visible = true
if self.performing then
visible = component.properties.visible or false
end
textActors[actorId] = {
content = textActorsContent[actorId],
order = component.properties.order,
visible = visible,
actor = actor,
isSelected = self.selectedActorIds[actorId] ~= nil,
hasTapTrigger = self:_textActorHasTapTrigger(actor),
}
end
ui.data({ textActors = textActors })
end
function Client:uiGlobalActions()
local actionsAvailable = {}
local actions = {}
actionsAvailable['onPlay'] = not self.performing
actions['onPlay'] = function()
endEditing()
end
actionsAvailable['onRewind'] = self.performing
actions['onRewind'] = function()
beginEditing()
end
local hasUndo, hasRedo = #self.undos > 0, #self.redos > 0
actionsAvailable['onUndo'] = hasUndo
actions['onUndo'] = function()
self:undo()
end
actionsAvailable['onRedo'] = hasRedo
actions['onRedo'] = function()
self:redo()
end
ui.data(
{
performing = self.performing,
hasSelection = next(self.selectedActorIds) ~= nil,
actionsAvailable = actionsAvailable,
},
{
actions = actions,
}
)
end
function Client:uiSettings()
for behaviorId, tool in pairs(self.tools) do
if tool.handlers.uiSettings then
tool:callHandler('uiSettings')
end
end
end
function Client:uiupdate()
-- Refresh tools first to make sure selections and applicable tool set are valid
self:applySelections()
-- Global actions
ui.pane('sceneCreatorGlobalActions', function()
self:uiGlobalActions()
end)
-- Blueprints
ui.pane('sceneCreatorBlueprints', function()
self:uiBlueprints()
end)
-- Inspector
ui.pane('sceneCreatorInspectorActions', function()
self:uiInspectorActions()
end)
local sceneCreatorInspectorProps = {}
local activeTool = self.activeToolBehaviorId and self.tools[self.activeToolBehaviorId]
if activeTool and activeTool.handlers.contentHeight then
sceneCreatorInspectorProps.contentHeight = activeTool.handlers.contentHeight()
end
ui.pane('sceneCreatorInspector', sceneCreatorInspectorProps, function()
self:uiInspector()
end)
-- Settings
ui.pane('sceneCreatorSettings', function()
self:uiSettings()
end)
-- Text actors
ui.pane('sceneCreatorTextActors', function()
self:uiTextActorsData()
end)
end