Пример #1
0
    public void AddField(string name, Func <string> read, Action <string> write)
    {
        var field = Instantiate(InputField, transform);

        field.Label.text        = name;
        field.Field.contentType = TMP_InputField.ContentType.Standard;
        field.Field.onValueChanged.AddListener(val => write(val));
        // field.Field.text = read();
        RefreshPropertyValues += () =>
        {
            var s = read();
            if (field.Field.text != s)
            {
                field.Field.text = s;
                field.gameObject.SetActive(false);
                Observable.NextFrame().Subscribe(_ =>
                {
                    if (field != null)
                    {
                        OnPropertyAdded?.Invoke(field.gameObject);
                    }
                });
            }
        };
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #2
0
    public RectTransform AddSpacer()
    {
        var spacer = Instantiate(Spacer, Content ?? transform);

        Properties.Add(spacer.gameObject);
        OnPropertyAdded?.Invoke(spacer.gameObject);
        return(spacer);
    }
Пример #3
0
 /// <summary>
 /// Add a property. This version has no key, you should not mix the key with non key versions.
 /// </summary>
 /// <param name="property">The property to add.</param>
 public void addEditableProperty(EditableProperty property)
 {
     editableProperties.AddLast(property);
     if (OnPropertyAdded != null)
     {
         OnPropertyAdded.Invoke(property);
     }
 }
Пример #4
0
    public StatSheet AddStatSheet()
    {
        var sheet = Instantiate(StatSheet, Content ?? transform);

        Properties.Add(sheet.gameObject);
        OnPropertyAdded?.Invoke(sheet.gameObject);
        RefreshPropertyValues += () => sheet.RefreshValues();
        return(sheet);
    }
Пример #5
0
    public RectTransform AddSection(string name)
    {
        var section = Instantiate(SectionPrefab, transform);

        section.GetComponentInChildren <TextMeshProUGUI>().text = name;
        Properties.Add(section.gameObject);
        OnPropertyAdded?.Invoke(section.gameObject);
        return(section);
    }
Пример #6
0
    public virtual PropertyButton AddButton(string name, Action <PointerEventData> onClick)
    {
        var button = Instantiate(PropertyButton, transform);

        button.Label.text      = name;
        button.Button.OnClick += onClick;
        Properties.Add(button.gameObject);
        OnPropertyAdded?.Invoke(button.gameObject);
        return(button);
    }
Пример #7
0
    public void AddButton(string name, string label, Action <PointerEventData> onClick)
    {
        var button = Instantiate(ButtonField, transform);

        button.Label.text       = name;
        button.ButtonLabel.text = label;
        button.Button.OnClick  += onClick;
        Properties.Add(button.gameObject);
        OnPropertyAdded?.Invoke(button.gameObject);
    }
Пример #8
0
    public void AddField(string name, Func <bool> read, Action <bool> write)
    {
        var field = Instantiate(BoolField, transform);

        field.Label.text = name;
        field.Toggle.onValueChanged.AddListener(val => write(val));
        RefreshPropertyValues += () => field.Toggle.isOn = read();
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #9
0
    public virtual PropertyButton AddButton(string name, Action onClick)
    {
        var button = Instantiate(PropertyButton, Content ?? transform);

        button.Label.text          = name;
        button.Button.interactable = onClick != null;
        button.Button.onClick.AddListener(() => onClick());
        Properties.Add(button.gameObject);
        OnPropertyAdded?.Invoke(button.gameObject);
        return(button);
    }
Пример #10
0
    public void AddButton(string name, string label, Action onClick)
    {
        var button = Instantiate(ButtonField, Content ?? transform);

        button.Label.text          = name;
        button.ButtonLabel.text    = label;
        button.Button.interactable = onClick != null;
        button.Button.onClick.AddListener(() => onClick());
        Properties.Add(button.gameObject);
        OnPropertyAdded?.Invoke(button.gameObject);
    }
Пример #11
0
    public AttributeProperty AddPersonalityProperty(PersonalityAttribute attribute, Func <float> read)
    {
        var attributeInstance = Instantiate(AttributePrefab, transform);

        attributeInstance.Title.text     = attribute.Name;
        attributeInstance.HighLabel.text = attribute.HighName;
        attributeInstance.LowLabel.text  = attribute.LowName;
        RefreshPropertyValues           += () => attributeInstance.Slider.value = read();
        Properties.Add(attributeInstance.gameObject);
        OnPropertyAdded?.Invoke(attributeInstance.gameObject);
        return(attributeInstance);
    }
Пример #12
0
    public void AddField(string name, Func <int> read, Action <int> write, int min, int max)
    {
        var field = Instantiate(RangedFloatField, transform);

        field.Label.text          = name;
        field.Slider.wholeNumbers = true;
        field.Slider.minValue     = min;
        field.Slider.maxValue     = max;
        field.Slider.onValueChanged.AddListener(val => write(Mathf.RoundToInt(val)));
        RefreshPropertyValues += () => field.Slider.value = read();
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #13
0
    public void AddProgressField(string name, Func <float> read)
    {
        var field = Instantiate(ProgressField, transform);

        field.Label.text          = name;
        field.Slider.wholeNumbers = false;
        field.Slider.minValue     = 0;
        field.Slider.maxValue     = 1;
        //field.Slider.onValueChanged.AddListener(val => write(val));
        RefreshPropertyValues += () => field.Slider.value = read();
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #14
0
    public Property AddProperty(Func <string> read)
    {
        if (read == null)
        {
            throw new ArgumentException("Attempted to add property with null read function!");
        }

        var property = Instantiate(Property, Content ?? transform);

        property.Label.text = read();

        RefreshPropertyValues += () => property.Label.text = read();
        Properties.Add(property.gameObject);
        OnPropertyAdded?.Invoke(property.gameObject);
        return(property);
    }
Пример #15
0
    public PropertyButton AddProperty(string name, Func <string> read = null, Action <PointerEventData> onClick = null, bool radio = false)
    {
        PropertyButton property;

        if (read != null)
        {
            property = Instantiate(PropertyLabelPrefab, transform);
        }
        else
        {
            property = Instantiate(PropertyPrefab, transform);
        }
        property.Label.text = name;
        if (radio)
        {
            RadioSelection = true;
            Buttons.Add(property.Button);
            property.Button.OnClick += data =>
            {
                if (data.button == PointerEventData.InputButton.Left)
                {
                    if (SelectedChild != null)
                    {
                        SelectedChild.CurrentState = FlatButtonState.Unselected;
                    }
                    SelectedChild = property.Button;
                    SelectedChild.CurrentState = FlatButtonState.Selected;
                }
                onClick?.Invoke(data);
            };
        }
        else if (onClick != null)
        {
            property.Button.OnClick += onClick;
        }

        if (read != null)
        {
            RefreshPropertyValues += () => ((PropertyLabel)property).Value.text = read.Invoke();
        }
        Properties.Add(property.gameObject);
        OnPropertyAdded?.Invoke(property.gameObject);
        return(property);
    }
Пример #16
0
    public void AddField(string name, Func <int> read, Action <int> write)
    {
        var field = Instantiate(InputField, transform);

        field.Label.text        = name;
        field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
        field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
        RefreshPropertyValues += () =>
        {
            var s = read().ToString(CultureInfo.InvariantCulture);
            if (field.Field.text != s)
            {
                field.Field.text = s;
                field.gameObject.SetActive(false);
                Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
            }
        };
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #17
0
    public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
    {
        var list = Instantiate(ListPrefab, transform);

        list.Context    = Context;
        list.Dropdown   = Dropdown;
        list.Title.text = name;
        // foreach (var element in elements)
        // {
        //     var item = Instantiate(PropertyPrefab, list);
        //     item.Name.text = element.Item1;
        //     item.Value.text = element.Item2();
        //     item.ValueFunction = element.Item2;
        //     Properties.Add(item.gameObject);
        // }
        //RefreshPropertyValues += () => list.RefreshValues();
        Properties.Add(list.gameObject);
        OnPropertyAdded?.Invoke(list.gameObject);
        return(list);
    }
Пример #18
0
    public Property AddProperty(string name, Func <string> read = null)
    {
        Property property;

        if (read != null)
        {
            property = Instantiate(PropertyLabel, Content ?? transform);
        }
        else
        {
            property = Instantiate(Property, Content ?? transform);
        }
        property.Label.text = name;

        if (read != null)
        {
            RefreshPropertyValues += () => ((PropertyLabel)property).Value.text = read.Invoke();
        }
        Properties.Add(property.gameObject);
        OnPropertyAdded?.Invoke(property.gameObject);
        return(property);
    }
Пример #19
0
    public void AddField(string name, Func <int> read, Action <int> write, string[] enumOptions)
    {
        var field = Instantiate(EnumField, transform);

        field.Label.text        = name;
        field.Dropdown.OnClick += data =>
        {
            var selected = read();
            Dropdown.gameObject.SetActive(true);
            Dropdown.Clear();
            for (int i = 0; i < enumOptions.Length; i++)
            {
                var index = i;
                Dropdown.AddOption(enumOptions[i], () => write(index), index == selected);
            }

            Dropdown.Show((RectTransform)field.Dropdown.transform);
        };
        RefreshPropertyValues += () => field.Dropdown.Label.text = enumOptions[read()];
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #20
0
    public void AddIncrementField(string name, Func <int> read, Action <int> write, Func <int> min, Func <int> max)
    {
        var field = Instantiate(IncrementField, transform);

        field.Label.text         = name;
        field.Increment.OnClick += data => write(read() + 1);
        field.Decrement.OnClick += data => write(read() - 1);
        RefreshPropertyValues   += () =>
        {
            var val    = read();
            var minval = min();
            var maxval = max();
            if (val < minval || val > maxval)
            {
                write(val = clamp(val, minval, maxval));
            }
            field.Value.text             = val.ToString(CultureInfo.InvariantCulture);
            field.Increment.CurrentState = val == maxval ? FlatButtonState.Disabled : FlatButtonState.Unselected;
            field.Decrement.CurrentState = val == minval ? FlatButtonState.Disabled : FlatButtonState.Unselected;
        };
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #21
0
    public void AddIncrementField(string name, Func <int> read, Action <int> write, Func <int> min, Func <int> max)
    {
        var field = Instantiate(IncrementField, Content ?? transform);

        field.Label.text = name;
        field.Increment.onClick.AddListener(() => write(read() + 1));
        field.Decrement.onClick.AddListener(() => write(read() - 1));
        RefreshPropertyValues += () =>
        {
            var val    = read();
            var minval = min();
            var maxval = max();
            if (val < minval || val > maxval)
            {
                write(val = clamp(val, minval, maxval));
            }
            field.Value.text             = val.ToString(CultureInfo.InvariantCulture);
            field.Increment.interactable = val == maxval;
            field.Decrement.interactable = val == minval;
        };
        Properties.Add(field.gameObject);
        OnPropertyAdded?.Invoke(field.gameObject);
    }
Пример #22
0
    public void Inspect(EquippedItem item)
    {
        Clear();
        if (item?.EquippableItem == null)
        {
            return;
        }

        Title.text = GetTitle(item.EquippableItem);

        AddItemProperties(item.EquippableItem);
        AddSpacer();

        if (item.GetBehavior <Weapon>() != null)
        {
            var weaponGroups = Instantiate(WeaponGroupAssignment, Content ?? transform);
            weaponGroups.Inspect(item);
            var       dragOffset = Vector2.zero;
            Transform dragObject = null;
            weaponGroups.OnBeginDragAsObservable().Subscribe(x =>
            {
                //Debug.Log($"Began dragging weapon group {x.group}");
                GameManager.BeginDrag(new WeaponGroupDragObject(x.group));
                dragObject = Instantiate(weaponGroups.Groups[x.group], DragParent, true).transform;
                dragOffset = (Vector2)dragObject.position - x.pointerEventData.position;
            });
            weaponGroups.OnDragAsObservable().Subscribe(x =>
            {
                dragObject.position = x.pointerEventData.position + dragOffset;
            });
            weaponGroups.OnEndDragAsObservable().Subscribe(x =>
            {
                //Debug.Log($"Ended dragging weapon group {x.group}");
                GameManager.EndDrag();
                Destroy(dragObject.gameObject);
            });
            Properties.Add(weaponGroups.gameObject);
            OnPropertyAdded?.Invoke(weaponGroups.gameObject);
        }

        var gearData    = GameManager.ItemManager.GetData(item.EquippableItem);
        var statusSheet = AddStatSheet();

        if (item.EquippableItem.Durability < .01f)
        {
            statusSheet.AddStat("Durability", () => "Item Destroyed!");
        }
        else
        {
            statusSheet.AddStat("Durability", () => $"{(int)(item.EquippableItem.Durability / gearData.Durability * 100)}%");
        }
        statusSheet.AddStat("Temperature", () => ActionGameManager.PlayerSettings.FormatTemperature(item.Temperature));

        var heatCurve = AddCurveField();

        heatCurve.Show(
            "Thermal Performance",
            gearData.HeatPerformanceCurve,
            t => ActionGameManager.PlayerSettings.FormatTemperature(lerp(gearData.MinimumTemperature, gearData.MaximumTemperature, t)),
            true);
        RefreshPropertyValues += () => heatCurve.SetCurrent(unlerp(gearData.MinimumTemperature, gearData.MaximumTemperature, item.Temperature));
        AddEquippableItemProperties(item.EquippableItem, item.Evaluate);
        AddSpacer();

        AddField("Override Shutdown", () => item.EquippableItem.OverrideShutdown, b => item.EquippableItem.OverrideShutdown = b);

        foreach (var behavior in item.Behaviors)
        {
            switch (behavior)
            {
            case Thermotoggle thermotoggle when thermotoggle.ThermotoggleData.Adjustable:
                AddField("Target Temperature",
                         () => thermotoggle.TargetTemperature,
                         temp => thermotoggle.TargetTemperature = temp);
                break;
            }
        }

        RefreshValues();
    }