axmol/extensions/cocostudio/WidgetReader/RadioButtonReader/RadioButtonGroupReader.cpp

119 lines
3.3 KiB
C++
Raw Normal View History

2019-11-24 23:15:56 +08:00
#include "WidgetReader/RadioButtonReader/RadioButtonGroupReader.h"
2019-11-24 23:15:56 +08:00
#include "ui/UIRadioButton.h"
#include "platform/CCFileUtils.h"
#include "2d/CCSpriteFrame.h"
#include "2d/CCSpriteFrameCache.h"
#include "CocoLoader.h"
#include "CSParseBinary_generated.h"
#include "FlatBuffersSerialize.h"
2019-11-24 23:15:56 +08:00
#include "flatbuffers/flatbuffers.h"
USING_NS_AX;
2019-11-24 23:15:56 +08:00
using namespace ui;
using namespace flatbuffers;
namespace cocostudio
{
2021-12-25 10:04:45 +08:00
static const char* P_Scale9Enable = "scale9Enable";
static const char* P_FileNameData = "fileNameData";
static const char* P_CapInsetsX = "capInsetsX";
static const char* P_CapInsetsY = "capInsetsY";
static const char* P_CapInsetsWidth = "capInsetsWidth";
static const char* P_CapInsetsHeight = "capInsetsHeight";
static const char* P_Scale9Width = "scale9Width";
static const char* P_Scale9Height = "scale9Height";
static RadioButtonGroupReader* s_readerInstance = nullptr;
IMPLEMENT_CLASS_NODE_READER_INFO(RadioButtonGroupReader)
RadioButtonGroupReader::RadioButtonGroupReader() {}
RadioButtonGroupReader::~RadioButtonGroupReader() {}
RadioButtonGroupReader* RadioButtonGroupReader::getInstance()
{
if (!s_readerInstance)
2019-11-24 23:15:56 +08:00
{
2021-12-25 10:04:45 +08:00
s_readerInstance = new RadioButtonGroupReader();
2019-11-24 23:15:56 +08:00
}
2021-12-25 10:04:45 +08:00
return s_readerInstance;
}
void RadioButtonGroupReader::destroyInstance()
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(s_readerInstance);
2021-12-25 10:04:45 +08:00
}
Offset<Table> RadioButtonGroupReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
flatbuffers::FlatBufferBuilder* builder)
{
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
bool allowdNoSelection = false;
// attributes
auto attribute = objectData.first_attribute();
while (attribute)
2019-11-24 23:15:56 +08:00
{
2021-12-31 15:49:45 +08:00
std::string_view name = attribute.name();
std::string_view value = attribute.value();
2021-12-25 10:04:45 +08:00
if (name == "AllowedNoSelection")
2019-11-24 23:15:56 +08:00
{
2021-12-25 10:04:45 +08:00
allowdNoSelection = (value == "True");
2019-11-24 23:15:56 +08:00
}
2021-12-25 10:04:45 +08:00
attribute = attribute.next_attribute();
2019-11-24 23:15:56 +08:00
}
2021-12-25 10:04:45 +08:00
auto options = CreateRadioButtonGroupOptions(*builder, widgetOptions, allowdNoSelection);
return *(Offset<Table>*)(&options);
}
void RadioButtonGroupReader::setPropsWithFlatBuffers(axis::Node* node, const flatbuffers::Table* params)
2021-12-25 10:04:45 +08:00
{
auto radioButtonGroup = static_cast<ui::RadioButtonGroup*>(node);
auto options = (RadioButtonGroupOptions*)params;
auto widgetReader = WidgetReader::getInstance();
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
radioButtonGroup->setAllowedNoSelection(options->allowedNoSelection());
}
Node* RadioButtonGroupReader::createNodeWithFlatBuffers(const flatbuffers::Table* options)
{
auto node = ui::RadioButtonGroup::create();
setPropsWithFlatBuffers(node, (Table*)options);
return node;
}
2021-12-31 15:49:45 +08:00
/*int RadioButtonGroupReader::getResourceType(std::string_view key)
2021-12-25 10:04:45 +08:00
{
if(key == "Normal" || key == "Default")
2019-11-24 23:15:56 +08:00
{
2021-12-25 10:04:45 +08:00
return 0;
2019-11-24 23:15:56 +08:00
}
2021-12-25 10:04:45 +08:00
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
if(fbs->_isSimulator)
2019-11-24 23:15:56 +08:00
{
2021-12-25 10:04:45 +08:00
if(key == "MarkedSubImage")
2019-11-24 23:15:56 +08:00
{
2021-12-25 10:04:45 +08:00
return 0;
2019-11-24 23:15:56 +08:00
}
}
2021-12-25 10:04:45 +08:00
return 1;
}*/
} // namespace cocostudio