Пример #1
0
        public void DrawPawnKindRow(PawnKindDef pawnKind)
        {
            Rect rectRow   = new Rect(_x, _y, ColWidth, _rowHeight);
            Rect rectLabel = new Rect(_x, _y, LabWidth, _rowHeight);

            Widgets.Label(rectLabel, pawnKind.LabelCap);
            Rect rectIcon = new Rect(_x2 + _iconWidthOffset, _y, _iconSize, _iconSize);
            bool inList   = Widgets_Filter.FilterPawnKind.Contains(pawnKind);

            GUI.DrawTexture(rectIcon, inList ? Widgets.CheckboxOnTex : Widgets.CheckboxOffTex);
            if (Mouse.IsOver(rectRow))
            {
                GUI.DrawTexture(rectRow, TexUI.HighlightTex);
            }
            if (Widgets.InvisibleButton(rectRow))
            {
                if (inList)
                {
                    SoundDefOf.CheckboxTurnedOff.PlayOneShotOnCamera();
                }
                else
                {
                    SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                }
                Widgets_Filter.TogglePawnKindFilter(pawnKind, inList);
                MainTabWindow_Animals.IsDirty = true;
            }
            _y += _rowHeight;
        }
Пример #2
0
        public override void DoWindowContents(Rect inRect)
        {
            // Close if animals tab closed
            if (Find.WindowStack.WindowOfType <MainTabWindow_Animals>() == null)
            {
                Find.WindowStack.TryRemove(this);
            }

            Text.Font = GameFont.Small;


            // Pawnkinds on the left.
            _x  = 5f;
            _y  = 5f;
            _x2 = ColWidth - 45f;

            Rect rect = new Rect(_x, _y, ColWidth, _rowHeight);

            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.LowerLeft;
            Widgets.Label(rect, "Fluffy.FilterByRace".Translate());
            Text.Font = GameFont.Small;


            _y += _rowHeight;

            foreach (PawnKindDef pawnKind in PawnKinds)
            {
                DrawPawnKindRow(pawnKind);
            }

            // set window's actual height
            if (_y > _actualHeight)
            {
                _actualHeight = _y;
            }

            // specials on the right.
            _x  = inRect.width / 2f + 5f;
            _x2 = inRect.width / 2f + ColWidth - 45f;
            _y  = 5f;

            Text.Font = GameFont.Tiny;
            Rect rectAttributes = new Rect(_x, 5f, ColWidth, _rowHeight);

            Widgets.Label(rectAttributes, "Fluffy.FilterByAttributes".Translate());
            Text.Font = GameFont.Small;

            _y += _rowHeight;

            // draw filter rows.
            foreach (IFilter filter in Widgets_Filter.Filters)
            {
                DrawFilterRow(filter);
            }

            // set window's actual height
            if (_y > _actualHeight)
            {
                _actualHeight = _y;
            }

            // sticky option
            Rect stickyRect = new Rect(5f, inRect.height - 35f, (inRect.width / 4) - 10, 35f);

            Widgets.LabelCheckbox(stickyRect, "Fluffy.FilterSticky".Translate(), ref Sticky);


            // buttons
            if (Widgets.TextButton(new Rect(inRect.width / 4f + 5f, inRect.height - 35f, inRect.width / 4f - 10f, 35f),
                                   "Fluffy.Clear".Translate()))
            {
                Widgets_Filter.ResetFilter();
                Widgets_Filter.DisableFilter();
                MainTabWindow_Animals.IsDirty = true;
                Event.current.Use();
            }

            if (!Widgets_Filter.Filter)
            {
                if (Widgets.TextButton(new Rect(_x, inRect.height - 35f, inRect.width / 4f - 10f, 35f),
                                       "Fluffy.Enable".Translate()))
                {
                    Widgets_Filter.EnableFilter();
                    MainTabWindow_Animals.IsDirty = true;
                    Event.current.Use();
                }
            }
            else
            {
                if (Widgets.TextButton(new Rect(_x, inRect.height - 35f, inRect.width / 4f - 10f, 35f),
                                       "Fluffy.Disable".Translate()))
                {
                    Widgets_Filter.DisableFilter();
                    MainTabWindow_Animals.IsDirty = true;
                    Event.current.Use();
                }
            }


            if (Widgets.TextButton(new Rect(_x + inRect.width / 4, inRect.height - 35f, inRect.width / 4f - 10f, 35f),
                                   "OK".Translate()))
            {
                Find.WindowStack.TryRemove(this);
                Event.current.Use();
            }

            Text.Anchor = TextAnchor.UpperLeft;
        }
        protected override void BuildPawnList()
        {
            IEnumerable <Pawn> sorted;

            switch (Order)
            {
            case Orders.Default:
                sorted = from p in Find.ListerPawns.PawnsInFaction(Faction.OfColony)
                         where p.RaceProps.Animal
                         orderby p.RaceProps.petness descending, p.RaceProps.baseBodySize, p.def.label
                select p;
                break;

            case Orders.Name:
                sorted = from p in Find.ListerPawns.PawnsInFaction(Faction.OfColony)
                         where p.RaceProps.Animal
                         orderby p.Name.Numerical, p.Name.ToStringFull, p.def.label
                select p;
                break;

            case Orders.Gender:
                sorted = from p in Find.ListerPawns.PawnsInFaction(Faction.OfColony)
                         where p.RaceProps.Animal
                         orderby p.KindLabel, p.gender
                select p;
                break;

            case Orders.LifeStage:
                sorted = from p in Find.ListerPawns.PawnsInFaction(Faction.OfColony)
                         where p.RaceProps.Animal
                         orderby p.ageTracker.CurLifeStageRace.minAge descending, p.ageTracker.AgeBiologicalTicks descending
                select p;
                break;

            case Orders.Slaughter:
                sorted = from p in Find.ListerPawns.PawnsInFaction(Faction.OfColony)
                         where p.RaceProps.Animal
                         orderby Find.DesignationManager.DesignationOn(p, DesignationDefOf.Slaughter) != null descending, p.BodySize descending
                select p;

                break;

            case Orders.Training:
                bool dump;
                sorted = from p in Find.ListerPawns.PawnsInFaction(Faction.OfColony)
                         where p.RaceProps.Animal
                         orderby p.training.IsCompleted(TrainingOrder) descending, p.training.GetWanted(TrainingOrder) descending, p.training.CanAssignToTrain(TrainingOrder, out dump).Accepted descending
                select p;

                break;

            default:
                sorted = from p in Find.ListerPawns.PawnsInFaction(Faction.OfColony)
                         where p.RaceProps.Animal
                         orderby p.RaceProps.petness descending, p.RaceProps.baseBodySize, p.def.label
                select p;
                break;
            }

            Pawns = sorted.ToList();

            if (Widgets_Filter.Filter)
            {
                Pawns = Widgets_Filter.FilterAnimals(Pawns);
            }

            if (Asc && Pawns.Count > 1)
            {
                Pawns.Reverse();
            }

            IsDirty = false;
        }
        public override void DoWindowContents(Rect fillRect)
        {
            base.DoWindowContents(fillRect);
            Rect position = new Rect(0f, 0f, fillRect.width, 65f);

            GUI.BeginGroup(position);

            // ARRRGGHHH!!!
            // Allow other panels to trigger rebuilding the pawn list. (This took me forever to figure out...)
            if (IsDirty)
            {
                BuildPawnList();
            }


            Rect filterButton = new Rect(0f, 0f, 200f, Mathf.Round(position.height / 2f));

            Text.Font = GameFont.Small;
            if (Widgets.TextButton(filterButton, "Fluffy.Filter".Translate()))
            {
                if (Event.current.button == 0)
                {
                    Find.WindowStack.Add(new Dialog_FilterAnimals());
                }
                else if (Event.current.button == 1)
                {
                    List <PawnKindDef> list = Find.ListerPawns.PawnsInFaction(Faction.OfColony).Where(p => p.RaceProps.Animal)
                                              .Select(p => p.kindDef).Distinct().OrderBy(p => p.LabelCap).ToList();

                    if (list.Count > 0)
                    {
                        List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                        list2.AddRange(list.ConvertAll(p => new FloatMenuOption(p.LabelCap, delegate
                        {
                            Widgets_Filter.QuickFilterPawnKind(p);
                            IsDirty = true;
                        })));
                        Find.WindowStack.Add(new FloatMenu(list2));
                    }
                }
            }
            TooltipHandler.TipRegion(filterButton, "Fluffy.FilterTooltip".Translate());
            Rect filterIcon = new Rect(205f, (filterButton.height - 24f) / 2f, 24f, 24f);

            if (Widgets_Filter.Filter)
            {
                if (Widgets.ImageButton(filterIcon, FilterOffTex))
                {
                    Widgets_Filter.DisableFilter();
                    BuildPawnList();
                    SoundDefOf.ClickReject.PlayOneShotOnCamera();
                }
                TooltipHandler.TipRegion(filterIcon, "Fluffy.DisableFilter".Translate());
            }
            else if (Widgets_Filter.FilterPossible)
            {
                if (Widgets.ImageButton(filterIcon, FilterTex))
                {
                    Widgets_Filter.EnableFilter();
                    BuildPawnList();
                    SoundDefOf.Click.PlayOneShotOnCamera();
                }
                TooltipHandler.TipRegion(filterIcon, "Fluffy.EnableFilter".Translate());
            }

            float num = 175f;

            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.LowerCenter;
            Rect rectname = new Rect(0f, 0f, num, position.height + 3f);

            Widgets.Label(rectname, "Fluffy.Name".Translate());
            if (Widgets.InvisibleButton(rectname))
            {
                if (Order == Orders.Name)
                {
                    Asc = !Asc;
                }
                else
                {
                    Order = Orders.Name;
                    Asc   = false;
                }
                SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                BuildPawnList();
            }
            Rect highlightName = new Rect(0f, rectname.height - 30f, rectname.width, 30);

            TooltipHandler.TipRegion(highlightName, "Fluffy.SortByName".Translate());
            if (Mouse.IsOver(highlightName))
            {
                GUI.DrawTexture(highlightName, TexUI.HighlightTex);
            }

            Rect rect = new Rect(num, rectname.height - 30f, 90f, 30);

            Widgets.Label(rect, "Master".Translate());
            if (Widgets.InvisibleButton(rect))
            {
                SoundDefOf.AmountDecrement.PlayOneShotOnCamera();
                if (Order == Orders.Default)
                {
                    Asc = !Asc;
                }
                else
                {
                    Order = Orders.Default;
                    Asc   = false;
                }
                SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                BuildPawnList();
            }
            TooltipHandler.TipRegion(rect, "Fluffy.SortByPetness".Translate());
            if (Mouse.IsOver(rect))
            {
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }
            num += 90f;

            float x = 16f;

            Rect recta  = new Rect(num, rectname.height - 30f, 50f, 30f);
            Rect recta1 = new Rect(num + 9, 48f, x, x);

            GUI.DrawTexture(recta1, GenderTextures[1]);
            num += 25f;

            Rect recta2 = new Rect(num, 48f, x, x);

            GUI.DrawTexture(recta2, GenderTextures[2]);
            num += 25f;

            if (Widgets.InvisibleButton(recta))
            {
                if (Order == Orders.Gender)
                {
                    Asc = !Asc;
                }
                else
                {
                    Order = Orders.Gender;
                    Asc   = false;
                }
                SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                BuildPawnList();
            }
            TooltipHandler.TipRegion(recta, "Fluffy.SortByGender".Translate());
            if (Mouse.IsOver(recta))
            {
                GUI.DrawTexture(recta, TexUI.HighlightTex);
            }

            Rect rectb  = new Rect(num, rectname.height - 30f, 50f, 30f);
            Rect rectb1 = new Rect(num + 1, 48f, x, x);

            GUI.DrawTexture(rectb1, LifeStageTextures[0]);
            num += 17f;

            Rect rectb2 = new Rect(num, 48f, x, x);

            GUI.DrawTexture(rectb2, LifeStageTextures[1]);
            num += 16f;

            Rect rectb3 = new Rect(num, 48f, x, x);

            GUI.DrawTexture(rectb3, LifeStageTextures[2]);
            num += 17f;

            if (Widgets.InvisibleButton(rectb))
            {
                if (Order == Orders.LifeStage)
                {
                    Asc = !Asc;
                }
                else
                {
                    Order = Orders.LifeStage;
                    Asc   = false;
                }
                SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                BuildPawnList();
            }
            TooltipHandler.TipRegion(rectb, "Fluffy.SortByAge".Translate());
            if (Mouse.IsOver(rectb))
            {
                GUI.DrawTexture(rectb, TexUI.HighlightTex);
            }

            Rect rectc  = new Rect(num, rectname.height - 30f, 50f, 30f);
            Rect rectc1 = new Rect(num + 17f, 48f, 16f, 16f);

            GUI.DrawTexture(rectc1, SlaughterTex);
            if (Widgets.InvisibleButton(rectc1))
            {
                if (Event.current.shift)
                {
                    Widgets_Animals.SlaughterAllAnimals(Pawns);
                }
                else
                {
                    if (Order == Orders.Slaughter)
                    {
                        Asc = !Asc;
                    }
                    else
                    {
                        Order = Orders.Slaughter;
                        Asc   = false;
                    }
                    SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                    BuildPawnList();
                }
            }
            TooltipHandler.TipRegion(rectc, "Fluffy.SortByBodysizeSlaughter".Translate());
            if (Mouse.IsOver(rectc))
            {
                GUI.DrawTexture(rectc, TexUI.HighlightTex);
            }

            num += 50f;
            Rect headers = new Rect(num, rectname.height - 30f, 80f, 30f);

            Widgets_Animals.DoTrainingHeaders(headers, Pawns);

            num += 90f;

            Rect rect2 = new Rect(num, 0f, 350f, Mathf.Round(position.height / 2f));

            Text.Font = GameFont.Small;
            if (Widgets.TextButton(rect2, "ManageAreas".Translate()))
            {
                Find.WindowStack.Add(new Dialog_ManageAreas());
            }
            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.LowerCenter;
            Rect rect3 = new Rect(num, position.height - 27f, 350f, 30f);

            Widgets_Animals.DoAllowedAreaHeaders(rect3, Pawns, AllowedAreaMode.Animal);
            GUI.EndGroup();
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
            Rect outRect = new Rect(0f, position.height, fillRect.width, fillRect.height - position.height);

            DrawRows(outRect);
        }