Example #1
0
        public override void DoWindowContents(Rect inRect)
        {
            Rect exitVote = new Rect(inRect.width - 25f, 0f, 20f, 20f);

            if (Widgets.ButtonTextSubtle(exitVote, "X"))
            {
                VoteHandler.ForceEnd();
            }

            GameFont old = Text.Font;

            Text.Font = ToolkitSettings.LargeVotingWindow ? GameFont.Medium : GameFont.Small;
            float lineheight = ToolkitSettings.LargeVotingWindow ? 50 : 30;

            string titleLabel  = "<b>" + title + "</b>";
            float  titleHeight = Text.CalcHeight(titleLabel, inRect.width);

            Widgets.Label(inRect, titleLabel);
            inRect.y += titleHeight + 10;
            for (int i = 0; i < optionsKeys.Count; i++)
            {
                string msg = "[" + (i + 1) + "] ";
                msg += (vote.VoteKeyLabel(i)) + $": {vote.voteCounts[i]}";
                Widgets.Label(inRect, msg);
                inRect.y += lineheight;
            }
            int secondsElapsed = TimeHelper.SecondsElapsed(VoteHandler.voteStartedAt);

            Rect bar = new Rect(inRect.x, inRect.y, 225, 20);

            Widgets.FillableBar(bar, ((float)ToolkitSettings.VoteTime * 60f - (float)secondsElapsed) / ((float)ToolkitSettings.VoteTime * 60f));

            Text.Font = old;
        }
Example #2
0
        public override void DoWindowContents(Rect inRect)
        {
            base.DoWindowContents(inRect);
            Text.Font = GameFont.Small;
            float num  = (float)(inRect.width / 2.0);
            float num2 = 0f;
            float num3 = 0f;

            for (int i = 0; i < this.desPanelsCached.Count; i++)
            {
                Rect rect = new Rect(num2 * num, (float)(num3 * 32.0), num, 32f);
                rect.height += 1f;
                if (num2 == 0.0)
                {
                    rect.width += 1f;
                }
                if (Widgets.ButtonTextSubtle(rect, this.desPanelsCached[i].def.LabelCap, 0f, 8f, SoundDefOf.MouseoverCategory, new Vector2(-1f, -1f)))
                {
                    this.ClickedCategory(this.desPanelsCached[i]);
                }
                if (this.selectedDesPanel != this.desPanelsCached[i])
                {
                    UIHighlighter.HighlightOpportunity(rect, this.desPanelsCached[i].def.cachedHighlightClosedTag);
                }
                num2 = (float)(num2 + 1.0);
                if (num2 > 1.0)
                {
                    num2 = 0f;
                    num3 = (float)(num3 + 1.0);
                }
            }
        }
        public virtual void DoButton(Rect rect)
        {
            Text.Font = GameFont.Small;
            string labelCap = this.def.LabelCap;

            if ((!this.def.validWithoutMap || this.def == MainButtonDefOf.World) && Find.VisibleMap == null)
            {
                Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas);
                if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect))
                {
                    Event.current.Use();
                }
                return;
            }
            string   label             = labelCap;
            float    buttonBarPercent  = this.ButtonBarPercent;
            SoundDef mouseoverCategory = SoundDefOf.MouseoverCategory;

            if (Widgets.ButtonTextSubtle(rect, label, buttonBarPercent, -1f, mouseoverCategory, default(Vector2)))
            {
                this.InterfaceTryActivate();
            }
            if (Find.MainTabsRoot.OpenTab != this.def && !Find.WindowStack.NonImmediateDialogWindowOpen)
            {
                UIHighlighter.HighlightOpportunity(rect, this.def.cachedHighlightTagClosed);
            }
            if (!this.def.description.NullOrEmpty())
            {
                TooltipHandler.TipRegion(rect, this.def.description);
            }
        }
Example #4
0
        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.DrawMenuSection(new Rect(0, 0, 544, 150));
            Widgets.Label(new Rect(10, 0, 500, 60), header);
            Widgets.DrawLineHorizontal(0, 155, 544);



            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font   = GameFont.Tiny;
            Widgets.Label(new Rect(20, 60, 470, 90), desc);


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



            for (int i = 0; i < options.Count(); i++)
            {
                if (Widgets.ButtonTextSubtle(new Rect(xoffset, yoffset + (i * (height + yspacing)), length, height), ""))
                {
                    if (PaymentUtil.getSilver() >= options[i].silverCost)
                    {
                        PaymentUtil.paySilver(options[i].silverCost);

                        FCEventMaker.calculateSuccess(options[i], parentEvent);
                        //Log.Message(options[i].label);


                        Find.WindowStack.TryRemove(this);
                    }
                    else
                    {
                        Messages.Message("You do not have enough silver on the map to pay for that option", MessageTypeDefOf.RejectInput);
                    }
                }

                //label
                Widgets.Label(new Rect(xoffset + 5, yoffset + 5 + (i * (height + yspacing)), length - 10, height - 10), options[i].label);
            }
            //Widgets.DrawBox(new Rect(xoffset, yoffset - yspacing, length, height - yspacing * 2));

            //reset anchor/font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
        public static bool DoArchitectButton(Rect rect, string label, float barPercent = 0f, float textLeftMargin = -1f, SoundDef mouseoverSound = null,
                                             Vector2 functionalSizeOffset = default, Color?labelColor             = null, bool highlight = false)
        {
            var result = Widgets.ButtonTextSubtle(rect, label, barPercent, textLeftMargin + 16f, mouseoverSound,
                                                  functionalSizeOffset, labelColor, highlight);

            GUI.DrawTexture(new Rect(rect.position + new Vector2(4, 8), new Vector2(16, 16)),
                            Resources.FindArchitectTabCategoryIcon(DefNameFromLabel(label)));
            return(result);
        }
Example #6
0
        private void DrawTabReports(Rect inRect)
        {
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;

            if (Widgets.ButtonTextSubtle(new Rect(tabSize * 2, 0, tabSize, 30), "Bills".Translate(), 0f, 8f, SoundDefOf.Mouseover_Category, new Vector2(-1f, -1f)))
            {
                Find.WindowStack.Add(new FCBillWindow());
                //Log.Message("Try open bills");
            }
        }
Example #7
0
        private void DrawTabFaction(Rect inRect)
        {
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;

            if (Widgets.ButtonTextSubtle(new Rect(0, 0, tabSize, 30), "Faction".Translate(), 0f, 8f, SoundDefOf.Mouseover_Category, new Vector2(-1f, -1f)))
            {
                tab = 0;
                faction.updateTotalProfit();
            }
        }
Example #8
0
        private void DrawTabEvent(Rect inRect)
        {
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;

            if (Widgets.ButtonTextSubtle(new Rect(tabSize * 3, 0, tabSize, 30), "Events".Translate(), 0f, 8f, SoundDefOf.Mouseover_Category, new Vector2(-1f, -1f)))
            {
                //tab = 0;
                //Open Event window
                Find.WindowStack.Add(new FCEventWindow());
            }
        }
Example #9
0
        private void DrawTabColony(Rect inRect)
        {
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;

            if (Widgets.ButtonTextSubtle(new Rect(tabSize, 0, tabSize, 30), "Colonies".Translate(), 0f, 8f, SoundDefOf.Mouseover_Category, new Vector2(-1f, -1f)))
            {
                tab       = 1;
                scroll    = 0;
                maxScroll = (settlementList.Count() * yspacing) - 264;
            }
        }
        public override void DoWindowContents(Rect rect)
        {
            if (faction.militaryCustomizationUtil.DeployedSquads.Count() == 0)
            {
                Close();
            }

            GameFont   prevFont   = Text.Font;
            TextAnchor prevAnchor = Text.Anchor;

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;

            float rectBaseHeight = 40f;
            float rectWidth      = 160f;

            Rect selectSquad       = new Rect(0, 0, rectWidth, rectBaseHeight);
            Rect commandAttack     = new Rect(0, rectBaseHeight, rectWidth, rectBaseHeight);
            Rect commandMove       = new Rect(0, rectBaseHeight * 2, rectWidth, rectBaseHeight);
            Rect commandHeal       = new Rect(0, rectBaseHeight * 3, rectWidth, rectBaseHeight);
            Rect commandKillWindow = new Rect(0, rectBaseHeight * 4, rectWidth, rectBaseHeight);

            squadText = (selectedSquad == null) ? "selectDeployedSquad".Translate() : "selectedDeployedSquad".Translate(selectedSquad.getSettlement.name, selectedSquad.outfit.name);

            if (Widgets.ButtonText(selectSquad, squadText))
            {
                DoSelectSquadCommand();
            }
            if (Widgets.ButtonTextSubtle(commandAttack, "commandAttack".Translate()))
            {
                DoAttackCommand();
            }
            if (Widgets.ButtonTextSubtle(commandMove, "commandMove".Translate()))
            {
                DoMoveCommand();
            }
            if (Widgets.ButtonTextSubtle(commandHeal, "commandLeave".Translate()))
            {
                DoLeaveCommand();
            }

            if (Prefs.DevMode)
            {
                if (Widgets.ButtonTextSubtle(commandKillWindow, "debugRemoveAllCommand".Translate()))
                {
                    DoDebugCommand();
                }
            }

            Text.Font   = prevFont;
            Text.Anchor = prevAnchor;
        }
Example #11
0
        public virtual void DoButton(Rect rect)
        {
            Text.Font = GameFont.Small;
            string text = def.LabelCap;
            float  num  = def.LabelCapWidth;

            if (num > rect.width - 2f)
            {
                text = def.ShortenedLabelCap;
                num  = def.ShortenedLabelCapWidth;
            }
            if (Disabled)
            {
                Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas);
                if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect))
                {
                    Event.current.Use();
                }
                return;
            }
            bool   flag           = num > 0.85f * rect.width - 1f;
            Rect   rect2          = rect;
            string label          = ((def.Icon == null) ? text : "");
            float  textLeftMargin = (flag ? 2f : (-1f));

            if (Widgets.ButtonTextSubtle(rect2, label, ButtonBarPercent, textLeftMargin, SoundDefOf.Mouseover_Category))
            {
                InterfaceTryActivate();
            }
            if (def.Icon != null)
            {
                Vector2 center = rect.center;
                float   num2   = 16f;
                if (Mouse.IsOver(rect))
                {
                    center += new Vector2(2f, -2f);
                }
                GUI.DrawTexture(new Rect(center.x - num2, center.y - num2, 32f, 32f), def.Icon);
            }
            if (Find.MainTabsRoot.OpenTab != def && !Find.WindowStack.NonImmediateDialogWindowOpen)
            {
                UIHighlighter.HighlightOpportunity(rect, def.cachedHighlightTagClosed);
            }
            if (Mouse.IsOver(rect) && !def.description.NullOrEmpty())
            {
                TooltipHandler.TipRegion(rect, def.LabelCap + "\n\n" + def.description);
            }
        }
        public void DrawHeaderTabs()
        {
            Rect milDesigination = new Rect(0, 0, 0, 35);
            Rect milSetSquad     = new Rect(milDesigination.x + milDesigination.width, milDesigination.y, 187,
                                            milDesigination.height);
            Rect milCreateSquad = new Rect(milSetSquad.x + milSetSquad.width, milDesigination.y, 187,
                                           milDesigination.height);
            Rect milCreateUnit = new Rect(milCreateSquad.x + milCreateSquad.width, milDesigination.y, 187,
                                          milDesigination.height);
            Rect milCreateFiresupport = new Rect(milCreateUnit.x + milCreateUnit.width, milDesigination.y, 187,
                                                 milDesigination.height);
            Rect helpButton = new Rect(760, 0, 30, 30);

            if (Widgets.ButtonImage(helpButton, TexLoad.questionmark))
            {
                string header      = "Help! What is this for?";
                string description = "Need Help with this menu? Go to this youtube video: https://youtu.be/lvWb1rMMsq8";
                Find.WindowStack.Add(new DescWindowFc(description, header));
            }

            if (Widgets.ButtonTextSubtle(milDesigination, "Military Designations"))
            {
                window = null;
                util.checkMilitaryUtilForErrors();
            }

            if (Widgets.ButtonTextSubtle(milSetSquad, "Designate Squads"))
            {
                window = new AssignSquadsWindow(util, faction);
                util.checkMilitaryUtilForErrors();
            }

            if (Widgets.ButtonTextSubtle(milCreateSquad, "Create Squads"))
            {
                window = new DesignSquadsWindow(util);
            }

            if (Widgets.ButtonTextSubtle(milCreateUnit, "Create Units"))
            {
                window = new DesignUnitsWindow(util, faction);
            }

            if (Widgets.ButtonTextSubtle(milCreateFiresupport, "Create Fire Support"))
            {
                window = new FireSupportWindow(util);
            }
        }
        public override void DoButton(Rect rect)
        {
            Text.Font = GameFont.Small;
            string text = def.LabelCap;
            float num = def.LabelCapWidth;
            if (num > rect.width - 2f)
            {
                text = def.ShortenedLabelCap;
                num = def.ShortenedLabelCapWidth;
            }

            if (enableBar||enableTip||onScreenMemUsage)
            {
                updatetick++;
                if (updatetick > updateInterval)
                {
                    updatetick = 0;

                    long mem = GC.GetTotalMemory(false) / 1024;
                    float memMb = mem / 1024f;
                    if (enableTip)
                    {
                        tipCache = string.Format(MMTipTranslated, memMb);
                    }
                    if (enableBar)
                    {
                        progress = Mathf.Clamp01((memMb - memoryBarLowerMb) / memoryBarStepMb);
                    }
                    if (onScreenMemUsage)
                    {
                        labelCache = string.Format("{0:F2} Mb\n{1} Kb", memMb, mem);
                    }
                }
            }

            bool flag = num > 0.85f * rect.width - 1f;
            string label = onScreenMemUsage ? labelCache : text;
            float textLeftMargin = (!flag) ? -1f : 2f;
            if (Widgets.ButtonTextSubtle(rect, label, progress, textLeftMargin, SoundDefOf.Mouseover_Category, default(Vector2)))
            {
                if(Current.ProgramState== ProgramState.Playing)
                    InterfaceTryActivate();
            }

            TooltipHandler.TipRegion(rect, TabDescriptionTranslated + tipCache);
        }
Example #14
0
        public virtual void DoButton(Rect rect)
        {
            Text.Font = GameFont.Small;
            Profiler.BeginSample("lab");
            string text = this.def.LabelCap;

            Profiler.EndSample();
            float num = this.def.LabelCapWidth;

            if (num > rect.width - 2f)
            {
                text = this.def.ShortenedLabelCap;
                num  = this.def.ShortenedLabelCapWidth;
            }
            if ((!this.def.validWithoutMap || this.def == MainButtonDefOf.World) && Find.CurrentMap == null)
            {
                Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas);
                if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect))
                {
                    Event.current.Use();
                }
            }
            else
            {
                Profiler.BeginSample("ButtonTextSubtle");
                bool   flag           = num > 0.85f * rect.width - 1f;
                Rect   rect2          = rect;
                string label          = text;
                float  textLeftMargin = (!flag) ? -1f : 2f;
                if (Widgets.ButtonTextSubtle(rect2, label, this.ButtonBarPercent, textLeftMargin, SoundDefOf.Mouseover_Category, default(Vector2)))
                {
                    this.InterfaceTryActivate();
                }
                Profiler.EndSample();
                if (Find.MainTabsRoot.OpenTab != this.def && !Find.WindowStack.NonImmediateDialogWindowOpen)
                {
                    UIHighlighter.HighlightOpportunity(rect, this.def.cachedHighlightTagClosed);
                }
                if (!this.def.description.NullOrEmpty())
                {
                    TooltipHandler.TipRegion(rect, this.def.description);
                }
            }
        }
Example #15
0
        public virtual void DoButton(Rect rect)
        {
            Text.Font = GameFont.Small;
            string text = def.LabelCap;
            float  num  = def.LabelCapWidth;

            if (num > rect.width - 2f)
            {
                text = def.ShortenedLabelCap;
                num  = def.ShortenedLabelCapWidth;
            }
            if (Disabled)
            {
                Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas);
                if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect))
                {
                    Event.current.Use();
                }
            }
            else
            {
                bool   flag           = num > 0.85f * rect.width - 1f;
                Rect   rect2          = rect;
                string label          = text;
                float  textLeftMargin = (!flag) ? (-1f) : 2f;
                if (Widgets.ButtonTextSubtle(rect2, label, ButtonBarPercent, textLeftMargin, SoundDefOf.Mouseover_Category))
                {
                    InterfaceTryActivate();
                }
                if (Find.MainTabsRoot.OpenTab != def && !Find.WindowStack.NonImmediateDialogWindowOpen)
                {
                    UIHighlighter.HighlightOpportunity(rect, def.cachedHighlightTagClosed);
                }
                if (!def.description.NullOrEmpty())
                {
                    TooltipHandler.TipRegion(rect, def.description);
                }
            }
        }
        public override void DoWindowContents(Rect inRect)
        {
            SetInitialSizeAndPosition();
            Text.Font = GameFont.Small;
            float width = inRect.width / 2f;
            float num1  = 0.0f;
            float num2  = 0.0f;

            for (int index = 0; index < desPanelsCached.Count; ++index)
            {
                Rect rect = new Rect(num1 * width, num2 * 32f, width, 32f);
                ++rect.height;
                if ((double)num1 == 0.0)
                {
                    ++rect.width;
                }

                if (Widgets.ButtonTextSubtle(rect, desPanelsCached[index].def.LabelCap, 0.0f, 24f,
                                             SoundDefOf.MouseoverCategory))
                {
                    this.ClickedCategory(desPanelsCached[index]);
                }
                if (this.selectedDesPanel != desPanelsCached[index])
                {
                    UIHighlighter.HighlightOpportunity(rect, desPanelsCached[index].def.cachedHighlightClosedTag);
                }
                ++num1;
                if ((double)num1 > 1.0)
                {
                    num1 = 0.0f;
                    ++num2;
                }

                GUI.DrawTexture(new Rect(rect.position + new Vector2(4, (32 - 16) / 2), new Vector2(16, 16)),
                                Resources.FindArchitectTabCategoryIcon(desPanelsCached[index].def.defName));
            }
        }
Example #17
0
        public override void DrawTab(Rect rect)
        {
            Rect SettlementBox  = new Rect(5, 45, 535, settlementHeight);
            Rect SettlementName = new Rect(SettlementBox.x + 5, SettlementBox.y + 5, 250, 25);
            Rect MilitaryLevel  = new Rect(SettlementName.x, SettlementName.y + 30, 250, 25);
            Rect AssignedSquad  = new Rect(MilitaryLevel.x, MilitaryLevel.y + 30, 250, 25);
            Rect isBusy         = new Rect(AssignedSquad.x, AssignedSquad.y + 30, 250, 25);

            Rect buttonSetSquad  = new Rect(SettlementBox.x + SettlementBox.width - 265, SettlementBox.y + 5, 100, 25);
            Rect buttonViewSquad = new Rect(buttonSetSquad.x, buttonSetSquad.y + 3 + buttonSetSquad.height,
                                            buttonSetSquad.width, buttonSetSquad.height);
            Rect buttonDeploySquad = new Rect(buttonViewSquad.x, buttonViewSquad.y + 3 + buttonViewSquad.height,
                                              buttonSetSquad.width, buttonSetSquad.height);
            Rect buttonResetPawns = new Rect(buttonDeploySquad.x, buttonDeploySquad.y + 3 + buttonDeploySquad.height,
                                             buttonSetSquad.width, buttonSetSquad.height);
            Rect buttonOrderFireSupport = new Rect(buttonSetSquad.x + 125 + 5, SettlementBox.y + 5, 125, 25);


            //set text anchor and font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;


            int count = 0;

            foreach (SettlementFC settlement in Find.World.GetComponent <FactionFC>().settlements)
            {
                Text.Font = GameFont.Small;

                Widgets.DrawMenuSection(new Rect(SettlementBox.x,
                                                 SettlementBox.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                                 SettlementBox.width, SettlementBox.height));

                //click on settlement name
                if (Widgets.ButtonTextSubtle(
                        new Rect(SettlementName.x,
                                 SettlementName.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                 SettlementName.width, SettlementName.height), settlement.name))
                {
                    Find.WindowStack.Add(new SettlementWindowFc(settlement));
                }

                Widgets.Label(
                    new Rect(MilitaryLevel.x,
                             MilitaryLevel.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                             MilitaryLevel.width, MilitaryLevel.height * 2),
                    "Mil Level: " + settlement.settlementMilitaryLevel + " - Max Squad Cost: " +
                    FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel));
                if (settlement.militarySquad != null)
                {
                    if (settlement.militarySquad.outfit != null)
                    {
                        Widgets.Label(
                            new Rect(AssignedSquad.x,
                                     AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                     AssignedSquad.width, AssignedSquad.height),
                            "Assigned Squad: " +
                            settlement.militarySquad.outfit.name); //settlement.militarySquad.name);
                    }
                    else
                    {
                        Widgets.Label(
                            new Rect(AssignedSquad.x,
                                     AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                     AssignedSquad.width, AssignedSquad.height),
                            "No assigned Squad"); //settlement.militarySquad.name);
                    }
                }
                else
                {
                    Widgets.Label(
                        new Rect(AssignedSquad.x,
                                 AssignedSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                 AssignedSquad.width, AssignedSquad.height), "No assigned Squad");
                }


                Widgets.Label(
                    new Rect(isBusy.x, isBusy.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                             isBusy.width, isBusy.height), "Available: " + (!settlement.isMilitaryBusySilent()));

                Text.Font = GameFont.Tiny;

                //Set Squad Button
                if (Widgets.ButtonText(
                        new Rect(buttonSetSquad.x,
                                 buttonSetSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                 buttonSetSquad.width, buttonSetSquad.height), "Set Squad"))
                {
                    //check null
                    if (util.squads == null)
                    {
                        util.resetSquads();
                    }

                    List <FloatMenuOption> squads = new List <FloatMenuOption>();

                    squads.AddRange(util.squads
                                    .Select(squad => new FloatMenuOption(squad.name + " - Total Equipment Cost: " +
                                                                         squad.equipmentTotalCost, delegate
                    {
                        //Unit is selected
                        util.attemptToAssignSquad(settlement, squad);
                    })));

                    if (!squads.Any())
                    {
                        squads.Add(new FloatMenuOption("No Available Squads", null));
                    }

                    FloatMenu selection = new FloatMenuSearchable(squads);
                    Find.WindowStack.Add(selection);
                }

                //View Squad
                if (Widgets.ButtonText(
                        new Rect(buttonViewSquad.x,
                                 buttonViewSquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                 buttonViewSquad.width, buttonViewSquad.height), "View Squad"))
                {
                    Messages.Message("This is currently not implemented.", MessageTypeDefOf.RejectInput);
                }


                //Deploy Squad
                if (Widgets.ButtonText(
                        new Rect(buttonDeploySquad.x,
                                 buttonDeploySquad.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                 buttonDeploySquad.width, buttonDeploySquad.height), "Deploy Squad"))
                {
                    if (!(settlement.isMilitaryBusy()) && settlement.isMilitarySquadValid())
                    {
                        Find.WindowStack.Add(new FloatMenu(DeploymentOptions(settlement)));
                    }
                    else if (settlement.isMilitaryBusy() && settlement.isMilitarySquadValid() &&
                             faction.hasPolicy(FCPolicyDefOf.militaristic))
                    {
                        if ((faction.traitMilitaristicTickLastUsedExtraSquad + GenDate.TicksPerDay * 5) <=
                            Find.TickManager.TicksGame)
                        {
                            int cost = (int)Math.Round(settlement.militarySquad.outfit.updateEquipmentTotalCost() *
                                                       .2);
                            List <FloatMenuOption> options = new List <FloatMenuOption>();

                            options.Add(new FloatMenuOption("Deploy Secondary Squad - $" + cost + " silver",
                                                            delegate
                            {
                                if (PaymentUtil.getSilver() >= cost)
                                {
                                    List <FloatMenuOption> deploymentOptions = new List <FloatMenuOption>();

                                    deploymentOptions.Add(new FloatMenuOption("Walk into map", delegate
                                    {
                                        FactionColonies.CallinAlliedForces(settlement, false, cost);
                                        Find.WindowStack.currentlyDrawnWindow.Close();
                                    }));
                                    //check if medieval only
                                    bool medievalOnly = LoadedModManager.GetMod <FactionColoniesMod>()
                                                        .GetSettings <FactionColonies>().medievalTechOnly;
                                    if (!medievalOnly && (DefDatabase <ResearchProjectDef>
                                                          .GetNamed("TransportPod", false)?.IsFinished ?? false))
                                    {
                                        deploymentOptions.Add(new FloatMenuOption("Drop-Pod", delegate
                                        {
                                            FactionColonies.CallinAlliedForces(settlement, true, cost);
                                            Find.WindowStack.currentlyDrawnWindow.Close();
                                        }));
                                    }

                                    Find.WindowStack.Add(new FloatMenu(deploymentOptions));
                                }
                                else
                                {
                                    Messages.Message("NotEnoughSilverToDeploySquad".Translate(),
                                                     MessageTypeDefOf.RejectInput);
                                }
                            }));

                            Find.WindowStack.Add(new FloatMenu(options));
                        }
                        else
                        {
                            Messages.Message(
                                "XDaysToRedeploy".Translate(Math.Round(
                                                                ((faction.traitMilitaristicTickLastUsedExtraSquad + GenDate.TicksPerDay * 5) -
                                                                 Find.TickManager.TicksGame).TicksToDays(), 1)), MessageTypeDefOf.RejectInput);
                        }
                    }
                }

                //Reset Squad
                if (Widgets.ButtonText(
                        new Rect(buttonResetPawns.x,
                                 buttonResetPawns.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                 buttonResetPawns.width, buttonResetPawns.height), "Reset Pawns"))
                {
                    FloatMenuOption confirm = new FloatMenuOption("Are you sure? Click to confirm", delegate
                    {
                        if (settlement.militarySquad != null)
                        {
                            Messages.Message("Pawns have been regenerated for the squad",
                                             MessageTypeDefOf.NeutralEvent);
                            settlement.militarySquad.initiateSquad();
                        }
                        else
                        {
                            Messages.Message("There is no pawns to reset. Assign a squad first.",
                                             MessageTypeDefOf.RejectInput);
                        }
                    });

                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    list.Add(confirm);
                    Find.WindowStack.Add(new FloatMenu(list));
                }

                //Order Fire Support
                if (Widgets.ButtonText(
                        new Rect(buttonOrderFireSupport.x,
                                 buttonOrderFireSupport.y + (SettlementBox.height + settlementYSpacing) * count + scroll,
                                 buttonOrderFireSupport.width, buttonOrderFireSupport.height), "Order Fire Support"))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();


                    foreach (MilitaryFireSupport support in util.fireSupportDefs)
                    {
                        float           cost   = support.returnTotalCost();
                        FloatMenuOption option = new FloatMenuOption(support.name + " - $" + cost, delegate
                        {
                            if (support.returnTotalCost() <=
                                FactionColonies.calculateMilitaryLevelPoints(settlement.settlementMilitaryLevel))
                            {
                                if (settlement.buildings.Contains(BuildingFCDefOf.artilleryOutpost))
                                {
                                    if (settlement.artilleryTimer <= Find.TickManager.TicksGame)
                                    {
                                        if (PaymentUtil.getSilver() >= cost)
                                        {
                                            FactionColonies.FireSupport(settlement, support);
                                            Find.WindowStack.TryRemove(typeof(MilitaryCustomizationWindowFc));
                                        }
                                        else
                                        {
                                            Messages.Message(
                                                "You lack the required amount of silver to use that firesupport option!",
                                                MessageTypeDefOf.RejectInput);
                                        }
                                    }
                                    else
                                    {
                                        Messages.Message(
                                            "That firesupport option is on cooldown for another " +
                                            (settlement.artilleryTimer - Find.TickManager.TicksGame)
                                            .ToStringTicksToDays(), MessageTypeDefOf.RejectInput);
                                    }
                                }
                                else
                                {
                                    Messages.Message(
                                        "The settlement requires an artillery outpost to be built to use that firesupport option",
                                        MessageTypeDefOf.RejectInput);
                                }
                            }
                            else
                            {
                                Messages.Message(
                                    "The settlement requires a higher military level to use that fire support!",
                                    MessageTypeDefOf.RejectInput);
                            }
                        });
                        list.Add(option);
                    }

                    if (!list.Any())
                    {
                        list.Add(new FloatMenuOption("No fire supports currently made. Make one", delegate { }));
                    }

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

                count++;
            }

            //Reset Text anchor and font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;

            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y, settlementMaxScroll);
            }
        }
Example #18
0
        public override void DoWindowContents(Rect rect)
        {
            FactionFC faction = Find.World.GetComponent <FactionFC>();

            if (faction.militaryCustomizationUtil.DeployedSquads.Count() == 0)
            {
                Close();
            }

            GameFont   oldFont   = Text.Font;
            TextAnchor oldAnchor = Text.Anchor;

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;

            float rectBaseHeight = 40f;
            float rectWidth      = 160f;

            Rect selectSquad   = new Rect(0, 0, rectWidth, rectBaseHeight);
            Rect commandAttack = new Rect(0, rectBaseHeight, rectWidth, rectBaseHeight);
            Rect commandMove   = new Rect(0, rectBaseHeight * 2, rectWidth, rectBaseHeight);
            Rect commandHeal   = new Rect(0, rectBaseHeight * 3, rectWidth, rectBaseHeight);


            if (selectedSquad == null)
            {
                squadText = "selectDeployedSquad".Translate();
            }
            else
            {
                squadText = "selectedDeployedSquad".Translate(selectedSquad.getSettlement.name, selectedSquad.outfit.name);
            }

            //Select a squad
            if (Widgets.ButtonText(selectSquad, squadText))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (MercenarySquadFC squad in faction.militaryCustomizationUtil.DeployedSquads)
                {
                    if (squad.getSettlement != null)
                    {
                        list.Add(new FloatMenuOption("selectedDeployedSquad".Translate(squad.getSettlement.name, squad.outfit.name), delegate
                        {
                            selectedSquad = squad;
                        }));
                    }
                }
                if (!list.Any())
                {
                    list.Add(new FloatMenuOption("noSquadsAvailable".Translate(), null));
                }

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



            if (Widgets.ButtonTextSubtle(commandAttack, "commandAttack".Translate()))
            {
                if (selectedSquad != null)
                {
                    selectedSquad.order = MilitaryOrders.Attack;
                    Messages.Message("attackSuccess".Translate(selectedSquad.outfit.name), MessageTypeDefOf.NeutralEvent);
                    //selectedSquad.orderLocation = Position;
                }
            }
            if (Widgets.ButtonTextSubtle(commandMove, "commandMove".Translate()))
            {
                if (selectedSquad != null)
                {
                    DebugTool tool;
                    IntVec3   Position;
                    tool = new DebugTool("Select Move Position", delegate()
                    {
                        Position = UI.MouseCell();

                        selectedSquad.order         = MilitaryOrders.Standby;
                        selectedSquad.orderLocation = Position;
                        Messages.Message("moveSuccess".Translate(selectedSquad.outfit.name), MessageTypeDefOf.NeutralEvent);

                        DebugTools.curTool = null;
                    });
                    DebugTools.curTool = tool;
                }
            }
            if (Widgets.ButtonTextSubtle(commandHeal, "commandLeave".Translate()))
            {
                if (selectedSquad != null)
                {
                    selectedSquad.order = MilitaryOrders.Leave;
                    Messages.Message("commandLeave".Translate(selectedSquad.outfit.name, selectedSquad.dead), MessageTypeDefOf.NeutralEvent);
                }
            }

            //Example command:

            //DebugTool tool = null;
            //IntVec3 Position;
            //tool = new DebugTool("Select Drop Position", delegate ()
            //{
            //   Position = UI.MouseCell();

            //    selectedSquad.order = MilitaryOrders.Standby;
            //    selectedSquad.orderLocation = Position;

            //    DebugTools.curTool = null;
            //});
            //DebugTools.curTool = tool;


            Text.Font   = oldFont;
            Text.Anchor = oldAnchor;
        }
        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(labelFaction, header);

            Text.Font = GameFont.Small;
            Widgets.Label(labelFactionName, "FactionName".Translate() + ":");
            name = Widgets.TextField(textfieldName, name);

            Widgets.Label(labelFactionTitle, "FactionTitle".Translate() + ":");
            title = Widgets.TextField(textfieldTitle, title);

            Widgets.Label(labelFactionIcon, "FactionIcon".Translate());
            if (Widgets.ButtonImage(buttonIcon, tempFactionIcon))
            {
                List <FloatMenuOption> list = TexLoad.factionIcons.Select(texture => new FloatMenuOption(texture.name, delegate
                {
                    tempFactionIcon     = texture;
                    tempFactionIconPath = texture.name;
                }, texture, Color.white)).ToList();

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

            if (Widgets.ButtonTextSubtle(buttonAllowedRaces, "AllowedRaces".Translate()))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>
                {
                    new FloatMenuOption("Enable All", delegate { faction.resetRaceFilter(); })
                };
                List <string> races = new List <string>();
                foreach (PawnKindDef def in DefDatabase <PawnKindDef> .AllDefsListForReading.Where(def => def.IsHumanlikeWithLabelRace() && !races.Contains(def.race.label)))
                {
                    if (def.race.label == "Human" && def.LabelCap != "Colonist")
                    {
                        continue;
                    }
                    races.Add(def.race.label);
                    list.Add(new FloatMenuOption(
                                 def.race.label.CapitalizeFirst() + " - Allowed: " + faction.raceFilter.Allows(def.race),
                                 delegate
                    {
                        if (faction.raceFilter.AllowedThingDefs.Count() == 1 && faction.raceFilter.Allows(def.race))
                        {
                            Messages.Message("CannotHaveLessThanOneRace".Translate(), MessageTypeDefOf.RejectInput);
                        }
                        else if (faction.raceFilter.AllowedThingDefs.Count() > 0)
                        {
                            if (!faction.raceFilter.SetAllow(def.race, !faction.raceFilter.Allows(def.race)))
                            {
                                Messages.Message(new Message("InvalidFaction".Translate(), MessageTypeDefOf.RejectInput));
                            }
                        }
                        else
                        {
                            Log.Message("Empire Error - Zero races available for faction - Report this");
                            Log.Message("Resetting race filter");
                            faction.resetRaceFilter();
                        }
                    }));
                }

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

            if (Widgets.ButtonText(buttonConfirm, "ConfirmChanges".Translate()))
            {
                Faction fact = FactionColonies.getPlayerColonyFaction();
                faction.title           = title;
                faction.name            = name;
                fact.Name               = name;
                faction.name            = name;
                faction.factionIconPath = tempFactionIconPath;
                faction.factionIcon     = tempFactionIcon;
                faction.updateFactionRaces();
                faction.factionBackup = fact;

                faction.updateFactionIcon(ref fact, "FactionIcons/" + tempFactionIconPath);


                if (!traitsChosen)
                {
                    //check each trait bool. If true and does not exist already, add to factionfc
                    if (boolMilitaristic)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.militaristic));
                    }
                    if (boolPacifist)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.pacifist));
                    }
                    if (boolAuthoritarian)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.authoritarian));
                    }
                    if (boolEgalitarian)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.egalitarian));
                    }
                    if (boolIsolationist)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.isolationist));
                    }
                    if (boolExpansionist)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.expansionist));
                    }
                    if (boolTechnocrat)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.technocratic));
                    }
                    if (boolFeudal)
                    {
                        faction.policies.Add(new FCPolicy(FCPolicyDefOf.feudal));
                    }
                }

                Find.WindowStack.TryRemove(this);
            }


            if (!traitsChosen)
            {
                switch (faction.policies.Count())
                {
                case 0:
                case 1:
                    alertText = "FCSelectTraits0".Translate();
                    break;

                case 2:
                    alertText = "FCSelectTraits2".Translate();
                    break;
                }
            }
            else
            {
                alertText = "FCTraitsChosen".Translate();
            }


            Widgets.Label(labelPickTrait, alertText);


            Texture2D icon = TexLoad.iconLoyalty;

            if (boolMilitaristic)
            {
                icon = FCPolicyDefOf.militaristic.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.militaristic.IconDark;
            }
            if (buttonMilitaristic.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonMilitaristic, returnPolicyText(FCPolicyDefOf.militaristic));
            }

            if (Widgets.ButtonImage(buttonMilitaristic, icon))
            {
                if (numberTraitsSelected <= 1 || boolMilitaristic)
                {
                    //Continue
                    if (boolPacifist == false)
                    {
                        boolMilitaristic = !boolMilitaristic;
                        if (boolMilitaristic)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.militaristic);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolAuthoritarian)
            {
                icon = FCPolicyDefOf.authoritarian.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.authoritarian.IconDark;
            }
            if (buttonAuthoritarian.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonAuthoritarian, returnPolicyText(FCPolicyDefOf.authoritarian));
            }

            if (Widgets.ButtonImage(buttonAuthoritarian, icon))
            {
                if (numberTraitsSelected <= 1 || boolAuthoritarian)
                {
                    //Continue
                    if (boolEgalitarian == false)
                    {
                        boolAuthoritarian = !boolAuthoritarian;
                        if (boolAuthoritarian)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.authoritarian);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolIsolationist)
            {
                icon = FCPolicyDefOf.isolationist.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.isolationist.IconDark;
            }
            if (buttonIsolationist.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonIsolationist, returnPolicyText(FCPolicyDefOf.isolationist));
            }

            if (Widgets.ButtonImage(buttonIsolationist, icon))
            {
                if (numberTraitsSelected <= 1 || boolIsolationist)
                {
                    //Continue
                    if (boolExpansionist == false)
                    {
                        boolIsolationist = !boolIsolationist;
                        if (boolIsolationist)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.isolationist);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolFeudal)
            {
                icon = FCPolicyDefOf.feudal.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.feudal.IconDark;
            }
            if (buttonFeudal.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonFeudal, returnPolicyText(FCPolicyDefOf.feudal));
            }

            if (Widgets.ButtonImage(buttonFeudal, icon))
            {
                if (numberTraitsSelected <= 1 || boolFeudal)
                {
                    //Continue
                    if (boolTechnocrat == false)
                    {
                        boolFeudal = !boolFeudal;
                        if (boolFeudal)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.feudal);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolPacifist)
            {
                icon = FCPolicyDefOf.pacifist.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.pacifist.IconDark;
            }
            if (buttonPacifist.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonPacifist, returnPolicyText(FCPolicyDefOf.pacifist));
            }

            if (Widgets.ButtonImage(buttonPacifist, icon))
            {
                if (numberTraitsSelected <= 1 || boolPacifist)
                {
                    //Continue
                    if (boolMilitaristic == false)
                    {
                        boolPacifist = !boolPacifist;
                        if (boolPacifist)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.pacifist);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolEgalitarian)
            {
                icon = FCPolicyDefOf.egalitarian.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.egalitarian.IconDark;
            }
            if (buttonEgalitarian.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonEgalitarian, returnPolicyText(FCPolicyDefOf.egalitarian));
            }

            if (Widgets.ButtonImage(buttonEgalitarian, icon))
            {
                if (numberTraitsSelected <= 1 || boolEgalitarian)
                {
                    //Continue
                    if (boolAuthoritarian == false)
                    {
                        boolEgalitarian = !boolEgalitarian;
                        if (boolEgalitarian)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.egalitarian);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolExpansionist)
            {
                icon = FCPolicyDefOf.expansionist.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.expansionist.IconDark;
            }
            if (buttonExpansionist.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonExpansionist, returnPolicyText(FCPolicyDefOf.expansionist));
            }

            if (Widgets.ButtonImage(buttonExpansionist, icon))
            {
                if (numberTraitsSelected <= 1 || boolExpansionist)
                {
                    //Continue
                    if (boolIsolationist == false)
                    {
                        boolExpansionist = !boolExpansionist;
                        if (boolExpansionist)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.expansionist);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            if (boolTechnocrat)
            {
                icon = FCPolicyDefOf.technocratic.IconLight;
            }
            else
            {
                icon = FCPolicyDefOf.technocratic.IconDark;
            }
            if (buttonTechnocrat.Contains(Event.current.mousePosition))
            {
                TooltipHandler.TipRegion(buttonTechnocrat, returnPolicyText(FCPolicyDefOf.technocratic));
            }

            if (Widgets.ButtonImage(buttonTechnocrat, icon))
            {
                if (numberTraitsSelected <= 1 || boolTechnocrat)
                {
                    //Continue
                    if (boolFeudal == false)
                    {
                        boolTechnocrat = !boolTechnocrat;
                        if (boolTechnocrat)
                        {
                            numberTraitsSelected += 1;
                        }
                        else
                        {
                            numberTraitsSelected -= 1;
                        }

                        policyText = returnPolicyText(FCPolicyDefOf.technocratic);
                    }
                    else
                    {
                        Messages.Message("FCConflictingTraits".Translate(), MessageTypeDefOf.RejectInput);
                    }
                }
                else
                {
                    Messages.Message("FCUnselectTrait".Translate(), MessageTypeDefOf.RejectInput);
                }
            }


            //Widgets.DrawMenuSection(menusectionTrait);
            //Widgets.Label(menusectionTrait, policyText);


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

            //top label
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;

            //build outline
            Widgets.DrawMenuSection(eventsBox);


            //loop through each event
            //GoTo Here if change
            int i = 0;

            Text.Anchor = TextAnchor.MiddleCenter;
            foreach (FCEvent evt in events)
            {
                i++;
                Rect name      = new Rect();
                Rect desc      = new Rect();
                Rect location  = new Rect();
                Rect time      = new Rect();
                Rect highlight = new Rect();


                name     = eventNameBase;
                desc     = eventDescBase;
                location = eventLocationBase;
                time     = eventTimeRemaining;

                name.y     = scroll + eventHeight * i;
                desc.y     = scroll + eventHeight * i;
                location.y = scroll + eventHeight * i;
                time.y     = scroll + eventHeight * i;

                highlight = new Rect(name.x, name.y, time.x + time.width, eventHeight);



                if (i % 2 == 0)
                {
                    Widgets.DrawHighlight(highlight);
                }
                Widgets.Label(name, evt.def.label);
                //
                if (Widgets.ButtonText(desc, "Desc"))
                {
                    if (evt.hasCustomDescription == false)
                    {
                        //If desc button clicked
                        string settlementString = "";
                        foreach (SettlementFC loc in evt.settlementTraitLocations)
                        {
                            if (loc != null)
                            {
                                if (settlementString == "")
                                {
                                    settlementString += loc.name;
                                }
                                else
                                {
                                    settlementString += ", " + loc.name;
                                }
                            }
                        }
                        if (settlementString != "")
                        {
                            Find.WindowStack.Add(new DescWindowFc(evt.def.description + "\n This event is affecting the following settlements: " + settlementString));
                        }
                        else
                        {
                            Find.WindowStack.Add(new DescWindowFc(evt.def.description));
                        }
                    }
                    else
                    {
                        //has custom description
                        Find.WindowStack.Add(new DescWindowFc(evt.customDescription));
                    }
                }
                //
                if (Widgets.ButtonText(location, "Location".Translate().CapitalizeFirst()))
                {
                    if (evt.hasDestination == true)
                    {
                        Find.WindowStack.Add(new SettlementWindowFc(faction.returnSettlementByLocation(evt.location, evt.planetName)));
                    }
                    else
                    {
                        if (evt.settlementTraitLocations.Count() > 0)
                        {
                            //if event affecting colonies
                            List <FloatMenuOption> list = new List <FloatMenuOption>();
                            foreach (SettlementFC settlement in evt.settlementTraitLocations)
                            {
                                if (settlement != null)
                                {
                                    list.Add(new FloatMenuOption(settlement.name, delegate { Find.WindowStack.Add(new SettlementWindowFc(settlement)); }));
                                }
                            }
                            if (list.Count == 0)
                            {
                                list.Add(new FloatMenuOption("Null", null));
                            }
                            Find.WindowStack.Add(new FloatMenu(list));
                        }
                        else
                        {
                            if (evt.def == FCEventDefOf.taxColony && evt.source != -1)
                            {
                                Find.WindowStack.Add(new SettlementWindowFc(faction.returnSettlementByLocation(evt.source, evt.planetName)));
                            }
                        }
                    }
                }
                Widgets.Label(time, (evt.timeTillTrigger - Find.TickManager.TicksGame).ToTimeString());
            }



            //Top label
            Widgets.ButtonTextSubtle(eventNameBase, "Name".Translate());
            Widgets.ButtonTextSubtle(eventDescBase, "Description".Translate());
            Widgets.ButtonTextSubtle(eventLocationBase, "Source".Translate());
            Widgets.ButtonTextSubtle(eventTimeRemaining, "TimeRemaining".Translate());

            //Menu Outline
            Widgets.DrawBox(eventsBox);


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


            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y);
            }
        }
Example #21
0
        public void DrawFireSupportBox(float x, float y, float rowHeight)
        {
            //Set Text anchor and font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;


            for (int i = 0; i <= selectedSupport.projectiles.Count; i++)
            {
                //Declare Rects
                Rect text = new Rect(x + 2, y + 2 + i * rowHeight + scroll, rowHeight - 4, rowHeight - 4);
                Rect cost = deriveRectRow(text, 2, 0, 150);
                Rect icon = deriveRectRow(cost, 2, 0, 250);
                //Rect name = deriveRectRow(icon, 2, 0, 150);
                Rect options   = deriveRectRow(icon, 2, 0, 74);
                Rect upArrow   = deriveRectRow(options, 12, 0, rowHeight - 4, rowHeight - 4);
                Rect downArrow = deriveRectRow(upArrow, 4);
                Rect delete    = deriveRectRow(downArrow, 12);
                //Create outside box last to encapsulate entirety
                Rect box = new Rect(x, y + i * rowHeight + scroll, delete.x + delete.width + 4 - x, rowHeight);


                Widgets.DrawHighlight(box);
                Widgets.DrawMenuSection(box);

                if (i == selectedSupport.projectiles.Count)
                {
                    //If on last row
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(text, i.ToString());
                    if (Widgets.ButtonTextSubtle(icon, "Add new projectile"))
                    {
                        //if creating new projectile
                        List <FloatMenuOption> thingOptions = new List <FloatMenuOption>();
                        foreach (ThingDef def in selectedSupport.returnFireSupportOptions())
                        {
                            thingOptions.Add(new FloatMenuOption(
                                                 def.LabelCap + " - " + Math.Round(def.BaseMarketValue * 1.5, 2).ToString(),
                                                 delegate { selectedSupport.projectiles.Add(def); }, def));
                        }

                        if (!thingOptions.Any())
                        {
                            thingOptions.Add(
                                new FloatMenuOption("No available projectiles found", delegate { }));
                        }

                        Find.WindowStack.Add(new FloatMenu(thingOptions));
                    }
                }
                else
                {
                    //if on row with projectile
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(text, i.ToString());
                    if (Widgets.ButtonTextSubtle(icon, ""))
                    {
                        List <FloatMenuOption> thingOptions = new List <FloatMenuOption>();
                        foreach (ThingDef def in selectedSupport.returnFireSupportOptions())
                        {
                            int k = i;
                            thingOptions.Add(new FloatMenuOption(
                                                 def.LabelCap + " - " + Math.Round(def.BaseMarketValue * 1.5, 2).ToString(),
                                                 delegate { selectedSupport.projectiles[k] = def; }, def));
                        }

                        if (!thingOptions.Any())
                        {
                            thingOptions.Add(
                                new FloatMenuOption("No available projectiles found", delegate { }));
                        }

                        Find.WindowStack.Add(new FloatMenu(thingOptions));
                    }

                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(cost,
                                  "$ " + (Math.Round(selectedSupport.projectiles[i].BaseMarketValue * 1.5,
                                                     2))); //ADD in future mod setting for firesupport cost

                    Widgets.DefLabelWithIcon(icon, selectedSupport.projectiles[i]);
                    if (Widgets.ButtonTextSubtle(options, "Options"))
                    {
                        //If clicked options button
                        int k = i;
                        List <FloatMenuOption> listOptions = new List <FloatMenuOption>
                        {
                            new FloatMenuOption("Insert Projectile Above Slot", delegate
                            {
                                List <FloatMenuOption> thingOptions = new List <FloatMenuOption>();
                                foreach (ThingDef def in selectedSupport.returnFireSupportOptions())
                                {
                                    thingOptions.Add(new FloatMenuOption(
                                                         def.LabelCap + " - " + Math.Round(def.BaseMarketValue * 1.5, 2).ToString(),
                                                         delegate
                                    {
                                        Log.Message("insert at " + k);
                                        selectedSupport.projectiles.Insert(k, def);
                                    }, def));
                                }

                                if (!thingOptions.Any())
                                {
                                    thingOptions.Add(new FloatMenuOption("No available projectiles found",
                                                                         delegate { }));
                                }

                                Find.WindowStack.Add(new FloatMenu(thingOptions));
                            }),
                            new FloatMenuOption("Duplicate", delegate
                            {
                                ThingDef tempDef = selectedSupport.projectiles[k];
                                List <FloatMenuOption> thingOptions = new List <FloatMenuOption>();

                                thingOptions.Add(new FloatMenuOption("1x", delegate
                                {
                                    for (int l = 0; l < 1; l++)
                                    {
                                        if (k == selectedSupport.projectiles.Count - 1)
                                        {
                                            selectedSupport.projectiles.Add(tempDef);
                                        }
                                        else
                                        {
                                            selectedSupport.projectiles.Insert(k + 1, tempDef);
                                        }
                                    }
                                }));
                                thingOptions.Add(new FloatMenuOption("5x", delegate
                                {
                                    for (int l = 0; l < 5; l++)
                                    {
                                        if (k == selectedSupport.projectiles.Count - 1)
                                        {
                                            selectedSupport.projectiles.Add(tempDef);
                                        }
                                        else
                                        {
                                            selectedSupport.projectiles.Insert(k + 1, tempDef);
                                        }
                                    }
                                }));
                                thingOptions.Add(new FloatMenuOption("10x", delegate
                                {
                                    for (int l = 0; l < 10; l++)
                                    {
                                        if (k == selectedSupport.projectiles.Count - 1)
                                        {
                                            selectedSupport.projectiles.Add(tempDef);
                                        }
                                        else
                                        {
                                            selectedSupport.projectiles.Insert(k + 1, tempDef);
                                        }
                                    }
                                }));
                                thingOptions.Add(new FloatMenuOption("20x", delegate
                                {
                                    for (int l = 0; l < 20; l++)
                                    {
                                        if (k == selectedSupport.projectiles.Count - 1)
                                        {
                                            selectedSupport.projectiles.Add(tempDef);
                                        }
                                        else
                                        {
                                            selectedSupport.projectiles.Insert(k + 1, tempDef);
                                        }
                                    }
                                }));
                                thingOptions.Add(new FloatMenuOption("50x", delegate
                                {
                                    for (int l = 0; l < 50; l++)
                                    {
                                        if (k == selectedSupport.projectiles.Count - 1)
                                        {
                                            selectedSupport.projectiles.Add(tempDef);
                                        }
                                        else
                                        {
                                            selectedSupport.projectiles.Insert(k + 1, tempDef);
                                        }
                                    }
                                }));
                                Find.WindowStack.Add(new FloatMenu(thingOptions));
                            })
                        };
                        Find.WindowStack.Add(new FloatMenu(listOptions));
                    }

                    if (Widgets.ButtonTextSubtle(upArrow, ""))
                    {
                        //if click up arrow button
                        if (i != 0)
                        {
                            ThingDef temp = selectedSupport.projectiles[i];
                            selectedSupport.projectiles[i]     = selectedSupport.projectiles[i - 1];
                            selectedSupport.projectiles[i - 1] = temp;
                        }
                    }

                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(upArrow, "^");
                    if (Widgets.ButtonTextSubtle(downArrow, ""))
                    {
                        //if click down arrow button
                        if (i != selectedSupport.projectiles.Count - 1)
                        {
                            ThingDef temp = selectedSupport.projectiles[i];
                            selectedSupport.projectiles[i]     = selectedSupport.projectiles[i + 1];
                            selectedSupport.projectiles[i + 1] = temp;
                        }
                    }

                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(downArrow, "v");
                    if (Widgets.ButtonTextSubtle(delete, ""))
                    {
                        //if click delete  button
                        selectedSupport.projectiles.RemoveAt(i);
                    }

                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(delete, "X");
                }
            }

            //Reset Text anchor and font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
        public override void DoWindowContents(Rect inRect)
        {
            if (console == null)
            {
                return;
            }

            if (!st.IsRunning)
            {
                st.Start();
            }

            if (st.ElapsedMilliseconds >= RefreshInterval)
            {
                st.Restart();
                Refresh();
            }

            bool  indented = false;
            int   column   = 0;
            float itemHeight;

            Text.Font = GameFont.Medium;
            Widgets.Label(GetItemRect(40), $"<b>{"AA.PowerNetInfo".Translate()}</b>");
            float  totalPower     = console.PowerTraderComp.PowerNet.CurrentEnergyGainRate() / CompPower.WattsToWattDaysPerTick;
            string totalPowerText = GetPrettyPower(totalPower);

            if (totalPower > 0)
            {
                totalPowerText = $"<color=green>{totalPowerText}</color>";
            }
            if (totalPower < 0)
            {
                totalPowerText = $"<color=red>{totalPowerText}</color>";
            }
            Widgets.Label(new Rect(inRect.x + 200, inRect.y, 200, 32), totalPowerText);

            if (InstantFlickActive)
            {
                string flickActiveText = $"<color=yellow>{"AA.InstantFlickActive".Translate()}</color>";
                var    flickActiveSize = Text.CalcSize(flickActiveText);
                Widgets.Label(new Rect(inRect.xMax - flickActiveSize.x - 5, inRect.y, flickActiveSize.x, 32), flickActiveText);
            }
            MoveDown(45);
            Text.Font = GameFont.Small;

            if (console?.PowerTraderComp?.PowerNet == null)
            {
                Widgets.Label(GetItemRect(40), "AA.ConsoleNotConnected".Translate());
                return;
            }
            if (!console.PowerTraderComp.PowerOn)
            {
                Widgets.Label(GetItemRect(40), "AA.ConsoleNotPowered".Translate());
                return;
            }

            GetItemRect(32);

            string ascDec = Ascending ? "AA.Ascending".Translate() : "AA.Descending".Translate();
            var    isCat  = true;

            // Name.
            if (Widgets.ButtonTextSubtle(GetColumnRect(), $"<b>{"AA.Name".Translate().CapitalizeFirst()}</b> {(SortingMode == SortMode.Name ? ascDec : "")}"))
            {
                if (SortingMode != SortMode.Name)
                {
                    SortingMode = SortMode.Name;
                    Ascending   = true;
                    Refresh();
                    return;
                }
                else
                {
                    Ascending = !Ascending;
                    Refresh();
                    return;
                }
            }

            // Power in/out.
            if (Widgets.ButtonTextSubtle(GetColumnRect(), $"<b>{"AA.Power".Translate().CapitalizeFirst()}</b> {(SortingMode == SortMode.Power ? ascDec : "")}"))
            {
                {
                    if (SortingMode != SortMode.Power)
                    {
                        SortingMode = SortMode.Power;
                        Ascending   = true;
                        Refresh();
                        return;
                    }
                    else
                    {
                        Ascending = !Ascending;
                        Refresh();
                        return;
                    }
                }
            }

            // Turn on/off
            if (Widgets.ButtonTextSubtle(GetColumnRect(), $"<b>{"AA.Enabled".Translate().CapitalizeFirst()}</b> {(SortingMode == SortMode.Enabled ? ascDec : "")}"))
            {
                {
                    if (SortingMode != SortMode.Enabled)
                    {
                        SortingMode = SortMode.Enabled;
                        Ascending   = true;
                        Refresh();
                        return;
                    }
                    else
                    {
                        Ascending = !Ascending;
                        Refresh();
                        return;
                    }
                }
            }

            MoveDown(32 + 10f);

            Widgets.BeginScrollView(new Rect(inRect.x, inRect.y, inRect.width, inRect.height - 100), ref scroll, new Rect(inRect.x, inRect.y, inRect.width - 20, lastHeight));
            lastHeight = 0f;

            foreach (var cat in AllCats)
            {
                if (cat.Count == 1)
                {
                    indented = false;
                    isCat    = true;
                    DrawThing(cat.Things[0]);
                }
                else
                {
                    indented = false;
                    isCat    = true;
                    var r = GetItemRect(36f);
                    column = 0;
                    Widgets.DrawBox(r, 2);

                    var  expRect = new Rect(inRect.x, inRect.y, 32, 32);
                    bool isExp   = IsExpanded(cat.DefName);
                    if (Widgets.ButtonImage(expRect, isExp ? Content.Collapse : Content.Expand))
                    {
                        isExp = !isExp;
                        SetExpanded(cat.DefName, isExp);
                    }

                    // Name.
                    var labelRect = GetColumnRect();
                    Widgets.Label(labelRect.GetInner(), cat.Label + $" x{cat.Count}");

                    if (Widgets.ButtonInvisible(labelRect))
                    {
                        Vector3 averagePos = Vector3.zero;
                        if (!Input.GetKey(KeyCode.LeftShift))
                        {
                            Find.Selector.ClearSelection();
                        }
                        foreach (var thing in cat.Things)
                        {
                            averagePos += thing.Thing.DrawPos;
                            Find.Selector.Select(thing.Thing);
                        }
                        averagePos /= cat.Things.Count;

                        Find.CameraDriver.JumpToCurrentMapLoc(averagePos);
                    }

                    // Power in/out.
                    float  catPower = cat.TotalPower;
                    string wattText = GetPrettyPower(catPower);
                    if (catPower > 0)
                    {
                        wattText = $"<color=green>{wattText}</color>";
                    }
                    if (catPower < 0)
                    {
                        wattText = $"<color=red>{wattText}</color>";
                    }

                    Widgets.Label(GetColumnRect().GetInner(), wattText);

                    // Turn on/off
                    var  fr = GetColumnRect();
                    bool on = cat.AreAllEnabled(out int flickable);

                    if (flickable > 0 && Widgets.ButtonText(fr.GetInner(3), $"{"AA.TurnAll".Translate()} {(on ? "AA.Off".Translate() : "AA.On".Translate())}"))
                    {
                        cat.FlickAll(on);
                        Refresh();
                        Widgets.EndScrollView();
                        return;
                    }

                    MoveDown(32 + 10f);

                    isCat = false;

                    if (!isExp)
                    {
                        continue;
                    }
                    indented = true;
                    foreach (var thing in cat.Things)
                    {
                        DrawThing(thing);
                    }
                }
            }

            Widgets.EndScrollView();

            void DrawThing(PowerThing thing)
            {
                var r = GetItemRect(32);

                column = 0;
                Widgets.DrawBox(r);

                // Name.
                Rect nameRect = GetColumnRect();

                Widgets.Label(nameRect.GetInner(), thing.Thing.LabelShortCap);

                // Power in/out.
                string wattText = GetPrettyPower(thing.Watts);

                if (thing.Watts > 0)
                {
                    wattText = $"<color=green>{wattText}</color>";
                }
                if (thing.Watts < 0)
                {
                    wattText = $"<color=red>{wattText}</color>";
                }

                Widgets.Label(GetColumnRect().GetInner(), wattText);

                // Turn on/off
                var fr = GetColumnRect();

                if (thing.FlickComp != null)
                {
                    if (Widgets.ButtonText(fr.GetInner(3), $"{"AA.Turn".Translate().CapitalizeFirst()} {(thing.IsFlickedOn() ? "AA.Off".Translate() : "AA.On".Translate())}"))
                    {
                        thing.Flick();
                    }
                }

                if (Widgets.ButtonInvisible(nameRect))
                {
                    Find.CameraDriver.JumpToCurrentMapLoc(thing.Thing.DrawPos);
                    if (!Input.GetKey(KeyCode.LeftShift))
                    {
                        Find.Selector.ClearSelection();
                    }
                    Find.Selector.Select(thing.Thing);
                }

                MoveDown(32 + 10f);
            }

            Rect GetItemRect(float height)
            {
                int add = indented ? 32 : 0;
                var r   = new Rect(inRect.x + add, inRect.y, inRect.width - 20 - add, height);

                itemHeight = height;
                return(r);
            }

            Rect GetColumnRect()
            {
                int add = indented ? 32 : 0;

                if (isCat)
                {
                    add += 32;
                }
                var r = new Rect(inRect.x + cumulativeWidths[column] + add, inRect.y, columnWidths[column], itemHeight);

                column++;
                return(r);
            }

            void MoveDown(float amount)
            {
                inRect.y      += amount;
                inRect.height += amount;
                lastHeight    += amount;
            }
        }
Example #23
0
        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.MiddleCenter;
            Text.Font   = GameFont.Small;

            Widgets.DrawMenuSection(menuSectionHeader);
            Widgets.DrawBox(menuSectionHeader);
            //Icon button
            if (Widgets.ButtonImage(headerFactionIcon, faction.factionIcon))
            {
            }

            Text.Anchor = TextAnchor.MiddleLeft;
            Text.Font   = GameFont.Medium;
            Widgets.Label(headerFactionName, faction.name);

            Text.Font = GameFont.Small;
            Widgets.Label(headerFactionTitle, faction.title);

            //Settings button
            if (Widgets.ButtonImage(headerSettings, TexLoad.iconCustomize))
            {
                Faction fact = FactionColonies.getPlayerColonyFaction();
                if (fact != null)
                {
                    Find.WindowStack.Add(new FactionCustomizeWindowFc(faction));
                }
            }


            //Progress bar

            Widgets.FillableBar(progressBarLevelUp, faction.factionXPCurrent / faction.factionXPGoal, foreground,
                                background, true);
            Widgets.DrawShadowAround(progressBarLevelUp);
            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(progressBarLevelUp, Math.Round(faction.factionXPCurrent) + "/" + faction.factionXPGoal);
            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.DrawBox(progressBarLevelUp);

            Text.Font = GameFont.Small;
            Widgets.Label(factionLevel, "FCLevel".Translate(faction.factionLevel));


            //Policies
            if (faction.policies.Count() == 2)
            {
                Widgets.ButtonImage(policy_1, faction.policies[0].def.IconLight);
                if (policy_1.Contains(Event.current.mousePosition))
                {
                    TooltipHandler.TipRegion(policy_1, returnPolicyText(faction.policies[0].def));
                }

                //Widgets.Label(policy_2, new GUIContent("test", "test test test"));
                Widgets.ButtonImage(policy_2, faction.policies[1].def.IconLight);
                if (policy_2.Contains(Event.current.mousePosition))
                {
                    TooltipHandler.TipRegion(policy_2, returnPolicyText(faction.policies[1].def));
                }
            }
            else
            {
                Widgets.Label(new Rect(policy_1.x, policy_1.y, 200, 50), "FCSelectYourTraits".Translate());
            }


            List <FloatMenuOption> list      = new List <FloatMenuOption>();
            List <FCPolicyDef>     available = availableTraitsList();

            //Trait)

            //TraitSlot
            if (Widgets.ButtonTextSubtle(trait_1, returnTraitAvailibility(1, faction.factionTraits[0]))) //CHANGE THIS
            {
                if (canChangeTrait(1, faction.factionTraits[0]))
                {
                    foreach (FCPolicyDef trait in available)
                    {
                        list.Add(new FloatMenuOption(trait.label, delegate
                        {
                            List <FloatMenuOption> confirm = new List <FloatMenuOption>();
                            confirm.Add(new FloatMenuOption("FCConfirmTrait".Translate(trait.label),
                                                            delegate { faction.factionTraits[0] = new FCPolicy(trait); }));
                            Find.WindowStack.Add(new FloatMenu(confirm));
                        },
                                                     mouseoverGuiAction: delegate
                        {
                            TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(100, 200)),
                                                     returnPolicyText(trait));
                        }));
                    }

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

            if (Mouse.IsOver(trait_1) && faction.factionTraits[0].def != FCPolicyDefOf.empty)
            {
                TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(100, 200)),
                                         returnPolicyText(faction.factionTraits[0].def));
            }
            //End Trait Slot

            //TraitSlot
            if (Widgets.ButtonTextSubtle(trait_2, returnTraitAvailibility(2, faction.factionTraits[1]))) //CHANGE THIS
            {
                if (canChangeTrait(2, faction.factionTraits[1]))
                {
                    foreach (FCPolicyDef trait in available)
                    {
                        list.Add(new FloatMenuOption(trait.label, delegate
                        {
                            List <FloatMenuOption> confirm = new List <FloatMenuOption>();
                            confirm.Add(new FloatMenuOption("FCConfirmTrait".Translate(trait.label),
                                                            delegate { faction.factionTraits[1] = new FCPolicy(trait); }));
                            Find.WindowStack.Add(new FloatMenu(confirm));
                        },
                                                     mouseoverGuiAction: delegate
                        {
                            TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(200, 200)),
                                                     returnPolicyText(trait));
                        }));
                    }

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

            if (Mouse.IsOver(trait_2) && faction.factionTraits[1].def != FCPolicyDefOf.empty)
            {
                TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(200, 200)),
                                         returnPolicyText(faction.factionTraits[1].def));
            }
            //End Trait Slot

            //TraitSlot
            if (Widgets.ButtonTextSubtle(trait_3, returnTraitAvailibility(3, faction.factionTraits[2]))) //CHANGE THIS
            {
                if (canChangeTrait(3, faction.factionTraits[2]))
                {
                    foreach (FCPolicyDef trait in available)
                    {
                        list.Add(new FloatMenuOption(trait.label, delegate
                        {
                            List <FloatMenuOption> confirm = new List <FloatMenuOption>();
                            confirm.Add(new FloatMenuOption("FCConfirmTrait".Translate(trait.label),
                                                            delegate { faction.factionTraits[2] = new FCPolicy(trait); }));
                            Find.WindowStack.Add(new FloatMenu(confirm));
                        },
                                                     mouseoverGuiAction: delegate
                        {
                            TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(300, 200)),
                                                     returnPolicyText(trait));
                        }));
                    }

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

            if (Mouse.IsOver(trait_3) && faction.factionTraits[2].def != FCPolicyDefOf.empty)
            {
                TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(300, 200)),
                                         returnPolicyText(faction.factionTraits[2].def));
            }
            //End Trait Slot

            //TraitSlot
            if (Widgets.ButtonTextSubtle(trait_4, returnTraitAvailibility(4, faction.factionTraits[3]))) //CHANGE THIS
            {
                if (canChangeTrait(4, faction.factionTraits[3]))
                {
                    foreach (FCPolicyDef trait in available)
                    {
                        list.Add(new FloatMenuOption(trait.label, delegate
                        {
                            List <FloatMenuOption> confirm = new List <FloatMenuOption>();
                            confirm.Add(new FloatMenuOption("FCConfirmTrait".Translate(trait.label),
                                                            delegate { faction.factionTraits[3] = new FCPolicy(trait); }));
                            Find.WindowStack.Add(new FloatMenu(confirm));
                        },
                                                     mouseoverGuiAction: delegate
                        {
                            TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(400, 200)),
                                                     returnPolicyText(trait));
                        }));
                    }

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

            if (Mouse.IsOver(trait_4) && faction.factionTraits[3].def != FCPolicyDefOf.empty)
            {
                TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(400, 200)),
                                         returnPolicyText(faction.factionTraits[3].def));
            }
            //End Trait Slot

            //TraitSlot
            if (Widgets.ButtonTextSubtle(trait_5, returnTraitAvailibility(5, faction.factionTraits[4]))) //CHANGE THIS
            {
                if (canChangeTrait(5, faction.factionTraits[4]))
                {
                    foreach (FCPolicyDef trait in available)
                    {
                        list.Add(new FloatMenuOption(trait.label, delegate
                        {
                            List <FloatMenuOption> confirm = new List <FloatMenuOption>();
                            confirm.Add(new FloatMenuOption("FCConfirmTrait".Translate(trait.label),
                                                            delegate { faction.factionTraits[4] = new FCPolicy(trait); }));
                            Find.WindowStack.Add(new FloatMenu(confirm));
                        },
                                                     mouseoverGuiAction: delegate
                        {
                            TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(500, 200)),
                                                     returnPolicyText(trait));
                        }));
                    }

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

            if (Mouse.IsOver(trait_5) && faction.factionTraits[4].def != FCPolicyDefOf.empty)
            {
                TooltipHandler.TipRegion(new Rect(Event.current.mousePosition, new Vector2(500, 200)),
                                         returnPolicyText(faction.factionTraits[4].def));
            }
            //End Trait Slot

            FactionFC fc = Find.World.GetComponent <FactionFC>();

            Widgets.Label(roadBuilding, "FCBuildRoads".Translate());
            Widgets.Checkbox(roadBuilding.x + roadBuilding.width + 5, roadBuilding.y,
                             ref fc.roadBuilder.roadBuildingEnabled);

            //SettlementBox


            Widgets.DrawMenuSection(settlementsBox);
            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.MiddleCenter;
            GUI.BeginGroup(settlementsBoxLabels);
            Widgets.DrawMenuSection(new Rect(0, 0, settlementsBox.width, 20));
            Widgets.DrawLightHighlight(new Rect(0, 0, settlementsBox.width, 20));
            Widgets.Label(settlement_1, "Name");
            if (Widgets.ButtonInvisible(settlement_1))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementName);
            }

            Widgets.Label(settlement_2, "Level");
            if (Widgets.ButtonInvisible(settlement_2))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementLevel);
            }

            Widgets.Label(settlement_3, "Mil Level");
            if (Widgets.ButtonInvisible(settlement_3))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementMilitaryLevel);
            }

            Widgets.Label(settlement_4, "Profit");
            if (Widgets.ButtonInvisible(settlement_4))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementProfit);
            }

            Widgets.Label(settlement_5, "Free Workers");
            if (Widgets.ButtonInvisible(settlement_5))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementFreeWorkers);
            }

            Widgets.Label(settlement_6, "Happiness");
            if (Widgets.ButtonInvisible(settlement_6))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementHappiness);
            }

            Widgets.Label(settlement_7, "Loyalty");
            if (Widgets.ButtonInvisible(settlement_7))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementLoyalty);
            }

            Widgets.Label(settlement_8, "Unrest");
            if (Widgets.ButtonInvisible(settlement_8))
            {
                faction.settlements.Sort(FactionColonies.CompareSettlementUnrest);
            }


            GUI.EndGroup();


            GUI.BeginGroup(settlementsBox);

            for (int i = 0; i < faction.settlements.Count(); i++)
            {
                SettlementFC settlement = faction.settlements[i];

                //settlement name
                if (Widgets.ButtonTextSubtle(AdjustRect(settlement_1, i), settlement.name))
                {
                    Find.WindowStack.Add(new SettlementWindowFc(settlement));
                }

                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(AdjustRect(settlement_2, i), settlement.settlementLevel.ToString());
                Widgets.Label(AdjustRect(settlement_3, i), settlement.settlementMilitaryLevel.ToString());
                Widgets.Label(AdjustRect(settlement_4, i), ((int)settlement.getTotalProfit()).ToString());
                Widgets.Label(AdjustRect(settlement_5, i), (settlement.workersUltraMax - settlement.getTotalWorkers()).ToString());
                Widgets.Label(AdjustRect(settlement_6, i), ((int)settlement.Happiness).ToString());
                Widgets.Label(AdjustRect(settlement_7, i), ((int)settlement.Loyalty).ToString());
                Widgets.Label(AdjustRect(settlement_8, i), ((int)settlement.Unrest).ToString());
            }

            GUI.EndGroup();


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

            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y);
            }
        }
        public override void DoWindowContents(Rect inRect)
        {
            //grab before anchor/font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            //Buildings
            for (int i = 0; i < buildingList.Count; i++)
            {
                BuildingFCDef building = buildingList[i];
                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))
                            {
                                return;
                            }
                            FCEvent tmpEvt = new FCEvent(true)
                            {
                                def          = FCEventDefOf.constructBuilding,
                                source       = settlement.mapLocation,
                                planetName   = settlement.planetName,
                                building     = building,
                                buildingSlot = buildingSlot
                            };


                            int triggerTime = building.constructionDuration;
                            if (factionfc.hasPolicy(FCPolicyDefOf.isolationist))
                            {
                                triggerTime /= 2;
                            }

                            tmpEvt.timeTillTrigger = Find.TickManager.TicksGame + triggerTime;
                            Find.World.GetComponent <FactionFC>().addEvent(tmpEvt);

                            PaymentUtil.paySilver(Convert.ToInt32(building.cost));
                            settlement.deconstructBuilding(buildingSlot);
                            Messages.Message(building.label + " " + "WillBeConstructedIn".Translate() + " " + (tmpEvt.timeTillTrigger - Find.TickManager.TicksGame).ToTimeString(), 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);
            }


            //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);
            }
        }
Example #25
0
        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 < 4; i++)             //for each field to customize
            {
                switch (i)
                {
                case 0:                          //faction name
                    Widgets.Label(new Rect(xoffset + 3, yoffset + yspacing * i, length / 4, yspacing), "FactionName".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), "FactionTitle".Translate() + ": ");
                    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), "FactionIcon".Translate() + ": ");
                    if (Widgets.ButtonImage(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i, 40, 40), tempFactionIcon)) //change to faction icon
                    {
                        List <FloatMenuOption> list = new List <FloatMenuOption>();
                        foreach (KeyValuePair <string, Texture2D> pair in texLoad.factionIcons)
                        {
                            list.Add(new FloatMenuOption(pair.Key, delegate
                            {
                                tempFactionIcon     = pair.Value;
                                tempFactionIconPath = pair.Key;
                            }, pair.Value, Color.white));
                        }
                        FloatMenu menu = new FloatMenu(list);
                        Find.WindowStack.Add(menu);

                        //Messages.Message("ButtonNotAvailable".Translate() + ".", MessageTypeDefOf.CautionInput);
                        //Log.Message("Faction icon select pressed");
                        //Open window to select new icon
                    }
                    break;

                case 3:
                    if (Widgets.ButtonTextSubtle(new Rect(xoffset + 3 + length / 4 + 5, yoffset + yspacing * i + 15, length / 2, yspacing), "AllowedRaces".Translate()))                              //change to faction icon
                    {
                        List <string>          races = new List <string>();
                        List <FloatMenuOption> list  = new List <FloatMenuOption>();
                        list.Add(new FloatMenuOption("Enable All", delegate { faction.resetRaceFilter(); }));
                        foreach (PawnKindDef def in DefDatabase <PawnKindDef> .AllDefsListForReading)
                        {
                            if (def.race.race.intelligence == Intelligence.Humanlike & races.Contains(def.race.label) == false && def.race.BaseMarketValue != 0)
                            {
                                if (def.race.label == "Human" && def.LabelCap != "Colonist")
                                {
                                }
                                else
                                {
                                    races.Add(def.race.label);
                                    list.Add(new FloatMenuOption(def.race.label.CapitalizeFirst() + " - Allowed: " + faction.raceFilter.Allows(def.race), delegate
                                    {
                                        if (faction.raceFilter.AllowedThingDefs.Count() == 1 && faction.raceFilter.Allows(def.race) == true)
                                        {
                                            Messages.Message("CannotHaveLessThanOneRace".Translate(), MessageTypeDefOf.RejectInput);
                                        }
                                        else if (faction.raceFilter.AllowedThingDefs.Count() > 1)
                                        {
                                            faction.raceFilter.SetAllow(def.race, !faction.raceFilter.Allows(def.race));
                                        }
                                        else
                                        {
                                            Log.Message("Empire Error - Zero races available for faction - Report this");
                                            Log.Message("Reseting race filter");
                                            faction.resetRaceFilter();
                                        }
                                    }));
                                }
                            }
                        }
                        FloatMenu menu = new FloatMenu(list);
                        Find.WindowStack.Add(menu);

                        //Messages.Message("ButtonNotAvailable".Translate() + ".", MessageTypeDefOf.CautionInput);
                        //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()))
            {
                Faction   fact      = FactionColonies.getPlayerColonyFaction();
                FactionFC component = Find.World.GetComponent <FactionFC>();
                faction.title             = title;
                faction.name              = name;
                fact.Name                 = name;
                component.name            = name;
                component.factionIconPath = tempFactionIconPath;
                component.factionIcon     = tempFactionIcon;
                component.updateFactionRaces();
                component.factionBackup = fact;

                faction.updateFactionIcon(ref fact, "FactionIcons/" + tempFactionIconPath);
                Find.LetterStack.ReceiveLetter("Note on Faction Icon", "Note: The faction icon on the world map will only update after a full restart of your game. Or pure luck.", LetterDefOf.NeutralEvent);
                Find.WindowStack.TryRemove(this);
            }

            //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));

            //reset anchor/font
            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;
        }
Example #26
0
        public override void DoWindowContents(Rect rect)
        {
            FactionFC faction = Find.World.GetComponent <FactionFC>();

            if (faction.militaryCustomizationUtil.DeployedSquads.Count() == 0)
            {
                this.Close();
            }

            GameFont   oldFont   = Text.Font;
            TextAnchor oldAnchor = Text.Anchor;

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;

            Rect selectSquad   = new Rect(0, 0, 160, 40);
            Rect commandAttack = new Rect(0, 40, 160, 40);
            Rect commandMove   = new Rect(0, 80, 160, 40);
            Rect commandHeal   = new Rect(0, 120, 160, 40);


            if (selectedSquad == null)
            {
                squadText = "Select Deployed Squad";
            }
            else
            {
                squadText = selectedSquad.getSettlement.name + "'s " + selectedSquad.outfit.name;
            }

            //Select a squad
            if (Widgets.ButtonText(selectSquad, squadText))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (MercenarySquadFC squad in faction.militaryCustomizationUtil.DeployedSquads)
                {
                    if (squad.getSettlement != null)
                    {
                        list.Add(new FloatMenuOption(squad.getSettlement.name + "'s " + squad.outfit.name, delegate
                        {
                            selectedSquad = squad;
                        }));
                    }
                }
                if (!list.Any())
                {
                    list.Add(new FloatMenuOption("No squads available", null));
                }

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



            if (Widgets.ButtonTextSubtle(commandAttack, "Attack"))
            {
                if (selectedSquad != null)
                {
                    selectedSquad.order = MilitaryOrders.Attack;
                    Messages.Message(selectedSquad.outfit.name + " are now charging the enemy.", MessageTypeDefOf.NeutralEvent);
                    //selectedSquad.orderLocation = Position;
                }
            }
            if (Widgets.ButtonTextSubtle(commandMove, "Move"))
            {
                if (selectedSquad != null)
                {
                    DebugTool tool;
                    IntVec3   Position;
                    tool = new DebugTool("Select Move Position", delegate()
                    {
                        Position = UI.MouseCell();

                        selectedSquad.order         = MilitaryOrders.Standby;
                        selectedSquad.orderLocation = Position;
                        Messages.Message(selectedSquad.outfit.name + " are moving to the position and standing by.", MessageTypeDefOf.NeutralEvent);

                        DebugTools.curTool = null;
                    });
                    DebugTools.curTool = tool;
                }
            }
            if (Widgets.ButtonTextSubtle(commandHeal, "Leave"))
            {
                if (selectedSquad != null)
                {
                    selectedSquad.order = MilitaryOrders.Leave;
                    Messages.Message(selectedSquad.outfit.name + " are now leaving the map. " + selectedSquad.dead + " dead.",
                                     MessageTypeDefOf.NeutralEvent);
                }
            }

            //Example command:

            //DebugTool tool = null;
            //IntVec3 Position;
            //tool = new DebugTool("Select Drop Position", delegate ()
            //{
            //   Position = UI.MouseCell();

            //    selectedSquad.order = MilitaryOrders.Standby;
            //    selectedSquad.orderLocation = Position;

            //    DebugTools.curTool = null;
            //});
            //DebugTools.curTool = tool;


            Text.Font   = oldFont;
            Text.Anchor = oldAnchor;
        }
Example #27
0
        public override void DoWindowContents(Rect inRect)
        {
            //grab before anchor/font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            //top label
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;



            Text.Anchor = TextAnchor.MiddleLeft;

            int i = 0;

            foreach (FCPrisoner prisoner in prisoners)
            {
                Rect Box;
                Rect PawnIcon;
                Rect PawnName;
                Rect PawnHealth;
                Rect PawnUnrest;
                Rect PawnWorkload;
                Rect ButtonInfo;
                Rect ButtonAction;

                Box          = optionBox;
                PawnIcon     = optionPawnIcon;
                PawnName     = optionPawnName;
                PawnHealth   = optionPawnHealth;
                PawnUnrest   = optionPawnUnrest;
                PawnWorkload = optionPawnWorkload;
                ButtonInfo   = optionButtonInfo;
                ButtonAction = optionButtonAction;

                Box.y          += scroll + optionHeight * i;
                PawnIcon.y     += scroll + optionHeight * i;
                PawnName.y     += scroll + optionHeight * i;
                PawnHealth.y   += scroll + optionHeight * i;
                PawnUnrest.y   += scroll + optionHeight * i;
                PawnWorkload.y += scroll + optionHeight * i;
                ButtonInfo.y   += scroll + optionHeight * i;
                ButtonAction.y += scroll + optionHeight * i;


                //display stuff now
                Widgets.DrawMenuSection(Box);
                //on every other box
                if (i % 2 == 0)
                {
                    Widgets.DrawHighlight(Box);
                }

                //show pawn;
                Widgets.ThingIcon(PawnIcon, prisoner.prisoner);
                //Pawn Name
                Widgets.Label(PawnName, prisoner.prisoner.Name.ToString());
                //Pawn Health
                Widgets.Label(PawnHealth, "Health".Translate().CapitalizeFirst() + " " + prisoner.health);
                //Pawn Unrest
                //Widgets.Label(PawnUnrest, "Unrest".Translate().CapitalizeFirst() + " " + prisoner.unrest);



                //Pawn Workload
                string workload;
                switch (prisoner.workload)
                {
                case FCWorkLoad.Heavy:
                    workload = "FCHeavy".Translate().CapitalizeFirst();
                    break;

                case FCWorkLoad.Medium:
                    workload = "FCMedium".Translate().CapitalizeFirst();
                    break;

                case FCWorkLoad.Light:
                    workload = "FCLight".Translate().CapitalizeFirst();
                    break;

                default:
                    workload = "null";
                    break;
                }
                if (Widgets.ButtonText(PawnWorkload, "FCWorkload".Translate().CapitalizeFirst() + ": " + workload))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    list.Add(new FloatMenuOption("FCHeavy".Translate().CapitalizeFirst() + " - " + "FCHeavyExplanation".Translate(), delegate
                    {
                        prisoner.workload = FCWorkLoad.Heavy;
                    }));
                    list.Add(new FloatMenuOption("FCMedium".Translate().CapitalizeFirst() + " - " + "FCMediumExplanation".Translate(), delegate
                    {
                        prisoner.workload = FCWorkLoad.Medium;
                    }));
                    list.Add(new FloatMenuOption("FCLight".Translate().CapitalizeFirst() + " - " + "FCLightExplanation".Translate(), delegate
                    {
                        prisoner.workload = FCWorkLoad.Light;
                    }));
                    FloatMenu menu = new FloatMenu(list);
                    Find.WindowStack.Add(menu);
                }

                //Info Button
                if (Widgets.ButtonTextSubtle(ButtonInfo, "ViewInfo".Translate()))
                {
                    Pawn pawn = new Pawn();
                    pawn = prisoner.prisoner;

                    if (prisoner.healthTracker != null)
                    {
                        prisoner.prisoner.health = prisoner.healthTracker;
                    }
                    else
                    {
                        prisoner.prisoner.health = new Pawn_HealthTracker(prisoner.prisoner);
                        prisoner.healthTracker   = new Pawn_HealthTracker(prisoner.prisoner);
                    }

                    pawn.health = prisoner.healthTracker;


                    Find.WindowStack.Add(new Dialog_InfoCard(pawn));
                }

                //Action button
                if (Widgets.ButtonTextSubtle(ButtonAction, "Actions".Translate()))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();

                    list.Add(new FloatMenuOption("SellPawn".Translate() + " $" + prisoner.prisoner.MarketValue + " " + "SellPawnInfo".Translate(), delegate

                    {
                        settlement.addSilverIncome(prisoner.prisoner.MarketValue);

                        //reset window
                        prisoners.Remove(prisoner);
                        WindowUpdate();
                        return;
                    }));

                    list.Add(new FloatMenuOption("ReturnToPlayer".Translate(), delegate
                    {
                        if (prisoner.healthTracker != null)
                        {
                            prisoner.prisoner.health = prisoner.healthTracker;
                        }
                        else
                        {
                            prisoner.prisoner.health = new Pawn_HealthTracker(prisoner.prisoner);
                            prisoner.healthTracker   = new Pawn_HealthTracker(prisoner.prisoner);
                        }
                        HealthUtility.DamageUntilDowned(prisoner.prisoner, false);
                        if (prisoner.prisoner.guest == null)
                        {
                            prisoner.prisoner.guest = new Pawn_GuestTracker();
                        }
                        prisoner.prisoner.guest.isPrisonerInt = true;
                        FieldInfo hostFaction = typeof(Pawn_GuestTracker).GetField("hostFactionInt", BindingFlags.NonPublic | BindingFlags.Instance);
                        hostFaction.SetValue(prisoner.prisoner.guest, Find.FactionManager.OfPlayer);

                        List <Thing> things = new List <Thing>();
                        things.Add(prisoner.prisoner);
                        DropPodUtility.DropThingsNear(DropCellFinder.TradeDropSpot(Find.CurrentMap), Find.CurrentMap, things);

                        //reset window
                        prisoners.Remove(prisoner);
                        WindowUpdate();
                        return;
                    }));


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



                //increment i
                i++;
            }

            Text.Font   = fontBefore;
            Text.Anchor = anchorBefore;

            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y);
            }
        }
        public void DoThingFilterConfigWindow(Rect canvas, ref Vector2 scrollPosition, ThingFilter filter,
                                              ThingFilter parentFilter = null, int openMask = 1,
                                              bool buttonsAtBottom     = false)
        {
            // respect your bounds!
            GUI.BeginGroup(canvas);
            canvas = canvas.AtZero();

            // set up buttons
            Text.Font = GameFont.Tiny;
            float width           = canvas.width - 2f;
            var   clearButtonRect = new Rect(canvas.x + 1f, canvas.y + 1f, width / 2f, 24f);
            var   allButtonRect   = new Rect(clearButtonRect.xMax + 1f, clearButtonRect.y, width / 2f, 24f);

            // offset canvas position for buttons.
            if (buttonsAtBottom)
            {
                clearButtonRect.y = canvas.height - clearButtonRect.height;
                allButtonRect.y   = canvas.height - clearButtonRect.height;
                canvas.yMax      -= clearButtonRect.height;
            }
            else
            {
                canvas.yMin = clearButtonRect.height;
            }

            // draw buttons + logic
            if (Widgets.ButtonTextSubtle(clearButtonRect, "ClearAll".Translate()))
            {
                filter.SetDisallowAll();
            }
            if (Widgets.ButtonTextSubtle(allButtonRect, "AllowAll".Translate()))
            {
                filter.SetAllowAll(parentFilter);
            }
            Text.Font = GameFont.Small;

            // do list
            var curY     = 2f;
            var viewRect = new Rect(0f, 0f, canvas.width - ScrollbarWidth, viewHeight);

            // scrollview
            Widgets.BeginScrollView(canvas, ref scrollPosition, viewRect);

            // slider(s)
            DrawHitPointsFilterConfig(ref curY, viewRect.width, filter);
            DrawQualityFilterConfig(ref curY, viewRect.width, filter);

            // main listing
            var listingRect            = new Rect(0f, curY, viewRect.width, 9999f);
            var listingTreeThingFilter = new Listing_TreeThingFilter(filter, parentFilter, null, null, null);

            listingTreeThingFilter.Begin(listingRect);
            TreeNode_ThingCategory node = ThingCategoryNodeDatabase.RootNode;

            if (parentFilter != null)
            {
                if (parentFilter.DisplayRootCategory == null)
                {
                    parentFilter.RecalculateDisplayRootCategory();
                }
                node = parentFilter.DisplayRootCategory;
            }

            // draw the actual thing
            listingTreeThingFilter.DoCategoryChildren(node, 0, openMask, Find.CurrentMap, true);
            listingTreeThingFilter.End();

            // update height.
            viewHeight = curY + listingTreeThingFilter.CurHeight;
            Widgets.EndScrollView();
            GUI.EndGroup();
        }
Example #29
0
        private void DoThingTab(Rect rect)
        {
            if (!Analyzer.SelectedMode.IsPatched)
            {
                Text.Font   = GameFont.Medium;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(rect, $"Loading{GenText.MarchingEllipsis(0f)}");
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.UpperLeft;
                return;
            }

            var  topslot = rect.TopPartPixels(20f);
            Rect rowby   = topslot.LeftPartPixels(25f);

            if (Widgets.ButtonImage(rowby, TexButton.SpeedButtonTextures[Analyzer.running ? 0 : 1]))
            {
                Analyzer.running = !Analyzer.running;
            }

            TooltipHandler.TipRegion(rowby, "Start and stop logging");
            bool save = false;

            if (Analyzer.Settings.AdvancedMode)
            {
                Rect searchbox = topslot.LeftPartPixels(topslot.width - 300f);
                searchbox.x += 25f;
                DubGUI.InputField(searchbox, "Search", ref TimesFilter, DubGUI.MintSearch);
                rowby.x     = searchbox.xMax;
                rowby.width = 175f;
                if (Widgets.ButtonTextSubtle(rowby, stlank, Mathf.Clamp01(Mathf.InverseLerp(H_RootUpdate.LastMinGC, H_RootUpdate.LastMaxGC, totalBytesOfMemoryUsed)), 5))
                {
                    totalBytesOfMemoryUsed = GC.GetTotalMemory(true);
                }
                TooltipHandler.TipRegion(rowby, "Approximation of total bytes currently allocated in managed memory + rate of new allocation\n\nClick to force GC");

                rowby.x     = rowby.xMax;
                rowby.width = 100f;
                save        = Widgets.ButtonTextSubtle(rowby, "Save .CSV");
                TooltipHandler.TipRegion(rowby, $"Save the current list of times to a csv file in {GenFilePaths.FolderUnderSaveData("Profiling")}");
            }
            else
            {
                Rect searchbox = topslot.RightPartPixels(topslot.width - 25f);
                DubGUI.InputField(searchbox, "Search", ref TimesFilter, DubGUI.MintSearch);
            }

            rowby.x     = rowby.xMax;
            rowby.width = 25f;


            rect.y      += 25f;
            rect.height -= 25f;

            var innyrek = rect.AtZero();

            innyrek.width -= 16f;
            innyrek.height = groaner;

            GizmoListRect    = rect.AtZero();
            GizmoListRect.y += scrolpos.y;
            Widgets.BeginScrollView(rect, ref scrolpos, innyrek);

            GUI.BeginGroup(innyrek);

            listing.Begin(innyrek);

            float goat = 0;

            //List<ProfileLog> logs = null;

            //if (Analyzer.SortBy == "First")
            //{
            //    logs = Analyzer.Logs.ToList();
            //}
            //else if (Analyzer.SortBy == "A-Z")
            //{
            //    logs = Analyzer.Logs.ToList().OrderBy(x => x.Key).ToList();
            //}
            //else if (Analyzer.SortBy == "Usage")
            //{
            //    logs = Analyzer.Logs.ToList().OrderByDescending(x => x.Average).ToList();
            //}

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

            lock (Analyzer.sync)
            {
                foreach (var log in Analyzer.Logs)
                {
                    if (!log.Label.Has(TimesFilter))
                    {
                        continue;
                    }

                    var r = listing.GetRect(40f);

                    if (r.Overlaps(GizmoListRect))
                    {
                        var profile = Analyzer.Profiles[log.Key];

                        if (Input.GetKey(KeyCode.LeftControl))
                        {
                            if (Widgets.ButtonInvisible(r))
                            {
                                Analyzer.SelectedMode.Clicked?.Invoke(null, new object[] { profile, log });
                                Analyzer.Settings.Write();
                            }
                        }

                        bool on = true;

                        if (Analyzer.SelectedMode.Selected != null)
                        {
                            on = (bool)Analyzer.SelectedMode.Selected.Invoke(null, new object[] { profile, log });
                        }

                        if (Analyzer.SelectedMode.Checkbox != null)
                        {
                            var r2 = new Rect(r.x, r.y, 25f, r.height);
                            r.x += 25f;
                            if (DubGUI.Checkbox(r2, "", ref on))
                            {
                                Analyzer.SelectedMode.Checkbox?.Invoke(null, new object[] { profile, log });
                                Analyzer.Settings.Write();
                            }
                        }

                        Widgets.DrawHighlightIfMouseover(r);

                        if (Widgets.ButtonInvisible(r))
                        {
                            Dialog_Graph.RunKey(log.Key);
                        }

                        if (Dialog_Graph.key == log.Key)
                        {
                            Widgets.DrawHighlightSelected(r);
                        }


                        var col = grey;
                        if (log.Percent > 0.25f)
                        {
                            col = blue;
                        }

                        if (log.Percent > 0.75f)
                        {
                            col = red;
                        }


                        Widgets.FillableBar(r.BottomPartPixels(8f), log.Percent, col, clear, false);

                        r = r.LeftPartPixels(50);

                        if (!on)
                        {
                            GUI.color = Color.grey;
                        }

                        Widgets.Label(r, log.Average_s);

                        if (Analyzer.Settings.AdvancedMode)
                        {
                            r.x = r.xMax;

                            Widgets.Label(r, profile.memRiseStr);
                        }

                        r.x     = r.xMax;
                        r.width = 2000;
                        Widgets.Label(r, log.Label);

                        GUI.color = Color.white;

                        if (save)
                        {
                            csv.Append($"{log.Label},{log.Average},{profile.BytesUsed}");
                            foreach (var historyTime in profile.History.times)
                            {
                                csv.Append($",{historyTime}");
                            }
                            csv.AppendLine();
                        }
                    }
                    listing.GapLine(0f);
                    goat += 4f;
                    goat += r.height;
                }
            }

            if (save)
            {
                var path = GenFilePaths.FolderUnderSaveData("Profiling") + $"/{Analyzer.SelectedMode.name}_{DateTime.Now.ToFileTime()}.csv";
                File.WriteAllText(path, csv.ToString());
                csv.Clear();
                Messages.Message($"Saved to {path}", MessageTypeDefOf.TaskCompletion, false);
            }

            listing.End();
            groaner = goat;
            GUI.EndGroup();

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;
            Widgets.EndScrollView();
        }
Example #30
0
        public override void DoWindowContents(Rect inRect)
        {
            //grab before anchor/font
            GameFont   fontBefore   = Text.Font;
            TextAnchor anchorBefore = Text.Anchor;

            //top label
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;

            //build outline
            Widgets.DrawMenuSection(billsBox);


            //loop through each bill
            //GoTo Here if change
Reset:

            int i = 0;

            Text.Anchor = TextAnchor.MiddleCenter;
            foreach (BillFC bill in bills)
            {
                i++;
                Rect settlement = new Rect();
                Rect date       = new Rect();
                Rect amount     = new Rect();
                Rect tithe      = new Rect();
                Rect resolve    = new Rect();
                Rect highlight  = new Rect();


                settlement = billNameBase;
                date       = billDescBase;
                amount     = billLocationBase;
                tithe      = billTimeRemaining;
                resolve    = billResolveBase;

                settlement.y = scroll + billHeight * i;
                date.y       = scroll + billHeight * i;
                amount.y     = scroll + billHeight * i;
                tithe.y      = scroll + billHeight * i;
                resolve.y    = scroll + billHeight * i;

                highlight = new Rect(settlement.x, settlement.y, resolve.x + resolve.width, billHeight);



                if (i % 2 == 0)
                {
                    Widgets.DrawHighlight(highlight);
                }
                String settlementName;
                if (bill.settlement != null)
                {
                    settlementName = bill.settlement.name;
                }
                else
                {
                    settlementName = "Null";
                }
                if (Widgets.ButtonText(settlement, settlementName))
                {
                    if (bill.settlement != null)
                    {
                        Find.WindowStack.Add(new settlementWindowFC(bill.settlement));
                    }
                }
                //
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(date, GenDate.ToStringTicksToDays(bill.dueTick - Find.TickManager.TicksGame));

                //
                Widgets.Label(amount, bill.taxes.silverAmount.ToString());
                //
                bool bul;
                bul = (bill.taxes.itemTithes.Count > 0);
                Widgets.Checkbox(new Vector2(tithe.x + tithe.width / 2 - 12, tithe.y), ref bul);

                if (Widgets.ButtonText(resolve, "ResolveBill".Translate()))
                {
                    if (PaymentUtil.getSilver() >= -1 * (bill.taxes.silverAmount) || bill.taxes.silverAmount >= 0)
                    { //if have enough silver on the current map to pay  & map belongs to player
                        FCEventMaker.createTaxEvent(bill);
                        if (bill.taxes.researchCompleted != 0)
                        {
                            faction.researchPointPool += bill.taxes.researchCompleted;
                            Messages.Message(TranslatorFormattedStringExtensions.Translate("PointsAddedToResearchPool", bill.taxes.researchCompleted), MessageTypeDefOf.PositiveEvent);
                        }
                        if (bill.taxes.electricityAllotted != 0)
                        {
                            faction.powerPool += bill.taxes.electricityAllotted;
                        }
                        goto Reset;
                    }
                    else
                    {
                        Messages.Message("NotEnoughSilverOnMapToPayBill".Translate() + "!", MessageTypeDefOf.RejectInput);
                    }
                }
            }



            //Top label
            Widgets.ButtonTextSubtle(billNameBase, "Settlement".Translate());
            Widgets.ButtonTextSubtle(billDescBase, "DueFC".Translate());
            Widgets.ButtonTextSubtle(billLocationBase, "Amount".Translate());
            Widgets.ButtonTextSubtle(billTimeRemaining, "HasTithe".Translate());
            if (Widgets.ButtonTextSubtle(billResolveBase, "Auto-Resolve"))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();

                FloatMenuOption option = new FloatMenuOption("Auto-Resolving : " + faction.autoResolveBills, delegate
                {
                    faction.autoResolveBills = !faction.autoResolveBills;
                    switch (faction.autoResolveBills)
                    {
                    case true:
                        Messages.Message("Bills are now autoresolving!", MessageTypeDefOf.NeutralEvent);
                        PaymentUtil.autoresolveBills(bills);
                        break;

                    case false:
                        Messages.Message("Bills are now not autoresolving.", MessageTypeDefOf.NeutralEvent);
                        break;
                    }
                });
                list.Add(option);


                FloatMenu menu = new FloatMenu(list);
                Find.WindowStack.Add(menu);
            }
            Widgets.Checkbox(new Vector2(billResolveBase.x + billResolveBase.width - 30, billResolveBase.y + 3), ref faction.autoResolveBills, 24, true);

            //Menu Outline
            Widgets.DrawBox(billsBox);


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


            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollWindow(Event.current.delta.y);
            }
        }