TitleInfoView.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import i18n from "../../../i18n/i18n";
  2. import Main from "../../../main/Main";
  3. import ViewObject from "../../../main/ViewObject";
  4. import { HttpStateType, ReveData } from "../../../util/CHttp";
  5. import FFCalAttr from "../../data/FFCalAttr";
  6. import { __RoleIcon } from "../../data/sdata/SManage";
  7. import RoleFrameView from "./RoleFrameView";
  8. import RoleIconView from "./RoleIconView";
  9. import RoleTitleItem from "./RoleTitleItem";
  10. import RoleTitleView from "./RoleTitleView";
  11. /**
  12. * 称号详情查看
  13. */
  14. const {ccclass, property} = cc._decorator;
  15. @ccclass
  16. export default class TitleInfoView extends cc.Component{
  17. @property(RoleTitleItem)
  18. mRoleIcon: RoleTitleItem = 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 roleTitleView:RoleTitleView = null
  36. private fip:RoleTitleItem = null
  37. public main:Main
  38. public init(main:Main,fip:RoleTitleItem){
  39. this.main = main
  40. this.fip = fip
  41. let roleIcon = fip.roleIcon
  42. this.mRoleIcon.roleIcon = roleIcon
  43. this.mRoleIcon.init()
  44. this.mAtk.string = ''+roleIcon.atk
  45. this.mDef.string = ''+roleIcon.def
  46. this.mHp.string = ''+roleIcon.hp
  47. this.mSp.string = ''+roleIcon.sp
  48. let zdl = FFCalAttr.getZdl(roleIcon)
  49. this.mZdl.string = ''+zdl
  50. this.flushButton()
  51. }
  52. public initFrame(main:Main,fip:RoleTitleItem){
  53. this.main = main
  54. this.fip = fip
  55. let roleIcon = fip.roleIcon
  56. this.mRoleIcon.roleIcon = roleIcon
  57. this.mAtk.string = ''+roleIcon.atk
  58. this.mDef.string = ''+roleIcon.def
  59. this.mHp.string = ''+roleIcon.hp
  60. this.mSp.string = ''+roleIcon.sp
  61. let zdl = FFCalAttr.getZdl(roleIcon)
  62. this.mZdl.string = ''+zdl
  63. this.flushButton()
  64. }
  65. private flushButton(){
  66. let status = this.getStatus()
  67. if(status == 0){//还未获得
  68. this.mButtonIcon.spriteFrame = this.mButtonIconFrame[2]
  69. this.mButtonLabel.string = i18n.t('未获得')
  70. }else if(status == 1){//已经使用
  71. this.mButtonIcon.spriteFrame = this.mButtonIconFrame[0]
  72. this.mButtonLabel.string = i18n.t('卸下')
  73. }else if(status == 2){//获得未使用
  74. this.mButtonIcon.spriteFrame = this.mButtonIconFrame[1]
  75. this.mButtonLabel.string = i18n.t('使用')
  76. }
  77. }
  78. private getStatus():number{
  79. let roleIcon = this.fip.roleIcon
  80. let roleIcons = this.main.player.roleIcon
  81. if(roleIcons.open.indexOf(roleIcon.id) >= 0){
  82. return 1
  83. }if(roleIcons.data.indexOf(roleIcon.id) >= 0){
  84. return 2
  85. }
  86. return 0;
  87. }
  88. public onclick(){
  89. let status = this.getStatus()
  90. if(status == 1){
  91. this.roleIconRemove();
  92. }else if(status == 2){
  93. this.roleIconActive()
  94. }
  95. }
  96. /**
  97. * 激活
  98. */
  99. private roleIconActive(){
  100. let roleIcon = this.fip.roleIcon
  101. let msg = {
  102. id:roleIcon.id,
  103. }
  104. this.main.gameHttp.sendJson('set/v1/activeIcon',msg,(state,reve:ReveData)=>{
  105. this.main.stopLoad();
  106. if(state == HttpStateType.SUCCESS){
  107. if(reve.retCode == 0){
  108. this.main.player.roleIcon.open.push(roleIcon.id)
  109. this.main.showTips('使用成功');
  110. this.flushButton()
  111. }else{
  112. this.main.showTips(reve.message);
  113. }
  114. }else{
  115. this.main.showTips('网络异常');
  116. }
  117. });
  118. }
  119. /**
  120. * 移除
  121. */
  122. private roleIconRemove(){
  123. let roleIcon = this.fip.roleIcon
  124. let msg = {
  125. id:roleIcon.id,
  126. }
  127. this.main.gameHttp.sendJson('set/v1/removeTitle',msg,(state,reve:ReveData)=>{
  128. this.main.stopLoad();
  129. if(state == HttpStateType.SUCCESS){
  130. if(reve.retCode == 0){
  131. let open = this.main.player.roleIcon.open
  132. for (let i = 0; i < open.length; i++) {
  133. const id = open[i];
  134. if(id == roleIcon.id){
  135. open.splice(i,1)
  136. break
  137. }
  138. }
  139. this.flushButton()
  140. this.main.showTips('卸下成功');
  141. }else{
  142. this.main.showTips(reve.message);
  143. }
  144. }else{
  145. this.main.showTips('网络异常');
  146. }
  147. });
  148. }
  149. }