axmol/extensions/cocostudio/WidgetReader/TabControlReader/TabControlReader.cpp

965 lines
31 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
2019-11-24 23:15:56 +08:00
Copyright (c) 2015-2017 Chukong Technologies Inc.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
http://www.cocos2d-x.org
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "flatbuffers/flatbuffers.h"
#include "WidgetReader/WidgetReader.h"
#include "CSParseBinary_generated.h"
#include "WidgetReader/TabControlReader/TabControlReader.h"
#include "FlatBuffersSerialize.h"
#include "ActionTimeline/CSLoader.h"
2019-11-23 20:27:39 +08:00
#include "ui/UITabControl.h"
#include "platform/CCFileUtils.h"
#include "2d/CCSpriteFrameCache.h"
USING_NS_CC;
using namespace cocostudio;
using namespace flatbuffers;
using namespace cocos2d::ui;
IMPLEMENT_CLASS_NODE_READER_INFO(TabControlReader)
2021-12-25 10:04:45 +08:00
TabControlReader::TabControlReader() {}
2019-11-23 20:27:39 +08:00
TabControlReader* TabControlReader::_tabReaderInstance = nullptr;
TabControlReader* TabControlReader::getInstance()
{
if (_tabReaderInstance == nullptr)
{
2021-12-25 10:04:45 +08:00
_tabReaderInstance = new TabControlReader();
2019-11-23 20:27:39 +08:00
}
return _tabReaderInstance;
}
void TabControlReader::destroyInstance()
{
CC_SAFE_DELETE(_tabReaderInstance);
}
flatbuffers::Offset<flatbuffers::Table> TabControlReader::createOptionsWithFlatBuffers(
2021-12-25 10:04:45 +08:00
pugi::xml_node objectData,
flatbuffers::FlatBufferBuilder* builder)
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
2019-11-23 20:27:39 +08:00
auto nodeOptions = *(Offset<WidgetOptions>*)(&temp);
2021-12-25 10:04:45 +08:00
int headerPlace = 0;
int headerWidth = 50;
int headerHeight = 20;
float selectedTabZoom = 0.0f;
int selectedIndex = 0;
2019-11-23 20:27:39 +08:00
bool ignoretexturesize = true;
2021-12-25 10:04:45 +08:00
std::vector<Offset<TabItemOption>> tabItems;
auto attribute = objectData.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
std::string attriname = attribute.name();
2021-12-25 10:04:45 +08:00
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (attriname == "HeaderPlace")
{
auto placeStr = value.c_str();
if (strcmp(placeStr, "TOP") == 0)
headerPlace = 0;
else if (strcmp(placeStr, "LEFT") == 0)
headerPlace = 1;
else if (strcmp(placeStr, "BOTTOM") == 0)
headerPlace = 2;
else if (strcmp(placeStr, "RIGHT") == 0)
headerPlace = 3;
}
else if (attriname == "HeaderWidth")
{
headerWidth = atoi(value.c_str());
}
else if (attriname == "HeaderHeight")
{
headerHeight = atoi(value.c_str());
}
else if (attriname == "SelectedTabZoom")
{
selectedTabZoom = atof(value.c_str());
}
else if (attriname == "SelectedTabIndex")
{
selectedIndex = atoi(value.c_str());
}
else if (attriname == "IgnoreHeaderTextureSize")
{
ignoretexturesize = FLATSTR_TO_BOOL(value);
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
bool containChildrenElement = false;
2021-12-25 10:04:45 +08:00
auto child = objectData.first_child();
2019-11-23 20:27:39 +08:00
while (child)
{
2019-11-24 23:15:56 +08:00
if (strcmp("Children", child.name()) == 0)
2019-11-23 20:27:39 +08:00
{
containChildrenElement = true;
break;
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
child = child.next_sibling();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (containChildrenElement)
{
2021-12-25 10:04:45 +08:00
child = child.first_child(); // first child
2019-11-23 20:27:39 +08:00
bool hasItem = true;
while (child && hasItem)
{
2019-11-24 23:15:56 +08:00
pugi::xml_attribute childattribute = child.first_attribute();
2019-11-23 20:27:39 +08:00
while (childattribute)
{
2019-11-24 23:15:56 +08:00
std::string attriname = childattribute.name();
2021-12-25 10:04:45 +08:00
std::string value = childattribute.value();
2019-11-23 20:27:39 +08:00
if (attriname == "ctype")
{
if (value.compare("TabItemObjectData") == 0)
{
2021-12-25 10:04:45 +08:00
auto itemOption =
TabItemReader::getInstance()->createTabItemOptionWithFlatBuffers(child, builder);
2019-11-23 20:27:39 +08:00
tabItems.push_back(itemOption);
break;
}
else
hasItem = false;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
break;
}
2019-11-24 23:15:56 +08:00
childattribute = childattribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2019-11-24 23:15:56 +08:00
child = child.next_sibling();
2019-11-23 20:27:39 +08:00
}
}
2021-12-25 10:04:45 +08:00
auto options =
CreateTabControlOption(*builder, nodeOptions, headerPlace, headerWidth, headerHeight, selectedTabZoom,
selectedIndex, ignoretexturesize, builder->CreateVector(tabItems));
2019-11-23 20:27:39 +08:00
return *(Offset<Table>*)(&options);
}
void TabControlReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOption)
{
auto tabControl = static_cast<cocos2d::ui::TabControl*>(node);
2021-12-25 10:04:45 +08:00
auto options = (flatbuffers::TabControlOption*)nodeOption;
2019-11-23 20:27:39 +08:00
int headerPlace = options->headerPlace();
tabControl->ignoreHeadersTextureSize(options->ignoreHeaderTextureSize() != 0);
tabControl->setHeaderDockPlace((cocos2d::ui::TabControl::Dock)headerPlace);
tabControl->setHeaderWidth(options->headerWidth());
tabControl->setHeaderHeight(options->headerHeight());
tabControl->setHeaderSelectedZoom(options->selectedTabZoom());
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int tabItemCount = options->tabItems()->size();
for (int i = 0; i < tabItemCount; i++)
{
2021-12-25 10:04:45 +08:00
auto item = options->tabItems()->Get(i);
auto header = TabHeaderReader::getInstance()->createNodeWithFlatBuffers((Table*)item->header());
2019-11-23 20:27:39 +08:00
auto container = CSLoader::getInstance()->nodeWithFlatBuffers(item->container());
tabControl->insertTab(i, (TabHeader*)header, (Layout*)container);
}
tabControl->setSelectTab(options->selectedTabIndex());
}
cocos2d::Node* TabControlReader::createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions)
{
auto node = cocos2d::ui::TabControl::create();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
auto taboptions = (flatbuffers::TabControlOption*)nodeOptions;
setPropsWithFlatBuffers(node, nodeOptions);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
auto nodereader = WidgetReader::getInstance();
nodereader->setPropsWithFlatBuffers(node, (Table*)taboptions->nodeOptions());
return node;
}
2021-12-25 10:04:45 +08:00
TabControlReader::~TabControlReader() {}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
TabHeaderReader::TabHeaderReader() {}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
TabHeaderReader::~TabHeaderReader() {}
2019-11-23 20:27:39 +08:00
TabHeaderReader* TabHeaderReader::_tabheaderReaderInstance = nullptr;
TabHeaderReader* TabHeaderReader::getInstance()
{
if (_tabheaderReaderInstance == nullptr)
{
2021-12-08 00:11:53 +08:00
_tabheaderReaderInstance = new TabHeaderReader();
2019-11-23 20:27:39 +08:00
}
return _tabheaderReaderInstance;
}
void TabHeaderReader::destroyInstance()
{
CC_SAFE_DELETE(_tabheaderReaderInstance);
}
flatbuffers::Offset<flatbuffers::Table> TabHeaderReader::createOptionsWithFlatBuffers(
2021-12-25 10:04:45 +08:00
pugi::xml_node objectData,
flatbuffers::FlatBufferBuilder* builder)
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
2019-11-23 20:27:39 +08:00
auto nodeOptions = *(Offset<WidgetOptions>*)(&temp);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int fontsize = 12;
2020-08-04 10:55:30 +08:00
std::string text;
2019-11-23 20:27:39 +08:00
cocos2d::Color4B textColor(255, 255, 255, 255);
std::string fontName;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int backgroundboxResourceType = 0;
2020-08-04 10:55:30 +08:00
std::string backgroundboxPath;
std::string backgroundboxPlistFile;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int backGroundBoxSelectedResourceType = 0;
2020-08-04 10:55:30 +08:00
std::string backGroundBoxSelectedPath;
std::string backGroundBoxSelectedPlistFile;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int frontCrossResourceType = 0;
2020-08-04 10:55:30 +08:00
std::string frontCrossPath;
std::string frontCrossPlistFile;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int backGroundBoxDisabledResourceType = 0;
2020-08-04 10:55:30 +08:00
std::string backGroundBoxDisabledPath;
std::string backGroundBoxDisabledPlistFile;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int frontCrossDisabledResourceType = 0;
2020-08-04 10:55:30 +08:00
std::string frontCrossDisabledPath;
std::string frontCrossDisabledPlistFile;
2021-12-25 10:04:45 +08:00
2020-08-04 10:55:30 +08:00
std::string fontResourcePath;
std::string fontResourcePlistFile;
2019-11-23 20:27:39 +08:00
int fontResourceResourceType = 0;
2021-12-25 10:04:45 +08:00
auto attribute = objectData.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
std::string attriname = attribute.name();
2021-12-25 10:04:45 +08:00
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (attriname.compare("FontSize") == 0)
{
fontsize = atoi(value.c_str());
}
else if (attriname.compare("TitleText") == 0)
{
text = value;
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
auto child = objectData.first_child();
2019-11-23 20:27:39 +08:00
while (child)
{
2019-11-24 23:15:56 +08:00
std::string name = child.name();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "TextColor")
{
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2021-12-25 10:04:45 +08:00
name = attribute.name();
2019-11-24 23:15:56 +08:00
std::string value = attribute.value();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "R")
{
textColor.r = atoi(value.c_str());
}
else if (name == "G")
{
textColor.g = atoi(value.c_str());
}
else if (name == "B")
{
textColor.b = atoi(value.c_str());
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
}
else if (name == "NormalBackFileData")
{
2020-08-04 10:55:30 +08:00
std::string texture;
std::string texturePng;
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
while (attribute)
{
2021-12-25 10:04:45 +08:00
name = attribute.name();
2019-11-24 23:15:56 +08:00
std::string value = attribute.value();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
backgroundboxPath = value;
}
else if (name == "Type")
{
backgroundboxResourceType = getResourceType(value);
}
else if (name == "Plist")
{
backgroundboxPlistFile = value;
2021-12-25 10:04:45 +08:00
texture = value;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (backgroundboxResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "PressedBackFileData")
{
2020-08-04 10:55:30 +08:00
std::string texture;
std::string texturePng;
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
while (attribute)
{
2021-12-25 10:04:45 +08:00
name = attribute.name();
2019-11-24 23:15:56 +08:00
std::string value = attribute.value();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
backGroundBoxSelectedPath = value;
}
else if (name == "Type")
{
backGroundBoxSelectedResourceType = getResourceType(value);
}
else if (name == "Plist")
{
backGroundBoxSelectedPlistFile = value;
2021-12-25 10:04:45 +08:00
texture = value;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (backGroundBoxSelectedResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "NodeNormalFileData")
{
2020-08-04 10:55:30 +08:00
std::string texture;
std::string texturePng;
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
while (attribute)
{
2021-12-25 10:04:45 +08:00
name = attribute.name();
2019-11-24 23:15:56 +08:00
std::string value = attribute.value();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
frontCrossPath = value;
}
else if (name == "Type")
{
frontCrossResourceType = getResourceType(value);
}
else if (name == "Plist")
{
frontCrossPlistFile = value;
2021-12-25 10:04:45 +08:00
texture = value;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (frontCrossResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "DisableBackFileData")
{
2020-08-04 10:55:30 +08:00
std::string texture;
std::string texturePng;
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
while (attribute)
{
2021-12-25 10:04:45 +08:00
name = attribute.name();
2019-11-24 23:15:56 +08:00
std::string value = attribute.value();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
backGroundBoxDisabledPath = value;
}
else if (name == "Type")
{
backGroundBoxDisabledResourceType = getResourceType(value);
}
else if (name == "Plist")
{
backGroundBoxDisabledPlistFile = value;
2021-12-25 10:04:45 +08:00
texture = value;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (backGroundBoxDisabledResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "NodeDisableFileData")
{
2020-08-04 10:55:30 +08:00
std::string texture;
std::string texturePng;
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
while (attribute)
{
2021-12-25 10:04:45 +08:00
name = attribute.name();
2019-11-24 23:15:56 +08:00
std::string value = attribute.value();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
frontCrossDisabledPath = value;
}
else if (name == "Type")
{
frontCrossDisabledResourceType = getResourceType(value);
}
else if (name == "Plist")
{
frontCrossDisabledPlistFile = value;
2021-12-25 10:04:45 +08:00
texture = value;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (frontCrossDisabledResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "FontResource")
{
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
while (attribute)
{
2021-12-25 10:04:45 +08:00
name = attribute.name();
2019-11-24 23:15:56 +08:00
std::string value = attribute.value();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
fontResourcePath = value;
}
else if (name == "Type")
{
fontResourceResourceType = getResourceType(value);
}
else if (name == "Plist")
{
fontResourcePlistFile = value;
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
}
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
child = child.next_sibling();
2019-11-23 20:27:39 +08:00
}
Color f_textColor(255, textColor.r, textColor.g, textColor.b);
2021-12-25 10:04:45 +08:00
auto option = CreateTabHeaderOption(
*builder, nodeOptions,
CreateResourceData(*builder, builder->CreateString(fontResourcePath),
builder->CreateString(fontResourcePlistFile), fontResourceResourceType),
fontsize, builder->CreateString(text), &f_textColor,
CreateResourceData(*builder, builder->CreateString(backgroundboxPath),
builder->CreateString(backgroundboxPlistFile), backgroundboxResourceType),
CreateResourceData(*builder, builder->CreateString(backGroundBoxSelectedPath),
builder->CreateString(backGroundBoxSelectedPlistFile), backGroundBoxSelectedResourceType),
CreateResourceData(*builder, builder->CreateString(backGroundBoxDisabledPath),
builder->CreateString(backGroundBoxDisabledPlistFile), backGroundBoxDisabledResourceType),
CreateResourceData(*builder, builder->CreateString(frontCrossPath), builder->CreateString(frontCrossPlistFile),
frontCrossResourceType),
CreateResourceData(*builder, builder->CreateString(frontCrossDisabledPath),
builder->CreateString(frontCrossDisabledPlistFile), frontCrossDisabledResourceType));
return *(Offset<Table>*)(&option);
2019-11-23 20:27:39 +08:00
}
void TabHeaderReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOption)
{
2021-12-25 10:04:45 +08:00
auto header = static_cast<cocos2d::ui::TabHeader*>(node);
2019-11-23 20:27:39 +08:00
auto options = (flatbuffers::TabHeaderOption*)nodeOption;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
header->setTitleFontSize(options->fontSize());
header->setTitleText(options->titleText()->c_str());
auto textColor = options->textColor();
Color4B titleColor(textColor->r(), textColor->g(), textColor->b(), textColor->a());
header->setTitleColor(titleColor);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
auto resourceData = options->fontRes();
2021-12-25 10:04:45 +08:00
bool fileExist = false;
2020-08-04 10:55:30 +08:00
std::string errorFilePath;
2019-11-23 20:27:39 +08:00
std::string path = resourceData->path()->c_str();
if (path != "")
{
if (FileUtils::getInstance()->isFileExist(path))
{
fileExist = true;
}
else
{
errorFilePath = path;
2021-12-25 10:04:45 +08:00
fileExist = false;
2019-11-23 20:27:39 +08:00
}
if (fileExist)
{
header->setTitleFontName(path);
}
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
bool backGroundFileExist = false;
2020-08-04 10:55:30 +08:00
std::string backGroundErrorFilePath;
2021-12-25 10:04:45 +08:00
auto backGroundDic = options->normalBackFile();
int backGroundType = backGroundDic->resourceType();
2019-11-23 20:27:39 +08:00
std::string backGroundTexturePath = backGroundDic->path()->c_str();
switch (backGroundType)
{
2021-12-25 10:04:45 +08:00
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundTexturePath))
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
backGroundFileExist = true;
}
else
{
backGroundErrorFilePath = backGroundTexturePath;
backGroundFileExist = false;
}
break;
}
case 1:
{
std::string plist = backGroundDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundTexturePath);
if (spriteFrame)
{
backGroundFileExist = true;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
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))
{
backGroundErrorFilePath = textureFileName;
}
2019-11-23 20:27:39 +08:00
}
else
{
2021-12-25 10:04:45 +08:00
backGroundErrorFilePath = plist;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
backGroundFileExist = false;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
break;
}
default:
break;
2019-11-23 20:27:39 +08:00
}
if (backGroundFileExist)
{
header->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
}
2021-12-25 10:04:45 +08:00
// load background selected image
2019-11-23 20:27:39 +08:00
bool backGroundSelectedfileExist = false;
2020-08-04 10:55:30 +08:00
std::string backGroundSelectedErrorFilePath;
2021-12-25 10:04:45 +08:00
auto backGroundSelectedDic = options->pressBackFile();
int backGroundSelectedType = backGroundSelectedDic->resourceType();
2019-11-23 20:27:39 +08:00
std::string backGroundSelectedTexturePath = backGroundSelectedDic->path()->c_str();
switch (backGroundSelectedType)
{
2021-12-25 10:04:45 +08:00
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundSelectedTexturePath))
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
backGroundSelectedfileExist = true;
}
else
{
backGroundSelectedErrorFilePath = backGroundSelectedTexturePath;
backGroundSelectedfileExist = false;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
break;
}
case 1:
{
std::string plist = backGroundSelectedDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundSelectedTexturePath);
if (spriteFrame)
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
backGroundSelectedfileExist = true;
}
else
{
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))
{
backGroundSelectedErrorFilePath = textureFileName;
}
2019-11-23 20:27:39 +08:00
}
else
{
2021-12-25 10:04:45 +08:00
backGroundSelectedErrorFilePath = plist;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
backGroundSelectedfileExist = false;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
break;
}
default:
break;
2019-11-23 20:27:39 +08:00
}
if (backGroundSelectedfileExist)
{
2021-12-25 10:04:45 +08:00
header->loadTextureBackGroundSelected(backGroundSelectedTexturePath,
(cocos2d::ui::Widget::TextureResType)backGroundSelectedType);
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
// load frontCross image
2019-11-23 20:27:39 +08:00
bool frontCrossFileExist = false;
2020-08-04 10:55:30 +08:00
std::string frontCrossErrorFilePath;
2021-12-25 10:04:45 +08:00
auto frontCrossDic = options->crossNormalFile();
int frontCrossType = frontCrossDic->resourceType();
2019-11-23 20:27:39 +08:00
std::string frontCrossFileName = frontCrossDic->path()->c_str();
switch (frontCrossType)
{
2021-12-25 10:04:45 +08:00
case 0:
{
if (FileUtils::getInstance()->isFileExist(frontCrossFileName))
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
frontCrossFileExist = true;
}
else
{
frontCrossErrorFilePath = frontCrossFileName;
frontCrossFileExist = false;
}
break;
}
case 1:
{
std::string plist = frontCrossDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossFileName);
if (spriteFrame)
{
frontCrossFileExist = true;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
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))
{
frontCrossErrorFilePath = textureFileName;
}
2019-11-23 20:27:39 +08:00
}
else
{
2021-12-25 10:04:45 +08:00
frontCrossErrorFilePath = plist;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
frontCrossFileExist = false;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
break;
}
default:
break;
2019-11-23 20:27:39 +08:00
}
if (frontCrossFileExist)
{
header->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
}
2021-12-25 10:04:45 +08:00
// load backGroundBoxDisabledData
2019-11-23 20:27:39 +08:00
bool backGroundBoxDisabledFileExist = false;
2020-08-04 10:55:30 +08:00
std::string backGroundBoxDisabledErrorFilePath;
2021-12-25 10:04:45 +08:00
auto backGroundDisabledDic = options->disableBackFile();
int backGroundDisabledType = backGroundDisabledDic->resourceType();
2019-11-23 20:27:39 +08:00
std::string backGroundDisabledFileName = backGroundDisabledDic->path()->c_str();
switch (backGroundDisabledType)
{
2021-12-25 10:04:45 +08:00
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundDisabledFileName))
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
backGroundBoxDisabledFileExist = true;
}
else
{
backGroundBoxDisabledErrorFilePath = backGroundDisabledFileName;
backGroundBoxDisabledFileExist = false;
}
break;
}
case 1:
{
std::string plist = backGroundDisabledDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundDisabledFileName);
if (spriteFrame)
{
backGroundBoxDisabledFileExist = true;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
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))
{
backGroundBoxDisabledErrorFilePath = textureFileName;
}
2019-11-23 20:27:39 +08:00
}
else
{
2021-12-25 10:04:45 +08:00
backGroundBoxDisabledErrorFilePath = plist;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
backGroundBoxDisabledFileExist = false;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
break;
}
default:
break;
2019-11-23 20:27:39 +08:00
}
if (backGroundBoxDisabledFileExist)
{
2021-12-25 10:04:45 +08:00
header->loadTextureBackGroundDisabled(backGroundDisabledFileName,
(Widget::TextureResType)backGroundDisabledType);
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
/// load frontCrossDisabledData
2019-11-23 20:27:39 +08:00
bool frontCrossDisabledFileExist = false;
2020-08-04 10:55:30 +08:00
std::string frontCrossDisabledErrorFilePath;
2021-12-25 10:04:45 +08:00
auto frontCrossDisabledDic = options->crossDisableFile();
int frontCrossDisabledType = frontCrossDisabledDic->resourceType();
2019-11-23 20:27:39 +08:00
std::string frontCrossDisabledFileName = frontCrossDisabledDic->path()->c_str();
switch (frontCrossDisabledType)
{
2021-12-25 10:04:45 +08:00
case 0:
{
if (FileUtils::getInstance()->isFileExist(frontCrossDisabledFileName))
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
frontCrossDisabledFileExist = true;
}
else
{
frontCrossDisabledErrorFilePath = frontCrossDisabledFileName;
frontCrossDisabledFileExist = false;
}
break;
}
case 1:
{
std::string plist = frontCrossDisabledDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossDisabledFileName);
if (spriteFrame)
{
frontCrossDisabledFileExist = true;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
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))
{
frontCrossDisabledErrorFilePath = textureFileName;
}
2019-11-23 20:27:39 +08:00
}
else
{
2021-12-25 10:04:45 +08:00
frontCrossDisabledErrorFilePath = plist;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
frontCrossDisabledFileExist = false;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
break;
}
default:
break;
2019-11-23 20:27:39 +08:00
}
if (frontCrossDisabledFileExist)
{
2021-12-25 10:04:45 +08:00
header->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,
(Widget::TextureResType)frontCrossDisabledType);
2019-11-23 20:27:39 +08:00
}
}
cocos2d::Node* TabHeaderReader::createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions)
{
auto node = cocos2d::ui::TabHeader::create();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
auto taboptions = (flatbuffers::TabHeaderOption*)nodeOptions;
setPropsWithFlatBuffers(node, nodeOptions);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
auto nodereader = WidgetReader::getInstance();
nodereader->setPropsWithFlatBuffers(node, (Table*)taboptions->nodeOptions());
return node;
}
int TabHeaderReader::getResourceType(std::string key)
{
if (key == "Normal" || key == "Default")
{
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
2019-11-23 20:27:39 +08:00
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
if (fbs->_isSimulator)
{
if (key == "MarkedSubImage")
{
return 0;
}
}
return 1;
}
2021-12-25 10:04:45 +08:00
TabItemReader::TabItemReader() {}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
TabItemReader::~TabItemReader() {}
2019-11-23 20:27:39 +08:00
TabItemReader* TabItemReader::_tabItemReaderInstance = nullptr;
TabItemReader* TabItemReader::getInstance()
{
if (_tabItemReaderInstance == nullptr)
{
2021-12-08 00:11:53 +08:00
_tabItemReaderInstance = new TabItemReader();
2019-11-23 20:27:39 +08:00
}
return _tabItemReaderInstance;
}
void TabItemReader::destroyInstance()
{
CC_SAFE_DELETE(_tabItemReaderInstance);
}
flatbuffers::Offset<flatbuffers::TabItemOption> TabItemReader::createTabItemOptionWithFlatBuffers(
2021-12-25 10:04:45 +08:00
pugi::xml_node objectData,
flatbuffers::FlatBufferBuilder* builder)
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
flatbuffers::Offset<Table> header;
flatbuffers::Offset<NodeTree> container;
2019-11-24 23:15:56 +08:00
pugi::xml_node containerData;
pugi::xml_node containerChildrenData;
2021-12-25 10:04:45 +08:00
2019-11-24 23:15:56 +08:00
auto child = objectData.first_child();
2019-11-23 20:27:39 +08:00
while (child)
{
2019-11-24 23:15:56 +08:00
std::string attriName = child.name();
2019-11-23 20:27:39 +08:00
if (attriName.compare("Children") == 0)
{
2019-11-24 23:15:56 +08:00
containerChildrenData = child;
2019-11-23 20:27:39 +08:00
}
if (attriName.compare("Header") == 0)
{
header = TabHeaderReader::getInstance()->createOptionsWithFlatBuffers(child, builder);
}
else if (attriName.compare("Container") == 0)
{
2019-11-24 23:15:56 +08:00
containerData = child;
2019-11-23 20:27:39 +08:00
}
2019-11-24 23:15:56 +08:00
child = child.next_sibling();
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (containerChildrenData != nullptr)
{
2019-11-24 23:15:56 +08:00
containerData.append_copy(containerChildrenData);
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
container = FlatBuffersSerialize::getInstance()->createNodeTree(containerData, "PanelObjectData");
2021-12-25 10:04:45 +08:00
auto options = CreateTabItemOption(*builder, *(Offset<flatbuffers::TabHeaderOption>*)(&header), container);
return *(&options);
2019-11-23 20:27:39 +08:00
}
void TabItemReader::setPropsWithFlatBuffers(cocos2d::Node* /*node*/, const flatbuffers::Table* /*nodeOption*/)
{
// do nothing
}
cocos2d::Node* TabItemReader::createNodeWithFlatBuffers(const flatbuffers::Table* /*nodeOptions*/)
{
// do nothing
return nullptr;
}
flatbuffers::Offset<flatbuffers::Table> TabItemReader::createOptionsWithFlatBuffers(
2021-12-25 10:04:45 +08:00
pugi::xml_node /*objectData*/,
flatbuffers::FlatBufferBuilder* /*builder*/)
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
// nothing
return flatbuffers::Offset<flatbuffers::Table>();
}