IconInfoView.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import i18n from "../../../i18n/i18n";
  2. import ViewObject from "../../../main/ViewObject";
  3. import { HttpStateType, ReveData } from "../../../util/CHttp";
  4. import FFCalAttr from "../../data/FFCalAttr";
  5. import { __RoleIcon } from "../../data/sdata/SManage";
  6. import RoleIconItem from "./RoleIconItem";
  7. import RoleFrameView from "./RoleFrameView";
  8. import RoleIconView from "./RoleIconView";
  9. import Mail from "../../mail/Mail";
  10. import Main from "../../../main/Main";
  11. /**
  12. * 头像详情查看
  13. */
  14. const {ccclass, property} = cc._decorator;
  15. @ccclass
  16. export default class IconInfoView extends cc.Component {
  17. @property(RoleIconItem)
  18. mRoleIcon: RoleIconItem = null;
  19. @property(cc.Label)
  20. mZdl: cc.Label = null;
  21. @property(cc.Label)
  22. mAtk: cc.Label = null;
  23. @property(cc.Label)
  24. mDef: cc.Label = null;
  25. @property(cc.Label)
  26. mHp: cc.Label = null;
  27. @property(cc.Label)
  28. mSp: cc.Label = null;
  29. @property(cc.Sprite)
  30. mButtonIcon: cc.Sprite = null;
  31. @property(cc.Label)
  32. mButtonLabel: cc.Label = null;
  33. @property([cc.SpriteFrame])
  34. mButtonIconFrame: Array<cc.SpriteFrame> = [];
  35. public roleIconView:RoleIconView = null
  36. public roleFrameView:RoleFrameView = null
  37. private fip:RoleIconItem = null
  38. public openType = 0;//1:头像,2:框
  39. public main:Main
  40. public init(main:Main,fip:RoleIconItem){
  41. this.main = main
  42. this.fip = fip
  43. let roleIcon = fip.roleIcon
  44. this.mRoleIcon.roleIcon = roleIcon
  45. this.mAtk.string = ''+roleIcon.atk
  46. this.mDef.string = ''+roleIcon.def
  47. this.mHp.string = ''+roleIcon.hp
  48. this.mSp.string = ''+roleIcon.sp
  49. let zdl = FFCalAttr.getZdl(roleIcon)
  50. this.mZdl.string = ''+zdl
  51. this.mRoleIcon.loadIcon(this.main)
  52. this.flushButton()
  53. }
  54. public initFrame(main:Main,fip:RoleIconItem){
  55. this.main = main
  56. this.fip = fip
  57. let roleIcon = fip.roleIcon
  58. this.mRoleIcon.roleIcon = roleIcon
  59. this.mAtk.string = ''+roleIcon.atk
  60. this.mDef.string = ''+roleIcon.def
  61. this.mHp.string = ''+roleIcon.hp
  62. this.mSp.string = ''+roleIcon.sp
  63. let zdl = FFCalAttr.getZdl(roleIcon)
  64. this.mZdl.string = ''+zdl
  65. this.mRoleIcon.loadFrame(this.main)
  66. this.flushButton()
  67. }
  68. private flushButton(){
  69. let status = this.getStatus()
  70. if(status == 0){//还未获得
  71. this.mButtonIcon.spriteFrame = this.mButtonIconFrame[2]
  72. this.mButtonLabel.string = i18n.t('未获得')
  73. }else if(status == 1){//已经激活
  74. this.mButtonIcon.spriteFrame = this.mButtonIconFrame[0]
  75. this.mButtonLabel.string = i18n.t('使用')
  76. }else if(status == 2){//未激活
  77. this.mButtonIcon.spriteFrame = this.mButtonIconFrame[1]
  78. this.mButtonLabel.string = i18n.t('激活')
  79. }
  80. }
  81. private getStatus():number{
  82. let roleIcon = this.fip.roleIcon
  83. let roleIcons = this.main.player.roleIcon
  84. if(roleIcons.open.indexOf(roleIcon.id) >= 0){
  85. return 1
  86. }if(roleIcons.data.indexOf(roleIcon.id) >= 0){
  87. return 2
  88. }
  89. return 0;
  90. }
  91. public onclick(){
  92. let status = this.getStatus()
  93. if(status == 1){
  94. this.roleIconUser()
  95. }else if(status == 2){
  96. this.roleIconActive()
  97. }
  98. }
  99. /**
  100. * 激活
  101. */
  102. private roleIconActive(){
  103. let roleIcon = this.fip.roleIcon
  104. let msg = {
  105. id:roleIcon.id,
  106. }
  107. this.main.gameHttp.sendJson('set/v1/activeIcon',msg,(state,reve:ReveData)=>{
  108. this.main.stopLoad();
  109. if(state == HttpStateType.SUCCESS){
  110. if(reve.retCode == 0){
  111. this.main.player.roleIcon.open.push(roleIcon.id)
  112. this.flushButton()
  113. this.fip.flush(this.main)
  114. if(this.roleIconView){
  115. this.roleIconView.flush(this.fip)
  116. }
  117. if(this.roleFrameView){
  118. this.roleFrameView.flush(this.fip)
  119. }
  120. this.main.showTips('激活成功');
  121. }else{
  122. this.main.showTips(reve.message);
  123. }
  124. }else{
  125. this.main.showTips('网络异常');
  126. }
  127. });
  128. }
  129. /**
  130. * 使用
  131. */
  132. private roleIconUser(){
  133. let roleIcon = this.fip.roleIcon
  134. let msg = {
  135. type:this.openType,
  136. id:roleIcon.id,
  137. }
  138. this.main.gameHttp.sendJson('set/v1/useIcon',msg,(state,reve:ReveData)=>{
  139. this.main.stopLoad();
  140. if(state == HttpStateType.SUCCESS){
  141. if(reve.retCode == 0){
  142. if(this.openType == 1){
  143. this.main.player.role.icon = roleIcon.id
  144. }else{
  145. this.main.player.role.frame = roleIcon.id
  146. }
  147. this.flushButton()
  148. this.fip.flush(this.main)
  149. if(this.roleIconView){
  150. this.roleIconView.flush(this.fip)
  151. }
  152. if(this.roleFrameView){
  153. this.roleFrameView.flush(this.fip)
  154. }
  155. this.main.showTips('使用成功');
  156. this.main.home.flush()
  157. }else{
  158. this.main.showTips(reve.message);
  159. }
  160. }else{
  161. this.main.showTips('网络异常');
  162. }
  163. });
  164. }
  165. }