Example #1
0
 private void DownloadFile(MessageViewModel message, DiceStickers stickers)
 {
     if (stickers is DiceStickersRegular regular)
     {
         if (regular.Sticker.StickerValue.Local.CanBeDownloaded && !regular.Sticker.StickerValue.Local.IsDownloadingActive)
         {
             message.ProtoService.DownloadFile(regular.Sticker.StickerValue.Id, 1);
         }
     }
     else if (stickers is DiceStickersSlotMachine slotMachine)
     {
         if (slotMachine.Background.StickerValue.Local.CanBeDownloaded && !slotMachine.Background.StickerValue.Local.IsDownloadingActive)
         {
             message.ProtoService.DownloadFile(slotMachine.Background.StickerValue.Id, 1);
         }
         if (slotMachine.LeftReel.StickerValue.Local.CanBeDownloaded && !slotMachine.LeftReel.StickerValue.Local.IsDownloadingActive)
         {
             message.ProtoService.DownloadFile(slotMachine.LeftReel.StickerValue.Id, 1);
         }
         if (slotMachine.CenterReel.StickerValue.Local.CanBeDownloaded && !slotMachine.CenterReel.StickerValue.Local.IsDownloadingActive)
         {
             message.ProtoService.DownloadFile(slotMachine.CenterReel.StickerValue.Id, 1);
         }
         if (slotMachine.RightReel.StickerValue.Local.CanBeDownloaded && !slotMachine.RightReel.StickerValue.Local.IsDownloadingActive)
         {
             message.ProtoService.DownloadFile(slotMachine.RightReel.StickerValue.Id, 1);
         }
         if (slotMachine.Lever.StickerValue.Local.CanBeDownloaded && !slotMachine.Lever.StickerValue.Local.IsDownloadingActive)
         {
             message.ProtoService.DownloadFile(slotMachine.Lever.StickerValue.Id, 1);
         }
     }
 }
Example #2
0
        public void Dispose()
        {
            //if (_animation is IDisposable disposable)
            //{
            //    Debug.WriteLine("Disposing animation for: " + Path.GetFileName(_source));
            //    disposable.Dispose();
            //}

            //_animation = null;
            _valueState    = null;
            _enqueuedState = null;
            _previousState = null;
        }
Example #3
0
        private void DownloadFile(MessageViewModel message, DiceStickers stickers)
        {
            if (stickers is DiceStickersRegular regular)
            {
                if (regular.Sticker.StickerValue.Local.CanBeDownloaded && !regular.Sticker.StickerValue.Local.IsDownloadingActive)
                {
                    // Unsubscribe all tokens
                    UpdateManager.Unsubscribe(this);

                    UpdateManager.Subscribe(this, message, regular.Sticker.StickerValue, ref _part1Token, UpdateFile, true);
                    message.ProtoService.DownloadFile(regular.Sticker.StickerValue.Id, 1);
                }
            }
            else if (stickers is DiceStickersSlotMachine slotMachine)
            {
                if (slotMachine.Background.StickerValue.Local.CanBeDownloaded && !slotMachine.Background.StickerValue.Local.IsDownloadingActive)
                {
                    UpdateManager.Subscribe(this, message, slotMachine.Background.StickerValue, ref _part1Token, UpdateFile, true);
                    message.ProtoService.DownloadFile(slotMachine.Background.StickerValue.Id, 1);
                }
                if (slotMachine.LeftReel.StickerValue.Local.CanBeDownloaded && !slotMachine.LeftReel.StickerValue.Local.IsDownloadingActive)
                {
                    UpdateManager.Subscribe(this, message, slotMachine.LeftReel.StickerValue, ref _part2Token, UpdateFile, true);
                    message.ProtoService.DownloadFile(slotMachine.LeftReel.StickerValue.Id, 1);
                }
                if (slotMachine.CenterReel.StickerValue.Local.CanBeDownloaded && !slotMachine.CenterReel.StickerValue.Local.IsDownloadingActive)
                {
                    UpdateManager.Subscribe(this, message, slotMachine.CenterReel.StickerValue, ref _part3Token, UpdateFile, true);
                    message.ProtoService.DownloadFile(slotMachine.CenterReel.StickerValue.Id, 1);
                }
                if (slotMachine.RightReel.StickerValue.Local.CanBeDownloaded && !slotMachine.RightReel.StickerValue.Local.IsDownloadingActive)
                {
                    UpdateManager.Subscribe(this, message, slotMachine.RightReel.StickerValue, ref _part4Token, UpdateFile, true);
                    message.ProtoService.DownloadFile(slotMachine.RightReel.StickerValue.Id, 1);
                }
                if (slotMachine.Lever.StickerValue.Local.CanBeDownloaded && !slotMachine.Lever.StickerValue.Local.IsDownloadingActive)
                {
                    UpdateManager.Subscribe(this, message, slotMachine.Lever.StickerValue, ref _part5Token, UpdateFile, true);
                    message.ProtoService.DownloadFile(slotMachine.Lever.StickerValue.Id, 1);
                }
            }
        }
Example #4
0
        public void Unload()
        {
            _shouldPlay = false;
            _unloaded   = true;
            Subscribe(false);

            if (_canvas != null)
            {
                _canvas.CreateResources -= OnCreateResources;
                _canvas.Draw            -= OnDraw;
                _canvas.RemoveFromVisualTree();
                _canvas = null;
            }

            _valueState = null;

            //_bitmap?.Dispose();
            _bitmaps = null;

            //_animation?.Dispose();
            _animations = null;
        }
Example #5
0
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            _shouldPlay = false;
            _unloaded   = true;
            Subscribe(false);

            if (_canvas != null)
            {
                _canvas.CreateResources -= OnCreateResources;
                _canvas.Draw            -= OnDraw;
                _canvas.RemoveFromVisualTree();
                _canvas = null;
            }

            _valueState = null;

            //_bitmap?.Dispose();
            _bitmaps = null;

            //_animation?.Dispose();
            _animations = null;
        }
Example #6
0
        public async void SetValue(DiceStickers state, int newValue)
        {
            var canvas = _canvas;

            if (canvas == null)
            {
                _previous      = newValue;
                _previousState = state;
                return;
            }

            if (state == null)
            {
                //canvas.Paused = true;
                //canvas.ResetElapsedTime();
                Subscribe(false);

                Dispose();
                return;
            }

            if (newValue == _value)
            {
                return;
            }

            if (newValue != _value && /*newValue != _enqueued &&*/ _value == 0)
            {
                if (_subscribed)
                {
                    _shouldPlay    = true;
                    _enqueued      = newValue;
                    _enqueuedState = state;
                    return;
                }
            }

            var force = _enqueued == newValue;

            _value      = newValue;
            _valueState = state;

            _previous      = newValue;
            _previousState = state;

            _enqueued      = 0;
            _enqueuedState = null;

            var initial    = newValue == 0;
            var shouldPlay = _shouldPlay;

            var animations = new LottieAnimation[_parts];
            await Task.Run(() =>
            {
                if (state is DiceStickersSlotMachine slotMachine)
                {
                    animations[0] = _backAnimation ??= LottieAnimation.LoadFromFile(slotMachine.Background.StickerValue.Local.Path, false, null);
                    animations[1] = LottieAnimation.LoadFromData(MergeReels(slotMachine), $"{newValue}", false, null);
                    animations[2] = _frontAnimation ??= LottieAnimation.LoadFromFile(slotMachine.Lever.StickerValue.Local.Path, false, null);
                }
                else if (state is DiceStickersRegular regular)
                {
                    animations[1] = LottieAnimation.LoadFromFile(regular.Sticker.StickerValue.Local.Path, false, null);
                }
            });

            if (_shouldPlay)
            {
                shouldPlay = true;
            }

            _animations          = animations;
            _isLoopingEnabled[1] = initial;

            _animationFrameRate  = animations.Max(x => x?.FrameRate ?? 0);
            _animationTotalFrame = animations.Max(x => x?.TotalFrame ?? 0);

            _startIndex[0] = _animationTotalFrame;

            _index[0] = 1;
            _index[1] = IsContentUnread || initial ? 0 : animations[1].TotalFrame - 1;
            _index[2] = initial ? 0 : _index[2];

            //canvas.Paused = true;
            //canvas.ResetElapsedTime();
            //canvas.TargetElapsedTime = update > TimeSpan.Zero ? update : TimeSpan.MaxValue;

            if (AutoPlay || shouldPlay || force)
            {
                _shouldPlay = false;
                Subscribe(true);
                //canvas.Paused = false;
            }
            else
            {
                Subscribe(false);

                // Invalidate to render the first frame
                Invalidate();
                _canvas?.Invalidate();
            }
        }