YZ_ShortcutWidget.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { utils } from "./Utils";
  2. import CompatibleTool from "./CompatibleTool";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class YZ_ShortcutWidget extends cc.Component {
  6. _panel: cc.Node = null;
  7. _handImg: cc.Node = null;
  8. _callback: Function = null;
  9. public set Callback(value: Function) {
  10. this._callback = value;
  11. }
  12. onLoad() {
  13. this._panel = this.node.getChildByName("Panel");
  14. this._panel.active = false;
  15. this._handImg = cc.find("Panel/handImg", this.node);
  16. this._handImg.runAction(cc.repeatForever(cc.sequence(cc.moveBy(0.5, CompatibleTool.position(0, -50)), cc.moveBy(0.5, CompatibleTool.position(0, 50)))));
  17. }
  18. onEnable() {
  19. utils.registerServerInitEvent(() => {
  20. if (!utils.isShowCreateShortcutWidget()) {
  21. this.node.destroy();
  22. } else {
  23. this._panel.active = true;
  24. }
  25. }, this);
  26. }
  27. onDisable() {
  28. utils.unregisterServerInitEvent(this);
  29. }
  30. onBtnClickHandler(event: any, data: any) {
  31. switch (event.target.name) {
  32. case "Btn_Shortcut": {
  33. if (utils.canCreateShortcut()) {
  34. utils.createShortcut((ret) => {
  35. if (ret) {
  36. utils.showLog("快捷方式创建成功!");
  37. if (this._callback) {
  38. this._callback(true);
  39. }
  40. } else {
  41. utils.showLog("快捷方式创建失败!");
  42. if (this._callback) {
  43. this._callback(false);
  44. }
  45. }
  46. });
  47. }
  48. break;
  49. }
  50. }
  51. }
  52. }