UIHelp.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import UIToastMessage from "../../ui/uiview/common/UIToastMessage";
  2. import { ViewZorder } from "../constant/ViewZOrder";
  3. import UIBase, { UIClass } from "./UIBase";
  4. import UIMng from "./UIMng";
  5. /**确定框界面参数 */
  6. export interface DialogParams {
  7. title: string,
  8. content: string,
  9. certainCb?: Function,
  10. cancelCb?: Function
  11. }
  12. export default class UIHelp {
  13. public static SetLabel(node: cc.Node, value: string | number) {
  14. if (typeof value === 'number') {
  15. value = value.toString();
  16. } else if (value == undefined) {
  17. value = "";
  18. }
  19. // 文本和富文本只能二选一
  20. if (node.getComponent(cc.RichText)) {
  21. let defaultColor = node.color.toHEX('#rrggbb');
  22. node.getComponent(cc.RichText).string = `<color=${defaultColor}>${value}</c>`;
  23. } else {
  24. node.getComponent(cc.Label).string = value;
  25. }
  26. }
  27. /**按钮灰化,只有注册click事件,才会真正被禁用 */
  28. public static SetBtnGrayState(node: cc.Node, isGray) {
  29. let button = node.getComponent(cc.Button);
  30. if (!button) {
  31. return;
  32. }
  33. button.interactable = !isGray;
  34. button.enableAutoGrayEffect = isGray;
  35. }
  36. public static IsBtnGray(node: cc.Node) {
  37. let button = node.getComponent(cc.Button);
  38. if (!button) {
  39. return false;
  40. }
  41. return !button.interactable;
  42. }
  43. public static ShowUI<T extends UIBase>(uiClass: UIClass<T>, callback?: Function, ...args: any[]) {
  44. UIMng.getInstance().openUI(uiClass, ViewZorder.UI, callback, null, ...args);
  45. }
  46. public static CloseUI<T extends UIBase>(uiClass: UIClass<T>) {
  47. UIMng.getInstance().closeUI(uiClass);
  48. }
  49. public static IsShowingUI<T extends UIBase>(uiClass: UIClass<T>) {
  50. return UIMng.getInstance().isShowing(uiClass);
  51. }
  52. public static ShowTips(message: string, ...param: any[]) {
  53. let tipUI = UIMng.getInstance().getUI(UIToastMessage) as UIToastMessage;
  54. if (!tipUI) {
  55. UIMng.getInstance().openUI(UIToastMessage, ViewZorder.Tips, (ui) => {
  56. (ui as UIToastMessage).pushMessage(message);
  57. });
  58. } else {
  59. }
  60. }
  61. // public static ShowDialog(data: DialogParams) {
  62. // UIMng.getInstance().openUI(UIConfirmDialog, ViewZorder.Dialog, null, null, data);
  63. // }
  64. }