Пример #1
0
		public void InvokeOnMainLoop (GuiUnit.InvokerHelper helper)
		{
			var invokeOnMainThreadMethods = Application.GetMethods (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
			var invokeOnMainThreadMethod = invokeOnMainThreadMethods.First (d => d.Name == "Invoke" && d.GetParameters ().Length == 1);
			EventHandler invoker = delegate { helper.Invoke (); };
			invokeOnMainThreadMethod.Invoke (null, new [] { invoker });
		}
Пример #2
0
    private bool IsMercenary(global::Empire onlooker, GuiUnit guiUnit)
    {
        if (guiUnit == null)
        {
            return(false);
        }
        Army army = guiUnit.TryGetUnitGarrison() as Army;

        return((army == null || !army.HasCatspaw) && this.IsMercenary(onlooker, guiUnit.UnitDesign));
    }
Пример #3
0
 protected virtual void RefreshGuiUnit(AgeTransform unitTransform, GuiUnit guiUnit, int index)
 {
     unitTransform.GetComponent <UnitGuiItem>().RefreshContent(guiUnit, base.gameObject, base.AgeTransform);
     unitTransform.Enable = !guiUnit.IsMilitia;
     if (guiUnit.Unit == this.Garrison.Hero)
     {
         unitTransform.Visible = false;
     }
     else
     {
         unitTransform.Visible = true;
     }
 }
    protected override IEnumerator OnShow(params object[] parameters)
    {
        if (this.Background != null)
        {
            this.Background.TintColor = this.NonEmbarkedBackgroundColor;
        }
        this.abilityReferences.Clear();
        if (this.context is IUnitAbilityController)
        {
            UnitAbilityReference[] abilities = (this.context as IUnitAbilityController).GetAbilities();
            if (abilities != null)
            {
                UnitAbilityReference[] array = abilities;
                for (int i = 0; i < array.Length; i++)
                {
                    UnitAbilityReference ability = array[i];
                    if (this.abilityReferences.Any((UnitAbilityReference match) => match.Name == ability.Name))
                    {
                        int index = this.abilityReferences.FindIndex((UnitAbilityReference match) => match.Name == ability.Name);
                        if (ability.Level > this.abilityReferences[index].Level)
                        {
                            this.abilityReferences[index] = ability;
                        }
                    }
                    else
                    {
                        this.abilityReferences.Add(ability);
                    }
                }
            }
        }
        this.abilityReferences.RemoveAll((UnitAbilityReference match) => !this.unitAbilityDatatable.ContainsKey(match.Name) || this.unitAbilityDatatable.GetValue(match.Name).Hidden);
        if (this.abilityReferences.Count > this.smallPrefabThreshold && this.abilityReferences.Count <= this.minimalPrefabThreshold && this.ResizeSelf)
        {
            if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Small)
            {
                this.CapacitiesTable.DestroyAllChildren();
                this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Small;
            }
            this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacitySmallPrefab, "Item");
        }
        else if (this.abilityReferences.Count > this.minimalPrefabThreshold && this.ResizeSelf)
        {
            if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Minimal)
            {
                this.CapacitiesTable.DestroyAllChildren();
                this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Minimal;
            }
            this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacityMinimalPrefab, "Item");
        }
        else
        {
            if (this.previousSize != PanelFeatureCapacities.CapacityPrefabSizes.Normal)
            {
                this.CapacitiesTable.DestroyAllChildren();
                this.previousSize = PanelFeatureCapacities.CapacityPrefabSizes.Normal;
            }
            this.CapacitiesTable.ReserveChildren(this.abilityReferences.Count, this.CapacityPrefab, "Item");
        }
        GuiUnit guiUnit = this.context as GuiUnit;
        Unit    unit    = this.context as Unit;
        List <UnitAbilityReference> listToCheck   = new List <UnitAbilityReference>();
        List <UnitAbilityReference> HeroAbilities = new List <UnitAbilityReference>();
        List <UnitAbilityReference> ItemAbilities = new List <UnitAbilityReference>();
        UnitDesign unitDesign = null;

        if (unit != null)
        {
            unitDesign = unit.UnitDesign;
        }
        if (guiUnit != null)
        {
            unitDesign = guiUnit.UnitDesign;
        }
        if (unitDesign != null)
        {
            if (unitDesign.UnitBodyDefinition.UnitAbilities != null && unitDesign.UnitBodyDefinition.UnitAbilities.Length != 0)
            {
                listToCheck = unitDesign.UnitBodyDefinition.UnitAbilities.ToList <UnitAbilityReference>();
            }
            UnitProfile unitProfile = unitDesign as UnitProfile;
            if (unitProfile != null && unitProfile.ProfileAbilityReferences != null && unitProfile.ProfileAbilityReferences.Length != 0)
            {
                HeroAbilities = unitProfile.ProfileAbilityReferences.ToList <UnitAbilityReference>();
            }
            if (unitDesign.UnitEquipmentSet != null)
            {
                List <StaticString>        list     = new List <StaticString>(unitDesign.UnitEquipmentSet.Slots.Length);
                IDatabase <ItemDefinition> database = Databases.GetDatabase <ItemDefinition>(false);
                Diagnostics.Assert(database != null);
                for (int j = 0; j < unitDesign.UnitEquipmentSet.Slots.Length; j++)
                {
                    UnitEquipmentSet.Slot slot = unitDesign.UnitEquipmentSet.Slots[j];
                    if (!list.Contains(slot.ItemName))
                    {
                        StaticString   key = slot.ItemName.ToString().Split(DepartmentOfDefense.ItemSeparators)[0];
                        ItemDefinition itemDefinition;
                        if (database.TryGetValue(key, out itemDefinition))
                        {
                            Diagnostics.Assert(itemDefinition != null);
                            if (itemDefinition.AbilityReferences != null)
                            {
                                ItemAbilities.AddRange(itemDefinition.AbilityReferences);
                                list.Add(slot.ItemName);
                            }
                        }
                    }
                }
            }
        }
        this.abilityReferences.Sort(delegate(UnitAbilityReference left, UnitAbilityReference right)
        {
            bool flag   = !this.ContainsAbilityReference(HeroAbilities, left) && !this.ContainsAbilityReference(ItemAbilities, left);
            bool flag2  = this.ContainsAbilityReference(HeroAbilities, left);
            bool flag3  = this.ContainsAbilityReference(ItemAbilities, left);
            bool flag4  = !this.ContainsAbilityReference(HeroAbilities, right) && !this.ContainsAbilityReference(ItemAbilities, right);
            bool flag5  = this.ContainsAbilityReference(HeroAbilities, right);
            bool flag6  = this.ContainsAbilityReference(ItemAbilities, right);
            string x    = left.Name + Mathf.Max((float)left.Level, 0f);
            string text = "";
            GuiElement guiElement;
            if (this.GuiService.GuiPanelHelper.TryGetGuiElement(x, out guiElement))
            {
                text = AgeLocalizer.Instance.LocalizeString(guiElement.Title);
            }
            x           = right.Name + Mathf.Max((float)right.Level, 0f);
            string strB = "";
            if (this.GuiService.GuiPanelHelper.TryGetGuiElement(x, out guiElement))
            {
                strB = AgeLocalizer.Instance.LocalizeString(guiElement.Title);
            }
            if (flag && flag5)
            {
                return(-1);
            }
            if (flag && flag6)
            {
                return(-1);
            }
            if (flag2 && flag4)
            {
                return(1);
            }
            if (flag3 && flag4)
            {
                return(1);
            }
            if (flag2 && flag6)
            {
                return(-1);
            }
            if (flag3 && flag2)
            {
                return(1);
            }
            if ((flag && flag4) || (flag2 && flag5) || (flag3 && flag6))
            {
                return(text.CompareTo(strB));
            }
            return(0);
        });
        this.CapacitiesTable.RefreshChildrenIList <UnitAbilityReference>(this.abilityReferences, this.refreshAbilityReferenceDelegate, true, false);
        this.CapacitiesTable.ArrangeChildren();
        int num = this.CapacitiesTable.ComputeVisibleChildren();

        if (num > 0)
        {
            this.CapacitiesTable.Visible = true;
            AgeTransform ageTransform = this.CapacitiesTable.GetChildren()[num - 1];
            this.CapacitiesTable.Height = ageTransform.Y + ageTransform.Height + this.CapacitiesTable.VerticalMargin;
            this.Title.Text             = AgeLocalizer.Instance.LocalizeString("%FeatureCapacitiesTitle");
            if (this.ResizeSelf)
            {
                base.AgeTransform.Height = this.CapacitiesTable.PixelMarginTop + this.CapacitiesTable.Height + this.CapacitiesTable.PixelMarginBottom;
            }
            if (guiUnit != null && (guiUnit.Unit != null || guiUnit.UnitSnapshot != null) && this.Background != null && ((guiUnit.Unit != null && guiUnit.Unit.Embarked) || (guiUnit.UnitSnapshot != null && guiUnit.UnitSnapshot.Embarked)))
            {
                this.Title.Text           = "%FeatureCapacitiesEmbarkedTitle";
                this.Background.TintColor = this.EmbarkedBackgroundColor;
            }
            Color tintColor  = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor1"), 0)];
            Color tintColor2 = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor2"), 2)];
            Color tintColor3 = PanelFeatureCapacities.Colorlist[Amplitude.Unity.Framework.Application.Registry.GetValue <int>(new StaticString("Settings/ELCP/UI/CapacityColor3"), 8)];
            for (int k = 0; k < this.abilityReferences.Count; k++)
            {
                FeatureItemCapacity component = this.CapacitiesTable.GetChildren()[k].GetComponent <FeatureItemCapacity>();
                if (component != null && !this.ContainsAbilityReference(listToCheck, this.abilityReferences[k]))
                {
                    component.Icon.TintColor = tintColor;
                    if (this.ContainsAbilityReference(HeroAbilities, this.abilityReferences[k]))
                    {
                        component.Icon.TintColor = tintColor2;
                    }
                    else if (this.ContainsAbilityReference(ItemAbilities, this.abilityReferences[k]))
                    {
                        component.Icon.TintColor = tintColor3;
                    }
                    else
                    {
                        component.Icon.TintColor = tintColor;
                    }
                }
                else if (component != null && this.ContainsAbilityReference(listToCheck, this.abilityReferences[k]))
                {
                    component.Icon.TintColor = tintColor;
                }
            }
        }
        else
        {
            this.CapacitiesTable.Visible = false;
            this.Title.Text = AgeLocalizer.Instance.LocalizeString("%FeatureNoCapacitiesTitle");
            if (this.ResizeSelf)
            {
                base.AgeTransform.Height = this.CapacitiesTable.PixelMarginTop;
            }
        }
        yield return(base.OnShow(parameters));

        yield break;
    }
Пример #5
0
    public void RefreshContent(GuiUnit guiUnit, GameObject client, AgeTransform anchor)
    {
        this.Reset();
        if (guiUnit.UnitDesign == null)
        {
            this.DestroyedCrossImage.Alpha = 0f;
            this.LevelUpImage.Alpha        = 0f;
            this.LastStandImage.Alpha      = 0f;
            this.UnitName.Text             = "Unknown";
            if (this.tooltip != null && guiUnit.UnitSnapshot != null)
            {
                this.tooltip.Class   = "Simple";
                this.tooltip.Content = string.Format("Unknown Unit Design: {0}, {1}, {2} (in Empire {3})", new object[]
                {
                    guiUnit.UnitSnapshot.UnitDesignDefinitionName,
                    guiUnit.UnitSnapshot.UnitDesignModel,
                    guiUnit.UnitSnapshot.UnitDesignModelRevision,
                    guiUnit.Empire.Index
                });
            }
            return;
        }
        this.GuiUnit = guiUnit;
        if (this.tooltip != null)
        {
            this.tooltip.Anchor     = anchor;
            this.tooltip.Class      = "Unit";
            this.tooltip.ClientData = this.GuiUnit;
            this.tooltip.Content    = this.GuiUnit.UnitDesign.UnitBodyDefinitionReference;
        }
        this.UnitName.Text      = GuiUnitDesign.GetTruncatedTitle(this.GuiUnit.UnitDesign, this.UnitName);
        this.UnitPortrait.Image = this.GuiUnit.GetPortraitTexture(global::GuiPanel.IconSize.Small);
        this.UnitLevel.Text     = this.GuiUnit.LevelDisplayed.ToString();
        IGuiPanelHelper guiPanelHelper = Services.GetService <global::IGuiService>().GuiPanelHelper;

        Diagnostics.Assert(guiPanelHelper != null, "Unable to access GuiPanelHelper");
        IDownloadableContentService service = Services.GetService <IDownloadableContentService>();
        GuiElement guiElement;
        Texture2D  image;

        if (service != null && service.IsShared(DownloadableContent13.ReadOnlyName) && this.GuiUnit.IsShifted && guiPanelHelper.TryGetGuiElement(this.GuiUnit.UnitDesign.Name, out guiElement) && guiPanelHelper.TryGetTextureFromIcon(guiElement, global::GuiPanel.IconSize.ShiftedSmall, out image))
        {
            this.UnitPortrait.Image = image;
        }
        this.UnitToggle.State = false;
        if (client != null)
        {
            this.UnitToggle.OnSwitchMethod      = "OnUnitToggle";
            this.UnitToggle.OnMiddleClickMethod = "OnUnitToggle";
            this.UnitToggle.OnRightClickMethod  = "OnUnitToggle";
            this.UnitToggle.OnSwitchObject      = client;
            this.UnitToggle.AgeTransform.Enable = true;
        }
        else
        {
            this.UnitToggle.OnSwitchMethod      = string.Empty;
            this.UnitToggle.OnSwitchObject      = null;
            this.UnitToggle.AgeTransform.Enable = false;
        }
        if (this.PrivateerGroup != null)
        {
            this.PrivateerGroup.Visible = this.IsMercenary(this.GuiUnit);
        }
        this.LifeGauge.AgeTransform.PercentTop = 100f * (1f - this.GuiUnit.HealthRatio);
        this.LifeGauge.TintColor          = this.GuiUnit.HealthColor;
        this.LifeGauge.AgeTransform.Alpha = 1f;
        this.DestroyedCrossImage.Alpha    = ((this.GuiUnit.Health <= 0f) ? 1f : 0f);
        this.LevelUpImage.Alpha           = ((!this.GuiUnit.HasJustLeveledUp) ? 0f : 1f);
        this.LastStandImage.Alpha         = ((!this.GuiUnit.HasBeenLastStanding) ? 0f : 1f);
        this.UndeadImage.Alpha            = ((!this.GuiUnit.HasRisenFromTheDead) ? 0f : 1f);
        if (this.EmbarkedGroup != null && (guiUnit.Unit != null || guiUnit.UnitSnapshot != null))
        {
            this.EmbarkedGroup.Visible = ((guiUnit.Unit != null && guiUnit.Unit.Embarked) || (guiUnit.UnitSnapshot != null && guiUnit.UnitSnapshot.Embarked));
        }
    }
Пример #6
0
 private bool IsMercenary(GuiUnit guiUnit)
 {
     return(guiUnit != null && guiUnit.Empire != null && this.IsMercenary(guiUnit.Empire, guiUnit));
 }