LayoutObject.h
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
//  LayoutObject.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 16.05.2017.
//
//
#ifndef LayoutObject_h
#define LayoutObject_h
#include "json/document.h"
#include "ui/CocosGUI.h"
#include "ScenarioObject.h"
#include "JSONParseUtils.h"
class LayoutViewInterface;
class LayoutObject : public ScenarioObject
{
    public:
    
        std::string className;
        std::string objectName;
        cocos2d::Point originalPosition;
    
        virtual ~LayoutObject();
    
        virtual void loadPropertiesFromJSON(const rapidjson::Value& jsonValue, LayoutViewInterface* scene = NULL, const std::string resFolder = "", const std::string altResFolder = "") = 0;
    
        virtual void loadCommonPropertiesFromJSON(const rapidjson::Value& jsonValue, LayoutViewInterface* scene = NULL, const std::string resFolder = "", const std::string altResFolder = "");
    
        virtual void prepareSize(const rapidjson::Value& jsonValue, float& width, float& height);
    
        virtual bool isWidget()
        {
            return false;
        };
    
        // for widgets
    
        virtual void setOnTouchBeganCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback){};
        virtual void setOnTouchEndedCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback){};
        virtual void setOnTouchCancelledCallback(std::function<void(std::string, cocos2d::ui::Widget::TouchEventType)> callback){};
        // ScenarioObject
        virtual std::string getObjectName(){
            return objectName;
        };
    
        virtual std::string getClassName(){
            return className;
        };
    
        virtual std::string getPropertyAsString(std::string propertyName = ""){
            if(propertyName == "objectName"){
                return objectName;
            }
            return "NULL";
        };
    
        virtual void animate(){
            if(_activationAnimation != nullptr){
                animate(_activationAnimation);
            }
        }
    
protected:
    rapidjson::Value* _activationAnimation;
    
    virtual float animate(rapidjson::Value* animationData);
};
#endif /* LayoutObject_h */
