Example #1
0
        private void DoContent(Rect rect)
        {
            // background
            Widgets.DrawMenuSection(rect);

            // cop out if nothing is selected.
            if (_selectedCurrent == null)
            {
                Label(rect, "FM.Livestock.SelectPawnKind".Translate(), TextAnchor.MiddleCenter);
                return;
            }

            // rects
            var optionsColumnRect = new Rect(
                rect.xMin,
                rect.yMin,
                rect.width * 3 / 5f,
                rect.height - Margin - ButtonSize.y);
            var animalsColumnRect = new Rect(
                optionsColumnRect.xMax,
                rect.yMin,
                rect.width * 2 / 5f,
                rect.height - Margin - ButtonSize.y);
            var buttonRect = new Rect(
                rect.xMax - ButtonSize.x,
                rect.yMax - ButtonSize.y,
                ButtonSize.x - Margin,
                ButtonSize.y - Margin);

            Vector2 position;
            float   width;

            Widgets_Section.BeginSectionColumn(optionsColumnRect, "Livestock.Options", out position, out width);

            Widgets_Section.Section(ref position, width, DrawTargetCountsSection, "FM.Livestock.TargetCountsHeader".Translate());
            Widgets_Section.Section(ref position, width, DrawTamingSection, "FM.Livestock.TamingHeader".Translate());
            Widgets_Section.Section(ref position, width, DrawButcherSection, "FM.Livestock.ButcherHeader".Translate());
            Widgets_Section.Section(ref position, width, DrawTrainingSection, "FM.Livestock.TrainingHeader".Translate());
            Widgets_Section.Section(ref position, width, DrawAreaRestrictionsSection, "FM.Livestock.AreaRestrictionsHeader".Translate());
            Widgets_Section.Section(ref position, width, DrawFollowSection, "FM.Livestock.FollowHeader".Translate());

            Widgets_Section.EndSectionColumn("Livestock.Options", position);

            // Start animals list
            // get our pawnkind
            Widgets_Section.BeginSectionColumn(animalsColumnRect, "Livestock.Animals", out position, out width);

            Widgets_Section.Section(ref position, width, DrawTamedAnimalSection, "FM.Livestock.AnimalsHeader".Translate("FML.Tame".Translate(), _selectedCurrent.Trigger.pawnKind.GetLabelPlural()).CapitalizeFirst());
            Widgets_Section.Section(ref position, width, DrawWildAnimalSection, "FM.Livestock.AnimalsHeader".Translate("FML.Wild".Translate(), _selectedCurrent.Trigger.pawnKind.GetLabelPlural()).CapitalizeFirst());

            Widgets_Section.EndSectionColumn("Livestock.Animals", position);


            // add / remove to the stack
            if (_selectedCurrent.Managed)
            {
                if (Widgets.ButtonText(buttonRect, "FM.Delete".Translate()))
                {
                    _selectedCurrent.Delete();
                    _selectedCurrent = null;
                    _onCurrentTab    = false;
                    Refresh();
                    return; // just skip to the next tick to avoid null reference errors.
                }

                TooltipHandler.TipRegion(buttonRect, "FMP.DeleteBillTooltip".Translate());
            }
            else
            {
                if (Widgets.ButtonText(buttonRect, "FM.Manage".Translate()))
                {
                    _selectedCurrent.Managed = true;
                    _onCurrentTab            = true;
                    Manager.For(manager).JobStack.Add(_selectedCurrent);
                    Refresh();
                }
                TooltipHandler.TipRegion(buttonRect, "FMP.ManageBillTooltip".Translate());
            }
        }
        private void DoContent(Rect rect)
        {
            // cop out if nothing is selected.
            if (_selectedCurrent == null)
            {
                return;
            }

            // background
            Widgets.DrawMenuSection(rect);

            // begin window
            GUI.BeginGroup(rect);
            rect = rect.AtZero();

            // rects
            var optionsColumnRect = new Rect(Utilities.Margin / 2,
                                             _topAreaHeight,
                                             rect.width / 2 - Utilities.Margin,
                                             rect.height - _topAreaHeight - Utilities.Margin - Utilities.ButtonSize.y);
            var animalsRect = new Rect(optionsColumnRect.xMax + Utilities.Margin,
                                       _topAreaHeight,
                                       rect.width / 2 - Utilities.Margin,
                                       rect.height - _topAreaHeight - Utilities.Margin - Utilities.ButtonSize.y);

            var optionsColumnTitle = new Rect(optionsColumnRect.xMin,
                                              0f,
                                              optionsColumnRect.width,
                                              _topAreaHeight);
            var animalsColumnTitle = new Rect(animalsRect.xMin,
                                              0f,
                                              animalsRect.width,
                                              _topAreaHeight);

            // backgrounds
            GUI.DrawTexture(optionsColumnRect, Resources.SlightlyDarkBackground);
            GUI.DrawTexture(animalsRect, Resources.SlightlyDarkBackground);

            // titles
            Utilities.Label(optionsColumnTitle, "FMP.Options".Translate(),
                            anchor: TextAnchor.LowerLeft, lrMargin: Utilities.Margin * 2, font: GameFont.Tiny);
            Utilities.Label(animalsColumnTitle, "FML.Animals".Translate(),
                            anchor: TextAnchor.LowerLeft, lrMargin: Utilities.Margin * 2, font: GameFont.Tiny);

            // options
            GUI.BeginGroup(optionsColumnRect);
            Vector2 cur         = Vector2.zero;
            var     optionIndex = 1;

            // counts header
            Utilities.Label(ref cur, optionsColumnRect.width, _entryHeight, "FML.TargetCounts".Translate(),
                            alt: optionIndex % 2 == 0);

            // counts table
            var   cols  = 3;
            float fifth = optionsColumnRect.width / 5;

            float[] widths  = { fifth, fifth * 2, fifth * 2 };
            float[] heights = { _entryHeight / 3 * 2, _entryHeight, _entryHeight };

            // set up a 3x3 table of rects
            var countRects = new Rect[cols, cols];

            for (var x = 0; x < cols; x++)
            {
                for (var y = 0; y < cols; y++)
                {
                    // kindof overkill for a 3x3 table, but ok.
                    countRects[x, y] = new Rect(widths.Take(x).Sum(), cur.y + heights.Take(y).Sum(), widths[x],
                                                heights[y]);
                    if (optionIndex % 2 == 0)
                    {
                        Widgets.DrawAltRect(countRects[x, y]);
                    }
                }
            }

            optionIndex++;

            // headers
            Utilities.Label(countRects[1, 0], Gender.Female.ToString(), null, TextAnchor.LowerCenter,
                            font: GameFont.Tiny);
            Utilities.Label(countRects[2, 0], Gender.Male.ToString(), null, TextAnchor.LowerCenter, font: GameFont.Tiny);
            Utilities.Label(countRects[0, 1], "FML.Adult".Translate(), null, TextAnchor.MiddleRight,
                            font: GameFont.Tiny);
            Utilities.Label(countRects[0, 2], "FML.Juvenile".Translate(), null, TextAnchor.MiddleRight,
                            font: GameFont.Tiny);

            // fields
            DoCountField(countRects[1, 1], Utilities_Livestock.AgeAndSex.AdultFemale);
            DoCountField(countRects[2, 1], Utilities_Livestock.AgeAndSex.AdultMale);
            DoCountField(countRects[1, 2], Utilities_Livestock.AgeAndSex.JuvenileFemale);
            DoCountField(countRects[2, 2], Utilities_Livestock.AgeAndSex.JuvenileMale);
            cur.y += 3 * _entryHeight;

            // restrict to area
            var restrictAreaRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);

            if (optionIndex % 2 == 0)
            {
                Widgets.DrawAltRect(restrictAreaRect);
            }
            Utilities.DrawToggle(restrictAreaRect, "FML.RestrictToArea".Translate(),
                                 ref _selectedCurrent.RestrictToArea);
            cur.y += _entryHeight;
            if (_selectedCurrent.RestrictToArea)
            {
                // area selectors table
                // set up a 3x3 table of rects
                var areaRects = new Rect[cols, cols];
                for (var x = 0; x < cols; x++)
                {
                    for (var y = 0; y < cols; y++)
                    {
                        // kindof overkill for a 3x3 table, but ok.
                        areaRects[x, y] = new Rect(widths.Take(x).Sum(), cur.y + heights.Take(y).Sum(), widths[x],
                                                   heights[y]);
                        if (optionIndex % 2 == 0)
                        {
                            Widgets.DrawAltRect(areaRects[x, y]);
                        }
                    }
                }

                // headers
                Utilities.Label(areaRects[1, 0], Gender.Female.ToString(), null, TextAnchor.LowerCenter,
                                font: GameFont.Tiny);
                Utilities.Label(areaRects[2, 0], Gender.Male.ToString(), null, TextAnchor.LowerCenter,
                                font: GameFont.Tiny);
                Utilities.Label(areaRects[0, 1], "FML.Adult".Translate(), null, TextAnchor.MiddleRight,
                                font: GameFont.Tiny);
                Utilities.Label(areaRects[0, 2], "FML.Juvenile".Translate(), null, TextAnchor.MiddleRight,
                                font: GameFont.Tiny);

                // do the selectors
                _selectedCurrent.RestrictArea[0] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[1, 1],
                                                                                         _selectedCurrent.RestrictArea[
                                                                                             0
                                                                                         ],
                                                                                         manager,
                                                                                         AllowedAreaMode.Animal,
                                                                                         Utilities.Margin);
                _selectedCurrent.RestrictArea[1] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[2, 1],
                                                                                         _selectedCurrent.RestrictArea[
                                                                                             1
                                                                                         ],
                                                                                         manager,
                                                                                         AllowedAreaMode.Animal,
                                                                                         Utilities.Margin);
                _selectedCurrent.RestrictArea[2] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[1, 2],
                                                                                         _selectedCurrent.RestrictArea[
                                                                                             2
                                                                                         ],
                                                                                         manager,
                                                                                         AllowedAreaMode.Animal,
                                                                                         Utilities.Margin);
                _selectedCurrent.RestrictArea[3] = AreaAllowedGUI.DoAllowedAreaSelectors(areaRects[2, 2],
                                                                                         _selectedCurrent.RestrictArea[
                                                                                             3
                                                                                         ],
                                                                                         manager,
                                                                                         AllowedAreaMode.Animal,
                                                                                         Utilities.Margin);

                cur.y += 3 * _entryHeight;
            }

            optionIndex++;

            // train
            Utilities.Label(ref cur, optionsColumnRect.width, _entryHeight, "FML.Training".Translate(),
                            alt: optionIndex % 2 == 0);
            var trainingRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);

            if (optionIndex++ % 2 == 0)
            {
                Widgets.DrawAltRect(trainingRect);
            }
            _selectedCurrent.DrawTrainingSelector(trainingRect, Utilities.Margin);
            cur.y += _entryHeight;

            if (_selectedCurrent.Training.Any)
            {
                var trainYoungRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);
                if (optionIndex++ % 2 == 0)
                {
                    Widgets.DrawAltRect(trainYoungRect);
                }
                Utilities.DrawToggle(trainYoungRect, "FML.TrainYoung".Translate(),
                                     ref _selectedCurrent.Training.TrainYoung);
                cur.y += _entryHeight;
            }

            // butchery stuff
            var butcherExcessRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);

            if (optionIndex++ % 2 == 0)
            {
                Widgets.DrawAltRect(butcherExcessRect);
            }
            Utilities.DrawToggle(butcherExcessRect, "FML.ButcherExcess".Translate(), ref _selectedCurrent.ButcherExcess);
            cur.y += _entryHeight;

            var butcherTrainedRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);

            if (optionIndex++ % 2 == 0)
            {
                Widgets.DrawAltRect(butcherTrainedRect);
            }
            Utilities.DrawToggle(butcherTrainedRect, "FML.ButcherTrained".Translate(),
                                 ref _selectedCurrent.ButcherTrained);
            cur.y += _entryHeight;

            // try tame more?
            var tameMoreRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);

            cur.y += _entryHeight;

            Utilities.DrawToggle(tameMoreRect, "FML.TameMore".Translate(), ref _selectedCurrent.TryTameMore);
            if (optionIndex % 2 == 0)
            {
                Widgets.DrawAltRect(tameMoreRect);
            }

            // area to train from (if taming more);
            if (_selectedCurrent.TryTameMore)
            {
                var tameAreaRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);
                if (optionIndex % 2 == 0)
                {
                    Widgets.DrawAltRect(tameAreaRect);
                }
                cur.y += _entryHeight;
                var tameAreaSelectorRect = new Rect(cur.x, cur.y, optionsColumnRect.width, _entryHeight);
                if (optionIndex % 2 == 0)
                {
                    Widgets.DrawAltRect(tameAreaSelectorRect);
                }
                cur.y += _entryHeight;

                Utilities.Label(tameAreaRect, "FML.TameArea".Translate());
                AreaAllowedGUI.DoAllowedAreaSelectors(tameAreaSelectorRect, ref _selectedCurrent.TameArea, manager,
                                                      AllowedAreaMode.Any, Utilities.Margin);

                // why am I getting an error for not being at upperleft? Oh well, force it.
                Text.Anchor = TextAnchor.UpperLeft;
            }
            optionIndex++;

            GUI.EndGroup(); // options

            // Start animals list
            // get our pawnkind
            PawnKindDef pawnKind = _onCurrentTab ? _selectedCurrent.Trigger.pawnKind : _selectedAvailable;

            if (pawnKind != null)
            {
                Rect viewRect = animalsRect;
                viewRect.height = _actualHeight;
                if (_actualHeight > animalsRect.height)
                {
                    viewRect.width -= 16f;
                }

                Widgets.BeginScrollView(animalsRect, ref _animalsScrollPosition, viewRect);
                GUI.BeginGroup(viewRect);
                cur = Vector2.zero;

                // tamed animals
                DrawAnimalListheader(ref cur, new Vector2(viewRect.width, _entryHeight / 3 * 2), pawnKind,
                                     "FML.Tame".Translate().CapitalizeFirst());
                List <Pawn> tame = pawnKind.GetTame(manager);
                if (tame.Count == 0)
                {
                    Utilities.Label(ref cur, viewRect.width, _entryHeight,
                                    "FML.NoAnimals".Translate("FML.Tame".Translate()),
                                    anchor: TextAnchor.MiddleCenter, color: Color.grey);
                }
                for (var i = 0; i < tame.Count; i++)
                {
                    DrawAnimalRow(ref cur, new Vector2(viewRect.width, _entryHeight), tame[i], i % 2 == 0);
                }

                cur.y += _entryHeight;

                // wild animals
                DrawAnimalListheader(ref cur, new Vector2(viewRect.width, _entryHeight / 3 * 2), pawnKind,
                                     "FML.Wild".Translate().CapitalizeFirst());
                List <Pawn> wild = pawnKind.GetWild(manager);
                if (wild.Count == 0)
                {
                    Utilities.Label(ref cur, viewRect.width, _entryHeight,
                                    "FML.NoAnimals".Translate("FML.Wild".Translate()), null, TextAnchor.MiddleCenter,
                                    color: Color.grey);
                }
                for (var i = 0; i < wild.Count; i++)
                {
                    DrawAnimalRow(ref cur, new Vector2(animalsRect.width, _entryHeight), wild[i], i % 2 == 0);
                }

                // update list height
                _actualHeight = cur.y;

                GUI.EndGroup(); // animals
                Widgets.EndScrollView();
            }

            // bottom button
            var buttonRect = new Rect(rect.xMax - Utilities.ButtonSize.x, rect.yMax - Utilities.ButtonSize.y,
                                      Utilities.ButtonSize.x - Utilities.Margin,
                                      Utilities.ButtonSize.y - Utilities.Margin);

            // add / remove to the stack
            if (_selectedCurrent.Managed)
            {
                if (Widgets.ButtonText(buttonRect, "FM.Delete".Translate()))
                {
                    _selectedCurrent.Delete();
                    _selectedCurrent = null;
                    _onCurrentTab    = false;
                    Refresh();
                    return; // just skip to the next tick to avoid null reference errors.
                }

                TooltipHandler.TipRegion(buttonRect, "FMP.DeleteBillTooltip".Translate());
            }
            else
            {
                if (Widgets.ButtonText(buttonRect, "FM.Manage".Translate()))
                {
                    _selectedCurrent.Managed = true;
                    _onCurrentTab            = true;
                    Manager.For(manager).JobStack.Add(_selectedCurrent);
                    Refresh();
                }
                TooltipHandler.TipRegion(buttonRect, "FMP.ManageBillTooltip".Translate());
            }

            GUI.EndGroup(); // window
        }