TaskWindowItem.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, Node, Label, RichText, ProgressBar, Sprite, SpriteFrame, Vec3, find, v3 } from 'cc';
  2. import InfiniteCell from '../../core/InfiniteList/InfiniteCell';
  3. import { Http } from '../../core/net/Http';
  4. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  5. import { WindowManager } from '../../core/ui/window/WindowManager';
  6. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  7. import { g } from '../../Data/g';
  8. import { platform } from '../../Data/platform';
  9. import { FarmManager } from '../../Main/FarmManager';
  10. import { MoveToCenter } from '../../Map/MoveToCenter';
  11. import { GetType } from '../GetWindow/GetType';
  12. import { UIEffect } from '../UIEffect';
  13. import { TaskWindow } from './TaskWindow';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('TaskWindowItem')
  16. export class TaskWindowItem extends InfiniteCell {
  17. @property({ type: RichText, tooltip: "任务描述" }) taskLabel: RichText;
  18. @property({ type: ProgressBar, tooltip: "任务进度条" }) taskProgress: ProgressBar;
  19. @property({ type: Label, tooltip: "进度文本" }) taskProgressLabel: Label;
  20. @property({ type: Label, tooltip: "奖励数量" }) taskRewardLabel: Label;
  21. @property({ type: Sprite, tooltip: "奖励图标" }) taskRewardSprite: Sprite;
  22. @property({ type: Node, tooltip: "领取按钮" }) getButton: Node;
  23. @property({ type: Node, tooltip: "前往按钮" }) gotoButton: Node;
  24. @property({ type: Node, tooltip: "任务完成图标" }) completeNode: Node;
  25. @property({ tooltip: "网络请求对象", type: Http }) http: Http;
  26. private window: TaskWindow = null;
  27. private iconPath = "";
  28. private data: any;
  29. async UpdateContent(itemData: any) {
  30. this.window = itemData.window;
  31. this.data = itemData.data;
  32. let strs = this.data.name.split('/');
  33. let str = "";
  34. for (let i = 0; i < strs.length; i++) {
  35. if (i % 2 == 0) {
  36. str += `<color=#7B4B31>${strs[i]}</color>`;
  37. } else {
  38. str += `<color=#D95D27>${strs[i]}</color>`;
  39. }
  40. }
  41. this.taskLabel.string = str;
  42. this.taskProgress.progress = this.data.progress / this.data.num;
  43. this.taskProgressLabel.string = `${this.data.progress} / ${this.data.num}`;
  44. this.taskRewardLabel.string = this.data.value + "";
  45. switch (this.data.reward_type) {
  46. case "exp":
  47. this.iconPath = "Images/Turntable/star_small/spriteFrame";
  48. this.taskRewardSprite.spriteFrame = await ResourcesUtils.load(this.iconPath, SpriteFrame, this.node);
  49. break;
  50. case "diamond":
  51. this.iconPath = "Images/Turntable/diamond_small/spriteFrame";
  52. this.taskRewardSprite.spriteFrame = await ResourcesUtils.load(this.iconPath, SpriteFrame, this.node);
  53. break;
  54. }
  55. this.gotoButton.active = !(this.getButton.active = this.data.progress == this.data.num);
  56. if (this.data.progress > this.data.num) {
  57. this.getButton.active = this.gotoButton.active = false;
  58. this.completeNode.active = true;
  59. this.taskProgressLabel.string = `${this.data.num} / ${this.data.num}`;
  60. } else {
  61. this.completeNode.active = false;
  62. }
  63. }
  64. public async onGetReward() {
  65. let result = await this.http.send("/api/task/taskReceive", { taskID: this.data.id });
  66. if (result.code == 0) {
  67. platform.reportThinking("quest", JSON.stringify({ quest_id: this.data.id, quest_name: this.data.name, award_id: this.data.reward_type, award_no: this.data.value }));
  68. let ui = find("Canvas/UI");
  69. switch (this.data.reward_type) {
  70. case "exp":
  71. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: this.data.value, type: GetType.exp, needBezierEffect: true }], this.window.node);
  72. break;
  73. case "diamond":
  74. platform.reportThinking("diamond_increase", JSON.stringify({ previous_number: g.userData.diamond, increase_number: this.data.value, current_number: g.userData.diamond + this.data.value, reasons: "taskReceive" }));
  75. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: this.data.value, type: GetType.Diamond, needBezierEffect: true }], this.window.node);
  76. break;
  77. }
  78. this.window.reloadList();
  79. }
  80. }
  81. public onGoto(): void {
  82. WindowManager.close();
  83. switch (this.data.type) {
  84. case 3:
  85. FarmManager.selectFristFarm();
  86. break;
  87. case 7:
  88. WindowManager.open("Prefabs/Turntable/Turntable", WindowOpenMode.CloseAndCover);
  89. break;
  90. case 13:
  91. WindowManager.open("Prefabs/AddDiamond", WindowOpenMode.CloseAndCover);
  92. break;
  93. }
  94. }
  95. }