130 lines
4.6 KiB
Plaintext
130 lines
4.6 KiB
Plaintext
import { _decorator, instantiate, Label, Node, Prefab, ScrollView, Sprite, tween, UIOpacity, UITransform } from 'cc';
|
|
import { GButton } from '../../Main/Common/GButton';
|
|
import Utils from '../../Main/Common/Utils';
|
|
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
|
|
import li_BaseView from '../../Main/Common/li_BaseView';
|
|
import GameManager from '../../Main/Manager/GameManager';
|
|
import ResManager from '../../Main/Manager/ResManager';
|
|
import { SDKManager } from '../../Main/Channel/SDKManager';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
//聊天记录界面
|
|
@ccclass('Record_UI')
|
|
export class Record_UI extends li_BaseView {
|
|
|
|
@property(Prefab)
|
|
private talkNpcItem: Prefab = null;
|
|
@property(Prefab)
|
|
private talkUserItem: Prefab = null;
|
|
|
|
private _nodeTab: any = {};
|
|
private talkSV: ScrollView = null;
|
|
private _data;
|
|
|
|
private itemNodeList: any[] = [];
|
|
|
|
//----重写父类接口---------------------------------------
|
|
onLoadCT() {
|
|
this.registerListenner();
|
|
Utils.parseNode(this.node, this._nodeTab)
|
|
this.talkSV = this._nodeTab.talkSV.getComponent(ScrollView);
|
|
}
|
|
openUIDataCT(data: any): void {
|
|
this._data = data
|
|
}
|
|
|
|
|
|
registerListenner() {
|
|
// Utils.addInnerEL(InnerMsgCode.GM_UI_Close, this, this.resiveGMClose)
|
|
}
|
|
|
|
|
|
start() {
|
|
GButton.BandClick(this._nodeTab.btnBack, ()=>{
|
|
this.onClose();
|
|
}, this);
|
|
|
|
let lvCfg = GameManager.getLevelCfg(GameManager.CurLevelId)
|
|
//npc名字
|
|
Utils.setString(this._nodeTab.npcName, lvCfg.name)
|
|
|
|
for (let i=0; i<GameManager.TalkRecordList.length; i++) {
|
|
// for (let i=GameManager.TalkRecordList.length-1; i>=0; i--) {
|
|
let info = GameManager.TalkRecordList[i];
|
|
let titem = info.isMe ? this.talkUserItem : this.talkNpcItem;
|
|
let itemClone:any = instantiate(titem);
|
|
this._nodeTab.talkLay.addChild(itemClone);
|
|
|
|
Utils.parseNode(itemClone);
|
|
//头像
|
|
let spt = itemClone.headIcon.getComponent(Sprite)
|
|
if (info.isMe) {
|
|
SDKManager.getUserInfo((data) => {
|
|
ResManager.I.changeRemoteSpriteFrame(spt, data.avatarUrl)
|
|
})
|
|
} else {
|
|
let headPath = `head/${lvCfg.characterAvatar}`
|
|
ResManager.I.changeBundleSpriteFrame(spt.getComponent(Sprite), headPath, "Raw")
|
|
}
|
|
//对话文本
|
|
Utils.setString(itemClone.labTalk, info.talk)
|
|
this.itemNodeList.push(itemClone);
|
|
//得分
|
|
if (info.isMe || info.score < 0) {
|
|
itemClone.labScore.active = false;
|
|
} else {
|
|
itemClone.labScore.active = true;
|
|
Utils.setString(itemClone.labScore, `得分:${info.score}`)
|
|
}
|
|
|
|
//动作
|
|
let kuangOpa:UIOpacity = itemClone.kuang.getComponent(UIOpacity)
|
|
kuangOpa.opacity = 0;
|
|
// let didx = GameManager.TalkRecordList.length-1-i;
|
|
let didx = i;
|
|
let tdelay = didx * 0.05;
|
|
tween(kuangOpa)
|
|
.delay(0.1 + tdelay)
|
|
.to(0.2, { opacity: 255 })
|
|
.start();
|
|
}
|
|
|
|
//延迟一下,设置文本换行模式
|
|
this.scheduleOnce(()=>{
|
|
for (let i=0; i<this.itemNodeList.length; i++) {
|
|
let item = this.itemNodeList[i];
|
|
let labTf:UITransform = item.labTalk.getComponent(UITransform);
|
|
let lab:Label = item.labTalk.getComponent(Label);
|
|
if (labTf.height < 50) { //小于50,说明没换行,改为自动宽度
|
|
lab.overflow = Label.Overflow.NONE;
|
|
} else {
|
|
lab.overflow = Label.Overflow.RESIZE_HEIGHT;
|
|
}
|
|
}
|
|
|
|
let svSize = this.talkSV.getComponent(UITransform).contentSize;
|
|
let contentSize = this.talkSV.content.getComponent(UITransform).contentSize;
|
|
if (contentSize.height > svSize.height) {
|
|
this.talkSV.scrollToBottom();
|
|
}
|
|
}, 0.1)
|
|
|
|
//延迟一下,调整文本框的宽度。高度由layout自动调整
|
|
this.scheduleOnce(()=>{
|
|
for (let i=0; i<this.itemNodeList.length; i++) {
|
|
let item = this.itemNodeList[i];
|
|
let labTf:UITransform = item.labTalk.getComponent(UITransform);
|
|
let kuangTf:UITransform = item.kuang.getComponent(UITransform);
|
|
kuangTf.width = labTf.width + 30;
|
|
}
|
|
}, 0.15)
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|