UIHelp.ts 7.5 KB

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