CCEventListenerAssetsManagerEx.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __cocos2d_libs__CCEventListenerAssetsManagerEx__
  22. #define __cocos2d_libs__CCEventListenerAssetsManagerEx__
  23. #include "base/CCEventListener.h"
  24. #include "base/CCEventListenerCustom.h"
  25. #include "extensions/ExtensionMacros.h"
  26. #include "extensions/ExtensionExport.h"
  27. NS_CC_EXT_BEGIN
  28. class EventAssetsManagerEx;
  29. class AssetsManagerEx;
  30. /**
  31. * Usage:
  32. * auto dispatcher = Director::getInstance()->getEventDispatcher();
  33. * auto manager = AssetsManagerEx::create(manifestUrl, storagePath);
  34. * Adds a listener:
  35. *
  36. * auto callback = [](EventAssetsManagerEx* event){ do_some_thing(); };
  37. * auto listener = EventListenerAssetsManagerEx::create(manager, callback);
  38. * dispatcher->addEventListenerWithSceneGraphPriority(listener, one_node);
  39. *
  40. * Removes a listener
  41. *
  42. * dispatcher->removeEventListener(listener);
  43. */
  44. class CC_EX_DLL EventListenerAssetsManagerEx : public cocos2d::EventListenerCustom
  45. {
  46. public:
  47. friend class AssetsManagerEx;
  48. /** Creates an event listener with type and callback.
  49. * @param eventType The type of the event.
  50. * @param callback The callback function when the specified event was emitted.
  51. */
  52. static EventListenerAssetsManagerEx* create(AssetsManagerEx *AssetsManagerEx, const std::function<void(EventAssetsManagerEx*)>& callback);
  53. /// Overrides
  54. virtual bool checkAvailable() override;
  55. virtual EventListenerAssetsManagerEx* clone() override;
  56. CC_CONSTRUCTOR_ACCESS:
  57. /** Constructor */
  58. EventListenerAssetsManagerEx();
  59. /** Initializes event with type and callback function */
  60. bool init(const AssetsManagerEx *AssetsManagerEx, const std::function<void(EventAssetsManagerEx*)>& callback);
  61. protected:
  62. static const std::string LISTENER_ID;
  63. std::function<void(EventAssetsManagerEx*)> _onAssetsManagerExEvent;
  64. const AssetsManagerEx *_AssetsManagerEx;
  65. //friend class luaEventListenerAssetsManagerEx;
  66. };
  67. NS_CC_EXT_END
  68. #endif /* defined(__cocos2d_libs__CCEventListenerAssetsManagerEx__) */