RoleIconItem.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import Main from "../../../main/Main";
  2. import { __RoleIcon } from "../../data/sdata/SManage";
  3. /**
  4. * 头像/框
  5. */
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class RoleIconItem extends cc.Component {
  9. @property(cc.Sprite)
  10. mIcon: cc.Sprite = null;//图标
  11. @property(cc.Sprite)
  12. mFrame: cc.Sprite = null;//底框
  13. @property(cc.Node)
  14. mCheck: cc.Node = null;//选中
  15. @property(cc.Node)
  16. mLock: cc.Node = null;//锁
  17. public roleIcon:__RoleIcon
  18. private callback:(frameIcon:RoleIconItem)=>void
  19. public setCallback(callback:(frameIcon:RoleIconItem)=>void){
  20. this.callback = callback
  21. }
  22. public onclick(){
  23. if(this.callback){
  24. this.callback(this)
  25. }
  26. }
  27. public loadIcon(main:Main){
  28. this.mCheck.active = false
  29. this.mLock.active = false
  30. cc.resources.load('icon/role_head/'+this.roleIcon.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  31. if(err){
  32. cc.error(err);
  33. }else{
  34. this.mIcon.spriteFrame = spriteFrame;
  35. }
  36. } );
  37. // //载入角色底框
  38. if(main){
  39. let role = main.player.role
  40. let roleFrame = main.sManage.getRoleIconById(role.frame)
  41. if(roleFrame){
  42. cc.resources.load('icon/role_head/txk/'+roleFrame.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  43. if(err){
  44. cc.error(err);
  45. }else{
  46. this.mFrame.spriteFrame = spriteFrame;
  47. }
  48. } );
  49. }
  50. }
  51. }
  52. public loadFrame(main:Main){
  53. this.mCheck.active = false
  54. this.mLock.active = false
  55. cc.resources.load('icon/role_head/txk/'+this.roleIcon.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  56. if(err){
  57. cc.error(err);
  58. }else{
  59. this.mFrame.spriteFrame = spriteFrame;
  60. }
  61. } );
  62. // //载入角色头像
  63. if(this.mIcon){
  64. let role = main.player.role
  65. let roleIcon = main.sManage.getRoleIconById(role.icon)
  66. if(roleIcon){
  67. cc.resources.load('icon/role_head/'+roleIcon.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  68. if(err){
  69. cc.error(err);
  70. }else{
  71. this.mIcon.spriteFrame = spriteFrame;
  72. }
  73. } );
  74. }
  75. }
  76. }
  77. /**
  78. * 动态设置背景
  79. * @param main
  80. */
  81. public flushFrame(main:Main){
  82. let player = main.player
  83. let roleFrame = main.sManage.getRoleIconById(player.role.frame)
  84. if(roleFrame){
  85. cc.resources.load('icon/role_head/txk/'+roleFrame.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  86. if(err){
  87. cc.error(err);
  88. }else{
  89. this.mFrame.spriteFrame = spriteFrame;
  90. }
  91. } );
  92. }
  93. }
  94. public flush(main:Main){
  95. this.loadIcon(null)
  96. this.flushLock(main)
  97. }
  98. public flushLock(main:Main){
  99. let roleIcon = main.player.roleIcon
  100. if(roleIcon.open.indexOf(this.roleIcon.id) < 0){
  101. this.mLock.active = true
  102. }else{
  103. this.mLock.active = false
  104. }
  105. }
  106. public setCheck(bool){
  107. if(this.mCheck){
  108. this.mCheck.active = bool
  109. }
  110. }
  111. }