init
|
After Width: | Height: | Size: 45 KiB |
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "57563773-e4c8-4f04-8789-8accf41e1f18",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
|
After Width: | Height: | Size: 442 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "d03e3e5d-0721-48ed-a87a-61347d0cb4d7",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "d03e3e5d-0721-48ed-a87a-61347d0cb4d7@6c48a",
|
||||
"displayName": "hilaryvel_laugh",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "d03e3e5d-0721-48ed-a87a-61347d0cb4d7",
|
||||
"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": "d03e3e5d-0721-48ed-a87a-61347d0cb4d7@f9941",
|
||||
"displayName": "hilaryvel_laugh",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": -1,
|
||||
"offsetY": -10,
|
||||
"trimX": 0,
|
||||
"trimY": 20,
|
||||
"width": 923,
|
||||
"height": 1169,
|
||||
"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": [
|
||||
-461.5,
|
||||
-584.5,
|
||||
0,
|
||||
461.5,
|
||||
-584.5,
|
||||
0,
|
||||
-461.5,
|
||||
584.5,
|
||||
0,
|
||||
461.5,
|
||||
584.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
1169,
|
||||
923,
|
||||
1169,
|
||||
0,
|
||||
0,
|
||||
923,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
0.9978378378378379,
|
||||
0,
|
||||
0,
|
||||
0.9831791421362489,
|
||||
0.9978378378378379,
|
||||
0.9831791421362489
|
||||
],
|
||||
"minPos": [
|
||||
-461.5,
|
||||
-584.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
461.5,
|
||||
584.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "d03e3e5d-0721-48ed-a87a-61347d0cb4d7@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "d03e3e5d-0721-48ed-a87a-61347d0cb4d7@6c48a"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 951 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "3236e035-8e1b-4af2-8f61-c3182bb91011",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "3236e035-8e1b-4af2-8f61-c3182bb91011@6c48a",
|
||||
"displayName": "may_maria_disgust",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "3236e035-8e1b-4af2-8f61-c3182bb91011",
|
||||
"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": "3236e035-8e1b-4af2-8f61-c3182bb91011@f9941",
|
||||
"displayName": "may_maria_disgust",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 5,
|
||||
"offsetY": -2.5,
|
||||
"trimX": 38,
|
||||
"trimY": 5,
|
||||
"width": 859,
|
||||
"height": 1184,
|
||||
"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": [
|
||||
-429.5,
|
||||
-592,
|
||||
0,
|
||||
429.5,
|
||||
-592,
|
||||
0,
|
||||
-429.5,
|
||||
592,
|
||||
0,
|
||||
429.5,
|
||||
592,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
38,
|
||||
1184,
|
||||
897,
|
||||
1184,
|
||||
38,
|
||||
0,
|
||||
897,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0.04108108108108108,
|
||||
0,
|
||||
0.9697297297297297,
|
||||
0,
|
||||
0.04108108108108108,
|
||||
0.9957947855340622,
|
||||
0.9697297297297297,
|
||||
0.9957947855340622
|
||||
],
|
||||
"minPos": [
|
||||
-429.5,
|
||||
-592,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
429.5,
|
||||
592,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "3236e035-8e1b-4af2-8f61-c3182bb91011@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "3236e035-8e1b-4af2-8f61-c3182bb91011@6c48a"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 877 KiB |
@@ -0,0 +1,88 @@
|
||||
import { _decorator, Button, EventTouch, Node, Vec3 } from "cc";
|
||||
import AudioManager from "../Manager/AudioManager";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
let _vec3 = new Vec3();
|
||||
|
||||
@ccclass('GButton')
|
||||
export class GButton {
|
||||
/**
|
||||
* 添加绑定事件
|
||||
* @param node
|
||||
* @param func 点击结束回调方法
|
||||
* @param obj 上下文
|
||||
* @param buttonType 点击事件类型(处理音效使用)
|
||||
* @param backStart 点击开始回调
|
||||
* @param backCancle 点击取消回调
|
||||
* @returns
|
||||
*/
|
||||
public static BandClick(node: Node, func: Function, obj: any, buttonType=10000, backStart: Function = null, backCancle: Function = null, clickScale: boolean = true): void {
|
||||
if (!node) {
|
||||
//hg_utils.hgLog("GButton, bandClick, failed by node is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buttonType == null) {
|
||||
buttonType = 10000;
|
||||
}
|
||||
|
||||
if (!node['oldScale']) {
|
||||
node['oldScale'] = node.scale.clone();
|
||||
}
|
||||
|
||||
node.on(Node.EventType.TOUCH_START, (ev: EventTouch) => {
|
||||
// let bs = node.getComponent(Button);
|
||||
// if (!bs || (bs && bs.interactable == true)) {
|
||||
// backStart && backStart.call(obj, ev);
|
||||
// }
|
||||
if (clickScale) {
|
||||
node.scale = Vec3.multiplyScalar(_vec3, node['oldScale'], 1.05);
|
||||
}
|
||||
if (backStart) {
|
||||
backStart.call(obj, ev);
|
||||
}
|
||||
}, obj);
|
||||
node.on(Node.EventType.TOUCH_CANCEL, (ev: EventTouch) => {
|
||||
if (clickScale) {
|
||||
node.scale = (node['oldScale'] as Vec3).clone();
|
||||
}
|
||||
if (backCancle) {
|
||||
backCancle.call(obj, ev);
|
||||
}
|
||||
}, obj);
|
||||
node.on(Node.EventType.TOUCH_END, (ev: EventTouch) => {
|
||||
if (clickScale) {
|
||||
node.scale = (node['oldScale'] as Vec3).clone();
|
||||
}
|
||||
//当前节点不是button,或button且不在禁用状态才可以执行点击回调
|
||||
let bs = node.getComponent(Button);
|
||||
if (!bs || (bs && bs.interactable == true)) {
|
||||
func.call(obj, ev);
|
||||
}
|
||||
//点击音效处理
|
||||
if (buttonType > 0) {
|
||||
AudioManager.I.PlayEffect(buttonType); //音效
|
||||
}
|
||||
}, obj);
|
||||
}
|
||||
/**
|
||||
* 移除绑定事件
|
||||
* @param node
|
||||
*/
|
||||
public static RemoveClick(node: Node, func?: Function) {
|
||||
if (node.isValid) {
|
||||
node.off(Node.EventType.TOUCH_START, func);
|
||||
node.off(Node.EventType.TOUCH_END, func);
|
||||
node.off(Node.EventType.TOUCH_CANCEL, func);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 先移除再绑定
|
||||
*/
|
||||
public static RemoveAndBandClick(node: Node, func: Function, obj: any = null, buttonType = null, backStart: Function = null, backCancle: Function = null, clickScale: boolean = true): void {
|
||||
obj = obj || node;
|
||||
GButton.RemoveClick(node);
|
||||
GButton.BandClick(node, func, obj, buttonType, backStart, backCancle, clickScale);
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 41 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "c9854e1c-f8d9-4b23-a87e-0f3d42fd1057",
|
||||
"files": [
|
||||
".jpg",
|
||||
".json"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "c9854e1c-f8d9-4b23-a87e-0f3d42fd1057@6c48a",
|
||||
"displayName": "diduoduo_3_cg",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "c9854e1c-f8d9-4b23-a87e-0f3d42fd1057",
|
||||
"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": "c9854e1c-f8d9-4b23-a87e-0f3d42fd1057@f9941",
|
||||
"displayName": "diduoduo_3_cg",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 996,
|
||||
"height": 1280,
|
||||
"rawWidth": 996,
|
||||
"rawHeight": 1280,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-498,
|
||||
-640,
|
||||
0,
|
||||
498,
|
||||
-640,
|
||||
0,
|
||||
-498,
|
||||
640,
|
||||
0,
|
||||
498,
|
||||
640,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
1280,
|
||||
996,
|
||||
1280,
|
||||
0,
|
||||
0,
|
||||
996,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-498,
|
||||
-640,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
498,
|
||||
640,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "c9854e1c-f8d9-4b23-a87e-0f3d42fd1057@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": false,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "c9854e1c-f8d9-4b23-a87e-0f3d42fd1057@6c48a"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 963 KiB |
|
After Width: | Height: | Size: 378 KiB |
@@ -0,0 +1,970 @@
|
||||
import { _decorator, AudioSource, EditBox, EventTouch, isValid, Label, Node, ScrollView, Sprite, Tween, tween, UIOpacity, utils, v3, 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_TalkStage, 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';
|
||||
import GlobalValue from '../../Main/Common/GlobalValue';
|
||||
import AudioManager from '../../Main/Manager/AudioManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//聊天界面
|
||||
@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, dotTm:0, dotTs:0.3, tm:0, ts:1.5}; //等待npc回复 stage:0-未开始,1-获取中,2-获取完成
|
||||
private aiHuifuInfo = {stage: 0, labAry:[], dotStr:"...", dotIdx:0, dotTm:0, dotTs:0.3}; //等待ai回复 stage:0-未开始,1-获取中,2-获取完成
|
||||
private ebTalk: EditBox;
|
||||
private labNpcTalk: Label;
|
||||
private xindongSpt: Sprite;
|
||||
private lvCfg: I_LevelConfig = null; //当前关卡配置
|
||||
private lastRandTalkIdx: number = -1; //上一次随机对话的索引
|
||||
|
||||
//----重写父类接口---------------------------------------
|
||||
onLoadCT() {
|
||||
Utils.parseNode(this.node, this._nodeTab)
|
||||
this.registerListenner();
|
||||
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.npcTalkSV.on(Node.EventType.TOUCH_START, (event: EventTouch)=>{
|
||||
// event.preventSwallow = true; //允许点击事件穿透
|
||||
// }, this);
|
||||
this._nodeTab.npcTalkSV.getChildByName("view").on(Node.EventType.TOUCH_END, (event:EventTouch) => {
|
||||
// event.preventSwallow = true; //允许点击事件穿透
|
||||
this.onNpcFramClick();
|
||||
}, 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)
|
||||
Utils.addInnerEL(InnerMsgCode.UI_TalkStageUp, this, this.resiveTalkStageUp)
|
||||
Utils.addInnerEL(InnerMsgCode.Data_LevelStarUp, this, this.resiveLevelStarUp)
|
||||
Utils.addInnerEL(InnerMsgCode.Data_ChehuiUp, this, this.resiveChehuiUp)
|
||||
Utils.addInnerEL(InnerMsgCode.UI_ResartGame, this, this.resiveResartGame)
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
//弹窗适配
|
||||
let scaleRatio = Utils.getScaleRatio(2)
|
||||
if (scaleRatio > 1) {
|
||||
scaleRatio = 1;
|
||||
}
|
||||
this._nodeTab.gs1frame.scale = new Vec3(scaleRatio, scaleRatio, 1)
|
||||
//规则内容
|
||||
Utils.setString(this._nodeTab.labGs1Tips, GlobalValue.RuleStr)
|
||||
|
||||
// GButton.BandClick(this._nodeTab.npcTalkFrame, ()=>{
|
||||
// this.onNpcFramClick();
|
||||
// }, this, 0, null, null, false);
|
||||
|
||||
GButton.BandClick(this._nodeTab.btnRecord, ()=>{
|
||||
// // 测试代码
|
||||
// if (true) {
|
||||
// this.showXinAddAnimation()
|
||||
// return
|
||||
// }
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Record_UI")
|
||||
}, this);
|
||||
GButton.BandClick(this._nodeTab.btnTishi, ()=>{
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Tips_UI")
|
||||
//上报服务器记录
|
||||
HttpUnit.ins.sendTipRecord({level_id: this.lvCfg.id}, null)
|
||||
}, this);
|
||||
GButton.BandClick(this._nodeTab.btnAD, ()=>{
|
||||
let contStr = ""
|
||||
let levelData = GameManager.CurLevelData
|
||||
if (!levelData || levelData.ad_num <= 0) {
|
||||
contStr = "关卡内续航次数已用完"
|
||||
} else {
|
||||
contStr = `看广告或分享可额外获取对话次数,剩余${levelData.ad_num}次`
|
||||
}
|
||||
ViewManager.I.openBundlesView("UI/StartUI/TalkAdDialog", {
|
||||
type: E_AD_TARGET.liaotian, //加聊天次数
|
||||
content: contStr,
|
||||
adCallback: ()=>{
|
||||
SDKManager.show_reward_video_ad(this.node.uuid, 1)
|
||||
},
|
||||
shareCallback: ()=>{
|
||||
SDKManager.show_reward_share(this.node.uuid, 1)
|
||||
}
|
||||
})
|
||||
}, this);
|
||||
GButton.BandClick(this._nodeTab.btnJia10, ()=>{
|
||||
let contStr = ""
|
||||
let levelData = GameManager.CurLevelData
|
||||
if (!levelData || levelData.can_use_strength_cnt <= 0) {
|
||||
contStr = "关卡内加分次数已用完"
|
||||
} else {
|
||||
contStr = `下一次聊天的最终得分增加 10 分(不超过 100 分,不影响对话效果)剩余 ${levelData.can_use_strength_cnt} 次`
|
||||
}
|
||||
ViewManager.I.openBundlesView("UI/StartUI/TalkAdDialog", {
|
||||
type: E_AD_TARGET.baoji, //加聊天次数
|
||||
content: contStr,
|
||||
adCallback: (isfree:any)=>{
|
||||
if (isfree){
|
||||
this.doStrengthTalk()
|
||||
} else {
|
||||
SDKManager.show_reward_video_ad(this.node.uuid, 2)
|
||||
}
|
||||
},
|
||||
shareCallback: ()=>{
|
||||
SDKManager.show_reward_share(this.node.uuid, 2)
|
||||
}
|
||||
})
|
||||
}, this);
|
||||
|
||||
GButton.BandClick(this._nodeTab.btnRole, ()=>{
|
||||
this._nodeTab.ruleNode.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) {
|
||||
// 加次数
|
||||
SubManager.ShowPrompt("观看视频成功,获得聊天次数")
|
||||
this.doAddLevelCnt(1)
|
||||
} else if (tag == 2) {
|
||||
// 甜蜜暴击
|
||||
SubManager.ShowPrompt("观看视频成功")
|
||||
this.doStrengthTalk()
|
||||
}
|
||||
})
|
||||
SDKManager.register_share_reward(this.node.uuid, (tag:number)=>{
|
||||
console.log("分享回调", tag)
|
||||
if (tag == 1) {
|
||||
// 加次数
|
||||
SubManager.ShowPrompt("分享成功,获得聊天次数")
|
||||
this.doAddLevelCnt(2)
|
||||
}
|
||||
})
|
||||
|
||||
this.initedGame()
|
||||
this.initXinAni()
|
||||
}
|
||||
|
||||
onDestroy () {
|
||||
super.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
|
||||
}
|
||||
let talksv = this._nodeTab.npcTalkSV.getComponent(ScrollView)
|
||||
talksv.scrollToBottom(0.1)
|
||||
}
|
||||
} else if (this.dazijiInfo.stage == 2) {
|
||||
console.log("文本打字机效果结束")
|
||||
this.dazijiInfo.stage = 0
|
||||
this.dazijiInfo.lab.string = this.dazijiInfo.str
|
||||
this._nodeTab.arrowNode.active = true;
|
||||
let talksv = this._nodeTab.npcTalkSV.getComponent(ScrollView)
|
||||
this.scheduleOnce(() => {
|
||||
talksv.scrollToBottom(0.1)
|
||||
}, 0.1)
|
||||
}
|
||||
|
||||
//接收npc回复逻辑
|
||||
if (this.npcTalkInfo.stage == 1) {
|
||||
//...的频率
|
||||
this.npcTalkInfo.dotTm += deltaTime
|
||||
if (this.npcTalkInfo.dotTm >= this.npcTalkInfo.dotTs) {
|
||||
this.npcTalkInfo.dotTm = 0
|
||||
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
|
||||
}
|
||||
}
|
||||
//sorket获取频率
|
||||
this.npcTalkInfo.tm += deltaTime
|
||||
if (this.npcTalkInfo.tm >= this.npcTalkInfo.ts) {
|
||||
this.npcTalkInfo.tm = 0
|
||||
GameManager.I.getNpcTalkBack({})
|
||||
}
|
||||
}
|
||||
|
||||
//接收ai回复逻辑
|
||||
if (this.aiHuifuInfo.stage == 1) {
|
||||
//...的频率
|
||||
this.aiHuifuInfo.dotTm += deltaTime
|
||||
if (this.aiHuifuInfo.dotTm >= this.aiHuifuInfo.dotTs) {
|
||||
this.aiHuifuInfo.dotTm = 0
|
||||
this.aiHuifuInfo.labAry.forEach((_lab: Label) => {
|
||||
_lab.string = "提示加载中" + this.aiHuifuInfo.dotStr.substring(0, this.aiHuifuInfo.dotIdx)
|
||||
})
|
||||
this.aiHuifuInfo.dotIdx += 1
|
||||
if (this.aiHuifuInfo.dotIdx > this.aiHuifuInfo.dotStr.length) {
|
||||
this.aiHuifuInfo.dotIdx = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region NPC回复消息
|
||||
/**接收到npc回复数据流 */
|
||||
resiveNpcTalkBack(data:I_NpcTalkBack) {
|
||||
this.npcTalkInfo.stage = 0
|
||||
GameManager.TurnToStage(E_TalkStage.npcTalk)
|
||||
|
||||
let npcTalk = GameManager.CurNpcTalkData
|
||||
//npc回复后清空玩家之前的输入
|
||||
if (npcTalk.judgement > -1) {
|
||||
this.ebTalk.string = ""
|
||||
this.refreshInputNum()
|
||||
}
|
||||
//友盟事件上报 对话轮数
|
||||
let id = HttpUnit.GetID()
|
||||
SDKManager.umaEvent(SDKManager.Uma_Event_TalkRound, {
|
||||
userId: id+"", //玩家id
|
||||
ISay: npcTalk.userInput, //玩家发言
|
||||
NpcSay: npcTalk.aiResponse, //npc发言
|
||||
})
|
||||
}
|
||||
|
||||
/**socket连接超时 */
|
||||
resiveSocketTimeout(data:any) {
|
||||
SubManager.ShowConfirm({
|
||||
content: "连接已断开,请重新开始游戏",
|
||||
hideNo: true, //隐藏取消按钮
|
||||
yesCallback: () => {
|
||||
ViewManager.I.closeAllView();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Talk_Back, {})
|
||||
},
|
||||
closeCallback: () => {
|
||||
ViewManager.I.closeAllView();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Talk_Back, {})
|
||||
}
|
||||
})
|
||||
this.npcTalkInfo.stage = 0
|
||||
}
|
||||
|
||||
/**接收到聊天状态变化消息 */
|
||||
resiveTalkStageUp(data:any) {
|
||||
this.refreshTalkStage()
|
||||
}
|
||||
/**接收到星级变化消息 */
|
||||
resiveLevelStarUp(data:any) {
|
||||
if (data && data.level == GameManager.CurLevelId) {
|
||||
for (let i=1; i<=3; i++) {
|
||||
let lsStar = this._nodeTab["lsStar"+i].getComponent(Sprite)
|
||||
let starPath = data.star >= i ? "lv_3" : "lv_2"
|
||||
ResManager.I.changeBundleSpriteFrame(lsStar, starPath, "Zhujiemian")
|
||||
}
|
||||
}
|
||||
}
|
||||
//region 撤回逻辑
|
||||
/**收到撤回消息 */
|
||||
resiveChehuiUp(data:any) {
|
||||
//刷新次数
|
||||
this.refreshTalkStepData()
|
||||
//刷新对话得分
|
||||
this.refreshDuihuaDefen()
|
||||
//刷新心动次数
|
||||
this.refreshXindongCishu(false)
|
||||
//刷新npc表情
|
||||
let talkdata = GameManager.CurNpcTalkData
|
||||
let aiEmoji = talkdata ? talkdata.aiEmoji : ""
|
||||
let rolePath = GameManager.GetNpcEmoPic(aiEmoji)
|
||||
Utils.sendInnerMsg(InnerMsgCode.SceneLayerBgUp, {rolePath:rolePath})
|
||||
}
|
||||
/**重新开始游戏 */
|
||||
resiveResartGame(data:any) {
|
||||
console.log("重新开始游戏")
|
||||
this.initedGame()
|
||||
}
|
||||
|
||||
|
||||
//region UI初始化
|
||||
/**初始化 */
|
||||
initedGame() {
|
||||
this.lvCfg = GameManager.getLevelCfg(GameManager.CurLevelId)
|
||||
|
||||
//背景乐
|
||||
let bgmUrl = `https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/BGM/${this.lvCfg.bgm}.mp3`
|
||||
AudioManager.I.PlayRemoteMusic(bgmUrl, true)
|
||||
|
||||
//名称
|
||||
Utils.setString(this._nodeTab.npcName, this.lvCfg.name)
|
||||
|
||||
//刷新历史星级
|
||||
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.ruleNode.active = false
|
||||
this.hideAiAnswer()
|
||||
|
||||
this.refreshTalkStage()
|
||||
|
||||
//首次进入如果直接是玩家回答,则立即获取ai回复
|
||||
if (GameManager.curStage == E_TalkStage.myTalk) {
|
||||
this.showAiAnswer()
|
||||
}
|
||||
|
||||
//刷新状态显示
|
||||
this.refreshTalkStepData()
|
||||
this.refreshBaojiState()
|
||||
this.refreshXindongCishu(false)
|
||||
this.refreshDuihuaDefen()
|
||||
|
||||
//检测引导
|
||||
this.checkGuide()
|
||||
|
||||
//开始时先自动显示一下npc的攻略
|
||||
if (PlayerDataManager.I.GuideTalkFinished) {
|
||||
this.autoShowNpcTip()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//输入框开始编辑事件
|
||||
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)
|
||||
}
|
||||
//输入框文本改变事件
|
||||
onTextChanged(param1:any, param2:any) {
|
||||
// console.log("聊天界面4: onTextChanged", param1, param2)
|
||||
this.refreshInputNum()
|
||||
}
|
||||
|
||||
|
||||
//刷新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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
//region 刷新聊天状态
|
||||
private refreshTalkStage() {
|
||||
let gStage = GameManager.curStage
|
||||
if (gStage == E_TalkStage.prologue) {
|
||||
this.showNpcPrologue()
|
||||
this.showAiAnswer()
|
||||
} else if (gStage == E_TalkStage.myTalk) {
|
||||
this.turnToMyTalk()
|
||||
} else if (gStage == E_TalkStage.waitNpcTalk) {
|
||||
this.turnToWaitNpcTalk()
|
||||
} else if (gStage == E_TalkStage.npcTalk) {
|
||||
this.turnToNpcTalk(GameManager.CurNpcTalkData)
|
||||
this.showAiAnswer()
|
||||
} else if (gStage == E_TalkStage.npcFixedTalk) {
|
||||
this.turnToNpcFixedTalk(GameManager.CurNpcFixedTalkText)
|
||||
} else if (gStage == E_TalkStage.upTalkStatus) {
|
||||
this.turnToUpdateStage()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//显示NPC开场白
|
||||
private showNpcPrologue() {
|
||||
this._nodeTab.NpcTalkNode.active = true
|
||||
this._nodeTab.MyTalkNode.active = false
|
||||
this._nodeTab.arrowNode.active = false;
|
||||
//开场白
|
||||
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, score:-1, scoreBase:-1, scoreAdditional:0})
|
||||
// this.playAIVoice(this.lvCfg.prologueMessage)
|
||||
}
|
||||
|
||||
/**切换到玩家说话状态 */
|
||||
private turnToMyTalk() {
|
||||
this._nodeTab.NpcTalkNode.active = false
|
||||
this._nodeTab.MyTalkNode.active = true
|
||||
// //刷新npc表情
|
||||
// let rolePath = GameManager.GetNpcEmoPic("")
|
||||
// Utils.sendInnerMsg(InnerMsgCode.SceneLayerBgUp, {rolePath:rolePath})
|
||||
}
|
||||
/**切换到等待NPC说话状态 */
|
||||
private turnToWaitNpcTalk() {
|
||||
this._nodeTab.NpcTalkNode.active = true
|
||||
this._nodeTab.MyTalkNode.active = false
|
||||
this._nodeTab.arrowNode.active = false;
|
||||
this.labNpcTalk.string = ""
|
||||
}
|
||||
/**切换到NPC说话状态 */
|
||||
private turnToNpcTalk(data:I_NpcTalkBack) {
|
||||
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, score:data.aiScore, scoreBase:data.aiBaseScore, scoreAdditional:data.aiAdditionalScore})
|
||||
this.playAIVoice(data.aiResponse)
|
||||
//刷新npc表情
|
||||
let rolePath = GameManager.GetNpcEmoPic(data.aiEmoji)
|
||||
Utils.sendInnerMsg(InnerMsgCode.SceneLayerBgUp, {rolePath:rolePath})
|
||||
//额外分数
|
||||
if (data.aiAdditionalScore > 0) {
|
||||
SubManager.ShowPrompt(`恭喜!聊天加分成功!${data.aiBaseScore} + ${data.aiAdditionalScore}`)
|
||||
}
|
||||
//对话轮次
|
||||
GameManager.srouceCnt = data.sourceCnt
|
||||
this.refreshTalkStepData()
|
||||
}
|
||||
/**切换到npc固定话术展示状态 */
|
||||
private turnToNpcFixedTalk(str:string) {
|
||||
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() {
|
||||
HttpUnit.ins.getTalkStage({record_id: GameManager.RecordId}, (data) => {
|
||||
if (data) {
|
||||
GameManager.CurLevelData = data.level
|
||||
this.refreshTalkStepData()
|
||||
this.refreshBaojiState()
|
||||
this.checkIsFinish()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**刷新心动次数 */
|
||||
private refreshXindongCishu(doAct:boolean = true) {
|
||||
let maxCount = HttpUnit.GetXindongMaxCount()
|
||||
let curCount = GameManager.xindongCishu
|
||||
Utils.setString(this._nodeTab.xindongNum, `${curCount}/${maxCount}`)
|
||||
|
||||
Tween.stopAllByTarget(this.xindongSpt)
|
||||
if (doAct) {
|
||||
tween(this.xindongSpt).to(0.3, { fillRange: curCount / maxCount }).start()
|
||||
} else {
|
||||
this.xindongSpt.fillRange = curCount / 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 curCnt = GameManager.srouceCnt
|
||||
let stepData = GameManager.CurLevelData
|
||||
Utils.setString(this._nodeTab.lunciNum, `${curCnt}/${stepData.total_cnt}`)
|
||||
}
|
||||
/**刷新暴击状态是否显示 */
|
||||
private refreshBaojiState() {
|
||||
let stepData = GameManager.CurLevelData
|
||||
this._nodeTab.baojiNode.active = stepData && stepData.is_strength_take_effect == true
|
||||
}
|
||||
/**刷新玩家输入字数 */
|
||||
private refreshInputNum() {
|
||||
let numMax = this.ebTalk.maxLength
|
||||
let numCur = this.ebTalk.string.length
|
||||
Utils.setString(this._nodeTab.labStrLen, `(${numCur}/${numMax})`)
|
||||
}
|
||||
|
||||
|
||||
//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 = stepData.ad_num > 0 //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 {
|
||||
GameManager.TurnToStage(E_TalkStage.myTalk)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//增加聊天次数 atype: 1=看广告 2=分享
|
||||
private doAddLevelCnt(atype:number) {
|
||||
HttpUnit.ins.addTalkCnt({record_id: GameManager.RecordId, type:atype}, (data) => {
|
||||
if (data) {
|
||||
GameManager.CurLevelData = data.level
|
||||
this.refreshTalkStepData()
|
||||
this.refreshBaojiState()
|
||||
//判断是否继续对话
|
||||
if (GameManager.srouceCnt < data.level.total_cnt) {
|
||||
if (GameManager.curStage != E_TalkStage.waitNpcTalk) {
|
||||
GameManager.TurnToStage(E_TalkStage.myTalk)
|
||||
}
|
||||
} else {
|
||||
this.doJiesuan()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**增强下一轮对话 */
|
||||
private doStrengthTalk() {
|
||||
HttpUnit.ins.sendTalkStrength({record_id: GameManager.RecordId}, (data) => {
|
||||
if (data) {
|
||||
GameManager.CurLevelData = data.level
|
||||
this.refreshBaojiState()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//结算
|
||||
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("结算失败,服务器返回异常!")
|
||||
ViewManager.I.closeAllView();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Talk_Back, {})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//退出聊天
|
||||
onBackClick() {
|
||||
SubManager.ShowConfirm({
|
||||
content: "确定退出吗?\n(退出会保留当前聊天进度)",
|
||||
yesCallback: () => {
|
||||
//退出并结算
|
||||
// this.doJiesuan();
|
||||
|
||||
//只退出聊天,不结算
|
||||
this.onClose();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Talk_Back, {})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//发送消息
|
||||
onSendClick() {
|
||||
let str = this.ebTalk.string;
|
||||
if (str.length == 0) {
|
||||
SubManager.ShowPrompt("请先输入内容")
|
||||
return
|
||||
}
|
||||
GameRootUI.DisableOper(2)
|
||||
HttpUnit.ins.sendUserTalk({record_id: GameManager.RecordId, user_input: str}, (data) => {
|
||||
GameRootUI.EnableOper()
|
||||
if (data) {
|
||||
if (GameManager.curStage != E_TalkStage.myTalk) {
|
||||
return
|
||||
}
|
||||
GameManager.TurnToStage(E_TalkStage.waitNpcTalk)
|
||||
this.hideAiAnswer()
|
||||
//使用服务器处理过的字符串
|
||||
if (data.user_input) {
|
||||
str = data.user_input
|
||||
}
|
||||
GameManager.AddTalkRecord({talk:str, isMe:true, score:-1, scoreBase:-1, scoreAdditional:0})
|
||||
//开始接收npc回复
|
||||
this.npcTalkInfo.stage = 1
|
||||
this.npcTalkInfo.str = ""
|
||||
this.npcTalkInfo.dotTm = this.npcTalkInfo.dotTs
|
||||
this.npcTalkInfo.tm = this.npcTalkInfo.ts
|
||||
this.npcTalkInfo.dotIdx = 1
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//随机回复对话
|
||||
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]
|
||||
this.refreshInputNum()
|
||||
}
|
||||
|
||||
//点击npc对话背景
|
||||
onNpcFramClick() {
|
||||
if (this.dazijiInfo.stage == 1) {
|
||||
this.dazijiInfo.stage = 2
|
||||
} else {
|
||||
if (GameManager.curStage == E_TalkStage.prologue) {
|
||||
GameManager.TurnToStage(E_TalkStage.upTalkStatus)
|
||||
} else if (GameManager.curStage == E_TalkStage.npcTalk) {
|
||||
let npcTalk = GameManager.CurNpcTalkData
|
||||
if (npcTalk.judgement == 0) {
|
||||
console.log("固定鼓励话术展示!", GameManager.npcFixTalkCountXihuan)
|
||||
if (GameManager.npcFixTalkCountXihuan > 0) {
|
||||
GameManager.TurnToStage(E_TalkStage.upTalkStatus)
|
||||
} else {
|
||||
GameManager.CurNpcFixedTalkText = this.lvCfg.encourageMessage
|
||||
GameManager.TurnToStage(E_TalkStage.npcFixedTalk)
|
||||
}
|
||||
GameManager.npcFixTalkCountXihuan = GameManager.npcFixTalkCountXihuan + 1
|
||||
GameManager.xindongCishu = GameManager.xindongCishu + 1
|
||||
this.showXinAddAnimation()
|
||||
// this.refreshXindongCishu(true)
|
||||
} else if (npcTalk.judgement == 2) {
|
||||
console.log("固定厌恶话术展示!", GameManager.npcFixTalkCountTaoyan)
|
||||
if (GameManager.npcFixTalkCountTaoyan > 0) {
|
||||
GameManager.TurnToStage(E_TalkStage.upTalkStatus)
|
||||
} else {
|
||||
GameManager.CurNpcFixedTalkText = this.lvCfg.hateMessage
|
||||
GameManager.TurnToStage(E_TalkStage.npcFixedTalk)
|
||||
}
|
||||
GameManager.npcFixTalkCountTaoyan = GameManager.npcFixTalkCountTaoyan + 1
|
||||
} else {
|
||||
GameManager.TurnToStage(E_TalkStage.upTalkStatus)
|
||||
}
|
||||
} else if (GameManager.curStage == E_TalkStage.npcFixedTalk) {
|
||||
GameManager.TurnToStage(E_TalkStage.upTalkStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region ai生成的回复
|
||||
/**从服务器获取回复 */
|
||||
private showAiAnswer() {
|
||||
this._nodeTab.aiAnsNode.active = true
|
||||
//获取到之前
|
||||
this.aiHuifuInfo.labAry = []
|
||||
for (let i=1; i<=3; i++) {
|
||||
let AiAnsItem: Node = this._nodeTab["AiAnsItem"+i]
|
||||
let labAns = AiAnsItem.getComponentInChildren(Label)
|
||||
labAns.string = "" // "提示加载中..."
|
||||
GButton.RemoveAndBandClick(AiAnsItem, ()=>{
|
||||
SubManager.ShowPrompt("提示获取中,请稍后")
|
||||
}, this);
|
||||
this.aiHuifuInfo.labAry.push(labAns)
|
||||
}
|
||||
|
||||
//播放ai回复效果
|
||||
this.aiHuifuInfo.stage = 1
|
||||
this.aiHuifuInfo.dotTm = this.aiHuifuInfo.dotTs
|
||||
this.aiHuifuInfo.dotIdx = 1
|
||||
|
||||
HttpUnit.ins.getAIAutoAns({record_id: GameManager.RecordId}, (data) => {
|
||||
//获取到之后
|
||||
this.aiHuifuInfo.stage = 0
|
||||
if (data) {
|
||||
console.log("从服务器获取回复", data)
|
||||
// let gStage = GameManager.curStage
|
||||
// if (gStage == E_TalkStage.myTalk) {
|
||||
// this._showAiAnswerUI(data)
|
||||
// }
|
||||
this._showAiAnswerUI(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
private _showAiAnswerUI(ansList: any) {
|
||||
for (let i=1; i<=3; i++) {
|
||||
let AiAnsItem: Node = this._nodeTab["AiAnsItem"+i]
|
||||
let labAns = AiAnsItem.getComponentInChildren(Label)
|
||||
let ans = ansList["tips"+i]
|
||||
if (ans) {
|
||||
labAns.string = this.clampAiAnswer(ans)
|
||||
GButton.RemoveAndBandClick(AiAnsItem, ()=>{
|
||||
this.ebTalk.string = ans
|
||||
this.refreshInputNum()
|
||||
}, this);
|
||||
} else {
|
||||
labAns.string = ""
|
||||
GButton.RemoveClick(AiAnsItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
private hideAiAnswer() {
|
||||
this._nodeTab.aiAnsNode.active = false
|
||||
}
|
||||
//截取字符串,超过长度的用...代替
|
||||
private clampAiAnswer(ansStr: string) {
|
||||
let labelLimit = 20 //字符串长度限制
|
||||
let tempStr: string = "";
|
||||
let tempLen: number = 0;
|
||||
for (let i = 0; i < ansStr.length; i++) {
|
||||
tempLen += ansStr.charCodeAt(i) > 255 ? 2 : 1;
|
||||
if (tempLen > labelLimit) {
|
||||
return tempStr + "...";
|
||||
}
|
||||
tempStr += ansStr.charAt(i);
|
||||
}
|
||||
return ansStr;
|
||||
}
|
||||
|
||||
|
||||
//region 爱心增加动画
|
||||
private _xin1PosOrig: Vec3
|
||||
private _xin2PosOrig: Vec3
|
||||
private _xin2Opa: UIOpacity = null
|
||||
//初始化爱心动画
|
||||
private initXinAni() {
|
||||
this._xin1PosOrig = (this._nodeTab.xinSpt1 as Node).position.clone()
|
||||
this._xin2PosOrig = (this._nodeTab.xinSpt2 as Node).position.clone()
|
||||
this._xin2Opa = this._nodeTab.xinSpt2.getComponent(UIOpacity)
|
||||
this._xin2Opa.opacity = 0
|
||||
}
|
||||
//显示爱心增加动画
|
||||
private showXinAddAnimation() {
|
||||
Tween.stopAllByTarget(this._nodeTab.xinSpt2)
|
||||
Tween.stopAllByTarget(this._xin2Opa)
|
||||
let xinSpt2: Node = this._nodeTab.xinSpt2
|
||||
//缩放
|
||||
xinSpt2.scale = new Vec3(0.1, 0.1, 0.1)
|
||||
tween(xinSpt2)
|
||||
.to(0.2, { scale: new Vec3(2.2, 2.2, 1) }, {easing: 'sineIn'})
|
||||
.to(0.2, { scale: new Vec3(1, 1, 1) }, {easing: 'sineOut'})
|
||||
.start()
|
||||
//移动
|
||||
xinSpt2.position = this._xin2PosOrig
|
||||
tween(xinSpt2)
|
||||
.delay(0.4)
|
||||
.to(0.45, { position: this._xin1PosOrig }, {easing: 'sineIn'})
|
||||
.call(() => {
|
||||
this.showXin2Animation()
|
||||
this.refreshXindongCishu(true) //刷新次数显示
|
||||
})
|
||||
.start()
|
||||
|
||||
// #region 贝塞尔曲线动作
|
||||
// // 三维空间的缓动
|
||||
// const quadraticCurve = (t: number, p1: Vec3, cp: Vec3, p2: Vec3, out: Vec3) => {
|
||||
// out.x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x
|
||||
// out.y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y
|
||||
// out.z = (1 - t) * (1 - t) * p1.z + 2 * t * (1 - t) * cp.z + t * t * p2.z
|
||||
// }
|
||||
// const startPos = this._xin2PosOrig
|
||||
// const controlPos = v3(2, 3, 0)
|
||||
// const endPos = this._xin1PosOrig
|
||||
// const tempVec3 = v3()
|
||||
// tween(xinSpt2)
|
||||
// .to(
|
||||
// 0.45,
|
||||
// { position: endPos },
|
||||
// {
|
||||
// onUpdate: (target, ratio) => {
|
||||
// quadraticCurve(ratio, startPos, controlPos, endPos, tempVec3)
|
||||
// xinSpt2.setPosition(tempVec3)
|
||||
// },
|
||||
// }
|
||||
// )
|
||||
// .call(() => {
|
||||
// this.showXin2Animation()
|
||||
// this.refreshXindongCishu(true) //刷新次数显示
|
||||
// })
|
||||
// .start()
|
||||
// #endregion
|
||||
|
||||
//透明度
|
||||
this._xin2Opa.opacity = 0
|
||||
tween(this._xin2Opa)
|
||||
.to(0.05, { opacity: 255 })
|
||||
.delay(0.75)
|
||||
.to(0.05, { opacity: 0 })
|
||||
.start()
|
||||
}
|
||||
private showXin2Animation() {
|
||||
Tween.stopAllByTarget(this._nodeTab.xinSpt1)
|
||||
let xinSpt1: Node = this._nodeTab.xinSpt1
|
||||
xinSpt1.scale = new Vec3(1, 1, 1)
|
||||
tween(xinSpt1)
|
||||
.to(0.3, {scale: new Vec3(1.4, 1.4, 1.4) }, {easing: 'sineInOut'})
|
||||
.to(0.3, {scale: new Vec3(1, 1, 1) }, {easing: 'sineInOut'})
|
||||
.start()
|
||||
}
|
||||
|
||||
|
||||
//region 引导相关
|
||||
//检查引导
|
||||
private checkGuide() {
|
||||
if (PlayerDataManager.I.GuideTalkFinished) {
|
||||
return
|
||||
}
|
||||
|
||||
let delayInterval = 0.5
|
||||
GameRootUI.DisableOper(delayInterval)
|
||||
this.scheduleOnce(() => {
|
||||
this._nodeTab.ruleNode.active = true
|
||||
},delayInterval)
|
||||
}
|
||||
//引导完成
|
||||
private finishGuide() {
|
||||
if (PlayerDataManager.I.GuideTalkFinished) {
|
||||
return
|
||||
}
|
||||
PlayerDataManager.I.SetGuideTalkFinish(true)
|
||||
|
||||
this.autoShowNpcTip()
|
||||
}
|
||||
//关闭规则弹窗
|
||||
private onRoleCloseClick() {
|
||||
this._nodeTab.ruleNode.active = false
|
||||
this.finishGuide()
|
||||
}
|
||||
|
||||
|
||||
//自动显示NPC提示弹窗
|
||||
private autoShowNpcTip() {
|
||||
if (GameManager.srouceCnt > 0) {
|
||||
return
|
||||
}
|
||||
let delayInterval = 0.5
|
||||
GameRootUI.DisableOper(delayInterval)
|
||||
this.scheduleOnce(() => {
|
||||
ViewManager.I.openBundlesView("UI/StartUI/Tips_UI")
|
||||
},delayInterval)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,524 @@
|
||||
import { randomRange, view } from "cc";
|
||||
import GlobalValue from "../Common/GlobalValue";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import { I_SDK_UserInfo_Callback } from "./SDKManager";
|
||||
import Utils from "../Common/Utils";
|
||||
import uma from "../../../utils/uma.wx.min.js"
|
||||
|
||||
//广告ID
|
||||
const wx_banner_ad_unit_id = 'test'
|
||||
const wx_splash_ad_unit_id = 'test'
|
||||
const wx_video_ad_unit_id = 'test'
|
||||
|
||||
export class WXSDK{
|
||||
|
||||
static g_InGameScene = null; //游戏场景值
|
||||
|
||||
private wx_video:any = null;
|
||||
private wx_splash:any = null;
|
||||
private wx_banner:any = null;
|
||||
private wx_video_callback:Function = null;
|
||||
private wx_video_tag:number = null;
|
||||
private wx_gameClub:any = null; //游戏圈按钮
|
||||
|
||||
private ShareSTime: any;
|
||||
private ShareCb: any; //分享回调
|
||||
private shareTxt = ["分享失败", "请分享到一个群", "请分享给一位好友", "分享过于频繁"]
|
||||
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
// 保持屏幕常亮
|
||||
window['wx'].setKeepScreenOn({ keepScreenOn: true });
|
||||
WXSDK.g_InGameScene = window['wx'].getLaunchOptionsSync().scene;
|
||||
console.log('init 微信 - 进入游戏的场景值', WXSDK.g_InGameScene);
|
||||
|
||||
//显示分享按钮
|
||||
window['wx'].showShareMenu({
|
||||
withShareTicket: true,
|
||||
menus: ["shareAppMessage", "shareTimeline"],
|
||||
});
|
||||
window['wx'].onShareAppMessage(() => {
|
||||
return this.shareInfo();
|
||||
});
|
||||
window['wx'].onShareTimeline(() => {
|
||||
return this.shareInfo();
|
||||
})
|
||||
|
||||
//小游戏回到前台
|
||||
window['wx'].onShow(this.onWxShow.bind(this));
|
||||
//小游戏被隐藏 记个时间
|
||||
window['wx'].onHide(() => {
|
||||
if (this.ShareCb) {
|
||||
this.ShareSTime = new Date().getTime();
|
||||
console.log("分享时间差 记录:", this.ShareSTime);
|
||||
}
|
||||
});
|
||||
|
||||
this.init_video(); //初始化视频广告
|
||||
this.init_splash(); //初始化插屏广告
|
||||
this.init_banner(); //初始化Banner广告 弹窗广告
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
|
||||
//小游戏回到前台
|
||||
onWxShow(data: any) {
|
||||
console.log("onWxShow:" + JSON.stringify(data))
|
||||
//返回小游戏场景值
|
||||
if (data && data.query && data.query.ShareCode) {
|
||||
GlobalValue.ShareTocusid = data.query.ShareCode
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
//分享失败
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**获取用户授权状态
|
||||
* @param autoKey string 授权类型 userInfo=用户信息,对应接口wx.getUserInfo
|
||||
*/
|
||||
checkAutoSetting(autoKey:string, cb:Function = null) {
|
||||
window['wx'].getSetting({
|
||||
success(res:any) {
|
||||
console.log("微信 - 检测权限状态 succ:",JSON.stringify(res))
|
||||
if (autoKey == "userInfo" && res.authSetting['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) {
|
||||
console.log("微信 - 正在获取用户信息...")
|
||||
var self = this;
|
||||
window['wx'].getUserInfo({
|
||||
success: (res) => {
|
||||
console.log("微信 - 获取用户信息成功:", res);
|
||||
cb && cb({avatarUrl:res.userInfo.avatarUrl, nickName:res.userInfo.nickName})
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("微信 - 获取用户信息失败:", err);
|
||||
self.openUserAuthorize(cb);
|
||||
}
|
||||
})
|
||||
}
|
||||
//申请用户信息授权
|
||||
openUserAuthorize(cb: any) {
|
||||
var self = this;
|
||||
window['wx'].getSetting({
|
||||
scope: 'scope.userInfo',
|
||||
success(res:any) {
|
||||
console.log("微信 authorize succ:",JSON.stringify(res))
|
||||
|
||||
if (res.authSetting['scope.userInfo']) {
|
||||
self.getUserInfo(cb)
|
||||
} else {
|
||||
let systemInfo = window['wx'].getSystemInfoSync();
|
||||
let button = window['wx'].createUserInfoButton({
|
||||
type: 'text',
|
||||
text: '',
|
||||
// @ts-ignore
|
||||
style: {
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: systemInfo.screenWidth,
|
||||
height: systemInfo.screenHeight,
|
||||
backgroundColor: '#00000000',//最后两位为透明度
|
||||
textAlign: "center",
|
||||
}
|
||||
});
|
||||
console.log("微信 点击开始游戏授权用户信息")
|
||||
button.onTap((res) => {
|
||||
button.destroy();
|
||||
// if (res.userInfo) {
|
||||
// console.log(res.userInfo)
|
||||
// //此时可进行登录操作
|
||||
// cb && cb(res.userInfo)
|
||||
// }
|
||||
console.log("微信 点击Tap", res)
|
||||
self.getUserInfo(cb)
|
||||
});
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.log('微信 - authorize fail', err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//微信登录
|
||||
login(cb: Function = null) {
|
||||
window['wx'].login({
|
||||
success: (res) => {
|
||||
if (res.code) {
|
||||
console.log('微信 - 登录成功', res.code);
|
||||
cb && cb({ platform:1, code: res.code });
|
||||
} else {
|
||||
console.log('微信 - 登录失败', res.errMsg);
|
||||
cb && cb({ platform:1, code: null });
|
||||
}
|
||||
},
|
||||
fail(res: any) {
|
||||
console.log(`微信 login 调用失败`);
|
||||
console.log(res.anonymousCode)
|
||||
cb && cb({ platform:1, code: null });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//初始化视频广告
|
||||
private init_video() {
|
||||
this.wx_video = window['wx'].createRewardedVideoAd({
|
||||
adUnitId: wx_video_ad_unit_id
|
||||
});
|
||||
this.wx_video.onLoad(() => {
|
||||
console.log('onLoad event emit');
|
||||
});
|
||||
this.wx_video.onError((err) => {
|
||||
console.log('onError event emit', err);
|
||||
});
|
||||
this.wx_video.onClose(res => {
|
||||
console.log('onClose event emit',res);
|
||||
// 用户点击了【关闭广告】按钮
|
||||
// 小于 2.1.0 的基础库版本,res 是一个 undefined
|
||||
if (res && res.isEnded || res === undefined) {
|
||||
// 正常播放结束,可以下发游戏奖励
|
||||
if (this.wx_video_callback) {
|
||||
this.wx_video_callback(this.wx_video_tag);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 播放中途退出,不下发游戏奖励
|
||||
//wx_video_callback(-1);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//初始化插屏广告
|
||||
private init_splash() {
|
||||
// 创建插屏广告实例,提前初始化
|
||||
if (window['wx'].createInterstitialAd){
|
||||
this.wx_splash = window['wx'].createInterstitialAd({
|
||||
adUnitId: wx_splash_ad_unit_id
|
||||
});
|
||||
this.wx_splash.onLoad(() => {
|
||||
console.log('splash onLoad event emit');
|
||||
});
|
||||
this.wx_splash.onError((err) => {
|
||||
console.log('splash onError event emit', err);
|
||||
});
|
||||
this.wx_splash.onClose(res => {
|
||||
console.log('splash onClose event emit', res);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//初始化Banner
|
||||
private init_banner() {
|
||||
let winSize = window['wx'].getSystemInfoSync();
|
||||
let bannerHeight = 80;
|
||||
let bannerWidth = 300;
|
||||
this.wx_banner = window['wx'].createBannerAd({
|
||||
adUnitId: wx_banner_ad_unit_id,
|
||||
adIntervals: 30,
|
||||
style: {
|
||||
left: (winSize.windowWidth- bannerWidth)/2,
|
||||
top: winSize.windowHeight- bannerHeight,
|
||||
width: bannerWidth,
|
||||
}
|
||||
});
|
||||
//微信缩放后得到banner的真实高度,从新设置banner的top 属性
|
||||
this.wx_banner.onResize(res => {
|
||||
this.wx_banner.style.top = winSize.windowHeight - this.wx_banner.style.realHeight;
|
||||
})
|
||||
|
||||
this.wx_banner.onError(res => {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
//显示视频广告
|
||||
show_video(callback:Function, tag:number) {
|
||||
if (wx_video_ad_unit_id == 'test') {
|
||||
console.log('未接入广告ID,视频广告请求直接返回');
|
||||
callback && callback();
|
||||
return;
|
||||
}
|
||||
if (this.wx_video) {
|
||||
this.wx_video_callback = callback;
|
||||
this.wx_video_tag = tag;
|
||||
this.wx_video.load()
|
||||
.then(() => {
|
||||
this.wx_video.show()
|
||||
.catch(err => {
|
||||
this.wx_video.load()
|
||||
.then(() => this.wx_video.show())
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//显示插屏
|
||||
show_splash() {
|
||||
|
||||
// 在适合的场景显示插屏广告
|
||||
// if (this.wx_splash) {
|
||||
// this.wx_splash.show().catch((err) => {
|
||||
// this.wx_splash.load().then(()=>{
|
||||
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
if (this.wx_splash) {
|
||||
this.wx_splash
|
||||
.load()
|
||||
.then(() => {
|
||||
this.wx_splash.show();
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//显示Banner
|
||||
show_banner() {
|
||||
if (this.wx_banner) {
|
||||
this.wx_banner.show(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//隐藏Banner
|
||||
hide_banner() {
|
||||
if (this.wx_banner) {
|
||||
this.wx_banner.hide(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**分享图片*/
|
||||
private SharePicAry = [
|
||||
{id:"7wUnG0FFQry/nCdxI9kKYQ==", url:"https://mmocgame.qpic.cn/wechatgame/W9Az4zfwkAvic2MPaoBEdYEMVht0VwJv6eQF2myMU8IIFbQAZ92Fg73Qp9MUdPMj8/0"},
|
||||
{id:"NCa1cR9YSWinaozMovG6kQ==", url:"https://mmocgame.qpic.cn/wechatgame/uRnpa1JW3rTyYxQHVUI2OaUmHZStMSWfoXPpx7AgceIN2EuqE2DRicDNjcBTA7arK/0"},
|
||||
{id:"adU43/q3Te+86ThFH+8R+g==", url:"https://mmocgame.qpic.cn/wechatgame/fVu8XV4rOQv0iaLzIr4m67DZAOgN1NDe7jSCDoT2ibHuqRkacaeHCdCopIgLzrlBibR/0"},
|
||||
{id:"k93MB1OQQzGuHDv6LhlJ4g==", url:"https://mmocgame.qpic.cn/wechatgame/rrYFeia8mywog7QfGagj9Uiad5Sicu3qNhV6IQcgVkZbUjibaWe70SUsvp9vNESBpje7/0"},
|
||||
{id:"/ry07TA6SXea+AoABH1D+w==", url:"https://mmocgame.qpic.cn/wechatgame/f0cXVicm8xoT33Txqf2o2CRyreAicOiaHh8JFlbxHaDibYWZoBulHTF9v1s3EaUWfaMk/0"},
|
||||
{id:"hYrwZorvQaOP3XbbC77PZw==", url:"https://mmocgame.qpic.cn/wechatgame/HEsiaI4wLnb2SVCthB5pZeBULvWsk71EdlK1WUXic23cPuzeWribbjibjlebOPyNy1wL/0"},
|
||||
{id:"nzn7R/iLQoerxHhYbEM6AQ==", url:"https://mmocgame.qpic.cn/wechatgame/fxaAdTaO5GvRicwozj7sfUiat1ef3XLgjicLLZpeJYWtjyBjIhfh7TP2aZzOItwlpff/0"},
|
||||
{id:"RvJk1ZZzR1iwqKvI39Rt8w==", url:"https://mmocgame.qpic.cn/wechatgame/WibiboKxDQsGxnVMhxebwvouMGnn5MKJibF18lS1iaibo1yrWnoTJgPAIgVX3dZEkV0Ta/0"},
|
||||
{id:"6OgcDWd5SI2R2SmnOxs3Gw==", url:"https://mmocgame.qpic.cn/wechatgame/bpd6RQyPEB7xsoqyzribiaGnibELo6xARRPSLsgtickwcMHtSv920nweBbxIG7OiaJXFo/0"},
|
||||
{id:"6qb2SmFBRgi3pv+pUIbulA==", url:"https://mmocgame.qpic.cn/wechatgame/LXCSUXdVagducqPcChicS5yQWqna7oduKCnzwlG11a7W1Lx6Rwv4Y1tBsMVWqP4Fs/0"},
|
||||
{id:"rdrtaMpJTd6CtMI3dJikHg==", url:"https://mmocgame.qpic.cn/wechatgame/Zzc9s1q36erWTkUxLDjqOus62PTTysBW4PGUaDO5Pr67kT3g9W3HlMakBSiaicxGdH/0"},
|
||||
{id:"sflrnBurRxC2dow0iuQNEg==", url:"https://mmocgame.qpic.cn/wechatgame/YiacDpfxzCGbXUHmtMmcfr8gIF7DicDib6q0pJaiaWXbTWOBGkCbpeuMic1SMgr91v43K/0"},
|
||||
{id:"GkB88GpmR6KvjrV3yMxeWA==", url:"https://mmocgame.qpic.cn/wechatgame/f4fzfIKfgFIBFWxjsFibMUHKQA72JutALOXbuM3vaS0W9ZSUjC2rysb5Tic23lQb95/0"},
|
||||
{id:"UxAhraIxTayr/3Mdhi0Uzg==", url:"https://mmocgame.qpic.cn/wechatgame/qDv24VqH6NBBP0IXNJ2EbSScIic6WsX0KcLJSNs1ThibYJx6QnDnKIT59CcIQSnZvD/0"},
|
||||
{id:"ISSkaxiBRhyn3yZh2AS0eQ==", url:"https://mmocgame.qpic.cn/wechatgame/22HxqYDEUu1yelwdMR30ntjn6rzaYf8QJgrOkFlteicoqbacSptHiaNgK7cygteg99/0"},
|
||||
{id:"m0GQ8b4YTU2u1So1Wr9Rjg==", url:"https://mmocgame.qpic.cn/wechatgame/D8nvAYkIticAEYwTBb3uC83TVferTkpqU5Akj8XGwPCYfNZibTeunZVd5ticqHxvgHC/0"},
|
||||
{id:"F6j57H82QyyiD1i0MaS+0g==", url:"https://mmocgame.qpic.cn/wechatgame/FtniagLR3ueTRx3ibhy98G6pGdC69A38n9jUrVFHEhL9gqceaUnaTpmQHkiaPU1JE4h/0"},
|
||||
{id:"dqd9Gfx2QGKilvChFwoc7Q==", url:"https://mmocgame.qpic.cn/wechatgame/yauvGchcicTl0zx4dYqfhAxl40k7ZbVM59VbPjDPcouesWbPrpsFQzNvfsSUYwUkb/0"},
|
||||
]
|
||||
|
||||
//分享文本
|
||||
private ShareTextAry = [
|
||||
"话术策略大挑战:十句话让 AI 二次元少女心动!",
|
||||
"心动话术挑战,60 位 AI 女友候选等你 Pick!",
|
||||
"二次元话术相亲模拟!60 位 AI 对象等你攻略!",
|
||||
"全 AI 聊天互动!收集二次元少女的心动信号!",
|
||||
"首款 AI 话术策略游戏,攻略个性 AI 二次元女友!",
|
||||
"锻炼你的话术策略,挑战 AI 女友最速结婚路线!",
|
||||
"直男 or 情话海王?60 位 AI 女友检测话术段位!",
|
||||
"高能话术挑战 60 位 AI 少女,解锁专属甜蜜结局!",
|
||||
]
|
||||
|
||||
//分享信息
|
||||
shareInfo() {
|
||||
let rand1 = Utils.getRandomInt(0, this.SharePicAry.length-1);
|
||||
let picmap = this.SharePicAry[rand1];
|
||||
let rand2 = Utils.getRandomInt(0, this.ShareTextAry.length-1);
|
||||
let text = this.ShareTextAry[rand2];
|
||||
console.log("分享:", rand1, rand2);
|
||||
return {
|
||||
title: text,
|
||||
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
|
||||
imageUrl: picmap.url,
|
||||
imageUrlId: picmap.id,
|
||||
}
|
||||
}
|
||||
//主动拉起分享
|
||||
show_share(rewardCB?:Function) {
|
||||
console.log("主动拉起分享");
|
||||
let info:any = this.shareInfo();
|
||||
info.succ = rewardCB;
|
||||
info.fail = null;
|
||||
this.ShareCb = info;
|
||||
window['wx'].shareAppMessage(info);
|
||||
}
|
||||
|
||||
|
||||
//获取设备分辨率
|
||||
getWindowSize() {
|
||||
let windowinfo = window['wx'].getWindowInfo();
|
||||
return {width:windowinfo.screenWidth, height: windowinfo.screenHeight};
|
||||
}
|
||||
|
||||
//显示游戏圈
|
||||
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
|
||||
console.log("显示游戏圈");
|
||||
if (this.wx_gameClub) {
|
||||
this.wx_gameClub.show();
|
||||
}else {
|
||||
let windowinfo = window['wx'].getWindowInfo();
|
||||
let x = windowinfo.screenWidth * leftRatio;
|
||||
let y = windowinfo.screenHeight * topRatio;
|
||||
let w = windowinfo.screenWidth * widthRatio; //按钮宽高
|
||||
let h = windowinfo.screenHeight * heightRatio;
|
||||
|
||||
console.log("游戏圈按钮配置:", windowinfo, leftRatio, topRatio, widthRatio, heightRatio, x, y, w, h);
|
||||
this.wx_gameClub = window['wx'].createGameClubButton({
|
||||
type: 'string',
|
||||
text: '',
|
||||
// type: 'image',
|
||||
icon: 'green',
|
||||
style: {
|
||||
left: x, //这个坐标对应UI上的按钮时,按钮要勾选适配
|
||||
top: y,
|
||||
width: w,
|
||||
height: h,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
//隐藏游戏圈
|
||||
hide_gameClub() {
|
||||
console.log("隐藏游戏圈");
|
||||
if (this.wx_gameClub) {
|
||||
this.wx_gameClub.hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//检查是否支持base64音频播放
|
||||
checkSupportBase64Audio() {
|
||||
return true;
|
||||
}
|
||||
//播放base64音频
|
||||
private _innerAudioContext: any = null;
|
||||
private _iacIdx = 0 //音频播放索引
|
||||
playBase64Audio(base64, loop) {
|
||||
if (!this.checkSupportBase64Audio()) {
|
||||
console.log("微信平台不支持base64音频播放");
|
||||
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['wx'].getFileSystemManager();
|
||||
//1.删除上一个音频
|
||||
const lastPath = window['wx'].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['wx'].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['wx'].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);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region 友盟+
|
||||
//初始化友盟+
|
||||
umaInit() {
|
||||
uma.init({
|
||||
appKey:'67c969b99a16fe6dcd5bfec5',
|
||||
useOpenid:true,// default true
|
||||
autoGetOpenid:true,
|
||||
debug:true,
|
||||
uploadUserInfo:true// 上传用户信息,上传后可以看到有用户头像和昵称的分享信息
|
||||
})
|
||||
console.log("微信 uma 初始化");
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return true;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
window['wx'].uma.trackEvent(eventName, value);
|
||||
console.log("微信 uma 统计:", eventName, value);
|
||||
}
|
||||
}
|
||||
|
||||