// TODO: Add pawn icon in menu, next to name
        private static void AddButton(Rect rect, Listing_Standard list, Pawn pawn, bool fromColonistBar)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }
            if (pawn == null)
            {
                throw new ArgumentNullException(nameof(pawn));
            }
            float  truncWidth = rect.width / 2f - 4f;
            string pawnLabel  = pawn.Label.Truncate(truncWidth);

            if (ColonistBarUtility.IsHidden(pawn))
            {
                string buttonLabel = "ColonistBarHiding.Restore".Translate();
                buttonLabel = buttonLabel.Truncate(truncWidth);
                if (list.ButtonTextLabeled(pawnLabel, buttonLabel))
                {
                    ColonistBarUtility.RestoreColonist(pawn);
                }
            }
            else
            {
                string buttonLabel = "ColonistBarHiding.Remove".Translate();
                buttonLabel = buttonLabel.Truncate(truncWidth);
                if (list.ButtonTextLabeled(pawnLabel, buttonLabel))
                {
                    ColonistBarUtility.RemoveColonist(pawn, fromColonistBar);
                }
            }
        }
        private void DoBottomButtons(Rect rect, float distFromBottom)
        {
            // Show all, Hide all, Close

            float heightPer  = distFromBottom - 5f;
            float totalWidth = rect.width;
            float xGap       = 10f;
            float widthPer   = (totalWidth - (3 * xGap)) / 3f;

            Rect buttonRect = new Rect(rect.x, rect.yMax + 10f, widthPer, heightPer);

            if (Widgets.ButtonText(buttonRect, "ColonistBarHiding.ShowAllColonists".Translate()))
            {
                ColonistBarUtility.RestoreAllColonists();
            }
            buttonRect.x += widthPer + xGap;
            if (Widgets.ButtonText(buttonRect, "ColonistBarHiding.HideAllColonists".Translate()))
            {
                ColonistBarUtility.RemoveAllColonists(fromColonistBar);
            }
            buttonRect.x += widthPer + xGap;
            if (Widgets.ButtonText(buttonRect, "ColonistBarHiding.Close".Translate()))
            {
                this.Close();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles clicks and repaints to the colonist bar.
        /// </summary>
        /// <param name="colonistsToHighlight">The colonists to highlight on the colonist bar.</param>
        private static void HandleOnGUI(List <Pawn> colonistsToHighlight)
        {
            var colonistBar = Find.ColonistBar;
            var entries     = ColonistBarUtility.GetVisibleEntries();

            int currentGroup     = -1;
            int reorderableGroup = -1;

            for (int i = 0; i < colonistBar.DrawLocs.Count; i++)
            {
                var rect  = ColonistBarUtility.GetRect(i);
                var entry = entries[i];

                bool isDifferentGroup = currentGroup != entry.group;
                currentGroup = entry.group;
                if (isDifferentGroup)
                {
                    reorderableGroup = GetReorderableGroup(entry, entries);
                }
                bool reordering;
                if (entry.pawn != null)
                {
                    colonistBar.drawer.HandleClicks(
                        rect, entry.pawn, reorderableGroup, out reordering);
                }
                else
                {
                    reordering = false;
                }
                HandleRepaint(entry, rect, isDifferentGroup, reordering, colonistsToHighlight);
            }
        }
        // Modified public method ColonistBar.ColonistsOrCorpsesInScreenRect()
        private static List <Thing> ColonistsOrCorpsesInScreenRect(Rect rect,
                                                                   List <Pair <Thing, Map> > tmpColonistsWithMap, List <Thing> tmpColonists)
        {
            List <Vector2> drawLocs = Find.ColonistBar.DrawLocs;
            var            entries  = ColonistBarUtility.GetVisibleEntries();
            Vector2        size     = Find.ColonistBar.Size;

            tmpColonistsWithMap.Clear();
            for (int i = 0; i < drawLocs.Count; i++)
            {
                if (rect.Overlaps(new Rect(drawLocs[i].x, drawLocs[i].y, size.x, size.y)))
                {
                    Pawn pawn = entries[i].pawn;
                    if (pawn != null)
                    {
                        Thing first;
                        if (pawn.Dead && pawn.Corpse != null && pawn.Corpse.SpawnedOrAnyParentSpawned)
                        {
                            first = pawn.Corpse;
                        }
                        else
                        {
                            first = pawn;
                        }
                        tmpColonistsWithMap.Add(new Pair <Thing, Map>(first, entries[i].map));
                    }
                }
            }
            if (WorldRendererUtility.WorldRenderedNow)
            {
                if (tmpColonistsWithMap.Any((Pair <Thing, Map> x) => x.Second == null))
                {
                    tmpColonistsWithMap.RemoveAll((Pair <Thing, Map> x) => x.Second != null);
                    goto IL_1A1;
                }
            }
            if (tmpColonistsWithMap.Any((Pair <Thing, Map> x) => x.Second == Find.CurrentMap))
            {
                tmpColonistsWithMap.RemoveAll((Pair <Thing, Map> x) => x.Second != Find.CurrentMap);
            }
IL_1A1:
            tmpColonists.Clear();
            for (int j = 0; j < tmpColonistsWithMap.Count; j++)
            {
                tmpColonists.Add(tmpColonistsWithMap[j].First);
            }
            tmpColonistsWithMap.Clear();
            return(tmpColonists);
        }
 private static void CalculateDrawLocs(List <Vector2> outDrawLocs, List <int> entriesInGroup, out float scale, ref List <int> horizontalSlotsPerGroup)
 {
     if (!ColonistBarUtility.AnyVisibleEntries())
     {
         outDrawLocs.Clear();
         scale = 1f;
     }
     else
     {
         entriesInGroup = ColonistBarDrawLocsUtility.GetGroupEntryCounts();
         scale          = ColonistBarDrawLocsUtility.GetBestScale(
             entriesInGroup,
             out bool onlyOneRow, out int maxPerGlobalRow, out horizontalSlotsPerGroup);
         ColonistBarDrawLocsUtility.GetDrawLocs(scale, onlyOneRow, maxPerGlobalRow, entriesInGroup, horizontalSlotsPerGroup, outDrawLocs);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the reorderable group for the <see cref="ColonistBar"/>.
        /// </summary>
        /// <param name="entry">The entry to reorder.</param>
        /// <param name="entries">The colonist bar entries.</param>
        /// <returns>The new group to reorder to.</returns>
        private static int GetReorderableGroup(ColonistBar.Entry entry, List <ColonistBar.Entry> entries)
        {
            int group = entry.group;

            return(ReorderableWidget.NewGroup(delegate(int from, int to)
            {
                ColonistBarUtility.Reorder(from, to, group, entries);
            },
                                              ReorderableDirection.Horizontal,
                                              Find.ColonistBar.SpaceBetweenColonistsHorizontal,
                                              delegate(int index, Vector2 dragStartPos)
            {
                ColonistBarUtility.DrawColonistMouseAttachment(
                    index, dragStartPos, group, entries);
            }));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Handles the colonist bar's display on a GUI call, accounting for
 /// hidden colonists. Original method: <see cref="ColonistBar.ColonistBarOnGUI"/>.
 /// </summary>
 /// <param name="colonistsToHighlight">The colonists to highlight on the colonist bar.</param>
 private static void ColonistBarOnGUI(List <Pawn> colonistsToHighlight)
 {
     if (ColonistBarUtility.ShouldBeVisible())
     {
         if (Event.current.type != EventType.Layout)
         {
             HandleOnGUI(colonistsToHighlight);
             const int currentGroup = -1;
             HandleGroupFrameClicks(currentGroup);
         }
         if (Event.current.type == EventType.Repaint)
         {
             colonistsToHighlight.Clear();
         }
     }
 }
        public override void DoWindowContents(Rect inRect)
        {
            if (Current.Game == null)
            {
                throw new InvalidOperationException($"Cannot manage colonist bar if there is no current game.");
            }
            var rect = inRect.ContractedBy(Margin);
            // Avoid overlapping with close button
            const float distFromBottom = 40f;

            rect.height -= distFromBottom;
            var rect4 = new Rect(0, 0, rect.width - 16f, this.viewHeight);

            Widgets.BeginScrollView(rect, ref scrollPosition, rect4, true);
            var rect5 = rect4;

            rect5.width -= 16f;
            rect5.height = 9999f;

            Listing_Standard list = new Listing_Standard()
            {
                ColumnWidth     = rect5.width,
                maxOneColumn    = true,
                verticalSpacing = 6f
            };

            list.Begin(rect5);

            var pawns = ColonistBarUtility.GetColonistBarPawns();

            foreach (var pawn in pawns)
            {
                var pawnRect = list.GetRect(32f);
                AddPawnRow(pawnRect, list, pawn, fromColonistBar);
            }

            if (Event.current.type == EventType.Layout)
            {
                this.viewHeight = list.CurHeight;
            }
            list.End();
            Widgets.EndScrollView();

            // Bottom buttons
            DoBottomButtons(rect, distFromBottom);
        }
        // Modified private method ColonistBarColonistDrawer.GroupFrameRect()
        private static Rect GroupFrameRect(int group)
        {
            float          num      = 99999f;
            float          num2     = 0f;
            float          num3     = 0f;
            var            entries  = ColonistBarUtility.GetVisibleEntries();
            List <Vector2> drawLocs = Find.ColonistBar.DrawLocs;

            for (int i = 0; i < entries.Count; i++)
            {
                if (entries[i].group == group)
                {
                    num  = Mathf.Min(num, drawLocs[i].x);
                    num2 = Mathf.Max(num2, drawLocs[i].x + Find.ColonistBar.Size.x);
                    num3 = Mathf.Max(num3, drawLocs[i].y + Find.ColonistBar.Size.y);
                }
            }
            return(new Rect(num, 0f, num2 - num, num3).ContractedBy(-12f * Find.ColonistBar.Scale));
        }
        // Modified public method ColonistBar.MapColonistsOrCorpsesInScreenRect()
        private static List <Thing> MapColonistsOrCorpsesInScreenRect(Rect rect,
                                                                      List <Thing> tmpMapColonistsOrCorpsesInScreenRect)
        {
            tmpMapColonistsOrCorpsesInScreenRect.Clear();
            if (!ColonistBarUtility.ShouldBeVisible())
            {
                return(tmpMapColonistsOrCorpsesInScreenRect);
            }
            List <Thing> list = Find.ColonistBar.ColonistsOrCorpsesInScreenRect(rect);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Spawned)
                {
                    tmpMapColonistsOrCorpsesInScreenRect.Add(list[i]);
                }
            }
            return(tmpMapColonistsOrCorpsesInScreenRect);
        }
        private static bool Prefix(ref List <int> ___entriesInGroup)
        {
            var entries          = ColonistBarUtility.GetVisibleEntries(Find.ColonistBar);
            var totalGroupsCount = ColonistBarUtility.GetTotalGroupsCount();

            var list = new List <int>(totalGroupsCount);

            for (int i = 0; i < totalGroupsCount; i++)
            {
                list.Add(0);
            }
            foreach (var entry in entries)
            {
                int group = entry.group;
                list[group]++;
            }
            ___entriesInGroup = list;
            return(false);
        }
        public override void DoWindowContents(Rect inRect)
        {
            var rect = inRect.ContractedBy(Margin);
            // Avoid overlapping with close button
            const float distFromBottom = 40f;

            rect.height -= distFromBottom;
            var rect4 = new Rect(0, 0, rect.width - 16f, this.viewHeight);

            Widgets.BeginScrollView(rect, ref scrollPosition, rect4, true);
            var rect5 = rect4;

            rect5.width -= 16f;
            rect5.height = 9999f;

            Listing_Standard list = new Listing_Standard()
            {
                ColumnWidth     = rect5.width,
                maxOneColumn    = true,
                verticalSpacing = 6f
            };

            list.Begin(rect5);

            var pawns = ColonistBarUtility.GetColonistBarPawns();

            foreach (var pawn in pawns)
            {
                var pawnRect = list.GetRect(6f);
                if (pawn == null)
                {
                    continue;
                }
                AddButton(pawnRect, list, pawn, fromColonistBar);
            }

            if (Event.current.type == EventType.Layout)
            {
                this.viewHeight = list.CurHeight;
            }
            list.End();
            Widgets.EndScrollView();
        }
        // Original public method ColonistBar.ColonistOrCorpseAt()
        private static Thing ColonistOrCorpseAt(Vector2 pos)
        {
            if (!ColonistBarUtility.ShouldBeVisible())
            {
                return(null);
            }
            ColonistBar.Entry entry;
            if (!ColonistBarUtility.TryGetEntryAt(pos, out entry))
            {
                return(null);
            }
            Pawn  pawn = entry.pawn;
            Thing result;

            if (pawn != null && pawn.Dead && pawn.Corpse != null && pawn.Corpse.SpawnedOrAnyParentSpawned)
            {
                result = pawn.Corpse;
            }
            else
            {
                result = pawn;
            }
            return(result);
        }
        private static void AddPawnRow(Rect rect, Listing_Standard list, Pawn pawn, bool fromColonistBar)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }
            if (pawn == null)
            {
                throw new ArgumentNullException(nameof(pawn));
            }
            float  truncWidth = rect.width / 2f - 4f;
            string pawnLabel  = pawn.Label.Truncate(truncWidth);

            string buttonLabel;

            if (ColonistBarUtility.IsHidden(pawn))
            {
                buttonLabel = "ColonistBarHiding.Restore".Translate();
            }
            else
            {
                buttonLabel = "ColonistBarHiding.Remove".Translate();
            }
            buttonLabel = buttonLabel.Truncate(truncWidth);

            // Position it better
            //float yLabel = Text.CalcHeight(pawnLabel, rect.width);
            //Rect labelRect = list.GetRect(yLabel);

            //Widgets.Label(labelRect.LeftHalf(), pawnLabel);
            var rL = rect.LeftHalf();

            rL.y += 5f;
            Widgets.Label(rL, pawnLabel);
            Rect iconButtonRect = rect.RightHalf();

            //float iconWidth = 12f;

            if (ColonistBarUtility.IsHidden(pawn))
            {
                Rect textureRect = new Rect(iconButtonRect.x, iconButtonRect.y, iconButtonRect.height, iconButtonRect.height);
                var  texture     = ContentFinder <Texture2D> .Get("ColonistBarHiding/HiddenIcon", true);

                Widgets.DrawTextureFitted(textureRect, texture, 1.0f);
                TooltipHandler.TipRegion(textureRect, () => { return("ColonistBarHiding.ColonistIsHidden".Translate()); }, 585743620);
            }
            float spacing = 6f;

            iconButtonRect.x     += iconButtonRect.height + spacing;
            iconButtonRect.width -= iconButtonRect.height + spacing;
            if (ColonistBarUtility.IsHidden(pawn))
            {
                if (Widgets.ButtonText(iconButtonRect, buttonLabel))
                {
                    ColonistBarUtility.RestoreColonist(pawn);
                }
            }
            else
            {
                if (Widgets.ButtonText(iconButtonRect, buttonLabel))
                {
                    ColonistBarUtility.RemoveColonist(pawn, fromColonistBar);
                }
            }
            list.Gap();
        }
 private static bool Prefix(ref bool __result, Vector2 pos, ref ColonistBar.Entry entry)
 {
     __result = ColonistBarUtility.TryGetEntryAt(pos, out entry);
     return(false);
 }
 private static bool Prefix(int __result)
 {
     __result = ColonistBarUtility.GetVisibleGroupsCount();
     return(false);
 }