public static UIButton GetKeymapping(UIComponent parent, Shortcut shortcut)
        {
            UIPanel uIPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject(kKeyBindingTemplate)) as UIPanel;

            UIButton uIButton = uIPanel.Find <UIButton>("Binding");

            //uIButton = UnityEngine.Object.Instantiate<GameObject>(uIButton.gameObject).GetComponent<UIButton>();
            m_components.Add(uIButton);
            parent.AttachUIComponent(uIButton.gameObject);

            uIButton.eventKeyDown   += new KeyPressHandler(OnBindingKeyDown);
            uIButton.eventMouseDown += new MouseEventHandler(OnBindingMouseDown);

            if (shortcut != null)
            {
                uIButton.text = SavedInputKey.ToLocalizedString("KEYNAME", shortcut.inputKey);
            }
            else
            {
                uIButton.text = Locale.Get("KEYNAME", ((InputKey)0).ToString());
            }
            uIButton.objectUserData = shortcut;

            //GameObject.DestroyImmediate(uIPanel);

            return(uIButton);
        }
Пример #2
0
        public UILabel AddLabel(string name)
        {
            UIPanel uIPanel = m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;

            uIPanel.autoFitChildrenVertically = true;
            UILabel label = uIPanel.Find <UILabel>("Label");

            label.text        = name;
            label.maximumSize = new Vector2(700, 9999);
            label.minimumSize = new Vector2(700, 0);
            label.wordWrap    = true;
            GameObject.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject);

            return(label);
        }
Пример #3
0
        void CreateView()
        {
            ModDebug.Log("Creating view");

            GameObject rootObject = new GameObject(panelName);

            tabstrip = rootObject.AddComponent <UITabstrip>();

            CreateButtons();

            roadsOptionPanel.AttachUIComponent(tabstrip.gameObject);
            tabstrip.relativePosition = new Vector3(90, 38);
            tabstrip.width            = 80;
            tabstrip.selectedIndex    = -1;
            tabstrip.padding          = new RectOffset(0, 1, 0, 0);

            if (builtinModeChangedHandler == null)
            {
                builtinModeChangedHandler = (UIComponent component, int index) => {
                    if (!ignoreBuiltinTabstripEvents)
                    {
                        if (selectedToolModeChanged != null)
                        {
                            selectedToolModeChanged(ToolMode.None);
                        }
                    }
                };
            }

            builtinTabstrip.eventSelectedIndexChanged += builtinModeChangedHandler;

            // Setting selectedIndex needs to be delayed for some reason
            tabstrip.StartCoroutine(FinishCreatingView());
        }
Пример #4
0
        public CrudDropDownComponent(UIComponent parent, string title)
        {
            m_parent = parent;
            UIPanel uIPanel = m_parent.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;

            uIPanel.name   = "DropDownColorSelector";
            uIPanel.height = 40;
            uIPanel.width  = 280;
            uIPanel.autoLayoutDirection = LayoutDirection.Horizontal;
            uIPanel.autoLayoutStart     = LayoutStart.TopLeft;


            m_title               = uIPanel.Find <UILabel> ("Label");
            m_title.autoSize      = false;
            m_title.name          = "Title";
            m_title.text          = title;
            m_title.height        = 28;
            m_title.width         = 140;
            m_title.textAlignment = UIHorizontalAlignment.Left;
            m_title.textColor     = Color.white;
            m_title.padding       = new RectOffset(5, 5, 5, 5);

            m_dropDown = uIPanel.Find <UIDropDown> ("Dropdown");
            initializeDropDown(ref m_dropDown);
        }
Пример #5
0
        public static UIColorField CreateColorField(this UIComponent parent, string text, Vector2 position)
        {
            UIComponent template = UITemplateManager.Get("LineTemplate");

            if (template == null)
            {
                return(null);
            }

            UIColorField colorFIeldTemplate = template.Find <UIColorField>("LineColor");

            if (colorFIeldTemplate == null)
            {
                return(null);
            }

            UIColorField colorField = Object.Instantiate(colorFIeldTemplate.gameObject).GetComponent <UIColorField>();

            parent.AttachUIComponent(colorField.gameObject);
            colorField.name = "PainterColorField";
            colorField.AlignTo(parent, UIAlignAnchor.TopRight);
            colorField.position       = position;
            colorField.size           = new Vector2(40f, 40f);
            colorField.pickerPosition = UIColorField.ColorPickerPosition.RightBelow;
            return(colorField);
        }
Пример #6
0
        public static UIColorField CreateColorField(UIComponent parent)
        {
            // Creating a ColorField from scratch is tricky. Cloning an existing one instead.

            if (_colorFIeldTemplate == null)
            {
                // Get the LineTemplate (PublicTransportDetailPanel)
                UIComponent template = UITemplateManager.Get("LineTemplate");
                if (template == null)
                {
                    return(null);
                }

                // Extract the ColorField
                _colorFIeldTemplate = template.Find <UIColorField>("LineColor");
                if (_colorFIeldTemplate == null)
                {
                    return(null);
                }
            }

            UIColorField colorField = UnityEngine.Object.Instantiate <GameObject>(_colorFIeldTemplate.gameObject).GetComponent <UIColorField>();

            parent.AttachUIComponent(colorField.gameObject);

            colorField.size           = new Vector2(40f, 26f);
            colorField.pickerPosition = UIColorField.ColorPickerPosition.LeftAbove;

            return(colorField);
        }
Пример #7
0
        /*
         * public static UISlider CreatSliderWithLabel(out UILabel label, UIComponent parent, string labelText, float width)
         * {
         *  var labelWidth = Mathf.Round(width * LABEL_RELATIVE_WIDTH);
         *
         *  var slider = UIUtil.CreateSlider(parent);
         *  slider.relativePosition = new Vector3(labelWidth + COLUMN_PADDING, 0);
         *  slider.width = width - labelWidth - COLUMN_PADDING;
         *
         *  label = AddLabel(parent, labelText, labelWidth, dropDown.height);
         *
         *  return slider;
         * }*/

        public static UIPanel CreateSlider(UIComponent parent, string text, float min, float max, float step, float defaultValue, [NotNull] OnValueChanged eventCallback)
        {
            if (eventCallback == null)
            {
                throw new ArgumentNullException(nameof(eventCallback));
            }

            UIPanel uIPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject(kSliderTemplate)) as UIPanel;

            uIPanel.position = Vector3.zero;

            uIPanel.Find <UILabel>("Label").text = text;

            UISlider uISlider = uIPanel.Find <UISlider>("Slider");

            uISlider.minValue           = min;
            uISlider.maxValue           = max;
            uISlider.stepSize           = step;
            uISlider.value              = defaultValue;
            uISlider.eventValueChanged += delegate(UIComponent c, float val)
            {
                eventCallback(val);
            };
            return(uIPanel);
        }
 public static UISlider AddSlider(UIComponent parent, string text, float min, float max, float step, float defaultValue, OnValueChanged eventCallback, out UILabel label)
 {
     if (eventCallback != null)
     {
         var uIPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject(kSliderTemplate)) as UIPanel;
         uIPanel.transform.localScale = Vector3.one;
         if (string.IsNullOrEmpty(text))
         {
             label = null;
             GameObject.Destroy(uIPanel.Find <UILabel>("Label"));
         }
         else
         {
             label      = uIPanel.Find <UILabel>("Label");
             label.text = text;
         }
         UISlider uISlider = uIPanel.Find <UISlider>("Slider");
         uISlider.minValue           = min;
         uISlider.maxValue           = max;
         uISlider.stepSize           = step;
         uISlider.value              = defaultValue;
         uISlider.eventValueChanged += delegate(UIComponent c, float val)
         {
             eventCallback(val);
         };
         return(uISlider);
     }
     DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create slider with no name or no event");
     label = null;
     return(null);
 }
 public static UIDropDown CloneBasicDropDownLocalized(string text, string[] options, OnDropdownSelectionChanged eventCallback, int defaultSelection, UIComponent parent, out UILabel label, out UIPanel container, bool limitLabelByPanelWidth = false)
 {
     if (eventCallback != null && !string.IsNullOrEmpty(text))
     {
         container = parent.AttachUIComponent(UITemplateManager.GetAsGameObject(kDropdownTemplate)) as UIPanel;
         container.transform.localScale = Vector3.one;
         label             = container.Find <UILabel>("Label");
         label.localeID    = text;
         label.isLocalized = true;
         if (limitLabelByPanelWidth)
         {
             KlyteMonoUtils.LimitWidthAndBox(label, (uint)container.width);
         }
         UIDropDown uIDropDown = container.Find <UIDropDown>("Dropdown");
         uIDropDown.items                      = options;
         uIDropDown.selectedIndex              = defaultSelection;
         uIDropDown.eventSelectedIndexChanged += delegate(UIComponent c, int sel)
         {
             eventCallback(sel);
         };
         return(uIDropDown);
     }
     DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create dropdown with no name or no event");
     label     = null;
     container = null;
     return(null);
 }
Пример #10
0
        private UIColorField CreateColorField(UIComponent parent)
        {
            if (colorFIeldTemplate == null)
            {
                UIComponent template = UITemplateManager.Get("LineTemplate");
                if (template == null)
                {
                    return(null);
                }

                colorFIeldTemplate = template.Find <UIColorField>("LineColor");
                if (colorFIeldTemplate == null)
                {
                    return(null);
                }
            }

            UIColorField cF = Instantiate(colorFIeldTemplate.gameObject).GetComponent <UIColorField>();

            parent.AttachUIComponent(cF.gameObject);
            cF.name = "PainterColorField";
            cF.AlignTo(parent, UIAlignAnchor.TopRight);
            cF.relativePosition          += new Vector3(-40f, 43f, 0f);
            cF.size                       = new Vector2(26f, 26f);
            cF.pickerPosition             = UIColorField.ColorPickerPosition.RightBelow;
            cF.eventSelectedColorChanged += EventSelectedColorChangedHandler;
            cF.eventColorPickerOpen      += EventColorPickerOpenHandler;
            return(cF);
        }
Пример #11
0
        internal static BitMaskPanel Add(
            RoadEditorPanel roadEditorPanel,
            UIComponent container,
            string label,
            string hint,
            FlagDataT flagData)
        {
            try {
                Log.Debug($"BitMaskPanel.Add(container:{container}, label:{label}, enumType:{flagData.EnumType})");
                var subPanel = UIView.GetAView().AddUIComponent(typeof(BitMaskPanel)) as BitMaskPanel;
                subPanel.FlagData   = flagData;
                subPanel.Target     = roadEditorPanel.GetTarget();
                subPanel.Label.text = label + ":";
                subPanel.Hint       = hint;
                subPanel.Initialize();

                container.AttachUIComponent(subPanel.gameObject);
                roadEditorPanel.FitToContainer(subPanel);
                subPanel.EventPropertyChanged += roadEditorPanel.OnObjectModified;


                return(subPanel);
            } catch (Exception ex) {
                Log.Exception(ex);
                return(null);
            }
        }
Пример #12
0
        /// <summary>
        /// Adds a slider with a descriptive text label above.
        /// </summary>
        /// <param name="parent">Panel to add the control to</param>
        /// <param name="text">Descriptive label text</param>
        /// <param name="min">Slider minimum value</param>
        /// <param name="max">Slider maximum value</param>
        /// <param name="step">Slider minimum step</param>
        /// <param name="defaultValue">Slider initial value</param>
        /// <param name="width">Slider width (excluding value label to right) (default 600)</param>
        /// <returns>New UI slider with attached labels</returns>
        public static UISlider AddSlider(UIComponent parent, string text, float min, float max, float step, float defaultValue, float width = 600f)
        {
            // Add slider component.
            UIPanel sliderPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject("OptionsSliderTemplate")) as UIPanel;

            // Label.
            UILabel sliderLabel = sliderPanel.Find<UILabel>("Label");
            sliderLabel.autoHeight = true;
            sliderLabel.width = width;
            sliderLabel.anchor = UIAnchorStyle.Left | UIAnchorStyle.Top;
            sliderLabel.relativePosition = Vector3.zero;
            sliderLabel.relativePosition = Vector3.zero;
            sliderLabel.text = text;

            // Slider configuration.
            UISlider newSlider = sliderPanel.Find<UISlider>("Slider");
            newSlider.minValue = min;
            newSlider.maxValue = max;
            newSlider.stepSize = step;
            newSlider.value = defaultValue;

            // Move default slider position to match resized label.
            sliderPanel.autoLayout = false;
            newSlider.anchor = UIAnchorStyle.Left | UIAnchorStyle.Top;
            newSlider.relativePosition = PositionUnder(sliderLabel);
            newSlider.width = width;

            // Increase height of panel to accomodate it all plus some extra space for margin.
            sliderPanel.autoSize = false;
            sliderPanel.width = width + 50f;
            sliderPanel.height = newSlider.relativePosition.y + newSlider.height + 20f;

            return newSlider;
        }
Пример #13
0
        public static BitMaskPanel Add(
            RoadEditorPanel roadEditorPanel,
            UIComponent container,
            string label,
            Type enumType,
            SetHandlerD setHandler,
            GetHandlerD getHandler,
            string hint)
        {
            Log.Debug($"BitMaskPanel.Add(container:{container}, label:{label}, enumType:{enumType})");
            var subPanel = UIView.GetAView().AddUIComponent(typeof(BitMaskPanel)) as BitMaskPanel;

            subPanel.EnumType   = enumType;
            subPanel.SetHandler = setHandler;
            subPanel.GetHandler = getHandler;
            subPanel.Initialize();
            subPanel.Label.text = label + ":";
            subPanel.Hint       = hint;
            //if (dark)
            //    subPanel.opacity = 0.1f;
            //else
            //    subPanel.opacity = 0.3f;

            container.AttachUIComponent(subPanel.gameObject);
            roadEditorPanel.FitToContainer(subPanel);

            return(subPanel);
        }
Пример #14
0
        public static Component Get <Component>(UIComponent parent, string name = null, int zOrder = -1)
            where Component : UIComponent, IReusable
        {
            Component component;

            var queue = GetQueue(typeof(Component));

            if (queue.Count != 0)
            {
                component = queue.Dequeue() as Component;
                parent.AttachUIComponent(component.gameObject);
            }
            else
            {
                component = parent.AddUIComponent <Component>();
            }

            component.InCache = false;

            if (name != null)
            {
                component.cachedName = name;
            }
            if (zOrder != -1)
            {
                component.zOrder = zOrder;
            }

            return(component);
        }
Пример #15
0
        public DropDownColorSelector(UIComponent parent, Color initialColor, int id = 0)
        {
            this.id          = 0;
            m_parent         = parent;
            m_uiPanel        = m_parent.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;
            m_uiPanel.name   = "DropDownColorSelector";
            m_uiPanel.height = 40;
            m_uiPanel.width  = 280;
            m_uiPanel.autoLayoutDirection       = LayoutDirection.Horizontal;
            m_uiPanel.autoLayoutStart           = LayoutStart.TopLeft;
            m_uiPanel.autoFitChildrenVertically = true;

            m_title               = m_uiPanel.Find <UILabel>("Label");
            m_title.autoSize      = false;
            m_title.height        = 28;
            m_title.width         = 60;
            m_title.textAlignment = UIHorizontalAlignment.Center;
            m_title.padding       = new RectOffset(5, 5, 5, 5);

            m_r      = m_uiPanel.Find <UIDropDown>("Dropdown");
            this.m_g = m_uiPanel.AttachUIComponent(GameObject.Instantiate(m_r.gameObject)) as UIDropDown;
            m_b      = m_uiPanel.AttachUIComponent(GameObject.Instantiate(m_r.gameObject)) as UIDropDown;
            InitializeDropDown(ref m_b);
            InitializeDropDown(ref m_r);
            InitializeDropDown(ref m_g);

            m_r.color = new Color32(255, 0, 0, 255);
            m_g.color = new Color32(0, 255, 0, 255);
            m_b.color = new Color32(0, 0, 255, 255);

            m_displayColor                   = GameObject.Instantiate(m_uiPanel.Find <UILabel>("Label").gameObject, m_uiPanel.transform).GetComponent <UILabel>();
            m_displayColor.autoSize          = false;
            m_displayColor.name              = "Color result";
            m_displayColor.relativePosition += new Vector3(0, 160, 0);
            m_displayColor.text              = "";
            m_displayColor.height            = 28;
            m_displayColor.width             = 100;
            m_displayColor.textAlignment     = UIHorizontalAlignment.Center;
            m_displayColor.backgroundSprite  = "EmptySprite";
            m_displayColor.useOutline        = true;
            m_displayColor.outlineColor      = Color.black;
            m_displayColor.textColor         = Color.white;
            m_displayColor.padding           = new RectOffset(5, 5, 5, 5);

            m_remove                         = m_uiPanel.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kButtonTemplate)) as UIButton;
            m_remove.text                    = "x";
            m_remove.autoSize                = false;
            m_remove.height                  = 27;
            m_remove.width                   = 27;
            m_remove.textPadding             = new RectOffset(0, 0, 0, 0);
            m_remove.textHorizontalAlignment = UIHorizontalAlignment.Center;
            m_remove.eventClick             += delegate(UIComponent c, UIMouseEventParameter sel)
            {
                Disable();
                eventOnRemove?.Invoke();
            };

            SetSelectedColor(initialColor);
        }
Пример #16
0
        /// <summary>
        /// Creates a plain textfield using the game's option panel checkbox template.
        /// </summary>
        /// <param name="parent">Parent component</param>
        /// <param name="text">Descriptive label text</param>
        /// <returns>New checkbox using the game's option panel template</returns>
        public static UITextField AddPlainTextfield(UIComponent parent, string text)
        {
            UIPanel textFieldPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject("OptionsTextfieldTemplate")) as UIPanel;

            // Set text label.
            textFieldPanel.Find <UILabel>("Label").text = text;
            return(textFieldPanel.Find <UITextField>("Text Field"));
        }
Пример #17
0
        /// <summary>
        /// Creates a plain checkbox using the game's option panel checkbox template.
        /// </summary>
        /// <param name="parent">Parent component</param>
        /// <param name="text">Descriptive label text</param>
        /// <returns>New checkbox using the game's option panel template</returns>
        public static UICheckBox AddPlainCheckBox(UIComponent parent, string text)
        {
            UICheckBox checkBox = parent.AttachUIComponent(UITemplateManager.GetAsGameObject("OptionsCheckBoxTemplate")) as UICheckBox;

            // Set text.
            checkBox.text = text;

            return(checkBox);
        }
Пример #18
0
        public TextList(UIComponent parent, Dictionary <T, string> initiaItemList, int width, int height, string name)
        {
            this.name = name;
            m_parent  = parent;
            ((UIPanel)parent).autoFitChildrenVertically = true;
            ((UIPanel)parent).padding = new RectOffset(20, 20, 20, 20);
            UIPanel panelListing = m_parent.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;

            panelListing.name   = "TextList";
            panelListing.height = height;
            panelListing.width  = width;
            panelListing.autoLayoutDirection       = LayoutDirection.Vertical;
            panelListing.autoLayoutStart           = LayoutStart.TopLeft;
            panelListing.autoFitChildrenVertically = true;
            panelListing.wrapLayout       = true;
            panelListing.padding          = new RectOffset(0, 0, 0, 0);
            panelListing.clipChildren     = true;
            panelListing.pivot            = UIPivotPoint.MiddleCenter;
            panelListing.relativePosition = Vector2.zero;
            foreach (Transform t in panelListing.transform)
            {
                GameObject.Destroy(t.gameObject);
            }

            GameObject scrollObj = new GameObject("Lines Listing Scroll", new Type[] { typeof(UIScrollablePanel) });

            //			DebugOutputPanel.AddMessage (PluginManager.MessageType.Message, "SCROLL LOADED");
            linesListPanel                     = scrollObj.GetComponent <UIScrollablePanel>();
            linesListPanel.autoLayout          = false;
            linesListPanel.width               = width;
            linesListPanel.height              = height;
            linesListPanel.useTouchMouseScroll = true;
            linesListPanel.scrollWheelAmount   = 20;
            linesListPanel.eventMouseWheel    += (UIComponent component, UIMouseEventParameter eventParam) =>
            {
                linesListPanel.scrollPosition -= new Vector2(0, eventParam.wheelDelta * linesListPanel.scrollWheelAmount);
            };
            panelListing.AttachUIComponent(linesListPanel.gameObject);
            linesListPanel.autoLayout          = true;
            linesListPanel.autoLayoutDirection = LayoutDirection.Vertical;

            linesListPanel.useTouchMouseScroll = true;
            linesListPanel.scrollWheelAmount   = 20;
            linesListPanel.eventMouseWheel    += (UIComponent component, UIMouseEventParameter eventParam) =>
            {
                linesListPanel.scrollPosition -= new Vector2(0, eventParam.wheelDelta * linesListPanel.scrollWheelAmount);
                eventParam.Use();
            };

            foreach (Transform t in linesListPanel.transform)
            {
                GameObject.Destroy(t.gameObject);
            }

            itemsList = initiaItemList;
        }
Пример #19
0
        private UIButton CreateButton(string menuItemPrefab, string caption, UIComponent parent)
        {
            var gameObject = UITemplateManager.GetAsGameObject(menuItemPrefab);

            gameObject.name = caption;
            var button = (UIButton)parent.AttachUIComponent(gameObject);

            button.text        = caption;
            button.eventClick += Click;
            return(button);
        }
Пример #20
0
        // Token: 0x0600001E RID: 30 RVA: 0x00002F50 File Offset: 0x00001150
        public static UIColorField CreateColorField(UIComponent parent)
        {
            UIColorField component = UnityEngine.Object.Instantiate <GameObject>(UnityEngine.Object.FindObjectOfType <UIColorField>().gameObject).GetComponent <UIColorField>();

            parent.AttachUIComponent(component.gameObject);
            component.size            = new Vector2(40f, 26f);
            component.normalBgSprite  = "ColorPickerOutline";
            component.hoveredBgSprite = "ColorPickerOutlineHovered";
            component.selectedColor   = Color.white;
            component.pickerPosition  = UIColorField.ColorPickerPosition.RightAbove;
            return(component);
        }
Пример #21
0
        public static UICheckBox AddCheckBox(UIComponent parent, string text)
        {
            var checkboxTemplate = UITemplateManager.GetAsGameObject("OptionsCheckBoxTemplate");
            var checkbox         = parent.AttachUIComponent(checkboxTemplate) as UICheckBox;

            checkbox.text      = text;
            checkbox.width     = 40f;
            checkbox.height    = 25f;
            checkbox.enabled   = true;
            checkbox.isChecked = true;
            return(checkbox);
        }
Пример #22
0
        /// <summary>
        /// Adds a slider with a descriptive text label above and an automatically updating value label immediately to the right.
        /// </summary>
        /// <param name="parent">Panel to add the control to</param>
        /// <param name="text">Descriptive label text</param>
        /// <param name="min">Slider minimum value</param>
        /// <param name="max">Slider maximum value</param>
        /// <param name="step">Slider minimum step</param>
        /// <param name="defaultValue">Slider initial value</param>
        /// <param name="eventCallback">Slider event handler</param>
        /// <param name="width">Slider width (excluding value label to right) (default 600)</param>
        /// <returns>New UI slider with attached labels</returns>
        internal static UISlider AddSliderWithValue(UIComponent parent, string text, float min, float max, float step, float defaultValue, OnValueChanged eventCallback, float width = 600f, float textScale = 1f)
        {
            // Add slider component.
            UIPanel sliderPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject("OptionsSliderTemplate")) as UIPanel;

            sliderPanel.Find <UILabel>("Label").text = text;

            // Label.
            UILabel sliderLabel = sliderPanel.Find <UILabel>("Label");

            sliderLabel.autoHeight       = true;
            sliderLabel.width            = width;
            sliderLabel.anchor           = UIAnchorStyle.Left | UIAnchorStyle.Top;
            sliderLabel.relativePosition = Vector3.zero;
            sliderLabel.relativePosition = Vector3.zero;
            sliderLabel.textScale        = textScale;
            sliderLabel.text             = text;

            // Slider configuration.
            UISlider newSlider = sliderPanel.Find <UISlider>("Slider");

            newSlider.minValue = min;
            newSlider.maxValue = max;
            newSlider.stepSize = step;
            newSlider.value    = defaultValue;

            // Move default slider position to match resized label.
            sliderPanel.autoLayout     = false;
            newSlider.anchor           = UIAnchorStyle.Left | UIAnchorStyle.Top;
            newSlider.relativePosition = PositionUnder(sliderLabel);
            newSlider.width            = width;

            // Increase height of panel to accomodate it all plus some extra space for margin.
            sliderPanel.autoSize = false;
            sliderPanel.width    = width + 50f;
            sliderPanel.height   = newSlider.relativePosition.y + newSlider.height + 15f;

            // Value label.
            UILabel valueLabel = sliderPanel.AddUIComponent <UILabel>();

            valueLabel.name             = "ValueLabel";
            valueLabel.text             = newSlider.value.ToString();
            valueLabel.relativePosition = PositionRightOf(newSlider, 8f, 1f);

            // Event handler to update value label.
            newSlider.eventValueChanged += (component, value) =>
            {
                valueLabel.text = value.ToString();
                eventCallback(value);
            };

            return(newSlider);
        }
Пример #23
0
        public static UIColorField CreateColorField(UIComponent parent)
        {
            if (!EnsureColorFieldTemplate())
            {
                return(null);
            }

            var          go        = GameObject.Instantiate(m_colorFieldTemplate.gameObject, parent.transform);
            UIColorField component = go.GetComponent <UIColorField>();

            parent.AttachUIComponent(go).transform.localScale = Vector3.one;
            InitColorField(component, 28);
            return(component);
        }
Пример #24
0
        /// <summary>
        /// Create a box with title
        /// </summary>
        /// <param name="text">Title</param>
        private void BeginGroup(string text)
        {
            const string K_GROUP_TEMPLATE = "OptionsGroupTemplate";
            var          groupPanel       = scrollPanel_.AttachUIComponent(
                UITemplateManager.GetAsGameObject(K_GROUP_TEMPLATE)) as UIPanel;

            groupPanel.autoLayoutStart     = LayoutStart.TopLeft;
            groupPanel.autoLayoutDirection = LayoutDirection.Vertical;
            groupPanel.autoLayout          = true;

            groupPanel.Find <UILabel>("Label").text = text;

            currentGroup_ = groupPanel.Find("Content");
        }
Пример #25
0
        private void SpawnPolicyEntry(UIComponent container, string name, string unlockText, bool isEnabled)
        {
            UIPanel uiPanel;
            var     objectIndex = (int)_objectIndexField.GetValue(this);

            if (container.childCount > objectIndex)
            {
                uiPanel = container.components[objectIndex] as UIPanel;
            }
            else
            {
                GameObject asGameObject = UITemplateManager.GetAsGameObject(kPolicyTemplate);
                asGameObject.name = name;
                uiPanel           = container.AttachUIComponent(asGameObject) as UIPanel;
            }
            uiPanel.FitTo(uiPanel.parent, LayoutDirection.Horizontal);
            uiPanel.stringUserData = name;
            uiPanel.objectUserData = (object)this;
            uiPanel.isEnabled      = isEnabled;
            UIButton uiButton = uiPanel.Find <UIButton>("PolicyButton");

            uiButton.text = ColossalFramework.Globalization.Locale.Get("POLICIES", name);
            string str = "IconPolicy" + name;

            uiButton.pivot = this.m_DockingPosition != PoliciesPanel.DockingPosition.Left ? UIPivotPoint.TopLeft : UIPivotPoint.TopRight;
            if (isEnabled)
            {
                uiButton.tooltipBox = (UIComponent)_policiesTooltipPropertyInfo.GetValue(this, null);
                uiButton.tooltip    = TooltipHelper.Format("title", ColossalFramework.Globalization.Locale.Get("POLICIES", name), "text", ColossalFramework.Globalization.Locale.Get("POLICIES_DETAIL", name));
            }
            else
            {
                uiButton.tooltipBox = (UIComponent)_defaultTooltipPropertyInfo.GetValue(this, null);
                uiButton.tooltip    = ColossalFramework.Globalization.Locale.Get("POLICIES", name) + " - " + unlockText;
            }
            //begin mod
            uiButton.eventTooltipEnter += (sender, p) =>
            {
                DistrictManager.instance.HighlightPolicy = (DistrictPolicies.Policies)Enum.Parse(typeof(DistrictPolicies.Policies), name);
            };
            uiButton.eventTooltipLeave += (sender, p) =>
            {
                DistrictManager.instance.HighlightPolicy = DistrictPolicies.Policies.None;
            };
            //end mod
            uiButton.normalFgSprite   = str;
            uiButton.disabledFgSprite = str + "Disabled";
            _objectIndexField.SetValue(this, objectIndex + 1);
        }
Пример #26
0
 public static UIDropDown CloneBasicDropDownNoLabel(string[] options, OnDropdownSelectionChanged eventCallback, UIComponent parent)
 {
     if (eventCallback != null)
     {
         UIDropDown uIDropDown = parent.AttachUIComponent(GameObject.Instantiate(GameObject.Find("Dropdown"))).GetComponent <UIDropDown>();
         uIDropDown.items = options;
         uIDropDown.eventSelectedIndexChanged += delegate(UIComponent c, int sel)
         {
             eventCallback(sel);
         };
         return(uIDropDown);
     }
     DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create dropdown with no name or no event");
     return(null);
 }
 public static UIButton AddButton(UIComponent parent, string text, OnButtonClicked eventCallback)
 {
     if (eventCallback != null && !string.IsNullOrEmpty(text))
     {
         var uIButton = parent.AttachUIComponent(UITemplateManager.GetAsGameObject(kButtonTemplate)) as UIButton;
         uIButton.text        = text;
         uIButton.eventClick += delegate(UIComponent c, UIMouseEventParameter sel)
         {
             eventCallback();
         };
         return(uIButton);
     }
     DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create button with no name or no event");
     return(null);
 }
        public UICheckBox AddCheckboxNoLabel(string name, OnCheckChanged eventCallback = null)
        {
            var uICheckBox = m_root.AttachUIComponent(UITemplateManager.GetAsGameObject(kCheckBoxTemplate)) as UICheckBox;

            uICheckBox.width = uICheckBox.height;
            GameObject.Destroy(uICheckBox.label.gameObject);
            uICheckBox.name = name;
            if (eventCallback != null)
            {
                uICheckBox.eventCheckChanged += delegate(UIComponent c, bool isChecked)
                {
                    eventCallback(isChecked);
                };
            }
            return(uICheckBox);
        }
Пример #29
0
        public static UIColorField CreateColorField(UIComponent parent)
        {
            //UIColorField colorField = parent.AddUIComponent<UIColorField>();
            // Creating a ColorField from scratch is tricky. Cloning an existing one instead.
            // Probably doesn't work when on main menu screen and such as no ColorField exists.
            UIColorField colorField = UnityEngine.Object.Instantiate<GameObject>(UnityEngine.Object.FindObjectOfType<UIColorField>().gameObject).GetComponent<UIColorField>();
            parent.AttachUIComponent(colorField.gameObject);

            colorField.size = new Vector2(40f, 26f);
            colorField.normalBgSprite = "ColorPickerOutline";
            colorField.hoveredBgSprite = "ColorPickerOutlineHovered";
            colorField.selectedColor = Color.black;
            colorField.pickerPosition = UIColorField.ColorPickerPosition.RightAbove;

            return colorField;
        }
Пример #30
0
        public static UIColorField CreateColorField(UIComponent parent)
        {
            //UIColorField colorField = parent.AddUIComponent<UIColorField>();
            // Creating a ColorField from scratch is tricky. Cloning an existing one instead.
            // Probably doesn't work when on main menu screen and such as no ColorField exists.
            UIColorField colorField = UnityEngine.Object.Instantiate <GameObject>(UnityEngine.Object.FindObjectOfType <UIColorField>().gameObject).GetComponent <UIColorField>();

            parent.AttachUIComponent(colorField.gameObject);

            colorField.size            = new Vector2(40f, 26f);
            colorField.normalBgSprite  = "ColorPickerOutline";
            colorField.hoveredBgSprite = "ColorPickerOutlineHovered";
            colorField.selectedColor   = Color.white;
            colorField.pickerPosition  = UIColorField.ColorPickerPosition.RightAbove;

            return(colorField);
        }
Пример #31
0
        /// <summary>
        /// Creates a plain dropdown using the game's option panel dropdown template.
        /// </summary>
        /// <param name="parent">Parent component</param>
        /// <param name="text">Descriptive label text</param>
        /// <param name="items">Dropdown menu item list</param>
        /// <param name="selectedIndex">Initially selected index (default 0)</param>
        /// <param name="width">Width of dropdown (default 60)</param>
        /// <returns></returns>
        internal static UIDropDown AddPlainDropDown(UIComponent parent, string text, string[] items, int selectedIndex = 0, float width = 270f)
        {
            UIPanel    panel    = parent.AttachUIComponent(UITemplateManager.GetAsGameObject("OptionsDropdownTemplate")) as UIPanel;
            UIDropDown dropDown = panel.Find <UIDropDown>("Dropdown");

            // Set text.
            panel.Find <UILabel>("Label").text = text;

            // Slightly increase width.
            dropDown.autoSize = false;
            dropDown.width    = width;

            // Add items.
            dropDown.items         = items;
            dropDown.selectedIndex = selectedIndex;

            return(dropDown);
        }
Пример #32
0
        /*
        public static UISlider CreatSliderWithLabel(out UILabel label, UIComponent parent, string labelText, float width)
        {
            var labelWidth = Mathf.Round(width * LABEL_RELATIVE_WIDTH);

            var slider = UIUtil.CreateSlider(parent);
            slider.relativePosition = new Vector3(labelWidth + COLUMN_PADDING, 0);
            slider.width = width - labelWidth - COLUMN_PADDING;

            label = AddLabel(parent, labelText, labelWidth, dropDown.height);

            return slider;
        }*/
        public static UIPanel CreateSlider(UIComponent parent, string text, float min, float max, float step, float defaultValue, [NotNull] OnValueChanged eventCallback)
        {
            if (eventCallback == null) throw new ArgumentNullException(nameof(eventCallback));

            UIPanel uIPanel = parent.AttachUIComponent(UITemplateManager.GetAsGameObject(kSliderTemplate)) as UIPanel;
            uIPanel.position = Vector3.zero;

            uIPanel.Find<UILabel>("Label").text = text;

            UISlider uISlider = uIPanel.Find<UISlider>("Slider");
            uISlider.minValue = min;
            uISlider.maxValue = max;
            uISlider.stepSize = step;
            uISlider.value = defaultValue;
            uISlider.eventValueChanged += delegate (UIComponent c, float val)
            {
                eventCallback(val);
            };
            return uIPanel;
        }