RoleIconView.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 RoleIconView 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.roleIconView = this
  25. this.iconInfoView.openType = 1
  26. this.init()
  27. }
  28. private init(){
  29. let roleIcons = this.main.sManage.getRoleIcon()
  30. let fip = undefined
  31. let iconId = this.main.player.role.icon
  32. for (let i = 0; i < roleIcons.length; i++) {
  33. const element = roleIcons[i];
  34. if(element.type == 1){
  35. let node = cc.instantiate(this.mFrameIcon)
  36. let frameIcon = node.getComponent(RoleIconItem)
  37. frameIcon.roleIcon = element
  38. frameIcon.flush(this.main)
  39. node.parent = this.mContent
  40. frameIcon.setCallback((fip:RoleIconItem)=>{
  41. this.openInfo(fip)
  42. })
  43. if(iconId == element.id){
  44. fip = frameIcon
  45. }
  46. }
  47. }
  48. if(!fip){
  49. fip = this.mContent.children[0].getComponent(RoleIconItem)
  50. }
  51. this.flush(fip)
  52. }
  53. public flush(fip:RoleIconItem){
  54. this.iconInfoView.init(this.main,fip)
  55. let data = {
  56. atk:0,
  57. def:0,
  58. hp:0,
  59. sp:0
  60. }
  61. let open = this.main.player.roleIcon.open
  62. for (let i = 0; i < open.length; i++) {
  63. const element = open[i];
  64. if(element < 200){
  65. let temp = this.main.sManage.getRoleIconById(element)
  66. data.atk += temp.atk
  67. data.def += temp.def
  68. data.hp += temp.hp
  69. data.sp += temp.sp
  70. }
  71. }
  72. let zdl = FFCalAttr.getZdl(data)
  73. this.mZdl.string = ''+zdl
  74. let nodes = this.mContent.children
  75. for (let i = 0; i < nodes.length; i++) {
  76. const node = nodes[i];
  77. let item = node.getComponent(RoleIconItem)
  78. if(item.roleIcon.id != this.main.player.role.icon){
  79. item.setCheck(false)
  80. }else{
  81. item.setCheck(true)
  82. }
  83. }
  84. }
  85. private openInfo(fip:RoleIconItem){
  86. this.flush(fip)
  87. fip.mCheck.active = true
  88. let nodes = fip.node.parent.children
  89. for (let i = 0; i < nodes.length; i++) {
  90. const element = nodes[i];
  91. let tmp = element.getComponent(RoleIconItem)
  92. if(tmp != fip){
  93. tmp.mCheck.active = false;
  94. }
  95. }
  96. }
  97. }