2020-12-22 20:32:49 +08:00
var StartScreen ;
2019-12-16 03:04:31 +08:00
var ColorPanel ;
2019-07-18 00:02:07 +08:00
//Panels
2020-07-16 15:32:59 +08:00
2019-07-18 00:02:07 +08:00
class ResizeLine {
constructor ( data ) {
var scope = this ;
this . id = data . id
this . horizontal = data . horizontal === true
this . position = data . position
this . condition = data . condition
this . width = 0 ;
var jq = $ ( '<div class="resizer ' + ( data . horizontal ? 'horizontal' : 'vertical' ) + '"></div>' )
this . node = jq . get ( 0 )
jq . draggable ( {
2020-04-26 02:25:07 +08:00
axis : this . horizontal ? 'y' : 'x' ,
2021-07-24 19:51:42 +08:00
containment : '#work_screen' ,
2019-07-18 00:02:07 +08:00
revert : true ,
2020-04-26 02:25:07 +08:00
revertDuration : 0 ,
2019-07-18 00:02:07 +08:00
start : function ( e , u ) {
scope . before = data . get ( )
} ,
drag : function ( e , u ) {
if ( scope . horizontal ) {
data . set ( scope . before , u . position . top - u . originalPosition . top )
} else {
2020-04-26 02:25:07 +08:00
data . set ( scope . before , ( u . position . left - u . originalPosition . left ) )
2019-07-18 00:02:07 +08:00
}
updateInterface ( )
} ,
stop : function ( e , u ) {
updateInterface ( )
}
} )
}
update ( ) {
if ( BARS . condition ( this . condition ) ) {
$ ( this . node ) . show ( )
if ( this . position ) {
this . position ( this )
}
} else {
$ ( this . node ) . hide ( )
}
}
setPosition ( data ) {
var jq = $ ( this . node )
jq . css ( 'top' , data . top !== undefined ? data . top + 'px' : '' )
jq . css ( 'bottom' , data . bottom !== undefined ? data . bottom + 'px' : '' )
jq . css ( 'left' , data . left !== undefined ? data . left + 'px' : '' )
jq . css ( 'right' , data . right !== undefined ? data . right + 'px' : '' )
if ( data . top !== undefined ) {
jq . css ( 'top' , data . top + 'px' )
}
if ( data . bottom !== undefined && ( ! data . horizontal || data . top === undefined ) ) {
jq . css ( 'bottom' , data . bottom + 'px' )
}
if ( data . left !== undefined ) {
jq . css ( 'left' , data . left + 'px' )
}
if ( data . right !== undefined && ( data . horizontal || data . left === undefined ) ) {
jq . css ( 'right' , data . right + 'px' )
}
}
}
2020-07-16 15:32:59 +08:00
const Interface = {
2019-07-18 00:02:07 +08:00
default _data : {
2021-02-06 04:51:04 +08:00
left _bar _width : 366 ,
2019-07-26 19:33:29 +08:00
right _bar _width : 314 ,
2019-07-18 00:02:07 +08:00
quad _view _x : 50 ,
quad _view _y : 50 ,
2019-08-18 00:26:14 +08:00
timeline _height : 260 ,
2019-07-18 00:02:07 +08:00
left _bar : [ 'uv' , 'textures' , 'display' , 'animations' , 'keyframe' , 'variable_placeholders' ] ,
2020-09-16 17:11:29 +08:00
right _bar : [ 'element' , 'bone' , 'color' , 'outliner' , 'chat' ]
2019-07-18 00:02:07 +08:00
} ,
2021-01-10 01:33:42 +08:00
get left _bar _width ( ) {
return Prop . show _left _bar ? Interface . data . left _bar _width : 0 ;
} ,
get right _bar _width ( ) {
return Prop . show _right _bar ? Interface . data . right _bar _width : 0 ;
} ,
2019-07-18 00:02:07 +08:00
Resizers : {
left : new ResizeLine ( {
id : 'left' ,
condition : function ( ) {
2021-01-10 01:33:42 +08:00
if ( ! Prop . show _left _bar ) return false ;
2020-07-16 15:32:59 +08:00
for ( let p of Interface . data . left _bar ) {
if ( Interface . Panels [ p ] && BARS . condition ( Interface . Panels [ p ] . condition ) ) {
return true ;
}
}
2019-07-18 00:02:07 +08:00
} ,
get : function ( ) { return Interface . data . left _bar _width } ,
set : function ( o , diff ) {
2021-04-11 19:15:21 +08:00
let min = 128 ;
let calculated = limitNumber ( o + diff , min , window . innerWidth - 120 - Interface . data . right _bar _width )
2020-04-26 02:25:07 +08:00
Interface . data . left _bar _width = Math . snapToValues ( calculated , [ Interface . default _data . left _bar _width ] , 16 ) ;
2021-04-11 19:15:21 +08:00
if ( calculated == min ) {
Prop . show _left _bar = false ;
Interface . data . left _bar _width = Interface . default _data . left _bar _width ;
} else {
Prop . show _left _bar = true ;
}
2019-07-18 00:02:07 +08:00
} ,
position : function ( line ) {
line . setPosition ( {
2021-07-24 19:51:42 +08:00
top : document . getElementById ( 'work_screen' ) . offsetTop ,
2019-07-18 00:02:07 +08:00
bottom : 0 ,
2020-04-26 02:25:07 +08:00
left : Interface . data . left _bar _width + 2
2019-07-18 00:02:07 +08:00
} )
}
} ) ,
right : new ResizeLine ( {
id : 'right' ,
condition : function ( ) {
2021-01-10 01:33:42 +08:00
if ( ! Prop . show _right _bar ) return false ;
2020-07-16 15:32:59 +08:00
for ( let p of Interface . data . right _bar ) {
if ( Interface . Panels [ p ] && BARS . condition ( Interface . Panels [ p ] . condition ) ) {
return true ;
}
}
2019-07-18 00:02:07 +08:00
} ,
get : function ( ) { return Interface . data . right _bar _width } ,
set : function ( o , diff ) {
2021-04-11 19:15:21 +08:00
let min = 128 ;
let calculated = limitNumber ( o - diff , min , window . innerWidth - 120 - Interface . data . left _bar _width ) ;
2020-04-26 02:25:07 +08:00
Interface . data . right _bar _width = Math . snapToValues ( calculated , [ Interface . default _data . right _bar _width ] , 12 ) ;
2021-04-11 19:15:21 +08:00
if ( calculated == min ) {
Prop . show _right _bar = false ;
Interface . data . right _bar _width = Interface . default _data . right _bar _width ;
} else {
Prop . show _right _bar = true ;
}
2019-07-18 00:02:07 +08:00
} ,
position : function ( line ) {
line . setPosition ( {
2021-07-24 19:51:42 +08:00
top : document . getElementById ( 'work_screen' ) . offsetTop + 30 ,
2019-07-18 00:02:07 +08:00
bottom : 0 ,
2020-04-26 02:25:07 +08:00
right : Interface . data . right _bar _width - 2
2019-07-18 00:02:07 +08:00
} )
}
} ) ,
quad _view _x : new ResizeLine ( {
id : 'quad_view_x' ,
condition : function ( ) { return quad _previews . enabled } ,
get : function ( ) { return Interface . data . quad _view _x } ,
set : function ( o , diff ) { Interface . data . quad _view _x = limitNumber ( o + diff / $ ( '#preview' ) . width ( ) * 100 , 5 , 95 ) } ,
2019-08-18 00:26:14 +08:00
position : function ( line ) {
var p = document . getElementById ( 'preview' )
line . setPosition ( {
top : 32 ,
bottom : p ? window . innerHeight - ( p . clientHeight + p . offsetTop ) : 0 ,
2021-01-10 01:33:42 +08:00
left : Interface . left _bar _width + $ ( '#preview' ) . width ( ) * Interface . data . quad _view _x / 100
2019-08-18 00:26:14 +08:00
}
) }
2019-07-18 00:02:07 +08:00
} ) ,
quad _view _y : new ResizeLine ( {
id : 'quad_view_y' ,
horizontal : true ,
condition : function ( ) { return quad _previews . enabled } ,
get : function ( ) { return Interface . data . quad _view _y } ,
set : function ( o , diff ) {
Interface . data . quad _view _y = limitNumber ( o + diff / $ ( '#preview' ) . height ( ) * 100 , 5 , 95 )
} ,
position : function ( line ) { line . setPosition ( {
2021-01-10 01:33:42 +08:00
left : Interface . left _bar _width + 2 ,
right : Interface . right _bar _width + 2 ,
2019-07-18 00:02:07 +08:00
top : $ ( '#preview' ) . offset ( ) . top + $ ( '#preview' ) . height ( ) * Interface . data . quad _view _y / 100
} ) }
2019-08-18 00:26:14 +08:00
} ) ,
timeline : new ResizeLine ( {
id : 'timeline' ,
horizontal : true ,
condition : function ( ) { return Modes . animate } ,
get : function ( ) { return Interface . data . timeline _height } ,
set : function ( o , diff ) {
Interface . data . timeline _height = limitNumber ( o - diff , 150 , document . body . clientHeight - 120 )
} ,
position : function ( line ) { line . setPosition ( {
2021-01-10 01:33:42 +08:00
left : Interface . left _bar _width + 2 ,
right : Interface . right _bar _width + 2 ,
2019-08-18 00:26:14 +08:00
top : $ ( '#timeline' ) . offset ( ) . top
} ) }
2019-07-18 00:02:07 +08:00
} )
} ,
status _bar : { } ,
2021-01-10 01:33:42 +08:00
Panels : { } ,
toggleSidebar ( side ) {
let status = ! Prop [ ` show_ ${ side } _bar ` ] ;
Prop [ ` show_ ${ side } _bar ` ] = status ;
resizeWindow ( ) ;
}
2019-07-18 00:02:07 +08:00
}
2020-09-22 05:23:42 +08:00
Interface . panel _definers = [ ]
Interface . definePanels = function ( callback ) {
Interface . panel _definers . push ( callback ) ;
}
2019-07-18 00:02:07 +08:00
//Misc
function unselectInterface ( event ) {
if ( open _menu && $ ( '.contextMenu' ) . find ( event . target ) . length === 0 && $ ( '.menu_bar_point.opened:hover' ) . length === 0 ) {
open _menu . hide ( ) ;
}
if ( ActionControl . open && $ ( '#action_selector' ) . find ( event . target ) . length === 0 ) {
ActionControl . hide ( ) ;
}
if ( $ ( event . target ) . is ( 'input.cube_name:not([disabled])' ) === false && Blockbench . hasFlag ( 'renaming' ) ) {
stopRenameOutliner ( )
}
}
function setupInterface ( ) {
Interface . data = $ . extend ( true , { } , Interface . default _data )
var interface _data = localStorage . getItem ( 'interface_data' )
try {
interface _data = JSON . parse ( interface _data )
var old _data = Interface . data
2019-08-01 06:01:47 +08:00
if ( interface _data . left _bar ) Interface . data . left _bar = interface _data . left _bar ;
if ( interface _data . right _bar ) Interface . data . right _bar = interface _data . right _bar ;
2019-07-18 00:02:07 +08:00
$ . extend ( true , Interface . data , interface _data )
} catch ( err ) { }
2021-02-10 05:26:52 +08:00
translateUI ( )
2019-07-18 00:02:07 +08:00
$ ( '.edit_session_active' ) . hide ( )
2020-03-05 03:56:17 +08:00
$ ( '#center' ) . toggleClass ( 'checkerboard' , settings . preview _checkerboard . value ) ;
2020-07-16 15:32:59 +08:00
setupPanels ( )
2020-10-11 22:54:52 +08:00
2020-10-22 00:31:26 +08:00
if ( Blockbench . isMobile && window . setupMobilePanelSelector ) {
2020-10-11 22:54:52 +08:00
setupMobilePanelSelector ( )
}
2019-07-18 00:02:07 +08:00
for ( var key in Interface . Resizers ) {
var resizer = Interface . Resizers [ key ]
2021-07-24 19:51:42 +08:00
$ ( '#work_screen' ) . append ( resizer . node )
2019-07-18 00:02:07 +08:00
}
//$(document).contextmenu()
//Tooltip Fix
2019-08-18 00:26:14 +08:00
$ ( document ) . on ( 'mouseenter' , '.tool' , function ( ) {
2019-07-18 00:02:07 +08:00
var tooltip = $ ( this ) . find ( 'div.tooltip' )
if ( ! tooltip || typeof tooltip . offset ( ) !== 'object' ) return ;
//Left
if ( tooltip . css ( 'left' ) === '-4px' ) {
tooltip . css ( 'left' , 'auto' )
}
if ( - tooltip . offset ( ) . left > 4 ) {
tooltip . css ( 'left' , '-4px' )
}
//Right
if ( tooltip . css ( 'right' ) === '-4px' ) {
tooltip . css ( 'right' , 'auto' )
}
2019-08-18 00:26:14 +08:00
2021-01-31 07:12:53 +08:00
if ( ( tooltip . offset ( ) . left + tooltip . width ( ) ) - window . innerWidth > 4 ) {
2019-07-18 00:02:07 +08:00
tooltip . css ( 'right' , '-4px' )
2019-08-18 00:26:14 +08:00
} else if ( $ ( this ) . parent ( ) . css ( 'position' ) == 'relative' ) {
tooltip . css ( 'right' , '0' )
2019-07-18 00:02:07 +08:00
}
} )
//Clickbinds
2021-01-31 05:30:34 +08:00
$ ( 'header' ) . click ( function ( ) { setActivePanel ( 'header' ) } )
$ ( '#preview' ) . click ( function ( ) { setActivePanel ( 'preview' ) } )
2019-07-18 00:02:07 +08:00
$ ( '#texture_list' ) . click ( function ( ) {
unselectTextures ( )
} )
$ ( '#timeline' ) . mousedown ( ( event ) => {
setActivePanel ( 'timeline' ) ;
} )
2019-12-16 03:04:31 +08:00
$ ( document ) . on ( 'mousedown touchstart' , unselectInterface )
2021-03-11 02:25:56 +08:00
window . addEventListener ( 'resize' , resizeWindow ) ;
window . addEventListener ( 'orientationchange' , ( ) => {
setTimeout ( resizeWindow , 100 )
} ) ;
2019-07-18 00:02:07 +08:00
$ ( '.context_handler' ) . on ( 'click' , function ( ) {
$ ( this ) . addClass ( 'ctx' )
} )
2021-03-11 02:25:56 +08:00
Interface . text _edit _menu = new Menu ( [
{
id : 'copy' ,
name : 'Copy' ,
icon : 'fa-copy' ,
click ( ) {
document . execCommand ( 'copy' ) ;
}
} ,
{
id : 'paste' ,
name : 'Paste' ,
icon : 'fa-paste' ,
click ( ) {
document . execCommand ( 'paste' ) ;
}
}
] )
$ ( document ) . on ( 'contextmenu' , function ( event ) {
2019-07-18 00:02:07 +08:00
if ( ! $ ( event . target ) . hasClass ( 'allow_default_menu' ) ) {
2021-03-11 02:25:56 +08:00
if ( event . target . nodeName === 'INPUT' && $ ( event . target ) . is ( ':focus' ) ) {
2019-07-18 00:02:07 +08:00
Interface . text _edit _menu . open ( event , event . target )
2021-03-11 02:25:56 +08:00
}
2019-07-18 00:02:07 +08:00
return false ;
}
} )
//Scrolling
$ ( 'input[type="range"]' ) . on ( 'mousewheel' , function ( ) {
var obj = $ ( event . target )
var factor = event . deltaY > 0 ? - 1 : 1
var val = parseFloat ( obj . val ( ) ) + parseFloat ( obj . attr ( 'step' ) ) * factor
val = limitNumber ( val , obj . attr ( 'min' ) , obj . attr ( 'max' ) )
if ( obj . attr ( 'trigger_type' ) ) {
DisplayMode . scrollSlider ( obj . attr ( 'trigger_type' ) , val , obj )
return ;
}
obj . val ( val )
eval ( obj . attr ( 'oninput' ) )
eval ( obj . attr ( 'onmouseup' ) )
} )
//Mousemove
$ ( document ) . mousemove ( function ( event ) {
mouse _pos . x = event . clientX
mouse _pos . y = event . clientY
} )
updateInterface ( )
}
function updateInterface ( ) {
BARS . updateConditions ( )
MenuBar . update ( )
resizeWindow ( )
localStorage . setItem ( 'interface_data' , JSON . stringify ( Interface . data ) )
}
function updateInterfacePanels ( ) {
2021-01-10 01:33:42 +08:00
2021-01-24 19:35:13 +08:00
if ( ! Blockbench . isMobile ) {
$ ( '.sidebar#left_bar' ) . css ( 'display' , Prop . show _left _bar ? 'flex' : 'none' ) ;
$ ( '.sidebar#right_bar' ) . css ( 'display' , Prop . show _right _bar ? 'flex' : 'none' ) ;
}
2021-07-11 04:22:02 +08:00
let work _screen = document . getElementById ( 'work_screen' ) ;
2021-01-10 01:33:42 +08:00
2021-07-11 04:22:02 +08:00
work _screen . style . setProperty (
2019-07-18 00:02:07 +08:00
'grid-template-columns' ,
Interface . data . left _bar _width + 'px auto ' + Interface . data . right _bar _width + 'px'
)
for ( var key in Interface . Panels ) {
var panel = Interface . Panels [ key ]
panel . update ( )
}
2021-01-10 01:33:42 +08:00
var left _width = $ ( '.sidebar#left_bar > .panel:visible' ) . length ? Interface . left _bar _width : 0 ;
var right _width = $ ( '.sidebar#right_bar > .panel:visible' ) . length ? Interface . right _bar _width : 0 ;
2019-07-18 00:02:07 +08:00
if ( ! left _width || ! right _width ) {
2021-07-11 04:22:02 +08:00
work _screen . style . setProperty (
2019-07-18 00:02:07 +08:00
'grid-template-columns' ,
left _width + 'px auto ' + right _width + 'px'
)
}
$ ( '.quad_canvas_wrapper.qcw_x' ) . css ( 'width' , Interface . data . quad _view _x + '%' )
$ ( '.quad_canvas_wrapper.qcw_y' ) . css ( 'height' , Interface . data . quad _view _y + '%' )
$ ( '.quad_canvas_wrapper:not(.qcw_x)' ) . css ( 'width' , ( 100 - Interface . data . quad _view _x ) + '%' )
$ ( '.quad_canvas_wrapper:not(.qcw_y)' ) . css ( 'height' , ( 100 - Interface . data . quad _view _y ) + '%' )
2019-08-18 00:26:14 +08:00
$ ( '#timeline' ) . css ( 'height' , Interface . data . timeline _height + 'px' )
2019-07-18 00:02:07 +08:00
for ( var key in Interface . Resizers ) {
var resizer = Interface . Resizers [ key ]
resizer . update ( )
}
}
function resizeWindow ( event ) {
2021-03-11 02:25:56 +08:00
if ( ! Preview . all || ( event && event . target && event . target !== window ) ) {
2019-07-18 00:02:07 +08:00
return ;
}
if ( Interface . data ) {
updateInterfacePanels ( )
}
2021-06-17 05:31:02 +08:00
if ( Animator . open ) {
Timeline . updateSize ( )
}
2020-07-16 15:32:59 +08:00
Preview . all . forEach ( function ( prev ) {
2019-07-18 00:02:07 +08:00
if ( prev . canvas . isConnected ) {
prev . resize ( )
}
} )
var dialog = $ ( 'dialog#' + open _dialog )
if ( dialog . length ) {
if ( dialog . outerWidth ( ) + dialog . offset ( ) . left > window . innerWidth ) {
dialog . css ( 'left' , limitNumber ( window . innerWidth - dialog . outerWidth ( ) , 0 , 4e3 ) + 'px' )
}
if ( dialog . outerHeight ( ) + dialog . offset ( ) . top > window . innerHeight ) {
dialog . css ( 'top' , limitNumber ( window . innerHeight - dialog . outerHeight ( ) , 0 , 4e3 ) + 'px' )
}
}
2020-10-22 00:31:26 +08:00
Blockbench . dispatchEvent ( 'resize_window' , event ) ;
2019-07-18 00:02:07 +08:00
}
2021-03-09 05:42:06 +08:00
2019-07-18 00:02:07 +08:00
function setProjectTitle ( title ) {
2021-07-11 04:22:02 +08:00
let window _title = 'Blockbench' ;
if ( title == undefined && Project . geometry _name ) {
2019-07-18 00:02:07 +08:00
title = Project . geometry _name
}
if ( title ) {
Prop . file _name = Prop . file _name _alt = title
if ( ! Project . name ) {
Project . name = title
}
if ( Format . bone _rig ) {
title = title . replace ( /^geometry\./ , '' ) . replace ( /:[a-z0-9.]+/ , '' )
}
2021-07-11 04:22:02 +08:00
window _title = title + ' - Blockbench' ;
2019-07-18 00:02:07 +08:00
} else {
Prop . file _name = Prop . file _name _alt = ''
}
2021-07-11 04:22:02 +08:00
$ ( 'title' ) . text ( window _title ) ;
$ ( '#header_free_bar' ) . text ( window _title ) ;
2019-07-18 00:02:07 +08:00
}
//Zoom
function setZoomLevel ( mode ) {
if ( Prop . active _panel === 'uv' ) {
var zoom = main _uv . zoom
switch ( mode ) {
case 'in' : zoom *= 1.5 ; break ;
case 'out' : zoom *= 0.66 ; break ;
case 'reset' : zoom = 1 ; break ;
}
zoom = limitNumber ( zoom , 1 , 4 )
main _uv . setZoom ( zoom )
2021-06-09 02:05:43 +08:00
} else if ( Prop . active _panel == 'timeline' ) {
let body = document . getElementById ( 'timeline_body' ) ;
let offsetX = Timeline . vue . scroll _left + ( body . clientWidth - Timeline . vue . head _width ) / 2 ;
if ( mode == 'reset' ) {
let original _size = Timeline . vue . _data . size
Timeline . vue . _data . size = 200 ;
body . scrollLeft += ( Timeline . vue . _data . size - original _size ) * ( offsetX / original _size )
} else {
let zoom = mode == 'in' ? 1.2 : 0.8 ;
let original _size = Timeline . vue . _data . size
let updated _size = limitNumber ( Timeline . vue . _data . size * zoom , 10 , 1000 )
Timeline . vue . _data . size = updated _size ;
body . scrollLeft += ( updated _size - original _size ) * ( offsetX / original _size )
}
} else {
2019-07-18 00:02:07 +08:00
switch ( mode ) {
2021-06-09 02:05:43 +08:00
case 'in' : Preview . selected . controls . dollyIn ( 1.16 ) ; break ;
case 'out' : Preview . selected . controls . dollyOut ( 1.16 ) ; break ;
2019-07-18 00:02:07 +08:00
}
2021-06-09 02:05:43 +08:00
}
2019-07-18 00:02:07 +08:00
}
//Dialogs
function showDialog ( dialog ) {
var obj = $ ( '.dialog#' + dialog )
2021-02-20 05:10:47 +08:00
$ ( '.dialog' ) . hide ( )
2019-07-18 00:02:07 +08:00
if ( open _menu ) {
open _menu . hide ( )
}
2021-02-20 05:10:47 +08:00
$ ( '#blackout' ) . show ( )
obj . show ( )
2019-07-18 00:02:07 +08:00
open _dialog = dialog
2021-06-13 18:35:48 +08:00
open _interface = {
confirm ( ) {
$ ( 'dialog#' + open _dialog ) . find ( '.confirm_btn:not([disabled])' ) . trigger ( 'click' ) ;
} ,
cancel ( ) {
$ ( 'dialog#' + open _dialog ) . find ( '.cancel_btn:not([disabled])' ) . trigger ( 'click' ) ;
}
}
2019-07-18 00:02:07 +08:00
Prop . active _panel = 'dialog'
//Draggable
if ( obj . hasClass ( 'draggable' ) ) {
obj . draggable ( {
handle : ".dialog_handle" ,
2019-09-06 06:16:54 +08:00
containment : '#page_wrapper'
2019-07-18 00:02:07 +08:00
} )
2021-01-31 07:12:53 +08:00
var x = ( window . innerWidth - obj . outerWidth ( ) ) / 2 ;
2019-07-18 00:02:07 +08:00
obj . css ( 'left' , x + 'px' )
2021-01-31 07:12:53 +08:00
obj . css ( 'max-height' , ( window . innerHeight - 128 ) + 'px' )
2019-07-18 00:02:07 +08:00
}
}
function hideDialog ( ) {
2021-02-20 05:10:47 +08:00
$ ( '#blackout' ) . hide ( )
$ ( '.dialog' ) . hide ( )
2019-07-18 00:02:07 +08:00
open _dialog = false ;
open _interface = false ;
Prop . active _panel = undefined
}
2021-02-10 05:26:52 +08:00
function getStringWidth ( string , size ) {
var a = $ ( '<label style="position: absolute">' + string + '</label>' )
if ( size && size !== 16 ) {
a . css ( 'font-size' , size + 'pt' )
}
$ ( 'body' ) . append ( a . css ( 'visibility' , 'hidden' ) )
var width = a . width ( )
a . detach ( )
return width ;
} ;
2019-07-18 00:02:07 +08:00
//UI Edit
function setProgressBar ( id , val , time ) {
if ( ! id || id === 'main' ) {
Prop . progress = val
} else {
$ ( '#' + id + ' > .progress_bar_inner' ) . animate ( { width : val * 488 } , time - 1 )
}
if ( isApp ) {
currentwindow . setProgressBar ( val )
}
}
//Tooltip
function showShiftTooltip ( ) {
$ ( ':hover' ) . find ( '.tooltip_shift' ) . css ( 'display' , 'inline' )
}
$ ( document ) . keyup ( function ( event ) {
if ( event . which === 16 ) {
$ ( '.tooltip_shift' ) . hide ( )
}
} )
//Start Screen
2020-07-16 15:32:59 +08:00
function addStartScreenSection ( id , data ) {
if ( typeof id == 'object' ) {
data = id ;
id = '' ;
}
var obj = $ ( ` <section id=" ${ id } "></section> ` )
2019-07-18 00:02:07 +08:00
if ( typeof data . graphic === 'object' ) {
var left = $ ( '<left class="graphic"></left>' )
obj . append ( left )
if ( data . graphic . type === 'icon' ) {
var icon = Blockbench . getIconNode ( data . graphic . icon )
$ ( icon ) . 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' ) . 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 ) left . css ( 'height' , data . graphic . width + 'px' ) ;
}
}
if ( data . text instanceof Array ) {
var right = $ ( '<right></right>' )
obj . append ( right )
data . text . forEach ( line => {
var content = line . text ? marked ( tl ( line . text ) ) : '' ;
switch ( line . type ) {
case 'h1' : var tag = 'h3' ; break ;
case 'h2' : var tag = 'h4' ; 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' ) {
2021-07-01 15:46:06 +08:00
l . on ( 'click' , line . click ) ;
2019-07-18 00:02:07 +08:00
}
right . append ( l ) ;
} )
}
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 ( )
} ) ;
}
2021-07-01 15:46:06 +08:00
if ( typeof data . click == 'function' ) {
obj . on ( 'click' , event => {
if ( event . target . classList . contains ( 'start_screen_close_button' ) ) return ;
data . click ( )
} )
}
2019-07-18 00:02:07 +08:00
if ( data . color ) {
obj . css ( 'background-color' , data . color ) ;
2019-12-16 03:04:31 +08:00
if ( data . color == 'var(--color-bright_ui)' ) {
obj . addClass ( 'bright_ui' )
}
2019-07-18 00:02:07 +08:00
}
if ( data . text _color ) {
obj . css ( 'color' , data . text _color ) ;
}
if ( data . last ) {
$ ( '#start_screen content' ) . append ( obj ) ;
} else {
$ ( '#start_screen content' ) . prepend ( obj ) ;
}
}
( function ( ) {
2021-06-18 03:37:11 +08:00
var news _call = $ . getJSON ( 'https://web.blockbench.net/content/news.json' )
2019-07-18 00:02:07 +08:00
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 )
}
if ( data . psa ) {
2020-07-27 00:03:16 +08:00
( 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 )
} ) ( )
2019-07-18 00:02:07 +08:00
}
} )
documentReady . then ( ( ) => {
2019-12-16 03:04:31 +08:00
Blockbench . startup _count = parseInt ( localStorage . getItem ( 'startups' ) || 0 )
2019-07-18 00:02:07 +08:00
//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 : 'h1' , 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 } )
} }
]
} )
}
2020-07-16 15:32:59 +08:00
if ( settings . streamer _mode . value ) {
updateStreamerModeNotification ( )
}
2019-07-18 00:02:07 +08:00
2020-07-25 03:13:25 +08:00
//Twitter
let twitter _ad ;
if ( Blockbench . startup _count < 20 && Blockbench . startup _count % 5 === 4 ) {
twitter _ad = true ;
2019-07-18 00:02:07 +08:00
addStartScreenSection ( {
2020-07-25 03:13:25 +08:00
color : '#1da1f2' ,
2019-07-18 00:02:07 +08:00
text _color : '#ffffff' ,
2020-07-25 03:13:25 +08:00
graphic : { type : 'icon' , icon : 'fab.fa-twitter' } ,
2019-07-18 00:02:07 +08:00
text : [
2020-07-25 03:13:25 +08:00
{ type : 'h1' , 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/)' }
2019-07-18 00:02:07 +08:00
] ,
last : true
} )
}
2020-07-25 03:13:25 +08:00
//Discord
if ( Blockbench . startup _count < 6 && ! twitter _ad ) {
2020-04-26 02:25:07 +08:00
addStartScreenSection ( {
2021-06-29 16:11:27 +08:00
color : '#5865F2' ,
2020-04-26 02:25:07 +08:00
text _color : '#ffffff' ,
2020-07-25 03:13:25 +08:00
graphic : { type : 'icon' , icon : 'fab.fa-discord' } ,
2020-04-26 02:25:07 +08:00
text : [
2020-07-25 03:13:25 +08:00
{ type : 'h1' , text : 'Discord Server' } ,
2021-06-29 16:11:27 +08:00
{ text : 'You need help with modeling or you want to chat about Blockbench? Join the official [Blockbench Discord](https://discord.gg/WVHg5kH)!' }
2020-04-26 02:25:07 +08:00
] ,
last : true
} )
}
2021-06-24 03:20:15 +08:00
// Keymap Preference
2021-06-29 16:11:27 +08:00
if ( ! Blockbench . isMobile && Blockbench . startup _count <= 1 ) {
2021-06-24 03:20:15 +08:00
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 ) ;
2021-06-25 00:19:06 +08:00
obj . detach ( ) ;
2021-06-24 03:20:15 +08:00
} )
keymap _list . append ( node ) ;
} )
$ ( '#start_screen content' ) . prepend ( obj ) ;
}
2019-07-18 00:02:07 +08:00
} )
} ) ( )
onVueSetup ( function ( ) {
2021-01-24 21:39:53 +08:00
Interface . status _bar . vue = new Vue ( {
2020-12-22 20:32:49 +08:00
el : '#status_bar' ,
2019-07-18 00:02:07 +08:00
data : {
2021-01-24 19:35:13 +08:00
Prop ,
isMobile : Blockbench . isMobile
2021-01-24 21:39:53 +08:00
} ,
methods : {
toggleSidebar : Interface . toggleSidebar
} ,
template : `
< div id = "status_bar" @ contextmenu = "Interface.status_bar.menu.show(event)" >
< div class = "sidebar_toggle_button" v - if = "!isMobile" @ click = "toggleSidebar('left')" : title = "tl('status_bar.toggle_sidebar')" >
< i class = "material-icons" > { { Prop . show _left _bar ? 'chevron_left' : 'chevron_right' } } < / i >
< / d i v >
< div class = "f_left" v - if = "settings.streamer_mode.value"
style = "background-color: var(--color-stream); color: var(--color-light);"
@ click = "Settings.open({search: 'streamer_mode'})"
v - bind : title = "tl('interface.streamer_mode_on')"
>
< i class = "material-icons" > live _tv < / i >
< / d i v >
< div v - html = "Blockbench.getIconNode(Format.icon).outerHTML" v - bind : title = "Format.name" > < / d i v >
< div v - if = "Prop.recording" v - html = "Blockbench.getIconNode('fiber_manual_record').outerHTML" style = "color: var(--color-close)" v - bind : title = "tl('status_bar.recording')" > < / d i v >
< div id = "status_name" >
{ { Prop . file _name } }
< / d i v >
< div id = "status_message" class = "hidden" > < / d i v >
< div class = "f_right" >
{ { Prop . fps } } FPS
< / d i v >
< div class = "sidebar_toggle_button" v - if = "!isMobile" @ click = "toggleSidebar('right')" : title = "tl('status_bar.toggle_sidebar')" >
< i class = "material-icons" > { { Prop . show _right _bar ? 'chevron_right' : 'chevron_left' } } < / i >
< / d i v >
< div id = "status_progress" v - if = "Prop.progress" v - bind : style = "{width: Prop.progress*100+'%'}" > < / d i v >
< / d i v >
`
2019-07-18 00:02:07 +08:00
} )
} )