Skip to content

Commit bb3e155

Browse files
committed
some UI work
1 parent b143d2c commit bb3e155

3 files changed

Lines changed: 48 additions & 27 deletions

File tree

src/managers/StatsManager.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,15 +661,14 @@ void StatsManager::logRuns(const std::vector<Run>& runs) {
661661

662662
bool StatsManager::safeCheckCurrF0(){
663663
auto from0Res = getGeneral(currentLevel);
664-
if (from0Res.isOk()){
665-
currentFrom0 = from0Res.unwrap();
666-
return true;
667-
}
668-
else{
664+
if (from0Res.isErr() && from0Res.unwrapErr().code != 1) {
669665
currentFrom0 = std::nullopt;
670-
Notification::create("Deat Tracker cant save! File corrupted!")->show();
666+
Notification::create("Death Tracker cant save! File corrupted!")->show();
671667
return false;
672668
}
669+
670+
currentFrom0 = from0Res.unwrap();
671+
return true;
673672
}
674673

675674
/* utility functions

src/nodes/layers/LayoutOptionsLayer.cpp

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ LayoutOptionsLayer* LayoutOptionsLayer::create(const CCSize& size) {
3838
bool LayoutOptionsLayer::init(const CCSize& size) {
3939
if (!CCLayer::init()) return false;
4040

41+
this->size = size;
42+
4143
this->setContentSize(size);
4244

4345
// @geode-ignore(unknown-resource)
@@ -211,9 +213,8 @@ bool LayoutOptionsLayer::init(const CCSize& size) {
211213
scaleSlider = Slider::create(this, menu_selector(LayoutOptionsLayer::scaleSliderChanged), .5f);
212214
scaleSlider->setContentSize({0, 0});
213215
scaleSlider->setPositionY(-215);
214-
scaleSlider->setPositionX(fontSizeInput->getPositionX());
216+
//scaleSlider->setPositionX(fontSizeInput->getPositionX() + 30);
215217
scaleSlider->setID("font-size-slider");
216-
scaleSlider->setScaleX(.7f);
217218
scaleSlider->m_delegate = this;
218219
labelSettingsNode->addChild(scaleSlider);
219220

@@ -296,29 +297,25 @@ bool LayoutOptionsLayer::init(const CCSize& size) {
296297

297298
labelSettingsNode->addChild(wrappingModeBtn);
298299

299-
auto fontSelectionBtnSpr = ButtonSprite::create("Select Font");
300-
fontSelectionBtnSpr->setScale(.55f);
300+
auto fontSelectionBtnSpr = ButtonSprite::create("Choose");
301+
fontSelectionBtnSpr->setScale(.45f);
301302
auto fontSelectionBtn = CCMenuItemSpriteExtra::create(
302303
fontSelectionBtnSpr,
303304
this,
304305
menu_selector(LayoutOptionsLayer::onFontSelection)
305306
);
306307
fontSelectionBtn->setPositionY(-260);
308+
fontSelectionBtn->setPositionX(size.width / 2 - 5 - fontSelectionBtn->getContentWidth() / 2);
307309
fontSelectionBtn->setID("font-selection-btn");
308310
labelSettingsNode->addChild(fontSelectionBtn);
309311

310-
fontSelectedIndicatorLabel = SimpleTextArea::create("Selected: font -1", "gjFont21.fnt");
311-
fontSelectedIndicatorLabel->setID("font-select-indicator-label");
312-
fontSelectedIndicatorLabel->setScale(.4f);
313-
fontSelectedIndicatorLabel->setAlignment(CCTextAlignment::kCCTextAlignmentCenter);
314-
fontSelectedIndicatorLabel->setPosition(fontSelectionBtn->getPosition() + ccp(0, 5 + fontSelectionBtn->getScaledContentHeight() / 2 + fontSelectedIndicatorLabel->getScaledContentHeight() / 2));
315-
labelSettingsNode->addChild(fontSelectedIndicatorLabel);
312+
updateFontSelectFont();
316313

317-
auto fontSelectionBtnLabel = CCLabelBMFont::create("Font", "bigFont.fnt");
318-
fontSelectionBtnLabel->setID("font-selection-label");
319-
fontSelectionBtnLabel->setScale(.4f);
320-
fontSelectionBtnLabel->setPosition(fontSelectedIndicatorLabel->getPosition() + ccp(0, fontSelectedIndicatorLabel->getScaledContentHeight() / 2 + fontSelectionBtnLabel->getScaledContentHeight() / 2));
321-
labelSettingsNode->addChild(fontSelectionBtnLabel);
314+
// auto fontSelectionBtnLabel = CCLabelBMFont::create("Font", "bigFont.fnt");
315+
// fontSelectionBtnLabel->setID("font-selection-label");
316+
// fontSelectionBtnLabel->setScale(.4f);
317+
// fontSelectionBtnLabel->setPosition(fontSelectedIndicatorLabel->getPosition() + ccp(0, fontSelectedIndicatorLabel->getScaledContentHeight() / 2 + fontSelectionBtnLabel->getScaledContentHeight() / 2));
318+
// labelSettingsNode->addChild(fontSelectionBtnLabel);
322319

323320
this->addEventListener(
324321
KeybindSettingPressedEvent(
@@ -543,8 +540,7 @@ void LayoutOptionsLayer::setEditedNodeTo(DTLabel* label) {
543540
);
544541
scaleSliderChanged(nullptr);
545542

546-
fontSelectedIndicatorLabel->setText(fmt::format("selected: \"{}\"", label->info.font.substr(0, label->info.font.length() - 4)));
547-
fontSelectedIndicatorLabel->setFont(label->info.font);
543+
updateFontSelectFont();
548544
if (currentlySelectedFontCell != nullptr)
549545
currentlySelectedFontCell->deselect();
550546
currentlySelectedFontCell = allFontCells[label->info.font];
@@ -776,7 +772,7 @@ void LayoutOptionsLayer::onDelete(CCObject*){
776772
if (onBackedOut != NULL)
777773
onBackedOut();
778774
}
779-
}
775+
}
780776

781777
void LayoutOptionsLayer::onFontSelected(FontSelectionCell* cell){
782778
if (!isEditingNode()) return;
@@ -788,8 +784,7 @@ void LayoutOptionsLayer::onFontSelected(FontSelectionCell* cell){
788784
if (editedLabel.has_value()){
789785
editedLabel.value()->setFont(cell->font);
790786
DTLayer::get()->organizeLayout();
791-
fontSelectedIndicatorLabel->setText(fmt::format("selected: \"{}\"", cell->font.substr(0, cell->font.length() - 4)));
792-
fontSelectedIndicatorLabel->setFont(cell->font);
787+
updateFontSelectFont();
793788
}
794789
}
795790

@@ -884,4 +879,27 @@ void LayoutOptionsLayer::sliderEnded(Slider* slider){
884879
#if defined(GEODE_IS_MOBILE)
885880
sliderUpdate();
886881
#endif
882+
}
883+
884+
void LayoutOptionsLayer::updateFontSelectFont(){
885+
if (!editedLabel.has_value()) return;
886+
887+
if (fontSelectedIndicatorLabel != nullptr)
888+
fontSelectedIndicatorLabel->removeMeAndCleanup();
889+
890+
fontSelectedIndicatorLabel = TextInput::create(
891+
size.width / 2 + 10,
892+
"",
893+
editedLabel.value()->info.font
894+
);
895+
fontSelectedIndicatorLabel->setID("font-select-indicator-label");
896+
fontSelectedIndicatorLabel->setString(fmt::format(
897+
"Font: \"{}\"",
898+
editedLabel.value()->info.font.substr(0, editedLabel.value()->info.font.length() - 4)
899+
));
900+
fontSelectedIndicatorLabel->getInputNode()->setTouchEnabled(false);
901+
fontSelectedIndicatorLabel->setAnchorPoint({0, .5f});
902+
fontSelectedIndicatorLabel->setPosition(ccp(-size.width / 2 + 5, -260));
903+
fontSelectedIndicatorLabel->getBGSprite()->setScaleY(.3f);
904+
labelSettingsNode->addChild(fontSelectedIndicatorLabel);
887905
}

src/nodes/layers/LayoutOptionsLayer.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class LayoutOptionsLayer : public CCLayer, public SliderDelegate {
2929
private:
3030
bool init(const CCSize& size);
3131

32+
CCSize size;
33+
3234
std::optional<DTLabel*> editedLabel = std::nullopt;
3335
std::optional<LayoutColumn*> editedColumn = std::nullopt;
3436

@@ -66,7 +68,7 @@ class LayoutOptionsLayer : public CCLayer, public SliderDelegate {
6668
CCMenuItemSpriteExtra* wrappingModeBtn;
6769

6870
void onFontSelection(CCObject*);
69-
SimpleTextArea* fontSelectedIndicatorLabel;
71+
TextInput* fontSelectedIndicatorLabel;
7072

7173
void onBack(CCObject*);
7274
void onDelete(CCObject*);
@@ -90,4 +92,6 @@ class LayoutOptionsLayer : public CCLayer, public SliderDelegate {
9092

9193
void sliderEnded(Slider* slider) override;
9294
void sliderUpdate();
95+
96+
void updateFontSelectFont();
9397
};

0 commit comments

Comments
 (0)