Exemple #1
0
        private void DrawThingRow(ref float y, float width, Thing thing, bool showDropButtonIfPrisoner = false)
        {
            Rect rect = new Rect(0f, y, width, _thingRowHeight);

            Widgets.InfoCardButton(rect.width - 24f, y, thing);
            rect.width -= 24f;
            if (CanControl || (SelPawnForGear.Faction == Faction.OfPlayer && SelPawnForGear.RaceProps.packAnimal) || (showDropButtonIfPrisoner && SelPawnForGear.IsPrisonerOfColony))
            {
                Rect dropRect = new Rect(rect.width - 24f, y, 24f, 24f);
                TooltipHandler.TipRegion(dropRect, "DropThing".Translate());
                if (Widgets.ButtonImage(dropRect, TexButton.Drop))
                {
                    SoundDefOf.Tick_High.PlayOneShotOnCamera();
                    InterfaceDrop(thing);
                }
                rect.width -= 24f;
            }
            if (this.CanControl && thing.IngestibleNow && base.SelPawn.RaceProps.CanEverEat(thing))
            {
                Rect   rect3     = new Rect(rect.width - 24f, y, 24f, 24f);
                string tipString = thing.def.ingestible.ingestCommandString.NullOrEmpty() ? "ConsumeThing".Translate(thing.LabelShort, thing) : string.Format(thing.def.ingestible.ingestCommandString, thing.LabelShort);
                TooltipHandler.TipRegion(rect3, tipString);
                if (Widgets.ButtonImage(rect3, TexButton.Ingest))
                {
                    SoundDefOf.Tick_High.PlayOneShotOnCamera();
                    this.InterfaceEatThis(thing);
                }
                rect.width -= 24f;
            }
            if (Mouse.IsOver(rect))
            {
                GUI.color = _highlightColor;
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }

            if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null)
            {
                Widgets.ThingIcon(new Rect(4f, y, _thingIconSize, _thingIconSize), thing);
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = _thingLabelColor;
            Rect   thingLabelRect = new Rect(_thingLeftX, y, rect.width - _thingLeftX, _thingRowHeight);
            string thingLabel     = thing.LabelCap;

            if ((thing is Apparel && SelPawnForGear.outfits != null && SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing)) ||
                (SelPawnForGear.inventory != null && SelPawnForGear.HoldTrackerIsHeld(thing)))
            {
                thingLabel = thingLabel + ", " + "ApparelForcedLower".Translate();
            }
            Widgets.Label(thingLabelRect, thingLabel);
            y += _thingRowHeight;

            TooltipHandler.TipRegion(thingLabelRect, thing.GetWeightAndBulkTip());
            // RMB menu
            if (Widgets.ButtonInvisible(thingLabelRect) && Event.current.button == 1)
            {
                List <FloatMenuOption> floatOptionList = new List <FloatMenuOption>();
                floatOptionList.Add(new FloatMenuOption("ThingInfo".Translate(), delegate
                {
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }, MenuOptionPriority.Default, null, null));
                if (CanControl)
                {
                    // Equip option
                    ThingWithComps eq = thing as ThingWithComps;
                    if (eq != null && eq.TryGetComp <CompEquippable>() != null)
                    {
                        CompInventory compInventory = SelPawnForGear.TryGetComp <CompInventory>();
                        if (compInventory != null)
                        {
                            FloatMenuOption equipOption;
                            string          eqLabel = GenLabel.ThingLabel(eq.def, eq.Stuff, 1);
                            if (SelPawnForGear.equipment.AllEquipmentListForReading.Contains(eq) && SelPawnForGear.inventory != null)
                            {
                                equipOption = new FloatMenuOption("CE_PutAway".Translate(eqLabel),
                                                                  new Action(delegate
                                {
                                    SelPawnForGear.equipment.TryTransferEquipmentToContainer(SelPawnForGear.equipment.Primary, SelPawnForGear.inventory.innerContainer);
                                }));
                            }
                            else if (!SelPawnForGear.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                            {
                                equipOption = new FloatMenuOption("CannotEquip".Translate(eqLabel), null);
                            }
                            else
                            {
                                string equipOptionLabel = "Equip".Translate(eqLabel);
                                if (eq.def.IsRangedWeapon && SelPawnForGear.story != null && SelPawnForGear.story.traits.HasTrait(TraitDefOf.Brawler))
                                {
                                    equipOptionLabel = equipOptionLabel + " " + "EquipWarningBrawler".Translate();
                                }
                                equipOption = new FloatMenuOption(
                                    equipOptionLabel,
                                    (SelPawnForGear.story != null && SelPawnForGear.story.WorkTagIsDisabled(WorkTags.Violent))
                                    ? null
                                    : new Action(delegate
                                {
                                    compInventory.TrySwitchToWeapon(eq);
                                }));
                            }
                            floatOptionList.Add(equipOption);
                        }
                    }
                    // Drop option
                    Action dropApparel = delegate
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                        InterfaceDrop(thing);
                    };
                    Action dropApparelHaul = delegate
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                        InterfaceDropHaul(thing);
                    };
                    if (this.CanControl && thing.IngestibleNow && base.SelPawn.RaceProps.CanEverEat(thing))
                    {
                        Action eatFood = delegate
                        {
                            SoundDefOf.Tick_High.PlayOneShotOnCamera();
                            InterfaceEatThis(thing);
                        };
                        string label = thing.def.ingestible.ingestCommandString.NullOrEmpty() ? "ConsumeThing".Translate(thing.LabelShort, thing) : string.Format(thing.def.ingestible.ingestCommandString, thing.LabelShort);
                        floatOptionList.Add(new FloatMenuOption(label, eatFood));
                    }
                    floatOptionList.Add(new FloatMenuOption("DropThing".Translate(), dropApparel));
                    floatOptionList.Add(new FloatMenuOption("CE_DropThingHaul".Translate(), dropApparelHaul));
                    if (this.CanControl && SelPawnForGear.HoldTrackerIsHeld(thing))
                    {
                        Action forgetHoldTracker = delegate
                        {
                            SoundDefOf.Tick_High.PlayOneShotOnCamera();
                            SelPawnForGear.HoldTrackerForget(thing);
                        };
                        floatOptionList.Add(new FloatMenuOption("CE_HoldTrackerForget".Translate(), forgetHoldTracker));
                    }
                }
                FloatMenu window = new FloatMenu(floatOptionList, thing.LabelCap, false);
                Find.WindowStack.Add(window);
            }
            // end menu
        }
        public override void LessonOnGUI()
        {
            Rect  mainRect = this.MainRect;
            float alpha    = 1f;

            if (this.doFadeIn)
            {
                alpha = Mathf.Clamp01(base.AgeSeconds / 0.4f);
            }
            if (this.Expiring)
            {
                float num = this.expiryTime - Time.timeSinceLevelLoad;
                if (num < 1.1f)
                {
                    alpha = num / 1.1f;
                }
            }
            WindowStack windowStack  = Find.WindowStack;
            int         id           = 134706;
            Rect        mainRect2    = mainRect;
            WindowLayer layer        = WindowLayer.Super;
            Action      doWindowFunc = delegate()
            {
                Rect rect = mainRect.AtZero();
                Text.Font = GameFont.Small;
                if (!this.Expiring)
                {
                    this.def.HighlightAllTags();
                }
                if (this.doFadeIn || this.Expiring)
                {
                    GUI.color = new Color(1f, 1f, 1f, alpha);
                }
                Widgets.DrawWindowBackgroundTutor(rect);
                Rect rect2 = rect.ContractedBy(10f);
                rect2.width = 432f;
                Widgets.Label(rect2, this.def.HelpTextAdjusted);
                Rect      butRect = new Rect(rect.xMax - 32f - 8f, rect.y + 8f, 32f, 32f);
                Texture2D tex;
                if (this.Expiring)
                {
                    tex = Widgets.CheckboxOnTex;
                }
                else
                {
                    tex = TexButton.CloseXBig;
                }
                if (Widgets.ButtonImage(butRect, tex, new Color(0.95f, 0.95f, 0.95f), new Color(0.8352941f, 0.6666667f, 0.274509817f)))
                {
                    SoundDefOf.Click.PlayOneShotOnCamera(null);
                    this.CloseButtonClicked();
                }
                if (Time.timeSinceLevelLoad > this.expiryTime)
                {
                    this.CloseButtonClicked();
                }
                GUI.color = Color.white;
            };
            bool  doBackground = false;
            float alpha2       = alpha;

            windowStack.ImmediateWindow(id, mainRect2, layer, doWindowFunc, doBackground, false, alpha2);
        }
Exemple #3
0
        public static void DrawFilters(Dialog_BillConfig __instance, Rect inRect)
        {
            var billRaw = (Bill_Production)BillGetter.GetValue(__instance);

            if (billRaw == null)
            {
                return;
            }

            Main.Instance.IsRootBillFilterBeingDrawn = false;

            var extendedBillDataStorage = Main.Instance.GetExtendedBillDataStorage();

            extendedBillDataStorage.MirrorBillToLinkedBills(billRaw);

            var extendedBillData = extendedBillDataStorage.GetExtendedDataFor(billRaw);

            if (extendedBillData == null)
            {
                return;
            }

            // Bill navigation buttons
            DrawWorkTableNavigation(__instance, billRaw, inRect);

            // Linked bill handling
            if (extendedBillDataStorage.IsLinkedBill(billRaw))
            {
                var unlinkRect = new Rect(inRect.xMin + 28f, inRect.yMin + 50f, 24f, 24f);
                if (Widgets.ButtonImage(unlinkRect, Resources.BreakLink))
                {
                    extendedBillDataStorage.RemoveBillFromLinkSets(billRaw);
                }
                TooltipHandler.TipRegion(unlinkRect, "IW.BreakLinkToOtherBillsTip".Translate());
            }

            // Bill renaming
            {
                var renameRect = new Rect(inRect.xMax - 75f, inRect.yMin + 4f, 24f, 24f);
                if (Widgets.ButtonImage(renameRect, Resources.Rename))
                {
                    Find.WindowStack.Add(new Dialog_RenameBill(extendedBillData, billRaw.LabelCap));
                }
                TooltipHandler.TipRegion(renameRect, "IW.RenameBillTip".Translate());
            }

            const float columnWidth  = 180f;
            const float middleColumn = columnWidth + 34f;

            // Allowed worker filter
            var potentialWorkers = GetAllowedWorkersWithSkillLevel(billRaw);

            if (potentialWorkers != null)
            {
                var anyoneText       = "IW.NoColRestrictionLabel".Translate();
                var workerButtonRect = new Rect(middleColumn + 3f, inRect.yMin + 18f,
                                                columnWidth, 30f);

                var currentWorkerLabel =
                    extendedBillData.Worker != null
                    ? "IW.RestrictToLabel".Translate() + " " + extendedBillData.Worker.NameStringShort.CapitalizeFirst()
                    : anyoneText;

                if (Widgets.ButtonText(workerButtonRect, currentWorkerLabel))
                {
                    var potentialWorkerList = new List <FloatMenuOption>
                    {
                        new FloatMenuOption(
                            anyoneText, delegate { extendedBillData.Worker = null; })
                    };

                    foreach (var allowedWorkerAndTheirSkill in potentialWorkers)
                    {
                        var allowedWorker = allowedWorkerAndTheirSkill.First;
                        var skillRecord   = allowedWorkerAndTheirSkill.Second;
                        var skillPrefix   = "";
                        if (skillRecord != null)
                        {
                            var    level = skillRecord.Level;
                            string passion;
                            switch (skillRecord.passion)
                            {
                            case Passion.Minor:
                                passion = "+";
                                break;

                            case Passion.Major:
                                passion = "++";
                                break;

                            default:
                                passion = "";
                                break;
                            }
                            skillPrefix = $"[{level}{passion}] ";
                        }
                        var nameWithSkill = $"{skillPrefix}" + "IW.RestrictToLabel".Translate() + " " + $"{allowedWorker}";

                        var workerMenuItem = new FloatMenuOption(nameWithSkill,
                                                                 delegate { extendedBillData.Worker = allowedWorker; });

                        potentialWorkerList.Add(workerMenuItem);
                    }

                    Find.WindowStack.Add(new FloatMenu(potentialWorkerList));
                }
                TooltipHandler.TipRegion(workerButtonRect, "IW.RestrictJobToSpecificColonistTip".Translate());
            }

            // Custom take to stockpile, overlay dummy button
            {
                var storeRect = new Rect(middleColumn + 3f, inRect.yMin + 114f,
                                         columnWidth, 30f);

                var label = extendedBillData.UsesTakeToStockpile()
                    ? extendedBillData.CurrentTakeToStockpileLabel()
                    : billRaw.storeMode.LabelCap;

                Widgets.ButtonText(storeRect, label);
                TooltipHandler.TipRegion(storeRect,
                                         "IW.CrafterWillToSpecificStockpileTip".Translate());
            }

            // Filter copy/paste buttons
            if (billRaw.ingredientFilter != null)
            {
                const float filterButtonWidth  = 96f;
                const float filterButtonHeight = 24f;
                var         oldFont            = Text.Font;
                Text.Font = GameFont.Tiny;

                var copyPasteHandler = Main.Instance.BillCopyPasteHandler;
                var copyButtonRect   = new Rect(inRect.xMax - filterButtonWidth * 2 + 4f, inRect.yMax - 35f,
                                                filterButtonWidth, filterButtonHeight);

                var parentFilter = billRaw.recipe?.fixedIngredientFilter;
                if (Widgets.ButtonText(copyButtonRect, "IW.CopyFilterButton".Translate()))
                {
                    copyPasteHandler.CopyFilter(billRaw.ingredientFilter, parentFilter);
                }
                TooltipHandler.TipRegion(copyButtonRect, "IW.CopyFilterTip".Translate());

                if (copyPasteHandler.IsMatchingFilterCopied(parentFilter))
                {
                    var pasteButtonRect = new Rect(copyButtonRect);
                    pasteButtonRect.xMin += filterButtonWidth + 4f;
                    pasteButtonRect.xMax += filterButtonWidth + 4f;
                    if (Widgets.ButtonText(pasteButtonRect, "IW.PasteFilterButton".Translate()))
                    {
                        copyPasteHandler.PasteCopiedFilterInto(billRaw.ingredientFilter);
                    }
                }

                Text.Font = oldFont;
            }

            if (!ExtendedBillDataStorage.CanOutputBeFiltered(billRaw))
            {
                return;
            }

            if (billRaw.repeatMode != BillRepeatModeDefOf.TargetCount)
            {
                return;
            }

            {
                var keyboardRect = new Rect(middleColumn + 90f, inRect.yMin + 208f, 24f, 24f);
                void TargetCountSetter(int i)
                {
                    billRaw.targetCount = i;
                    if (billRaw.unpauseWhenYouHave >= billRaw.targetCount)
                    {
                        billRaw.unpauseWhenYouHave = billRaw.targetCount - 1;
                    }
                }

                if (Widgets.ButtonImage(keyboardRect, Resources.Rename))
                {
                    Find.WindowStack.Add(new Dialog_NumericEntry(
                                             billRaw.targetCount,
                                             i => i > 0,
                                             TargetCountSetter));
                }
                TooltipHandler.TipRegion(keyboardRect, "IW.RenameTip".Translate());
            }

            const float buttonHeight      = 26f;
            const float smallButtonHeight = 24f;
            var         y = inRect.height - 248f + Text.LineHeight;

            // "Unpause when" level adjustment buttons
            if (billRaw.pauseWhenSatisfied)
            {
                var buttonWidth  = 42f;
                var minusOneRect = new Rect(middleColumn, inRect.height - 70, buttonWidth, smallButtonHeight);
                if (Widgets.ButtonText(minusOneRect, "-1"))
                {
                    if (billRaw.unpauseWhenYouHave > 0)
                    {
                        billRaw.unpauseWhenYouHave--;
                    }
                }

                var plusOneRect = new Rect(minusOneRect);
                plusOneRect.xMin += buttonWidth + 2f;
                plusOneRect.xMax += buttonWidth + 2f;
                if (Widgets.ButtonText(plusOneRect, "+1"))
                {
                    if (billRaw.unpauseWhenYouHave < billRaw.targetCount - 1)
                    {
                        billRaw.unpauseWhenYouHave++;
                    }
                }

                var keyboardRect = new Rect(plusOneRect.xMax + 2f, plusOneRect.yMin, 24f, 24f);
                if (Widgets.ButtonImage(keyboardRect, Resources.Rename))
                {
                    Find.WindowStack.Add(new Dialog_NumericEntry(
                                             billRaw.unpauseWhenYouHave,
                                             i => i < billRaw.targetCount,
                                             i => billRaw.unpauseWhenYouHave = i));
                }
                TooltipHandler.TipRegion(keyboardRect, "IW.RenameTip".Translate());
            }

            // Restrict counting to specific stockpile
            {
                y += 33;
                var subRect          = new Rect(0f, y, columnWidth, buttonHeight);
                var anyStockpileText = "IW.CountOnStockpilesText".Translate();
                var currentCountingStockpileLabel = extendedBillData.UsesCountingStockpile()
                    ? "IW.CountInText".Translate() + extendedBillData.GetCountingStockpile().label
                    : anyStockpileText;

                var map           = Find.VisibleMap;
                var allStockpiles =
                    map.zoneManager.AllZones.OfType <Zone_Stockpile>().ToList();

                if (Widgets.ButtonText(subRect, currentCountingStockpileLabel))
                {
                    var potentialStockpileList = new List <FloatMenuOption>
                    {
                        new FloatMenuOption(
                            anyStockpileText, delegate { extendedBillData.RemoveCountingStockpile(); })
                    };

                    foreach (var stockpile in allStockpiles)
                    {
                        var stockpileName = "IW.CountInText".Translate() + " " + stockpile.label;
                        var menuOption    = new FloatMenuOption(
                            stockpileName,
                            delegate { extendedBillData.SetCountingStockpile(stockpile); });

                        potentialStockpileList.Add(menuOption);
                    }

                    Find.WindowStack.Add(new FloatMenu(potentialStockpileList));
                }
                TooltipHandler.TipRegion(subRect,
                                         "IW.WillCountTowardsTargetTip".Translate());
            }

            var thingDef = billRaw.recipe.products.First().thingDef;

            if (!thingDef.CountAsResource)
            {
                // Counted items filter
                y += 33;
                var countedLabelRect = new Rect(0f, y, columnWidth, buttonHeight);
                Widgets.Label(countedLabelRect, "IW.CountedItemsFilter".Translate());
                y += Text.LineHeight;

                var filter = extendedBillData.OutputFilter;
                if (filter.allowedHitPointsConfigurable)
                {
                    var allowedHitPointsPercents = filter.AllowedHitPointsPercents;
                    var rect1 = new Rect(0f, y, columnWidth, buttonHeight);
                    Widgets.FloatRange(rect1, 10, ref allowedHitPointsPercents, 0f, 1f,
                                       "HitPoints", ToStringStyle.PercentZero);

                    TooltipHandler.TipRegion(rect1,
                                             "IW.HitPointsTip".Translate());
                    filter.AllowedHitPointsPercents = allowedHitPointsPercents;
                }

                if (filter.allowedQualitiesConfigurable)
                {
                    y += 33;
                    var rect2 = new Rect(0f, y, columnWidth, buttonHeight);
                    var allowedQualityLevels = filter.AllowedQualityLevels;
                    Widgets.QualityRange(rect2, 11, ref allowedQualityLevels);
                    TooltipHandler.TipRegion(rect2,
                                             "IW.QualityTip".Translate());
                    filter.AllowedQualityLevels = allowedQualityLevels;
                }
            }

            // Use input ingredients for counted items filter
            if (billRaw.ingredientFilter != null && thingDef.MadeFromStuff)
            {
                y += 33;
                var subRect = new Rect(0f, y, columnWidth, buttonHeight);
                Widgets.CheckboxLabeled(subRect, "IW.MatchInputIngredientsText".Translate(),
                                        ref extendedBillData.UseInputFilter);

                TooltipHandler.TipRegion(subRect,
                                         "IW.IngredientsTip".Translate());
            }


            // Deadmans clothing count filter
            if (thingDef.IsApparel)
            {
                var nonDeadmansApparelFilter = new SpecialThingFilterWorker_NonDeadmansApparel();
                if (!nonDeadmansApparelFilter.CanEverMatch(thingDef))
                {
                    // Thing can't be worn.
                    return;
                }

                y += 26;
                var rect3 = new Rect(0f, y, columnWidth, buttonHeight);
                Widgets.CheckboxLabeled(rect3, "IW.CountCorpseClothesLabel".Translate(),
                                        ref extendedBillData.AllowDeadmansApparel);
                TooltipHandler.TipRegion(rect3,
                                         "IW.CountCorpseClothesDesc".Translate());

                y += 26;
                var rect4 = new Rect(0f, y, columnWidth, buttonHeight);
                Widgets.CheckboxLabeled(rect4, "IW.CountEquippedClothesLabel".Translate(),
                                        ref extendedBillData.CountWornApparel);
                TooltipHandler.TipRegion(rect4,
                                         "IW.CountEquippedClothesDesc".Translate());
            }
        }
        public override void DoWindowContents(Rect inRect)
        {
            Vector2 vector  = new Vector2(inRect.width - 16f, 36f);
            Vector2 vector2 = new Vector2(100f, vector.y - 2f);

            inRect.height -= 45f;
            float num      = vector.y + 3f;
            float height   = (float)this.files.Count * num;
            Rect  viewRect = new Rect(0f, 0f, inRect.width - 16f, height);
            Rect  outRect  = new Rect(inRect.AtZero());

            outRect.height -= this.bottomAreaHeight;
            Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect, true);
            float num2 = 0f;
            int   num3 = 0;

            foreach (SaveFileInfo sfi in this.files)
            {
                if (num2 + vector.y >= this.scrollPosition.y && num2 <= this.scrollPosition.y + outRect.height)
                {
                    Rect rect = new Rect(0f, num2, vector.x, vector.y);
                    if (num3 % 2 == 0)
                    {
                        Widgets.DrawAltRect(rect);
                    }
                    Rect position = rect.ContractedBy(1f);
                    GUI.BeginGroup(position);
                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(sfi.FileInfo.Name);
                    GUI.color = this.FileNameColor(sfi);
                    Rect rect2 = new Rect(15f, 0f, position.width, position.height);
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Text.Font   = GameFont.Small;
                    Widgets.Label(rect2, fileNameWithoutExtension);
                    GUI.color = Color.white;
                    Rect rect3 = new Rect(270f, 0f, 200f, position.height);
                    Dialog_FileList.DrawDateAndVersion(sfi, rect3);
                    GUI.color   = Color.white;
                    Text.Anchor = TextAnchor.UpperLeft;
                    Text.Font   = GameFont.Small;
                    float num4  = vector.x - 2f - vector2.x - vector2.y;
                    Rect  rect4 = new Rect(num4, 0f, vector2.x, vector2.y);
                    if (Widgets.ButtonText(rect4, this.interactButLabel, true, false, true))
                    {
                        this.DoFileInteraction(Path.GetFileNameWithoutExtension(sfi.FileInfo.Name));
                    }
                    Rect rect5 = new Rect(num4 + vector2.x + 5f, 0f, vector2.y, vector2.y);
                    if (Widgets.ButtonImage(rect5, TexButton.DeleteX, Color.white, GenUI.SubtleMouseoverColor))
                    {
                        FileInfo localFile = sfi.FileInfo;
                        Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmDelete".Translate(new object[]
                        {
                            localFile.Name
                        }), delegate
                        {
                            localFile.Delete();
                            this.ReloadFiles();
                        }, true, null));
                    }
                    TooltipHandler.TipRegion(rect5, "DeleteThisSavegame".Translate());
                    GUI.EndGroup();
                }
                num2 += vector.y + 3f;
                num3++;
            }
            Widgets.EndScrollView();
            if (this.ShouldDoTypeInField)
            {
                this.DoTypeInField(inRect.AtZero());
            }
        }
        /* (ProfoundDarkness) I've intentionally left some code remarked in the following code because it's a useful guide on how to create
         * and maintain the transpilers that will do nearly identical changes to RimWorld's code for the other 2 PawnColumnWorkers.
         */
        public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
        {
            if (pawn.outfits == null)
            {
                return;
            }
            //changed: int num = Mathf.FloorToInt((rect.width - 4f) * 0.714285731f);
            int num = Mathf.FloorToInt((rect.width - 4f) - IconSize);
            //changed: int num2 = Mathf.FloorToInt((rect.width - 4f) * 0.2857143f);
            int   num2 = Mathf.FloorToInt(IconSize);
            float num3 = rect.x;
            //added:
            float num4 = rect.y + ((rect.height - IconSize) / 2);

            // Reduce width if we're adding a clear forced button
            bool somethingIsForced = pawn.HoldTrackerAnythingHeld();
            Rect loadoutButtonRect = new Rect(num3, rect.y + 2f, (float)num, rect.height - 4f);

            if (somethingIsForced)
            {
                loadoutButtonRect.width -= 4f + (float)num2;
            }

            // Main loadout button
            string label = pawn.GetLoadout().label.Truncate(loadoutButtonRect.width, null);

            Widgets.Dropdown <Pawn, Loadout>(loadoutButtonRect, pawn, (Pawn p) => p.GetLoadout(), new Func <Pawn, IEnumerable <Widgets.DropdownMenuElement <Loadout> > >(Button_GenerateMenu), label, null, null, null, null, true);

            // Clear forced button
            num3 += loadoutButtonRect.width;
            num3 += 4f;
            //changed: Rect forcedHoldRect = new Rect(num3, rect.y + 2f, (float)num2, rect.height - 4f);
            Rect forcedHoldRect = new Rect(num3, num4, (float)num2, (float)num2);

            if (somethingIsForced)
            {
                if (Widgets.ButtonImage(forcedHoldRect, ClearImage))
                {
                    pawn.HoldTrackerClear(); // yes this will also delete records that haven't been picked up and thus not shown to the player...
                }
                TooltipHandler.TipRegion(forcedHoldRect, new TipSignal(delegate
                {
                    string text = "CE_ForcedHold".Translate() + ":\n";
                    foreach (HoldRecord rec in LoadoutManager.GetHoldRecords(pawn))
                    {
                        if (!rec.pickedUp)
                        {
                            continue;
                        }
                        text = text + "\n   " + rec.thingDef.LabelCap + " x" + rec.count;
                    }
                    return(text);
                }, pawn.GetHashCode() * 613));
                num3 += (float)num2;
                num3 += 4f;
            }

            //changed: Rect assignTabRect = new Rect(num3, rect.y + 2f, (float)num2, rect.height - 4f);
            Rect assignTabRect = new Rect(num3, num4, (float)num2, (float)num2);

            //changed: if (Widgets.ButtonText(assignTabRect, "AssignTabEdit".Translate(), true, false, true))
            if (Widgets.ButtonImage(assignTabRect, EditImage))
            {
                Find.WindowStack.Add(new Dialog_ManageLoadouts(pawn.GetLoadout()));
            }
            // Added this next line.
            TooltipHandler.TipRegion(assignTabRect, new TipSignal(textGetter("CE_Loadouts"), pawn.GetHashCode() * 613));
            num3 += (float)num2;
        }
Exemple #6
0
        public Rect DoInterface(float x, float y, float width, int index)
        {
            Rect  rect = new Rect(x, y, width, 53f);
            float num  = 0f;

            if (!this.StatusString.NullOrEmpty())
            {
                num = Mathf.Max(17f, this.StatusLineMinHeight);
            }
            rect.height += num;
            Color white = Color.white;

            if (!this.ShouldDoNow())
            {
                white = new Color(1f, 0.7f, 0.7f, 0.7f);
            }
            GUI.color = white;
            Text.Font = GameFont.Small;
            if (index % 2 == 0)
            {
                Widgets.DrawAltRect(rect);
            }
            GUI.BeginGroup(rect);
            Rect butRect = new Rect(0f, 0f, 24f, 24f);

            if (this.billStack.IndexOf(this) > 0 && Widgets.ButtonImage(butRect, TexButton.ReorderUp, white))
            {
                this.billStack.Reorder(this, -1);
                SoundDefOf.TickHigh.PlayOneShotOnCamera(null);
            }
            if (this.billStack.IndexOf(this) < this.billStack.Count - 1)
            {
                Rect butRect2 = new Rect(0f, 24f, 24f, 24f);
                if (Widgets.ButtonImage(butRect2, TexButton.ReorderDown, white))
                {
                    this.billStack.Reorder(this, 1);
                    SoundDefOf.TickLow.PlayOneShotOnCamera(null);
                }
            }
            Rect rect2 = new Rect(28f, 0f, rect.width - 48f - 20f, rect.height + 5f);

            Widgets.Label(rect2, this.LabelCap);
            this.DoConfigInterface(rect.AtZero(), white);
            Rect rect3 = new Rect(rect.width - 24f, 0f, 24f, 24f);

            if (Widgets.ButtonImage(rect3, TexButton.DeleteX, white))
            {
                this.billStack.Delete(this);
            }
            Rect butRect3 = new Rect(rect3);

            butRect3.x -= butRect3.width + 4f;
            if (Widgets.ButtonImage(butRect3, TexButton.Suspend, white))
            {
                this.suspended = !this.suspended;
            }
            if (!this.StatusString.NullOrEmpty())
            {
                Text.Font = GameFont.Tiny;
                Rect rect4 = new Rect(24f, rect.height - num, rect.width - 24f, num);
                Widgets.Label(rect4, this.StatusString);
                this.DoStatusLineInterface(rect4);
            }
            GUI.EndGroup();
            if (this.suspended)
            {
                Text.Font   = GameFont.Medium;
                Text.Anchor = TextAnchor.MiddleCenter;
                Rect rect5 = new Rect(rect.x + rect.width / 2f - 70f, rect.y + rect.height / 2f - 20f, 140f, 40f);
                GUI.DrawTexture(rect5, TexUI.GrayTextBG);
                Widgets.Label(rect5, "SuspendedCaps".Translate());
                Text.Anchor = TextAnchor.UpperLeft;
                Text.Font   = GameFont.Small;
            }
            Text.Font = GameFont.Small;
            GUI.color = Color.white;
            return(rect);
        }
Exemple #7
0
        public static void DrawWorldList(ref Rect inRect, float margin, Vector2 closeButtonSize, List <UIEntry> worldEntries, List <UIEntry> saveGameEntries, Action <string> loadWorld, Action <string> deleteWorld, Action <string> convertWorld)
        {
            const int perRow = 3;
            var       gap    = (int)margin;

            inRect.width += gap;

            UITools.DrawBoxGridView(out _, out _, ref inRect, ref _scrollPosition, perRow, gap,
                                    (i, boxRect) =>
            {
                var selectedList = i >= worldEntries.Count ? saveGameEntries : worldEntries;
                i = i >= worldEntries.Count ? i - worldEntries.Count : i;

                var isWorldEntries    = selectedList == worldEntries;
                var isSaveGameEntries = selectedList == saveGameEntries;

                var currentItem = selectedList[i];

                Widgets.DrawAltRect(boxRect);

                if (isWorldEntries)
                {
                    var deleteSize = boxRect.width / 8;

                    var deleteRect = new Rect(boxRect.x + boxRect.width - deleteSize, boxRect.y, deleteSize,
                                              deleteSize);

                    if (Widgets.ButtonImage(deleteRect, DeleteX))
                    {
                        deleteWorld(currentItem.Path);
                    }

                    TooltipHandler.TipRegion(deleteRect,
                                             "FilUnderscore.PersistentRimWorlds.Delete.World".Translate());

                    DrawTexture(boxRect, OpenFolder, out var textureRect, 0.3f, 0.2f);

                    const float nameMargin = 4f;

                    var worldNameRect = new Rect(boxRect.x + nameMargin, boxRect.y + nameMargin,
                                                 boxRect.width - nameMargin - deleteSize, textureRect.y - boxRect.y);

                    DrawLabel(worldNameRect, ((WorldUIEntry)currentItem).Name, currentItem);
                }
                else if (isSaveGameEntries)
                {
                    DrawTexture(boxRect, ConvertFile, out var textureRect, 0.48f, 0.42f);

                    const float nameMargin = 4f;

                    var saveNameRect = new Rect(boxRect.x + nameMargin, boxRect.y + nameMargin,
                                                boxRect.width - nameMargin, textureRect.y - boxRect.y);

                    DrawLabel(saveNameRect, Path.GetFileNameWithoutExtension(((SaveGameUIEntry)currentItem).Path),
                              currentItem);
                }

                Widgets.DrawHighlightIfMouseover(boxRect);

                if (!Widgets.ButtonInvisible(boxRect))
                {
                    return(true);
                }

                if (isWorldEntries)
                {
                    loadWorld(selectedList[i].Path);
                }
                else if (isSaveGameEntries)
                {
                    convertWorld(selectedList[i].Path);
                }

                return(true);
            }, worldEntries.Count + saveGameEntries.Count, null, closeButtonSize);
        }
        protected override void DrawPawnRow(Rect rect, Pawn p)
        {
            // available space for row
            Rect rowRect = new Rect(rect.x + 175f, rect.y, rect.width - 175f, rect.height);

            // response button rect
            Vector2 responsePos = new Vector2(rowRect.xMin, rowRect.yMin + (rowRect.height - 24f) / 2f);

            // offset rest of row for that button, so we don't have to mess with all the other rect calculations
            rowRect.xMin += 24f + _margin;

            // label + buttons for outfit
            Rect outfitRect = new Rect(rowRect.xMin,
                                       rowRect.yMin,
                                       rowRect.width * (1f / 3f) + (_margin + _buttonSize) / 2f,
                                       rowRect.height);

            Rect labelOutfitRect = new Rect(outfitRect.xMin,
                                            outfitRect.yMin,
                                            outfitRect.width - _margin * 3 - _buttonSize * 2,
                                            outfitRect.height)
                                   .ContractedBy(_margin / 2f);
            Rect editOutfitRect = new Rect(labelOutfitRect.xMax + _margin,
                                           outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2),
                                           _buttonSize,
                                           _buttonSize);
            Rect forcedOutfitRect = new Rect(labelOutfitRect.xMax + _buttonSize + _margin * 2,
                                             outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2),
                                             _buttonSize,
                                             _buttonSize);

            // label + button for loadout
            Rect loadoutRect = new Rect(outfitRect.xMax,
                                        rowRect.yMin,
                                        rowRect.width * (1f / 3f) - (_margin + _buttonSize) / 2f,
                                        rowRect.height);
            Rect labelLoadoutRect = new Rect(loadoutRect.xMin,
                                             loadoutRect.yMin,
                                             loadoutRect.width - _margin * 2 - _buttonSize,
                                             loadoutRect.height)
                                    .ContractedBy(_margin / 2f);
            Rect editLoadoutRect = new Rect(labelLoadoutRect.xMax + _margin,
                                            loadoutRect.yMin + ((loadoutRect.height - _buttonSize) / 2),
                                            _buttonSize,
                                            _buttonSize);

            // fight or flight button
            HostilityResponseModeUtility.DrawResponseButton(responsePos, p);

            // weight + bulk indicators
            Rect weightRect = new Rect(loadoutRect.xMax, rowRect.yMin, rowRect.width * (1f / 6f) - _margin, rowRect.height).ContractedBy(_margin / 2f);
            Rect bulkRect   = new Rect(weightRect.xMax, rowRect.yMin, rowRect.width * (1f / 6f) - _margin, rowRect.height).ContractedBy(_margin / 2f);

            // OUTFITS
            // main button
            if (Widgets.ButtonText(labelOutfitRect, p.outfits.CurrentOutfit.label, true, false))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (Outfit current in Current.Game.outfitDatabase.AllOutfits)
                {
                    // need to create a local copy for delegate
                    Outfit localOut = current;
                    options.Add(new FloatMenuOption(localOut.label, delegate
                    {
                        p.outfits.CurrentOutfit = localOut;
                    }, MenuOptionPriority.Medium, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(options, optionalTitle, false));
            }

            // edit button
            TooltipHandler.TipRegion(editOutfitRect, "CR.EditX".Translate("CR.outfit".Translate() + " " + p.outfits.CurrentOutfit.label));
            if (Widgets.ButtonImage(editOutfitRect, _iconEdit))
            {
                Find.WindowStack.Add(new Dialog_ManageOutfits(p.outfits.CurrentOutfit));
            }

            // clear forced button
            if (p.outfits.forcedHandler.SomethingIsForced)
            {
                TooltipHandler.TipRegion(forcedOutfitRect, "ClearForcedApparel".Translate());
                if (Widgets.ButtonImage(forcedOutfitRect, _iconClearForced))
                {
                    p.outfits.forcedHandler.Reset();
                }
                TooltipHandler.TipRegion(forcedOutfitRect, new TipSignal(delegate
                {
                    string text = "ForcedApparel".Translate() + ":\n";
                    foreach (Apparel current2 in p.outfits.forcedHandler.ForcedApparel)
                    {
                        text = text + "\n   " + current2.LabelCap;
                    }
                    return(text);
                }, p.GetHashCode() * 612));
            }

            // LOADOUTS
            // main button
            if (Widgets.ButtonText(labelLoadoutRect, p.GetLoadout().LabelCap, true, false))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (Loadout loadout in LoadoutManager.Loadouts)
                {
                    // need to create a local copy for delegate
                    Loadout localLoadout = loadout;
                    options.Add(new FloatMenuOption(localLoadout.LabelCap, delegate
                    {
                        p.SetLoadout(localLoadout);
                    }, MenuOptionPriority.Medium, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(options, optionalTitle, false));
            }

            // edit button
            TooltipHandler.TipRegion(editLoadoutRect, "CR.EditX".Translate("CR.loadout".Translate() + " " + p.GetLoadout().LabelCap));
            if (Widgets.ButtonImage(editLoadoutRect, _iconEdit))
            {
                Find.WindowStack.Add(new Dialog_ManageLoadouts(p.GetLoadout()));
            }

            // STATUS BARS
            // fetch the comp
            CompInventory comp = p.TryGetComp <CompInventory>();

            if (comp != null)
            {
                Utility_Loadouts.DrawBar(bulkRect, comp.currentBulk, comp.capacityBulk, "", p.GetBulkTip());
                Utility_Loadouts.DrawBar(weightRect, comp.currentWeight, comp.capacityWeight, "", p.GetWeightTip());
            }
        }
        public override void DoWindowContents(Rect canvas)
        {
            // fix weird zooming bug
            Text.Font = GameFont.Small;

            base.DoWindowContents(canvas);

            // available space
            Rect header = new Rect(175f + 24f + _margin, _topArea - _rowHeight, canvas.width - 175f - 24f - _margin - 16f, _rowHeight);

            // label + buttons for outfit
            Rect outfitRect = new Rect(header.xMin,
                                       header.yMin,
                                       header.width * (1f / 3f) + (_margin + _buttonSize) / 2f,
                                       header.height);
            Rect labelOutfitRect = new Rect(outfitRect.xMin,
                                            outfitRect.yMin,
                                            outfitRect.width - _margin * 3 - _buttonSize * 2,
                                            outfitRect.height)
                                   .ContractedBy(_margin / 2f);
            Rect editOutfitRect = new Rect(labelOutfitRect.xMax + _margin,
                                           outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2),
                                           _buttonSize,
                                           _buttonSize);
            Rect forcedOutfitRect = new Rect(labelOutfitRect.xMax + _buttonSize + _margin * 2,
                                             outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2),
                                             _buttonSize,
                                             _buttonSize);

            // label + button for loadout
            Rect loadoutRect = new Rect(outfitRect.xMax,
                                        header.yMin,
                                        header.width * (1f / 3f) - (_margin + _buttonSize) / 2f,
                                        header.height);
            Rect labelLoadoutRect = new Rect(loadoutRect.xMin,
                                             loadoutRect.yMin,
                                             loadoutRect.width - _margin * 2 - _buttonSize,
                                             loadoutRect.height)
                                    .ContractedBy(_margin / 2f);
            Rect editLoadoutRect = new Rect(labelLoadoutRect.xMax + _margin,
                                            loadoutRect.yMin + ((loadoutRect.height - _buttonSize) / 2),
                                            _buttonSize,
                                            _buttonSize);

            // weight + bulk indicators
            Rect weightRect = new Rect(loadoutRect.xMax, header.yMin, header.width * (1f / 6f) - _margin, header.height).ContractedBy(_margin / 2f);
            Rect bulkRect   = new Rect(weightRect.xMax, header.yMin, header.width * (1f / 6f) - _margin, header.height).ContractedBy(_margin / 2f);

            // draw headers
            Text.Anchor = TextAnchor.LowerCenter;
            Widgets.Label(labelOutfitRect, "CurrentOutfit".Translate());
            TooltipHandler.TipRegion(editOutfitRect, "CR.EditX".Translate("CR.Outfits".Translate()));
            if (Widgets.ButtonImage(editOutfitRect, _iconEdit))
            {
                Find.WindowStack.Add(new Dialog_ManageOutfits(null));
            }
            Widgets.Label(labelLoadoutRect, "CR.CurrentLoadout".Translate());
            TooltipHandler.TipRegion(editLoadoutRect, "CR.EditX".Translate("CR.Loadouts".Translate()));
            if (Widgets.ButtonImage(editLoadoutRect, _iconEdit))
            {
                Find.WindowStack.Add(new Dialog_ManageLoadouts(null));
            }
            Widgets.Label(weightRect, "CR.Weight".Translate());
            Widgets.Label(bulkRect, "CR.Bulk".Translate());
            Text.Anchor = TextAnchor.UpperLeft;

            // draw the rows
            canvas.yMin += 45f;
            base.DrawRows(canvas);
        }
Exemple #10
0
        public override void DoWindowContents(Rect inRect)
        {
            //grab before anchor/font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;



            //Buildings
            int i = 0;

            foreach (BuildingFCDef building in buildingList)
            {
                newBuildingWindow = new Rect(BaseBuildingWindow.x, BaseBuildingWindow.y + (i * (rowHeight)) + scroll, BaseBuildingWindow.width, BaseBuildingWindow.height);
                newBuildingIcon   = new Rect(BaseBuildingIcon.x, BaseBuildingIcon.y + (i * (rowHeight)) + scroll, BaseBuildingIcon.width, BaseBuildingIcon.height);
                newBuildingLabel  = new Rect(BaseBuildingLabel.x, BaseBuildingLabel.y + (i * (rowHeight)) + scroll, BaseBuildingLabel.width, BaseBuildingLabel.height);
                newBuildingDesc   = new Rect(BaseBuildingDesc.x, BaseBuildingDesc.y + (i * (rowHeight)) + scroll, BaseBuildingDesc.width, BaseBuildingDesc.height);

                if (Widgets.ButtonInvisible(newBuildingWindow))
                {
                    //If click on building
                    List <FloatMenuOption> list = new List <FloatMenuOption>();

                    if (building == buildingDef)
                    {
                        //if the same building
                        list.Add(new FloatMenuOption("Destroy".Translate(), delegate
                        {
                            settlement.deconstructBuilding(buildingSlot);
                            Find.WindowStack.TryRemove(this);
                            Find.WindowStack.WindowOfType <settlementWindowFC>().WindowUpdateFC();
                        }));
                    }
                    else
                    {
                        //if not the same building
                        list.Add(new FloatMenuOption("Build".Translate(), delegate
                        {
                            if (settlement.validConstructBuilding(building, buildingSlot, settlement))
                            {
                                FCEvent tmpEvt         = new FCEvent(true);
                                tmpEvt.def             = FCEventDefOf.constructBuilding;
                                tmpEvt.source          = settlement.mapLocation;
                                tmpEvt.building        = building;
                                tmpEvt.buildingSlot    = buildingSlot;
                                tmpEvt.timeTillTrigger = Find.TickManager.TicksGame + building.constructionDuration;
                                Find.World.GetComponent <FactionFC>().addEvent(tmpEvt);

                                PaymentUtil.paySilver(Convert.ToInt32(building.cost));
                                settlement.deconstructBuilding(buildingSlot);
                                Messages.Message(building.label + " " + "WillBeConstructedIn".Translate() + " " + GenDate.ToStringTicksToDays(tmpEvt.timeTillTrigger - Find.TickManager.TicksGame), MessageTypeDefOf.PositiveEvent);
                                settlement.buildings[buildingSlot] = BuildingFCDefOf.Construction;
                                Find.WindowStack.TryRemove(this);
                                Find.WindowStack.WindowOfType <settlementWindowFC>().WindowUpdateFC();
                            }
                        }));
                    }



                    FloatMenu menu = new FloatMenu(list);
                    Find.WindowStack.Add(menu);
                }


                Widgets.DrawMenuSection(newBuildingWindow);
                Widgets.DrawMenuSection(newBuildingIcon);
                Widgets.DrawLightHighlight(newBuildingIcon);
                Widgets.ButtonImage(newBuildingIcon, building.icon);

                Text.Font = GameFont.Small;
                Widgets.ButtonTextSubtle(newBuildingLabel, "");
                Widgets.Label(newBuildingLabel, "  " + building.LabelCap + " - " + "Cost".Translate() + ": " + building.cost);

                Text.Font = GameFont.Tiny;
                Widgets.Label(newBuildingDesc, building.desc);



                i++;
            }


            //Top Window
            Widgets.DrawMenuSection(TopWindow);
            Widgets.DrawHighlight(TopWindow);
            Widgets.DrawMenuSection(TopIcon);
            Widgets.DrawLightHighlight(TopIcon);

            Widgets.DrawBox(new Rect(0, 0, 400, 500));
            Widgets.ButtonImage(TopIcon, buildingDef.icon);

            Widgets.ButtonTextSubtle(TopName, "");
            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.UpperLeft;
            Widgets.Label(new Rect(TopName.x + 5, TopName.y, TopName.width, TopName.height), buildingDef.LabelCap);

            Widgets.DrawMenuSection(new Rect(TopDescription.x - 5, TopDescription.y - 5, TopDescription.width, TopDescription.height));
            Text.Font = GameFont.Small;
            Widgets.Label(TopDescription, buildingDef.desc);

            Widgets.DrawLineHorizontal(0, TopWindow.y + TopWindow.height, 400);



            //reset anchor/font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;

            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y);
            }
        }
        private static void DrawCrossPromotions(ref Rect canvas, IEnumerable <CrossPromotion> promotions)
        {
            var backgroundRect = new Rect(
                canvas.xMin,
                canvas.yMin,
                canvas.width,
                PromotionsHeight);
            var outRect = backgroundRect.ContractedBy(SmallMargin / 2);
            var height  = (int)outRect.height;
            var width   = promotions.Sum(p => p.NormalizedWidth(height)) + (promotions.Count() - 1) * SmallMargin;

            if (width > outRect.width)
            {
                height -= 16;
                // recalculate total width
                width = promotions.Sum(p => p.NormalizedWidth(height)) + (promotions.Count() - 1) * SmallMargin;
            }
            var viewRect = new Rect(
                canvas.xMin,
                canvas.yMin,
                width,
                height);
            var pos = viewRect.min;

            canvas.yMin += PromotionsHeight + SmallMargin;

            Widgets.DrawBoxSolid(backgroundRect, SlightlyDarkBackground);
            if (Mouse.IsOver(outRect) && Event.current.type == EventType.ScrollWheel)
            {
                _scrollPosition.x += Event.current.delta.y * Constants.ScrollSpeed;
            }
            Widgets.BeginScrollView(outRect, ref _scrollPosition, viewRect);
            foreach (var promotion in promotions)
            {
                var normalizedWidth = promotion.NormalizedWidth(height);
                var rect            = new Rect(pos.x, pos.y, normalizedWidth, height);
                if (Widgets.ButtonImage(rect, promotion.Preview, new Color(.9f, .9f, .9f), Color.white))
                {
                    if (!promotion.Installed)
                    {
                        var options = Utilities.NewOptionsList;
                        options.Add(new FloatMenuOption(I18n.Subscribe(promotion.Name),
                                                        () => Workshop.Subscribe(promotion.FileId)));
                        options.Add(new FloatMenuOption(I18n.WorkshopPage(promotion.Name),
                                                        () => SteamUtility.OpenWorkshopPage(promotion.FileId)));
                        Utilities.FloatMenu(options);
                    }
                    else
                    {
                        var button = ModButtonManager.AllButtons.FirstOrDefault(b => b.Name == promotion.Name);
                        if (button != null)
                        {
                            Page_BetterModConfig.Instance.Selected = button;
                        }
                    }
                }
                TooltipHandler.TipRegion(rect, promotion.Name + "\n\n" + promotion.Description);
                pos.x += normalizedWidth + SmallMargin;
            }
            Widgets.EndScrollView();
        }
        void DrawSelectionArea(Rect rect)
        {
            Widgets.DrawMenuSection(rect);

            _filterUpdate();
            Rect filterRect = new Rect(rect.xMin + WindowMargin, rect.yMin + WindowMargin, rect.width - 3 * WindowMargin - 30f, 30f);
            Rect clearRect  = new Rect(filterRect.xMax + WindowMargin + 3f, rect.yMin + WindowMargin + 3f, 24f, 24f);

            _filterString = Widgets.TextField(filterRect, _filterString);
            if (_filterString != "")
            {
                if (Widgets.ButtonImage(clearRect, Widgets.CheckboxOffTex))
                {
                    _filterString = "";
                    Filter();
                }
            }

            Rect outRect = rect;

            outRect.yMin += 40f;
            outRect.xMax -= 2f; // some spacing around the scrollbar

            float viewWidth = SelectionHeight > outRect.height ? outRect.width - 16f : outRect.width;
            var   viewRect  = new Rect(0f, 0f, viewWidth, SelectionHeight);

            GUI.BeginGroup(outRect);
            Widgets.BeginScrollView(outRect.AtZero(), ref SelectionScrollPos, viewRect);

            if (CachedHelpCategories.Count(mc => mc.ShouldDraw) < 1)
            {
                Rect messageRect = outRect.AtZero();
                Widgets.Label(messageRect, "NoHelpDefs".Translate());
            }
            else
            {
                Vector2 cur = Vector2.zero;

                // This works fine for the current artificial three levels of helpdefs.
                // Can easily be adapted by giving each category a list of subcategories,
                // and migrating the responsibility for drawing them and the helpdefs to DrawCatEntry().
                // Would also require some minor adaptations to the filter methods, but nothing major.
                // - Fluffy.
                foreach (ModCategory mc in CachedHelpCategories.Where(mc => mc.ShouldDraw))
                {
                    DrawModEntry(ref cur, 0, viewRect, mc);

                    cur.x += EntryIndent;
                    if (mc.Expanded)
                    {
                        foreach (HelpCategoryDef hc in mc.HelpCategories.Where(hc => hc.ShouldDraw))
                        {
                            DrawCatEntry(ref cur, 1, viewRect, hc);

                            if (hc.Expanded)
                            {
                                foreach (HelpDef hd in hc.HelpDefs.Where(hd => hd.ShouldDraw))
                                {
                                    DrawHelpEntry(ref cur, 1, viewRect, hd);
                                }
                            }
                        }
                    }
                }

                SelectionHeight = cur.y;
            }

            Widgets.EndScrollView();
            GUI.EndGroup();
        }
        // RimWorld.CharacterCardUtility
        public static void DrawVampCard(Rect rect, Pawn pawn)
        {
            AdjustForLanguage();

            GUI.BeginGroup(rect);

            CompVampire compVampire = pawn.GetComp <CompVampire>();

            if (compVampire != null && (compVampire.IsVampire || compVampire.IsGhoul))
            {
                Rect rect7 = new Rect(CharacterCardUtility.PawnCardSize.x - 105f, 0f, 30f, 30f);
                TooltipHandler.TipRegion(rect7, new TipSignal("ROMV_CharacterSheet".Translate()));
                if (Widgets.ButtonImage(rect7, TexButton.ROMV_HumanIcon))
                {
                    HarmonyPatches.isSwitched = false;
                }

                if (compVampire.IsVampire)
                {
                    Rect rectVampOptions = new Rect(CharacterCardUtility.PawnCardSize.x - 105f, 150f, 30f, 30f);
                    switch (compVampire.CurrentSunlightPolicy)
                    {
                    case SunlightPolicy.Relaxed:
                        TooltipHandler.TipRegion(rectVampOptions, new TipSignal("ROMV_SP_Relaxed".Translate()));
                        if (Widgets.ButtonImage(rectVampOptions, TexButton.ROMV_SunlightPolicyRelaxed))
                        {
                            compVampire.CurrentSunlightPolicy = SunlightPolicy.Restricted;
                        }
                        break;

                    case SunlightPolicy.Restricted:
                        TooltipHandler.TipRegion(rectVampOptions, new TipSignal("ROMV_SP_Restricted".Translate()));
                        if (Widgets.ButtonImage(rectVampOptions, TexButton.ROMV_SunlightPolicyRestricted))
                        {
                            compVampire.CurrentSunlightPolicy = SunlightPolicy.NoAI;
                        }
                        break;

                    case SunlightPolicy.NoAI:
                        TooltipHandler.TipRegion(rectVampOptions, new TipSignal("ROMV_SP_NoAI".Translate()));
                        if (Widgets.ButtonImage(rectVampOptions, TexButton.ROMV_SunlightPolicyNoAI))
                        {
                            compVampire.CurrentSunlightPolicy = SunlightPolicy.Relaxed;
                        }
                        break;
                    }
                }

                NameTriple nameTriple      = pawn.Name as NameTriple;
                Rect       rectSkillsLabel = new Rect(rect.xMin, rect.yMin - 15, rect.width, HeaderSize);

                Text.Font = GameFont.Medium;
                Widgets.Label(rectSkillsLabel, pawn.Name.ToStringFull);
                Text.Font = GameFont.Small;
                string label    = (compVampire.IsGhoul) ? GhoulUtility.MainDesc(pawn)  : VampireUtility.MainDesc(pawn);
                Rect   rectDesc = new Rect(0f, 45f, rect.width, 60f);
                Widgets.Label(rectDesc, label);

                //                               Skills

                //Widgets.DrawLineHorizontal(rect.x - 10, rectSkillsLabel.yMax + Padding, rect.width - 15f);
                //---------------------------------------------------------------------

                Rect rectSkills     = new Rect(rect.x, rectDesc.yMax - 30 + Padding, rectSkillsLabel.width, SkillsColumnHeight);
                Rect rectInfoPane   = new Rect(rectSkills.x, rectSkills.y + Padding, SkillsColumnDivider, SkillsColumnHeight);
                Rect rectSkillsPane = new Rect(rectSkills.x + SkillsColumnDivider, rectSkills.y + Padding, rectSkills.width - SkillsColumnDivider, SkillsColumnHeight);

                LevelPane(rectInfoPane, compVampire);
                InfoPane(rectSkillsPane, compVampire);

                // LEVEL ________________             |
                // ||||||||||||||||||||||             |
                // Points Available 1                 |
                //

                float powersTextSize  = Text.CalcSize("ROMV_Disciplines".Translate()).x;
                Rect  rectPowersLabel = new Rect(rect.width / 2 - powersTextSize / 2, rectSkills.yMax + SectionOffset - 5, rect.width, HeaderSize);
                Text.Font = GameFont.Medium;
                Widgets.Label(rectPowersLabel, "ROMV_Disciplines".Translate().CapitalizeFirst());
                Text.Font = GameFont.Small;

                //Powers

                Widgets.DrawLineHorizontal(rect.x - 10, rectPowersLabel.yMax, rect.width - 15f);
                //---------------------------------------------------------------------


                float curY = rectPowersLabel.yMax;
                if (compVampire.Sheet.Pawn == null)
                {
                    compVampire.Sheet.Pawn = pawn;
                }
                if (compVampire.Sheet.Disciplines.NullOrEmpty())
                {
                    compVampire.Sheet.InitializeDisciplines();
                }
                for (int i = 0; i < compVampire.Sheet.Disciplines.Count; i++)
                {
                    Rect rectDisciplines = new Rect(rect.x + ButtonSize, curY, rectPowersLabel.width, ButtonSize + Padding);
                    PowersGUIHandler(rectDisciplines, compVampire, compVampire.Sheet.Disciplines[i]);
                    curY += ButtonSize + Padding * 2 + TextSize * 2;
                }
            }
            GUI.EndGroup();
        }
        public static void PowersGUIHandler(Rect inRect, CompVampire compVampire, Discipline discipline)
        {
            float buttonXOffset = inRect.x;

            if (discipline?.Def?.abilities is List <VitaeAbilityDef> abilities && !abilities.NullOrEmpty())
            {
                Rect rectLabel = new Rect(inRect.x - ButtonSize, inRect.y, inRect.width * 0.7f, TextSize);
                Text.Font = GameFont.Small;
                Widgets.Label(rectLabel, discipline.Def.LabelCap);
                Text.Font = GameFont.Small;
                int count    = 0;
                int pntCount = 0;

                foreach (VitaeAbilityDef ability in discipline.Def.abilities)
                {
                    Rect buttonRect = new Rect(buttonXOffset, rectLabel.yMax, VampButtonSize, VampButtonSize);
                    TooltipHandler.TipRegion(buttonRect, () => ability.LabelCap + "\n\n" + ability.description, 398452); //"\n\n" + "PJ_CheckStarsForMoreInfo".Translate()


                    Texture2D abilityTex        = ability.uiIcon;
                    bool      disabledForGhouls =
                        compVampire.IsGhoul && (int)compVampire.GhoulHediff.ghoulPower < discipline.Level;
                    if (disabledForGhouls)
                    {
                        GUI.color = Color.gray;
                    }
                    if (compVampire.AbilityPoints == 0 || discipline.Level >= 4)
                    {
                        Widgets.DrawTextureFitted(buttonRect, abilityTex, 1.0f);
                    }
                    else if (Widgets.ButtonImage(buttonRect, abilityTex) && compVampire.AbilityUser.Faction == Faction.OfPlayer)
                    {
                        if (compVampire.AbilityUser.story != null && compVampire.AbilityUser.story.WorkTagIsDisabled(WorkTags.Violent) && ability.MainVerb.isViolent)
                        {
                            Messages.Message("IsIncapableOfViolenceLower".Translate(new object[]
                            {
                                compVampire.parent.LabelShort
                            }), MessageTypeDefOf.RejectInput);
                            return;
                        }
                        if (disabledForGhouls)
                        {
                            Messages.Message("ROMV_DomitorVitaeIsTooWeak".Translate(new object[]
                            {
                                compVampire.parent.LabelShort
                            }), MessageTypeDefOf.RejectInput);
                            return;
                        }

                        discipline.Notify_PointsInvested(1); //LevelUpPower(power);
                        compVampire.Notify_UpdateAbilities();
                        compVampire.AbilityPoints -= 1;      //powerDef.abilityPoints;
                    }

                    float drawXOffset = buttonXOffset - ButtonSize;
                    float modifier    = 0f;
                    switch (count)
                    {
                    case 0: break;

                    case 1: modifier = 0.75f; break;

                    case 2: modifier = 0.72f; break;

                    case 3: modifier = 0.60f; break;
                    }
                    if (count != 0)
                    {
                        drawXOffset -= VampButtonPointSize * count * modifier;
                    }
                    else
                    {
                        drawXOffset -= 2;
                    }

                    for (int j = 0; j < count + 1; j++)
                    {
                        ++pntCount;
                        float drawYOffset = VampButtonSize + TextSize + Padding;
                        Rect  powerRegion = new Rect(inRect.x + drawXOffset + VampButtonPointSize * j, inRect.y + drawYOffset, VampButtonPointSize, VampButtonPointSize);
                        if (discipline.Points >= pntCount)
                        {
                            Widgets.DrawTextureFitted(powerRegion, TexButton.ROMV_PointFull, 1.0f);
                        }
                        else
                        {
                            Widgets.DrawTextureFitted(powerRegion, TexButton.ROMV_PointEmpty, 1.0f);
                        }

                        TooltipHandler.TipRegion(powerRegion, () => ability.GetDescription() + "\n" + compVampire.PostAbilityVerbCompDesc(ability.MainVerb), 398462);
                    }
                    ++count;
                    buttonXOffset += ButtonSize * 3f + Padding;
                    if (disabledForGhouls)
                    {
                        GUI.color = Color.white;
                    }
                }
            }
        }
        //Draw Filters
        public void DoFilter(Rect rect)
        {
            bool changed = false;

            Text.Font = GameFont.Medium;
            Rect headerRect = rect.TopPartPixels(Text.LineHeight);
            Rect filterRect = rect.BottomPartPixels(rect.height - Text.LineHeight);

            //Header
            Rect headerButRect = headerRect.RightPartPixels(Text.LineHeight).ContractedBy(2f);
            Rect labelRect     = new Rect(headerRect.x, headerRect.y, headerRect.width - Text.LineHeight * 2, headerRect.height);

            if (Widgets.ButtonImage(headerButRect, TexButton.CancelTex))
            {
                findDesc = new FindDescription();
                changed  = true;
            }
            TooltipHandler.TipRegion(headerButRect, "ClearAll".Translate().CapitalizeFirst());

            headerButRect.x -= Text.LineHeight;
            if (Widgets.ButtonImage(headerButRect, findDesc.locked ? TexButton.LockOn : TexButton.LockOff))
            {
                findDesc.locked = !findDesc.locked;
            }
            TooltipHandler.TipRegion(headerButRect, "TD.LockEditing".Translate());

            //Header Title
            Widgets.Label(labelRect, "TD.Listing".Translate() + findDesc.baseType.TranslateEnum());
            Widgets.DrawHighlightIfMouseover(labelRect);
            if (Widgets.ButtonInvisible(labelRect))
            {
                List <FloatMenuOption> types = new List <FloatMenuOption>();
                foreach (BaseListType type in Prefs.DevMode ? Enum.GetValues(typeof(BaseListType)) : BaseListNormalTypes.normalTypes)
                {
                    types.Add(new FloatMenuOption(type.TranslateEnum(), () => findDesc.baseType = type));
                }

                Find.WindowStack.Add(new FloatMenu(types)
                {
                    onCloseCallback = RemakeList
                });
            }

            Listing_StandardIndent listing = new Listing_StandardIndent()
            {
                maxOneColumn = true
            };

            listing.Begin(filterRect);

            /* maybe don't show name box
             * //Filter Name
             * Rect nameRect = listing.GetRect(Text.LineHeight);
             * WidgetRow nameRow = new WidgetRow(nameRect.x, nameRect.y);
             * nameRow.Label("TD.Name".Translate());
             * nameRect.xMin = nameRow.FinalX;
             * findDesc.name = Widgets.TextField(nameRect, findDesc.name);
             * listing.Gap();
             */
            listing.GapLine();


            //Draw Filters!!!
            Rect listRect = listing.GetRect(500);
            Listing_StandardIndent filterListing = new Listing_StandardIndent()
            {
                maxOneColumn = true
            };

            float viewWidth = listRect.width;

            if (scrollViewHeightFilt > listRect.height)
            {
                viewWidth -= 16f;
            }

            Rect viewRect = new Rect(0f, 0f, viewWidth, scrollViewHeightFilt);

            //Lock out input to filters.
            if (findDesc.locked &&
                Event.current.type != EventType.Repaint &&
                Event.current.type != EventType.Layout &&
                Event.current.type != EventType.Ignore &&
                Event.current.type != EventType.Used &&
                Mouse.IsOver(viewRect))
            {
                Event.current.Use();
            }

            filterListing.BeginScrollView(listRect, ref scrollPositionFilt, viewRect);

            //Draw Scrolling list:
            if (DoFilters(filterListing, findDesc.filters))
            {
                changed = true;
            }

            if (!findDesc.locked)
            {
                DrawAddRow(filterListing, findDesc);
            }

            filterListing.EndScrollView(ref viewRect);
            scrollViewHeightFilt = viewRect.height;


            //Extra options:
            bool newMaps = findDesc.allMaps;

            listing.CheckboxLabeled(
                "TD.AllMaps".Translate(),
                ref newMaps,
                "TD.CertainFiltersDontWorkForAllMaps-LikeZonesAndAreasThatAreObviouslySpecificToASingleMap".Translate());
            if (findDesc.allMaps != newMaps)
            {
                findDesc.allMaps = newMaps;
                changed          = true;
            }

            listing.GapLine();

            //Manage/Save/Load Buttons
            Rect savedRect = listing.GetRect(Text.LineHeight);

            savedRect = savedRect.LeftPart(0.25f);

            //Saved Filters
            if (Widgets.ButtonText(savedRect, "SaveButton".Translate()))
            {
                Find.WindowStack.Add(new Dialog_Name(findDesc.name, name => Settings.Get().Save(name, findDesc)));
            }

            savedRect.x += savedRect.width;
            if (Settings.Get().SavedNames().Count() > 0 &&
                Widgets.ButtonText(savedRect, "Load".Translate()))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (string name in Settings.Get().SavedNames())
                {
                    options.Add(new FloatMenuOption(name, () => findDesc = Settings.Get().Load(name)));
                }

                DoFloatMenu(options);
            }

            savedRect.x += savedRect.width * 2;
            if (Widgets.ButtonText(savedRect, "TD.ManageSaved".Translate()))
            {
                Find.WindowStack.Add(new Dialog_ManageSavedLists());
            }

            //Alerts
            Rect alertsRect = listing.GetRect(Text.LineHeight);

            alertsRect = alertsRect.LeftPart(0.25f);

            var comp = Current.Game.GetComponent <ListEverythingGameComp>();

            if (Widgets.ButtonText(alertsRect, "TD.MakeAlert".Translate()))
            {
                Find.WindowStack.Add(new Dialog_Name(findDesc.name,
                                                     name => comp.AddAlert(name, findDesc)));
            }

            alertsRect.x += alertsRect.width;
            if (comp.AlertNames().Count() > 0 &&
                Widgets.ButtonText(alertsRect, "TD.LoadAlert".Translate()))
            {
                List <FloatMenuOption> options = new List <FloatMenuOption>();
                foreach (string name in comp.AlertNames())
                {
                    options.Add(new FloatMenuOption(name, () => findDesc = comp.LoadAlert(name)));
                }

                DoFloatMenu(options);
            }

            alertsRect.x += alertsRect.width * 2;
            if (Widgets.ButtonText(alertsRect, "TD.ManageAlerts".Translate()))
            {
                Find.WindowStack.Add(new AlertByFindDialog());
            }



            //Global Options
            listing.CheckboxLabeled(
                "TD.OnlyShowFilterOptionsForAvailableThings".Translate(),
                ref ContentsUtility.onlyAvailable,
                "TD.ForExampleDontShowTheOptionMadeFromPlasteelIfNothingIsMadeFromPlasteel".Translate());

            listing.End();

            //Update if needed
            if (changed)
            {
                RemakeList();
            }
        }
 public void DoStatUpButton(Rect rect, Pawn pawn)
 {
     TooltipHandler.TipRegion(rect, Translator.Translate("LvTab_Distribute"));
     if (Widgets.ButtonImage(rect, harmony_patches.DistributeIMG, Color.white, GenUI.SubtleMouseoverColor))
     {
         PawnLvComp pawnlvcomp = pawn.TryGetComp <PawnLvComp>();
         if (pawnlvcomp != null)
         {
             if (Input.GetKey(KeyCode.LeftShift))
             {
                 for (int i = 0; i < 10; i++)
                 {
                     if (pawnlvcomp.StatPoint > 0)
                     {
                         pawnlvcomp.StatPoint -= 1;
                         pawnlvcomp.INT       += 1;
                     }
                 }
             }
             else if (Input.GetKey(KeyCode.LeftControl))
             {
                 for (int i = 0; i < 100; i++)
                 {
                     if (pawnlvcomp.StatPoint > 0)
                     {
                         pawnlvcomp.StatPoint -= 1;
                         pawnlvcomp.INT       += 1;
                     }
                 }
             }
             else if (Input.GetKey(KeyCode.LeftAlt))
             {
                 if (Input.GetKey(KeyCode.LeftShift))
                 {
                     int tempv = Math.Min(pawnlvcomp.INT - FP_RSLUM_setting.Startingstat_min, 10);
                     if (pawnlvcomp.INT > FP_RSLUM_setting.Startingstat_min)
                     {
                         pawnlvcomp.StatPoint += tempv;
                         pawnlvcomp.INT       -= tempv;
                     }
                 }
                 else if (Input.GetKey(KeyCode.LeftControl))
                 {
                     int tempv = Math.Min(pawnlvcomp.INT - FP_RSLUM_setting.Startingstat_min, 100);
                     if (pawnlvcomp.INT > FP_RSLUM_setting.Startingstat_min)
                     {
                         pawnlvcomp.StatPoint += tempv;
                         pawnlvcomp.INT       -= tempv;
                     }
                 }
                 else
                 {
                     if (pawnlvcomp.INT > FP_RSLUM_setting.Startingstat_min)
                     {
                         pawnlvcomp.StatPoint += 1;
                         pawnlvcomp.INT       -= 1;
                     }
                 }
             }
             else
             {
                 if (pawnlvcomp.StatPoint > 0)
                 {
                     pawnlvcomp.StatPoint -= 1;
                     pawnlvcomp.INT       += 1;
                 }
             }
         }
     }
 }
Exemple #17
0
        public static void DrawStorytellerSelectionInterface(Rect rect, ref StorytellerDef chosenStoryteller, ref DifficultyDef difficulty, Listing_Standard infoListing)
        {
            GUI.BeginGroup(rect);
            if (chosenStoryteller != null && chosenStoryteller.listVisible)
            {
                Rect position = new Rect(390f, rect.height - Storyteller.PortraitSizeLarge.y - 1f, Storyteller.PortraitSizeLarge.x, Storyteller.PortraitSizeLarge.y);
                GUI.DrawTexture(position, chosenStoryteller.portraitLargeTex);
                Widgets.DrawLineHorizontal(0f, rect.height, rect.width);
            }
            Rect outRect  = new Rect(0f, 0f, Storyteller.PortraitSizeTiny.x + 16f, rect.height);
            Rect viewRect = new Rect(0f, 0f, Storyteller.PortraitSizeTiny.x, (float)DefDatabase <StorytellerDef> .AllDefs.Count <StorytellerDef>() * (Storyteller.PortraitSizeTiny.y + 10f));

            Widgets.BeginScrollView(outRect, ref StorytellerUI.scrollPosition, viewRect, true);
            Rect rect2 = new Rect(0f, 0f, Storyteller.PortraitSizeTiny.x, Storyteller.PortraitSizeTiny.y);

            foreach (StorytellerDef storytellerDef in from tel in DefDatabase <StorytellerDef> .AllDefs
                     orderby tel.listOrder
                     select tel)
            {
                if (storytellerDef.listVisible)
                {
                    if (Widgets.ButtonImage(rect2, storytellerDef.portraitTinyTex))
                    {
                        TutorSystem.Notify_Event("ChooseStoryteller");
                        chosenStoryteller = storytellerDef;
                    }
                    if (chosenStoryteller == storytellerDef)
                    {
                        GUI.DrawTexture(rect2, StorytellerUI.StorytellerHighlightTex);
                    }
                    rect2.y += rect2.height + 8f;
                }
            }
            Widgets.EndScrollView();
            Text.Font = GameFont.Small;
            Rect rect3 = new Rect(outRect.xMax + 8f, 0f, 300f, 999f);

            Widgets.Label(rect3, "HowStorytellersWork".Translate());
            if (chosenStoryteller != null && chosenStoryteller.listVisible)
            {
                Rect rect4 = new Rect(outRect.xMax + 8f, outRect.yMin + 160f, 290f, 0f);
                rect4.height = rect.height - rect4.y;
                Text.Font    = GameFont.Medium;
                Rect rect5 = new Rect(rect4.x + 15f, rect4.y - 40f, 9999f, 40f);
                Widgets.Label(rect5, chosenStoryteller.label);
                Text.Anchor = TextAnchor.UpperLeft;
                Text.Font   = GameFont.Small;
                infoListing.Begin(rect4);
                infoListing.Label(chosenStoryteller.description, 160f, null);
                infoListing.Gap(6f);
                foreach (DifficultyDef difficultyDef in DefDatabase <DifficultyDef> .AllDefs)
                {
                    if (!difficultyDef.isExtreme || Prefs.ExtremeDifficultyUnlocked)
                    {
                        GUI.color = difficultyDef.drawColor;
                        string text   = difficultyDef.LabelCap;
                        bool   active = difficulty == difficultyDef;
                        string text2  = difficultyDef.description;
                        if (infoListing.RadioButton(text, active, 0f, text2))
                        {
                            difficulty = difficultyDef;
                        }
                        infoListing.Gap(3f);
                    }
                }
                GUI.color = Color.white;
                if (Current.ProgramState == ProgramState.Entry)
                {
                    infoListing.Gap(25f);
                    bool   flag   = Find.GameInitData.permadeathChosen && Find.GameInitData.permadeath;
                    bool   flag2  = Find.GameInitData.permadeathChosen && !Find.GameInitData.permadeath;
                    string text2  = "ReloadAnytimeMode".Translate();
                    bool   active = flag2;
                    string text   = "ReloadAnytimeModeInfo".Translate();
                    if (infoListing.RadioButton(text2, active, 0f, text))
                    {
                        Find.GameInitData.permadeathChosen = true;
                        Find.GameInitData.permadeath       = false;
                    }
                    infoListing.Gap(3f);
                    text   = "CommitmentMode".TranslateWithBackup("PermadeathMode");
                    active = flag;
                    text2  = "PermadeathModeInfo".Translate();
                    if (infoListing.RadioButton(text, active, 0f, text2))
                    {
                        Find.GameInitData.permadeathChosen = true;
                        Find.GameInitData.permadeath       = true;
                    }
                }
                infoListing.End();
            }
            GUI.EndGroup();
        }
Exemple #18
0
        public void DrawFilterControls(Rect canvas)
        {
            GUI.BeginGroup(canvas);

            string oldPhrase = _filterPhrase;

            if (!_inputChar.NullOrEmpty())
            {
                _filterPhrase += _inputChar;
                _inputChar     = "";
            }

            // check the toggle button
            if (Widgets.ButtonImage(RectFilterBtn, FilterIcon))
            {
                // flip the toggle
                _forceShowFilter = !(_forceShowFilter || !_filterPhrase.NullOrEmpty());
                if (!_forceShowFilter)
                {
                    ClearInput();
                }
            }

            if (FilterActive())
            {
                if (Widgets.ButtonImage(RectClearBtn, Widgets.CheckboxOffTex))
                {
                    ClearInput();
                }
                else
                {
                    // add a text widget with the current filter phrase
                    GUI.SetNextControlName(_filterInputName);

                    // focus the filter input field immediately if we're not already focused
                    if (GUI.GetNameOfFocusedControl() != _filterInputName)
                    {
                        _settingFocus = true;
                        GUI.FocusControl(_filterInputName);
                    }
                    else
                    {
                        // if the focus was just set, then the automatic behaviour is to select all the text
                        // we don't want that, so immediately deselect the text, and move the cursor to the end
                        if (_settingFocus)
                        {
                            TextEditor te = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                            te.SelectNone();
                            te.MoveTextEnd();
                            _settingFocus = false;
                        }
                    }

                    _filterPhrase = Widgets.TextField(RectFilter, _filterPhrase);
                }
            }
            else if (GUI.GetNameOfFocusedControl() == _filterInputName)
            {
                GUIUtility.keyboardControl = 0;
            }

            _filterDirty = (oldPhrase != _filterPhrase);
            if (_filterDirty)
            {
                _matchResults.Clear();
            }
            GUI.EndGroup();
        }
Exemple #19
0
        public static void DrawWorldSaveList(ref Rect inRect, float margin, Vector2 closeButtonSize, List <UIEntry> worldEntries,
                                             Action saveWorld, Action newWorld, Action <string> deleteWorld)
        {
            const int perRow = 3;
            var       gap    = (int)margin;

            inRect.width += gap;

            UITools.DrawBoxGridView(out _, out _, ref inRect, ref _scrollPosition, perRow, gap, (i, boxRect) =>
            {
                if (i >= worldEntries.Count)
                {
                    return(false);
                }

                var currentItem = worldEntries[i];

                var currentWorld = new DirectoryInfo(currentItem.Path).FullName.EqualsIgnoreCase(
                    PersistentWorldManager.GetInstance().PersistentWorld.LoadSaver
                    .GetWorldFolderPath());

                if (currentWorld)
                {
                    Widgets.DrawHighlight(boxRect);
                }
                else
                {
                    Widgets.DrawAltRect(boxRect);
                }

                var deleteSize = 0f;

                if (!currentWorld)
                {
                    deleteSize = boxRect.width / 8;

                    var deleteRect = new Rect(boxRect.x + boxRect.width - deleteSize, boxRect.y, deleteSize,
                                              deleteSize);

                    if (Widgets.ButtonImage(deleteRect, DeleteX))
                    {
                        deleteWorld(currentItem.Path);
                    }

                    TooltipHandler.TipRegion(deleteRect,
                                             "FilUnderscore.PersistentRimWorlds.Delete.World.Click".Translate());
                }

                DrawTexture(boxRect, OpenFolder, out var textureRect, 0.3f, 0.2f);

                const float nameMargin = 4f;

                var worldNameRect = new Rect(boxRect.x + nameMargin, boxRect.y + nameMargin,
                                             boxRect.width - nameMargin - deleteSize, textureRect.y - boxRect.y);

                DrawLabel(worldNameRect, ((WorldUIEntry)currentItem).Name, currentItem);

                Widgets.DrawHighlightIfMouseover(boxRect);

                if (!currentWorld)
                {
                    return(true);
                }

                if (Widgets.ButtonInvisible(boxRect))
                {
                    saveWorld();
                }

                return(true);
            }, worldEntries.Count + 1, (width, height) =>
            {
                var y = width * Mathf.Floor((float)worldEntries.Count / perRow) +
                        (worldEntries.Count / perRow) * gap;

                var boxRect = new Rect((width * (worldEntries.Count % perRow)) + (worldEntries.Count % perRow) * gap,
                                       y, width,
                                       width);

                Widgets.DrawHighlightIfMouseover(boxRect);
                Widgets.DrawAltRect(boxRect);

                if (Widgets.ButtonInvisible(boxRect))
                {
                    newWorld();
                }

                TooltipHandler.TipRegion(boxRect,
                                         "FilUnderscore.PersistentRimWorlds.Save.NewWorld".Translate());

                Widgets.DrawLine(new Vector2(boxRect.x + boxRect.width / 2, boxRect.y + boxRect.height / 3),
                                 new Vector2(boxRect.x + boxRect.width / 2, boxRect.y + boxRect.height * 0.66f), Color.white,
                                 1f);

                Widgets.DrawLine(new Vector2(boxRect.x + boxRect.width / 3, boxRect.y + boxRect.height / 2),
                                 new Vector2(boxRect.x + boxRect.width * 0.66f, boxRect.y + boxRect.height / 2), Color.white,
                                 1f);
            }, closeButtonSize);
        }
Exemple #20
0
        public void DrawPlot(Rect rect, int target = 0, string label = "", bool positiveOnly = false,
                             bool negativeOnly     = false)
        {
            // set sign
            int sign = negativeOnly ? -1 : 1;

            // subset chapters
            List <Chapter> chapters =
                _chaptersShown.Where(chapter => !positiveOnly || chapter.pages[periodShown].Any(i => i > 0))
                .Where(chapter => !negativeOnly || chapter.pages[periodShown].Any(i => i < 0))
                .ToList();

            // get out early if no chapters.
            if (chapters.Count == 0)
            {
                GUI.DrawTexture(rect.ContractedBy(Margin), Resources.SlightlyDarkBackground);
                Widgets_Labels.Label(rect, "FM.HistoryNoChapters".Translate(), TextAnchor.MiddleCenter, color: Color.grey);
                return;
            }

            // stuff we need
            Rect plot = rect.ContractedBy(Margin);

            plot.xMin += _yAxisMargin;

            // maximum of all chapters.
            int max =
                CeilToPrecision(Math.Max(chapters.Select(c => c.Max(periodShown, !negativeOnly)).Max(), target) *
                                1.2f);

            // size, and pixels per node.
            float w  = plot.width;
            float h  = plot.height;
            float wu = w / Size;           // width per section
            float hu = h / max;            // height per count
            int   bi = max / (Breaks + 1); // count per break
            float bu = hu * bi;            // height per break

            // plot the line(s)
            GUI.DrawTexture(plot, Resources.SlightlyDarkBackground);
            GUI.BeginGroup(plot);
            foreach (Chapter chapter in chapters)
            {
                chapter.Plot(periodShown, plot.AtZero(), wu, hu, sign);
            }

            // handle mouseover events
            if (Mouse.IsOver(plot.AtZero()))
            {
                // very conveniently this is the position within the current group.
                Vector2 pos  = Event.current.mousePosition;
                var     upos = new Vector2(pos.x / wu, (plot.height - pos.y) / hu);

                // get distances
                float[] distances =
                    chapters.Select(c => Math.Abs(c.ValueAt(periodShown, (int)upos.x, sign) - upos.y)).ToArray();

                // get the minimum index
                float min      = int.MaxValue;
                var   minIndex = 0;
                for (var i = 0; i < distances.Count(); i++)
                {
                    if (distances[i] < min)
                    {
                        minIndex = i;
                        min      = distances[i];
                    }
                }

                // closest line
                Chapter closest = chapters[minIndex];

                // do minimum stuff.
                var realpos  = new Vector2(pos.x, plot.height - closest.ValueAt(periodShown, (int)upos.x, sign) * hu);
                var blipRect = new Rect(realpos.x - SmallIconSize / 2f,
                                        realpos.y - SmallIconSize / 2f, SmallIconSize,
                                        SmallIconSize);
                GUI.color = closest.lineColor;
                GUI.DrawTexture(blipRect, Resources.StageB);
                GUI.color = DefaultLineColor;

                // get orientation of tooltip
                Vector2 tippos = realpos + new Vector2(Margin, Margin);
                string  tip    = chapters[minIndex].label + ": " +
                                 FormatCount(chapters[minIndex].ValueAt(periodShown, (int)upos.x, sign));
                Vector2 tipsize = Text.CalcSize(tip);
                bool    up = false, left = false;
                if (tippos.x + tipsize.x > plot.width)
                {
                    left      = true;
                    tippos.x -= tipsize.x + 2 * +Margin;
                }
                if (tippos.y + tipsize.y > plot.height)
                {
                    up        = true;
                    tippos.y -= tipsize.y + 2 * Margin;
                }

                var anchor = TextAnchor.UpperLeft;
                if (up && left)
                {
                    anchor = TextAnchor.LowerRight;
                }
                if (up && !left)
                {
                    anchor = TextAnchor.LowerLeft;
                }
                if (!up && left)
                {
                    anchor = TextAnchor.UpperRight;
                }
                var tooltipRect = new Rect(tippos.x, tippos.y, tipsize.x, tipsize.y);
                Widgets_Labels.Label(tooltipRect, tip, anchor: anchor, font: GameFont.Tiny);
            }

            // draw target line
            if (DrawTargetLine)
            {
                GUI.color = Color.gray;
                for (var i = 0; i < plot.width / DashLength; i += 2)
                {
                    Widgets.DrawLineHorizontal(i * DashLength, plot.height - target * hu, DashLength);
                }
            }

            // draw legend
            int lineCount = _chapters.Count;

            if (AllowTogglingLegend && lineCount > 1 && DrawInlineLegend)
            {
                var rowHeight  = 20f;
                var lineLength = 30f;
                var labelWidth = 100f;

                Vector2 cur = Vector2.zero;
                foreach (Chapter chapter in _chapters)
                {
                    GUI.color = chapter.lineColor;
                    Widgets.DrawLineHorizontal(cur.x, cur.y + rowHeight / 2f, lineLength);
                    cur.x += lineLength;
                    Widgets_Labels.Label(ref cur, labelWidth, rowHeight, chapter.label, font: GameFont.Tiny);
                    cur.x = 0f;
                }

                GUI.color = Color.white;
            }

            GUI.EndGroup();

            // plot axis
            GUI.BeginGroup(rect);
            Text.Anchor = TextAnchor.MiddleRight;
            Text.Font   = GameFont.Tiny;

            // draw ticks + labels
            for (var i = 1; i < Breaks + 1; i++)
            {
                Widgets.DrawLineHorizontal(_yAxisMargin + Margin / 2, plot.height - i * bu, Margin);
                var labRect = new Rect(0f, plot.height - i * bu - 4f, _yAxisMargin, 20f);
                Widgets.Label(labRect, FormatCount(i * bi));
            }

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

            rect = rect.AtZero(); // ugh, I'm tired, just work.

            // period / variables picker
            if (DrawOptions)
            {
                var switchRect = new Rect(rect.xMax - SmallIconSize - Margin,
                                          rect.yMin + Margin, SmallIconSize,
                                          SmallIconSize);

                Widgets.DrawHighlightIfMouseover(switchRect);
                if (Widgets.ButtonImage(switchRect, Resources.Cog))
                {
                    List <FloatMenuOption> options =
                        periods.Select(
                            p =>
                            new FloatMenuOption("FM.HistoryPeriod".Translate() + ": " + p.ToString(),
                                                delegate
                                                { periodShown = p; })).ToList();
                    if (AllowTogglingLegend && _chapters.Count > 1)   // add option to show/hide legend if appropriate.
                    {
                        options.Add(new FloatMenuOption("FM.HistoryShowHideLegend".Translate(),
                                                        delegate
                                                        { DrawInlineLegend = !DrawInlineLegend; }));
                    }
                    Find.WindowStack.Add(new FloatMenu(options));
                }
            }

            GUI.EndGroup();
        }
        public static void DrawCharacterCard(Rect rect, Pawn pawn, Action randomizeCallback = null, Rect creationRect = default(Rect))
        {
            bool flag = randomizeCallback != null;

            GUI.BeginGroup((!flag) ? rect : creationRect);
            Rect       rect2      = new Rect(0f, 0f, 300f, 30f);
            NameTriple nameTriple = pawn.Name as NameTriple;

            if (flag && nameTriple != null)
            {
                Rect rect3 = new Rect(rect2);
                rect3.width *= 0.333f;
                Rect rect4 = new Rect(rect2);
                rect4.width *= 0.333f;
                rect4.x     += rect4.width;
                Rect rect5 = new Rect(rect2);
                rect5.width *= 0.333f;
                rect5.x     += rect4.width * 2f;
                string first = nameTriple.First;
                string nick  = nameTriple.Nick;
                string last  = nameTriple.Last;
                CharacterCardUtility.DoNameInputRect(rect3, ref first, 12);
                if (nameTriple.Nick == nameTriple.First || nameTriple.Nick == nameTriple.Last)
                {
                    GUI.color = new Color(1f, 1f, 1f, 0.5f);
                }
                CharacterCardUtility.DoNameInputRect(rect4, ref nick, 9);
                GUI.color = Color.white;
                CharacterCardUtility.DoNameInputRect(rect5, ref last, 12);
                if (nameTriple.First != first || nameTriple.Nick != nick || nameTriple.Last != last)
                {
                    pawn.Name = new NameTriple(first, nick, last);
                }
                TooltipHandler.TipRegion(rect3, "FirstNameDesc".Translate());
                TooltipHandler.TipRegion(rect4, "ShortIdentifierDesc".Translate());
                TooltipHandler.TipRegion(rect5, "LastNameDesc".Translate());
            }
            else
            {
                rect2.width = 999f;
                Text.Font   = GameFont.Medium;
                Widgets.Label(rect2, pawn.Name.ToStringFull);
                Text.Font = GameFont.Small;
            }
            if (randomizeCallback != null)
            {
                Rect rect6 = new Rect(creationRect.width - 24f - 100f, 0f, 100f, rect2.height);
                if (Widgets.ButtonText(rect6, "Randomize".Translate(), true, false, true))
                {
                    SoundDefOf.TickTiny.PlayOneShotOnCamera(null);
                    randomizeCallback();
                }
                UIHighlighter.HighlightOpportunity(rect6, "RandomizePawn");
            }
            if (flag)
            {
                Widgets.InfoCardButton(creationRect.width - 24f, 0f, pawn);
            }
            else if (!pawn.health.Dead)
            {
                float num = CharacterCardUtility.PawnCardSize.x - 85f;
                if ((pawn.Faction == Faction.OfPlayer || pawn.IsPrisonerOfColony) && pawn.Spawned)
                {
                    Rect rect7 = new Rect(num, 0f, 30f, 30f);
                    TooltipHandler.TipRegion(rect7, PawnBanishUtility.GetBanishButtonTip(pawn));
                    if (Widgets.ButtonImage(rect7, TexButton.Banish))
                    {
                        if (pawn.Downed)
                        {
                            Messages.Message("MessageCantBanishDownedPawn".Translate(new object[]
                            {
                                pawn.LabelShort
                            }).AdjustedFor(pawn), pawn, MessageTypeDefOf.RejectInput);
                        }
                        else
                        {
                            PawnBanishUtility.ShowBanishPawnConfirmationDialog(pawn);
                        }
                    }
                    num -= 40f;
                }
                if (pawn.IsColonist)
                {
                    Rect rect8 = new Rect(num, 0f, 30f, 30f);
                    TooltipHandler.TipRegion(rect8, "RenameColonist".Translate());
                    if (Widgets.ButtonImage(rect8, TexButton.Rename))
                    {
                        Find.WindowStack.Add(new Dialog_ChangeNameTriple(pawn));
                    }
                    num -= 40f;
                }
            }
            string label = pawn.MainDesc(true);
            Rect   rect9 = new Rect(0f, 45f, rect.width, 60f);

            Widgets.Label(rect9, label);
            TooltipHandler.TipRegion(rect9, () => pawn.ageTracker.AgeTooltipString, 6873641);
            Rect position  = new Rect(0f, 100f, 250f, 450f);
            Rect position2 = new Rect(position.xMax, 100f, 258f, 450f);

            GUI.BeginGroup(position);
            float num2 = 0f;

            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, 0f, 200f, 30f), "Backstory".Translate());
            num2     += 30f;
            Text.Font = GameFont.Small;
            foreach (BackstorySlot backstorySlot in Enum.GetValues(typeof(BackstorySlot)))
            {
                Backstory backstory = pawn.story.GetBackstory(backstorySlot);
                if (backstory != null)
                {
                    Rect rect10 = new Rect(0f, num2, position.width, 24f);
                    if (Mouse.IsOver(rect10))
                    {
                        Widgets.DrawHighlight(rect10);
                    }
                    TooltipHandler.TipRegion(rect10, backstory.FullDescriptionFor(pawn));
                    Text.Anchor = TextAnchor.MiddleLeft;
                    string str = (backstorySlot != BackstorySlot.Adulthood) ? "Childhood".Translate() : "Adulthood".Translate();
                    Widgets.Label(rect10, str + ":");
                    Text.Anchor = TextAnchor.UpperLeft;
                    Rect rect11 = new Rect(rect10);
                    rect11.x     += 90f;
                    rect11.width -= 90f;
                    string title = backstory.Title;
                    Widgets.Label(rect11, title);
                    num2 += rect10.height + 2f;
                }
            }
            num2     += 25f;
            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, num2, 200f, 30f), "IncapableOf".Translate());
            num2     += 30f;
            Text.Font = GameFont.Small;
            StringBuilder stringBuilder            = new StringBuilder();
            WorkTags      combinedDisabledWorkTags = pawn.story.CombinedDisabledWorkTags;

            if (combinedDisabledWorkTags == WorkTags.None)
            {
                stringBuilder.Append("(" + "NoneLower".Translate() + "), ");
            }
            else
            {
                List <WorkTags> list  = CharacterCardUtility.WorkTagsFrom(combinedDisabledWorkTags).ToList <WorkTags>();
                bool            flag2 = true;
                foreach (WorkTags current in list)
                {
                    if (flag2)
                    {
                        stringBuilder.Append(current.LabelTranslated().CapitalizeFirst());
                    }
                    else
                    {
                        stringBuilder.Append(current.LabelTranslated());
                    }
                    stringBuilder.Append(", ");
                    flag2 = false;
                }
            }
            string text = stringBuilder.ToString();

            text = text.Substring(0, text.Length - 2);
            Rect rect12 = new Rect(0f, num2, position.width, 999f);

            Widgets.Label(rect12, text);
            num2     += 100f;
            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, num2, 200f, 30f), "Traits".Translate());
            num2     += 30f;
            Text.Font = GameFont.Small;
            for (int i = 0; i < pawn.story.traits.allTraits.Count; i++)
            {
                Trait trait  = pawn.story.traits.allTraits[i];
                Rect  rect13 = new Rect(0f, num2, position.width, 24f);
                if (Mouse.IsOver(rect13))
                {
                    Widgets.DrawHighlight(rect13);
                }
                Widgets.Label(rect13, trait.LabelCap);
                num2 += rect13.height + 2f;
                Trait     trLocal = trait;
                TipSignal tip     = new TipSignal(() => trLocal.TipString(pawn), (int)num2 * 37);
                TooltipHandler.TipRegion(rect13, tip);
            }
            GUI.EndGroup();
            GUI.BeginGroup(position2);
            Text.Font = GameFont.Medium;
            Widgets.Label(new Rect(0f, 0f, 200f, 30f), "Skills".Translate());
            SkillUI.SkillDrawMode mode;
            if (Current.ProgramState == ProgramState.Playing)
            {
                mode = SkillUI.SkillDrawMode.Gameplay;
            }
            else
            {
                mode = SkillUI.SkillDrawMode.Menu;
            }
            SkillUI.DrawSkillsOf(pawn, new Vector2(0f, 35f), mode);
            GUI.EndGroup();
            GUI.EndGroup();
        }
        public static void DoMainMenuControls(Rect rect, bool anyMapFiles)
        {
            GUI.BeginGroup(rect);
            Rect rect2 = new Rect(0f, 0f, 170f, rect.height);
            Rect rect3 = new Rect(rect2.xMax + 17f, 0f, 145f, rect.height);

            Text.Font = GameFont.Small;
            List <ListableOption> list = new List <ListableOption>();

            if (Current.ProgramState == ProgramState.Entry)
            {
                string label;
                if (!"Tutorial".CanTranslate())
                {
                    label = "LearnToPlay".Translate();
                }
                else
                {
                    label = "Tutorial".Translate();
                }
                list.Add(new ListableOption(label, delegate
                {
                    MainMenuDrawer.InitLearnToPlay();
                }, null));
                list.Add(new ListableOption("NewColony".Translate(), delegate
                {
                    Find.WindowStack.Add(new Page_SelectScenario());
                }, null));
            }
            if (Current.ProgramState == ProgramState.Playing && !Current.Game.Info.permadeathMode)
            {
                list.Add(new ListableOption("Save".Translate(), delegate
                {
                    MainMenuDrawer.CloseMainTab();
                    Find.WindowStack.Add(new Dialog_SaveFileList_Save());
                }, null));
            }
            ListableOption item;

            if (anyMapFiles && (Current.ProgramState != ProgramState.Playing || !Current.Game.Info.permadeathMode))
            {
                item = new ListableOption("LoadGame".Translate(), delegate
                {
                    MainMenuDrawer.CloseMainTab();
                    Find.WindowStack.Add(new Dialog_SaveFileList_Load());
                }, null);
                list.Add(item);
            }
            if (Current.ProgramState == ProgramState.Playing)
            {
                list.Add(new ListableOption("ReviewScenario".Translate(), delegate
                {
                    WindowStack arg_29_0       = Find.WindowStack;
                    string fullInformationText = Find.Scenario.GetFullInformationText();
                    string name = Find.Scenario.name;
                    arg_29_0.Add(new Dialog_MessageBox(fullInformationText, null, null, null, null, name, false, null, null));
                }, null));
            }
            item = new ListableOption("Options".Translate(), delegate
            {
                MainMenuDrawer.CloseMainTab();
                Find.WindowStack.Add(new Dialog_Options());
            }, "MenuButton-Options");
            list.Add(item);
            if (Current.ProgramState == ProgramState.Entry)
            {
                item = new ListableOption("Mods".Translate(), delegate
                {
                    Find.WindowStack.Add(new Page_ModsConfig());
                }, null);
                list.Add(item);
                if (Prefs.DevMode && LanguageDatabase.activeLanguage == LanguageDatabase.defaultLanguage && LanguageDatabase.activeLanguage.anyError)
                {
                    item = new ListableOption("SaveTranslationReport".Translate(), delegate
                    {
                        LanguageReportGenerator.SaveTranslationReport();
                    }, null);
                    list.Add(item);
                }
                item = new ListableOption("Credits".Translate(), delegate
                {
                    Find.WindowStack.Add(new Screen_Credits());
                }, null);
                list.Add(item);
            }
            if (Current.ProgramState == ProgramState.Playing)
            {
                if (Current.Game.Info.permadeathMode)
                {
                    item = new ListableOption("SaveAndQuitToMainMenu".Translate(), delegate
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
                            MemoryUtility.ClearAllMapsAndWorld();
                        }, "Entry", "SavingLongEvent", false, null);
                    }, null);
                    list.Add(item);
                    item = new ListableOption("SaveAndQuitToOS".Translate(), delegate
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
                            LongEventHandler.ExecuteWhenFinished(delegate
                            {
                                Root.Shutdown();
                            });
                        }, "SavingLongEvent", false, null);
                    }, null);
                    list.Add(item);
                }
                else
                {
                    Action action = delegate
                    {
                        if (GameDataSaveLoader.CurrentGameStateIsValuable)
                        {
                            Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmQuit".Translate(), delegate
                            {
                                GenScene.GoToMainMenu();
                            }, true, null));
                        }
                        else
                        {
                            GenScene.GoToMainMenu();
                        }
                    };
                    item = new ListableOption("QuitToMainMenu".Translate(), action, null);
                    list.Add(item);
                    Action action2 = delegate
                    {
                        if (GameDataSaveLoader.CurrentGameStateIsValuable)
                        {
                            Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmQuit".Translate(), delegate
                            {
                                Root.Shutdown();
                            }, true, null));
                        }
                        else
                        {
                            Root.Shutdown();
                        }
                    };
                    item = new ListableOption("QuitToOS".Translate(), action2, null);
                    list.Add(item);
                }
            }
            else
            {
                item = new ListableOption("QuitToOS".Translate(), delegate
                {
                    Root.Shutdown();
                }, null);
                list.Add(item);
            }
            OptionListingUtility.DrawOptionListing(rect2, list);
            Text.Font = GameFont.Small;
            List <ListableOption> list2 = new List <ListableOption>();
            ListableOption        item2 = new ListableOption_WebLink("FictionPrimer".Translate(), "https://rimworldgame.com/backstory", TexButton.IconBlog);

            list2.Add(item2);
            item2 = new ListableOption_WebLink("LudeonBlog".Translate(), "https://ludeon.com/blog", TexButton.IconBlog);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("Forums".Translate(), "https://ludeon.com/forums", TexButton.IconForums);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("OfficialWiki".Translate(), "https://rimworldwiki.com", TexButton.IconBlog);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("TynansTwitter".Translate(), "https://twitter.com/TynanSylvester", TexButton.IconTwitter);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("TynansDesignBook".Translate(), "https://tynansylvester.com/book", TexButton.IconBook);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("HelpTranslate".Translate(), MainMenuDrawer.TranslationsContributeURL, TexButton.IconForums);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("BuySoundtrack".Translate(), "http://www.lasgameaudio.co.uk/#!store/t04fw", TexButton.IconSoundtrack);
            list2.Add(item2);
            float num = OptionListingUtility.DrawOptionListing(rect3, list2);

            GUI.BeginGroup(rect3);
            if (Current.ProgramState == ProgramState.Entry && Widgets.ButtonImage(new Rect(0f, num + 10f, 64f, 32f), LanguageDatabase.activeLanguage.icon))
            {
                List <FloatMenuOption> list3 = new List <FloatMenuOption>();
                foreach (LoadedLanguage current in LanguageDatabase.AllLoadedLanguages)
                {
                    LoadedLanguage localLang = current;
                    list3.Add(new FloatMenuOption(localLang.FriendlyNameNative, delegate
                    {
                        LanguageDatabase.SelectLanguage(localLang);
                        Prefs.Save();
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list3));
            }
            GUI.EndGroup();
            GUI.EndGroup();
        }
        public override void DoWindowContents(Rect borderRect)
        {
            float buttons_left;
            {
                var button_rects = Enumerable.Range(0, int.MaxValue).Select(delegate(int x) {
                    float right = borderRect.width - 32f - (32f * x);
                    return(new Rect(right - 24f, 3f, 24f, 24f));
                }).GetEnumerator();

                //duplicate window button
                button_rects.MoveNext();
                if (Widgets.ButtonImage(button_rects.Current, ConsoleTexturePool.Get("Console/DuplicateConsoleWindowButton")))
                {
                    //button pressed
                    Find.WindowStack.Add(new ConsoleWindow(console.target));
                }

                //new window button
                button_rects.MoveNext();
                if (Widgets.ButtonImage(button_rects.Current, ConsoleTexturePool.Get("Console/NewConsoleWindowButton")))
                {
                    MakeNewWindowMenu();
                }

                buttons_left = button_rects.Current.xMin;
            }

            Rect consoleRect = new Rect(borderRect);

            consoleRect.yMin += titlebarHeight;
            consoleRect.yMax -= statusbarHeight;
            consoleRect       = consoleRect.ContractedBy(consoleMargin);

            int id = GUIUtility.GetControlID(controlIDHint, FocusType.Keyboard, consoleRect);

            switch (Event.current.type)
            {
            case EventType.Repaint:
                //title
                Rect titleRect  = new Rect(8f, 2f, buttons_left - 8f, titlebarHeight - 2f);
                var  titleStyle = new GUIStyle(Text.fontStyles[(int)GameFont.Small]);
                titleStyle.alignment = TextAnchor.MiddleLeft;
                titleStyle.wordWrap  = false;
                GUI.color            = new Color(1f, 1f, 1f);
                GUI.Label(titleRect, console.title, titleStyle);
                //console
                DrawConsole(consoleRect);
                break;

            case EventType.MouseDown:
                GUIUtility.keyboardControl = id;
                break;

            case EventType.KeyDown:
                if (GUIUtility.keyboardControl != id)
                {
                    break;
                }
                bool use = true;
                switch (Event.current.keyCode)
                {
                case KeyCode.Return:
                case KeyCode.KeypadEnter:
                    console.ProcessInput();
                    break;

                case KeyCode.Delete:
                    console.DeleteChar(false);
                    break;

                case KeyCode.Backspace:
                    console.DeleteChar(true);
                    break;

                case KeyCode.LeftArrow:
                    console.EditorCursor--;
                    break;

                case KeyCode.RightArrow:
                    console.EditorCursor++;
                    break;

                case KeyCode.UpArrow:
                    console.CurrentInputIndex--;
                    break;

                case KeyCode.DownArrow:
                    console.CurrentInputIndex++;
                    break;

                default:
                    char c = Event.current.character;
                    if (ConsoleTextureCacheRenderer.UnityFont.HasCharacter(c))
                    {
                        console.InputChar(c);
                    }
                    else if (c == '\0')
                    {
                    }
                    else
                    {
                        Log.Message(((int)Event.current.character).ToString()); use = false;
                    }
                    break;
                }
                if (use)
                {
                    Event.current.Use();
                }
                break;
            }
        }
Exemple #24
0
        private void DrawThingRow(ref float y, float width, Thing thing, bool showDropButtonIfPrisoner = false)
        {
            Rect rect = new Rect(0f, y, width, _thingRowHeight);

            Widgets.InfoCardButton(rect.width - 24f, y, thing);
            rect.width -= 24f;
            if (CanControl || (SelPawnForGear.Faction == Faction.OfPlayer && SelPawnForGear.RaceProps.packAnimal) || (showDropButtonIfPrisoner && SelPawnForGear.IsPrisonerOfColony))
            {
                Rect dropRect = new Rect(rect.width - 24f, y, 24f, 24f);
                TooltipHandler.TipRegion(dropRect, "DropThing".Translate());
                if (Widgets.ButtonImage(dropRect, TexButton.Drop))
                {
                    SoundDefOf.Tick_High.PlayOneShotOnCamera();
                    InterfaceDrop(thing);
                }
                rect.width -= 24f;
            }
            if (CanControlColonist)
            {
                if ((thing.def.IsNutritionGivingIngestible || thing.def.IsNonMedicalDrug) && thing.IngestibleNow && base.SelPawn.WillEat(thing, null) && (!SelPawnForGear.IsTeetotaler() || !thing.def.IsNonMedicalDrug))
                {
                    Rect rect3 = new Rect(rect.width - 24f, y, 24f, 24f);
                    TooltipHandler.TipRegion(rect3, "ConsumeThing".Translate(thing.LabelNoCount, thing));
                    if (Widgets.ButtonImage(rect3, TexButton.Ingest))
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
                        InterfaceIngest(thing);
                    }
                }
                rect.width -= 24f;
            }
            Rect rect4 = rect;

            rect4.xMin = rect4.xMax - 60f;
            CaravanThingsTabUtility.DrawMass(thing, rect4);
            rect.width -= 60f;
            if (Mouse.IsOver(rect))
            {
                GUI.color = _highlightColor;
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }

            if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null)
            {
                Widgets.ThingIcon(new Rect(4f, y, _thingIconSize, _thingIconSize), thing, 1f);
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = ThingLabelColor;
            Rect   thingLabelRect = new Rect(_thingLeftX, y, rect.width - _thingLeftX, _thingRowHeight);
            string thingLabel     = thing.LabelCap;

            if ((thing is Apparel && SelPawnForGear.outfits != null && SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing)) ||
                (SelPawnForGear.inventory != null && SelPawnForGear.HoldTrackerIsHeld(thing)))
            {
                thingLabel = thingLabel + ", " + "ApparelForcedLower".Translate();
            }

            Text.WordWrap = false;
            Widgets.Label(thingLabelRect, thingLabel.Truncate(thingLabelRect.width, null));
            Text.WordWrap = true;
            string text2 = string.Concat(new object[]
            {
                thing.LabelCap,
                "\n",
                thing.DescriptionDetailed,
                "\n",
                thing.GetWeightAndBulkTip()
            });

            if (thing.def.useHitPoints)
            {
                string text3 = text2;
                text2 = string.Concat(new object[]
                {
                    text3,
                    "\n",
                    "HitPointsBasic".Translate().CapitalizeFirst(),
                    ": ",
                    thing.HitPoints,
                    " / ",
                    thing.MaxHitPoints
                });
            }
            TooltipHandler.TipRegion(thingLabelRect, text2);
            y += 28f;

            // RMB menu
            if (Widgets.ButtonInvisible(thingLabelRect) && Event.current.button == 1)
            {
                List <FloatMenuOption> floatOptionList = new List <FloatMenuOption>();
                floatOptionList.Add(new FloatMenuOption("ThingInfo".Translate(), delegate
                {
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }, MenuOptionPriority.Default, null, null));
                if (CanControl)
                {
                    // Equip option
                    ThingWithComps eq = thing as ThingWithComps;
                    if (eq != null && eq.TryGetComp <CompEquippable>() != null)
                    {
                        CompInventory  compInventory = SelPawnForGear.TryGetComp <CompInventory>();
                        CompBiocodable compBiocoded  = eq.TryGetComp <CompBiocodable>();
                        if (compInventory != null)
                        {
                            FloatMenuOption equipOption;
                            string          eqLabel = GenLabel.ThingLabel(eq.def, eq.Stuff, 1);
                            if (compBiocoded != null && compBiocoded.Biocoded && compBiocoded.CodedPawn != SelPawnForGear)
                            {
                                equipOption = new FloatMenuOption("CannotEquip".Translate(eqLabel) + ": " + "BiocodedCodedForSomeoneElse".Translate(), null);
                            }
                            else if (SelPawnForGear.equipment.AllEquipmentListForReading.Contains(eq) && SelPawnForGear.inventory != null)
                            {
                                equipOption = new FloatMenuOption("CE_PutAway".Translate(eqLabel),
                                                                  new Action(delegate
                                {
                                    SelPawnForGear.equipment.TryTransferEquipmentToContainer(SelPawnForGear.equipment.Primary, SelPawnForGear.inventory.innerContainer);
                                }));
                            }
                            else if (!SelPawnForGear.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                            {
                                equipOption = new FloatMenuOption("CannotEquip".Translate(eqLabel), null);
                            }
                            else
                            {
                                string equipOptionLabel = "Equip".Translate(eqLabel);
                                if (eq.def.IsRangedWeapon && SelPawnForGear.story != null && SelPawnForGear.story.traits.HasTrait(TraitDefOf.Brawler))
                                {
                                    equipOptionLabel = equipOptionLabel + " " + "EquipWarningBrawler".Translate();
                                }
                                equipOption = new FloatMenuOption(
                                    equipOptionLabel,
                                    (SelPawnForGear.story != null && SelPawnForGear.WorkTagIsDisabled(WorkTags.Violent))
                                    ? null
                                    : new Action(delegate
                                {
                                    compInventory.TrySwitchToWeapon(eq);
                                }));
                            }
                            floatOptionList.Add(equipOption);
                        }
                    }
                    //Reload apparel option
                    foreach (var apparel in SelPawnForGear?.apparel?.WornApparel)
                    {
                        var compReloadable = apparel.TryGetComp <CompReloadable>();
                        if (compReloadable != null && compReloadable.AmmoDef == thing.def && compReloadable.NeedsReload(true))
                        {
                            if (!SelPawnForGear.Drafted)    //TODO-1.2 This should be doable for drafted pawns as well, but the job does nothing. Figure out what's wrong and remove this condition.
                            {
                                FloatMenuOption reloadApparelOption = new FloatMenuOption(
                                    "CE_ReloadApparel".Translate(apparel.Label, thing.Label),
                                    new Action(delegate
                                {
                                    //var reloadJob = JobMaker.MakeJob(JobDefOf.Reload, apparel, thing);
                                    //SelPawnForGear.jobs.StartJob(reloadJob, JobCondition.InterruptForced, null, SelPawnForGear.CurJob?.def != reloadJob.def, true);

                                    SelPawnForGear.jobs.TryTakeOrderedJob(JobMaker.MakeJob(JobDefOf.Reload, apparel, thing));
                                })
                                    );
                                floatOptionList.Add(reloadApparelOption);
                            }
                        }
                    }
                    // Drop and consume options
                    Action dropApparel = delegate
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                        InterfaceDrop(thing);
                    };
                    Action dropApparelHaul = delegate
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                        InterfaceDropHaul(thing);
                    };
                    if (CanControl && thing.IngestibleNow && base.SelPawn.RaceProps.CanEverEat(thing))
                    {
                        Action eatFood = delegate
                        {
                            SoundDefOf.Tick_High.PlayOneShotOnCamera();
                            InterfaceIngest(thing);
                        };
                        string label = thing.def.ingestible.ingestCommandString.NullOrEmpty() ? (string)"ConsumeThing".Translate(thing.LabelShort, thing) : string.Format(thing.def.ingestible.ingestCommandString, thing.LabelShort);
                        if (SelPawnForGear.IsTeetotaler() && thing.def.IsNonMedicalDrug)
                        {
                            floatOptionList.Add(new FloatMenuOption(label + ": " + TraitDefOf.DrugDesire.degreeDatas.Where(x => x.degree == -1).First()?.label, null));
                        }
                        else
                        {
                            floatOptionList.Add(new FloatMenuOption(label, eatFood));
                        }
                    }
                    floatOptionList.Add(new FloatMenuOption("DropThing".Translate(), dropApparel));
                    floatOptionList.Add(new FloatMenuOption("CE_DropThingHaul".Translate(), dropApparelHaul));
                    if (CanControl && SelPawnForGear.HoldTrackerIsHeld(thing))
                    {
                        Action forgetHoldTracker = delegate
                        {
                            SoundDefOf.Tick_High.PlayOneShotOnCamera();
                            SelPawnForGear.HoldTrackerForget(thing);
                        };
                        floatOptionList.Add(new FloatMenuOption("CE_HoldTrackerForget".Translate(), forgetHoldTracker));
                    }
                }
                FloatMenu window = new FloatMenu(floatOptionList, thing.LabelCap, false);
                Find.WindowStack.Add(window);
            }
            // end menu
        }
        //Drawing
        public override void DoWindowContents(Rect inRect)
        {
            FactionFC faction = Find.World.GetComponent <FactionFC>();

            faction.roadBuilder.DrawPaths();

            if (Find.WorldSelector.selectedTile != -1 && Find.WorldSelector.selectedTile != currentTileSelected)
            {
                currentTileSelected = Find.WorldSelector.selectedTile;
                //Log.Message("Current: " + currentTileSelected + ", Selected: " + Find.WorldSelector.selectedTile);
                currentBiomeSelected = DefDatabase <BiomeResourceDef> .GetNamed(
                    Find.WorldGrid.tiles[currentTileSelected].biome.ToString(), false);

                //default biome
                if (currentBiomeSelected == default(BiomeResourceDef))
                {
                    //Log Modded Biome
                    currentBiomeSelected = BiomeResourceDefOf.defaultBiome;
                }
                currentHillinessSelected = DefDatabase <BiomeResourceDef> .GetNamed(
                    Find.WorldGrid.tiles[currentTileSelected].hilliness.ToString());

                if (currentBiomeSelected.canSettle && currentHillinessSelected.canSettle && currentTileSelected != 1)
                {
                    timeToTravel = FactionColonies.ReturnTicksToArrive(
                        Find.World.GetComponent <FactionFC>().capitalLocation, currentTileSelected);
                }
                else
                {
                    timeToTravel = 0;
                }
            }


            //grab before anchor/font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;


            int silverToCreateSettlement = (int)(TraitUtilsFC.cycleTraits(new double(), "createSettlementMultiplier", Find.World.GetComponent <FactionFC>().traits, "multiply") * (FactionColonies.silverToCreateSettlement + (500 * (Find.World.GetComponent <FactionFC>().settlements.Count() + Find.World.GetComponent <FactionFC>().settlementCaravansList.Count())) + (TraitUtilsFC.cycleTraits(new double(), "createSettlementBaseCost", Find.World.GetComponent <FactionFC>().traits, "add"))));

            if (faction.hasPolicy(FCPolicyDefOf.isolationist))
            {
                silverToCreateSettlement *= 2;
            }

            if (faction.hasPolicy(FCPolicyDefOf.expansionist))
            {
                if (!faction.settlements.Any() && !faction.settlementCaravansList.Any())
                {
                    traitExpansionistReducedFee = false;
                    silverToCreateSettlement    = 0;
                }
                else
                {
                    if (faction.traitExpansionistTickLastUsedSettlementFeeReduction == -1 || (faction.traitExpansionistBoolCanUseSettlementFeeReduction))
                    {
                        traitExpansionistReducedFee = true;
                        silverToCreateSettlement   /= 2;
                    }
                    else
                    {
                        traitExpansionistReducedFee = false;
                    }
                }
            }


            //Draw Label
            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(new Rect(0, 0, 268, 40), "SettleANewColony".Translate());

            //hori line
            Widgets.DrawLineHorizontal(0, 40, 300);


            //Upper menu
            Widgets.DrawMenuSection(new Rect(5, 45, 258, 220));

            DrawLabelBox(10, 50, 100, 100, "TravelTime".Translate(), timeToTravel.ToStringTicksToDays());
            DrawLabelBox(153, 50, 100, 100, "InitialCost".Translate(), silverToCreateSettlement + " " + "Silver".Translate());


            //Lower Menu label
            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(new Rect(0, 270, 268, 40), "BaseProductionStats".Translate());


            //Lower menu
            Widgets.DrawMenuSection(new Rect(5, 310, 258, 220));


            //Draw production
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;

            //Production headers
            Widgets.Label(new Rect(40, 310, 60, 25), "Base".Translate());
            Widgets.Label(new Rect(110, 310, 60, 25), "Modifier".Translate());
            Widgets.Label(new Rect(180, 310, 60, 25), "Final".Translate());

            if (currentTileSelected != -1)
            {
                foreach (ResourceType titheType in ResourceUtils.resourceTypes)
                {
                    int height = 15;
                    if (Widgets.ButtonImage(new Rect(20, 335 + (int)titheType * (5 + height), height, height),
                                            faction.returnResource(titheType).getIcon()))
                    {
                        Find.WindowStack.Add(new DescWindowFc("SettlementProductionOf".Translate() + ": "
                                                              + faction.returnResource(titheType).label,
                                                              char.ToUpper(faction.returnResource(titheType).label[0])
                                                              + faction.returnResource(titheType).label.Substring(1)));
                    }
                    Widgets.Label(new Rect(40, 335 + (int)titheType * (5 + height), 60, height + 2),
                                  (currentBiomeSelected.BaseProductionAdditive[(int)titheType]
                                   + currentHillinessSelected.BaseProductionAdditive[(int)titheType]).ToString());
                    Widgets.Label(new Rect(110, 335 + (int)titheType * (5 + height), 60, height + 2),
                                  (currentBiomeSelected.BaseProductionMultiplicative[(int)titheType]
                                   * currentHillinessSelected.BaseProductionMultiplicative[(int)titheType]).ToString());
                    Widgets.Label(new Rect(180, 335 + (int)titheType * (5 + height), 60, height + 2),
                                  ((currentBiomeSelected.BaseProductionAdditive[(int)titheType]
                                    + currentHillinessSelected.BaseProductionAdditive[(int)titheType])
                                   * (currentBiomeSelected.BaseProductionMultiplicative[(int)titheType]
                                      * currentHillinessSelected.BaseProductionMultiplicative[(int)titheType])).ToString());
                }
            }



            //Settle button
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;
            int buttonLength = 130;

            if (Widgets.ButtonText(new Rect((InitialSize.x - 32 - buttonLength) / 2f, 535, buttonLength, 32),
                                   "Settle".Translate() + ": (" + silverToCreateSettlement + ")")) //add inital cost
            {                                                                                      //if click button to settle
                if (PaymentUtil.getSilver() >= silverToCreateSettlement)                           //if have enough monies to make new settlement
                {
                    StringBuilder reason = new StringBuilder();
                    if (currentTileSelected == -1 || !TileFinder.IsValidTileForNewSettlement(currentTileSelected, reason) ||
                        Find.World.GetComponent <FactionFC>().checkSettlementCaravansList(currentTileSelected.ToString()))
                    {
                        //Alert Error to User
                        Messages.Message(reason.ToString(), MessageTypeDefOf.NegativeEvent);
                    }
                    else
                    {   //Else if valid tile
                        PaymentUtil.paySilver(silverToCreateSettlement);
                        //if PROCESS MONEY HERE

                        if (traitExpansionistReducedFee)
                        {
                            faction.traitExpansionistTickLastUsedSettlementFeeReduction = Find.TickManager.TicksGame;
                            faction.traitExpansionistBoolCanUseSettlementFeeReduction   = false;
                        }

                        //create settle event
                        FCEvent tmp = FCEventMaker.MakeEvent(FCEventDefOf.settleNewColony);
                        tmp.location        = currentTileSelected;
                        tmp.planetName      = Find.World.info.name;
                        tmp.timeTillTrigger = Find.TickManager.TicksGame + timeToTravel;
                        tmp.source          = Find.World.GetComponent <FactionFC>().capitalLocation;
                        Find.World.GetComponent <FactionFC>().addEvent(tmp);

                        Find.World.GetComponent <FactionFC>().settlementCaravansList.Add(tmp.location.ToString());
                        Messages.Message("CaravanSentToLocation".Translate()
                                         + " " + (tmp.timeTillTrigger
                                                  - Find.TickManager.TicksGame).ToStringTicksToDays() + "!",
                                         MessageTypeDefOf.PositiveEvent);
                        // when event activate FactionColonies.createPlayerColonySettlement(currentTileSelected);
                    }
                }
                else
                {  //if don't have enough monies to make settlement
                    Messages.Message("NotEnoughSilverToSettle".Translate() + "!", MessageTypeDefOf.NeutralEvent);
                }
            }



            //reset anchor/font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
        public override void DoWindowContents(Rect inRect)
        {
            //grab before anchor/font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;



            //Settlement Tax Collection Header
            Text.Anchor = TextAnchor.MiddleLeft;
            Text.Font   = GameFont.Medium;
            Widgets.Label(new Rect(3, 3, 300, 60), header);


            Text.Font = GameFont.Small;
            for (int i = 0; i < 1; i++)             //for each field to customize
            {
                switch (i)
                {
                case 0:                          //faction name
                    Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "SettlementName".Translate() + ": ");
                    name = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), name);
                    break;

                case 1:                         //faction title
                    Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "## title: ");
                    title = Widgets.TextField(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, length / 2, yspacing), title);
                    break;

                case 2:                                                                                                                  //faction icon
                    Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "## Icon: ");
                    if (Widgets.ButtonImage(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, 40, 40), texLoad.iconUnrest)) //change to faction icon
                    {
                        //Log.Message("Faction icon select pressed");
                        //Open window to select new icon
                    }
                    break;
                }
            }

            if (Widgets.ButtonText(new Rect((InitialSize.x - 120 - 18) / 2, yoffset + InitialSize.y - 120, 120, 30), "ConfirmChanges".Translate()))
            {
                settlement.name = name;
                Find.WorldObjects.SettlementAt(settlement.mapLocation).Name = name;
            }

            //settlement buttons

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

            //0 tithe total string
            //1 source - -1
            //2 due/delivery date
            //3 Silver (- || +)
            //4 tithe


            Widgets.Label(new Rect(xoffset + 2, yoffset - yspacing + 2, length - 4, height - 4 + yspacing * 2), desc);
            Widgets.DrawBox(new Rect(xoffset, yoffset - yspacing, length, height - yspacing * 2));

            //reset anchor/font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
Exemple #27
0
 public void LearningReadoutOnGUI()
 {
     if (!TutorSystem.TutorialMode && TutorSystem.AdaptiveTrainingEnabled && (Find.PlaySettings.showLearningHelper || activeConcepts.Count != 0) && !Find.WindowStack.IsOpen <Screen_Credits>())
     {
         float b       = (float)UI.screenHeight / 2f;
         float a       = contentHeight + 14f;
         Rect  outRect = new Rect((float)UI.screenWidth - 8f - 200f, 8f, 200f, Mathf.Min(a, b));
         Rect  rect    = outRect;
         Find.WindowStack.ImmediateWindow(76136312, outRect, WindowLayer.Super, delegate
         {
             outRect       = outRect.AtZero();
             Rect rect2    = outRect.ContractedBy(7f);
             Rect viewRect = rect2.AtZero();
             bool flag     = contentHeight > rect2.height;
             Widgets.DrawWindowBackgroundTutor(outRect);
             if (flag)
             {
                 viewRect.height = contentHeight + 40f;
                 viewRect.width -= 20f;
                 scrollPosition  = GUI.BeginScrollView(rect2, scrollPosition, viewRect);
             }
             else
             {
                 GUI.BeginGroup(rect2);
             }
             float num2 = 0f;
             Text.Font  = GameFont.Small;
             Rect rect3 = new Rect(0f, 0f, viewRect.width - 24f, 24f);
             Widgets.Label(rect3, "LearningHelper".Translate());
             num2         = rect3.yMax;
             Rect butRect = new Rect(rect3.xMax, rect3.y, 24f, 24f);
             if (Widgets.ButtonImage(butRect, showAllMode ? TexButton.Minus : TexButton.Plus))
             {
                 showAllMode = !showAllMode;
                 if (showAllMode)
                 {
                     SoundDefOf.Tick_High.PlayOneShotOnCamera();
                 }
                 else
                 {
                     SoundDefOf.Tick_Low.PlayOneShotOnCamera();
                 }
             }
             if (showAllMode)
             {
                 Rect rect4   = new Rect(0f, num2, viewRect.width - 20f - 2f, 28f);
                 searchString = FilterSearchStringInput(Widgets.TextField(rect4, searchString));
                 if (searchString == string.Empty)
                 {
                     GUI.color   = new Color(0.6f, 0.6f, 0.6f, 1f);
                     Text.Anchor = TextAnchor.MiddleLeft;
                     Rect rect5  = rect4;
                     rect5.xMin += 7f;
                     Widgets.Label(rect5, "Filter".Translate() + "...");
                     Text.Anchor = TextAnchor.UpperLeft;
                     GUI.color   = Color.white;
                 }
                 Rect butRect2 = new Rect(viewRect.width - 20f, num2 + 14f - 10f, 20f, 20f);
                 if (Widgets.ButtonImage(butRect2, TexButton.CloseXSmall))
                 {
                     searchString = string.Empty;
                     SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
                 }
                 num2 = rect4.yMax + 4f;
             }
             IEnumerable <ConceptDef> enumerable = showAllMode ? DefDatabase <ConceptDef> .AllDefs : activeConcepts;
             if (enumerable.Any())
             {
                 GUI.color = new Color(1f, 1f, 1f, 0.5f);
                 Widgets.DrawLineHorizontal(0f, num2, viewRect.width);
                 GUI.color = Color.white;
                 num2     += 4f;
             }
             if (showAllMode)
             {
                 enumerable = from c in enumerable
                              orderby DisplayPriority(c) descending, c.label
                 select c;
             }
             foreach (ConceptDef item in enumerable)
             {
                 if (!item.TriggeredDirect)
                 {
                     num2 = DrawConceptListRow(0f, num2, viewRect.width, item).yMax;
                 }
             }
             contentHeight = num2;
             if (flag)
             {
                 GUI.EndScrollView();
             }
             else
             {
                 GUI.EndGroup();
             }
         }, doBackground: false);
         float num = Time.realtimeSinceStartup - lastConceptActivateRealTime;
         if (num < 1f && num > 0f)
         {
             float   x      = rect.x;
             Vector2 center = rect.center;
             GenUI.DrawFlash(x, center.y, (float)UI.screenWidth * 0.6f, Pulser.PulseBrightness(1f, 1f, num) * 0.85f, new Color(0.8f, 0.77f, 0.53f));
         }
         ConceptDef conceptDef = (selectedConcept == null) ? mouseoverConcept : selectedConcept;
         if (conceptDef != null)
         {
             DrawInfoPane(conceptDef);
             conceptDef.HighlightAllTags();
         }
         mouseoverConcept = null;
     }
 }
Exemple #28
0
        /// <summary>
        /// Create interface for changing amount being transfered in VehicleCaravan dialog
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="trad"></param>
        /// <param name="pawns"></param>
        /// <param name="stoppingPoints"></param>
        /// <param name="index"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="flash"></param>
        /// <param name="readOnly"></param>
        private static void DoCountAdjustInterfaceInternal(Rect rect, Transferable trad, List <TransferableOneWay> pawns, List <TransferableCountToTransferStoppingPoint> stoppingPoints, int index, int min, int max, bool flash, bool readOnly)
        {
            rect = rect.Rounded();
            Rect rect2 = new Rect(rect.center.x - 45f, rect.center.y - 12.5f, 90f, 25f).Rounded();

            if (flash)
            {
                GUI.DrawTexture(rect2, TransferableUIUtility.FlashTex);
            }
            TransferableOneWay transferableOneWay = trad as TransferableOneWay;

            bool flag3 = trad.CountToTransfer != 0;
            bool flag4 = flag3;

            Rect buttonRect = new Rect(rect2.x, rect2.y, 120f, rect.height);

            if (Widgets.ButtonText(buttonRect, "AssignSeats".Translate()))
            {
                Find.WindowStack.Add(new Dialog_AssignSeats(pawns, transferableOneWay));
            }
            Rect checkboxRect = new Rect(buttonRect.x + buttonRect.width + 5f, buttonRect.y, 24f, 24f);

            if (Widgets.ButtonImage(checkboxRect, flag4 ? Widgets.CheckboxOnTex : Widgets.CheckboxOffTex))
            {
                if (!flag4)
                {
                    Find.WindowStack.Add(new Dialog_AssignSeats(pawns, transferableOneWay));
                }
                else
                {
                    foreach (Pawn pawn in (trad.AnyThing as VehiclePawn).AllPawnsAboard)
                    {
                        if (CaravanHelper.assignedSeats.ContainsKey(pawn))
                        {
                            CaravanHelper.assignedSeats.Remove(pawn);
                        }
                    }
                    SoundDefOf.Click.PlayOneShotOnCamera();
                    flag4 = !flag4;
                }
            }

            if (flag4 != flag3)
            {
                if (flag4)
                {
                    trad.AdjustTo(trad.GetMaximumToTransfer());
                }
                else
                {
                    trad.AdjustTo(trad.GetMinimumToTransfer());
                }
            }
            if (trad.CountToTransfer != 0)
            {
                Rect position = new Rect(rect2.x + rect2.width / 2f - (VehicleTex.TradeArrow.width / 2), rect2.y + rect2.height / 2f - (VehicleTex.TradeArrow.height / 2),
                                         VehicleTex.TradeArrow.width, VehicleTex.TradeArrow.height);
                TransferablePositiveCountDirection positiveCountDirection2 = trad.PositiveCountDirection;
                if ((positiveCountDirection2 == TransferablePositiveCountDirection.Source && trad.CountToTransfer > 0) || (positiveCountDirection2 == TransferablePositiveCountDirection.Destination && trad.CountToTransfer < 0))
                {
                    position.x     += position.width;
                    position.width *= -1f;
                }
                //GUI.DrawTexture(position, TradeArrow); //REDO?
            }
        }
        private void DrawHost(Rect inRect)
        {
            if (!filesRead)
            {
                ReloadFiles();
                filesRead = true;
            }

            inRect.y += 8;

            float margin   = 80;
            Rect  outRect  = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 80);
            Rect  viewRect = new Rect(0, 0, outRect.width - 16f, hostHeight);

            Widgets.BeginScrollView(outRect, ref hostScroll, viewRect, true);

            Rect collapseRect = new Rect(0, 4f, 18f, 18f);

            if (Widgets.ButtonImage(collapseRect, mpCollapsed ? TexButton.Reveal : TexButton.Collapse))
            {
                mpCollapsed = !mpCollapsed;
            }

            float y = 0;

            Text.Font = GameFont.Medium;
            float textHeight1 = Text.CalcHeight("MpMultiplayer".Translate(), inRect.width);

            Widgets.Label(viewRect.Right(18f), "MpMultiplayer".Translate());
            Text.Font = GameFont.Small;
            y        += textHeight1 + 10;

            if (!mpCollapsed)
            {
                DrawSaveList(mpReplays, viewRect.width, ref y);
                y += 25;
            }

            collapseRect.y += y;

            if (Widgets.ButtonImage(collapseRect, spCollapsed ? TexButton.Reveal : TexButton.Collapse))
            {
                spCollapsed = !spCollapsed;
            }

            viewRect.y = y;
            Text.Font  = GameFont.Medium;
            float textHeight2 = Text.CalcHeight("MpSingleplayer".Translate(), inRect.width);

            Widgets.Label(viewRect.Right(18), "MpSingleplayer".Translate());
            Text.Font = GameFont.Small;
            y        += textHeight2 + 10;

            if (!spCollapsed)
            {
                DrawSaveList(spSaves, viewRect.width, ref y);
            }

            if (Event.current.type == EventType.Layout)
            {
                hostHeight = y;
            }

            Widgets.EndScrollView();

            if (selectedFile == null)
            {
                Text.Anchor = TextAnchor.MiddleCenter;

                bool noSaves = spSaves.Count == 0 && mpReplays.Count == 0;
                Widgets.Label(new Rect(outRect.x, outRect.yMax, outRect.width, 80), noSaves ? "MpNoSaves".Translate() : "MpNothingSelected".Translate());

                Text.Anchor = TextAnchor.UpperLeft;
            }
            else
            {
                float width = 0;

                GUI.BeginGroup(new Rect(outRect.x + (outRect.width - fileButtonsWidth) / 2, outRect.yMax + 20, fileButtonsWidth, 40));
                DrawFileButtons(selectedFile, ref width);
                GUI.EndGroup();

                if (Event.current.type == EventType.Layout)
                {
                    fileButtonsWidth = width;
                }
            }
        }
Exemple #30
0
        private void DrawAvailableApparel(float x, float y, float width, float height)
        {
#if TRACE && CUSTOM_OUTFIT_UI
            Log.Warning("Begin CustomOutfitUI.DrawAvailableApparel " + x + " " + y);
#endif
            // Apparel Selection Titles

            /*Widgets.Label(new Rect(x, y, 150, 30), "ChangeDresser.AvailableApparel".Translate());
             * searchText = Widgets.TextArea(new Rect(x + 160, y, 100, 30), searchText).ToLower();
             * y += HEIGHT + Y_BUFFER;*/

            Rect apparelListRect   = new Rect(x, y, width - 10, height);
            Rect apparelScrollRect = new Rect(0f, 0f, apparelListRect.width - 16f, this.availableApparel.Count * CELL_HEIGHT);

            GUI.BeginGroup(apparelListRect);
            this.scrollPosLeft = GUI.BeginScrollView(new Rect(GenUI.AtZero(apparelListRect)), this.scrollPosLeft, apparelScrollRect);

            for (int i = 0, count = 0; i < this.availableApparel.Count; ++i)
            {
                Apparel apparel = this.availableApparel[i];
                //if (searchText.Trim().Length == 0 ||
                //    apparel.Label.ToLower().Contains(searchText))
                if (this.apparelFilter.IncludeAppareL(apparel))
                {
                    Rect rowRect = new Rect(0, 2f + count * CELL_HEIGHT, apparelListRect.width, CELL_HEIGHT);
                    ++count;
                    GUI.BeginGroup(rowRect);

                    Widgets.ThingIcon(new Rect(0f, 0f, CELL_HEIGHT, CELL_HEIGHT), apparel);

                    if (Widgets.InfoCardButton(40, 0, apparel))
                    {
                        Find.WindowStack.Add(new Dialog_InfoCard(apparel));
                    }

                    Widgets.Label(new Rect(30 + CELL_HEIGHT + 5f, 0f, rowRect.width - 40f - CELL_HEIGHT, CELL_HEIGHT), apparel.Label);

                    if (this.customOutfit != null)
                    {
                        Rect buttonRect = new Rect(rowRect.width - 35f, 10, 20, 20);
                        if (this.CanWear(apparel))
                        {
                            if (Widgets.ButtonImage(buttonRect, WidgetUtil.nextTexture))
                            {
                                this.AddApparelToOutfit(apparel);
                                break;
                            }
                        }
                        else
                        {
                            Widgets.ButtonImage(buttonRect, WidgetUtil.cantTexture);
                        }
                    }
                    GUI.EndGroup();
                }
            }
            GUI.EndScrollView();
            GUI.EndGroup();
#if TRACE && CUSTOM_OUTFIT_UI
            Log.Warning("End CustomOutfitUI.DrawAvailableApparel " + x + " " + y);
#endif
        }