Menu Screen + UI Restyle

Created menu screen
Created inventory tab with 2 cargo panes and properties panel
Updated the style of every UI prefab
Implemented Blurred UI material
Implemented UI shaders for map layers
Created Map tab (still needs input)
This commit is contained in:
Reinier Vens 2020-12-14 02:56:35 +00:00
commit 4f19189244
106 changed files with 11233 additions and 24584 deletions

View file

@ -5,10 +5,12 @@ using System.IO;
using System.Linq;
using Cinemachine;
using MessagePack;
using TMPro;
using UniRx;
using UnityEngine;
using Unity.Mathematics;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using static Unity.Mathematics.math;
using float2 = Unity.Mathematics.float2;
@ -16,11 +18,13 @@ public class ActionGameManager : MonoBehaviour
{
public GameSettings Settings;
public SectorRenderer SectorRenderer;
public MapView MapView;
// public MapView MapView;
public CinemachineVirtualCamera TopDownCamera;
public CinemachineVirtualCamera FollowCamera;
public GameObject GameplayUI;
public InventoryPanel InventoryPanel;
public MenuPanel Menu;
public InventoryMenu Inventory;
//public PlayerInput Input;
private DirectoryInfo _filePath;
@ -69,22 +73,22 @@ public class ActionGameManager : MonoBehaviour
SectorRenderer.MinimapDistance = Settings.MinimapZoomLevels[_zoomLevelIndex];
};
_input.Global.MapToggle.performed += context =>
{
MapView.enabled = !MapView.enabled;
GameplayUI.SetActive(!MapView.enabled);
if (MapView.enabled)
{
MapView.BindInput(_input.UI);
_input.Player.Disable();
}
else
{
_input.Player.Enable();
SectorRenderer.ViewDistance = Settings.DefaultViewDistance;
SectorRenderer.MinimapDistance = Settings.MinimapZoomLevels[_zoomLevelIndex];
}
};
// _input.Global.MapToggle.performed += context =>
// {
// MapView.enabled = !MapView.enabled;
// GameplayUI.SetActive(!MapView.enabled);
// if (MapView.enabled)
// {
// MapView.BindInput(_input.UI);
// _input.Player.Disable();
// }
// else
// {
// _input.Player.Enable();
// SectorRenderer.ViewDistance = Settings.DefaultViewDistance;
// SectorRenderer.MinimapDistance = Settings.MinimapZoomLevels[_zoomLevelIndex];
// }
// };
ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
ConsoleController.AddCommand("savezone", args =>
@ -93,11 +97,19 @@ public class ActionGameManager : MonoBehaviour
Zone.Data.Name = args[0];
SaveZone();
});
var hullType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Ship);
var hull = ItemManager.CreateInstance(hullType, 0, 1) as EquippableItem;
var entity = new Ship(ItemManager, Zone, hull);
InventoryPanel.Display(ItemManager, entity);
// MapButton.onClick.AddListener(() =>
// {
// if (_currentMenuTabButton == MapPanel) return;
//
// _currentMenuTabButton.GetComponent<TextMeshProUGUI>().color = Color.white;
// _currentMenuTabButton = MapButton;
// });
//
// var hullType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Ship);
// var hull = ItemManager.CreateInstance(hullType, 0, 1) as EquippableItem;
// var entity = new Ship(ItemManager, Zone, hull);
//InventoryPanel.Display(ItemManager, entity);
}
public void SaveZone() => File.WriteAllBytes(

View file

@ -17,8 +17,6 @@ public class SectorRenderer : MonoBehaviour
public Transform ZoneRoot;
public Transform SectorBrushes;
public MeshRenderer SectorBoundaryBrush;
public MeshRenderer MinimapGravityQuad;
public MeshRenderer MinimapTintQuad;
public CinemachineVirtualCamera SceneCamera;
public Camera[] FogCameras;
public Camera[] MinimapCameras;
@ -85,7 +83,7 @@ public class SectorRenderer : MonoBehaviour
{
foreach(var camera in MinimapCameras)
camera.orthographicSize = value;
MinimapGravityQuad.transform.localScale = value * 2 * Vector3.one;
// MinimapGravityQuad.transform.localScale = value * 2 * Vector3.one;
foreach (var planet in _planets.Values)
planet.Icon.transform.localScale = Settings.IconSize / 256 * value * Vector3.one;
}
@ -307,14 +305,14 @@ public class SectorRenderer : MonoBehaviour
SectorBoundaryBrush.material.SetFloat("_Depth", Settings.PlanetSettings.ZoneDepth + Settings.PlanetSettings.ZoneBoundaryFog);
var startDepth = Zone.PowerPulse(Settings.MinimapZoneGravityRange, Settings.PlanetSettings.ZoneDepthExponent) * Settings.PlanetSettings.ZoneDepth;
var depthRange = Settings.PlanetSettings.ZoneDepth - startDepth + _maxDepth;
MinimapGravityQuad.material.SetFloat("_StartDepth", startDepth);
MinimapGravityQuad.material.SetFloat("_DepthRange", depthRange);
// MinimapGravityQuad.material.SetFloat("_StartDepth", startDepth);
// MinimapGravityQuad.material.SetFloat("_DepthRange", depthRange);
FogMaterial.SetFloat("_GridOffset", Settings.PlanetSettings.ZoneBoundaryFog);
FogMaterial.SetVector("_GridTransform", new Vector4(fogPos.x,fogPos.z,_viewDistance*2));
var gravPos = MinimapGravityQuad.transform.position;
gravPos.y = -Settings.PlanetSettings.ZoneDepth - _maxDepth;
MinimapGravityQuad.transform.position = gravPos;
MinimapTintQuad.transform.position = gravPos - Vector3.up*10;
// var gravPos = MinimapGravityQuad.transform.position;
// gravPos.y = -Settings.PlanetSettings.ZoneDepth - _maxDepth;
// MinimapGravityQuad.transform.position = gravPos;
// MinimapTintQuad.transform.position = gravPos - Vector3.up*10;
}
}

View file

@ -530,20 +530,20 @@ public class EquippedCargoBay : EquippedItem
public readonly ItemInstance[,] Occupancy;
public readonly Dictionary<Guid, List<ItemInstance>> ItemsOfType = new Dictionary<Guid, List<ItemInstance>>();
private readonly CargoBayData _cargoData;
public readonly CargoBayData Data;
public float Mass { get; private set; }
public float ThermalMass { get; private set; }
public EquippedCargoBay(ItemManager itemManager, EquippableItem item, int2 position) : base(itemManager, item, position)
{
_cargoData = _itemManager.GetData(EquippableItem) as CargoBayData;
Data = _itemManager.GetData(EquippableItem) as CargoBayData;
Mass = _cargoData.Mass;
ThermalMass = _cargoData.Mass * _cargoData.SpecificHeat;
Mass = Data.Mass;
ThermalMass = Data.Mass * Data.SpecificHeat;
Occupancy = new ItemInstance[_cargoData.InteriorShape.Width,_cargoData.InteriorShape.Height];
Occupancy = new ItemInstance[Data.InteriorShape.Width,Data.InteriorShape.Height];
}
// Check whether the given item will fit when its origin is placed at the given coordinate
@ -587,7 +587,7 @@ public class EquippedCargoBay : EquippedItem
}
// Search all the space in the cargo bay for an empty space where the item fits
foreach (var cargoCoord in _cargoData.InteriorShape.Coordinates)
foreach (var cargoCoord in Data.InteriorShape.Coordinates)
{
if (ItemFits(item, cargoCoord))
{
@ -660,7 +660,7 @@ public class EquippedCargoBay : EquippedItem
public bool TryFindSpace(CraftedItemInstance item, out int2 position)
{
// Search all the space in the cargo bay for an empty space where the item fits
foreach (var cargoCoord in _cargoData.InteriorShape.Coordinates)
foreach (var cargoCoord in Data.InteriorShape.Coordinates)
{
if (ItemFits(item, cargoCoord))
{

View file

@ -45,11 +45,11 @@ public class Shape
{
var newCells = new bool[width, height];
for (int x = 0; x < width && x < Width; x++)
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height && y < Height; y++)
for (int y = 0; y < height; y++)
{
newCells[x, y] = Cells[x, y];
newCells[x, y] = x >= Width || y >= Height || Cells[x, y];
}
}
@ -315,16 +315,22 @@ public class HardpointData : ITintInspector
{
get
{
if (_tintColors == null)
{
var hardpointTypes = ((HardpointType[]) Enum.GetValues(typeof(HardpointType)));
_tintColors = hardpointTypes.ToDictionary(x => x,
x => ColorMath.HsvToRgb(float3((float)(int)x/hardpointTypes.Length, 1, 1)));
}
return _tintColors.ContainsKey(Type) ? _tintColors[Type] : _tintColors[HardpointType.Hull];
return GetColor(Type);
}
}
public static float3 GetColor(HardpointType type)
{
if (_tintColors == null)
{
var hardpointTypes = ((HardpointType[]) Enum.GetValues(typeof(HardpointType)));
_tintColors = hardpointTypes.ToDictionary(x => x,
x => ColorMath.HsvToRgb(float3((float)(int)x/hardpointTypes.Length, 1, 1)));
}
return _tintColors.ContainsKey(type) ? _tintColors[type] : _tintColors[HardpointType.Hull];
}
private static Dictionary<HardpointType, float3> _tintColors;
}

View file

@ -2,10 +2,11 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ButtonField : MonoBehaviour
{
public TextMeshProUGUI Label;
public TextMeshProUGUI ButtonLabel;
public FlatFlatButton Button;
public Button Button;
}

View file

@ -2,28 +2,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ConfirmationDialog : PropertiesPanel
{
public ClickCatcher CancelClickCatcher;
public FlatButton Cancel;
public FlatButton Confirm;
public Button Cancel;
public Button Confirm;
private Action _onCancel;
private Action _onConfirm;
private new void Start()
{
Cancel.OnClick += () =>
Cancel.onClick.AddListener(() =>
{
_onCancel?.Invoke();
End();
};
Confirm.OnClick += () =>
});
Confirm.onClick.AddListener(() =>
{
_onConfirm?.Invoke();
End();
};
});
if (CancelClickCatcher != null)
CancelClickCatcher.OnClick += data =>
{

View file

@ -46,12 +46,13 @@ public class DropdownMenu : MonoBehaviour
{
var optionButton = Instantiate(OptionPrefab, ContentRoot);
optionButton.Label.text = text;
optionButton.Button.OnClick += data =>
optionButton.Button.onClick.AddListener(() =>
{
action();
End();
};
optionButton.Button.CurrentState = !enabled ? FlatButtonState.Disabled : selected ? FlatButtonState.Selected : FlatButtonState.Unselected;
});
optionButton.Button.interactable = enabled;
//optionButton.Button..CurrentState = !enabled ? FlatButtonState.Disabled : selected ? FlatButtonState.Selected : FlatButtonState.Unselected;
_options.Add(optionButton.gameObject);
}

View file

@ -2,11 +2,12 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class IncrementField : MonoBehaviour
{
public TextMeshProUGUI Label;
public TextMeshProUGUI Value;
public FlatFlatButton Increment;
public FlatFlatButton Decrement;
public Button Increment;
public Button Decrement;
}

View file

@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UI;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using int2 = Unity.Mathematics.int2;
@ -70,7 +70,7 @@ public class InventoryPanel : MonoBehaviour
spriteIndex += 1 << i;
}
if (spriteIndex == 15)
if (spriteIndex == 0)
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
@ -80,7 +80,54 @@ public class InventoryPanel : MonoBehaviour
var node = NodePrototype.Instantiate<Prototype>().gameObject;
var image = node.GetComponentInChildren<Image>();
image.sprite = NodeTextures[spriteIndex];
image.color = hardpoint != null ? hardpoint.TintColor.ToColor() : interior ? Color.white * .5f : Color.white;
image.color = hardpoint?.TintColor.ToColor() ?? (interior ? Color.white * .5f : Color.white);
return node;
});
}
public void Display(ItemManager manager, EquippedCargoBay cargo)
{
Grid.constraintCount = cargo.Data.Shape.Width;
_nodeInstances = cargo.Data.Shape.AllCoordinates
.ToDictionary(v => v,
v =>
{
if (!cargo.Data.Shape[v])
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
return empty;
}
var spriteIndex = 0;
var item = cargo.Occupancy[v.x, v.y];
bool ItemMatch(int2 offset) =>
!cargo.Data.Shape[v + offset] ||
item == null ||
cargo.Occupancy[v.x + offset.x, v.y + offset.y] != item;
for(int i = 0; i < 8; i++)
if (ItemMatch(_offsets[i]))
spriteIndex += 1 << i;
if (spriteIndex == 0)
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
return empty;
}
var node = NodePrototype.Instantiate<Prototype>().gameObject;
var image = node.GetComponentInChildren<Image>();
image.sprite = NodeTextures[spriteIndex];
var itemData = manager.GetData(item);
if (item == null)
image.color = Color.white * .5f;
else if (itemData is EquippableItemData equippable)
image.color = HardpointData.GetColor(equippable.HardpointType).ToColor();
else
image.color = Color.white;
return node;
});
}

View file

@ -10,7 +10,7 @@ public class PropertiesList : PropertiesPanel
{
public Image FoldoutIcon;
public float FoldoutRotationDamping;
public FlatFlatButton Button;
public Button Button;
public VerticalLayoutGroup LayoutGroup;
public int FoldedPadding = -8;
public int ExpandedPadding = 8;
@ -24,7 +24,7 @@ public class PropertiesList : PropertiesPanel
public new void Awake()
{
Button.OnClick += _ => ToggleExpand();
Button.onClick.AddListener(ToggleExpand);
OnPropertyAdded += go => go.SetActive(_expanded);
//SetExpanded(true, true);
}

View file

@ -16,11 +16,11 @@ public class PropertiesPanel : MonoBehaviour
{
public DropdownMenu Dropdown;
public TextMeshProUGUI Title;
public RectTransform SectionPrefab;
public PropertiesList ListPrefab;
public PropertyButton PropertyPrefab;
public PropertyLabel PropertyLabelPrefab;
public AttributeProperty AttributePrefab;
public RectTransform Section;
public PropertiesList List;
public Property Property;
public PropertyLabel PropertyLabel;
public AttributeProperty Attribute;
public InputField InputField;
public RangedFloatField RangedFloatField;
public RangedFloatField ProgressField;
@ -82,38 +82,21 @@ public class PropertiesPanel : MonoBehaviour
public RectTransform AddSection(string name)
{
var section = Instantiate(SectionPrefab, transform);
var section = Instantiate(Section, transform);
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
Properties.Add(section.gameObject);
OnPropertyAdded?.Invoke(section.gameObject);
return section;
}
public PropertyButton AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
public Property AddProperty(string name, Func<string> read = null)
{
PropertyButton property;
Property property;
if(read != null)
property = Instantiate(PropertyLabelPrefab, transform);
property = Instantiate(PropertyLabel, transform);
else
property = Instantiate(PropertyPrefab, transform);
property = Instantiate(Property, 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();
@ -124,7 +107,7 @@ public class PropertiesPanel : MonoBehaviour
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
{
var list = Instantiate(ListPrefab, transform);
var list = Instantiate(List, transform);
list.Context = Context;
list.Dropdown = Dropdown;
list.Title.text = name;
@ -144,7 +127,7 @@ public class PropertiesPanel : MonoBehaviour
public AttributeProperty AddPersonalityProperty(PersonalityAttribute attribute, Func<float> read)
{
var attributeInstance = Instantiate(AttributePrefab, transform);
var attributeInstance = Instantiate(Attribute, transform);
attributeInstance.Title.text = attribute.Name;
attributeInstance.HighLabel.text = attribute.HighName;
attributeInstance.LowLabel.text = attribute.LowName;
@ -154,22 +137,22 @@ public class PropertiesPanel : MonoBehaviour
return attributeInstance;
}
public virtual PropertyButton AddButton(string name, Action<PointerEventData> onClick)
public virtual PropertyButton AddButton(string name, Action onClick)
{
var button = Instantiate(PropertyButton, transform);
button.Label.text = name;
button.Button.OnClick += onClick;
button.Button.onClick.AddListener(() => onClick());
Properties.Add(button.gameObject);
OnPropertyAdded?.Invoke(button.gameObject);
return button;
}
public void AddButton(string name, string label, Action<PointerEventData> onClick)
public void AddButton(string name, string label, Action onClick)
{
var button = Instantiate(ButtonField, transform);
button.Label.text = name;
button.ButtonLabel.text = label;
button.Button.OnClick += onClick;
button.Button.onClick.AddListener(() => onClick());
Properties.Add(button.gameObject);
OnPropertyAdded?.Invoke(button.gameObject);
}
@ -243,8 +226,8 @@ public class PropertiesPanel : MonoBehaviour
{
var field = Instantiate(IncrementField, transform);
field.Label.text = name;
field.Increment.OnClick += data => write(read() + 1);
field.Decrement.OnClick += data => write(read() - 1);
field.Increment.onClick.AddListener(() => write(read() + 1));
field.Decrement.onClick.AddListener(() => write(read() - 1));
RefreshPropertyValues += () =>
{
var val = read();
@ -253,8 +236,8 @@ public class PropertiesPanel : MonoBehaviour
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;
field.Increment.interactable = val == maxval;
field.Decrement.interactable = val == minval;
};
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);

View file

@ -0,0 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Property : MonoBehaviour
{
public TextMeshProUGUI Label;
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c0b005aebd0cd947a04034f1a42e838
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,10 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class PropertyButton : MonoBehaviour
public class PropertyButton : Property
{
public TextMeshProUGUI Label;
public FlatFlatButton Button;
public Button Button;
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8c0b005aebd0cd947a04034f1a42e838
guid: 58ab24f16cf869f4d88cd351417103a6
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -4,7 +4,7 @@ using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PropertyLabel : PropertyButton
public class PropertyLabel : Property
{
public TextMeshProUGUI Value;
}