123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import { ItemName, PopName } from "../EventName/EventName";
- import HTTPS, { NetGet } from "../Template/HTTPS";
- import PopComponet from "../Template/PopComponet";
- import HonorManger, { HonorWallDetailsType } from "./HonorManger";
- import HonorWallitem from "./HonorWallitem";
- import PopManger from "./PopManger";
- import Privacy from "./Privacy";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class HonorWall extends PopComponet {
- @property(cc.Node)
- Itemparent: cc.Node = null
- @property(cc.Label)
- progressLabel: cc.Label = null
- onLoad() {
- this.node.on('ClickItem', this.ClickItem, this)
- }
- onDestroy(): void {
- this.node.off('ClickItem', this.ClickItem, this)
- }
- ClickItem(event) {
- // 处理事件
- let data = event.getUserData(); // 获取自定义数据
- let Title = this.node.getChildByName("Title")
- let Bg = Title.getChildByName("Bg")
- let Sp = Title.getChildByName("Sp")
- let Name = Title.getChildByName("Name")
- let Detail = Title.getChildByName("Detail")
- Bg.active = true
- Sp.active = true
- Name.active = true
- Detail.active = true;
- Name.getComponent(cc.Label).string = (<HonorWallDetailsType>data.MyType).Name
- Detail.getComponent(cc.Label).string = (<HonorWallDetailsType>data.MyType).Description
- Sp.getComponent(cc.Sprite).spriteFrame = (<cc.Sprite>data.sp).spriteFrame
- if ((<boolean>data.Gray)) {
- // @ts-ignore
- Sp.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
- Bg.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, null))
- } else {
- // @ts-ignore
- Sp.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
- Bg.getComponent(cc.Sprite).setMaterial(0, cc.MaterialVariant.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, null))
- }
- }
- start() {
- this.init()
- }
- init() {
- this.initDisPlay()
- this.initIconItem()
- }
- initDisPlay() {
- let HonorDataAll = [
- ...HonorManger.getInstance().HonorWallDetails_Shangban,
- ...HonorManger.getInstance().HonorWallDetails_ChiDao,
- ...HonorManger.getInstance().HonorWallDetails_Qita];
- let d = HonorDataAll.filter(e => { return HonorManger.getInstance().SelectHonorM == e.Id })
- let Title = this.node.getChildByName("Title")
- let Bg = Title.getChildByName("Bg")
- let Sp = Title.getChildByName("Sp")
- let Name = Title.getChildByName("Name")
- let Detail = Title.getChildByName("Detail")
- //如果有值
- if (HonorManger.getInstance().SelectHonorM > 0) {
- Bg.active = true
- Sp.active = true
- Name.active = true
- Detail.active = true
- Name.getComponent(cc.Label).string = d[0].Name
- Detail.getComponent(cc.Label).string = d[0].Description
- } else {
- Bg.active = false
- Sp.active = false
- Name.active = false
- Detail.active = false
- }
- }
- initIconItem() {
- let HonorDataAll = [
- ...HonorManger.getInstance().HonorWallDetails_Shangban,
- ...HonorManger.getInstance().HonorWallDetails_ChiDao,
- ...HonorManger.getInstance().HonorWallDetails_Qita];
- this.progressLabel.string = `已获得 ${HonorManger.getInstance().HonorMList.length}/${HonorDataAll.length}`;
- for (let j = 0; j < HonorDataAll.length; j++) {
- const element = HonorDataAll[j];
- PopManger.getInstance().LoadAssets<cc.Prefab>(ItemName.HonorItem).then((Prefab) => {
- let subPrefab = cc.instantiate(Prefab)
- subPrefab.getComponent(HonorWallitem).MyType = element
- subPrefab.parent = this.Itemparent
- }).catch((error) => {
- // 加载失败的处理
- });
- }
- }
- ClickDelete() {
- this.node.destroy()
- }
- }
|