Skip to content

Commit 041c8d1

Browse files
committed
added way to hide label header and fixed best runs
1 parent c9e238b commit 041c8d1

7 files changed

Lines changed: 152 additions & 67 deletions

File tree

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "5.6.1",
2+
"geode": "5.7.0",
33
"gd": {
44
"android": "2.2081",
55
"win": "2.2081",

src/managers/StatsManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ Result<std::string> StatsManager::createRunKey(const Run& runKey){
736736
if (runKey.start == std::nullopt){
737737
return Ok(std::to_string(runKey.end));
738738
}
739-
else if (runKey.start >= 0){
740-
return Ok(fmt::format("{}-{}", runKey.start, runKey.end));
739+
else if (runKey.start.value() >= 0){
740+
return Ok(fmt::format("{}-{}", runKey.start.value(), runKey.end));
741741
}
742742

743743
return Err("Bad percentages");

src/nodes/DTLabel.cpp

Lines changed: 101 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -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

226255
void 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

712740
void DTLabel::setTextColor(const ccColor4B& newColor){
@@ -744,6 +772,22 @@ void DTLabel::onBeingEditedEnded(){
744772

745773
void 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

749793
arc::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
}

src/nodes/DTLabel.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ class DTLabel : public CCMenu {
9696
SimpleTextArea* labelTitleArea;
9797

9898
CCNode* labelTextContainer;
99-
//RichTextArea* labelText;
100-
SimpleTextArea* labelText;
99+
RichTextArea* labelText;
101100
float currentHeight;
102101

103102
float normalBGOpacity = 150;
@@ -136,4 +135,6 @@ class DTLabel : public CCMenu {
136135
bool isHovering;
137136

138137
float doubleClickTimer = .2f;
138+
139+
float getSpecificTitleHeight();
139140
};

src/nodes/layers/DTLayer.cpp

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,8 @@ bool DTLayer::createDeathsString(const Deaths& deaths, const LevelMetadeta& meta
12201220

12211221
int hiddenRuns = 0;
12221222

1223+
int runIndex = 0;
1224+
12231225
for (const auto& [run, amount] : deathVec)
12241226
{
12251227
auto runSplitRes = StatsManager::splitRunKey(run);
@@ -1254,6 +1256,11 @@ bool DTLayer::createDeathsString(const Deaths& deaths, const LevelMetadeta& meta
12541256
continue;
12551257
}
12561258
}
1259+
1260+
if (runIndex % 2 == 0){
1261+
nbDeColor = "</cplus>";
1262+
nbColor = fmt::format("<cplus={}>", custom.alternateStrength);
1263+
}
12571264
}
12581265
else if (!includeRunStart && !ignoreExtraSettings){
12591266
//log::info("a {}", runSplit.end);
@@ -1263,8 +1270,12 @@ bool DTLayer::createDeathsString(const Deaths& deaths, const LevelMetadeta& meta
12631270
}
12641271

12651272
if (newBests.has_value() && newBests.value().contains(runSplit.end)){
1266-
nbDeColor = "</wave></color>";
1267-
nbColor = fmt::format("<color={}><wave>", cc3bToHexString(newBestColoring));
1273+
nbDeColor = "</color>";
1274+
nbColor = fmt::format("<color={}>", cc3bToHexString(newBestColoring));
1275+
}
1276+
else if (runIndex % 2 == 0){
1277+
nbDeColor = "</cplus>";
1278+
nbColor = fmt::format("<cplus={}>", custom.alternateStrength);
12681279
}
12691280
}
12701281

@@ -1291,9 +1302,11 @@ bool DTLayer::createDeathsString(const Deaths& deaths, const LevelMetadeta& meta
12911302
);
12921303

12931304
//old coloring
1294-
//out += fmt::format("{}{}{}{}", nbColor, format, nbDeColor, custom.seperator);
1295-
auto toAdd = fmt::format("{}{}", format, custom.seperator);
1296-
out += toAdd;
1305+
out += fmt::format("{}{}{}{}", nbColor, format, nbDeColor, custom.seperator);
1306+
// auto toAdd = fmt::format("{}{}", format, custom.seperator);
1307+
// out += toAdd;
1308+
1309+
runIndex++;
12971310
}
12981311

12991312
if (out == "" && hiddenRuns == 0)
@@ -2899,7 +2912,7 @@ UpdateFuture DTLayer::onBestRunsKey(){
28992912
for (const auto& [bestRunStart, bestRunEnd] : bestRuns)
29002913
{
29012914
co_await arc::yield();
2902-
auto runStringRes = StatsManager::createRunKey(Run{bestRunStart, bestRunEnd});
2915+
auto runStringRes = StatsManager::createRunKey(Run{bestRunStart == -1 ? std::nullopt : std::make_optional(bestRunStart), bestRunEnd});
29032916
if (runStringRes.isErr()) continue;
29042917
auto runString = runStringRes.unwrap();
29052918
if (!deaths.contains(runString)) continue;
@@ -3199,6 +3212,8 @@ UpdateFuture DTLayer::onSectionKey(){
31993212

32003213
auto custom = Save::getFrom0Customazations();
32013214

3215+
int indexofyeah = 0;
3216+
32023217
for (const auto& startIdx : order)
32033218
{
32043219
for (const auto& endIdx : order)
@@ -3211,7 +3226,17 @@ UpdateFuture DTLayer::onSectionKey(){
32113226
format = std::regex_replace(format, std::regex("\\{per\\}"), sectionID);
32123227
format = std::regex_replace(format, std::regex("\\{d\\}"), std::to_string(it->second));
32133228

3214-
out += fmt::format("{}{}", format, custom.seperator);
3229+
std::string keysStart = "";
3230+
std::string keysEnd = "";
3231+
3232+
if (indexofyeah % 2 == 0){
3233+
keysEnd = "</cplus>";
3234+
keysStart = fmt::format("<cplus={}>", custom.alternateStrength);
3235+
}
3236+
3237+
out += fmt::format("{}{}{}{}", keysStart, format, custom.seperator, keysEnd);
3238+
3239+
indexofyeah++;
32153240
}
32163241

32173242
if (startIdx != order.back())

0 commit comments

Comments
 (0)