286 lines
7.8 KiB
JavaScript
286 lines
7.8 KiB
JavaScript
//滑动
|
|
//-------------------------------------------------------------//
|
|
var SlideBar=function(desc){
|
|
this.desc=desc||"";
|
|
var btn=0,
|
|
bar=0,
|
|
text=0;
|
|
var data=[];
|
|
var oneFunc,
|
|
lastFunc;
|
|
var aline=false;
|
|
var frontValue=0;
|
|
var behindVlue=0;
|
|
this.currentValue=0;
|
|
this.currentValue_index=0;
|
|
var next_id=0;
|
|
var before_id=0;
|
|
var canclick=true;
|
|
this.init=function(obj){
|
|
btn=obj.btnId||0;
|
|
bar=obj.barId||0;
|
|
text=obj.textId||0;
|
|
next_id=obj.nextId||0;
|
|
before_id=obj.beforeId||0;
|
|
aline=obj.aline||false;
|
|
data=obj.data||[0,0];
|
|
oneFunc=obj.oneFunc||function(){return 0;};
|
|
frontValue=obj.frontValue||0;
|
|
behindVlue=obj.behindVlue||data.length-1;
|
|
var btnWidth=get_self(btn,20,0,0);
|
|
var barWidth=get_self(bar,20,0,0);
|
|
var btnHeight=get_self(btn,21,0,0);
|
|
var barHeight=get_self(bar,21,0,0);
|
|
var btnX=get_self(btn,18,0,0);
|
|
var btnY=get_self(btn,19,0,0);
|
|
var barX=get_self(bar,18,0,0);
|
|
var barY=get_self(bar,19,0,0);
|
|
var y= barY+barHeight/2-btnHeight/2;
|
|
var x= barX-btnWidth/2;
|
|
set_self(btn,18,x,0,0);
|
|
set_self(btn,19,y,0,0);
|
|
this.set_text(data[0]);
|
|
if (aline) {
|
|
//textWidth(get_self(text,7,0,0),text);
|
|
Func.bindFather(text,btn,"mid");
|
|
}
|
|
if (behindVlue>=frontValue) {
|
|
this.set_value(frontValue);
|
|
}
|
|
};
|
|
this.set_data=function(o_data){
|
|
data=o_data;
|
|
frontValue=0;
|
|
behindVlue=data.length-1;
|
|
this.set_value(this.currentValue_index);
|
|
this.currentValue=data[this.currentValue_index];
|
|
//textWidth(get_self(text,7,0,0),text);
|
|
};
|
|
this.set_text=function(ta){
|
|
var w=String(ta).length;
|
|
set_self(text,20,30*w,0,0);
|
|
set_self(text,7,ta,0,0);
|
|
}
|
|
this.get_data=function(){
|
|
return data;
|
|
}
|
|
this.hide_btn=function(){
|
|
set_self(btn,37,0,0,0);
|
|
this.can_click(false);
|
|
}
|
|
this.show_btn=function(){
|
|
if (get_self(bar,37,0,0)==1) {
|
|
set_self(btn,37,1,0,0);
|
|
}
|
|
this.can_click(true);
|
|
}
|
|
this.hide_text=function(){
|
|
set_self(text,37,0,0,0);
|
|
}
|
|
this.show_text=function(){
|
|
set_self(text,37,1,0,0);
|
|
}
|
|
this.can_click=function(click){
|
|
canclick=click;
|
|
}
|
|
this.set_limit=function(limit){
|
|
frontValue=limit.left||0;
|
|
behindVlue=limit.right||data.length-1;
|
|
if (behindVlue>=frontValue) {
|
|
this.set_value(frontValue);
|
|
//currentValue=data[frontValue];
|
|
}
|
|
}
|
|
this.set_value=function(item){
|
|
var rate=get_self(bar,20,0,0)/((data.length-1)*2);//一份的长度
|
|
var length=item*rate*2+get_self(bar,18,0,0);
|
|
set_self(btn,18,length-get_self(btn,20,0,0)/2,0,0);
|
|
oneFunc(data[item],data);
|
|
this.set_text(data[item]);
|
|
|
|
//textWidth(get_self(text,7,0,0),text);
|
|
this.currentValue=data[item];
|
|
this.currentValue_index=item;
|
|
}
|
|
this.mouseup=function(gameid, spid_down, downx, downy, spid_up, upx, upy, timelong, no1, no2){
|
|
if (spid_up===spid_down && spid_up===next_id&&canclick) {
|
|
var item=this.currentValue_index;
|
|
item+=1;
|
|
if (item<frontValue) {
|
|
item=frontValue;
|
|
}else if (item>behindVlue) {//data.length-1
|
|
item=behindVlue;
|
|
}
|
|
this.set_value(item);
|
|
}
|
|
if (spid_up===spid_down && spid_up===before_id&&canclick) {
|
|
var item=this.currentValue_index;
|
|
item-=1;
|
|
if (item<frontValue) {
|
|
item=frontValue;
|
|
}else if (item>behindVlue) {//data.length-1
|
|
item=behindVlue;
|
|
}
|
|
this.set_value(item);
|
|
}
|
|
if (spid_up===spid_down && spid_up===bar&&canclick) {
|
|
var ux=upx-get_self(bar,18,0,0);
|
|
var rate=get_self(bar,20,0,0)/((data.length-1)*2);//一份的长度
|
|
var item=Math.round(parseInt(ux/rate)/2);//](get_self(btn,18,0,0)+get_self(btn,20,0,0)/2)
|
|
if (item<frontValue) {
|
|
item=frontValue;
|
|
}else if (item>behindVlue) {//data.length-1
|
|
item=behindVlue;
|
|
}
|
|
var length=item*rate*2+get_self(bar,18,0,0);
|
|
oneFunc(data[item],data)
|
|
this.currentValue=data[item];
|
|
this.currentValue_index=item;
|
|
this.set_text(data[item]);
|
|
set_self(btn,18,length-get_self(btn,20,0,0)/2,0,0);
|
|
//oneFunc(data[item]);
|
|
if (aline) {
|
|
//textWidth(get_self(text,7,0,0),text);
|
|
Func.bindFather(text,btn,"mid");
|
|
}
|
|
}
|
|
}
|
|
this.mousemove=function(gameid, spid, downx, downy, movex,movey ,timelong,offmovex, offmovey, no1){
|
|
if ( spid===btn&&canclick) {
|
|
var rate=get_self(bar,20,0,0)/((data.length-1)*2);//一份的长度
|
|
var item=parseInt((movex-get_self(bar,18,0,0))/rate);//](get_self(btn,18,0,0)+get_self(btn,20,0,0)/2)
|
|
item=Math.round(item/2);//ceil
|
|
if (item<frontValue) {
|
|
item=frontValue;
|
|
}else if (item>behindVlue) {
|
|
item=behindVlue;
|
|
}
|
|
var length=item*rate*2+get_self(bar,18,0,0);
|
|
oneFunc(data[item],data);
|
|
this.currentValue=data[item];
|
|
this.currentValue_index=item;
|
|
this.set_text(data[item]);
|
|
set_self(spid,18,length-get_self(btn,20,0,0)/2,0,0);
|
|
//oneFunc(data[item]);
|
|
if (aline) {
|
|
//textWidth(get_self(text,7,0,0),text);
|
|
Func.bindFather(text,btn,"mid");
|
|
}
|
|
//这里是滑动 ---------
|
|
//var length=offmovex;
|
|
//if ((get_self(btn,18,0,0)+get_self(btn,20,0,0)/2+offmovex)<get_self(bar,18,0,0)){
|
|
//length=-get_self(btn,18,0,0)-get_self(btn,20,0,0)/2+get_self(bar,18,0,0);
|
|
//}
|
|
//if ((get_self(btn,18,0,0)+get_self(btn,20,0,0)/2+offmovex)>(get_self(bar,18,0,0)+get_self(bar,20,0,0))){
|
|
//length= -get_self(btn,18,0,0)-get_self(btn,20,0,0)/2+(get_self(bar,18,0,0)+get_self(bar,20,0,0));
|
|
//}
|
|
//var rate=(get_self(btn,18,0,0)+get_self(btn,20,0,0)/2-get_self(bar,18,0,0))/get_self(bar,20,0,0);//多少分
|
|
//oneFunc(parseInt(rate*100));
|
|
//set_self(spid,18,length,1,0);
|
|
//set_self(text,7,parseInt(rate*100),0,0);
|
|
//这里是滑动---------
|
|
}
|
|
}
|
|
};
|
|
SB=app.register("TopValue",new SlideBar(""));
|
|
SB2=app.register("TopValue2",new SlideBar(""));
|
|
SB3=app.register("TopValue3",new SlideBar(""));
|
|
//===============================
|
|
var Input=function(desc){
|
|
this.desc=desc;
|
|
this.doorid=[];
|
|
this.valueid=-1;
|
|
this.limite=[0,99999];
|
|
this.current=-1;
|
|
this.lableid=-1;
|
|
this.title='';
|
|
this.realtitle='';
|
|
this.warning='',
|
|
this.success=function(){}
|
|
this.failed=function(){}
|
|
this.init=function(obj){
|
|
this.doorid=obj.door||this.doorid;
|
|
this.valueid=obj.value||this.valueid;
|
|
this.lableid=obj.lable||this.lableid;
|
|
this.realtitle=obj.title||'';
|
|
this.warning=obj.warning||'';
|
|
this.limite=obj.limite||this.limite;
|
|
this.current=this.limite[0];
|
|
this.success=obj.success||function(){}
|
|
this.failed=obj.failed||function(){}
|
|
if (this.valueid>0) {
|
|
Func.set_text_adjust(this.valueid,this.current);
|
|
this.success(this.current);
|
|
}
|
|
this.title=this.realtitle+'('+this.limite[0]+','+this.limite[1]+')';
|
|
if (this.lableid>0) {
|
|
set_self(this.lableid,7,this.title);
|
|
}
|
|
}
|
|
}
|
|
|
|
Input.prototype.setValue=function(type){
|
|
if (this.valueid<=0) {
|
|
return;
|
|
}
|
|
switch (type){
|
|
case 0:
|
|
this.current=this.limite[0];
|
|
Func.set_text_adjust(this.valueid,this.current);
|
|
this.success(this.current);
|
|
break;
|
|
case 1:
|
|
this.current=this.limite[1];
|
|
Func.set_text_adjust(this.valueid,this.current);
|
|
this.success(this.current);
|
|
break;
|
|
}
|
|
}
|
|
|
|
Input.prototype.updateLimted=function(value){
|
|
if (this.lableid<=0||this.valueid<=0) {
|
|
return;
|
|
}
|
|
this.limite=value||this.limite;
|
|
this.title=this.realtitle+'('+this.limite[0]+','+this.limite[1]+')';
|
|
set_self(this.lableid,7,this.title);
|
|
if (this.current<this.limite[0]||this.current>this.limite[1]) {
|
|
this.current=this.limite[0];
|
|
Func.set_text_adjust(this.valueid,this.current);
|
|
}
|
|
}
|
|
Input.prototype.mouseup=function(gameid, spid_down, downx, downy, spid_up, upx, upy, timelong, no1, no2){
|
|
if (this.doorid.indexOf(spid_up)!=-1) {
|
|
this.openInput();
|
|
}
|
|
}
|
|
Input.prototype.openInput=function(){
|
|
var that=this;
|
|
Utl.openInputPanel(that.title,function (value) {
|
|
if (value>=that.limite[0]&&value<=that.limite[1]) {
|
|
that.current=value;
|
|
Func.set_text_adjust(that.valueid,value);
|
|
that.success(value);
|
|
Utl.closeInputPanel();
|
|
}else{
|
|
that.failed(value);
|
|
Utl.openTips(that.warning,2000)
|
|
}
|
|
})
|
|
}
|
|
sb1=app.register("In1",new Input(""));
|
|
sb2=app.register("In2",new Input(""));
|
|
sb3=app.register("In3",new Input(""));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|