Commit 19aa4721 authored by wjf's avatar wjf

l

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