
function Confirmpanel(type,action_func,focus_moveto){
this.superClass=container;
this.superClass({
components:[
this.frame=new actor({
base_col:[COL_POP_BORDER,COL_POP_BORDER],
base_col_width:2,
bg_image:[
this.bg_c=new gbox({color:COL_POP_A}),
]}),
this.message=new gtextbox({visible_p:false,align:LC_TEXT_ALIGN,color:COL_TEXT_ONBASE}),
this.title=new gtext({font_size:36,font_name:"F015T-bold",
visible_p:false,align:LC_TEXT_ALIGN,}),
this.buttons=new container({
visible_p:true,
translate:[0,-this.height/2+100,0],
}),
]
});
this.visible_p=false;
this.focus_moveto=focus_moveto;
this.cursor=0;this._point=null;
if(type==this.OPTION_TYPE_OK){
this.btn_num=1;
this.btn_list=[new this.Button(0)];
this.setButtonLabel(LANG("LT_OK"));
this.buttonPos=[{"x":0,"y":-this.height/2+100,"w":230,"h":48,}];}else if(type==this.OPTION_TYPE_YES_NO){
this.btn_num=2;
this.btn_list=[new this.Button(-170),
new this.Button(170)
];
this.buttonPos=[{"x":-170,"y":-this.height/2+100,"w":230,"h":48,},
{"x":170,"y":-this.height/2+100,"w":230,"h":48,}];}else if(type==this.OPTION_TYPE_YES_NO_CANCEL){
this.btn_num=3;
this.btn_list=[new this.Button(-300),
new this.Button(0),
new this.Button(300)
];
this.buttonPos=[{"x":-300,"y":-this.height/2+100,"w":230,"h":48,},
{"x":0,"y":-this.height/2+100,"w":230,"h":48,},
{"x":300,"y":-this.height/2+100,"w":230,"h":48,}];}else{
console.log("[Confirm]no button");
this.btn_num=0;
this.buttonPos=[];}
for(var i=0;i<this.btn_num;i++){
if(typeof action_func[i]=="function"){
this.btn_list[i].setAction(action_func[i]);}
}
if(this.btn_num>0)
this.buttons.components.push.apply(this.buttons.components,this.btn_list);
this.setSize(this.width,this.height);};
Confirmpanel.prototype=new container({});
Confirmpanel.prototype.OPTION_TYPE_OK=0;
Confirmpanel.prototype.OPTION_TYPE_YES_NO=1;
Confirmpanel.prototype.OPTION_TYPE_YES_NO_CANCEL=2;
Confirmpanel.prototype.IMG_PATH=IMG_PATH;
Confirmpanel.prototype.width=1600;Confirmpanel.prototype.height=800;
Confirmpanel.prototype.cursor=null;Confirmpanel.prototype.buttons=null;Confirmpanel.prototype.btn_list=null;Confirmpanel.prototype.btn_num=null;Confirmpanel.prototype.focus_moveto=function(){console.log("No function to move focus.");};
Confirmpanel.prototype.close_action=null;
Confirmpanel.prototype.free=function(){
setf_text(this.message,"");
setf_text(this.title,"");
for(var i=0;i<this.btn_num;i++){
this.btn_list[i].free();}
this.components.splice(0,this.components.length);};
Confirmpanel.prototype.setIconImage=function(img){
};
Confirmpanel.prototype.setTitle=function(s){
this.title_text=s;
setf_text(this.title,s);
this.title.visible_p=true;};
Confirmpanel.prototype.setMessageText=function(s){
this.message_text=s;
setf_text(this.message,s);
this.message.visible_p=true;};
Confirmpanel.prototype.addObject=function(obj){
this.components.push(obj);
if(this.btn_num>0){
obj.translate[1]=50;}
};
Confirmpanel.prototype.setButtonLabel=function(b1,b2,b3){
if(this.btn_num==0)return;
if((b1)&&(this.btn_list[0])){
this.btn_list[0].setText(b1);}
if((b2)&&(this.btn_list[1])){
this.btn_list[1].setText(b2);}
if((b3)&&(this.btn_list[2])){
this.btn_list[2].setText(b3);}
};
Confirmpanel.prototype.setShow=function(b){
if(b){
this.visible_p=true;
}else{
this.visible_p=false;}
force_redraw();};
Confirmpanel.prototype.isShow=function(b){
return this.visible_p;};
Confirmpanel.prototype.setTranslate=function(x,y,z){
this.translate[0]=x;
this.translate[1]=y;
this.translate[2]=z;};
Confirmpanel.prototype.setSize=function(w,h){
w=Math.floor(w);
h=Math.floor(h);
this.width=w;
this.height=h;
this.bg_c.width=w-28;
this.bg_c.height=h-28;
this.title.width=this.width-120;
this.title.translate[1]=this.height/2-60;
if(this.title_text){
setf_text(this.title,this.title_text);}
this.buttons.translate[1]=-this.height/2+80;
this.message.width=this.width-120;
this.message.height=(this.title.translate[1]-20)-(this.buttons.translate[1]+this.Button.prototype.height/2+20);
this.message.translate[1]=(this.title.translate[1]-30)-this.message.height/2;
if(this.message_text){
setf_text(this.message,this.message_text);}
if(this.btn_num>0){
for(var i=0;i<this.btn_num;i++){
this.buttonPos[i].y=-this.height/2+80;}
}

};
Confirmpanel.prototype.onFocus=function(b,keysym){
if(b==true){
this.cursor=this.btn_num-1;
this.correctFocus();}else{
return true;}
};
Confirmpanel.prototype.setAction=function(action_func){
for(var i=0;i<this.btn_num;i++){
this.btn_list[i].setAction(action_func[i]);}
};
Confirmpanel.prototype.setCloseAction=function(action_func){
this.close_action=action_func;};
Confirmpanel.prototype.closeAction=function(){
if(this.close_action)this.close_action();};
Confirmpanel.prototype.key_hook=function(updown,keysym){
if(updown!=KEY_PRESS)return false;
switch(keysym){
case TXK_RIGHT:
if(this.btn_num==0)break;
if(this.cursor==this.btn_list.length-1){
return false;}else{
this.cursor++;
this.correctFocus();
return true;}
case TXK_LEFT:
if(this.btn_num==0)break;
if(this.cursor==0){
return false;}else{
this.cursor--;
this.correctFocus();
return true;}
case TXK_ENTER:
if(this.btn_num==0)break;
try{
this.btn_list[this.cursor].action();
return true;}catch(e){
return false;}
case TXK_RETURN:
try{
this.btn_list[this.btn_list.length-1].action();
return true;}catch(e){
return false;}
default:
}
return false;};
Confirmpanel.prototype._getButtonIndex=function(x,y){
var my_len=this.buttonPos.length;
if(this.buttonPos.length==0)return;
for(var i=0;i<my_len;i++){
var pobj=this.buttonPos[i];
if(((pobj.x-pobj.w*0.5)<=x)&&(x<=(pobj.x+pobj.w*0.5))
&&((pobj.y-pobj.h*0.5)<=y)&&(y<=(pobj.y+pobj.h*0.5))){
return i;}
}
return;}
Confirmpanel.prototype.point_hook=function(type,id,x,y,screenX,screenY){
switch(type){
case "touchstart":
var button=this._getButtonIndex(x,y);
if(button==null)return false;
this.cursor=button;
this._point=this.cursor;
this.correctFocus();
return true;
break;

case "touchmove":
break;
case "touchend":
if(this._point!=null){
try{
var button=this._getButtonIndex(x,y);
if((button==null)||(this.cursor!=button))return false;
this._point=null;
this.btn_list[this.cursor].action();
return true;}catch(e){};}
break;
case "touchcancel":
this._point=null;
break;

default:
break;}
return false;};
Confirmpanel.prototype.correctFocus=function(){
if(this.btn_num==0)return;
var btn=this.btn_list[this.cursor];
var position=[this.translate[0]+this.buttons.translate[0]+btn.getPosition()[0],
this.translate[1]+this.buttons.translate[1]+btn.getPosition()[1],
this.translate[2]+this.buttons.translate[2]+btn.getPosition()[2]];
this.focus_moveto(position,btn.getSize(),0,30,null);};
CHANGE_FONT_SIZE_B=function (obj){
if(get_text_font_height(obj,obj.text)>obj.height){
for(var i=obj.font_size;i>14;i-=4){
obj.font_size=i;
if(get_text_font_height(obj,obj.text)<=obj.height){
break;}
}
setf_text(obj,obj.text);}
};
Confirmpanel.prototype.Button=function(x){
this.superClass=container;
this.superClass({
translate:[x,0,0],
components:[
this.background=new gbox({width:this.width,height:this.height,color:COL_BTN_BORDER,
round_enable:false,round_width:10,round_height:10,}),
this.background2=new gbox({width:this.width-4,height:this.height-4,color:COL_BTN,
round_enable:false,round_width:10,round_height:10,}),
this.text=new gtextbox({width:this.width-10,height:this.height,color:COL_TEXT_ONBASE,
valign:MIDDLE,align:CENTER,}),
]
});};
Confirmpanel.prototype.Button.prototype.IMG_PATH=IMG_PATH;
Confirmpanel.prototype.Button.prototype.width=230;
Confirmpanel.prototype.Button.prototype.height=48;
Confirmpanel.prototype.Button.prototype.background=null;Confirmpanel.prototype.Button.prototype.text=null;Confirmpanel.prototype.Button.prototype.action=function(){};
Confirmpanel.prototype.Button.prototype.free=function(){
setf_text(this.text,"");
this.components.splice(0,this.components.length);};
Confirmpanel.prototype.Button.prototype.setText=function(text){
setf_text(this.text,text);
CHANGE_FONT_SIZE_B(this.text);};
Confirmpanel.prototype.Button.prototype.setAction=function(action_func){
this.action=action_func;};
Confirmpanel.prototype.Button.prototype.getPosition=function(){
return this.translate;};
Confirmpanel.prototype.Button.prototype.getSize=function(){
return [this.width,this.height];};
provide("pkg_confirmpanel");
