|
@ -5,9 +5,10 @@ using System.Linq; |
|
|
|
|
|
|
|
|
namespace GWConquest |
|
|
namespace GWConquest |
|
|
{ |
|
|
{ |
|
|
public class TransportUIElement : MonoBehaviour, IUpdatable<object> |
|
|
|
|
|
|
|
|
public class TransportUIElement : DragDropElement, IUpdatable<object> |
|
|
{ |
|
|
{ |
|
|
public Image SpriteImage; |
|
|
public Image SpriteImage; |
|
|
|
|
|
public RectTransform ImageTransform; |
|
|
public Text NameText; |
|
|
public Text NameText; |
|
|
public RectTransform Arrow; |
|
|
public RectTransform Arrow; |
|
|
|
|
|
|
|
@ -31,8 +32,13 @@ namespace GWConquest |
|
|
private List<TransportUIItemIcon> ItemIconList = new List<TransportUIItemIcon>(); |
|
|
private List<TransportUIItemIcon> ItemIconList = new List<TransportUIItemIcon>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum ObjectType |
|
|
|
|
|
{ |
|
|
|
|
|
District, Formation, Planet |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[System.NonSerialized] |
|
|
[System.NonSerialized] |
|
|
public bool IsDistrict; |
|
|
|
|
|
|
|
|
public ObjectType Type; |
|
|
|
|
|
|
|
|
[System.NonSerialized] |
|
|
[System.NonSerialized] |
|
|
public District District; |
|
|
public District District; |
|
@ -40,6 +46,9 @@ namespace GWConquest |
|
|
[System.NonSerialized] |
|
|
[System.NonSerialized] |
|
|
public Formation Formation; |
|
|
public Formation Formation; |
|
|
|
|
|
|
|
|
|
|
|
[System.NonSerialized] |
|
|
|
|
|
public Planet Planet; |
|
|
|
|
|
|
|
|
[System.NonSerialized] |
|
|
[System.NonSerialized] |
|
|
public bool IsExpanded = true; |
|
|
public bool IsExpanded = true; |
|
|
|
|
|
|
|
@ -56,7 +65,11 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
private IEnumerable<ItemStack> GetAllItems() |
|
|
private IEnumerable<ItemStack> GetAllItems() |
|
|
{ |
|
|
{ |
|
|
if(IsDistrict) |
|
|
|
|
|
|
|
|
if(Type == ObjectType.Planet) |
|
|
|
|
|
{ |
|
|
|
|
|
return Enumerable.Empty<ItemStack>(); |
|
|
|
|
|
} |
|
|
|
|
|
else if(Type == ObjectType.District) |
|
|
{ |
|
|
{ |
|
|
return District.Inventory; |
|
|
return District.Inventory; |
|
|
} |
|
|
} |
|
@ -67,9 +80,13 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
private IEnumerable<Formation> GetSubFormations() |
|
|
private IEnumerable<Formation> GetSubFormations() |
|
|
{ |
|
|
{ |
|
|
if(IsDistrict) |
|
|
|
|
|
|
|
|
if(Type == ObjectType.Planet) |
|
|
{ |
|
|
{ |
|
|
return District.Zone.Formations; |
|
|
|
|
|
|
|
|
return Planet.InTransitFormations; |
|
|
|
|
|
} |
|
|
|
|
|
else if(Type == ObjectType.District) |
|
|
|
|
|
{ |
|
|
|
|
|
return District.Zone.Formations.Where(f => !f.IsEmbarked); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return Formation.SubFormations; |
|
|
return Formation.SubFormations; |
|
@ -118,14 +135,14 @@ namespace GWConquest |
|
|
elementRT.localScale = Vector3.one; |
|
|
elementRT.localScale = Vector3.one; |
|
|
|
|
|
|
|
|
var elementComp = subElGO.GetComponent<TransportUIElement>(); |
|
|
var elementComp = subElGO.GetComponent<TransportUIElement>(); |
|
|
elementComp.IsDistrict = false; |
|
|
|
|
|
|
|
|
elementComp.Type = ObjectType.Formation; |
|
|
elementComp.Formation = d as Formation; |
|
|
elementComp.Formation = d as Formation; |
|
|
elementComp.Rebuild(); |
|
|
elementComp.Rebuild(); |
|
|
|
|
|
|
|
|
return elementComp; |
|
|
return elementComp; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if(!IsDistrict) |
|
|
|
|
|
|
|
|
if(Type == ObjectType.Formation) |
|
|
{ |
|
|
{ |
|
|
var AllUnits = Formation.Units.Where(u => u != Formation.HeroUnit); |
|
|
var AllUnits = Formation.Units.Where(u => u != Formation.HeroUnit); |
|
|
GWLayout.UpdateGameObjects(UnitIconList, AllUnits.ToList(), unit => { |
|
|
GWLayout.UpdateGameObjects(UnitIconList, AllUnits.ToList(), unit => { |
|
@ -159,8 +176,11 @@ namespace GWConquest |
|
|
UnitIconsTransform.SetAsLastSibling(); |
|
|
UnitIconsTransform.SetAsLastSibling(); |
|
|
ItemIconsTransform.SetAsLastSibling(); |
|
|
ItemIconsTransform.SetAsLastSibling(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(IsDistrict) |
|
|
|
|
|
|
|
|
if(Type == ObjectType.Planet) |
|
|
|
|
|
{ |
|
|
|
|
|
NameText.text = "In Transit"; |
|
|
|
|
|
} |
|
|
|
|
|
else if(Type == ObjectType.District) |
|
|
{ |
|
|
{ |
|
|
SpriteImage.sprite = District.GetCurrentSprite(); |
|
|
SpriteImage.sprite = District.GetCurrentSprite(); |
|
|
NameText.text = District.GetDistrictName(); |
|
|
NameText.text = District.GetDistrictName(); |
|
@ -176,7 +196,11 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
public object GetObject() |
|
|
public object GetObject() |
|
|
{ |
|
|
{ |
|
|
if(IsDistrict) |
|
|
|
|
|
|
|
|
if(Type == ObjectType.Planet) |
|
|
|
|
|
{ |
|
|
|
|
|
return Planet; |
|
|
|
|
|
} |
|
|
|
|
|
else if(Type == ObjectType.District) |
|
|
{ |
|
|
{ |
|
|
return District; |
|
|
return District; |
|
|
} |
|
|
} |
|
@ -185,6 +209,68 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override RectTransform rectTransform => ImageTransform; |
|
|
|
|
|
|
|
|
|
|
|
public override void OnDragBegin() |
|
|
|
|
|
{ |
|
|
|
|
|
ChildrenTransform.gameObject.SetActive(false); |
|
|
|
|
|
Arrow.gameObject.SetActive(false); |
|
|
|
|
|
NameText.gameObject.SetActive(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override bool OnDragFinished() |
|
|
|
|
|
{ |
|
|
|
|
|
var mousePos = Input.mousePosition; |
|
|
|
|
|
foreach(var ui in FindObjectsOfType<TransportUIElement>()) |
|
|
|
|
|
{ |
|
|
|
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(ui.GetComponent<RectTransform>(), mousePos)) |
|
|
|
|
|
{ |
|
|
|
|
|
if(Formation.ZoneType == ZoneType.Ground) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!Formation.IsEmbarked && ui.Type == ObjectType.District && ui.District.Zone.zoneType == ZoneType.Ground) |
|
|
|
|
|
{ |
|
|
|
|
|
// Transition Boden -> Boden
|
|
|
|
|
|
var goalZone = ui.District.Zone; |
|
|
|
|
|
var pathfinding = Formation.currentZone.planet.pathfindingGraph; |
|
|
|
|
|
var shortestPath = pathfinding.FindShortestPath(Formation, Formation.currentZone, goalZone); |
|
|
|
|
|
if (shortestPath != null) |
|
|
|
|
|
{ |
|
|
|
|
|
Formation.StartMovingOnPath(shortestPath.zones); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if (ui.Type == ObjectType.Formation && ui.Formation.ZoneType == ZoneType.Space) |
|
|
|
|
|
{ |
|
|
|
|
|
if(ui.Formation.CanCarry(Formation)) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!Formation.IsEmbarked) |
|
|
|
|
|
{ |
|
|
|
|
|
// Transition Boden -> Weltall
|
|
|
|
|
|
var goalZone = ui.Formation.currentZone; |
|
|
|
|
|
var path = new List<Zone>() {Formation.currentZone, goalZone}; |
|
|
|
|
|
Formation.StartMovingOnPath(path, ui.Formation); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// Transition Weltall -> Weltall (Flottenwechsel)
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ChildrenTransform.gameObject.SetActive(true); |
|
|
|
|
|
Arrow.gameObject.SetActive(true); |
|
|
|
|
|
NameText.gameObject.SetActive(true); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override bool CanDrag() |
|
|
|
|
|
{ |
|
|
|
|
|
return Type == ObjectType.Formation && Formation.CanMove; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|