Path: blob/main/static/src/gs/public/radius-raid/js/button.js
1324 views
/*==============================================================================1Init2==============================================================================*/3$.Button = function( opt ) {4for( var k in opt ) {5this[k] = opt[k];6}7var text = $.text( {8ctx: $.ctxmg,9x: 0,10y: 0,11text: this.title,12hspacing: 1,13vspacing: 0,14halign: 'center',15valign: 'center',16scale: this.scale,17snap: 1,18render: 019} );20this.width = this.lockedWidth;21this.height = this.lockedHeight;2223this.sx = this.x - this.width / 2;24this.sy = this.y - this.height / 2;25this.cx = this.x;26this.cy = this.y;27this.ex = this.x + this.width / 2;28this.ey = this.y + this.height / 2;29this.hovering = 0;30this.ohovering = 0;31};3233/*==============================================================================34Update35==============================================================================*/36$.Button.prototype.update = function( i ) {37/*==============================================================================38Check Hover State39==============================================================================*/40if( $.util.pointInRect( $.mouse.sx, $.mouse.sy, this.sx, this.sy, this.width, this.height ) ){41this.hovering = 1;42if( !this.ohovering ) {43$.audio.play( 'hover' );44}45} else {46this.hovering = 0;47}48this.ohovering = this.hovering;4950/*==============================================================================51Check Click52==============================================================================*/53if( this.hovering && $.mouse.down ) {54$.audio.play( 'click' );55this.action();56}57};5859/*==============================================================================60Render61==============================================================================*/62$.Button.prototype.render = function( i ) {63if( this.hovering ) {64$.ctxmg.fillStyle = 'hsla(0, 0%, 10%, 1)';65$.ctxmg.fillRect( Math.floor( this.sx ), Math.floor( this.sy ), this.width, this.height );66$.ctxmg.strokeStyle = 'hsla(0, 0%, 0%, 1)';67$.ctxmg.strokeRect( Math.floor( this.sx ) + 0.5, Math.floor( this.sy ) + 0.5, this.width - 1, this.height - 1, 1 );68$.ctxmg.strokeStyle = 'hsla(0, 0%, 100%, 0.2)';69$.ctxmg.strokeRect( Math.floor( this.sx ) + 1.5, Math.floor( this.sy ) + 1.5, this.width - 3, this.height - 3, 1 );70} else {71$.ctxmg.fillStyle = 'hsla(0, 0%, 0%, 1)';72$.ctxmg.fillRect( Math.floor( this.sx ), Math.floor( this.sy ), this.width, this.height );73$.ctxmg.strokeStyle = 'hsla(0, 0%, 0%, 1)';74$.ctxmg.strokeRect( Math.floor( this.sx ) + 0.5, Math.floor( this.sy ) + 0.5, this.width - 1, this.height - 1, 1 );75$.ctxmg.strokeStyle = 'hsla(0, 0%, 100%, 0.15)';76$.ctxmg.strokeRect( Math.floor( this.sx ) + 1.5, Math.floor( this.sy ) + 1.5, this.width - 3, this.height - 3, 1 );77}7879$.ctxmg.beginPath();80$.text( {81ctx: $.ctxmg,82x: this.cx,83y: this.cy,84text: this.title,85hspacing: 1,86vspacing: 0,87halign: 'center',88valign: 'center',89scale: this.scale,90snap: 1,91render: true92} );9394$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.7)';95if( this.hovering ) {96$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 1)';97}98$.ctxmg.fill();99100$.ctxmg.fillStyle = 'hsla(0, 0%, 100%, 0.07)';101$.ctxmg.fillRect( Math.floor( this.sx ) + 2, Math.floor( this.sy ) + 2, this.width - 4, Math.floor( ( this.height - 4 ) / 2 ) );102};103104