TapRoleName.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import i18n from "../../i18n/i18n";
  2. import ViewObject from "../../main/ViewObject";
  3. import { HttpStateType, ReveData } from "../../util/CHttp";
  4. import TapRole from "./TapRole";
  5. /**
  6. * 角色改名
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class TapRoleName extends ViewObject{
  11. @property(cc.Label)
  12. mName: cc.Label = null;
  13. @property(cc.EditBox)
  14. mEditBox: cc.EditBox = null;
  15. @property(cc.Label)
  16. mCount: cc.Label = null;
  17. @property(cc.Node)
  18. mFreeNode: cc.Node = null;//免费
  19. @property(cc.Node)
  20. mGoldNode: cc.Node = null;
  21. @property(cc.Label)
  22. mGoldCount: cc.Label = null;
  23. public tapRole:TapRole = null;
  24. /**
  25. *
  26. * @param prev 父界面
  27. */
  28. public show(prev?:ViewObject){
  29. if(prev){
  30. this.prev = prev;
  31. this.prev.__close();
  32. }
  33. this.main.viewManage.popView1(this.node);
  34. if(this.main && this.main.gameHttp){
  35. this.main.gameHttp.pushEvent(this);
  36. }
  37. }
  38. start () {
  39. let role = this.main.player.role
  40. this.mName.string = role.name
  41. this.mCount.string = i18n.t('第{value}次改名',{value:(role.renameCount+1)})
  42. if(role.renameCount <= 0){
  43. this.mFreeNode.active = true
  44. this.mGoldNode.active = false
  45. }else{
  46. this.mFreeNode.active = false
  47. this.mGoldNode.active = true
  48. }
  49. }
  50. public onclickRename(){
  51. let msg = {
  52. name:this.mEditBox.string
  53. }
  54. this.main.gameHttp.sendJson('set/v1/name',msg,(state,reve:ReveData)=>{
  55. this.main.stopLoad();
  56. if(state == HttpStateType.SUCCESS){
  57. if(reve.retCode == 0){
  58. this.main.player.role.name = this.mEditBox.string
  59. this.exitDistroy()
  60. this.main.showTips('改名成功');
  61. this.tapRole.flush()
  62. }else{
  63. this.main.showTips(reve.message);
  64. }
  65. }else{
  66. this.main.showTips('网络异常');
  67. }
  68. });
  69. }
  70. }