phaser3-rex-plugins
Version:
47 lines (36 loc) • 1.08 kB
JavaScript
import CreateTab from '../builders/CreateTab.js';
const GetValue = Phaser.Utils.Objects.GetValue;
var AddTab = function (config) {
if (config === undefined) {
config = {};
}
// Create tab
var tabStyle = GetValue(this.styles, 'tab') || {};
var tab = CreateTab(this, config, tabStyle);
// Add tab
this.add(
tab,
{
proportion: (tab.minWidth === 0) ? 1 : 0,
expand: true
}
);
var pagesConfig = GetValue(config, 'pages') || [];
var pages = [];
var shownPageIndex = 0;
for (var i = 0, cnt = pagesConfig.length; i < cnt; i++) {
var childTweaker = tab.getPage(i);
var isPageShown = pagesConfig[i].show;
if (isPageShown) {
shownPageIndex = i;
}
var key = pagesConfig[i].key;
if (key) {
this.root.addChildrenMap(key, childTweaker);
}
pages.push(childTweaker);
}
tab.swapPage(shownPageIndex, 0);
return pages;
}
export default AddTab;