1- #include " include.h"
21#include " FLAlertLayer.h"
2+ #include " DialogLayer.h"
33
44bool blockKeys = false ;
55
@@ -131,7 +131,6 @@ void DeltaruneAlertLayer::onBtn2(CCObject* sender) {
131131 else if (btnSelected == 1 ) FLAlertLayer::onBtn1 (sender);
132132}
133133void DeltaruneAlertLayer::onBtn1 (CCObject* sender) {
134- bool dialog = m_fields->dialog ;
135134 if (m_fields->incompatible ) {
136135 FLAlertLayer::onBtn1 (sender);
137136 return ;
@@ -374,6 +373,27 @@ void DeltaruneAlertLayer::skipText() {
374373 if (doneRolling) showButtons ();
375374}
376375
376+ int DeltaruneAlertLayer::emptyLinesAmount (int offset) {
377+ auto & textArea = m_fields->textArea ;
378+ auto & linesProgressed = m_fields->linesProgressed ;
379+ auto fontNode = (CCNode*) textArea->getChildren ()->objectAtIndex (0 );
380+ int lines = 0 ;
381+ while (true ) {
382+ auto topLine = (CCLabelBMFont*) fontNode->getChildren ()->objectAtIndex (linesProgressed + lines + offset);
383+ if (!topLine) break ;
384+ std::string topLineString = topLine->getString ();
385+ std::string noSpaceTopLineString = " " ;
386+ std::for_each (topLineString.begin (), topLineString.end (), [&noSpaceTopLineString](char c) {
387+ if (c != ' ' ) noSpaceTopLineString += c;
388+ });
389+ if (noSpaceTopLineString != " " ) break ;
390+ lines++;
391+ m_mainLayer->getChildByID (" star" _spr)->setVisible (true );
392+ if (!Mod::get ()->getSettingValue <bool >(" noShadow" )) m_mainLayer->getChildByID (" starShadow" _spr)->setVisible (true );
393+ }
394+ return lines;
395+ }
396+
377397void DeltaruneAlertLayer::progressText () {
378398 if (!m_mainLayer) return ;
379399 if (!m_buttonMenu) return ;
@@ -393,11 +413,12 @@ void DeltaruneAlertLayer::progressText() {
393413
394414 if (getLinesLeft () <= 3 ) {
395415 if (!m_button2) {
396- bool dialog = m_fields->dialog ;
397- DialogLayer* dialogLayer = m_fields->dialogLayer ;
416+ auto dialogLayer = m_fields->dialogLayer ;
398417 done = true ;
418+ if (m_fields->dialog && dialogLayer) {
419+ dialogLayer->onClose ();
420+ }
399421 FLAlertLayer::onBtn1 (btn1);
400- if (dialog && dialogLayer) dialogLayer->onClose ();
401422 return ;
402423 }
403424 else if (btnSelected != 0 ) {
@@ -426,26 +447,12 @@ void DeltaruneAlertLayer::progressText() {
426447 else if (getLinesLeft () == 3 )
427448 offset = 1 ;
428449
429- auto fontNode = (CCNode*) textArea->getChildren ()->objectAtIndex (0 );
430- bool emptyLinesRemoved = false ;
431- while (true ) {
432- auto topLine = (CCLabelBMFont*) fontNode->getChildren ()->objectAtIndex (linesProgressed + offset);
433- if (!topLine) break ;
434- std::string topLineString = topLine->getString ();
435- std::string noSpaceTopLineString = " " ;
436- std::for_each (topLineString.begin (), topLineString.end (), [&noSpaceTopLineString](char c) {
437- if (c != ' ' ) noSpaceTopLineString += c;
438- });
439- if (noSpaceTopLineString != " " ) break ;
440- offset++;
441- m_mainLayer->getChildByID (" star" _spr)->setVisible (true );
442- if (!noShadow) m_mainLayer->getChildByID (" starShadow" _spr)->setVisible (true );
443- emptyLinesRemoved = true ;
444- }
450+ int emptyLines = emptyLinesAmount (offset);
451+ offset += emptyLines;
445452
446453 auto & characters = m_fields->characterSpriteNames ;
447454 int & dialogCount = m_fields->dialogCount ;
448- if (emptyLinesRemoved && characters.size () > 1 ) {
455+ if (characters.size () > 1 ) {
449456 dialogCount++;
450457 auto & spriteName = characters[dialogCount];
451458 auto prevChar = (CCSpriteGrayscale*) m_mainLayer->getChildByID (" character-sprite" _spr);
@@ -483,70 +490,84 @@ void DeltaruneAlertLayer::rollText(float dt) {
483490 bool & playedSound = m_fields->playedSound ;
484491 bool & doneRolling = m_fields->doneRolling ;
485492 bool & rolledPage = m_fields->rolledPage ;
493+ float & lostTime = m_fields->lostTime ;
494+ float const pause = Mod::get ()->getSettingValue <double >(" textRollingPause" ) / 30 ;
486495
487- if (waitQueue != 0 ) {
488- waitQueue--;
489- playedSound = false ;
490- return ;
491- }
492- CCArrayExt<TextArea*> textAreas = m_fields->textAreaClippingNode ->getChildren ();
493- if (rollingLine == 3 ) {
494- unschedule (schedule_selector (DeltaruneAlertLayer::rollText));
495- rolledPage = true ;
496- return ;
497- }
498- else rolledPage = false ;
496+ if (dt - pause > pause)
497+ lostTime += dt - pause;
499498
500- bool newLine = false ;
501499 bool playSound = true ;
502- for (auto textArea : textAreas) {
503- CCArrayExt<CCLabelBMFont*> lines = static_cast <CCNode*>(textArea->getChildren ()->objectAtIndex (0 ))->getChildren ();
504- int i = linesProgressed + rollingLine;
505- if (i < lines.size () && i < linesProgressed + 3 ) {
506- auto line = lines[i];
507- CCArrayExt<CCNode*> letters = line->getChildren ();
508- auto letter = letters[characterCount];
509- if (letter->isVisible ()) {
500+
501+ for (bool firstRun = true ; lostTime >= pause || firstRun;) {
502+ bool newLine = false ;
503+ firstRun = false ;
504+ if (waitQueue != 0 ) {
505+ waitQueue--;
506+ playedSound = false ;
507+ if (lostTime >= pause && !firstRun) {
508+ lostTime -= pause;
509+ }
510+ continue ;
511+ }
512+ CCArrayExt<TextArea*> textAreas = m_fields->textAreaClippingNode ->getChildren ();
513+ if (rollingLine == 3 ) {
514+ unschedule (schedule_selector (DeltaruneAlertLayer::rollText));
515+ rolledPage = true ;
516+ return ;
517+ }
518+ else rolledPage = false ;
519+
520+ for (auto textArea : textAreas) {
521+ CCArrayExt<CCLabelBMFont*> lines = static_cast <CCNode*>(textArea->getChildren ()->objectAtIndex (0 ))->getChildren ();
522+ int currentLine = linesProgressed + rollingLine;
523+ if (currentLine < lines.size () && currentLine < linesProgressed + 3 ) {
524+ auto line = lines[currentLine];
525+ CCArrayExt<CCNode*> letters = line->getChildren ();
526+ auto letter = letters[characterCount];
527+ if (letter->isVisible ()) {
528+ unschedule (schedule_selector (DeltaruneAlertLayer::rollText));
529+ doneRolling = true ;
530+ rolledPage = true ;
531+ showButtons ();
532+ return ;
533+ }
534+ letter->setVisible (true );
535+ switch (line->getString ()[characterCount]) {
536+ case ' ' :
537+ playSound = false ;
538+ break ;
539+ case ' .' : [[fallthrough]];
540+ case ' ,' : [[fallthrough]];
541+ case ' :' : [[fallthrough]];
542+ case ' ;' : [[fallthrough]];
543+ case ' ?' : [[fallthrough]];
544+ case ' !' :
545+ waitQueue = 2 ;
546+ break ;
547+ default :
548+ break ;
549+ }
550+ if (characterCount == line->getChildrenCount () - 1 ) {
551+ newLine = true ;
552+ }
553+ }
554+ else {
510555 unschedule (schedule_selector (DeltaruneAlertLayer::rollText));
511556 doneRolling = true ;
512557 rolledPage = true ;
513558 showButtons ();
514559 return ;
515560 }
516- letter->setVisible (true );
517- switch (line->getString ()[characterCount]) {
518- case ' ' :
519- playSound = false ;
520- break ;
521- case ' .' : [[fallthrough]];
522- case ' ,' : [[fallthrough]];
523- case ' :' : [[fallthrough]];
524- case ' ;' : [[fallthrough]];
525- case ' ?' : [[fallthrough]];
526- case ' !' :
527- waitQueue = 2 ;
528- break ;
529- default :
530- break ;
531- }
532- if (characterCount == line->getChildrenCount () - 1 ) {
533- newLine = true ;
534- }
535561 }
536- else {
537- unschedule (schedule_selector (DeltaruneAlertLayer::rollText));
538- doneRolling = true ;
539- rolledPage = true ;
540- showButtons ();
541- return ;
562+ characterCount++;
563+ if (newLine) {
564+ characterCount = 0 ;
565+ rollingLine++;
566+ }
567+ if (lostTime >= pause && !firstRun) {
568+ lostTime -= pause;
542569 }
543570 }
544- characterCount++;
545- if (newLine) {
546- characterCount = 0 ;
547- rollingLine++;
548- }
549-
550571 auto nameToFile = m_fields->nameToFile ;
551572 std::string const textSound = m_fields->textSound ;
552573 std::string const resFolder = Mod::get ()->getResourcesDir ().string ();
0 commit comments