<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using TCC.Data;

namespace TCC.Controls
{
    /// <summary>
    /// Logica di interazione per FixedSkillControl.xaml
    /// </summary>
    public partial class FixedSkillControl : UserControl, INotifyPropertyChanged
    {
        public FixedSkillControl()
        {
            InitializeComponent();
        }

        FixedSkillCooldown _context;



        private bool isRunning = false;
        public bool IsRunning
        {
            get { return isRunning; }
            set
            {
                if (isRunning == value) return;
                isRunning = value;
                NotifyPropertyChanged("IsRunning");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string p)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p));
        }

        void Control_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this)) return;
            _context = (FixedSkillCooldown)DataContext;
            _context.PropertyChanged += _context_PropertyChanged;
        }

        void _context_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Refresh")
            {
                if (_context.Cooldown == _context.OriginalCooldown) return;
                double newVal = (double)_context.Cooldown / (double)_context.OriginalCooldown;
                if (newVal > 1) newVal = 1;
                if (_context.Cooldown == 0)
                {
                    IsRunning = false;
                    AnimateAvailableSkill();
                    return;
                }

                AnimateArcAngle(newVal);
            }
            else if (e.PropertyName == "Start")
            {
                IsRunning = true;
                AnimateArcAngle();
            }
            else if(e.PropertyName == "IsAvailable")
            {
                if (_context.IsAvailable)
                {
                    IsRunning = false;
                    AnimateAvailableSkill();
                }

            }
        }

        void AnimateArcAngle(double val = 1)
        {
            var an = new DoubleAnimation(val * 359.9, 0, TimeSpan.FromMilliseconds(_context.Cooldown));
            //an.Completed += An_Completed;
            int fps = _context.Cooldown > 80000 ? 1 : 30;
            DoubleAnimation.SetDesiredFrameRate(an, fps);
            arc.BeginAnimation(Arc.EndAngleProperty, an);
        }
        void AnimateArcThickness(double val = 1)<commit_msg>added invoke<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using TCC.Data;

namespace TCC.Controls
{
    /// <summary>
    /// Logica di interazione per FixedSkillControl.xaml
    /// </summary>
    public partial class FixedSkillControl : UserControl, INotifyPropertyChanged
    {
        public FixedSkillControl()
        {
            InitializeComponent();
        }

        FixedSkillCooldown _context;



        private bool isRunning = false;
        public bool IsRunning
        {
            get { return isRunning; }
            set
            {
                if (isRunning == value) return;
                isRunning = value;
                NotifyPropertyChanged("IsRunning");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string p)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p));
        }

        void Control_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this)) return;
            _context = (FixedSkillCooldown)DataContext;
            _context.PropertyChanged += _context_PropertyChanged;
        }

        void _context_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Dispatcher.InvokeIfRequired(() =>
            {
                if (e.PropertyName == "Refresh")
                {
                    if (_context.Cooldown == _context.OriginalCooldown) return;
                    double newVal = (double)_context.Cooldown / (double)_context.OriginalCooldown;
                    if (newVal > 1) newVal = 1;
                    if (_context.Cooldown == 0)
                    {
                        IsRunning = false;
                        AnimateAvailableSkill();
                        return;
                    }

                    AnimateArcAngle(newVal);
                }
                else if (e.PropertyName == "Start")
                {
                    IsRunning = true;
                    AnimateArcAngle();
                }
                else if (e.PropertyName == "IsAvailable")
                {
                    if (_context.IsAvailable)
                    {
                        IsRunning = false;
                        AnimateAvailableSkill();
                    }

                }
            },
            DispatcherPriority.DataBind);

        }

        void AnimateArcAngle(double val = 1)
        {

            var an = new DoubleAnimation(val * 359.9, 0, TimeSpan.FromMilliseconds(_context.Cooldown));
            //an.Completed += An_Completed;
            int fps = _context.Cooldown > 80000 ? 1 : 30;
            DoubleAnimation.SetDesiredFrameRate(an, fps);
            arc.BeginAnimation(Arc.EndAngleProperty, an);

        }
        void AnimateArcThickness(double val = 1)
{'fraction_non_alphanumeric': 0.08294501397949673, 'fraction_numerical': 0.005591798695246971, 'mean_word_length': 1.690764730463853, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1073315', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1569, 'n_words': 339}