@@ -731,8 +731,7 @@ std::vector<std::string> UIModding::generateValidSprites(const std::string& path
731731void UIModding::setSprite (CCNode* node, const matjson::Value& attributes) {
732732 if (!attributes.contains (" sprite" ) && !attributes.contains (" sprite-frame" )) return ;
733733
734- matjson::Value sprite = attributes[" sprite" ];
735- if (attributes.contains (" sprite-frame" )) sprite = attributes[" sprite-frame" ];
734+ matjson::Value sprite = attributes.contains (" sprite-frame" ) ? attributes[" sprite-frame" ] : attributes[" sprite" ];
736735 std::string spriteName;
737736 CCSprite* spr = nullptr ;
738737
@@ -820,6 +819,40 @@ void UIModding::setSprite(CCNode* node, const matjson::Value& attributes) {
820819 }
821820}
822821
822+ void UIModding::setCascadeColor (CCNode* node, const matjson::Value& attributes) {
823+ if (!attributes.contains (" cascade-color" )) return ;
824+
825+ if (auto cascade = attributes[" cascade-color" ]; cascade.isBool ()) {
826+ if (auto node1 = typeinfo_cast<CCMenuItemSpriteExtra*>(node)) {
827+ node1->setCascadeColorEnabled (cascade.asBool ().unwrap ());
828+ if (auto node2 = node1->getChildByType <ButtonSprite>(0 )) {
829+ node2->setCascadeColorEnabled (cascade.asBool ().unwrap ());
830+ }
831+ }
832+
833+ if (auto rgba = typeinfo_cast<CCRGBAProtocol*>(node)) {
834+ rgba->setCascadeColorEnabled (cascade.asBool ().unwrap ());
835+ }
836+ }
837+ }
838+
839+ void UIModding::setCascadeOpacity (CCNode* node, const matjson::Value& attributes) {
840+ if (!attributes.contains (" cascade-opacity" )) return ;
841+
842+ if (auto cascade = attributes[" cascade-opacity" ]; cascade.isBool ()) {
843+ if (auto node1 = typeinfo_cast<CCMenuItemSpriteExtra*>(node)) {
844+ node1->setCascadeOpacityEnabled (cascade.asBool ().unwrap ());
845+ if (auto node2 = node1->getChildByType <ButtonSprite>(0 )) {
846+ node2->setCascadeOpacityEnabled (cascade.asBool ().unwrap ());
847+ }
848+ }
849+
850+ if (auto rgba = typeinfo_cast<CCRGBAProtocol*>(node)) {
851+ rgba->setCascadeOpacityEnabled (cascade.asBool ().unwrap ());
852+ }
853+ }
854+ }
855+
823856void UIModding::setOpacity (CCNode* node, const matjson::Value& attributes) {
824857 if (!attributes.contains (" opacity" )) return ;
825858
@@ -835,11 +868,8 @@ void UIModding::setOpacity(CCNode* node, const matjson::Value& attributes) {
835868 }
836869 }
837870
838- if (auto nodeRGBA = typeinfo_cast<CCNodeRGBA*>(node)) {
839- nodeRGBA->setOpacity (opacityNum);
840- }
841- if (auto layerRGBA = typeinfo_cast<CCLayerRGBA*>(node)) {
842- layerRGBA->setOpacity (opacityNum);
871+ if (auto rgba = typeinfo_cast<CCRGBAProtocol*>(node)) {
872+ rgba->setOpacity (opacityNum);
843873 }
844874 }
845875
@@ -908,72 +938,53 @@ void UIModding::setScale(CCNode* node, const matjson::Value& attributes) {
908938 }
909939
910940 if (auto fit = scale[" fit" ]; fit.isObject ()) {
911- std::string fitRelative = fit[" relative" ].asString ().unwrapOrDefault ();
912- float scaleMultiplier = fit[" multiplier" ].asDouble ().unwrapOr (1 .f );
913- CCSize targetSize = {-1 , -1 };
914- CCSize screenSize = CCDirector::get ()->getWinSize ();
915- CCSize parentSize = targetSize;
916- if (auto parent = node->getParent ()) {
917- parentSize = parent->getContentSize ();
918- }
919- if (fitRelative == " screen" ) {
920- targetSize = screenSize;
921- }
922- if (fitRelative == " screen-width" ) {
923- targetSize.width = screenSize.width ;
924- }
925- if (fitRelative == " screen-height" ) {
926- targetSize.height = screenSize.height ;
927- }
928- if (fitRelative == " parent" ) {
929- targetSize = parentSize;
930- }
931- if (fitRelative == " parent-width" ) {
932- targetSize.width = parentSize.width ;
933- }
934- if (fitRelative == " parent-height" ) {
935- targetSize.height = parentSize.height ;
936- }
937- if (fitRelative == " size" ) {
938- if (auto size = fit[" size" ]; fit.isObject ()) {
939- if (auto widthVal = size[" width" ]; widthVal.isNumber ()) {
940- targetSize.width = widthVal.asDouble ().unwrapOr (-1 .f );
941+ std::string relative = fit[" relative" ].asString ().unwrapOr (" screen" );
942+ std::string mode = fit[" mode" ].asString ().unwrapOr (" fit" );
943+ float multiplier = fit[" multiplier" ].asDouble ().unwrapOr (1 .f );
944+
945+ CCSize screen = CCDirector::get ()->getWinSize ();
946+ CCSize parent = node->getParent () ? node->getParent ()->getContentSize () : CCSize{0 ,0 };
947+ CCSize target = {-1 , -1 };
948+
949+ if (relative == " screen" ) target = screen;
950+ else if (relative == " screen-width" ) target.width = screen.width ;
951+ else if (relative == " screen-height" ) target.height = screen.height ;
952+ else if (relative == " parent" ) target = parent;
953+ else if (relative == " parent-width" ) target.width = parent.width ;
954+ else if (relative == " parent-height" ) target.height = parent.height ;
955+ else if (relative == " size" ) {
956+ if (auto size = fit[" size" ]; size.isObject ()) {
957+ if (size[" width" ].isNumber ()) {
958+ target.width = size[" width" ].asDouble ().unwrapOr (-1 .f );
941959 }
942- if (auto heightVal = size[" height" ]; heightVal .isNumber ()) {
943- targetSize .height = heightVal .asDouble ().unwrapOr (-1 .f );
960+ if (size[" height" ].isNumber ()) {
961+ target .height = size[ " height " ] .asDouble ().unwrapOr (-1 .f );
944962 }
945963 }
946964 }
947965
948- CCSize contentSize = node->getContentSize ();
966+ CCSize content = node->getContentSize ();
949967
950- float largestSide = - 1 ;
951- float largestContentSide = - 1 ;
968+ float scaleX = target. width > 0 ? target. width / content. width : - 1 . f ;
969+ float scaleY = target. height > 0 ? target. height / content. height : - 1 . f ;
952970
953- if (targetSize.width != -1 && targetSize.height != -1 ) {
954- if (targetSize.width > targetSize.height ) {
955- largestSide = targetSize.width ;
956- largestContentSide = contentSize.width ;
957- }
958- else {
959- largestSide = targetSize.height ;
960- largestContentSide = contentSize.height ;
961- }
971+ if (mode == " stretch" ) {
972+ if (scaleX > 0 ) node->setScaleX (scaleX * multiplier);
973+ if (scaleY > 0 ) node->setScaleY (scaleY * multiplier);
974+ return ;
962975 }
963- else if (targetSize.width != -1 ) {
964- largestSide = targetSize.width ;
965- largestContentSide = contentSize.width ;
976+
977+ float finalScale = -1 .f ;
978+
979+ if (scaleX > 0 && scaleY > 0 ) {
980+ finalScale = (mode == " fill" ) ? std::max (scaleX, scaleY) : std::min (scaleX, scaleY);
966981 }
967- else if (targetSize.height != -1 ) {
968- largestSide = targetSize.height ;
969- largestContentSide = contentSize.height ;
982+ else {
983+ finalScale = std::max (scaleX, scaleY);
970984 }
971-
972- if (largestSide != -1 ) {
973- float scale = largestSide / largestContentSide;
974- node->setScale (scale * scaleMultiplier);
985+ if (finalScale > 0 ) {
986+ node->setScale (finalScale * multiplier);
975987 }
976- return ;
977988 }
978989}
979990
@@ -1080,6 +1091,8 @@ void UIModding::handleAttributes(CCNode* node, const matjson::Value& attributes)
10801091 nodesFor (setContentSize);
10811092 nodesFor (setVisible);
10821093 nodesFor (setIgnoreAnchorPos);
1094+ nodesFor (setCascadeColor);
1095+ nodesFor (setCascadeOpacity);
10831096 nodesFor (setColor);
10841097 nodesFor (setOpacity);
10851098 nodesFor (setPosition);
0 commit comments