UIHelp.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. /**确定框界面参数 */
  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. // 信息飘字提示
  96. public static ShowTips(message: string) {
  97. // if (FguiMgr.Instance.isShowing(ShowTipsView)) {
  98. // EventMng.emit(FguiEvent.SHOWTIPS, message)
  99. // }
  100. // else {
  101. // FguiMgr.Instance.openUI(ShowTipsView, ViewZorder.POP_SYSTEM, null, message);
  102. // }
  103. }
  104. public static ShowI18nTips(key: string, ...args) {
  105. let str = I18n.getI18nText(key, ...args)
  106. this.ShowTips(str);
  107. }
  108. public static ShowHelp(type: HelpType, cb?: Function) {
  109. // FguiMgr.Instance.openUI(HelpViewView, ViewZorder.HELP, cb, type)
  110. }
  111. /**
  112. * 每日提示整合进dialogview内,如果已经勾选,自动执行cbConfirm
  113. * dayTipsModel改为dailogModel
  114. * @param data
  115. * @returns
  116. */
  117. public static ShowDialog(data: DialogParams, zIndex?: number) {
  118. if (FguiMgr.Instance.isShowing(DialogViewView)) {
  119. return
  120. }
  121. if (data.dayTipsKey && GameDataCenter.dialog.checkSetToday(data.dayTipsKey) && data.cbConfirm) {
  122. data.cbConfirm()
  123. return
  124. }
  125. FguiMgr.Instance.openUI(DialogViewView, zIndex ? zIndex : ViewZOrder.Dialog, null, data);
  126. }
  127. // 系统文字弹窗
  128. public static ShowSystemDialog(data: DialogParams) {
  129. /*if (FguiMgr.Instance.isShowing(DialogViewView)) {
  130. return
  131. }
  132. FguiMgr.Instance.openUI(DialogViewView, ViewZorder.POP_SYSTEM, null, data);*/
  133. EventMng.emit(WindowEvent.SHOW_SYS_DIALOG, data);
  134. }
  135. public static ShowSideItemTips(item: KindItem) {
  136. // let cfg = GameDataCenter.item.getItemCfgBase(item);
  137. // let color = uiCommon.getColorByPz(cfg.pinzhi);
  138. // UIHelp.ShowSideTips(`[color=${color}]${cfg.name}x${item[2]}[/color]`, item);
  139. }
  140. // 信息飘字提示
  141. public static ShowSideTips(message: string, kindItem?: KindItem) {
  142. // if (FguiMgr.Instance.isShowing(ShowSideTipsView)) {
  143. // EventMng.emit(FguiEvent.SHOWSIDETIPS, { msg: message, kindItem: kindItem })
  144. // }
  145. // else {
  146. // FguiMgr.Instance.openUI(ShowSideTipsView, ViewZorder.POP_SYSTEM, null, { msg: message, kindItem: kindItem });
  147. // }
  148. }
  149. public static FlyItemParticle(startPos: cc.Vec3, endPos: cc.Vec3, panel: fairygui.GObject, item: KindItem, index: number, cb: Function = null) {
  150. // let expEffect = eg.poolManager.GetPool("FlyItemParticle").get();
  151. // if (expEffect) {
  152. // // 通过 size 接口判断对象池中是否有空闲的对象
  153. // expEffect.active = true;
  154. // panel.node.addChild(expEffect);
  155. // expEffect.getComponent(FlyItemParticle).ShowItemEffect(startPos, endPos, item, index, cb);
  156. // } else {
  157. // // 如果没有空闲对象,也就是对象池中备用对象不够时
  158. // AssetsBundleMgr.loadBundlePrefab("particle/flyItem", (err, prefab: cc.Prefab) => {
  159. // if (prefab) {
  160. // expEffect = cc.instantiate(prefab);
  161. // expEffect.active = true;
  162. // expEffect.name = "expEffect";
  163. // panel.node.addChild(expEffect);
  164. // expEffect.getComponent(FlyItemParticle).ShowItemEffect(startPos, endPos, item, index, cb);
  165. // } else {
  166. // console.log("空的particle/flyItem资源");
  167. // }
  168. // });
  169. // }
  170. }
  171. /** 调试弹框用 */
  172. public static ShowDebugDialog(msg: string) {
  173. let data: DialogParams = {
  174. content: msg,
  175. cbConfirm: () => {
  176. }
  177. };
  178. this.ShowDialog(data);
  179. }
  180. }