RoleFrameView.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { GameViewType } from "../../../main/ViewManage";
  2. import ViewObject from "../../../main/ViewObject";
  3. import FFCalAttr from "../../data/FFCalAttr";
  4. import TapRole from "../TapRole";
  5. import RoleIconItem from "./RoleIconItem";
  6. import IconInfoView from "./IconInfoView";
  7. /**
  8. * 头像框设置界面
  9. */
  10. const {ccclass, property} = cc._decorator;
  11. @ccclass
  12. export default class RoleFrameView extends ViewObject {
  13. @property(cc.Node)
  14. mContent: cc.Node = null;
  15. @property(cc.Prefab)
  16. mFrameIcon: cc.Prefab = null;
  17. @property(cc.Label)
  18. mZdl: cc.Label = null;
  19. @property(IconInfoView)
  20. private iconInfoView:IconInfoView = null
  21. public tapRole:TapRole = null;
  22. onLoad(){
  23. this.iconInfoView.main = this.main
  24. this.iconInfoView.roleFrameView = this
  25. this.iconInfoView.openType = 2
  26. this.init()
  27. }
  28. private init(){
  29. let roleIcons = this.main.sManage.getRoleIcon()
  30. let fip = undefined
  31. let frameId = this.main.player.role.frame
  32. for (let i = 0; i < roleIcons.length; i++) {
  33. const element = roleIcons[i];
  34. if(element.type == 2){
  35. let node = cc.instantiate(this.mFrameIcon)
  36. let frameIcon = node.getComponent(RoleIconItem)
  37. frameIcon.roleIcon = element
  38. frameIcon.mIcon.node.active = false
  39. frameIcon.loadFrame(this.main)
  40. frameIcon.flushLock(this.main)
  41. node.parent = this.mContent
  42. frameIcon.setCallback((fip:RoleIconItem)=>{
  43. this.openInfo(fip)
  44. })
  45. if(frameId == element.id){
  46. fip = frameIcon
  47. }
  48. }
  49. }
  50. if(!fip){
  51. fip = this.mContent.children[0].getComponent(RoleIconItem)
  52. }
  53. this.flush(fip)
  54. }
  55. public flush(fip:RoleIconItem){
  56. this.iconInfoView.initFrame(this.main,fip)
  57. let data = {
  58. atk:0,
  59. def:0,
  60. hp:0,
  61. sp:0
  62. }
  63. let open = this.main.player.roleIcon.open
  64. for (let i = 0; i < open.length; i++) {
  65. const element = open[i];
  66. if(element >= 200 && element < 300){
  67. let temp = this.main.sManage.getRoleIconById(element)
  68. data.atk += temp.atk
  69. data.def += temp.def
  70. data.hp += temp.hp
  71. data.sp += temp.sp
  72. }
  73. }
  74. let zdl = FFCalAttr.getZdl(data)
  75. this.mZdl.string = ''+zdl
  76. let nodes = this.mContent.children
  77. for (let i = 0; i < nodes.length; i++) {
  78. const node = nodes[i];
  79. let item = node.getComponent(RoleIconItem)
  80. if(item.roleIcon.id != this.main.player.role.frame){
  81. item.setCheck(false)
  82. }else{
  83. item.setCheck(true)
  84. }
  85. }
  86. }
  87. private openInfo(fip:RoleIconItem){
  88. this.flush(fip)
  89. fip.mCheck.active = true
  90. let nodes = fip.node.parent.children
  91. for (let i = 0; i < nodes.length; i++) {
  92. const element = nodes[i];
  93. let tmp = element.getComponent(RoleIconItem)
  94. if(tmp != fip){
  95. tmp.mCheck.active = false;
  96. }
  97. }
  98. }
  99. }