FControl.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 _touchShootStartEvent() {
  98. if (this.ff && this.ff.mainSprite) {
  99. this.ff.mainSprite.setShooting(true);
  100. }
  101. }
  102. private _touchShootEndEvent() {
  103. if (this.ff && this.ff.mainSprite) {
  104. this.ff.mainSprite.setShooting(false);
  105. }
  106. }
  107. /**
  108. * 注册长按事件按钮
  109. * @param spriteFrame 事件按钮图标
  110. * @param startCallback 事件按钮按下
  111. * @param endCallback 事件按钮取消
  112. */
  113. public showEventBtTouch(spriteFrame: cc.SpriteFrame,startCallback:()=>void,endCallback:()=>void){
  114. this.ff.mainSprite.setShooting(false);
  115. this.ff.mainSprite.status == SpriteType.NONE
  116. this.mEventButton.node.active = true
  117. this.mEventButton.mIcon.spriteFrame = spriteFrame
  118. this.mShooting.active = false
  119. this.mEventButton.onTouchEvent(startCallback,endCallback)
  120. }
  121. /**
  122. * 取消注册事件长按
  123. */
  124. public closeEventBtTouch(){
  125. this.mEventButton.node.active = false
  126. this.mShooting.active = true
  127. this.mEventButton.offTouchEvent()
  128. }
  129. public onclickSkill1() {
  130. if (!this.skillOK1) {
  131. return
  132. }
  133. this.skillOK1 = false
  134. this.lastTime1 = CUtil.getNowTime()
  135. this.mBtSkill1.interactable = false
  136. this.mBtLabel1.node.active = true
  137. let target = this.ff.mainSprite.findEnemy(3000).sprite
  138. this.ff.mainSprite.skill1.exe(target,()=>{
  139. })
  140. }
  141. public onclickSkill2() {
  142. if (!this.skillOK2) {
  143. return
  144. }
  145. this.skillOK2 = false
  146. this.lastTime2 = CUtil.getNowTime()
  147. this.mBtSkill2.interactable = false
  148. this.mBtLabel2.node.active = true
  149. let target = this.ff.mainSprite.findEnemy(3000).sprite
  150. this.ff.mainSprite.skill1.exe(target,()=>{
  151. })
  152. }
  153. update(dt) {
  154. if (this._skillData1 && !this.skillOK1) {
  155. let curTime = CUtil.getNowTime()
  156. let x = curTime - this.lastTime1
  157. if (x >= this._skillData1.time) {
  158. this.skillOK1 = true
  159. this.mBtSkill1.interactable = true
  160. this.mBtLabel1.node.active = false
  161. } else {
  162. this.mBtLabel1.string = '' + (this._skillData1.time - x)
  163. }
  164. }
  165. if (this._skillData1 && !this.skillOK2) {
  166. let curTime = CUtil.getNowTime()
  167. let x = curTime - this.lastTime2
  168. if (x >= this._skillData1.time) {
  169. this.skillOK2 = true
  170. this.mBtSkill2.interactable = true
  171. this.mBtLabel2.node.active = false
  172. } else {
  173. this.mBtLabel2.string = '' + (this._skillData1.time - x)
  174. }
  175. }
  176. }
  177. }