コード例 #1
0
 public ConfigElement(PropertyFieldWrapper memberInfo, object item, IList array)
 {
     Width.Set(0f, 1f);
     Height.Set(30f, 0f);
     this.memberInfo           = memberInfo;
     this.item                 = item;
     this.array                = array;
     this.backgroundColor      = UICommon.defaultUIBlue;
     this._TextDisplayFunction = () => memberInfo.Name;
     labelAttribute            = ConfigManager.GetCustomAttribute <LabelAttribute>(memberInfo, item, array);
     if (labelAttribute != null)
     {
         this._TextDisplayFunction = () => labelAttribute.Label;
     }
     tooltipAttribute = ConfigManager.GetCustomAttribute <TooltipAttribute>(memberInfo, item, array);
     if (tooltipAttribute != null)
     {
         this._TooltipFunction = () => tooltipAttribute.Tooltip;
     }
     backgroundColorAttribute = ConfigManager.GetCustomAttribute <BackgroundColorAttribute>(memberInfo, item, array);
     if (backgroundColorAttribute != null)
     {
         backgroundColor = backgroundColorAttribute.color;
     }
     rangeAttribute     = ConfigManager.GetCustomAttribute <RangeAttribute>(memberInfo, item, array);
     incrementAttribute = ConfigManager.GetCustomAttribute <IncrementAttribute>(memberInfo, item, array);
 }
コード例 #2
0
 private void HandleBackgroundColorOptions(BackgroundColorAttribute bgColorAttr, SerializedProperty property, ReorderableListData data)
 {
     data.DrawBackgroundCallback = (active, focused) =>
     {
         if (focused)
         {
             return(1.35f * bgColorAttr.Color);
         }
         else if (active)
         {
             return(Color.Lerp(Color.white, bgColorAttr.Color, 0.75f));
         }
         else
         {
             return(bgColorAttr.Color);
         }
     };
 }
コード例 #3
0
ファイル: ConfigElement.cs プロジェクト: hamstar0/tModLoader
 public virtual void OnBind()
 {
     TextDisplayFunction = () => memberInfo.Name;
     labelAttribute      = ConfigManager.GetCustomAttribute <LabelAttribute>(memberInfo, item, list);
     if (labelAttribute != null)
     {
         TextDisplayFunction = () => labelAttribute.Label;
     }
     tooltipAttribute = ConfigManager.GetCustomAttribute <TooltipAttribute>(memberInfo, item, list);
     if (tooltipAttribute != null)
     {
         this.TooltipFunction = () => tooltipAttribute.Tooltip;
     }
     backgroundColorAttribute = ConfigManager.GetCustomAttribute <BackgroundColorAttribute>(memberInfo, item, list);
     if (backgroundColorAttribute != null)
     {
         backgroundColor = backgroundColorAttribute.color;
     }
     rangeAttribute     = ConfigManager.GetCustomAttribute <RangeAttribute>(memberInfo, item, list);
     incrementAttribute = ConfigManager.GetCustomAttribute <IncrementAttribute>(memberInfo, item, list);
 }
コード例 #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);
        }