123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { _decorator, Label, Node, Sprite, SpriteFrame } from 'cc';
- import { ResKeeper } from '../../../framework/res/ResKeeper';
- import { ItemEnum } from '../../common/InterfaceAddEnum';
- import { Framework } from '../../../framework/Framework';
- import { ViewID } from '../../../framework/config/LayerConf';
- const { ccclass, property } = _decorator;
- @ccclass('CommonItem')
- export class CommonItem extends ResKeeper {
- @property({ type: Sprite, tooltip: "背景" })
- farmeBg: Sprite = null;
- @property({ type: Label, tooltip: "数量" })
- numTx: Label = null;
- @property({ type: Sprite, tooltip: "图标" })
- icoImg: Sprite = null;
- @property({ type: Node, tooltip: "碎片标记" })
- pieceIco: Node = null;
- @property({ type: Node, tooltip: "阵营标记" })
- raceIco: Node = null;
- @property({ type: Node, tooltip: "星级节点" })
- starNode: Node = null;
- @property({ type: [Node], tooltip: "星星" })
- stars: Node[] = [];
- @property({ type: [SpriteFrame], tooltip: "星星" })
- gradeBgs: SpriteFrame[] = [];
- @property({ type: Node, tooltip: "选中效果" })
- selectBg: Node = null;
- @property({ type: [SpriteFrame], tooltip: "背景图" })
- bgFrame: SpriteFrame[] = [];
- private isSelect = false;
- private isNumShow = true;
- private isClickEnable = true;
- private data = null;
- private clickFunc = null;
- protected onLoad() {
- this.selectBg.active = false;
- this.pieceIco.active = false;
- this.raceIco.active = false;
- this.starNode.active = false;
- }
- protected onDestroy() {
- //如果该组件有事件自行取消注释
- //Framework.event.removeEvent(this);
- super.onDestroy();
- }
- //如果使用了池中的节点,在该函数内归还,该函数会在onDestroy前调用
- onClose() {
- }
- //UI事件处理
- private onTouchButton(event: Event) {
- //Framework.audio.playEffect(AudioID.Click);
- let target: any = event.target;
- }
- refreshItem(data) {
- this.data = data;
- if (data.clickFunc) {
- this.clickFunc = data.clickFunc;
- }
- if (this.data.type == ItemEnum.material) {
- this.setMaterial();
- } else if (this.data.type == ItemEnum.equip) {
- this.setEquip();
- } else if (this.data.type == ItemEnum.role) {
- this.setRole();
- }
- else if (this.data.type == ItemEnum.user) {
- this.setUser();
- }
- this.numTx.node.active = this.isNumShow;
- }
- setMaterial() {
- this.farmeBg.spriteFrame = this.bgFrame[this.data.conf.Quality];
- this.load('common', `texture/icon/item/item_1/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
- this.icoImg.spriteFrame = res;
- })
- this.numTx.string = this.data.count;
- }
- setEquip() {
- this.farmeBg.spriteFrame = this.bgFrame[this.data.conf.Quality];
- this.load('common', `texture/icon/equips/equip1_${this.data.conf.Slot}1/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
- this.icoImg.spriteFrame = res;
- })
- this.numTx.string = this.data.count;
- }
- setRole() {
- this.farmeBg.spriteFrame = this.bgFrame[this.data.conf.Quality];
- this.load('common', `texture/icon/hero/head_${this.data.conf.Id}/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
- this.icoImg.spriteFrame = res;
- })
- this.numTx.string = this.data.count;
- }
- setUser() {
- // this.farmeBg.spriteFrame = this.bgFrame[this.data.conf.Quality];
- // this.load('common', `texture/icon/item/item_1/spriteFrame`, SpriteFrame, (res: SpriteFrame) => {
- // this.icoImg.spriteFrame = res;
- // })
- // this.numTx.string = this.data.count;
- }
- setSelectEnable(state: boolean) {
- this.selectBg.active = state;
- }
- setClickEnable(state: boolean) {
- this.isClickEnable = state;
- }
- setNumShow(state: boolean) {
- this.isNumShow = state;
- }
- setClick(callFunc) {
- this.clickFunc = callFunc;
- }
- onClick() {
- this.isSelect = !this.isSelect;
- if (this.clickFunc) {
- this.clickFunc(this.data, this.isSelect);
- } else {
- if (this.isClickEnable) {
- Framework.layer.open(ViewID.ItemMsg, null, this.data);
- }
- }
- }
- }
|