601 lines
25 KiB
TypeScript
601 lines
25 KiB
TypeScript
import { popupContent } from "./PopupContent";
|
|
import PopupAnimator, { ActivityPopupAnimationType as PopupType } from "./ActivityPopupAnimator";
|
|
import CollisionDetection from "./CollisionDetection";
|
|
import JiaZai from "./JiaZai";
|
|
import LoadingCatAnimation from "./LoadingCatAnimation";
|
|
import MapConroler from "./Map";
|
|
import Utils from "./module/Pay/Utils";
|
|
import { MiniGameManager } from "./Sdk/MiniGameManager";
|
|
import { MiniGameSdk } from "./Sdk/MiniGameSdk";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class Avatar extends cc.Component {
|
|
onDisable() {
|
|
this.unschedule(this.playPopupEntrance);
|
|
PopupAnimator.cancel(popupContent(this.node, ["New Sprite(Splash)", "address", "Loading"]));
|
|
}
|
|
|
|
onEnable() {
|
|
this.unschedule(this.playPopupEntrance);
|
|
PopupAnimator.prepareOpen(popupContent(this.node, ["New Sprite(Splash)","address","Loading"]));
|
|
this.scheduleOnce(this.playPopupEntrance, 0);
|
|
}
|
|
private playPopupEntrance() {
|
|
if (cc.isValid(this.node, true) && this.node.activeInHierarchy) PopupAnimator.openPrepared(popupContent(this.node, ["New Sprite(Splash)","address","Loading"]));
|
|
}
|
|
|
|
|
|
// @property({
|
|
// tooltip: '碰撞形状,None就是无敌,不参与碰撞',
|
|
// type: cc.Enum(BlockType),
|
|
// // default: BlockType.Nomal,
|
|
// displayName: '碰撞形状'
|
|
// })
|
|
@property(cc.Node)
|
|
content: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
content2: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
content3: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
content4: cc.Node = null;
|
|
|
|
@property(cc.SpriteAtlas)
|
|
ui: cc.SpriteAtlas = null;
|
|
|
|
avatar: any; //正在使用中的头像
|
|
address: string = "";
|
|
avatarNow: any// 选中的头像
|
|
avatarKuang: any;
|
|
avatarCat: any;
|
|
|
|
avatarData: any;
|
|
film: any;
|
|
catArr: any;
|
|
private initialAddress: string = "";
|
|
private initialAvatar: string = "";
|
|
private initialAvatarCat: string = "";
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
|
}
|
|
start() {
|
|
}
|
|
init(data, film) {
|
|
this.onEnable();
|
|
this.node.getChildByName("kuang").active = false;
|
|
this.node.getChildByName("catBtn").active = true;
|
|
console.log("拿到的头像数据:", data);
|
|
this.avatarData = [];
|
|
if (data) {
|
|
this.avatarData = cc.fx.GameTool.getAvatarData(data.headArr);
|
|
}
|
|
this.catArr = [];
|
|
if (data.catArr) {
|
|
this.catArr = cc.fx.GameTool.getCatData(data.catArr);
|
|
}
|
|
this.film = data.film;
|
|
// console.log("头像信息", this.avatarData);
|
|
this.avatar = cc.fx.GameConfig.GM_INFO.useravatarIcon;
|
|
this.avatarKuang = cc.fx.GameConfig.GM_INFO.useravaterkuang;
|
|
this.address = cc.fx.GameConfig.GM_INFO.address;
|
|
this.avatarCat = cc.fx.GameConfig.GM_INFO.useravatarCat;
|
|
this.initialAddress = String(cc.fx.GameConfig.GM_INFO.address || "");
|
|
this.initialAvatar = String(cc.fx.GameConfig.GM_INFO.useravatarIcon || "");
|
|
this.initialAvatarCat = String(cc.fx.GameConfig.GM_INFO.useravatarCat || "");
|
|
console.log("进入头像:", this.avatar, this.avatarKuang, this.avatarCat);
|
|
this.changeBtnState("avatar");
|
|
this.changeAvatar(null, this.avatar);
|
|
this.changeState(null, "tou");
|
|
this.getSelfAvatar();
|
|
|
|
let Info = this.node.getChildByName("Info");
|
|
//用户ID
|
|
Info.getChildByName("Id").getComponent(cc.Label).string = cc.fx.GameConfig.GM_INFO.userId + "D";
|
|
//用户名称
|
|
let username = cc.fx.GameConfig.GM_INFO.username;
|
|
if (username.length > 12) username = cc.fx.GameTool.subName(username, 12);
|
|
else if (username == "user") username = "匿名玩家";
|
|
Info.getChildByName("Name").getComponent(cc.Label).string = username;
|
|
//用户城市
|
|
let city = cc.fx.GameConfig.GM_INFO.address;
|
|
if (city == "北京" || city == "上海" || city == "重庆" || city == "天津") {
|
|
city = city + "市";
|
|
}
|
|
Info.getChildByName("Address").getComponent(cc.Label).string = city + "";
|
|
//用户注册时间
|
|
let time = cc.fx.GameConfig.GM_INFO.firstTime;
|
|
let formattedDate = "";
|
|
if (time != 0) {
|
|
let date = new Date(time);
|
|
console.log("原始时间:", time, date);
|
|
// 格式化年月日
|
|
let year = date.getFullYear();
|
|
let month = date.getMonth() + 1; // 月份从0开始,需要+1
|
|
let day = date.getDate();
|
|
|
|
formattedDate = `${year}年${month}月${day}日`;
|
|
}
|
|
|
|
Info.getChildByName("FirstTime").getComponent(cc.Label).string = formattedDate;
|
|
for (let i = 0; i < this.content.children.length; i++) {
|
|
this.content.children[i].getChildByName("kuang").getComponent(cc.Sprite).spriteFrame = this.ui.getSpriteFrame(this.avatarKuang);
|
|
}
|
|
|
|
|
|
for (let j = 0; j < this.avatarData.length; j++) {
|
|
console.log("头像解锁", this.avatarData[j]);
|
|
this.content.children[this.avatarData[j] - 4].getChildByName("lock").active = false;
|
|
}
|
|
|
|
// 按节点名匹配,避免新增猫 ID 越界;复用窗口时重新计算锁状态。
|
|
const ownedCats = [1, 2, 3].concat(this.catArr.map(id => Number(id)));
|
|
this.content4.children.forEach(cat => {
|
|
const id = Number(cat.name.replace("cat_", ""));
|
|
const lock = cat.getChildByName("lock");
|
|
if (lock) lock.active = ownedCats.indexOf(id) < 0;
|
|
});
|
|
|
|
|
|
}
|
|
|
|
getSelfAvatar(event?: cc.Event) {
|
|
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
// this.content2.getChildByName(this.avatarKuang).getChildByName("select").active = true;
|
|
console.log("获取进入头像:", this.avatar);
|
|
if (this.avatar.length > 10) {
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("sp").active = false;
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("texture").active = true;
|
|
this.setSelfAvatar(true);
|
|
}
|
|
else {
|
|
console.log("没有头像", this.avatar);
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("sp").active = true;
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("texture").active = false;
|
|
let actionName = cc.fx.GameTool.getActionName(this.avatar);
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("sp").scale = 0.85;
|
|
cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("self").getChildByName("icon").getChildByName("sp"), actionName);
|
|
// this.node.getChildByName("self").getChildByName("icon").getChildByName("texture").getComponent(cc.Sprite).spriteFrame =
|
|
// this.ui.getSpriteFrame(this.avatar);
|
|
}
|
|
|
|
this.node.getChildByName("self").getChildByName("kuang").getComponent(cc.Sprite).spriteFrame =
|
|
this.ui.getSpriteFrame(this.avatarKuang);
|
|
// this.node.getChildByName("self").getChildByName("kuang").getComponent(cc.Sprite).spriteFrame =
|
|
// this.ui.getSpriteFrame(this.avatarKuang);
|
|
cc.fx.GameTool.getUserAvatar((data) => {
|
|
console.log("有头像__________", cc.fx.GameConfig.GM_INFO.useravatar)
|
|
this.setSelfAvatar(true);
|
|
if (data == true) {
|
|
this.avatar = cc.fx.GameConfig.GM_INFO.useravatar;
|
|
this.changeAvatar(null, this.avatar);
|
|
this.clickBtn();
|
|
}
|
|
|
|
})
|
|
}
|
|
|
|
closeAvatar() {
|
|
this.unschedule(this.playPopupEntrance);
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
|
|
const jiazaiComp = jiazaiNode.getComponent(JiaZai);
|
|
if (jiazaiComp) {
|
|
console.log("获取到JiaZai组件", jiazaiComp);
|
|
const rankInfoChanged =
|
|
this.initialAddress !== String(cc.fx.GameConfig.GM_INFO.address || "")
|
|
|| this.initialAvatar !== String(cc.fx.GameConfig.GM_INFO.useravatarIcon || "")
|
|
|| this.initialAvatarCat !== String(cc.fx.GameConfig.GM_INFO.useravatarCat || "");
|
|
jiazaiComp.closeAvatar(rankInfoChanged);
|
|
|
|
} else {
|
|
console.log("无法获取JiaZai组件");
|
|
}
|
|
}
|
|
|
|
openLoad() {
|
|
LoadingCatAnimation.play(this.node.getChildByName("Loading"));
|
|
}
|
|
|
|
|
|
openGacha() {
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
const jiazaiNode = cc.find("Canvas"); // 假设 JiaZai 挂在 Canvas 节点
|
|
const jiazaiComp = jiazaiNode.getComponent(JiaZai);
|
|
if (jiazaiComp) {
|
|
console.log("打開抽卡之前", this.avatarData);
|
|
jiazaiComp.openGacha(null, null, this.avatarData, this.film, this.catArr);
|
|
jiazaiComp.closeAvatar();
|
|
|
|
} else {
|
|
console.log("无法获取JiaZai组件");
|
|
}
|
|
}
|
|
|
|
// 切换头像和形象列表,节点透明度由弹窗动画管理。
|
|
changeState(event, state) {
|
|
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
if (state !== "tou" && state !== "kuang") return;
|
|
|
|
const showAvatar = state === "tou";
|
|
const cat = this.node.getChildByName("cat");
|
|
if (!showAvatar && !cat.active) {
|
|
this.closeSelectKuang();
|
|
this.closeCatKuang();
|
|
this.avatarCat = cc.fx.GameConfig.GM_INFO.useravatarCat;
|
|
this.changeCat(null, this.avatarCat);
|
|
}
|
|
this.node.getChildByName("avatar").active = showAvatar;
|
|
cat.active = !showAvatar;
|
|
this.node.getChildByName("avatarKuang").active = false;
|
|
this.node.getChildByName("tou").getComponent(cc.Sprite).enabled = !showAvatar;
|
|
this.changeBtnState(showAvatar ? "avatar" : "kuang");
|
|
}
|
|
|
|
// 判断按钮状态,切换按钮状态
|
|
changeBtnState(state) {
|
|
if (state == 'avatar') {
|
|
if (this.avatar == cc.fx.GameConfig.GM_INFO.useravatarIcon) {
|
|
this.node.getChildByName("btn").active = false;
|
|
this.node.getChildByName("btnUse").active = true;
|
|
}
|
|
else {
|
|
this.node.getChildByName("btn").active = true;
|
|
this.node.getChildByName("btnUse").active = false;
|
|
}
|
|
}
|
|
else if (state == 'kuang') {
|
|
if (this.avatarCat == cc.fx.GameConfig.GM_INFO.useravatarCat) {
|
|
this.node.getChildByName("btn").active = false;
|
|
this.node.getChildByName("btnUse").active = true;
|
|
}
|
|
else {
|
|
this.node.getChildByName("btn").active = true;
|
|
this.node.getChildByName("btnUse").active = false;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//改变头像
|
|
changeAvatar(event, avatar) {
|
|
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
this.closeSelectAvatar();
|
|
this.avatar = avatar;
|
|
switch (avatar) {
|
|
case "icon":
|
|
if (cc.fx.GameConfig.GM_INFO.useravatar.length > 10) {
|
|
this.avatar = cc.fx.GameConfig.GM_INFO.useravatar;
|
|
}
|
|
this.content.children[0].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_0":
|
|
this.content.children[1].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_1":
|
|
this.content.children[2].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_2":
|
|
this.content.children[3].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_3":
|
|
this.content.children[4].getChildByName("select").active = true;
|
|
break
|
|
case "icon_4":
|
|
this.content.children[4].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_5":
|
|
this.content.children[5].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_6":
|
|
this.content.children[6].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_7":
|
|
this.content.children[7].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_8":
|
|
this.content.children[8].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_9":
|
|
this.content.children[9].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_10":
|
|
this.content.children[9].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_11":
|
|
this.content.children[10].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_12":
|
|
this.content.children[11].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_13":
|
|
this.content.children[12].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_14":
|
|
this.content.children[11].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_15":
|
|
this.content.children[13].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_16":
|
|
this.content.children[14].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_19":
|
|
this.content.children[15].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_20":
|
|
this.content.children[16].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_21":
|
|
this.content.children[17].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_22":
|
|
this.content.children[18].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_23":
|
|
this.content.children[19].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_24":
|
|
this.content.children[20].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_25":
|
|
this.content.children[21].getChildByName("select").active = true;
|
|
break;
|
|
case "icon_26":
|
|
this.content.children[22].getChildByName("select").active = true;
|
|
break;
|
|
default:
|
|
if (this.avatar.length > 10) {
|
|
this.content.children[0].getChildByName("select").active = true;
|
|
}
|
|
|
|
break;
|
|
}
|
|
this.changeBtnState("avatar");
|
|
}
|
|
|
|
setSelfAvatar(data) {
|
|
let url = cc.fx.GameConfig.GM_INFO.useravatar;
|
|
if (url == "") {
|
|
return;
|
|
}
|
|
var self = this;
|
|
cc.assetManager.loadRemote(cc.fx.GameConfig.GM_INFO.useravatar, { ext: '.png' }, (err, texture: cc.Texture2D) => {
|
|
if (texture) {
|
|
if (data == true || cc.fx.GameConfig.GM_INFO.useravatar.length > 10) {
|
|
if (this.avatar == cc.fx.GameConfig.GM_INFO.useravatar) {
|
|
var sprite = self.node.getChildByName("self").getChildByName("icon").getChildByName("texture").getComponent(cc.Sprite);
|
|
sprite.spriteFrame = new cc.SpriteFrame(texture);
|
|
}
|
|
var sprite2 = self.content.children[0].getChildByName("icon").getChildByName("texture").getComponent(cc.Sprite);
|
|
sprite2.spriteFrame = new cc.SpriteFrame(texture);
|
|
}
|
|
// var sprite2 = self.content.children[0].getChildByName("icon").getComponent(cc.Sprite);
|
|
// sprite2.spriteFrame = new cc.SpriteFrame(texture);
|
|
}
|
|
})
|
|
}
|
|
|
|
//使用 按钮
|
|
clickBtn(event?: cc.Event) {
|
|
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
if (this.node.getChildByName("avatar").active == true) {
|
|
cc.fx.GameConfig.GM_INFO.useravatarIcon = this.avatar;
|
|
if (cc.fx.GameConfig.GM_INFO.useravatarIcon.length > 10) {
|
|
cc.fx.GameConfig.GM_INFO.useravatarIcon = cc.fx.GameConfig.GM_INFO.useravatar;
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("sp").active = false;
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("texture").active = true;
|
|
this.setSelfAvatar(true);
|
|
}
|
|
else {
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("sp").active = true;
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("texture").active = false;
|
|
let actionName = cc.fx.GameTool.getActionName(this.avatar);
|
|
this.node.getChildByName("self").getChildByName("icon").getChildByName("sp").scale = 0.85;
|
|
cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("self").getChildByName("icon").getChildByName("sp"), actionName);
|
|
// this.node.getChildByName("self").getChildByName("icon").getChildByName("texture").getComponent(cc.Sprite).spriteFrame =
|
|
// this.ui.getSpriteFrame(this.avatar);
|
|
}
|
|
}
|
|
else {
|
|
cc.fx.GameConfig.GM_INFO.useravatarCat = this.avatarCat;
|
|
|
|
|
|
console.log("________________保存头像框", this.avatarCat);
|
|
|
|
}
|
|
for (let i = 0; i < this.content.children.length; i++) {
|
|
this.content.children[i].getChildByName("kuang").getComponent(cc.Sprite).spriteFrame = this.ui.getSpriteFrame(this.avatarKuang);
|
|
}
|
|
this.node.getChildByName("btn").active = false;
|
|
this.node.getChildByName("btnUse").active = true;
|
|
}
|
|
|
|
//改变头像框
|
|
changeKuang(event, kuang) {
|
|
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
this.closeSelectKuang();
|
|
this.avatarKuang = kuang;
|
|
console.log("谁应该为true222", kuang);
|
|
this.content3.getChildByName(kuang).getChildByName("select").active = true;
|
|
this.changeBtnState("kuang");
|
|
}
|
|
|
|
//改变头像框
|
|
changeCat(event, catData) {
|
|
const cat = this.content4.getChildByName(catData);
|
|
if (!cat) { cc.warn("[Avatar] 缺少猫形象节点", catData); return; }
|
|
const lock = cat.getChildByName("lock");
|
|
if (event && lock && lock.active) return;
|
|
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
this.closeCatKuang();
|
|
this.avatarCat = catData;
|
|
console.log("谁应该为true111", catData);
|
|
console.log(this.content4.children);
|
|
cat.getChildByName("select").active = true;
|
|
this.changeBtnState("kuang");
|
|
}
|
|
|
|
closeSelectAvatar() {
|
|
for (let i = 0; i < this.content.children.length; i++) {
|
|
this.content.children[i].getChildByName("select").active = false;
|
|
}
|
|
}
|
|
|
|
closeSelectKuang() {
|
|
for (let i = 0; i < this.content3.children.length; i++) {
|
|
this.content3.children[i].getChildByName("select").active = false;
|
|
}
|
|
}
|
|
|
|
closeCatKuang() {
|
|
for (let i = 0; i < this.content4.children.length; i++) {
|
|
this.content4.children[i].getChildByName("select").active = false;
|
|
}
|
|
}
|
|
|
|
switchAddress(event, address) {
|
|
if (event) cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
if (cc.fx.GameConfig.GM_INFO.address != address) {
|
|
cc.fx.GameConfig.GM_INFO.address = address;
|
|
}
|
|
|
|
let node = this.content2.getChildByName(address);
|
|
if (node) {
|
|
this.content2.getChildByName("choice").active = true;
|
|
this.content2.getChildByName("choice").x = node.x;
|
|
this.content2.getChildByName("choice").y = node.y;
|
|
let name = address;
|
|
if (name != "北京" && name != "天津" && name != "上海" && name != "重庆" && name != "广西" && name != "新疆" && name != "西藏" && name != "宁夏" && name != "港澳台" && name != "内蒙古") {
|
|
name = name.substring(0, name.length - 1);
|
|
}
|
|
this.content2.getChildByName("choice").getChildByName("cityName").getComponent(cc.Label).string = name;
|
|
}
|
|
}
|
|
|
|
openAddress() {
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
let change = cc.fx.StorageMessage.getStorage("changeAddress");
|
|
//没缓存过,没授权过
|
|
if (change == "" || change == null || change == undefined) {
|
|
}
|
|
else {
|
|
let time = change.time;
|
|
let changeCount = change.changeCount;
|
|
if (changeCount >= 2) {
|
|
// 获取当前时间戳
|
|
let nowTime = Math.floor(Date.now() / 1000);
|
|
|
|
// 将时间戳转换为日期对象
|
|
let currentDate = new Date(nowTime * 1000);
|
|
let storedDate = new Date(time * 1000);
|
|
|
|
// 比较年月日是否相同
|
|
let currentYear = currentDate.getFullYear();
|
|
let currentMonth = currentDate.getMonth();
|
|
let currentDay = currentDate.getDate();
|
|
|
|
let storedYear = storedDate.getFullYear();
|
|
let storedMonth = storedDate.getMonth();
|
|
let storedDay = storedDate.getDate();
|
|
|
|
// 如果年月日没变,则return
|
|
if (currentYear === storedYear && currentMonth === storedMonth && currentDay === storedDay) {
|
|
MiniGameSdk.API.showToast("每日可变更地址两次,今日变更次数已用完");
|
|
return;
|
|
}
|
|
else {
|
|
changeCount = 0;
|
|
let changeInfo = {
|
|
time: nowTime,
|
|
changeCount: changeCount
|
|
}
|
|
cc.fx.StorageMessage.setStorage("changeAddress", changeInfo);
|
|
}
|
|
// 否则不处理,继续执行后续代码
|
|
}
|
|
}
|
|
|
|
this.node.getChildByName("address").active = true;
|
|
this.content2.getChildByName("choice").active = false;
|
|
this.address = cc.fx.GameConfig.GM_INFO.address;
|
|
if (cc.fx.GameConfig.GM_INFO.address != "" && cc.fx.GameConfig.GM_INFO.address != null) {
|
|
let node = this.content2.getChildByName(this.address);
|
|
if (node) {
|
|
this.content2.getChildByName("choice").active = true;
|
|
this.content2.getChildByName("choice").x = node.x;
|
|
this.content2.getChildByName("choice").y = node.y;
|
|
this.content2.getChildByName("choice").getChildByName("cityName").getComponent(cc.Label).string = this.address;
|
|
}
|
|
}
|
|
|
|
PopupAnimator.open(popupContent(this.node.getChildByName("address"), ["New Sprite(Splash)"]));
|
|
}
|
|
|
|
closeAddress() {
|
|
const content = popupContent(this.node.getChildByName("address"), ["New Sprite(Splash)"]);
|
|
if (!content || (Array.isArray(content) && !content.length)) { this.finishPopupCloseAddress(); return; }
|
|
PopupAnimator.close(content, PopupType.Bounce, () => this.finishPopupCloseAddress());
|
|
}
|
|
|
|
finishPopupCloseAddress() {
|
|
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
|
|
if (this.address != cc.fx.GameConfig.GM_INFO.address) {
|
|
this.address = cc.fx.GameConfig.GM_INFO.address;
|
|
let Info = this.node.getChildByName("Info");
|
|
//用户城市
|
|
let city = cc.fx.GameConfig.GM_INFO.address;
|
|
if (city == "北京" || city == "上海" || city == "重庆" || city == "天津") {
|
|
city = city + "市";
|
|
}
|
|
Info.getChildByName("Address").getComponent(cc.Label).string = city + "";
|
|
|
|
let nowTime = Math.floor(Date.now() / 1000);
|
|
let addressInfo = {
|
|
address: cc.fx.GameConfig.GM_INFO.address,
|
|
time: nowTime,
|
|
authorize: false
|
|
}
|
|
cc.fx.StorageMessage.setStorage("address", addressInfo);
|
|
Utils.setCityInfo(null, cc.fx.GameConfig.GM_INFO.address, true);
|
|
let locationInfo = {
|
|
type: "manual",
|
|
result: cc.fx.GameConfig.GM_INFO.address,
|
|
is_success: true,
|
|
info: ""
|
|
}
|
|
cc.fx.GameTool.shushu_Track("location", locationInfo);
|
|
|
|
|
|
let changeCount = 0;
|
|
let change = cc.fx.StorageMessage.getStorage("changeAddress");
|
|
//没缓存过,没授权过
|
|
if (change == "" || change == null || change == undefined) {
|
|
// changeCount = 1;
|
|
changeCount += 1;
|
|
}
|
|
else {
|
|
changeCount = change.changeCount + 1;
|
|
}
|
|
|
|
let changeInfo = {
|
|
time: nowTime,
|
|
changeCount: changeCount
|
|
}
|
|
cc.fx.StorageMessage.setStorage("changeAddress", changeInfo);
|
|
}
|
|
|
|
|
|
this.node.getChildByName("address").active = false;
|
|
}
|
|
}
|
|
|
|
|