
var MENU_SELECT="select";
var MENU_ADD="add";
var MENU_ADD2="add2";
var MENU_ADD3="add3";
var MENU_DEL="delete";
var MENU_MOVE="move";
var MENU_MOVE2="move2";
var switch_op=HOME.switchscreen_op;
switch_op.cursor=null;
switch_op.is_move=false;
switch_op._adding_screen=false;
var top_menu=new container({});
var left_menu=new container({});
var indicator=new container({});
var template_menu=new container({});
var screen_base=new container({});
screen_base._active_screen=[null,null,null];
var MYPOSITION={
"MYSCREEN":{
alpha:0.35,speed:12,dest:[
{pos:[-1920*1.4*2,0,0],angle:46},
{pos:[-1920*1.4,0,0],angle:46},
{pos:[0,0,0],angle:0},
{pos:[1920*1.4,0,0],angle:-46},
{pos:[1920*1.4*2,0,0],angle:-46},
],
},
"3MIRROR":{
alpha:0.35,speed:16,dest:[
{pos:[-1920*1.4*2,0,-1920*1.4],angle:46},
{pos:[-1920*1.4,0,-1920*1.4],angle:46},
{pos:[0,0,-1600],angle:0},
{pos:[1920*1.4,0,-1920*1.4],angle:-46},
{pos:[1920*1.4*2,0,-1920*1.4],angle:-46},
],
},
"DELETE":{
alpha:0.35,speed:12,dest:[
{pos:[-1920*1.4*2,0,0],angle:46},
{pos:[-1920*1.4,0,0],angle:46},
{pos:[0,0,CAMERA_POS*10],angle:0},
{pos:[1920*1.4,0,0],angle:-46},
{pos:[1920*1.4*2,0,0],angle:-46},
],
},
"ADD":{
alpha:0.35,speed:8,dest:[
{pos:[-(345+530*2-80)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[-(345+530*1-80)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[-(345+530*0-80)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[+(345+530*0-80)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[+(345+530*1-80)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[+(345+530*2-80)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
],
},
"ADD_OPEN":{
alpha:0.35*2,speed:4,dest:[
{pos:[-(345+530*2)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[-(345+530*1)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[-(345+530*0)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[+(345+530*0)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[+(345+530*1)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
{pos:[+(345+530*2)*3.8,-254*3.8,CAMERA_POS*2.8],angle:0},
],
},
"MOVE2":null,
"MOVE2_OPEN":null,
};
MYPOSITION["MOVE2"]=MYPOSITION["ADD"];
MYPOSITION["MOVE2_OPEN"]=MYPOSITION["ADD_OPEN"];
var FOCUS_POSITION={pos:[0,0,0],size:[976+6,549+6]};
var is_return_lock=false;
var is_exec_lock=false;
var return_lock=function(bool){
is_return_lock=bool;
switch_op.is_move=(is_return_lock||is_exec_lock);
if(HOME.setowner_op)
HOME.setowner_op.is_move=switch_op.is_move;};
var exec_lock=function(bool){
is_exec_lock=bool;
switch_op.is_move=(is_return_lock||is_exec_lock);
if(HOME.setowner_op)
HOME.setowner_op.is_move=switch_op.is_move;};
switch_op._active_screen=screen_base._active_screen;
switch_op.init=function(){
var me=this;
this.visible_p=false;
this.top_menu=top_menu;
this.top_menu.left_menu=left_menu;
this.top_menu.left_menu.indicator=indicator;
this.top_menu.left_menu.template_menu=template_menu;
this.screen_base=startup_selection.screen_base;
this.top_menu.left_menu.screen_base=this.screen_base;

var createConfirmpanel=function(){
me.createConfirmpanel.apply(me,arguments);}
var changeOperator=function (mode){
if(mode==HOME.EDIT_SCREEN)
me._adding_screen=true;
me.switchUI(me,HOME.MY_SCREEN);}
this.top_menu.init(this.getScreenOrder,this.getScreenInfo,
this.focus,this.getScreen,
createConfirmpanel,this.getVanishProductIDs,
this.removeScreen,this.getPowerOnScreen,this.addScreen,
changeOperator);
this.cursor=this.top_menu;
this.components=[this.focus];
this.components.unshift(this.screen_base);
this.components.unshift(this.top_menu);}
switch_op.key_hook=function(up_down,key){
if(is_return_lock==true)return true;
var me=this;
if(up_down==KEY_PRESS&&
(key==TXK_HOME||key==TXK_EXIT)){
if(this.is_move==true)return true;
this._back_hs();
return true;}
if(this.cursor&&this.cursor.key_hook)
if(this.cursor.key_hook(up_down,key))
return true;
if(up_down!=KEY_PRESS)
return false;
var current_key=me.getCurrentScreenKey();
switch(key){
case TXK_ENTER:
if(this.is_move)
return false;
var type=this.top_menu.getMenuType();
switch(type){
case MENU_SELECT:
HOME.HomeSoundPlay("enter");
exec_lock(true);
var finished=function(){
exec_lock(false);
me.switchUI(me,HOME.MY_SCREEN);}
this.jumpScreen(current_key,function(){
me.top_menu.selectScreen(finished);});
break;
default:
break;}
return true;
case TXK_RETURN:
this._back_hs();
return true;
default:
break;}
return false;}
switch_op.in_hook=function (enable_screen,func){
HOME.setCurProfId(null);
this.visible_p=true;
this.focus.setShow(false);
this.focus.setTranslate.apply(this.focus,FOCUS_POSITION.pos);
this.focus.setSize.apply(this.focus,FOCUS_POSITION.size);
this.focus.stopAnimation();
return_lock(false);
exec_lock(false);
this.top_menu.in_hook.apply(this.top_menu,arguments);
this._last_screen_key=this._active_screen[1].getScreenKey();
var bplayer=new BroadcastPlayer();
try{
bplayer.connect(VideoDev,AudioDev);
bplayer.set_browser_mode(BR_SRC_DEFAULT);
bplayer.df_connect();}catch(e){};}
switch_op.out_hook=function (){
this.visible_p=false;
this.focus.setShow(false);
this.focus.setTranslate.apply(this.focus,FOCUS_POSITION.pos);
this.focus.setSize.apply(this.focus,FOCUS_POSITION.size);
this.focus.stopAnimation();
this.top_menu.out_hook();
this._active_screen[1].createGadgets();
return this._active_screen.slice();}
switch_op.createConfirmpanel=function (type,text,label1,label2,
action_func1,action_func2,mysize){
var me=this;
var focus_moveto=function(){
me.focus.moveTo.apply(me.focus,arguments);};
var func1=function(){
me.preDestroyConfirmpanel();
if(action_func1)action_func1.apply(me,arguments);
me.destroyConfirmpanel();};
var func2=function(){
me.preDestroyConfirmpanel();
if(action_func2)action_func2.apply(me,arguments);
me.destroyConfirmpanel();};
this.bg=new gbox({translate:[0,0,2],width:1920+2,height:1080+2,color:COL_GRAYOUT});
this.confirm=new Confirmpanel(type,[func1,func2],focus_moveto);
this.confirm.setMessageText(text);
this.confirm.setButtonLabel(label1,label2);
this.confirm.setTranslate(0,0,0);
var size=[800,350];
if(mysize&&isNumber(mysize[0])&&isNumber(mysize[1]))size=mysize;
this.confirm.setSize(size[0],size[1]);
this.components.push(this.bg,this.confirm);
this.confirm.setShow(true);
var id=this.components.indexOf(this.focus);
this.components.splice(id,1);
this.components.push(this.focus);
this.cursor=this.confirm;
this.cursor.onFocus(true);
this._is_exec_lock=is_exec_lock;}
switch_op.preDestroyConfirmpanel=function(){
exec_lock(this._is_exec_lock);}
switch_op.destroyConfirmpanel=function(){
this.cursor=top_menu;
this.cursor.onFocus(true);
if(this.confirm){
this.confirm.setShow(false);
this.confirm.free();}
var id=this.components.indexOf(this.bg);
if(id!=-1)this.components.splice(id,1);
var id=this.components.indexOf(this.confirm);
if(id!=-1)this.components.splice(id,1);}
switch_op.getMenuType=function(){
return this.top_menu.getMenuType();}
switch_op.getLastScreenKey=function (){
return this.top_menu.getLastScreenKey();}
switch_op.activateSelectedScreen=function(bool){
return this.top_menu.activateSelectedScreen(bool);};
switch_op.getCurrentScreenKey=function(){
return this.top_menu.getCurrentScreenKey();}
switch_op.getSelectedScreen=function(){
return this.top_menu.getSelectedScreen();}
switch_op.addDLScreen=function(install_id){
var me=this;
me.focus.setShow(false);
var finished=function (){
append_timer(me._addDLScreenTimer,500,function(obj){
delete_timer(obj);
exec_lock(false);
me.switchUI(me,HOME.MY_SCREEN);});}
append_timer(this._addDLScreenTimer,2000,function(obj){
delete_timer(obj);
me.top_menu.addDLScreen.apply(me.top_menu,[install_id,finished]);});}
switch_op.jumpScreenTimer={};
switch_op.jumpScreen=function(dest_screen_key,finished_func){
return this._back(dest_screen_key,finished_func);};
switch_op.updateScreen=function(finished_func){
var screen_key=this.getCurrentScreenKey();
this.jumpScreen(screen_key,finished_func);
return true;};
switch_op._addDLScreenTimer={};
switch_op._back_hs=function(){
var me=this;
var dest_screen_key=this._last_screen_key;
var finished_func=function(){
me.switchUI(me,HOME.MY_SCREEN);};
return this._back(dest_screen_key,finished_func);}
switch_op._back=function(dest_screen_key,finished_func){
this.focus.setShow(false);
exec_lock(true);return_lock(true);this.destroyConfirmpanel();
var me=this;
var finished=function(){
append_timer({},500,function(obj){
delete_timer(obj);
exec_lock(false);return_lock(false);
if(finished_func)finished_func();});}
this.top_menu.setArrow(false);
this.top_menu.setCursorArrow(false);
this.top_menu.menu.map(function(obj){obj.bg_highlight(false);});
var order=this.getScreenOrder();
if(order.indexOf(dest_screen_key)==-1){
dest_screen_key=order[0];}
var selected=this.getSelectedScreen();
if(!selected){
if(this.top_menu.getMenuType()==MENU_ADD2){
this.top_menu.onFocus(false);
this.top_menu.setMenuType(MENU_SELECT);
this.top_menu.onFocus(true);
append_timer({},500,function(obj){
delete_timer(obj);
me.top_menu.jumpScreen(dest_screen_key,finished,true);});
return;}
this.top_menu.jumpScreen(dest_screen_key,finished,true);
return;}
var target_key=dest_screen_key;
var pre_finished=finished;
if(dest_screen_key!=selected.getScreenKey()){
target_key=selected.getScreenKey();
pre_finished=function(){
me.top_menu.onFocus(false);
me.top_menu.cursor=me.top_menu.left_menu;
me.top_menu.onFocus(true);
append_timer({},500,function(obj){
delete_timer(obj);
me.top_menu.jumpScreen(dest_screen_key,finished,true);});};}

var order=this.getScreenOrder();
var index=order.indexOf(target_key);
var ret_screen_key=order[index-1];
if(!isScreenKey(ret_screen_key)){
ret_screen_key="first";}
this.top_menu.jumpScreen(ret_screen_key,function(){
me.top_menu.moveScreen(pre_finished,true);},true);}
switch_op.updateUsrprof=function(){
var screen_key=this.top_menu.getCurrentScreenKey();
this.top_menu.initMenu(screen_key);}
top_menu.init=function (getScreenOrder,getScreenInfo,
focus,getScreen,
createConfirmpanel,getVanishProductIDs,
removeScreen,getPowerOnScreen,addNewScreen,
changeOperator){
this.getScreenOrder=getScreenOrder;
this.getScreenInfo=getScreenInfo;
this.focus=focus;
this.createConfirmpanel=createConfirmpanel;
this.addNewScreen=addNewScreen;
this.changeOperator=changeOperator;

var me=this;
var topmenu_addScreen=function(){
me.addScreen.apply(me,arguments);}
var topmenu_moveScreen=function(){
me.moveScreen.apply(me,arguments);}
this.left_menu.init(getScreenOrder,getScreenInfo,
focus,getScreen,
createConfirmpanel,getVanishProductIDs,
removeScreen,getPowerOnScreen,addNewScreen,
changeOperator,
topmenu_addScreen,topmenu_moveScreen);
this.menulist=[
{label:LANG("LT_HOME_ADD_1"),type:MENU_ADD},
{label:LANG("LT_HOME_DELETE"),type:MENU_DEL},
{label:LANG("LT_HOME_MOVE_SCREEN"),type:MENU_MOVE},
];
this.screen_title=new gtext({translate:[-1920/2+664/2,1080/2-54/2,0],
width:600,color:COL_TEXT_ONBASE,
text:LANG("LT_HOME_SCREEN_SELECTION"),font_size:40,});
this.menu=[];
for(var i=0;i<this.menulist.length;i++){
this.menu[i]=new btn(370,52,false,null);
this.menu[i].translate=[i*380,1080/2-27-6,0];
this.menu[i].setSkin(this.menulist[i].label,32);
if(system.mdl_cfg.with_smart_lock==true
&&system.mdl_cfg.is_smart_lock==true
&&system.mdl_cfg.settings_lock==true){
this.menu[i].setEnabled(false);}else {
this.menu[i].setEnabled(true);}
}
this.border=new gbox({translate:[0,1080/2-62+2,0],
width:1920,height:2,color:COL_BORDER_ONBASE});
this.components.push(this.left_menu);
this.components.push(this.screen_title);
this.components.push.apply(this.components,this.menu);
this.components.push(this.border);}
top_menu.in_hook=function (){
this.visible_p=true;
var me=this;
var index=0;
this.cursor=this.left_menu;
this.index_cursor=this.menu[index];
this.menu.map(function(obj){obj.bg_highlight(false);});
this.left_menu.in_hook.apply(this.left_menu,arguments);
this.setMenuType(MENU_SELECT,"reload");}
top_menu.out_hook=function (){
this.visible_p=false;
this.left_menu.out_hook.apply(this.left_menu,arguments);}
top_menu.onFocus=function(bool){
if(this.cursor){
this.cursor.onFocus(bool);
if(bool&&this.cursor.voicePlay){
if(this.getMenuType()==MENU_SELECT)
this.cursor.voicePlay();}
return;}
if(!this.index_cursor){
this.index_cursor=this.menu[0];}
var target=this.index_cursor;
this.focus.moveTo(target.translate,[target.width,target.height]);
if(bool&&(this.index_cursor instanceof btn)&&this.index_cursor.voicePlay)
this.index_cursor.voicePlay();}
top_menu.getLastScreenKey=function (){
return this.left_menu.getLastScreenKey();}
top_menu.getCurrentScreenKey=function (){
return this.left_menu.getCurrentScreenKey();}
top_menu.activateSelectedScreen=function(bool){
return this.left_menu.activateSelectedScreen(bool);};
top_menu.key_hook=function (up_down,key){
if(this.cursor&&this.cursor.key_hook)
if(this.cursor.key_hook(up_down,key))
return true;
if(up_down!=KEY_PRESS)
return false;
var me=this;
var current_key=this.getCurrentScreenKey();
switch(key){
case TXK_ENTER:
var type=this.getMenuType();
var newtype=null;
var index=0;
switch(type){case MENU_SELECT:
if(this.cursor!=this.left_menu){
var index=this.menu.indexOf(this.index_cursor);
if(!this.menu[index]._enabled)
return true;
newtype=this.menulist[index].type;
switch(newtype){
case MENU_ADD:
var ret=this.checkAddableScreen();
if(!ret)return true;
this.onFocus(false);
this.cursor=this.left_menu;
this.cursor.enableVoicePlay(false);
this.onFocus(true);
this.cursor.enableVoicePlay(true);
break;}
}
break;}
switch(newtype){case null:
break;
case MENU_ADD:
exec_lock(true);
this.menu.map(function(obj){obj.bg_highlight(obj==me.index_cursor);});
this.setMenuType(newtype);
HOME.HomeSoundPlay("enter");
return true;
case MENU_DEL:
exec_lock(true);
this.menu.map(function(obj){obj.bg_highlight(obj==me.index_cursor);});
this.deleteScreen();
this.setMenuType(newtype);
HOME.HomeSoundPlay("enter");
exec_lock(false);
return true;
case MENU_MOVE:
if(this.cursor==this.left_menu)
return false;
exec_lock(true);
this.setMenuType(newtype);
HOME.HomeSoundPlay("enter");
this.menu.map(function(obj){obj.bg_highlight(obj==me.index_cursor);});
this.onFocus(false);
this.cursor=this.left_menu;
this.jumpScreen(current_key,function(){
me.setMenuType(MENU_MOVE2);
me.left_menu.onFocus(true);
exec_lock(false);},true);
return true;}
return false;
case TXK_RETURN:
if(is_exec_lock)
return true;
switch(this.getMenuType()){
case MENU_ADD2:
this.setCursorArrow(false);
this.menu.map(function(obj){obj.bg_highlight(false);});
this.onFocus(false);
this.cursor=null;
this.onFocus(true);
HOME.HomeSoundPlay("cancel");
this.setMenuType(MENU_SELECT);
return true;
case MENU_MOVE2:
this.setCursorArrow(false);
this.menu.map(function(obj){obj.bg_highlight(false);});
this.onFocus(false);
this.cursor=null;
this.onFocus(true);
HOME.HomeSoundPlay("cancel");
this.setMenuType(MENU_SELECT);
return true;}
break;
case TXK_LEFT:
case TXK_RIGHT:
var type=this.getMenuType();
switch(type){
case MENU_ADD2:
HOME.HomeSoundPlay(0);
this.cursor=this.left_menu;
return false;
default:
if(is_exec_lock)
return true;
var index=this.menu.indexOf(this.index_cursor);
if(index==-1)index=0;
var next=index+((key==TXK_LEFT)?-1:1);
if(next<0||next>=this.menu.length)return true;
HOME.HomeSoundPlay(0);
this.index_cursor=this.menu[next];
this.onFocus(true);}
return true;
case TXK_UP:if(is_exec_lock)return true;
this.gotoSelect(true);

return true;
case TXK_DOWN:
if(this.cursor)
return false;
this.onFocus(false);
this.cursor=this.left_menu;
this.index_cursor=this.menu[0];
this.onFocus(true);
this.setMenuType(MENU_SELECT);
HOME.HomeSoundPlay(0);
force_redraw();
return true;}
return false;}
top_menu.setMenuType=function(type){
this._menu_type=type;
this.left_menu.setMenuType(type);}
top_menu.getMenuType=function(){
return this.left_menu.getMenuType();}
top_menu.setArrow=function(bool){
return this.left_menu.setArrow(bool);}
top_menu.setCursorArrow=function(bool){
return this.left_menu.setCursorArrow(bool);}
top_menu.getSelectedScreen=function (){
return this.left_menu.getSelectedScreen();}
top_menu.jumpScreen=function (screen_key,finished,isFast){
this.left_menu.initMenu(screen_key);
this.left_menu.jumpScreen(screen_key,finished,false,isFast);}
top_menu.initMenu=function (screen_key){
this.left_menu.initMenu(screen_key);}
top_menu.selectScreen=function (finished){
var screen_key=this.getCurrentScreenKey();
var info=this.getScreenInfo(screen_key);
if(info.template=="inst")return;
if(finished)finished();}
top_menu.checkAddableScreen=function (){
if(getUserScreenNum()<HOME.SCREEN_USER_MAX_NUM){
return true;}else {
this.createConfirmpanel(Confirmpanel.prototype.OPTION_TYPE_OK,
LANG("LT_HOME_SETTING_1"),LANG("LT_OK"),null,
function(){HOME.HomeSoundPlay("cancel");});
return false;}
}
top_menu.addScreen=function (){
var me=this;
exec_lock(true);
var finished_func=function(){
exec_lock(false);
me.changeOperator(HOME.EDIT_SCREEN);};
return this.left_menu.addScreen(finished_func);}
top_menu.addDLScreen=function(){return this.left_menu.addDLScreen.apply(this.left_menu,arguments);}
top_menu.deleteScreen=function (){
var info={removable:false};
var screen_key=this.getCurrentScreenKey();
if(!isScreenKey(screen_key)){
this.menu.map(function(obj){obj.bg_highlight(false);});
this.setMenuType(MENU_SELECT);
return;}
info=this.getScreenInfo(screen_key);
var me=this;
if(info.removable==false){
this.createConfirmpanel(Confirmpanel.prototype.OPTION_TYPE_OK,
LANG("LT_HOME_SETTING_2"),LANG("LT_OK"),null,
function(){
me.setMenuType(MENU_SELECT);
me.menu.map(function(obj){obj.bg_highlight(false);});
HOME.HomeSoundPlay("cancel");});}else{
this.createConfirmpanel(Confirmpanel.prototype.OPTION_TYPE_YES_NO,
LANG("LT_CONTENT_DELETE"),LANG("LT_YES"),LANG("LT_NO"),
function(){
try{
HOME.HomeSoundPlay("enter");
exec_lock(true);
me.jumpScreen(screen_key,function(){
me._deleteScreen(screen_key,function(){
me.menu.map(function(obj){obj.bg_highlight(false);});
me.setMenuType(MENU_SELECT);
exec_lock(false);});});}catch(e){
console.log("[JS ERROR] "+e.fileName+":"+e.lineNumber+" , "+e.message)
}
},
function(){
me.menu.map(function(obj){obj.bg_highlight(false);});
me.setMenuType(MENU_SELECT);
HOME.HomeSoundPlay("cancel");});}
}
top_menu.moveScreen=function(finished,isFast){
exec_lock(true);
var me=this;
var finished_func=function(){
exec_lock(false);
me.menu.map(function(obj){obj.bg_highlight(false);});
me.onFocus(false);
me.cursor=null;
me.setMenuType(MENU_SELECT,"fast");
me.onFocus(true);
if(finished)finished();};
var current_key=this.getCurrentScreenKey();
this.jumpScreen(current_key,function(){
me.left_menu.moveScreen(finished_func);},false,isFast);}
top_menu.gotoSelect=function(bell){
this.setCursorArrow(false);
var type=this.getMenuType();
this.menu.map(function(obj){obj.bg_highlight(false);});
this.onFocus(false);
if(this.cursor){
if(bell)HOME.HomeSoundPlay(0);}else{
return true;}
this.cursor=null;
if(type==MENU_SELECT){
this.index_cursor=this.menu[0];}
this.onFocus(true);
this.setMenuType(MENU_SELECT);
return true;};
top_menu._menu_type=MENU_SELECT;
top_menu._deleteScreen=function(screen_key,finished){
var me=this;
if(!isDLScreen(screen_key)){
return this.left_menu.deleteScreen(screen_key,finished);}
var screen_install_id=getScreenInstallId(screen_key);
var finished_func=function (result){
if(result&&result.error=="0"){
me.left_menu.deleteScreen(screen_key,finished);}else{
if(isDisclaimerNeeded()){
apputil.launch_apl(DISCLAIMER_APPS);
if(finished)finished();
return;}
me.createConfirmpanel(Confirmpanel.prototype.OPTION_TYPE_OK,
LANG("LT_HOME_DL_HS_DELETE_ERROR"),LANG("LT_PM_RETURN"),null,
function(){
if(finished)finished();
HOME.HomeSoundPlay("cancel");});}
};
var uninstall_func=function(){
exec_lock(true);
HOME.HomeSoundPlay("enter");
startup_screen.uninstall(screen_install_id,finished_func);}
append_timer({},200,function(obj){
delete_timer(obj);
exec_lock(false);
me.createConfirmpanel(Confirmpanel.prototype.OPTION_TYPE_YES_NO,
LANG("LT_HOME_DL_HS_NOT_DELETE"),LANG("LT_OK"),LANG("LT_PM_RETURN"),
uninstall_func,
function(){
if(finished)finished();
HOME.HomeSoundPlay("cancel");});});
return;}
left_menu.init=function (getScreenOrder,getScreenInfo,
focus,getScreen,
createConfirmpanel,getVanishProductIDs,
removeScreen,getPowerOnScreen,addNewScreen,
changeOperator,
topmenu_addScreen,topmenu_moveScreen){
this.getScreenOrder=getScreenOrder;
this.getScreenInfo=getScreenInfo;
this.focus=focus;
this.getVanishProductIDs=getVanishProductIDs;
this.removeScreen=removeScreen;
this.getPowerOnScreen=getPowerOnScreen;
this.addNewScreen=addNewScreen;
this.topmenu_addScreen=topmenu_addScreen;
this.topmenu_moveScreen=topmenu_moveScreen;
this._menu_list=[];
this.components=[];
var me=this;
var leftmenu_anim_finished=function(){
me.menu_base.setShow(true);
me.setArrow(true);
me.setCursorArrow(true);};
var inherit=[getScreenOrder,getScreenInfo,
focus,getScreen,
createConfirmpanel,getVanishProductIDs,
removeScreen,getPowerOnScreen,addNewScreen,
leftmenu_anim_finished]
this.indicator.init.apply(this.indicator,arguments);
this.template_menu.init.apply(this.template_menu,arguments);
this.screen_base.init.apply(this.screen_base,inherit);
this.arrow_l=new gimage({src:IMG_PATH+"apps_arrow_l.png",translate:[-856+300,0,0],blend:true,
color:system.fdp_color.ICON_ONBASE,
width:20,height:87}),
this.arrow_r=new gimage({src:IMG_PATH+"apps_arrow_r.png",translate:[856-300,0,0],blend:true,
color:system.fdp_color.ICON_ONBASE,
width:20,height:88}),
this.cursor_arrow_l=new gimage({src:IMG_PATH+"apps_arrow_l.png",translate:[-50,-250,0],
blend:true,color:system.fdp_color.FCS,
width:20,height:87}),
this.cursor_arrow_r=new gimage({src:IMG_PATH+"apps_arrow_r.png",translate:[50,-250,0],
blend:true,color:system.fdp_color.FCS,
width:20,height:88}),
this.pickup_screen=new container({
visible_p:false,
components:[
this.pickup_screenname=new gtext({translate:[0,-10,0],align:CENTER,omitter:"...",
width:600,height:64,color:COL_TEXT_ONBASE}),
this.pickup_userIcon=new gimage({translate:[0,440,0,],width:58,height:58}),
],
});
this.menu=[];
for(var i=0;i<7;i++)
this.menu[i]=new namePlate(300,54);
this.menu_base=new container({});
this.menu_base.setFilter=function(func){
this._filter_func=func;};
this.menu_base.setShow=function(bool){
this.visible_p=bool;
if(!bool)return;
if(this._filter_func instanceof Function){
var len=me.menu.length;
var active_screen=me.screen_base._active_screen;
for(var i=0;i<me.screen_base._active_screen.length;i++){
var enabled=this._filter_func(active_screen[i]);
me.menu[~~(len/2)+(i-1)].setEnabled(enabled);}
}
};
this.menu_base.components=this.menu;
this.components.push(this.screen_base.adding_mark);
this.components.push(this.pickup_screen);
this.components.push(this.menu_base,this.template_menu,this.indicator);
this.components.push(this.arrow_l,this.arrow_r);
this.components.push(this.cursor_arrow_l,this.cursor_arrow_r);}
left_menu.in_hook=function (enable_screen,func,filter_func){
var screen_key=enable_screen[1].getScreenKey();
var order=this.getScreenOrder();
var id=order.indexOf(screen_key);
if(id==-1)id=0;
this.menu_base.setFilter(filter_func);
this._menu_type=null;this._menu_list=this.menu;
this.cursor=this._menu_list[3];
this.setSelectedScreen(null);
this.setIgnoreList(null);
this.initMenu(screen_key);
this.screen_base.adding_mark.open(false);
this.indicator.in_hook.apply(this.indicator,arguments);
this.screen_base.in_hook.apply(this.screen_base,arguments);
this.onFocus(true);
this.setArrow(false);
this.setCursorArrow(false);}
left_menu.out_hook=function (){
this.indicator.out_hook.apply(this.indicator,arguments);
this.template_menu.out_hook.apply(this.template_menu,arguments);
this.screen_base.out_hook.apply(this.screen_base,arguments);}
left_menu.onFocus=function (bool,last_type){
var type=this.getMenuType();
if(last_type!=undefined&&!bool)
type=last_type;
switch(type){
case MENU_MOVE:
case MENU_MOVE2:
var target=this.screen_base.adding_mark;
if(bool){
this.focus.setShow(true);
this.focus.moveTo(target.translate,[-1,target.height]);}
return;
case MENU_ADD2:
this.cursor.onFocus(bool);
return;}
this.screen_base.onFocus(bool);}
left_menu.enabled_voiceplay=true;
left_menu.enableVoicePlay=function (bool){
this.enabled_voiceplay=bool;}
left_menu.voicePlay=function (){
if(!this.enabled_voiceplay)return;
if(this.cursor&&this.cursor.voicePlay)
this.cursor.voicePlay();}
left_menu.getCurrentScreenKey=function (){
if(!this.cursor){
return null;}
if(this.cursor==this.template_menu){
return this.getLastScreenKey();}
return this.cursor.screenKey;}
left_menu.getLastScreenKey=function (){
return this.last_screen_key;}
left_menu.setSelectedScreen=function (screen){
this.selected_screen=null;
if(screen instanceof Screen)
this.selected_screen=screen;}
left_menu.activateSelectedScreen=function (bool){
var screen=this.getSelectedScreen();
if(screen instanceof Screen){
screen.activate(bool);
return true;}
return false;}
left_menu.getSelectedScreen=function (){
return this.selected_screen;}
left_menu.setIgnoreList=function (list){
this.ignore_list=list;}
left_menu.getIgnoreList=function (){
return this.ignore_list;}
left_menu.getMenuType=function (){
return this._menu_type;}
left_menu.setMenuType=function (type,option){
var me=this;
var ret=this.getSelectedScreen();
if(ret){
return_lock(true);
var order=this.getScreenOrder();
var index=order.indexOf(ret.getScreenKey());
var ret_screen_key=order[index-1];
if(!isScreenKey(ret_screen_key)){
ret_screen_key="first";}
var finished_func=function(){
me._setMenuType(type,option);
return_lock(false);};
var callback=function(){
append_timer({},600,function(obj){
delete_timer(obj);
me.moveScreen(finished_func);});};
this.jumpScreen(ret_screen_key,callback,false,true);}else{
this._setMenuType(type,option);}
}
left_menu.initMenu=function (screen_key){
for(var i=0;i<7;i++){
this.setMenu(this._menu_list[i],screen_key,i-3);}
var type=this.getMenuType();
this.indicator.jumpScreen(screen_key,type,this.getIgnoreList());
for(var i=0;i<7;i++){
this.setMenuPosition(this.menu[i],i-3);}
}
left_menu.setMenu=function (target,current_key,pos){
var order=this.getScreenOrder();
var ignore=this.getIgnoreList();
var tmp_order=[];
for(var i=0;i<order.length;i++){
if(!ignore||ignore.indexOf(order[i])==-1)
tmp_order.push(order[i]);}
var index=tmp_order.indexOf(current_key);
if(index+pos==-1){
target.screenKey="first";
target.free();}else if(index+pos<0||index+pos>=tmp_order.length){
target.screenKey=null;
target.free();}else{
var info=this.getScreenInfo(tmp_order[index+pos]);
var enabled=true;
if(info.template=="inst")enabled=false;
target.hide();
target.setSkin(info.screen_name,null,null,null);
if(isNumber(info.usrprof_id)&&info.usrprof_id>=0){
target.setIcon(info.usrprof_id);}else{
target.setIcon(-1);}
target.setEnabled(enabled);
target.screenKey=tmp_order[index+pos];}
this.setMenuPosition(target,pos);};
left_menu.setMenuPosition=function (target,pos){
var type=this.getMenuType();
switch(type){
case MENU_ADD:
case MENU_ADD2:
case MENU_MOVE2:
if(pos<=0){
target.translate=[-(345+530*(0-pos)),-412,0];}else if(pos>0){
target.translate=[+(345+530*(pos-1)),-412,0];}
target.visible_p=true;
target.rotation=[0,0,0,0];
target.setSkin(null,32,400,CENTER);
target.setIcon(null,0,340,58);
break;
case MENU_SELECT:
case MENU_ADD3:
case MENU_MOVE:
default:
target.visible_p=true;
switch(pos){
case -1:
target.translate=[-690,-310,0];
target.rotation=[0,0,0,0];
target.setSkin(null,36,500,LEFT);
target.setIcon(null,-120,560,80);
break;
case 0:
target.translate=[0,-310,0];
target.rotation=[0,0,0,0];
target.setSkin(null,42,800,CENTER);
target.setIcon(null,0,680,120);
break;
case 1:
target.translate=[+690,-310,0];
target.rotation=[0,0,0,0];
target.setSkin(null,36,500,RIGHT);
target.setIcon(null,+120,560,80);
break;
default:
target.visible_p=false;
break;}
break;}
};
left_menu.updateMenu=function (key){
var type=this.getMenuType();
switch(key){
case TXK_LEFT:
if(!this.menu[3-1]||this.menu[3-1].screenKey==null)
return false;
if(this.menu[3-1].screenKey=="first"&&
type==MENU_SELECT)
return false;
var tmp=this.menu.pop();
this.setMenu(tmp,this.cursor.screenKey,-3-1);
this.menu.unshift(tmp);
break;
case TXK_RIGHT:
if(!this.menu[3+1]||this.menu[3+1].screenKey==null)
return false;
var tmp=this.menu.shift();
this.setMenu(tmp,this.cursor.screenKey,+3+1);
this.menu.push(tmp);
break;}
this.cursor=this._menu_list[3];
this.indicator.jumpScreen(this.cursor.screenKey,type,this.getIgnoreList());
for(var i=0;i<7;i++){
this.setMenuPosition(this.menu[i],i-3);}
return true;}
left_menu._jumping=false;
left_menu.jumpScreen=function (dest_screen_key,finished_func,sync,isFast){
var me=this;
var msec=(this._jumping)?300:200;
if(isFast)msec=40;
if(sync){
this._jumpScreen.apply(this,[dest_screen_key,true]);
if(finished_func)finished_func();
return;}
this.screen_base.cancelTimer();
append_timer(this._jumpScreenTimer,msec,function(obj,cnt){
if(cnt!=1&&cnt<4)return;
var is_first_request=(cnt==1);
var ret=me._jumpScreen.apply(me,[dest_screen_key,is_first_request]);
var center_s=me.screen_base._active_screen[1];
var pure_s=me.screen_base.screen[2];
var tmp_order=[];
{
var order=me.getScreenOrder();
var ignore=me.getIgnoreList();
for(var i=0;i<order.length;i++){
if(!ignore||ignore.indexOf(order[i])==-1)
tmp_order.push(order[i]);}
}
var center_key=center_s.getScreenKey();
var is_dest_Screen=(center_key==dest_screen_key);
var is_first_screen=(dest_screen_key=="first"&&center_key==tmp_order[0]&&pure_s!=center_s);
var is_missing=(tmp_order.indexOf(dest_screen_key)==-1&&dest_screen_key!="first");
if((ret&&center_s&&is_dest_Screen)||
(ret&&center_s&&is_first_screen)||
(is_missing)
){
force_redraw();
delete_timer(obj);
if(finished_func){
finished_func();}
me._jumping=false;}});
this._jumping=true;}
left_menu.key_hook=function (up_down,key){
if(this.cursor&&this.cursor.key_hook)
if(this.cursor.key_hook(up_down,key))
return true;

if(up_down!=KEY_PRESS)
return false;
if(is_exec_lock)
return false;
var me=this;
switch(key){
case TXK_ENTER:
var type=this.getMenuType();
switch(type){
case MENU_ADD2:
HOME.HomeSoundPlay("enter");
this.topmenu_addScreen();
return true;
case MENU_MOVE2:
HOME.HomeSoundPlay("enter");
this.setCursorArrow(false);
this.topmenu_moveScreen();
return true;}
break;
case TXK_UP:
return false;
case TXK_LEFT:
case TXK_RIGHT:
this.setArrow(false);
this.setCursorArrow(false);
if(!this.updateMenu(key))
return true;
this.menu_base.setShow(false);
HOME.HomeSoundPlay(3);
if(this.getMenuType()==MENU_SELECT)
this.cursor.voicePlay();
this.jumpScreen(this.cursor.screenKey,null,!true);
return true;}
return false;}
left_menu.addScreen=function (finished){
var template_id=this.template_menu.getTemplateId();
if(template_id=="HSMARKET"){
var args="-T -s -R -l "+"vmarket:jump=null";
apputil.launch_apl(HSMARKET_APPS,args);
exec_lock(false);}else{
this._addTemplateScreen(template_id,finished);}
return true;}
left_menu.addDLScreen=function (install_id,finished){
var order=this.getScreenOrder();
var id=order.indexOf(install_id);
if(id==-1)
return;

var screen=screen_base._getScreen(install_id,[0,0,CAMERA_POS*4.4]);
this.screen_base._active_screen[1]=screen;
screen.activate(false);
screen.setTranslate(538*1.5,500,CAMERA_POS*2);
screen.setAngle(0);
screen.createGadgets();
screen.setShow(true);
this.screen_base.screen.unshift(screen);
this.setMenuType(MENU_ADD3,"reload");
append_timer(this,800,function(obj){
delete_timer(obj);
if(finished)finished();});}
left_menu.deleteScreen=function (screen_key,finished){
var info=this.getScreenInfo(screen_key);
var center_s=this.screen_base._active_screen[1];
center_s.removeAll();
var vanish_product_id=this.getVanishProductIDs(info.product_id_list,screen_key);
if(vanish_product_id&&vanish_product_id.length!=0){
center_s.vanish(vanish_product_id);}
var order=this.getScreenOrder();
var current_index=order.indexOf(screen_key);
var temp_name=center_s.getTemplateName();
if(isDLScreen(screen_key)){
var info=this.getScreenInfo(screen_key);
if(info&&isString(info.org_id))
temp_name=info.org_id;}
LogReport.report(LogReport.OPERATE_HS,"hs.screen",
{action:"delete",pos:current_index.toString(),template:temp_name,});
this.removeScreen(screen_key);
var poweron_screen=this.getPowerOnScreen();
if(screen_key==poweron_screen){
var screen_order=this.getScreenOrder();
var screen_order=[];
HOME.checkPowerOnScreen(screen_order);}
var order=this.getScreenOrder();
var next=current_index;
if(!isScreenKey(order[next])){
next=order.length-1;}
var remove_target=this.screen_base._active_screen[1];
if(this.screen_base._active_screen[2] instanceof Screen){
this.screen_base._active_screen[1]=this.screen_base._active_screen[2];}else{
this.screen_base._active_screen[1]=this.screen_base._active_screen[0];}
var next_key=this.screen_base._active_screen[1].getScreenKey();
var id=order.indexOf(next_key);
if(id==-1)id=0;
var me=this;
var finished_func=function(){
me.initMenu(next_key);
remove_target.freeResource(true);
remove_target.setShow(false);
me.setMenuType(MENU_SELECT,"reload");
me.jumpScreen(order[next],null,null,true);
if(finished)finished();}
remove_target.activate(false);
remove_target.moveTo(MYPOSITION["DELETE"]["dest"][2].pos,null,
MYPOSITION["DELETE"]["dest"][2].angle,40,finished_func);}
left_menu.moveScreen=function(finished){
var selected_screen=this.getSelectedScreen();
var selected_screen_key=null;
if(selected_screen instanceof Screen)
selected_screen_key=selected_screen.getScreenKey();
var order=this.getScreenOrder();
var current_key=this.getCurrentScreenKey();
var selected_index=order.indexOf(selected_screen_key);
if(selected_index==-1)selected_index=0;
var prev_key=order[selected_index-1];

this.setSelectedScreen(null);
if(selected_screen_key!=current_key){
if(selected_index==-1){
if(finished)finished();
return;}
order.splice(selected_index,1);
var current_index=order.indexOf(current_key);
if(current_index==-1&&current_key!="first"){
if(finished)finished();
return;}
order.splice(current_index+1,0,selected_screen_key);
HOME.storeScreenOrder(order);
var order=this.getScreenOrder();
var temp_name=selected_screen.getTemplateName();
if(isDLScreen(selected_screen_key)){
var info=this.getScreenInfo(selected_screen_key);
if(info&&isString(info.org_id))
temp_name=info.org_id;}
LogReport.report(LogReport.OPERATE_HS,"hs.screen",
{action:"move",pos:(current_index+1).toString(),
template:temp_name,from:selected_index.toString()});}
var screen=selected_screen;
selected_screen._anim_type=null;
this.pickup_screen.components.splice(0);
this.screen_base.screen.unshift(screen);
this.screen_base._active_screen[1]=screen;this.screen_base.components.push(screen)
this.setIgnoreList(null);
var id=order.indexOf(selected_screen_key);
if(id==-1)id=0;
this.initMenu(selected_screen_key);
if(finished)finished();}
left_menu.setArrow=function (bool){
var type=this.getMenuType();
var target=null;
var use_arrow=false;
if(type==MENU_SELECT||type==MENU_DEL)
use_arrow=bool;
this.arrow_l.visible_p=use_arrow;
this.arrow_r.visible_p=use_arrow;
target=this.menu[3-1];
if(!target||target.screenKey==null||target.screenKey=="first")
this.arrow_l.visible_p=false;
target=this.menu[3+1];
if(!target||target.screenKey==null)
this.arrow_r.visible_p=false;}
left_menu.setCursorArrow=function (bool){
var type=this.getMenuType();
var target=null;
var use_arrow=false;
if(type==MENU_MOVE2&&!is_return_lock){
use_arrow=bool;}
this.cursor_arrow_l.visible_p=use_arrow;
this.cursor_arrow_r.visible_p=use_arrow;
target=this.menu[3-1];
if(!target||target.screenKey==null)
this.cursor_arrow_l.visible_p=false;
target=this.menu[3+1];
if(!target||target.screenKey==null)
this.cursor_arrow_r.visible_p=false;}
left_menu._menu_type=null;
left_menu._menu_list=null;
left_menu._anim_type=null;
left_menu._jumpScreenTimer={};
left_menu._setMenuType=function (type,option){
var update=false;
var last_type=this.getMenuType();
if(last_type!=type||option=="reload"){
update=true;}
var screen_key=this.getCurrentScreenKey();
if(last_type==MENU_ADD2){
screen_key=this.getLastScreenKey();}
var me=this;
if(update){
this._menu_type=type;
this.indicator.setShow(true);
switch(type){
case MENU_ADD:
this.focus.setShow(false);
this.onFocus(false,last_type);
this.cursor=null;
this.setArrow(false);
this.template_menu.prepare();
this._anim_type="ADD";
if(last_type!=type){
append_timer(this.pickup_screen,500,function(obj){
delete_timer(obj);
me.setMenuType(MENU_ADD2);});}
break;
case MENU_ADD2:
this.setArrow(false);
exec_lock(false);
this.template_menu.setShow(true);
if(last_type==MENU_ADD&&this.cursor)
this.last_screen_key=this.cursor.screenKey;
{
this.onFocus(false,last_type);
this.cursor=this.template_menu;
this.onFocus(true);
this.setIgnoreList(null);}
return;
case MENU_ADD3:this._menu_list=this.menu;
this._anim_type="3MIRROR";
this.template_menu.discard();
this.onFocus(false,last_type);
this.pickup_screen.components.splice(0);
screen_key=this.screen_base._active_screen[1].getScreenKey();
break;
case MENU_MOVE:
this._menu_list=this.menu;
this._anim_type="3MIRROR";
this.template_menu.discard();
this.pickup_screen.components.splice(0);
break;
case MENU_MOVE2:
this.setArrow(false);
this._anim_type="MOVE2";
this.template_menu.discard();
this._pickupSelectedScreen(type,last_type);
return;
case MENU_SELECT:
default:
this.setCursorArrow(false);
this.template_menu.discard(false);
this._menu_list=this.menu;
this._anim_type="3MIRROR";
this.pickup_screen.components.splice(0);
break;}
if(type!=MENU_MOVE){
this.setIgnoreList(null);}
this.initMenu(screen_key);}
var order=this.getScreenOrder();
var id=order.indexOf(screen_key);
if(id==-1)id=0;
if(this.cursor)this.cursor.onFocus(false);
this.cursor=this._menu_list[3];
if(this.cursor&&this.cursor.focus)this.cursor.focus.setShow(true);
if(this.cursor)this.cursor.onFocus(true);
if(update){
this.jumpScreen(screen_key,null,true);}
}
left_menu._jumpScreen=function (dest_screen_key,is_first_request){
var order=this.getScreenOrder();
var ignore=this.getIgnoreList();
var tmp_order=[];
for(var i=0;i<order.length;i++){
if(!ignore||ignore.indexOf(order[i])==-1)
tmp_order.push(order[i]);}
var current_key=this.getCurrentScreenKey();
var index=tmp_order.indexOf(current_key);
if(index==-1&&current_key!="first"){
index=0;}
var tmp_index=tmp_order.indexOf(dest_screen_key);
if(tmp_index==-1&&dest_screen_key!="first")tmp_index=0;
var dest_index=tmp_index;
var new_dest_screen_key=dest_screen_key;
if(index>tmp_index){
dest_index=index-1;
if(!this.updateMenu(TXK_LEFT))
return false;}else if(index<tmp_index){
dest_index=index+1;
if(!this.updateMenu(TXK_RIGHT))
return false;}else{
dest_index=tmp_index;
if(!is_first_request){
return true;}
}
if(dest_index<0){
new_dest_screen_key="first";}else{
new_dest_screen_key=tmp_order[dest_index];}
var ret=this.screen_base.jumpScreen(new_dest_screen_key,this._anim_type,
is_first_request,this.getIgnoreList());
if(ret==false)
return true;
return false;}
left_menu._addTemplateScreen=function (template_id,finished){
var order=this.getScreenOrder();
var current_key=this.getLastScreenKey();
var index=0;
if(current_key=="first"){
index=0;}else{
index=order.indexOf(current_key);
if(index==-1)index=order.length-1;
index+=1;}
var screen=this.addNewScreen(template_id,index);
this.screen_base._active_screen[1]=screen;
var screen_key=screen.getScreenKey();
var current_index=order.indexOf(screen_key);
var temp_name=screen.getTemplateName();
if(isDLScreen(screen_key)){
var info=this.getScreenInfo(screen_key);
if(info&&isString(info.org_id))
temp_name=info.org_id;}
LogReport.report(LogReport.OPERATE_HS,"hs.screen",
{action:"create",pos:current_index.toString(),template:temp_name,});
screen.activate(false);
screen.setTranslate(0,200*5.4,CAMERA_POS*4.4);
screen.setAngle(0);
screen.createGadgets();
screen.setShow(true);
this.focus.setShow(false);
this.screen_base.screen.unshift(screen);
this.setMenuType(MENU_ADD3,"reload");
append_timer(this,800,function(obj){
delete_timer(obj);
if(finished)finished();});

return true;}
left_menu._pickupSelectedScreen=function(type,last_type){
if(last_type==MENU_MOVE&&this.cursor){
this.selected_screen_key=this.cursor.screenKey;
this.setIgnoreList([this.selected_screen_key]);}
if(last_type!=type){
var selectScreen=this.screen_base._active_screen[1];selectScreen.createGadgets();
this.setSelectedScreen(selectScreen);
selectScreen.activate(false);
var me=this;
this.pickup_screen.components=[selectScreen];
setf_text(this.pickup_screenname,selectScreen.getScreenName());
this.pickup_userIcon.src="";
try{
var info=me.getScreenInfo(selectScreen.getScreenKey());
if(HOME.isMultiProfile()&&isNumber(info.usrprof_id)){
var uprofile=getProfile(info.usrprof_id);
this.pickup_userIcon.src=uprofile.mhc.icon;}
}catch(e){}
this.pickup_screen.visible_p=true;
selectScreen.moveTo([0,230*2.8-60,CAMERA_POS*1.8],null,0,40,function(){
selectScreen.activate(true);
me.pickup_screen.components=[selectScreen,me.pickup_screenname,me.pickup_userIcon];});
var id=this.screen_base.screen.indexOf(selectScreen);
if(id!=-1)this.screen_base.screen.splice(id,1);
var screen_key=null;
if(this.screen_base._active_screen[0] instanceof Screen){
this.screen_base._active_screen[1]=this.screen_base._active_screen[0];
screen_key=this.screen_base._active_screen[1].getScreenKey();}else{
this.screen_base._active_screen[1]=this.screen_base._active_screen[2];
screen_key="first";}
this.jumpScreen(screen_key,null,!true,true);
this.initMenu(screen_key);
var order=this.getScreenOrder();
var id=order.indexOf(selectScreen.getScreenKey());
if(id==-1)id=0;
if(this.cursor)this.cursor.onFocus(false);
if(this.cursor&&this.cursor.focus)this.cursor.focus.setShow(true);
if(this.cursor)this.cursor.onFocus(true);}
}
indicator.init=function(getScreenOrder){
this.getScreenOrder=getScreenOrder;
if(this.components.length>0)return;
this.translate=[0,-465,0];
this.bg=new gbox({width:1660,height:2,color:COL_BASE_SUB});
this.bar=new gbox({width:0,height:8,color:COL_TEXT_ONBASE});
this.arrow_l=new gimage({translate:[-850,0,0],width:16,height:18,
src:IMG_PATH+"scroll_arrow.png",color:COL_BASE_SUB});
this.arrow_r=new gimage({translate:[850,0,0],width:16,height:18,
flip:FLIP_HORIZONTAL,
src:IMG_PATH+"scroll_arrow.png",color:COL_BASE_SUB});
this.components.push(this.arrow_l,this.arrow_r,this.bg,this.bar);}
indicator.in_hook=function(enable_screen){
var screen_key=enable_screen[1].getScreenKey();
this.jumpScreen(screen_key);}
indicator.out_hook=function(){}
indicator.onFocus=NULL_FUNCTION;
indicator.setShow=function (bool){
this.visible_p=bool;}
indicator.jumpScreen=function (dest_screen_key,type,ignore){
var order=this.getScreenOrder();
var tmp_order=[];
for(var i=0;i<order.length;i++){
if(!ignore||ignore.indexOf(order[i])==-1)
tmp_order.push(order[i]);}
if(type==MENU_MOVE2){
tmp_order.unshift("first");}
var len=tmp_order.length;
var width=~~(this.bg.width/len);
if(width<10)width=10;
this.bar.width=width;
var index=tmp_order.indexOf(dest_screen_key);
if(index==-1){
this.bar.width=0;
return;}

this.bar.translate[0]=(this.bg.width/ len) * (index) - (this.bg.width - width)/2;
force_redraw();}
template_menu.init=function(getScreenOrder,getScreenInfo,focus){
this.focus=focus;
this._menu=[];}
template_menu.in_hook=function(){}
template_menu.out_hook=function(){
this._menu=[];
this._freeMenu();}
template_menu.onFocus=function(bool){
if(!this.cursor)
this.cursor=this._menu[0];
if(bool)this.focus.setShow(true);
this.cursor.onFocus(bool);}
template_menu.key_hook=function(up_down,key){
if(up_down!=KEY_PRESS)
return false;
switch(key){
case TXK_LEFT:
case TXK_RIGHT:
var id=this._menu.indexOf(this.cursor);
if(id==-1)id=0;
var next=id+((key==TXK_RIGHT)?1:-1);
if(!this._menu[next]||!this._menu[next].id)
return true;
if(this.cursor)this.cursor.onFocus(false);
this.cursor=this._menu[next];
this.cursor.onFocus(true);
HOME.HomeSoundPlay(0);
return true;}
return false;}
template_menu.prepare=function(){
this._freeResource(true);
this.visible_p=false;};
template_menu.setShow=function(bool){
this._freeResource(bool);
this.visible_p=bool;};
template_menu.discard=function(){
this.setShow(false);};
template_menu.getTemplateId=function(){
if(!this.cursor)
this.cursor=this._menu[0];
return this.cursor.id;}
template_menu.getCurrentPosition=function(){
if(!this.cursor)
this.cursor=this._menu[0];
return this.cursor.translate;}
template_menu._templatelist=null;
template_menu._menu=null;
template_menu._freeResource=function(bool){
if(!this._templatelist){
this._templatelist=[
{id:"life",image:IMG_PATH+"temp_life.png"},
{id:"info",image:IMG_PATH+"temp_info.png"},
{id:"play0",image:IMG_PATH+"temp_play0.png"},
];
if((HOME.getInitStyle()).zapping){
this._templatelist.unshift({id:"zapping",image:IMG_PATH+"temp_zapping.png"});}
if(system.mdl_cfg.with_vc_market==true){
var lang=system.locale.language.substr(0,5);
switch(lang){
case "fr-CA":
this._templatelist.unshift({id:"HSMARKET",image:IMG_PATH+"mhs_market_fr-CA.png"});
break;
case "ja-JP":
this._templatelist.unshift({id:"HSMARKET",image:IMG_PATH+"mhs_market_ja-JP.png"});
break;
default:
this._templatelist.unshift({id:"HSMARKET",image:IMG_PATH+"mhs_market.png"});
break;}
}
}
if(bool){
if(!this._active){
this._initMenu();}
}else{
this._freeMenu();}
}
template_menu._initMenu=function(){
var len=this._templatelist.length;
for(var i=0;i<len;i++){
this._menu[i]=new imagebtn(354,200,this.focus);
this._menu[i].translate=[(1-len)*372/2+i*372,190,0];}
this.components=this._menu;
for(var i=0;i<this._templatelist.length;i++){
var image=this._templatelist[i].image;
this._menu[i].setSkinPath(image);
this._menu[i].id=this._templatelist[i].id;}
this.cursor=this._menu[0];
this._active=true;};
template_menu._freeMenu=function(){
if(this.components.length==0)return;
for(var i=0;i<this._menu.length;i++)
this._menu[i].free();
this._active=false;};
screen_base.init=function (getScreenOrder,getScreenInfo,focus,getScreen,
createConfirmpanel,getVanishProductIDs,
removeScreen,getPowerOnScreen,addNewScreen,
leftmenu_anim_finished){
this.getScreenOrder=getScreenOrder;
this.getScreen=getScreen;
this.getScreenInfo=getScreenInfo;
this.focus=focus;
this.leftmenu_anim_finished=leftmenu_anim_finished;
this.screen=[{},{},{},{},{}];}
screen_base.in_hook=function (enable_screen,func){
if(!enable_screen)return;
this._active=false;
this.screen_order=this.getScreenOrder();
var zbuf=[0,4,1,3,2];
for(var i=0;i<5;i++){
if(enable_screen[zbuf[i]-1]){
this.screen[zbuf[i]]=enable_screen[zbuf[i]-1];
this.components.push(this.screen[zbuf[i]]);}
}
for(var i=0;i<3;i++){
this._active_screen[i]=this.screen[i+1];}
var me=this;
var left_s=this.screen[1];
var center_s=this.screen[2];
var right_s=this.screen[3];
VoiceCancelReservation();
if(HOME.operator===HOME.switchscreen_op){
VoiceReserve(VOICE("LT_HOME_SCREEN_SELECTION"));
VoicePlay(center_s.getScreenName());}
var finished_func=function(){
center_s.activate(true);
me.onFocus(true);
if(func)func();};
var initial_style="MYSCREEN";
if(HOME.last_operator===HOME.switchscreen_op||
HOME.last_operator===HOME.setowner_op)
initial_style="3MIRROR";

this.cursor=center_s;
this.visible_p=true;
if(left_s instanceof Screen){
left_s.setTranslate.apply(left_s,MYPOSITION[initial_style]["dest"][1].pos);
left_s.setAngle(MYPOSITION[initial_style]["dest"][1].angle);
left_s.activate(false);
left_s.setEdgeMask(true);
left_s.setShow(true);
left_s.moveTo(MYPOSITION["3MIRROR"]["dest"][1].pos,
null,MYPOSITION["3MIRROR"]["dest"][1].angle,50,function(){
append_timer(left_s,500,function(obj){
delete_timer(obj);
obj.createGadgets();});});}
center_s.setTranslate.apply(center_s,MYPOSITION[initial_style]["dest"][2].pos);
center_s.setAngle(MYPOSITION[initial_style]["dest"][2].angle);
center_s.setShow(true);
center_s.setFullscreen(false);
center_s.activate(false);
center_s.moveTo(MYPOSITION["3MIRROR"]["dest"][2].pos,
null,MYPOSITION["3MIRROR"]["dest"][2].angle,40,finished_func);
if(right_s instanceof Screen){
right_s.setTranslate.apply(right_s,MYPOSITION[initial_style]["dest"][3].pos);
right_s.setAngle(MYPOSITION[initial_style]["dest"][3].angle);
right_s.activate(false);
right_s.setEdgeMask(true);
right_s.setShow(true);
right_s.moveTo(MYPOSITION["3MIRROR"]["dest"][3].pos,
null,MYPOSITION["3MIRROR"]["dest"][3].angle,40,function(){
append_timer(right_s,500,function(obj){
delete_timer(obj);
obj.createGadgets();});});}
}
screen_base.out_hook=function (){
this.components.splice(0);}
screen_base.onFocus=function (bool){
this._active=bool;
if(!bool)return;
this.focus.setShow(true);
this.focus.moveTo(FOCUS_POSITION.pos,FOCUS_POSITION.size);}
screen_base.jumpScreen=function(dest_screen_key,type,is_first_request,ignore){
var order=this.getScreenOrder();
var currentKey=this._active_screen[1].getScreenKey();
var dest=order.indexOf(dest_screen_key);
var now=order.indexOf(currentKey);
if(dest_screen_key!="first"&&(dest==-1||now==-1))
return false;
this._update(dest_screen_key,type,is_first_request,ignore);
return true;}
screen_base._selfUpdate={};
screen_base.cancelTimer=function(){
delete_timer(this._selfUpdate);
for(var i=0;i<this.screen.length;i++)
delete_timer(this.screen[i]);}
screen_base._update=function(dest_screen_key,type,is_first_request,ignore){
if(is_first_request===undefined)
is_first_request=true;
if(ignore&&ignore.indexOf(dest_screen_key)!=-1){
return true;}
var order=this.getScreenOrder();
var tmp_order=[];
for(var i=0;i<order.length;i++){
if(!ignore||ignore.indexOf(order[i])==-1)
tmp_order.push(order[i]);}
var current_key=this._active_screen[1].getScreenKey();
var index=tmp_order.indexOf(current_key);
if(index==-1)index=0;
var screen_len=MYPOSITION[type]["dest"].length;
var screen_box=[];
var direction=0;
var tmp_index=tmp_order.indexOf(dest_screen_key);
if(tmp_index==-1)tmp_index=0;
var dest_index=tmp_index;
if(dest_screen_key=="first"){
tmp_index=-1;
dest_index=tmp_index;
direction=0;}else if(index>tmp_index){
dest_index=index-1;
direction=-1;}else if(index<tmp_index){
dest_index=index+1;
direction=+1;}else{
dest_index=tmp_index;
direction=0;
if(!is_first_request)
return;}
var need_update=false;
delete_timer(this);
for(var i=0;i<screen_len;i++){
if(this.screen[i] instanceof Screen){
var key=this.screen[i].getScreenKey();
var tmp_screen_key=tmp_order[dest_index+i-2];
if(!isScreenKey(tmp_screen_key)||tmp_screen_key!=key){
need_update=true;}
}
}
if(!need_update&&!is_first_request){
if(dest_screen_key=="first"&&(type=="ADD"||type=="MOVE2")){
append_timer(this,40,function(obj,cnt){
if(cnt<10)return;
delete_timer(obj)
obj.adding_mark.open((type=="ADD"));
var next_type=type+"_OPEN";
obj._update(dest_screen_key,next_type,true,ignore);
if(obj.leftmenu_anim_finished)
obj.leftmenu_anim_finished();});
return true;}
var anim_type=this.screen[2]._anim_type;
if(current_key==dest_screen_key&&
current_key!=tmp_order[0]&&
(type=="ADD"||type=="MOVE2")&&
(anim_type=="ADD_OPEN"||anim_type=="MOVE2_OPEN")){
exec_lock(false);
return true;}
if(!is_first_request){
console.log("no need update.");
exec_lock(false);
return true;}
}
for(var i=0;i<this.screen.length;i++){
if(this.screen[i] instanceof Screen){
var key=this.screen[i].getScreenKey();
screen_box[key]=this.screen[i]
}
};

this.screen.splice(0);
for(var i=0;i<screen_len;i++){
var key=tmp_order[dest_index+i-2];
if((direction<=0&&i==0)||(direction>=0&&i==screen_len-1)){
this.screen[i]={};}else if(!isScreenKey(key)){
this.screen[i]={};}else{
if(!(screen_box[key] instanceof Screen)){
var pos=i+(dest_index-index);
if(pos<0)pos=0;
if(screen_len<=pos)pos=screen_len-1;
this.screen[i]=this._getScreen(key,MYPOSITION[type]["dest"][pos]);}else{
this.screen[i]=screen_box[key];
delete screen_box[key];}
}
}
for(var key in screen_box){
var screen=screen_box[key];
if(screen instanceof Screen){
delete_timer(screen);
screen.setShow(false);
screen.freeResource(true);
screen.destroyGadgets();
screen.destroy();}
}
screen_box.splice(0);
var offset=0;
if(dest_screen_key=="first")offset=1;
for(var i=0;i<3;i++){
this._active_screen[i]=this.screen[i+1+offset];}
if(this._active){
this.focus.setShow((type!="ADD"));
this.focus.setTranslate.apply(this.focus,FOCUS_POSITION.pos);
this.focus.setSize.apply(this.focus,FOCUS_POSITION.size);
this.focus.moveTo(FOCUS_POSITION.pos,FOCUS_POSITION.size);}
this.components.splice(0);
var zbuf=[0,4,1,3,2,5];
for(var i=0;i<screen_len;i++){
var screen=this.screen[zbuf[i]];
if(screen instanceof Screen)
this.components.push(screen);}
var alpha=MYPOSITION[type]["alpha"];
var max_count=MYPOSITION[type]["speed"];
var me=this;
this.adding_mark.open(type=="ADD_OPEN");
for(var i=0;i<screen_len;i++){
if(!(this.screen[i] instanceof Screen))
continue;
this.screen[i].setEdgeMask(true);
if(i==2){
for(var j=0;j<3;j++){
if(this.screen[i].translate[j]!=MYPOSITION[type]["dest"][i].pos[j]){
this.screen[i].activate(false);
break;}
}
}else{
this.screen[i].activate(false);}
var make_finished_func=function(id){
var closure=me.screen[id];
var closure_screen=me.screen;
return function(){
if(!(closure instanceof Screen))
return;
if(type=="ADD"||type=="MOVE2"){
if(id==2)me._update(dest_screen_key,type+"_OPEN",true,ignore);
return;}
if(id==2||(type&&type.match("^MOVE2")&&id==3)){
exec_lock(false);
if(me.leftmenu_anim_finished)
me.leftmenu_anim_finished();}
if(id==2&&!(type&&type.match("^MOVE2"))){
append_timer(closure,200,function(obj){
delete_timer(obj);
force_redraw();
closure.setScreenNameShow(true);
closure.setEdgeMask(false);
closure.activate(true);
closure.createGadgets();});}else if(id==2||id==3||(id==1&&screen_len!=6)){
append_timer(closure,500,function(obj){
delete_timer(obj);
force_redraw();
closure.setScreenNameShow(true);
closure.createGadgets();})
}else if(id==1||(id==4&&screen_len==6)){
closure.destroyGadgets();
closure.setScreenNameShow(false);}else{
closure.setShow(false);
closure.freeResource(true);
closure.destroyGadgets();
closure.destroy();
var index=closure_screen.indexOf(closure);
if(index!=-1)closure_screen[index]={};}
}};
this.screen[i]._anim_type=type;
this.screen[i].moveTo2(MYPOSITION[type]["dest"][i].pos,
MYPOSITION[type]["dest"][i].angle,
alpha,max_count,make_finished_func(i));}
append_timer(this._selfUpdate,100,function(obj){
delete_timer(obj);
me._update(dest_screen_key,type,false,ignore);});}
screen_base._getScreen=function(screen_key,posdata){
var info=this.getScreenInfo(screen_key);
var tmp=HOME.getNewScreen(info,screen_key,false);if(tmp instanceof Screen){
tmp.setTranslate.apply(tmp,posdata.pos);
tmp.setAngle(posdata.angle);
tmp.setScreenName(info.screen_name);
tmp.setShow(true);}
return tmp;}
screen_base.adding_mark=new gbox({
translate:[0,-250,0],
width:0,height:280,color:COL_POINT});
screen_base.adding_mark.open=function(bool){
if(bool){
append_timer(this,40,function(obj,cnt){
if(cnt>=3)
delete_timer(obj);
var w=Math.floor(cnt*5/3);
if(obj.width<w)
obj.width=w*8;
force_redraw();});}else{
delete_timer(this);
this.width=0;
force_redraw();}
}
function btn(width,height,is_oneline,focus){
this.width=width;
this.height=height;
this.focus=focus;
this.components=[
this.bg=new gbox({width:this.width+4,height:this.height,
visible_p:false,color:COL_POINT_ONBASE}),
];
if(is_oneline){
this.label=new gtext({width:this.width-32,align:CENTER,font_size:30,height:48,
omitter:"...",
redraw:false,
color:COL_TEXT_ONBASE});}else{
this.label=new gtextbox({width:this.width-32,align:CENTER,font_size:30,
height:this.height,valign:MIDDLE,
redraw:false,
color:COL_TEXT_ONBASE});}
if(!this.label.margin)this.label.margin=[];
this.components.push(this.label);
this.base_obj=[this.bg,this.label];}
btn.prototype=new container({});
btn.prototype.voicePlay=function(){
if(HOME.operator===HOME.switchscreen_op)
VoicePlay(this.label.text);}
btn.prototype.onFocus=function(bool){
this.components=this.base_obj.slice();
if(this.icon&&bool&&this._enabled){
this.components.push(this.icon);}
if(!bool||!this.focus)return;
var size=this.focus.getSize();
if(size[0]>=1920&&size[1]>=1080){
var me=this;
append_timer(this.focus,500,function(obj){
delete_timer(obj);
obj.moveTo(me.translate,[me.width,me.height],null,20,null);});}else{
this.focus.moveTo(this.translate,[this.width,this.height],null,20,null);}
};
btn.prototype.bg_highlight=function(bool){
this.bg.visible_p=bool;};
btn.prototype.setSkin=function(text,font_size,width,align){
var update=false;
if(isString(text)){
if(text!=this.label.text){
this.label.text=text;
update=true;}
}
if(isNumber(font_size)){
if(this.label.font_size!=font_size){
this.label.font_size=font_size;
update=true;}
}
if(isNumber(width)){
if(this.label.width!=width){
this.width=width;
this.bg.width=width+4;
this.label.width=width-32;
update=true;}
}
if(align!=undefined){
if(this.label.align!=align){
this.label.align=align;
update=true;}
}
if(update==true){
setf_text(this.label,this.label.text);
if(this.label instanceof gtextbox){
change_font_size_b(this.label);}
}
}
btn.prototype.setEnabled=function(bool){
this.visible_p=true;
this._enabled=bool;
this.label.color=(bool)?COL_TEXT_ONBASE:COL_WIDGET_SUB;}
btn.prototype.free=function(){
setf_text(this.label,"");
this.icon=null;
this.visible_p=false;}
function namePlate(width,height){
this.width=width;
this.height=height;
this.bg=new gbox({width:this.width+4,height:this.height,
visible_p:false,color:COL_POINT_ONBASE}),
this.label=new gtext({width:this.width-32,align:CENTER,font_size:30,height:48,
omitter:"...",
redraw:false,
color:COL_TEXT_ONBASE});
this.userIcon=new gimage({width:120,height:120});
this.components=[this.bg,this.label,this.userIcon];}
namePlate.prototype=new container({});
namePlate.prototype.voicePlay=function(){
if(HOME.operator===HOME.switchscreen_op)
VoicePlay(this.label.text);}
namePlate.prototype.onFocus=function(){}
namePlate.prototype.setSkin=function(text,font_size,width,align){
var update=false;
if(isString(text)){
if(text!=this.label.text){
this.label.text=text;
update=true;}
}
if(isNumber(font_size)){
if(this.label.font_size!=font_size){
this.label.font_size=font_size;
update=true;}
}
if(isNumber(width)){
if(this.label.width!=width){
this.width=width;
this.bg.width=width+4;
this.label.width=width-32;
update=true;}
}
if(align!=undefined){
if(this.label.align!=align){
this.label.align=align;
update=true;}
}
if(update==true){
setf_text(this.label,this.label.text);
if(this.label instanceof gtextbox){
change_font_size_b(this.label);}
}
}
namePlate.prototype.setIcon=function(usrprof_id,x,y,scale){
if(isNumber(x))
this.userIcon.translate[0]=x;
if(isNumber(y))
this.userIcon.translate[1]=y;
if(isNumber(scale))
this.userIcon.height=scale;
if(HOME.isMultiProfile()){
if(usrprof_id!=null){
var uprofile=getProfile(usrprof_id);
if(uprofile){
var bin=uprofile.mhc.icon||"";
var hash=null;
if(bin instanceof Binary){
hash=sysutil.hex.encode(sysutil.hash.generate(sysutil.cipher.DIGEST_SHA1,bin));}else{
hash=bin;}
if(this.userIcon.hash!=hash){
this.userIcon.src=bin;
this.userIcon.hash=hash;}
}else{
this.userIcon.src="";
this.userIcon.hash="";}
}
}
}
namePlate.prototype.setEnabled=function(bool){
this.visible_p=true;
this._enabled=bool;
this.label.color=(bool)?COL_TEXT_ONBASE:COL_WIDGET_SUB;}
namePlate.prototype.free=function(){
setf_text(this.label,"");
this.userIcon.src="";
this.userIcon.hash="";
this.visible_p=false;}
namePlate.prototype.hide=function(){
this.visible_p=false;}
function imagebtn(width,height,focus){
this.width=width;
this.height=height;
this.focus=focus;
this.components=[
this.icon=new gimage({width:this.width,height:this.height,blend:false}),
];}
imagebtn.prototype=new container({});
imagebtn.prototype.onFocus=function(bool){
if(!bool||!this.focus)return;
this.focus.moveTo(this.translate,[this.width+4,this.height+4],null,60,null);};
imagebtn.prototype.setSkinPath=function(icon){
if(isString(icon)&&icon!=""){
if(icon!=this.icon.src){
this.icon.src=icon;}
}else{
this.icon.src="";}
}
imagebtn.prototype.setEnabled=function(bool){
this.visible_p=true;}
imagebtn.prototype.free=function(){
this.icon.src="";}

