コード例 #1
0
        public UIColorField AddColorPicker(string name, Color defaultValue, OnColorChanged eventCallback, out UILabel title)
        {
            if (eventCallback != null && !string.IsNullOrEmpty(name))
            {
                UIPanel panel = m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;
                panel.name = "DropDownColorSelector";
                title      = panel.Find <UILabel>("Label");
                title.text = name;
                panel.autoLayoutDirection       = LayoutDirection.Horizontal;
                panel.wrapLayout                = false;
                panel.autoFitChildrenVertically = true;
                GameObject.Destroy(panel.Find <UIDropDown>("Dropdown").gameObject);
                var colorField = KlyteUtils.CreateColorField(panel);

                colorField.eventSelectedColorReleased += (cp, value) =>
                {
                    eventCallback(value);
                };

                return(colorField);
            }
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event");
            title = null;
            return(null);
        }
コード例 #2
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);
        }
コード例 #3
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame && mode != LoadMode.NewMap &&
                mode != LoadMode.LoadMap)
            {
                return;
            }
            _mode = mode;

            buildingWindowGameObject = new GameObject("buildingWindowObject");

            var view = UIView.GetAView();

            this.buildingWindow = buildingWindowGameObject.AddComponent <MapperWindow7>();
            this.buildingWindow.transform.parent = view.transform;
            this.buildingWindow.position         = new Vector3(300, 122);
            this.buildingWindow.Hide();


            UITabstrip strip = null;

            if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame)
            {
                strip = ToolsModifierControl.mainToolbar.component as UITabstrip;
            }
            else
            {
                strip = UIView.Find <UITabstrip>("MainToolstrip");
            }

            buttonObject           = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate");
            buttonObject2          = UITemplateManager.GetAsGameObject("ScrollablePanelTemplate");
            menuButton             = strip.AddTab("mapperMod", buttonObject, buttonObject2, new Type[] {}) as UIButton;
            menuButton.eventClick += uiButton_eventClick;
        }
コード例 #4
0
        public TextList <T> AddTextList <T>(string name, Dictionary <T, string> defaultValues, OnButtonSelect <T> eventCallback, int width, int height)
        {
            if (eventCallback != null)
            {
                UIPanel uIPanel = m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;
                uIPanel.name = "NumberedColorList";
                if (string.IsNullOrEmpty(name))
                {
                    uIPanel.Find <UILabel>("Label").text = "";
                }
                else
                {
                    uIPanel.Find <UILabel>("Label").text = name;
                }
                GameObject.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject);
                TextList <T> ddcs = new TextList <T>(uIPanel, defaultValues, width, height, name);

                ddcs.eventOnClick += (T value) =>
                {
                    eventCallback(value);
                };

                return(ddcs);
            }
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event");
            return(null);
        }
コード例 #5
0
        public UITextField AddFloatField(string name, float defaultValue, Action <float> eventSubmittedCallback, bool acceptNegative = true)
        {
            if ((eventSubmittedCallback != null) && !string.IsNullOrEmpty(name))
            {
                UITextField result;
                UIPanel     uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(kTextfieldTemplate)) as UIPanel;
                uIPanel.Find <UILabel>("Label").text = name;
                uIPanel.autoLayout                = true;
                uIPanel.autoLayoutDirection       = LayoutDirection.Horizontal;
                uIPanel.wrapLayout                = false;
                uIPanel.autoFitChildrenVertically = true;
                result = uIPanel.Find <UITextField>("Text Field");
                result.numericalOnly = true;
                result.width         = 60;
                result.allowNegative = acceptNegative;
                result.allowFloats   = true;

                void textSubmitAction(UIComponent c, string sel)
                {
                    float.TryParse(result.text, out float val);
                    eventSubmittedCallback?.Invoke(val);
                }

                result.eventTextSubmitted += textSubmitAction;
                result.text = defaultValue.ToString();
                return(result);
            }
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create dropdown with no name or no event");
            return(null);
        }
コード例 #6
0
        public DropDownColorSelector AddColorField(string name, Color defaultValue, OnColorChanged eventCallback, OnButtonClicked eventRemove)
        {
            if (eventCallback != null && !string.IsNullOrEmpty(name))
            {
                UIPanel uIPanel = m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;
                uIPanel.name = "DropDownColorSelector";
                uIPanel.Find <UILabel>("Label").text = name;
                GameObject.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject);
                DropDownColorSelector ddcs = new DropDownColorSelector(uIPanel, defaultValue);

                ddcs.eventColorChanged += (Color32 value) =>
                {
                    eventCallback(value);
                };

                ddcs.eventOnRemove += () =>
                {
                    if (eventRemove != null)
                    {
                        eventRemove();
                    }
                };
                return(ddcs);
            }
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event");
            return(null);
        }
コード例 #7
0
        public NumberedColorList AddNumberedColorList(string name, List <Color32> defaultValues, OnButtonSelect <int> eventCallback, UIComponent addButtonContainer, OnButtonClicked eventAdd)
        {
            if (eventCallback != null)
            {
                UIPanel uIPanel = m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;
                uIPanel.name = "NumberedColorList";
                if (string.IsNullOrEmpty(name))
                {
                    uIPanel.Find <UILabel>("Label").text = "";
                }
                else
                {
                    uIPanel.Find <UILabel>("Label").text = name;
                }
                GameObject.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject);
                NumberedColorList ddcs = new NumberedColorList(uIPanel, defaultValues, addButtonContainer);

                ddcs.eventOnClick += (int value) =>
                {
                    eventCallback(value);
                };

                ddcs.eventOnAdd += () =>
                {
                    if (eventAdd != null)
                    {
                        eventAdd();
                    }
                };
                return(ddcs);
            }
            DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event");
            return(null);
        }
コード例 #8
0
        // Custom method to delete a single message - uses ChirpMessages.
        private void DeleteMessage(ChirpMessage message)
        {
            // Get container for chirps
            Transform container = chirpPane.transform.FindChild("Chirps").FindChild("Clipper").FindChild("Container").gameObject.transform;

            for (int i = 0; i < container.childCount; ++i)
            {
                if (container.GetChild(i).GetComponentInChildren <UILabel>().text.Equals(message.GetText()))
                {
                    DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, "[SuperChirper] Deleted Message:" + message.text);
                    // Remove both visual and internal message.
                    UITemplateManager.RemoveInstance("ChirpTemplate", container.GetChild(i).GetComponent <UIPanel>());

                    // Find the original message, remove it from manager.
                    IChirperMessage delMessage;
                    messageMap.TryGetValue(message, out delMessage);
                    messageManager.DeleteMessage(delMessage);


                    if (!userOpened)
                    {
                        chirpPane.Collapse();
                    }
                    return;
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// OnNewMessage runs before the message can be found in the stack. So we try to get
        /// rid of it here Mostly copied from https://github.com/mabako/reddit-for-city-skylines/
        /// </summary>
        public override void OnUpdate()
        {
            // If there's no message to remove, continue on
            if (_messageRemovalTarget == null)
                return;

            if (ChirpPanel.instance == null) 
                return;

            // This code is roughly based on the work by Juuso "Zuppi" Hietala.
            // Get the Chirper container, where all of the chirps reside
            var container = ChirpPanel.instance.transform.Find("Chirps").Find("Clipper").Find("Container").gameObject.transform;
            for (var i = 0; i < container.childCount; ++i)
            {
                // Keep looping until we get the one we want. It should pretty much be the very first one we snag every time, on very rare
                // occurence the second one
                if (!container.GetChild(i).GetComponentInChildren<UILabel>().text.Equals(_messageRemovalTarget.GetText()))
                    continue;

                // Remove the message
                UITemplateManager.RemoveInstance("ChirpTemplate", container.GetChild(i).GetComponent<UIPanel>());
                MessageManager.instance.DeleteMessage(_messageRemovalTarget);

                // We're done here
                _messageRemovalTarget = null;

                break;
            }
        }
コード例 #10
0
        private Button CreateMenuItem(string name, string label, string insertAfterName)
        {
            // TODO: Create a proper Wrapper for UITemplateManager
            // TODO: AttachUIComponent in ColossalControl
            GameObject gameObject = UITemplateManager.GetAsGameObject("MainMenuButtonTemplate");

            gameObject.name = name;

            UIButton button = (UIButton)mainMenu.component.AttachUIComponent(gameObject);

            button.text = label;

            UIButton[] buttons = mainMenu.GetComponentsInChildren <UIButton>();

            for (int i = buttons.Count() - 2; i >= 0; i--)
            {
                if (buttons[i].name == insertAfterName)
                {
                    break;
                }

                button.MoveBackward();
            }

            Log.Debug("MainMenu", "Created main menu button {0} with label {1} after button {2}", name, label, insertAfterName);

            return(new Button(button, true));
        }
コード例 #11
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);
        }
コード例 #12
0
        public TextList <T> AddTextList <T>(string name, Dictionary <T, string> defaultValues, OnButtonSelect <T> eventCallback, int width, int height)
        {
            bool         flag = eventCallback != null;
            TextList <T> result;

            if (flag)
            {
                UIPanel uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;
                uIPanel.name = "NumberedColorList";
                bool flag2 = string.IsNullOrEmpty(name);
                if (flag2)
                {
                    uIPanel.Find <UILabel>("Label").text = "";
                }
                else
                {
                    uIPanel.Find <UILabel>("Label").text = name;
                }
                UnityEngine.Object.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject);
                TextList <T> textList = new TextList <T>(uIPanel, defaultValues, width, height, name);
                textList.eventOnClick += delegate(T value)
                {
                    eventCallback(value);
                };
                result = textList;
            }
            else
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event");
                result = null;
            }
            return(result);
        }
コード例 #13
0
        public DropDownColorSelector AddColorField(string name, Color defaultValue, OnColorChanged eventCallback, OnButtonClicked eventRemove)
        {
            bool flag = eventCallback != null && !string.IsNullOrEmpty(name);
            DropDownColorSelector result;

            if (flag)
            {
                UIPanel uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kDropdownTemplate)) as UIPanel;
                uIPanel.name = "DropDownColorSelector";
                uIPanel.Find <UILabel>("Label").text = name;
                UnityEngine.Object.Destroy(uIPanel.Find <UIDropDown>("Dropdown").gameObject);
                DropDownColorSelector dropDownColorSelector = new DropDownColorSelector(uIPanel, defaultValue, 0);
                dropDownColorSelector.eventColorChanged += delegate(Color32 value)
                {
                    eventCallback(value);
                };
                dropDownColorSelector.eventOnRemove += delegate
                {
                    bool flag2 = eventRemove != null;
                    if (flag2)
                    {
                        eventRemove();
                    }
                };
                result = dropDownColorSelector;
            }
            else
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create colorPicker with no name or no event");
                result = null;
            }
            return(result);
        }
コード例 #14
0
        public object AddTextfield(string text, string defaultContent, OnTextChanged eventChangedCallback, OnTextSubmitted eventSubmittedCallback)
        {
            bool   flag = eventChangedCallback != null && !string.IsNullOrEmpty(text);
            object result;

            if (flag)
            {
                UIPanel uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kTextfieldTemplate)) as UIPanel;
                uIPanel.Find <UILabel>("Label").text = text;
                UITextField uITextField = uIPanel.Find <UITextField>("Text Field");
                uITextField.text              = defaultContent;
                uITextField.eventTextChanged += delegate(UIComponent c, string sel)
                {
                    eventChangedCallback(sel);
                };
                uITextField.eventTextSubmitted += delegate(UIComponent c, string sel)
                {
                    bool flag2 = eventSubmittedCallback != null;
                    if (flag2)
                    {
                        eventSubmittedCallback(sel);
                    }
                };
                result = uITextField;
            }
            else
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create dropdown with no name or no event");
                result = null;
            }
            return(result);
        }
コード例 #15
0
        public object AddSlider(string text, float min, float max, float step, float defaultValue, OnValueChanged eventCallback)
        {
            bool   flag = eventCallback != null && !string.IsNullOrEmpty(text);
            object result;

            if (flag)
            {
                UIPanel uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(UIHelperExtension.kSliderTemplate)) as UIPanel;
                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);
                };
                result = uISlider;
            }
            else
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create slider with no name or no event");
                result = null;
            }
            return(result);
        }
コード例 #16
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;
        }
コード例 #17
0
ファイル: UiHelper.cs プロジェクト: qifengwei/Tango
        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);
        }
コード例 #18
0
ファイル: UIUtils.cs プロジェクト: Versatilus/FindIt2
        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);
        }
コード例 #19
0
        public ModifierDropDown AddKeymapping(StyleModifier value, string description)
        {
            UIPanel uiPanel = component.AttachUIComponent(UITemplateManager.GetAsGameObject(keyBindingTemplate)) as UIPanel;

            int num = count;

            count = num + 1;
            if (num % 2 == 1)
            {
                uiPanel.backgroundSprite = null;
            }

            UILabel  uilabel  = uiPanel.Find <UILabel>("Name");
            UIButton uibutton = uiPanel.Find <UIButton>("Binding");

            uiPanel.RemoveUIComponent(uibutton);
            Destroy(uibutton);
            var modifier = uiPanel.AddUIComponent <ModifierDropDown>();

            modifier.relativePosition       = new Vector2(380, 6);
            modifier.SelectedObject         = value;
            modifier.OnSelectObjectChanged += ModifierChanged;

            uilabel.text = description;

            return(modifier);
        }
コード例 #20
0
ファイル: ForestBrush.cs プロジェクト: TPBCS/ForestBrush
        private ToggleButtonComponents CreateToggleButtonComponents(UITabstrip tabstrip)
        {
            SeparatorComponents preSeparatorComponents = CreateSeparatorComponents(tabstrip);

            GameObject tabStripPage = UITemplateManager.GetAsGameObject(kEmptyContainer);
            GameObject mainToolbarButtonTemplate = UITemplateManager.GetAsGameObject(kMainToolbarButtonTemplate);

            UIButton toggleButton = tabstrip.AddTab(kToggleButton, mainToolbarButtonTemplate, tabStripPage, new Type[0]) as UIButton;

            toggleButton.atlas = Resources.ResourceLoader.ForestBrushAtlas;

            toggleButton.normalFgSprite   = "ForestBrushNormal";
            toggleButton.disabledFgSprite = "ForestBrushDisabled";
            toggleButton.focusedFgSprite  = "ForestBrushFocused";
            toggleButton.hoveredFgSprite  = "ForestBrushHovered";
            toggleButton.pressedFgSprite  = "ForestBrushPressed";

            toggleButton.normalBgSprite   = "ToolbarIconGroup6Normal";
            toggleButton.disabledBgSprite = "ToolbarIconGroup6Disabled";
            toggleButton.focusedBgSprite  = "ToolbarIconGroup6Focused";
            toggleButton.hoveredBgSprite  = "ToolbarIconGroup6Hovered";
            toggleButton.pressedBgSprite  = "ToolbarIconGroup6Pressed";
            toggleButton.parent.height    = 1f;

            IncrementObjectIndex();

            SeparatorComponents postSeparatorComponents = CreateSeparatorComponents(tabstrip);

            return(new ToggleButtonComponents(preSeparatorComponents, tabStripPage, mainToolbarButtonTemplate, toggleButton, postSeparatorComponents));
        }
コード例 #21
0
ファイル: StyleModifier.cs プロジェクト: MacSergey/NodeMarkup
        public ModifierDropDown AddKeymapping(StyleModifier value, string description)
        {
            var panel = component.AttachUIComponent(UITemplateManager.GetAsGameObject("KeyBindingTemplate")) as UIPanel;

            if (count % 2 == 1)
            {
                panel.backgroundSprite = null;
            }

            count += 1;

            var button = panel.Find <UIButton>("Binding");

            panel.RemoveUIComponent(button);
            Destroy(button);

            var modifier = panel.AddUIComponent <ModifierDropDown>();

            modifier.relativePosition       = new Vector2(380, 6);
            modifier.SelectedObject         = value;
            modifier.OnSelectObjectChanged += ModifierChanged;

            var label = panel.Find <UILabel>("Name");

            label.text = description;

            return(modifier);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        private void AddShortcutDisplay(int i, string name, SavedInputKey shortcut)
        {
            const string keyBindingTemplate = "KeyBindingTemplate";
            var          pnl = (UIPanel)this.AttachUIComponent(UITemplateManager.GetAsGameObject(keyBindingTemplate));

            if (i % 2 == 0)
            {
                pnl.backgroundSprite = string.Empty;
            }

            var lbl = pnl.Find <UILabel>("Name");

            lbl.text    = name;
            lbl.tooltip = "C:S shortcut. Change in Cities:Skylines Keymapping settings";

            var btn = pnl.Find <UIButton>("Binding");

            btn.objectUserData = shortcut;
            btn.text           = shortcut.ToLocalizedString("KEYNAME");
            btn.tooltip        = lbl.tooltip;
            btn.canFocus       = false;
            btn.hoveredColor   = btn.color;
            btn.pressedColor   = btn.color;
            btn.focusedColor   = btn.color;
        }
コード例 #24
0
ファイル: Painter.cs プロジェクト: vitalii2011/Painter
        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);
        }
コード例 #25
0
 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);
 }
コード例 #26
0
 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);
 }
コード例 #27
0
ファイル: Loader.cs プロジェクト: usagi/cs-terraingen
        public override void OnLevelLoaded(LoadMode m)
        {
            if (m != LoadMode.NewMap)
            {
                return;
            }

            window = new GameObject("Terrain Panel");

            UIView v = UIView.GetAView();

            strip = UIView.Find <UITabstrip>("MainToolstrip");

            button1                = UITemplateManager.GetAsGameObject("MainToolbarButtonTemplate");
            button2                = UITemplateManager.GetAsGameObject("ScrollablePanelTemplate");
            menuButton             = strip.AddTab("TerrainGenerator", button1, button2, new Type[] { }) as UIButton;
            menuButton.eventClick += uiButton_eventClick;

            menuButton.normalFgSprite  = "InfoIconTerrainHeight";
            menuButton.hoveredFgSprite = "InfoIconTerrainHeightHovered";
            menuButton.focusedFgSprite = "InfoIconTerrainHeightFocused";
            menuButton.pressedFgSprite = "InfoIconTerrainHeightPressed";
            menuButton.tooltip         = "Generate Terrain";

            panel = window.AddComponent <TerrainUIMainPanel>();
            panel.transform.parent = v.transform;
            panel.position         = new Vector3(menuButton.position.x - 240, menuButton.position.y - 105);
            panel.Hide();

            initialized = true;
        }
コード例 #28
0
        private void WorkshopAdPanelOnQueryCompleted(UGCDetails result, bool ioError)
        {
            try
            {
                var workshopAdPanel = GameObject.Find("WorkshopAdPanel").GetComponent <WorkshopAdPanel>();

                if (result.result == Result.OK)
                {
                    UIComponent uIComponent = Util.GetPrivate <UIScrollablePanel>(workshopAdPanel, "m_ScrollContainer").AttachUIComponent
                                                  (UITemplateManager.GetAsGameObject("WorkshopAdTemplate"));

                    string price = String.Format(CultureInfo.CurrentCulture, "{0:C}", 0.99f);
                    if (UnityEngine.Random.Range(0, 2) == 0)
                    {
                        price = String.Format(CultureInfo.CurrentCulture, "{0:C}", 2.49f);
                    }
                    else if (UnityEngine.Random.Range(0, 7) == 0)
                    {
                        price = String.Format(CultureInfo.CurrentCulture, "{0:C}", 4.99f);
                    }
                    else if (UnityEngine.Random.Range(0, 25) == 0)
                    {
                        price = String.Format(CultureInfo.CurrentCulture, "{0:C}", 8.49f);
                    }

                    uIComponent.Find <UILabel>("Title").text = String.Format("{0} - {1}\n{2}", result.title, price, result.tags);

                    if (result.image != null)
                    {
                        result.image.wrapMode = TextureWrapMode.Clamp;
                    }
                    uIComponent.Find <UITextureSprite>("Image").texture = result.image;
                    UIProgressBar uIProgressBar = uIComponent.Find <UIProgressBar>("Rating");
                    uIProgressBar.isVisible = (result.score >= 0f);
                    uIProgressBar.value     = result.score;
                    uIComponent.Find <UIButton>("ClickableArea").eventClick += delegate(UIComponent c, UIMouseEventParameter p)
                    {
                        if (Steam.IsOverlayEnabled())
                        {
                            Steam.ActivateGameOverlayToWorkshopItem(result.publishedFileId);
                        }
                    };
                }
                else
                {
                    CODebugBase <LogChannel> .Warn(LogChannel.Core, string.Concat(new object[]
                    {
                        "Workshop item: ",
                        result.publishedFileId,
                        " error: ",
                        result.result
                    }));
                }
            }
            catch (Exception ex)
            {
                CODebugBase <LogChannel> .Error(LogChannel.Core, ex.ToString());
            }
        }
コード例 #29
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);
        }
コード例 #30
0
ファイル: UIControls.cs プロジェクト: JacekWolnicki/BOB
        /// <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"));
        }