2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "WidgetReader/ScrollViewReader/ScrollViewReader.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "ui/UIScrollView.h"
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/FileUtils.h"
|
|
|
|
#include "2d/SpriteFrameCache.h"
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CocoLoader.h"
|
|
|
|
#include "CSParseBinary_generated.h"
|
|
|
|
#include "FlatBuffersSerialize.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2019-11-23 20:27:39 +08:00
|
|
|
using namespace ui;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
static const char* P_InnerWidth = "innerWidth";
|
|
|
|
static const char* P_InnerHeight = "innerHeight";
|
|
|
|
static const char* P_Direction = "direction";
|
|
|
|
static const char* P_BounceEnable = "bounceEnable";
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static ScrollViewReader* instanceScrollViewReader = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
IMPLEMENT_CLASS_NODE_READER_INFO(ScrollViewReader)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ScrollViewReader::ScrollViewReader() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ScrollViewReader::~ScrollViewReader() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ScrollViewReader* ScrollViewReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceScrollViewReader)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
instanceScrollViewReader = new ScrollViewReader();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return instanceScrollViewReader;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ScrollViewReader::destroyInstance()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SAFE_DELETE(instanceScrollViewReader);
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void ScrollViewReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* cocoNode)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
// TODO: need to refactor...
|
|
|
|
LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ScrollView* scrollView = static_cast<ScrollView*>(widget);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* stChildArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
float innerWidth;
|
|
|
|
float innerHeight;
|
|
|
|
for (int i = 0; i < cocoNode->GetChildNum(); ++i)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string key = stChildArray[i].GetName(cocoLoader);
|
|
|
|
std::string value = stChildArray[i].GetValue(cocoLoader);
|
|
|
|
if (key == P_InnerWidth)
|
|
|
|
{
|
|
|
|
innerWidth = valueToFloat(value);
|
|
|
|
}
|
|
|
|
else if (key == P_InnerHeight)
|
|
|
|
{
|
|
|
|
innerHeight = valueToFloat(value);
|
|
|
|
}
|
|
|
|
else if (key == P_Direction)
|
|
|
|
{
|
|
|
|
scrollView->setDirection((ScrollView::Direction)valueToInt(value));
|
|
|
|
}
|
|
|
|
else if (key == P_BounceEnable)
|
|
|
|
{
|
|
|
|
scrollView->setBounceEnabled(valueToBool(value));
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // end of for loop
|
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ScrollViewReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options)
|
|
|
|
{
|
|
|
|
LayoutReader::setPropsFromJsonDictionary(widget, options);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ScrollView* scrollView = static_cast<ScrollView*>(widget);
|
|
|
|
float innerWidth = DICTOOL->getFloatValue_json(options, P_InnerWidth, 200);
|
|
|
|
float innerHeight = DICTOOL->getFloatValue_json(options, P_InnerHeight, 200);
|
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
int direction = DICTOOL->getFloatValue_json(options, P_Direction, 1);
|
|
|
|
scrollView->setDirection((ScrollView::Direction)direction);
|
|
|
|
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, P_BounceEnable));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
LayoutReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Offset<Table> ScrollViewReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
|
|
|
flatbuffers::FlatBufferBuilder* builder)
|
|
|
|
{
|
|
|
|
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
|
|
|
auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
std::string plistFile;
|
|
|
|
int resourceType = 0;
|
|
|
|
|
|
|
|
bool clipEnabled = false;
|
|
|
|
Color3B bgColor;
|
|
|
|
Color3B bgStartColor;
|
|
|
|
Color3B bgEndColor;
|
|
|
|
int colorType = 0;
|
|
|
|
uint8_t bgColorOpacity = 255;
|
|
|
|
Vec2 colorVector(0.0f, -0.5f);
|
|
|
|
Rect capInsets;
|
|
|
|
Size scale9Size;
|
|
|
|
bool backGroundScale9Enabled = false;
|
|
|
|
Size innerSize(200, 300);
|
|
|
|
int direction = 0;
|
|
|
|
bool bounceEnabled = false;
|
|
|
|
bool scrollbarEnabled = true;
|
|
|
|
bool scrollbarAutoHide = true;
|
|
|
|
float scrollbarAutoHideTime = 0.2f;
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
auto attribute = objectData.first_attribute();
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view name = attribute.name();
|
|
|
|
std::string_view value = attribute.value();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "ClipAble")
|
|
|
|
{
|
|
|
|
clipEnabled = FLATSTR_TO_BOOL(value);
|
|
|
|
}
|
|
|
|
else if (name == "ComboBoxIndex")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
colorType = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "BackColorAlpha")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgColorOpacity = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "Scale9Enable")
|
|
|
|
{
|
|
|
|
backGroundScale9Enabled = FLATSTR_TO_BOOL(value);
|
|
|
|
}
|
|
|
|
else if (name == "Scale9OriginX")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
capInsets.origin.x = atof(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "Scale9OriginY")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
capInsets.origin.y = atof(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "Scale9Width")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
capInsets.size.width = atof(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "Scale9Height")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
capInsets.size.height = atof(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "ScrollDirectionType")
|
|
|
|
{
|
|
|
|
if (value == "Vertical")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
direction = 1;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (value == "Horizontal")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
direction = 2;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (value == "Vertical_Horizontal")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
direction = 3;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "IsBounceEnabled")
|
|
|
|
{
|
|
|
|
bounceEnabled = FLATSTR_TO_BOOL(value);
|
|
|
|
}
|
|
|
|
else if (name.compare("BarEnabled") == 0)
|
|
|
|
{
|
|
|
|
scrollbarEnabled = FLATSTR_TO_BOOL(value);
|
|
|
|
}
|
|
|
|
else if (name.compare("BarAutoHide") == 0)
|
|
|
|
{
|
|
|
|
scrollbarAutoHide = FLATSTR_TO_BOOL(value);
|
|
|
|
}
|
|
|
|
else if (name.compare("BarAutoHideTime") == 0)
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
scrollbarAutoHideTime = atof(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
attribute = attribute.next_attribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
// child elements
|
|
|
|
auto child = objectData.first_child();
|
|
|
|
while (child)
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view name = child.name();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "InnerNodeSize")
|
|
|
|
{
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "Width")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
innerSize.width = atof(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Height")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
innerSize.height = atof(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Size" && backGroundScale9Enabled)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
attribute = child.first_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "X")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
scale9Size.width = atof(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Y")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
scale9Size.height = atof(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "SingleColor")
|
|
|
|
{
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "R")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgColor.r = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "G")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgColor.g = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "B")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgColor.b = atoi(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "EndColor")
|
|
|
|
{
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "R")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgEndColor.r = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "G")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgEndColor.g = atoi(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "B")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgEndColor.b = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "FirstColor")
|
|
|
|
{
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "R")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgStartColor.r = atoi(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "G")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgStartColor.g = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "B")
|
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
bgStartColor.b = atoi(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "ColorVector")
|
|
|
|
{
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "ScaleX")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
colorVector.x = atof(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "ScaleY")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
colorVector.y = atof(value.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
attribute = attribute.next_attribute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "FileData")
|
|
|
|
{
|
|
|
|
std::string texture;
|
|
|
|
std::string texturePng;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
attribute = child.first_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (name == "Path")
|
|
|
|
{
|
|
|
|
path = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Type")
|
|
|
|
{
|
|
|
|
resourceType = getResourceType(value);
|
|
|
|
}
|
|
|
|
else if (name == "Plist")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
plistFile = value;
|
|
|
|
texture = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (resourceType == 1)
|
|
|
|
{
|
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2022-08-09 09:54:53 +08:00
|
|
|
fbs->_textures.emplace_back(builder->CreateString(texture));
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
child = child.next_sibling();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Color f_bgColor(255, bgColor.r, bgColor.g, bgColor.b);
|
|
|
|
Color f_bgStartColor(255, bgStartColor.r, bgStartColor.g, bgStartColor.b);
|
|
|
|
Color f_bgEndColor(255, bgEndColor.r, bgEndColor.g, bgEndColor.b);
|
|
|
|
ColorVector f_colorVector(colorVector.x, colorVector.y);
|
|
|
|
CapInsets f_capInsets(capInsets.origin.x, capInsets.origin.y, capInsets.size.width, capInsets.size.height);
|
|
|
|
FlatSize f_scale9Size(scale9Size.width, scale9Size.height);
|
|
|
|
FlatSize f_innerSize(innerSize.width, innerSize.height);
|
|
|
|
|
|
|
|
auto options = CreateScrollViewOptions(
|
|
|
|
*builder, widgetOptions,
|
|
|
|
CreateResourceData(*builder, builder->CreateString(path), builder->CreateString(plistFile), resourceType),
|
|
|
|
clipEnabled, &f_bgColor, &f_bgStartColor, &f_bgEndColor, colorType, bgColorOpacity, &f_colorVector,
|
|
|
|
&f_capInsets, &f_scale9Size, backGroundScale9Enabled, &f_innerSize, direction, bounceEnabled, scrollbarEnabled,
|
|
|
|
scrollbarAutoHide, scrollbarAutoHideTime);
|
|
|
|
|
|
|
|
return *(Offset<Table>*)(&options);
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void ScrollViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* scrollViewOptions)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
ScrollView* scrollView = static_cast<ScrollView*>(node);
|
|
|
|
auto options = (ScrollViewOptions*)scrollViewOptions;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool clipEnabled = options->clipEnabled() != 0;
|
|
|
|
scrollView->setClippingEnabled(clipEnabled);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool backGroundScale9Enabled = options->backGroundScale9Enabled() != 0;
|
|
|
|
scrollView->setBackGroundImageScale9Enabled(backGroundScale9Enabled);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto f_bgColor = options->bgColor();
|
|
|
|
Color3B bgColor(f_bgColor->r(), f_bgColor->g(), f_bgColor->b());
|
|
|
|
auto f_bgStartColor = options->bgStartColor();
|
|
|
|
Color3B bgStartColor(f_bgStartColor->r(), f_bgStartColor->g(), f_bgStartColor->b());
|
|
|
|
auto f_bgEndColor = options->bgEndColor();
|
|
|
|
Color3B bgEndColor(f_bgEndColor->r(), f_bgEndColor->g(), f_bgEndColor->b());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto f_colorVecor = options->colorVector();
|
|
|
|
Vec2 colorVector(f_colorVecor->vectorX(), f_colorVecor->vectorY());
|
|
|
|
scrollView->setBackGroundColorVector(colorVector);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int bgColorOpacity = options->bgColorOpacity();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int colorType = options->colorType();
|
|
|
|
scrollView->setBackGroundColorType(Layout::BackGroundColorType(colorType));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
scrollView->setBackGroundColor(bgStartColor, bgEndColor);
|
|
|
|
scrollView->setBackGroundColor(bgColor);
|
|
|
|
scrollView->setBackGroundColorOpacity(bgColorOpacity);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool fileExist = false;
|
|
|
|
std::string errorFilePath;
|
|
|
|
auto imageFileNameDic = (options->backGroundImageData());
|
|
|
|
int imageFileNameType = imageFileNameDic->resourceType();
|
|
|
|
std::string imageFileName = imageFileNameDic->path()->c_str();
|
|
|
|
if (imageFileName != "")
|
|
|
|
{
|
|
|
|
switch (imageFileNameType)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(imageFileName))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
fileExist = true;
|
|
|
|
}
|
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
errorFilePath = imageFileName;
|
|
|
|
fileExist = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
std::string plist = imageFileNameDic->plistFile()->c_str();
|
2022-08-03 09:53:53 +08:00
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->findFrame(imageFileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
fileExist = true;
|
|
|
|
}
|
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
|
|
|
{
|
|
|
|
errorFilePath = textureFileName;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
errorFilePath = plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
fileExist = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fileExist)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
scrollView->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto widgetOptions = options->widgetOptions();
|
|
|
|
auto f_color = widgetOptions->color();
|
|
|
|
Color3B color(f_color->r(), f_color->g(), f_color->b());
|
|
|
|
scrollView->setColor(color);
|
|
|
|
|
|
|
|
int opacity = widgetOptions->alpha();
|
|
|
|
scrollView->setOpacity(opacity);
|
|
|
|
|
|
|
|
auto f_innerSize = options->innerSize();
|
|
|
|
Size innerSize(f_innerSize->width(), f_innerSize->height());
|
|
|
|
scrollView->setInnerContainerSize(innerSize);
|
|
|
|
int direction = options->direction();
|
|
|
|
scrollView->setDirection((ScrollView::Direction)direction);
|
|
|
|
bool bounceEnabled = options->bounceEnabled() != 0;
|
|
|
|
scrollView->setBounceEnabled(bounceEnabled);
|
|
|
|
|
|
|
|
bool scrollbarEnabled = options->scrollbarEnabeld() != 0;
|
|
|
|
scrollView->setScrollBarEnabled(scrollbarEnabled);
|
|
|
|
if (scrollbarEnabled)
|
|
|
|
{
|
|
|
|
bool scrollbarAutoHide = options->scrollbarAutoHide() != 0;
|
|
|
|
scrollView->setScrollBarAutoHideEnabled(scrollbarAutoHide);
|
|
|
|
float barAutoHideTime = options->scrollbarAutoHideTime();
|
|
|
|
scrollView->setScrollBarAutoHideTime(barAutoHideTime);
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto widgetReader = WidgetReader::getInstance();
|
|
|
|
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (backGroundScale9Enabled)
|
|
|
|
{
|
|
|
|
auto f_capInsets = options->capInsets();
|
|
|
|
Rect capInsets(f_capInsets->x(), f_capInsets->y(), f_capInsets->width(), f_capInsets->height());
|
|
|
|
scrollView->setBackGroundImageCapInsets(capInsets);
|
|
|
|
|
|
|
|
auto f_scale9Size = options->scale9Size();
|
|
|
|
Size scale9Size(f_scale9Size->width(), f_scale9Size->height());
|
|
|
|
scrollView->setContentSize(scale9Size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!scrollView->isIgnoreContentAdaptWithSize())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height());
|
|
|
|
scrollView->setContentSize(contentSize);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Node* ScrollViewReader::createNodeWithFlatBuffers(const flatbuffers::Table* scrollViewOptions)
|
|
|
|
{
|
|
|
|
ScrollView* scrollView = ScrollView::create();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
setPropsWithFlatBuffers(scrollView, (Table*)scrollViewOptions);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
return scrollView;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 15:49:45 +08:00
|
|
|
int ScrollViewReader::getResourceType(std::string_view key)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
if (key == "Normal" || key == "Default")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
|
|
|
if (fbs->_isSimulator)
|
|
|
|
{
|
|
|
|
if (key == "MarkedSubImage")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
return 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return 1;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
} // namespace cocostudio
|