DiamondWithWin.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { _decorator, Component, Node, Prefab, instantiate, JsonAsset, Label, RichText, EventHandler, UITransform, ScrollView, Sprite } from 'cc';
  2. import InfiniteCell from '../core/InfiniteList/InfiniteCell';
  3. import { IFDataSource, InfiniteList } from '../core/InfiniteList/InfiniteList';
  4. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  5. import { ConfigData } from '../Data/ConfigData';
  6. import { g } from '../Data/g';
  7. import { DiamondWithItem } from '../Item/DiamondWithItem';
  8. import { NoviceWindow } from './NoviceWindow';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('DiamondWithWin')
  11. export class DiamondWithWin extends Component implements IFDataSource {
  12. @property({ tooltip: "list列表", type: InfiniteList }) public list: InfiniteList;
  13. @property({ tooltip: "Item预制体", type: Prefab }) item: Prefab;
  14. @property({ tooltip: "神石总值文本", type: Label }) public diamondTxt: Label;
  15. @property({ tooltip: "可兑换金币金额", type: RichText }) public moneyTxt: RichText;
  16. @property({ tooltip: "item回调,刷新界面", type: EventHandler }) public initBack: EventHandler;
  17. // @property({ tooltip: "新手手势", type: Sprite })
  18. // handSprite: Sprite;
  19. public withConfig: any;
  20. public prefabHeight: number = 0;
  21. async start() {
  22. if (NoviceWindow.isNovicing) {
  23. NoviceWindow.isNovicing = false;
  24. // this.handSprite.node.active = true;
  25. // this.list.getComponent(ScrollView).enabled = false;
  26. }
  27. let prefab = instantiate(this.item);
  28. this.prefabHeight = prefab.getComponent(UITransform).height;
  29. // this.withConfig = await (await ResourcesUtils.load<JsonAsset>("Configs/diamondWithdraw", JsonAsset, this.node)).json;
  30. this.withConfig = ConfigData.configMap.get("diamondWithdraw");
  31. this.initUI();
  32. for (let i = 0; i < this.withConfig.length; i++) {
  33. this.withConfig[i].backFun = this.initBack;
  34. }
  35. this.list.Init(this);
  36. this.list.Reload(true);
  37. }
  38. update() {
  39. // if (this.handSprite.node.active && !NoviceWindow.isNovicing) {
  40. // this.handSprite.node.active = false;
  41. // }
  42. }
  43. public async initUI() {
  44. this.moneyTxt.string = "<color=#c3771c>约 </color><color=#3a8d40>" + g.userData.diamond / ConfigData.configMap.get("systemConfig").moneyRate + "</color><color=#c3771c> 元</color>";
  45. this.diamondTxt.string = g.userData.diamond + "";
  46. }
  47. public updateUI() {
  48. this.initUI();
  49. this.list.Refresh();
  50. this.list.getComponent(ScrollView).enabled = true;
  51. }
  52. //#region IFDataSource
  53. public GetCellNumber(): number {
  54. return this.withConfig.length;
  55. }
  56. public GetCellIdentifer(dataIndex: number): string {
  57. return "DiamondWithItem";
  58. }
  59. public GetCellSize(dataIndex: number): number {
  60. return this.prefabHeight;
  61. }
  62. public GetCellView(dataIndex: number, identifier?: string): DiamondWithItem {
  63. let node = instantiate(this.item);
  64. return node.getComponent(DiamondWithItem);
  65. }
  66. public GetCellData?(dataIndex: number): any {
  67. return this.withConfig[dataIndex];
  68. }
  69. //#endregion
  70. }