155 lines
5.0 KiB
Plaintext
155 lines
5.0 KiB
Plaintext
import { _decorator, Component, instantiate, isValid, Label, Material, Node, Prefab, Sprite, tween, UIOpacity, v3 } from 'cc';
|
|
import Utils from '../../Main/Common/Utils';
|
|
import HXZ_ScrollViewList from '../../Main/Common/ScrollViewList';
|
|
import GameManager from '../../Main/Manager/GameManager';
|
|
import { I_HuiyiInfo, I_ZhengCangConfig } from '../../Main/Config/CommonConfig';
|
|
import ResManager from '../../Main/Manager/ResManager';
|
|
import { GButton } from '../../Main/Common/GButton';
|
|
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
|
|
import SubManager from '../SubManager';
|
|
import HttpUnit from '../../Main/Common/HttpUnit';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/**图鉴 - 私房珍藏 */
|
|
@ccclass('tj_zhencang')
|
|
export class tj_zhencang extends Component {
|
|
|
|
private itemClone!: any;
|
|
@property(HXZ_ScrollViewList)
|
|
Item_List: HXZ_ScrollViewList = null!; // 回忆列表
|
|
@property(Prefab)
|
|
Item_Temp: Prefab = null!;//被克隆的模板
|
|
|
|
private _nodeTab:any = {}
|
|
private huiyiDataList: any[] = []
|
|
private nextPage = 1 // 当前页数,每10个记录为一页
|
|
|
|
protected onLoad(): void {
|
|
Utils.parseNode(this.node, this._nodeTab)
|
|
|
|
this.itemClone = instantiate(this.Item_Temp);
|
|
this.Item_List.setTemplateItem(this.itemClone);
|
|
|
|
}
|
|
start() {
|
|
this._nodeTab.EmptyNode.active = false;
|
|
this.getNextPage()
|
|
|
|
//已读红点 珍藏
|
|
let isshow = HttpUnit.IsHaveZhencangRedpoint()
|
|
if (isshow) {
|
|
HttpUnit.ins.readRedpointZhencang({}, (data) => {
|
|
if (data) {
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
|
|
}
|
|
|
|
//刷新列表
|
|
getNextPage() {
|
|
let self = this
|
|
HttpUnit.ins.getZhencangList({limit:10, page:this.nextPage, type:1}, (data) => {
|
|
let lastPage = self.nextPage
|
|
let lastlen = self.huiyiDataList.length
|
|
if (data && data.data && data.data.length > 0) {
|
|
self.nextPage++
|
|
for (let i = 0; i < data.data.length; i++) {
|
|
let item = data.data[i]
|
|
let rcell = GameManager.getZhencangCfg(item.img)
|
|
if (rcell) {
|
|
this.huiyiDataList.push(item)
|
|
}
|
|
}
|
|
}
|
|
|
|
let thislen = self.huiyiDataList.length
|
|
if (thislen > lastlen) {
|
|
let len = Math.ceil(self.huiyiDataList.length / 2);
|
|
self.Item_List.numItems = len
|
|
} else {
|
|
if (lastPage == self.nextPage) {
|
|
if (thislen == 0) {
|
|
self._nodeTab.EmptyNode.active = true
|
|
}
|
|
} else {
|
|
self.getNextPage()
|
|
}
|
|
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
//region 列表渲染
|
|
onRenderItemList(node: any, idx: number) {
|
|
if(!isValid(node)) {return}
|
|
if (!node.inited) {
|
|
node.inited = true;
|
|
Utils.parseNode(node);
|
|
|
|
let opa1:UIOpacity = node.zcItem1.getComponent(UIOpacity)
|
|
let opa2:UIOpacity = node.zcItem2.getComponent(UIOpacity)
|
|
|
|
opa1.opacity = 0
|
|
tween(opa1)
|
|
.delay(0.1)
|
|
.to(0.2, {opacity: 255})
|
|
.start()
|
|
|
|
opa2.opacity = 0
|
|
tween(opa2)
|
|
.delay(0.15)
|
|
.to(0.2, {opacity: 255})
|
|
.start()
|
|
}
|
|
|
|
let startIdx = idx * 2
|
|
this.refreshHuiyiCell(node.zcItem1, startIdx)
|
|
this.refreshHuiyiCell(node.zcItem2, startIdx+1)
|
|
|
|
//翻到底部加载下一页
|
|
if (startIdx+1 >= this.huiyiDataList.length-1) {
|
|
this.getNextPage()
|
|
}
|
|
}
|
|
//刷新单个节点
|
|
private refreshHuiyiCell(zcItem:any, idx:number) {
|
|
let data = this.huiyiDataList[idx]
|
|
if (!data) {
|
|
zcItem.active = false
|
|
return
|
|
}
|
|
zcItem.active = true
|
|
if (!zcItem.inited) {
|
|
zcItem.inited = true;
|
|
Utils.parseNode(zcItem);
|
|
}
|
|
|
|
let zhencangCfg: I_ZhengCangConfig = GameManager.getZhencangCfg(data.img)
|
|
let lvcfg = GameManager.getLevelCfg(zhencangCfg.levelId)
|
|
|
|
//名字
|
|
Utils.setString(zcItem.npcName, lvcfg.name)
|
|
//简介
|
|
let talkstr = Utils.clampAiAnswer(zhencangCfg.giftSummary, 54)
|
|
Utils.setString(zcItem.labTalk, talkstr)
|
|
|
|
let cgPic: Sprite = zcItem.npcPic.getComponent(Sprite)
|
|
//图片
|
|
let picUrl = `${HttpUnit.ZhenCangUrl}${zhencangCfg.giftImgName}.jpg`
|
|
ResManager.I.changeRemoteSpriteFrame(cgPic, picUrl, "jpg")
|
|
|
|
GButton.RemoveAndBandClick(zcItem, ()=>{
|
|
Utils.sendInnerMsg(InnerMsgCode.UI_Tj_huiyi_Pic, {hyItem:zcItem, talk:zhencangCfg.giftSummary})
|
|
HttpUnit.ins.sendEventTujian({type:2, img:zhencangCfg.giftImgName}) //type: 1=心动回忆 2=私房珍藏
|
|
}, this, 0, null, null, false);
|
|
}
|
|
|
|
}
|
|
|
|
|