-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathlayout.js
245 lines (215 loc) · 10.3 KB
/
layout.js
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
$(document).ready(function() {
// --------------------------------------------------------------------------------
// Create an instance of our docker window and assign it to the document.
var myDocker = new wcDocker('.dockerContainer', {
allowDrawers: true,
responseRate: 10,
themePath: 'app://js/Themes',
theme: 'default'
})
if (myDocker) {
var _currentTheme = 'default'
var _showingInfo = true
var _savedLayout = null
var _chatterIndex = 1
myDocker.registerPanelType('NodePanel', {
faicon: 'compass',
onCreate: function(myPanel) {
myPanel.title("节点面板")
myPanel.initSize(240, 400)
myPanel.maxSize(Infinity, Infinity)
var $node = $('<ve-nodeorder id="NodePanel" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></ve-nodeorder>')
myPanel._main = $node[0]
myPanel.layout().addItem($node).stretch('', '100%')
}
})
myDocker.registerPanelType('ResourcePanel', {
faicon: 'plus-square',
onCreate: function(myPanel) {
myPanel.title("资源面板")
myPanel.initSize(240, 400)
var $node = $('<ve-resorder style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></ve-resorder>')
myPanel._main = $node[0]
myPanel.layout().addItem($node).stretch('', '100%')
}
})
myDocker.registerPanelType('ControlPanel', {
faicon: 'cog',
onCreate: function(myPanel) {
myPanel.title("控件")
myPanel.maxSize(135, Infinity)
var $node = $('<ve-controlpanel style="position:absolute;top:0px;left:0px;right:0px;bottom:0px; "></ve-controlpanel>')
myPanel._main = $node[0]
myPanel.layout().addItem($node).stretch('', '100%')
}
})
myDocker.registerPanelType('ConsolePanel', {
faicon: 'archive',
onCreate: function(myPanel) {
myPanel.title("控制台面板")
var $node = $('<ve-console style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></ve-console>')
myPanel._main = $node[0]
myPanel.layout().addItem($node).stretch('', '100%')
}
})
myDocker.registerPanelType('RenderPanel', {
isPersistent: true,
faicon: 'github',
onCreate: function(myPanel) {
myPanel.title("渲染面板")
myPanel.closeable(false);
var $tabArea = $('<div style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;">')
myPanel.layout().addItem($tabArea)
var tabFrame = new wcTabFrame($tabArea, myPanel)
// var $node = $('<ve-renderpanel id="render" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></ve-renderpanel>')
// tabFrame.addTab('Unknow', -1, wcDocker.LAYOUT.SIMPLE).addItem($node)
// myPanel._main = $node[0]
// tabFrame.closeable(0, true) // 0 based index 3 is actually Custom Tab 4
// tabFrame.faicon(0, 'gears')
myPanel.on(wcDocker.EVENT.RESIZED, function(data) {
Ipc.sendToAll('panelResized')
})
let curActivePanel = null;
myPanel.messages = {}
myPanel.messages['ui:open_file'] = function(event, message) {
if (!endWith(message.path, ".ui")) {
return;
}
let subPath = calcRelativePath(window.projectFolder + '/', message.path)
for (var i = 0; i < tabFrame.tabCount(); i++) {
let layout = tabFrame.layout(i)
if (layout.name == subPath || layout.name == subPath + '*') {
tabFrame.tab(i, true)
return
}
}
var $node = $('<ve-renderpanel id="render" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></ve-renderpanel>')
let newLayout = tabFrame.addTab(subPath, 0, wcDocker.LAYOUT.SIMPLE)
newLayout.addItem($node)
tabFrame.tab(0, true)
tabFrame.closeable(0, true)
newLayout._main = $node[0]
myPanel._main = $node[0]
myPanel._layout = newLayout
curActivePanel = $node[0];
Ipc.sendToAll('ui:open_scene_file', message)
}
myPanel.messages['ui:new-ui-file'] = function(event, message) {
let name = ""
for (var j = 0; j < 100; j++) {
name = "Unknow" + j;
let isFind = false;
for (var i = 0; i < tabFrame.tabCount(); i++) {
let layout = tabFrame.layout(i)
if (layout.name == name || layout.name == name + '*') {
isFind = true;
break
}
}
if (!isFind) {
break
}
}
var $node = $('<ve-renderpanel id="render" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></ve-renderpanel>')
let newLayout = tabFrame.addTab(name, 0, wcDocker.LAYOUT.SIMPLE)
newLayout.addItem($node)
tabFrame.tab(0, true)
newLayout._main = $node[0]
myPanel._main = $node[0]
myPanel._layout = newLayout
curActivePanel = $node[0];
Ipc.sendToAll('ui:open_scene_file', { path: name }, true)
}
myPanel.messages['ui:name-change'] = function(event, message) {
if (myPanel._layout.name != message) {
myPanel._layout.name = message
tabFrame.__updateTabs();
}
}
let tabChanged = function(index) {
let layout = tabFrame.layout(index)
myPanel._layout = layout
if (!layout) {
curActivePanel = null
Ipc.sendToAllPanel('ui:new-ui-file')
return
}
myPanel._main = layout._main
curActivePanel = layout._main;
Ipc.sendToAll('ui:cur_tab_select', { index: index })
}
let removeCallback = function(obj) {
if (myPanel._close_by_render == true) {
return true
}
obj.layout._main.ensureExitCurRender();
return false
}
myPanel.messages['ui:closeCurRender'] = function(event, message) {
myPanel._close_by_render = true
tabFrame.removeTab(tabFrame._curTab)
tabChanged(tabFrame._curTab)
myPanel._close_by_render = false
}
myPanel.on(wcDocker.EVENT.CUSTOM_TAB_CHANGED, function(data) {
tabChanged(data.index)
})
tabFrame.setRemoveCallback(removeCallback);
setInterval(function() {
if (curActivePanel) {
let runScene = curActivePanel.$.scene.getRunScene()
if (!runScene) {
return;
}
if (runScene._undo.isSaved()) {
Ipc.sendToAllPanel("ui:name-change", curActivePanel._localName)
} else {
Ipc.sendToAllPanel("ui:name-change", curActivePanel._localName + "*")
}
}
}, 1000);
}
})
myDocker.registerPanelType('PropPanel', {
faicon: 'arrows',
onCreate: function(myPanel) {
myPanel.title("属性面板")
var $node = $('<ve-proppanel style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;"></ve-proppanel>')
myPanel._main = $node[0]
myPanel.layout().addItem($node).stretch('', '100%')
}
})
myDocker.registerPanelType('Theme Builder', {
faicon: 'map',
onCreate: wcThemeBuilder
})
global.myDocker = myDocker
myDocker.startLoading('Loading...')
myDocker.setInitLayout = function() {
myDocker.clear()
var nodePanel = myDocker.addPanel('NodePanel', wcDocker.DOCK.LEFT, null)
var controlPanel = myDocker.addPanel('ControlPanel', wcDocker.DOCK.RIGHT, null, { w: '200px' })
var renderPanel = myDocker.addPanel('RenderPanel', wcDocker.DOCK.RIGHT, controlPanel)
var propPanel = myDocker.addPanel('PropPanel', wcDocker.DOCK.RIGHT, null, { w: '200px' })
var consolePanel = myDocker.addPanel('ConsolePanel', wcDocker.DOCK.BOTTOM, wcDocker.COLLAPSED, { h: '20%' })
var resourcePanel = myDocker.addPanel('ResourcePanel', wcDocker.DOCK.BOTTOM, nodePanel, { h: '60%' })
// var gridPanel = myDocker.addPanel('GridPanel', wcDocker.DOCK.LEFT, wcDocker.COLLAPSED, {h: '20%'})
}
if (getSaveData('saveLayout')) {
myDocker.restore(getSaveData('saveLayout'))
} else {
var data = GetFileContent("layout.json");
if (data) {
myDocker.restore(data)
} else {
myDocker.setInitLayout()
}
}
myDocker.on(wcDocker.EVENT.LOADED, function() {
myDocker.finishLoading(500)
})
document.body.addEventListener('keydown', function(event) {
Ipc.sendToAll('ui:keydownEvent', { keyCode: event.keyCode, ctrlKey: isCtrlKey(event), shiftKey: event.shiftKey, altKey: event.altKey })
})
}
})