Save/Load and Main Menu Submenus

Redid all of the property panel UI prefabs (oof)
Implemented saving and loading of the game state
Moved sector generation to sector constructor (along with loading from save file)
Entity settings now separate from player settings
Player settings (incl. saved run) now statically accessible from game manager
Added animations and submenus to the main menu
Unified main menu settings and properties panel styles for prefab reusability
This commit is contained in:
Reinier Vens 2021-03-14 03:56:49 +00:00
commit b6828a975a
63 changed files with 2007 additions and 1158 deletions

View file

@ -6,9 +6,11 @@ using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class EnumField : MonoBehaviour
{
public TextMeshProUGUI Label;
public FlatFlatButton Dropdown;
public Button Dropdown;
public TextMeshProUGUI DropdownLabel;
}

View file

@ -391,8 +391,8 @@ public class InventoryMenu : MonoBehaviour
{
PropertiesPanel.Clear();
PropertiesPanel.AddField("Shutdown Threshold",
() => GameManager.PlayerSettings.ShutdownPerformance,
f => GameManager.PlayerSettings.ShutdownPerformance = f,
() => GameManager.CurrentEntity.Settings.ShutdownPerformance,
f => GameManager.CurrentEntity.Settings.ShutdownPerformance = f,
0,
1);
});

View file

@ -147,6 +147,7 @@ public class PropertiesPanel : MonoBehaviour
{
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);
@ -158,6 +159,7 @@ public class PropertiesPanel : MonoBehaviour
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);
@ -302,7 +304,7 @@ public class PropertiesPanel : MonoBehaviour
{
var field = Instantiate(EnumField, Content ?? transform);
field.Label.text = name;
field.Dropdown.OnClick += data =>
field.Dropdown.onClick.AddListener(() =>
{
var selected = read();
Dropdown.gameObject.SetActive(true);
@ -314,8 +316,8 @@ public class PropertiesPanel : MonoBehaviour
}
Dropdown.Show((RectTransform) field.Dropdown.transform);
};
RefreshPropertyValues += () => field.Dropdown.Label.text = enumOptions[read()];
});
RefreshPropertyValues += () => field.DropdownLabel.text = enumOptions[read()];
Properties.Add(field.gameObject);
OnPropertyAdded?.Invoke(field.gameObject);
}

View file

@ -20,6 +20,7 @@ public class SectorMap : MonoBehaviour
public Prototype ZonePrototype;
public Prototype LinkPrototype;
public Prototype IconPrototype;
public Prototype IconBackgroundPrototype;
public Material ZonePrimaryMaterial;
public Material ZoneSecondaryMaterial;
public Material ZoneLinkMaterial;
@ -32,8 +33,7 @@ public class SectorMap : MonoBehaviour
public Texture2D HomeIcon;
public Prototype LegendPrototype;
public float IconDistance = 1;
public int ZoneCount = 64;
public float LinkDensity = .5f;
public float IconBackgroundSize = 3;
public float LabelDistance = .4f;
private Dictionary<MegaCorporation, (RenderTexture influence, Material primaryMaterial, Material secondaryMaterial, Material linkMaterial)> _factionMaterials =
@ -66,7 +66,7 @@ public class SectorMap : MonoBehaviour
}
Settings.NoisePosition = Random.value * 100;
var sector = SectorGenerator.GenerateSector(Settings, sectorMegas, ref random);
var sector = new Sector(Settings, sectorMegas, ref random);
var visitedZones = new HashSet<SectorZone>();
Debug.Log($"Found {sector.Zones.Count(z=>!z.AdjacentZones.Any())} orphaned zones!");
@ -135,27 +135,55 @@ public class SectorMap : MonoBehaviour
var homeMega = sector.HomeZones.Keys.FirstOrDefault(m => sector.HomeZones[m] == zone);
if (homeMega != null)
{
var backgroundInstance = IconBackgroundPrototype.Instantiate<MeshRenderer>();
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
backgroundInstance.material.SetColor("_TintColor", homeMega.SecondaryColor.ToColor());
iconInstance.material.mainTexture = HomeIcon;
iconInstance.material.SetColor("_TintColor", homeMega.PrimaryColor.ToColor());
var backgroundTransform = backgroundInstance.transform;
var iconTransform = iconInstance.transform;
backgroundTransform.SetParent(zoneInstanceTransform);
iconTransform.SetParent(zoneInstanceTransform);
backgroundTransform.localScale = Vector3.one * IconBackgroundSize;
iconTransform.localScale = Vector3.one;
backgroundTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance, .5f);
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
}
var bossMega = sector.BossZones.Keys.FirstOrDefault(m => sector.BossZones[m] == zone);
if (bossMega != null)
{
var backgroundInstance = IconBackgroundPrototype.Instantiate<MeshRenderer>();
var iconInstance = IconPrototype.Instantiate<MeshRenderer>();
backgroundInstance.material.SetColor("_TintColor", bossMega.SecondaryColor.ToColor());
iconInstance.material.mainTexture = BossIcon;
iconInstance.material.SetColor("_TintColor", bossMega.PrimaryColor.ToColor());
var backgroundTransform = backgroundInstance.transform;
var iconTransform = iconInstance.transform;
backgroundTransform.SetParent(zoneInstanceTransform);
iconTransform.SetParent(zoneInstanceTransform);
backgroundTransform.localScale = Vector3.one * IconBackgroundSize;
iconTransform.localScale = Vector3.one;
if(homeMega != null)
if (homeMega != null)
{
backgroundTransform.localPosition = new Vector3(linkDirection.x * IconDistance, linkDirection.y * IconDistance, .5f);
iconTransform.localPosition = new Vector3(linkDirection.x * IconDistance, linkDirection.y * IconDistance);
else iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
}
else
{
backgroundTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance, .5f);
iconTransform.localPosition = new Vector3(-linkDirection.x * IconDistance, -linkDirection.y * IconDistance);
}
}
}
@ -167,9 +195,9 @@ public class SectorMap : MonoBehaviour
{
var instance = zoneInstances[zone];
var influence = 0f;
if (zone.Megas.Length > 0)
if (zone.Factions.Length > 0)
{
if (zone.Megas.Contains(mega))
if (zone.Factions.Contains(mega))
{
influence = 10;
if (zone.Owner != mega)

View file

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using static Unity.Mathematics.math;
public class TextButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public Button Button;
public TextMeshProUGUI Label;
public float AnimationDuration;
public float HoverSpacing;
private float _lerp;
private bool _hovering;
// Update is called once per frame
void Update()
{
_lerp = saturate(_lerp + Time.deltaTime / AnimationDuration * (Button.interactable && _hovering ? 1 : -1));
Label.characterSpacing = HoverSpacing * _lerp;
}
public void OnPointerEnter(PointerEventData eventData)
{
_hovering = true;
}
public void OnPointerExit(PointerEventData eventData)
{
_hovering = false;
}
}

View file

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

View file

@ -358,8 +358,8 @@ public class TradeMenu : MonoBehaviour
var hull = GameManager.ItemManager.CreateInstance(data) as EquippableItem;
Entity entity;
if(data.HullType==HullType.Ship)
entity = new Ship(GameManager.ItemManager, GameManager.Zone, hull);
else entity = new OrbitalEntity(GameManager.ItemManager, GameManager.Zone, hull, Guid.Empty);
entity = new Ship(GameManager.ItemManager, GameManager.Zone, hull, GameManager.Settings.DefaultEntitySettings);
else entity = new OrbitalEntity(GameManager.ItemManager, GameManager.Zone, hull, Guid.Empty, GameManager.Settings.DefaultEntitySettings);
entity.SetParent(GameManager.DockedEntity);
GameManager.PlayerEntities.Add(entity);