Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 109 additions & 1 deletion demo/bin/libs/fairygui/fairygui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14922,6 +14922,114 @@
}
})(fgui);

(function (fgui) {
var Texture = Laya.Texture;
var HTMLImageElement = Laya.HTMLImageElement;
const proto = HTMLImageElement.prototype;
const reset = proto.reset;
const src = Object.getOwnPropertyDescriptor(proto, 'src').set;
Object.defineProperties(proto, {
// @Overwrite
reset: {
// Call in constructor and destroy
value() {
return reset.call(this._stop()._resetAni());
}
},
_resetAni: {
value() {
this._tex = null;
this._frame = 0;
this._reverse = false;
this._pi = null;
return this;
}
},
_stop: {
value() {
Laya.timer.clear(this, this._drawImage);
return this;
}
},
_drawImage: {
value(graphic, gX, gY) {
let tex = this._tex;
if (!tex || !tex.getIsReady())
return;
if (!this.parent || this.parent._children.length === 0) {
// TODO I think there have a bug in laya, So I wrote this code
// Detail: https://github.com/porky-prince/LayaAir/commit/dd565d30b8d43f453bb784d0c63d978fca8375de
this._stop();
return;
}
const width = this.width || tex.width;
const height = this.height || tex.height;
const pi = this._pi;
if (pi) {
const frames = pi.load();
const curFrame = frames[this._frame];
let delay = pi.interval + curFrame.addDelay;
const border = !this._reverse ? frames.length - 1 : 0;
const i = !this._reverse ? 1 : -1;
if (this._frame === border) {
if (pi.swing) {
this._reverse = !this._reverse;
this._frame -= i;
}
else {
this._frame = 0;
}
delay += pi.repeatDelay;
}
else {
this._frame += i;
}
this._tex = frames[this._frame].texture; // Next frame
Laya.timer.once(delay, this, this._drawImage, [graphic, gX, gY]);
}
graphic.drawImage(tex, gX, gY, width, height);
}
},
// @Overwrite
renderSelfToGraphic: {
value(graphic, gX, gY) {
this._stop()._drawImage(graphic, gX, gY);
}
},
// @Overwrite
src: {
set(url) {
if (fgui.ToolSet.startsWith(url, "ui://")) {
if (this._url === url)
return;
this._stop()._resetAni();
const pi = fgui.UIPackage.getItemByURL(url);
let tex = null;
// Asset must be preloaded
if (pi) {
const asset = pi.load();
if (asset instanceof Texture) {
tex = asset;
}
else if (pi.type === fgui.PackageItemType.MovieClip && Array.isArray(asset) && asset.length > 0) {
// Assuming that each texture is the same size, just layout once
tex = asset[0].texture;
if (asset.length > 1)
this._pi = pi;
}
this._tex = tex;
tex && this.onloaded();
}
}
else {
// Dynamic loading asset
src.call(this, url);
}
}
}
});
})(fgui);

(function (fgui) {
class Image extends Laya.Sprite {
constructor() {
Expand Down Expand Up @@ -17648,7 +17756,7 @@
if (pos1 < this._text.length)
result += this._text.substr(pos1);
this._text = null;
return result;
return result.replace(/\n/g, '<br>');
}
}
UBBParser.inst = new UBBParser();
Expand Down
2 changes: 2 additions & 0 deletions demo/libs/fairygui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,8 @@ declare namespace fgui {
declare namespace fgui {
function fillImage(w: number, h: number, method: number, origin: number, clockwise: boolean, amount: number): number[];
}
declare namespace fgui {
}
declare namespace fgui {
class Image extends Laya.Sprite {
protected _source: Laya.Texture;
Expand Down
2 changes: 2 additions & 0 deletions source/bin/fairygui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,8 @@ declare namespace fgui {
declare namespace fgui {
function fillImage(w: number, h: number, method: number, origin: number, clockwise: boolean, amount: number): number[];
}
declare namespace fgui {
}
declare namespace fgui {
class Image extends Laya.Sprite {
protected _source: Laya.Texture;
Expand Down
110 changes: 109 additions & 1 deletion source/bin/fairygui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14922,6 +14922,114 @@
}
})(fgui);

(function (fgui) {
var Texture = Laya.Texture;
var HTMLImageElement = Laya.HTMLImageElement;
const proto = HTMLImageElement.prototype;
const reset = proto.reset;
const src = Object.getOwnPropertyDescriptor(proto, 'src').set;
Object.defineProperties(proto, {
// @Overwrite
reset: {
// Call in constructor and destroy
value() {
return reset.call(this._stop()._resetAni());
}
},
_resetAni: {
value() {
this._tex = null;
this._frame = 0;
this._reverse = false;
this._pi = null;
return this;
}
},
_stop: {
value() {
Laya.timer.clear(this, this._drawImage);
return this;
}
},
_drawImage: {
value(graphic, gX, gY) {
let tex = this._tex;
if (!tex || !tex.getIsReady())
return;
if (!this.parent || this.parent._children.length === 0) {
// TODO I think there have a bug in laya, So I wrote this code
// Detail: https://github.com/porky-prince/LayaAir/commit/dd565d30b8d43f453bb784d0c63d978fca8375de
this._stop();
return;
}
const width = this.width || tex.width;
const height = this.height || tex.height;
const pi = this._pi;
if (pi) {
const frames = pi.load();
const curFrame = frames[this._frame];
let delay = pi.interval + curFrame.addDelay;
const border = !this._reverse ? frames.length - 1 : 0;
const i = !this._reverse ? 1 : -1;
if (this._frame === border) {
if (pi.swing) {
this._reverse = !this._reverse;
this._frame -= i;
}
else {
this._frame = 0;
}
delay += pi.repeatDelay;
}
else {
this._frame += i;
}
this._tex = frames[this._frame].texture; // Next frame
Laya.timer.once(delay, this, this._drawImage, [graphic, gX, gY]);
}
graphic.drawImage(tex, gX, gY, width, height);
}
},
// @Overwrite
renderSelfToGraphic: {
value(graphic, gX, gY) {
this._stop()._drawImage(graphic, gX, gY);
}
},
// @Overwrite
src: {
set(url) {
if (fgui.ToolSet.startsWith(url, "ui://")) {
if (this._url === url)
return;
this._stop()._resetAni();
const pi = fgui.UIPackage.getItemByURL(url);
let tex = null;
// Asset must be preloaded
if (pi) {
const asset = pi.load();
if (asset instanceof Texture) {
tex = asset;
}
else if (pi.type === fgui.PackageItemType.MovieClip && Array.isArray(asset) && asset.length > 0) {
// Assuming that each texture is the same size, just layout once
tex = asset[0].texture;
if (asset.length > 1)
this._pi = pi;
}
this._tex = tex;
tex && this.onloaded();
}
}
else {
// Dynamic loading asset
src.call(this, url);
}
}
}
});
})(fgui);

(function (fgui) {
class Image extends Laya.Sprite {
constructor() {
Expand Down Expand Up @@ -17648,7 +17756,7 @@
if (pos1 < this._text.length)
result += this._text.substr(pos1);
this._text = null;
return result;
return result.replace(/\n/g, '<br>');
}
}
UBBParser.inst = new UBBParser();
Expand Down
2 changes: 1 addition & 1 deletion source/src/fairygui/AssetProxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace fgui {
export class AssetProxy {

private _asset: any;
private _asset: Laya.LoaderManager;

constructor() {
this._asset = Laya.loader;
Expand Down
102 changes: 102 additions & 0 deletions source/src/fairygui/display/HTMLImageElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
namespace fgui {
import Texture = Laya.Texture;
import HTMLImageElement = Laya.HTMLImageElement;
const proto: HTMLImageElement = HTMLImageElement.prototype;
const reset: Function = proto.reset;
const src: Function = Object.getOwnPropertyDescriptor(proto, 'src').set;

Object.defineProperties(proto, {
// @Overwrite
reset: {
// Call in constructor and destroy
value(): HTMLImageElement {
return reset.call(this._stop()._resetAni());
}
},
_resetAni: {
value(): HTMLImageElement {
this._tex = null;
this._frame = 0;
this._reverse = false;
this._pi = null;
return this;
}
},
_stop: {
value(): HTMLImageElement {
Laya.timer.clear(this, this._drawImage);
return this;
}
},
_drawImage: {
value(graphic: Laya.Graphics, gX: number, gY: number): void {
let tex = this._tex;
if (!tex || !tex.getIsReady()) return;
if (!this.parent || this.parent._children.length === 0) {
// TODO I think there have a bug in laya, So I wrote this code
// Detail: https://github.com/porky-prince/LayaAir/commit/dd565d30b8d43f453bb784d0c63d978fca8375de
this._stop();
return;
}
const width: number = this.width || tex.width;
const height: number = this.height || tex.height;
const pi: PackageItem = this._pi;
if (pi) {
const frames = pi.load() as Frame[];
const curFrame: Frame = frames[this._frame];
let delay: number = pi.interval + curFrame.addDelay;
const border: number = !this._reverse ? frames.length - 1 : 0;
const i: number = !this._reverse ? 1 : -1;
if (this._frame === border) {
if (pi.swing) {
this._reverse = !this._reverse;
this._frame -= i;
} else {
this._frame = 0;
}
delay += pi.repeatDelay;
} else {
this._frame += i;
}

this._tex = frames[this._frame].texture;// Next frame
Laya.timer.once(delay, this, this._drawImage, [graphic, gX, gY]);
}
graphic.drawImage(tex, gX, gY, width, height);
}
},
// @Overwrite
renderSelfToGraphic: {
value(graphic: Laya.Graphics, gX: number, gY: number): void {
this._stop()._drawImage(graphic, gX, gY);
}
},
// @Overwrite
src: {
set(url: string) {
if (ToolSet.startsWith(url, "ui://")) {
if (this._url === url) return;
this._stop()._resetAni();
const pi: PackageItem = UIPackage.getItemByURL(url);
let tex: Texture = null;
// Asset must be preloaded
if (pi) {
const asset: Object = pi.load();
if (asset instanceof Texture) {
tex = asset;
} else if (pi.type === PackageItemType.MovieClip && Array.isArray(asset) && asset.length > 0) {
// Assuming that each texture is the same size, just layout once
tex = asset[0].texture;
if (asset.length > 1) this._pi = pi;
}
this._tex = tex;
tex && this.onloaded();
}
} else {
// Dynamic loading asset
src.call(this, url);
}
}
}
});
}
2 changes: 1 addition & 1 deletion source/src/fairygui/utils/UBBParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ namespace fgui {

this._text = null;

return result;
return result.replace(/\n/g, '<br>');
}
}
}