RecruitResultUI.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { _decorator, Component, Node, Prefab, ScrollView, Vec3, instantiate } from 'cc';
  2. import { DataSystem } from '../../core/data/DataSystem';
  3. import { Window } from '../../core/ui/window/Window';
  4. import { WindowSystem } from '../../core/ui/window/WindowSystem';
  5. import { ConfigData } from '../../data/ConfigData';
  6. import { MarshalSkillSystem } from '../../marshal/MarshalSkillSystem';
  7. import { RecruitData } from '../RecruitData';
  8. import { RecruitResultItem } from './RecruitResultItem';
  9. const { ccclass, property } = _decorator;
  10. /**
  11. * 招募奖品展示页
  12. * @author 郑聂华
  13. */
  14. @ccclass('RecruitResultUI')
  15. export class RecruitResultUI extends Component {
  16. @property({ type: ScrollView, displayName: '窗口滑动组件', tooltip: "窗口滑动组件" }) scrollView: ScrollView = null;
  17. @property({ type: Node, displayName: 'Content', tooltip: "Content" }) content: Node = null;
  18. @property({ type: Prefab, displayName: '奖励Item', tooltip: "奖励Item" }) resultResultItemPrefab: Prefab = null;
  19. start() {
  20. let data = DataSystem.getData(RecruitData).recruitResults;
  21. data.sort(function (a, b) {
  22. let heroA = DataSystem.getData(ConfigData).get("general")[a.id];
  23. let heroB = DataSystem.getData(ConfigData).get("general")[b.id];
  24. if (heroA.color == heroB.color) {
  25. if (heroA.initStar == heroB.star) {
  26. if (heroA.camp == heroB.camp) {
  27. return heroB.id - heroA.id;
  28. } else {
  29. return heroA.camp - heroB.camp;//阵营 魏蜀吴群 1-4
  30. }
  31. } else {
  32. return heroB.initStar - heroA.initStar;
  33. }
  34. } else {
  35. return heroB.color - heroA.color;
  36. }
  37. });
  38. if (data != null && data.length > 0) {
  39. if (data.length <= 3) {
  40. this.scrollView.enabled = false;
  41. this.content.setPosition(Vec3.ZERO);
  42. } else {
  43. let posx = (data.length * 110 + (data.length - 1) * 30) / 2 - 253;
  44. this.content.setPosition(new Vec3(posx, 0, 0));
  45. }
  46. for (let i = 0; i < data.length; i++) {
  47. let scr = instantiate(this.resultResultItemPrefab).getComponent(RecruitResultItem);
  48. let hero = DataSystem.getData(ConfigData).get("general")[data[i].id];
  49. scr.Init(hero, data[i]);
  50. scr.node.active = true;
  51. this.content.addChild(scr.node);
  52. }
  53. } else {
  54. this.getComponent(Window).close();
  55. }
  56. }
  57. onDestroy() {
  58. DataSystem.getData(RecruitData).recruitResults = null;
  59. MarshalSkillSystem.openMarshalSkillNotice();
  60. }
  61. }