//public MapItemsContainer CreateInventoryItemContainerOnMap(PositionOnMap positionOnMap) //{ // // create new item on map // MapItemsContainer mapItem = Instantiate(inventoryItemOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent<MapItemsContainer>())).GetComponent<MapItemsContainer>(); // // place item on map to original position on map // mapItem.GetComponent<RectTransform>().offsetMin = new Vector2(positionOnMap.offsetMinX, positionOnMap.offsetMinY); // mapItem.GetComponent<RectTransform>().offsetMax = new Vector2(positionOnMap.offsetMaxX, positionOnMap.offsetMaxY); // // rename it // mapItem.gameObject.name = "TreasureChest"; // // set it as first sibling so it does not apper in front of heroes, cities or labels // // mapItem.transform.SetAsFirstSibling(); // // Create item label on map // MapObjectLabel mapItemLabel = Instantiate(inventoryItemOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent<MapObjectLabel>())).GetComponent<MapObjectLabel>(); // // Link item to the lable and label to the item // mapItem.GetComponent<MapObject>().Label = mapItemLabel; // mapItemLabel.MapObject = mapItem.GetComponent<MapObject>(); // // activate item label on map // mapItemLabel.gameObject.SetActive(true); // // activate it // mapItem.gameObject.SetActive(true); // // return it as result // return mapItem; //} public MapItemsContainer CreateInventoryItemContainerOnMap(MapCoordinates mapCoordinates) { // create new item on map MapItemsContainer mapItem = Instantiate(inventoryItemOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapItemsContainer>())).GetComponent <MapItemsContainer>(); // set position offset Vector3 itemPositionOffset = new Vector3(8f, 8f, 0); // place it to original position on map based on the tile coordinates mapItem.transform.position = MapManager.Instance.GetWorldPositionByCoordinates(mapCoordinates) - itemPositionOffset; // rename it mapItem.gameObject.name = "TreasureChest"; // set it as first sibling so it does not apper in front of heroes, cities or labels // mapItem.transform.SetAsFirstSibling(); // Create item label on map MapObjectLabel mapItemLabel = Instantiate(inventoryItemOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>(); // Link item to the lable and label to the item mapItem.GetComponent <MapObject>().Label = mapItemLabel; mapItemLabel.MapObject = mapItem.GetComponent <MapObject>(); // activate item label on map mapItemLabel.gameObject.SetActive(true); // activate it mapItem.gameObject.SetActive(true); // return it as result return(mapItem); }
MapHero CreatePartyOnMap(HeroParty heroParty, PartyData partyData) { Debug.Log("Creating party on map representation"); // Create new party on map UI MapHero newPartyOnMap = Instantiate(heroPartyOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapHero>())).GetComponent <MapHero>(); // place party to original position on map //newPartyOnMap.GetComponent<RectTransform>().offsetMin = new Vector2(partyData.partyMapPosition.offsetMinX, partyData.partyMapPosition.offsetMinY); //newPartyOnMap.GetComponent<RectTransform>().offsetMax = new Vector2(partyData.partyMapPosition.offsetMaxX, partyData.partyMapPosition.offsetMaxY); // place it to original position on map based on the tile coordinates newPartyOnMap.transform.position = MapManager.Instance.GetWorldPositionByCoordinates(partyData.partyMapCoordinates); // Create hero label on map MapObjectLabel newPartyOnMapLabel = Instantiate(heroPartyOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>(); // Link hero to the lable and label to the hero newPartyOnMap.GetComponent <MapObject>().Label = newPartyOnMapLabel; newPartyOnMapLabel.MapObject = newPartyOnMap.GetComponent <MapObject>(); // create links between party on map and hero party newPartyOnMap.LHeroParty = heroParty; heroParty.LMapHero = newPartyOnMap; // rename it newPartyOnMap.gameObject.name = heroParty.GetPartyLeader().GivenName + " " + heroParty.GetPartyLeader().UnitName + " Party"; // set color according to the player color preference newPartyOnMap.SetColor(GetPlayerByFaction(heroParty.Faction).PlayerColor); // activate hero on map newPartyOnMap.gameObject.SetActive(true); // activate hero label on map newPartyOnMapLabel.gameObject.SetActive(true); // return result return(newPartyOnMap); }
void CreateCityOnMap(City city, CityData cityData) { // Create new party on map MapCity newCityOnMap = Instantiate(cityOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapCity>())).GetComponent <MapCity>(); // city to original position on map //newCityOnMap.GetComponent<RectTransform>().offsetMin = new Vector2(cityData.cityMapPosition.offsetMinX, cityData.cityMapPosition.offsetMinY); //newCityOnMap.GetComponent<RectTransform>().offsetMax = new Vector2(cityData.cityMapPosition.offsetMaxX, cityData.cityMapPosition.offsetMaxY); // place it to original position on map based on the tile coordinates Vector3 cityPositionOffset = new Vector3(8f, 8f, 0); newCityOnMap.transform.position = MapManager.Instance.GetWorldPositionByCoordinates(cityData.cityMapCoordinates) - cityPositionOffset; // create links between city on map and city newCityOnMap.LCity = city; city.LMapCity = newCityOnMap; // rename it newCityOnMap.gameObject.name = city.CityName; // Create city label on map MapObjectLabel newCityOnMapLabel = Instantiate(cityOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>(); // Link city to the lable and label to the city newCityOnMap.GetComponent <MapObject>().Label = newCityOnMapLabel; newCityOnMapLabel.MapObject = newCityOnMap.GetComponent <MapObject>(); // activate city label on map newCityOnMapLabel.gameObject.SetActive(true); // set color according to the player color preference newCityOnMap.SetColor(GetPlayerByFaction(city.CityCurrentFaction).PlayerColor); // activate city on map newCityOnMap.gameObject.SetActive(true); }
void SetHeroPartyRepresentationOnTheMap(HeroParty newLeaderParty, City city = null) { // Create Hero's object on the map // create and update Hero Party panel in UI, (no - parent it to city UI) //Transform parentCityOnMap = map.Find(transform.name); // Create new hero party on map ui MapHero newPartyOnMapUI = Instantiate(ObjectsManager.Instance.HeroPartyOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapHero>())).GetComponent <MapHero>(); // Verify if argument is null if (city == null) { // Assign currently linked city city = LCity; } // adjust position, because city and hero transform have differnet anchor points // Get ui world corners // 12 // 03 Vector3[] worldCorners = new Vector3[4]; newPartyOnMapUI.GetComponent <RectTransform>().GetWorldCorners(worldCorners); // get map hero ui width and heigh float newPartyOnMapUIHeight = Mathf.Abs(worldCorners[3].x - worldCorners[0].x); float newPartyOnMapUIWidth = Mathf.Abs(worldCorners[1].y - worldCorners[0].y); // Debug.Log(newPartyOnMapUIWidth + ":" + newPartyOnMapUIHeight); Vector3 positionAdjustment = new Vector3(newPartyOnMapUIHeight / 2f, newPartyOnMapUIWidth / 2f, 0); // set it to the same position as the parent city newPartyOnMapUI.transform.position = city.LMapCity.transform.position + positionAdjustment; // Create hero label on map MapObjectLabel newPartyOnMapLabel = Instantiate(ObjectsManager.Instance.HeroPartyOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>(); // Link hero to the lable and label to the hero newPartyOnMapUI.GetComponent <MapObject>().Label = newPartyOnMapLabel; newPartyOnMapLabel.MapObject = newPartyOnMapUI.GetComponent <MapObject>(); // activate new party on map UI newPartyOnMapUI.gameObject.SetActive(true); // activate hero label on map newPartyOnMapLabel.gameObject.SetActive(true); // Link HeroParty to the hero party on the map newPartyOnMapUI.LHeroParty = newLeaderParty; // Link hero on the map to HeroParty newLeaderParty.LMapHero = (newPartyOnMapUI); // Link hero on the map to city on the map city.LMapCity.GetComponent <MapCity>().LMapHero = newPartyOnMapUI.GetComponent <MapHero>(); // Link city on the map to hero on the map newPartyOnMapUI.GetComponent <MapHero>().lMapCity = city.LMapCity; // move hero party to the back, so its UI label is not covering city's UI label // but it is in front of map slices // newPartyOnMapUI.transform.SetSiblingIndex(1); // rename it newPartyOnMapUI.gameObject.name = newLeaderParty.GetPartyLeader().GivenName + " " + newLeaderParty.GetPartyLeader().UnitName + " Party"; // set color according to the player color preference newPartyOnMapUI.SetColor(ObjectsManager.Instance.GetPlayerByFaction(newLeaderParty.Faction).PlayerColor); }
public void DestroyParty(PartyPanel partyPanel) { Debug.Log("Destroy party"); // set variables HeroParty heroParty = partyPanel.GetHeroParty(); MapHero heroOnMapRepresentation = heroParty.LMapHero; MapObjectLabel heroOnMapLabel = heroOnMapRepresentation.GetComponent <MapObject>().Label; // destroy label Destroy(heroOnMapLabel.gameObject); // destroy on map party representation Destroy(heroOnMapRepresentation.gameObject); // destroy party Destroy(heroParty.gameObject); }
public void DismissPartyLeader(UnitSlot unitSlot) { // Get hero Party UI // Structure: LeftHeroParty-3PartyPanel-2Top/Middle/Bottom(Row)-1Back/Front/Wide(Cell)-UnitSlot(this) HeroPartyUI heroPartyUI = unitSlot.transform.parent.parent.parent.parent.GetComponent <HeroPartyUI>(); // Get Hero Party HeroParty heroParty = heroPartyUI.LHeroParty; // Get Focus Panel FocusPanel focusPanel = GetComponentInParent <UIManager>().GetFocusPanelByHeroParty(heroParty); // Get Map hero UI MapHero mapHero = heroPartyUI.LHeroParty.LMapHero; // Get map hero label MapObjectLabel mapHeroLabel = mapHero.GetComponent <MapObject>().Label; // Deactivate HeroParty UI heroPartyUI.gameObject.SetActive(false); // verify if focus panel not deactivated already // .. find out why it is deactivated earlier and by whom if (focusPanel != null) { // Deactivate Focus Panel focusPanel.gameObject.SetActive(false); } // destroy label Destroy(mapHeroLabel.gameObject); // Destroy hero's represetnation on map Destroy(mapHero.gameObject); // Destroy hero's party Destroy(heroParty.gameObject); // Verify if we are in city and not in hero edit mode if (GetComponentInParent <UIManager>().GetHeroPartyByMode(PartyMode.Garnizon, false) != null) { // Enable Hire leader panel transform.parent.Find("HireHeroPanel").gameObject.SetActive(true); // Activate focus panel again to display NoPartyInfo focusPanel.gameObject.SetActive(true); } else { // check if there was only one hero in this screen if (LHeroParties.Length == 1) { // return to the map view with animation StartCoroutine(ReturnToTheMapScreenWithAnimation()); } } }