Infrastructure and Production
Added the ability to directly install blueprints onto hardpoints in the colony tab Added the ability to customize production of factories This stuff is still kinda buggy
This commit is contained in:
parent
a99b4e82f3
commit
4eb83acb34
32 changed files with 2525 additions and 399 deletions
11
Assets/Scripts/UI/ButtonField.cs
Normal file
11
Assets/Scripts/UI/ButtonField.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class ButtonField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public TextMeshProUGUI ButtonLabel;
|
||||
public FlatFlatButton Button;
|
||||
}
|
||||
11
Assets/Scripts/UI/ButtonField.cs.meta
Normal file
11
Assets/Scripts/UI/ButtonField.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 16f77bec2596fd74ba40cb68aa4c7f20
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -3,30 +3,65 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class ColonyTab : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Title;
|
||||
public PropertiesPanel General;
|
||||
public PropertiesPanel Inventory;
|
||||
public PropertiesPanel Details;
|
||||
|
||||
public ContextMenu ContextMenu;
|
||||
|
||||
[HideInInspector]
|
||||
public GameContext Context;
|
||||
public GameContext Context
|
||||
{
|
||||
get => _context;
|
||||
set
|
||||
{
|
||||
_context = value;
|
||||
General.Context = value;
|
||||
Inventory.Context = value;
|
||||
Details.Context = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Guid _selectedColony;
|
||||
private GameContext _context;
|
||||
private HardpointData _selectedHardpoint;
|
||||
|
||||
public void Open(Guid colony)
|
||||
{
|
||||
_selectedColony = colony;
|
||||
_selectedHardpoint = null;
|
||||
|
||||
var entity = Context.Cache.Get<Entity>(_selectedColony);
|
||||
entity.OnInventoryUpdate += () => PopulateScreen(entity);
|
||||
PopulateScreen(entity);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
var entity = Context.Cache.Get<Entity>(_selectedColony);
|
||||
entity.ClearInventoryListeners();
|
||||
}
|
||||
|
||||
public void PopulateScreen(Entity entity){
|
||||
Title.text = entity.Name;
|
||||
|
||||
General.Clear();
|
||||
Inventory.Clear();
|
||||
Details.Clear();
|
||||
|
||||
var entity = Context.Cache.Get<Entity>(_selectedColony);
|
||||
|
||||
General.AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{entity.Capacity:0}");
|
||||
var corporation = Context.Cache.Get<Corporation>(entity.Corporation);
|
||||
var blueprints = corporation.UnlockedBlueprints.Select(id => Context.Cache.Get<BlueprintData>(id));
|
||||
var hull = Context.Cache.Get<Gear>(entity.Hull);
|
||||
var hullData = Context.Cache.Get<HullData>(hull.Data);
|
||||
var capacity = Context.Evaluate(hullData.Capacity, hull, entity);
|
||||
|
||||
General.AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{capacity:0}");
|
||||
General.AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
General.AddProperty("Temperature", () => $"{entity.Temperature:0}°K");
|
||||
General.AddProperty("Energy", () => $"{entity.Energy:0}/{entity.GetBehaviors<Reactor>().First().Capacitance:0}");
|
||||
|
|
@ -37,24 +72,107 @@ public class ColonyTab : MonoBehaviour
|
|||
() => attribute.Value);
|
||||
General.RefreshValues();
|
||||
|
||||
Inventory.ChildRadioSelection = true;
|
||||
var cargoData = entity.Cargo.ToDictionary(id => _context.Cache.Get<ItemInstance>(id),
|
||||
id => Context.Cache.Get<ItemData>(_context.Cache.Get<ItemInstance>(id).Data));
|
||||
//var incompleteGear = entity.IncompleteGear.Keys.Select(id => _context.Cache.Get<Gear>(id));
|
||||
// var incompleteGear = entity.IncompleteGear.Select(x =>
|
||||
// {
|
||||
// var gear = _context.Cache.Get<Gear>(x.Key);
|
||||
// var productionTime = _context.Cache.Get<BlueprintData>(gear.Blueprint).ProductionTime;
|
||||
// var progress = (productionTime - (float) x.Value) / productionTime;
|
||||
// return (gear, progress);
|
||||
// });
|
||||
Inventory.AddSection("Gear");
|
||||
var equippedItems = entity.EquippedItems.Select(g => Context.Cache.Get<Gear>(g));
|
||||
foreach(var gear in equippedItems)
|
||||
Inventory.AddProperty(gear.ItemData.Name, null, () => PopulateDetails(gear, entity));
|
||||
var gearList = new List<Gear>(entity.GearData.Keys.Concat(entity.IncompleteGear.Keys.Select(id => _context.Cache.Get<Gear>(id))));
|
||||
foreach (var hardpoint in hullData.Hardpoints)
|
||||
{
|
||||
var match = gearList.FirstOrDefault(g => g.ItemData.HardpointType == hardpoint.Type);
|
||||
var matchingCargoGear = cargoData
|
||||
.Where(x => x.Value is EquippableItemData equippableItemData &&
|
||||
equippableItemData.HardpointType == hardpoint.Type).Select(x=>x.Key as Gear)
|
||||
.ToArray();
|
||||
if (match == null)
|
||||
{
|
||||
var matchingBlueprints = blueprints.Where(bp =>
|
||||
bp.FactoryItem == Guid.Empty &&
|
||||
Context.Cache.Get<ItemData>(bp.Item) is GearData gearData &&
|
||||
gearData.HardpointType == hardpoint.Type).ToArray();
|
||||
Action<PointerEventData> onClick = null;
|
||||
if (matchingCargoGear.Any() || matchingBlueprints.Any())
|
||||
onClick = data =>
|
||||
{
|
||||
if (data.button == PointerEventData.InputButton.Left)
|
||||
{
|
||||
Details.Clear();
|
||||
foreach (var blueprint in matchingBlueprints)
|
||||
{
|
||||
var blueprintList = Details.AddList(blueprint.Name);
|
||||
|
||||
foreach (var ingredient in blueprint.Ingredients)
|
||||
{
|
||||
var itemData = _context.Cache.Get<ItemData>(ingredient.Key);
|
||||
blueprintList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
|
||||
}
|
||||
|
||||
var bpItemData = _context.Cache.Get<ItemData>(blueprint.Item);
|
||||
|
||||
if(entity.GetBlueprintIngredients(blueprint, out _, out _))
|
||||
blueprintList.AddButton("Build", _ => entity.Build(blueprint, 1, bpItemData.Name, true));
|
||||
}
|
||||
Details.RefreshValues();
|
||||
}
|
||||
else if (data.button == PointerEventData.InputButton.Right)
|
||||
{
|
||||
ContextMenu.gameObject.SetActive(true);
|
||||
ContextMenu.Clear();
|
||||
if (matchingCargoGear.Any())
|
||||
ContextMenu.AddDropdown("Install", matchingCargoGear
|
||||
.Select<Gear, (string, Action, bool)>(gear => (gear.Name, () => entity.Equip(gear), true)));
|
||||
if(matchingBlueprints.Any())
|
||||
ContextMenu.AddDropdown("Build", matchingBlueprints
|
||||
.Select<BlueprintData, (string, Action, bool)>(blueprint => (blueprint.Name, () => entity.Build(blueprint, 1, _context.Cache.Get<ItemData>(blueprint.Item).Name, true), entity.GetBlueprintIngredients(blueprint, out _, out _))));
|
||||
ContextMenu.Show();
|
||||
}
|
||||
};
|
||||
Inventory.AddProperty($"Empty {Enum.GetName(typeof(HardpointType), hardpoint.Type)} Hardpoint", null, onClick, matchingBlueprints.Any());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entity.IncompleteGear.ContainsKey(match.ID))
|
||||
{
|
||||
Inventory.AddProgressField(match.Name, () =>
|
||||
{
|
||||
var productionTime = _context.Cache.Get<BlueprintData>(match.Blueprint).ProductionTime;
|
||||
return (productionTime - (float) entity.IncompleteGear[match.ID]) / productionTime;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var prop = Inventory.AddProperty(match.Name, null, _ =>
|
||||
{
|
||||
_selectedHardpoint = hardpoint;
|
||||
PopulateDetails(match, entity);
|
||||
}, true);
|
||||
|
||||
if (hardpoint == _selectedHardpoint) prop.Button.OnPointerClick(new PointerEventData(null){button = PointerEventData.InputButton.Left});
|
||||
}
|
||||
|
||||
|
||||
gearList.Remove(match);
|
||||
}
|
||||
}
|
||||
|
||||
if(!entity.Cargo.Any())
|
||||
Inventory.AddSection("No Cargo");
|
||||
else
|
||||
{
|
||||
Inventory.AddSection("Cargo");
|
||||
foreach (var itemID in entity.Cargo)
|
||||
foreach (var x in cargoData)
|
||||
{
|
||||
var itemInstance = Context.Cache.Get<ItemInstance>(itemID);
|
||||
var data = Context.Cache.Get<ItemData>(itemInstance.Data);
|
||||
if(itemInstance is SimpleCommodity simpleCommodity)
|
||||
Inventory.AddProperty(data.Name, () => simpleCommodity.Quantity.ToString());
|
||||
if(x.Key is SimpleCommodity simpleCommodity)
|
||||
Inventory.AddProperty(x.Value.Name, () => simpleCommodity.Quantity.ToString());
|
||||
else
|
||||
Inventory.AddProperty(data.Name);
|
||||
Inventory.AddProperty(x.Value.Name);
|
||||
}
|
||||
}
|
||||
Inventory.RefreshValues();
|
||||
|
|
@ -69,6 +187,52 @@ public class ColonyTab : MonoBehaviour
|
|||
Details.AddProperty("Durability",
|
||||
() =>
|
||||
$"{gear.Durability.SignificantDigits(Context.GlobalData.SignificantDigits)}/{Context.Evaluate(data.Durability, gear).SignificantDigits(Context.GlobalData.SignificantDigits)}");
|
||||
foreach (var behavior in entity.ItemBehaviors[gear])
|
||||
{
|
||||
if (behavior is Factory factory)
|
||||
{
|
||||
factory.OnToolingUpdate += () => PopulateDetails(item, entity);
|
||||
Details.AddField("Production Quality", () => factory.ProductionQuality, f => factory.ProductionQuality = f, 0, 1);
|
||||
var corporation = Context.Cache.Get<Corporation>(entity.Corporation);
|
||||
var compatibleBlueprints = corporation.UnlockedBlueprints
|
||||
.Select(id => _context.Cache.Get<BlueprintData>(id))
|
||||
.Where(bp => bp.FactoryItem == data.ID).ToList();
|
||||
if (factory.RetoolingTime > 0)
|
||||
{
|
||||
Details.AddProgressField("Retooling", () => (factory.ToolingTime - (float) factory.RetoolingTime) / factory.ToolingTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
Details.AddField("Item",
|
||||
() => compatibleBlueprints.FindIndex(bp=>bp.ID== factory.Blueprint) + 1,
|
||||
i => factory.Blueprint = i == 0 ? Guid.Empty : compatibleBlueprints[i - 1].ID,
|
||||
new []{"None"}.Concat(compatibleBlueprints.Select(bp=>bp.Name)).ToArray());
|
||||
if (factory.Blueprint != Guid.Empty)
|
||||
{
|
||||
if (factory.ItemsUnderConstruction.Any())
|
||||
{
|
||||
Details.AddProgressField("Production", () =>
|
||||
{
|
||||
var itemUnderConstruction = factory.ItemsUnderConstruction[0];
|
||||
var itemInstance = _context.Cache.Get<CraftedItemInstance>(itemUnderConstruction);
|
||||
var blueprintData = _context.Cache.Get<BlueprintData>(itemInstance.Blueprint);
|
||||
return (blueprintData.ProductionTime - (float) entity.IncompleteCargo[itemUnderConstruction]) / blueprintData.ProductionTime;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var ingredientsList = Details.AddList("Ingredients Needed");
|
||||
var blueprintData = _context.Cache.Get<BlueprintData>(factory.Blueprint);
|
||||
foreach (var ingredient in blueprintData.Ingredients)
|
||||
{
|
||||
var itemData = _context.Cache.Get<ItemData>(ingredient.Key);
|
||||
ingredientsList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var behavior in data.Behaviors)
|
||||
{
|
||||
var type = behavior.GetType();
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class ContextMenu : MonoBehaviour
|
|||
_hasDropdown = false;
|
||||
}
|
||||
|
||||
public void AddOption(string text, Action action)
|
||||
public void AddOption(string text, Action action, bool enabled = true)
|
||||
{
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
optionButton.Label.text = text;
|
||||
|
|
@ -72,10 +72,11 @@ public class ContextMenu : MonoBehaviour
|
|||
Destroy(_dropdown);
|
||||
};
|
||||
optionButton.Arrow.gameObject.SetActive(false);
|
||||
optionButton.Button.interactable = enabled;
|
||||
_options.Add(optionButton.gameObject);
|
||||
}
|
||||
|
||||
public void AddDropdown(string text, IEnumerable<(string text, Action action)> options)
|
||||
public void AddDropdown(string text, IEnumerable<(string text, Action action, bool enabled)> options)
|
||||
{
|
||||
_hasDropdown = true;
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
|
|
@ -89,7 +90,7 @@ public class ContextMenu : MonoBehaviour
|
|||
var drop = Instantiate(DropMenuPrefab, Root);
|
||||
_dropdown = drop.gameObject;
|
||||
foreach (var option in options)
|
||||
drop.AddOption(option.text, option.action);
|
||||
drop.AddOption(option.text, option.action, option.enabled);
|
||||
drop.Parent = this;
|
||||
drop.ForceDirectionRight = _dropdownRight;
|
||||
Vector3[] corners = new Vector3[4];
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public class FlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandl
|
|||
public FlatButtonAppearance SelectedAppearance;
|
||||
public FlatButtonAppearance HoverAppearance;
|
||||
public FlatButtonAppearance ClickAppearance;
|
||||
public FlatButtonAppearance DisabledAppearance;
|
||||
|
||||
private RectOffset _defaultPadding;
|
||||
private float _currentPadding;
|
||||
|
|
@ -45,7 +46,7 @@ public class FlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandl
|
|||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!DisableClickWhenSelected || CurrentState != FlatButtonState.Selected)
|
||||
if (CurrentState != FlatButtonState.Disabled && (!DisableClickWhenSelected || CurrentState != FlatButtonState.Selected))
|
||||
{
|
||||
Fill.color = ClickAppearance.FillColor;
|
||||
Outline.color = ClickAppearance.OutlineColor;
|
||||
|
|
@ -67,6 +68,9 @@ public class FlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandl
|
|||
case FlatButtonState.Hover:
|
||||
appearance = HoverAppearance;
|
||||
break;
|
||||
case FlatButtonState.Disabled:
|
||||
appearance = DisabledAppearance;
|
||||
break;
|
||||
default:
|
||||
appearance = new FlatButtonAppearance();
|
||||
break;
|
||||
|
|
@ -89,7 +93,8 @@ public enum FlatButtonState
|
|||
{
|
||||
Unselected,
|
||||
Selected,
|
||||
Hover
|
||||
Hover,
|
||||
Disabled
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using UnityEngine.UI;
|
|||
|
||||
public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
public event Action OnClick;
|
||||
public event Action<PointerEventData> OnClick;
|
||||
public float StateDamping;
|
||||
// public RectTransform Tab;
|
||||
public Image Fill;
|
||||
|
|
@ -19,6 +19,7 @@ public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitH
|
|||
public Color SelectedColor;
|
||||
public Color HoverColor;
|
||||
public Color ClickColor;
|
||||
public Color DisabledColor;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
|
|
@ -34,12 +35,12 @@ public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitH
|
|||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!DisableClickWhenSelected || CurrentState != FlatButtonState.Selected)
|
||||
if (CurrentState != FlatButtonState.Disabled && (!DisableClickWhenSelected || CurrentState != FlatButtonState.Selected))
|
||||
{
|
||||
if (OnClick != null)
|
||||
{
|
||||
Fill.color = ClickColor;
|
||||
OnClick();
|
||||
OnClick(eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +59,9 @@ public class FlatFlatButton : MonoBehaviour, IPointerEnterHandler, IPointerExitH
|
|||
case FlatButtonState.Hover:
|
||||
appearance = HoverColor;
|
||||
break;
|
||||
case FlatButtonState.Disabled:
|
||||
appearance = DisabledColor;
|
||||
break;
|
||||
default:
|
||||
appearance = Color.white;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PropertiesList : PropertiesPanel
|
||||
|
|
@ -33,7 +34,7 @@ public class PropertiesList : PropertiesPanel
|
|||
|
||||
public void Start()
|
||||
{
|
||||
Button.OnClick += ToggleExpand;
|
||||
Button.OnClick += _ => ToggleExpand();
|
||||
}
|
||||
|
||||
public void ToggleExpand() => Expanded = !_expanded;
|
||||
|
|
@ -45,24 +46,31 @@ public class PropertiesList : PropertiesPanel
|
|||
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
|
||||
}
|
||||
|
||||
public new PropertyLabel AddProperty(string name, Func<string> value = null, Action onClick = null)
|
||||
public override PropertyLabel AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
|
||||
{
|
||||
var prop = base.AddProperty(name, value, onClick);
|
||||
var prop = base.AddProperty(name, read, onClick, radio);
|
||||
prop.gameObject.SetActive(false);
|
||||
return prop;
|
||||
}
|
||||
|
||||
public new PropertiesList AddList(string name)
|
||||
public override PropertiesList AddList(string name)
|
||||
{
|
||||
var list = base.AddList(name);
|
||||
list.gameObject.SetActive(false);
|
||||
return list;
|
||||
}
|
||||
|
||||
public new RectTransform AddSection(string name)
|
||||
public override RectTransform AddSection(string name)
|
||||
{
|
||||
var section = base.AddSection(name);
|
||||
section.gameObject.SetActive(false);
|
||||
return section;
|
||||
}
|
||||
|
||||
public override PropertyButton AddButton(string name, Action<PointerEventData> onClick)
|
||||
{
|
||||
var button = base.AddButton(name, onClick);
|
||||
button.gameObject.SetActive(false);
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class PropertiesPanel : MonoBehaviour
|
||||
{
|
||||
|
|
@ -15,14 +16,18 @@ public class PropertiesPanel : MonoBehaviour
|
|||
public AttributeProperty AttributePrefab;
|
||||
public InputField InputField;
|
||||
public RangedFloatField RangedFloatField;
|
||||
public RangedFloatField ProgressField;
|
||||
public EnumField EnumField;
|
||||
public BoolField BoolField;
|
||||
public bool ChildRadioSelection;
|
||||
public PropertyButton PropertyButton;
|
||||
public ButtonField ButtonField;
|
||||
[HideInInspector] public GameContext Context;
|
||||
|
||||
protected List<GameObject> Properties = new List<GameObject>();
|
||||
protected List<FlatFlatButton> Buttons = new List<FlatFlatButton>();
|
||||
protected FlatFlatButton SelectedChild;
|
||||
protected event Action RefreshPropertyValues;
|
||||
protected bool RadioSelection = false;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
|
@ -37,6 +42,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Buttons.Clear();
|
||||
SelectedChild = null;
|
||||
RefreshPropertyValues = null;
|
||||
RadioSelection = false;
|
||||
}
|
||||
|
||||
public void Deselect()
|
||||
|
|
@ -46,7 +52,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
SelectedChild = null;
|
||||
}
|
||||
|
||||
public RectTransform AddSection(string name)
|
||||
public virtual RectTransform AddSection(string name)
|
||||
{
|
||||
var section = Instantiate(SectionPrefab, transform);
|
||||
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
|
||||
|
|
@ -54,20 +60,24 @@ public class PropertiesPanel : MonoBehaviour
|
|||
return section;
|
||||
}
|
||||
|
||||
public PropertyLabel AddProperty(string name, Func<string> read = null, Action onClick = null)
|
||||
public virtual PropertyLabel AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
|
||||
{
|
||||
var property = Instantiate(PropertyPrefab, transform);
|
||||
property.Name.text = name;
|
||||
if (ChildRadioSelection)
|
||||
if (radio)
|
||||
{
|
||||
RadioSelection = true;
|
||||
Buttons.Add(property.Button);
|
||||
property.Button.OnClick += () =>
|
||||
property.Button.OnClick += data =>
|
||||
{
|
||||
if (SelectedChild != null)
|
||||
SelectedChild.CurrentState = FlatButtonState.Unselected;
|
||||
SelectedChild = property.Button;
|
||||
SelectedChild.CurrentState = FlatButtonState.Selected;
|
||||
onClick?.Invoke();
|
||||
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;
|
||||
|
|
@ -76,7 +86,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
return property;
|
||||
}
|
||||
|
||||
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
|
||||
public virtual PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
|
||||
{
|
||||
var list = Instantiate(ListPrefab, transform);
|
||||
list.Title.text = name;
|
||||
|
|
@ -103,8 +113,26 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Properties.Add(attributeInstance.gameObject);
|
||||
return attributeInstance;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<string> read, Action<string> write)
|
||||
public void AddField(string name, Func<string> read, Action<string> write)
|
||||
{
|
||||
var field = Instantiate(InputField, transform);
|
||||
field.Label.text = name;
|
||||
|
|
@ -114,7 +142,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<float> read, Action<float> write)
|
||||
public void AddField(string name, Func<float> read, Action<float> write)
|
||||
{
|
||||
var field = Instantiate(InputField, transform);
|
||||
field.Label.text = name;
|
||||
|
|
@ -124,7 +152,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<int> read, Action<int> write)
|
||||
public void AddField(string name, Func<int> read, Action<int> write)
|
||||
{
|
||||
var field = Instantiate(InputField, transform);
|
||||
field.Label.text = name;
|
||||
|
|
@ -134,7 +162,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<float> read, Action<float> write, float min, float max)
|
||||
public void AddField(string name, Func<float> read, Action<float> write, float min, float max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, transform);
|
||||
field.Label.text = name;
|
||||
|
|
@ -146,7 +174,19 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<int> read, Action<int> write, int min, int max)
|
||||
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);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<int> read, Action<int> write, int min, int max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, transform);
|
||||
field.Label.text = name;
|
||||
|
|
@ -158,7 +198,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<bool> read, Action<bool> write)
|
||||
public void AddField(string name, Func<bool> read, Action<bool> write)
|
||||
{
|
||||
var field = Instantiate(BoolField, transform);
|
||||
field.Label.text = name;
|
||||
|
|
@ -167,7 +207,7 @@ public class PropertiesPanel : MonoBehaviour
|
|||
Properties.Add(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProperty(string name, Func<int> read, Action<int> write, string[] enumOptions)
|
||||
public void AddField(string name, Func<int> read, Action<int> write, string[] enumOptions)
|
||||
{
|
||||
var field = Instantiate(EnumField, transform);
|
||||
field.Label.text = name;
|
||||
|
|
|
|||
10
Assets/Scripts/UI/PropertyButton.cs
Normal file
10
Assets/Scripts/UI/PropertyButton.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class PropertyButton : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public FlatFlatButton Button;
|
||||
}
|
||||
11
Assets/Scripts/UI/PropertyButton.cs.meta
Normal file
11
Assets/Scripts/UI/PropertyButton.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8c0b005aebd0cd947a04034f1a42e838
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue