コード例 #1
0
 private static void EndCurrentJobPostfix(Pawn ___pawn, Dictionary <WorkType, WorkState> __state)
 {
     if (__state?.Count > 0)
     {
         foreach (var state in __state.InRandomOrder())
         {
             if (state.Value != WorkState.Inactive && CanWork(___pawn))
             {
                 if (state.Value == WorkState.Active && !CanWorkActive(___pawn))
                 {
                     continue;
                 }
                 var curJob = ___pawn.CurJob;
                 WorkSearchUtility.SearchForWork(state.Key, new List <Pawn> {
                     ___pawn
                 });
                 if (curJob != ___pawn.CurJob)
                 {
                     break;
                 }
                 else if (state.Value == WorkState.Temporary && ___pawn.TryGetGroups(out HashSet <ColonistGroup> groups))
                 {
                     foreach (var group in groups)
                     {
                         group.temporaryWorkers.Remove(___pawn);
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
        public override void DoWindowContents(Rect rect)
        {
            base.DoWindowContents(rect);
            Text.Anchor = TextAnchor.MiddleCenter;
            var sendRect = new Rect(rect.x + 20, rect.y + 25, Textures.SetClearButton.width, Textures.SetClearButton.height);

            GUI.DrawTexture(sendRect, Textures.SetClearButton);
            Widgets.Label(sendRect, Strings.Send);
            if (Mouse.IsOver(sendRect))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    var window = new Dialog_FormCaravan(this.colonistGroup.Map);
                    Find.WindowStack.Add(window);
                    Traverse.Create(window).Field("autoSelectFoodAndMedicine").SetValue(this.colonistGroup.travelSuppliesEnabled);
                    List <Pawn> selectedPawns = new List <Pawn>();
                    foreach (var trad in window.transferables)
                    {
                        if (trad.AnyThing is Pawn pawn2 && this.colonistGroup.ActivePawns.Contains(pawn2))
                        {
                            trad.AdjustTo(1);
                            selectedPawns.Add(pawn2);
                        }
                    }
                    Traverse.Create(window).Method("CountToTransferChanged").GetValue();
                    if (!this.colonistGroup.travelSuppliesEnabled && this.colonistGroup.bedrollsEnabled)
                    {
                        this.SelectBedrolls(window, window.transferables, selectedPawns);
                    }
                    this.CloseAllWindows();
                    Event.current.Use();
                }
                GUI.DrawTexture(sendRect, Textures.WorkButtonHover);
            }

            var unloadRect = new Rect(sendRect.xMax - 15, sendRect.yMax + 20, Textures.SetClearButton.width, Textures.SetClearButton.height);

            GUI.DrawTexture(unloadRect, Textures.SetClearButton);
            Widgets.Label(unloadRect, Strings.Unload);
            if (Mouse.IsOver(unloadRect))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    this.colonistGroup.AssignTemporaryWorkers(WorkTypeEnum.UnloadCaravan);
                    WorkSearchUtility.SearchForWork(WorkTypeEnum.UnloadCaravan, this.colonistGroup.ActivePawns);
                    Event.current.Use();
                }
                GUI.DrawTexture(unloadRect, Textures.WorkButtonHover);
            }

            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }
コード例 #3
0
ファイル: WorkMenu.cs プロジェクト: TroyAlias/tacticalgroups
        public WorkMenu(TieredFloatMenu parentWindow, ColonistGroup colonistGroup, Rect originRect, Texture2D backgroundTexture)
            : base(parentWindow, colonistGroup, originRect, backgroundTexture)
        {
            this.options = new List <TieredFloatMenuOption>();

            var lookBusy = new TieredFloatMenuOption(Strings.LookBusy, null, Textures.LookBusyButton, Textures.LookBusyButtonHover, null, TextAnchor.MiddleCenter,
                                                     MenuOptionPriority.High, 0f, Textures.LookBusyButton.width - 2f, Strings.LookBusyTooltip);

            lookBusy.action = delegate
            {
                TacticDefOf.TG_WorkSFX.PlayOneShotOnCamera();
                WorkSearchUtility.SearchForWork(WorkType.None, this.colonistGroup.ActivePawns);
            };
            lookBusy.bottomIndent = 400f;
            options.Add(lookBusy);

            var takeFive = new TieredFloatMenuOption(Strings.TakeFive, null, Textures.LookBusyButton, Textures.LookBusyButtonHover, null, TextAnchor.MiddleCenter, MenuOptionPriority.High, 0f,
                                                     Textures.LookBusyButton.width - 2f, Strings.TakeFiveTooltip);

            takeFive.action = delegate
            {
                TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                WorkSearchUtility.TakeABreak(BreakType.None, this.colonistGroup.ActivePawns);
            };
            options.Add(takeFive);

            workIconStates[Textures.ConstructButton] = WorkType.Construction;
            workIconStates[Textures.CraftButton]     = WorkType.Crafting;
            workIconStates[Textures.HaulButton]      = WorkType.Hauling;
            workIconStates[Textures.CleanButton]     = WorkType.Cleaning;
            workIconStates[Textures.HuntButton]      = WorkType.Hunting;
            workIconStates[Textures.CookButton]      = WorkType.Cooking;
            workIconStates[Textures.MineButton]      = WorkType.Mining;
            workIconStates[Textures.ChopWoodButton]  = WorkType.WoodChopping;

            workIconStates[Textures.TailorButton]         = WorkType.Tailor;
            workIconStates[Textures.SmithButton]          = WorkType.Smith;
            workIconStates[Textures.FireExtinguishButton] = WorkType.FireExtinguish;
            workIconStates[Textures.ArtButton]            = WorkType.Art;

            workIconStates[Textures.FarmButton]      = WorkType.Plants;
            workIconStates[Textures.HandleButton]    = WorkType.Handle;
            workIconStates[Textures.WardenButton]    = WorkType.Warden;
            workIconStates[Textures.ClearSnowButton] = WorkType.ClearSnow;

            breakIconStates[Textures.ChowHallButton]  = BreakType.ChowHall;
            breakIconStates[Textures.LightsOutButton] = BreakType.LightsOut;

            tooltips[Textures.ConstructButton] = Strings.WorkTaskTooltipConstruction;
            tooltips[Textures.CraftButton]     = Strings.WorkTaskTooltipCraft;
            tooltips[Textures.HaulButton]      = Strings.WorkTaskTooltipHaul;
            tooltips[Textures.CleanButton]     = Strings.WorkTaskTooltipClean;
            tooltips[Textures.HuntButton]      = Strings.WorkTaskTooltipHunt;
            tooltips[Textures.CookButton]      = Strings.WorkTaskTooltipCook;
            tooltips[Textures.MineButton]      = Strings.WorkTaskTooltipMine;
            tooltips[Textures.ChopWoodButton]  = Strings.WorkTaskTooltipChopWood;
            tooltips[Textures.FarmButton]      = Strings.WorkTaskTooltipFarm;
            tooltips[Textures.ClearSnowButton] = Strings.WorkTaskTooltipClearSnow;
            tooltips[Textures.WardenButton]    = Strings.WorkTaskTooltipWarden;

            tooltips[Textures.TailorButton]         = Strings.WorkTaskTooltipTailor;
            tooltips[Textures.SmithButton]          = Strings.WorkTaskTooltipSmith;
            tooltips[Textures.HandleButton]         = Strings.WorkTaskTooltipHandle;
            tooltips[Textures.FireExtinguishButton] = Strings.WorkTaskTooltipFireExtinguish;
            tooltips[Textures.ArtButton]            = Strings.WorkTaskTooltipArt;

            tooltips[Textures.ChowHallButton]  = Strings.ChowHallToolTip;
            tooltips[Textures.LightsOutButton] = Strings.SleepTooltip;


            for (int i = 0; i < options.Count; i++)
            {
                options[i].SetSizeMode(SizeMode);
            }
        }
コード例 #4
0
ファイル: WorkMenu.cs プロジェクト: TroyAlias/tacticalgroups
        public override void DoWindowContents(Rect rect)
        {
            base.DoWindowContents(rect);
            Vector2 zero = Vector2.zero;

            zero += InitialFloatOptionPositionShift;
            for (int i = 0; i < options.Count; i++)
            {
                TieredFloatMenuOption floatMenuOption = options[i];
                Rect rect2 = new Rect(zero.x, zero.y, (this.backgroundTexture.width - InitialFloatOptionPositionShift.x) / 1.2f, floatMenuOption.curIcon.height);
                if (floatMenuOption.DoGUI(rect2, this))
                {
                    Find.WindowStack.TryRemove(this);
                    break;
                }
                zero.y += floatMenuOption.bottomIndent;
            }

            var rect3    = new Rect(rect.x + zero.x, rect.y + 75f, rect.width, rect.height);
            var iconRows = GetWorkIconRows(2);

            for (var i = 0; i < iconRows.Count; i++)
            {
                for (var j = 0; j < iconRows[i].Count; j++)
                {
                    Rect iconRect = new Rect(rect3.x + (j * iconRows[i][j].width) + j * 10, rect3.y + (i * iconRows[i][j].height) + i * 7,
                                             iconRows[i][j].width, iconRows[i][j].height);
                    GUI.DrawTexture(iconRect, iconRows[i][j]);
                    if (this.colonistGroup.activeWorkTypes.TryGetValue(workIconStates[iconRows[i][j]], out WorkState state2))
                    {
                        if (state2 == WorkState.Active)
                        {
                            GUI.DrawTexture(iconRect, Textures.Clock);
                        }
                        else if (state2 == WorkState.ForcedLabor)
                        {
                            GUI.DrawTexture(iconRect, Textures.ClockSlave);
                        }
                    }
                    TooltipHandler.TipRegion(iconRect, tooltips[iconRows[i][j]] + "\n" + Strings.ForcedLaborTooltip);
                    if (Mouse.IsOver(iconRect))
                    {
                        GUI.DrawTexture(iconRect, Textures.WorkButtonHover);
                        if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                        {
                            this.colonistGroup.RemoveWorkState(workIconStates[iconRows[i][j]]);
                            TacticDefOf.TG_WorkSFX.PlayOneShotOnCamera();
                            WorkSearchUtility.SearchForWork(workIconStates[iconRows[i][j]], this.colonistGroup.ActivePawns);
                            Event.current.Use();
                        }
                        else if (Event.current.type == EventType.MouseDown && Event.current.button == 1 && Event.current.clickCount == 1)
                        {
                            this.colonistGroup.ChangeWorkState(workIconStates[iconRows[i][j]]);
                            if (this.colonistGroup.activeWorkTypes[workIconStates[iconRows[i][j]]] == WorkState.ForcedLabor)
                            {
                                TacticDefOf.TG_SlaveLaborSFX.PlayOneShotOnCamera();
                            }
                            else
                            {
                                TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                            }
                            WorkSearchUtility.SearchForWork(workIconStates[iconRows[i][j]], this.colonistGroup.ActivePawns);
                            Event.current.Use();
                        }
                    }
                }
            }

            var rect4     = new Rect(rect.x + zero.x, rect.y + 475f, rect.width, rect.height);
            var iconRows2 = GetBreakIconRows(2);

            for (var i = 0; i < iconRows2.Count; i++)
            {
                for (var j = 0; j < iconRows2[i].Count; j++)
                {
                    Rect iconRect = new Rect(rect4.x + (j * iconRows2[i][j].width) + j * 10, rect4.y + (i * iconRows2[i][j].height) + i * 7,
                                             iconRows2[i][j].width, iconRows2[i][j].height);
                    GUI.DrawTexture(iconRect, iconRows2[i][j]);
                    TooltipHandler.TipRegion(iconRect, tooltips[iconRows2[i][j]]);

                    if (Mouse.IsOver(iconRect))
                    {
                        GUI.DrawTexture(iconRect, Textures.WorkButtonHover);
                        if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                        {
                            if (breakIconStates[iconRows2[i][j]] == BreakType.LightsOut)
                            {
                                TacticDefOf.TG_LightsOutSFX.PlayOneShotOnCamera();
                            }
                            else if (breakIconStates[iconRows2[i][j]] == BreakType.ChowHall)
                            {
                                TacticDefOf.TG_ChowTimeSFX.PlayOneShotOnCamera();
                            }
                            WorkSearchUtility.TakeABreak(breakIconStates[iconRows2[i][j]], this.colonistGroup.ActivePawns);
                            Event.current.Use();
                        }
                    }
                }
            }

            var workRows     = GetWorkTypeRows(2);
            var initialRect  = new Rect((rect.x + rect.width) - 245, rect.y + 75, 240, rect.height - 95);
            var workMenuRect = new Rect(initialRect);

            workMenuRect.height -= 103;

            DoManualPrioritiesCheckbox(new Rect(workMenuRect.x, rect.y + 30, workMenuRect.width, 40));
            float listHeight = workRows.Count * 33 + (workRows.Count * 2);
            Rect  rect5      = new Rect(0f, 0f, workMenuRect.width - 16f, listHeight);

            Widgets.BeginScrollView(workMenuRect, ref scrollPosition, rect5);

            for (var i = 0; i < workRows.Count; i++)
            {
                for (var j = 0; j < workRows[i].Count; j++)
                {
                    Rect workRect = new Rect(rect5.x + (j * 20) + j * 91.5f, rect5.y + (i * 17) + i * 17, 24, 24);
                    this.DoWorkCell(workRect, workRows[i][j]);
                    this.DoWorkHeader(workRect, workRows[i][j]);
                }
            }
            Widgets.EndScrollView();
            DrawExtraGui(rect);


            var caravanButtonRect = new Rect(initialRect.x + 155, rect.y + 23, Textures.CaravanButton.width, Textures.CaravanButton.height);

            GUI.DrawTexture(caravanButtonRect, Textures.CaravanButton);
            if (Mouse.IsOver(caravanButtonRect))
            {
                GUI.DrawTexture(caravanButtonRect, Textures.CaravanHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_WorkSFX.PlayOneShotOnCamera();

                    var floatMenu = new CaravanMenu(this, this.colonistGroup, this.windowRect, Textures.CaravanMenu);
                    this.OpenNewMenu(floatMenu);
                    Event.current.Use();
                }
            }


            var researchWorkRect = new Rect(rect.x + 253, rect.y + 459, Textures.ResearchWorkButton.width, Textures.ResearchWorkButton.height);

            GUI.DrawTexture(researchWorkRect, Textures.ResearchWorkButton);
            if (this.colonistGroup.activeWorkTypes.TryGetValue(WorkType.Research, out WorkState state))
            {
                if (state == WorkState.Active)
                {
                    GUI.DrawTexture(researchWorkRect, Textures.Clock, ScaleMode.ScaleToFit);
                }
                else if (state == WorkState.ForcedLabor)
                {
                    GUI.DrawTexture(researchWorkRect, Textures.ClockSlave, ScaleMode.ScaleToFit);
                }
            }

            Text.Anchor = TextAnchor.MiddleCenter;
            var researchLabel = new Rect(researchWorkRect.x + 30, researchWorkRect.y - 25, 80, 24);

            Widgets.Label(researchLabel, Strings.WorkTaskTooltipResearch);
            Text.Anchor = TextAnchor.UpperLeft;

            TooltipHandler.TipRegion(researchWorkRect, Strings.WorkTaskTooltipResearch + "\n" + Strings.ForcedLaborTooltip);
            if (Mouse.IsOver(researchWorkRect))
            {
                GUI.DrawTexture(researchWorkRect, Textures.ResearchHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ResearchSFX.PlayOneShotOnCamera();
                    this.colonistGroup.RemoveWorkState(WorkType.Research);
                    WorkSearchUtility.SearchForWork(WorkType.Research, this.colonistGroup.ActivePawns);
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.MouseDown && Event.current.button == 1 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    this.colonistGroup.ChangeWorkState(WorkType.Research);
                    WorkSearchUtility.SearchForWork(WorkType.Research, this.colonistGroup.ActivePawns);
                    Event.current.Use();
                }
            }
            var researchMenuRect = new Rect(researchWorkRect.x + 89, researchWorkRect.y, Textures.ResearchMenuButton.width, Textures.ResearchMenuButton.height);

            GUI.DrawTexture(researchMenuRect, Textures.ResearchMenuButton);
            if (Mouse.IsOver(researchMenuRect))
            {
                GUI.DrawTexture(researchMenuRect, Textures.ResearchHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    Find.MainTabsRoot.ToggleTab(MainButtonDefOf.Research);
                    Event.current.Use();
                }
            }
            TooltipHandler.TipRegion(researchMenuRect, Strings.WorkTaskTooltipResearchMenu);
            GUI.color = Color.white;
        }
コード例 #5
0
ファイル: OrderMenu.cs プロジェクト: TroyAlias/tacticalgroups
        public override void DrawExtraGui(Rect rect)
        {
            base.DrawExtraGui(rect);
            Vector2 zero        = Vector2.zero + InitialFloatOptionPositionShift;
            var     tendWounded = new Rect(zero.x + 10, rect.y + 407, Textures.TendWounded.width, Textures.TendWounded.height);

            GUI.DrawTexture(tendWounded, Textures.TendWounded);
            if (this.colonistGroup.activeWorkTypes.TryGetValue(WorkType.TendWounded, out WorkState state))
            {
                if (state == WorkState.Active)
                {
                    GUI.DrawTexture(tendWounded, Textures.Clock);
                }
                else if (state == WorkState.ForcedLabor)
                {
                    GUI.DrawTexture(tendWounded, Textures.ClockSlave);
                }
            }
            if (Mouse.IsOver(tendWounded))
            {
                GUI.DrawTexture(tendWounded, Textures.RescueTendHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    this.colonistGroup.RemoveWorkState(WorkType.TendWounded);
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    WorkSearchUtility.SearchForWork(WorkType.TendWounded, this.colonistGroup.ActivePawns);
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.MouseDown && Event.current.button == 1 && Event.current.clickCount == 1)
                {
                    this.colonistGroup.ChangeWorkState(WorkType.TendWounded);
                    if (this.colonistGroup.activeWorkTypes[WorkType.TendWounded] == WorkState.ForcedLabor)
                    {
                        TacticDefOf.TG_SlaveLaborSFX.PlayOneShotOnCamera();
                    }
                    else
                    {
                        TacticDefOf.TG_WorkSFX.PlayOneShotOnCamera();
                    }
                    WorkSearchUtility.SearchForWork(WorkType.TendWounded, this.colonistGroup.ActivePawns);
                    Event.current.Use();
                }
                TooltipHandler.TipRegion(tendWounded, Strings.ForcedLaborTooltip);
            }
            TooltipHandler.TipRegion(tendWounded, Strings.TendWoundedTooltip);
            var rescureFallen = new Rect(((zero.x + Textures.LookBusyButton.width) - (Textures.RescueFallen.width + 11f)) - 10f, tendWounded.y, Textures.RescueFallen.width, Textures.RescueFallen.height);

            GUI.DrawTexture(rescureFallen, Textures.RescueFallen);
            if (this.colonistGroup.activeWorkTypes.TryGetValue(WorkType.RescueFallen, out WorkState state2))
            {
                if (state2 == WorkState.Active)
                {
                    GUI.DrawTexture(rescureFallen, Textures.Clock);
                }
                else if (state2 == WorkState.ForcedLabor)
                {
                    GUI.DrawTexture(rescureFallen, Textures.ClockSlave);
                }
            }
            if (Mouse.IsOver(rescureFallen))
            {
                GUI.DrawTexture(rescureFallen, Textures.RescueTendHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    this.colonistGroup.RemoveWorkState(WorkType.RescueFallen);
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    WorkSearchUtility.SearchForWork(WorkType.RescueFallen, this.colonistGroup.ActivePawns);
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.MouseDown && Event.current.button == 1 && Event.current.clickCount == 1)
                {
                    this.colonistGroup.ChangeWorkState(WorkType.RescueFallen);
                    if (this.colonistGroup.activeWorkTypes[WorkType.RescueFallen] == WorkState.ForcedLabor)
                    {
                        TacticDefOf.TG_SlaveLaborSFX.PlayOneShotOnCamera();
                    }
                    else
                    {
                        TacticDefOf.TG_WorkSFX.PlayOneShotOnCamera();
                    }
                    WorkSearchUtility.SearchForWork(WorkType.RescueFallen, this.colonistGroup.ActivePawns);
                    Event.current.Use();
                }
                GUI.DrawTexture(rescureFallen, Textures.RescueTendHover);
                TooltipHandler.TipRegion(rescureFallen, Strings.ForcedLaborTooltip);
            }
            TooltipHandler.TipRegion(rescureFallen, Strings.RescueDownedTooltip);
            var shooterIconRect = new Rect(rect.x + 10, rect.y + 25f, Textures.ShootingIcon.width, Textures.ShootingIcon.height);

            GUI.DrawTexture(shooterIconRect, Textures.ShootingIcon);
            if (Mouse.IsOver(shooterIconRect))
            {
                GUI.DrawTexture(shooterIconRect, Textures.ShootingMeleeHover);
            }
            var shooters         = this.colonistGroup.ActivePawns.Where(x => x.equipment?.Primary?.def.IsRangedWeapon ?? false);
            var shooterCountRect = new Rect(shooterIconRect.x + shooterIconRect.width + 2f, shooterIconRect.y, 30, shooterIconRect.height);

            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(shooterCountRect, shooters.Count().ToString());
            var totalShooterRect = new Rect(shooterIconRect.x, shooterIconRect.y, Textures.ShootingIcon.width + 25, shooterIconRect.height).ExpandedBy(5f);

            TooltipHandler.TipRegion(totalShooterRect, Strings.ShootersToolTip);
            if (Mouse.IsOver(totalShooterRect))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    Find.Selector.ClearSelection();
                    foreach (var shooter in shooters)
                    {
                        Find.Selector.Select(shooter);
                    }
                    Event.current.Use();
                }
            }
            Text.Anchor = TextAnchor.MiddleCenter;
            var middlePawnCountRect = new Rect(totalShooterRect.x + totalShooterRect.width, totalShooterRect.y, 70, totalShooterRect.height);
            var capablePawns        = this.colonistGroup.ActivePawns.Where(x => !x.IsDownedOrIncapable());

            Widgets.Label(middlePawnCountRect, capablePawns.Count() + " / " + this.colonistGroup.ActivePawns.Count);

            TooltipHandler.TipRegion(middlePawnCountRect, Strings.MiddlePawnCountToolTip);
            if (Mouse.IsOver(middlePawnCountRect))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    Find.Selector.ClearSelection();
                    foreach (var pawn in capablePawns)
                    {
                        Find.Selector.Select(pawn);
                    }
                    Event.current.Use();
                }
            }

            var meleeIconRect = new Rect((rect.x + rect.width) - 35, rect.y + 25f, Textures.MeleeIcon.width, Textures.MeleeIcon.height);

            GUI.DrawTexture(meleeIconRect, Textures.MeleeIcon);
            if (Mouse.IsOver(meleeIconRect))
            {
                GUI.DrawTexture(meleeIconRect, Textures.ShootingMeleeHover);
            }

            var melees         = this.colonistGroup.ActivePawns.Where(x => x.equipment?.Primary?.def.IsMeleeWeapon ?? false);
            var meleeCountRect = new Rect(meleeIconRect.x - (Textures.MeleeIcon.width + 5f), meleeIconRect.y, 30, meleeIconRect.height);

            Text.Anchor = TextAnchor.MiddleRight;
            Widgets.Label(meleeCountRect, melees.Count().ToString());

            var totalMeleeRect = new Rect(meleeCountRect.x, meleeIconRect.y, meleeIconRect.width + meleeCountRect.width, meleeIconRect.height).ExpandedBy(5f);

            TooltipHandler.TipRegion(totalMeleeRect, Strings.MeleeToolTip);

            if (Mouse.IsOver(totalMeleeRect))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    Find.Selector.ClearSelection();
                    foreach (var melee in melees)
                    {
                        Find.Selector.Select(melee);
                    }
                    Event.current.Use();
                }
            }
            Text.Anchor = TextAnchor.MiddleCenter;

            var rectY   = (rect.height / 2f) - 30f;
            var setRect = new Rect(zero.x, rectY, Textures.SetClearButton.width, Textures.SetClearButton.height);

            GUI.DrawTexture(setRect, Textures.SetClearButton);
            Widgets.Label(setRect, Strings.Set);
            TooltipHandler.TipRegion(setRect, Strings.BattleStationsSetTooltip);

            if (Mouse.IsOver(setRect))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    this.colonistGroup.SetBattleStations();
                    Event.current.Use();
                }
                GUI.DrawTexture(setRect, Textures.WorkButtonHover);
            }
            var clearRect = new Rect((zero.x + (Textures.MenuButton.width - Textures.SetClearButton.width)) - 12f, rectY, Textures.SetClearButton.width, Textures.SetClearButton.height);

            GUI.DrawTexture(clearRect, Textures.SetClearButton);
            Widgets.Label(clearRect, Strings.Clear);
            TooltipHandler.TipRegion(clearRect, Strings.BattleStationsClearTooltip);
            if (Mouse.IsOver(clearRect))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    this.colonistGroup.ClearBattleStations();
                    Event.current.Use();
                }
                GUI.DrawTexture(clearRect, Textures.WorkButtonHover);
            }

            var upgradeArmorRect = new Rect(zero.x - 8f, rect.height / 1.76f, Textures.UpgradeArmorIcon.width, Textures.UpgradeArmorIcon.height);

            GUI.DrawTexture(upgradeArmorRect, Textures.UpgradeArmorIcon);
            TooltipHandler.TipRegion(upgradeArmorRect, Strings.UpgradeArmorTooltip);

            if (Mouse.IsOver(upgradeArmorRect))
            {
                GUI.DrawTexture(upgradeArmorRect, Textures.UpgradeIconHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_UpgradeArmorWeaponsSFX.PlayOneShotOnCamera();
                    foreach (var pawn in this.colonistGroup.ActivePawns)
                    {
                        var thing = TacticUtils.PickBestArmorFor(pawn);
                        if (thing != null)
                        {
                            var job = JobMaker.MakeJob(JobDefOf.Wear, thing);
                            job.locomotionUrgency = LocomotionUrgency.Sprint;
                            pawn.jobs.TryTakeOrderedJob(job);
                        }
                    }
                    Event.current.Use();
                }
            }

            var takeBuffRect = new Rect(upgradeArmorRect.x + 56, upgradeArmorRect.y, Textures.TakeBuffButton.width, Textures.TakeBuffButton.height);

            GUI.DrawTexture(takeBuffRect, Textures.TakeBuffButton);
            TooltipHandler.TipRegion(takeBuffRect, Strings.TakeBuffTooltip);
            if (Mouse.IsOver(takeBuffRect))
            {
                GUI.DrawTexture(takeBuffRect, Textures.TakeBuffButtonHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_TakeBuffSFX.PlayOneShotOnCamera();
                    foreach (var pawn in this.colonistGroup.ActivePawns)
                    {
                        var jbg    = new JobGiver_TakeCombatEnhancingDrug();
                        var result = jbg.TryIssueJobPackage(pawn, default(JobIssueParams));
                        if (result.Job != null)
                        {
                            pawn.jobs.TryTakeOrderedJob(result.Job);
                        }
                    }
                    Event.current.Use();
                }
            }

            var upgradeWeaponRect = new Rect((rect.x + rect.width) - (20 + Textures.UpgradeWeaponIcon.width), upgradeArmorRect.y, Textures.UpgradeWeaponIcon.width, Textures.UpgradeWeaponIcon.height);

            GUI.DrawTexture(upgradeWeaponRect, Textures.UpgradeWeaponIcon);
            TooltipHandler.TipRegion(upgradeWeaponRect, Strings.UpgradeWeaponTooltip);
            if (Mouse.IsOver(upgradeWeaponRect))
            {
                GUI.DrawTexture(upgradeWeaponRect, Textures.UpgradeIconHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_UpgradeWeaponSFX.PlayOneShotOnCamera();
                    foreach (var pawn in this.colonistGroup.ActivePawns)
                    {
                        var thing = TacticUtils.PickBestWeaponFor(pawn);
                        if (thing != null)
                        {
                            if (pawn.inventory?.innerContainer?.InnerListForReading?.Contains(thing) ?? false)
                            {
                                TacticUtils.TrySwitchToWeapon(thing as ThingWithComps, pawn);
                            }
                            else if (thing != pawn.equipment?.Primary)
                            {
                                var job = JobMaker.MakeJob(JobDefOf.Equip, thing);
                                job.locomotionUrgency = LocomotionUrgency.Sprint;
                                pawn.jobs.TryTakeOrderedJob(job);
                            }
                        }
                    }
                    Event.current.Use();
                }
            }

            var totalArmorRect = new Rect(rect.x + 10f, rect.height - 43, Textures.ArmorIcon.width, Textures.ArmorIcon.height);

            GUI.DrawTexture(totalArmorRect, Textures.ArmorIcon);
            Text.Anchor = TextAnchor.LowerLeft;
            var totalArmorLabel = new Rect(totalArmorRect.x + totalArmorRect.width + 2, totalArmorRect.y - 3, 30, 24);
            var armorValues     = new List <float>();

            foreach (var pawn in this.colonistGroup.ActivePawns)
            {
                if (pawn.apparel.WornApparel != null)
                {
                    var armorValue = TacticUtils.OverallArmorValue(pawn);
                    armorValues.Add(armorValue);
                }
            }
            var averageArmor = armorValues.Sum() / this.colonistGroup.ActivePawns.Count();

            Widgets.Label(totalArmorLabel, averageArmor.ToStringDecimalIfSmall());
            TooltipHandler.TipRegion(totalArmorLabel, Strings.ArmorTooltip);

            Text.Anchor = TextAnchor.MiddleCenter;
            var totalDPSLabel = new Rect(totalArmorRect.x + totalArmorRect.width + 50, totalArmorRect.y - 3, 30, 24);
            var dpsValues     = new List <float>();

            foreach (var pawn in this.colonistGroup.ActivePawns)
            {
                if (pawn.equipment.Primary != null)
                {
                    dpsValues.Add(TacticUtils.WeaponScoreGain(pawn.equipment.Primary));
                }
                else
                {
                    dpsValues.Add(pawn.GetStatValue(StatDefOf.MeleeDPS));
                }
            }

            var averageDPS = dpsValues.Average();

            Widgets.Label(totalDPSLabel, averageDPS.ToStringDecimalIfSmall());
            TooltipHandler.TipRegion(totalDPSLabel, Strings.DPSTooltip);
            var rankTexture = GetCurRank(averageDPS + averageArmor);
            var rankRect    = new Rect((rect.x + rect.width) - (rankTexture.width + 12f), totalArmorRect.y - 10f, rankTexture.width, rankTexture.height);

            GUI.DrawTexture(rankRect, rankTexture);
            TooltipHandler.TipRegion(rankRect, Strings.RankTooltip);
            Text.Anchor = TextAnchor.UpperLeft;
        }
コード例 #6
0
ファイル: WorkMenu.cs プロジェクト: TroyAlias/tacticalgroups
        public override void DoWindowContents(Rect rect)
        {
            base.DoWindowContents(rect);
            Vector2 zero = Vector2.zero;

            zero += InitialFloatOptionPositionShift;
            for (int i = 0; i < options.Count; i++)
            {
                TieredFloatMenuOption floatMenuOption = options[i];
                Rect rect2 = new Rect(zero.x, zero.y, (this.backgroundTexture.width - InitialFloatOptionPositionShift.x) / 1.2f, floatMenuOption.curIcon.height);
                if (floatMenuOption.DoGUI(rect2, this))
                {
                    Find.WindowStack.TryRemove(this);
                    break;
                }
                zero.y += floatMenuOption.bottomIndent;
            }

            var getBreakIconRect = new Rect(rect.x + zero.x, rect.y + 475f, rect.width, rect.height);
            var iconRows         = GetBreakIconRows(2);

            for (var i = 0; i < iconRows.Count; i++)
            {
                for (var j = 0; j < iconRows[i].Count; j++)
                {
                    Rect iconRect = new Rect(getBreakIconRect.x + (j * iconRows[i][j].width) + j * 10, getBreakIconRect.y + (i * iconRows[i][j].height) + i * 7,
                                             iconRows[i][j].width, iconRows[i][j].height);
                    GUI.DrawTexture(iconRect, iconRows[i][j]);
                    TooltipHandler.TipRegion(iconRect, tooltips[iconRows[i][j]]);

                    if (Mouse.IsOver(iconRect))
                    {
                        GUI.DrawTexture(iconRect, Textures.WorkButtonHover);
                        if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                        {
                            if (breakIconStates[iconRows[i][j]] == BreakType.LightsOut)
                            {
                                TacticDefOf.TG_LightsOutSFX.PlayOneShotOnCamera();
                            }
                            else if (breakIconStates[iconRows[i][j]] == BreakType.ChowHall)
                            {
                                TacticDefOf.TG_ChowTimeSFX.PlayOneShotOnCamera();
                            }
                            WorkSearchUtility.TakeABreak(breakIconStates[iconRows[i][j]], this.colonistGroup.ActivePawns);
                            Event.current.Use();
                        }
                    }
                }
            }

            var workRows     = GetWorkTypeRows(2);
            var initialRect  = new Rect(rect.x, rect.y + 75, 320, rect.height - 95);
            var workMenuRect = new Rect(initialRect);

            workMenuRect.height -= 103;
            var resetWorkPriorities = new Rect(workMenuRect.x + 20, rect.y + 32, Textures.ResetIcon.width, Textures.ResetIcon.height);

            GUI.DrawTexture(resetWorkPriorities, Textures.ResetIcon);
            if (Mouse.IsOver(resetWorkPriorities))
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    this.colonistGroup.groupWorkPriorities?.Clear();
                    Event.current.Use();
                }
                TooltipHandler.TipRegion(resetWorkPriorities, Strings.GroupWorkPrioritiesReset);
            }

            var manualPrioritiesRect = new Rect(resetWorkPriorities.xMax + 10, rect.y + 30, 162, 40);

            DoManualPrioritiesCheckbox(manualPrioritiesRect);
            float listHeight   = workRows.Count * 33 + (workRows.Count * 2);
            Rect  workCellRect = new Rect(0f, 0f, workMenuRect.width - 16f, listHeight);

            Widgets.BeginScrollView(workMenuRect, ref scrollPosition, workCellRect);

            for (var i = 0; i < workRows.Count; i++)
            {
                for (var j = 0; j < workRows[i].Count; j++)
                {
                    Rect      workTypeRect = new Rect(workCellRect.x + (j * 72) + (j * 72) + 17.5f, (workCellRect.y + (i * 17) + (i * 17)) + 8, Textures.WorkSelectEmpty.width, Textures.WorkSelectEmpty.height);
                    var       workDictData = this.colonistGroup.activeWorkTypes.FirstOrDefault(x => x.Key.workTypeDef == workRows[i][j]);
                    WorkState workState;
                    if (workDictData.Key != null)
                    {
                        workState = workDictData.Value;
                    }
                    else
                    {
                        workState = WorkState.Inactive;
                    }

                    switch (workState)
                    {
                    case WorkState.Temporary:
                    case WorkState.Inactive:
                        GUI.DrawTexture(workTypeRect, Textures.WorkSelectEmpty);
                        TooltipHandler.TipRegion(workTypeRect, Strings.WorkTypeLeftClickToApply);
                        break;

                    case WorkState.Active:
                        GUI.DrawTexture(workTypeRect, Textures.WorkSelectBlue);
                        TooltipHandler.TipRegion(workTypeRect, Strings.WorkTypeForcedLabor);
                        break;

                    case WorkState.ForcedLabor:
                        GUI.DrawTexture(workTypeRect, Textures.WorkSelectRed);
                        TooltipHandler.TipRegion(workTypeRect, Strings.WorkTypeSlaveLabor);
                        break;
                    }

                    if (Mouse.IsOver(workTypeRect))
                    {
                        if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                        {
                            WorkSearchUtility.SearchForWork(workRows[i][j], this.colonistGroup.pawns);
                            this.colonistGroup.ChangeWorkState(workRows[i][j]);
                            Event.current.Use();
                        }
                    }
                    Rect workRect = new Rect(workTypeRect.xMax + 5, workTypeRect.y - 8, 24, 24);
                    this.DoWorkCell(workRect, workRows[i][j]);
                    this.DoWorkHeader(workRect, workRows[i][j]);
                }
            }
            Widgets.EndScrollView();
            DrawExtraGui(rect);

            var caravanButtonRect = new Rect(manualPrioritiesRect.xMax + 5, rect.y + 23, Textures.CaravanButton.width, Textures.CaravanButton.height);

            GUI.DrawTexture(caravanButtonRect, Textures.CaravanButton);
            if (Mouse.IsOver(caravanButtonRect))
            {
                GUI.DrawTexture(caravanButtonRect, Textures.CaravanHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_WorkSFX.PlayOneShotOnCamera();

                    var floatMenu = new CaravanMenu(this, this.colonistGroup, this.windowRect, Textures.CaravanMenu);
                    this.OpenNewMenu(floatMenu);
                    Event.current.Use();
                }
            }


            var researchMenuRect = new Rect(rect.x + 253, rect.y + 459, Textures.ResearchWorkButton.width, Textures.ResearchWorkButton.height);

            GUI.DrawTexture(researchMenuRect, Textures.ResearchMenuButton);
            if (Mouse.IsOver(researchMenuRect))
            {
                GUI.DrawTexture(researchMenuRect, Textures.ResearchHover);
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 1)
                {
                    TacticDefOf.TG_ClickSFX.PlayOneShotOnCamera();
                    Find.MainTabsRoot.ToggleTab(MainButtonDefOf.Research);
                    Event.current.Use();
                }
            }
            TooltipHandler.TipRegion(researchMenuRect, Strings.WorkTaskTooltipResearchMenu);
            GUI.color = Color.white;
        }