Beispiel #1
0
        /// <summary>Initializes a new instance of the <see cref="CitiesSliderItem"/> class.</summary>
        /// <param name="uiHelper">The game's UI helper reference.</param>
        /// <param name="id">The view item's unique ID.</param>
        /// <param name="property">
        /// The property description that specifies the target property where to store the value.
        /// </param>
        /// <param name="config">The configuration storage object for the value.</param>
        /// <param name="min">The minimum slider value.</param>
        /// <param name="max">The maximum slider value.</param>
        /// <param name="step">The slider step value. Default is 1.</param>
        /// <param name="valueType">The type of the value to display. Default is <see cref="SliderValueType.Percentage"/>.</param>
        /// <param name="displayMultiplier">A value that will be multiplied with original values for displaying purposes.</param>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        /// <exception cref="ArgumentException">
        /// thrown when the <paramref name="id"/> is an empty string.
        /// </exception>
        public CitiesSliderItem(
            UIHelperBase uiHelper,
            string id,
            PropertyInfo property,
            object config,
            float min,
            float max,
            float step,
            SliderValueType valueType,
            float displayMultiplier)
            : base(uiHelper, id, property, config)
        {
            UIComponent.minValue   = min;
            UIComponent.maxValue   = max;
            UIComponent.stepSize   = step;
            this.valueType         = valueType;
            this.displayMultiplier = displayMultiplier;
            var parentPanel = UIComponent.parent as UIPanel;

            if (parentPanel != null)
            {
                parentPanel.autoLayoutDirection = LayoutDirection.Horizontal;
                parentPanel.autoSize            = true;
            }

            if (UIComponent.parent != null)
            {
                valueLabel = UIComponent.parent.AddUIComponent <UILabel>();
                valueLabel.padding.left = SliderValueLabelPadding;
                valueLabel.name         = id + LabelName;
                UpdateValueLabel(Value);
            }
        }
Beispiel #2
0
 public IViewItem CreateSlider(
     IContainerViewItem container,
     string id,
     PropertyInfo property,
     object config,
     float min,
     float max,
     float step,
     SliderValueType valueType)
 {
     return(new UnitySliderItem(container.Container, id, property, config, min, max, step, valueType));
 }
Beispiel #3
0
 /// <summary>Creates a new slider view item.</summary>
 /// <param name="container">The parent container for the created item.</param>
 /// <param name="id">The ID of the item to create.</param>
 /// <param name="property">The property description that specifies the target property where to store the value.</param>
 /// <param name="config">The configuration storage object for the value.</param>
 /// <param name="min">The minimum slider value.</param>
 /// <param name="max">The maximum slider value.</param>
 /// <param name="step">The slider step value.</param>
 /// <param name="valueType">Type of the value to be represented by the slider.</param>
 /// <param name="displayMultiplier">A value that will be multiplied with original values for displaying purposes.</param>
 /// <returns>A newly created <see cref="IViewItem"/> instance representing a slider.</returns>
 /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
 /// <exception cref="ArgumentException">Thrown when <paramref name="id"/> is an empty string.</exception>
 /// <exception cref="ArgumentException">
 /// Thrown when the <paramref name="max"/> value is less or equal to the <paramref name="min"/> value.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// Thrown when the <paramref name="step"/> value is less or equal to zero.
 /// </exception>
 public IViewItem CreateSlider(
     IContainerViewItem container,
     string id,
     PropertyInfo property,
     object config,
     float min,
     float max,
     float step,
     SliderValueType valueType,
     float displayMultiplier)
 {
     return(new CitiesSliderItem(container.Container, id, property, config, min, max, step, valueType, displayMultiplier));
 }
        public ConfigItemSliderAttribute(float min, float max, float step, SliderValueType valueType)
        {
            if (max <= min)
            {
                throw new ArgumentException("The maximum value must be greater than the minimum value");
            }

            if (step == 0)
            {
                throw new ArgumentException("The step value must be greater than 0");
            }

            Min       = min;
            Max       = max;
            Step      = step;
            ValueType = valueType;
        }
        /// <summary>Creates a new slider view item.</summary>
        /// <param name="container">The parent container for the created item.</param>
        /// <param name="id">The ID of the item to create.</param>
        /// <param name="property">The property description that specifies the target property where to store the value.</param>
        /// <param name="configProvider">A method that provides the configuration storage object for the value.</param>
        /// <param name="min">The minimum slider value.</param>
        /// <param name="max">The maximum slider value.</param>
        /// <param name="step">The slider step value.</param>
        /// <param name="valueType">Type of the value to be represented by the slider.</param>
        /// <param name="displayMultiplier">A value that will be multiplied with original values for displaying purposes.</param>
        /// <returns>A newly created <see cref="IViewItem"/> instance representing a slider.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="id"/> is an empty string.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown when the <paramref name="max"/> value is less or equal to the <paramref name="min"/> value.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown when the <paramref name="step"/> value is less or equal to zero.
        /// </exception>
        public IViewItem CreateSlider(
            IContainerViewItem container,
            string id,
            PropertyInfo property,
            Func <object> configProvider,
            float min,
            float max,
            float step,
            SliderValueType valueType,
            float displayMultiplier)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            return(new CitiesSliderItem(container.Container, id, property, configProvider, min, max, step, valueType, displayMultiplier));
        }
Beispiel #6
0
        /// <summary>Initializes a new instance of the <see cref="CitiesSliderItem"/> class.</summary>
        /// <param name="uiHelper">The game's UI helper reference.</param>
        /// <param name="id">The view item's unique ID.</param>
        /// <param name="property">
        /// The property description that specifies the target property where to store the value.
        /// </param>
        /// <param name="configProvider">A method that provides the configuration storage object for the value.</param>
        /// <param name="min">The minimum slider value.</param>
        /// <param name="max">The maximum slider value.</param>
        /// <param name="step">The slider step value. Default is 1.</param>
        /// <param name="valueType">The type of the value to display. Default is <see cref="SliderValueType.Percentage"/>.</param>
        /// <param name="displayMultiplier">A value that will be multiplied with original values for displaying purposes.</param>
        /// <exception cref="ArgumentNullException">Thrown when any argument is null.</exception>
        /// <exception cref="ArgumentException">
        /// thrown when the <paramref name="id"/> is an empty string.
        /// </exception>
        public CitiesSliderItem(
            UIHelperBase uiHelper,
            string id,
            PropertyInfo property,
            Func <object> configProvider,
            float min,
            float max,
            float step,
            SliderValueType valueType,
            float displayMultiplier)
            : base(uiHelper, id, property, configProvider)
        {
            UIComponent.minValue   = min;
            UIComponent.maxValue   = max;
            UIComponent.stepSize   = step;
            UIComponent.width      = 320;
            this.valueType         = valueType;
            this.displayMultiplier = displayMultiplier;
            var parentPanel = UIComponent.parent as UIPanel;

            if (parentPanel != null)
            {
                parentPanel.autoLayoutDirection         = LayoutDirection.Horizontal;
                parentPanel.autoFitChildrenHorizontally = true;
                parentPanel.autoFitChildrenVertically   = true;

                UILabel label = parentPanel.components.OfType <UILabel>().FirstOrDefault();
                if (label != null)
                {
                    label.width         = SliderLabelWidth;
                    label.padding.right = 10;
                }
            }

            if (UIComponent.parent != null)
            {
                valueLabel = UIComponent.parent.AddUIComponent <UILabel>();
                valueLabel.padding.left = SliderValueLabelPadding;
                valueLabel.name         = id + LabelName;
                UpdateValueLabel(Value);
            }

            Refresh();
        }