364 lines
14 KiB
Plaintext
364 lines
14 KiB
Plaintext
import { _decorator, instantiate, Label, Layout, Node, Prefab, RichText, ScrollView, Sprite, tween, UIOpacity, UITransform, Vec3 } 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';
|
||
import { ViewManager } from '../../Main/Manager/ViewManager';
|
||
import { E_AD_TARGET } from './TalkAdDialog';
|
||
import SubManager from '../SubManager';
|
||
import HttpUnit from '../../Main/Common/HttpUnit';
|
||
const { ccclass, property } = _decorator;
|
||
|
||
//聊天记录界面
|
||
@ccclass('Record_UI')
|
||
export class Record_UI extends li_BaseView {
|
||
|
||
@property(Prefab)
|
||
private talkDescItem: Prefab = null;
|
||
@property(Prefab)
|
||
private talkNpcItem: Prefab = null;
|
||
@property(Prefab)
|
||
private talkUserItem: Prefab = null;
|
||
|
||
private _nodeTab: any = {};
|
||
private talkSV: ScrollView = null;
|
||
private _data;
|
||
|
||
private itemNodeList: any[] = [];
|
||
private itemDataList: 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);
|
||
|
||
//撤回按钮
|
||
GButton.BandClick(this._nodeTab.chehuiNode, ()=>{
|
||
let cellLen = this.itemDataList.length
|
||
if (cellLen <= 1) {
|
||
SubManager.ShowPrompt("没有可以撤回的对话")
|
||
return
|
||
}
|
||
|
||
let contStr = ""
|
||
let levelData = GameManager.CurLevelData
|
||
if (!levelData || levelData.can_use_cancel_cnt <= 0) {
|
||
contStr = "关卡内撤回次数已用完"
|
||
} else {
|
||
contStr = `撤回最近 1 次对话,并返还 1 次对话次数,剩余 ${levelData.can_use_cancel_cnt} 次`
|
||
}
|
||
ViewManager.I.openBundlesView("UI/StartUI/TalkAdDialog", {
|
||
type: E_AD_TARGET.chehui, //撤回,并加聊天次数
|
||
content: contStr,
|
||
adCallback: (isfree: any) => {
|
||
if (isfree) {
|
||
this.doChehuiTalk()
|
||
} else {
|
||
SDKManager.show_reward_video_ad(this.node.uuid, 1)
|
||
}
|
||
},
|
||
shareCallback: ()=>{
|
||
SDKManager.show_reward_share(this.node.uuid, 1)
|
||
}
|
||
})
|
||
}, this);
|
||
|
||
SDKManager.register_video_reward(this.node.uuid, (tag:number)=>{
|
||
console.log("视频广告回调", tag)
|
||
if (tag == 1) {
|
||
// 撤回聊天
|
||
this.doChehuiTalk()
|
||
}
|
||
})
|
||
SDKManager.register_share_reward(this.node.uuid, (tag:number)=>{
|
||
console.log("分享回调", tag)
|
||
if (tag == 1) {
|
||
// 撤回聊天
|
||
this.doChehuiTalk()
|
||
}
|
||
})
|
||
|
||
let lvCfg = GameManager.getLevelCfg(GameManager.CurLevelId)
|
||
//npc名字
|
||
Utils.setString(this._nodeTab.npcName, lvCfg.name)
|
||
|
||
//介绍
|
||
let descClone:any = instantiate(this.talkDescItem)
|
||
this._nodeTab.talkLay.addChild(descClone);
|
||
Utils.parseNode(descClone);
|
||
Utils.setString(descClone.labDesc, lvCfg.tips)
|
||
let descOpa:UIOpacity = descClone.getComponent(UIOpacity)
|
||
descOpa.opacity = 0
|
||
tween(descOpa).to(0.2, {opacity: 255}).start()
|
||
|
||
//聊天列表
|
||
this.itemNodeList = []
|
||
this.itemDataList = []
|
||
let talkLay: Layout = this.talkSV.content.getComponent(Layout)
|
||
let talkCellLen = GameManager.TalkRecordList.length
|
||
let aniTime = 0 //滚动动作总时间
|
||
talkLay.enabled = false;
|
||
for (let i=0; i<talkCellLen; i++) {
|
||
// for (let i=talkCellLen-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);
|
||
this.itemNodeList.push(itemClone);
|
||
this.itemDataList.push(info);
|
||
|
||
let labpx = info.isMe ? -15 : 15;
|
||
itemClone.zw1.position = new Vec3(0, 0, 0)
|
||
itemClone.zw2.position = new Vec3(0, 0, 0)
|
||
itemClone.labTalk1.position = new Vec3(labpx, 0, 0)
|
||
itemClone.labTalk2.position = new Vec3(labpx, 0, 0)
|
||
itemClone.zw1.active = false
|
||
itemClone.zw2.active = false
|
||
itemClone.labTalk1.active = false
|
||
itemClone.labTalk2.active = false
|
||
|
||
//头像
|
||
let spt = itemClone.headIcon.getComponent(Sprite)
|
||
if (info.isMe) {
|
||
let avatarUrl = SDKManager.avatarUrl;
|
||
if (avatarUrl == "" || avatarUrl == null) {
|
||
SDKManager.getUserInfo((data) => {
|
||
ResManager.I.changeRemoteSpriteFrame(spt, data.avatarUrl)
|
||
})
|
||
} else {
|
||
ResManager.I.changeRemoteSpriteFrame(spt, avatarUrl)
|
||
}
|
||
} else {
|
||
let headPath = `head/${lvCfg.characterAvatar}`
|
||
ResManager.I.changeBundleSpriteFrame(spt.getComponent(Sprite), headPath, "Raw")
|
||
}
|
||
|
||
//对话文本前后有各有一个占位节点
|
||
let zw1 = instantiate(itemClone.zw1)
|
||
zw1.active = true
|
||
itemClone.kuang.addChild(zw1)
|
||
//对话文本 括号中间的文字用斜体
|
||
let kidx = 0
|
||
let clab
|
||
for(let i=0; i<10; i++) {
|
||
let kl = info.talk.indexOf("(", kidx) //左括号
|
||
if (kl == -1) {
|
||
if (kidx < info.talk.length) {
|
||
clab = instantiate(itemClone.labTalk2)
|
||
clab.active = true
|
||
itemClone.kuang.addChild(clab)
|
||
Utils.setString(clab, info.talk.substring(kidx, info.talk.length))
|
||
kidx = info.talk.length
|
||
}
|
||
} else {
|
||
let kr = info.talk.indexOf(")", kl) //右括号
|
||
if (kr != -1) {
|
||
//匹配到括号
|
||
if (kidx < kl) {
|
||
clab = instantiate(itemClone.labTalk2)
|
||
clab.active = true
|
||
itemClone.kuang.addChild(clab)
|
||
Utils.setString(clab, info.talk.substring(kidx, kl))
|
||
}
|
||
clab = instantiate(itemClone.labTalk1)
|
||
clab.active = true
|
||
itemClone.kuang.addChild(clab)
|
||
Utils.setString(clab, info.talk.substring(kl+1, kr))
|
||
kidx = kr + 1
|
||
} else {
|
||
if (kidx < info.talk.length) {
|
||
clab = instantiate(itemClone.labTalk2)
|
||
clab.active = true
|
||
itemClone.kuang.addChild(clab)
|
||
Utils.setString(clab, info.talk.substring(kidx, info.talk.length))
|
||
kidx = info.talk.length
|
||
}
|
||
}
|
||
}
|
||
if (kidx >= info.talk.length) {
|
||
break
|
||
}
|
||
}
|
||
let zw2 = instantiate(itemClone.zw1)
|
||
zw2.active = true
|
||
itemClone.kuang.addChild(zw2)
|
||
//基础得分
|
||
let scoreBase = info.scoreBase || -1;
|
||
if (info.isMe || scoreBase < 0) {
|
||
itemClone.labScore.active = false;
|
||
} else {
|
||
itemClone.labScore.active = true;
|
||
Utils.setString(itemClone.labScore, `得分:${scoreBase}`)
|
||
}
|
||
//额外加分
|
||
let scoreAdditional = info.scoreAdditional || 0;
|
||
if (info.isMe || scoreAdditional <= 0) {
|
||
itemClone.labScoreAdd.active = false;
|
||
} else {
|
||
itemClone.labScoreAdd.active = true;
|
||
Utils.setString(itemClone.labScoreAdd, `加分:${scoreAdditional}`)
|
||
}
|
||
|
||
//动作
|
||
let kuangOpa:UIOpacity = itemClone.kuang.getComponent(UIOpacity)
|
||
kuangOpa.opacity = 1;
|
||
// let didx = talkCellLen-1-i;
|
||
let didx = i;
|
||
let tdelay = didx * 0.03;
|
||
let self = this;
|
||
if (i == talkCellLen-1) {
|
||
aniTime = 0.2 + tdelay;
|
||
}
|
||
tween(kuangOpa)
|
||
.delay(0.2 + tdelay)
|
||
.call(()=>{
|
||
//滚动到当前节点处
|
||
self.talkSV.scrollToPercentVertical((talkCellLen-1-i) / talkCellLen, 0.1);
|
||
//调整框宽度
|
||
let widthmax = 0;
|
||
itemClone.kuang.children.forEach((item)=>{
|
||
let tf = item.getComponent(UITransform);
|
||
if (tf && tf.width > widthmax) {
|
||
widthmax = tf.width;
|
||
}
|
||
})
|
||
let kuangTf:UITransform = itemClone.kuang.getComponent(UITransform);
|
||
kuangTf.width = widthmax + 30;
|
||
})
|
||
.to(0.2, { opacity: 255 })
|
||
.start();
|
||
}
|
||
|
||
//延迟一下,设置文本换行模式
|
||
this.scheduleOnce(()=>{
|
||
for (let i=0; i<this.itemNodeList.length; i++) {
|
||
let item = this.itemNodeList[i];
|
||
item.kuang.children.forEach((child)=>{
|
||
let lab = child.getComponent(Label);
|
||
if (lab) {
|
||
let labTf:UITransform = child.getComponent(UITransform);
|
||
if (labTf.height < 50) { //小于50,说明没换行,改为自动宽度
|
||
lab.overflow = Label.Overflow.NONE;
|
||
} else {
|
||
lab.overflow = Label.Overflow.RESIZE_HEIGHT;
|
||
}
|
||
}
|
||
})
|
||
}
|
||
}, 0.1)
|
||
//延迟一下,都设置成一样宽,是右侧的文本左对齐
|
||
this.scheduleOnce(()=>{
|
||
for (let i=0; i<this.itemNodeList.length; i++) {
|
||
let item = this.itemNodeList[i];
|
||
|
||
let widthmax = 0;
|
||
item.kuang.children.forEach((item)=>{
|
||
let tf = item.getComponent(UITransform);
|
||
if (tf && tf.width > widthmax) {
|
||
widthmax = tf.width;
|
||
}
|
||
})
|
||
|
||
item.kuang.children.forEach((child)=>{
|
||
let lab = child.getComponent(Label);
|
||
if (lab) {
|
||
let labTf:UITransform = child.getComponent(UITransform);
|
||
lab.overflow = Label.Overflow.RESIZE_HEIGHT;
|
||
labTf.width = widthmax;
|
||
// if (labTf.height < 50) { //小于50,说明没换行,改为自动宽度
|
||
// lab.overflow = Label.Overflow.NONE;
|
||
// } else {
|
||
// lab.overflow = Label.Overflow.RESIZE_HEIGHT;
|
||
// }
|
||
}
|
||
})
|
||
}
|
||
}, 0.12)
|
||
|
||
//延迟一下,调整文本框的宽度。高度由layout自动调整
|
||
this.scheduleOnce(()=>{
|
||
talkLay.enabled = true;
|
||
}, 0.15)
|
||
|
||
//撤回按钮显示动画
|
||
let chehuiOpa: UIOpacity = this._nodeTab.chehuiNode.getComponent(UIOpacity);
|
||
chehuiOpa.opacity = 0;
|
||
tween(chehuiOpa)
|
||
.delay(aniTime)
|
||
.to(0.2, {opacity: 255})
|
||
.start();
|
||
|
||
//刷新撤回次数
|
||
this.refreshChehuiCount()
|
||
}
|
||
|
||
update(deltaTime: number) {
|
||
|
||
}
|
||
|
||
|
||
/**刷新撤回次数 */
|
||
refreshChehuiCount() {
|
||
let levelData = GameManager.CurLevelData
|
||
let n_cur = levelData.can_use_cancel_cnt || 0
|
||
let n_max = 3
|
||
Utils.setString(this._nodeTab.labChehui, n_cur + "/" + n_max)
|
||
}
|
||
|
||
|
||
/**撤回上一轮发言 */
|
||
doChehuiTalk() {
|
||
HttpUnit.ins.sendTalkChehui({record_id: GameManager.RecordId}, (data) => {
|
||
if (data) {
|
||
SubManager.ShowPrompt("撤回成功,已返还聊天次数")
|
||
GameManager.CurLevelData = data.level
|
||
GameManager.srouceCnt = data.level.current_cnt
|
||
GameManager.RemoveLastRoundTalkRecord()
|
||
GameManager.RemoveLastSetpScore()
|
||
GameManager.removeLastNpcTalkData()
|
||
Utils.sendInnerMsg(InnerMsgCode.Data_ChehuiUp, {})
|
||
this.onClose()
|
||
// this.refreshChehuiCount()
|
||
// let cellLen = this.itemNodeList.length
|
||
// if (cellLen > 1) {
|
||
// for (let i=cellLen-1; i>=0; i--) {
|
||
// let item: Node = this.itemNodeList[i]
|
||
// let info = this.itemDataList[i]
|
||
// item.removeFromParent()
|
||
// this.itemNodeList.splice(i, 1)
|
||
// this.itemDataList.splice(i, 1)
|
||
// if (info && info.isMe) {
|
||
// break
|
||
// }
|
||
// }
|
||
// GameManager.RemoveLastRoundTalkRecord()
|
||
// }
|
||
}
|
||
})
|
||
}
|
||
|
||
}
|
||
|
||
|