const StartScreen = {
loaders: {},
open() {
Interface.tab_bar.openNewTab();
}
};
function addStartScreenSection(id, data) {
if (typeof id == 'object') {
data = id;
id = '';
}
var obj = $(Interface.createElement('section', {id}))
if (typeof data.graphic === 'object') {
var left = $('
')
obj.append(left)
if (data.graphic.type === 'icon') {
var icon = Blockbench.getIconNode(data.graphic.icon)
left.addClass('graphic_icon')
left.append(icon)
} else {
left.css('background-image', `url('${data.graphic.source}')`)
}
if (data.graphic.width) {
left.css('width', data.graphic.width+'px');
}
if (data.graphic.width && data.text) {
left.css('flex-shrink', '0');
}
if (data.graphic.width && data.graphic.height && Blockbench.isMobile) {
left.css('height', '0')
.css('padding-top', '0')
.css('padding-bottom', (data.graphic.height/data.graphic.width*100)+'%')
} else {
if (data.graphic.height) left.css('height', data.graphic.height+'px');
if (data.graphic.width && !data.graphic.height && !data.graphic.aspect_ratio) left.css('height', data.graphic.width+'px');
if (data.graphic.aspect_ratio) left.css('aspect-ratio', data.graphic.aspect_ratio);
}
if (data.graphic.description) {
let content = $(pureMarked(data.graphic.description));
content.addClass('start_screen_graphic_description')
content.css({
'color': data.graphic.text_color || '#ffffff',
});
left.append(content);
}
}
if (data.text instanceof Array) {
var right = $('')
obj.append(right)
data.text.forEach(line => {
var content = line.text ? pureMarked(tl(line.text)) : '';
switch (line.type) {
case 'h1': var tag = 'h1'; break;
case 'h2': var tag = 'h3'; break;
case 'h3': var tag = 'h4'; break;
case 'list':
var tag = 'ul class="list_style"';
line.list.forEach(string => {
content += `
${pureMarked(tl(string))}
`;
})
break;
case 'button': var tag = 'button'; break;
default: var tag = 'p'; break;
}
var l = $(`<${tag}>${content}${tag.split(' ')[0]}>`);
if (typeof line.click == 'function') {
l.on('click', line.click);
}
right.append(l);
})
}
if (data.layout == 'vertical') {
obj.addClass('vertical');
}
if (data.features instanceof Array) {
let features_section = document.createElement('ul');
features_section.className = 'start_screen_features'
data.features.forEach(feature => {
let li = document.createElement('li');
let img = new Image(); img.src = feature.image;
let title = document.createElement('h3'); title.textContent = feature.title;
let text = document.createElement('p'); text.textContent = feature.text;
li.append(img, title, text);
features_section.append(li);
})
obj.append(features_section);
}
if (data.closable !== false) {
obj.append(`clear`);
obj.find('i.start_screen_close_button').click((e) => {
obj.detach()
});
}
if (typeof data.click == 'function') {
obj.on('click', event => {
if (event.target.classList.contains('start_screen_close_button')) return;
data.click()
})
}
if (data.color) {
obj.css('background-color', data.color);
if (data.color == 'var(--color-bright_ui)') {
obj.addClass('bright_ui')
}
}
if (data.text_color) {
obj.css('color', data.text_color);
}
if (data.last) {
$('#start_screen > content').append(obj);
} else if (data.insert_after) {
$('#start_screen > content').find(`#${data.insert_after}`).after(obj);
} else if (data.insert_before) {
$('#start_screen > content').find(`#${data.insert_before}`).before(obj);
} else {
$('#start_screen > content').prepend(obj);
}
if (!obj[0].parentElement) {
$('#start_screen > content').append(obj);
}
return {
delete() {
obj[0].remove();
}
}
}
onVueSetup(function() {
StateMemory.init('start_screen_list_type', 'string')
let slideshow_timer = 0;
StartScreen.vue = new Vue({
el: '#start_screen',
components: {},
data: {
formats: Formats,
loaders: ModelLoader.loaders,
selected_format_id: '',
viewed_format: null,
recent: isApp ? recent_projects : [],
list_type: StateMemory.start_screen_list_type || 'grid',
redact_names: settings.streamer_mode.value,
redacted: tl('generic.redacted'),
search_term: '',
isApp,
mobile_layout: Blockbench.isMobile,
thumbnails: {},
getIconNode: Blockbench.getIconNode,
slideshow: [
{
source: "./assets/splash_art/1.png",
description: "Splash Art 1st Place by [KanekiAkira](https://twitter.com/kaneki_akira) & [Jumi](https://jumi-pf.com)",
},
{
source: "./assets/splash_art/2.png",
description: "Splash Art 2nd Place by [PICASSO](https://twitter.com/Picasso114514) & [AnzSama](https://twitter.com/AnzSamaEr)",
},
{
source: "./assets/splash_art/3.png",
description: "Splash Art 3rd Place by [Wanwin](https://wan-win.com/#3darts)",
},
{
source: "./assets/splash_art/4.png",
description: "Splash Art 4th Place by [soul shadow](https://twitter.com/Ghost773748999)",
},
{
source: "./assets/splash_art/5.png",
description: "Splash Art 5th Place by [Azagwen](https://twitter.com/azagwen) & [shroomy](https://twitter.com/ShroomyArts)",
}
],
show_splash_screen: (Blockbench.hasFlag('after_update') || settings.always_show_splash_art.value),
slideshow_selected: 0,
slideshow_last: null,
slideshow_autoplay: true
},
methods: {
getDate(p) {
if (p.day) {
var diff = (365e10 + Blockbench.openTime.dayOfYear() - p.day) % 365;
if (diff <= 0) {
return tl('dates.today');
} else if (diff == 1) {
return tl('dates.yesterday');
} else if (diff <= 7) {
return tl('dates.this_week');
} else {
return tl('dates.weeks_ago', [Math.ceil(diff/7)]);
}
} else {
return '-'
}
},
openProject: function(p, event) {
Blockbench.read([p.path], {}, files => {
loadModelFile(files[0]);
})
},
updateThumbnails(model_paths) {
this.recent.forEach(project => {
if (model_paths && !model_paths.includes(project.path)) return;
let hash = project.path.hashCode().toString().replace(/^-/, '0');
let path = PathModule.join(app.getPath('userData'), 'thumbnails', `${hash}.png`);
if (!fs.existsSync(path)) {
delete this.thumbnails[project.path];
} else {
this.thumbnails[project.path] = path + '?' + Math.round(Math.random()*255);
}
})
this.$forceUpdate();
},
setListType(type) {
this.list_type = type;
StateMemory.start_screen_list_type = type;
StateMemory.save('start_screen_list_type')
},
recentProjectContextMenu(recent_project, event) {
let menu = new Menu('recent_project', [
{
id: 'favorite',
name: 'mode.start.recent.favorite',
icon: recent_project.favorite ? 'fas.fa-star' : 'far.fa-star',
click: () => {
this.toggleProjectFavorite(recent_project);
}
},
{
id: 'open_folder',
name: 'menu.texture.folder',
icon: 'folder',
click() {
shell.showItemInFolder(recent_project.path)
}
},
{
id: 'remove',
name: 'generic.remove',
icon: 'clear',
click: () => {
recent_projects.remove(recent_project);
updateRecentProjects();
}
}
])
menu.show(event);
},
toggleProjectFavorite(recent_project) {
recent_project.favorite = !recent_project.favorite;
if (recent_project.favorite) {
recent_projects.remove(recent_project);
recent_projects.splice(0, 0, recent_project);
}
updateRecentProjects();
},
getFormatCategories() {
let categories = {};
function add(key, format) {
if (!categories[format.category]) {
categories[format.category] = {
name: tl('format_category.' + format.category),
entries: []
}
}
categories[format.category].entries.push(format);
}
for (let key in this.formats) {
if (this.formats[key].show_on_start_screen != false) {
add(key, this.formats[key]);
}
}
for (let key in this.loaders) {
if (this.loaders[key].show_on_start_screen != false) {
add(key, this.loaders[key]);
}
}
return categories;
},
loadFormat(format_entry) {
this.selected_format_id = format_entry.id;
if (format_entry.onFormatPage) format_entry.onFormatPage();
Vue.nextTick(() => {
let button = document.querySelector('.start_screen_format_page button');
if (!button) return;
let offset = $(button).offset().top;
if (offset + 38 > window.innerHeight) {
let change = offset + 64 - window.innerHeight;
StartScreen.vue.$el.scrollTo({top: StartScreen.vue.$el.scrollTop + change, behavior: 'smooth'})
}
})
},
confirmSetupScreen(format_entry) {
this.selected_format_id = '';
if (format_entry.onStart) format_entry.onStart();
if (typeof format_entry.new == 'function') format_entry.new();
},
getBackground(url) {
return `url("${url}")`
},
setSlide(index) {
this.slideshow_last = this.slideshow_selected;
this.slideshow_selected = index;
setTimeout(() => this.slideshow_last = null, 500);
slideshow_timer = 0;
},
openLink(link) {
Blockbench.openLink(link);
},
pureMarked,
tl
},
computed: {
projects() {
if (!this.search_term) return this.recent;
let terms = this.search_term.toLowerCase().split(/\s/);
return this.recent.filter(project => {
return !terms.find(term => (
!project.path.toLowerCase().includes(term)
))
})
}
},
mounted() {
this.updateThumbnails();
setInterval(() => {
if (this.show_splash_screen && this.slideshow_autoplay && this.$el.offsetParent) {
slideshow_timer += 1;
if (slideshow_timer == 24) {
this.setSlide((this.slideshow_selected+1) % this.slideshow.length);
}
}
}, 1000);
if (settings.always_show_splash_art.value && !Blockbench.hasFlag('after_update') && !Blockbench.isMobile) {
document.getElementById('start_screen').scrollTop = 100;
}
},
template: `