public void ActivateAdvance(MapCity mapCity) { Debug.Log("Show City info"); // verify if there is a hero in the city if (mapCity.LMapHero != null) { // Get Lefto Hero Party UI HeroPartyUI leftHeroPartyUI = transform.root.Find("MiscUI/LeftHeroParty").GetComponent <HeroPartyUI>(); // assign HeroParty to left hero party UI leftHeroPartyUI.LHeroParty = mapCity.LCity.GetHeroPartyByMode(PartyMode.Party); // activate left hero party UI leftHeroPartyUI.gameObject.SetActive(true); // deactivate inventory leftHeroPartyUI.GetComponentInChildren <PartyInventoryUI>(true).gameObject.SetActive(false); //// Activate placeholder to be used as background //transform.Find("LeftPartyInfoPlaceHolder").gameObject.SetActive(true); } else { // No hero in city // Display black box transform.Find("LeftPartyInfoPlaceHolder").gameObject.SetActive(true); } // Get Right Hero Party UI HeroPartyUI rightHeroPartyUI = transform.root.Find("MiscUI/RightHeroParty").GetComponent <HeroPartyUI>(); // assign City garnizon HeroParty to right hero party UI rightHeroPartyUI.LHeroParty = mapCity.LCity.GetHeroPartyByMode(PartyMode.Garnizon); // activate right hero party UI rightHeroPartyUI.gameObject.SetActive(true); // deactivate inventory rightHeroPartyUI.GetComponentInChildren <PartyInventoryUI>(true).gameObject.SetActive(false); //// Activate placeholder to be used as background //transform.Find("RightPartyInfoPlaceHolder").gameObject.SetActive(true); }
void HirePartyLeader(PartyUnit hiredUnitTemplate, bool doCreateUI = true, City city = null) { // create new party HeroPartyUI newHeroPartyUI = CreateNewPartyInCity(city); // Get unit's slot transform Transform newUnitParentSlot = newHeroPartyUI.GetComponentInChildren <PartyPanel>(true).GetUnitSlotTr(PartyPanel.Row.Middle, GetHiredLeaderDestinationSlotName(hiredUnitTemplate)); // Hire unit, but do not create canvas, because it will be done automatically by HeroParty on enable PartyUnit newPartyLeader = HireGenericUnit(hiredUnitTemplate, newHeroPartyUI.LHeroParty, newUnitParentSlot, false); // Rename hero party, when we know the leader newHeroPartyUI.LHeroParty.gameObject.name = newPartyLeader.GivenName + " " + newPartyLeader.UnitName + " Party"; // Create hero's representation on the map // prerequisites: party leader should be created beforehand SetHeroPartyRepresentationOnTheMap(newHeroPartyUI.LHeroParty, city); if (doCreateUI) { // Activate HeroPartyUI newHeroPartyUI.gameObject.SetActive(true); // trigger onDisable focus panel function so it reset its state transform.root.Find("MiscUI/LeftFocus").GetComponent <FocusPanel>().OnDisable(); // link party leader to the Left Focus panel so it can use it to fill in information transform.root.Find("MiscUI/LeftFocus").GetComponent <FocusPanel>().focusedObject = newHeroPartyUI.GetPartyLeaderUI().gameObject; // trigger onEnable focus panel so it get linked unit data and update its information transform.root.Find("MiscUI/LeftFocus").GetComponent <FocusPanel>().OnEnable(); // Disable Hire leader panel transform.parent.Find("HireHeroPanel").gameObject.SetActive(false); } }
HeroPartyUI CreateNewPartyInCity(City city = null) { // create and update Hero Party panel in UI, parent it to city UI // verify if city argument is null if (city == null) { // Set target city to the linked city to this screen city = LCity; } // create new party instance in city HeroParty newHeroParty = Instantiate(ObjectsManager.Instance.HeroPartyTemplate, city.transform).GetComponent <HeroParty>(); // Set party mode newHeroParty.PartyMode = PartyMode.Party; // Set faction newHeroParty.Faction = city.CityCurrentFaction; // Activate new party newHeroParty.gameObject.SetActive(true); // Get LeftHeroParty UI HeroPartyUI leftHeroPartyUI = transform.parent.Find("LeftHeroParty").GetComponent <HeroPartyUI>(); // Set link to HeroParty leftHeroPartyUI.LHeroParty = newHeroParty; // return new party UI as result return(leftHeroPartyUI); }
public HeroParty GetHeroPartyByMode(PartyMode partyMode, bool includeInactive = false) { HeroPartyUI heroPartyUI = GetHeroPartyUIByMode(partyMode, includeInactive); if (heroPartyUI != null) { return(heroPartyUI.LHeroParty); } else { return(null); } }
void InitFocusPanel(string focusPanelName, HeroPartyUI heroPartyUI) { // get party mode if (heroPartyUI.LHeroParty.PartyMode == PartyMode.Party) { // Party mode // assign party leader to the focus panel transform.root.Find("MiscUI/" + focusPanelName).GetComponent <FocusPanel>().focusedObject = heroPartyUI.GetPartyLeaderUI().gameObject; } else { // Garnizon mode // assign city to the focus panel transform.root.Find("MiscUI/" + focusPanelName).GetComponent <FocusPanel>().focusedObject = heroPartyUI.LHeroParty.GetComponentInParent <City>().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()); } } }
void EnterBattleCommon(HeroParty playerHeroParty, HeroParty enemyHeroParty) { // activate this battle sreen gameObject.SetActive(true); // get Left Hero Party UI HeroPartyUI playerHeroPartyUI = transform.root.Find("MiscUI/LeftHeroParty").GetComponent <HeroPartyUI>(); // link Player to the Left UI playerHeroPartyUI.LHeroParty = playerHeroParty; // get Right Hero Party UI HeroPartyUI enemyHeroPartyUI = transform.root.Find("MiscUI/RightHeroParty").GetComponent <HeroPartyUI>(); // link Enemy to the Right UI enemyHeroPartyUI.LHeroParty = enemyHeroParty; // Record original poisitions playerHeroParty.PreBattleParentTr = playerHeroParty.transform.parent; enemyHeroParty.PreBattleParentTr = enemyHeroParty.transform.parent; // set if party can escape based on its original position playerHeroParty.CanEscapeFromBattle = CanEscape(playerHeroParty.PreBattleParentTr); enemyHeroParty.CanEscapeFromBattle = CanEscape(enemyHeroParty.PreBattleParentTr); // Activate Hero parties UIs upfront so that PartyLeaders UIs are created playerHeroPartyUI.gameObject.SetActive(true); enemyHeroPartyUI.gameObject.SetActive(true); // init left focus panel InitFocusPanel("LeftFocus", playerHeroPartyUI); // init right focus panel InitFocusPanel("RightFocus", enemyHeroPartyUI); //// assign party leader to the left focus panel //transform.root.Find("MiscUI/LeftFocus").GetComponent<FocusPanel>().focusedObject = playerHeroPartyUI.GetPartyLeaderUI().gameObject; //// assign party leader to the right focus panel //transform.root.Find("MiscUI/RightFocus").GetComponent<FocusPanel>().focusedObject = enemyHeroPartyUI.GetPartyLeaderUI().gameObject; // trigger battle screen enable event battleScreenEnable.Raise(); // Activate all needed UI at once SetCommonBattleUIActive(true); // Get parties panels playerPartyPanel = playerHeroPartyUI.GetComponentInChildren <PartyPanel>(); enemyPartyPanel = enemyHeroPartyUI.GetComponentInChildren <PartyPanel>(); // Set if parties panels are AI or player controllable // .. do it automatically in future, based on ... playerPartyPanel.IsAIControlled = false; enemyPartyPanel.IsAIControlled = false; // start turn based battle StartBattle(); }
void ActivateHeroPartiesView() { // check check if we have one party if (LHeroParties.Length <= 1) { // We have at least one party // Activate left view with this party // Get hero party HeroParty heroParty = LHeroParties[0]; // we have only one party // Get HeroParty UI HeroPartyUI heroPartyUI = transform.root.Find("MiscUI/LeftHeroParty").GetComponent <HeroPartyUI>(); // assign HeroParty to the left hero party UI heroPartyUI.LHeroParty = heroParty; // activate left hero party UI heroPartyUI.gameObject.SetActive(true); // assign party leader UI to the left focus panel transform.root.Find("MiscUI/LeftFocus").GetComponent <FocusPanel>().focusedObject = heroPartyUI.GetPartyLeaderUI().gameObject; // activate left Focus panel transform.root.Find("MiscUI/LeftFocus").gameObject.SetActive(true); } // Check if we have 2 parties if (LHeroParties.Length == 2) { // we have 2 parties // Activate right view with this party // Get hero party HeroParty heroParty = LHeroParties[1]; // Get HeroParty UI HeroPartyUI heroPartyUI = transform.root.Find("MiscUI/RightHeroParty").GetComponent <HeroPartyUI>(); // assign HeroParty to the right hero party UI heroPartyUI.LHeroParty = heroParty; // activate right hero party UI heroPartyUI.gameObject.SetActive(true); // assign party leader UI to the right focus panel transform.root.Find("MiscUI/RightFocus").GetComponent <FocusPanel>().focusedObject = heroPartyUI.GetPartyLeaderUI().gameObject; // activate right Focus panel transform.root.Find("MiscUI/RightFocus").gameObject.SetActive(true); } }
public void SetHireUnitPnlButtonActive(bool activate) { // get garnizon UI HeroPartyUI garnizonUI = GetComponentInParent <UIManager>().GetHeroPartyUIByMode(PartyMode.Garnizon); // this is only needed in garnizon mode, only in this mode hire buttons are present // verify if garnizon is present if (garnizonUI) { // Debug.Log("Activate or Deactivate Hire Unit Buttons in City Garnizon"); foreach (UnitSlot unitSlot in garnizonUI.GetComponentsInChildren <UnitSlot>(true)) { // verify if we are not checking wide cell, because there is no + button in wide cells if (unitSlot.GetComponent <UnitSlotDropHandler>().CellSize != UnitSize.Double) { // verify if we need to activate if (activate // Verify if city capacity is enough && (LCity.GetUnitsCapacity() > garnizonUI.LHeroParty.GetLeadershipConsumedByPartyUnits()) // verify if drop slot doesn't have an !active! unit in it && (!unitSlot.GetComponentInChildren <PartyUnitUI>(false)) // verify if wide cell is not active = occupied in the same row && (!unitSlot.transform.parent.parent.Find(PartyPanel.Cell.Wide.ToString()).gameObject.activeSelf) ) { //Debug.Log("Activate + button in " + horisontalPanel + "/" + cell + " cell"); SetHireUnitButtonActiveByCell(true, unitSlot.GetUnitPPRow(), unitSlot.GetUnitPPCell()); // And bring panel to the front BringHireUnitPnlButtonToTheFront(); } else { //Debug.Log("Deactivate + button in " + horisontalPanel + "/" + cell + " cell"); SetHireUnitButtonActiveByCell(false, unitSlot.GetUnitPPRow(), unitSlot.GetUnitPPCell()); } } } } }
public void ActivateAdvance(MapHero mapHero) { Debug.Log("Show Party Info"); //// clone hero panel and place it into the middle placeholder //SetPartyPanelPosition(mapHero.LHeroParty.Find("PartyPanel"), transform.Find("SinglePartyPlaceholder")); // Get Lefto Hero Party UI HeroPartyUI leftHeroPartyUI = transform.root.Find("MiscUI/LeftHeroParty").GetComponent <HeroPartyUI>(); // assign HeroParty to left hero party UI leftHeroPartyUI.LHeroParty = mapHero.LHeroParty; // Get Party Panel PartyPanel partyPanel = leftHeroPartyUI.GetComponentInChildren <PartyPanel>(true); // Get new position RectTransform newPosition = transform.Find("SinglePartyPlaceholder").GetComponent <RectTransform>(); // Change Party Panel position to new SetPartyPanelPosition(partyPanel, newPosition); // activate left hero party UI leftHeroPartyUI.gameObject.SetActive(true); // deactivate inventory leftHeroPartyUI.GetComponentInChildren <PartyInventoryUI>(true).gameObject.SetActive(false); //// Activate placeholder to be used as background //transform.Find("SinglePartyPlaceholder").gameObject.SetActive(true); }
void ActivateCityView() { // get hero party in city, if it is present HeroParty heroParty = LCity.GetHeroPartyByMode(PartyMode.Party); HeroPartyUI heroPartyUI = null; // verify if there is party in a city if (heroParty != null) { // Get HeroParty UI heroPartyUI = transform.root.Find("MiscUI/LeftHeroParty").GetComponent <HeroPartyUI>(); // assign HeroParty to left hero party UI heroPartyUI.GetComponent <HeroPartyUI>().LHeroParty = heroParty; // activate left hero party UI heroPartyUI.gameObject.SetActive(true); // assign party leader to left focus panel if (transform.root.Find("MiscUI/LeftFocus") == null) { Debug.LogWarning("1"); } if (transform.root.Find("MiscUI/LeftFocus").GetComponent <FocusPanel>() == null) { Debug.LogWarning("2"); } if (transform.root.Find("MiscUI/LeftFocus").GetComponent <FocusPanel>().focusedObject == null) { Debug.LogWarning("3"); } if (heroPartyUI == null) { Debug.LogWarning("4"); } if (heroPartyUI.GetPartyLeaderUI() == null) { Debug.LogWarning("5"); } if (heroPartyUI.GetPartyLeaderUI().gameObject == null) { Debug.LogWarning("6"); } transform.root.Find("MiscUI/LeftFocus").GetComponent <FocusPanel>().focusedObject = heroPartyUI.GetPartyLeaderUI().gameObject; // activate left Focus panel transform.root.Find("MiscUI/LeftFocus").gameObject.SetActive(true); } else { // activate left Focus panel // without linked hero it will trigger no-party info transform.root.Find("MiscUI/LeftFocus").gameObject.SetActive(true); // activate hire hero panel transform.root.Find("MiscUI/HireHeroPanel").gameObject.SetActive(true); } // Get HeroParty UI heroPartyUI = transform.root.Find("MiscUI/RightHeroParty").GetComponent <HeroPartyUI>(); // assign City garnizon HeroParty to right hero party UI heroPartyUI.LHeroParty = LCity.GetHeroPartyByMode(PartyMode.Garnizon); // activate right hero party UI heroPartyUI.gameObject.SetActive(true); // activate hire common units panel transform.root.Find("MiscUI/HireCommonUnitButtons").gameObject.SetActive(true); // assign city to right focus panel transform.root.Find("MiscUI/RightFocus").GetComponent <FocusPanel>().focusedObject = LCity.gameObject; // activate right Focus panel transform.root.Find("MiscUI/RightFocus").gameObject.SetActive(true); }