/// <summary>
 /// Applied before Refresh runs.
 /// </summary>
 internal static bool Prefix(MinionStatsPanel __instance)
 {
     if (__instance.gameObject.activeSelf)
     {
         Refresh(__instance);
     }
     return(false);
 }
            /// <summary>
            /// Applied before OnSpawn runs.
            /// </summary>
            internal static void Prefix(MinionStatsPanel __instance)
            {
                var go = __instance.gameObject;

                if (go != null)
                {
                    go.AddOrGet <MinionStatsPanelWrapper>().panel = __instance;
                }
            }
 public override void OnCleanUp()
 {
     modifiers = null;
     panel     = null;
     resume    = null;
     target    = null;
     instance  = null;
     base.OnCleanUp();
 }
        /// <summary>
        /// Refreshes the Duplicant's attributes.
        /// </summary>
        /// <param name="msp">The Duplicant stats panel to update.</param>
        /// <param name="modifiers">The currently selected Duplicant's attributes.</param>
        private static void RefreshAttributes(MinionStatsPanel msp, Modifiers modifiers)
        {
            var drawer      = msp.attributesDrawer;
            var currentAttr = modifiers.attributes.AttributeTable;
            int n           = currentAttr.Count;

            drawer.BeginDrawing();
            for (int i = 0; i < n; i++)
            {
                var attrInstance = currentAttr[i];
                if (attrInstance.Attribute.ShowInUI == Klei.AI.Attribute.Display.Skill)
                {
                    drawer.NewLabel(attrInstance.Name + ": " + attrInstance.
                                    GetFormattedValue()).Tooltip(attrInstance.
                                                                 GetAttributeValueTooltip());
                }
            }
            drawer.EndDrawing();
        }
        /// <summary>
        /// Refreshes the Duplicant stats panel.
        /// </summary>
        /// <param name="msp">The Duplicant stats panel to update.</param>
        private static void Refresh(MinionStatsPanel msp)
        {
            var inst = instance;

            if (inst != null)
            {
                bool   changed     = inst.SetTarget(msp.selectedTarget);
                var    resume      = inst.resume;
                var    resumePanel = msp.resumePanel;
                var    target      = inst.target;
                string name        = null;
                var    modifiers   = inst.modifiers;
                if (changed)
                {
                    var attributesPanel = msp.attributesPanel;
                    resumePanel.SetActive(resume != null);
                    attributesPanel.SetActive(resume != null);
                    attributesPanel.GetComponent <CollapsibleDetailContentPanel>().HeaderLabel.
                    SetText(STRINGS.UI.DETAILTABS.STATS.GROUPNAME_ATTRIBUTES);
                }
                if (target != null)
                {
                    var text = CACHED_BUILDER;
                    name = target.name;
                    text.Clear().Append(PERSONALITY.GROUPNAME_RESUME).Replace("{0}",
                                                                              StringFormatter.ToUpper(name));
                    resumePanel.GetComponent <CollapsibleDetailContentPanel>().HeaderLabel.
                    SetText(text);
                }
                if (resume != null)
                {
                    RefreshResume(msp, resume, name);
                }
                if (modifiers != null)
                {
                    RefreshAttributes(msp, modifiers);
                }
            }
        }
        /// <summary>
        /// Refreshes the Duplicant's resume.
        /// </summary>
        /// <param name="msp">The Duplicant stats panel to update.</param>
        /// <param name="resume">The currently selected Duplicant's resume.</param>
        /// <param name="name">The currently selected Duplicant's name</param>
        private static void RefreshResume(MinionStatsPanel msp, MinionResume resume,
                                          string name)
        {
            var drawer = msp.resumeDrawer;
            var text   = CACHED_BUILDER;
            int skills = 0;

            drawer.BeginDrawing();
            drawer.NewLabel(PERSONALITY.RESUME.MASTERED_SKILLS).Tooltip(PERSONALITY.RESUME.
                                                                        MASTERED_SKILLS_TOOLTIP);
            foreach (var pair in resume.MasteryBySkillID)
            {
                if (pair.Value)
                {
                    var skill = Db.Get().Skills.Get(pair.Key);
                    var perks = skill.perks;
                    int n     = perks.Count;
                    text.Clear();
                    text.AppendLine(skill.description);
                    for (int i = 0; i < n; i++)
                    {
                        text.Append(" " + Constants.BULLETSTRING).AppendLine(perks[i].Name);
                    }
                    drawer.NewLabel((" " + Constants.BULLETSTRING) + skill.Name).Tooltip(text.
                                                                                         ToString());
                    skills++;
                }
            }
            if (skills == 0)
            {
                drawer.NewLabel((" " + Constants.BULLETSTRING) + PERSONALITY.RESUME.
                                NO_MASTERED_SKILLS.NAME).Tooltip(PERSONALITY.RESUME.NO_MASTERED_SKILLS.
                                                                 TOOLTIP.Format(name));
            }
            drawer.EndDrawing();
        }