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) {
|
2022-05-20 06:24:43 +08:00
|
|
|
Modes.selected.unselect();
|
2020-03-11 05:19:17 +08:00
|
|
|
}
|
|
|
|
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()
|
|
|
|
}
|
2022-12-17 23:04:53 +08:00
|
|
|
updatePanelSelector();
|
2023-04-08 05:24:03 +08:00
|
|
|
ReferenceImage.updateAll();
|
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';
|
|
|
|
}
|
2023-11-25 20:55:27 +08:00
|
|
|
|
|
|
|
UVEditor.beforeMoving();
|
2023-11-23 07:22:33 +08:00
|
|
|
for (let id in Panels) {
|
2023-11-26 01:39:02 +08:00
|
|
|
let old_pos_data = Panels[id].position_data;
|
2023-11-23 07:22:33 +08:00
|
|
|
Panels[id].position_data = Interface.getModeData().panels[id];
|
2023-11-26 01:39:02 +08:00
|
|
|
if (!Panels[id].position_data) {
|
|
|
|
Panels[id].position_data = Interface.getModeData().panels[id] = JSON.parse(JSON.stringify(old_pos_data))
|
|
|
|
}
|
2023-11-23 07:22:33 +08:00
|
|
|
Panels[id].updateSlot();
|
|
|
|
}
|
|
|
|
updateSidebarOrder();
|
|
|
|
|
2020-03-11 05:19:17 +08:00
|
|
|
Canvas.updateRenderSides()
|
2022-11-04 02:11:26 +08:00
|
|
|
if (this.tool && BarItems[this.tool] && Condition(BarItems[this.tool])) {
|
2022-10-29 23:25:33 +08:00
|
|
|
BarItems[this.tool].select();
|
|
|
|
} else if (BarItems[this.default_tool]) {
|
|
|
|
if (!BarItems[this.default_tool].selected) BarItems[this.default_tool].select();
|
2020-03-11 05:19:17 +08:00
|
|
|
} else {
|
2022-10-29 23:25:33 +08:00
|
|
|
if (!BarItems.move_tool.selected) BarItems.move_tool.select();
|
2020-03-11 05:19:17 +08:00
|
|
|
}
|
2022-10-08 06:27:49 +08:00
|
|
|
TickUpdates.interface = true;
|
2020-03-11 05:19:17 +08:00
|
|
|
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
|
|
|
}
|
2022-05-20 06:24:43 +08:00
|
|
|
unselect() {
|
|
|
|
delete Modes[this.id];
|
|
|
|
Modes.previous_id = this.id;
|
|
|
|
if (typeof this.onUnselect === 'function') {
|
|
|
|
Blockbench.dispatchEvent('unselect_mode', {mode: this})
|
|
|
|
this.onUnselect()
|
|
|
|
}
|
|
|
|
this.selected = false;
|
|
|
|
Mode.selected = Modes.selected = 0;
|
|
|
|
}
|
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() {
|
2022-05-20 06:24:43 +08:00
|
|
|
return Mode.selected ? Mode.selected.id : ''
|
2020-11-28 06:23:16 +08:00
|
|
|
},
|
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: {
|
2022-08-06 19:37:20 +08:00
|
|
|
showModes() {
|
|
|
|
let count = 0;
|
|
|
|
for (let key in this.options) {
|
|
|
|
if (Condition(this.options[key].condition)) count++;
|
|
|
|
}
|
|
|
|
return count > 1;
|
|
|
|
},
|
2021-09-21 17:20:10 +08:00
|
|
|
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',
|
2022-08-06 19:37:20 +08:00
|
|
|
condition: () => Format && Format.edit_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',
|
2022-08-06 19:37:20 +08:00
|
|
|
condition: () => Format && Format.paint_mode,
|
2020-03-11 05:19:17 +08:00
|
|
|
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);
|
2022-12-21 22:13:41 +08:00
|
|
|
if (StateMemory.color_picker_rgb) {
|
|
|
|
BarItems.slider_color_red.update();
|
|
|
|
BarItems.slider_color_green.update();
|
|
|
|
BarItems.slider_color_blue.update();
|
|
|
|
} else {
|
|
|
|
BarItems.slider_color_h.update();
|
|
|
|
BarItems.slider_color_s.update();
|
|
|
|
BarItems.slider_color_v.update();
|
|
|
|
}
|
2020-03-11 05:19:17 +08:00
|
|
|
|
2022-03-11 04:24:33 +08:00
|
|
|
Panels.uv.handle.firstChild.textContent = tl('mode.paint');
|
2022-08-06 19:37:20 +08:00
|
|
|
|
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
|
|
|
})
|
2022-03-11 04:24:33 +08:00
|
|
|
Panels.uv.handle.firstChild.textContent = tl('panel.uv');
|
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()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|