add uiManager auto scan and load skin resource

This commit is contained in:
Vick Scarlet
2021-11-07 23:00:22 +08:00
parent 22fa5d755a
commit 2666983f89
5 changed files with 25 additions and 19 deletions

View File

@ -42,7 +42,7 @@
{
"x":15,
"type":"Button",
"props":{"y":200,"var":"btnBack","skin":"images/button/button_back@3x.png","left":30},
"props":{"y":200,"var":"btnBack","skin":"images/button/button_back@3x.png","name":"btnBack","left":30},
"nodeParent":1,
"label":"Button(btnBack)",
"isDirectory":false,

View File

@ -40,7 +40,9 @@ class App{
Laya.Text.langPacks = (await import(`./i18n/${this.#language}.js`)).default;
}
async start(language = App.languages['zh-cn']) {
async start({
language = App.languages['zh-cn']
}) {
this.#initLaya();
const uiManager = UIManager.getInstance();
uiManager.themes = ViewTypes.themes.default;
@ -55,21 +57,6 @@ class App{
"images/atlas/images/button.atlas",
"images/atlas/images/icons.atlas",
"images/atlas/images/progress.atlas",
"images/background/background_1@3x.png",
"images/background/background_2@3x.png",
"images/accessories/insert_coin@3x.png",
"images/accessories/title@3x.png",
"images/accessories/titlebar@3x.png",
"images/border/achievement_complete@3x.png",
"images/border/border_1@3x.png",
"images/border/border_2@3x.png",
"images/border/card@3x.png",
"images/border/talent_item@3x.png",
"images/border/talent_item_selected@3x.png",
"images/border/up@3x.png",
"images/button/button_main@3x.png",
"images/slider/vslider_1@3x$bar.png",
"images/slider/vslider_1@3x.png",
]
});
}

View File

@ -12,4 +12,4 @@ location.search.substr(1).split('&').forEach(item => {
query[parts[0]] = parts[1];
});
game.start(query.lang);
game.start(query);

File diff suppressed because one or more lines are too long

View File

@ -72,6 +72,12 @@ class UIManager {
// load view
const ViewClass = await this.loadView(viewName);
const resourceList = await ViewClass.load?.(args);
const scanedResourceList = this.#loading? this.scanResource(ViewClass.uiView): [];
if(preload) {
preload = [].concat(preload).concat(scanedResourceList);
} else {
preload = scanedResourceList;
}
await this.loadRes(resourceList, preload, onProgress);
// create view
@ -127,4 +133,17 @@ class UIManager {
clearAllDialog() {
this.#dialogLayer.removeChildren();
}
scanResource(uiView) {
if(!uiView) return [];
const resourceList = [];
if(uiView.props?.skin) {
resourceList.push(uiView.props.skin);
}
uiView.child?.forEach(child => {
resourceList.push(...this.scanResource(child));
});
return resourceList;
}
}