@@ -70,8 +70,7 @@ bool DTLabel::init(const DTLabelInfo& info){
7070 labelTextContainer->setZOrder (1 );
7171 this ->addChild (labelTextContainer);
7272
73- // labelText = RichTextArea::create("", info.font, info.scale);
74- labelText = SimpleTextArea::create (" " , info.font , info.scale );
73+ labelText = RichTextArea::create (" " , info.font , info.scale );
7574 labelText->setID (" text" );
7675 labelText->setAnchorPoint ({.5f , 1 });
7776 labelText->setAlignment (info.horizontalAlignment );
@@ -80,55 +79,80 @@ bool DTLabel::init(const DTLabelInfo& info){
8079 setLabelText (info.text );
8180 labelTextContainer->addChild (labelText);
8281
83- // labelText->registerRichTextKey(std::make_shared<RichTextKey<std::tuple<float, float, float, float>>>(
84- // "wave",
85- // [](std::string value) -> Result<std::tuple<float, float, float, float>> {
86- // float speed = 1;
87- // float distanceY = 5;
88- // float distanceX = 0;
89- // float offsetPerIndex = .3f;
90-
91- // auto splitStr = utils::string::split(value, ",");
92- // if (splitStr.size() >= 1){
93- // auto speedRes = geode::utils::numFromString<float>(splitStr[0]);
94- // if (speedRes.isOk()) speed = speedRes.unwrap();
95- // }
96- // if (splitStr.size() >= 2){
97- // auto distanceYRes = geode::utils::numFromString<float>(splitStr[1]);
98- // if (distanceYRes.isOk()) distanceY = distanceYRes.unwrap();
99- // }
100- // if (splitStr.size() >= 3){
101- // auto distanceXRes = geode::utils::numFromString<float>(splitStr[2]);
102- // if (distanceXRes.isOk()) distanceX = distanceXRes.unwrap();
103- // }
104- // if (splitStr.size() >= 4){
105- // auto offsetPerIndexRes = geode::utils::numFromString<float>(splitStr[3]);
106- // if (offsetPerIndexRes.isOk()) offsetPerIndex = offsetPerIndexRes.unwrap();
107- // }
108-
109- // return Ok(std::make_tuple(speed, distanceY, distanceX, offsetPerIndex));
110- // },
111- // [](std::tuple<float, float, float, float> const& value, cocos2d::CCFontSprite* sprite, int localIndex, int charIndex) {
112- // sprite->runAction(
113- // CCRepeatForever::create(
114- // CCWaveAction::create(
115- // std::get<0>(value),
116- // std::get<2>(value),
117- // std::get<1>(value),
118- // std::get<3>(value) * localIndex
119- // )
120- // )
121- // );
122- // }
123- // ));
82+ labelText->registerRichTextKey (std::make_shared<RichTextKey<std::tuple<float , float , float , float >>>(
83+ " wave" ,
84+ [](std::string value) -> Result<std::tuple<float , float , float , float >> {
85+ float speed = 1 ;
86+ float distanceY = 5 ;
87+ float distanceX = 0 ;
88+ float offsetPerIndex = .3f ;
89+
90+ auto splitStr = utils::string::split (value, " ," );
91+ if (splitStr.size () >= 1 ){
92+ auto speedRes = geode::utils::numFromString<float >(splitStr[0 ]);
93+ if (speedRes.isOk ()) speed = speedRes.unwrap ();
94+ }
95+ if (splitStr.size () >= 2 ){
96+ auto distanceYRes = geode::utils::numFromString<float >(splitStr[1 ]);
97+ if (distanceYRes.isOk ()) distanceY = distanceYRes.unwrap ();
98+ }
99+ if (splitStr.size () >= 3 ){
100+ auto distanceXRes = geode::utils::numFromString<float >(splitStr[2 ]);
101+ if (distanceXRes.isOk ()) distanceX = distanceXRes.unwrap ();
102+ }
103+ if (splitStr.size () >= 4 ){
104+ auto offsetPerIndexRes = geode::utils::numFromString<float >(splitStr[3 ]);
105+ if (offsetPerIndexRes.isOk ()) offsetPerIndex = offsetPerIndexRes.unwrap ();
106+ }
107+
108+ return Ok (std::make_tuple (speed, distanceY, distanceX, offsetPerIndex));
109+ },
110+ [](std::tuple<float , float , float , float > const & value, cocos2d::CCFontSprite* sprite, int localIndex, int charIndex) {
111+ sprite->runAction (
112+ CCRepeatForever::create (
113+ CCWaveAction::create (
114+ std::get<0 >(value),
115+ std::get<2 >(value),
116+ std::get<1 >(value),
117+ std::get<3 >(value) * localIndex
118+ )
119+ )
120+ );
121+ }
122+ ));
123+
124+ labelText->registerRichTextKey (std::make_shared<RichTextKey<int >>(
125+ " cplus" ,
126+ [](std::string value) -> Result<int > {
127+ GEODE_UNWRAP_INTO (auto num, utils::numFromString<int >(value));
128+
129+ return Ok (num);
130+ },
131+ [](int const & value, cocos2d::CCFontSprite* sprite, int localIndex, int charIndex) {
132+ auto colorAdded = sprite->getColor ();
133+ if (colorAdded == ccWHITE) colorAdded = static_cast <CCLabelBMFont*>(sprite->getParent ())->getColor ();
134+
135+ auto r = colorAdded.r + value;
136+ auto g = colorAdded.g + value;
137+ auto b = colorAdded.b + value;
138+
139+ if (r > 255 ) r = 255 ;
140+ if (g > 255 ) g = 255 ;
141+ if (b > 255 ) b = 255 ;
142+
143+ auto newColor = ccColor3B{static_cast <GLubyte>(r), static_cast <GLubyte>(g), static_cast <GLubyte>(b)};
144+
145+ sprite->setColor (newColor);
146+ }
147+ ));
124148
125149 auto textHeight = 0 .0f ;
126150 if (!info.isExpanded ) textHeight = 0 ;
127151 else {
128152 textHeight = labelText->getContentHeight () + textCornerOffset;
129153 }
130154
131- this ->setContentHeight (textHeight + labelTitleHeight );
155+ this ->setContentHeight (textHeight + getSpecificTitleHeight () );
132156 this ->setContentWidth (0 );
133157 this ->setPosition ({0 , 0 });
134158 this ->ignoreAnchorPointForPosition (false );
@@ -137,10 +161,10 @@ bool DTLabel::init(const DTLabelInfo& info){
137161
138162 bg = CCScale9Sprite::create (" GJ_squareB_01.png" );
139163 bg->setID (" text-bg" );
140- bg->setOpacity (normalBGOpacity);
164+ bg->setOpacity (normalBGOpacity * (info. labelColor . a / 255 . 0f ) );
141165 bg->setScale (.2f );
142166 bg->setAnchorPoint ({0 , 1 });
143- bg->setContentHeight (labelTitleHeight / bg->getScale ());
167+ bg->setContentHeight (getSpecificTitleHeight () / bg->getScale ());
144168 if (info.isExpanded ) bg->setContentHeight (this ->getContentHeight () / bg->getScale ());
145169 this ->addChild (bg);
146170
@@ -149,6 +173,7 @@ bool DTLabel::init(const DTLabelInfo& info){
149173 labelTitleBG->setScale (.15f );
150174 labelTitleBG->setAnchorPoint ({0 , 1 });
151175 labelTitleBG->setContentHeight (labelTitleHeight / labelTitleBG->getScale ());
176+ labelTitleBG->setOpacity (info.hideHeader ? 0 : 255 );
152177 this ->addChild (labelTitleBG);
153178
154179 labelTitleArea = SimpleTextArea::create (info.labelName , " bigFont.fnt" , .35f );
@@ -158,6 +183,7 @@ bool DTLabel::init(const DTLabelInfo& info){
158183 labelTitleArea->setPositionX (15 );
159184 labelTitleArea->setWrappingMode (WrappingMode::CUTOFF_WRAP );
160185 labelTitleArea->setMaxLines (1 );
186+ labelTitleArea->setVisible (!info.hideHeader );
161187 this ->addChild (labelTitleArea);
162188
163189 float expandLineWidth = 3 ;
@@ -200,6 +226,9 @@ bool DTLabel::init(const DTLabelInfo& info){
200226 expandBtn->setPositionX (8 );
201227 }
202228
229+ menu->setEnabled (!info.hideHeader );
230+ menu->setOpacity (info.hideHeader ? 0 : 255 );
231+
203232 this ->scheduleUpdate ();
204233
205234 setLabelColor (info.labelColor );
@@ -225,7 +254,7 @@ void DTLabel::registerWithTouchDispatcher(){
225254
226255void DTLabel::update (float dt){
227256
228- labelTextContainer->setPosition (bg->getPosition () + ccp (this ->getContentWidth () / 2 , -labelTitleHeight ));
257+ labelTextContainer->setPosition (bg->getPosition () + ccp (this ->getContentWidth () / 2 , -getSpecificTitleHeight () ));
229258 if (labelText->getWidth () != this ->getContentWidth () - textCornerOffset && info.isExpanded ){
230259 labelText->setWidth (this ->getContentWidth () - textCornerOffset);
231260 labelText->setWidth (labelText->getWidth ());
@@ -242,7 +271,7 @@ void DTLabel::update(float dt){
242271 if (!info.isExpanded ) textHeight = 0 ;
243272 else textHeight = labelText->getContentHeight () + textCornerOffset;
244273
245- float targetHeight = textHeight + labelTitleHeight ;
274+ float targetHeight = textHeight + getSpecificTitleHeight () ;
246275 bool doUpdateLayout = false ;
247276
248277 if (targetHeight != this ->getContentHeight ()) doUpdateLayout = true ;
@@ -265,7 +294,7 @@ void DTLabel::update(float dt){
265294 bg->setPositionY (this ->getContentHeight ());
266295 menu->setPositionY (this ->getContentHeight ());
267296
268- loadingCircle->setPosition ({this ->getContentWidth () / 2 , this ->getContentHeight () - labelTitleHeight / 2 });
297+ loadingCircle->setPosition ({this ->getContentWidth () / 2 , this ->getContentHeight () - getSpecificTitleHeight () / 2 });
269298
270299 labelTitleArea->setWidth (this ->getContentWidth () - labelTitleArea->getPositionX () - 4 );
271300 labelTitleArea->setPositionY (this ->getContentHeight ());
@@ -633,8 +662,7 @@ arc::Future<std::optional<std::string>> DTLabel::modifyKeys(){
633662 auto text = co_await async::waitForMainThread<std::string>([self = this ]() -> std::string {
634663 if (!self) return " " ;
635664 self->loadingCircle ->setVisible (true );
636- // return self->labelText->getRawText();
637- return self->labelText ->getText ();
665+ return self->labelText ->getRawText ();
638666 });
639667 if (!text.has_value ()) {
640668 co_return std::nullopt ;
@@ -704,9 +732,9 @@ void DTLabel::setLabelColor(const ccColor4B& newColor){
704732 info.labelColor = newColor;
705733
706734 bg->setColor ({info.labelColor .r , info.labelColor .g , info.labelColor .b });
707- bg->setOpacity (normalBGOpacity * (info.labelColor .a / 255 ));
735+ bg->setOpacity (normalBGOpacity * (info.labelColor .a / 255 . 0f ));
708736 labelTitleBG->setColor ({info.labelColor .r , info.labelColor .g , info.labelColor .b });
709- labelTitleBG->setOpacity (info.labelColor .a );
737+ labelTitleBG->setOpacity (info.hideHeader ? 0 : info. labelColor .a );
710738}
711739
712740void DTLabel::setTextColor (const ccColor4B& newColor){
@@ -744,6 +772,22 @@ void DTLabel::onBeingEditedEnded(){
744772
745773void DTLabel::setEditable (bool editable){
746774 isEditable = editable;
775+
776+ if (isEditable){
777+ labelTitleBG->setOpacity (info.labelColor .a );
778+ menu->setEnabled (true );
779+ menu->setOpacity (255 );
780+ labelTitleArea->setVisible (true );
781+ }
782+ else {
783+ labelTitleBG->setOpacity (info.hideHeader ? 0 : info.labelColor .a );
784+ menu->setEnabled (!info.hideHeader );
785+ menu->setOpacity (info.hideHeader ? 0 : 255 );
786+ if (info.hideHeader && !info.isExpanded )
787+ toggleExpand (nullptr );
788+
789+ labelTitleArea->setVisible (!info.hideHeader );
790+ }
747791}
748792
749793arc::Future<std::string> DTLabel::modifyStrRecursive (const std::string& str){
@@ -828,4 +872,8 @@ void DTLabel::fadeTitleColorTo(ccColor4B newColor, float time){
828872
829873 labelTitleArea->runAction (faceAction);
830874 labelTitleArea->runAction (colorAction);
875+ }
876+
877+ float DTLabel::getSpecificTitleHeight (){
878+ return !info.hideHeader || isEditable ? labelTitleHeight : 0 ;
831879}
0 commit comments