YZ_RecordWidget.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { utils } from "./Utils";
  2. import PlatUtils from "./PlatUtils";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class YZ_RecordWidget extends cc.Component {
  6. _panel: cc.Node = null;
  7. _normalBtn: cc.Node = null;
  8. _actionBtn: cc.Node = null;
  9. _isRecording: boolean = false;
  10. _originScale: number = 1;
  11. onLoad() {
  12. this._panel = this.node.getChildByName("Panel");
  13. this._panel.active = false;
  14. let background: cc.Node = this._panel.getChildByName("Background");
  15. this._normalBtn = background.getChildByName("normalBtn");
  16. this._actionBtn = background.getChildByName("actionBtn");
  17. this._originScale = this._actionBtn.scale;
  18. }
  19. _onGameMessage(event: any) {
  20. switch (event.type) {
  21. case "YZ_RecordStart": {
  22. this._updateState();
  23. break;
  24. }
  25. case "YZ_RecordEnd": {
  26. this._updateState();
  27. break;
  28. }
  29. }
  30. }
  31. onEnable() {
  32. cc.game.on("YZ_CommonMessage", this._onGameMessage, this);
  33. utils.registerServerInitEvent(() => {
  34. this._panel.on(cc.Node.EventType.TOUCH_END, (event: cc.Event) => {
  35. event.stopPropagation();
  36. if (!utils.isRecording) {
  37. utils.recordStart();
  38. } else {
  39. utils.isSuccess = undefined;
  40. if (utils.cur_tool && utils.cur_tool.isClickEnd != undefined) {
  41. utils.cur_tool.isClickEnd = true;
  42. }
  43. utils.recordEnd();
  44. }
  45. }, this);
  46. this._updateState();
  47. if (utils.isShowRecordWidget()) {
  48. this._panel.active = true;
  49. } else {
  50. utils.showLog("不支持录屏!");
  51. this.node.destroy();
  52. }
  53. }, this);
  54. // if (PlatUtils.IsDouyin) {
  55. // utils.showLog("record onEnable");
  56. // utils.Tool_Douyin.isAutoShare = true;
  57. // }
  58. if (utils.cur_tool && utils.cur_tool.isAutoShare != undefined) {
  59. utils.cur_tool.isAutoShare = true;
  60. }
  61. }
  62. onDisable() {
  63. cc.game.targetOff(this);
  64. // utils.isRecording = false;
  65. // this._updateState();
  66. // if (PlatUtils.IsDouyin) {
  67. // utils.showLog("record onDisable");
  68. // // utils.Tool_Douyin.isAutoShare = false;
  69. // }
  70. // utils.recordEnd();
  71. }
  72. _updateState() {
  73. if (utils.isRecording) {
  74. this._normalBtn.active = false;
  75. this._actionBtn.active = true;
  76. this._actionBtn.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.3, this._originScale * 0.8), cc.scaleTo(0.3, this._originScale))));
  77. } else {
  78. this._normalBtn.active = true;
  79. this._actionBtn.stopAllActions();
  80. this._actionBtn.active = false;
  81. }
  82. }
  83. }