class Panel{
	constructor(x,y,width,height){
		this.width=width;
		this.height=height;
		this.pos={
			x: x,
			y: y
		};
	}
	draw(){
		ctx.drawImage($("#img_panel")[0],this.pos.x,this.pos.y,this.width,this.height);
	}
}
class Throttlelever{
	constructor(panel,x,y,scale){
		this.panel=panel;
		this.scale=scale;
		this.name="throttle lever";
		this.desc="changes the power when teleporting";
		this.handlescale=scale*1.6;
		this.pos={
			x: setwidth/2-this.scale/2+x,
			y: setheight/2-this.scale/2+y
		};
		this.min=(this.pos.y-(this.scale+80)/5).toFixed(2);
		this.max=(this.pos.y+(this.scale+80)/2.4).toFixed(2);
		this.handlepos={
			x: setwidth/2-this.handlescale/2+x,
			y: this.max
		}
		this.mouseisdown=false;
		this.mouseisover=false;
	}
	draw(){
		if(panelnum==this.panel){
			if(this.handlepos.y<this.min){
				this.handlepos.y=this.min
			}
			if(this.handlepos.y>this.max){
				this.handlepos.y=this.max;
			}
			if(power.ison==false){
				this.handlepos.y=this.max
			}
			this.value=100-(((this.handlepos.y-this.pos.y+26).toFixed())/80*100).toFixed();
			ctx.drawImage($("#img_throttle_base")[0],this.pos.x,this.pos.y,this.scale,this.scale+80);
			ctx.drawImage($("#img_throttle_handle")[0],this.handlepos.x,this.handlepos.y,this.handlescale,this.handlescale+20);
			if(power.ison==true){
				ctx.fillStyle = "#0df";
				ctx.font = "13px Ariel";
				ctx.fillText(this.value,this.pos.x+15,this.pos.y+this.scale+72)
			}
			if(telepathicChover.ison==true&&this.mouseisover==true){
				ctx.fillStyle = "#000";
				ctx.globalAlpha = 0.8;
				ctx.fillRect(globalcx,globalcy,150,100)
				ctx.globalAlpha = 1;
				ctx.font = "15px Ariel";
				ctx.fillStyle = "#fff";
				ctx.fillText(this.name,globalcx+20,globalcy+20,149)
				ctx.font = "12px Ariel";
				ctx.fillText(this.desc,globalcx,globalcy+40,149)
			}
		}
	}
	mouseon(cx,cy){
		if(panelnum==this.panel){
			if(cx>this.pos.x&&cx<this.pos.x+this.scale&&cy>this.pos.y&&cy<this.pos.y+this.scale+80){
				this.mouseisdown=true;
				this.handlepos.y=cy-this.handlescale/2;
			}
		}
	}
	move(cx,cy){
		if(panelnum==this.panel){
			if(cx>this.pos.x&&cx<this.pos.x+this.scale&&cy>this.pos.y&&cy<this.pos.y+this.scale+80){
				if(this.mouseisdown==true){
					this.handlepos.y=cy-this.handlescale/2;
				}
				this.mouseisover=true;
			} else {
				this.mouseisover=false;
			}
		}
	}
}
class Button{
	constructor(panel,x,y,scale,Back,offNoPower,redOff,redNoPower,name,desc){
		this.panel=panel;
		this.scale=scale;
		this.name=name;
		this.desc=desc;
		this.pos={
			x: setwidth/2-this.scale/2+x,
			y: setheight/2-this.scale/2+y
		};
		this.ison=false;
		this.back=Back;
		this.redOff=redOff;
		this.offNoPower=offNoPower;
		this.redNoPower=redNoPower;
		this.mouseisover=false;
		this.locked=false;
		this.run_function=false;
	}
	draw(){
		if(power.ison==false&&this.offNoPower==true){
			this.ison=false;
		}
		if(panelnum==this.panel){
			if(this.ison==true&&this.back==true){
				ctx.drawImage($("#img_button_back")[0],this.pos.x,this.pos.y,this.scale,this.scale);
			} else if(this.redNoPower==true&&power.ison==false){
				ctx.drawImage($("#img_button_back_red")[0],this.pos.x,this.pos.y,this.scale,this.scale);
			} else if(this.ison==false&&this.redOff==false){
				ctx.drawImage($("#img_button_back_white")[0],this.pos.x,this.pos.y,this.scale,this.scale);
			} else if(this.ison==false&&this.redOff==true){
				ctx.drawImage($("#img_button_back_red")[0],this.pos.x,this.pos.y,this.scale,this.scale);
			}
			ctx.drawImage($("#img_button")[0],this.pos.x,this.pos.y,this.scale,this.scale);
		}
	}
	drawhover(){
		if(telepathicChover.ison==true&&this.mouseisover==true){
			ctx.fillStyle = "#000";
			ctx.globalAlpha = 0.8;
			ctx.fillRect(globalcx,globalcy,150,120)
			ctx.globalAlpha = 1;
			ctx.font = "15px Ariel";
			ctx.fillStyle = "#fff";
			ctx.fillText(this.name,globalcx+20,globalcy+20,120)
			ctx.font = "12px Ariel";
			ctx.fillText(this.desc,globalcx,globalcy+40,120)
		}
	}
	toggle(cx,cy,run_function){
		if(panelnum==this.panel){
			if(cx>this.pos.x&&cx<this.pos.x+this.scale&&cy>this.pos.y&&cy<this.pos.y+this.scale){
				if(this.locked==false){
					this.run_function=run_function;
					switch(this.ison){
						case false:
							this.ison = true;
							break;
						case true:
							this.ison = false;
							break;
					}
				}
			}
		}
	}
	move(cx,cy){
		if(panelnum==this.panel&&cx>this.pos.x&&cx<this.pos.x+this.scale&&cy>this.pos.y&&cy<this.pos.y+this.scale){
			this.mouseisover=true;
		} else {
			this.mouseisover=false;
		}
	}
}
class Switch{
	constructor(panel,x,y,scale,offNoPower,is3stage,name,desc){
		this.panel=panel;
		this.scale=scale;
		this.name=name;
		this.desc=desc;
		this.pos={
			x: setwidth/2-this.scale/2+x,
			y: setheight/2-this.scale/2+y
		};
		this.stage=2;
		this.ison=false;
		this.offNoPower=offNoPower;
		this.is3stage=is3stage;
		this.mouseisover=false;
	}
	draw(){
		if(power.ison==false&&this.offNoPower==true){
			this.stage=2;
			this.ison=false;
		}
		if(panelnum==this.panel){
			if(this.stage==1){
				this.ison=true;
				ctx.drawImage($("#img_switch_down")[0],this.pos.x,this.pos.y,this.scale,this.scale);
			}
			if(this.stage==2){
				this.ison=false;
				ctx.drawImage($("#img_switch")[0],this.pos.x,this.pos.y,this.scale,this.scale);
			}
			if(this.stage==3){
				this.ison=true;
				ctx.drawImage($("#img_switch_up")[0],this.pos.x,this.pos.y,this.scale,this.scale);
			}
		}
	}
	drawhover(){
		if(telepathicChover.ison==true&&this.mouseisover==true){
			ctx.fillStyle = "#000";
			ctx.globalAlpha = 0.8;
			ctx.fillRect(globalcx,globalcy,150,100)
			ctx.globalAlpha = 1;
			ctx.font = "15px Ariel";
			ctx.fillStyle = "#fff";
			ctx.fillText(this.name,globalcx+20,globalcy+20,this.pos.y+this.scale)
			ctx.font = "12px Ariel";
			ctx.fillText(this.desc,globalcx,globalcy+40,this.pos.y+this.scale)
		}
	}
	toggle(cx,cy){
		if(panelnum==this.panel){
			if(this.is3stage==false){
				if(cx>this.pos.x&&cx<this.pos.x+this.scale&&cy>this.pos.y&&cy<this.pos.y+this.scale){
					switch(this.stage){
						case 2:
							this.stage=3;
							break;
						case 3:
							this.stage=2;
							break;
					}
				}
			} else {
				if(cx>this.pos.x&&cx<this.pos.x+this.scale){
					if(cy>this.pos.y&&cy<this.pos.y+(this.scale/3)){
						this.stage=3;
					}
					if(cy>this.pos.y+(this.scale/3)&&cy<this.pos.y+(this.scale/3*2)){
						this.stage=2;
					}
					if(cy>this.pos.y+(this.scale/3*2)&&cy<this.pos.y+this.scale){
						this.stage=1;
					}
				}
			}
		}
	}
	move(cx,cy){
		if(panelnum==this.panel&&cx>this.pos.x&&cx<this.pos.x+this.scale&&cy>this.pos.y&&cy<this.pos.y+this.scale){
			this.mouseisover=true;
		} else {
			this.mouseisover=false;
		}
	}
}
class Arrowbutton{
	constructor(x,y,width,height){
		this.width=width;
		this.height=height;
		this.pos={
			x: x,
			y: y
		};
	}
	draw(name){
		ctx.drawImage($(name)[0],this.pos.x,this.pos.y,this.width,this.height);
	}
	click(cx,cy,type){
		if(cx>this.pos.x&&cx<this.pos.x+this.width&&cy>this.pos.y&&cy<this.pos.y+this.height){
			if(type=="up"){
				panelnum++;
				if(panelnum>4)panelnum=1;
			}
			if(type=="down"){
				panelnum--;
				if(panelnum<1)panelnum=4;
			}
		}
	}
}
class Flever{
	constructor(panel,x,y,scale){
		this.panel=panel;
		this.state="#img_flever";
		this.scale=-120;
		this.name="flight lever"
		this.desc="allows you to move when flightmode is enabled"
		this.pos={
			x: setwidth/2-(this.scale+260)/2+x,
			y: setheight/2-(this.scale+409)/2+y
		};
		this.buttonpos={
			x: ((this.pos.x+(this.scale+260)/2)-(this.scale+239)/2)+6,
			y: this.pos.y+(this.scale+409)-90
		}
		this.mouseisover=false;
		this.mobilebuttons=false;
	}
	draw(){
		if(panelnum==this.panel){
			ctx.drawImage($(this.state)[0],this.pos.x,this.pos.y,this.scale+260,this.scale+409);
			if(this.mobilebuttons==true){
				ctx.drawImage($("#img_flever_mobile")[0],this.buttonpos.x,this.buttonpos.y,this.scale+239,this.scale+191);
			}
		}
	}
	drawhover(){
		if(telepathicChover.ison==true&&this.mouseisover==true){
			ctx.fillStyle = "#000";
			ctx.globalAlpha = 0.8;
			ctx.fillRect(globalcx,globalcy,160,100)
			ctx.globalAlpha = 1;
			ctx.font = "15px Ariel";
			ctx.fillStyle = "#fff";
			ctx.fillText(this.name,globalcx+20,globalcy+20,this.pos.y+this.scale)
			ctx.font = "12px Ariel";
			ctx.fillText(this.desc,globalcx,globalcy+40,this.pos.y+this.scale+20)
			ctx.fillText("use arrow keys on keyboard",globalcx,globalcy+80,this.pos.y+this.scale)
		}
	}
	toggle(cx,cy){
		if(panelnum==this.panel&&cx>this.pos.x&&cx<this.pos.x+this.scale+260&&cy>this.pos.y&&cy<this.pos.y+this.scale+409){
			if(this.mobilebuttons==true){
				if(cx>((this.buttonpos.x)+6)+(this.scale+227)/3&&cy>this.buttonpos.y&&cx<(((this.buttonpos.x)+6)+(this.scale+227)/3)+(this.scale+227)/3&&cy<this.buttonpos.y+(this.scale+191)/2){
					this.state="#img_flever_forward";
				}
				else if(cx>((this.buttonpos.x)+6)+(this.scale+227)/3&&cy>this.buttonpos.y+(this.scale+155)&&cx<(((this.buttonpos.x)+6)+(this.scale+227)/3)+(this.scale+227)/3&&cy<this.buttonpos.y+(this.scale+155)+(this.scale+191)/2){
					this.state="#img_flever_back";
				}
				else if(cx>((this.buttonpos.x)+6)&&cy>this.buttonpos.y+(this.scale+155)&&cx<(((this.buttonpos.x)+6)+(this.scale+227)/3)+(this.scale+227)/3&&cy<this.buttonpos.y+(this.scale+155)+(this.scale+191)/2){
					this.state="#img_flever_left";
				} 
				else if(cx>((this.buttonpos.x)+6)+(this.scale+227)/1.5&&cy>this.buttonpos.y+(this.scale+155)&&cy<this.buttonpos.y+(this.scale+155)+(this.scale+191)/2){
					this.state="#img_flever_right";
				} else {
					this.state="#img_flever";
				}
			}
			this.mobilebuttons=true;
		}
	}
	move(cx,cy){
		if(panelnum==this.panel&&cx>this.pos.x&&cx<this.pos.x+this.scale+260&&cy>this.pos.y&&cy<this.pos.y+this.scale+409){
			this.mouseisover=true;
		} else {
			this.mouseisover=false;
		}
	}
}
class Textpanel{
	constructor(panel,x,y,width,height){
		this.panel=panel;
		this.width=width;
		this.height=height;
		this.pos={
			x: setwidth/2-this.width/2+x,
			y: setheight/2-this.height/2+y
		};
		this.text="";
	}
	draw(){
		if(panelnum==this.panel){
			ctx.drawImage($("#img_text_panel")[0],this.pos.x,this.pos.y,this.width,this.height);
			this.text=this.text.toString().split("BR");
			ctx.fillStyle = "#0df";
			if(this.text.length>1){
			var size=(this.height/1.8-0.5)/(this.text.length-0.5);
			} else {
				var size=(this.height/1.8-0.5)/1;
			}
			ctx.font = size+"px Ariel";
			if(power.ison==true){
				for(var i=0; i<this.text.length; i++){
					ctx.fillText(this.text[i],this.pos.x+this.width/12,this.pos.y+this.height/this.text.length*(i+1-0.3),this.width/1.21);
				}

			}
		}
	}
}
//scanner

