From 03445f57726b2e8394f206af510db67909779ddf Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:07:27 -0700 Subject: [PATCH] Add Control class. --- game/game.js | 151 +++++++++++++++++++++------------------------------ 1 file changed, 61 insertions(+), 90 deletions(-) diff --git a/game/game.js b/game/game.js index 030e3a6ad..574071748 100644 --- a/game/game.js +++ b/game/game.js @@ -31188,8 +31188,52 @@ return this; } }, - control:{ - open:function(){ + Control:class extends HTMLDivElement{ + constructor(){ + const nc=!ui.control.querySelector('div:not(.removing):not(.stayleft)'); + const controls=Array.isArray(arguments[0])?arguments[0]:Array.from(arguments); + const control=ui.create.div('.control'); + Object.setPrototypeOf(control,lib.element.Control.prototype); + ui.control.insertBefore(control,_status.createControl||ui.confirm); + controls.forEach(argument=>{ + if(argument=='nozoom') return; + if(typeof argument=='function') control.custom=argument; + else if(argument=='stayleft'){ + control.stayleft=true; + control.classList.add('stayleft'); + } + else control.add(argument); + }); + ui.controls.unshift(control); + if(nc) ui.control.animate('nozoom',100); + if(control.childNodes.length){ + control.style.transition='opacity 0.5s'; + control.animate('controlpressdownx',500); + ui.refresh(control); + if(!control.stayleft) control.style.transform=`translateX(-${control.offsetWidth/2}px)`; + control.style.opacity=1; + ui.refresh(control); + control.style.transition=''; + } + + control.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.control2); + + if(lib.config.button_press){ + control.addEventListener(lib.config.touchscreen?'touchstart':'mousedown',function(){ + if(this.classList.contains('disabled')) return; + this.classList.add('controlpressdown'); + if(typeof this._offset=='number') this.style.transform=`translateX(${this._offset}px) scale(0.97)`; + }); + control.addEventListener(lib.config.touchscreen?'touchend':'mouseup',function(){ + this.classList.remove('controlpressdown'); + if(typeof this._offset=='number') this.style.transform=`translateX(${this._offset}px)`; + }); + } + + ui.updatec(); + return control; + } + open(){ ui.control.insertBefore(this,_status.createControl||ui.confirm); ui.controls.unshift(this); if(this.childNodes.length){ @@ -31205,15 +31249,15 @@ } ui.updatec(); return this; - }, - add:function(item){ + } + add(item){ var node=document.createElement('div'); this.appendChild(node); node.link=item; node.innerHTML=get.translation(item); node.addEventListener(lib.config.touchscreen?'touchend':'click',ui.click.control); - }, - close:function(){ + } + close(){ this.animate('controlpressdownx',500); ui.controls.remove(this); @@ -31226,8 +31270,8 @@ if(ui.skills==this) delete ui.skills; if(ui.skills2==this) delete ui.skills2; if(ui.skills3==this) delete ui.skills3; - }, - replace:function(){ + } + replace(){ // this.animate('controlpressdownx',500); if(this.replaceTransition===false){ this.style.transitionProperty='none'; @@ -31412,6 +31456,12 @@ */ get dialog(){ return this.Dialog.prototype; + }, + /** + * @legacy Use `lib.element.Control.prototype` instead. + */ + get control(){ + return this.Control.prototype; } }, card:{ @@ -50775,88 +50825,7 @@ return caption; }, control:function(){ - var nc=!ui.control.querySelector('div:not(.removing):not(.stayleft)'); - // for(var i=0;i