@@ -7,6 +7,38 @@ float randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber(float
77 return static_cast <float >(rand () % static_cast <int >(range * 100 + 1 )) / 100 .f - (range / 2 .f );
88}
99
10+ void DeltaruneAlertLayer::initMaps () {
11+ auto & nameToFile = m_fields->nameToFile ;
12+ auto & nameToSound = m_fields->nameToSound ;
13+
14+ nameToFile[" Default" ] = " SND_TXT1" ;
15+ nameToFile[" Typewriter" ] = " SND_TXT2" ;
16+ nameToFile[" Toriel" ] = " snd_txttor" ;
17+ nameToFile[" Sans" ] = " snd_txtsans" ;
18+ nameToFile[" Papyrus" ] = " snd_txtpap" ;
19+ nameToFile[" Undyne" ] = " snd_txtund" ;
20+ nameToFile[" Alphys" ] = " snd_txtal" ;
21+ nameToFile[" Asgore" ] = " snd_txtasg" ;
22+ nameToFile[" Asriel" ] = " snd_txtasr" ;
23+ nameToFile[" Susie" ] = " snd_txtsus" ;
24+ nameToFile[" Ralsei" ] = " snd_txtral" ;
25+ nameToFile[" Lancer" ] = " snd_txtlan" ;
26+ nameToFile[" Noelle" ] = " snd_txtnoe" ;
27+ nameToFile[" Berdly" ] = " snd_txtber" ;
28+ nameToFile[" Spamton" ] = " snd_txtspam" ;
29+ nameToFile[" Spamton NEO" ] = " snd_txtspam2" ;
30+ nameToFile[" Jevil" ] = " snd_txtjok" ;
31+ nameToFile[" Queen" ] = " snd_txtq" ;
32+
33+ nameToSound[" The Mechanic" ] = " Alphys" ;
34+ nameToSound[" The Shopkeeper" ] = " Spamton" ;
35+ nameToSound[" Scratch" ] = " Lancer" ;
36+ nameToSound[" Potbor" ] = " Spamton NEO" ;
37+ nameToSound[" Diamond Shopkeeper" ] = " Papyrus" ;
38+ nameToSound[" The Keymaster" ] = " Susie" ;
39+
40+ }
41+
1042bool DeltaruneAlertLayer::init (FLAlertLayerProtocol* delegate, char const * title, gd::string desc, char const * btn1, char const * btn2, float width, bool scroll, float height, float textScale) {
1143 float & screenSize = m_fields->screenSize ;
1244 if (screenSize >= 569 && !m_fields->dontRestrictWidth )
@@ -19,17 +51,20 @@ bool DeltaruneAlertLayer::init(FLAlertLayerProtocol* delegate, char const* title
1951
2052 NodeIDs::provideFor (this );
2153 setID (" FLAlertLayer" );
22- if (Loader::get ()->isModLoaded (" firee.prism" )) {
54+ if (Loader::get ()->isModLoaded (" firee.prism" )) { // probably the easiest way to detect a Prism Menu alert :3
2355 if (desc == " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ) {
2456 m_fields->incompatible = true ;
2557 return true ;
2658 }
2759 }
2860
61+
2962 auto & textArea = m_fields->textArea ;
3063 auto & bg = m_fields->bg ;
3164 auto & titleNode = m_fields->title ;
3265
66+ initMaps (); // for sounds
67+
3368 this ->m_noElasticity = true ;
3469
3570 m_fields->btn1 = m_button1 ? this ->m_button1 ->getParent () : nullptr ;
@@ -220,7 +255,7 @@ void DeltaruneAlertLayer::keyDown(enumKeyCodes key) {
220255 progressText ();
221256 return ;
222257 }
223- else if (key == enumKeyCodes::KEY_X || key == enumKeyCodes::KEY_Shift || key == enumKeyCodes::CONTROLLER_B) {
258+ else if (key == enumKeyCodes::KEY_X || key == enumKeyCodes::KEY_Space || key == enumKeyCodes::CONTROLLER_B) {
224259 skipText ();
225260 return ;
226261 }
@@ -321,46 +356,37 @@ void DeltaruneAlertLayer::progressText() {
321356 }
322357 else if (btnSelected != 0 ) {
323358 done = true ;
324- if (btnSelected == 1 )
325- FLAlertLayer::onBtn1 (btn1);
326- else if (btnSelected == 2 )
327- FLAlertLayer::onBtn2 (btn2);
359+ if (btnSelected == 1 ) FLAlertLayer::onBtn1 (btn1);
360+ else if (btnSelected == 2 ) FLAlertLayer::onBtn2 (btn2);
328361 return ;
329362 }
330363 }
364+ // Don't progress if there's only a choice left!
331365 if (getLinesLeft () < 3 && m_button2)
332366 return ;
333367
334- // move EVERYTHING up
335-
368+ // Move EVERYTHING up
369+
336370 int offset;
337-
338371 m_mainLayer->getChildByID (" star" _spr)->setVisible (false );
339-
340372 if (!noShadow) m_mainLayer->getChildByID (" starShadow" _spr)->setVisible (false );
341-
342-
343373
344374 unschedule (schedule_selector (DeltaruneAlertLayer::rollText));
345375 m_fields->characterCount = 0 ;
346376 m_fields->rollingLine = 0 ;
347377
348-
349378 if (getLinesLeft () > 3 )
350379 offset = 3 ;
351380 else if (getLinesLeft () == 3 )
352- offset = 2 ;
353-
381+ offset = 1 ;
354382
355383 auto fontNode = (CCNode*) textArea->getChildren ()->objectAtIndex (0 );
356-
357-
358384 while (true ) {
359385 auto topLine = (CCLabelBMFont*) fontNode->getChildren ()->objectAtIndex (linesProgressed + offset);
360386 if (!topLine) break ;
361387 std::string topLineString = topLine->getString ();
362388 std::string noSpaceTopLineString = " " ;
363- std::for_each (topLineString.begin (), topLineString.end (), [&](char c) {
389+ std::for_each (topLineString.begin (), topLineString.end (), [&noSpaceTopLineString ](char c) {
364390 if (c != ' ' ) noSpaceTopLineString += c;
365391 });
366392 if (noSpaceTopLineString != " " ) break ;
@@ -369,20 +395,16 @@ void DeltaruneAlertLayer::progressText() {
369395 if (!noShadow) m_mainLayer->getChildByID (" starShadow" _spr)->setVisible (true );
370396 }
371397
372-
373398 linesProgressed += offset;
374399 textArea->setPositionY (textArea->getPositionY () + m_fields->textSize * offset);
375- if (gradientOverlay)
376- gradientOverlay->setPositionY (textArea->getPositionY ());
377- if (shadow)
378- shadow->setPositionY (textArea->getPositionY () - 1 );
379-
400+ if (gradientOverlay) gradientOverlay->setPositionY (textArea->getPositionY ());
401+ if (shadow) shadow->setPositionY (textArea->getPositionY () - 1 );
380402
381403 showButtons ();
382404 float pause = Mod::get ()->getSettingValue <double >(" textRollingPause" );
383405 schedule (schedule_selector (DeltaruneAlertLayer::rollText), pause / 30 );
384- log::info (" Finished" );
385406}
407+
386408void DeltaruneAlertLayer::rollText (float dt) {
387409 int & waitQueue = m_fields->waitQueue ;
388410 int & linesProgressed = m_fields->linesProgressed ;
@@ -454,44 +476,30 @@ void DeltaruneAlertLayer::rollText(float dt) {
454476 characterCount = 0 ;
455477 rollingLine++;
456478 }
457- if (playSound) {
458- if (playedSound) {
459- playedSound = false ;
460- return ;
461- }
462- float pitch = 1 ;
463- playedSound = true ;
464- std::string sound = " " ;
465- if (sound == " Default" ) sound = " SND_TXT1" ;
466- else if (sound == " Typewriter" ) sound = " SND_TXT2" ;
467- else if (sound == " Toriel" ) sound = " snd_txttor" ;
468- else if (sound == " Sans" ) sound = " snd_txtsans" ;
469- else if (sound == " Papyrus" ) sound = " snd_txtpap" ;
470- else if (sound == " Undyne" ) sound = " snd_txtund" ;
471- else if (sound == " Alphys" ) sound = " snd_txtal" ;
472- else if (sound == " Asgore" ) sound = " snd_txtasg" ;
473- else if (sound == " Asriel" ) sound = " snd_txtasr" ;
474- else if (sound == " Susie" ) sound = " snd_txtsus" ;
475- else if (sound == " Ralsei" ) sound = " snd_txtral" ;
476- else if (sound == " Lancer" ) sound = " snd_txtlan" ;
477- else if (sound == " Noelle" ) sound = " snd_txtnoe" ;
478- else if (sound == " Berdly" ) sound = " snd_txtber" ;
479- else if (sound == " Spamton" ) sound = " snd_txtspam" ;
480- else if (sound == " Spamton NEO" ) sound = " snd_txtspam2" ;
481- else if (sound == " Jevil" ) sound = " snd_txtjok" ;
482- else if (sound == " Queen" ) {
483- sound = " snd_txtq" ;
484- pitch = 1 + randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber (0 .2f );
485- }
486- std::string path = fmt::format (" {}/{}.wav" , Mod::get ()->getResourcesDir ().string (), sound);
487- auto & system = m_fields->system ;
488- auto & fmodSound = m_fields->sound ;
489- auto & channel = m_fields->channel ;
490-
491- system->createSound (path.c_str (), FMOD_DEFAULT, nullptr , &fmodSound);
492- system->playSound (fmodSound, nullptr , false , &channel);
493- channel->setPitch (pitch);
494- channel->setVolume (FMODAudioEngine::sharedEngine ()->m_sfxVolume );
479+
480+ auto nameToFile = m_fields->nameToFile ;
481+ std::string const textSound = m_fields->textSound ;
482+ std::string const resFolder = Mod::get ()->getResourcesDir ().string ();
483+ std::string path = fmt::format (" {}/{}.wav" , resFolder, nameToFile[textSound]);
484+
485+ if (nameToFile.find (textSound) == nameToFile.end ()) return ;
486+
487+ if (!playSound || playedSound) {
488+ playedSound = false ;
489+ return ;
495490 }
496- else playedSound = false ;
491+ float pitch = 1 ;
492+ playedSound = true ;
493+
494+ auto & system = m_fields->system ;
495+ auto & channel = m_fields->channel ;
496+ auto & sound = m_fields->sound ;
497+
498+ if (textSound == " Queen" )
499+ pitch = 1 + randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber (0 .2f );
500+
501+ system->createSound (path.c_str (), FMOD_DEFAULT, nullptr , &sound);
502+ system->playSound (sound, nullptr , false , &channel);
503+ channel->setPitch (pitch);
504+ channel->setVolume (FMODAudioEngine::sharedEngine ()->m_sfxVolume );
497505}
0 commit comments