Skip to content

Commit

Permalink
Merge branch 'sound'
Browse files Browse the repository at this point in the history
  • Loading branch information
runinspring committed Sep 24, 2019
2 parents 2a308d1 + 9817ce3 commit 1833c81
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/HtmlSound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,12 @@ namespace egret.baidugame {
* @inheritDoc
*/
public close() {
if (this.loaded == false && this.originAudio)
if (this.loaded && this.originAudio)
this.originAudio.src = "";
if (this.originAudio)
this.originAudio = null;
HtmlSound.$clear(this.url);
this.loaded = false;
}

/**
Expand Down
88 changes: 80 additions & 8 deletions src/WebFps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,63 @@ namespace egret.baidugame {
* @private
*/
let fpsText = new egret.TextField();
/**
* @private
*/
let logText = new egret.TextField();


/**
* @private
*/
export class WebFps extends egret.DisplayObject implements egret.FPSDisplay {

private bg: egret.Shape
private showFPS: boolean
private showLog: boolean
constructor(stage: Stage, showFPS: boolean, showLog: boolean, logFilter: string, styles: Object) {
super();
if (!showFPS) {
if (!showFPS && !showLog) {
return;
}
this.showFPS = showFPS;
this.showLog = showLog
this.arrFps = [];
this.arrCost = [];
fpsText.x = styles["x"] == undefined ? 0 : parseInt(styles["x"]);
fpsText.y = styles["y"] == undefined ? 0 : parseInt(styles["y"]);
fpsText.textColor = styles["textColor"] == undefined ? '#ffffff' : styles['textColor'].replace("0x", "#");

let tx = styles["x"] == undefined ? 0 : parseInt(styles["x"]);
let ty = styles["y"] == undefined ? 0 : parseInt(styles["y"]);
let bgAlpha = styles["bgAlpha"] == undefined ? 1 : Number(styles["bgAlpha"]);
let fontSize = styles["size"] == undefined ? 12 : parseInt(styles['size']);
fpsText.size = fontSize;
let fontColor = styles["textColor"] === undefined ? 0x000000 : parseInt(styles['textColor'].replace("#", "0x"));
let bg = new egret.Shape();
this.bg = bg;
bg.graphics.beginFill(0x000000, bgAlpha)
bg.graphics.drawRect(0, 0, 10, 10)
bg.graphics.endFill();
bg.x = tx;
bg.y = ty;
if (showFPS) {
fpsText.x = tx + 4;
fpsText.y = ty + 4;
fpsText.textColor = fontColor;
fpsText.size = fontSize;
}
if (showLog) {
logText.x = tx + 4;
logText.y = ty + 4;
logText.textColor = fontColor;
logText.size = fontSize;
}
}

private addText() {
egret.sys.$TempStage.addChild(this.bg);
if (this.showFPS) {
egret.sys.$TempStage.addChild(fpsText);
}
if (this.showLog) {
egret.sys.$TempStage.addChild(logText);
}
}

private addFps() {
Expand Down Expand Up @@ -102,14 +139,49 @@ namespace egret.baidugame {
+ `min:${fpsMin} max:${fpsMax} avg:${fpsAvg}\n`
+ `Draw ${this.lastNumDraw}\n`
+ `Cost ${numCostTicker} ${numCostRender}`;
egret.sys.$TempStage.addChild(fpsText);
};
this.resizeBG()
}

private resizeBG() {
this.addText();
let bgScaleX: number = 0;
let bgScaclY: number = 0;
if (this.showFPS && this.showLog) {
bgScaleX = Math.ceil((Math.max(fpsText.width, logText.width) + 8) / 10);
bgScaclY = Math.ceil((fpsText.height + logText.height + 8) / 10);
logText.y = this.bg.y + 4 + fpsText.height;
} else if (this.showFPS) {
bgScaleX = Math.ceil((fpsText.width + 8) / 10);
bgScaclY = Math.ceil((fpsText.height + 8) / 10);
} else {
bgScaleX = Math.ceil((logText.width + 8) / 10);
bgScaclY = Math.ceil((logText.height + 8) / 10);
logText.y = this.bg.y + 4;
}
this.bg.scaleX = bgScaleX;
this.bg.scaleY = bgScaclY;
}

private arrLog: string[] = [];
public updateInfo(info: string) {
this.arrLog.push(info);
this.updateLogLayout();
}
public updateWarn(info: string) {
this.arrLog.push("[Warning]" + info);
this.updateLogLayout();
}
public updateError(info: string) {
this.arrLog.push("[Error]" + info);
this.updateLogLayout();
}
private updateLogLayout(): void {
logText.text = this.arrLog.join('\n');
if (egret.sys.$TempStage.height < (logText.y + logText.height + logText.size * 2)) {
this.arrLog.shift();
logText.text = this.arrLog.join('\n');
}
this.resizeBG();
}
}
egret.FPSDisplay = WebFps;
Expand Down
86 changes: 78 additions & 8 deletions target/template/egret.baidugame.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,12 @@ r.prototype = e.prototype, t.prototype = new r();
* @inheritDoc
*/
HtmlSound.prototype.close = function () {
if (this.loaded == false && this.originAudio)
if (this.loaded && this.originAudio)
this.originAudio.src = "";
if (this.originAudio)
this.originAudio = null;
HtmlSound.$clear(this.url);
this.loaded = false;
};
HtmlSound.$clear = function (url) {
HtmlSound.clearAudios[url] = true;
Expand Down Expand Up @@ -3047,6 +3048,10 @@ egret.Capabilities["runtimeType" + ""] = "baidugame";
* @private
*/
var fpsText = new egret.TextField();
/**
* @private
*/
var logText = new egret.TextField();
/**
* @private
*/
Expand All @@ -3056,18 +3061,49 @@ egret.Capabilities["runtimeType" + ""] = "baidugame";
var _this = _super.call(this) || this;
_this.arrFps = [];
_this.arrCost = [];
if (!showFPS) {
_this.arrLog = [];
if (!showFPS && !showLog) {
return _this;
}
_this.showFPS = showFPS;
_this.showLog = showLog;
_this.arrFps = [];
_this.arrCost = [];
fpsText.x = styles["x"] == undefined ? 0 : parseInt(styles["x"]);
fpsText.y = styles["y"] == undefined ? 0 : parseInt(styles["y"]);
fpsText.textColor = styles["textColor"] == undefined ? '#ffffff' : styles['textColor'].replace("0x", "#");
var tx = styles["x"] == undefined ? 0 : parseInt(styles["x"]);
var ty = styles["y"] == undefined ? 0 : parseInt(styles["y"]);
var bgAlpha = styles["bgAlpha"] == undefined ? 1 : Number(styles["bgAlpha"]);
var fontSize = styles["size"] == undefined ? 12 : parseInt(styles['size']);
fpsText.size = fontSize;
var fontColor = styles["textColor"] === undefined ? 0x000000 : parseInt(styles['textColor'].replace("#", "0x"));
var bg = new egret.Shape();
_this.bg = bg;
bg.graphics.beginFill(0x000000, bgAlpha);
bg.graphics.drawRect(0, 0, 10, 10);
bg.graphics.endFill();
bg.x = tx;
bg.y = ty;
if (showFPS) {
fpsText.x = tx + 4;
fpsText.y = ty + 4;
fpsText.textColor = fontColor;
fpsText.size = fontSize;
}
if (showLog) {
logText.x = tx + 4;
logText.y = ty + 4;
logText.textColor = fontColor;
logText.size = fontSize;
}
return _this;
}
WebFps.prototype.addText = function () {
egret.sys.$TempStage.addChild(this.bg);
if (this.showFPS) {
egret.sys.$TempStage.addChild(fpsText);
}
if (this.showLog) {
egret.sys.$TempStage.addChild(logText);
}
};
WebFps.prototype.addFps = function () {
};
WebFps.prototype.addLog = function () {
Expand Down Expand Up @@ -3112,14 +3148,48 @@ egret.Capabilities["runtimeType" + ""] = "baidugame";
+ ("min:" + fpsMin + " max:" + fpsMax + " avg:" + fpsAvg + "\n")
+ ("Draw " + this.lastNumDraw + "\n")
+ ("Cost " + numCostTicker + " " + numCostRender);
egret.sys.$TempStage.addChild(fpsText);
this.resizeBG();
};
WebFps.prototype.resizeBG = function () {
this.addText();
var bgScaleX = 0;
var bgScaclY = 0;
if (this.showFPS && this.showLog) {
bgScaleX = Math.ceil((Math.max(fpsText.width, logText.width) + 8) / 10);
bgScaclY = Math.ceil((fpsText.height + logText.height + 8) / 10);
logText.y = this.bg.y + 4 + fpsText.height;
}
else if (this.showFPS) {
bgScaleX = Math.ceil((fpsText.width + 8) / 10);
bgScaclY = Math.ceil((fpsText.height + 8) / 10);
}
else {
bgScaleX = Math.ceil((logText.width + 8) / 10);
bgScaclY = Math.ceil((logText.height + 8) / 10);
logText.y = this.bg.y + 4;
}
this.bg.scaleX = bgScaleX;
this.bg.scaleY = bgScaclY;
};
;
WebFps.prototype.updateInfo = function (info) {
this.arrLog.push(info);
this.updateLogLayout();
};
WebFps.prototype.updateWarn = function (info) {
this.arrLog.push("[Warning]" + info);
this.updateLogLayout();
};
WebFps.prototype.updateError = function (info) {
this.arrLog.push("[Error]" + info);
this.updateLogLayout();
};
WebFps.prototype.updateLogLayout = function () {
logText.text = this.arrLog.join('\n');
if (egret.sys.$TempStage.height < (logText.y + logText.height + logText.size * 2)) {
this.arrLog.shift();
logText.text = this.arrLog.join('\n');
}
this.resizeBG();
};
return WebFps;
}(egret.DisplayObject));
Expand Down

0 comments on commit 1833c81

Please sign in to comment.