2023-09-12 01:06:28 +08:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-18 20:11:59 +08:00
|
|
|
#include <memory>
|
2023-09-12 01:06:28 +08:00
|
|
|
#include "ExtensionMacros.h"
|
|
|
|
#include "base/Config.h"
|
|
|
|
#include <string>
|
2023-10-18 20:11:59 +08:00
|
|
|
#include <unordered_map>
|
2023-10-19 15:31:01 +08:00
|
|
|
#include "EventListenerCustom.h"
|
|
|
|
#include "RefPtr.h"
|
|
|
|
#include "2d/Node.h"
|
2023-09-12 01:06:28 +08:00
|
|
|
|
|
|
|
NS_AX_BEGIN
|
|
|
|
class Node;
|
|
|
|
class Scene;
|
|
|
|
|
|
|
|
NS_AX_END
|
|
|
|
|
|
|
|
NS_AX_EXT_BEGIN
|
|
|
|
|
2023-10-18 20:11:59 +08:00
|
|
|
class InspectPropertyHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~InspectPropertyHandler() = default;
|
|
|
|
virtual bool isSupportedType(Node* node) = 0;
|
|
|
|
virtual void drawProperties(Node* node) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InspectorNodePropertyHandler : public InspectPropertyHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~InspectorNodePropertyHandler() override = default;
|
|
|
|
bool isSupportedType(Node* node) override;
|
|
|
|
void drawProperties(Node* node) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InspectorSpritePropertyHandler : public InspectPropertyHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~InspectorSpritePropertyHandler() override = default;
|
|
|
|
bool isSupportedType(Node* node) override;
|
|
|
|
void drawProperties(Node* node) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InspectorLabelProtocolPropertyHandler : public InspectPropertyHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~InspectorLabelProtocolPropertyHandler() override = default;
|
|
|
|
bool isSupportedType(Node* node) override;
|
|
|
|
void drawProperties(Node* node) override;
|
|
|
|
};
|
|
|
|
|
2023-09-12 01:06:28 +08:00
|
|
|
class Inspector
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static Inspector* getInstance();
|
|
|
|
static void destroyInstance();
|
2023-10-18 20:11:59 +08:00
|
|
|
static std::string getNodeTypeName(Node*);
|
2023-09-12 01:06:28 +08:00
|
|
|
static std::string demangle(const char* mangled);
|
|
|
|
void openForScene(Scene*);
|
2023-10-19 15:31:01 +08:00
|
|
|
void openForCurrentScene();
|
2023-09-12 01:06:28 +08:00
|
|
|
void close();
|
|
|
|
|
2023-10-18 20:11:59 +08:00
|
|
|
bool addPropertyHandler(std::string_view handlerId, std::unique_ptr<InspectPropertyHandler> handler);
|
|
|
|
void removePropertyHandler(const std::string& handlerId);
|
|
|
|
|
2023-10-19 15:31:01 +08:00
|
|
|
void setAutoAddToScenes(bool autoAdd);
|
|
|
|
|
|
|
|
std::string_view getFontPath() { return _fontPath; }
|
|
|
|
void setFontPath(std::string_view fontPath);
|
|
|
|
|
2023-09-12 01:06:28 +08:00
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
void mainLoop();
|
2023-10-18 20:11:59 +08:00
|
|
|
void drawTreeRecursive(Node*, int index = 0);
|
2023-09-12 01:06:28 +08:00
|
|
|
void drawProperties();
|
|
|
|
|
2023-10-19 15:31:01 +08:00
|
|
|
ax::RefPtr<ax::Node> _selected_node = nullptr;
|
2023-09-12 01:06:28 +08:00
|
|
|
ax::Scene* _target = nullptr;
|
2023-10-18 20:11:59 +08:00
|
|
|
|
|
|
|
std::unordered_map<std::string, std::unique_ptr<InspectPropertyHandler>> _propertyHandlers;
|
2023-10-19 15:31:01 +08:00
|
|
|
RefPtr<EventListenerCustom> _beforeNewSceneEventListener;
|
|
|
|
RefPtr<EventListenerCustom> _afterNewSceneEventListener;
|
|
|
|
|
|
|
|
bool _autoAddToScenes = false;
|
|
|
|
std::string _fontPath;
|
2023-09-12 01:06:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_AX_EXT_END
|