예제 #1
0
        public void SetMessage(string text, Color color)
        {
            message.TextScale = 1f;
            message.SetText("Notification: " + text);
            float width = Main.fontMouseText.MeasureString(text).X;

            if (width > 400)
            {
                message.TextScale = 400 / width;
                message.Recalculate();
            }
            message.TextColor = color;
        }
예제 #2
0
        private UITextPanel <string> AddButtonWithLabel(string labelText)
        {
            var button = new UITextPanel <string>(string.Empty);

            button.HAlign     = 1;
            button.Top.Pixels = _height;
            button.MarginTop  = 5;
            button.Recalculate();
            _height += button.GetOuterDimensions().Height;

            var label = new UIText(labelText);

            label.Top.Pixels = button.Top.Pixels + 15;
            Append(button);
            Append(label);
            return(button);
        }
예제 #3
0
        public override void Update(GameTime gameTime)
        {
            if (!_loading && _ready)
            {
                _uITextPanel.SetText(Language.GetTextValue("tModLoader.ModInfoHeader") + _modDisplayName, 0.8f, true);
                _uITextPanel.Recalculate();
                _modInfo.SetText(_info);

                if (!string.IsNullOrEmpty(_url))
                {
                    _uIElement.Append(_modHomepageButton);
                }

                if (_localMod != null)
                {
                    _uIElement.AddOrRemoveChild(_deleteButton, ModLoader.Mods.All(x => x.Name != _localMod.Name));
                    _uIElement.Append(_extractButton);
                    Recalculate();
                }
            }
        }
예제 #4
0
        internal static UIPanel MakeSeparateListPanel(object item, object subitem, PropertyFieldWrapper memberInfo, IList array, int index, Func <string> AbridgedTextDisplayFunction)
        {
            UIPanel uIPanel = new UIPanel();

            uIPanel.CopyStyle(Interface.modConfig.uIPanel);
            uIPanel.BackgroundColor = UICommon.MainPanelBackground;

            BackgroundColorAttribute bca = ConfigManager.GetCustomAttribute <BackgroundColorAttribute>(memberInfo, subitem, null);

            if (bca != null)
            {
                uIPanel.BackgroundColor = bca.color;
            }

            //uIElement.Append(uIPanel);

            UIList separateList = new UIList();

            separateList.CopyStyle(Interface.modConfig.mainConfigList);
            separateList.Height.Set(-40f, 1f);
            separateList.Top.Set(40f, 0f);
            uIPanel.Append(separateList);
            int i   = 0;
            int top = 0;

            UIScrollbar uIScrollbar = new UIScrollbar();

            uIScrollbar.SetView(100f, 1000f);
            uIScrollbar.Height.Set(-40f, 1f);
            uIScrollbar.Top.Set(40f, 0f);
            uIScrollbar.HAlign = 1f;
            uIPanel.Append(uIScrollbar);
            separateList.SetScrollbar(uIScrollbar);

            string name = ConfigManager.GetCustomAttribute <LabelAttribute>(memberInfo, subitem, null)?.Label ?? memberInfo.Name;

            if (index != -1)
            {
                name = name + " #" + (index + 1);
            }
            Interface.modConfig.subPageStack.Push(name);
            //UIPanel heading = new UIPanel();
            //UIText headingText = new UIText(name);

            name = string.Join(" > ", Interface.modConfig.subPageStack.Reverse());   //.Aggregate((current, next) => current + "/" + next);

            UITextPanel <string> heading = new UITextPanel <string>(name);           // TODO: ToString as well. Separate label?

            heading.HAlign = 0f;
            //heading.Width.Set(-10, 0.5f);
            //heading.Left.Set(60, 0f);
            heading.Top.Set(-6, 0);
            heading.Height.Set(40, 0);
            //var headingContainer = GetContainer(heading, i++);
            //headingContainer.Height.Pixels = 40;
            uIPanel.Append(heading);
            //headingText.Top.Set(6, 0);
            //headingText.Left.Set(0, .5f);
            //headingText.HAlign = .5f;
            //uIPanel.Append(headingText);
            //top += 40;

            UITextPanel <string> back = new UITextPanel <string>("Back");

            back.HAlign = 1f;
            back.Width.Set(50, 0f);
            back.Top.Set(-6, 0);
            //top += 40;
            //var capturedCurrent = Interface.modConfig.currentConfigList;
            back.OnClick += (a, c) => {
                Interface.modConfig.uIElement.RemoveChild(uIPanel);
                Interface.modConfig.configPanelStack.Pop();
                Interface.modConfig.uIElement.Append(Interface.modConfig.configPanelStack.Peek());
                //Interface.modConfig.configPanelStack.Peek().SetScrollbar(Interface.modConfig.uIScrollbar);
                //Interface.modConfig.currentConfigList = capturedCurrent;
            };
            back.WithFadedMouseOver();
            //var backContainer = GetContainer(back, i++);
            //backContainer.Height.Pixels = 40;
            uIPanel.Append(back);

            //var b = new UIText("Test");
            //separateList.Add(b);
            // Make rest of list


            // load all mod config options into UIList
            // TODO: Inheritance with ModConfig? DeclaredOnly?

            if (true)
            {
                int  order       = 0;
                bool hasToString = false;
                if (array != null)
                {
                    var listType = memberInfo.Type.GetGenericArguments()[0];
                    hasToString = listType.GetMethod("ToString", new Type[0]).DeclaringType != typeof(object);
                }
                else
                {
                    hasToString = memberInfo.Type.GetMethod("ToString", new Type[0]).DeclaringType != typeof(object);
                }
                if (AbridgedTextDisplayFunction != null)
                {
                    var display = new UITextPanel <FuncStringWrapper>(new FuncStringWrapper()
                    {
                        func = AbridgedTextDisplayFunction,
                    })
                    {
                        DrawPanel = true
                    };
                    display.Recalculate();
                    var container = GetContainer(display, order++);
                    container.Height.Pixels = (int)display.GetOuterDimensions().Height;
                    separateList.Add(container);
                }
                //if (hasToString)
                //	_TextDisplayFunction = () => index + 1 + ": " + (array[index]?.ToString() ?? "null");
                foreach (PropertyFieldWrapper variable in ConfigManager.GetFieldsAndProperties(subitem))
                {
                    if (Attribute.IsDefined(variable.MemberInfo, typeof(JsonIgnoreAttribute)) && !Attribute.IsDefined(variable.MemberInfo, typeof(LabelAttribute)))                     // TODO, appropriately named attribute
                    {
                        continue;
                    }
                    HeaderAttribute header = ConfigManager.GetCustomAttribute <HeaderAttribute>(variable, null, null);
                    if (header != null)
                    {
                        var wrapper = new PropertyFieldWrapper(typeof(HeaderAttribute).GetProperty(nameof(HeaderAttribute.Header)));
                        WrapIt(separateList, ref top, wrapper, header, order++);
                    }
                    WrapIt(separateList, ref top, variable, subitem, order++);
                }
            }
            else
            {
                //ignoreSeparatePage just to simplify ToString label--> had some issues.
                //WrapIt(separateList, ref top, memberInfo, item, 1, ignoreSeparatePage: true);
            }

            Interface.modConfig.subPageStack.Pop();
            return(uIPanel);
        }
예제 #5
0
 private void SetHeading(string heading)
 {
     uITextPanel.SetText(heading, 0.8f, true);
     uITextPanel.Recalculate();
 }