diff --git a/js/interface/menu.js b/js/interface/menu.js index 9e08589f..5cb2eccf 100644 --- a/js/interface/menu.js +++ b/js/interface/menu.js @@ -476,7 +476,7 @@ class Menu { } entry = Interface.createElement('li', {title: s.description && tl(s.description), menu_item: s.id}, Interface.createElement('span', {}, tl(s.name))); entry.prepend(icon); - if (s.marked) { + if (s.marked && Condition(s.marked, scope_context)) { entry.classList.add('marked'); } if (s.keybind) { diff --git a/js/interface/menu_bar.js b/js/interface/menu_bar.js index a277343b..870bfe53 100644 --- a/js/interface/menu_bar.js +++ b/js/interface/menu_bar.js @@ -463,13 +463,39 @@ const MenuBar = { new MenuSeparator('interface'), { id: 'panels', - name: 'Panels', + name: 'menu.view.panels', + icon: 'web_asset', children() { let entries = []; for (let id in Panels) { let panel = Panels[id]; - + if (!Condition(panel.condition)) continue; + let menu_entry = { + id, + name: panel.name, + icon: panel.icon, + children: [ + { + id: 'move_to', + name: panel.slot == 'hidden' ? 'menu.panel.enable' : 'menu.panel.move_to', + icon: 'drag_handle', + context: panel, + children: panel.snap_menu.structure + }, + { + id: 'fold', + name: 'menu.panel.fold', + icon: panel.folded == true, + condition: panel.slot != 'hidden', + click() { + panel.fold(); + } + } + ] + } + entries.push(menu_entry); } + return entries; } }, 'toggle_sidebars', diff --git a/js/interface/panels.js b/js/interface/panels.js index fe054fad..3b92723b 100644 --- a/js/interface/panels.js +++ b/js/interface/panels.js @@ -11,6 +11,7 @@ class Panel extends EventSystem { this.condition = data.condition; this.display_condition = data.display_condition; this.previous_slot = 'left_bar'; + this.optional = data.optional ?? false; this.plugin = data.plugin || (typeof Plugins != 'undefined' ? Plugins.currently_loading : ''); this.growable = data.growable; @@ -103,38 +104,8 @@ class Panel extends EventSystem { let snap_button = Interface.createElement('div', {class: 'tool panel_control'}, Blockbench.getIconNode('drag_handle')) this.handle.append(snap_button); - let moveTo = slot => { - this.fixed_height = false; - this.moveTo(slot); - }; snap_button.addEventListener('click', (e) => { - new Menu([ - { - name: 'Left Sidebar', - icon: 'align_horizontal_left', - click: () => moveTo('left_bar') - }, - { - name: 'Right Sidebar', - icon: 'align_horizontal_right', - click: () => moveTo('right_bar') - }, - { - name: 'Top', - icon: 'align_vertical_top', - click: () => moveTo('top') - }, - { - name: 'Bottom', - icon: 'align_vertical_bottom', - click: () => moveTo('bottom') - }, - { - name: 'Float', - icon: 'web_asset', - click: () => moveTo('float') - } - ]).show(snap_button); + this.snap_menu.show(snap_button, this); }) let fold_button = Interface.createElement('div', {class: 'tool panel_control panel_folding_button'}, Blockbench.getIconNode('expand_more')) @@ -597,6 +568,8 @@ class Panel extends EventSystem { if (!this.resize_handles) { this.setupFloatHandles(); } + } else if (slot == 'hidden' && !Blockbench.isMobile) { + this.node.remove(); } if (slot !== 'float') { Panel.floating_panel_z_order.remove(this.id); @@ -635,6 +608,8 @@ class Panel extends EventSystem { if (!this.resize_handles) { this.setupFloatHandles(); } + } else if (slot == 'hidden' && !Blockbench.isMobile) { + this.node.remove(); } if (slot !== 'float') { Panel.floating_panel_z_order.remove(this.id); @@ -747,6 +722,64 @@ class Panel extends EventSystem { } } Panel.floating_panel_z_order = []; +Panel.prototype.snap_menu = new Menu([ + { + name: 'menu.panel.move_to.left_bar', + icon: 'align_horizontal_left', + marked: panel => panel.slot == 'left_bar', + click: (panel) => { + panel.fixed_height = false; + panel.moveTo('left_bar'); + } + }, + { + name: 'menu.panel.move_to.right_bar', + icon: 'align_horizontal_right', + marked: panel => panel.slot == 'right_bar', + click: (panel) => { + panel.fixed_height = false; + panel.moveTo('right_bar'); + } + }, + { + name: 'menu.panel.move_to.top', + icon: 'align_vertical_top', + marked: panel => panel.slot == 'top', + click: (panel) => { + panel.fixed_height = false; + panel.moveTo('top'); + } + }, + { + name: 'menu.panel.move_to.bottom', + icon: 'align_vertical_bottom', + marked: panel => panel.slot == 'bottom', + click: (panel) => { + panel.fixed_height = false; + panel.moveTo('bottom'); + } + }, + { + name: 'menu.panel.move_to.float', + icon: 'web_asset', + marked: panel => panel.slot == 'float', + click: (panel) => { + panel.fixed_height = false; + panel.moveTo('float'); + } + }, + '_', + { + name: 'menu.panel.move_to.hidden', + icon: 'web_asset_off', + marked: panel => panel.slot == 'hidden', + condition: panel => (panel.optional && panel.slot != 'hidden'), + click: (panel) => { + panel.fixed_height = false; + panel.moveTo('hidden'); + } + } +]) function setupPanels() { diff --git a/js/outliner/collections.js b/js/outliner/collections.js index b99af85a..c80b9c26 100644 --- a/js/outliner/collections.js +++ b/js/outliner/collections.js @@ -315,12 +315,14 @@ Interface.definePanels(function() { icon: 'inventory_2', growable: true, resizable: true, + optional: true, default_position: { - slot: 'left_bar', + slot: 'hidden', float_position: [0, 0], float_size: [300, 300], height: 300 }, + condition: {modes: ['edit', 'paint']}, toolbars: [ new Toolbar('collections', { children: [ diff --git a/lang/en.json b/lang/en.json index 586a7476..b56a8f21 100644 --- a/lang/en.json +++ b/lang/en.json @@ -2022,6 +2022,7 @@ "menu.display.preset_all": "Apply Preset Everywhere", "menu.display.remove_preset": "Remove Preset", "menu.view.zoom": "Zoom", + "menu.view.panels": "Panels", "menu.view.background": "Background", "menu.view.screenshot": "Screenshot", @@ -2132,6 +2133,16 @@ "menu.uv.flip_y": "Mirror Y", "menu.uv.texture": "Texture", + "menu.panel.enable": "Enable", + "menu.panel.move_to": "Move To", + "menu.panel.move_to.left_bar": "Left Sidebar", + "menu.panel.move_to.right_bar": "Right Sidebar", + "menu.panel.move_to.top": "Top", + "menu.panel.move_to.bottom": "Bottom", + "menu.panel.move_to.float": "Float", + "menu.panel.move_to.hidden": "Hide", + "menu.panel.fold": "Collapse", + "menu.mirror_painting.enabled": "Enabled", "menu.mirror_painting.axis": "Axis", "menu.mirror_painting.axis.desc": "Select on which axis paint strokes will get mirrored",