diff --git a/Assets/GWConquest/Scripts/UI/DistrictIcon.cs b/Assets/GWConquest/Scripts/UI/DistrictIcon.cs index 23a3140..6e51191 100644 --- a/Assets/GWConquest/Scripts/UI/DistrictIcon.cs +++ b/Assets/GWConquest/Scripts/UI/DistrictIcon.cs @@ -29,21 +29,35 @@ namespace GWConquest public Image CooldownCircle; public Image CooldownIcon; - public District district { get; private set; } + public Zone zone { get; private set; } + public District district {get => zone?.GetComponent();} private bool isSelected = false; - public void SetDistrict(District d) + public void SetDistrict(Zone z) { - district = d; - iconImage.sprite = d.GetCurrentSprite(); - nameText.text = d.GetDistrictName(); + zone = z; + if(district != null) + { + iconImage.sprite = district.GetCurrentSprite(); + iconImage.enabled = true; + nameText.text = district.GetDistrictName(); + } + else { + iconImage.sprite = null; + iconImage.enabled = false; + nameText.text = "Space"; + } } public void OnClicked() { animator.SetTrigger("Pressed"); - isSelected = true; - FindObjectOfType().PlanetView.SelectZone(district.Zone); + if(district != null) + { + isSelected = true; + FindObjectOfType().PlanetView.SelectZone(zone); + } + } public void OnDeselected() @@ -70,7 +84,7 @@ namespace GWConquest public void UpdateIndicator(bool isPlanetContested) { - IEnumerable formations = district.Zone.Formations; + IEnumerable formations = zone.Formations; var playerFormations = formations.Where(f => f.Player == Player.CurrentPlayer).ToList(); float playerStrength = playerFormations.Sum(f => f.GetFormationStrength()); var enemyFormations = formations.Where(f => f.Player != Player.CurrentPlayer).ToList(); @@ -101,9 +115,9 @@ namespace GWConquest EnemyIndicatorMask.enabled = false; } - var controllingPlayer = district.ControllingPlayer; + var controllingPlayer = district?.ControllingPlayer; - if(isPlanetContested && controllingPlayer != null && !district.Zone.HasBattle) + if(isPlanetContested && controllingPlayer != null && !zone.HasBattle) { FactionLogoGO.SetActive(true); FactionLogo.sprite = controllingPlayer.Faction.FactionLogo; @@ -123,8 +137,8 @@ namespace GWConquest } private void Update() { - var factory = district.GetComponent(); - if(factory != null) + var factory = zone.GetComponent(); + if(district != null && factory != null) { var producing = factory.IsProducing; if(animator.GetBool("Producing") != producing) @@ -159,14 +173,14 @@ namespace GWConquest } } - BattleIcon.SetActive(district.Zone.HasBattle); + BattleIcon.SetActive(zone.HasBattle); } public void OpenBattleMenu() { - if(district.Zone.HasBattle) + if(zone.HasBattle) { - GetComponentInParent().ShowBattleUI(district.Zone.CurrentBattle); + GetComponentInParent().ShowBattleUI(zone.CurrentBattle); } } diff --git a/Assets/GWConquest/Scripts/UI/FormationIcon.cs b/Assets/GWConquest/Scripts/UI/FormationIcon.cs index 9793883..73b6cab 100644 --- a/Assets/GWConquest/Scripts/UI/FormationIcon.cs +++ b/Assets/GWConquest/Scripts/UI/FormationIcon.cs @@ -122,8 +122,8 @@ namespace GWConquest { { if (RectTransformUtility.RectangleContainsScreenPoint(di.GetComponent(), mousePos)) { - CurrentFormation.TryMoveToZone(di.district.Zone); - BoltLog.Info("Moving formation {0} to zone {1}", CurrentFormation.name, di.district.Zone); + CurrentFormation.TryMoveToZone(di.zone); + BoltLog.Info("Moving formation {0} to zone {1}", CurrentFormation.name, di.zone); break; } } diff --git a/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs b/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs index 10df27c..8a68cb2 100644 --- a/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs +++ b/Assets/GWConquest/Scripts/UI/PlanetViewUI.cs @@ -66,29 +66,30 @@ namespace GWConquest DestroyAllIcons(); - District[] districts = planet.GetComponentsInChildren(); - - foreach(District district in districts) + foreach(Zone zone in planet.GetComponentsInChildren()) { - GameObject iconGO = Instantiate(DistrictIconPrefab); - iconGO.transform.SetParent(DistrictIcons); - iconGO.transform.Reset(); + if(!zone.attackZone) + { + GameObject iconGO = Instantiate(DistrictIconPrefab); + iconGO.transform.SetParent(DistrictIcons); + iconGO.transform.Reset(); - DistrictIcon iconComp = iconGO.GetComponent(); - iconComp.SetDistrict(district); + DistrictIcon iconComp = iconGO.GetComponent(); + iconComp.SetDistrict(zone); - StickUIToPlanet stick = iconGO.GetComponent(); - if(district.Zone.zoneType == ZoneType.Ground) - { - stick.target = district.transform; - } - else { - stick.enabled = false; - iconGO.transform.position = SpaceStationPositionClosed.position; - } + StickUIToPlanet stick = iconGO.GetComponent(); + if(zone.zoneType == ZoneType.Ground) + { + stick.target = zone.transform; + } + else { + stick.enabled = false; + iconGO.transform.position = SpaceStationPositionClosed.position; + } - DistrictIconList.Add(iconComp); + DistrictIconList.Add(iconComp); + } } DistrictConnection[] districtConnections = planet.GetComponentsInChildren(); @@ -127,12 +128,12 @@ namespace GWConquest if (isLanding) { startTrans = FleetIcons.FleetIcons.FirstOrDefault(i => i.formation == f.MovementOriginFormation).transform; - endTrans = DistrictIconList.FirstOrDefault(i => Zone.GetZoneId(i.district.Zone) == f.State.CurrentTransition.TargetZone).transform; + endTrans = DistrictIconList.FirstOrDefault(i => Zone.GetZoneId(i.zone) == f.State.CurrentTransition.TargetZone).transform; } else { endTrans = FleetIcons.FleetIcons.FirstOrDefault(i => i.formation == f.MovementTargetFormation).transform; - startTrans = DistrictIconList.FirstOrDefault(i => Zone.GetZoneId(i.district.Zone) == f.State.CurrentTransition.OriginZone).transform; + startTrans = DistrictIconList.FirstOrDefault(i => Zone.GetZoneId(i.zone) == f.State.CurrentTransition.OriginZone).transform; } GameObject lineGO = Instantiate(LandingLinePrefab); @@ -293,7 +294,7 @@ namespace GWConquest LogisticsButton.SetActive(false); GroundPanel.SelectDistrict(selectedZone.GetComponent()); - var spaceIcon = DistrictIconList.FirstOrDefault(i => i.district.Zone.zoneType == ZoneType.Space); + var spaceIcon = DistrictIconList.FirstOrDefault(i => i.zone.zoneType == ZoneType.Space); if(spaceIcon != null) { spaceIcon.transform.position = SpaceStationPositionOpen.position; @@ -448,7 +449,7 @@ namespace GWConquest HideTransportUI(); } - var spaceIcon = DistrictIconList.FirstOrDefault(i => i.district.Zone.zoneType == ZoneType.Space); + var spaceIcon = DistrictIconList.FirstOrDefault(i => i.zone.zoneType == ZoneType.Space); if(spaceIcon != null) { spaceIcon.transform.position = SpaceStationPositionClosed.position; diff --git a/Assets/GWConquest/Scripts/UI/StickToFormation.cs b/Assets/GWConquest/Scripts/UI/StickToFormation.cs index a0bdb5d..b122edf 100644 --- a/Assets/GWConquest/Scripts/UI/StickToFormation.cs +++ b/Assets/GWConquest/Scripts/UI/StickToFormation.cs @@ -34,7 +34,7 @@ namespace GWConquest if(originZone.zoneType == ZoneType.Ground) { - origin = districtIcons.FirstOrDefault(d => d.district.Zone==originZone).transform; + origin = districtIcons.FirstOrDefault(d => d.zone==originZone).transform; } else { origin = fleetIcons.FirstOrDefault(f => f.formation == formation.MovementOriginFormation).transform; @@ -42,7 +42,7 @@ namespace GWConquest if(targetZone.zoneType == ZoneType.Ground) { - target = districtIcons.FirstOrDefault(d => d.district.Zone==targetZone).transform; + target = districtIcons.FirstOrDefault(d => d.zone==targetZone).transform; } else { target = fleetIcons.FirstOrDefault(f => f.formation == formation.MovementTargetFormation).transform; diff --git a/Assets/GWConquest/Scripts/UI/TransportUIElement.cs b/Assets/GWConquest/Scripts/UI/TransportUIElement.cs index d1dc358..3477e41 100644 --- a/Assets/GWConquest/Scripts/UI/TransportUIElement.cs +++ b/Assets/GWConquest/Scripts/UI/TransportUIElement.cs @@ -342,7 +342,7 @@ namespace GWConquest { if (RectTransformUtility.RectangleContainsScreenPoint(di.GetComponent(), mousePos)) { - HandleTransition(ObjectType.District, di.district.Zone); + HandleTransition(ObjectType.District, di.zone); break; } }