Blame view

ios/Runner/Wowgame/Classes/game_animal/AniPlainLabel.cpp 5.09 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  //
  //  AniPlainLabel.cpp
  //  WattsenglishToyApp-mobile
  //
  //  Created by Katarzyna Kalinowska-Górska on 19/11/2019.
  //
  
  #include <stdio.h>
  #include "AniPlainLabel.h"
  #include "AniScalingUtils.h"
  #include "AniJSONParseUtils.h"
  
  AniPlainLabel* AniPlainLabel::create(const std::string& text, const std::string fontPath, int fontBaseSize)
  {
      AniPlainLabel * label = new (std::nothrow) AniPlainLabel();
      if(label && label->init(text, fontPath, fontBaseSize))
      {
          label->autorelease();
          return label;
      }
      CC_SAFE_DELETE(label);
      return nullptr;
  }
  
  bool AniPlainLabel::init(const std::string& text, const std::string fontPath, int fontBaseSize){
      if(!cocos2d::Label::initWithTTF(text, "fonts/ComicSansMSBold.ttf", fontBaseSize*AniScalingUtils::getScaleForFont())){ //120
          return false;
      }
      return true;
  }
  
  void AniPlainLabel::loadPropertiesFromJSON(const rapidjson::Value& jsonValue, AniLayoutViewInterface* scene, const std::string resFolder, const std::string altResFolder)
  {
      this->loadCommonPropertiesFromJSON(jsonValue);
      if(AniJSONParseUtils::hasMemberColor3B(jsonValue, "colour")){
          setColor(AniJSONParseUtils::getColor3B(jsonValue["colour"]));
      }
  }
  
  void AniPlainLabel::prepareSize(const rapidjson::Value& jsonValue, float& width, float& height)
  {
      width = this->getBoundingBox().size.width;
      height = this->getBoundingBox().size.height;
  //    width = this->getContentSize().width;
  //    height = this->getContentSize().height;
  }
  
  void AniPlainLabel::setProperty(std::string propertyName, const rapidjson::Value& newValue, ActionParseDelegate* parseDelegate)
  {
      if(propertyName == "opacity"){
          auto value = newValue.GetInt();
          this->setOpacity(value);
      }
  }
  
  void AniPlainLabel::callFunctionByName(std::string methodName, const rapidjson::Value* arguments, ActionParseDelegate* parseDelegate, std::function<void()> callback)
  {
      AniLayoutObject::callFunctionByName(methodName, arguments, parseDelegate);
  //    auto scale = 1/cocos2d::Director::getInstance()->getContentScaleFactor();
      
  //    if(methodName == "setVisible"){
  //        if((*arguments).IsArray()){
  //            this->setVisible((*arguments).GetArray()[0].GetBool());
  //        }
  //    }
  //    else if(methodName == "setFlippedX"){
  //        if((*arguments).IsArray()){
  //            this->setFlippedX((*arguments).GetArray()[0].GetBool());
  //        }
  //    }
  //    else if(methodName == "setFlippedY"){
  //        if((*arguments).IsArray()){
  //            this->setFlippedY((*arguments).GetArray()[0].GetBool());
  //        }
  //    }
  //    else if (methodName == "setScale"){
  //        if((*arguments).IsArray()){
  //            this->setScale((*arguments).GetArray()[0].GetFloat(), (*arguments).GetArray()[0].GetFloat());
  //        }
  //    }
  //    else if(methodName == "setOpacity"){
  //        if((*arguments).IsArray()){
  //            this->setOpacity((*arguments).GetArray()[0].GetInt());
  //        }
  //    }
  //    else if(methodName == "setPositionX"){
  //        if((*arguments).IsArray()){
  //            this->setPositionX((*arguments).GetArray()[0].GetFloat()*scale);
  //        }
  //    }
  //    else if(methodName == "setPositionY"){
  //        if((*arguments).IsArray()){
  //            this->setPositionY((*arguments).GetArray()[0].GetFloat()*scale);
  //        }
  //    }
  //    else if(methodName == "setPosition"){
  //        if((*arguments).IsArray()){
  //            auto point = AniJSONParseUtils::getPoint((*arguments).GetArray()[0]);
  //            AniMathUtils::multiplyPoint(point, scale);
  //            this->setPosition(point);
  //        }
  //    }
  //    else if(methodName == "setTextureRect"){
  //        if((*arguments).IsArray()){
  //            auto newRect = AniJSONParseUtils::getRect((*arguments).GetArray()[0]);
  //            AniMathUtils::multiplyRectPosition(newRect, scale);
  //            this->setTextureRect(newRect);
  //        }
  //    }
  //    else if(methodName == "setContentSize"){
  //        if((*arguments).IsArray()){
  //            this->setContentSize(AniJSONParseUtils::getSize((*arguments).GetArray()[0]));
  //        }
  //    }
  //    else if(methodName == "setRotation"){
  //        if((*arguments).IsArray()){
  //            this->setRotation(((*arguments).GetArray()[0]).GetFloat());
  //        }
  //    }
  //    else if(methodName == "clipSprite"){
  //        if((*arguments).IsArray()){
  //            auto by = AniJSONParseUtils::getPoint((*arguments)[0]);
  //            auto prevTextureRect = this->getTextureRect();
  //            this->setTextureRect(cocos2d::Rect(prevTextureRect.origin.x - by.x, prevTextureRect.origin.y - by.y, prevTextureRect.size.width, prevTextureRect.size.height));
  //        }
  //    }
  //    else if(methodName == "stopAnimations"){
  //        this->stopAllActions();
  //    }
  //    else if(methodName == "setPicture"){
  //        if((*arguments).IsArray()){
  //            std::string imagePath = ((*arguments).GetArray()[0]).GetString();
  //            auto texture = cocos2d::Director::getInstance()->getTextureCache()->addImage(imagePath);
  //            this->setTexture(texture);
  //            this->setTextureRect(cocos2d::Rect(cocos2d::Point::ZERO, texture->getContentSize()));
  //        }
  //    }
  }