Commit 7de6de9a authored by rockyl's avatar rockyl

init

parent b4f2e18e
This diff is collapsed.
......@@ -47,7 +47,7 @@
"success"
],
"id": "show-toast",
"script": "var toastProps = Object.assign({}, props, args);\nglobal.gameStage.toast.show(toastProps);\nnext('success');\n",
"script": "var toastProps = {};\nengine.injectProp(toastProps, props);\nengine.injectProp(toastProps, args);\nglobal.gameStage.toast.show(toastProps);\nnext('success');\n",
"group": "view",
"type": "builtin"
}
This diff is collapsed.
......@@ -2,7 +2,9 @@
* Created by rockyl on 2019-11-16.
*/
const toastProps = Object.assign({}, props, args);
const toastProps = {};
engine.injectProp(toastProps, props);
engine.injectProp(toastProps, args);
global.gameStage.toast.show(toastProps);
......
......@@ -7,6 +7,7 @@ export default class ZoomScroll extends engine.ScriptBase {
autoInit: boolean = true;
duration: number = 1000;
mvvmMode: boolean = false;
@engine.dirtyFieldTrigger
index: number = 0;
@engine.dirtyFieldTrigger
......@@ -31,36 +32,32 @@ export default class ZoomScroll extends engine.ScriptBase {
this._centerOffset = this.host.width / 2;
if(this.autoInit){
this.init();
setTimeout(this.init);
}
}
sleep(): void {
this.host.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDragStart, this);
}
update(t) {
get children(){
return this.mvvmMode ? this.host.children[0].children : this.host.children;
}
init() {
for (let i = 0, li = this.host.children.length; i < li; i++) {
const child = this.host.children[i];
init=()=> {
for (let i = 0, li = this.children.length; i < li; i++) {
const child = this.children[i];
child.anchorX = child.width / 2;
child.anchorY = child.height / 2;
child.x = child.ix = i * this.itemWidth + this._centerOffset - this.itemWidth / 2;
}
this.scrollTo(0, false);
this.host.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDragStart, this);
}
updateOffset(offset) {
this._dragOffset.x = this._startDragOffset.x + offset.x;
for (let i = 0, li = this.host.children.length; i < li; i++) {
const child = this.host.children[i];
for (let i = 0, li = this.children.length; i < li; i++) {
const child = this.children[i];
let x = child.x = child.ix + this._dragOffset.x;
let s = 40 / Math.abs(x - this._centerOffset + this.itemWidth / 2);
......@@ -109,9 +106,7 @@ export default class ZoomScroll extends engine.ScriptBase {
this._startDragOffset.y = 0;
let index = Math.round(this._dragOffset.x / this.itemWidth);
index = -Math.min(0, Math.max(1 - this.host.children.length, index));
this['_index'] = index;
index = -Math.min(0, Math.max(1 - this.children.length, index));
this.scrollTo(index);
......@@ -127,12 +122,20 @@ export default class ZoomScroll extends engine.ScriptBase {
}
private scrollTo(index, animation = true) {
this['_index'] = index;
this.host.dispatchEvent('willScroll', {index});
let indexPos = -index * this.itemWidth;
if (animation) {
engine.Tween.get(this, null, null, true)
.to({t: indexPos}, 100, engine.Ease.cubicOut);
.to({t: indexPos}, 100, engine.Ease.cubicOut)
.call(()=>{
this.host.dispatchEvent('didScrolled', {index});
});
} else {
this.t = indexPos;
this.host.dispatchEvent('didScrolled', {index});
}
}
......@@ -141,7 +144,7 @@ export default class ZoomScroll extends engine.ScriptBase {
case 'index':
let index = value;
if(oldValue!==undefined){
index = Math.max(0, Math.min(this.host.children.length - 1, value));
index = Math.max(0, Math.min(this.children.length - 1, value));
this['_index'] = index;
}
......
{
"name": "缩放滚动",
"props": {
"mvvmMode": {
"alias": "mvvm模式",
"type": "boolean",
"default": false
},
"autoInit": {
"alias": "自动初始化",
"type": "boolean",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment