Commit 7de6de9a authored by rockyl's avatar rockyl

init

parent b4f2e18e
{
"name": "摇奖机",
"desc": "摇奖机",
"props": {
"imgSizeW": {
"alias": "奖品图片宽",
"type": "number",
"default": 99
},
"imgSizeH": {
"alias": "奖品图片高",
"type": "number",
"default": 99
},
"spaceSizeX": {
"alias": "奖品横向间隙",
"type": "number",
"default": 20
},
"spaceSizeY": {
"alias": "奖品纵向间隙",
"type": "number",
"default": 20
},
"cOriginSizeX": {
"alias": "遮罩左边顶点坐标",
"type": "number",
"default": 22
},
"cOriginSizeY": {
"alias": "遮罩左边顶点坐标",
"type": "number",
"default": 19
},
"cSpaceSizeX": {
"alias": "每列奖品容器的横向间隙",
"type": "number",
"default": 23
},
"maskSizeW": {
"alias": "遮罩宽",
"type": "number",
"default": 428
},
"maskSizeH": {
"alias": "遮罩高",
"type": "number",
"default": 221
},
"viewWidth": {
"alias": "模块宽",
"type": "number",
"default": 472
},
"viewHeight": {
"alias": "模块高",
"type": "number",
"default": 256
}
},
"assets": [
{
"name": "rock-背景",
"url": "//yun.duiba.com.cn/aurora/assets/877058dcced99e42ddd2ccf19c2bce189fa45d5c.png",
"uuid": "7baa74f5-e057-4fd3-846f-f58ff7a92c3d",
"ext": ".png"
}
],
"events": {
"in": {
"rock-info": {
"alias": "初始化进入页面调用",
"data": [
{
"icon": "//yun.duiba.com.cn/aurora/assets/88d89ba9c3ddac732f2e017023a216be915655e4.png",
"id": "o58df634f",
"index": 1,
"name": "一等奖",
"prizeId": "sss_3",
"prizeType": 2,
"refId": "49781",
"refType": "virtual"
},
{
"icon": "//yun.duiba.com.cn/aurora/assets/1c0e0fcb192b2e0772bd555c3aae1c86621ccb09.png",
"id": "o4a578392",
"index": 2,
"name": "二等奖",
"prizeId": "sss_2",
"prizeType": 2,
"refId": "49780",
"refType": "virtual"
},
{
"icon": "//yun.duiba.com.cn/aurora/assets/bc23cd948cdd20467af9abc1f65e08e4f1e9bf30.png",
"id": "o26efbbeb",
"index": 3,
"name": "三等奖",
"prizeId": "sss_1",
"prizeType": 2,
"refId": "49779",
"refType": "virtual"
}
]
},
"rock-start": {
"alias": "开始摇奖,透传中奖id",
"data": {
"prizeId": "sss_3"
}
},
"rock-reset": {
"alias": "关闭中奖弹窗时调用"
}
},
"out": {
"rock-gameover": {
"alias": "摇奖机停止是派发"
}
}
},
"id": "rockji",
"code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof define === 'function' && define.amd ? define(['tslib'], factory) :\n\t(global = global || self, global.rockji = factory(global.tslib));\n}(this, (function (tslib) { 'use strict';\n\n\tvar props = {};\n\tfunction prepareProps() {\n\t var metaProps = getProps();\n\t engine.injectProp(props, metaProps);\n\t}\n\tfunction injectProps(p) {\n\t engine.injectProp(props, p);\n\t}\n\n\tvar GameView = (function (_super) {\n\t tslib.__extends(GameView, _super);\n\t function GameView() {\n\t var _this = _super.call(this) || this;\n\t _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);\n\t _this.prizeId = props.prizeId;\n\t _this.prizes = props.prizes;\n\t _this.countdown = 150;\n\t _this.timeSpace = 500;\n\t console.log(\"props.prizes=\", props.prizes);\n\t return _this;\n\t }\n\t GameView.prototype.setup = function () {\n\t if (this._hasSetup) {\n\t return;\n\t }\n\t this._hasSetup = true;\n\t this.itemInfo = {};\n\t this.mainContainer = new engine.Container();\n\t this.viewContainer = new engine.Container();\n\t this.addChild(this.viewContainer);\n\t this.viewContainer.width = props.viewWidth;\n\t this.viewContainer.height = props.viewHeight;\n\t this.bgImg = new engine.Image();\n\t this.bgImg.source = getAssetByName(\"rock-背景\").url;\n\t this.viewContainer.addChild(this.bgImg);\n\t this.container0 = new engine.Container();\n\t this.container1 = new engine.Container();\n\t this.container2 = new engine.Container();\n\t this.mainContainer.addChild(this.container0);\n\t this.mainContainer.addChild(this.container1);\n\t this.mainContainer.addChild(this.container2);\n\t this.viewContainer.addChild(this.mainContainer);\n\t this.mainContainer.x = props.cOriginSizeX;\n\t this.mainContainer.y = props.cOriginSizeY;\n\t var mask = new engine.Rect();\n\t mask.x = props.cOriginSizeX;\n\t mask.y = props.cOriginSizeY;\n\t mask.fillColor = 0xffff00;\n\t mask.width = props.maskSizeW;\n\t mask.height = props.maskSizeH;\n\t this.addChild(mask);\n\t this.mainContainer.mask = mask;\n\t if (this.prizes.length > 3) {\n\t this.createItem(2);\n\t this.prizeMaxH = this.prizes.length * (props.imgSizeW + props.spaceSizeY) + props.spaceSizeY;\n\t }\n\t else {\n\t this.createItem(1);\n\t this.prizeMaxH = 4 * (props.imgSizeW + props.spaceSizeY) + props.spaceSizeY;\n\t }\n\t this.orgY = -(this.prizeMaxH - props.maskSizeH) + props.imgSizeH * 0.5;\n\t for (var i = 0; i < 3; i++) {\n\t this['container' + i].x = i * (props.cSpaceSizeX * 2 + props.imgSizeW);\n\t this['container' + i].y = this.orgY;\n\t }\n\t };\n\t GameView.prototype.createItem = function (type) {\n\t var len = 4;\n\t if (type == 1) {\n\t len = 4;\n\t }\n\t else if (type == 2) {\n\t len = this.prizes.length;\n\t }\n\t for (var j = 0; j < 3; j++) {\n\t this.itemInfo[\"items\" + j] = [];\n\t for (var i = 0; i < len; i++) {\n\t var url = this.prizes[i % this.prizes.length].icon;\n\t var item = new engine.Sprite();\n\t item.texture = engine.Texture.fromImage(url);\n\t this.itemInfo[\"items\" + j][i] = item;\n\t this[\"container\" + j].addChild(item);\n\t item.width = props.imgSizeW;\n\t item.height = props.imgSizeH;\n\t item.x = props.spaceSizeX;\n\t item.y = props.spaceSizeY + i * (props.imgSizeH + props.spaceSizeY);\n\t }\n\t }\n\t };\n\t GameView.prototype.reset = function () {\n\t for (var i = 0; i < 3; i++) {\n\t this[\"container\" + i].y = this.orgY;\n\t }\n\t };\n\t GameView.prototype.start = function () {\n\t var _this = this;\n\t this.prizeId = props.prizeId;\n\t console.log(\"this.prizeId=\", this.prizeId);\n\t var _loop_1 = function (i) {\n\t engine.Tween.removeTweens(this_1[\"container\" + i]);\n\t setTimeout(function () {\n\t engine.Tween.get(_this[\"container\" + i], { loop: true }).to({ y: 0 }, _this.countdown).call(function () {\n\t _this[\"container\" + i].y = _this.orgY;\n\t });\n\t }, this_1.timeSpace * i);\n\t };\n\t var this_1 = this;\n\t for (var i = 0; i < 3; i++) {\n\t _loop_1(i);\n\t }\n\t setTimeout(function () {\n\t var _loop_2 = function (i) {\n\t setTimeout(function () {\n\t _this[\"container\" + i].y = _this.orgY;\n\t engine.Tween.removeTweens(_this[\"container\" + i]);\n\t engine.Tween.get(_this[\"container\" + i]).to({ y: -(props.imgSizeH * 0.5 + props.spaceSizeY) }, 1500);\n\t }, _this.timeSpace * i);\n\t };\n\t for (var i = 0; i < 3; i++) {\n\t _loop_2(i);\n\t }\n\t _this.setPrizePos();\n\t setTimeout(function () {\n\t engine.globalEvent.dispatchEvent('rock-gameover');\n\t }, _this.timeSpace * 2 + 2000);\n\t }, 2500);\n\t };\n\t GameView.prototype.setPrizePos = function () {\n\t var direct = Math.random() > 0.5 ? 1 : -1;\n\t for (var j = 0; j < 3; j++) {\n\t var len = this.itemInfo[\"items\" + j].length;\n\t direct *= -1;\n\t for (var i = 0; i < len; i++) {\n\t var plen = this.prizes.length;\n\t if (direct > 0) {\n\t this.itemInfo[\"items\" + j][i].source = this.prizes[(plen - 1) - (i % plen)].icon;\n\t }\n\t else {\n\t this.itemInfo[\"items\" + j][i].source = this.prizes[(i % plen)].icon;\n\t }\n\t }\n\t }\n\t for (var i = 0; i < 3; i++) {\n\t this.itemInfo[\"items\" + i][1].source = this.getPrizeUrl(this.prizeId);\n\t }\n\t };\n\t GameView.prototype.getPrizeUrl = function (pid) {\n\t for (var _i = 0, _a = this.prizes; _i < _a.length; _i++) {\n\t var prize = _a[_i];\n\t if (prize.prizeId == pid) {\n\t return prize.icon;\n\t }\n\t }\n\t };\n\t GameView.prototype.pause = function () {\n\t };\n\t GameView.prototype.revive = function () {\n\t };\n\t GameView.prototype.resume = function () {\n\t };\n\t GameView.prototype.died = function () {\n\t this.pause();\n\t };\n\t return GameView;\n\t}(engine.Container));\n\n\tvar GameWrapper = (function (_super) {\n\t tslib.__extends(GameWrapper, _super);\n\t function GameWrapper() {\n\t var _this = _super.call(this) || this;\n\t engine.globalEvent.addEventListener('rock-reset', _this.reset, _this);\n\t engine.globalEvent.addEventListener('rock-start', _this.start, _this);\n\t engine.globalEvent.addEventListener('rock-info', _this.rinfo, _this);\n\t return _this;\n\t }\n\t GameWrapper.prototype.reset = function (event) {\n\t injectProps(event.data);\n\t this._gameView.visible = true;\n\t this._gameView.reset();\n\t };\n\t GameWrapper.prototype.start = function (event) {\n\t injectProps(event.data);\n\t this._status = 1;\n\t this._gameView.start();\n\t };\n\t GameWrapper.prototype.rinfo = function (event) {\n\t injectProps(event.data);\n\t console.log(\"event=\", event);\n\t console.log(\"event.data = \", event.data);\n\t var gameView = this._gameView = new GameView();\n\t this.addChild(gameView);\n\t };\n\t GameWrapper.prototype.pause = function () {\n\t this._gameView.pause();\n\t };\n\t GameWrapper.prototype.resume = function () {\n\t this._gameView.resume();\n\t };\n\t GameWrapper.prototype.revive = function () {\n\t this._gameView.revive();\n\t };\n\t GameWrapper.prototype.clear = function () {\n\t this._gameView.visible = false;\n\t };\n\t GameWrapper.prototype.onTap = function (event) {\n\t };\n\t return GameWrapper;\n\t}(engine.Container));\n\n\tfunction index (props) {\n\t prepareProps();\n\t injectProps(props);\n\t var instance = new GameWrapper();\n\t return instance;\n\t}\n\n\treturn index;\n\n})));\n"
}
......@@ -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"
}
{
"name": "缩放滚动",
"props": {
"mvvmMode": {
"alias": "mvvm模式",
"type": "boolean",
"default": false
},
"autoInit": {
"alias": "自动初始化",
"type": "boolean",
......@@ -48,5 +53,5 @@
}
},
"id": "zoom-scroll",
"code": "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ZoomScroll = (function (_super) {\n __extends(ZoomScroll, _super);\n function ZoomScroll() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.autoInit = true;\n _this.duration = 1000;\n _this.index = 0;\n _this.itemWidth = 0;\n _this.itemHeight = 0;\n _this.scaleMin = 0.7;\n _this.scaleMax = 1;\n _this.alphaOut = 0.5;\n _this.alphaIn = 1;\n _this._startDragOffset = { x: 0, y: 0 };\n _this._dragOffset = { x: 0, y: 0 };\n return _this;\n }\n ZoomScroll.prototype.mounted = function () {\n this._centerOffset = this.host.width / 2;\n if (this.autoInit) {\n this.init();\n }\n };\n ZoomScroll.prototype.sleep = function () {\n };\n ZoomScroll.prototype.update = function (t) {\n };\n ZoomScroll.prototype.init = function () {\n for (var i = 0, li = this.host.children.length; i < li; i++) {\n var child = this.host.children[i];\n child.anchorX = child.width / 2;\n child.anchorY = child.height / 2;\n child.x = child.ix = i * this.itemWidth + this._centerOffset - this.itemWidth / 2;\n }\n this.scrollTo(0, false);\n this.host.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDragStart, this);\n };\n ZoomScroll.prototype.updateOffset = function (offset) {\n this._dragOffset.x = this._startDragOffset.x + offset.x;\n for (var i = 0, li = this.host.children.length; i < li; i++) {\n var child = this.host.children[i];\n var x = child.x = child.ix + this._dragOffset.x;\n var s = 40 / Math.abs(x - this._centerOffset + this.itemWidth / 2);\n child.scaleX = child.scaleY = x === 0 ? 1 : Math.min(s + this.scaleMin, this.scaleMax);\n child.alpha = x === 0 ? 1 : Math.min(s + this.alphaOut, this.alphaIn);\n }\n };\n ZoomScroll.prototype.onDragStart = function (event) {\n this.host.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onDraging, this);\n this.host.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.onDragEnd, this);\n this._startDragPos = {\n x: event.stageX,\n y: event.stageY,\n };\n this._startDragOffset.x = this._dragOffset.x;\n this._startDragOffset.y = this._dragOffset.y;\n };\n ZoomScroll.prototype.onDraging = function (event) {\n if (!this._startDragPos) {\n return;\n }\n var _a = this._startDragPos, x = _a.x, y = _a.y;\n var stageX = event.stageX, stageY = event.stageY;\n var offset = {\n x: stageX - x,\n y: stageY - y,\n };\n this.updateOffset(offset);\n };\n ZoomScroll.prototype.onDragEnd = function (event) {\n this.host.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onDraging, this);\n this.host.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.onDragEnd, this);\n if (!this._startDragPos) {\n return;\n }\n this._startDragOffset.x = 0;\n this._startDragOffset.y = 0;\n var index = Math.round(this._dragOffset.x / this.itemWidth);\n index = -Math.min(0, Math.max(1 - this.host.children.length, index));\n this['_index'] = index;\n this.scrollTo(index);\n this._startDragPos = null;\n };\n Object.defineProperty(ZoomScroll.prototype, \"t\", {\n get: function () {\n return this._dragOffset.x;\n },\n set: function (v) {\n this.updateOffset({ x: v, y: 0 });\n },\n enumerable: true,\n configurable: true\n });\n ZoomScroll.prototype.scrollTo = function (index, animation) {\n if (animation === void 0) { animation = true; }\n var indexPos = -index * this.itemWidth;\n if (animation) {\n engine.Tween.get(this, null, null, true)\n .to({ t: indexPos }, 100, engine.Ease.cubicOut);\n }\n else {\n this.t = indexPos;\n }\n };\n ZoomScroll.prototype.onModify = function (value, key, oldValue) {\n var _this = this;\n switch (key) {\n case 'index':\n var index_1 = value;\n if (oldValue !== undefined) {\n index_1 = Math.max(0, Math.min(this.host.children.length - 1, value));\n this['_index'] = index_1;\n }\n setTimeout(function () {\n _this.scrollTo(index_1, oldValue !== undefined);\n });\n break;\n }\n };\n ZoomScroll.id = 'zoom-scroll';\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"index\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"itemWidth\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"itemHeight\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"scaleMin\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"scaleMax\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"alphaOut\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"alphaIn\", void 0);\n return ZoomScroll;\n}(engine.ScriptBase));\nexports.default = ZoomScroll;\n"
"code": "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ZoomScroll = (function (_super) {\n __extends(ZoomScroll, _super);\n function ZoomScroll() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.autoInit = true;\n _this.duration = 1000;\n _this.mvvmMode = false;\n _this.index = 0;\n _this.itemWidth = 0;\n _this.itemHeight = 0;\n _this.scaleMin = 0.7;\n _this.scaleMax = 1;\n _this.alphaOut = 0.5;\n _this.alphaIn = 1;\n _this._startDragOffset = { x: 0, y: 0 };\n _this._dragOffset = { x: 0, y: 0 };\n _this.init = function () {\n for (var i = 0, li = _this.children.length; i < li; i++) {\n var child = _this.children[i];\n child.anchorX = child.width / 2;\n child.anchorY = child.height / 2;\n child.x = child.ix = i * _this.itemWidth + _this._centerOffset - _this.itemWidth / 2;\n }\n _this.scrollTo(0, false);\n };\n return _this;\n }\n ZoomScroll.prototype.mounted = function () {\n this._centerOffset = this.host.width / 2;\n if (this.autoInit) {\n setTimeout(this.init);\n }\n this.host.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDragStart, this);\n };\n Object.defineProperty(ZoomScroll.prototype, \"children\", {\n get: function () {\n return this.mvvmMode ? this.host.children[0].children : this.host.children;\n },\n enumerable: true,\n configurable: true\n });\n ZoomScroll.prototype.updateOffset = function (offset) {\n this._dragOffset.x = this._startDragOffset.x + offset.x;\n for (var i = 0, li = this.children.length; i < li; i++) {\n var child = this.children[i];\n var x = child.x = child.ix + this._dragOffset.x;\n var s = 40 / Math.abs(x - this._centerOffset + this.itemWidth / 2);\n child.scaleX = child.scaleY = x === 0 ? 1 : Math.min(s + this.scaleMin, this.scaleMax);\n child.alpha = x === 0 ? 1 : Math.min(s + this.alphaOut, this.alphaIn);\n }\n };\n ZoomScroll.prototype.onDragStart = function (event) {\n this.host.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onDraging, this);\n this.host.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.onDragEnd, this);\n this._startDragPos = {\n x: event.stageX,\n y: event.stageY,\n };\n this._startDragOffset.x = this._dragOffset.x;\n this._startDragOffset.y = this._dragOffset.y;\n };\n ZoomScroll.prototype.onDraging = function (event) {\n if (!this._startDragPos) {\n return;\n }\n var _a = this._startDragPos, x = _a.x, y = _a.y;\n var stageX = event.stageX, stageY = event.stageY;\n var offset = {\n x: stageX - x,\n y: stageY - y,\n };\n this.updateOffset(offset);\n };\n ZoomScroll.prototype.onDragEnd = function (event) {\n this.host.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onDraging, this);\n this.host.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.onDragEnd, this);\n if (!this._startDragPos) {\n return;\n }\n this._startDragOffset.x = 0;\n this._startDragOffset.y = 0;\n var index = Math.round(this._dragOffset.x / this.itemWidth);\n index = -Math.min(0, Math.max(1 - this.children.length, index));\n this.scrollTo(index);\n this._startDragPos = null;\n };\n Object.defineProperty(ZoomScroll.prototype, \"t\", {\n get: function () {\n return this._dragOffset.x;\n },\n set: function (v) {\n this.updateOffset({ x: v, y: 0 });\n },\n enumerable: true,\n configurable: true\n });\n ZoomScroll.prototype.scrollTo = function (index, animation) {\n var _this = this;\n if (animation === void 0) { animation = true; }\n this['_index'] = index;\n this.host.dispatchEvent('willScroll', { index: index });\n var indexPos = -index * this.itemWidth;\n if (animation) {\n engine.Tween.get(this, null, null, true)\n .to({ t: indexPos }, 100, engine.Ease.cubicOut)\n .call(function () {\n _this.host.dispatchEvent('didScrolled', { index: index });\n });\n }\n else {\n this.t = indexPos;\n this.host.dispatchEvent('didScrolled', { index: index });\n }\n };\n ZoomScroll.prototype.onModify = function (value, key, oldValue) {\n var _this = this;\n switch (key) {\n case 'index':\n var index_1 = value;\n if (oldValue !== undefined) {\n index_1 = Math.max(0, Math.min(this.children.length - 1, value));\n this['_index'] = index_1;\n }\n setTimeout(function () {\n _this.scrollTo(index_1, oldValue !== undefined);\n });\n break;\n }\n };\n ZoomScroll.id = 'zoom-scroll';\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"index\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"itemWidth\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"itemHeight\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"scaleMin\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"scaleMax\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"alphaOut\", void 0);\n __decorate([\n engine.dirtyFieldTrigger\n ], ZoomScroll.prototype, \"alphaIn\", void 0);\n return ZoomScroll;\n}(engine.ScriptBase));\nexports.default = ZoomScroll;\n"
}
......@@ -2,8 +2,10 @@
* 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);
next('success');
\ No newline at end of file
next('success');
......@@ -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",
......@@ -47,4 +52,4 @@
"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