Пример #1
0
        private static Ability DoActiveAbilityInterface(Rect abilityRect, Ability ability, Pawn pawn)
        {
            CompAbilityHolder abilityHolderComp = pawn.GetComp <CompAbilityHolder>();

            GUI.BeginGroup(abilityRect);
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = Color.white;

            Rect iconRect = new Rect(0f, 0f, iconSize, iconSize);

            Widgets_Extensions.AbilityIcon(iconRect, ability);

            Rect labelRect = new Rect(iconRect.width + 2f, 0f, 120f, 32f);

            Widgets.Label(labelRect, ability.def.LabelCap);

            Rect upRect = new Rect(abilityRect.xMax - 24f - 24f - 34f, 0f, 24f, 24f);

            if (ability.gizmoOrder > 0)
            {
                if (Widgets.ButtonImage(upRect, Widgets_Extensions.reorderUpTex, Color.white))
                {
                    abilityHolderComp.ReorderClickable(ability, -1);
                }
            }

            Rect downRect = new Rect(abilityRect.xMax - 24f - 34f, 0f, 24f, 24f);

            if (ability.gizmoOrder != abilityHolderComp.LastGizmoNumber)
            {
                if (Widgets.ButtonImage(downRect, Widgets_Extensions.reorderDownTex, Color.white))
                {
                    abilityHolderComp.ReorderClickable(ability, 1);
                }
            }

            Rect deleteRect = new Rect(abilityRect.xMax - 34f, 0f, 24f, 24f); // 24f + 10f (scrollbar) = 34f

            if (Widgets.ButtonImage(deleteRect, Widgets_Extensions.deleteXTex, Color.white))
            {
                abilityHolderComp.ToggleClickable(ability);
            }

            float effectsWidth = abilityRect.width - iconRect.width - labelRect.width - upRect.width - downRect.width - deleteRect.width;
            Rect  effectsRect  = new Rect(labelRect.x + labelRect.width + 2f, 0f, effectsWidth, 32f);

            Widgets.Label(effectsRect, ability.def.description);

            GUI.EndGroup();

            if (Mouse.IsOver(abilityRect))
            {
                return(ability);
            }

            return(null);
        }
Пример #2
0
        private static Ability DoForgettingAbilityInterface(Rect abilityRect, Ability forgettingAbility, Pawn pawn)
        {
            CompAbilityHolder abilityHolderComp = pawn.GetComp <CompAbilityHolder>();

            GUI.BeginGroup(abilityRect);
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = Color.white;

            Rect iconRect = new Rect(0f, 0f, iconSize, iconSize);

            Widgets_Extensions.AbilityIcon(iconRect, forgettingAbility);

            Rect labelRect = new Rect(iconRect.width + 2f, 0f, 120f, 32f);

            Widgets.Label(labelRect, forgettingAbility.def.LabelCap);

            Rect timerRect = new Rect(abilityRect.xMax - 180f - 34f, 0f, 180f, 24f);

            GUI.color   = forgettingAbility.remainingTicksToForget > forgettingAbility.remainingTicksToForget * 0.5 ? Color.white : forgettingAbility.remainingTicksToForget > forgettingAbility.remainingTicksToForget * 0.2 ? Color.yellow : Color.red;
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Tiny;
            Widgets.Label(timerRect, GenDate.ToStringTicksToPeriod(forgettingAbility.remainingTicksToForget, true, true));
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.MiddleLeft;
            Text.Font   = GameFont.Small;

            Rect deleteRect = new Rect(abilityRect.xMax - 34f, 0f, 24f, 24f); // 24f + 10f (scrollbar) = 34f

            if (Widgets.ButtonImage(deleteRect, Widgets_Extensions.deleteXTex, Color.white))
            {
                abilityHolderComp.ToggleForgettable(forgettingAbility);
            }

            float effectsWidth = abilityRect.width - iconRect.width - labelRect.width - timerRect.width - deleteRect.width;
            Rect  effectsRect  = new Rect(labelRect.x + labelRect.width + 2f, 0f, effectsWidth, 32f);

            //Widgets.Label(effectsRect, forgettingAbility.def.description);

            GUI.EndGroup();

            if (Mouse.IsOver(abilityRect))
            {
                return(forgettingAbility);
            }

            return(null);
        }
Пример #3
0
        private static float DoForgettingAbilities(CompAbilityHolder abilityHolderComp, Rect rect, List <Ability> forgettingAbilities)
        {
            float y = 0f;

            for (int i = 0; i < forgettingAbilities.Count; i++)
            {
                Rect    abilityRect    = new Rect(rect.x, y, rect.width, AbilityHeight);
                Ability hoveredAbility = DoForgettingAbilityInterface(abilityRect, forgettingAbilities[i], abilityHolderComp.parent as Pawn);

                //                if (hoveredAbility != null)
                //                    mouseHoveredAbility = hoveredAbility;

                y += AbilityHeight + AbilityVerticalGap;
            }

            return(y);
        }
Пример #4
0
        private void AddAbilities(List <AbilityDef> abilities)
        {
            CompAbilityHolder abilityHolder = parent.GetComp <CompAbilityHolder>();

            if (abilityHolder == null)
            {
                Log.Error("AbilityHolder component not found on " + (Pawn)parent + ".");
                return;
            }

            foreach (AbilityDef abilityDef in abilities)
            {
                Ability ability = AbilityMaker.MakeAbility(abilityDef);
                if (!abilityHolder.TryAddAbility(ability))
                {
                    Log.Warning("Failed to add ability (" + ability.def.defName + ") to " + (Pawn)parent + ".");
                }
            }
        }
Пример #5
0
        private static Ability DoAbilityInterface(Rect abilityRect, Ability ability, Pawn pawn)
        {
            CompAbilityHolder abilityHolderComp = pawn.GetComp <CompAbilityHolder>();

            GUI.BeginGroup(abilityRect);
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = Color.white;

            Rect iconRect = new Rect(0f, 0f, iconSize, iconSize);

            Widgets_Extensions.AbilityIcon(iconRect, ability);

            GUI.color = abilityHolderComp.ClickableAbilities.Contains(ability) ? Color.green : Color.white;
            Rect labelRect = new Rect(iconRect.width + 4f, 0f, 120f, 32f);

            Widgets.Label(labelRect, ability.def.LabelCap);
            GUI.color = Color.white;

            float deleteRectWidth = ability.lastAttemptedForget <= 0 ? 34f : 154f;

            Rect infoRect = new Rect(abilityRect.xMax - 24f - 24f - deleteRectWidth, 0f, 24f, 24f);

            if (Widgets.ButtonImage(infoRect, Widgets_Extensions.infoTex, Color.white))
            {
                Log.Warning("clicked info");
            }

            Rect addRect = new Rect(abilityRect.xMax - 24f - deleteRectWidth, 0f, 24f, 24f);

            if (Widgets.ButtonImage(addRect, Widgets_Extensions.plusTex, Color.white))
            {
                abilityHolderComp.ToggleClickable(ability);
            }

            Rect deleteRect = new Rect(abilityRect.xMax - deleteRectWidth, 0f, deleteRectWidth - 10f, 24f); // 24f + 10f (scrollbar) = 34f

            if (ability.lastAttemptedForget <= 0)
            {
                if (Widgets.ButtonImage(deleteRect, Widgets_Extensions.deleteXTex, ability.forgetting ? new Color(0.2f, 0.2f, 0.2f) : Color.white))
                {
                    abilityHolderComp.ToggleForgettable(ability);
                }
            }
            else
            {
                Text.Anchor = TextAnchor.MiddleCenter;
                Text.Font   = GameFont.Tiny;
                Widgets.Label(deleteRect, GenDate.ToStringTicksToPeriod(ability.lastAttemptedForget, true, true));
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.UpperLeft;
            }

            GUI.color = abilityHolderComp.ClickableAbilities.Contains(ability) ? Color.green : Color.white;
            float effectsWidth = abilityRect.width - iconRect.width - labelRect.width - infoRect.width - addRect.width - deleteRect.width - 8f; // 8f sum of gaps.
            Rect  effectsRect  = new Rect(labelRect.x + labelRect.width + 4f, 0f, effectsWidth, 32f);

            Widgets.Label(effectsRect, ability.def.description);
            GUI.color = Color.white;
            GUI.EndGroup();

            if (ability.forgetting)
            {
                Text.Font   = GameFont.Medium;
                Text.Anchor = TextAnchor.MiddleCenter;
                Rect forgettingRect = new Rect(abilityRect.x, abilityRect.y, abilityRect.width, abilityRect.height);
                GUI.DrawTexture(forgettingRect, TexUI.TextBGBlack);
                Widgets.Label(forgettingRect, "ForgettingAbility".Translate());
                Text.Anchor = TextAnchor.UpperLeft;
                Text.Font   = GameFont.Small;
            }

            if (Mouse.IsOver(abilityRect))
            {
                return(ability);
            }

            return(null);
        }
Пример #6
0
        public static float DrawAbilitiesTab(Rect rect, Pawn pawn, float curY)
        {
            CompAbilityHolder abilityHolderComp   = pawn.GetComp <CompAbilityHolder>();
            List <Ability>    abilities           = abilityHolderComp.abilities;
            List <Ability>    activeAbilities     = abilityHolderComp.SortedClickableAbilities;
            List <Ability>    forgettingAbilities = abilityHolderComp.ForgettingAbilities;

            // ========== All Abilities ==========
            PrepareAbilityCategoryDefs(abilities);
            onAbilityCategories.Clear();
            foreach (AbilityCategoryDef catDef in AbilityCategoryDefs)
            {
                onAbilityCategories.Add(false);
            }
            if (!onAbilityCategories.NullOrEmpty())
            {
                onAbilityCategories[0] = true;
            }

            Rect allAbilitiesByCategoryRect = new Rect(0f, 40f, rect.width, 148f);

            Widgets.DrawMenuSection(allAbilitiesByCategoryRect);
            List <TabRecord> abilityTabs = new List <TabRecord>();

            for (int i = 0; i < AbilityCategoryDefs.Count; i++)
            {
                abilityTabs.Add(new TabRecord((AbilityCategoryDefs[i].defName + "Key").Translate(), delegate
                {
                    for (int t = 0; t < onAbilityCategories.Count; t++)
                    {
                        onAbilityCategories[t] = false;
                    }

                    onAbilityCategories[i] = true;
                }, onAbilityCategories[i]));
            }

            if (!abilityTabs.NullOrEmpty())
            {
                TabDrawer.DrawTabs(allAbilitiesByCategoryRect, abilityTabs);

                rect = rect.ContractedBy(9f);
                GUI.BeginGroup(allAbilitiesByCategoryRect);
                Text.Font   = GameFont.Small;
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;

                DoAbilityCategories(allAbilitiesByCategoryRect, abilities, pawn);

                GUI.EndGroup();
            }
            else
            {
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(allAbilitiesByCategoryRect, "PawnHasNoAbilities".Translate());
            }

            Text.Font   = GameFont.Small;
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;

            Rect abilityCapacity = new Rect(rect.xMax - 180f, 190f, 180f, 30f);

            GUI.BeginGroup(abilityCapacity);

            Rect labelRect = new Rect(0f, 0f, 130f, 30f);

            Widgets.Label(labelRect, "AcquiredAbilities".Translate() + ": ");

            Rect currentMaxRect = new Rect(120f, 0f, 50f, 30f);

            Widgets.Label(currentMaxRect, "99/99");

            GUI.EndGroup();

            // ========== Active Abilities ==========

            Rect activeAbilitiesOuterRect = new Rect(4f, 225f, rect.width + 10f, 140f);
            Rect activeAbilitiesViewRect  = new Rect(
                activeAbilitiesOuterRect.x,
                0f,
                activeAbilitiesOuterRect.width - 16f,
                activeAbilities.NullOrEmpty() ? activeAbilitiesOuterRect.height : activeAbilities.Count * AbilityHeight + (activeAbilities.Count - 1) * AbilityVerticalGap);

            Widgets.BeginScrollView(activeAbilitiesOuterRect, ref ActiveAbilitiesScrollPosition, activeAbilitiesViewRect, true);
            GUI.BeginGroup(activeAbilitiesViewRect);
            Text.Font   = GameFont.Small;
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.MiddleCenter;
            if (!activeAbilities.NullOrEmpty())
            {
                DoActiveAbilities(abilityHolderComp, activeAbilitiesViewRect, activeAbilities);
            }

            GUI.EndGroup();
            Widgets.EndScrollView();

            if (activeAbilities.NullOrEmpty())
            {
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(activeAbilitiesOuterRect, "PawnHasNoActiveAbilities".Translate());
            }

            // ========== Forgetting Abilities ==========

            Rect forgettingAbilitiesRect = new Rect(4f, 385f, rect.width + 10f, 68f);

            GUI.BeginGroup(forgettingAbilitiesRect);
            Text.Font   = GameFont.Small;
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.MiddleCenter;
            if (!forgettingAbilities.NullOrEmpty())
            {
                DoForgettingAbilities(abilityHolderComp, forgettingAbilitiesRect, forgettingAbilities);
            }
            GUI.EndGroup();

            if (forgettingAbilities.NullOrEmpty())
            {
                Text.Font = GameFont.Small;
                Widgets.Label(forgettingAbilitiesRect, "PawnIsNotForgettingAbilities".Translate());
            }

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;

            return(curY); // obsolete
        }