Beispiel #1
0
        public LoaderOutput GetLoaderOutput(BaseConfig config)
        {
            LoaderOutput lo = new LoaderOutput();

            switch (config.SourceType)
            {
            case SourceType.XML:
            {
                Picker = new XMLPicker();
                break;
            }

            case SourceType.Server:
            {
                Picker = new ServerPicker();
                break;
            }

            default:
            {
                throw new Exception("Niepoprawny typ danych w pliku konfiguracyjnym (SourceType)");
            }
            }

            lo = Picker.Load(config as BaseConfig);
            lo.CalculationScript = CleanScript(lo.CalculationScript);

            return(lo);
        }
Beispiel #2
0
        /// <summary>
        /// 根据彩种名称获取采集器列表
        /// </summary>
        /// <param name="lottery"></param>
        public static List <IPicker> GetPickerList(string lottery)
        {
            List <Type> list = GetTypeList(lottery);

            if (list.Count == 0)
            {
                return(new List <IPicker>());
            }

            List <IPicker> pickerList = new List <IPicker>();

            foreach (Type t in list)
            {
                try
                {
                    IPicker picker = Activator.CreateInstance(t) as IPicker;
                    if (picker != null)
                    {
                        pickerList.Add(picker);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return(pickerList);
        }
Beispiel #3
0
        internal static void UpdatePicker(this MauiPicker platformPicker, IPicker picker, int?newSelectedIndex = null)
        {
            var selectedIndex = newSelectedIndex ?? picker.SelectedIndex;

            // Revert to placeholder/title if nothing selected
            platformPicker.Text = selectedIndex == -1
                                ? (picker.Title ?? string.Empty)
                                : picker.GetItem(selectedIndex);

            var pickerView = platformPicker.UIPickerView;

            pickerView?.ReloadAllComponents();

            if (picker.GetCount() == 0)
            {
                return;
            }

            picker.SelectedIndex = selectedIndex;

            if (pickerView?.Model is PickerSource source)
            {
                source.SelectedIndex = selectedIndex;
            }

            pickerView?.Select(Math.Max(selectedIndex, 0), 0, true);
        }
Beispiel #4
0
 public CalculateStreak(
     IPicker picker,
     IResultChecker resultChecker)
 {
     _picker        = picker;
     _resultChecker = resultChecker;
 }
Beispiel #5
0
        /// <summary>
        /// 根据彩种和数据源获取采集器
        /// </summary>
        /// <param name="lottery">彩种代码</param>
        /// <param name="dataSource">数据源代码</param>
        public static IPicker GetPicker(string lottery, string dataSource)
        {
            List <Type> list = GetTypeList(lottery);

            if (list.Count == 0)
            {
                return(null);
            }

            list = list.Where(t => t.Name.Contains(dataSource)).ToList();
            if (list.Count == 0)
            {
                return(null);
            }


            try
            {
                IPicker picker = Activator.CreateInstance(list[0]) as IPicker;
                return(picker);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #6
0
        internal static void SetSelectedItem(this MauiPicker nativePicker, IPicker picker)
        {
            if (picker == null || nativePicker == null)
            {
                return;
            }

            int index = picker.SelectedIndex;

            if (index == -1)
            {
                picker.SelectedItem = null;
                return;
            }

            if (picker.ItemsSource != null)
            {
                picker.SelectedItem = picker.ItemsSource[index];
                return;
            }

            if (picker.Items != null)
            {
                picker.SelectedItem = picker.Items[index];
            }
        }
Beispiel #7
0
 /// <summary>
 /// Try to pick up a pickable object. Return true if successful. It may fail because
 /// the pickable object is being held by a picker whose <see cref="AllowSwitchingPicker"/>
 /// is false.
 /// </summary>
 /// <param name="pickable">The pickable object.</param>
 /// <returns>True if successful.</returns>
 protected bool AttachPickable(IPickable pickable)
 {
     if (pickable.IsPicked)
     {
         IPicker otherPicker = pickable.Picker;
         if (otherPicker == this)
         {
             Debug.LogError("Picking the same object.");
             return(false);
         }
         if (!otherPicker.AllowSwitchingPicker)
         {
             return(false);
         }
         else
         {
             // Switch picker
             otherPicker.SwitchPickerRelease();
         }
     }
     PickedObj = pickable;
     IsHolding = true;
     pickable.OnPickedInit(this);
     return(true);
 }
Beispiel #8
0
        /// <summary>
        /// Find the picker's angle of rotation from zero.
        /// </summary>
        /// <remarks>
        /// Once the picker is grasping the pickable object, it will stay on the "surface" of the
        /// pickable by maintaining a fixed displacement with a constrain point. The constrain point
        /// is a game object that will rotate together with this one. E.g. it can be the edge of the
        /// lever. When picker is moved to new position, the position of the new constrain point can
        /// be found in turn. Picker's angle of rotation can be calculated from the angle that needs
        /// to rotate from zero deg to the direction from centre of rotation to new constrain point.
        /// </remarks>
        /// <param name="picker">The picker that is grasping the object.</param>
        /// <returns>Picker's angle of rotation from zero.</returns>
        protected override float GetPickerAngleInRotationAxis(IPicker picker)
        {
            PickerDexmo pickerDexmo     = picker as PickerDexmo;
            Transform   pickerReference = pickerDexmo == null ? picker.Transform : pickerDexmo.PalmCenter;

            // We want the picker transform to maintain a fixed displacement in world space with the
            // constrain point, so when picker transform is moved to a new point, the new
            // constrain point can be obtained by subtracting the fixed displacement from
            // the picker transform.
            Vector3 newConstrainPoint = pickerReference.position - PickerFixedDisplacementWrtConstrainPoint;

            // Since the object itself is the centre of rotation and will rotate during runtime,
            // all the directions here is calculated in parent transform's coordinate.

            // transform.position is the centre of rotation. Find the direction pointing from
            // centre of rotation to new constrain point position.
            Vector3 pickerRelativeDirectionInParentCoordinate =
                Miscellaneous.InverseTransformDirectionInParentCoordinate(transform,
                                                                          newConstrainPoint - transform.position);
            // Find the angle of rotation from zero reference to the direction connecting the
            // centre of rotation to new constrain point position.
            float angle = RotationUtils.AngleInPlane(LocalRotationAxisInParentCoordinate,
                                                     ZeroReferenceDirectionInParentCoordinate, pickerRelativeDirectionInParentCoordinate);

            return(angle);
        }
Beispiel #9
0
        /// <summary>
        /// Called when the picker just grasps this object. Set some variables for
        /// later use.
        /// </summary>
        /// <param name="picker">Picker that grasps this object.</param>
        public override void OnPickedInit(IPicker picker)
        {
            Transform pickerTransform = picker.Transform;

            base.OnPickedInit(picker);
            _pickerPositionOffset = InverseTransformPointInParentCoordinate(
                pickerTransform.position);
        }
Beispiel #10
0
        /// <summary>
        /// Calculate the position to move based on the picker's current position
        /// during grasping.
        /// </summary>
        /// <param name="picker">Picker that is grasping this object.</param>
        protected override void MoveTowardsTargetWithConstraint(IPicker picker)
        {
            Transform pickerTransform = picker.Transform;
            float     currentMovement = GetPickerMovement(pickerTransform);

            transform.localPosition = _startPointInParentCoordinate +
                                      currentMovement * _linearRange * _linearMoveAxis;
        }
        /// <summary>
        /// It contrains the picker by overwriting its position and rotation. In this function
        /// it constrains picker by keeping picker a fixed postion and rotation offset with
        /// the position and the rotation of the constrain point reference transform.
        /// </summary>
        /// <remarks>
        /// The position and rotation offset between the picker and the constrain point reference
        /// is determined when this object is just picked up in <see cref="OnPickedInit"/>.
        /// Then when this pickable moves towards the picker with certain constraint, the
        /// constraint reference will move accordingly. This function is called to bring back
        /// picker so it always have the some offset with the constrain reference.
        /// This is a virtual function and the mechanism to constrain picker may be overridden by
        /// derived classes.
        /// </remarks>
        /// <param name="picker">The picker to constrain</param>
        protected virtual void ConstrainPicker(IPicker picker)
        {
            PickerDexmo pickerDexmo     = picker as PickerDexmo;
            Transform   pickerReference = null;

            if (pickerDexmo == null)
            {
                pickerReference = picker.Transform;
            }
            else
            {
                switch (PickerDexmoConstrainPart)
                {
                case PickerDexmoConstrainPartType.Wrist:
                    pickerReference = pickerDexmo.transform;
                    break;

                case PickerDexmoConstrainPartType.PalmCenter:
                    pickerReference = pickerDexmo.PalmCenter;
                    break;
                }
            }
            if (_constrainPositionReference != null)
            {
                // Constrain picker's position to ensure it has fixed displacement
                // with constrain reference.
                pickerReference.position = _constrainPositionReference.position +
                                           PickerFixedDisplacementWrtConstrainPoint;
            }
            if (_constrainRotationReference != null)
            {
                // Constrain picker's position to ensure it has fixed relative rotation
                // with constrain reference.
                pickerReference.rotation = _constrainRotationReference.rotation *
                                           PickerFixedAngleDisplacementWrtConstrainPoint;
            }
            else
            {
                //pickerReference.rotation = InitialPickerRotation;
            }

            if (pickerDexmo != null)
            {
                Vector3    pickerReferenceTargetPosition = pickerReference.position;
                Quaternion pickerReferenceTargetRotation = pickerReference.rotation;
                // In Unity, moving child transform will not change its parent, but
                // moving parent's transform will change all of its children, so the
                // constrained position and rotation of the hand root tranform (the
                // most parent transform) needs to be calculated and modified to constrain
                // the entire hand model. Target position and rotation of hand root
                // transform can be calculated from the target position and rotation of
                // its children, e.g. palm center.
                Miscellaneous.MoveParentTransformGivenChildTransform(
                    pickerDexmo.HandRootTransform, pickerReference,
                    pickerReferenceTargetPosition, pickerReferenceTargetRotation,
                    HandRootPositionRelativeToPicker, HandRootRotationRelativeToPicker);
            }
        }
        /// <summary>
        /// It is called when this pickable object is released by the picker.
        /// </summary>
        /// <remarks>
        /// Note it is a little different from the implementation of <see cref="Pickable"/>. It does
        /// not need to change the rigidbody properties, since all the movement has been defined
        /// in <see cref="MoveTowardsTargetWithConstraint"/>.
        /// </remarks>
        /// <param name="picker">The picker that releases it.</param>
        public override void OnReleased(IPicker picker)
        {
            Rigidbody activeRb = GetActiveRb();

            // Need to update pickable mapping whenever a pickable object is released.
            PickableMapping.UpdatePickableMapping(activeRb, false, picker);
            // Send PickedRelease event
            OnReleasedEvent(picker);
        }
Beispiel #13
0
        public static void UpdateTitle(this MauiComboBox nativeComboBox, IPicker picker)
        {
            nativeComboBox.Header = null;

            nativeComboBox.HeaderTemplate = string.IsNullOrEmpty(picker.Title) ? null :
                                            (UI.Xaml.DataTemplate)UI.Xaml.Application.Current.Resources["ComboBoxHeader"];

            nativeComboBox.DataContext = picker;
        }
        /// <summary>
        /// Calculate the angle it needs to rotate based on the current
        /// position of the picker and rotate itself from zero reference to that
        /// angle. Update the trigger state from the current angle.
        /// </summary>
        /// <param name="picker">The picker that is grasping the object.</param>
        protected override void MoveTowardsTargetWithConstraint(IPicker picker)
        {
            float currentAngle = GetAdjustedCurrentAngleFromPicker(picker);

            transform.localRotation = InitialLocalRotation;
            transform.Rotate(LocalRotationAxis, currentAngle, Space.Self);
            LastPickableAngle = currentAngle;
            UpdateTriggerState(currentAngle);
        }
Beispiel #15
0
        public static void UpdateCharacterSpacing(this MauiPicker nativePicker, IPicker picker)
        {
            var textAttr = nativePicker.AttributedText?.WithCharacterSpacing(picker.CharacterSpacing);

            if (textAttr != null)
            {
                nativePicker.AttributedText = textAttr;
            }
        }
Beispiel #16
0
        /// <summary>
        /// It will be called when this object is just picked up. It will save some relative
        /// rotation variables to be used later.
        /// </summary>
        /// <param name="picker">The picker that picks it up.</param>
        public override void OnPickedInit(IPicker picker)
        {
            PickerDexmo pickerDexmo     = picker as PickerDexmo;
            Transform   pickerReference =
                pickerDexmo == null ? picker.Transform : pickerDexmo.PalmCenter;

            _pickerRelativeRotationWrtKnob =
                Quaternion.Inverse(transform.rotation) * pickerReference.rotation;
            base.OnPickedInit(picker);
        }
Beispiel #17
0
        /// <summary>
        /// It will be called for every FixedUpdate cycle when this object is being held by
        /// the picker. It calculates its rigidbody's current position and rotation based on
        /// the fixed relative position and rotation recorded in <see cref="OnPickedInit"/>
        /// with respect to the picker.
        /// </summary>
        /// <param name="picker">The picker currently holding this pickable object.</param>
        public virtual void OnPickedUpdate(IPicker picker)
        {
            if (!IsPicked)
            {
                return;
            }
            Transform pickerTransform = picker.Transform;
            Rigidbody rb = GetActiveRb();
            // The position following the movement of the picker
            Vector3 calPosition = pickerTransform.position + pickerTransform.rotation * PositionOffsetWithPicker;
            // The rotation following the movement of the picker
            Quaternion calRotation = pickerTransform.rotation * RotationOffsetWithPicker;

            rb.MovePosition(calPosition);
            rb.MoveRotation(calRotation);
            //if (GameController.Instance.ForceReleaseWhenAway)
            //{
            //    if (Vector3.Distance(calPosition, rb.position) > GameController.Instance.ForceReleaseDistance)
            //    {
            //        OnReleased(picker);
            //        return;
            //    }
            //}
            //if (GameController.Instance.AllowPassThrough)
            //{
            //    rb.MovePosition(calPosition);
            //    rb.MoveRotation(calRotation);
            //}
            //else
            //{
            //    float angle;
            //    Vector3 axis;
            //    (calRotation * Quaternion.Inverse(rb.rotation)).ToAngleAxis(out angle, out axis);
            //    if (angle > 180)
            //    {
            //        angle -= 360;
            //    }
            //    // Angular velocity of the rigidbody at rb.position
            //    Vector3 angularVelocity = angle * axis / Time.fixedDeltaTime * 0.02f;
            //    // Linear velocity of the rigidbody at rb.position
            //    Vector3 velocityPoint = (calPosition - rb.position) / Time.fixedDeltaTime * 0.5f;
            //    // Find the angular velocity and linear velocity of the COM of rigidbody.
            //    // Note: rb.velocity the velocity of center of mass, which is not always equal to
            //    // that of rb.position. Same for rb.angularVelocity. That's why we need to find
            //    // the velocity and angularVelocity for COM of the rigidbody.
            //    FollowPointMotionRb(rb, rb.position, velocityPoint, angularVelocity,
            //        _velocityMax, _distMaxForFollowingAngVel);
            //    //Vector3 velocityCM = PhysicsUtils.FindCMLinearVelFromPoint(rb, rb.transform.position, velocityPoint, angularVelocity);
            //    //rb.angularVelocity = angularVelocity;
            //    //rb.velocity = velocityCM;
            //}

            // Send the PickedUpdate event.
            OnPickedUpdateEvent(picker);
        }
        async Task ValidateNativeSelectedIndex(IPicker slider, int selectedIndex)
        {
            var expected = await GetValueAsync(slider, handler =>
            {
                var pickerView = GetNativePicker(handler).UIPickerView;
                var model      = (PickerSource)pickerView.Model;
                return(model.SelectedIndex);
            });

            Assert.Equal(expected, selectedIndex);
        }
        async Task ValidateNativeItemsSource(IPicker picker, int itemsCount)
        {
            var expected = await GetValueAsync(picker, handler =>
            {
                var pickerView = GetNativePicker(handler).UIPickerView;
                var model      = (PickerSource)pickerView.Model;
                return(model.GetRowsInComponent(pickerView, 0));
            });

            Assert.Equal(expected, itemsCount);
        }
Beispiel #20
0
 internal static void UpdatePicker(this Entry platformPicker, IPicker picker)
 {
     if (picker.SelectedIndex == -1 || picker.SelectedIndex >= picker.GetCount())
     {
         platformPicker.Text = string.Empty;
     }
     else
     {
         platformPicker.Text = picker.GetItem(picker.SelectedIndex);
     }
 }
 /// <summary>
 /// It is called at every FixedUpdate cycle. It moves according to the current position and
 /// rotation of the picker. Then it constrains the picker position and rotation by overwriting
 /// it, so it appears in graphics that the picker always stay on the surface of this pickable
 /// object.
 /// </summary>
 /// <param name="picker">The picker that is holding it.</param>
 public override void OnPickedUpdate(IPicker picker)
 {
     // Move itself according to the picker's current position and rotation. The exact movement
     // is implemented by the derived class.
     MoveTowardsTargetWithConstraint(picker);
     // Since the picker is tracked in reality, its position and rotation needs to be overwritten
     // to appear to stay on the surface of this pickable.
     ConstrainPicker(picker);
     // Send PickedUpdate event
     OnPickedUpdateEvent(picker);
 }
        public static async Task <IEnumerable <T> > TryRunAsync <T>(this IPicker <T> source, IEnumerable <T> context, IEnumerable <T> selected = null, string title = "", string prompt = "", string primaryText = "", string secondaryText = "", bool freezeSelected = false)
        {
            if (source == null)
            {
                return(Enumerable.Empty <T>());
            }

            var vm = new PickerViewModel <T>(context, selected, title, prompt, primaryText, secondaryText, freezeSelected);

            return(await source.RunAsync(vm));
        }
Beispiel #23
0
        public static void UpdateTextColor(this MauiComboBox nativeComboBox, IPicker picker, WBrush?defaultForeground)
        {
            Color color = picker.TextColor;

            if (color.IsDefault() && defaultForeground == null)
            {
                return;
            }

            nativeComboBox.Foreground = color.IsDefault() ? (defaultForeground ?? color.ToNative()) : color.ToNative();
        }
Beispiel #24
0
        public static void UpdateTitleColor(this MauiPicker platformPicker, IPicker picker)
        {
            var titleColor = picker.TitleColor;

            if (titleColor != null)
            {
                if (PlatformInterop.CreateEditTextColorStateList(platformPicker.TextColors, titleColor.ToPlatform()) is ColorStateList c)
                {
                    platformPicker.SetHintTextColor(c);
                }
            }
        }
        /// <summary>
        /// Calculate the angle it needs to rotate based on the current
        /// position of the picker and rotate itself from zero reference to that
        /// angle
        /// </summary>
        /// <param name="picker">The picker that is grasping the object.</param>
        protected override void MoveTowardsTargetWithConstraint(IPicker picker)
        {
            // Calculate the angle it needs to rotate based on the position
            // of the picker
            float currentAngle = GetAdjustedCurrentAngleFromPicker(picker);

            // Restore the itself to zero rotation and rotate from there
            transform.localRotation = InitialLocalRotation;
            transform.Rotate(_localRotationAxis, currentAngle, Space.Self);
            // Save its current angle of rotation
            LastPickableAngle = currentAngle;
        }
Beispiel #26
0
        internal static void SetSelectedIndex(this MauiPicker nativePicker, IPicker picker, int selectedIndex = 0)
        {
            picker.SelectedIndex = selectedIndex;

            var pickerView = nativePicker.UIPickerView;

            if (pickerView?.Model is PickerSource source)
            {
                source.SelectedIndex = selectedIndex;
            }

            pickerView?.Select(Math.Max(selectedIndex, 0), 0, true);
        }
Beispiel #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        public PickerCollection CreatePickers(string deviceType)
        {
            PickerCollection   uploadParsers = new PickerCollection();
            OperaDefineFactory f             = new OperaDefineFactory();

            f.LoadFromPath(DefineDirectory);
            foreach (UploadDefine ud in f.UploadDefines)
            {
                IPicker p = ud.Create("aaa");
                uploadParsers.Add(p);
            }
            return(uploadParsers);
        }
Beispiel #28
0
        internal static void UpdatePicker(this MauiPicker nativePicker, IPicker picker)
        {
            nativePicker.Hint = picker.Title;

            if (picker.SelectedIndex == -1 || picker.SelectedIndex >= picker.GetCount())
            {
                nativePicker.Text = null;
            }
            else
            {
                nativePicker.Text = picker.GetItem(picker.SelectedIndex);
            }
        }
Beispiel #29
0
        public static void UpdateTitleColor(this MauiPicker platformPicker, IPicker picker)
        {
            var titleColor = picker.TitleColor;

            if (titleColor != null)
            {
                var androidColor = titleColor.ToPlatform();
                if (!platformPicker.TextColors.IsOneColor(ColorStates.EditText, androidColor))
                {
                    platformPicker.SetHintTextColor(ColorStateListExtensions.CreateEditText(androidColor));
                }
            }
        }
Beispiel #30
0
        public static void UpdateBackground(this ComboBox nativeComboBox, IPicker picker)
        {
            var platformBrush = picker.Background?.ToPlatform();

            if (platformBrush == null)
            {
                nativeComboBox.Resources.RemoveKeys(_backgroundColorResourceKeys);
            }
            else
            {
                nativeComboBox.Resources.SetValueForAllKey(_backgroundColorResourceKeys, platformBrush);
            }
        }
		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);
			SetContentView (Resource.Layout.MainLayout);

			// Create the picker instance
			picker = Picker.CreatePicker (OneDriveAppId);

			// Add the start picker listener
			FindViewById<Button> (Resource.Id.startPickerButton).Click += delegate {
				// Clear out any previous results
				ClearResultTable ();

				// Determine the link type that was selected
				LinkType linkType;
				if (FindViewById<RadioButton> (Resource.Id.radioWebViewLink).Checked) {
					linkType = LinkType.WebViewLink;
				} else if (FindViewById<RadioButton> (Resource.Id.radioDownloadLink).Checked) {
					linkType = LinkType.DownloadLink;
				} else {
					throw new Exception ("Invalid Radio Button Choosen.");
				}

				// Start the picker
				picker.StartPicking (this, linkType);
			};

			// Add the save as listener for download links
			FindViewById<Button> (Resource.Id.saveAsButton).Click += delegate {
				if (downloadUrl != null) {
					var downloadManager = DownloadManager.FromContext (this);
					var request = new DownloadManager.Request (downloadUrl);
					request.SetNotificationVisibility (DownloadVisibility.VisibleNotifyCompleted);
					downloadManager.Enqueue (request);
				}
			};
		}
        public DatePickerHtmlBuilderBase(IPicker picker, string inputType)
        {
            Component = picker;

            InputType = inputType ?? "date";
        }