FControl.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import CMath from "../../util/CMath";
  2. import CUtil from "../../util/CUtil";
  3. import { __SkillData } from "../data/sdata/SManage";
  4. import BObject from "./bullet/BObject";
  5. import EventButton from "./EventButton";
  6. import FF from "./FF";
  7. import { SpriteActionType, SpriteType } from "./object/FSprite";
  8. const { ccclass, property } = cc._decorator;
  9. /**
  10. * 控制按钮处理
  11. * 技能,事件,攻击按钮
  12. */
  13. @ccclass
  14. export default class FControl extends cc.Component {
  15. @property(FF)
  16. ff: FF = null;
  17. @property(EventButton)
  18. mEventButton: EventButton = null;//事件按钮
  19. @property(cc.Node)
  20. mShooting: cc.Node = null;//射击按钮
  21. @property(cc.Button)
  22. mBtSkill1: cc.Button = null;//技能1
  23. @property(cc.Label)
  24. mBtLabel1: cc.Label = null;//技能1倒计时
  25. @property(cc.Button)
  26. mBtSkill2: cc.Button = null;//技能2
  27. @property(cc.Label)
  28. mBtLabel2: cc.Label = null;//技能2倒计时
  29. @property(cc.Node)
  30. mBtSkillEffect: cc.Node = null;//技能2特效
  31. @property(cc.Sprite)
  32. mSkillIcon: cc.Sprite = null;//技能图标
  33. private _skillData1: __SkillData
  34. /**
  35. * 技能是否准备好
  36. */
  37. private skillOK1: boolean = true
  38. private lastTime1: number = 0;
  39. private skillOK2: boolean = true
  40. private lastTime2: number = 0;
  41. onLoad() {
  42. this.mEventButton.node.active = false;
  43. this.mShooting.on(cc.Node.EventType.TOUCH_START, this._touchShootStartEvent, this);
  44. this.mShooting.on(cc.Node.EventType.TOUCH_END, this._touchShootEndEvent, this);
  45. this.mShooting.on(cc.Node.EventType.TOUCH_CANCEL, this._touchShootEndEvent, this);
  46. }
  47. public updateSkill() {
  48. let attrData = this.ff.mainSprite.attrData
  49. this._skillData1 = this.ff.main.sManage.getSkillById(attrData.weaponSkill)
  50. if(this._skillData1){
  51. cc.resources.load('icon/skill/'+this._skillData1.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  52. if(err){
  53. cc.error(err);
  54. }else{
  55. this.mSkillIcon.spriteFrame = spriteFrame;
  56. }
  57. } );
  58. }
  59. this.mBtSkill1.node.active = true;
  60. let role = this.ff.main.player.role
  61. if(role.openSkill){
  62. this.mBtSkill2.node.active = false;
  63. }else{
  64. this.mBtSkill2.node.active = false;
  65. }
  66. }
  67. /**
  68. * 显示技能2
  69. */
  70. public showSkill2(){
  71. // this.mBtSkill2.node.active = true;
  72. // this.mBtSkillEffect.active = true;
  73. // cc.tween(this.mBtSkillEffect).sequence(
  74. // cc.delayTime(2),
  75. // cc.destroySelf()
  76. // ).start()
  77. }
  78. /**
  79. * 设置事件按钮
  80. * @param spriteFrame
  81. */
  82. public showEventBt(spriteFrame: cc.SpriteFrame, callback: () => void) {
  83. this.ff.mainSprite.setShooting(false);
  84. this.ff.mainSprite.status == SpriteType.NONE
  85. this.mEventButton.node.active = true
  86. this.mEventButton.mIcon.spriteFrame = spriteFrame
  87. this.mShooting.active = false
  88. this.mEventButton.setCallback(() => {
  89. callback()
  90. })
  91. }
  92. public closeEventBt() {
  93. this.mEventButton.node.active = false
  94. this.mShooting.active = true
  95. this.mEventButton.setCallback(null)
  96. }
  97. private _touchRunningStartEvent() {
  98. if (this.ff && this.ff.mainSprite) {
  99. this.ff.mainSprite.setRuning(true);
  100. }
  101. }
  102. private _touchRunningEndEvent() {
  103. if (this.ff && this.ff.mainSprite) {
  104. this.ff.mainSprite.setRuning(false);
  105. }
  106. }
  107. private _touchShootStartEvent() {
  108. if (this.ff && this.ff.mainSprite) {
  109. this.ff.mainSprite.setShooting(true);
  110. }
  111. }
  112. private _touchShootEndEvent() {
  113. if (this.ff && this.ff.mainSprite) {
  114. this.ff.mainSprite.setShooting(false);
  115. }
  116. }
  117. public onclickSkill1() {
  118. if (!this.skillOK1) {
  119. return
  120. }
  121. this.skillOK1 = false
  122. this.lastTime1 = CUtil.getNowTime()
  123. this.mBtSkill1.interactable = false
  124. this.mBtLabel1.node.active = true
  125. let target = this.ff.mainSprite.findEnemy(3000).sprite
  126. this.ff.mainSprite.skill1.exe(target,()=>{
  127. })
  128. }
  129. public onclickSkill2() {
  130. if (!this.skillOK2) {
  131. return
  132. }
  133. this.skillOK2 = false
  134. this.lastTime2 = CUtil.getNowTime()
  135. this.mBtSkill2.interactable = false
  136. this.mBtLabel2.node.active = true
  137. let target = this.ff.mainSprite.findEnemy(3000).sprite
  138. this.ff.mainSprite.skill1.exe(target,()=>{
  139. })
  140. }
  141. update(dt) {
  142. if (this._skillData1 && !this.skillOK1) {
  143. let curTime = CUtil.getNowTime()
  144. let x = curTime - this.lastTime1
  145. if (x >= this._skillData1.time) {
  146. this.skillOK1 = true
  147. this.mBtSkill1.interactable = true
  148. this.mBtLabel1.node.active = false
  149. } else {
  150. this.mBtLabel1.string = '' + (this._skillData1.time - x)
  151. }
  152. }
  153. if (this._skillData1 && !this.skillOK2) {
  154. let curTime = CUtil.getNowTime()
  155. let x = curTime - this.lastTime2
  156. if (x >= this._skillData1.time) {
  157. this.skillOK2 = true
  158. this.mBtSkill2.interactable = true
  159. this.mBtLabel2.node.active = false
  160. } else {
  161. this.mBtLabel2.string = '' + (this._skillData1.time - x)
  162. }
  163. }
  164. }
  165. }