Пример #1
0
        // close
        void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            // opacity animation
            var opacityAnim = new DoubleAnimation(0, TimeSpan.FromMilliseconds(600));

            // scale Y animation
            SineEase easingFunction = new SineEase();
            easingFunction.EasingMode = EasingMode.EaseIn;
            var sclaeYAnim = new DoubleAnimation(0.001, TimeSpan.FromMilliseconds(300));
            sclaeYAnim.EasingFunction = easingFunction;

            // scale X animation
            var scaleXAnim = new DoubleAnimation(0, TimeSpan.FromMilliseconds(200));
            scaleXAnim.BeginTime = TimeSpan.FromMilliseconds(300);

            // storyboard
            var storyboard = new Storyboard();

            Storyboard.SetTargetProperty(opacityAnim, new PropertyPath(UIElement.OpacityProperty));
            Storyboard.SetTargetName(sclaeYAnim, "MyAnimatedScaleTransform");
            Storyboard.SetTargetProperty(sclaeYAnim, new PropertyPath(ScaleTransform.ScaleYProperty));
            Storyboard.SetTargetName(scaleXAnim, "MyAnimatedScaleTransform");
            Storyboard.SetTargetProperty(scaleXAnim, new PropertyPath(ScaleTransform.ScaleXProperty));

            storyboard.Children.Add(opacityAnim);
            storyboard.Children.Add(sclaeYAnim);
            storyboard.Children.Add(scaleXAnim);

            storyboard.Completed += delegate { window.Close(); };

            window.BeginStoryboard(storyboard);
        }
Пример #2
0
        public static EasingFunctionBase GetEasingFunction()
        {
            EasingFunctionBase result = null;
            switch (random.Next(5))
            {
                case 0:
                    result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 };
                    break;
                case 1:
                    result = new BounceEase() { EasingMode = EasingMode.EaseOut, Bounces = 3, Bounciness = 8 };
                    break;
                case 2:
                    result = new CircleEase() { EasingMode = EasingMode.EaseInOut };
                    break;
                case 3:
                    result = new CubicEase() { EasingMode = EasingMode.EaseIn };
                    break;
                case 4:
                    result = new ElasticEase() { EasingMode = EasingMode.EaseOut, Oscillations = 3, Springiness = 4 };
                    break;
                case 5:
                    result = new SineEase() { EasingMode = EasingMode.EaseInOut };
                    break;
                default:
                    result = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 };
                    break;
            }

            return result;
        }
Пример #3
0
        public static void Animate(this DependencyObject target, double from, double to, object propertyPath, int duration, int startTime, IEasingFunction easing = null, Action completed = null)
        {
            if (easing == null)
                easing = new SineEase();

            var db = new DoubleAnimation();
            db.To = to;
            db.From = from;
            db.EasingFunction = easing;
            db.Duration = TimeSpan.FromMilliseconds(duration);

            Storyboard.SetTarget(db, target);
            Storyboard.SetTargetProperty(db, new PropertyPath(propertyPath));

            var sb = new Storyboard();
            sb.BeginTime = TimeSpan.FromMilliseconds(startTime);

            if (completed != null)
            {
                sb.Completed += (s, e) => completed();
            }

            sb.Children.Add(db);
            sb.Begin();
        }
Пример #4
0
        public static void Animate(this DependencyObject target, double? from, double? to, object propertyPath,
                                   int duration, int startTime,
                                   IEasingFunction easing = null, Action completed = null)
        
        {
            if (easing == null)
                easing = new SineEase();

            var animation = new DoubleAnimation
            {
                To = to,
                From = @from,
                EasingFunction = easing,
                Duration = TimeSpan.FromMilliseconds(duration)
            };
            Storyboard.SetTarget(animation, target);
            Storyboard.SetTargetProperty(animation, new PropertyPath(propertyPath));

            var storyBoard = new Storyboard {BeginTime = TimeSpan.FromMilliseconds(startTime)};

            if (completed != null)
                storyBoard.Completed += (sender, args) => completed();

            storyBoard.Children.Add(animation);
            storyBoard.Begin();
        }
        public void confirmDenyPhoto(bool _yesNo)
        {

            // Hide the yes and no buttons
            DoubleAnimation daHeight = new DoubleAnimation(0, 150, new Duration(TimeSpan.FromSeconds(0.3)));
            DoubleAnimation daFHeight = new DoubleAnimation(0, 150, new Duration(TimeSpan.FromSeconds(0.3)));
            SineEase ease = new SineEase();
            ease.EasingMode = EasingMode.EaseIn;
            daHeight.EasingFunction = ease;
            daFHeight.EasingFunction = ease;
            daFHeight.BeginTime = TimeSpan.FromSeconds(0.2);
            YNSpacer2.BeginAnimation(Canvas.HeightProperty, daFHeight);
            YNSpacer.BeginAnimation(Canvas.HeightProperty, daHeight);
            //btnYes.BeginAnimation(Button.MarginProperty

            // Show take photo
            DoubleAnimation daOpacity = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(0.5)));
            txtTakePhoto.Text = "TAKE PHOTO";
            txtTakePhoto.BeginAnimation(TextBlock.OpacityProperty, daOpacity);
            txtStartCountdown.BeginAnimation(TextBlock.OpacityProperty, daOpacity);

            if (_yesNo == true)
            {
                // Captions
                requestNewCaption(ApplicationStates.STATE_PHOTO_SUBMITTED, false);
                saveImageFrame();
            }
            else
            {
                // Captions
                requestNewCaption(ApplicationStates.STATE_PHOTO_DESTROYED, false);
                freezePhoto = false;
            }
        }
Пример #6
0
        public Agent(string name)
        {
            InitializeComponent();

            this.characterName = name;
            this.cachedBitmapImageDictionary = new Dictionary<string, BitmapImage>();
            this.cachedMotionList = new List<Motion>();
            this.fadeStoryboardDictionary = new Dictionary<Storyboard, Window>();
            this.imageStoryboardDictionary = new Dictionary<Image, Storyboard>();
            this.queue = new System.Collections.Queue();
            this.motionQueue = new Queue<Motion>();
            this.ContextMenu = new ContextMenu();

            MenuItem opacityMenuItem = new MenuItem();
            MenuItem scalingMenuItem = new MenuItem();
            MenuItem refreshMenuItem = new MenuItem();
            MenuItem topmostMenuItem = new MenuItem();
            MenuItem showInTaskbarMenuItem = new MenuItem();
            MenuItem muteMenuItem = new MenuItem();
            MenuItem charactersMenuItem = new MenuItem();
            MenuItem updateMenuItem = new MenuItem();
            MenuItem exitMenuItem = new MenuItem();
            double opacity = 1;
            double scale = 2;

            opacityMenuItem.Header = Properties.Resources.Opacity;

            do
            {
                MenuItem menuItem = new MenuItem();

                menuItem.Header = String.Concat(((int)Math.Floor(opacity * 100)).ToString(System.Globalization.CultureInfo.CurrentCulture), Properties.Resources.Percent);
                menuItem.Tag = opacity;
                menuItem.Click += new RoutedEventHandler(delegate
                {
                    foreach (Window window in Application.Current.Windows)
                    {
                        Agent agent = window as Agent;

                        if (agent != null)
                        {
                            agent.opacity = (double)menuItem.Tag;

                            Storyboard storyboard1 = new Storyboard();
                            DoubleAnimation doubleAnimation1 = new DoubleAnimation(agent.Opacity, agent.opacity, TimeSpan.FromMilliseconds(500));

                            foreach (KeyValuePair<Storyboard, Window> kvp in agent.fadeStoryboardDictionary)
                            {
                                kvp.Key.Stop(kvp.Value);
                            }

                            agent.fadeStoryboardDictionary.Clear();

                            if (agent.Opacity < agent.opacity)
                            {
                                SineEase sineEase = new SineEase();

                                sineEase.EasingMode = EasingMode.EaseOut;
                                doubleAnimation1.EasingFunction = sineEase;
                            }
                            else if (agent.Opacity > agent.opacity)
                            {
                                SineEase sineEase = new SineEase();

                                sineEase.EasingMode = EasingMode.EaseIn;
                                doubleAnimation1.EasingFunction = sineEase;
                            }

                            doubleAnimation1.CurrentStateInvalidated += new EventHandler(delegate (object s, EventArgs e)
                            {
                                if (((Clock)s).CurrentState == ClockState.Filling)
                                {
                                    agent.Opacity = agent.opacity;
                                    storyboard1.Remove(agent);
                                    agent.fadeStoryboardDictionary.Remove(storyboard1);
                                }
                            });

                            storyboard1.Children.Add(doubleAnimation1);

                            Storyboard.SetTargetProperty(doubleAnimation1, new PropertyPath(Window.OpacityProperty));

                            agent.fadeStoryboardDictionary.Add(storyboard1, agent);
                            agent.BeginStoryboard(storyboard1, HandoffBehavior.SnapshotAndReplace, true);

                            if (agent.balloon.Opacity != 1)
                            {
                                Storyboard storyboard2 = new Storyboard();
                                DoubleAnimation doubleAnimation2 = new DoubleAnimation(agent.balloon.Opacity, 1, TimeSpan.FromMilliseconds(500));
                                SineEase sineEase = new SineEase();

                                sineEase.EasingMode = EasingMode.EaseOut;

                                doubleAnimation2.EasingFunction = sineEase;
                                doubleAnimation2.CurrentStateInvalidated += new EventHandler(delegate (object s, EventArgs e)
                                {
                                    if (((Clock)s).CurrentState == ClockState.Filling)
                                    {
                                        agent.balloon.Opacity = 1;
                                        storyboard2.Remove(agent.balloon);
                                        agent.fadeStoryboardDictionary.Remove(storyboard2);
                                    }
                                });

                                storyboard2.Children.Add(doubleAnimation2);

                                Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath(Window.OpacityProperty));

                                agent.fadeStoryboardDictionary.Add(storyboard2, agent.balloon);
                                agent.balloon.BeginStoryboard(storyboard2, HandoffBehavior.SnapshotAndReplace, true);
                            }
                        }
                    }
                });

                opacityMenuItem.Items.Add(menuItem);
                opacity -= 0.1;
            } while (Math.Floor(opacity * 100) > 0);

            scalingMenuItem.Header = Properties.Resources.Scaling;

            do
            {
                MenuItem menuItem = new MenuItem();

                menuItem.Header = String.Concat(((int)Math.Floor(scale * 100)).ToString(System.Globalization.CultureInfo.CurrentCulture), Properties.Resources.Percent);
                menuItem.Tag = scale;
                menuItem.Click += new RoutedEventHandler(delegate
                {
                    foreach (Window window in Application.Current.Windows)
                    {
                        Agent agent = window as Agent;

                        if (agent != null)
                        {
                            agent.scale = (double)menuItem.Tag;

                            foreach (Character character in from character in Script.Instance.Characters where character.Name.Equals(agent.characterName) select character)
                            {
                                Storyboard storyboard = new Storyboard();
                                DoubleAnimation doubleAnimation1 = new DoubleAnimation(agent.ZoomScaleTransform.ScaleX, agent.scale, TimeSpan.FromMilliseconds(500));
                                DoubleAnimation doubleAnimation2 = new DoubleAnimation(agent.ZoomScaleTransform.ScaleY, agent.scale, TimeSpan.FromMilliseconds(500));
                                DoubleAnimation doubleAnimation3 = new DoubleAnimation(agent.LayoutRoot.Width, character.Size.Width * agent.scale, TimeSpan.FromMilliseconds(500));
                                DoubleAnimation doubleAnimation4 = new DoubleAnimation(agent.LayoutRoot.Height, character.Size.Height * agent.scale, TimeSpan.FromMilliseconds(500));

                                if (agent.scaleStoryboard != null)
                                {
                                    agent.scaleStoryboard.Stop(agent.LayoutRoot);
                                }

                                if (agent.ZoomScaleTransform.ScaleX < agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseOut;
                                    doubleAnimation1.EasingFunction = sineEase;
                                }
                                else if (agent.ZoomScaleTransform.ScaleX > agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseIn;
                                    doubleAnimation1.EasingFunction = sineEase;
                                }

                                if (agent.ZoomScaleTransform.ScaleY < agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseOut;
                                    doubleAnimation2.EasingFunction = sineEase;
                                }
                                else if (agent.ZoomScaleTransform.ScaleY > agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseIn;
                                    doubleAnimation2.EasingFunction = sineEase;
                                }

                                if (agent.LayoutRoot.Width < character.Size.Width * agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseOut;
                                    doubleAnimation3.EasingFunction = sineEase;
                                }
                                else if (agent.LayoutRoot.Width > character.Size.Width * agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseIn;
                                    doubleAnimation3.EasingFunction = sineEase;
                                }

                                if (agent.LayoutRoot.Height < character.Size.Height * agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseOut;
                                    doubleAnimation4.EasingFunction = sineEase;
                                }
                                else if (agent.LayoutRoot.Height > character.Size.Height * agent.scale)
                                {
                                    SineEase sineEase = new SineEase();

                                    sineEase.EasingMode = EasingMode.EaseIn;
                                    doubleAnimation4.EasingFunction = sineEase;
                                }

                                storyboard.CurrentStateInvalidated += new EventHandler(delegate (object s, EventArgs e)
                                {
                                    if (((Clock)s).CurrentState == ClockState.Filling)
                                    {
                                        agent.ZoomScaleTransform.ScaleX = agent.scale;
                                        agent.ZoomScaleTransform.ScaleY = agent.scale;

                                        foreach (Character c in from c in Script.Instance.Characters where c.Name.Equals(agent.characterName) select c)
                                        {
                                            agent.LayoutRoot.Width = c.Size.Width * agent.scale;
                                            agent.LayoutRoot.Height = c.Size.Height * agent.scale;
                                        }

                                        storyboard.Remove(agent.LayoutRoot);
                                        agent.scaleStoryboard = null;
                                    }
                                });
                                storyboard.Children.Add(doubleAnimation1);
                                storyboard.Children.Add(doubleAnimation2);
                                storyboard.Children.Add(doubleAnimation3);
                                storyboard.Children.Add(doubleAnimation4);

                                Storyboard.SetTargetProperty(doubleAnimation1, new PropertyPath("(0).(1).(2)", ContentControl.ContentProperty, Canvas.RenderTransformProperty, ScaleTransform.ScaleXProperty));
                                Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath("(0).(1).(2)", ContentControl.ContentProperty, Canvas.RenderTransformProperty, ScaleTransform.ScaleYProperty));
                                Storyboard.SetTargetProperty(doubleAnimation3, new PropertyPath(ContentControl.WidthProperty));
                                Storyboard.SetTargetProperty(doubleAnimation4, new PropertyPath(ContentControl.HeightProperty));

                                agent.scaleStoryboard = storyboard;
                                agent.LayoutRoot.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, true);
                            }
                        }
                    }
                });

                scalingMenuItem.Items.Add(menuItem);
                scale -= 0.25;
            } while (Math.Floor(scale * 100) > 0);

            refreshMenuItem.Header = Properties.Resources.Refresh;
            refreshMenuItem.Click += new RoutedEventHandler(delegate
            {
                foreach (Window window in Application.Current.Windows)
                {
                    Agent agent = window as Agent;

                    if (agent != null)
                    {
                        agent.Render();
                    }
                }
            });
            topmostMenuItem.Header = Properties.Resources.Topmost;
            topmostMenuItem.IsCheckable = true;
            topmostMenuItem.Click += new RoutedEventHandler(delegate
            {
                foreach (Window window in Application.Current.Windows)
                {
                    if (window is Agent && window == Application.Current.MainWindow)
                    {
                        window.Topmost = topmostMenuItem.IsChecked;
                    }
                }
            });
            showInTaskbarMenuItem.Header = Properties.Resources.ShowInTaskbar;
            showInTaskbarMenuItem.IsCheckable = true;
            showInTaskbarMenuItem.Click += new RoutedEventHandler(delegate
            {
                foreach (Window window in Application.Current.Windows)
                {
                    if (window is Agent)
                    {
                        window.ShowInTaskbar = showInTaskbarMenuItem.IsChecked;
                    }
                }
            });
            muteMenuItem.Header = Properties.Resources.Mute;
            muteMenuItem.IsCheckable = true;
            muteMenuItem.Click += new RoutedEventHandler(delegate
            {
                foreach (Window window in Application.Current.Windows)
                {
                    Agent agent = window as Agent;

                    if (agent != null)
                    {
                        agent.isMute = muteMenuItem.IsChecked;
                    }
                }
            });
            charactersMenuItem.Header = Properties.Resources.Characters;
            updateMenuItem.Header = Properties.Resources.Update;
            updateMenuItem.Click += new RoutedEventHandler(delegate
            {
                Script.Instance.Update(true);
            });
            exitMenuItem.Header = Properties.Resources.Exit;
            exitMenuItem.Click += new RoutedEventHandler(delegate
            {
                if (Script.Instance.Enabled)
                {
                    Script.Instance.Enabled = false;
                }
            });

            this.ContextMenu.Items.Add(opacityMenuItem);
            this.ContextMenu.Items.Add(scalingMenuItem);
            this.ContextMenu.Items.Add(refreshMenuItem);
            this.ContextMenu.Items.Add(new Separator());
            this.ContextMenu.Items.Add(topmostMenuItem);
            this.ContextMenu.Items.Add(showInTaskbarMenuItem);
            this.ContextMenu.Items.Add(new Separator());
            this.ContextMenu.Items.Add(muteMenuItem);
            this.ContextMenu.Items.Add(new Separator());
            this.ContextMenu.Items.Add(charactersMenuItem);
            this.ContextMenu.Items.Add(new Separator());
            this.ContextMenu.Items.Add(updateMenuItem);
            this.ContextMenu.Items.Add(new Separator());
            this.ContextMenu.Items.Add(exitMenuItem);
            this.ContextMenu.Opened += new RoutedEventHandler(delegate
            {
                Agent agent = Application.Current.MainWindow as Agent;

                if (agent != null)
                {
                    foreach (MenuItem menuItem in opacityMenuItem.Items)
                    {
                        menuItem.IsChecked = Math.Floor((double)menuItem.Tag * 100) == Math.Floor(agent.Opacity * 100);
                    }

                    foreach (MenuItem menuItem in scalingMenuItem.Items)
                    {
                        menuItem.IsChecked = Math.Floor((double)menuItem.Tag * 100) == Math.Floor(agent.ZoomScaleTransform.ScaleX * 100) && Math.Floor((double)menuItem.Tag * 100) == Math.Floor(agent.ZoomScaleTransform.ScaleY * 100);
                    }

                    topmostMenuItem.IsChecked = agent.Topmost;
                    showInTaskbarMenuItem.IsChecked = agent.ShowInTaskbar;
                    muteMenuItem.IsChecked = agent.isMute;

                    List<MenuItem> menuItemList = new List<MenuItem>(charactersMenuItem.Items.Cast<MenuItem>());
                    HashSet<string> pathHashSet = new HashSet<string>();
                    LinkedList<KeyValuePair<Character, string>> characterLinkedList = new LinkedList<KeyValuePair<Character, string>>();

                    foreach (Character character in Script.Instance.Characters)
                    {
                        string path = Path.IsPathRooted(character.Script) ? character.Script : Path.GetFullPath(character.Script);

                        if (!pathHashSet.Contains(path))
                        {
                            pathHashSet.Add(path);
                        }

                        characterLinkedList.AddLast(new KeyValuePair<Character, string>(character, path));
                    }

                    List<KeyValuePair<string, string>> keyValuePairList = (from fileName in Directory.EnumerateFiles(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "*", SearchOption.AllDirectories) let extension = Path.GetExtension(fileName) let isZip = extension.Equals(".zip", StringComparison.OrdinalIgnoreCase) where isZip || extension.Equals(".xml", StringComparison.OrdinalIgnoreCase) select new KeyValuePair<bool, string>(isZip, fileName)).Concat(from path in pathHashSet select new KeyValuePair<bool, string>(Path.GetExtension(path).Equals(".zip", StringComparison.OrdinalIgnoreCase), path)).Aggregate<KeyValuePair<bool, string>, List<KeyValuePair<string, string>>>(new List<KeyValuePair<string, string>>(), (list, kvp1) =>
                    {
                        if (!list.Exists(delegate (KeyValuePair<string, string> kvp2)
                        {
                            return kvp2.Value.Equals(kvp1.Value);
                        }))
                        {
                            if (kvp1.Key)
                            {
                                FileStream fs = null;

                                try
                                {
                                    fs = new FileStream(kvp1.Value, FileMode.Open, FileAccess.Read, FileShare.Read);

                                    using (ZipArchive zipArchive = new ZipArchive(fs))
                                    {
                                        fs = null;

                                        foreach (ZipArchiveEntry zipArchiveEntry in from zipArchiveEntry in zipArchive.Entries where zipArchiveEntry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) select zipArchiveEntry)
                                        {
                                            Stream stream = null;

                                            try
                                            {
                                                stream = zipArchiveEntry.Open();

                                                foreach (string attribute in from attribute in ((System.Collections.IEnumerable)XDocument.Load(stream).XPathEvaluate("/script/character/@name")).Cast<XAttribute>() select attribute.Value)
                                                {
                                                    list.Add(new KeyValuePair<string, string>(attribute, kvp1.Value));
                                                }
                                            }
                                            catch
                                            {
                                                return list;
                                            }
                                            finally
                                            {
                                                if (stream != null)
                                                {
                                                    stream.Close();
                                                }
                                            }
                                        }
                                    }
                                }
                                finally
                                {
                                    if (fs != null)
                                    {
                                        fs.Close();
                                    }
                                }
                            }
                            else
                            {
                                FileStream fs = null;

                                try
                                {
                                    fs = new FileStream(kvp1.Value, FileMode.Open, FileAccess.Read, FileShare.Read);

                                    foreach (string attribute in from attribute in ((System.Collections.IEnumerable)XDocument.Load(fs).XPathEvaluate("/script/character/@name")).Cast<XAttribute>() select attribute.Value)
                                    {
                                        list.Add(new KeyValuePair<string, string>(attribute, kvp1.Value));
                                    }
                                }
                                catch
                                {
                                    return list;
                                }
                                finally
                                {
                                    if (fs != null)
                                    {
                                        fs.Close();
                                    }
                                }
                            }
                        }

                        return list;
                    });

                    charactersMenuItem.Items.Clear();

                    keyValuePairList.Sort(delegate (KeyValuePair<string, string> kvp1, KeyValuePair<string, string> kvp2)
                    {
                        return String.Compare(kvp1.Key, kvp2.Key, StringComparison.CurrentCulture);
                    });
                    keyValuePairList.ForEach(delegate (KeyValuePair<string, string> kvp)
                    {
                        for (LinkedListNode<KeyValuePair<Character, string>> nextLinkedListNode = characterLinkedList.First; nextLinkedListNode != null; nextLinkedListNode = nextLinkedListNode.Next)
                        {
                            if (nextLinkedListNode.Value.Key.Name.Equals(kvp.Key) && nextLinkedListNode.Value.Value.Equals(kvp.Value))
                            {
                                MenuItem selectedMenuItem = menuItemList.Find(delegate (MenuItem menuItem)
                                {
                                    return kvp.Key.Equals(menuItem.Header as string) && kvp.Value.Equals(menuItem.Tag as string) && (menuItem.IsChecked || menuItem.HasItems);
                                });

                                if (selectedMenuItem == null)
                                {
                                    selectedMenuItem = new MenuItem();
                                    selectedMenuItem.Header = kvp.Key;
                                    selectedMenuItem.Tag = kvp.Value;
                                }
                                else
                                {
                                    selectedMenuItem.Items.Clear();
                                    menuItemList.Remove(selectedMenuItem);
                                }

                                charactersMenuItem.Items.Add(selectedMenuItem);

                                List<MenuItem> childMenuItemList = new List<MenuItem>();
                                Dictionary<string, SortedSet<int>> dictionary = new Dictionary<string, SortedSet<int>>();
                                List<string> motionTypeList = new List<string>();

                                this.cachedMotionList.ForEach(delegate (Motion motion)
                                {
                                    if (motion.Type != null)
                                    {
                                        SortedSet<int> sortedSet;

                                        if (dictionary.TryGetValue(motion.Type, out sortedSet))
                                        {
                                            if (!sortedSet.Contains(motion.ZIndex))
                                            {
                                                sortedSet.Add(motion.ZIndex);
                                            }
                                        }
                                        else
                                        {
                                            sortedSet = new SortedSet<int>();
                                            sortedSet.Add(motion.ZIndex);
                                            dictionary.Add(motion.Type, sortedSet);
                                            motionTypeList.Add(motion.Type);
                                        }
                                    }
                                });

                                motionTypeList.Sort(delegate (string s1, string s2)
                                {
                                    return String.Compare(s1, s2, StringComparison.CurrentCulture);
                                });
                                motionTypeList.ForEach(delegate (string type)
                                {
                                    foreach (MenuItem menuItem in selectedMenuItem.Items)
                                    {
                                        if (type.Equals(menuItem.Header as string))
                                        {
                                            if (nextLinkedListNode.Value.Key.HasTypes)
                                            {
                                                menuItem.IsChecked = nextLinkedListNode.Value.Key.Types.Contains(menuItem.Header as string);
                                            }
                                            else
                                            {
                                                menuItem.IsChecked = false;
                                            }

                                            childMenuItemList.Add(menuItem);

                                            return;
                                        }
                                    }

                                    MenuItem childMenuItem = new MenuItem();

                                    childMenuItem.Header = type;
                                    childMenuItem.Tag = nextLinkedListNode.Value.Key.Name;
                                    childMenuItem.Click += new RoutedEventHandler(delegate
                                    {
                                        string tag = childMenuItem.Tag as string;

                                        if (tag != null)
                                        {
                                            foreach (Character c in from c in Script.Instance.Characters where c.Name.Equals(tag) select c)
                                            {
                                                foreach (Window window in Application.Current.Windows)
                                                {
                                                    Agent a = window as Agent;

                                                    if (a != null && c.Name.Equals(a.characterName))
                                                    {
                                                        string header = childMenuItem.Header as string;

                                                        a.Render();

                                                        if (c.Types.Contains(header))
                                                        {
                                                            c.Types.Remove(header);
                                                        }
                                                        else if (header != null)
                                                        {
                                                            SortedSet<int> sortedSet1;

                                                            if (dictionary.TryGetValue(header, out sortedSet1))
                                                            {
                                                                foreach (string s in c.Types.ToArray())
                                                                {
                                                                    SortedSet<int> sortedSet2;

                                                                    if (dictionary.TryGetValue(s, out sortedSet2) && sortedSet1.SequenceEqual(sortedSet2))
                                                                    {
                                                                        c.Types.Remove(s);
                                                                    }
                                                                }
                                                            }

                                                            c.Types.Add(header);
                                                        }

                                                        foreach (Image image in a.Canvas.Children.Cast<Image>())
                                                        {
                                                            Image i = image;
                                                            Motion motion = i.Tag as Motion;

                                                            if (motion != null)
                                                            {
                                                                List<string> typeList = null;
                                                                bool isVisible;

                                                                if (motion.Type == null)
                                                                {
                                                                    typeList = new List<string>();
                                                                    a.cachedMotionList.ForEach(delegate (Motion m)
                                                                    {
                                                                        if (m.ZIndex == motion.ZIndex)
                                                                        {
                                                                            typeList.Add(m.Type);
                                                                        }
                                                                    });
                                                                }

                                                                if (typeList == null)
                                                                {
                                                                    if (c.HasTypes)
                                                                    {
                                                                        typeList = new List<string>();
                                                                        a.cachedMotionList.ForEach(delegate (Motion m)
                                                                        {
                                                                            if (m.ZIndex == motion.ZIndex && c.Types.Contains(m.Type))
                                                                            {
                                                                                typeList.Add(m.Type);
                                                                            }
                                                                        });
                                                                        isVisible = typeList.Count > 0 && typeList.LastIndexOf(motion.Type) == typeList.Count - 1;
                                                                    }
                                                                    else
                                                                    {
                                                                        isVisible = false;
                                                                    }
                                                                }
                                                                else if (c.HasTypes)
                                                                {
                                                                    isVisible = !typeList.Exists(delegate (string t)
                                                                    {
                                                                        return c.Types.Contains(t);
                                                                    });
                                                                }
                                                                else
                                                                {
                                                                    isVisible = true;
                                                                }

                                                                if (isVisible && (i.Visibility != Visibility.Visible || i.OpacityMask != null))
                                                                {
                                                                    LinearGradientBrush linearGradientBrush = i.OpacityMask as LinearGradientBrush;

                                                                    if (linearGradientBrush == null)
                                                                    {
                                                                        GradientStopCollection gradientStopCollection = new GradientStopCollection();

                                                                        gradientStopCollection.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0));
                                                                        gradientStopCollection.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 1));

                                                                        i.OpacityMask = linearGradientBrush = new LinearGradientBrush(gradientStopCollection, new Point(0.5, 0), new Point(0.5, 1));
                                                                    }

                                                                    Storyboard storyboard;
                                                                    ColorAnimation colorAnimation1 = new ColorAnimation(linearGradientBrush.GradientStops[0].Color, Color.FromArgb(Byte.MaxValue, 0, 0, 0), TimeSpan.FromMilliseconds(250));
                                                                    ColorAnimation colorAnimation2 = new ColorAnimation(linearGradientBrush.GradientStops[1].Color, Color.FromArgb(Byte.MaxValue, 0, 0, 0), TimeSpan.FromMilliseconds(250));
                                                                    SineEase sineEase1 = new SineEase();
                                                                    SineEase sineEase2 = new SineEase();

                                                                    if (a.imageStoryboardDictionary.TryGetValue(i, out storyboard))
                                                                    {
                                                                        storyboard.Stop(i);
                                                                        a.imageStoryboardDictionary[i] = storyboard = new Storyboard();
                                                                    }
                                                                    else
                                                                    {
                                                                        storyboard = new Storyboard();
                                                                        a.imageStoryboardDictionary.Add(i, storyboard);
                                                                    }

                                                                    sineEase1.EasingMode = sineEase2.EasingMode = EasingMode.EaseInOut;

                                                                    colorAnimation1.EasingFunction = sineEase1;
                                                                    colorAnimation2.BeginTime = TimeSpan.FromMilliseconds(250);
                                                                    colorAnimation2.EasingFunction = sineEase2;

                                                                    storyboard.CurrentStateInvalidated += new EventHandler(delegate (object s, EventArgs e)
                                                                    {
                                                                        if (((Clock)s).CurrentState == ClockState.Filling)
                                                                        {
                                                                            i.OpacityMask = null;
                                                                            a.Render();
                                                                            storyboard.Remove(i);
                                                                            a.imageStoryboardDictionary.Remove(i);
                                                                        }
                                                                    });
                                                                    storyboard.Children.Add(colorAnimation1);
                                                                    storyboard.Children.Add(colorAnimation2);

                                                                    Storyboard.SetTargetProperty(colorAnimation1, new PropertyPath("(0).(1)[0].(2)", Image.OpacityMaskProperty, LinearGradientBrush.GradientStopsProperty, GradientStop.ColorProperty));
                                                                    Storyboard.SetTargetProperty(colorAnimation2, new PropertyPath("(0).(1)[1].(2)", Image.OpacityMaskProperty, LinearGradientBrush.GradientStopsProperty, GradientStop.ColorProperty));

                                                                    i.Visibility = Visibility.Visible;
                                                                    i.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, true);
                                                                }
                                                                else if (!isVisible && (i.Visibility == Visibility.Visible || i.OpacityMask != null))
                                                                {
                                                                    LinearGradientBrush linearGradientBrush = i.OpacityMask as LinearGradientBrush;

                                                                    if (linearGradientBrush == null)
                                                                    {
                                                                        GradientStopCollection gradientStopCollection = new GradientStopCollection();

                                                                        gradientStopCollection.Add(new GradientStop(Color.FromArgb(Byte.MaxValue, 0, 0, 0), 0));
                                                                        gradientStopCollection.Add(new GradientStop(Color.FromArgb(Byte.MaxValue, 0, 0, 0), 1));

                                                                        i.OpacityMask = linearGradientBrush = new LinearGradientBrush(gradientStopCollection, new Point(0.5, 0), new Point(0.5, 1));
                                                                    }

                                                                    Storyboard storyboard;
                                                                    ColorAnimation colorAnimation1 = new ColorAnimation(linearGradientBrush.GradientStops[0].Color, Color.FromArgb(0, 0, 0, 0), TimeSpan.FromMilliseconds(250));
                                                                    ColorAnimation colorAnimation2 = new ColorAnimation(linearGradientBrush.GradientStops[1].Color, Color.FromArgb(0, 0, 0, 0), TimeSpan.FromMilliseconds(250));
                                                                    SineEase sineEase1 = new SineEase();
                                                                    SineEase sineEase2 = new SineEase();

                                                                    if (a.imageStoryboardDictionary.TryGetValue(i, out storyboard))
                                                                    {
                                                                        storyboard.Stop(i);
                                                                        a.imageStoryboardDictionary[i] = storyboard = new Storyboard();
                                                                    }
                                                                    else
                                                                    {
                                                                        storyboard = new Storyboard();
                                                                        a.imageStoryboardDictionary.Add(i, storyboard);
                                                                    }

                                                                    sineEase1.EasingMode = sineEase2.EasingMode = EasingMode.EaseInOut;

                                                                    colorAnimation1.EasingFunction = sineEase1;
                                                                    colorAnimation2.BeginTime = TimeSpan.FromMilliseconds(250);
                                                                    colorAnimation2.EasingFunction = sineEase2;

                                                                    storyboard.CurrentStateInvalidated += new EventHandler(delegate (object s, EventArgs e)
                                                                    {
                                                                        if (((Clock)s).CurrentState == ClockState.Filling)
                                                                        {
                                                                            i.OpacityMask = null;
                                                                            a.Render();
                                                                            storyboard.Remove(i);
                                                                            a.imageStoryboardDictionary.Remove(i);
                                                                        }
                                                                    });
                                                                    storyboard.Children.Add(colorAnimation1);
                                                                    storyboard.Children.Add(colorAnimation2);

                                                                    Storyboard.SetTargetProperty(colorAnimation1, new PropertyPath("(0).(1)[0].(2)", Image.OpacityMaskProperty, LinearGradientBrush.GradientStopsProperty, GradientStop.ColorProperty));
                                                                    Storyboard.SetTargetProperty(colorAnimation2, new PropertyPath("(0).(1)[1].(2)", Image.OpacityMaskProperty, LinearGradientBrush.GradientStopsProperty, GradientStop.ColorProperty));

                                                                    i.BeginStoryboard(storyboard, HandoffBehavior.SnapshotAndReplace, true);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    });

                                    if (nextLinkedListNode.Value.Key.HasTypes)
                                    {
                                        childMenuItem.IsChecked = nextLinkedListNode.Value.Key.Types.Contains(childMenuItem.Header as string);
                                    }
                                    else
                                    {
                                        childMenuItem.IsChecked = false;
                                    }

                                    childMenuItemList.Add(childMenuItem);
                                });

                                selectedMenuItem.Items.Clear();

                                if (childMenuItemList.Count > 0)
                                {
                                    selectedMenuItem.IsChecked = false;
                                    childMenuItemList.ForEach(delegate (MenuItem mi)
                                    {
                                        selectedMenuItem.Items.Add(mi);
                                    });
                                }
                                else
                                {
                                    selectedMenuItem.IsChecked = true;
                                }

                                characterLinkedList.Remove(nextLinkedListNode);

                                return;
                            }
                        }

                        MenuItem unselectedMenuItem = menuItemList.Find(delegate (MenuItem menuItem)
                        {
                            return kvp.Key.Equals(menuItem.Header as string) && kvp.Value.Equals(menuItem.Tag as string) && !menuItem.IsChecked && !menuItem.HasItems;
                        });

                        if (unselectedMenuItem == null)
                        {
                            unselectedMenuItem = new MenuItem();
                            unselectedMenuItem.Header = kvp.Key;
                            unselectedMenuItem.Tag = kvp.Value;
                            unselectedMenuItem.Click += new RoutedEventHandler(delegate
                            {
                                string tag = unselectedMenuItem.Tag as string;

                                if (tag != null)
                                {
                                    List<Character> characterList = new List<Character>();

                                    if (Path.GetExtension(tag).Equals(".zip", StringComparison.OrdinalIgnoreCase))
                                    {
                                        FileStream fs = null;

                                        try
                                        {
                                            fs = new FileStream(tag, FileMode.Open, FileAccess.Read, FileShare.Read);

                                            using (ZipArchive zipArchive = new ZipArchive(fs))
                                            {
                                                fs = null;

                                                StringBuilder stringBuilder = new StringBuilder(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

                                                if (Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).LastIndexOf(Path.DirectorySeparatorChar) != Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).Length - 1)
                                                {
                                                    stringBuilder.Append(Path.DirectorySeparatorChar);
                                                }

                                                string path = tag.StartsWith(stringBuilder.ToString(), StringComparison.Ordinal) ? tag.Remove(0, stringBuilder.Length) : tag;

                                                foreach (ZipArchiveEntry zipArchiveEntry in from zipArchiveEntry in zipArchive.Entries where zipArchiveEntry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) select zipArchiveEntry)
                                                {
                                                    Stream stream = null;

                                                    try
                                                    {
                                                        stream = zipArchiveEntry.Open();

                                                        foreach (string a in from a in ((System.Collections.IEnumerable)XDocument.Load(stream).XPathEvaluate("/script/character/@name")).Cast<XAttribute>() select a.Value)
                                                        {
                                                            Character character = new Character();

                                                            character.Name = a;
                                                            character.Script = path;

                                                            characterList.Add(character);
                                                        }
                                                    }
                                                    catch
                                                    {
                                                        return;
                                                    }
                                                    finally
                                                    {
                                                        if (stream != null)
                                                        {
                                                            stream.Close();
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            if (fs != null)
                                            {
                                                fs.Close();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        FileStream fs = null;

                                        try
                                        {
                                            fs = new FileStream(tag, FileMode.Open, FileAccess.Read, FileShare.Read);

                                            StringBuilder stringBuilder = new StringBuilder(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

                                            if (Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).LastIndexOf(Path.DirectorySeparatorChar) != Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).Length - 1)
                                            {
                                                stringBuilder.Append(Path.DirectorySeparatorChar);
                                            }

                                            string path = tag.StartsWith(stringBuilder.ToString(), StringComparison.Ordinal) ? tag.Remove(0, stringBuilder.Length) : tag;

                                            foreach (string a in from a in ((System.Collections.IEnumerable)XDocument.Load(fs).XPathEvaluate("/script/character/@name")).Cast<XAttribute>() select a.Value)
                                            {
                                                Character character = new Character();

                                                character.Name = a;
                                                character.Script = path;

                                                characterList.Add(character);
                                            }
                                        }
                                        catch
                                        {
                                            return;
                                        }
                                        finally
                                        {
                                            if (fs != null)
                                            {
                                                fs.Close();
                                            }
                                        }
                                    }

                                    if (characterList.Count > 0)
                                    {
                                        Switch(characterList);
                                    }
                                }
                            });
                        }
                        else
                        {
                            menuItemList.Remove(unselectedMenuItem);
                        }

                        charactersMenuItem.Items.Add(unselectedMenuItem);
                    });
                }
            });

            if (this == Application.Current.MainWindow)
            {
                System.Configuration.Configuration config = null;
                string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);

                if (Directory.Exists(directory))
                {
                    string fileName = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                    foreach (string s in from s in Directory.EnumerateFiles(directory, "*.config") where fileName.Equals(Path.GetFileNameWithoutExtension(s)) select s)
                    {
                        System.Configuration.ExeConfigurationFileMap exeConfigurationFileMap = new System.Configuration.ExeConfigurationFileMap();

                        exeConfigurationFileMap.ExeConfigFilename = s;
                        config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, System.Configuration.ConfigurationUserLevel.None);
                    }
                }

                if (config == null)
                {
                    config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);
                }

                if (config.AppSettings.Settings["Left"] != null && config.AppSettings.Settings["Top"] != null)
                {
                    if (config.AppSettings.Settings["Left"].Value.Length > 0 && config.AppSettings.Settings["Top"].Value.Length > 0)
                    {
                        this.Left = Double.Parse(config.AppSettings.Settings["Left"].Value, System.Globalization.CultureInfo.InvariantCulture);
                        this.Top = Double.Parse(config.AppSettings.Settings["Top"].Value, System.Globalization.CultureInfo.InvariantCulture);
                    }
                }

                if (config.AppSettings.Settings["Opacity"] != null)
                {
                    if (config.AppSettings.Settings["Opacity"].Value.Length > 0)
                    {
                        this.opacity = Double.Parse(config.AppSettings.Settings["Opacity"].Value, System.Globalization.CultureInfo.InvariantCulture);
                    }
                }

                if (config.AppSettings.Settings["Scale"] != null)
                {
                    if (config.AppSettings.Settings["Scale"].Value.Length > 0)
                    {
                        this.scale = this.ZoomScaleTransform.ScaleX = this.ZoomScaleTransform.ScaleY = Double.Parse(config.AppSettings.Settings["Scale"].Value, System.Globalization.CultureInfo.InvariantCulture);
                    }
                }

                if (config.AppSettings.Settings["Topmost"] != null)
                {
                    if (config.AppSettings.Settings["Topmost"].Value.Length > 0)
                    {
                        this.Topmost = Boolean.Parse(config.AppSettings.Settings["Topmost"].Value);
                    }
                }

                if (config.AppSettings.Settings["ShowInTaskbar"] != null)
                {
                    if (config.AppSettings.Settings["ShowInTaskbar"].Value.Length > 0)
                    {
                        this.ShowInTaskbar = Boolean.Parse(config.AppSettings.Settings["ShowInTaskbar"].Value);
                    }
                }

                if (config.AppSettings.Settings["DropShadow"] != null)
                {
                    if (config.AppSettings.Settings["DropShadow"].Value.Length > 0)
                    {
                        if (Boolean.Parse(config.AppSettings.Settings["DropShadow"].Value))
                        {
                            DropShadowEffect dropShadowEffect = new DropShadowEffect();

                            dropShadowEffect.Color = Colors.Black;
                            dropShadowEffect.BlurRadius = 10;
                            dropShadowEffect.Direction = 270;
                            dropShadowEffect.ShadowDepth = 0;
                            dropShadowEffect.Opacity = 0.5;

                            if (dropShadowEffect.CanFreeze)
                            {
                                dropShadowEffect.Freeze();
                            }

                            this.Canvas.Effect = dropShadowEffect;
                        }
                    }
                }

                if (config.AppSettings.Settings["Mute"] != null)
                {
                    if (config.AppSettings.Settings["Mute"].Value.Length > 0)
                    {
                        this.isMute = Boolean.Parse(config.AppSettings.Settings["Mute"].Value);
                    }
                }

                if (config.AppSettings.Settings["FrameRate"] != null)
                {
                    if (config.AppSettings.Settings["FrameRate"].Value.Length > 0)
                    {
                        this.frameRate = Double.Parse(config.AppSettings.Settings["FrameRate"].Value, System.Globalization.CultureInfo.InvariantCulture);
                    }
                }
            }
            else
            {
                Agent agent = Application.Current.MainWindow as Agent;

                if (agent != null)
                {
                    this.opacity = agent.opacity;
                    this.scale = this.ZoomScaleTransform.ScaleX = this.ZoomScaleTransform.ScaleY = agent.scale;
                    this.Topmost = agent.Topmost;
                    this.ShowInTaskbar = agent.ShowInTaskbar;

                    if (agent.Canvas.Effect != null)
                    {
                        DropShadowEffect dropShadowEffect = new DropShadowEffect();

                        dropShadowEffect.Color = Colors.Black;
                        dropShadowEffect.BlurRadius = 10;
                        dropShadowEffect.Direction = 270;
                        dropShadowEffect.ShadowDepth = 0;
                        dropShadowEffect.Opacity = 0.5;

                        if (dropShadowEffect.CanFreeze)
                        {
                            dropShadowEffect.Freeze();
                        }

                        this.Canvas.Effect = dropShadowEffect;
                    }

                    this.isMute = agent.isMute;
                    this.frameRate = agent.frameRate;
                }
            }

            this.balloon = new Balloon();
            this.balloon.Title = this.Title;
            this.balloon.SizeChanged += new SizeChangedEventHandler(delegate (object s, SizeChangedEventArgs e)
            {
                foreach (Character character in from character in Script.Instance.Characters where character.Name.Equals(this.characterName) select character)
                {
                    this.balloon.Left = this.Left + (this.Width - e.NewSize.Width) / 2;
                    this.balloon.Top = this.Top - e.NewSize.Height + character.Origin.Y * this.ZoomScaleTransform.ScaleY;
                }
            });
            this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate
            {
                Run();

                return null;
            }), null);

            Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(this.OnPowerModeChanged);
        }
Пример #7
0
        public static PlotElementAnimation CreateAnimation(AnimationTransform transform, AnimationOrigin origin, Easing easing, bool indexDelay)
        {
            var sb = new Storyboard();
              var duration = new Duration(TimeSpan.FromSeconds(0.5));

              var style = new Style();
              style.TargetType = typeof(PlotElement);
              style.Setters.Add(new Setter(PlotElement.OpacityProperty, 0.0));

              if (transform == AnimationTransform.Scale)
            style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new ScaleTransform() { ScaleX = 0, ScaleY = 0 }));
              else if (transform == AnimationTransform.Rotation)
            style.Setters.Add(new Setter(PlotElement.RenderTransformProperty, new RotateTransform() { Angle = 180 }));

              var point = new Point(0.5, 0.5);
              switch (origin)
              {
            case AnimationOrigin.Bottom:
              point = new Point(0.5, 2);
              break;
            case AnimationOrigin.Top:
              point = new Point(0.5, -2);
              break;
            case AnimationOrigin.Left:
              point = new Point(-2, 0.5);
              break;
            case AnimationOrigin.Right:
              point = new Point(2, 0.5);
              break;
            case AnimationOrigin.TopLeft:
              point = new Point(2, -2);
              break;
            case AnimationOrigin.TopRight:
              point = new Point(-2, -2);
              break;
            case AnimationOrigin.BottomLeft:
              point = new Point(2, 2);
              break;
            case AnimationOrigin.BottomRight:
              point = new Point(-2, 2);
              break;
            default:
              break;
              }

              style.Setters.Add(new Setter(PlotElement.RenderTransformOriginProperty, point));

              var da = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
              Storyboard.SetTargetProperty(da, new PropertyPath("Opacity"));
              sb.Children.Add(da);

              if (transform == AnimationTransform.Scale)
              {
            var da2 = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
            Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).ScaleX"));

            var da3 = new DoubleAnimation() { From = 0, To = 1, Duration = duration };
            Storyboard.SetTargetProperty(da3, new PropertyPath("(RenderTransform).ScaleY"));

            sb.Children.Add(da2);
            sb.Children.Add(da3);
              }
              else if (transform == AnimationTransform.Rotation)
              {
            var da2 = new DoubleAnimation() { To = 0, Duration = duration };
            Storyboard.SetTargetProperty(da2, new PropertyPath("(RenderTransform).Angle"));
            sb.Children.Add(da2);
              }

              if (indexDelay)
              {
            foreach (var anim in sb.Children)
              PlotElementAnimation.SetIndexDelay(anim, 0.5);
              }

            #if CLR40
              if (easing != Easing.None)
              {
            IEasingFunction ef = null;

            switch (easing)
            {
              case Easing.BackEase:
            ef = new BackEase(); break;
              case Easing.BounceEase:
            ef = new BounceEase(); break;
              case Easing.CircleEase:
            ef = new CircleEase(); break;
              case Easing.CubicEase:
            ef = new CubicEase(); break;
              case Easing.ElasticEase:
            ef = new ElasticEase(); break;
              case Easing.ExponentialEase:
            ef = new ExponentialEase(); break;
              case Easing.PowerEase:
            ef = new PowerEase(); break;
              case Easing.QuadraticEase:
            ef = new QuadraticEase(); break;
              case Easing.QuarticEase:
            ef = new QuarticEase(); break;
              case Easing.QuinticEase:
            ef = new QuinticEase(); break;
              case Easing.SineEase:
            ef = new SineEase(); break;

              default:
            break;
            }

            foreach (DoubleAnimation anim in sb.Children)
              anim.EasingFunction = ef;
              }
            #endif

              return new PlotElementAnimation() { Storyboard = sb, SymbolStyle = style };
        }
        public void confirmDenyPhoto(bool _yesNo)
        {
            //7/28/2013 - There is a System.ArgumentException that can occurr here on a dependency property not 100% on what is causing it yet.
            // submission is not affected but it is related to a double animation. I expect from daHeight or daFHeight

            // It is also possible that this could be called immediately twice in a row with yes or no..so be careful...So a left and right hand
            // simultaniously activate or two players activate at the same time..so two of the same.
            if (_confirmDenyTransitioning == false)
            {
                try
                {
                    // Hide the yes and no buttons
                    DoubleAnimation daHeight = new DoubleAnimation(Canvas.GetTop(contentBorder) + contentBorder.ActualHeight + 50, (GlobalConfiguration.currentScreenH + btnStack.ActualHeight + 30), new Duration(TimeSpan.FromSeconds(0.3)));
                    // Slide the background selection back in
                    DoubleAnimation daFHeight = new DoubleAnimation((GlobalConfiguration.currentScreenW + 50), (GlobalConfiguration.currentScreenW / 2 - stackBGs.ActualWidth / 2), new Duration(TimeSpan.FromSeconds(0.3)));
                    SineEase ease = new SineEase();
                    ease.EasingMode = EasingMode.EaseIn;
                    daHeight.EasingFunction = ease;
                    daFHeight.EasingFunction = ease;
                    daFHeight.BeginTime = TimeSpan.FromSeconds(0.2);
                    btnStack.BeginAnimation(Canvas.TopProperty, daHeight);
                    stackBGs.BeginAnimation(Canvas.LeftProperty, daFHeight);
                    //btnYes.BeginAnimation(Button.MarginProperty

                    // Show take photo
                    daOpacity.Completed += showTakePhotoCompleted;
                    _confirmDenyTransitioning = true;
                    txtTakePhoto.Text = "TAKE PHOTO";
                    txtTakePhoto.BeginAnimation(TextBlock.OpacityProperty, daOpacity);
                    txtStartCountdown.BeginAnimation(TextBlock.OpacityProperty, daOpacity);
                    takePhoto.BeginAnimation(Image.OpacityProperty, daOpacity);
                }
                catch (ArgumentException aEx)
                {
                    System.Diagnostics.Debug.WriteLine("SectionPhoto - configmDenyPhoto argument exception: " + aEx.Message);
                }

                if (_yesNo == true)
                {
                    // Captions
                    requestNewCaption(ApplicationStates.STATE_PHOTO_SUBMITTED, false);
                    saveImageFrame();
                    // Ensure the main knows it needs to update the photo list in attract next time
                    if (requestNewPhotoList != null)
                    {
                        PhotoListStateEventArgs newArgs = new PhotoListStateEventArgs(true, null);
                        requestNewPhotoList(this, newArgs);
                    }
                }
                else
                {
                    // Captions
                    requestNewCaption(ApplicationStates.STATE_PHOTO_DESTROYED, false);
                }

                // Save photo or not, we can unfreese the video here. Saving is done in a background worker
                if (gsView != null)
                {
                    gsView.freezePhotoOrNot(false);
                }
            }
        }
        private void AnimateChildrenIn(bool reverse)
        {
            if (_popupContentControl == null) return;
            if (VisualTreeHelper.GetChildrenCount(_popupContentControl) != 1) return;
            var contentPresenter = VisualTreeHelper.GetChild(_popupContentControl, 0) as ContentPresenter;

            var controls = contentPresenter.VisualDepthFirstTraversal().OfType<ButtonBase>();
            double translateCoordinateFrom;
            if ((PlacementMode == PopupBoxPlacementMode.TopAndAlignCentres
                 || PlacementMode == PopupBoxPlacementMode.TopAndAlignLeftEdges
                 || PlacementMode == PopupBoxPlacementMode.TopAndAlignRightEdges
                 || PlacementMode == PopupBoxPlacementMode.LeftAndAlignBottomEdges
                 || PlacementMode == PopupBoxPlacementMode.RightAndAlignBottomEdges
                 || (UnfurlOrientation == Orientation.Horizontal &&
                     (
                         PlacementMode == PopupBoxPlacementMode.LeftAndAlignBottomEdges
                         || PlacementMode == PopupBoxPlacementMode.LeftAndAlignMiddles
                         || PlacementMode == PopupBoxPlacementMode.LeftAndAlignTopEdges
                         ))
                ))
            {
                controls = controls.Reverse();
                translateCoordinateFrom = 80;
            }
            else
                translateCoordinateFrom = -80;

            var translateCoordinatePath =
                "(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform."
                + (UnfurlOrientation == Orientation.Horizontal ? "X)" : "Y)");

            var sineEase = new SineEase();

            var i = 0;
            foreach (var uiElement in controls)
            {
                var deferredStart = i++*20;
                var deferredEnd = deferredStart+200.0;

                var absoluteZeroKeyTime = KeyTime.FromPercent(0.0);
                var deferredStartKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(deferredStart));
                var deferredEndKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(deferredEnd));

                var elementTranslateCoordinateFrom = translateCoordinateFrom * i;
                var translateTransform = new TranslateTransform(
                    UnfurlOrientation == Orientation.Vertical ? 0 : elementTranslateCoordinateFrom,
                    UnfurlOrientation == Orientation.Vertical ? elementTranslateCoordinateFrom : 0);

                var transformGroup = new TransformGroup
                {
                    Children = new TransformCollection(new Transform[]
                    {
                        new ScaleTransform(0, 0),
                        translateTransform
                    })
                };
                uiElement.SetCurrentValue(RenderTransformOriginProperty, new Point(.5, .5));
                uiElement.RenderTransform = transformGroup;

                var opacityAnimation = new DoubleAnimationUsingKeyFrames();
                opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, absoluteZeroKeyTime, sineEase));
                opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredStartKeyTime, sineEase));
                opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, deferredEndKeyTime, sineEase));
                Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                Storyboard.SetTarget(opacityAnimation, uiElement);

                var scaleXAnimation = new DoubleAnimationUsingKeyFrames();
                scaleXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, absoluteZeroKeyTime, sineEase));
                scaleXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredStartKeyTime, sineEase));
                scaleXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, deferredEndKeyTime, sineEase));
                Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"));
                Storyboard.SetTarget(scaleXAnimation, uiElement);

                var scaleYAnimation = new DoubleAnimationUsingKeyFrames();
                scaleYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, absoluteZeroKeyTime, sineEase));
                scaleYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredStartKeyTime, sineEase));
                scaleYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, deferredEndKeyTime, sineEase));
                Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"));
                Storyboard.SetTarget(scaleYAnimation, uiElement);

                var translateCoordinateAnimation = new DoubleAnimationUsingKeyFrames();
                translateCoordinateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(elementTranslateCoordinateFrom, absoluteZeroKeyTime, sineEase));
                translateCoordinateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(elementTranslateCoordinateFrom, deferredStartKeyTime, sineEase));
                translateCoordinateAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, deferredEndKeyTime, sineEase));

                Storyboard.SetTargetProperty(translateCoordinateAnimation, new PropertyPath(translateCoordinatePath));
                Storyboard.SetTarget(translateCoordinateAnimation, uiElement);

                var storyboard = new Storyboard();
                storyboard.Children.Add(opacityAnimation);
                storyboard.Children.Add(scaleXAnimation);
                storyboard.Children.Add(scaleYAnimation);
                storyboard.Children.Add(translateCoordinateAnimation);

                if (reverse)
                {
                    storyboard.AutoReverse = true;
                    storyboard.Begin();
                    storyboard.Seek(TimeSpan.FromMilliseconds(deferredEnd));
                    storyboard.Resume();

                }
                else
                    storyboard.Begin();
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            System.IO.Directory.CreateDirectory(App.GamePath);
            ConfigFileName = System.IO.Path.Combine(App.GamePath, ConfigFileName);

            if (System.IO.File.Exists(ConfigFileName))
                try
                {
                    config = Configuration.LoadFromFile(ConfigFileName);
                }
                catch
                {
                    config = new Configuration();
                }
            if (config == null)
                config = new Configuration();

            w.Name = "StatusWindow";
            w.Opacity = 0;
            w.Background = Brushes.Transparent;

            // Show app version in titlebar
            if (System.IO.File.Exists("version.txt"))
            {
                this.Title += " v";
                this.Title += System.IO.File.ReadAllText("version.txt").Replace("_", ".");
            }

            // Image gallery
            Task.Factory.StartNew(() =>
            {
                var urls =
                    (
                        from url in (new WebClient()).DownloadString("http://www.modernminas.de/img/gallery/launcher/").Split('\n')
                        where !string.IsNullOrEmpty(url) //&& !string.IsNullOrWhiteSpace(url)
                        select url
                        ).Randomize();
                while ((bool)this.Dispatcher.Invoke(new Func<bool>(() => { return this.IsVisible; })))
                {
                    foreach (string url in urls)
                    {
                        System.Threading.Thread.Sleep(5000);
                        this.Dispatcher.Invoke(new Action(() => { this.ContentPanel.Background = new ImageBrush(new BitmapImage(new Uri(url))); }));
                    }
                }

            });

            #if LOGO_ANIMATION
            // Logo animation
            this.Dispatcher.Invoke(new Action(() =>
            {

                Storyboard storyboard = new Storyboard();
                TimeSpan duration = TimeSpan.FromSeconds(8);

                DoubleAnimation animation = new DoubleAnimation();
                animation.Duration = new Duration(duration);

                var easing = new SineEase();
                easing.EasingMode = EasingMode.EaseInOut;
                animation.EasingFunction = easing;

                //Storyboard.SetTarget(animation, (System.Windows.Media.Effects.DropShadowEffect)this.Logo.Effect);
                //Storyboard.SetTargetProperty(animation, new PropertyPath(System.Windows.Media.Effects.DropShadowEffect.BlurRadiusProperty));
                Storyboard.SetTarget(animation, this.Logo);
                Storyboard.SetTargetProperty(animation, new PropertyPath(Control.WidthProperty));
                storyboard.Children.Add(animation);

                storyboard.Completed += (sender, e) =>
                {
                    // Reverse animation range...
                    var a = animation.From;
                    animation.From = animation.To;
                    animation.To = a;
                    // ...and start!
                    storyboard.Begin();
                };

                animation.From = this.Logo.Width - 10;
                animation.To = this.Logo.Width;
                storyboard.Begin();
            }));
            #endif

            this.Password.Password = config.Password != null && config.Password.Length > 0 ? UseSavedPasswordMagic : string.Empty;
            this.Username.Text = config.Username;
        }
Пример #11
0
        private IEasingFunction ObterFuncaoDaAnimacao()
        {
            EasingFunctionBase funcaoDaAnimacao = null;
            
            switch (FuncaoDaAnimacao.SelectedValue.ToString())
            {
                case "BackEase":
                    funcaoDaAnimacao =  new BackEase();
                    break;
                case "BounceEase":
                    funcaoDaAnimacao = new BounceEase();
                    break;
                case "CircleEase":
                    funcaoDaAnimacao = new CircleEase();
                    break;
                case "CubicEase":
                    funcaoDaAnimacao = new CubicEase();
                    break;
                case "ElasticEase":
                    funcaoDaAnimacao = new ElasticEase();
                    break;
                case "ExponentialEase":
                    funcaoDaAnimacao = new ExponentialEase();
                    break;
                case "PowerEase":
                    funcaoDaAnimacao = new PowerEase();
                    break;
                case "QuadraticEase":
                    funcaoDaAnimacao = new QuadraticEase();
                    break;
                case "QuarticEase":
                    funcaoDaAnimacao = new QuarticEase();
                    break;
                case "QuinticEase":
                    funcaoDaAnimacao = new QuinticEase();
                    break;
                case "SineEase":
                    funcaoDaAnimacao = new SineEase();
                    break;
            }

            funcaoDaAnimacao.EasingMode = ObterModoDaAnimacao();
            return funcaoDaAnimacao;
        }
Пример #12
0
        /// <summary>
        /// The animation of the singleplayer button
        /// </summary>
        private void AnimateSimpleSessionButton()
        {
            Random r = GlobalVariables.GlobalRandom;
            simpleButtonDirection = !simpleButtonDirection;
            Storyboard buttonsSTB = new Storyboard();
            ThicknessAnimation marginAnimation = new ThicknessAnimation();
            SineEase ease = new SineEase();
            ease.EasingMode = EasingMode.EaseInOut;
            Double yOffset;
            if (simpleButtonDirection) yOffset = (30.0 / 1920.0) * ActualWidth;
            else yOffset = -(30.0 / 1920.0) * ActualWidth;

            marginAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(r.Next(1500, 2000)));
            /*marginAnimation.AccelerationRatio = .3;
            marginAnimation.DecelerationRatio = .7;*/

            marginAnimation.From = CreateSession_Button.Margin;
            marginAnimation.To = new Thickness(0, 0, CreateSession_Button.Margin.Right, CreateSession_Button.Margin.Bottom + yOffset);
            marginAnimation.FillBehavior = FillBehavior.HoldEnd;
            marginAnimation.EasingFunction = ease;
            Storyboard.SetTarget(marginAnimation, CreateSession_Button);
            Storyboard.SetTargetProperty(marginAnimation, new PropertyPath(SurfaceButton.MarginProperty));

            buttonsSTB.Children.Add(marginAnimation);
            marginAnimation.Completed += new EventHandler(marginAnimation_Completed);

            buttonsSTB.Begin();
        }
Пример #13
0
        private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == ApiCodes.WM_SYSCOMMAND)
            {
                // minimize actions
                if (wParam.ToInt32() == ApiCodes.SC_MINIMIZE)
                {
                    SineEase easingFunction = new SineEase();
                    easingFunction.EasingMode = EasingMode.EaseIn;

                    var anim = new DoubleAnimation(0, TimeSpan.FromMilliseconds(300));
                    anim.EasingFunction = easingFunction;
                    anim.Completed += delegate { window.WindowState = WindowState.Minimized; };
                    window.BeginAnimation(UIElement.OpacityProperty, anim);

                    handled = true;
                }
                // restore actions
                else if (wParam.ToInt32() == ApiCodes.SC_RESTORE)
                {
                    SineEase easingFunction = new SineEase();
                    easingFunction.EasingMode = EasingMode.EaseIn;

                    window.WindowState = WindowState.Normal;
                    var anim = new DoubleAnimation(1, TimeSpan.FromMilliseconds(300));
                    anim.EasingFunction = easingFunction;
                    window.BeginAnimation(UIElement.OpacityProperty, anim);

                    handled = true;
                }
            }
            return IntPtr.Zero;
        }
Пример #14
0
        /// <summary>
        /// Note Bubble Animation 
        /// Moves the NoteBubble randomly on the screen.
        /// </summary>
        private void Animate()
        {
            if (canAnimate)
            {
                PointAnimation centerAnimation = new PointAnimation();
                SineEase ease = new SineEase();
                ease.EasingMode = EasingMode.EaseInOut;
                Random r = GlobalVariables.GlobalRandom;
                Double xOffset = (-2) * (r.Next() % 2 - .5) * r.Next(50, 100);
                Double yOffset = (-2) * (r.Next() % 2 - .5) * r.Next(50, 100);

                centerAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(r.Next(9000, 21000)));
                centerAnimation.AccelerationRatio = .3;
                centerAnimation.DecelerationRatio = .3;

                if (SVItem.Center.X + xOffset > ParentSV.ActualWidth)
                    xOffset = (ParentSV.ActualWidth - SVItem.Center.X) - (double)r.Next(50);
                if (SVItem.Center.X + xOffset < 0)
                    xOffset = 0 - SVItem.Center.X + (double)r.Next(50);
                if (SVItem.Center.Y + yOffset > ParentSV.ActualHeight)
                    yOffset = ParentSV.ActualHeight - SVItem.Center.Y - (double)r.Next(50);
                if (SVItem.Center.Y + yOffset < 630.0 * ParentSV.ActualHeight / 1080.0)
                    yOffset = ((630.0 * ParentSV.ActualHeight / 1080.0) - SVItem.Center.Y) + (double)r.Next(50);
                if (SVItem.Center.Y < 630.0 * ParentSV.ActualHeight / 1080.0)
                {
                    centerAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(r.Next(2000, 4000)));
                    centerAnimation.DecelerationRatio = .7;
                }

                centerAnimation.From = SVItem.Center;
                centerAnimation.To = new Point(SVItem.Center.X + xOffset, SVItem.Center.Y + yOffset);
                centerAnimation.FillBehavior = FillBehavior.HoldEnd;
                Storyboard.Children.Add(centerAnimation);
                Storyboard.SetTarget(centerAnimation, SVItem);
                Storyboard.SetTargetProperty(centerAnimation, new PropertyPath(ScatterViewItem.CenterProperty));

                centerAnimation.Completed += new EventHandler(centerAnimation_Completed);

                Storyboard.Begin();
            }
        }
        private void nextSFXStep()
        {
            if (sfxQueue != null)
            {
                sfxQueue.RemoveAt(0);
                if (sfxQueue.Count > 0)
                {
                    playSoundEffect(sfxQueue[0]);
                    if (countDown.Visibility == System.Windows.Visibility.Visible)
                    {
                        countDown.Text = Convert.ToString(sfxQueue.Count - 1);
                    }

                    if (sfxQueue.Count == 1)
                    {
                        // Hide the count
                        countDown.Visibility = System.Windows.Visibility.Hidden;
                        countDown.Text = "3";

                        // Take the photo
                        freezePhoto = true;

                        // Flash the white
                        //DoubleAnimation daFlashW = AnimationHelper.CreateDoubleAnimation(0, this.Width, null, new Duration(TimeSpan.FromSeconds(0.2)));
                        //DoubleAnimation daFlashH = AnimationHelper.CreateDoubleAnimation(0, this.Height, null, new Duration(TimeSpan.FromSeconds(0.2)));
                        DoubleAnimation daFlashOpacity = new DoubleAnimation(0, .8, new Duration(TimeSpan.FromSeconds(0.1)));
                        daFlashOpacity.AutoReverse = true;

                        //camFlash.BeginAnimation(Ellipse.WidthProperty, daFlashW);
                        //camFlash.BeginAnimation(Ellipse.HeightProperty, daFlashH);
                        camFlash.BeginAnimation(Ellipse.OpacityProperty, daFlashOpacity);
                    }
                }
                else
                {
                    sfxQueue = null;
                    // Done
                    destroySFXPlayer();

                    // Show retake photo
                    txtTakePhoto.Text = "RE-TAKE PHOTO";
                    DoubleAnimation daOpacity = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(0.5)));
                    daOpacity.BeginTime = TimeSpan.FromSeconds(6);
                    txtTakePhoto.BeginAnimation(TextBlock.OpacityProperty, daOpacity);
                    txtStartCountdown.BeginAnimation(TextBlock.OpacityProperty, daOpacity);
                    takePhoto.BeginAnimation(Button.OpacityProperty, daOpacity);
                    takePhoto.IsHitTestVisible = true;

                    // show yes or no button
                    DoubleAnimation daHeight = new DoubleAnimation(150, 0, new Duration(TimeSpan.FromSeconds(0.3)));
                    DoubleAnimation daHeightF = new DoubleAnimation(150, 0, new Duration(TimeSpan.FromSeconds(0.3)));
                    SineEase ease = new SineEase();
                    ease.EasingMode = EasingMode.EaseOut;
                    daHeight.EasingFunction = ease;
                    daHeightF.EasingFunction = ease;
                    daHeight.BeginTime = TimeSpan.FromSeconds(6);
                    daHeightF.BeginTime = TimeSpan.FromSeconds(6.2);
                    // Add a tiny delay
                    YNSpacer.BeginAnimation(Canvas.HeightProperty, daHeight);
                    YNSpacer2.BeginAnimation(Canvas.HeightProperty, daHeightF);

                    // Captions
                    requestNewCaption(ApplicationStates.STATE_LOOKINGGOOD, false);
                    requestNewCaption(ApplicationStates.STATE_SUBMISSION_AGREE, true);
                    requestNewCaption(ApplicationStates.STATE_YES_NOPHOTO, true);

                    // Re-enable the cursors
                    if (_mainWin != null)
                    {
                        _mainWin.enableDisableAllCursors(true);
                    }
                }
            }
        }
        public void initiatePhotoTake()
        {
            // Just in case it's a re-take
            freezePhoto = false;
            if (YNSpacer.Height < 150)
            {
                DoubleAnimation daHeight = new DoubleAnimation(YNSpacer.Height, 150, new Duration(TimeSpan.FromSeconds(0.3)));
                DoubleAnimation daFHeight = new DoubleAnimation(YNSpacer2.Height, 150, new Duration(TimeSpan.FromSeconds(0.3)));
                SineEase ease = new SineEase();
                ease.EasingMode = EasingMode.EaseIn;
                daHeight.EasingFunction = ease;
                daFHeight.EasingFunction = ease;
                daFHeight.BeginTime = TimeSpan.FromSeconds(0.2);
                YNSpacer2.BeginAnimation(Canvas.HeightProperty, daFHeight);
                YNSpacer.BeginAnimation(Canvas.HeightProperty, daHeight);
            }

            if (sfxQueue != null)
            {
                sfxQueue = null;
            }

            // Disable cursors - way too distracting
            if (_mainWin != null)
            {
                _mainWin.enableDisableAllCursors(false);
            }

            // Hide take photo
            DoubleAnimation daOpacityHide = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.5)));
            txtTakePhoto.BeginAnimation(TextBlock.OpacityProperty, daOpacityHide);
            txtStartCountdown.BeginAnimation(TextBlock.OpacityProperty, daOpacityHide);
            takePhoto.BeginAnimation(Button.OpacityProperty, daOpacityHide);
            takePhoto.IsHitTestVisible = false;
            // Hide the button

            sfxQueue = new List<string>();
            sfxQueue.Add("TDGenBeep.wav");
            sfxQueue.Add("TDGenBeep.wav");
            sfxQueue.Add("TDGenBeep.wav");
            sfxQueue.Add("CameraFlash.mp3");
            playSoundEffect(sfxQueue[0]);
            countDown.Visibility = System.Windows.Visibility.Visible;
        }
Пример #17
0
        internal void ShowTwist(TwistDirection twistDirection)
        {
            Double currentAngle = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.RotationProperty);
            Double totalTwistTime = 1.0;

            ((DoubleAnimation)QuadrantRotation.Children[0]).From = currentAngle;
            ((DoubleAnimation)QuadrantRotation.Children[0]).To =
                (twistDirection == TwistDirection.Clockwise) ? currentAngle + 90 : currentAngle - 90;
            ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = new Duration(TimeSpan.FromSeconds(totalTwistTime));
            QuadrantRotation.BeginTime = TimeSpan.FromSeconds(1);

            SineEase f = new SineEase();
            f.EasingMode = EasingMode.EaseOut;

            ((DoubleAnimation)QuadrantTranslation.Children[0]).From = 0;
            Double to = 0;
            switch (this.Name.ToLower())
            {
                case "upperleft":
                case "lowerleft":
                    to = -1 * MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0;
                    break;
                case "upperright":
                case "lowerright":
                    to = MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0;
                    break;
            }
            ((DoubleAnimation)QuadrantTranslation.Children[0]).To = to;

            ((DoubleAnimation)QuadrantTranslation.Children[0]).EasingFunction = f;
            ((DoubleAnimation)QuadrantTranslation.Children[0]).Duration = new Duration(TimeSpan.FromSeconds(totalTwistTime/2.0));

            ((DoubleAnimation)QuadrantTranslation.Children[1]).From = 0;
            switch (this.Name.ToLower())
            {
                case "upperleft":
                case "upperright":
                    to = -1 * MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0;
                    break;
                case "lowerleft":
                case "lowerright":
                    to = MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0;
                    break;
            }
            ((DoubleAnimation)QuadrantTranslation.Children[1]).To = to;
            ((DoubleAnimation)QuadrantTranslation.Children[1]).EasingFunction = f;
            ((DoubleAnimation)QuadrantTranslation.Children[1]).Duration = new Duration(TimeSpan.FromSeconds(totalTwistTime / 2.0));
            QuadrantTranslation.AutoReverse = true;
            QuadrantTranslation.BeginTime = TimeSpan.FromSeconds(1);

            QuadrantRotation.Begin();
            QuadrantTranslation.Begin();
        }
        public void initiatePhotoTake()
        {
            // Just in case it's a re-take, ensure the buttons are hidden
            // and background selection is hidden
            gsView.freezePhotoOrNot(false);

            if (Canvas.GetTop(btnStack) < (GlobalConfiguration.currentScreenH + btnStack.Height + 30) )
            {
                DoubleAnimation daHeight = new DoubleAnimation(Canvas.GetTop(contentBorder) + contentBorder.ActualHeight + 50, (GlobalConfiguration.currentScreenH + btnStack.ActualHeight + 30), new Duration(TimeSpan.FromSeconds(0.3)));
                
                SineEase ease = new SineEase();
                ease.EasingMode = EasingMode.EaseIn;
                daHeight.EasingFunction = ease;

                // Moves buttons down
                btnStack.BeginAnimation(Canvas.TopProperty, daHeight);
            }
            if (Canvas.GetLeft(stackBGs) < (GlobalConfiguration.currentScreenW + 50))
            {
                DoubleAnimation daFHeight = new DoubleAnimation((GlobalConfiguration.currentScreenW / 2 - stackBGs.ActualWidth / 2), (GlobalConfiguration.currentScreenW + 50), new Duration(TimeSpan.FromSeconds(0.3)));

                SineEase ease2 = new SineEase();
                daFHeight.EasingFunction = ease2;
                daFHeight.BeginTime = TimeSpan.FromSeconds(0.2);
                // Moves backgrounds off to the right
                stackBGs.BeginAnimation(Canvas.LeftProperty, daFHeight);
            }

            if (sfxQueue != null)
            {
                sfxQueue = null;
            }

            // Disable cursors - way too distracting
            if (_mainWin != null)
            {
                _mainWin.enableDisableAllCursors(false);
            }

            // Hide take photo
            DoubleAnimation daOpacityHide = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.5)));
            txtTakePhoto.BeginAnimation(TextBlock.OpacityProperty, daOpacityHide);
            txtStartCountdown.BeginAnimation(TextBlock.OpacityProperty, daOpacityHide);
            takePhoto.BeginAnimation(Button.OpacityProperty, daOpacityHide);
            takePhoto.IsHitTestVisible = false;
            // Hide the button

            sfxQueue = new List<string>();
            // Set the countdown text at the top most number
            countDown.Text = Properties.Settings.Default.photoCountdownSeconds.ToString();
            for (int i = 0; i < Properties.Settings.Default.photoCountdownSeconds; i++)
            {
                sfxQueue.Add("TDGenBeep.wav");
            }
            sfxQueue.Add("CameraFlash.mp3");
            playSoundEffect(sfxQueue[0]);
            countDown.Visibility = System.Windows.Visibility.Visible;
        }
Пример #19
0
        void PentagoQuadrant_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (mouseDrag)
            {
                mouseDrag = false;

                Double currentAngle = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.RotationProperty);
                Double currentX = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.TranslateXProperty);
                Double currentY = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.TranslateYProperty);

                Duration dur = new Duration(TimeSpan.FromSeconds(0.2));
                Double to = currentAngle;

                if ((currentAngle % 90) != 0)
                {
                    Double mod360 = currentAngle % 360;
                    Double mod45 = currentAngle % 45;
                    if (mod360 < 0) { mod360 += 360; }
                    if (mod45 < 0) { mod45 += 45; }

                    to = currentAngle - mod45;

                    if ((mod360 <= 90 && mod360 > 45) ||
                        (mod360 <= 360 && mod360 > 315) ||
                        (mod360 <= 270 && mod360 > 225) ||
                        (mod360 <= 180 && mod360 > 135))
                    {
                        to += 45;
                    }
                }
                ((DoubleAnimation)QuadrantRotation.Children[0]).From = currentAngle;
                ((DoubleAnimation)QuadrantRotation.Children[0]).To = to;
                ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = dur;
                QuadrantRotation.ClearValue(Storyboard.BeginTimeProperty);
                TwistDirection direction = GetTwistDirectionFromAngles(origAngle, to);
                if (direction != TwistDirection.None)
                {
                    sendTwistNotification = true;
                    latestTwistDirection = direction;
                }

                SineEase f = new SineEase();
                f.EasingMode = EasingMode.EaseIn;

                ((DoubleAnimation)QuadrantTranslation.Children[0]).From = currentX;
                ((DoubleAnimation)QuadrantTranslation.Children[0]).To = 0.0;
                ((DoubleAnimation)QuadrantTranslation.Children[0]).Duration = dur;
              //  ((DoubleAnimation)QuadrantTranslation.Children[0]).EasingFunction = f;

                ((DoubleAnimation)QuadrantTranslation.Children[1]).From = currentY;
                ((DoubleAnimation)QuadrantTranslation.Children[1]).To = 0.0;
                ((DoubleAnimation)QuadrantTranslation.Children[1]).Duration = dur;
             //   ((DoubleAnimation)QuadrantTranslation.Children[1]).EasingFunction = f;
                QuadrantTranslation.ClearValue(Storyboard.BeginTimeProperty);
                QuadrantTranslation.AutoReverse = false;

                this.ReleaseMouseCapture();
                QuadrantTranslation.Begin();
                QuadrantRotation.Begin();
                this.ClearValue(Canvas.ZIndexProperty);
            }
        }
        private void nextSFXStep()
        {
            if (sfxQueue != null)
            {
                sfxQueue.RemoveAt(0);
                if (sfxQueue.Count > 0)
                {
                    playSoundEffect(sfxQueue[0]);
                    if (countDown.Visibility == System.Windows.Visibility.Visible)
                    {
                        countDown.Text = Convert.ToString(sfxQueue.Count - 1);
                    }

                    if (sfxQueue.Count == 1)
                    {
                        // Hide the count
                        countDown.Visibility = System.Windows.Visibility.Hidden;
                        countDown.Text = Properties.Settings.Default.photoCountdownSeconds.ToString();

                        // Take the photo
                        gsView.freezePhotoOrNot( true );

                        // Flash the white
                        DoubleAnimation daFlashOpacity = new DoubleAnimation(0, .8, new Duration(TimeSpan.FromSeconds(0.1)));
                        daFlashOpacity.AutoReverse = true;

                        camFlash.BeginAnimation(Ellipse.OpacityProperty, daFlashOpacity);
                    }
                }
                else
                {
                    sfxQueue = null;
                    // Done
                    destroySFXPlayer();

                    // show yes or no button
                    DoubleAnimation daHeight = new DoubleAnimation((GlobalConfiguration.currentScreenH + btnStack.ActualHeight + 30), Canvas.GetTop(contentBorder) + contentBorder.ActualHeight + 50, new Duration(TimeSpan.FromSeconds(0.3)));

                    SineEase ease = new SineEase();
                    ease.EasingMode = EasingMode.EaseOut;
                    daHeight.EasingFunction = ease;
                    daHeight.BeginTime = TimeSpan.FromSeconds(6);
                    // Add a tiny delay
                    btnStack.BeginAnimation(Canvas.TopProperty, daHeight);

                    // Captions
                    requestNewCaption(ApplicationStates.STATE_LOOKINGGOOD, false);
                    requestNewCaption(ApplicationStates.STATE_YES_NOPHOTO, true);

                    // Re-enable the cursors
                    if (_mainWin != null)
                    {
                        _mainWin.enableDisableAllCursors(true);
                    }
                }
            }
        }
        private void ChangeContent(UIElement newContent)
        {
            if (transitionHolder.Children.Count == 0)
            {
                transitionHolder.Children.Add(newContent);
                return;
            }

            if (transitionHolder.Children.Count == 1)
            {
                transitionHolder.IsHitTestVisible = false;
                UIElement oldContent = transitionHolder.Children[0];

                // An anoynmous function....interesting
                EventHandler onAnimationCompletedHandler = delegate(object sender, EventArgs e)
                {
                    transitionHolder.IsHitTestVisible = true;
                    transitionHolder.Children.Remove(oldContent);

                    // All these have destroyInternals on them ideally would have extended
                    // a common class to not have to do all this casting
                    try
                    {
                        SectionAttract att = oldContent as SectionAttract;
                        if (att != null)
                        {
                            destroyAttractSection(false);
                        }
                        SectionPhoto phot = oldContent as SectionPhoto;
                        if (phot != null)
                        {
                            destroyPhotoSection(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        // Who cares
                        Console.WriteLine("Animation Helper Exception destroying internals on one of the main sections - " + ex.ToString());
                    }
                };

                // ---- SLide animation -----
                double leftStart = Canvas.GetLeft(oldContent);
                Canvas.SetLeft(newContent, leftStart - GlobalConfiguration.currentScreenW);

                transitionHolder.Children.Add(newContent);

                if (double.IsNaN(leftStart))
                {
                    leftStart = 0;
                }

                // -----> WHERE IS WIDTH COMING FROM??? THE WINDOW??
                DoubleAnimation outAnimation = new DoubleAnimation(leftStart, leftStart + GlobalConfiguration.currentScreenW, new Duration(TimeSpan.FromSeconds(0.5)));
                DoubleAnimation inAnimation = new DoubleAnimation(leftStart - GlobalConfiguration.currentScreenW, leftStart, new Duration(TimeSpan.FromSeconds(0.5)));
                inAnimation.Completed += onAnimationCompletedHandler;

                // Easing
                SineEase ease = new SineEase();
                ease.EasingMode = EasingMode.EaseOut;
                outAnimation.EasingFunction = ease;
                inAnimation.EasingFunction = ease;
                oldContent.BeginAnimation(Canvas.LeftProperty, outAnimation);
                newContent.BeginAnimation(Canvas.LeftProperty, inAnimation);
            }
        }
Пример #22
0
 public void Start()
 {
     if (ended)
     {
         NumberOfRotation=0;
         this.Visibility = Visibility.Visible;
         ended = false;
         nonFinalCanvas.Visibility = Visibility.Visible;
         finalCanvas.Visibility = Visibility.Collapsed;
         EasingFunctionBase easing = new SineEase();
         effect = new RotateEffect(-90, 90, 100, EasingMode.EaseInOut, easing);
         effect.RotationCenter = new Point(0.5, 0.5);
         effect.Duration = 500;
         effect.Completed += effect_Completed;
         q = new Queue<FrameworkElement>();
         if (Toss)
         {
             effect.Start(nonFinalCanvas);
             q.Enqueue(finalCanvas);
             q.Enqueue(nonFinalCanvas);
         }
         else
         {
             effect.Start(finalCanvas);
             q.Enqueue(nonFinalCanvas);
             q.Enqueue(finalCanvas);
         }
     }
 }
        // Should slide these in from the left and right
        private void showNewImages()
        {
            double delayBuildUp = 0;

            for (int i = 0; i < mainHolder.Children.Count; i++)
            {
                // need to get references to each border
                var curBorder = mainHolder.Children[i] as Border;
                if (curBorder != null)
                {

                    // Figure out a random placement and tilted angle on the display
                    // -45 to 45
                    int angle = _rand.Next(-10, 10);

                    // We know that the scroller needs 200 px
                    // We know the actual bar needs 74
                    double availableWidth = GlobalConfiguration.currentScreenW - 640 - 50;
                    int finX = _rand.Next(50, (int)availableWidth);
                    double availableHeight = GlobalConfiguration.currentScreenH - 250 - 480;
                    int finY = _rand.Next(0, (int)availableHeight);

                    var previousPoints = (Point)curBorder.GetValue(FrameworkElement.TagProperty);
                    if (previousPoints != null)
                    {
                        // Transforms for moving and rotating - need the first positions
                        TranslateTransform moveTransform = new TranslateTransform(previousPoints.X, previousPoints.Y);
                        RotateTransform rotTransform = new RotateTransform(0);
                        TransformGroup photoTransforms = new TransformGroup();
                        photoTransforms.Children.Add(moveTransform);
                        photoTransforms.Children.Add(rotTransform);

                        curBorder.RenderTransform = photoTransforms;

                        SineEase ease = new SineEase();
                        ease.EasingMode = EasingMode.EaseOut;

                        DoubleAnimation daMoveX = new DoubleAnimation();
                        DoubleAnimation daMoveY = new DoubleAnimation();
                        DoubleAnimation daRotate = new DoubleAnimation();
                        daMoveX.To = finX;
                        daMoveY.To = finY;
                        daRotate.To = angle;
                        daMoveX.EasingFunction = ease;
                        daRotate.EasingFunction = ease;
                        daMoveY.EasingFunction = ease;

                        int moveRandTime = _rand.Next(1, 3);
                        daMoveX.Duration = TimeSpan.FromSeconds(moveRandTime);
                        daRotate.Duration = TimeSpan.FromSeconds(_rand.Next(1, 2));
                        daMoveY.Duration = TimeSpan.FromSeconds(moveRandTime);

                        daMoveX.BeginTime = TimeSpan.FromSeconds(delayBuildUp);
                        daMoveY.BeginTime = TimeSpan.FromSeconds(delayBuildUp);
                        daRotate.BeginTime = TimeSpan.FromSeconds(delayBuildUp);
                        delayBuildUp += .3;

                        // Only add a complete listener to the final guy
                        if (i == mainHolder.Children.Count - 1)
                        {
                            daMoveX.Completed += handleAnimationOnComplete;
                        }

                        moveTransform.BeginAnimation(TranslateTransform.XProperty, daMoveX);
                        moveTransform.BeginAnimation(TranslateTransform.YProperty, daMoveY);
                        rotTransform.BeginAnimation(RotateTransform.AngleProperty, daRotate);
                    }

                }
            }
        }