cb/assets/action_bundle/script/shareFriend.ts
2026-06-22 19:57:56 +08:00

139 lines
5.0 KiB
TypeScript

import MapConroler from "../../Script/Map";
const { ccclass, property } = cc._decorator;
@ccclass
export default class shareFriend extends cc.Component {
@property(cc.SpriteAtlas)
ui: cc.SpriteAtlas = null;
onLoad() {
}
start() {
}
init(type, shuju) {
console.log("111111111", shuju);
this.node.getChildByName("level").getComponent(cc.Label).string = shuju.otherLevel + "";
let useravatarIcon = shuju.otherKuang;
useravatarIcon = "kuang_" + (parseInt(useravatarIcon) + 1);
console.log("3333333", useravatarIcon);
if (this.node.getChildByName("kuang"))
this.node.getChildByName("kuang").getComponent(cc.Sprite).spriteFrame =
this.ui.getSpriteFrame(useravatarIcon);
if (shuju.otherAvatarUrl == "" || shuju.otherAvatarUrl == null || shuju.otherAvatarUrl == undefined
) {
console.log("头像为空", shuju.otherAvatarUrl);
}
else if (shuju.otherAvatarUrl == "0" || shuju.otherAvatarUrl == "1" || shuju.otherAvatarUrl == "2"
|| shuju.otherAvatarUrl == "3" || shuju.otherAvatarUrl == "4" || shuju.otherAvatarUrl == "5"
|| shuju.otherAvatarUrl == "6" || shuju.otherAvatarUrl == "7" || shuju.otherAvatarUrl == "8"
|| shuju.otherAvatarUrl == "9" || shuju.otherAvatarUrl == "10" || shuju.otherAvatarUrl == "11"
|| shuju.otherAvatarUrl == "12" || shuju.otherAvatarUrl == "13" || shuju.otherAvatarUrl == "14"
|| shuju.otherAvatarUrl == "15" || shuju.otherAvatarUrl == "16" || shuju.otherAvatarUrl == "17") {
let useravatar = shuju.otherAvatarUrl;
// let useravatarTemp = "icon_" + useravatar;
if (this.node.getChildByName("iphone")) {
this.node.getChildByName("iphone").getChildByName("icon").active = false;
this.node.getChildByName("iphone").getChildByName("sp").active = true;
let actionName = cc.fx.GameTool.getActionName(shuju.otherAvatarUrl);
this.node.getChildByName("iphone").getChildByName("sp").scale = 1.2;
cc.fx.GameTool.loadSpineSimple(this.node.getChildByName("iphone").getChildByName("sp"), actionName);
}
// this.node.getChildByName("iphone").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.ui.getSpriteFrame(useravatarTemp);
}
else {
this.node.getChildByName("iphone").getChildByName("icon").active = true;
this.node.getChildByName("iphone").getChildByName("sp").active = false;
this.setPic(shuju.otherAvatarUrl);
}
let name = shuju.otherNickName;
if (name == "user" || name == null) name = "你的好友";
else {
if (shuju.otherNickName.length >= 7)
name = cc.fx.GameTool.subName(shuju.otherNickName, 7);
}
console.log("7777777");
if (this.node.getChildByName("name")) {
console.log("8888888", name);
this.node.getChildByName("name").getComponent(cc.Label).string = name + "";
}
}
helpBtn() {
const canvasTemp = cc.find("Canvas"); // 假设 Canvas 节点
if (canvasTemp) {
const JiaZai = canvasTemp.getComponent("JiaZai");
if (JiaZai) {
JiaZai.startGame();
}
}
}
closeBtn() {
if (this.node)
this.node.active = false;
cc.fx.GameConfig.GM_INFO.otherUid = "";
cc.fx.GameConfig.GM_INFO.otherLevel = 0;
}
public setPic(url) {
// console.log("设置头像:", this.data.useravatar);
var self = this;
console.log("6666666", url);
if (!self.node || !cc.isValid(self.node)) return;
let iphone = self.node.getChildByName("iphone");
if (!iphone) return;
let iconNode = iphone.getChildByName("icon");
if (iconNode) iconNode.active = false;
cc.assetManager.loadRemote(url, { ext: '.png' }, (err, texture: cc.Texture2D) => {
if (!self.node || !cc.isValid(self.node)) return;
if (texture) {
let iphoneNode = self.node.getChildByName("iphone");
if (!iphoneNode) return;
console.log("okokokokokok")
let icon = iphoneNode.getChildByName("icon");
if (icon) {
var sprite = icon.getComponent(cc.Sprite);
if (sprite) sprite.spriteFrame = new cc.SpriteFrame(texture);
console.log("最终设置成功")
icon.active = true;
}
}
else {
let iphoneNode = self.node.getChildByName("iphone");
if (iphoneNode) {
let icon = iphoneNode.getChildByName("icon");
if (icon) icon.active = true;
}
console.log("设置头像失败", url);
console.log(err, texture)
}
})
}
update() {
}
}