Commit 19aa4721 authored by wjf's avatar wjf

l

parent b5f88d29
...@@ -134,11 +134,15 @@ export namespace RES { ...@@ -134,11 +134,15 @@ export namespace RES {
} }
// 建一个promise // 建一个promise
let p = new Promise((resolve, reject) => { let p = new Promise((resolve, reject) => {
loadResList(() => { loadResList((allLoaded: boolean) => {
groupsCompleteHash[name] = true;
//移除 //移除
delete groupsPromiseHash[name]; delete groupsPromiseHash[name];
if (allLoaded) {
groupsCompleteHash[name] = true;//都加载完成就标记
resolve() resolve()
} else {
reject();
}
}, arr/*, resPath + name*/) }, arr/*, resPath + name*/)
}) })
groupsPromiseHash[name] = p; groupsPromiseHash[name] = p;
...@@ -421,14 +425,17 @@ export namespace RES { ...@@ -421,14 +425,17 @@ export namespace RES {
* @param callback * @param callback
* @param arr * @param arr
*/ */
function loadResList(callback: Function, arr: string[]) { function loadResList(callback: (allLoaded: boolean) => void, arr: string[]) {
let count = 0; let count = 0;
let countAll = arr.length; let countAll = arr.length;
if (!countAll) callback(); if (!countAll) callback(true);
let mark = true
for (var i = 0; i < countAll; i++) { for (var i = 0; i < countAll; i++) {
let res = arr[i]; let resName = arr[i];
getResAsync(res, () => { getResAsync(resName, (res) => {
if (++count == countAll) callback(); //标记失败,如果有一项资源加载失败,标记下
if (!res) mark = false
if (++count == countAll) callback(mark);
}, this) }, this)
} }
} }
......
...@@ -29,15 +29,15 @@ export default class PanelCtrl { ...@@ -29,15 +29,15 @@ export default class PanelCtrl {
init(parent: Container) { init(parent: Container) {
this._parent = parent; this._parent = parent;
let bg = new Graphics(); let bg = new Graphics()
bg.beginFill(0, 1); .beginFill(0, 1)
bg.drawRect( .drawRect(
layers.stageOffsetX - parent.x, layers.stageOffsetX - parent.x,
layers.stageOffsetY - parent.y, layers.stageOffsetY - parent.y,
layers.stageWidth, layers.stageWidth,
layers.stageHeight layers.stageHeight
); )
bg.endFill(); .endFill();
bg.visible = false; bg.visible = false;
this._parent.addChild(bg); this._parent.addChild(bg);
this._bg = bg; this._bg = bg;
......
...@@ -10,13 +10,20 @@ import { RES } from "../RES"; ...@@ -10,13 +10,20 @@ import { RES } from "../RES";
let inited = false; let inited = false;
let _toast: Toast; let _toast: Toast;
let _parent: Container let _parent: Container;
let startY: number//动画开始位置
let endY: number//动画结束位置
const initToast = () => { const initToast = () => {
if (!inited) { if (!inited) {
inited = true; inited = true;
_toast = new Toast(); _toast = new Toast();
_parent = layers.toastLayer; _parent = layers.toastLayer;
_toast.alpha = 0; _toast.alpha = 0;
_toast.x = layers.stageOffsetX - _parent.x + (layers.stageWidth - _toast.width) / 2;
var h = _toast.height;
var y = layers.stageOffsetY - _parent.y;
startY = y - h;
endY = y + (layers.stageHeight - h) / 2;
} }
} }
export const showToast = (msg: string) => { export const showToast = (msg: string) => {
...@@ -25,8 +32,8 @@ export const showToast = (msg: string) => { ...@@ -25,8 +32,8 @@ export const showToast = (msg: string) => {
_parent.addChild(_toast); _parent.addChild(_toast);
Tween.removeTweens(_toast); Tween.removeTweens(_toast);
Tween.get(_toast)//动画看需求 Tween.get(_toast)//动画看需求
.set({ y: -200, alpha: 1 }) .set({ y: startY, alpha: 1 })
.to({ y: 400 }, 500, Ease.quartOut) .to({ y: endY }, 500, Ease.quartOut)
.wait(800) .wait(800)
.to({ alpha: 0 }, 300) .to({ alpha: 0 }, 300)
.call(() => { .call(() => {
...@@ -58,7 +65,7 @@ class Toast extends Container { ...@@ -58,7 +65,7 @@ class Toast extends Container {
this.mouseEnable = false; this.mouseEnable = false;
var toastBgTexture: Texture = RES.getRes("toastBg.png"); var toastBgTexture: Texture = RES.getRes("toastBg.png");
this.bg = new Sprite(toastBgTexture); this.bg = new Sprite(toastBgTexture);
this.bg.x = (layers.stageWidth - this.bg.width) / 2 // this.bg.x = (layers.stageWidth - this.bg.width) / 2
this.addChild(this.bg); this.addChild(this.bg);
this.msg = new TextField(); this.msg = new TextField();
this.msg.size = 28; this.msg.size = 28;
...@@ -76,7 +83,7 @@ class Toast extends Container { ...@@ -76,7 +83,7 @@ class Toast extends Container {
show(msg: string) { show(msg: string) {
this.msg.text = msg; this.msg.text = msg;
//文本居中适配 //文本居中适配
this.msg.x = (layers.stageWidth - this.msg.textWidth) / 2; this.msg.x = (this.bg.width - this.msg.textWidth) / 2//(layers.stageWidth - this.msg.textWidth) / 2;
//是否需要根据文本宽度缩放背景 //是否需要根据文本宽度缩放背景
// this.bg.width = Math.min(this.msg.textWidth + this.PADDING * 2, 523); // this.bg.width = Math.min(this.msg.textWidth + this.PADDING * 2, 523);
//背景居中适配,由于上面一行注释,那这行就构造函数里只执行一次吧 //背景居中适配,由于上面一行注释,那这行就构造函数里只执行一次吧
......
...@@ -18,6 +18,19 @@ const initWaiting = () => { ...@@ -18,6 +18,19 @@ const initWaiting = () => {
const waiting = new Waiting(); const waiting = new Waiting();
_parent = layers.topLayer; _parent = layers.topLayer;
_waiting = waiting; _waiting = waiting;
//居中偏移
var offX = (layers.stageWidth - _waiting.width) / 2;
var offY = (layers.stageHeight - _waiting.height) / 2;
//位置适配
_waiting.x = layers.stageOffsetX - _parent.x + offX;
_waiting.y = layers.stageOffsetY - _parent.y + offY;
//阻止事件用
var bg: Graphics = new Graphics()
.beginFill(0x000000)
.drawRect(-offX, -offY, layers.stageWidth, layers.stageHeight)
.endFill();
bg.alpha = 0;
_waiting.addChildAt(bg, 0);
} }
} }
/** /**
...@@ -53,22 +66,14 @@ class Waiting extends Container { ...@@ -53,22 +66,14 @@ class Waiting extends Container {
msg: TextField; msg: TextField;
constructor() { constructor() {
super(); super();
//阻止事件用
var bg: Graphics = new Graphics();
bg.beginFill(0x000000, 0);
bg.drawRect(0, 0, 750, 1624);
bg.endFill();
this.addChild(bg);
//圆角矩形背景 //圆角矩形背景
var rectBgTexture: Texture = RES.getRes("waitingBg.png") var rectBgTexture: Texture = RES.getRes("waitingBg.png")
var rectBg = new Sprite(rectBgTexture); var rectBg = new Sprite(rectBgTexture);
rectBg.x = (layers.stageWidth - rectBgTexture.width) / 2;
rectBg.y = 486;//高度看需求,到时可以居中
this.addChild(rectBg); this.addChild(rectBg);
var rotTexture: Texture = RES.getRes("waitingRot.png") var rotTexture: Texture = RES.getRes("waitingRot.png")
let rot = new Sprite(rotTexture); let rot = new Sprite(rotTexture);
rot.x = (layers.stageWidth - rotTexture.width) / 2; rot.x = (rectBgTexture.width - rotTexture.width) / 2
rot.y = 533; rot.y = 47// 533;
rot.anchorX = rotTexture.width / 2; rot.anchorX = rotTexture.width / 2;
rot.anchorY = rotTexture.height / 2; rot.anchorY = rotTexture.height / 2;
this.addChild(rot); this.addChild(rot);
...@@ -78,9 +83,8 @@ class Waiting extends Container { ...@@ -78,9 +83,8 @@ class Waiting extends Container {
if (count % 30 == 0) rot.rotation += 45; if (count % 30 == 0) rot.rotation += 45;
}, this) }, this)
this.msg = new TextField(); this.msg = new TextField();
this.msg.x = 295; this.msg.y = 125;
this.msg.y = 611; this.msg.textWidth = rectBgTexture.width;
this.msg.textWidth = 160
this.msg.textAlign = TEXT_ALIGN.CENTER; this.msg.textAlign = TEXT_ALIGN.CENTER;
this.msg.size = 26 this.msg.size = 26
this.msg.fillColor = "#ffffff"; this.msg.fillColor = "#ffffff";
......
...@@ -30,13 +30,13 @@ export class Module extends Container { ...@@ -30,13 +30,13 @@ export class Module extends Container {
* 提前加载的资源 * 提前加载的资源
*/ */
protected preLoadRes() { protected preLoadRes() {
return new Promise(async (resolve, reject) => { return new Promise((resolve, reject) => {
if (this.groupNames && this.groupNames.length) { if (this.groupNames && this.groupNames.length) {
var arr: Promise<any>[] = []; var arr: Promise<any>[] = [];
for (var i = 0; i < this.groupNames.length; i++) { for (var i = 0; i < this.groupNames.length; i++) {
arr.push(RES.loadGroup(this.groupNames[i])) arr.push(RES.loadGroup(this.groupNames[i]))
} }
Promise.all(arr).then(() => { resolve() }) Promise.all(arr).then(resolve, reject)
} else { } else {
resolve() resolve()
} }
......
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