init
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 972 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,502 @@
|
||||
import { randomRange } from "cc"
|
||||
import GlobalValue from "../Common/GlobalValue"
|
||||
import { I_SDK_UserInfo, I_SDK_UserInfo_Callback } from "./SDKManager"
|
||||
import SubManager from "../../Sub/SubManager"
|
||||
import Utils from "../Common/Utils"
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode"
|
||||
import HttpUnit from "../Common/HttpUnit"
|
||||
|
||||
//广告ID
|
||||
const AD_AWARD = "1ntrdiqhmdket7v5fe"
|
||||
const AD_SPLASH = "xxxxx"
|
||||
const AD_BANNER = "xxxxx"
|
||||
const AD_BANNER_INTERVAL = 30
|
||||
const AD_BANNER_HEIGHT = 130
|
||||
|
||||
export class ByteDanceSDK{
|
||||
|
||||
private bd_video:any = null;
|
||||
private bd_splash:any = null;
|
||||
private bd_banner:any = null;
|
||||
private bd_video_callback:Function = null;
|
||||
private bd_video_tag:number = null;
|
||||
|
||||
private ShareSTime: any;
|
||||
private ShareCb: any; //分享回调
|
||||
private shareTxt = ["分享失败", "请分享到一个群", "请分享给一位好友", "分享过于频繁"]
|
||||
|
||||
|
||||
/**侧边栏状态 =0不显示 =1显示前往按钮 =2从侧边栏返回 =3奖励已领取 */
|
||||
private static _SidebarState:number = 0;
|
||||
public static get SidebarState():number{
|
||||
return ByteDanceSDK._SidebarState;
|
||||
}
|
||||
|
||||
|
||||
/**检测侧边栏功能是否可用 */
|
||||
public static CheckSidebarState(cb:Function=null){
|
||||
if (HttpUnit.IsBDSidebarReceive()) {
|
||||
ByteDanceSDK._SidebarState = 3;
|
||||
cb && cb(true);
|
||||
return;
|
||||
}
|
||||
if (ByteDanceSDK._SidebarState > 0){
|
||||
cb && cb(true);
|
||||
return;
|
||||
}
|
||||
window['tt'].checkScene({
|
||||
scene: "sidebar",
|
||||
success: (res) => {
|
||||
console.log("抖音 检测侧边栏功能->", res)
|
||||
if (res.isExist == true) {
|
||||
if (ByteDanceSDK._SidebarState == 0) {
|
||||
ByteDanceSDK._SidebarState = 1
|
||||
}
|
||||
}
|
||||
cb && cb(res.isExist == true);
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("抖音 检测侧边栏功能失败->", res)
|
||||
cb && cb(false);
|
||||
}
|
||||
})
|
||||
}
|
||||
/**前往侧边栏 */
|
||||
public static GotoSidebar(cb:Function = null){
|
||||
console.log("抖音 正在前往侧边栏...")
|
||||
window["tt"].navigateToScene({
|
||||
scene: "sidebar",
|
||||
success(res) {
|
||||
console.log("抖音 前往侧边栏 成功")
|
||||
cb && cb(true);
|
||||
},
|
||||
fail(res) {
|
||||
console.log("抖音 前往侧边栏 失败", res)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
console.log("init 抖音 初始化...")
|
||||
// 保持屏幕常亮
|
||||
window["tt"].setKeepScreenOn({
|
||||
keepScreenOn: true,
|
||||
success(res) {
|
||||
},
|
||||
fail(res) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
//小游戏回到前台
|
||||
window['tt'].onShow((res)=>{
|
||||
console.log("抖音 小游戏回到前台->", res)
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
// console.log("启动参数:", res.query);
|
||||
// console.log("来源信息:", res.refererInfo);
|
||||
// console.log("场景值:", res.scene);
|
||||
// console.log("启动场景字段:", res.launch_from, ", ", res.location);
|
||||
|
||||
//返回小游戏场景值
|
||||
if (res.query && res.query.ShareCode) {
|
||||
GlobalValue.ShareTocusid = res.query.ShareCode
|
||||
}
|
||||
|
||||
//从侧边栏返回
|
||||
if (res.launch_from == "homepage" && res.location == "sidebar_card") {
|
||||
console.log("从侧边栏返回, SidebarState=", ByteDanceSDK._SidebarState)
|
||||
if (ByteDanceSDK._SidebarState == 1) {
|
||||
ByteDanceSDK._SidebarState = 2
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_BD_Sidebar, {})
|
||||
//获取奖励
|
||||
HttpUnit.ins.getBDSidebarReward({}, (data) => {
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_BDSidebarReward, {})
|
||||
SubManager.ShowConfirm({
|
||||
content: "侧边栏奖励领取成功,相亲次数+1",
|
||||
hideNo: true, //隐藏取消按钮
|
||||
yesCallback: () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//处理分享事件
|
||||
if (this.ShareCb) {
|
||||
if (this.ShareSTime) {
|
||||
let nT = new Date().getTime();
|
||||
console.log("分享时间差 计算:",nT, this.ShareSTime);
|
||||
if (nT - this.ShareSTime > 1500) {
|
||||
let cb = this.ShareCb.succ
|
||||
cb && cb()
|
||||
} else {
|
||||
this.tostErr()
|
||||
}
|
||||
}
|
||||
this.ShareCb = null;
|
||||
}
|
||||
});
|
||||
//小游戏被隐藏 记个时间
|
||||
window['tt'].onHide(() => {
|
||||
if (this.ShareCb) {
|
||||
this.ShareSTime = new Date().getTime();
|
||||
console.log("分享时间差 记录:", this.ShareSTime);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.init_video();
|
||||
// this.init_splash();
|
||||
// this.init_banner();
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
//分享失败
|
||||
tostErr() {
|
||||
let rint = Math.floor( randomRange(0, this.shareTxt.length - 1) )
|
||||
SubManager.ShowPrompt(this.shareTxt[rint])
|
||||
if (this.ShareCb) {
|
||||
let cb = this.ShareCb.fail
|
||||
cb && cb()
|
||||
}
|
||||
}
|
||||
|
||||
//检查权限
|
||||
checkAutoSetting(autoKey:string, cb:Function = null) {
|
||||
// cb && cb(true);
|
||||
if (autoKey == "userInfo") {
|
||||
autoKey = "scope.userInfo"
|
||||
}
|
||||
window['tt'].authorize({
|
||||
scope: autoKey,
|
||||
success(res:any) {
|
||||
console.log("抖音 - 检测权限状态 succ:", JSON.stringify(res))
|
||||
if (autoKey == "scope.userInfo" && res.data['scope.userInfo']) {
|
||||
cb && cb(true)
|
||||
} else {
|
||||
cb && cb(false)
|
||||
}
|
||||
},
|
||||
fail(res:any) {
|
||||
console.log("抖音 - 检测权限状态 fail:",JSON.stringify(res))
|
||||
cb && cb(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
getUserInfo(cb:I_SDK_UserInfo_Callback = null) {
|
||||
// cb && cb({ nickName:"", avatarUrl:"" });
|
||||
//getUserProfile报错未找到
|
||||
window["tt"].getUserInfo({
|
||||
force: false, //当宿主未登录时,是否强制拉起登录框
|
||||
success(res) {
|
||||
console.log("抖音 - 获取用户信息成功:", res);
|
||||
cb && cb({avatarUrl:res.userInfo.avatarUrl, nickName:res.userInfo.nickName}) //encryptedData
|
||||
},
|
||||
fail(res) {
|
||||
console.log("抖音 - 获取用户信息失败", res);
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//登录
|
||||
login(cb: Function = null) {
|
||||
// cb && cb({ platform:2, code: null });
|
||||
window["tt"].login({
|
||||
force: false, //未登录时, 是否强制调起登录框
|
||||
success(res) {
|
||||
console.log(`抖音 - 登录成功 code=${res.code}, anonymousCode=${res.anonymousCode}`);
|
||||
cb && cb({ platform:2, code: res.code });
|
||||
},
|
||||
fail(res) {
|
||||
console.log(`抖音 - 登录失败`, res);
|
||||
cb && cb({ platform:2, code: null });
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
private init_banner() {
|
||||
|
||||
if (!window["tt"] || !window["tt"].createBannerAd) return
|
||||
|
||||
const systemInfo = window["tt"].getSystemInfoSync();
|
||||
//if (systemInfo.appName.toUpperCase() == 'DOUYIN') return
|
||||
//if (systemInfo.appName.toUpperCase() == 'TOUTIAO' && systemInfo.platform == "ios") return
|
||||
|
||||
if (systemInfo.appName.toUpperCase() == 'DOUYIN' || systemInfo.platform == "ios") return
|
||||
|
||||
const { windowWidth, windowHeight } = window["tt"].getSystemInfoSync();
|
||||
var targetBannerAdWidth = 128+ 100
|
||||
var targetBannerAdHeight = AD_BANNER_HEIGHT
|
||||
// 创建一个居于屏幕底部正中的广告
|
||||
this.bd_banner = window["tt"].createBannerAd({
|
||||
adUnitId: AD_BANNER,
|
||||
adIntervals: AD_BANNER_INTERVAL,
|
||||
style: {
|
||||
width: targetBannerAdWidth,
|
||||
left:(windowWidth - targetBannerAdWidth) / 2,
|
||||
top: windowHeight - targetBannerAdHeight
|
||||
},
|
||||
});
|
||||
|
||||
// 尺寸调整时会触发回调
|
||||
// 注意:如果在回调里再次调整尺寸,要确保不要触发死循环!!!
|
||||
this.bd_banner.onResize(size => {
|
||||
this.bd_banner.style.left = (windowWidth - size.width) / 2;
|
||||
this.bd_banner.style.top = windowHeight - size.height;
|
||||
});
|
||||
|
||||
// bd_banner.onLoad(() => {
|
||||
// bd_banner
|
||||
// .show()
|
||||
// .then(() => {
|
||||
// console.log("init_banner 广告显示成功");
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.log("init_banner 广告组件出现问题", err);
|
||||
// });
|
||||
// })
|
||||
}
|
||||
|
||||
private init_splash() {
|
||||
|
||||
this.preload_splash()
|
||||
}
|
||||
|
||||
private preload_splash() {
|
||||
if (!window["tt"] || !window["tt"].createInterstitialAd) return
|
||||
|
||||
if (this.bd_splash) {
|
||||
if (this.bd_splash['custom_show_stautus']) {
|
||||
this.bd_splash.destroy()
|
||||
this.bd_splash = null
|
||||
} else {
|
||||
if (!this.bd_splash['custom_load_stautus']) {
|
||||
this.bd_splash
|
||||
.load()
|
||||
.catch(err => {
|
||||
console.log("preload_splash err:",err);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.bd_splash) return
|
||||
|
||||
// 创建插屏广告实例,会自动进行一次load
|
||||
this.bd_splash = window["tt"].createInterstitialAd({
|
||||
adUnitId: AD_SPLASH
|
||||
})
|
||||
this.bd_splash.onLoad(function(){
|
||||
this.bd_splash['custom_load_stautus'] = true
|
||||
})
|
||||
this.bd_splash.onClose(function(){
|
||||
this.bd_splash.destroy()
|
||||
this.bd_splash = null
|
||||
|
||||
this.preload_splash()
|
||||
})
|
||||
this.bd_splash.onError(function(err){
|
||||
console.log("bd_splash err:",err)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private init_video() {
|
||||
|
||||
if (!window["tt"] || !window["tt"].createRewardedVideoAd) return
|
||||
|
||||
this.bd_video = window["tt"].createRewardedVideoAd({
|
||||
adUnitId: AD_AWARD,
|
||||
});
|
||||
|
||||
this.bd_video.onClose(res => {
|
||||
if (res.isEnded) {
|
||||
if (this.bd_video_callback) {
|
||||
this.bd_video_callback(this.bd_video_tag);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.bd_video.onError((err) => {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//显示视频广告
|
||||
show_video(callback:Function, tag:number) {
|
||||
if (AD_AWARD as any == 'test') {
|
||||
console.log('未接入广告ID,视频广告请求直接返回');
|
||||
callback && callback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.bd_video) return
|
||||
|
||||
this.bd_video_callback = callback;
|
||||
this.bd_video_tag = tag
|
||||
|
||||
this.bd_video
|
||||
.load()
|
||||
.then(() => {
|
||||
this.bd_video.show()
|
||||
})
|
||||
.catch(err => {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//显示插屏
|
||||
show_splash() {
|
||||
|
||||
//已加载 未展示
|
||||
if (this.bd_splash && this.bd_splash['custom_load_stautus'] && !this.bd_splash['custom_show_stautus']) {
|
||||
this.bd_splash.show().then(() => {
|
||||
this.bd_splash['custom_show_stautus'] = true
|
||||
console.log("插屏广告展示成功");
|
||||
})
|
||||
} else {
|
||||
console.log("插屏广告展示失败");
|
||||
this.preload_splash()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//显示Banner
|
||||
show_banner() {
|
||||
if (this.bd_banner) {
|
||||
this.bd_banner.show(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//隐藏Banner
|
||||
hide_banner() {
|
||||
if (this.bd_banner) {
|
||||
this.bd_banner.hide(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//移除
|
||||
clear_banner() {
|
||||
if (this.bd_banner) {
|
||||
this.bd_banner.destroy(); //banner 默认隐藏(hide) 要打开
|
||||
this.bd_banner = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//分享信息
|
||||
shareInfo() {
|
||||
return {
|
||||
title: "告白契约", //Resource.getText(_shareInfo.invite_des),
|
||||
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
|
||||
}
|
||||
}
|
||||
//主动拉起分享
|
||||
show_share(rewardCB?:Function) {
|
||||
// rewardCB && rewardCB()
|
||||
console.log("主动拉起分享");
|
||||
let info:any = this.shareInfo();
|
||||
info.succ = rewardCB;
|
||||
|
||||
info.success = (res) => {
|
||||
console.log("抖音 主动拉起分享成功", res);
|
||||
}
|
||||
info.fail = (err) => {
|
||||
console.log("抖音 主动拉起分享失败", err);
|
||||
}
|
||||
// info.complete = (res) => {
|
||||
// console.log("抖音 主动拉起分享完成", res);
|
||||
// }
|
||||
|
||||
this.ShareCb = info;
|
||||
window['tt'].shareAppMessage(info);
|
||||
}
|
||||
|
||||
//获取设备分辨率
|
||||
getWindowSize() {
|
||||
return {width:screen.width, height: screen.height};
|
||||
}
|
||||
|
||||
//显示游戏圈
|
||||
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
|
||||
|
||||
}
|
||||
//隐藏游戏圈
|
||||
hide_gameClub() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//检查是否支持base64音频播放
|
||||
checkSupportBase64Audio() {
|
||||
return true;
|
||||
}
|
||||
//播放base64音频
|
||||
private _innerAudioContext: any = null;
|
||||
private _iacIdx = 0 //音频播放索引
|
||||
playBase64Audio(base64, loop) {
|
||||
if (!this.checkSupportBase64Audio()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let substring = base64;
|
||||
let qianzhui = "data:audio/x-wav;base64,"
|
||||
if(base64.startsWith(qianzhui)) {
|
||||
substring = base64.substring(qianzhui.length, base64.length)
|
||||
}
|
||||
|
||||
let self = this;
|
||||
const fs = window['tt'].getFileSystemManager();
|
||||
//1.删除上一个音频
|
||||
const lastPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
console.log("抖音 正在删除上一个音频 ->", lastPath);
|
||||
fs.removeSavedFile({
|
||||
filePath: lastPath,
|
||||
success(res) {
|
||||
console.log("抖音 删除上一个音频成功", res);
|
||||
},
|
||||
fail(err) {
|
||||
console.log("抖音 删除上一个音频失败", err);
|
||||
},
|
||||
complete(res) {
|
||||
console.log("抖音 删除上一个音频完成", res);
|
||||
|
||||
//2.保存当前音频
|
||||
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
|
||||
self._iacIdx++;
|
||||
const audioPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
console.log("抖音 正在保存本次音频 ->", audioPath);
|
||||
fs.writeFile({
|
||||
filePath: audioPath,
|
||||
data: substring,
|
||||
encoding: 'base64',
|
||||
success(res) {
|
||||
if (self._innerAudioContext == null){
|
||||
self._innerAudioContext = window['tt'].createInnerAudioContext();
|
||||
// 添加播放结束的回调
|
||||
self._innerAudioContext.onEnded(() => {
|
||||
console.log("抖音 AI语音播放结束")
|
||||
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
|
||||
self._innerAudioContext.destroy(); // 销毁音频实例
|
||||
self._innerAudioContext = null;
|
||||
});
|
||||
}
|
||||
console.log("抖音 播放base64音频", audioPath)
|
||||
self._innerAudioContext.src = audioPath;
|
||||
self._innerAudioContext.play(); // 开始播放音频
|
||||
},
|
||||
fail(err) {
|
||||
console.log("抖音 保存本次音频失败", err);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "46979c81-b892-4ba4-a8d8-be5e8cec1ebc",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "46979c81-b892-4ba4-a8d8-be5e8cec1ebc@6c48a",
|
||||
"displayName": "zeiterin_disgust",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "46979c81-b892-4ba4-a8d8-be5e8cec1ebc",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "46979c81-b892-4ba4-a8d8-be5e8cec1ebc@f9941",
|
||||
"displayName": "zeiterin_disgust",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": -17,
|
||||
"offsetY": -2,
|
||||
"trimX": 4,
|
||||
"trimY": 4,
|
||||
"width": 883,
|
||||
"height": 1185,
|
||||
"rawWidth": 925,
|
||||
"rawHeight": 1189,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-441.5,
|
||||
-592.5,
|
||||
0,
|
||||
441.5,
|
||||
-592.5,
|
||||
0,
|
||||
-441.5,
|
||||
592.5,
|
||||
0,
|
||||
441.5,
|
||||
592.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
4,
|
||||
1185,
|
||||
887,
|
||||
1185,
|
||||
4,
|
||||
0,
|
||||
887,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0.004324324324324324,
|
||||
0,
|
||||
0.9589189189189189,
|
||||
0,
|
||||
0.004324324324324324,
|
||||
0.9966358284272497,
|
||||
0.9589189189189189,
|
||||
0.9966358284272497
|
||||
],
|
||||
"minPos": [
|
||||
-441.5,
|
||||
-592.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
441.5,
|
||||
592.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "46979c81-b892-4ba4-a8d8-be5e8cec1ebc@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "46979c81-b892-4ba4-a8d8-be5e8cec1ebc@6c48a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "59dec588-bdc9-4f94-a193-156c88a92dc2",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "59dec588-bdc9-4f94-a193-156c88a92dc2@6c48a",
|
||||
"displayName": "tarenaya_stage_icon",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "59dec588-bdc9-4f94-a193-156c88a92dc2",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "59dec588-bdc9-4f94-a193-156c88a92dc2@f9941",
|
||||
"displayName": "tarenaya_stage_icon",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 138,
|
||||
"height": 138,
|
||||
"rawWidth": 138,
|
||||
"rawHeight": 138,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-69,
|
||||
-69,
|
||||
0,
|
||||
69,
|
||||
-69,
|
||||
0,
|
||||
-69,
|
||||
69,
|
||||
0,
|
||||
69,
|
||||
69,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
138,
|
||||
138,
|
||||
138,
|
||||
0,
|
||||
0,
|
||||
138,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-69,
|
||||
-69,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
69,
|
||||
69,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "59dec588-bdc9-4f94-a193-156c88a92dc2@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "59dec588-bdc9-4f94-a193-156c88a92dc2@6c48a"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 950 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 416 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "dbbfabf8-e7f2-41b7-9466-a44d399da244",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "dbbfabf8-e7f2-41b7-9466-a44d399da244@6c48a",
|
||||
"displayName": "nico_disgust",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "dbbfabf8-e7f2-41b7-9466-a44d399da244",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "dbbfabf8-e7f2-41b7-9466-a44d399da244@f9941",
|
||||
"displayName": "nico_disgust",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "none",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 925,
|
||||
"height": 1189,
|
||||
"rawWidth": 925,
|
||||
"rawHeight": 1189,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-462.5,
|
||||
-594.5,
|
||||
0,
|
||||
462.5,
|
||||
-594.5,
|
||||
0,
|
||||
-462.5,
|
||||
594.5,
|
||||
0,
|
||||
462.5,
|
||||
594.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
1189,
|
||||
925,
|
||||
1189,
|
||||
0,
|
||||
0,
|
||||
925,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-462.5,
|
||||
-594.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
462.5,
|
||||
594.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "dbbfabf8-e7f2-41b7-9466-a44d399da244@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "dbbfabf8-e7f2-41b7-9466-a44d399da244@6c48a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { _decorator, Label, Node, Toggle } from 'cc';
|
||||
import { GButton } from '../../Main/Common/GButton';
|
||||
import AudioManager from '../../Main/Manager/AudioManager';
|
||||
import Utils from '../../Main/Common/Utils';
|
||||
import li_BaseView from '../../Main/Common/li_BaseView';
|
||||
import PlayerDataManager from '../../Main/Manager/PlayerDataManager';
|
||||
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
|
||||
import { SDKManager } from '../../Main/Channel/SDKManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//GM命令
|
||||
@ccclass('GM_UI')
|
||||
export class GM_UI extends li_BaseView {
|
||||
|
||||
private _nodeTab: any = {};
|
||||
|
||||
onLoad() {
|
||||
this._nodeTab = {}
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
Utils.parseNode(this.node, this._nodeTab)
|
||||
|
||||
GButton.BandClick(this._nodeTab.BtnClose, this.onCloseClick, this);
|
||||
let musicTg: Toggle = this._nodeTab.musicTg.getComponent(Toggle)
|
||||
musicTg.isChecked = PlayerDataManager.I.IsMusicOn
|
||||
let soudTg: Toggle = this._nodeTab.soudTg.getComponent(Toggle)
|
||||
soudTg.isChecked = PlayerDataManager.I.IsSoundOn
|
||||
|
||||
//GM Log
|
||||
let gmLog = this._nodeTab.gmLogLable.getComponent(Label)
|
||||
gmLog.string = "GM Log:\n" + SDKManager.GMLogString
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//音效开关变化事件 prefab中调用
|
||||
onSoundEvent(target: Toggle, arg2) {
|
||||
if (target) {
|
||||
PlayerDataManager.I.SetSoundOn(target.isChecked)
|
||||
}
|
||||
}
|
||||
|
||||
//音乐开关变化事件 prefab中调用
|
||||
onMusicEvent(target: Toggle, arg2) {
|
||||
if (target) {
|
||||
PlayerDataManager.I.SetMusicOn(target.isChecked)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//关闭按钮
|
||||
onCloseClick() {
|
||||
this.onClose()
|
||||
Utils.sendInnerMsg(InnerMsgCode.GM_UI_Close, {id:1})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 393 KiB |
@@ -0,0 +1,591 @@
|
||||
import { _decorator, AudioSource, EditBox, isValid, Label, Node, Sprite, tween, utils, Vec3 } from 'cc';
|
||||
import { GButton } from '../../Main/Common/GButton';
|
||||
import Utils from '../../Main/Common/Utils';
|
||||
import { ViewManager } from '../../Main/Manager/ViewManager';
|
||||
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
|
||||
import li_BaseView from '../../Main/Common/li_BaseView';
|
||||
import SubManager from '../SubManager';
|
||||
import GameManager, { E_TalkStatusType } from '../../Main/Manager/GameManager';
|
||||
import { I_LevelConfig, I_NpcTalkBack } from '../../Main/Config/CommonConfig';
|
||||
import HttpUnit from '../../Main/Common/HttpUnit';
|
||||
import { SDKManager } from '../../Main/Channel/SDKManager';
|
||||
import ResManager from '../../Main/Manager/ResManager';
|
||||
import PlayerDataManager from '../../Main/Manager/PlayerDataManager';
|
||||
import GameRootUI from '../../Main/Common/GameRootUI';
|
||||
import { E_AD_TARGET } from './TalkAdDialog';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**对话阶段 */
|
||||
const enum TalkStage {
|
||||
/**开场白 */
|
||||
prologue,
|
||||
/**我的对话 */
|
||||
myTalk,
|
||||
/**等待NPC回复 */
|
||||
waitNpcTalk,
|
||||
/**NPC对话 */
|
||||
npcTalk,
|
||||
/**NPC固定话术 */
|
||||
npcFixedTalk,
|
||||
/**更新对话状态 */
|
||||
upTalkStatus,
|
||||
}
|
||||
|
||||
//聊天界面
|
||||
@ccclass('Talk_UI')
|
||||
export class Talk_UI extends li_BaseView {
|
||||
|
||||
private _nodeTab: any = {};
|
||||
private _data;
|
||||
|
||||
private dazijiInfo = {stage: 0, idx: 0, str: "", tm:0, ts:0.05, lab:null}; //打字机信息 stage:0-未开始,1-正在打字,2-打字结束
|
||||
private npcTalkInfo = {stage: 0, str:"", dotStr:"...", dotIdx:0, tm:0, ts:0.3}; //等待npc回复 stage:0-未开始,1-获取中,2-获取完成
|
||||
private ebTalk: EditBox;
|
||||
private labNpcTalk: Label;
|
||||
private xindongSpt: Sprite;
|
||||
private curStage: TalkStage = TalkStage.prologue; //当前对话阶段
|
||||
private lvCfg: I_LevelConfig = null; //当前关卡配置
|
||||
private lastRandTalkIdx: number = -1; //上一次随机对话的索引
|
||||
private srouceCnt: number = 0; //已用对话轮次
|
||||
private xindongCishu: number = 0; //心动次数
|
||||
|
||||
//----重写父类接口---------------------------------------
|
||||
onLoadCT() {
|
||||
this.registerListenner();
|
||||
Utils.parseNode(this.node, this._nodeTab)
|
||||
this.ebTalk = this._nodeTab.ebTalk.getComponent(EditBox);
|
||||
this.labNpcTalk = this._nodeTab.npcTalk.getComponent(Label);
|
||||
this.xindongSpt = this._nodeTab.xindongSpt.getComponent(Sprite);
|
||||
this.ebTalk.node.on('editing-did-began', this.onEditingBegan, this);
|
||||
this.ebTalk.node.on('editing-did-ended', this.onEditingEnded, this);
|
||||
this.ebTalk.node.on('editing-return', this.onEditingReturn, this);
|
||||
|
||||
this._nodeTab.arrowNode.active = false;
|
||||
let npcNextArrow:Node = this._nodeTab.npcNextArrow
|
||||
tween(npcNextArrow)
|
||||
.to(0.5, {position: new Vec3(15, 0, 0)})
|
||||
.to(0.5, {position: new Vec3(-15, 0, 0)})
|
||||
.union()
|
||||
.repeatForever()
|
||||
.start()
|
||||
}
|
||||
openUIDataCT(data: any): void {
|
||||
this._data = data
|
||||
}
|
||||
|
||||
|
||||
registerListenner() {
|
||||
Utils.addInnerEL(InnerMsgCode.Data_NpcTalkBack, this, this.resiveNpcTalkBack)
|
||||
Utils.addInnerEL(InnerMsgCode.UI_Socket_Timeout, this, this.resiveSocketTimeout)
|
||||
}
|
||||
|
||||
|
||||
start() {
|
||||
GButton.BandClick(this._nodeTab.btnBack, this.onBackClick, this);
|
||||
GButton.BandClick(this._nodeTab.btnSend, this.onSendClick, this);
|
||||
GButton.BandClick(this._nodeTab.btnSuiji, this.onSuijiClick, this);
|
||||
|
||||
GButton.BandClick(this._nodeTab.npcTalkFrame, ()=>{
|
||||
this.onNpcFramClick();
|
||||
}, this, 0, null, null, false);
|
||||
|
||||
GButton.BandClick(this._nodeTab.btnRecord, ()=>{
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Record_UI")
|
||||
}, this);
|
||||
GButton.BandClick(this._nodeTab.btnTishi, ()=>{
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Tips_UI")
|
||||
}, this);
|
||||
GButton.BandClick(this._nodeTab.btnAD, ()=>{
|
||||
ViewManager.I.openBundlesView("UI/StartUI/TalkAdDialog", {
|
||||
type: E_AD_TARGET.liaotian, //加聊天次数
|
||||
content: "看广告或分享可额外获取对话次数",
|
||||
adCallback: ()=>{
|
||||
SDKManager.show_reward_video_ad(this.node.uuid, 1)
|
||||
},
|
||||
shareCallback: ()=>{
|
||||
SDKManager.show_reward_share(this.node.uuid, 1)
|
||||
}
|
||||
})
|
||||
}, this);
|
||||
|
||||
GButton.BandClick(this._nodeTab.btnRole, ()=>{
|
||||
this._nodeTab.roleNode.active = true
|
||||
}, this);
|
||||
GButton.BandClick(this._nodeTab.btnRoleOk, ()=>{
|
||||
this.onRoleCloseClick()
|
||||
}, this);
|
||||
GButton.BandClick(this._nodeTab.btnRoleClose, ()=>{
|
||||
this.onRoleCloseClick()
|
||||
}, this);
|
||||
|
||||
//ai语音开关
|
||||
GButton.BandClick(this._nodeTab.btnYuyin, ()=>{
|
||||
GameManager.AIVoiceSwt = !GameManager.AIVoiceSwt;
|
||||
this.refreshAIVoiceState()
|
||||
}, this);
|
||||
this.refreshAIVoiceState()
|
||||
if (!SDKManager.checkSupportBase64Audio()) {
|
||||
this._nodeTab.btnYuyin.active = false
|
||||
}
|
||||
|
||||
SDKManager.register_video_reward(this.node.uuid, (tag:number)=>{
|
||||
console.log("视频广告回调", tag)
|
||||
if (tag == 1) {
|
||||
// 加次数
|
||||
HttpUnit.ins.setUserAd({type:2}, (data) => {
|
||||
let addCnt = HttpUnit.GetTalkAdAddNum()
|
||||
SubManager.ShowPrompt("观看视频成功,获得聊天次数")
|
||||
this.doAddLevelCnt(addCnt)
|
||||
})
|
||||
}
|
||||
})
|
||||
SDKManager.register_share_reward(this.node.uuid, (tag:number)=>{
|
||||
console.log("分享回调", tag)
|
||||
if (tag == 1) {
|
||||
// 加次数
|
||||
HttpUnit.ins.setUserShare({type:2}, (data) => {
|
||||
let addCnt = HttpUnit.GetTalkShareAddNum()
|
||||
SubManager.ShowPrompt("分享成功,获得聊天次数")
|
||||
this.doAddLevelCnt(addCnt)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
this.lvCfg = GameManager.getLevelCfg(GameManager.CurLevelId)
|
||||
|
||||
//刷新历史星级
|
||||
for (let i=1; i<=3; i++) {
|
||||
let lsStar = this._nodeTab["lsStar"+i].getComponent(Sprite)
|
||||
let starPath = this.lvCfg.star >= i ? "lv_3" : "lv_2"
|
||||
ResManager.I.changeBundleSpriteFrame(lsStar, starPath, "Zhujiemian")
|
||||
}
|
||||
|
||||
this._nodeTab.roleNode.active = false
|
||||
this.srouceCnt = 0
|
||||
this.xindongCishu = 0
|
||||
|
||||
let scaleRatio = Utils.getScaleRatio(2)
|
||||
if (scaleRatio > 1) {
|
||||
scaleRatio = 1;
|
||||
}
|
||||
this._nodeTab.gs1frame.scale = new Vec3(scaleRatio, scaleRatio, 1)
|
||||
|
||||
//以npc开场白
|
||||
this.showNpcPrologue()
|
||||
//刷新状态显示
|
||||
this.refreshTalkStepData()
|
||||
this.refreshXindongCishu()
|
||||
this.refreshDuihuaDefen()
|
||||
|
||||
//检测引导
|
||||
this.checkGuide()
|
||||
}
|
||||
|
||||
onDestroy () {
|
||||
if (isValid(this.ebTalk)) {
|
||||
this.ebTalk.node.off('editing-did-began', this.onEditingBegan, this);
|
||||
this.ebTalk.node.off('editing-did-ended', this.onEditingEnded, this);
|
||||
this.ebTalk.node.off('editing-return', this.onEditingReturn, this);
|
||||
}
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
//region 打字机效果逻辑
|
||||
if (this.dazijiInfo.stage == 1) {
|
||||
this.dazijiInfo.tm += deltaTime
|
||||
if (this.dazijiInfo.tm >= this.dazijiInfo.ts) {
|
||||
this.dazijiInfo.tm = 0
|
||||
this.dazijiInfo.lab.string = this.dazijiInfo.str.substring(0, this.dazijiInfo.idx)
|
||||
|
||||
this.dazijiInfo.idx += 1
|
||||
if (this.dazijiInfo.idx > this.dazijiInfo.str.length) {
|
||||
this.dazijiInfo.stage = 2
|
||||
}
|
||||
}
|
||||
} else if (this.dazijiInfo.stage == 2) {
|
||||
console.log("文本打字机效果结束")
|
||||
this.dazijiInfo.stage = 0
|
||||
this.dazijiInfo.lab.string = this.dazijiInfo.str
|
||||
this._nodeTab.arrowNode.active = true;
|
||||
// if (this.curStage == TalkStage.prologue || this.curStage == TalkStage.npcTalk) {
|
||||
// this.scheduleOnce(() => {
|
||||
// this.turnToMyTalk()
|
||||
// }, 2)
|
||||
// }
|
||||
}
|
||||
|
||||
//接收npc回复逻辑
|
||||
if (this.npcTalkInfo.stage == 1) {
|
||||
this.npcTalkInfo.tm += deltaTime
|
||||
if (this.npcTalkInfo.tm >= this.npcTalkInfo.ts) {
|
||||
this.npcTalkInfo.tm = 0
|
||||
GameManager.I.getNpcTalkBack({})
|
||||
|
||||
this.labNpcTalk.string = this.npcTalkInfo.dotStr.substring(0, this.npcTalkInfo.dotIdx)
|
||||
this.npcTalkInfo.dotIdx += 1
|
||||
if (this.npcTalkInfo.dotIdx > this.npcTalkInfo.dotStr.length) {
|
||||
this.npcTalkInfo.dotIdx = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region AI回复消息
|
||||
/**接收到npc回复数据流 */
|
||||
resiveNpcTalkBack(data:I_NpcTalkBack) {
|
||||
if (this.curStage != TalkStage.waitNpcTalk) return
|
||||
if (data.isFinished) {
|
||||
this.npcTalkInfo.stage = 0
|
||||
console.log("npc回复:", data)
|
||||
GameManager.CurNpcTalkData = data
|
||||
this.turnToNpcTalk(data)
|
||||
}
|
||||
}
|
||||
|
||||
/**socket连接超时 */
|
||||
resiveSocketTimeout(data:any) {
|
||||
SubManager.ShowConfirm({
|
||||
content: "连接已断开,请重新开始游戏",
|
||||
hideNo: true, //隐藏取消按钮
|
||||
yesCallback: () => {
|
||||
this.doClose();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Talk_Back, {})
|
||||
}
|
||||
})
|
||||
this.npcTalkInfo.stage = 0
|
||||
}
|
||||
|
||||
|
||||
//输入框开始编辑事件
|
||||
onEditingBegan(param1:any, param2:any) {
|
||||
console.log("聊天界面1: onEditingBegan", param1, param2)
|
||||
}
|
||||
//输入框回车事件
|
||||
onEditingReturn(param1:any, param2:any) {
|
||||
console.log("聊天界面2: onEditingReturn", param1, param2)
|
||||
}
|
||||
//输入框结束编辑事件
|
||||
onEditingEnded(param1:any, param2:any) {
|
||||
console.log("聊天界面3: onEditingEnded", param1, param2)
|
||||
}
|
||||
|
||||
|
||||
//刷新AI语音状态
|
||||
private refreshAIVoiceState() {
|
||||
let voicePath = GameManager.AIVoiceSwt ? "lv_4" : "lv_5"
|
||||
let sptYuyin = this._nodeTab.sptYuyin.getComponent(Sprite)
|
||||
ResManager.I.changeBundleSpriteFrame(sptYuyin, voicePath, "Zhujiemian")
|
||||
}
|
||||
|
||||
//播放AI语音
|
||||
private playAIVoice(str:string) {
|
||||
if (!GameManager.AIVoiceSwt) {
|
||||
return //开关没开
|
||||
}
|
||||
if (!SDKManager.checkSupportBase64Audio()) {
|
||||
return //不支持base64音频
|
||||
}
|
||||
HttpUnit.ins.getAIVoice({record_id: GameManager.RecordId, text:str}, (data) => {
|
||||
if (data) {
|
||||
console.log("播放AI语音11", data)
|
||||
SDKManager.playBase64Audio(data.url, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//显示NPC开场白
|
||||
private showNpcPrologue() {
|
||||
this.curStage = TalkStage.prologue
|
||||
this._nodeTab.NpcTalkNode.active = true
|
||||
this._nodeTab.MyTalkNode.active = false
|
||||
this._nodeTab.arrowNode.active = false;
|
||||
//名称
|
||||
Utils.setString(this._nodeTab.npcName, this.lvCfg.name)
|
||||
//开场白
|
||||
this.dazijiInfo.stage = 1
|
||||
this.dazijiInfo.idx = 0
|
||||
this.dazijiInfo.lab = this.labNpcTalk
|
||||
this.dazijiInfo.str = this.lvCfg.prologueMessage
|
||||
this.dazijiInfo.tm = this.dazijiInfo.ts
|
||||
GameManager.AddTalkRecord({talk:this.lvCfg.prologueMessage, isMe:false})
|
||||
// this.playAIVoice(this.lvCfg.prologueMessage)
|
||||
}
|
||||
|
||||
/**切换到玩家说话状态 */
|
||||
private turnToMyTalk() {
|
||||
if (this.curStage == TalkStage.myTalk) return
|
||||
this.curStage = TalkStage.myTalk
|
||||
this._nodeTab.NpcTalkNode.active = false
|
||||
this._nodeTab.MyTalkNode.active = true
|
||||
this.ebTalk.string = ""
|
||||
}
|
||||
/**切换到等待NPC说话状态 */
|
||||
private turnToWaitNpcTalk() {
|
||||
if (this.curStage == TalkStage.waitNpcTalk) return
|
||||
this.curStage = TalkStage.waitNpcTalk
|
||||
this._nodeTab.NpcTalkNode.active = true
|
||||
this._nodeTab.MyTalkNode.active = false
|
||||
this._nodeTab.arrowNode.active = false;
|
||||
this.labNpcTalk.string = ""
|
||||
}
|
||||
/**切换到NPC说话状态 */
|
||||
private turnToNpcTalk(data:I_NpcTalkBack) {
|
||||
if (this.curStage == TalkStage.npcTalk) return
|
||||
this.curStage = TalkStage.npcTalk
|
||||
this._nodeTab.NpcTalkNode.active = true
|
||||
this._nodeTab.MyTalkNode.active = false
|
||||
this._nodeTab.arrowNode.active = false;
|
||||
GameManager.AddStepScore(data.aiScore) //记录本次分数
|
||||
this.refreshDuihuaDefen()
|
||||
//npc回复
|
||||
// this.labNpcTalk.string = data.aiResponse
|
||||
this.dazijiInfo.stage = 1
|
||||
this.dazijiInfo.idx = 0
|
||||
this.dazijiInfo.lab = this.labNpcTalk
|
||||
this.dazijiInfo.str = data.aiResponse
|
||||
this.dazijiInfo.tm = this.dazijiInfo.ts
|
||||
GameManager.AddTalkRecord({talk:data.aiResponse, isMe:false})
|
||||
this.playAIVoice(data.aiResponse)
|
||||
//npc表情
|
||||
|
||||
//分数
|
||||
|
||||
//对话轮次
|
||||
this.srouceCnt = data.sourceCnt
|
||||
this.refreshTalkStepData()
|
||||
}
|
||||
/**切换到npc固定话术展示状态 */
|
||||
private turnToNpcFixedTalk(str:string) {
|
||||
if (this.curStage == TalkStage.npcFixedTalk) return
|
||||
this.curStage = TalkStage.npcFixedTalk
|
||||
this._nodeTab.NpcTalkNode.active = true
|
||||
this._nodeTab.MyTalkNode.active = false
|
||||
this._nodeTab.arrowNode.active = false;
|
||||
//npc固定话术
|
||||
this.dazijiInfo.stage = 1
|
||||
this.dazijiInfo.idx = 0
|
||||
this.dazijiInfo.lab = this.labNpcTalk
|
||||
this.dazijiInfo.str = str
|
||||
this.dazijiInfo.tm = this.dazijiInfo.ts
|
||||
}
|
||||
/**切换到更新聊天状态状态 */
|
||||
private turnToUpdateStage() {
|
||||
if (this.curStage == TalkStage.upTalkStatus) return
|
||||
this.curStage = TalkStage.upTalkStatus
|
||||
HttpUnit.ins.getTalkStage({record_id: GameManager.RecordId}, (data) => {
|
||||
if (data) {
|
||||
GameManager.CurLevelData = data.level
|
||||
this.checkIsFinish()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**刷新心动次数 */
|
||||
private refreshXindongCishu() {
|
||||
let maxCount = HttpUnit.GetXindongMaxCount()
|
||||
Utils.setString(this._nodeTab.xindongNum, `${this.xindongCishu}/${maxCount}`)
|
||||
this.xindongSpt.fillRange = this.xindongCishu / maxCount
|
||||
}
|
||||
/**刷新对话得分 */
|
||||
private refreshDuihuaDefen() {
|
||||
let curScore = GameManager.getCurStepScore()
|
||||
let [totalScore, pjScore] = GameManager.getGameScore()
|
||||
Utils.setString(this._nodeTab.scoreNew, curScore+"")
|
||||
Utils.setString(this._nodeTab.scoreTotal, totalScore+"")
|
||||
}
|
||||
/**刷新当前状态显示 */
|
||||
private refreshTalkStepData() {
|
||||
let stepData = GameManager.CurLevelData
|
||||
Utils.setString(this._nodeTab.lunciNum, `${this.srouceCnt}/${stepData.total_cnt}`)
|
||||
}
|
||||
|
||||
//region 检测是否结束
|
||||
/**检查对话轮次是否用完
|
||||
* @returns [是否结束对话,是否显示广告加次数]
|
||||
*/
|
||||
private checkIsFinish() {
|
||||
|
||||
let isFinish = false //是否结束对话
|
||||
let isShowAD = false //是否显示广告
|
||||
let isSendEnd = false //是否发送结束请求
|
||||
let stepData = GameManager.CurLevelData
|
||||
if (stepData.status == E_TalkStatusType.succ) {
|
||||
//已成功
|
||||
isFinish = true
|
||||
} else if (stepData.status == E_TalkStatusType.fail) {
|
||||
//已失败
|
||||
isFinish = true
|
||||
} else if (stepData.status == E_TalkStatusType.noCount) {
|
||||
//次数已用完
|
||||
isFinish = true
|
||||
isShowAD = true
|
||||
isSendEnd = true
|
||||
}
|
||||
|
||||
if (isFinish) {
|
||||
if (isShowAD) {
|
||||
ViewManager.I.openBundlesView("UI/StartUI/TalkAdDialog", {
|
||||
type: E_AD_TARGET.liaotian, //加聊天次数
|
||||
content: "看广告或分享可额外获取对话次数",
|
||||
adCallback: ()=>{
|
||||
SDKManager.show_reward_video_ad(this.node.uuid, 1)
|
||||
},
|
||||
shareCallback: ()=>{
|
||||
SDKManager.show_reward_share(this.node.uuid, 1)
|
||||
},
|
||||
closeCallback: ()=>{
|
||||
if (isSendEnd) {
|
||||
this.doJiesuan()
|
||||
} else {
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Finish_UI", stepData)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (isSendEnd) {
|
||||
this.doJiesuan()
|
||||
} else {
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Finish_UI", stepData)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.turnToMyTalk()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//增加聊天次数
|
||||
private doAddLevelCnt(add:number = 1) {
|
||||
HttpUnit.ins.addTalkCnt({record_id: GameManager.RecordId, add_cnt:add}, (data) => {
|
||||
if (data) {
|
||||
GameManager.CurLevelData = data.level
|
||||
this.refreshTalkStepData()
|
||||
//判断是否继续对话
|
||||
if (this.srouceCnt < data.level.total_cnt) {
|
||||
this.turnToMyTalk()
|
||||
} else {
|
||||
this.doJiesuan()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//结算
|
||||
private doJiesuan() {
|
||||
let [score_all, score] = GameManager.getGameScore()
|
||||
HttpUnit.ins.sendLevelFinish({record_id: GameManager.RecordId, score:score, score_all:score_all}, (data) => {
|
||||
if (data && data.level) {
|
||||
//成功
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Finish_UI", data.level)
|
||||
} else {
|
||||
//失败
|
||||
console.warn("结算失败,服务器返回异常!")
|
||||
this.doClose();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Talk_Back, {})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//退出聊天
|
||||
onBackClick() {
|
||||
SubManager.ShowConfirm({
|
||||
content: "确定退出吗?",
|
||||
yesCallback: () => {
|
||||
this.doJiesuan();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//发送消息
|
||||
onSendClick() {
|
||||
let str = this.ebTalk.string;
|
||||
if (str.length == 0) {
|
||||
SubManager.ShowPrompt("请先输入内容")
|
||||
return
|
||||
}
|
||||
this.turnToWaitNpcTalk()
|
||||
this.ebTalk.string = ""
|
||||
HttpUnit.ins.sendUserTalk({record_id: GameManager.RecordId, user_input: str}, (data) => {
|
||||
if (data) {
|
||||
GameManager.AddTalkRecord({talk:str, isMe:true})
|
||||
//开始接收npc回复
|
||||
this.npcTalkInfo.stage = 1
|
||||
this.npcTalkInfo.str = ""
|
||||
this.npcTalkInfo.tm = this.npcTalkInfo.ts
|
||||
this.npcTalkInfo.dotIdx = 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//随机回复对话
|
||||
onSuijiClick() {
|
||||
let sjLen = this.lvCfg.randomInputPool.length
|
||||
let randIdx = Utils.getRandomInt(0, sjLen-1)
|
||||
console.log("随机回复对话:", randIdx, sjLen)
|
||||
if (randIdx == this.lastRandTalkIdx) {
|
||||
randIdx++
|
||||
if (randIdx >= sjLen) randIdx = 0
|
||||
}
|
||||
this.lastRandTalkIdx = randIdx
|
||||
this.ebTalk.string = this.lvCfg.randomInputPool[randIdx]
|
||||
}
|
||||
|
||||
//点击npc对话背景
|
||||
onNpcFramClick() {
|
||||
if (this.dazijiInfo.stage == 1) {
|
||||
this.dazijiInfo.stage = 2
|
||||
} else {
|
||||
if (this.curStage == TalkStage.prologue) {
|
||||
this.turnToUpdateStage()
|
||||
} else if (this.curStage == TalkStage.npcTalk) {
|
||||
// let stepData = GameManager.CurLevelData
|
||||
let npcTalk = GameManager.CurNpcTalkData
|
||||
if (npcTalk.judgement == 0) {
|
||||
console.log("固定鼓励话术展示!")
|
||||
this.turnToNpcFixedTalk(this.lvCfg.encourageMessage)
|
||||
this.xindongCishu++
|
||||
this.refreshXindongCishu()
|
||||
} else if (npcTalk.judgement == 2) {
|
||||
console.log("固定厌恶话术展示!")
|
||||
this.turnToNpcFixedTalk(this.lvCfg.hateMessage)
|
||||
} else {
|
||||
this.turnToUpdateStage()
|
||||
}
|
||||
} else if (this.curStage == TalkStage.npcFixedTalk) {
|
||||
this.turnToUpdateStage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region 引导相关
|
||||
//检查引导
|
||||
private checkGuide() {
|
||||
if (PlayerDataManager.I.GuideTalkFinished) {
|
||||
return
|
||||
}
|
||||
|
||||
let delayInterval = 0.5
|
||||
GameRootUI.DisableOper(delayInterval)
|
||||
this.scheduleOnce(() => {
|
||||
this._nodeTab.roleNode.active = true
|
||||
},delayInterval)
|
||||
}
|
||||
//引导完成
|
||||
private finishGuide() {
|
||||
if (PlayerDataManager.I.GuideTalkFinished) {
|
||||
return
|
||||
}
|
||||
PlayerDataManager.I.SetGuideTalkFinish(true)
|
||||
}
|
||||
//关闭规则弹窗
|
||||
private onRoleCloseClick() {
|
||||
this._nodeTab.roleNode.active = false
|
||||
this.finishGuide()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "8648256e-8fb9-43e9-871d-3524c3f058b5",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "8648256e-8fb9-43e9-871d-3524c3f058b5@6c48a",
|
||||
"displayName": "nico_portrait",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "8648256e-8fb9-43e9-871d-3524c3f058b5",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "8648256e-8fb9-43e9-871d-3524c3f058b5@f9941",
|
||||
"displayName": "nico_portrait",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": -19,
|
||||
"trimX": 0,
|
||||
"trimY": 38,
|
||||
"width": 276,
|
||||
"height": 326,
|
||||
"rawWidth": 276,
|
||||
"rawHeight": 364,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-138,
|
||||
-163,
|
||||
0,
|
||||
138,
|
||||
-163,
|
||||
0,
|
||||
-138,
|
||||
163,
|
||||
0,
|
||||
138,
|
||||
163,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
326,
|
||||
276,
|
||||
326,
|
||||
0,
|
||||
0,
|
||||
276,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0.8956043956043956,
|
||||
1,
|
||||
0.8956043956043956
|
||||
],
|
||||
"minPos": [
|
||||
-138,
|
||||
-163,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
138,
|
||||
163,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "8648256e-8fb9-43e9-871d-3524c3f058b5@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "8648256e-8fb9-43e9-871d-3524c3f058b5@6c48a"
|
||||
}
|
||||
}
|
||||