Commit 7de6de9a authored by rockyl's avatar rockyl

init

parent b4f2e18e
This diff is collapsed.
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
"success" "success"
], ],
"id": "show-toast", "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", "group": "view",
"type": "builtin" "type": "builtin"
} }
This diff is collapsed.
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
* Created by rockyl on 2019-11-16. * 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); global.gameStage.toast.show(toastProps);
next('success'); next('success');
\ No newline at end of file
...@@ -7,6 +7,7 @@ export default class ZoomScroll extends engine.ScriptBase { ...@@ -7,6 +7,7 @@ export default class ZoomScroll extends engine.ScriptBase {
autoInit: boolean = true; autoInit: boolean = true;
duration: number = 1000; duration: number = 1000;
mvvmMode: boolean = false;
@engine.dirtyFieldTrigger @engine.dirtyFieldTrigger
index: number = 0; index: number = 0;
@engine.dirtyFieldTrigger @engine.dirtyFieldTrigger
...@@ -31,36 +32,32 @@ export default class ZoomScroll extends engine.ScriptBase { ...@@ -31,36 +32,32 @@ export default class ZoomScroll extends engine.ScriptBase {
this._centerOffset = this.host.width / 2; this._centerOffset = this.host.width / 2;
if(this.autoInit){ 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() { init=()=> {
for (let i = 0, li = this.host.children.length; i < li; i++) { for (let i = 0, li = this.children.length; i < li; i++) {
const child = this.host.children[i]; const child = this.children[i];
child.anchorX = child.width / 2; child.anchorX = child.width / 2;
child.anchorY = child.height / 2; child.anchorY = child.height / 2;
child.x = child.ix = i * this.itemWidth + this._centerOffset - this.itemWidth / 2; child.x = child.ix = i * this.itemWidth + this._centerOffset - this.itemWidth / 2;
} }
this.scrollTo(0, false); this.scrollTo(0, false);
this.host.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDragStart, this);
} }
updateOffset(offset) { updateOffset(offset) {
this._dragOffset.x = this._startDragOffset.x + offset.x; this._dragOffset.x = this._startDragOffset.x + offset.x;
for (let i = 0, li = this.host.children.length; i < li; i++) { for (let i = 0, li = this.children.length; i < li; i++) {
const child = this.host.children[i]; const child = this.children[i];
let x = child.x = child.ix + this._dragOffset.x; let x = child.x = child.ix + this._dragOffset.x;
let s = 40 / Math.abs(x - this._centerOffset + this.itemWidth / 2); let s = 40 / Math.abs(x - this._centerOffset + this.itemWidth / 2);
...@@ -109,9 +106,7 @@ export default class ZoomScroll extends engine.ScriptBase { ...@@ -109,9 +106,7 @@ export default class ZoomScroll extends engine.ScriptBase {
this._startDragOffset.y = 0; this._startDragOffset.y = 0;
let index = Math.round(this._dragOffset.x / this.itemWidth); let index = Math.round(this._dragOffset.x / this.itemWidth);
index = -Math.min(0, Math.max(1 - this.host.children.length, index)); index = -Math.min(0, Math.max(1 - this.children.length, index));
this['_index'] = index;
this.scrollTo(index); this.scrollTo(index);
...@@ -127,12 +122,20 @@ export default class ZoomScroll extends engine.ScriptBase { ...@@ -127,12 +122,20 @@ export default class ZoomScroll extends engine.ScriptBase {
} }
private scrollTo(index, animation = true) { private scrollTo(index, animation = true) {
this['_index'] = index;
this.host.dispatchEvent('willScroll', {index});
let indexPos = -index * this.itemWidth; let indexPos = -index * this.itemWidth;
if (animation) { if (animation) {
engine.Tween.get(this, null, null, true) 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 { } else {
this.t = indexPos; this.t = indexPos;
this.host.dispatchEvent('didScrolled', {index});
} }
} }
...@@ -141,7 +144,7 @@ export default class ZoomScroll extends engine.ScriptBase { ...@@ -141,7 +144,7 @@ export default class ZoomScroll extends engine.ScriptBase {
case 'index': case 'index':
let index = value; let index = value;
if(oldValue!==undefined){ 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; this['_index'] = index;
} }
......
{ {
"name": "缩放滚动", "name": "缩放滚动",
"props": { "props": {
"mvvmMode": {
"alias": "mvvm模式",
"type": "boolean",
"default": false
},
"autoInit": { "autoInit": {
"alias": "自动初始化", "alias": "自动初始化",
"type": "boolean", "type": "boolean",
...@@ -47,4 +52,4 @@ ...@@ -47,4 +52,4 @@
"default": 1 "default": 1
} }
} }
} }
\ No newline at end of file
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