/// <summary>
    /// called by the "create new troop..." option from the demanding troop tier entry.
    /// should open the edit troop type panel for a new TT and then assign that new TT to the demandingEntry
    /// </summary>
    /// <param name="theDemandingEntry"></param>
    public void CreateNewTroopTypeForEntry(FactionTroopListEntry theDemandingEntry)
    {
        TroopType newTT = new TroopType(GameController.instance.LastRelevantTType);

        theDemandingEntry.SetContent(newTT);
        theDemandingEntry.RefreshInfoLabels();
        EditTierEntry(theDemandingEntry);
        GameInterface.instance.editFactionPanel.isDirty = true;
    }
 public void SelectTierEntry(FactionTroopListEntry theEntry)
 {
     if (selectedEntry)
     {
         selectedEntry.selectEntryBtn.image.color = unselectedEntryColor;
     }
     selectedEntry = theEntry;
     selectedEntry.selectEntryBtn.image.color = selectedEntryColor;
     SetEntryButtonsInteractable(true);
     delEntryBtn.interactable = CheckIfCanDeleteMoreEntries();
 }
 /// <summary>
 /// refreshes troop option names.
 /// should be called when rebuilding the tree or after a troop type has been edited
 /// </summary>
 public void UpdateTreeTroopOptions()
 {
     for (int i = 0; i < listContainer.childCount - 1; i++)
     {
         Transform             entry       = listContainer.GetChild(i);
         FactionTroopListEntry entryScript = entry.GetComponent <FactionTroopListEntry>();
         if (entryScript)
         {
             entryScript.RefreshInfoLabels();
         }
     }
 }
    public override void ClearList()
    {
        for (int i = 0; i < listContainer.childCount - 1; i++)
        {
            Transform             entry       = listContainer.GetChild(i);
            FactionTroopListEntry entryScript = entry.GetComponent <FactionTroopListEntry>();
            if (entryScript)
            {
                Destroy(entry.gameObject);
            }
        }

        SetEntryButtonsInteractable(false);
    }
    /// <summary>
    /// updates tier numbers for all entries
    /// </summary>
    public void UpdateTreeTierValues()
    {
        int curTierNumber = 1;

        for (int i = 0; i < listContainer.childCount - 1; i++)
        {
            Transform             entry       = listContainer.GetChild(i);
            FactionTroopListEntry entryScript = entry.GetComponent <FactionTroopListEntry>();
            if (entryScript)
            {
                entryScript.tierTxt.text = curTierNumber.ToString();
                curTierNumber++;
            }
        }
    }
    public override ListPanelEntry <TroopType> AddEntry(TroopType entryData)
    {
        GameObject newEntry = Instantiate(entryPrefab);

        newEntry.transform.SetParent(listContainer, false);
        FactionTroopListEntry entryScript = newEntry.GetComponent <FactionTroopListEntry>();

        entryScript.SetContent(entryData);
        entryScript.ReFillDropdownOptions();
        entryScript.selectEntryBtn.onClick.AddListener(() => SelectTierEntry(entryScript));
        entryScript.parentDirtablePanel   = GameInterface.instance.editFactionPanel;
        entryScript.actionOnEditTroopType = UpdateTreeTroopOptions;

        newEntry.transform.SetSiblingIndex(listContainer.childCount - 2);
        return(entryScript);
    }
    public List <int> BakeIntoTroopTree()
    {
        List <int> returnedTree = new List <int>();

        for (int i = 0; i < listContainer.childCount - 1; i++)
        {
            Transform             entry       = listContainer.GetChild(i);
            FactionTroopListEntry entryScript = entry.GetComponent <FactionTroopListEntry>();
            if (entryScript)
            {
                returnedTree.Add(entryScript.myContent.ID);
            }
        }

        return(returnedTree);
    }
    /// <summary>
    /// adds a new troop tier entry using the same troop type as the previous entry.
    /// if there is no previous entry, use the first troop type in the saved data list
    /// </summary>
    public void AddTroopTier()
    {
        TroopType newTierData = null;

        //if the container has more children than the maxGarrisonDelimiter and the "add tier" button...
        if (listContainer.childCount > 2)
        {
            FactionTroopListEntry entryScript = listContainer.GetChild(listContainer.childCount - 2).
                                                GetComponent <FactionTroopListEntry>();

            if (!entryScript)              //maybe it's the maxGarrLvlDelimiter
            {
                entryScript = listContainer.GetChild(listContainer.childCount - 3).
                              GetComponent <FactionTroopListEntry>();
            }
            if (entryScript)
            {
                newTierData = GameController.GetTroopTypeByName(entryScript.troopTypeDropdown.captionText.text);
            }
        }

        if (newTierData == null)
        {
            if (GameController.GuardGameDataExist())
            {
                newTierData = GameController.instance.LastRelevantTType;
            }
        }
        AddEntry(newTierData);

        addEntryBtn.transform.SetAsLastSibling();

        UpdateTreeTierValues();

        GameInterface.instance.editFactionPanel.isDirty = true;
    }
 /// <summary>
 /// opens the edit troop panel for the target entry's Troop type
 /// </summary>
 /// <param name="targetEntry"></param>
 public void EditTierEntry(FactionTroopListEntry targetEntry)
 {
     targetEntry.OpenEditTroopPanel();
     GameInterface.instance.editTroopPanel.onDoneEditing += UpdateTreeTroopOptions;
 }