Advertisement
revenant-smg

FNF Cutscenes like Hex

Sep 16th, 2021
1,622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 8.80 KB | None | 0 0
  1. package;
  2.  
  3. import flixel.FlxG;
  4. import flixel.FlxSprite;
  5. import flixel.addons.text.FlxTypeText;
  6. import flixel.graphics.frames.FlxAtlasFrames;
  7. import flixel.group.FlxSpriteGroup;
  8. import flixel.input.FlxKeyManager;
  9. import flixel.text.FlxText;
  10. import flixel.util.FlxColor;
  11. import flixel.util.FlxTimer;
  12.  
  13. using StringTools;
  14.  
  15. class DialogueBox extends FlxSpriteGroup
  16. {
  17.     var box:FlxSprite;
  18.     var daBg:FlxSprite;
  19.  
  20.     var curCharacter:String = '';
  21.  
  22.     var dialogue:Alphabet;
  23.     var dialogueList:Array<String> = [];
  24.     var whitelisted:Array<String> = [];
  25.  
  26.     // SECOND DIALOGUE FOR THE PIXEL SHIT INSTEAD???
  27.     var swagDialogue:FlxTypeText;
  28.  
  29.     var dropText:FlxText;
  30.  
  31.     public var finishThing:Void->Void;
  32.     public var isFade:Bool = false;
  33.     public var paused:Bool = false;
  34.  
  35.     var portraitLeft:FlxSprite;
  36.     var portraitRight:FlxSprite;
  37.     var portraitGF:FlxSprite;
  38.  
  39.     var handSelect:FlxSprite;
  40.     var bgFade:FlxSprite;
  41.  
  42.     public function new(talkingRight:Bool = true, ?dialogueList:Array<String>)
  43.     {
  44.         super();
  45.  
  46.         switch (PlayState.SONG.song.toLowerCase())
  47.         {
  48.             case 'senpai':
  49.                 FlxG.sound.playMusic(Paths.music('Lunchbox'), 0);
  50.                 FlxG.sound.music.fadeIn(1, 0, 0.8);
  51.             case 'thorns':
  52.                 FlxG.sound.playMusic(Paths.music('LunchboxScary'), 0);
  53.                 FlxG.sound.music.fadeIn(1, 0, 0.8);
  54.         }
  55.  
  56.         bgFade = new FlxSprite(-200, -200).makeGraphic(Std.int(FlxG.width * 1.3), Std.int(FlxG.height * 1.3), 0xFFB3DFd8);
  57.         bgFade.scrollFactor.set();
  58.         bgFade.alpha = 0;
  59.         add(bgFade);
  60.  
  61.         new FlxTimer().start(0.83, function(tmr:FlxTimer)
  62.         {
  63.             bgFade.alpha += (1 / 5) * 0.7;
  64.             if (bgFade.alpha > 0.7)
  65.                 bgFade.alpha = 0.7;
  66.         }, 5);
  67.  
  68.         box = new FlxSprite(-20, 45);
  69.        
  70.         var hasDialog = false;
  71.         switch (PlayState.SONG.song.toLowerCase())
  72.         {
  73.             case 'senpai':
  74.                 hasDialog = true;
  75.                 box.frames = Paths.getSparrowAtlas('weeb/pixelUI/dialogueBox-pixel');
  76.                 box.animation.addByPrefix('normalOpen', 'Text Box Appear', 24, false);
  77.                 box.animation.addByIndices('normal', 'Text Box Appear', [4], "", 24);
  78.             case 'roses':
  79.                 hasDialog = true;
  80.                 FlxG.sound.play(Paths.sound('ANGRY_TEXT_BOX'));
  81.  
  82.                 box.frames = Paths.getSparrowAtlas('weeb/pixelUI/dialogueBox-senpaiMad');
  83.                 box.animation.addByPrefix('normalOpen', 'SENPAI ANGRY IMPACT SPEECH', 24, false);
  84.                 box.animation.addByIndices('normal', 'SENPAI ANGRY IMPACT SPEECH', [4], "", 24);
  85.  
  86.             case 'thorns':
  87.                 hasDialog = true;
  88.                 box.frames = Paths.getSparrowAtlas('weeb/pixelUI/dialogueBox-evil');
  89.                 box.animation.addByPrefix('normalOpen', 'Spirit Textbox spawn', 24, false);
  90.                 box.animation.addByIndices('normal', 'Spirit Textbox spawn', [11], "", 24);
  91.  
  92.                 var face:FlxSprite = new FlxSprite(320, 170).loadGraphic(Paths.image('weeb/spiritFaceForward'));
  93.                 face.setGraphicSize(Std.int(face.width * 6));
  94.                 add(face);
  95.                
  96.             default:
  97.                 hasDialog = true;
  98.                 box.loadGraphic(Paths.image('resources/txtbox'),true,1280,720);
  99.                 box.animation.add('normalOpen', [0], 0);
  100.                 box.animation.add('normal', [0], 0);
  101.                 box.setPosition();
  102.  
  103.         }
  104.  
  105.         this.dialogueList = dialogueList;
  106.        
  107.         if (!hasDialog)
  108.             return;
  109.        
  110.         daBg = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
  111.         daBg.antialiasing = true;
  112.         add(daBg);
  113.         daBg.visible = false;
  114.  
  115.         portraitLeft = new FlxSprite(-20, 40);
  116.         portraitLeft.frames = Paths.getSparrowAtlas('resources/dadport');
  117.         portraitLeft.animation.addByPrefix('enter', 'bfport', 24, false);
  118.         portraitLeft.updateHitbox();
  119.         portraitLeft.scrollFactor.set();
  120.         portraitLeft.setPosition(-855.5,  160.95);
  121.         portraitLeft.visible = false;
  122.  
  123.         portraitRight = new FlxSprite(0, 40);
  124.         portraitRight.frames = Paths.getSparrowAtlas('resources/bfport');
  125.         portraitRight.animation.addByPrefix('enter', 'bfport', 24, false);
  126.         portraitRight.updateHitbox();
  127.         portraitRight.scrollFactor.set();
  128.         portraitRight.setPosition(854.4, 160.95);
  129.         portraitRight.visible = false;
  130.  
  131.         portraitGF = new FlxSprite(0, 40);
  132.         portraitGF.frames = Paths.getSparrowAtlas('resources/gfport');
  133.         portraitGF.animation.addByPrefix('enter', 'gf port idle', 24, false);
  134.         portraitGF.updateHitbox();
  135.         portraitGF.scrollFactor.set();
  136.         portraitGF.setPosition(854.4, 160.95);
  137.         portraitGF.visible = false;
  138.        
  139.         box.animation.play('normalOpen');
  140.         if(PlayState.curStage != 'stage')box.setGraphicSize(Std.int(box.width * PlayState.daPixelZoom * 0.9));
  141.         box.updateHitbox();
  142.         add(box);
  143.  
  144.         add(portraitRight);
  145.         add(portraitLeft);
  146.         add(portraitGF);
  147.  
  148.         box.screenCenter(X);
  149.         portraitLeft.screenCenter(X);
  150.  
  151.         handSelect = new FlxSprite(FlxG.width * 0.9, FlxG.height * 0.9).loadGraphic(Paths.image('weeb/pixelUI/hand_textbox'));
  152.         add(handSelect);
  153.  
  154.  
  155.         if (!talkingRight)
  156.         {
  157.             // box.flipX = true;
  158.         }
  159.  
  160.         dropText = new FlxText(242, 502, Std.int(FlxG.width * 0.6), "", 32);
  161.         dropText.font = 'Pixel Arial 11 Bold';
  162.         dropText.color = 0xFFD89494;
  163.         add(dropText);
  164.  
  165.         swagDialogue = new FlxTypeText(240, 500, Std.int(FlxG.width * 0.6), "", 32);
  166.         swagDialogue.font = 'Pixel Arial 11 Bold';
  167.         swagDialogue.color = 0xFF3F2021;
  168.         swagDialogue.sounds = [FlxG.sound.load(Paths.sound('pixelText'), 0.6)];
  169.         add(swagDialogue);
  170.  
  171.         dialogue = new Alphabet(0, 80, "", false, true);
  172.         // dialogue.x = 90;
  173.         // add(dialogue);
  174.     }
  175.  
  176.     var dialogueOpened:Bool = false;
  177.     var dialogueStarted:Bool = false;
  178.  
  179.     override function update(elapsed:Float)
  180.     {
  181.         // HARD CODING CUZ IM STUPDI
  182.         if (PlayState.SONG.song.toLowerCase() == 'roses')
  183.             portraitLeft.visible = false;
  184.         if (PlayState.SONG.song.toLowerCase() == 'thorns')
  185.         {
  186.             portraitLeft.color = FlxColor.BLACK;
  187.             swagDialogue.color = FlxColor.WHITE;
  188.             dropText.color = FlxColor.BLACK;
  189.         }
  190.  
  191.         dropText.text = swagDialogue.text;
  192.  
  193.         if (box.animation.curAnim != null)
  194.         {
  195.             if (box.animation.curAnim.name == 'normalOpen' && box.animation.curAnim.finished)
  196.             {
  197.                 box.animation.play('normal');
  198.                 dialogueOpened = true;
  199.             }
  200.         }
  201.  
  202.         if (dialogueOpened && !dialogueStarted)
  203.         {
  204.             startDialogue();
  205.             dialogueStarted = true;
  206.         }
  207.  
  208.         whitelisted = ['bg'];
  209.  
  210.         if (!paused && !isFade && !whitelisted.contains(curCharacter)) {
  211.             box.alpha = 1;
  212.             swagDialogue.alpha = 1;
  213.         } else {
  214.             box.alpha = 0;
  215.             swagDialogue.alpha = 0;
  216.         }
  217.  
  218.         if ((FlxG.keys.justPressed.ANY) || (dialogueList.length > 0 && whitelisted.contains(curCharacter)) && dialogueStarted == true && !paused && !isFade)
  219.         {
  220.             remove(dialogue);
  221.                
  222.             FlxG.sound.play(Paths.sound('clickText'), 0.8);
  223.  
  224.             if (!paused && !isFade)
  225.             {
  226.  
  227.                 switch(curCharacter)
  228.                 {
  229.                     case 'bg':
  230.                     daBg.loadGraphic(Paths.image(dialogueList[0]));
  231.                     daBg.visible = true;
  232.                 }
  233.  
  234.                 if (whitelisted.contains(curCharacter))
  235.                 {
  236.                     box.alpha = 0;
  237.                     swagDialogue.alpha = 0;
  238.                 }
  239.  
  240.                 remove(dialogue);
  241.  
  242.             }
  243.  
  244.             if (dialogueList[1] == null && dialogueList[0] != null)
  245.             {
  246.                 if (!isEnding)
  247.                 {
  248.                     isEnding = true;
  249.  
  250.                     if (PlayState.SONG.song.toLowerCase() == 'senpai' || PlayState.SONG.song.toLowerCase() == 'thorns')
  251.                         FlxG.sound.music.fadeOut(2.2, 0);
  252.  
  253.                     new FlxTimer().start(0.2, function(tmr:FlxTimer)
  254.                     {
  255.                         box.alpha -= 1 / 5;
  256.                         bgFade.alpha -= 1 / 5 * 0.7;
  257.                         portraitLeft.visible = false;
  258.                         portraitRight.visible = false;
  259.                         portraitGF.visible = false;
  260.                         daBg.alpha -= 1 / 5;
  261.                         swagDialogue.alpha -= 1 / 5;
  262.                         dropText.alpha = swagDialogue.alpha;
  263.                     }, 5);
  264.  
  265.                     new FlxTimer().start(1.2, function(tmr:FlxTimer)
  266.                     {
  267.                         finishThing();
  268.                         kill();
  269.                     });
  270.                 }
  271.             }
  272.             else
  273.             {
  274.                 dialogueList.remove(dialogueList[0]);
  275.                 startDialogue();
  276.             }
  277.         }
  278.        
  279.         super.update(elapsed);
  280.     }
  281.  
  282.     var isEnding:Bool = false;
  283.  
  284.     function hidePortraits():Void
  285.         {
  286.             portraitLeft.visible = false;
  287.             portraitRight.visible = false;
  288.             portraitGF.visible = false;
  289.  
  290.             swagDialogue.visible = true;
  291.             dropText.visible = true;
  292.         }
  293.  
  294.     function startDialogue():Void
  295.     {
  296.         cleanDialog();
  297.         // var theDialog:Alphabet = new Alphabet(0, 70, dialogueList[0], false, true);
  298.         // dialogue = theDialog;
  299.         // add(theDialog);
  300.  
  301.         // swagDialogue.text = ;
  302.         swagDialogue.resetText(dialogueList[0]);
  303.         swagDialogue.start(0.04, true);
  304.  
  305.         switch (curCharacter)
  306.         {
  307.             case 'dad':
  308.                 hidePortraits();
  309.                 if (!portraitLeft.visible)
  310.                 {
  311.                     portraitLeft.visible = true;
  312.                     portraitLeft.animation.play('enter');
  313.                 }
  314.             case 'bf':
  315.                 hidePortraits();
  316.                 if (!portraitRight.visible)
  317.                 {
  318.                     portraitRight.visible = true;
  319.                     portraitRight.animation.play('enter');
  320.                 }
  321.             case 'gf':
  322.                 hidePortraits();
  323.                 if (!portraitGF.visible)
  324.                 {
  325.                     portraitGF.visible = true;
  326.                     portraitGF.animation.play('enter');
  327.                 }
  328.         }
  329.     }
  330.  
  331.     function cleanDialog():Void
  332.     {
  333.         var splitName:Array<String> = dialogueList[0].split(":");
  334.         curCharacter = splitName[1];
  335.         dialogueList[0] = dialogueList[0].substr(splitName[1].length + 2).trim();
  336.     }
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement