194 lines
5.3 KiB
TypeScript
194 lines
5.3 KiB
TypeScript
import {
|
|
_decorator,
|
|
AssetManager,
|
|
Component,
|
|
Label,
|
|
Node,
|
|
randomRangeInt,
|
|
Sprite,
|
|
UITransform,
|
|
} from "cc";
|
|
import { Config18x } from "db://assets/Scripts/Main/Config/Config18x";
|
|
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
|
|
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
|
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
|
import { NavigationManager } from "../manager/NavigationManager";
|
|
import { PriceType } from "../../schema/schema";
|
|
import LanguageUtils from "../../Main/Common/LanguageUtils";
|
|
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
|
|
import { DataManager, DataId } from "../data/DataManager";
|
|
import { GirlData } from "../data/GirlData";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("GirlListItem")
|
|
export class GirlListItem extends Component {
|
|
@property(Sprite)
|
|
avatar: Sprite;
|
|
@property(Label)
|
|
girlName: Label;
|
|
@property(Label)
|
|
tags: Label;
|
|
@property(Label)
|
|
price: Label;
|
|
@property(Node)
|
|
freeNode: Node;
|
|
@property(Node)
|
|
unreleaseCover: Node;
|
|
|
|
@property(Node)
|
|
chatIcon: Node;
|
|
|
|
@property(Node)
|
|
starParent: Node;
|
|
|
|
stars: Sprite[];
|
|
|
|
id: number = -1;
|
|
|
|
nameKey: string;
|
|
tagKey: string;
|
|
category: number;
|
|
|
|
private onLanguageChangeCallback = () => {
|
|
if (!this.girlName || !this.tags) return;
|
|
|
|
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
|
let desc = "";
|
|
const tags = LanguageUtils.getText(this.tagKey).split("|");
|
|
for (let i = 0; i < tags.length; i++) {
|
|
if (i != 0) desc += "\n";
|
|
desc += tags[i];
|
|
}
|
|
this.tags.string = desc;
|
|
};
|
|
|
|
protected onLoad(): void {
|
|
Utils.addInnerEL(
|
|
InnerMsgCode.LanguageChange,
|
|
this,
|
|
this.onLanguageChangeCallback
|
|
);
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
Utils.removeInnerEL(
|
|
InnerMsgCode.LanguageChange,
|
|
this,
|
|
this.onLanguageChangeCallback
|
|
);
|
|
}
|
|
|
|
baseNode: Node;
|
|
refreshData(category: number, girlId: number, baseNode: Node) {
|
|
if (!this.stars) {
|
|
this.stars = this.starParent.getComponentsInChildren(Sprite);
|
|
}
|
|
|
|
this.category = category;
|
|
this.baseNode = baseNode;
|
|
this.id = girlId;
|
|
// 数据
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
this.nameKey = girlData.getGrilName(this.category.toString(), this.id);
|
|
this.girlName.string = LanguageUtils.getText(this.nameKey);
|
|
this.tagKey = girlData.getGrilTagKey(this.category.toString(), this.id);
|
|
// 是否已经解锁
|
|
const isRelease = girlData.getIsRelease(this.category.toString(), this.id);
|
|
let desc = "";
|
|
const tags = LanguageUtils.getText(this.tagKey).split("|");
|
|
for (let i = 0; i < tags.length; i++) {
|
|
if (i != 0) desc += "|";
|
|
desc += tags[i];
|
|
}
|
|
this.tags.string = desc;
|
|
let priceType = girlData.getGrilPriceType(
|
|
this.category.toString(),
|
|
this.id
|
|
);
|
|
this.price.string = girlData
|
|
.getGrilOriginalPrice(this.category.toString(), this.id)
|
|
.toString();
|
|
|
|
if (isRelease) {
|
|
this.price.node.active = false;
|
|
this.freeNode.active = false;
|
|
this.starParent.active = true;
|
|
this.chatIcon.active = true;
|
|
this.unreleaseCover.active = false;
|
|
} else {
|
|
this.unreleaseCover.active = true;
|
|
this.chatIcon.active = false;
|
|
if (priceType == PriceType.free) {
|
|
this.price.node.active = false;
|
|
this.freeNode.active = true;
|
|
this.starParent.active = true;
|
|
} else {
|
|
this.price.node.active = true;
|
|
this.freeNode.active = false;
|
|
this.starParent.active = false;
|
|
}
|
|
}
|
|
|
|
// this.price.node.active = priceType == PriceType.pay;
|
|
// this.freeNode.active = priceType == PriceType.free;
|
|
//this.tryNode.active = priceType == PriceType.first_time_free;
|
|
let listAvatarPath = girlData.getGrilAvatar(
|
|
this.category.toString(),
|
|
this.id
|
|
);
|
|
|
|
//listAvatarPath = listAvatarPath.replace("Avatar", "avatar"); //临时
|
|
ResManager.I.changeBundleSpriteFrame(
|
|
this.avatar,
|
|
listAvatarPath,
|
|
"Girls",
|
|
() => {
|
|
let sizeTran = this.avatar.node.parent.getComponent(UITransform);
|
|
Utils.adjustBgPixelRatioToSize(
|
|
sizeTran.contentSize,
|
|
this.avatar.node,
|
|
2
|
|
);
|
|
}
|
|
);
|
|
|
|
const star = girlData.getStar(this.category.toString(), this.id);
|
|
|
|
for (let i = 0; i < this.stars.length; i++) {
|
|
const element = this.stars[i];
|
|
if (star > i) {
|
|
ResManager.I.changeResourceSpriteFrame(element, "ui/common/heart");
|
|
} else {
|
|
ResManager.I.changeResourceSpriteFrame(
|
|
element,
|
|
"ui/common/heart_empty"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
refreshBuy(success: boolean) {
|
|
if (success) {
|
|
this.refreshData(this.category, this.id, this.baseNode);
|
|
}
|
|
}
|
|
|
|
onClickDetail() {
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
// 是否已经解锁
|
|
const isRelease = girlData.getIsRelease(this.category.toString(), this.id);
|
|
if (isRelease) {
|
|
NavigationManager.Instance.navigateToGirlDetail(this.id);
|
|
ViewManager.I.closeView(this.baseNode);
|
|
} else {
|
|
//未解锁
|
|
ViewManager.I.openBundlesPopupView("GirlListPopupPanel", {
|
|
base: this,
|
|
category: this.category,
|
|
id: this.id,
|
|
});
|
|
}
|
|
}
|
|
}
|