private void OverrideAffinitiesDropListTooltips()
    {
        AgeControlPopup componentInChildren = this.AffinityDropList.GetComponentInChildren <AgeControlPopup>();

        if (componentInChildren != null)
        {
            List <AgeTransform> children = componentInChildren.AgeTransform.GetChildren();
            for (int i = 0; i < children.Count; i++)
            {
                if (i < this.affinityGuiTraits.Count)
                {
                    GuiFactionTrait guiFactionTrait = this.affinityGuiTraits[i];
                    for (int j = 0; j < guiFactionTrait.SubGuiTraits.Count; j++)
                    {
                        GuiFactionTrait guiFactionTrait2 = guiFactionTrait.SubGuiTraits[j];
                        if (guiFactionTrait2.Type == GuiFactionTrait.TraitType.Affinity)
                        {
                            AgeTooltip component = children[i].GetComponent <AgeTooltip>();
                            if (component != null)
                            {
                                StaticString relatedAffinity = StaticString.Empty;
                                if (this.SelectedAffinity != null)
                                {
                                    relatedAffinity = this.SelectedAffinity.Name;
                                }
                                guiFactionTrait2.GenerateTooltip(component, relatedAffinity);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    protected override IEnumerator OnLoad()
    {
        yield return(base.OnLoad());

        this.setupAvailableGuiTraitDelegate  = new AgeTransform.RefreshTableItem <GuiFactionTrait>(this.SetupAvailableGuiTrait);
        this.setupSelectedGuiTraitDelegate   = new AgeTransform.RefreshTableItem <GuiFactionTrait>(this.SetupSelectedGuiTrait);
        this.setupCustomTraitFamilyDelegate  = new AgeTransform.RefreshTableItem <string>(this.SetupCustomTraitFamily);
        this.NameTextField.ValidChars        = AgeLocalizer.Instance.LocalizeString("%FactionValidChars");
        this.DescriptionTextField.ValidChars = AgeLocalizer.Instance.LocalizeString("%FactionValidChars");
        this.affinityGuiTraits.Clear();
        this.affinityMappingGuiTraits.Clear();
        this.standardGuiTraits.Clear();
        IDatabase <FactionTrait> factionTraitDatabase = Databases.GetDatabase <FactionTrait>(true);

        FactionTrait[] factionTraits = factionTraitDatabase.GetValues();
        for (int i = 0; i < factionTraits.Length; i++)
        {
            GuiFactionTrait guiTrait2 = new GuiFactionTrait(factionTraits[i]);
            if (!guiTrait2.FactionTrait.IsHidden)
            {
                if (guiTrait2.IsAffinity)
                {
                    if (guiTrait2.FactionTrait.SubCategory == "MajorFactionAffinity")
                    {
                        this.affinityGuiTraits.Add(guiTrait2);
                    }
                }
                else if (guiTrait2.IsAffinityMapping)
                {
                    if (guiTrait2.FactionTrait.SubCategory == "MajorFactionAffinityMapping")
                    {
                        this.affinityMappingGuiTraits.Add(guiTrait2);
                    }
                }
                else if (!guiTrait2.IsHidden)
                {
                    this.standardGuiTraits.Add(guiTrait2);
                }
            }
        }
        this.InitalizeRootInStandardTraits();
        this.BuildListOfAvailableFamilies();
        this.AffinityDropList.ItemTable = (from guiTrait in this.affinityGuiTraits
                                           select guiTrait.IconAndTitle).ToArray <string>();
        this.OverrideAffinitiesDropListTooltips();
        GameObject prefab = (GameObject)Resources.Load(DiplomaticNegotiationViewport.DefaultPrefabName);

        if (prefab != null)
        {
            GameObject instance = UnityEngine.Object.Instantiate <GameObject>(prefab);
            if (instance != null)
            {
                instance.transform.parent          = base.transform;
                this.diplomaticNegotiationViewport = instance.GetComponent <DiplomaticNegotiationViewport>();
                yield return(this.diplomaticNegotiationViewport.OnLoad(this.ViewportLayer));
            }
        }
        yield break;
    }
Exemplo n.º 3
0
    private void SetupGuiFactionTrait(AgeTransform tableItem, GuiFactionTrait guiFactionTrait, int index)
    {
        AgePrimitiveLabel component = tableItem.GetComponent <AgePrimitiveLabel>();

        if (component != null)
        {
            component.Text = guiFactionTrait.IconAndTitle;
        }
        if (tableItem.AgeTooltip != null)
        {
            guiFactionTrait.GenerateTooltip(tableItem.AgeTooltip, this.SelectedGuiFaction.Faction.Affinity);
        }
    }
 private void BuildListOfAvailableTraits()
 {
     FactionTrait[] factionTraits = (from guiTrait in this.selectedGuiTraits
                                     select guiTrait.FactionTrait).ToArray <FactionTrait>();
     this.availableGuiTraits.Clear();
     for (int i = 0; i < this.standardGuiTraits.Count; i++)
     {
         GuiFactionTrait guiTrait = this.standardGuiTraits[i];
         if (!this.selectedGuiTraits.Contains(guiTrait) && !guiTrait.IsHidden && guiTrait.ShowInCustom && (guiTrait.Family == this.selectedCustomTraitFamily || this.selectedCustomTraitFamily == "All"))
         {
             string empty = string.Empty;
             if (guiTrait.FactionTrait.CheckPrerequisites(this.SelectedAffinity.FactionTrait as FactionAffinity, factionTraits, ref empty))
             {
                 if (!string.IsNullOrEmpty(guiTrait.Root))
                 {
                     GuiFactionTrait guiFactionTrait = this.selectedGuiTraits.FirstOrDefault((GuiFactionTrait match) => match.Root == guiTrait.Root);
                     if (guiFactionTrait != null)
                     {
                         if (guiTrait.Level == guiFactionTrait.Level + 1)
                         {
                             this.availableGuiTraits.Add(guiTrait);
                         }
                     }
                     else if (guiTrait.Level == 1)
                     {
                         this.availableGuiTraits.Add(guiTrait);
                     }
                 }
                 else
                 {
                     this.availableGuiTraits.Add(guiTrait);
                 }
             }
             else
             {
                 string[] array = empty.Split(new char[]
                 {
                     ','
                 });
                 for (int j = 0; j < array.Length; j++)
                 {
                     Diagnostics.Log("Trait {0} discarded because of {1}", new object[]
                     {
                         guiTrait.Title,
                         array[j]
                     });
                 }
             }
         }
     }
 }
    private void SetupSelectedGuiTrait(AgeTransform tableItem, GuiFactionTrait guiFactionTrait, int index)
    {
        MenuCustomTraitLine component = tableItem.GetComponent <MenuCustomTraitLine>();

        if (component == null)
        {
            Diagnostics.LogError("In the MenuJoinGameScreen, trying to refresh a table item that is not a GameSessionLine");
            return;
        }
        if (index % 20 == 0)
        {
            tableItem.StartNewMesh = true;
        }
        component.RefreshContent(guiFactionTrait, this.SelectedAffinity.Name, base.gameObject, "OnClickSelectedLine");
    }
 private void CreateFactionSqueleton()
 {
     this.Faction = new Faction();
     if (this.CreateMode)
     {
         this.Faction.Name                 = Guid.NewGuid().ToString();
         this.Faction.LocalizedName        = AgeLocalizer.Instance.LocalizeString("%CustomFactionEnterName");
         this.Faction.LocalizedDescription = AgeLocalizer.Instance.LocalizeString("%CustomFactionEnterDescription");
         ISessionService service = Services.GetService <ISessionService>();
         this.Faction.Author = Steamworks.SteamAPI.SteamFriends.GetFriendPersonaName(service.Session.SteamIDUser);
     }
     else
     {
         Diagnostics.Assert(this.givenFaction != null);
         this.Faction.Name                 = this.givenFaction.Name;
         this.Faction.LocalizedName        = this.givenFaction.LocalizedName;
         this.Faction.LocalizedDescription = this.givenFaction.LocalizedDescription;
         this.Faction.Author               = this.givenFaction.Author;
         this.Faction.FileName             = this.givenFaction.FileName;
     }
     if (this.givenFaction != null)
     {
         if (!this.givenFaction.IsRandom)
         {
             this.SelectedAffinity        = this.affinityGuiTraits.Find((GuiFactionTrait guiTrait) => guiTrait.Name == this.givenFaction.Affinity.Name);
             this.SelectedAffinityMapping = this.affinityMappingGuiTraits.Find((GuiFactionTrait guiTrait) => guiTrait.Name == this.givenFaction.AffinityMapping.Name);
             int i;
             for (i = 0; i < this.givenFaction.Traits.Length; i++)
             {
                 GuiFactionTrait guiFactionTrait = this.standardGuiTraits.Find((GuiFactionTrait guiTrait) => guiTrait.Name == this.givenFaction.Traits[i].Name);
                 if (guiFactionTrait != null && !this.preselectedGuiTraits.Contains(guiFactionTrait))
                 {
                     this.selectedGuiTraits.Add(guiFactionTrait);
                 }
             }
         }
         else
         {
             this.SelectedAffinity        = this.affinityGuiTraits[0];
             this.SelectedAffinityMapping = this.affinityMappingGuiTraits[0];
         }
     }
 }
    private void OnClickAvailableLine(MenuCustomTraitLine customTraitLine)
    {
        this.modified = true;
        GuiFactionTrait guiFactionTrait = this.selectedGuiTraits.FirstOrDefault((GuiFactionTrait match) => !string.IsNullOrEmpty(match.Root) && match.Root == customTraitLine.GuiFactionTrait.Root);

        if (guiFactionTrait != null)
        {
            if (customTraitLine.GuiFactionTrait.Level > guiFactionTrait.Level)
            {
                this.selectedGuiTraits.Remove(guiFactionTrait);
                this.selectedGuiTraits.Add(customTraitLine.GuiFactionTrait);
            }
        }
        else
        {
            this.selectedGuiTraits.Add(customTraitLine.GuiFactionTrait);
        }
        this.RefreshContent();
    }
    private void InitalizeRootInStandardTraits()
    {
        Dictionary <string, List <GuiFactionTrait> > dictionary = new Dictionary <string, List <GuiFactionTrait> >();

        for (int i = 0; i < this.standardGuiTraits.Count; i++)
        {
            GuiFactionTrait guiFactionTrait = this.standardGuiTraits[i];
            if (!string.IsNullOrEmpty(guiFactionTrait.Root))
            {
                if (!dictionary.ContainsKey(guiFactionTrait.Root))
                {
                    dictionary.Add(guiFactionTrait.Root, new List <GuiFactionTrait>());
                }
                dictionary[guiFactionTrait.Root].Add(guiFactionTrait);
            }
        }
        foreach (string key in dictionary.Keys)
        {
            for (int j = 0; j < dictionary[key].Count; j++)
            {
                dictionary[key][j].RootTraits = dictionary[key];
            }
        }
    }
    protected override IEnumerator OnShow(params object[] parameters)
    {
        yield return(base.OnShow(parameters));

        if (this.affinityGuiTraits.Count == 0)
        {
            this.HandleCancelRequest();
            yield break;
        }
        if (this.affinityMappingGuiTraits.Count == 0)
        {
            this.HandleCancelRequest();
            yield break;
        }
        this.availableGuiTraits.Clear();
        this.preselectedGuiTraits.Clear();
        this.selectedGuiTraits.Clear();
        if (this.diplomaticNegotiationViewport != null)
        {
            this.diplomaticNegotiationViewport.OnShow(0.5f);
        }
        this.empireIndex = -1;
        if (parameters.Length > 0)
        {
            this.empireIndex = (int)parameters[0];
        }
        this.givenFaction = null;
        if (parameters.Length > 1)
        {
            this.givenFaction = (parameters[1] as Faction);
        }
        IDownloadableContentService downloadableContentService = Services.GetService <IDownloadableContentService>();

        if (downloadableContentService != null)
        {
            for (int index = 0; index < this.AffinityDropList.ItemTable.Length; index++)
            {
                this.AffinityDropList.EnableItem(index, true);
                if (index < this.affinityGuiTraits.Count)
                {
                    GuiFactionTrait guiFactionTrait = this.affinityGuiTraits[index];
                    if (this.givenFaction.Affinity == null || !(this.givenFaction.Affinity.Name == guiFactionTrait.Name))
                    {
                        bool result;
                        if (downloadableContentService.TryCheckAgainstRestrictions(DownloadableContentRestrictionCategory.FactionAffinity, guiFactionTrait.Name, out result) && !result)
                        {
                            this.AffinityDropList.EnableItem(index, false);
                        }
                    }
                }
            }
        }
        this.CreateFactionSqueleton();
        this.NameTextField.AgePrimitiveLabel.Text                 = this.Faction.LocalizedName;
        this.DescriptionTextField.AgePrimitiveLabel.Text          = this.Faction.LocalizedDescription;
        this.DescriptionTextField.AgeTransform.AgeTooltip.Content = this.Faction.LocalizedDescription;
        this.AuthorTextField.AgePrimitiveLabel.Text               = this.Faction.Author;
        if (this.CreateMode)
        {
            AgeManager.Instance.FocusedControl = this.NameTextField;
        }
        this.CreateCustomTraitFamilyFilters();
        this.AvailableTraitsSortsContainer.SetContent(this.CustomTraitPrefab, "CustomTrait", null);
        this.SelectedTraitsSortsContainer.SetContent(this.CustomTraitPrefab, "CustomTrait", null);
        this.RefreshContent();
        yield break;
    }