UIHelp.ts 7.4 KB

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