init
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
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_TalkRecordInfo } 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';
|
||||
import { ViewManager } from '../../Main/Manager/ViewManager';
|
||||
import { E_RECORD_TYPE } from './Record_UI';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**图鉴 - 相遇记录 */
|
||||
@ccclass('tj_jilu')
|
||||
export class tj_jilu 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()
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
/**获取下一批列表 */
|
||||
getNextPage() {
|
||||
HttpUnit.ins.getTalkJilu({limit:10, page: this.nextPage}, (data) => {
|
||||
if (data && data.length > 0) {
|
||||
this.nextPage++
|
||||
this.huiyiDataList = this.huiyiDataList.concat(data)
|
||||
let len = this.huiyiDataList.length;
|
||||
this.Item_List.numItems = len
|
||||
} else {
|
||||
if (this.nextPage == 1) {
|
||||
this._nodeTab.EmptyNode.active = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region 列表渲染
|
||||
onRenderItemList(node: any, idx: number) {
|
||||
if(!isValid(node)) {return}
|
||||
if (!node.inited) {
|
||||
node.inited = true;
|
||||
Utils.parseNode(node);
|
||||
}
|
||||
|
||||
let data = this.huiyiDataList[idx]
|
||||
let lvCfg = GameManager.getLevelCfg(data.level.id)
|
||||
//名字
|
||||
Utils.setString(node.labName, lvCfg.name)
|
||||
//头像
|
||||
let headPath = `headLevel/${lvCfg.icon}`
|
||||
ResManager.I.changeBundleSpriteFrame(node.head1.getComponent(Sprite), headPath, "Raw")
|
||||
//时间
|
||||
Utils.setString(node.labTime, data.level.end_time)
|
||||
//最后一句对话
|
||||
let lastSay = ""
|
||||
if (data.messages && data.messages.length > 0) {
|
||||
lastSay = data.messages[data.messages.length - 1].ai_response || ""
|
||||
}
|
||||
lastSay = Utils.clampAiAnswer(lastSay, 32)
|
||||
Utils.setString(node.labTalk, lastSay)
|
||||
|
||||
GButton.RemoveAndBandClick(node, ()=>{
|
||||
this.showTalkDetail(idx);
|
||||
}, this);
|
||||
|
||||
//翻到底部加载下一页
|
||||
if (idx >= this.huiyiDataList.length-1) {
|
||||
this.getNextPage()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**显示详细聊天 */
|
||||
showTalkDetail(idx: number) {
|
||||
let data = this.huiyiDataList[idx]
|
||||
let lvCfg = GameManager.getLevelCfg(data.level.id)
|
||||
let talkRecordList: I_TalkRecordInfo[] = []; //对话记录
|
||||
//开场白
|
||||
talkRecordList.push({talk:lvCfg.prologueMessage, isMe:false, score:-1, scoreBase:-1, scoreAdditional:0})
|
||||
//对话
|
||||
let messages = data.messages || []
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let m = messages[i]
|
||||
let aiBaseScore = m.ai_base_score || 0
|
||||
let aiAdditionalScore = m.ai_additional_score || 0
|
||||
talkRecordList.push({talk:m.user_input, isMe:true, score:-1, scoreBase:-1, scoreAdditional:0})
|
||||
talkRecordList.push({talk:m.ai_response, isMe:false, score:m.ai_score, scoreBase:aiBaseScore, scoreAdditional:aiAdditionalScore})
|
||||
}
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Record_UI", {mode:E_RECORD_TYPE.Jilu, talkList:talkRecordList, lvId:data.level.id})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user