RedBox.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _decorator, Component, Node, Layout, UITransform, Prefab, instantiate } from 'cc';
  2. import { Http } from '../core/net/Http';
  3. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  4. import { WindowManager } from '../core/ui/window/WindowManager';
  5. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  6. import { ConfigData } from '../Data/ConfigData';
  7. import { g } from '../Data/g';
  8. import { RedBoxItem } from '../Item/RedBoxItem';
  9. import { LoginWaitWin } from './LoginWaitWin';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('RedBox')
  12. export class RedBox extends Component {
  13. @property({ tooltip: "滚动视图", type: Node })
  14. public listBox: Node;
  15. @property({ tooltip: "滚动视图外框", type: Node })
  16. public listBoxGroup;
  17. @property({ tooltip: "http服务", type: Http })
  18. public http: Http;
  19. start() {
  20. this.listBox.getComponent(Layout).spacingX = this.listBox.getComponent(Layout).paddingLeft = (this.listBoxGroup.getComponent(UITransform).width - 205 * 3) / 4;
  21. g.gameData.hasNewRedPacketUpdate = false;
  22. this.initUI();
  23. }
  24. public async initUI() {
  25. let redList = g.gameData.myRedPacketDatas;
  26. redList.sort(function (a, b) {
  27. if (a.type != b.type) {
  28. return a.type - b.type;
  29. } else {
  30. return a.canOpenTime - b.canOpenTime;
  31. }
  32. })
  33. for (let i = 0; i < redList.length; i++) {
  34. let prefabData = await ResourcesUtils.load<Prefab>("Prefabs/Item/红包", null, this.node);
  35. var itemNode = instantiate(prefabData);
  36. itemNode.parent = this.listBox;
  37. itemNode.getComponent(RedBoxItem).setData(redList[i]);
  38. }
  39. }
  40. public toPk() {
  41. let _lv = ConfigData.configMap.get("systemConfig").openBattleLv;
  42. if (g.userData.lv >= _lv) {
  43. WindowManager.open("Prefabs/Battle/BattleUIWindow", WindowOpenMode.CloseAndAdd, { tabIndex: 0 });
  44. } else {
  45. WindowManager.showTips(_lv + '级开放');
  46. }
  47. }
  48. /**
  49. * 关闭回调
  50. */
  51. public close() {
  52. g.gameData.isAddRole = true;
  53. }
  54. }