init
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { _decorator, Component, EditBox, Label, macro, Node, view } from 'cc';
|
||||
import GameRootUI from './GameRootUI';
|
||||
const { ccclass, property, requireComponent } = _decorator;
|
||||
|
||||
//输入框事件监听
|
||||
@ccclass('EditBoxEvent')
|
||||
// @requireComponent(EditBox) //装饰器,表示这个组件必须包含EditBox组件
|
||||
export class EditBoxEvent extends Component {
|
||||
|
||||
private eb: EditBox = null!; //输入框组件
|
||||
|
||||
onLoad() {
|
||||
}
|
||||
|
||||
start() {
|
||||
this.eb = this.node.getComponent(EditBox)!;
|
||||
// this.node.on('editing-did-began', this.onEditDidBegan, this);
|
||||
this.node.on(EditBox.EventType.EDITING_DID_BEGAN, this.onEditDidBegan, this);
|
||||
this.node.on(EditBox.EventType.EDITING_DID_ENDED, this.onEditDidEnded, this);
|
||||
this.node.on(EditBox.EventType.EDITING_RETURN, this.onEditingReturn, this);
|
||||
console.log("EditBoxEvent: start.")
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
onEditDidBegan(editbox, customEventData) {
|
||||
console.log("EditBoxEvent: 开始编辑...")
|
||||
// view.setOrientation(macro.ORIENTATION_LANDSCAPE); //设置横屏
|
||||
// console.log("窗口大小 开始:", view.getVisibleSize(), GameRootUI.MainCamera)
|
||||
|
||||
}
|
||||
|
||||
onEditDidEnded(editbox, customEventData) {
|
||||
console.log("EditBoxEvent: 结束编辑.")
|
||||
// view.setOrientation(macro.ORIENTATION_LANDSCAPE); //设置横屏
|
||||
// console.log("窗口大小 结束:", view.getVisibleSize(), GameRootUI.MainCamera)
|
||||
}
|
||||
|
||||
onEditingReturn(editbox, customEventData) {
|
||||
console.log("EditBoxEvent: 按下返回.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "630cbad4-2995-47f6-8eb8-8844e8a356d5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d31f5542-1059-4930-b661-7cce067875bd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import { _decorator, assetManager, Camera, Canvas, Component, director, DynamicAtlasManager, instantiate, macro, Node, sys, tween, UIOpacity, Vec3 } from "cc";
|
||||
import { CommonConfig } from "../Config/CommonConfig";
|
||||
import ResManager from "../Manager/ResManager";
|
||||
import Utils from "./Utils";
|
||||
|
||||
const { ccclass, property, executeInEditMode, disallowMultiple } = _decorator;
|
||||
|
||||
//游戏根目录 每个场景都要加一下
|
||||
@ccclass
|
||||
// @executeInEditMode
|
||||
@disallowMultiple
|
||||
export default class GameRootUI extends Component {
|
||||
public static I: GameRootUI = null;
|
||||
|
||||
//当前场景摄像机
|
||||
private static _MainCamera: Camera = null;
|
||||
public static get MainCamera(): Camera {
|
||||
return GameRootUI._MainCamera
|
||||
}
|
||||
public static set MainCamera(value: Camera){
|
||||
GameRootUI._MainCamera = value
|
||||
}
|
||||
|
||||
public LayerNodeGroups = {} //界面组
|
||||
@property(Node)
|
||||
UIRoot: Node = null
|
||||
@property(Node)
|
||||
UILayerMod: Node = null
|
||||
@property
|
||||
public DefaultUI: string = "" //默认打开的界面
|
||||
|
||||
onLoad() {
|
||||
GameRootUI.I = this;
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
//创建界面层
|
||||
for (const key in CommonConfig.UILayerGroup) {
|
||||
if (isNaN(Number(key))) {
|
||||
let newNode = instantiate(this.UILayerMod);
|
||||
newNode.name = key
|
||||
this.UIRoot.addChild(newNode)
|
||||
newNode.setPosition(Vec3.ZERO)
|
||||
newNode.setScale(Vec3.ONE)
|
||||
let l_idx = CommonConfig.UILayerGroup[key]
|
||||
newNode.setSiblingIndex(Number(l_idx))
|
||||
this.LayerNodeGroups[key] = newNode
|
||||
}
|
||||
}
|
||||
|
||||
//默认打开的界面
|
||||
if (this.DefaultUI.length > 0) {
|
||||
ResManager.I.loadSubpackagePrefab(this.DefaultUI, (res)=>{
|
||||
|
||||
let viewSP = res.getComponent(res.name);
|
||||
viewSP && viewSP.openUIData && viewSP.openUIData(null);
|
||||
|
||||
this.AddUIToLayer(res, CommonConfig.UILayerGroup.Layer_ui1);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected update(dt: number): void {
|
||||
GameRootUI.I.CheckDisableOperTime(dt)
|
||||
}
|
||||
|
||||
|
||||
//手动创建时需要调用一下初始化
|
||||
public InitByCreate(_UIRoot: Node, _UILayerMod: Node, _DefaultUI: string) {
|
||||
this.UIRoot = _UIRoot
|
||||
this.UILayerMod = _UILayerMod
|
||||
this.DefaultUI = _DefaultUI
|
||||
}
|
||||
|
||||
//添加一个界面到某个层上
|
||||
public AddUIToLayer(ui:Node, e_layer:CommonConfig.UILayerGroup, zorder:number = 0){
|
||||
if (ui == null)
|
||||
return
|
||||
var n_layer = CommonConfig.UILayerGroup[e_layer]
|
||||
if (this.LayerNodeGroups[n_layer] != null){
|
||||
this.LayerNodeGroups[n_layer].addChild(ui)
|
||||
ui.setSiblingIndex(zorder)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//禁用操作界面----------------------------------------------------------------------------
|
||||
private static DisableOperUI: Node = null;
|
||||
private static DisableOperSwt: boolean = false;
|
||||
private static DisableOperDura: number = 0;
|
||||
private static DisableOperTime: number = 0;
|
||||
public static InitDisableOperUI(isshow: boolean) {
|
||||
if (GameRootUI.DisableOperUI == null){
|
||||
ResManager.I.loadSubpackagePrefab("UI/Cross/DisableOper_UI", (res:Node)=>{
|
||||
if (!GameRootUI.DisableOperUI) {
|
||||
GameRootUI.DisableOperUI = res
|
||||
director.getScene().addChild(res);
|
||||
director.addPersistRootNode(res);
|
||||
res.setSiblingIndex(9999)
|
||||
let croot = GameRootUI.DisableOperUI.getChildByName("croot")
|
||||
croot.active = false
|
||||
}
|
||||
|
||||
if (isshow) {
|
||||
GameRootUI.DisableOper(GameRootUI.DisableOperDura)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
/**开启禁用操作
|
||||
* @param dura 禁用时间 单位秒
|
||||
*/
|
||||
public static DisableOper(dura: number) {
|
||||
if (GameRootUI.DisableOperDura < dura){
|
||||
GameRootUI.DisableOperDura = dura
|
||||
}
|
||||
if (GameRootUI.DisableOperUI == null){
|
||||
GameRootUI.InitDisableOperUI(true)
|
||||
return
|
||||
}
|
||||
|
||||
Utils.Log("禁用操作 开启")
|
||||
GameRootUI.DisableOperSwt = true
|
||||
let croot = GameRootUI.DisableOperUI.getChildByName("croot")
|
||||
croot.active = true
|
||||
}
|
||||
/**关闭禁用操作 */
|
||||
public static EnableOper() {
|
||||
GameRootUI.DisableOperSwt = false
|
||||
GameRootUI.DisableOperDura = 0
|
||||
GameRootUI.DisableOperTime = 0
|
||||
if (GameRootUI.DisableOperUI){
|
||||
let croot = GameRootUI.DisableOperUI.getChildByName("croot")
|
||||
croot.active = false
|
||||
}
|
||||
Utils.Log("禁用操作 关闭")
|
||||
}
|
||||
private CheckDisableOperTime(dt: number) {
|
||||
if (!GameRootUI.DisableOperSwt)
|
||||
return
|
||||
GameRootUI.DisableOperTime += dt;
|
||||
if (GameRootUI.DisableOperTime >= GameRootUI.DisableOperDura){
|
||||
GameRootUI.EnableOper();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//过场界面----------------------------------------------------------------------------
|
||||
public static CrossUI: Node = null;
|
||||
public static InitCrossUI(isshow: boolean, cb = null) {
|
||||
if (GameRootUI.CrossUI == null){
|
||||
ResManager.I.loadSubpackagePrefab("UI/Cross/Cross_UI", (res:Node)=>{
|
||||
if (!GameRootUI.CrossUI) {
|
||||
GameRootUI.CrossUI = res
|
||||
director.getScene().addChild(res);
|
||||
director.addPersistRootNode(res);
|
||||
res.setSiblingIndex(9999)
|
||||
let croot = GameRootUI.CrossUI.getChildByName("croot")
|
||||
croot.active = false
|
||||
}
|
||||
|
||||
if (isshow) {
|
||||
GameRootUI.ShowCrossUI(cb)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
public static ShowCrossUI(cb = null) {
|
||||
// if (true) {
|
||||
// return
|
||||
// }
|
||||
|
||||
if (GameRootUI.CrossUI == null){
|
||||
GameRootUI.InitCrossUI(true)
|
||||
return
|
||||
}
|
||||
|
||||
// //设置摄像机
|
||||
// let canvas = GameRootUI.CrossUI.getComponent(Canvas)
|
||||
// canvas.cameraComponent = GameRootUI.MainCamera
|
||||
|
||||
//自动隐藏
|
||||
// Utils.Log("Cross 显示切换界面")
|
||||
let croot = GameRootUI.CrossUI.getChildByName("croot")
|
||||
croot.active = true
|
||||
let opa = croot.getComponent(UIOpacity)
|
||||
opa.opacity = 255
|
||||
tween(opa)
|
||||
.delay(0.3)
|
||||
.to(0.3, {opacity: 0})
|
||||
.call(()=>{
|
||||
croot.active = false
|
||||
// Utils.Log("Cross 隐藏切换界面")
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9fcf429c-5b25-4ade-89cb-6180e71f9a72",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { _decorator } from "cc";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//全局变量
|
||||
@ccclass
|
||||
export default class GlobalValue {
|
||||
static IsTest = false; //测试环境
|
||||
/**是否开启GM */
|
||||
static GMSwtitch = false;
|
||||
/**关卡数据中途缓存开关 */
|
||||
static LvHuancun = true;
|
||||
/**npc使用视频显示 */
|
||||
static NpcVideoMod = true;
|
||||
|
||||
/**分享关注id */
|
||||
static ShareTocusid = "share_tocusid";
|
||||
public static m_DomainData: any = {};
|
||||
// public static m_loginData = {};
|
||||
public static g_ChannelCfg = {};
|
||||
|
||||
/**规则说明内容 */
|
||||
public static RuleStr =
|
||||
`现在开始相亲!游戏规则如下:
|
||||
1. 你需要参考“关卡提示”,了解对方喜欢/厌恶的话题,投其所好,与对方聊天,说出让对方“心动”的对话。
|
||||
|
||||
2. 单次对话评分在 70 分以上即为心动对话,满足 5 次即可通关,游戏结束并解锁 1 星“通关”结局。
|
||||
|
||||
3. 对话中包含至少 1 次 90 分以上的对话,则可以解锁 2 星“恋人”结局。
|
||||
|
||||
4. 对话中包含至少 1 次 100 分的满分对话,则可以解锁 3 星“结婚”结局。
|
||||
|
||||
5. 对话次数耗尽,但仍然没有通关时,则视为相亲失败,解锁 0 星“失败”结局。
|
||||
|
||||
6. 如果出现 30 分及以下的对话,那么游戏会提前结束,视为相亲失败,解锁 0 星“失败”结局。
|
||||
|
||||
7. 默认拥有 10 次对话机会,可通过分享/观看广告增加对话机会,每次相亲中,最多可对话 25 次。
|
||||
|
||||
8. 可以通过友好地与对方交流喜好来获取高分。
|
||||
|
||||
9. 试着诱导让对方说出“愿意交往”,“愿意结婚”等表达交往意愿的对话来获取满分。`
|
||||
|
||||
|
||||
/**广告弹窗文本 加相亲次数 */
|
||||
public static XiangQinAdTipsStr = "每天只有 3 次相亲次数,请谨慎使用。每日可分享 1 次游戏,获得 1 次相亲次数,观看广告可获得 2 次相亲次数,最多可观看 3 次,每日 5:00 刷新相亲次数以及奖励获取次数。"
|
||||
|
||||
public static g_InGameScene = 0;//小程序获取当前进页面的来源
|
||||
public static g_InviteCode = ''; //玩家是否是通过邀请号进入的游
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**人物视频类型 */
|
||||
export enum VideoRoleType {
|
||||
None,
|
||||
/**待机动作 循环 */
|
||||
Idle,
|
||||
/**表情动作 */
|
||||
emo,
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0fa2fb18-9099-4544-957d-40caaae7f806",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,792 @@
|
||||
import { _decorator, sys } from "cc";
|
||||
import { SDKManager } from "../Channel/SDKManager";
|
||||
import GlobalValue from "./GlobalValue";
|
||||
import { I_UserInfo } from "../Config/CommonConfig";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import Utils from "./Utils";
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* http通讯
|
||||
*/
|
||||
@ccclass
|
||||
export default class HttpUnit {
|
||||
//业务接口
|
||||
static readonly ServerHttpHost = "https://xqmnyx.vip.hnhxzkj.com/api/"; //正式
|
||||
// static readonly ServerHttpHost = "https://test.xqmnyx.vip.hnhxzkj.com/api/"; //测试
|
||||
|
||||
//socket通讯
|
||||
static readonly SocketHost = "wss://www.confessioncontract.com/game/ai/response/"; //正式
|
||||
// static readonly SocketHost = "wss://www.confessioncontract.com/test/game/ai/response/"; //测试
|
||||
|
||||
static readonly BGMUrl = "https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/BGM/"; //关卡音乐地址
|
||||
static readonly ZhenCangUrl = "https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/ZhenCang/"; //私家珍藏图片地址
|
||||
static readonly BgVideoUrl = "https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/BgVideo/"; //视频背景地址
|
||||
|
||||
static PlayerToken = ""; //登录时获取的token
|
||||
static LoginState = 0; //登录状态 0未登录 1登录中 2已登录
|
||||
static UserInfo:I_UserInfo = null; //用户数据
|
||||
|
||||
//后台设置
|
||||
//ad_chat_times:看广告加聊天次数 register_chat_times:注册赠送聊天次数
|
||||
//reset_day_ad:每日重置看广告次数 reset_day_share:每日重置分享次数 share_chat_times:分享可加聊天次数
|
||||
//ad_tickets_times:看广告可加相亲次数 share_tickets_times:分享可加相亲次数
|
||||
static SerSetting:any = {};
|
||||
|
||||
//单例
|
||||
private static I: HttpUnit;
|
||||
public static get ins(): HttpUnit {
|
||||
if (this.I == null) {
|
||||
this.I = new HttpUnit();
|
||||
}
|
||||
return this.I;
|
||||
}
|
||||
public constructor() {
|
||||
|
||||
}
|
||||
public jsonToQueryString(json: any) {
|
||||
var str = '';
|
||||
if (typeof json == "object") {
|
||||
str = "?";
|
||||
for (var k in json) {
|
||||
if (str != "?") {
|
||||
str += "&";
|
||||
}
|
||||
str += k + "=" + json[k];
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
private objectToFormData(obj: Object): FormData {
|
||||
const formData = new FormData();
|
||||
for (const key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
const value = obj[key];
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) {
|
||||
formData.append(key, item);
|
||||
}
|
||||
} else {
|
||||
formData.append(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
private async quest(xhr: XMLHttpRequest, method: "GET" | "POST" | "PUT" = "GET", data: Object, formData: boolean = false) {
|
||||
return new Promise((resolve, reason) => {
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
// console.log("[Http] 返回", xhr.response);
|
||||
resolve(JSON.parse(xhr.response));
|
||||
} else {
|
||||
reason(xhr.status)
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.onerror = (error) => {
|
||||
console.error("http request onerror");
|
||||
SubManager.ShowPrompt("网络错误,请检查网络连接");
|
||||
reason(error)
|
||||
};
|
||||
xhr.ontimeout = (e) => {
|
||||
console.error("http request timeout");
|
||||
SubManager.ShowPrompt("网络错误,请检查网络连接");
|
||||
reason(e)
|
||||
}
|
||||
//根据POST和GET方式,选择是否发送msg数据
|
||||
if (formData) {
|
||||
xhr.send(this.objectToFormData(data));
|
||||
} else {
|
||||
if (method == 'POST') {
|
||||
xhr.send(JSON.stringify(data));
|
||||
} else if (method == 'PUT') {
|
||||
xhr.send(JSON.stringify(data));
|
||||
} else {
|
||||
xhr.send();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**是否已登录成功 */
|
||||
public static IsLogin(): boolean {
|
||||
return HttpUnit.LoginState == 2;
|
||||
}
|
||||
|
||||
/**获取背景视频url */
|
||||
public static GetBgVideoUrl(bgname: string): string {
|
||||
// let videoPath = "http://www.confessioncontract.com/data/video/confession-contract/hanako_standby.mp4"
|
||||
let videoPath = `${HttpUnit.BgVideoUrl}${bgname}.mp4`
|
||||
return videoPath
|
||||
|
||||
}
|
||||
|
||||
/**获取心动最大次数 */
|
||||
public static GetXindongMaxCount() {
|
||||
return 5;
|
||||
}
|
||||
/**获取最大相亲次数 */
|
||||
public static GetXiangqinMaxTickets() {
|
||||
//每天重置相亲次数
|
||||
let num1 = HttpUnit.SerSetting.reset_game_day_match ? HttpUnit.SerSetting.reset_game_day_match.value : 5;
|
||||
num1 = parseInt(num1) || 0;
|
||||
//看广告加的相亲次数
|
||||
let num2 = HttpUnit.SerSetting.ad_tickets_times ? HttpUnit.SerSetting.ad_tickets_times.value : 3;
|
||||
num2 = parseInt(num2) || 0;
|
||||
//分享加的相亲次数
|
||||
let num3 = HttpUnit.SerSetting.share_tickets_times ? HttpUnit.SerSetting.share_tickets_times.value : 3;
|
||||
num3 = parseInt(num3) || 0;
|
||||
return num1 + num2 + num3;
|
||||
}
|
||||
/**获取可相亲次数 */
|
||||
public static GetXiangqinTickets() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.ticket || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可分享次数 - 相亲次数 */
|
||||
public static GetXiangqinShareNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.game_share_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可看广告次数 - 相亲次数 */
|
||||
public static GetXiangqinAdNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.game_ad_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可分享次数 - 聊天次数 */
|
||||
public static GetTalkShareNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.level_share_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可看广告次数 - 聊天次数 */
|
||||
public static GetTalkAdNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.level_ad_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取看广告增加的聊天次数 */
|
||||
public static GetTalkAdAddNum() {
|
||||
let num = HttpUnit.SerSetting.ad_chat_times ? HttpUnit.SerSetting.ad_chat_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取分享增加的聊天次数 */
|
||||
public static GetTalkShareAddNum() {
|
||||
let num = HttpUnit.SerSetting.share_chat_times ? HttpUnit.SerSetting.share_chat_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取看广告增加的相亲次数 */
|
||||
public static GetXiangqinAdAddNum() {
|
||||
let num = HttpUnit.SerSetting.ad_tickets_times ? HttpUnit.SerSetting.ad_tickets_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取分享增加的相亲次数 */
|
||||
public static GetXiangqinShareAddNum() {
|
||||
let num = HttpUnit.SerSetting.share_tickets_times ? HttpUnit.SerSetting.share_tickets_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取昵称 */
|
||||
public static GetNickName() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return "游客"
|
||||
}
|
||||
let num = HttpUnit.UserInfo.nickname || "游客";
|
||||
return num;
|
||||
}
|
||||
/**获取ID */
|
||||
public static GetID() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.id || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取抖音侧边栏奖励是否已领取 */
|
||||
public static IsBDSidebarReceive() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return false
|
||||
}
|
||||
let isget = HttpUnit.UserInfo.is_receive == 1;
|
||||
return isget;
|
||||
}
|
||||
/**获取友盟关卡记录 */
|
||||
public static GetLevelRecord() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return []
|
||||
}
|
||||
let levels = HttpUnit.UserInfo.levels || [];
|
||||
return levels;
|
||||
}
|
||||
/**获取可免费获取珍藏次数 */
|
||||
public static GetZhencangFreeCount() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.free_private_collection || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取珍藏红点是否显示 */
|
||||
public static IsHaveZhencangRedpoint() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return false
|
||||
}
|
||||
let isget = HttpUnit.UserInfo.private_collection_mark == 1;
|
||||
return isget;
|
||||
}
|
||||
/**获取回忆红点是否显示 */
|
||||
public static IsHaveHuiyiRedpoint() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return false
|
||||
}
|
||||
let isget = HttpUnit.UserInfo.heartbeat_memories_mark == 1;
|
||||
return isget;
|
||||
}
|
||||
|
||||
|
||||
//region 登录
|
||||
private loginCB: Function = null;
|
||||
public login(cb: Function = null) {
|
||||
this.loginCB = cb;
|
||||
SDKManager.login((_loginData) => {
|
||||
console.log("SDK登录成功", _loginData)
|
||||
SDKManager.getUserInfo((userInfo) => {
|
||||
console.log("SDK获取用户信息成功", userInfo)
|
||||
// let serparam = {
|
||||
// platform: _loginData.platform,
|
||||
// code: _loginData.code,
|
||||
// user_info: {nickName:userInfo.nickName, avatarUrl:userInfo.avatarUrl}
|
||||
// }
|
||||
|
||||
_loginData.nickname = userInfo.nickName;
|
||||
_loginData.avatar = userInfo.avatarUrl;
|
||||
|
||||
if (GlobalValue.IsTest) {
|
||||
console.log("登录测试环境")
|
||||
this.loginSer({platform:0, code:12345}, this.initData.bind(this))
|
||||
} else {
|
||||
if (_loginData.code == null) {
|
||||
let uuid = sys.localStorage.getItem('uuid');
|
||||
if (!uuid) {
|
||||
uuid = Date.now(); //当前时间戳
|
||||
sys.localStorage.setItem('uuid', uuid);
|
||||
}
|
||||
_loginData.code = uuid;
|
||||
_loginData.platform = 0
|
||||
// _loginData.code = 123455 //测试代码
|
||||
}
|
||||
console.log("登录正式环境 loginData.code: ", _loginData)
|
||||
this.loginSer(_loginData, this.initData.bind(this))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
private initData(playerData) {
|
||||
// playerData = playerData || {};
|
||||
this.loginCB && this.loginCB(playerData);
|
||||
|
||||
}
|
||||
//登录服务器
|
||||
private async loginSer(msg, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("login", msg, "POST", true);
|
||||
console.log("登录----> 玩家数据:", msg, data)
|
||||
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.PlayerToken = data.data.token
|
||||
HttpUnit.LoginState = 2
|
||||
console.log("HttpUnit.PlayerToken:", HttpUnit.PlayerToken)
|
||||
//获取玩家信息
|
||||
// this.getUserInfo(cb);
|
||||
HttpUnit.UserInfo = data.data.user_info;
|
||||
//获取配置信息
|
||||
this.getCommSetting();
|
||||
cb && cb(data.data.user_info);
|
||||
}else{
|
||||
console.log("登陆失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`登陆失败,${data.msg}`);
|
||||
} else {
|
||||
SubManager.ShowPrompt(`登陆失败,服务器异常`);
|
||||
}
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
//获取关卡列表数据
|
||||
public async getLevelList(cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/levels", {}, "POST", true);
|
||||
console.log("关卡数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取关卡数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**开始关卡*/
|
||||
public async levelStart(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/start", msg, "POST", true);
|
||||
console.log("开始新关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("开始关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**推进关卡*/
|
||||
public async sendUserTalk(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/propel", msg, "POST", true);
|
||||
console.log("推进关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("推进关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
/**结束关卡*/
|
||||
public async sendLevelFinish(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/end", msg, "POST", true);
|
||||
console.log("结束关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("结束关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**增加次数,更新关卡*/
|
||||
public async addTalkCnt(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/update", msg, "POST", true);
|
||||
console.log("更新关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("更新关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**获取AI语音*/
|
||||
public async getAIVoice(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/voice", msg, "POST", true);
|
||||
console.log("获取AI语音:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取AI语音失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**获取当前聊天状态*/
|
||||
public async getTalkStage(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/status", msg, "POST", true);
|
||||
console.log("获取当前聊天状态:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取当前聊天状态失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//非三星通关时继续关卡
|
||||
public async sendGameContinue(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/continue", msg, "POST", true);
|
||||
console.log("非三星通关时继续关卡:", data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("非三星通关时继续关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//重新获取用户信息
|
||||
public async getUserData(cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/info", {}, "GET", true);
|
||||
console.log("重新获取用户信息数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("重新获取用户信息数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//用户看广告
|
||||
public async setUserAd(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/ad", msg, "POST", true);
|
||||
console.log("看广告数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("看广告数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//用户分享
|
||||
public async setUserShare(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/share", msg, "POST", true);
|
||||
console.log("用户分享数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("用户分享数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取常用配置
|
||||
public async getCommSetting(cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/setting", {}, "GET", true);
|
||||
console.log("获取常用配置数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.SerSetting = {};
|
||||
for (let i = 0; i < data.data.length; i++) {
|
||||
let item = data.data[i];
|
||||
HttpUnit.SerSetting[item.key] = item;
|
||||
}
|
||||
cb && cb();
|
||||
}else{
|
||||
console.log("获取常用配置数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//看广告解锁关卡
|
||||
public async levelUnlock(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/unlock_level", msg, "POST", true);
|
||||
console.log("看广告解锁关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("看广告解锁关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取抖音侧边栏奖励
|
||||
public async getBDSidebarReward(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/receive_award", msg, "POST", true);
|
||||
console.log("获取抖音侧边栏奖励:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取抖音侧边栏奖励失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//添加友盟关卡记录
|
||||
public async sendLevelRecord(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/add_level_record", msg, "POST", true);
|
||||
console.log("添加友盟关卡记录:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("添加友盟关卡记录失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//获得甜蜜暴击效果
|
||||
public async sendTalkStrength(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/strength", msg, "POST", true);
|
||||
console.log("获得甜蜜暴击效果:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获得甜蜜暴击效果失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//撤回一次聊天
|
||||
public async sendTalkChehui(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/cancel", msg, "POST", true);
|
||||
console.log("撤回一次聊天:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("撤回一次聊天失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//关卡提示事件上报
|
||||
public async sendTipRecord(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/add_record_tip", msg, "POST", true);
|
||||
console.log("关卡提示事件上报:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("关卡提示事件上报失败:"+ data);
|
||||
// if (data && data.msg) {
|
||||
// SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
// }
|
||||
}
|
||||
}
|
||||
//获取AI回复提示语
|
||||
public async getAIAutoAns(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/tips", msg, "POST", true);
|
||||
console.log("获取AI回复提示语:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取AI回复提示语失败:"+ data);
|
||||
// if (data && data.msg) {
|
||||
// SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
// }
|
||||
}
|
||||
}
|
||||
/**获取历史聊天记录*/
|
||||
public async getTalkJilu(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/get_history", msg, "POST", true);
|
||||
console.log("获取历史聊天记录:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取历史聊天记录失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**私家珍藏上报 */
|
||||
public async sendZhencangId(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/set_private_collection", msg, "POST", true);
|
||||
console.log("私家珍藏上报:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("私家珍藏上报失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**获取私家珍藏列表 limit:每页条数 page:当前页 type:类型 0待领取 1已领取 level_id:关卡ID*/
|
||||
public async getZhencangList(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/get_private_collection", msg, "POST", true);
|
||||
console.log("获取私家珍藏列表:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取私家珍藏列表失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**领取私家珍藏指定奖励*/
|
||||
public async getZhencangReward(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/private_collection_award", msg, "POST", true);
|
||||
console.log("领取私家珍藏指定奖励:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
}else{
|
||||
console.log("领取私家珍藏指定奖励失败:", data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**清除私家珍藏红点*/
|
||||
public async readRedpointZhencang(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/clear_private_collection_mark", msg, "POST", true);
|
||||
console.log("清除私家珍藏红点:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
}else{
|
||||
console.log("清除私家珍藏红点失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**清除心动回忆红点*/
|
||||
public async readRedpointHuiyi(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/clear_heartbeat_memories_mark", msg, "POST", true);
|
||||
console.log("清除心动回忆红点:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
}else{
|
||||
console.log("清除心动回忆红点失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**重新开始关卡时,结束上次进度并上报服务器*/
|
||||
public async sendLevelRestartReport(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/restart_report", msg, "POST", true);
|
||||
console.log("关卡结束上次进度:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("关卡结束上次进度失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**心动回忆数据埋点*/
|
||||
public async sendEventTujian(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/click_img_event", msg, "POST", true);
|
||||
console.log("心动回忆数据埋点:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("心动回忆数据埋点失败:"+ data);
|
||||
// if (data && data.msg) {
|
||||
// SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region api
|
||||
public async api(path: string, data: any, method: "GET" | "POST" | "PUT" = "GET", bLock: boolean = false, isFormData: boolean = false) {
|
||||
|
||||
let url = HttpUnit.ServerHttpHost + path;
|
||||
// console.log("[Http] 请求Url:",url, " 方式:", method, " Authorization:", GlobalValue.PlayerToken, " 数据:", JSON.stringify(data) );
|
||||
bLock && this.lock();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.timeout = 10000;
|
||||
// xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
// if (cc.sys.isNative) {
|
||||
// xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
// }
|
||||
// xhr.setRequestHeader('authorization', Config.TOKEN);
|
||||
//发送数据
|
||||
if (method == 'GET') {
|
||||
url = url + encodeURI(this.jsonToQueryString(data));
|
||||
xhr.open(method, url, true);
|
||||
if (sys.isNative) {
|
||||
xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
|
||||
xhr.setRequestHeader("content-type", "text/html;charset=utf-8");
|
||||
}
|
||||
} else {
|
||||
xhr.open(method, url, true);
|
||||
xhr.setRequestHeader("Content-type", "application/json");
|
||||
}
|
||||
xhr.setRequestHeader('Authorization', "Bearer " + HttpUnit.PlayerToken);
|
||||
let self = this;
|
||||
return new Promise((resolve, reason) => {
|
||||
self.quest(xhr, method, data, isFormData).then(value => {
|
||||
bLock && self.unlock();
|
||||
resolve(value);
|
||||
}).catch(err => {
|
||||
bLock && self.unlock();
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 发送请求
|
||||
* @param url 接口地址
|
||||
* @param data 消息字符串 (json格式)
|
||||
* @param method 请求方式
|
||||
* @param bLock 是否锁定屏幕
|
||||
* @param formData 是否formData
|
||||
* @returns
|
||||
*/
|
||||
public async send(url: string, data: any, method: "GET" | "POST" | "PUT" = "GET", bLock: boolean = false, formData: boolean = false) {
|
||||
// console.log("[Http] 请求Url:",url, " 方式:", method, " 数据:", data);
|
||||
bLock && this.lock();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.timeout = 10000;
|
||||
if (method == 'GET') {
|
||||
url = url + encodeURI(this.jsonToQueryString(data));
|
||||
xhr.open(method, url, true);
|
||||
if (sys.isNative) {
|
||||
xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
|
||||
xhr.setRequestHeader("content-type", "text/html;charset=utf-8");
|
||||
}
|
||||
} else {
|
||||
xhr.open(method, url, true);
|
||||
xhr.setRequestHeader("Content-type", "application/json");
|
||||
}
|
||||
let self = this;
|
||||
return new Promise((resolve, reason) => {
|
||||
self.quest(xhr, method, data, formData).then(value => {
|
||||
bLock && self.unlock();
|
||||
resolve(value);
|
||||
}).catch(err => {
|
||||
bLock && self.unlock();
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
/**解锁屏幕 */
|
||||
private unlock() {
|
||||
// LockScreenUI.ins.unShowloading();
|
||||
// Config.loading.hide2();
|
||||
}
|
||||
|
||||
/**锁屏 */
|
||||
private lock() {
|
||||
// Config.loading.show2();
|
||||
// LockScreenUI.ins.Showloading('网络加载中请稍后...');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "52115c35-aa3a-43c5-b66a-dce8559f819c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fd851b67-a13d-46d3-afdc-da282fc40abc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/******************************************
|
||||
* @doc 列表Item组件.
|
||||
* 说明:
|
||||
* 1、此组件须配合List组件使用。(配套的配套的..)
|
||||
* @end
|
||||
******************************************/
|
||||
const { ccclass, property, disallowMultiple, menu, executionOrder } = _decorator;
|
||||
import { Node, Component, Enum, Sprite, SpriteFrame, tween, _decorator, EventHandler, Tween, Button, UITransform, Vec3 } from 'cc';
|
||||
import { DEV } from 'cc/env';
|
||||
import ScrollViewList from './ScrollViewList';
|
||||
|
||||
enum SelectedType {
|
||||
NONE = 0,
|
||||
TOGGLE = 1,
|
||||
SWITCH = 2,
|
||||
}
|
||||
|
||||
@ccclass
|
||||
@disallowMultiple()
|
||||
@executionOrder(-5001) //先于List
|
||||
export default class ScrollViewListItem extends Component {
|
||||
//图标
|
||||
@property({ type: Sprite, tooltip: DEV ? '图标' : '' })
|
||||
icon: Sprite = null!;
|
||||
//标题
|
||||
@property({ type: Node, tooltip: DEV ? '标题' : '标题'})
|
||||
title: Node = null!;
|
||||
//选择模式
|
||||
@property({
|
||||
type: Enum(SelectedType),
|
||||
tooltip: DEV ? '选择模式' : '选择模式'
|
||||
})
|
||||
selectedMode: SelectedType = SelectedType.NONE;
|
||||
//被选标志
|
||||
@property({
|
||||
type: Node, tooltip: DEV ? '被选标识' : '被选标识',
|
||||
visible() { return this.selectedMode > SelectedType.NONE }
|
||||
})
|
||||
selectedFlag: Node = null!;
|
||||
//被选择的SpriteFrame
|
||||
@property({
|
||||
type: SpriteFrame, tooltip: DEV ? '被选择的SpriteFrame' : '被选择的SpriteFrame',
|
||||
visible() { return this.selectedMode == SelectedType.SWITCH }
|
||||
})
|
||||
selectedSpriteFrame: SpriteFrame = null!;
|
||||
//未被选择的SpriteFrame
|
||||
_unselectedSpriteFrame: SpriteFrame = null!;
|
||||
//自适应尺寸
|
||||
@property({
|
||||
tooltip: DEV ? '自适应尺寸(宽或高)' : '自适应尺寸(宽或高)',
|
||||
})
|
||||
adaptiveSize: boolean = false;
|
||||
//选择
|
||||
_selected: boolean = false;
|
||||
set selected(val: boolean) {
|
||||
this._selected = val;
|
||||
Tween
|
||||
if (!this.selectedFlag)
|
||||
return;
|
||||
switch (this.selectedMode) {
|
||||
case SelectedType.TOGGLE:
|
||||
this.selectedFlag.active = val;
|
||||
break;
|
||||
case SelectedType.SWITCH:
|
||||
let sp: Sprite = this.selectedFlag.getComponent(Sprite)!;
|
||||
if (sp) {
|
||||
sp.spriteFrame = val ? this.selectedSpriteFrame : this._unselectedSpriteFrame;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
get selected() {
|
||||
return this._selected;
|
||||
}
|
||||
//按钮组件
|
||||
private _btnCom: any;
|
||||
get btnCom() {
|
||||
if (!this._btnCom)
|
||||
this._btnCom = this.node.getComponent(Button);
|
||||
return this._btnCom;
|
||||
}
|
||||
//依赖的List组件
|
||||
public list!: ScrollViewList;
|
||||
//是否已经注册过事件
|
||||
private _eventReg = false;
|
||||
//序列id
|
||||
public listId!: number;
|
||||
|
||||
onLoad() {
|
||||
// //没有按钮组件的话,selectedFlag无效
|
||||
// if (!this.btnCom)
|
||||
// this.selectedMode == SelectedType.NONE;
|
||||
//有选择模式时,保存相应的东西
|
||||
if (this.selectedMode == SelectedType.SWITCH) {
|
||||
let com: Sprite = this.selectedFlag.getComponent(Sprite)!;
|
||||
this._unselectedSpriteFrame = com.spriteFrame!;
|
||||
}
|
||||
}
|
||||
|
||||
onNodeDestroy() {
|
||||
let t: any = this;
|
||||
t.node.off(Node.EventType.SIZE_CHANGED, t._onSizeChange, t);
|
||||
}
|
||||
|
||||
_registerEvent() {
|
||||
let t: any = this;
|
||||
if (!t._eventReg) {
|
||||
if (t.btnCom && t.list.selectedMode > 0) {
|
||||
t.btnCom.clickEvents.unshift(t.createEvt(this, 'onClickThis'));
|
||||
}
|
||||
if (t.adaptiveSize) {
|
||||
t.node.on(Node.EventType.SIZE_CHANGED, t._onSizeChange, this);
|
||||
}
|
||||
t._eventReg = true;
|
||||
}
|
||||
}
|
||||
|
||||
_onSizeChange() {
|
||||
this.list._onItemAdaptive(this.node);
|
||||
}
|
||||
/**
|
||||
* 创建事件
|
||||
* @param {cc.Component} component 组件脚本
|
||||
* @param {string} handlerName 触发函数名称
|
||||
* @param {cc.Node} node 组件所在node(不传的情况下取component.node)
|
||||
* @returns cc.Component.EventHandler
|
||||
*/
|
||||
createEvt(component: Component, handlerName: string, node: Node = null!) {
|
||||
if (!component || !component.isValid)
|
||||
return;//有些异步加载的,节点以及销毁了。
|
||||
component['comName'] = component['comName'] || component.name.match(/\<(.*?)\>/g).pop().replace(/\<|>/g, '');
|
||||
let evt = new EventHandler();
|
||||
evt.target = node || component.node;
|
||||
evt.component = component['comName'];
|
||||
evt.handler = handlerName;
|
||||
return evt;
|
||||
}
|
||||
|
||||
showAni(aniType: number, callFunc: Function, del: boolean) {
|
||||
let t: any = this;
|
||||
let twe: Tween<Node>;
|
||||
let ut: UITransform = t.node.getComponent(UITransform);
|
||||
switch (aniType) {
|
||||
case 0: //向上消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(0, ut.height * 2) });
|
||||
break;
|
||||
case 1: //向右消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(ut.width * 2, 0) });
|
||||
break;
|
||||
case 2: //向下消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(0, ut.height * -2) });
|
||||
break;
|
||||
case 3: //向左消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(ut.width * -2, 0) });
|
||||
break;
|
||||
default: //默认:缩小消失
|
||||
twe = tween(t.node)
|
||||
.to(.3, { scale: new Vec3(.1, .1) });
|
||||
break;
|
||||
}
|
||||
|
||||
if (callFunc || del) {
|
||||
twe.call(() => {
|
||||
if (del) {
|
||||
t.list._delSingleItem(t.node);
|
||||
for (let n: number = t.list.displayData.length - 1; n >= 0; n--) {
|
||||
if (t.list.displayData[n].id == t.listId) {
|
||||
t.list.displayData.splice(n, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
callFunc();
|
||||
});
|
||||
}
|
||||
twe.start();
|
||||
}
|
||||
|
||||
onClickThis() {
|
||||
this.list.selectedId = this.listId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1c274f61-58c2-4e59-bfb2-93c9eb201361",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
import Utils from "./Utils";
|
||||
|
||||
/**长连接*/
|
||||
export default class SocketUnit {
|
||||
private socket: WebSocket | null = null;
|
||||
private isConnected: boolean = false;
|
||||
private reconnetSwt: boolean = false; //重连开关
|
||||
private reconnectCount: number = 0; //重连次数
|
||||
private reconnectMaxCount: number = 3; //最大重连次数
|
||||
private reconnectInterval: number = 1500; //重连间隔时间 ms
|
||||
private reconnectTimer : number = null; //重连定时器
|
||||
private reSendData : any = null; //重连时需要重发的数据
|
||||
private url: string = ""; //连接地址
|
||||
|
||||
private dataReceivedCallback: (data: any) => void = () => { };
|
||||
|
||||
// 连接到服务器
|
||||
public connect(url: string): void {
|
||||
if (this.isConnected) {
|
||||
console.log("SocketUnit: Already connected.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.url = url;
|
||||
this.socket = new WebSocket(url);
|
||||
console.log("SocketUnit: Connecting to -> " + url);
|
||||
|
||||
// 连接成功
|
||||
this.socket.onopen = () => {
|
||||
this.isConnected = true;
|
||||
console.log("SocketUnit: Connection succ.");
|
||||
if (this.reconnetSwt) {
|
||||
console.log("SocketUnit: socket重连成功.");
|
||||
this.stopReconnect();
|
||||
if (this.reSendData) {
|
||||
this.sendData(this.reSendData);
|
||||
this.reSendData = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 接收到消息
|
||||
this.socket.onmessage = (event) => {
|
||||
// console.log("SocketUnit: Received data: ", event);
|
||||
if (this.dataReceivedCallback) {
|
||||
this.dataReceivedCallback(event);
|
||||
}
|
||||
};
|
||||
|
||||
// 连接关闭
|
||||
this.socket.onclose = () => {
|
||||
this.isConnected = false;
|
||||
console.log("SocketUnit: Connection closed.");
|
||||
};
|
||||
|
||||
// 发生错误
|
||||
this.socket.onerror = (error) => {
|
||||
console.error("SocketUnit: WebSocket error:", error);
|
||||
this.isConnected = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// 断开连接
|
||||
public disconnect(): void {
|
||||
if (this.socket && this.isConnected) {
|
||||
this.socket.close();
|
||||
this.isConnected = false;
|
||||
}
|
||||
this.stopReconnect()
|
||||
}
|
||||
|
||||
// 发送数据
|
||||
public sendData(data: string): void {
|
||||
// console.log("SocketUnit: sendData", data);
|
||||
if (this.socket && this.isConnected) {
|
||||
this.socket.send(data);
|
||||
} else {
|
||||
console.error("SocketUnit: Socket is not connected.");
|
||||
this.reSendData = data;
|
||||
this.beginReconnect()
|
||||
}
|
||||
}
|
||||
|
||||
// 设置数据接收回调
|
||||
public onDataReceived(callback: (data: string) => void): void {
|
||||
this.dataReceivedCallback = callback;
|
||||
}
|
||||
|
||||
// 获取连接状态
|
||||
public get isConnectedStatus(): boolean {
|
||||
return this.isConnected;
|
||||
}
|
||||
|
||||
//断线重连
|
||||
private beginReconnect(): void {
|
||||
if (this.reconnetSwt) {
|
||||
return
|
||||
}
|
||||
this.reconnetSwt = true;
|
||||
this.reconnectCount = 0;
|
||||
|
||||
if (this.reconnectTimer == null) {
|
||||
this.reconnectTimer = setInterval(() => {
|
||||
if (this.reconnectCount > this.reconnectMaxCount) {
|
||||
this.reconnectCount = 0;
|
||||
this.stopReconnect();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Socket_Timeout)
|
||||
return;
|
||||
}
|
||||
this._doReconnect();
|
||||
}, this.reconnectInterval);
|
||||
}
|
||||
}
|
||||
private _doReconnect(): void {
|
||||
this.reconnectCount++
|
||||
this.connect(this.url);
|
||||
}
|
||||
// 停止重连
|
||||
private stopReconnect(): void {
|
||||
if (this.reconnectTimer != null) {
|
||||
clearInterval(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
this.reconnetSwt = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "15cf30e1-81e1-4254-ace3-a2647836d26e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
import { _decorator, Color, isValid, Label, Node, RichText, Size, Sprite, UITransform, Vec3, view } from "cc";
|
||||
import li_EventManager from "./li_EventManager";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass
|
||||
export default class Utils {
|
||||
//log日志
|
||||
public static Log(msg: string | any, ...subst: any[]) {
|
||||
let IsLocalCSChanel = true
|
||||
if (IsLocalCSChanel) {
|
||||
console.log(msg, subst)
|
||||
}
|
||||
}
|
||||
//警告日志
|
||||
public static Warning(msg: string | any, ...subst: any[]) {
|
||||
let IsLocalCSChanel = true
|
||||
if (IsLocalCSChanel) {
|
||||
console.warn(msg, subst)
|
||||
}
|
||||
}
|
||||
//错误日志
|
||||
public static Error(msg: string | any, ...subst: any[]) {
|
||||
let IsLocalCSChanel = true
|
||||
if (IsLocalCSChanel) {
|
||||
console.error(msg, subst)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//解析节点
|
||||
public static parseNode = function (node: Node, oriObj?: any) {
|
||||
if (!node || !node.children) return;
|
||||
oriObj = oriObj || node;
|
||||
let chs = node.children;
|
||||
for (let i = 0; i < chs.length; i++) {
|
||||
let ch = chs[i];
|
||||
let chName = ch.name;
|
||||
if (chName && chName.length > 0) {
|
||||
try {
|
||||
oriObj[chName] = ch;
|
||||
} catch (error) {
|
||||
//hg_utils.hgLog("chName err:", chName);
|
||||
}
|
||||
}
|
||||
Utils.parseNode(ch, oriObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//更换父节点,保留原有的坐标和旋转
|
||||
public static changeNodeParent(node:Node, parentNode:Node) {
|
||||
let world_Q = node.getWorldRotation()
|
||||
let world_pos = node.getWorldPosition()//原来的世界坐标
|
||||
node.setParent(parentNode)
|
||||
node.setRotation(world_Q);
|
||||
node.setWorldPosition(world_pos)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 封装setString方法
|
||||
*/
|
||||
static setString(node: Node, str: string | number) {
|
||||
if (!isValid(node)) return;
|
||||
let lb:any = node.getComponent(Label);
|
||||
if (!lb) return;
|
||||
if(str == null) {str = ""}
|
||||
str += ""
|
||||
lb.string = str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加富文本
|
||||
* @param node
|
||||
* @param str
|
||||
* @param outLine
|
||||
* @param width
|
||||
* @returns
|
||||
*/
|
||||
static addRichText(node: Node, str: string, outLine: string | null = null, width: number | null = 2,max: number = 0) {
|
||||
if (!node) return;
|
||||
let comp = node.getComponent(RichText);
|
||||
if (!comp) return;
|
||||
str = Utils.replaceAll(str, "</>", "</color>");
|
||||
str = str.replace(/\<\/font\>/g, '</color>');
|
||||
str = Utils.replaceAll(str, "'>", ">");
|
||||
str = Utils.replaceAll(str, "<font", "<");
|
||||
str = Utils.replaceAll(str, "color='", "color=");
|
||||
str = Utils.replaceAll(str, "<br>", "\n");
|
||||
if (outLine) {
|
||||
str = `<outline color=${outLine} width=${width}>${str}</outline>`;
|
||||
}
|
||||
comp.string = str;
|
||||
// let csize:UITransform = comp.node.getComponent(UITransform)!
|
||||
// comp.maxWidth = Math.min(csize.width,max) ;
|
||||
}
|
||||
static replaceAll(str: string, ch1: string, ch2: string) {
|
||||
while (str.indexOf(ch1) >= 0) {
|
||||
str = str.replace(ch1, ch2);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**截取字符串,超过长度的用...代替
|
||||
* @param str 要处理的字符串
|
||||
* @param labelLimit 字符串长度限制
|
||||
* @param repStr 超过长度后代替的字符串
|
||||
*/
|
||||
static clampAiAnswer(ansStr: string, labelLimit:number, repStr: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 + repStr;
|
||||
}
|
||||
tempStr += ansStr.charAt(i);
|
||||
}
|
||||
return ansStr;
|
||||
}
|
||||
|
||||
|
||||
/**设置节点置灰 */
|
||||
static setNodeGray(node: Node, isGray: boolean, extra: any={}) {
|
||||
if (!isValid(node)) return;
|
||||
//图片
|
||||
let sp:Sprite = node.getComponent(Sprite);
|
||||
if (sp) {
|
||||
sp.grayscale = isGray;
|
||||
}
|
||||
// //文字
|
||||
// let lb:Label = node.getComponent(Label);
|
||||
// if (lb) {
|
||||
// if (isGray) {
|
||||
// lb.color = extra.labClrGray ? extra.labClrGray : Color.GRAY;
|
||||
// } else {
|
||||
// lb.color = extra.labClrWhite ? extra.labClrWhite : Color.WHITE;
|
||||
// }
|
||||
// }
|
||||
//对子节点执行同样操作
|
||||
let children = node.children;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
Utils.setNodeGray(children[i], isGray, extra);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**适配背景图
|
||||
* @method node 背景图节点
|
||||
* @param mod 适配模式 1=按高度适配 2=按宽度适配
|
||||
*/
|
||||
public static adjustBgPixelRatio(node:Node, mod:number = 1) {
|
||||
let windowSize = view.getVisibleSize();
|
||||
let bgTf = node.getComponent(UITransform)
|
||||
if (bgTf) {
|
||||
if (mod == 1 && bgTf.height < windowSize.height) {
|
||||
let scale = windowSize.height / bgTf.height
|
||||
bgTf.height = bgTf.height * scale
|
||||
bgTf.width = bgTf.width * scale
|
||||
} else if (mod == 2 && bgTf.width < windowSize.width) {
|
||||
let scale = windowSize.width / bgTf.width
|
||||
bgTf.height = bgTf.height * scale
|
||||
bgTf.width = bgTf.width * scale
|
||||
}
|
||||
}
|
||||
}
|
||||
/**适配背景图 按比例缩放 屏幕比设计分辨率小时缩小,反之则不缩放
|
||||
* @param node 背景图节点
|
||||
* @param mod 适配模式 1=按高度适配 2=按宽度适配
|
||||
*/
|
||||
public static adjustBgScaleRatio(node:Node, mod:number = 1) {
|
||||
let windowSize = view.getVisibleSize();
|
||||
let designSize = view.getDesignResolutionSize();
|
||||
if (mod == 1 && windowSize.height < designSize.height) {
|
||||
let scale = windowSize.height / designSize.height
|
||||
node.scale = new Vec3(scale, scale, 1)
|
||||
} else if (mod == 2 && windowSize.width < designSize.width) {
|
||||
let scale = windowSize.width / designSize.width
|
||||
node.scale = new Vec3(scale, scale, 1)
|
||||
}
|
||||
}
|
||||
/**获取屏幕分辨率和设计分辨率的比例
|
||||
* @method mod 适配模式 1=按高度适配 2=按宽度适配
|
||||
*/
|
||||
public static getScaleRatio(mod:number = 1) {
|
||||
let windowSize = view.getVisibleSize();
|
||||
let designSize = view.getDesignResolutionSize();
|
||||
// console.log("游戏分辨率:", windowSize, designSize);
|
||||
if (mod == 1) {
|
||||
return windowSize.height / designSize.height
|
||||
} else {
|
||||
return windowSize.width / designSize.width
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @method 浅复制一个对象
|
||||
* @param source 需要浅复制的对象
|
||||
* 合并对象,如果excludes中没有指明需要排除的字段,target也含有相同的字段,则会被object同名字段值覆盖掉
|
||||
* @param object
|
||||
* @param excludes 需要排除的字段
|
||||
*/
|
||||
static applyIf(object: any, target: any = {}, excludes: Array<string> = []): Object {
|
||||
if (!target) target = {};
|
||||
for (let key in object) {
|
||||
if (object.hasOwnProperty(key)) {
|
||||
if (excludes.indexOf(key) < 0) {
|
||||
target[key] = object[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
/**
|
||||
* @method 浅复制一个对象
|
||||
* @param source 需要浅复制的对象
|
||||
* @return 返回一个新的对象
|
||||
* @log 1. vincent,2018-12-18, func、date、reg 和 err 类型不能正常拷贝
|
||||
*/
|
||||
static easyCopy(source: Object): Object {
|
||||
const newObject = [];
|
||||
return Utils.applyIf(source);
|
||||
}
|
||||
/**复制一个数据表 */
|
||||
static clone(data:any) {
|
||||
return Utils.easyCopy(data);
|
||||
}
|
||||
|
||||
|
||||
/**发送内部事件 */
|
||||
public static sendInnerMsg(innerId: number, param?: any) {
|
||||
li_EventManager.I.onInnerEL(innerId, param);
|
||||
}
|
||||
/**注册内部事件 */
|
||||
public static addInnerEL(innerId: number, i_target, i_callback: Function,) {
|
||||
li_EventManager.I.addInnerEL(innerId, i_callback, i_target);
|
||||
}
|
||||
/**移除内部事件 */
|
||||
public static removeInnerEL(innerId: number, i_target, i_callback: Function) {
|
||||
li_EventManager.I.removeInnerEL(innerId, i_callback, i_target)
|
||||
}
|
||||
|
||||
|
||||
//获取随机数
|
||||
public static getRandomInt(i_start:number, i_end:number) : number {
|
||||
i_start = Math.ceil(i_start);
|
||||
i_end = Math.floor(i_end);
|
||||
return Math.floor(Math.random() * (i_end - i_start + 1)) + i_start;
|
||||
}
|
||||
//数字转字符串,指定位数,位数不足前面补0
|
||||
public static PrefixInt(num, length) {
|
||||
return (Array(length).join('0') + num).slice(-length);
|
||||
}
|
||||
//数字保留几位小数
|
||||
public static DecimalPlaces(num:number, weishu:number) {
|
||||
return num.toFixed(weishu);
|
||||
}
|
||||
|
||||
|
||||
/**获取屏幕分辨率 */
|
||||
public static GetWinSize():Size {
|
||||
return view.getVisibleSize()
|
||||
}
|
||||
|
||||
|
||||
/**获取当前日期,格式YYYY-MM-DD */
|
||||
public static GetNowFormatDay(nowDate: Date | null = null, char: string = "-") {
|
||||
if (nowDate == null) {
|
||||
nowDate = new Date();
|
||||
}
|
||||
let day = nowDate.getDate();
|
||||
let month = nowDate.getMonth() + 1;//注意月份需要+1
|
||||
let year = nowDate.getFullYear();
|
||||
//补全0,并拼接
|
||||
return year + char + Utils.completeDate(month) + char + Utils.completeDate(day);
|
||||
}
|
||||
//补全0
|
||||
private static completeDate(value: number) {
|
||||
return value < 10 ? "0" + value : value;
|
||||
}
|
||||
|
||||
|
||||
//打印消耗时间===================================================================================================
|
||||
private static _eplTime = 0;
|
||||
/**记录当前时间 */
|
||||
public static ProfilerTimeRecord() {
|
||||
Utils._eplTime = new Date().getTime();
|
||||
}
|
||||
/**打印消耗时间 */
|
||||
public static ProfilerTimePrint(key:string = "") {
|
||||
let time = new Date().getTime();
|
||||
let timecha = time - Utils._eplTime;
|
||||
console.log(`${key}消耗时间:${timecha}毫秒`);
|
||||
Utils._eplTime = time;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "871cd90f-732a-4a11-bdbf-bfbcfe6f6163",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
import { _decorator, Node } from 'cc';
|
||||
import li_Component from './li_Component';
|
||||
import Utils from './Utils';
|
||||
import { ViewManager } from '../Manager/ViewManager';
|
||||
|
||||
//界面基类
|
||||
@ccclass
|
||||
export default class li_BaseView extends li_Component {
|
||||
private isScriptComponent = true;//标记判断使用(勿删)
|
||||
|
||||
//命名为根节点,实际上是编辑器里可以看到的最上层节点,实际使用时需要getParent来获取根节点
|
||||
@property({ type: Node, visible: true, displayName: '界面根节点' })
|
||||
protected m_rootNode: Node = null;
|
||||
protected objNodes: any = null;
|
||||
|
||||
|
||||
//----以下接口由子类实现-----------------------------
|
||||
onLoadCT() {
|
||||
}
|
||||
|
||||
|
||||
onLoad() {
|
||||
if (this.m_rootNode == null) {
|
||||
this.m_rootNode = this.node;
|
||||
}
|
||||
|
||||
this.onLoadCT();
|
||||
}
|
||||
|
||||
parseNode() {
|
||||
// this.objNodes = {};
|
||||
// Utils.parseNode(this.node, this.objNodes);
|
||||
// let self = this;
|
||||
// setTimeout(() => {
|
||||
// self.bindBtnClose();
|
||||
// }, 10);
|
||||
}
|
||||
|
||||
private bindBtnClose() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected getRootNode() {
|
||||
// if (this.node) {
|
||||
// let node = this.node;
|
||||
// let parent = node.getParent();
|
||||
// let groundParent = parent && parent.getParent();
|
||||
// while (groundParent) {
|
||||
// node = parent;
|
||||
// parent = groundParent;
|
||||
// groundParent = parent && parent.getParent();
|
||||
// }
|
||||
// return node;
|
||||
// }
|
||||
}
|
||||
|
||||
public close() {
|
||||
ViewManager.I.closeView(this.m_rootNode ? this.m_rootNode : this.node);
|
||||
}
|
||||
|
||||
protected onClose() {
|
||||
// hg_utils.sendInnerMsg(InnerMsgCode.ViewClose)
|
||||
this.close();
|
||||
}
|
||||
|
||||
//实际移除界面
|
||||
protected removeView(): void {
|
||||
if (this.m_rootNode) {
|
||||
this.m_rootNode.destroy();
|
||||
this.m_rootNode.removeFromParent();
|
||||
this.m_rootNode = null
|
||||
}
|
||||
}
|
||||
|
||||
// protected doClose(): void {
|
||||
// this.removeView();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "24b87ef5-896c-4e31-8af9-6532aeaa8bcd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { _decorator, Component } from "cc";
|
||||
import li_EventManager from "./li_EventManager";
|
||||
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
@ccclass
|
||||
export default class hg_Component extends Component {
|
||||
protected m_config = {};
|
||||
public ExitViewFunc = null;
|
||||
|
||||
|
||||
//----以下接口由子类实现-----------------------------
|
||||
openUIDataCT(data) {
|
||||
}
|
||||
|
||||
|
||||
onDestroy() {
|
||||
li_EventManager.I.removeAllInnerEL(this);
|
||||
li_EventManager.I.removeAllNetEL(this);
|
||||
this.ExitViewFunc && this.ExitViewFunc();
|
||||
this.onNodeDestroy();
|
||||
this.onSceenDestroy();
|
||||
// li_EventManager.I.onInnerEL(InnerMsgCode.Node_Destroy_Release, this.node);
|
||||
}
|
||||
/**页面传值接收方法 */
|
||||
openUIData(data) {
|
||||
if (data && data.ExitViewFunc) {
|
||||
this.ExitViewFunc = data.ExitViewFunc;
|
||||
}
|
||||
|
||||
//设置截图背景纹理
|
||||
if (data && data.screenShotTex){
|
||||
// let blurMask = this.node.getComponentInChildren(BlurMask);
|
||||
// if (blurMask){
|
||||
// blurMask.setScreenShotTexture(data.screenShotTex)
|
||||
// }
|
||||
}
|
||||
|
||||
this.openUIDataCT(data)
|
||||
}
|
||||
onNodeDestroy() {
|
||||
}
|
||||
onSceenDestroy() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ca2072cc-d85a-44b8-977d-a8e1314bc220",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import { _decorator } from "cc";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//事件管理器
|
||||
@ccclass
|
||||
export default class li_EventManager {
|
||||
private static _Instance: li_EventManager = null;
|
||||
private _netEvent: object = {};
|
||||
private _innerEvent: object = {};
|
||||
|
||||
public static get I(): li_EventManager {
|
||||
if (!li_EventManager._Instance) {
|
||||
li_EventManager._Instance = new li_EventManager();
|
||||
}
|
||||
return li_EventManager._Instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**监听网络事件 */
|
||||
public onNetEL(netCodeId: number | string, ...param: any[]) {
|
||||
if (netCodeId) {
|
||||
let handlerArray = this._netEvent[netCodeId];
|
||||
if (!handlerArray) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < handlerArray.length; i++) {
|
||||
const func = handlerArray[i];
|
||||
if (func) {
|
||||
if (func.i_target) {
|
||||
func.apply(func.i_target, param);
|
||||
} else {
|
||||
func(param[0], param[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**添加网络事件 */
|
||||
public addNetEL(netCodeId: number | string, i_callback: any, i_target: any = null): void {
|
||||
if (this._netEvent[netCodeId] == null) {
|
||||
this._netEvent[netCodeId] = [];
|
||||
}
|
||||
i_callback.i_target = i_target;
|
||||
this._netEvent[netCodeId].push(i_callback);
|
||||
}
|
||||
/**移除网络事件 */
|
||||
public removeNetEL(netCodeId: number | string, i_callback: any) {
|
||||
let handlerArray = this._netEvent[netCodeId];
|
||||
if (!handlerArray) return;
|
||||
let index = handlerArray.indexOf(i_callback);
|
||||
if (index >= 0) {
|
||||
handlerArray.splice(index, 1);
|
||||
for (let idx in handlerArray) {
|
||||
if (handlerArray[+idx] == i_callback) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
i_callback.i_target = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**监听本地事件 */
|
||||
public onInnerEL(innerId: number | string, ...param: any[]) {
|
||||
if (this._innerEvent[innerId] == null) {
|
||||
return;
|
||||
}
|
||||
let handlerArray: Array<any> = this._innerEvent[innerId];
|
||||
let i: number = 0;
|
||||
let length: number = handlerArray.length;
|
||||
let handler: Array<any> = null;
|
||||
while (i < length) {
|
||||
handler = handlerArray[i];
|
||||
if (handler == null) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if ((handler[1] && handler[1]["isValid"] && handler[1]["isValid"] == false) ||
|
||||
(handler[1] && handler[1]["node"] && handler[1]["node"]["isValid"] && handler[1]["node"]["isValid"] == false)) {
|
||||
//当前事件的节点以失效或销毁(事件未移除)
|
||||
handlerArray.splice(i, 1);
|
||||
} else {
|
||||
try {
|
||||
handler[0].apply(handler[1], param);
|
||||
} catch (e) {
|
||||
console.error("innerErr:" + e.stack);
|
||||
}
|
||||
}
|
||||
if (handlerArray.length != length) {
|
||||
length = handlerArray.length;
|
||||
i--;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/**添加本地事件 */
|
||||
public addInnerEL(innerId: number | string, i_callback: Function, obj: any): void {
|
||||
let handlerArray: Array<any> = this._innerEvent[innerId];
|
||||
if (handlerArray == null) {
|
||||
handlerArray = [];
|
||||
this._innerEvent[innerId] = handlerArray;
|
||||
}
|
||||
//检测是否已经存在
|
||||
for (let i = 0; i < handlerArray.length; i++) {
|
||||
if (handlerArray[i] == null || (handlerArray[i][0] == i_callback && handlerArray[i][1] == obj)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._innerEvent[innerId].push([i_callback, obj]);
|
||||
}
|
||||
/**移除本地事件 */
|
||||
public removeInnerEL(innerId: number | string, i_callback: Function, obj: any) {
|
||||
let handlerArray: Array<any> = this._innerEvent[innerId];
|
||||
if (!handlerArray) return;
|
||||
for (let i = 0; i < handlerArray.length; i++) {
|
||||
if (handlerArray[i] == null || (handlerArray[i][0] == i_callback && handlerArray[i][1] == obj)) {
|
||||
handlerArray.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handlerArray.length == 0) {
|
||||
handlerArray[innerId] = null;
|
||||
delete this._innerEvent[innerId];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除某一对象的所有内部监听
|
||||
* @param listenerObj 侦听函数所属对象
|
||||
*/
|
||||
public removeAllInnerEL(listenerObj: any): void {
|
||||
let keys = Object.keys(this._innerEvent);
|
||||
for (let i: number = 0, len = keys.length; i < len; i++) {
|
||||
let type = keys[i];
|
||||
let arr: Array<any> = this._innerEvent[type];
|
||||
if (arr) {
|
||||
for (let j = 0; j < arr.length; j++) {
|
||||
if (arr[j][1] == listenerObj) {
|
||||
arr.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (arr.length == 0) {
|
||||
delete this._innerEvent[type];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 移除某一对象的所有网络监听
|
||||
* @param listenerObj 侦听函数所属对象
|
||||
*/
|
||||
public removeAllNetEL(listenerObj: any): void {
|
||||
let keys = Object.keys(this._netEvent);
|
||||
for (let i: number = 0, len = keys.length; i < len; i++) {
|
||||
let type = keys[i];
|
||||
let arr: Array<any> = this._netEvent[type];
|
||||
if (arr) {
|
||||
for (let j = 0; j < arr.length; j++) {
|
||||
if (arr[j].i_target == listenerObj) {
|
||||
arr.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (arr.length == 0) {
|
||||
delete this._netEvent[type];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**移除所有监听 */
|
||||
public removeAllEL() {
|
||||
this._netEvent = {};
|
||||
this._innerEvent = {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "82b74a90-b0a5-42bd-be17-e5600e03eff5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user