/** @format */ import {UI} from '../enums/UI' import {BaseUI} from './BaseUI' import {Data, Mgr} from '../GameControl' import {ccUtils} from '../utils/ccUtils' import {observer, render, node, label, editBox, list} from '../mobx/observer' import {msgCmd} from '../proto/msg_cmd' import List from '../uiutils/List' import {BUILDING, LANGUAGE_TYPE, TIMESTAMP_TYPE, LOCAL} from '../enums/Enum' import {RanksLevelConfig} from '../config/RanksLevelConfig' import {BuildingConfig, IBuildingConfig} from '../config/BuildingConfig' import {manual} from '../proto/typedef' import {WxUtils} from '../utils/WxUtils' import {manualGetDataRsp, roleRenameRsp} from '../proto/game' const {ccclass, property} = cc._decorator /** 每座建筑的等级列表 */ @ccclass @observer export class UserInfoUI extends BaseUI { @list('build_list') buildList: List // 建筑资源列表 @node('playerinfo') //玩家信息 playerInfoNode: cc.Node @label('playerinfo/id_frame/scrollingtext/lb') //UID 滚动文本 scrollingTextUID: cc.Label @label('playerinfo/name_frame/scrollingtext/lb') //名称 滚动文本 scrollingTextName: cc.Label @node('upd_name') //玩家信息界面 updateNameNode: cc.Node @editBox('upd_name/input_name') //玩家信息界面 inputName: cc.EditBox buildNameList: string[] = [ //建筑名称 LANGUAGE_TYPE.castle, //城堡 LANGUAGE_TYPE.goldMine, //金矿 LANGUAGE_TYPE.mine, //铁矿 LANGUAGE_TYPE.loggingYard, //木场 LANGUAGE_TYPE.farm, //农场 ] BuildDatalist: IBuildingConfig[][] = [] minInputName: number = 4 //更改名字最小字符长度 maxInputName: number = 21 //更改名字最大字符长度 onLoad() { for (let i = 0; i < Data.main.buildData.length; i++) { this.BuildDatalist[Data.main.buildData[i].id] = [] } let buildID = 10000 for (let key in BuildingConfig) { //(建筑ID*10000+等级) 分类用于获取每个类型的建筑的最大等级 let ID = BuildingConfig[key].ID / buildID if (parseInt(ID.toFixed(0)) == BUILDING.main) this.BuildDatalist[BUILDING.main].push(BuildingConfig[key]) else if (parseInt(ID.toFixed(0)) == BUILDING.iron) this.BuildDatalist[BUILDING.iron].push(BuildingConfig[key]) else if (parseInt(ID.toFixed(0)) == BUILDING.wood) this.BuildDatalist[BUILDING.wood].push(BuildingConfig[key]) else if (parseInt(ID.toFixed(0)) == BUILDING.gold) this.BuildDatalist[BUILDING.gold].push(BuildingConfig[key]) else if (parseInt(ID.toFixed(0)) == BUILDING.farm) this.BuildDatalist[BUILDING.farm].push(BuildingConfig[key]) } } onShow(args, fromUI: number) { Mgr.net.add(msgCmd.cmd_role_rename_rsp, this, this.onRoleRenameRsp) this.initUIData() this.buildList.numItems = Data.main.buildData.length this.initScrollingText(this.scrollingTextName) this.initScrollingText(this.scrollingTextUID) Mgr.global.initAvatar(cc.find('avatar', this.playerInfoNode), this) this.showRedDot() } onHide(): any { Mgr.event.removeAll(this) } //显示界面红点 showRedDot() { const regex = /^[\u4E00-\u9FA5a-zA-Z0-9\s]+$/ cc.find('red_dots', this.playerInfoNode).active = !regex.test(Data.user.nickname) } initUIData() { let curLevelCfg = RanksLevelConfig[Data.user.level + 1] if (!curLevelCfg) curLevelCfg = Object.values(RanksLevelConfig).pop() ccUtils.setLabel('lv.' + Data.user.level, this.playerInfoNode, 'lv_frame/lb') ccUtils.setLabel(Data.user.exp + '/' + curLevelCfg.exp, this.playerInfoNode, 'lv_frame/lb_num') ccUtils.setProgress(Data.user.exp / curLevelCfg.exp, this.playerInfoNode, 'lv_frame/lv_pb') ccUtils.setLabel(Mgr.global.getPowerString(), this.playerInfoNode, 'power_frame/lb_num') ccUtils.setLabel(Data.user.uid, this.playerInfoNode, 'id_frame/scrollingtext/lb') ccUtils.setLabel(Data.user.nickname, this.playerInfoNode, 'name_frame/scrollingtext/lb') this.scrollingTextUID.node['isLeftTop'] = true this.scrollingTextName.node['isLeftTop'] = true //是否到左边顶部了 } initScrollingText(label: cc.Label) { //如果是赋值后马上调用 文本宽度可能不是最新的、刷新一下文本宽度 ;(label)._forceUpdateRenderData() // 停止节点上的所有动作 let s_lb = label.node s_lb.stopAllActions() let offset = (s_lb.width - s_lb.parent.width) / 2 //偏移值 if (s_lb.width < s_lb.parent.width) { return } // 创建一个 cc.MoveBy 动作 let moveByAction let callbackAction //判断是否文本是不是再最左边 默认不是 默认居中 if (s_lb['isLeftTop']) { s_lb.x = offset moveByAction = cc.moveTo(3, cc.v2(-offset, 0)) callbackAction = cc.callFunc(() => { s_lb['isLeftTop'] = false this.initScrollingText(label) }) } else { s_lb.x = -offset moveByAction = cc.moveTo(3, cc.v2(offset, 0)) callbackAction = cc.callFunc(() => { s_lb['isLeftTop'] = true this.initScrollingText(label) }) } const delayAction = cc.delayTime(2) const sequence = cc.sequence(delayAction, moveByAction, callbackAction) cc.tween(s_lb).then(sequence).start() } initBuildItem(node: cc.Node, index: number) { this.loadTexImg(`UserInfoUI/building_icon_` + (index + 1), node, 'icon') //资源图标 ccUtils.setLabel(this.buildNameList[index], node, 'name_lb') ccUtils.setLabel('lv.' + Data.main.buildData[index].level, node, 'lv_lb') let lvPCT = Data.main.buildData[index].level / this.BuildDatalist[Data.main.buildData[index].id].length ccUtils.setProgress(lvPCT, node, 'lv_pb') } //网络事件>改名======================================= onRoleRenameRsp(data: roleRenameRsp) { Mgr.storage.set(LOCAL.isEditName, true) Data.user.nickname = data.name Data.user.renameTime = data.time this.updateNameNode.active = false Mgr.ui.tip(LANGUAGE_TYPE.successfully) ccUtils.setLabel(Data.user.nickname, this.playerInfoNode, 'name_frame/scrollingtext/lb') this.initScrollingText(this.scrollingTextName) this.showRedDot() } //输入修改名称字符 onInputNameChange(editBox: cc.EditBox) { //如果输入的昵称长度不符合限制 就改成原名称 if (editBox.string.getStrLen() < this.minInputName) { Mgr.ui.tip(LANGUAGE_TYPE.minInputLimit) ccUtils.setEditBox(Data.user.nickname, this.inputName.node) return } else if (editBox.string.getStrLen() > this.maxInputName) { Mgr.ui.tip(LANGUAGE_TYPE.maxInputLimit) ccUtils.setEditBox(Data.user.nickname, this.inputName.node) return } } //确认修改名称 onClickConfirmUpdateName() { const regex = /^[\u4E00-\u9FA5a-zA-Z0-9\s]+$/ let time = Data.main.serverTime - Data.user.renameTime //输入违规 if (!regex.test(this.inputName.string)) { Mgr.ui.tip(LANGUAGE_TYPE.specificSymbol) return } //48个小时内不能改名 服务器时间 - 修改名字的时间 = 间隔时间 >= 2天就可以改名了 if (time >= TIMESTAMP_TYPE.day * 2) { Mgr.net.send(msgCmd.cmd_role_rename, {name: this.inputName.string}) } else { Mgr.ui.tip(`${Mgr.i18n.getLabel(LANGUAGE_TYPE.changeNameCD)}...`) return } } //点击打开修改名称界面 onClickOpenUpdateName() { this.updateNameNode.active = true ccUtils.setEditBox(Data.user.nickname, this.inputName.node) } //关闭修改名称界面 onClickCloseUpdateName() { this.updateNameNode.active = false } //点击复制uid onClickCopyUID() { Mgr.platform.copyToClipboard(Data.user.uid) } }