Exemplo n.º 1
0
 private static void WriteTouchElementNode(XElement parent, TouchElement element)
 {
     parent.Add(new XElement("Touch",
                             new XElement("Location", $"{element.LocationX}, {element.LocationY}"),
                             new XElement("Size", $"{element.SizeX}, {element.SizeY}"),
                             new XElement("JumpScreen", element.JumpScreen),
                             new XElement("SoundIndex", element.SoundIndex),
                             new XElement("Command", element.CommandInfo.Name),
                             new XElement("CommandOption", element.CommandOption)
                             ));
 }
Exemplo n.º 2
0
        public void ClickHovers()
        {
            Entities.ForEach((ref ButtonClickType c0) => {
                c0.Value = ClickType.PressDown | ClickType.ReleaseUp;
            });
            Entities.ForEach((DynamicBuffer <TouchElement> b0) => {
                b0[0] = new TouchElement {
                    Phase = TouchPhase.Canceled
                };
            });

            mouseCollisionSystem.Update();

            Entities.ForEach((ref ClickState c0, ref ButtonVisual c1) => {
                Assert.AreEqual(false, c0.Value);
                Assert.AreEqual(ButtonVisualState.Hover, c1.Value);
            });
        }
Exemplo n.º 3
0
        protected override void OnUpdate()
        {
            Entities.ForEach((DynamicBuffer <TouchElement> b0) => {
                var touchBuffer = b0.AsNativeArray();

                var size = math.min(Input.touchCount, touchBuffer.Length);

                for (int i = 0; i < size; i++)
                {
                    touchBuffer[i] = Input.GetTouch(i);
                }

                for (int i = size; i < touchBuffer.Length; i++)
                {
                    touchBuffer[i] = TouchElement.Default();
                }
            }).WithoutBurst().Run();
        }
Exemplo n.º 4
0
        public void ClicksOnRelease()
        {
            Entities.ForEach((ref ButtonClickType c0) => {
                c0.Value = ClickType.ReleaseUp;
            });
            Entities.ForEach((DynamicBuffer <TouchElement> b0) => {
                for (int i = 0; i < b0.Length; i++)
                {
                    b0[i] = new TouchElement {
                        Phase = TouchPhase.Ended,
                    };
                }
            });

            mouseCollisionSystem.Update();

            Entities.ForEach((ref ClickState c0, ref ButtonVisual c1) => {
                Assert.AreEqual(true, c0.Value);
                Assert.AreEqual(ButtonVisualState.Pressed, c1.Value);
            });
        }
Exemplo n.º 5
0
        private static void WriteTouchElementNode(XElement parent, TouchElement element)
        {
            XElement touchNode = new XElement("Touch",
                                              new XElement("Location", $"{element.LocationX}, {element.LocationY}"),
                                              new XElement("Layer", element.Layer),
                                              new XElement("Size", $"{element.SizeX}, {element.SizeY}"),
                                              new XElement("JumpScreen", element.JumpScreen)
                                              );

            if (element.SoundEntries.Any())
            {
                touchNode.Add(new XElement("SoundEntries", element.SoundEntries.Select(WriteTouchElementSoundEntryNode)));
            }

            if (element.CommandEntries.Any())
            {
                touchNode.Add(new XElement("CommandEntries", element.CommandEntries.Select(WriteTouchElementCommandEntryNode)));
            }

            parent.Add(touchNode);
        }
Exemplo n.º 6
0
        public void ClickResets()
        {
            Entities.ForEach((ref ButtonClickType c0) => {
                c0.Value = ClickType.PressDown | ClickType.ReleaseUp;
            });
            Entities.ForEach((DynamicBuffer <TouchElement> b0) => {
                for (int i = 0; i < b0.Length; i++)
                {
                    b0[i] = new TouchElement {
                        Phase    = TouchPhase.Canceled,
                        Position = new float2(1920, 1080)
                    };
                }
            });

            mouseCollisionSystem.Update();

            Entities.ForEach((ref ClickState c0, ref ButtonVisual c1) => {
                Assert.AreEqual(false, c0.Value);
                Assert.AreEqual(ButtonVisualState.None, c1.Value);
            });
        }
Exemplo n.º 7
0
        public void ClicksOnHold()
        {
            Entities.ForEach((ref ButtonClickType c0) => {
                c0.Value = ClickType.Held;
            });
            Entities.ForEach((DynamicBuffer <TouchElement> b0) => {
                for (int i = 0; i < b0.Length; i++)
                {
                    b0[i] = new TouchElement {
                        Phase    = TouchPhase.Began | TouchPhase.Moved | TouchPhase.Stationary,
                        Position = new float2()
                    };
                }
            });

            mouseCollisionSystem.Update();

            Entities.ForEach((ref ClickState c0, ref ButtonVisual c1) => {
                Assert.AreEqual(true, c0.Value);
                Assert.AreEqual(ButtonVisualState.Pressed, c1.Value);
            });
        }
Exemplo n.º 8
0
        internal TouchElementViewModel(TouchElement touch)
        {
            CultureInfo culture = CultureInfo.InvariantCulture;

            CompositeDisposable treeItemDisposable = new CompositeDisposable();
            CompositeDisposable listItemDisposable = new CompositeDisposable();

            LocationX = touch
                        .ToReactivePropertyAsSynchronized(
                x => x.LocationX,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                        .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.Any, out result, out message);

                return(message);
            })
                        .AddTo(disposable);

            LocationY = touch
                        .ToReactivePropertyAsSynchronized(
                x => x.LocationY,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                        .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.Any, out result, out message);

                return(message);
            })
                        .AddTo(disposable);

            SizeX = touch
                    .ToReactivePropertyAsSynchronized(
                x => x.SizeX,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                    .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.NonNegative, out result, out message);

                return(message);
            })
                    .AddTo(disposable);

            SizeY = touch
                    .ToReactivePropertyAsSynchronized(
                x => x.SizeY,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                    .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.NonNegative, out result, out message);

                return(message);
            })
                    .AddTo(disposable);

            JumpScreen = touch
                         .ToReactivePropertyAsSynchronized(x => x.JumpScreen)
                         .AddTo(disposable);

            SoundEntries = touch.SoundEntries
                           .ToReadOnlyReactiveCollection(x => new SoundEntryViewModel(x))
                           .AddTo(disposable);

            CommandEntries = touch.CommandEntries
                             .ToReadOnlyReactiveCollection(x => new CommandEntryViewModel(x))
                             .AddTo(disposable);

            Layer = touch
                    .ToReactivePropertyAsSynchronized(x => x.Layer)
                    .AddTo(disposable);

            TreeItem = touch
                       .ObserveProperty(x => x.TreeItem)
                       .Do(_ => TreeItem?.Value.Dispose())
                       .Select(x => new TreeViewItemViewModel(x))
                       .ToReactiveProperty()
                       .AddTo(disposable);

            TreeItem.Subscribe(x =>
            {
                treeItemDisposable.Dispose();
                treeItemDisposable = new CompositeDisposable();

                x.PropertyChangedAsObservable()
                .ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.None)
                .Subscribe(_ => TreeItem.ForceNotify())
                .AddTo(treeItemDisposable);
            })
            .AddTo(disposable);

            SelectedTreeItem = touch
                               .ToReactivePropertyAsSynchronized(
                x => x.SelectedTreeItem,
                x => TreeItem.Value.SearchViewModel(x),
                x => x?.Model
                )
                               .AddTo(disposable);

            ListColumns = touch.ListColumns
                          .ToReadOnlyReactiveCollection(x => new ListViewColumnHeaderViewModel(x))
                          .AddTo(disposable);

            ListItems = touch.ListItems
                        .ToReadOnlyReactiveCollection(x => new ListViewItemViewModel(x))
                        .AddTo(disposable);

            SelectedListItem = touch
                               .ToReactivePropertyAsSynchronized(
                x => x.SelectedListItem,
                x => ListItems.FirstOrDefault(y => y.Model == x),
                x => x?.Model
                )
                               .AddTo(disposable);

            SelectedTreeItem
            .Subscribe(_ =>
            {
                SelectedListItem.Value = null;
                touch.CreateListColumns();
                touch.CreateListItems();
            })
            .AddTo(disposable);

            SelectedListItem
            .Where(x => x != null)
            .Subscribe(x =>
            {
                listItemDisposable.Dispose();
                listItemDisposable = new CompositeDisposable();

                CompositeDisposable tagDisposable = new CompositeDisposable();

                x.Tag
                .OfType <INotifyPropertyChanged>()
                .Subscribe(y =>
                {
                    tagDisposable.Dispose();
                    tagDisposable = new CompositeDisposable();

                    y.PropertyChangedAsObservable()
                    .Subscribe(_ => touch.UpdateListItem(x.Model))
                    .AddTo(tagDisposable);
                })
                .AddTo(listItemDisposable);

                tagDisposable.AddTo(listItemDisposable);
            })
            .AddTo(disposable);

            SelectedSoundEntry = SelectedListItem
                                 .Select(x => x?.Tag.Value as TouchElement.SoundEntry)
                                 .Do(_ => SelectedSoundEntry?.Value?.Dispose())
                                 .Select(x => x != null ? new SoundEntryViewModel(x) : null)
                                 .ToReadOnlyReactivePropertySlim()
                                 .AddTo(disposable);

            SelectedCommandEntry = SelectedListItem
                                   .Select(x => x?.Tag.Value as TouchElement.CommandEntry)
                                   .Do(_ => SelectedCommandEntry?.Value?.Dispose())
                                   .Select(x => x != null ? new CommandEntryViewModel(x) : null)
                                   .ToReadOnlyReactivePropertySlim()
                                   .AddTo(disposable);

            AddSoundEntry = SelectedTreeItem
                            .Select(x => x == TreeItem.Value.Children[0])
                            .ToReactiveCommand()
                            .WithSubscribe(touch.AddSoundEntry)
                            .AddTo(disposable);

            AddCommandEntry = SelectedTreeItem
                              .Select(x => x == TreeItem.Value.Children[1])
                              .ToReactiveCommand()
                              .WithSubscribe(touch.AddCommandEntry)
                              .AddTo(disposable);

            CopySoundEntry = SelectedSoundEntry
                             .Select(x => x != null)
                             .ToReactiveCommand()
                             .WithSubscribe(touch.CopySoundEntry)
                             .AddTo(disposable);

            CopyCommandEntry = SelectedCommandEntry
                               .Select(x => x != null)
                               .ToReactiveCommand()
                               .WithSubscribe(touch.CopyCommandEntry)
                               .AddTo(disposable);

            RemoveSoundEntry = SelectedSoundEntry
                               .Select(x => x != null)
                               .ToReactiveCommand()
                               .WithSubscribe(touch.RemoveSoundEntry)
                               .AddTo(disposable);

            RemoveCommandEntry = SelectedCommandEntry
                                 .Select(x => x != null)
                                 .ToReactiveCommand()
                                 .WithSubscribe(touch.RemoveCommandEntry)
                                 .AddTo(disposable);
        }
Exemplo n.º 9
0
 internal TouchElementViewModel(TouchElement element, IEnumerable <TouchElement> otherElements) : base(element, otherElements)
 {
 }
Exemplo n.º 10
0
        internal TouchElementViewModel(TouchElement touch)
        {
            CultureInfo culture = CultureInfo.InvariantCulture;

            LocationX = touch
                        .ToReactivePropertyAsSynchronized(
                x => x.LocationX,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                        .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.Any, out result, out message);

                return(message);
            })
                        .AddTo(disposable);

            LocationY = touch
                        .ToReactivePropertyAsSynchronized(
                x => x.LocationY,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                        .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.Any, out result, out message);

                return(message);
            })
                        .AddTo(disposable);

            SizeX = touch
                    .ToReactivePropertyAsSynchronized(
                x => x.SizeX,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                    .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.NonNegative, out result, out message);

                return(message);
            })
                    .AddTo(disposable);

            SizeY = touch
                    .ToReactivePropertyAsSynchronized(
                x => x.SizeY,
                x => x.ToString(culture),
                x => double.Parse(x, NumberStyles.Float, culture),
                ignoreValidationErrorValue: true
                )
                    .SetValidateNotifyError(x =>
            {
                double result;
                string message;

                Utilities.TryParse(x, NumberRange.NonNegative, out result, out message);

                return(message);
            })
                    .AddTo(disposable);

            JumpScreen = touch
                         .ToReactivePropertyAsSynchronized(x => x.JumpScreen)
                         .AddTo(disposable);

            SoundIndex = touch
                         .ToReactivePropertyAsSynchronized(x => x.SoundIndex)
                         .AddTo(disposable);

            CommandInfo = touch
                          .ToReactivePropertyAsSynchronized(x => x.CommandInfo)
                          .AddTo(disposable);

            CommandOption = touch
                            .ToReactivePropertyAsSynchronized(x => x.CommandOption)
                            .AddTo(disposable);
        }