commonui-lib-test
Version:
"#common ui lib test"
252 lines (251 loc) • 8.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_es_1 = require("lodash-es");
const dayjs_1 = require("dayjs");
const popMainten_1 = require("../../../ui/common/popMainten");
const DialogHandler_1 = require("./DialogHandler");
const commonUtils_1 = require("../../external/utils/commonUtils");
var EnumMaintenType;
(function (EnumMaintenType) {
EnumMaintenType[EnumMaintenType["None"] = 0] = "None";
EnumMaintenType[EnumMaintenType["Regular"] = 1] = "Regular";
EnumMaintenType[EnumMaintenType["Temporary"] = 2] = "Temporary";
})(EnumMaintenType || (EnumMaintenType = {}));
/**
* @api {class} MaintenHandler
* @apiName MaintenHandler
* @apiGroup MaintenHandler
* @apiDescription MaintenHandler
*/
class MaintenHandler {
constructor() {
this.initHandler();
}
static get Ins() { return MaintenHandler._instance = MaintenHandler._instance || new MaintenHandler(); }
/**
* @api {function} isInit
* @apiName isInit
* @apiGroup MaintenHandler
* @apiDescription isInit
*/
get isInit() {
return this.view && this.view.inContainer;
}
/**
* @api {function} currMaintenType
* @apiName currMaintenType
* @apiGroup MaintenHandler
* @apiDescription currMaintenType
*/
get currMaintenType() {
return this.view ? this.view.ctrlMaintenTypes.selectedIndex : 0;
}
/**
* @api {function} initHandler
* @apiName initHandler
* @apiGroup MaintenHandler
* @apiDescription initMaintenHandler
*/
initHandler(initCallBack) {
if (!this.view) {
console.warn("initMaintenHandler : init View");
this.createView();
}
if (!this.view.inContainer) {
console.warn("initMaintenHandler : add View");
this.viewUIReady();
}
if (initCallBack)
initCallBack.run();
this.setViewOrder();
}
/**
* @api {function} dispose
* @apiName dispose
* @apiGroup MaintenHandler
* @apiDescription dispose
*/
dispose() {
if (this.view) {
this.stopMaintenTween();
this.view.dispose();
}
this.view = null;
}
/**
* @api {function} createView
* @apiName createView
* @apiGroup MaintenHandler
* @apiDescription createView
*/
createView() {
this.view = popMainten_1.default.createInstance();
this.view.name = "MaintenHandler";
this.view.setSize(fgui.GRoot.inst.width, fgui.GRoot.inst.height);
this.view.addRelation(fgui.GRoot.inst, fgui.RelationType.Size);
}
/**
* @api {function} viewUIReady
* @apiName viewUIReady
* @apiGroup MaintenHandler
* @apiDescription viewUIReady
*/
viewUIReady() {
}
/**
* @api {function} setViewOrder
* @apiName setViewOrder
* @apiGroup MaintenHandler
* @apiDescription setViewOrder
*/
setViewOrder() {
fgui.GRoot.inst.addChild(this.view);
DialogHandler_1.default.Ins.setDialogOrder(this.view);
}
/**
* @api {function} setMaintenOrder
* @apiName setMaintenOrder
* @apiGroup MaintenHandler
* @apiDescription setMaintenOrder
*/
setMaintenOrder(targetView) {
let targetViewIndex = fgui.GRoot.inst.getChildIndex(targetView);
if (this.isInit) {
let selfIndex = fgui.GRoot.inst.getChildIndex(this.view);
targetViewIndex = fgui.GRoot.inst.setChildIndexBefore(targetView, selfIndex);
}
return targetViewIndex;
}
showServerMaintenance(maintenType = 0, timeLeft = 0, onCompleteCB = null) {
if (this.isInit) {
this.setServerMaintenanceData(maintenType, timeLeft, onCompleteCB);
}
else {
if (maintenType === EnumMaintenType.None)
return;
this.initHandler(Laya.Handler.create(this, () => this.setServerMaintenanceData(maintenType, timeLeft, onCompleteCB)));
}
}
/**
* @api {function} setServerMaintenanceData
* @apiName setServerMaintenanceData
* @apiGroup MaintenHandler
* @apiDescription setServerMaintenanceData
*/
setServerMaintenanceData(maintenType, timeLeft, onCompleteCB) {
this.view.ctrlMaintenTypes.selectedIndex = maintenType;
if (maintenType === EnumMaintenType.None) {
this.stopMaintenTween();
}
else {
this.startMaintenTween(timeLeft, onCompleteCB);
}
}
/**
* @api {function} startMaintenTween
* @apiName startMaintenTween
* @apiGroup MaintenHandler
* @apiDescription startMaintenTween
*/
startMaintenTween(timeLeft, onCompleteCB) {
this.stopMaintenTween();
fgui.GTween
.to(timeLeft, 0, lodash_es_1.divide(timeLeft, 1000))
.setEase(fgui.EaseType.Linear)
.setTarget(this.view.comPopMainten)
.onStart(this.onStartMaintenTween, this)
.onUpdate(this.onUpdateMaintenTween, this)
.onComplete(() => this.onCompleteMaintenTween(onCompleteCB), this);
}
/**
* @api {function} stopMaintenTween
* @apiName stopMaintenTween
* @apiGroup MaintenHandler
* @apiDescription stopMaintenTween
*/
stopMaintenTween() {
fgui.GTween.kill(this.view.comPopMainten);
}
/**
* @api {function} onStartMaintenTween
* @apiName onStartMaintenTween
* @apiGroup MaintenHandler
* @apiDescription onStartMaintenTween
*/
onStartMaintenTween(evt) {
let timeLeft = evt.value.x;
let textMainten = null;
switch (this.currMaintenType) {
case EnumMaintenType.Regular:
textMainten = this.view.comPopMainten.textRegular.textTitle;
break;
case EnumMaintenType.Temporary:
textMainten = this.view.comPopMainten.textTemporary.textTitle;
break;
default:
textMainten = this.view.comPopMainten.textRegular.textTitle;
break;
}
let currTimeLeft = dayjs_1.default(timeLeft).format("mm:ss");
textMainten.setVar("time", currTimeLeft).flushVars();
}
/**
* @api {function} onUpdateMaintenTween
* @apiName onUpdateMaintenTween
* @apiGroup MaintenHandler
* @apiDescription onUpdateMaintenTween
*/
onUpdateMaintenTween(evt) {
let timeLeft = evt.value.x;
let textMainten = null;
switch (this.currMaintenType) {
case EnumMaintenType.Regular:
textMainten = this.view.comPopMainten.textRegular.textTitle;
break;
case EnumMaintenType.Temporary:
textMainten = this.view.comPopMainten.textTemporary.textTitle;
break;
default:
textMainten = this.view.comPopMainten.textRegular.textTitle;
break;
}
this.setMaintenTimeText(textMainten, timeLeft);
}
/**
* @api {function} onCompleteMaintenTween
* @apiName onCompleteMaintenTween
* @apiGroup MaintenHandler
* @apiDescription onCompleteMaintenTween
*/
onCompleteMaintenTween(onCompleteCB) {
if (onCompleteCB)
onCompleteCB();
}
/**
* @api {function} setMaintenTimeText
* @apiName setMaintenTimeText
* @apiGroup MaintenHandler
* @apiDescription setMaintenTimeText
*/
setMaintenTimeText(textMainten, timeLeft) {
let templateVars = textMainten.templateVars;
let currTimeLeft = dayjs_1.default(timeLeft).format("mm:ss");
if (currTimeLeft >= templateVars.time)
return;
textMainten.setVar("time", currTimeLeft).flushVars();
// let templateVars = { time: currTimeLeft };
// textMainten.templateVars = templateVars;
}
/**
* @api {function} checkTimeLeft
* @apiName checkTimeLeft
* @apiGroup MaintenHandler
* @apiDescription checkTimeLeft
*/
checkTimeLeft(preTimeLeft, currTimeLeft) {
let pTimeLeft = commonUtils_1.default.convertString2Numeral(preTimeLeft);
let cTimeLeft = commonUtils_1.default.convertString2Numeral(currTimeLeft);
return cTimeLeft > pTimeLeft;
}
}
exports.default = MaintenHandler;