2020-03-11 05:19:17 +08:00
|
|
|
class Mode extends KeybindItem {
|
2020-12-22 20:32:49 +08:00
|
|
|
constructor(id, data) {
|
|
|
|
if (typeof id == 'object') {
|
|
|
|
data = id;
|
|
|
|
id = data.id;
|
|
|
|
}
|
2022-01-26 23:14:31 +08:00
|
|
|
super(id, data)
|
2020-12-22 20:32:49 +08:00
|
|
|
this.id = id;
|
2020-03-11 05:19:17 +08:00
|
|
|
this.name = data.name || tl('mode.'+this.id);
|
|
|
|
this.selected = false
|
2020-12-22 20:32:49 +08:00
|
|
|
|
2020-03-11 05:19:17 +08:00
|
|
|
this.default_tool = data.default_tool;
|
2021-07-28 23:49:09 +08:00
|
|
|
this.selectElements = data.selectElements !== false
|
2021-12-01 18:49:35 +08:00
|
|
|
this.hidden_node_types = data.hidden_node_types instanceof Array ? data.hidden_node_types.slice() : [];
|
2020-12-22 20:32:49 +08:00
|
|
|
|
2020-03-11 05:19:17 +08:00
|
|
|
this.hide_toolbars = data.hide_toolbars
|
2020-12-22 20:32:49 +08:00
|
|
|
this.hide_sidebars = data.hide_sidebars
|
2021-01-11 04:05:30 +08:00
|
|
|
this.hide_status_bar = data.hide_status_bar
|
2020-12-22 20:32:49 +08:00
|
|
|
|
2020-03-11 05:19:17 +08:00
|
|
|
this.condition = data.condition;
|
|
|
|
this.onSelect = data.onSelect;
|
|
|
|
this.onUnselect = data.onUnselect;
|
2020-12-22 20:32:49 +08:00
|
|
|
|
2020-03-11 05:19:17 +08:00
|
|
|
Modes.options[this.id] = this;
|
2020-12-22 20:32:49 +08:00
|
|
|
|
|
|
|
if (data.component) {
|
|
|
|
let node = document.createElement('div');
|
|
|
|
let mount = document.createElement('div');
|
|
|
|
node.id = 'mode_screen_' + this.id;
|
|
|
|
node.appendChild(mount);
|
|
|
|
document.getElementById('center').appendChild(node);
|
|
|
|
|
|
|
|
this.vue = new Vue(data.component)
|
|
|
|
this.vue.$mount(mount);
|
|
|
|
}
|
2020-03-11 05:19:17 +08:00
|
|
|
}
|
|
|
|
select() {
|
|
|
|
if (Modes.selected) {
|
|
|
|
delete Modes[Modes.selected.id];
|
|
|
|
Modes.previous_id = Modes.selected.id;
|
|
|
|
}
|
|
|
|
if (typeof Modes.selected.onUnselect === 'function') {
|
2020-08-05 22:38:38 +08:00
|
|
|
Blockbench.dispatchEvent('unselect_mode', {mode: Modes.selected})
|
2020-03-11 05:19:17 +08:00
|
|
|
Modes.selected.onUnselect()
|
|
|
|
}
|
|
|
|
if (Modes.selected.selected) {
|
|
|
|
Modes.selected.selected = false
|
|
|
|
}
|
|
|
|
this.selected = true;
|
2020-08-05 22:38:38 +08:00
|
|
|
Mode.selected = this;
|
2020-03-11 05:19:17 +08:00
|
|
|
Modes.selected = this;
|
|
|
|
Modes[Modes.selected.id] = true;
|
2021-07-11 04:22:02 +08:00
|
|
|
if (Project) Project.mode = this.id;
|
2020-03-11 05:19:17 +08:00
|
|
|
|
|
|
|
document.body.setAttribute('mode', this.id);
|
|
|
|
|
2021-01-11 04:05:30 +08:00
|
|
|
$('#main_toolbar .toolbar_wrapper').css('visibility', this.hide_toolbars ? 'hidden' : 'visible');
|
|
|
|
$('#status_bar').css('display', this.hide_status_bar ? 'none' : 'flex');
|
2020-03-11 05:19:17 +08:00
|
|
|
|
2021-12-01 18:49:35 +08:00
|
|
|
Outliner.vue.options.hidden_types.replace(this.hidden_node_types);
|
|
|
|
|
2020-03-11 05:19:17 +08:00
|
|
|
if (typeof this.onSelect === 'function') {
|
|
|
|
this.onSelect()
|
|
|
|
}
|
2020-10-11 22:54:52 +08:00
|
|
|
if (Blockbench.isMobile) {
|
|
|
|
Interface.PanelSelectorVue.$forceUpdate();
|
|
|
|
Interface.PanelSelectorVue.select(null);
|
|
|
|
}
|
2020-03-11 05:19:17 +08:00
|
|
|
|
2021-12-11 05:03:34 +08:00
|
|
|
if (Interface.Panels[Prop.active_panel] && !Condition(Interface.Panels[Prop.active_panel].condition)) {
|
|
|
|
Prop.active_panel = 'preview';
|
|
|
|
}
|
|
|
|
|
2020-03-11 05:19:17 +08:00
|
|
|
updateInterface()
|
|
|
|
Canvas.updateRenderSides()
|
|
|
|
if (BarItems[this.default_tool]) {
|
|
|
|
BarItems[this.default_tool].select()
|
|
|
|
} else {
|
|
|
|
BarItems.move_tool.select()
|
|
|
|
}
|
|
|
|
TickUpdates.selection = true;
|
2020-08-05 22:38:38 +08:00
|
|
|
Blockbench.dispatchEvent('select_mode', {mode: this})
|
2020-03-11 05:19:17 +08:00
|
|
|
}
|
|
|
|
trigger() {
|
|
|
|
if (Condition(this.condition)) {
|
|
|
|
this.select()
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 06:23:16 +08:00
|
|
|
delete() {
|
|
|
|
if (Mode.selected == this) {
|
2021-07-07 19:08:56 +08:00
|
|
|
Modes.options.edit.select();
|
2020-11-28 06:23:16 +08:00
|
|
|
}
|
|
|
|
delete Modes.options[this.id];
|
|
|
|
}
|
2020-03-11 05:19:17 +08:00
|
|
|
}
|
|
|
|
const Modes = {
|
2020-11-28 06:23:16 +08:00
|
|
|
get id() {
|
|
|
|
return Mode.selected ? Mode.selected.id : 'edit'
|
|
|
|
},
|
2020-03-11 05:19:17 +08:00
|
|
|
selected: false,
|
|
|
|
options: {},
|
|
|
|
};
|
|
|
|
onVueSetup(function() {
|
|
|
|
Modes.vue = new Vue({
|
|
|
|
el: '#mode_selector',
|
|
|
|
data: {
|
|
|
|
options: Modes.options
|
2021-09-21 17:20:10 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
Condition
|
2020-03-11 05:19:17 +08:00
|
|
|
}
|
|
|
|
})
|
2021-07-07 19:08:56 +08:00
|
|
|
});
|
|
|
|
BARS.defineActions(function() {
|
2020-12-22 20:32:49 +08:00
|
|
|
new Mode('edit', {
|
2020-03-11 05:19:17 +08:00
|
|
|
default_tool: 'move_tool',
|
|
|
|
category: 'navigate',
|
2021-11-23 19:51:09 +08:00
|
|
|
condition: () => Format && !Format.pose_mode,
|
2021-12-08 01:31:16 +08:00
|
|
|
onUnselect: () => {
|
|
|
|
if (Undo) Undo.closeAmendEditMenu();
|
|
|
|
}
|
2020-03-11 05:19:17 +08:00
|
|
|
})
|
2020-12-22 20:32:49 +08:00
|
|
|
new Mode('paint', {
|
2020-03-11 05:19:17 +08:00
|
|
|
default_tool: 'brush_tool',
|
|
|
|
category: 'navigate',
|
|
|
|
condition: () => Format,
|
|
|
|
onSelect: () => {
|
|
|
|
if (Modes.previous_id == 'animate') {
|
|
|
|
Animator.preview();
|
|
|
|
}
|
2021-09-22 03:13:24 +08:00
|
|
|
Outliner.elements.forEach(cube => {
|
|
|
|
if (cube.preview_controller.updatePaintingGrid) cube.preview_controller.updatePaintingGrid(cube);
|
2020-03-11 05:19:17 +08:00
|
|
|
})
|
|
|
|
$('#main_colorpicker').spectrum('set', ColorPanel.vue._data.main_color);
|
|
|
|
BarItems.slider_color_h.update();
|
|
|
|
BarItems.slider_color_s.update();
|
|
|
|
BarItems.slider_color_v.update();
|
|
|
|
|
2021-08-18 04:02:23 +08:00
|
|
|
UVEditor.vue.setMode('paint');
|
2020-03-11 05:19:17 +08:00
|
|
|
three_grid.visible = false;
|
|
|
|
},
|
|
|
|
onUnselect: () => {
|
2021-06-29 16:30:03 +08:00
|
|
|
Canvas.updateAllBones()
|
2021-09-22 03:13:24 +08:00
|
|
|
Outliner.elements.forEach(cube => {
|
|
|
|
if (cube.preview_controller.updatePaintingGrid) cube.preview_controller.updatePaintingGrid(cube);
|
2020-03-11 05:19:17 +08:00
|
|
|
})
|
2021-08-18 04:02:23 +08:00
|
|
|
UVEditor.vue.setMode('uv');
|
2020-03-11 05:19:17 +08:00
|
|
|
three_grid.visible = true;
|
|
|
|
},
|
|
|
|
})
|
2021-11-23 19:51:09 +08:00
|
|
|
new Mode('pose', {
|
|
|
|
default_tool: 'rotate_tool',
|
|
|
|
category: 'navigate',
|
|
|
|
condition: () => Format && Format.pose_mode,
|
|
|
|
})
|
2020-12-22 20:32:49 +08:00
|
|
|
new Mode('display', {
|
2021-07-28 23:49:09 +08:00
|
|
|
selectElements: false,
|
2020-03-11 05:19:17 +08:00
|
|
|
default_tool: 'move_tool',
|
|
|
|
category: 'navigate',
|
|
|
|
condition: () => Format.display_mode,
|
|
|
|
onSelect: () => {
|
|
|
|
enterDisplaySettings()
|
|
|
|
},
|
|
|
|
onUnselect: () => {
|
|
|
|
exitDisplaySettings()
|
|
|
|
},
|
|
|
|
})
|
2020-12-22 20:32:49 +08:00
|
|
|
new Mode('animate', {
|
2020-03-11 05:19:17 +08:00
|
|
|
default_tool: 'move_tool',
|
|
|
|
category: 'navigate',
|
2021-12-01 18:49:35 +08:00
|
|
|
hidden_node_types: ['cube', 'mesh', 'texture_mesh'],
|
2020-03-11 05:19:17 +08:00
|
|
|
condition: () => Format.animation_mode,
|
|
|
|
onSelect: () => {
|
|
|
|
Animator.join()
|
|
|
|
},
|
|
|
|
onUnselect: () => {
|
|
|
|
Animator.leave()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|