123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import { GameViewType } from "../../main/ViewManage";
- import ViewObject from "../../main/ViewObject";
- import CMath from "../../util/CMath";
- import RoleFrameView from "./roleicon/RoleFrameView";
- import RoleIconView from "./roleicon/RoleIconView";
- import RoleTitleItem from "./roleicon/RoleTitleItem";
- import RoleTitleView from "./roleicon/RoleTitleView";
- import TapRoleName from "./TapRoleName";
- /**
- * 角色信息
- */
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class TapRole extends ViewObject {
- @property(cc.Label)
- mName: cc.Label = null;
- @property(cc.Sprite)
- mIcon: cc.Sprite = null;
- @property(cc.Sprite)
- mFrame: cc.Sprite = null;
- @property(cc.Label)
- mId: cc.Label = null;
- @property(cc.Prefab)
- mFrameIcon: cc.Prefab = null;
- @property(cc.Node)
- mContentHas: cc.Node = null;
- @property(cc.Label)
- mZdl: cc.Label = null;
- onLoad () {
- let player = this.main.player;
- this.mName.string = player.role.name;
- this.mId.string = player.role.id;
- this.mZdl.string = ''+player.role.zdl
- }
- /**
- *
- * @param prev 父界面
- */
- public show(prev?:ViewObject){
- if(prev){
- this.prev = prev;
- this.prev.__close();
- }
- this.main.viewManage.popView1(this.node);
- if(this.main && this.main.gameHttp){
- this.main.gameHttp.pushEvent(this);
- }
- }
- onEnable(){
- this.flush()
- }
- public flush(){
- let player = this.main.player;
- this.mName.string = player.role.name;
-
- let roleIcon = this.main.sManage.getRoleIconById(player.role.icon)
- if(roleIcon){
- cc.resources.load('icon/role_head/'+roleIcon.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
- if(err){
- cc.error(err);
- }else{
- this.mIcon.spriteFrame = spriteFrame;
- }
- } );
- }
- let roleFrame = this.main.sManage.getRoleIconById(player.role.frame)
- if(roleFrame){
- cc.resources.load('icon/role_head/txk/'+roleFrame.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
- if(err){
- cc.error(err);
- }else{
- this.mFrame.spriteFrame = spriteFrame;
- }
- } );
- }
- this.flushTitle()
- }
- private flushTitle(){
- let roleIcon = this.main.player.roleIcon
- let open = roleIcon.open
- let nodes = this.mContentHas.children
- let copy:Array<number> = open.slice();
- for (let i = nodes.length - 1; i >= 0; i--) {
- const node = nodes[i];
- let rti = node.getComponent(RoleTitleItem)
- if(open.indexOf(rti.roleIcon.id) < 0){
- node.destroy()
- }
- for (let j = 0; j < copy.length; j++) {
- const tempId = copy[j];
- if(tempId == rti.roleIcon.id){
- copy.splice(j,1);
- break
- }
- }
- }
- let x0 = this.mContentHas.width/2 - 100
- let y0 = this.mContentHas.height/2 - 30
- for (let i = 0; i < copy.length; i++) {
- const id = copy[i];
- if(id >= 300){
- let node = cc.instantiate(this.mFrameIcon)
- node.x = CMath.getRandom(-x0,x0)
- node.y = CMath.getRandom(-y0,y0)
- let frameIcon = node.getComponent(RoleTitleItem)
- let roleIcon = this.main.sManage.getRoleIconById(id);
- frameIcon.roleIcon = roleIcon
- frameIcon.init()
- frameIcon.mLock.active = false
- node.parent = this.mContentHas
- }
- }
- }
- public onclickRename(){
- this.main.viewManage.loadFunc(GameViewType.tap_role_name,(viewObject:ViewObject)=>{
- let rename = viewObject as TapRoleName
- rename.tapRole = this
- viewObject.show(this);
- });
- }
-
- public onclickIcon(){
- this.main.viewManage.loadFunc(GameViewType.role_icon_view,(viewObject:ViewObject)=>{
- let rename = viewObject as RoleIconView
- rename.tapRole = this
- viewObject.show(this);
- });
- }
- public onclickFrame(){
- this.main.viewManage.loadFunc(GameViewType.role_frame_view,(viewObject:ViewObject)=>{
- let rename = viewObject as RoleFrameView
- rename.tapRole = this
- viewObject.show(this);
- });
- }
- public onclickTitle(){
- this.main.viewManage.loadFunc(GameViewType.role_title_view,(viewObject:ViewObject)=>{
- let rename = viewObject as RoleTitleView
- rename.init()
- viewObject.show(this);
- });
- }
- }
|