コード例 #1
0
 public EditWindow_TweakValues()
 {
     optionalTitle = "TweakValues";
     if (tweakValueFields == null)
     {
         tweakValueFields = (from ti in FindAllTweakables().Select(delegate(FieldInfo field)
         {
             TweakInfo result = default(TweakInfo);
             result.field = field;
             result.tweakValue = field.TryGetAttribute <TweakValue>();
             result.initial = GetAsFloat(field);
             return(result);
         })
                             orderby $"{ti.tweakValue.category}.{ti.field.DeclaringType.Name}"
                             select ti).ToList();
     }
 }
コード例 #2
0
        public override void DoWindowContents(Rect inRect)
        {
            Text.Font = GameFont.Small;
            Rect rect  = inRect.ContractedBy(4f);
            Rect rect2 = rect;

            rect2.xMax -= 33f;
            Rect rect3 = new Rect(0f, 0f, CategoryWidth, Text.CalcHeight("test", 1000f));
            Rect rect4 = new Rect(rect3.xMax, 0f, TitleWidth, rect3.height);
            Rect rect5 = new Rect(rect4.xMax, 0f, NumberWidth, rect3.height);
            Rect rect6 = new Rect(rect5.xMax, 0f, rect2.width - rect5.xMax, rect3.height);

            Widgets.BeginScrollView(rect, ref scrollPosition, new Rect(0f, 0f, rect2.width, rect3.height * (float)tweakValueFields.Count));
            foreach (TweakInfo tweakValueField in tweakValueFields)
            {
                TweakInfo current = tweakValueField;
                Widgets.Label(rect3, current.tweakValue.category);
                Widgets.Label(rect4, $"{current.field.DeclaringType.Name}.{current.field.Name}");
                float num;
                bool  flag;
                if (current.field.FieldType == typeof(float) || current.field.FieldType == typeof(int) || current.field.FieldType == typeof(ushort))
                {
                    float asFloat = GetAsFloat(current.field);
                    num = Widgets.HorizontalSlider(rect6, GetAsFloat(current.field), current.tweakValue.min, current.tweakValue.max);
                    SetFromFloat(current.field, num);
                    flag = (asFloat != num);
                }
                else if (current.field.FieldType == typeof(bool))
                {
                    bool flag2   = (bool)current.field.GetValue(null);
                    bool checkOn = flag2;
                    Widgets.Checkbox(rect6.xMin, rect6.yMin, ref checkOn);
                    current.field.SetValue(null, checkOn);
                    num  = (float)(checkOn ? 1 : 0);
                    flag = (flag2 != checkOn);
                }
                else
                {
                    Log.ErrorOnce($"Attempted to tweakvalue unknown field type {current.field.FieldType}", 83944645);
                    flag = false;
                    num  = current.initial;
                }
                if (num != current.initial)
                {
                    GUI.color = Color.red;
                    Widgets.Label(rect5, $"{current.initial} -> {num}");
                    GUI.color = Color.white;
                    if (Widgets.ButtonInvisible(rect5))
                    {
                        flag = true;
                        if (current.field.FieldType == typeof(float) || current.field.FieldType == typeof(int) || current.field.FieldType == typeof(ushort))
                        {
                            SetFromFloat(current.field, current.initial);
                        }
                        else if (current.field.FieldType == typeof(bool))
                        {
                            current.field.SetValue(null, current.initial != 0f);
                        }
                        else
                        {
                            Log.ErrorOnce($"Attempted to tweakvalue unknown field type {current.field.FieldType}", 83944646);
                        }
                    }
                }
                else
                {
                    Widgets.Label(rect5, $"{current.initial}");
                }
                if (flag)
                {
                    current.field.DeclaringType.GetMethod(current.field.Name + "_Changed", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(null, null);
                }
                rect3.y += rect3.height;
                rect4.y += rect3.height;
                rect5.y += rect3.height;
                rect6.y += rect3.height;
            }
            Widgets.EndScrollView();
        }