Skip to content

File Celebration.cs

File List > LemonUI > LemonUI > Scaleform > Celebration.cs

Go to the documentation of this file


#if ALTV
using AltV.Net.Client;
#elif FIVEM
using CitizenFX.Core;
using CitizenFX.Core.Native;
#elif RAGEMP
using RAGE.Game;
#elif RPH
using Rage;
using Rage.Native;
#elif SHVDN3 || SHVDNC
using GTA;
using GTA.Native;
#endif
using System;

namespace LemonUI.Scaleform
{
    public class Celebration : CelebrationCore
    {
        #region Fields

        private long showUntil = 0;
        private bool cancel = false;
        private string mode = string.Empty;
        private string job = string.Empty;
        private string challenge = string.Empty;

        #endregion

        #region Properties

        public CelebrationBackground Background { get; } = new CelebrationBackground();
        public CelebrationForeground Foreground { get; } = new CelebrationForeground();

        public string Mode
        {
            get => mode;
            set => mode = value ?? throw new ArgumentNullException(nameof(value));
        }

        public string Job
        {
            get => job;
            set => job = value ?? throw new ArgumentNullException(nameof(value));
        }

        public string Challenge
        {
            get => challenge;
            set => challenge = value ?? throw new ArgumentNullException(nameof(value));
        }
        public int Duration { get; set; } = 2;
        public CelebrationStyle Style { get; set; } = CelebrationStyle.Clean;

        #endregion

        #region Events

        public event EventHandler Shown;
        public event EventHandler Finished;

        #endregion

        #region Constructors

        public Celebration() : base("MP_CELEBRATION")
        {
        }

        #endregion

        #region Tools

        private void CallFunctionOnAll(string function, params object[] parameters)
        {
            Background.CallFunction(function, parameters);
            Foreground.CallFunction(function, parameters);
            CallFunction(function, parameters);
        }

        #endregion

        #region Functions

        public void Show()
        {
            cancel = false;
            Visible = true;

            const string wallId = "intro";

            CallFunctionOnAll("CLEANUP", wallId);
            CallFunctionOnAll("CREATE_STAT_WALL", wallId, "HUD_COLOUR_BLACK", 40);

            CallFunctionOnAll("SET_PAUSE_DURATION", Duration);
            // challengeTextLabel appears to be used as a bool and challengePartsText is appended
            CallFunctionOnAll("ADD_INTRO_TO_WALL", wallId, Mode, Job, true, Challenge, string.Empty, Challenge, Duration, string.Empty, true, "HUD_COLOUR_WHITE");
            CallFunctionOnAll("ADD_BACKGROUND_TO_WALL", wallId, 75, (int)Style);
            CallFunctionOnAll("SHOW_STAT_WALL", wallId);

            Shown?.Invoke(this, EventArgs.Empty);

            // Explanation for future me
            // 333ms going in
            // 333ms going out
#if ALTV
            long time = Alt.Natives.GetGameTimer();
#elif RAGEMP
            long time = Misc.GetGameTimer();
#elif FIVEM || RPH || SHVDN3 || SHVDNC
            long time = Game.GameTime;
#endif
            showUntil = time + 333 + 333 + (Duration * 1000);
        }
        public void Cancel()
        {
            if (Visible)
            {
                cancel = true;
            }
        }
        public override void Process()
        {
            if (!Visible)
            {
                return;
            }

            if (cancel)
            {
                showUntil = -1;
                Visible = false;
                return;
            }

            DrawFullScreen();

#if ALTV
            long time = Alt.Natives.GetGameTimer();
#elif RAGEMP
            long time = Misc.GetGameTimer();
#elif FIVEM || RPH || SHVDN3 || SHVDNC
            long time = Game.GameTime;
#endif

            if (showUntil < time)
            {
                showUntil = 0;
                Visible = false;
                Finished?.Invoke(this, EventArgs.Empty);
            }
        }
        public override void DrawFullScreen()
        {
            if (!Visible)
            {
                return;
            }

            #if ALTV
            Alt.Natives.DrawScaleformMovieFullscreenMasked(Background.Handle, Foreground.Handle, 255, 255, 255, 255);
            Alt.Natives.DrawScaleformMovieFullscreen(Handle, 255, 255, 255, 255, 255);
            #elif FIVEM
            API.DrawScaleformMovieFullscreenMasked(Background.Handle, Foreground.Handle, 255, 255, 255, 255);
            API.DrawScaleformMovieFullscreen(Handle, 255, 255, 255, 255, 255);
            #elif RAGEMP
            Invoker.Invoke(Natives.DrawScaleformMovieFullscreenMasked, Background.Handle, Foreground.Handle, 255, 255, 255, 255);
            Invoker.Invoke(Natives.DrawScaleformMovieFullscreen, Handle, 255, 255, 255, 255);
            #elif RPH
            NativeFunction.CallByHash<int>(0xCF537FDE4FBD4CE5, Background.Handle, Foreground.Handle, 255, 255, 255, 255);
            NativeFunction.CallByHash<int>(0x0DF606929C105BE1, Handle, 255, 255, 255, 255);
            #elif SHVDN3
            Function.Call(Hash.DRAW_SCALEFORM_MOVIE_FULLSCREEN_MASKED, Background.Handle, Foreground.Handle, 255, 255, 255, 255);
            Function.Call(Hash.DRAW_SCALEFORM_MOVIE_FULLSCREEN, Handle, 255, 255, 255, 255);
            #endif
        }

        #endregion
    }
}