AlertManager.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. const GameModule = require("./GameModule");
  2. const DWTool = require("./DWTool");
  3. const PrefabManager = require("./PrefabManager");
  4. /**
  5. * 通用弹窗管理
  6. */
  7. class AlertManager {
  8. // 显示任务界面弹窗
  9. static showQuestPopup() {
  10. GameModule.audioMng.playClickButton();
  11. PrefabManager.loadPrefab('quest_popup')
  12. .then((result) => {
  13. let alert = result;
  14. let canvas = cc.find("Canvas");
  15. canvas.addChild(alert);
  16. });
  17. }
  18. static showOfflineGrossIncome(offlineGold) {
  19. PrefabManager.loadPrefab('offline_grossIncome')
  20. .then((result) => {
  21. let alert = result;
  22. let canvas = cc.find("Canvas");
  23. canvas.addChild(alert);
  24. alert.getComponent('OfflineGrossIncome').init(offlineGold);
  25. });
  26. }
  27. /// 显示抽奖界面
  28. static showDrawAlert(data = 1) {
  29. GameModule.audioMng.playClickButton();
  30. PrefabManager.loadPrefab('draw_content')
  31. .then((result) => {
  32. let alert = result;
  33. let canvas = cc.find("Canvas");
  34. alert.setPosition(0, 0);
  35. canvas.addChild(alert);
  36. });
  37. }
  38. /// 显示抽奖滚动界面
  39. static showDrawScrollAlert(drawData, typeId) {
  40. PrefabManager.loadPrefab('drawCycleScroll')
  41. .then((result) => {
  42. let alert = result;
  43. let canvas = cc.find("Canvas");
  44. alert.setPosition(0, 0);
  45. canvas.addChild(alert);
  46. alert.getComponent("DrawCycleScroll").init(drawData, typeId);
  47. });
  48. }
  49. /// 显示抽奖成功得到明星的界面
  50. static showDrawSuccessAlert(drawData, typeId) {
  51. DWTool.loadResPrefab("./prefabs/draw/drawStarSuccss")
  52. .then((result) => {
  53. let alert = cc.instantiate(result);
  54. let canvas = cc.find("Canvas");
  55. alert.setPosition(0, 0);
  56. canvas.addChild(alert);
  57. alert.getComponent("DrawStarSuccss").init(drawData, typeId);
  58. });
  59. }
  60. /// 显示抽奖红包的界面
  61. static showDrawRedRecordAlert() {
  62. DWTool.loadResPrefab("./prefabs/draw/drawRedRecord")
  63. .then((result) => {
  64. let alert = cc.instantiate(result);
  65. let canvas = cc.find("Canvas");
  66. alert.setPosition(0, 0);
  67. canvas.addChild(alert);
  68. });
  69. }
  70. /// 显示技能弹窗界面
  71. static showSkillAlert() {
  72. GameModule.audioMng.playClickButton();
  73. if (GameGlobal.skillContent === undefined) {
  74. PrefabManager.loadPrefab('skill_content')
  75. .then((result) => {
  76. let alert = result;
  77. let canvas = cc.find("Canvas/commonNode");
  78. canvas.addChild(alert);
  79. GameGlobal.skillContent = alert;
  80. });
  81. } else {
  82. GameGlobal.skillContent.getComponent('skillContent').show();
  83. }
  84. }
  85. static showSkillBuyAlert (skillInfo, nextSkillInfo, starItem) {
  86. GameModule.audioMng.playClickButton();
  87. DWTool.loadResPrefab("./prefabs/skill/skillBuyAlert")
  88. .then((result) => {
  89. let alert = cc.instantiate(result);
  90. let canvas = cc.find("Canvas");
  91. canvas.addChild(alert);
  92. alert.getComponent('SkillBuyAlert').init(skillInfo, nextSkillInfo, starItem);
  93. });
  94. }
  95. /// 显示明星图鉴
  96. static showStarHandbookAlert() {
  97. GameModule.audioMng.playClickButton();
  98. PrefabManager.loadPrefab('starHandbook')
  99. .then((result) => {
  100. let alert = result;
  101. let canvas = cc.find("Canvas");
  102. canvas.addChild(alert);
  103. });
  104. }
  105. /// 显示明星界面
  106. static showStarAlert() {
  107. GameModule.audioMng.playClickButton();
  108. if (GameGlobal.starContent === undefined || GameGlobal.starContent === null) {
  109. PrefabManager.loadPrefab('star_content')
  110. .then((result) => {
  111. let alert = result;
  112. let canvas = cc.find("Canvas/commonNode");
  113. canvas.addChild(alert);
  114. GameGlobal.starContent = alert;
  115. });
  116. } else {
  117. GameGlobal.starContent.getComponent('StarContent').show();
  118. }
  119. }
  120. /// 显示获取道具弹窗界面
  121. static showActGiftAlert(type, showText, spriteFrame) {
  122. DWTool.loadResPrefab("./prefabs/common/actgift")
  123. .then((result) => {
  124. let alert = cc.instantiate(result);
  125. let canvas = cc.find("Canvas");
  126. canvas.addChild(alert);
  127. alert.getComponent("Actgift").init(type, showText, spriteFrame);
  128. });
  129. }
  130. /// 显示签到界面
  131. static showSignInAlert() {
  132. PrefabManager.loadPrefab('sign_in')
  133. .then((result) => {
  134. let alert = result;
  135. let canvas = cc.find("Canvas");
  136. canvas.addChild(alert);
  137. });
  138. }
  139. /// 显示明星图鉴
  140. static showRankAlert(index = 0) {
  141. GameModule.audioMng.playClickButton();
  142. PrefabManager.loadPrefab('game_rank')
  143. .then((result) => {
  144. let alert = result;
  145. let canvas = cc.find("Canvas");
  146. canvas.addChild(alert);
  147. alert.getComponent('GameRank').init(index);
  148. });
  149. }
  150. /// 显示商城界面
  151. static showStoreAlert() {
  152. GameModule.audioMng.playClickButton();
  153. PrefabManager.loadPrefab('store_content')
  154. .then((result) => {
  155. let alert = result;
  156. let canvas = cc.find("Canvas");
  157. canvas.addChild(alert);
  158. });
  159. }
  160. /// 显示商城合辑界面
  161. static showStoreAlbumAlert(temDatas) {
  162. DWTool.loadResPrefab("./prefabs/store/storeAlbum")
  163. .then((result) => {
  164. let alert = cc.instantiate(result);
  165. alert.getComponent('StoreSubcript').init(temDatas);
  166. let canvas = cc.find("Canvas");
  167. canvas.addChild(alert);
  168. });
  169. }
  170. /// 显示商城钻石优惠界面
  171. static showStoreDiamondAlert(selectIndex) {
  172. DWTool.loadResPrefab("./prefabs/store/storeDiamond")
  173. .then((result) => {
  174. let alert = cc.instantiate(result);
  175. let canvas = cc.find("Canvas");
  176. canvas.addChild(alert);
  177. alert.getComponent('StoreDiamondDiscount').init(selectIndex);
  178. });
  179. }
  180. //// 显示商城礼包弹窗
  181. static showStoreGiftAlert(giftIndex, giftData) {
  182. DWTool.loadResPrefab("./prefabs/store/storeGiftAlert")
  183. .then((result) => {
  184. let alert = cc.instantiate(result);
  185. let canvas = cc.find("Canvas");
  186. canvas.addChild(alert);
  187. alert.getComponent('StoreGiftAlert').init(giftIndex, giftData);
  188. });
  189. }
  190. /// 显示技能2弹出金币效果
  191. static showSkill2Efc(gold) {
  192. DWTool.loadResPrefab("./prefabs/skill/use_skill2_efc")
  193. .then((result) => {
  194. let alert = cc.instantiate(result);
  195. let canvas = cc.find("Canvas/useSkillNode");
  196. canvas.addChild(alert);
  197. alert.getComponent('UseSkill2Efc').init(gold);
  198. });
  199. }
  200. /// 显示共有弹窗
  201. static showCommonAlert(iconPath, desc, title) {
  202. DWTool.loadResPrefab("./prefabs/common/commonAlert")
  203. .then((result) => {
  204. let alert = cc.instantiate(result);
  205. let canvas = cc.find("Canvas");
  206. canvas.addChild(alert);
  207. alert.getComponent('commAlert').init(iconPath, desc, title);
  208. });
  209. }
  210. /// 显示每天获取钻石弹窗
  211. static showGetDiamondEveryDayAlert(iconPath, desc, title, diamond) {
  212. DWTool.loadResPrefab("./prefabs/common/commonAlert")
  213. .then((result) => {
  214. let alert = cc.instantiate(result);
  215. let canvas = cc.find("Canvas");
  216. canvas.addChild(alert);
  217. alert.getComponent('commAlert').initAddDiamond(iconPath, desc, title, diamond);
  218. });
  219. }
  220. /// 显示通知弹窗
  221. static showNoticeAlert(noticeStr) {
  222. DWTool.loadResPrefab("./prefabs/common/noticeAlert")
  223. .then((result) => {
  224. let alert = cc.instantiate(result);
  225. let canvas = cc.find("Canvas");
  226. canvas.addChild(alert);
  227. alert.getComponent('NoticeAlert').init(noticeStr);
  228. });
  229. }
  230. /// 显示分享失败弹窗
  231. static showShareFailAlert() {
  232. DWTool.loadResPrefab("./prefabs/common/shareFailAlert")
  233. .then((result) => {
  234. let alert = cc.instantiate(result);
  235. let canvas = cc.find("Canvas");
  236. canvas.addChild(alert);
  237. alert.getComponent('shareFailAlert').show();
  238. });
  239. }
  240. // 显示错误消息提示
  241. static showCommonErrorAlert(message) {
  242. if (window.tt != undefined) {
  243. //今日头条
  244. tt.showToast({
  245. title: message,
  246. icon: 'none'
  247. });
  248. } else if (CC_WECHATGAME) {
  249. wx.showToast({
  250. title: message,
  251. icon: 'none'
  252. });
  253. /// qq平台直接弹出错误
  254. } else if (CC_QQPLAY) {
  255. BK.UI.showToast({
  256. title: message,
  257. duration:1500, complete:function() {
  258. BK.Script.log(0,0,"complete show");
  259. }
  260. });
  261. } else {
  262. alert(message);
  263. }
  264. }
  265. // 显示所拥有礼包界面
  266. static showStarGiftBag(array) {
  267. DWTool.loadResPrefab("./prefabs/star/star_gift_bag")
  268. .then((result) => {
  269. let alert = cc.instantiate(result);
  270. let canvas = cc.find("Canvas");
  271. canvas.addChild(alert);
  272. alert.getComponent('StarGiftBag').init(array);
  273. });
  274. }
  275. // 显示所拥有礼包界面
  276. static showStoreQQaddGroup() {
  277. DWTool.loadResPrefab("./prefabs/store/storeQQAlert")
  278. .then((result) => {
  279. let alert = cc.instantiate(result);
  280. let canvas = cc.find("Canvas");
  281. canvas.addChild(alert);
  282. });
  283. }
  284. //显示我的小程序神秘礼包界面
  285. static showAppletAlert() {
  286. GameModule.audioMng.playClickButton();
  287. PrefabManager.loadPrefab('my_applet')
  288. .then((result) => {
  289. let alert = result;
  290. let canvas = cc.find("Canvas");
  291. canvas.addChild(alert);
  292. });
  293. }
  294. //显示邀请好友界面
  295. static showInviteAlert() {
  296. GameModule.audioMng.playClickButton();
  297. PrefabManager.loadPrefab('invite_mission')
  298. .then((result) => {
  299. let alert = result;
  300. let canvas = cc.find("Canvas");
  301. canvas.addChild(alert);
  302. });
  303. }
  304. static showLoginRewardAlert() {
  305. GameModule.audioMng.playClickButton();
  306. PrefabManager.loadPrefab('login_reward')
  307. .then((result) => {
  308. let alert = result;
  309. let canvas = cc.find("Canvas");
  310. canvas.addChild(alert);
  311. });
  312. }
  313. // 显示音效设置
  314. static showGameSetting() {
  315. GameModule.audioMng.playClickButton();
  316. DWTool.loadResPrefab("./prefabs/setting/game_setting")
  317. .then((result) => {
  318. let alert = cc.instantiate(result);
  319. let canvas = cc.find("Canvas");
  320. canvas.addChild(alert);
  321. });
  322. }
  323. //好友助力界面
  324. static showFriendHelpAlert() {
  325. GameModule.audioMng.playClickButton();
  326. PrefabManager.loadPrefab('friend_help_click')
  327. .then((result) => {
  328. let canvas = cc.find("Canvas");
  329. canvas.addChild(result);
  330. });
  331. }
  332. //好友系统界面
  333. static showGameFriend() {
  334. GameModule.audioMng.playClickButton();
  335. PrefabManager.loadPrefab('game_friend')
  336. .then((result) => {
  337. let canvas = cc.find("Canvas");
  338. canvas.addChild(result);
  339. result.getComponent('GameFriendCtrl').init();
  340. });
  341. }
  342. /**
  343. *每天时间段奖励的弹窗
  344. *
  345. * @static
  346. * @memberof AlertManager
  347. */
  348. static showGetAward() {
  349. GameModule.audioMng.playClickButton();
  350. PrefabManager.loadPrefab('dayAward_Alert')
  351. .then((result) => {
  352. let alert = result;
  353. let canvas = cc.find("Canvas");
  354. canvas.addChild(alert);
  355. });
  356. }
  357. }
  358. module.exports = AlertManager;