TapRole.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { GameViewType } from "../../main/ViewManage";
  2. import ViewObject from "../../main/ViewObject";
  3. import CMath from "../../util/CMath";
  4. import RoleFrameView from "./roleicon/RoleFrameView";
  5. import RoleIconView from "./roleicon/RoleIconView";
  6. import RoleTitleItem from "./roleicon/RoleTitleItem";
  7. import RoleTitleView from "./roleicon/RoleTitleView";
  8. import TapRoleName from "./TapRoleName";
  9. /**
  10. * 角色信息
  11. */
  12. const {ccclass, property} = cc._decorator;
  13. @ccclass
  14. export default class TapRole extends ViewObject {
  15. @property(cc.Label)
  16. mName: cc.Label = null;
  17. @property(cc.Sprite)
  18. mIcon: cc.Sprite = null;
  19. @property(cc.Sprite)
  20. mFrame: cc.Sprite = null;
  21. @property(cc.Label)
  22. mId: cc.Label = null;
  23. @property(cc.Prefab)
  24. mFrameIcon: cc.Prefab = null;
  25. @property(cc.Node)
  26. mContentHas: cc.Node = null;
  27. @property(cc.Label)
  28. mZdl: cc.Label = null;
  29. onLoad () {
  30. let player = this.main.player;
  31. this.mName.string = player.role.name;
  32. this.mId.string = player.role.id;
  33. this.mZdl.string = ''+player.role.zdl
  34. }
  35. /**
  36. *
  37. * @param prev 父界面
  38. */
  39. public show(prev?:ViewObject){
  40. if(prev){
  41. this.prev = prev;
  42. this.prev.__close();
  43. }
  44. this.main.viewManage.popView1(this.node);
  45. if(this.main && this.main.gameHttp){
  46. this.main.gameHttp.pushEvent(this);
  47. }
  48. }
  49. onEnable(){
  50. this.flush()
  51. }
  52. public flush(){
  53. let player = this.main.player;
  54. this.mName.string = player.role.name;
  55. let roleIcon = this.main.sManage.getRoleIconById(player.role.icon)
  56. if(roleIcon){
  57. cc.resources.load('icon/role_head/'+roleIcon.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  58. if(err){
  59. cc.error(err);
  60. }else{
  61. this.mIcon.spriteFrame = spriteFrame;
  62. }
  63. } );
  64. }
  65. let roleFrame = this.main.sManage.getRoleIconById(player.role.frame)
  66. if(roleFrame){
  67. cc.resources.load('icon/role_head/txk/'+roleFrame.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  68. if(err){
  69. cc.error(err);
  70. }else{
  71. this.mFrame.spriteFrame = spriteFrame;
  72. }
  73. } );
  74. }
  75. this.flushTitle()
  76. }
  77. private flushTitle(){
  78. let roleIcon = this.main.player.roleIcon
  79. let open = roleIcon.open
  80. let nodes = this.mContentHas.children
  81. let copy:Array<number> = open.slice();
  82. for (let i = nodes.length - 1; i >= 0; i--) {
  83. const node = nodes[i];
  84. let rti = node.getComponent(RoleTitleItem)
  85. if(open.indexOf(rti.roleIcon.id) < 0){
  86. node.destroy()
  87. }
  88. for (let j = 0; j < copy.length; j++) {
  89. const tempId = copy[j];
  90. if(tempId == rti.roleIcon.id){
  91. copy.splice(j,1);
  92. break
  93. }
  94. }
  95. }
  96. let x0 = this.mContentHas.width/2 - 100
  97. let y0 = this.mContentHas.height/2 - 30
  98. for (let i = 0; i < copy.length; i++) {
  99. const id = copy[i];
  100. if(id >= 300){
  101. let node = cc.instantiate(this.mFrameIcon)
  102. node.x = CMath.getRandom(-x0,x0)
  103. node.y = CMath.getRandom(-y0,y0)
  104. let frameIcon = node.getComponent(RoleTitleItem)
  105. let roleIcon = this.main.sManage.getRoleIconById(id);
  106. frameIcon.roleIcon = roleIcon
  107. frameIcon.init()
  108. frameIcon.mLock.active = false
  109. node.parent = this.mContentHas
  110. }
  111. }
  112. }
  113. public onclickRename(){
  114. this.main.viewManage.loadFunc(GameViewType.tap_role_name,(viewObject:ViewObject)=>{
  115. let rename = viewObject as TapRoleName
  116. rename.tapRole = this
  117. viewObject.show(this);
  118. });
  119. }
  120. public onclickIcon(){
  121. this.main.viewManage.loadFunc(GameViewType.role_icon_view,(viewObject:ViewObject)=>{
  122. let rename = viewObject as RoleIconView
  123. rename.tapRole = this
  124. viewObject.show(this);
  125. });
  126. }
  127. public onclickFrame(){
  128. this.main.viewManage.loadFunc(GameViewType.role_frame_view,(viewObject:ViewObject)=>{
  129. let rename = viewObject as RoleFrameView
  130. rename.tapRole = this
  131. viewObject.show(this);
  132. });
  133. }
  134. public onclickTitle(){
  135. this.main.viewManage.loadFunc(GameViewType.role_title_view,(viewObject:ViewObject)=>{
  136. let rename = viewObject as RoleTitleView
  137. rename.init()
  138. viewObject.show(this);
  139. });
  140. }
  141. }