2021-11-14 06:19:23 +08:00
const StartScreen = { } ;
function addStartScreenSection ( id , data ) {
if ( typeof id == 'object' ) {
data = id ;
id = '' ;
}
var obj = $ ( ` <section id=" ${ id } "></section> ` )
if ( typeof data . graphic === 'object' ) {
var left = $ ( '<div class="start_screen_left graphic"></div>' )
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 = $ ( marked ( data . graphic . description ) ) ;
content . css ( {
'bottom' : '15px' ,
'right' : '15px' ,
'color' : data . graphic . description _color || '#ffffff' ,
} ) ;
left . append ( content ) ;
}
}
if ( data . text instanceof Array ) {
var right = $ ( '<div class="start_screen_right"></div>' )
obj . append ( right )
data . text . forEach ( line => {
var content = line . text ? marked ( tl ( line . text ) ) : '' ;
switch ( line . type ) {
case 'h1' : var tag = 'h2' ; break ;
case 'h2' : var tag = 'h3' ; break ;
case 'list' :
var tag = 'ul class="list_style"' ;
line . list . forEach ( string => {
content += ` <li> ${ marked ( tl ( string ) ) } </li> ` ;
} )
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 ( ` <i class="material-icons start_screen_close_button">clear</i> ` ) ;
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 {
$ ( '#start_screen content' ) . prepend ( obj ) ;
}
}
onVueSetup ( function ( ) {
StateMemory . init ( 'start_screen_list_type' , 'string' )
StartScreen . vue = new Vue ( {
el : '#start_screen' ,
data : {
formats : Formats ,
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 ,
getIconNode : Blockbench . getIconNode
} ,
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 ] ) ;
} )
} ,
getThumbnail ( model _path ) {
let hash = model _path . hashCode ( ) . toString ( ) . replace ( /^-/ , '0' ) ;
let path = PathModule . join ( app . getPath ( 'userData' ) , 'thumbnails' , ` ${ hash } .png ` ) ;
if ( ! fs . existsSync ( path ) ) return ;
return path + '?' + Math . round ( Math . random ( ) * 255 ) ;
} ,
setListType ( type ) {
this . list _type = type ;
StateMemory . start _screen _list _type = type ;
StateMemory . save ( 'start_screen_list_type' )
} ,
tl
} ,
computed : {
projects ( ) {
if ( ! this . search _term ) return this . recent ;
let terms = this . search _term . toLowerCase ( ) . split ( /\s/ ) ;
2021-11-15 06:47:56 +08:00
2021-11-14 06:19:23 +08:00
return this . recent . filter ( project => {
return ! terms . find ( term => (
! project . path . toLowerCase ( ) . includes ( term )
) )
} )
}
} ,
template : `
< div id = "start_screen" >
< content >
< section id = "start-files" >
< div class = "start_screen_left" >
< h2 > $ { tl ( 'mode.start.new' ) } < / h 2 >
< div class = "bar next_to_title" >
< div class = "tool" onclick = "Blockbench.openLink('https://blockbench.net/quickstart/')" >
< div class = "tooltip" > $ { tl ( 'menu.help.quickstart' ) } < / d i v >
< i class = "fas fa-question-circle" > < / i >
< / d i v >
< / d i v >
< ul >
2021-12-11 00:14:05 +08:00
< li v - for = "format in formats" v - if = "format.show_on_start_screen && (!redact_names || !format.confidential)" v - on : click = "format.new()" >
2021-11-14 06:19:23 +08:00
< span class = "icon_wrapper f_left" v - html = "getIconNode(format.icon).outerHTML" > < / s p a n >
< h3 > { { format . name } } < / h 3 >
< p > { { format . description } } < / p >
< / l i >
< / u l >
< / d i v >
< div class = "start_screen_right" >
< h2 class = "tl" > $ { tl ( 'mode.start.recent' ) } < / h 2 >
< div id = "start_screen_view_menu" v - if = "isApp && !redact_names" >
< search - bar : hide = "true" v - model = "search_term" > < / s e a r c h - b a r >
< li class = "tool" v - bind : class = "{selected: list_type == 'grid'}" v - on : click = "setListType('grid')" >
< i class = "material-icons" > view _module < / i >
< / l i >
< li class = "tool" v - bind : class = "{selected: list_type == 'list'}" v - on : click = "setListType('list')" >
< i class = "material-icons" > list < / i >
< / l i >
< / d i v >
< div v - if = "redact_names" > { { '[' + tl ( 'generic.redacted' ) + ']' } } < / d i v >
< ul v - else - if = "list_type == 'list'" >
< li v - on : click = "openProject(project, $event)" v - for = "project in projects" : key = "project.path" v - bind : title = "redact_names ? '' : project.path" class = "recent_project" >
< span class = "icon_wrapper" v - html = "getIconNode(project.icon).outerHTML" > < / s p a n >
< span class = "recent_project_name" > { { redact _names ? redacted : project . name } } < / s p a n >
< span class = "recent_project_date" > { { getDate ( project ) } } < / s p a n >
< / l i >
< div v - if = "recent.length == 0" > { { tl ( 'mode.start.no_recents' ) } } < / d i v >
< / u l >
< ul : class = "{redact: redact_names}" style = "display: grid;" v - else >
2021-11-15 06:47:56 +08:00
< li v - on : click = "openProject(project, $event)" v - for = "project in projects" : key = "project.path" v - bind : title = "redact_names ? '' : project.path" class = "recent_project thumbnail" >
< img class = "thumbnail_image" v - if = "getThumbnail(project.path)" : src = "getThumbnail(project.path)" / >
< span class = "recent_project_name" > { { redact _names ? redacted : project . name } } < / s p a n >
< span class = "icon_wrapper" v - html = "getIconNode(project.icon).outerHTML" > < / s p a n >
< / l i >
2021-11-14 06:19:23 +08:00
< / u l >
< button style = "margin-top: 20px;" onclick = "BarItems.open_model.trigger()" > $ { tl ( 'action.open_model' ) } < / b u t t o n >
< / d i v >
< / s e c t i o n >
< / c o n t e n t >
< / d i v >
`
} )
} ) ;
( function ( ) {
/ * $ . g e t J S O N ( ' . / c o n t e n t / n e w s . j s o n ' ) . t h e n ( d a t a = > {
addStartScreenSection ( 'new_version' , data . new _version )
} ) * /
var news _call = $ . getJSON ( 'https://web.blockbench.net/content/news.json' )
Promise . all ( [ news _call , documentReady ] ) . then ( ( data ) => {
if ( ! data || ! data [ 0 ] ) return ;
data = data [ 0 ] ;
//Update Screen
if ( Blockbench . hasFlag ( 'after_update' ) && data . new _version ) {
addStartScreenSection ( data . new _version )
jQuery . ajax ( {
url : 'https://blckbn.ch/api/event/successful_update' ,
type : 'POST' ,
data : {
version : Blockbench . version
}
} )
}
if ( data . psa ) {
( function ( ) {
if ( typeof data . psa . version == 'string' ) {
if ( data . psa . version . includes ( '-' ) ) {
limits = data . psa . version . split ( '-' ) ;
if ( limits [ 0 ] && compareVersions ( limits [ 0 ] , Blockbench . version ) ) return ;
if ( limits [ 1 ] && compareVersions ( Blockbench . version , limits [ 1 ] ) ) return ;
} else {
if ( data . psa . version != Blockbench . version ) return ;
}
}
addStartScreenSection ( data . psa )
} ) ( )
}
} )
documentReady . then ( ( ) => {
Blockbench . startup _count = parseInt ( localStorage . getItem ( 'startups' ) || 0 )
//Backup Model
if ( localStorage . getItem ( 'backup_model' ) && ( ! isApp || ! currentwindow . webContents . second _instance ) ) {
var backup _model = localStorage . getItem ( 'backup_model' )
localStorage . removeItem ( 'backup_model' )
addStartScreenSection ( {
color : 'var(--color-back)' ,
graphic : { type : 'icon' , icon : 'fa-archive' } ,
text : [
{ type : 'h2' , text : tl ( 'message.recover_backup.title' ) } ,
{ text : tl ( 'message.recover_backup.message' ) } ,
{ type : 'button' , text : tl ( 'dialog.ok' ) , click : ( e ) => {
loadModelFile ( { content : backup _model , path : 'backup.bbmodel' , no _file : true } )
} }
]
} )
}
if ( settings . streamer _mode . value ) {
updateStreamerModeNotification ( )
}
//Twitter
let twitter _ad ;
if ( Blockbench . startup _count < 20 && Blockbench . startup _count % 5 === 4 ) {
twitter _ad = true ;
addStartScreenSection ( {
color : '#1da1f2' ,
text _color : '#ffffff' ,
graphic : { type : 'icon' , icon : 'fab.fa-twitter' } ,
text : [
{ type : 'h2' , text : 'Blockbench on Twitter' } ,
{ text : 'Follow Blockbench on Twitter for the latest news as well as cool models from the community! [twitter.com/blockbench](https://twitter.com/blockbench/)' }
] ,
last : true
} )
}
//Discord
if ( Blockbench . startup _count < 6 && ! twitter _ad ) {
addStartScreenSection ( {
color : '#5865F2' ,
text _color : '#ffffff' ,
graphic : { type : 'icon' , icon : 'fab.fa-discord' } ,
text : [
{ type : 'h2' , text : 'Discord Server' } ,
{ text : 'You need help with modeling or you want to chat about Blockbench? Join the official [Blockbench Discord](https://discord.gg/WVHg5kH)!' }
] ,
last : true
} )
}
// Keymap Preference
if ( ! Blockbench . isMobile && Blockbench . startup _count <= 1 ) {
var obj = $ ( ` <section id="keymap_preference">
< h2 > $ { tl ( 'mode.start.keymap_preference' ) } < / h 2 >
< p > $ { tl ( 'mode.start.keymap_preference.desc' ) } < / p >
< ul > < / u l >
< / s e c t i o n > ` )
var keymap _list = $ ( obj ) . find ( 'ul' ) ;
obj . prepend ( ` <i class="material-icons start_screen_close_button">clear</i> ` ) ;
obj . find ( 'i.start_screen_close_button' ) . on ( 'click' , ( e ) => {
obj . detach ( ) ;
} ) ;
[
[ 'default' , 'action.load_keymap.default' ] ,
[ 'mouse' , 'action.load_keymap.mouse' ] ,
[ 'blender' , 'Blender' ] ,
[ 'cinema4d' , 'Cinema 4D' ] ,
[ 'maya' , 'Maya' ] ,
] . forEach ( ( [ id , name ] , index ) => {
let node = $ ( ` <li class="keymap_select_box">
< h4 > $ { tl ( name ) } < / h 4 >
< p > $ { tl ( ` action.load_keymap. ${ id } .desc ` ) } < / p >
< / l i > ` )
node . on ( 'click' , e => {
Keybinds . loadKeymap ( id , true ) ;
obj . detach ( ) ;
} )
keymap _list . append ( node ) ;
} )
$ ( '#start_screen content' ) . prepend ( obj ) ;
}
} )
} ) ( )