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); }
public RectTransform AddSpacer() { var spacer = Instantiate(Spacer, Content ?? transform); Properties.Add(spacer.gameObject); OnPropertyAdded?.Invoke(spacer.gameObject); return(spacer); }
/// <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); } }
public StatSheet AddStatSheet() { var sheet = Instantiate(StatSheet, Content ?? transform); Properties.Add(sheet.gameObject); OnPropertyAdded?.Invoke(sheet.gameObject); RefreshPropertyValues += () => sheet.RefreshValues(); return(sheet); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); }