Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
JannisX11 committed May 12, 2024
2 parents 45903dc + ad7e3b1 commit 1363178
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 42 deletions.
48 changes: 42 additions & 6 deletions css/window.css
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
width: 68px;
flex-shrink: 0;
}
#settings_profiles_header_menu {
body:not(.is_mobile) #settings_profiles_header_menu {
width: 24px;
text-align: center;
padding-top: 2px;
Expand Down Expand Up @@ -586,19 +586,19 @@
li.menu_bar_point.highlighted {
animation: menu_item_highlight 1s infinite ease-in-out;
}
header .tool {
body.is_mobile header .tool {
height: 100%;
width: 42px;
}
header .tool > .icon {
body.is_mobile header .tool > .icon {
margin-top: 7px;
}
body:not(.is_mobile) header .tool > .icon {
margin-top: 2px;
}
header .tool.hidden {
display: none;
}
body.is_mobile.is_landscape #title_bar_undo_controls {
display: block;
}

#mode_selector {
height: 30px;
Expand All @@ -625,6 +625,42 @@
margin-top: 3px;
}

#mobile_menu_bar {
position: absolute;
margin: auto;
top: 50px;
left: 0;
right: 0;
width: fit-content;
max-width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
background-color: var(--color-bright_ui);
box-shadow: 0 0px 8px rgba(0, 0, 0, 0.64);
border-radius: 4px;
padding: 0 5px;
z-index: 30;
}
#mobile_menu_bar > .tool {
color: var(--color-bright_ui_text);
width: 42px;
height: 36px;
padding-top: 3px;
}
#mobile_menu_bar > .tool.selected {
background-color: var(--color-accent);
color: var(--color-accent_text);
}
#mobile_menu_bar > label {
height: 20px;
width: 0;
flex-basis: 100%;
text-align: center;
color: var(--color-bright_ui_text);
opacity: 0.8;
}

/* Tab Bar */
#tab_bar {
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ <h3><i class="material-icons icon">keyboard</i><span class="tl">keybindings.reco
<div id="title_bar_home_button" class="tool" onclick="Interface.tab_bar.openNewTab()"><i class="material-icons icon">home</i></div>
<div class="app-drag-region" id="header_free_bar"></div>
<div id="update_menu"></div>
<div id="settings_profiles_header_menu" class="hidden">
<div id="settings_profiles_header_menu" class="hidden tool">
<i class="material-icons icon">manage_accounts</i>
</div>
<ul id="windows_window_menu" hidden>
Expand Down
5 changes: 3 additions & 2 deletions js/interface/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2198,9 +2198,10 @@ const BARS = {
Toolbars.element_origin,
Toolbars.element_rotation
].forEach(toolbar => {
Toolbars.main_tools.children.forEach(child => {
for (let child of Toolbars.main_tools.children) {
if (toolbar.children.includes(child)) return;
toolbar.add(child);
})
}
})
}
Blockbench.onUpdateTo('4.4.0-beta.0', () => {
Expand Down
6 changes: 5 additions & 1 deletion js/interface/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ Interface.definePanels = function(callback) {

//Misc
function unselectInterface(event) {
if (open_menu && $('.contextMenu').find(event.target).length === 0 && $('.menu_bar_point.opened:hover').length === 0) {
if (
open_menu && $('.contextMenu').find(event.target).length === 0 &&
$('.menu_bar_point.opened:hover').length === 0 &&
!document.getElementById('mobile_menu_bar')?.contains(event.target)
) {
Menu.closed_in_this_click = open_menu.id;
open_menu.hide();

Expand Down
120 changes: 100 additions & 20 deletions js/interface/menu_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class BarMenu extends Menu {
this.node.className = 'contextMenu menu_bar_menu';
this.node.style.minHeight = '8px';
this.node.style.minWidth = '150px';
this.icon = options.icon;
this.name = tl(options.name || `menu.${id}`);
this.label = Interface.createElement('li', {class: 'menu_bar_point'}, this.name);
this.label.addEventListener('click', (event) => {
Expand Down Expand Up @@ -37,6 +38,7 @@ class BarMenu extends Menu {
MenuBar.open = undefined;
this.highlight_action = null;
this.label.classList.remove('highlighted');
if (MenuBar.last_opened == this) document.getElementById('mobile_menu_bar')?.remove();
return this;
}
highlight(action) {
Expand All @@ -48,6 +50,7 @@ class BarMenu extends Menu {
const MenuBar = {
menus: {},
open: undefined,
last_opened: null,
setup() {
MenuBar.menues = MenuBar.menus;
new BarMenu('file', [
Expand Down Expand Up @@ -228,7 +231,7 @@ const MenuBar = {
]},
'plugins_window',
'edit_session'
])
], {icon: 'draft'})
new BarMenu('edit', [
new MenuSeparator('undo'),
'undo',
Expand Down Expand Up @@ -270,7 +273,7 @@ const MenuBar = {
'select_all',
'unselect_all',
'invert_selection'
])
], {icon: 'edit'})
new BarMenu('transform', [
'scale',
{name: 'menu.transform.rotate', id: 'rotate', icon: 'rotate_90_degrees_ccw', children: [
Expand Down Expand Up @@ -302,11 +305,13 @@ const MenuBar = {
]}

], {
condition: {modes: ['edit']}
icon: 'open_with',
condition: {modes: ['edit']},
})

new BarMenu('uv', UVEditor.menu.structure, {
condition: {modes: ['edit']},
icon: 'photo_size_select_large',
onOpen() {
setActivePanel('uv');
}
Expand All @@ -330,6 +335,7 @@ const MenuBar = {
'resize_texture',
'crop_texture_to_selection'
], {
icon: 'image',
condition: {modes: ['paint']}
})

Expand All @@ -350,6 +356,7 @@ const MenuBar = {
'save_all_animations',
'export_animation_file'
], {
icon: 'movie',
condition: {modes: ['animate']}
})

Expand All @@ -373,6 +380,7 @@ const MenuBar = {
'resolve_keyframe_expressions',
'delete',
], {
icon: 'icon-keyframe',
condition: {modes: ['animate']}
})

Expand All @@ -382,7 +390,7 @@ const MenuBar = {
onOpen() {
setActivePanel('timeline');
}
})
}, {icon: 'timeline'})

new BarMenu('display', [
new MenuSeparator('copypaste'),
Expand All @@ -392,6 +400,7 @@ const MenuBar = {
'add_display_preset',
'apply_display_preset'
], {
icon: 'tune',
condition: {modes: ['display']}
})

Expand Down Expand Up @@ -427,7 +436,7 @@ const MenuBar = {
'convert_to_mesh',
'auto_set_cullfaces',
'remove_blank_faces',
])
], {icon: 'handyman'})
MenuBar.menus.filter = MenuBar.menus.tools;

new BarMenu('view', [
Expand Down Expand Up @@ -458,7 +467,7 @@ const MenuBar = {
'advanced_screenshot',
'record_model_gif',
'timelapse',
])
], {icon: 'visibility'})
new BarMenu('help', [
new MenuSeparator('search'),
{name: 'menu.help.search_action', description: BarItems.action_control.description, keybind: BarItems.action_control.keybind, id: 'search_action', icon: 'search', click: ActionControl.select},
Expand Down Expand Up @@ -515,7 +524,7 @@ const MenuBar = {
'reload',
]},
'about_window'
])
], {icon: 'help'})
MenuBar.update();

if (Blockbench.isMobile) {
Expand Down Expand Up @@ -547,29 +556,100 @@ const MenuBar = {
MenuBar.mode_switcher_button = mode_switcher;

let home_button = document.getElementById('title_bar_home_button');
let profile_button = document.getElementById('settings_profiles_header_menu');

let buttons = [menu_button, search_button, home_button, undo_button, redo_button, mode_switcher];
let buttons = [menu_button, search_button, profile_button, home_button, undo_button, redo_button,, mode_switcher];
buttons.forEach(button => {
header.append(button);
})

header.addEventListener('touchstart', e1 => {
convertTouchEvent(e1);
let opened, bar, initial;
let onMove = e2 => {
convertTouchEvent(e2);
let y_diff = e2.clientY - e1.clientY;
if (y_diff > 16) {
if (!opened) {
bar = MenuBar.openMobile(menu_button);
opened = true;
initial = y_diff;
}
}
if (bar) {
bar.style.marginTop = Math.clamp(y_diff - 50, -60, 0)+'px';
for (let node of bar.childNodes) {
if (!node.bbOpenMenu) continue;
let offset_center = bar.offsetLeft + node.offsetLeft + node.clientWidth/2;
if (Math.abs(offset_center - e2.clientX) < 21) {
node.bbOpenMenu(e2);
break;
}
}
}
}
let onStop = e2 => {
document.removeEventListener('touchmove', onMove);
document.removeEventListener('touchend', onStop);
if (bar) {
bar.style.marginTop = '0';
convertTouchEvent(e2);
let y_diff = e2.clientY - e1.clientY;
if (y_diff < initial && MenuBar.open) {
MenuBar.open.hide()
}
}
}
document.addEventListener('touchmove', onMove);
document.addEventListener('touchend', onStop);
})
}
},
openMobile(button, event) {
let entries = [];
if (document.getElementById('mobile_menu_bar')) {
document.getElementById('mobile_menu_bar').remove();
return;
}
let label = Interface.createElement('label', {});
let bar = Interface.createElement('div', {id: 'mobile_menu_bar'}, label);
let menu_button_nodes = [];
let menu_position;
let setSelected = (node, menu) => {
menu_button_nodes.forEach(n => n.classList.remove('selected'))
node.classList.add('selected');
label.innerText = menu.name;
}
for (let id in MenuBar.menus) {
if (id == 'filter') continue;
let menu = MenuBar.menus[id];
let entry = {
id,
icon: menu.icon || '',
name: menu.name,
children: menu.structure,
condition: menu.condition,
};
entries.push(entry);
if (id == 'filter') continue;
if (!Condition(menu.condition)) continue;

let node = Interface.createElement('div', {class: 'tool'}, Blockbench.getIconNode(menu.icon));
let openMenu = event => {
if (MenuBar.last_opened == menu) return;
MenuBar.last_opened = MenuBar.open = menu;
menu.open(menu_position);
setSelected(node, menu);
}
addEventListeners(node, 'pointerdown touchmove', openMenu);
node.bbOpenMenu = openMenu;

menu_button_nodes.push(node);
bar.append(node);
if (MenuBar.last_opened == menu || (!MenuBar.last_opened && id == 'file')) {
setTimeout(() => {
MenuBar.last_opened = menu;
menu.open(menu_position);
setSelected(node, menu);
}, 1)
}
}
document.body.append(bar);
menu_position = {
clientX: bar.offsetLeft + 7,
clientY: bar.offsetTop + bar.clientHeight - 1
}
let menu = new Menu(entries).open(button);
return menu;
return bar;
},
update() {
if (!Blockbench.isMobile) {
Expand Down
11 changes: 9 additions & 2 deletions js/interface/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ const CustomTheme = {
CustomTheme.updateColors();
},
loadThumbnailStyles() {
let split_regex;
try {
// Soft fail for iOS 16.3 and older
split_regex = eval('/(?<!\\[[^\\]]*),(?![^\\[]*\\])|(?<!"[^"]*),(?![^"]*")/g')
} catch (err) {
return;
}
let thumbnailStyles = '\n';
const style = document.createElement('style');
document.head.appendChild(style);
Expand All @@ -443,15 +450,15 @@ const CustomTheme = {
const sheet = style.sheet;
for (const rule of sheet.cssRules) {
if (!rule.selectorText) continue;
thumbnailStyles += `${rule.selectorText.split(/(?<!\[[^\]]*),(?![^\[]*\])|(?<!"[^"]*),(?![^"]*")/g).map(e => `[theme_id="${theme.id}"] ${e.trim()}`).join(", ")} { ${rule.style.cssText} }\n`;
thumbnailStyles += `${rule.selectorText.split(split_regex).map(e => `[theme_id="${theme.id}"] ${e.trim()}`).join(", ")} { ${rule.style.cssText} }\n`;
}
}
if (CustomTheme.data.customized) {
style.textContent = CustomTheme.data.thumbnail;
const sheet = style.sheet;
for (const rule of sheet.cssRules) {
if (!rule.selectorText) continue;
thumbnailStyles += `${rule.selectorText.split(/(?<!\[[^\]]*),(?![^\[]*\])|(?<!"[^"]*),(?![^"]*")/g).map(e => `[theme_id="${CustomTheme.data.id}"] ${e.trim()}`).join(", ")} { ${rule.style.cssText} }\n`;
thumbnailStyles += `${rule.selectorText.split(split_regex).map(e => `[theme_id="${CustomTheme.data.id}"] ${e.trim()}`).join(", ")} { ${rule.style.cssText} }\n`;
}
}
document.head.removeChild(style);
Expand Down
Loading

0 comments on commit 1363178

Please sign in to comment.