UIHelp.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import Config from "../../Config";
  2. import { KindItem } from "../../common/Xys";
  3. import GameDataCenter from "../../data/GameDataCenter";
  4. import { FguiEvent, WindowEvent } from "../../data/const/EventConst";
  5. import { AudioConst, DayTipsKey, HelpType, InGame } from "../../data/const/TypeConst";
  6. import { ViewZorder } from "../../data/const/ViewZOrder";
  7. import EventMng from "../../manager/EventMng";
  8. import UIMng from "../../manager/UIMng";
  9. import UIBase, { BASE_POP, UIClass } from "./UIBase";
  10. import { PayProductParam } from "../../data/const/TypeConst";
  11. import FguiMgr from "../../frameWork/fgui/FguiMgr";
  12. import IDataModel from "../../data/model/IDataModel";
  13. import { I18n } from "../../utils/I18nUtil";
  14. import { uiCommon } from "../../utils/UICommon";
  15. import { eg } from "../../frameWork/eg";
  16. import AssetsBundleMgr from "../../utils/AssetsBundleMgr";
  17. /**确定框界面参数 */
  18. export interface DialogParams {
  19. content: string,// 弹窗文本内容
  20. title?: string,// 弹窗标题
  21. cbConfirm?: Function,// 确定按钮的事件
  22. cbCancel?: Function,// 取消按钮的事件
  23. txtCancel?: string,// 取消按钮的文本
  24. txtConfirm?: string,// 确定按钮的文本
  25. onlyConfirm?: boolean//只有确认键
  26. costItem?: KindItem//消耗道具
  27. // needItem?: KindItem//需求道具
  28. showToggle?: boolean,// 是否显示toggle
  29. useDlg?: string// 哪个界面调用的弹窗
  30. dayTipsKey?: DayTipsKey,//今日不再提醒key,不为空则设置
  31. tipsModel?: IDataModel,//本次登录不再提醒model,不为空则设置
  32. tipsKey?: string,//本次登录不再提醒key,不为空则设置
  33. showVideoBtn?: boolean,//显示视频按钮
  34. videoCb?: Function,//视频按钮回调
  35. maskCloseOnly?: boolean,//点击遮罩只关闭 不执行cancel
  36. // videoParam?: {
  37. // kid: string,
  38. // sendUrl: string,
  39. // sendParam: any
  40. // }
  41. }
  42. /**确定框界面参数 */
  43. export interface DialogJintiaoTipsParams {
  44. data: PayProductParam,
  45. needNum: number,
  46. cbConfirm?: Function,
  47. cbCancel?: Function,
  48. }
  49. /**购买道具弹窗界面参数 */
  50. export interface BuyItemParams {
  51. // noAskKey: ShopToolKey
  52. buyItem: KindItem//需要购买的道具
  53. costItem: KindItem//消耗道具
  54. cb: Function//购买回调
  55. }
  56. /**通用输入框参数*/
  57. export interface InputParams {
  58. content?: string,// 弹窗输入框文本内容
  59. title?: string,// 弹窗标题
  60. cbConfirm: Function,// 确定按钮的事件
  61. txtConfirm?: string,// 确定按钮的文本
  62. limitLength?: number,// 限制的字符数量
  63. }
  64. export default class UIHelp {
  65. public static SetLabel(node: cc.Node, value: string | number) {
  66. if (typeof value === 'number') {
  67. value = value.toString();
  68. } else if (value == undefined) {
  69. value = "";
  70. }
  71. // 文本和富文本只能二选一
  72. if (node.getComponent(cc.RichText)) {
  73. let defaultColor = node.color.toHEX('#rrggbb');
  74. node.getComponent(cc.RichText).string = `<color=${defaultColor}>${value}</c>`;
  75. } else {
  76. node.getComponent(cc.Label).string = value;
  77. }
  78. }
  79. /**按钮灰化,只有注册click事件,才会真正被禁用 */
  80. public static SetBtnGrayState(node: cc.Node, isGray) {
  81. let button = node.getComponent(cc.Button);
  82. if (!button) {
  83. return;
  84. }
  85. button.interactable = !isGray;
  86. button.enableAutoGrayEffect = isGray;
  87. }
  88. public static IsBtnGray(node: cc.Node) {
  89. let button = node.getComponent(cc.Button);
  90. if (!button) {
  91. return false;
  92. }
  93. return !button.interactable;
  94. }
  95. public static ShowUI<T extends UIBase>(uiClass: UIClass<T>, callback?: Function, ...args: any[]) {
  96. if (uiClass.getPop() == BASE_POP.POP) {
  97. GameDataCenter.audio.playEffect(AudioConst.effect_open)
  98. }
  99. UIMng.getInstance().openUI(uiClass, ViewZorder.UI, callback, null, ...args);
  100. }
  101. public static CloseUI<T extends UIBase>(uiClass: UIClass<T>, del: boolean = false, playEffect: boolean = true) {
  102. if (playEffect && uiClass.getPop() == BASE_POP.POP) {
  103. GameDataCenter.audio.playEffect(AudioConst.effect_open)
  104. }
  105. UIMng.getInstance().closeUI(uiClass, del);
  106. }
  107. public static IsShowingUI<T extends UIBase>(uiClass: UIClass<T>) {
  108. return UIMng.getInstance().isShowing(uiClass);
  109. }
  110. // 信息飘字提示
  111. public static ShowTips(message: string) {
  112. // if (FguiMgr.Instance.isShowing(ShowTipsView)) {
  113. // EventMng.emit(FguiEvent.SHOWTIPS, message)
  114. // }
  115. // else {
  116. // FguiMgr.Instance.openUI(ShowTipsView, ViewZorder.POP_SYSTEM, null, message);
  117. // }
  118. }
  119. public static ShowI18nTips(key: string, ...args) {
  120. let str = I18n.getI18nText(key, ...args)
  121. this.ShowTips(str);
  122. }
  123. public static ShowHelp(type: HelpType, cb?: Function) {
  124. // FguiMgr.Instance.openUI(HelpViewView, ViewZorder.HELP, cb, type)
  125. }
  126. /**
  127. * 每日提示整合进dialogview内,如果已经勾选,自动执行cbConfirm
  128. * dayTipsModel改为dailogModel
  129. * @param data
  130. * @returns
  131. */
  132. public static ShowDialog(data: DialogParams, zIndex?: number) {
  133. // if (FguiMgr.Instance.isShowing(DialogViewView)) {
  134. // return
  135. // }
  136. // if (data.dayTipsKey && GameDataCenter.dialog.checkSetToday(data.dayTipsKey) && data.cbConfirm) {
  137. // data.cbConfirm()
  138. // return
  139. // }
  140. // FguiMgr.Instance.openUI(DialogViewView, zIndex ? zIndex : ViewZorder.DIALOG, null, data);
  141. }
  142. // 系统文字弹窗
  143. public static ShowSystemDialog(data: DialogParams) {
  144. /*if (FguiMgr.Instance.isShowing(DialogViewView)) {
  145. return
  146. }
  147. FguiMgr.Instance.openUI(DialogViewView, ViewZorder.POP_SYSTEM, null, data);*/
  148. EventMng.emit(WindowEvent.SHOW_SYS_DIALOG, data);
  149. }
  150. public static ShowSideItemTips(item: KindItem) {
  151. // let cfg = GameDataCenter.item.getItemCfgBase(item);
  152. // let color = uiCommon.getColorByPz(cfg.pinzhi);
  153. // UIHelp.ShowSideTips(`[color=${color}]${cfg.name}x${item[2]}[/color]`, item);
  154. }
  155. // 信息飘字提示
  156. public static ShowSideTips(message: string, kindItem?: KindItem) {
  157. // if (FguiMgr.Instance.isShowing(ShowSideTipsView)) {
  158. // EventMng.emit(FguiEvent.SHOWSIDETIPS, { msg: message, kindItem: kindItem })
  159. // }
  160. // else {
  161. // FguiMgr.Instance.openUI(ShowSideTipsView, ViewZorder.POP_SYSTEM, null, { msg: message, kindItem: kindItem });
  162. // }
  163. }
  164. public static FlyItemParticle(startPos: cc.Vec3, endPos: cc.Vec3, panel: fairygui.GObject, item: KindItem, index: number, cb: Function = null) {
  165. // let expEffect = eg.poolManager.GetPool("FlyItemParticle").get();
  166. // if (expEffect) {
  167. // // 通过 size 接口判断对象池中是否有空闲的对象
  168. // expEffect.active = true;
  169. // panel.node.addChild(expEffect);
  170. // expEffect.getComponent(FlyItemParticle).ShowItemEffect(startPos, endPos, item, index, cb);
  171. // } else {
  172. // // 如果没有空闲对象,也就是对象池中备用对象不够时
  173. // AssetsBundleMgr.loadBundlePrefab("particle/flyItem", (err, prefab: cc.Prefab) => {
  174. // if (prefab) {
  175. // expEffect = cc.instantiate(prefab);
  176. // expEffect.active = true;
  177. // expEffect.name = "expEffect";
  178. // panel.node.addChild(expEffect);
  179. // expEffect.getComponent(FlyItemParticle).ShowItemEffect(startPos, endPos, item, index, cb);
  180. // } else {
  181. // console.log("空的particle/flyItem资源");
  182. // }
  183. // });
  184. // }
  185. }
  186. /** 调试弹框用 */
  187. public static ShowDebugDialog(msg: string) {
  188. let data: DialogParams = {
  189. content: msg,
  190. cbConfirm: () => {
  191. }
  192. };
  193. this.ShowDialog(data);
  194. }
  195. }