1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import UIToastMessage from "../../ui/uiview/common/UIToastMessage";
- import { ViewZorder } from "../constant/ViewZOrder";
- import UIBase, { UIClass } from "./UIBase";
- import UIMng from "./UIMng";
- /**确定框界面参数 */
- export interface DialogParams {
- title: string,
- content: string,
- certainCb?: Function,
- cancelCb?: Function
- }
- export default class UIHelp {
- public static SetLabel(node: cc.Node, value: string | number) {
- if (typeof value === 'number') {
- value = value.toString();
- } else if (value == undefined) {
- value = "";
- }
- // 文本和富文本只能二选一
- if (node.getComponent(cc.RichText)) {
- let defaultColor = node.color.toHEX('#rrggbb');
- node.getComponent(cc.RichText).string = `<color=${defaultColor}>${value}</c>`;
- } else {
- node.getComponent(cc.Label).string = value;
- }
- }
- /**按钮灰化,只有注册click事件,才会真正被禁用 */
- public static SetBtnGrayState(node: cc.Node, isGray) {
- let button = node.getComponent(cc.Button);
- if (!button) {
- return;
- }
- button.interactable = !isGray;
- button.enableAutoGrayEffect = isGray;
- }
- public static IsBtnGray(node: cc.Node) {
- let button = node.getComponent(cc.Button);
- if (!button) {
- return false;
- }
- return !button.interactable;
- }
- public static ShowUI<T extends UIBase>(uiClass: UIClass<T>, callback?: Function, ...args: any[]) {
- UIMng.getInstance().openUI(uiClass, ViewZorder.UI, callback, null, ...args);
- }
- public static CloseUI<T extends UIBase>(uiClass: UIClass<T>) {
- UIMng.getInstance().closeUI(uiClass);
- }
- public static IsShowingUI<T extends UIBase>(uiClass: UIClass<T>) {
- return UIMng.getInstance().isShowing(uiClass);
- }
- public static ShowTips(message: string, ...param: any[]) {
- let tipUI = UIMng.getInstance().getUI(UIToastMessage) as UIToastMessage;
- if (!tipUI) {
- UIMng.getInstance().openUI(UIToastMessage, ViewZorder.Tips, (ui) => {
- (ui as UIToastMessage).pushMessage(message);
- });
- } else {
-
- }
- }
- // public static ShowDialog(data: DialogParams) {
- // UIMng.getInstance().openUI(UIConfirmDialog, ViewZorder.Dialog, null, null, data);
- // }
- }
|