Corporation Creation Screen
Added UI for creating a corporation; selecting a parent and choosing a name
This commit is contained in:
parent
17673cd264
commit
98371fc453
42 changed files with 4501 additions and 401 deletions
|
|
@ -109,6 +109,9 @@ public class MegaCorporation : DatabaseEntry, INamedEntry
|
|||
|
||||
[InspectableDatabaseLink(typeof(BlueprintData)), JsonProperty("initialTechs"), Key(6)]
|
||||
public List<Guid> InitialTechnologies = new List<Guid>();
|
||||
|
||||
[JsonProperty("parent"), Key(7)]
|
||||
public Guid HomeZone;
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
|
|
|
|||
|
|
@ -227,6 +227,12 @@ public class PersonalityAttribute : DatabaseEntry, INamedEntry
|
|||
[InspectableField, JsonProperty("name"), Key(1)]
|
||||
public string Name;
|
||||
|
||||
[InspectableField, JsonProperty("low"), Key(2)]
|
||||
public string LowName;
|
||||
|
||||
[InspectableField, JsonProperty("high"), Key(3)]
|
||||
public string HighName;
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
get => Name;
|
||||
|
|
|
|||
|
|
@ -18,16 +18,19 @@ public class ZoneData : DatabaseEntry, INamedEntry
|
|||
[JsonProperty("radius"), Key(3)]
|
||||
public float Radius = 2000;
|
||||
|
||||
[JsonProperty("visited"), Key(4)]
|
||||
[JsonProperty("mass"), Key(4)]
|
||||
public float Mass = 10000;
|
||||
|
||||
[JsonProperty("visited"), Key(5)]
|
||||
public bool Visited;
|
||||
|
||||
[JsonProperty("wormholes"), Key(5)]
|
||||
[JsonProperty("wormholes"), Key(6)]
|
||||
public List<Guid> Wormholes = new List<Guid>();
|
||||
|
||||
[JsonProperty("planets"), Key(6)]
|
||||
[JsonProperty("planets"), Key(7)]
|
||||
public Guid[] Planets;// = new List<Guid>();
|
||||
|
||||
[JsonProperty("orbits"), Key(7)]
|
||||
[JsonProperty("orbits"), Key(8)]
|
||||
public List<Guid> Orbits = new List<Guid>();
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ public class ZoneGenerator
|
|||
mapLayers
|
||||
.First(m => m.Name == "Mass")
|
||||
.Evaluate(zone.Position, context.GlobalData)));
|
||||
zone.Mass = zoneMass;
|
||||
|
||||
//Debug.Log($"Generating zone at position {zone.Position} with radius {zoneRadius} and mass {zoneMass}");
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using TMPro;
|
|||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
using Random = UnityEngine.Random;
|
||||
|
|
@ -27,6 +28,11 @@ public class StrategyGameManager : MonoBehaviour
|
|||
public ClickRaycaster ClickRaycaster;
|
||||
public ReadOnlyPropertiesPanel PropertiesPanel;
|
||||
public ContextMenu ContextMenu;
|
||||
public RectTransform GameMenuRoot;
|
||||
public RectTransform CorpMenuRoot;
|
||||
public CorporationMenuItem CorpOptionPrefab;
|
||||
public TabButton CorpMenuContinueButton;
|
||||
public TMP_InputField CorpNameInputField;
|
||||
|
||||
[Section("Tab Links")]
|
||||
public TabGroup PrimaryTabGroup;
|
||||
|
|
@ -78,6 +84,10 @@ public class StrategyGameManager : MonoBehaviour
|
|||
private Material _backgroundMaterial;
|
||||
private bool _techLayoutGenerated;
|
||||
private Connection _connection;
|
||||
// private bool _choosingCorporation;
|
||||
private Guid _playerCorporation;
|
||||
private Dictionary<CorporationMenuItem, Guid> _corpOptionMap = new Dictionary<CorporationMenuItem, Guid>();
|
||||
private CorporationMenuItem _selectedParent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
|
@ -99,6 +109,81 @@ public class StrategyGameManager : MonoBehaviour
|
|||
Position = z.Position,
|
||||
ZoneID = z.ID
|
||||
});
|
||||
|
||||
var megas = _cache.GetAll<MegaCorporation>();
|
||||
if (megas.First().HomeZone == Guid.Empty)
|
||||
{
|
||||
foreach (var corpzone in megas
|
||||
.Zip(_cache.GetAll<ZoneData>().OrderByDescending(z => z.Mass),
|
||||
(corporation, zone) => new {corporation, zone}))
|
||||
corpzone.corporation.HomeZone = corpzone.zone.ID;
|
||||
}
|
||||
|
||||
var player = _cache.GetAll<Player>().FirstOrDefault();
|
||||
if (player == null)
|
||||
{
|
||||
player = new Player
|
||||
{
|
||||
Context = _context,
|
||||
ID = Guid.NewGuid(),
|
||||
Username = Environment.UserName
|
||||
};
|
||||
_cache.Add(player);
|
||||
}
|
||||
|
||||
if (player.Corporation == Guid.Empty)
|
||||
{
|
||||
GameMenuRoot.gameObject.SetActive(false);
|
||||
CorpMenuRoot.gameObject.SetActive(true);
|
||||
|
||||
foreach (var mega in megas)
|
||||
{
|
||||
var corpOption = Instantiate(CorpOptionPrefab, CorpMenuRoot);
|
||||
_corpOptionMap[corpOption] = mega.ID;
|
||||
corpOption.Title.text = mega.Name;
|
||||
corpOption.Logo.sprite = Resources.Load<Sprite>(mega.Logo.Substring("Assets/Resources/".Length).Split('.').First());
|
||||
corpOption.Description.text = mega.Description;
|
||||
var corpOptionImage = corpOption.GetComponent<Image>();
|
||||
corpOptionImage.color = UnselectedColor;
|
||||
corpOption.GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
if (_selectedParent != null)
|
||||
{
|
||||
_selectedParent.GetComponent<Image>().color = UnselectedColor;
|
||||
}
|
||||
_selectedParent = corpOption;
|
||||
corpOptionImage.color = SelectedColor;
|
||||
});
|
||||
foreach (var attributeValue in mega.Personality.Select(kvp =>
|
||||
new {attribute = _cache.Get<PersonalityAttribute>(kvp.Key), val = kvp.Value}))
|
||||
{
|
||||
var attributeInstance = Instantiate(corpOption.AttributePrefab, corpOption.transform);
|
||||
attributeInstance.Slider.value = attributeValue.val;
|
||||
attributeInstance.Title.text = attributeValue.attribute.Name;
|
||||
attributeInstance.HighLabel.text = attributeValue.attribute.HighName;
|
||||
attributeInstance.LowLabel.text = attributeValue.attribute.LowName;
|
||||
}
|
||||
}
|
||||
|
||||
CorpMenuContinueButton.OnClick += _ =>
|
||||
{
|
||||
if (_selectedParent != null && !string.IsNullOrEmpty(CorpNameInputField.text))
|
||||
{
|
||||
var newCorp = new Corporation
|
||||
{
|
||||
Context = _context,
|
||||
ID = Guid.NewGuid(),
|
||||
Name = CorpNameInputField.text,
|
||||
Parent = _corpOptionMap[_selectedParent]
|
||||
};
|
||||
_cache.Add(newCorp);
|
||||
player.Corporation = newCorp.ID;
|
||||
|
||||
GameMenuRoot.gameObject.SetActive(true);
|
||||
CorpMenuRoot.gameObject.SetActive(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
13
Assets/Scripts/UI/AttributeProperty.cs
Normal file
13
Assets/Scripts/UI/AttributeProperty.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AttributeProperty : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Title;
|
||||
public TextMeshProUGUI LowLabel;
|
||||
public TextMeshProUGUI HighLabel;
|
||||
public Slider Slider;
|
||||
}
|
||||
11
Assets/Scripts/UI/AttributeProperty.cs.meta
Normal file
11
Assets/Scripts/UI/AttributeProperty.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a56d344686c0914684133c5b3a0ed81
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Scripts/UI/CorporationMenuItem.cs
Normal file
13
Assets/Scripts/UI/CorporationMenuItem.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CorporationMenuItem : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Title;
|
||||
public TextMeshProUGUI Description;
|
||||
public Image Logo;
|
||||
public AttributeProperty AttributePrefab;
|
||||
}
|
||||
11
Assets/Scripts/UI/CorporationMenuItem.cs.meta
Normal file
11
Assets/Scripts/UI/CorporationMenuItem.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2373df76ba827eb4591c6c83e10fa3bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue