Ejemplo n.º 1
0
 private void HandleMapClicks()
 {
     if (Event.current.type == EventType.MouseDown)
     {
         if (Event.current.button == 0)
         {
             if (Event.current.clickCount == 1)
             {
                 this.dragBox.active = true;
                 this.dragBox.start  = UI.MouseMapPosition();
             }
             if (Event.current.clickCount == 2)
             {
                 this.SelectAllMatchingObjectUnderMouseOnScreen();
             }
             Event.current.Use();
         }
         if (Event.current.button == 1)
         {
             if (this.selected.Count > 0)
             {
                 if (this.selected.Count == 1 && this.selected[0] is Pawn)
                 {
                     FloatMenuMakerMap.TryMakeFloatMenu((Pawn)this.selected[0]);
                 }
                 else
                 {
                     for (int i = 0; i < this.selected.Count; i++)
                     {
                         Pawn pawn = this.selected[i] as Pawn;
                         if (pawn != null)
                         {
                             Selector.MassTakeFirstAutoTakeableOption(pawn, UI.MouseCell());
                         }
                     }
                 }
                 Event.current.Use();
             }
         }
     }
     if (Event.current.rawType == EventType.MouseUp)
     {
         if (Event.current.button == 0)
         {
             if (this.dragBox.active)
             {
                 this.dragBox.active = false;
                 if (!this.dragBox.IsValid)
                 {
                     this.SelectUnderMouse();
                 }
                 else
                 {
                     this.SelectInsideDragBox();
                 }
             }
         }
         Event.current.Use();
     }
 }
Ejemplo n.º 2
0
 public static void TryMakeFloatMenu(Pawn pawn)
 {
     if (FloatMenuMakerMap.CanTakeOrder(pawn))
     {
         if (pawn.Downed)
         {
             Messages.Message("IsIncapped".Translate(pawn.LabelCap), pawn, MessageTypeDefOf.RejectInput);
         }
         else if (pawn.Map == Find.VisibleMap)
         {
             List <FloatMenuOption> list = FloatMenuMakerMap.ChoicesAtFor(UI.MouseMapPosition(), pawn);
             if (list.Count != 0)
             {
                 if (list.Count == 1 && list[0].autoTakeable)
                 {
                     list[0].Chosen(true);
                 }
                 else
                 {
                     FloatMenuMap floatMenuMap = new FloatMenuMap(list, pawn.LabelCap, UI.MouseMapPosition());
                     floatMenuMap.givesColonistOrders = true;
                     Find.WindowStack.Add(floatMenuMap);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 private static void AutoOrderToCell(Pawn pawn, IntVec3 dest)
 {
     foreach (FloatMenuOption current in FloatMenuMakerMap.ChoicesAtFor(dest.ToVector3Shifted(), pawn))
     {
         if (current.autoTakeable)
         {
             current.Chosen(true);
             break;
         }
     }
 }
Ejemplo n.º 4
0
        public static List <FloatMenuOption> ChoicesAtFor(Vector3 clickPos, Pawn pawn)
        {
            IntVec3 intVec = IntVec3.FromVector3(clickPos);
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            if (intVec.InBounds(pawn.Map) && FloatMenuMakerMap.CanTakeOrder(pawn))
            {
                if (pawn.Map != Find.VisibleMap)
                {
                    return(list);
                }
                FloatMenuMakerMap.makingFor = pawn;
                try
                {
                    if (intVec.Fogged(pawn.Map))
                    {
                        FloatMenuOption floatMenuOption = FloatMenuMakerMap.GotoLocationOption(intVec, pawn);
                        if (floatMenuOption != null)
                        {
                            if (!floatMenuOption.Disabled)
                            {
                                list.Add(floatMenuOption);
                                return(list);
                            }
                            return(list);
                        }
                        return(list);
                    }
                    if (pawn.Drafted)
                    {
                        FloatMenuMakerMap.AddDraftedOrders(clickPos, pawn, list);
                    }
                    if (pawn.RaceProps.Humanlike)
                    {
                        FloatMenuMakerMap.AddHumanlikeOrders(clickPos, pawn, list);
                    }
                    if (!pawn.Drafted)
                    {
                        FloatMenuMakerMap.AddUndraftedOrders(clickPos, pawn, list);
                    }
                    foreach (FloatMenuOption item in pawn.GetExtraFloatMenuOptionsFor(intVec))
                    {
                        list.Add(item);
                    }
                    return(list);
                }
                finally
                {
                    FloatMenuMakerMap.makingFor = null;
                }
            }
            return(list);
        }
Ejemplo n.º 5
0
        private static void MassTakeFirstAutoTakeableOption(Pawn pawn, IntVec3 dest)
        {
            FloatMenuOption floatMenuOption = null;

            foreach (FloatMenuOption item in FloatMenuMakerMap.ChoicesAtFor(dest.ToVector3Shifted(), pawn))
            {
                if (!item.Disabled && item.autoTakeable && (floatMenuOption == null || item.autoTakeablePriority > floatMenuOption.autoTakeablePriority))
                {
                    floatMenuOption = item;
                }
            }
            floatMenuOption?.Chosen(colonistOrdering: true, null);
        }
Ejemplo n.º 6
0
        private static void MassTakeFirstAutoTakeableOption_NewTemp(Pawn pawn, IntVec3 dest, out string cantTakeReason)
        {
            FloatMenuOption floatMenuOption = null;

            cantTakeReason = null;
            foreach (FloatMenuOption item in FloatMenuMakerMap.ChoicesAtFor(dest.ToVector3Shifted(), pawn))
            {
                if (item.Disabled || !item.autoTakeable)
                {
                    cantTakeReason = item.Label;
                }
                else if (floatMenuOption == null || item.autoTakeablePriority > floatMenuOption.autoTakeablePriority)
                {
                    floatMenuOption = item;
                }
            }
            floatMenuOption?.Chosen(colonistOrdering: true, null);
        }
Ejemplo n.º 7
0
        private static void MassTakeFirstAutoTakeableOption(Pawn pawn, IntVec3 dest)
        {
            FloatMenuOption floatMenuOption = null;

            foreach (FloatMenuOption current in FloatMenuMakerMap.ChoicesAtFor(dest.ToVector3Shifted(), pawn))
            {
                if (!current.Disabled && current.autoTakeable)
                {
                    if (floatMenuOption == null || current.autoTakeablePriority > floatMenuOption.autoTakeablePriority)
                    {
                        floatMenuOption = current;
                    }
                }
            }
            if (floatMenuOption != null)
            {
                floatMenuOption.Chosen(true, null);
            }
        }
Ejemplo n.º 8
0
 private void HandleMapClicks()
 {
     if (Event.current.type == EventType.MouseDown)
     {
         if (Event.current.button == 0)
         {
             if (Event.current.clickCount == 1)
             {
                 dragBox.active = true;
                 dragBox.start  = UI.MouseMapPosition();
             }
             if (Event.current.clickCount == 2)
             {
                 SelectAllMatchingObjectUnderMouseOnScreen();
             }
             Event.current.Use();
         }
         if (Event.current.button == 1 && selected.Count > 0)
         {
             if (selected.Count == 1 && selected[0] is Pawn)
             {
                 FloatMenuMakerMap.TryMakeFloatMenu((Pawn)selected[0]);
             }
             else
             {
                 cantTakeReasons.Clear();
                 for (int i = 0; i < selected.Count; i++)
                 {
                     Pawn pawn = selected[i] as Pawn;
                     if (pawn != null)
                     {
                         MassTakeFirstAutoTakeableOption_NewTemp(pawn, UI.MouseCell(), out string cantTakeReason);
                         if (cantTakeReason != null)
                         {
                             cantTakeReasons.Add(cantTakeReason);
                         }
                     }
                 }
                 if (cantTakeReasons.Count == selected.Count)
                 {
                     FloatMenu window = new FloatMenu((from r in cantTakeReasons.Distinct()
                                                       select new FloatMenuOption(r, null)).ToList());
                     Find.WindowStack.Add(window);
                 }
             }
             Event.current.Use();
         }
     }
     if (Event.current.rawType != EventType.MouseUp)
     {
         return;
     }
     if (Event.current.button == 0 && dragBox.active)
     {
         dragBox.active = false;
         if (!dragBox.IsValid)
         {
             SelectUnderMouse();
         }
         else
         {
             SelectInsideDragBox();
         }
     }
     Event.current.Use();
 }
Ejemplo n.º 9
0
        private static void AddDraftedOrders(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts)
        {
            IntVec3 clickCell = IntVec3.FromVector3(clickPos);

            foreach (LocalTargetInfo item in GenUI.TargetsAt(clickPos, TargetingParameters.ForAttackHostile(), true))
            {
                LocalTargetInfo attackTarg = item;
                if (pawn.equipment.Primary != null && !pawn.equipment.PrimaryEq.PrimaryVerb.verbProps.MeleeRange)
                {
                    string          str             = default(string);
                    Action          rangedAct       = FloatMenuUtility.GetRangedAttackAction(pawn, attackTarg, out str);
                    string          text            = "FireAt".Translate(attackTarg.Thing.Label);
                    FloatMenuOption floatMenuOption = new FloatMenuOption(MenuOptionPriority.High);
                    if (rangedAct == null)
                    {
                        text = text + " (" + str + ")";
                    }
                    else
                    {
                        floatMenuOption.autoTakeable = true;
                        floatMenuOption.action       = delegate
                        {
                            MoteMaker.MakeStaticMote(attackTarg.Thing.DrawPos, attackTarg.Thing.Map, ThingDefOf.Mote_FeedbackAttack, 1f);
                            rangedAct();
                        };
                    }
                    floatMenuOption.Label = text;
                    opts.Add(floatMenuOption);
                }
                string             str2               = default(string);
                Action             meleeAct           = FloatMenuUtility.GetMeleeAttackAction(pawn, attackTarg, out str2);
                Pawn               pawn2              = attackTarg.Thing as Pawn;
                string             text2              = (pawn2 == null || !pawn2.Downed) ? "MeleeAttack".Translate(attackTarg.Thing.Label) : "MeleeAttackToDeath".Translate(attackTarg.Thing.Label);
                MenuOptionPriority menuOptionPriority = (MenuOptionPriority)((!attackTarg.HasThing || !pawn.HostileTo(attackTarg.Thing)) ? 1 : 6);
                string             empty              = string.Empty;
                Action             action             = null;
                MenuOptionPriority priority           = menuOptionPriority;
                Thing              thing              = attackTarg.Thing;
                FloatMenuOption    floatMenuOption2   = new FloatMenuOption(empty, action, priority, null, thing, 0f, null, null);
                if (meleeAct == null)
                {
                    text2 = text2 + " (" + str2 + ")";
                }
                else
                {
                    floatMenuOption2.action = delegate
                    {
                        MoteMaker.MakeStaticMote(attackTarg.Thing.DrawPos, attackTarg.Thing.Map, ThingDefOf.Mote_FeedbackAttack, 1f);
                        meleeAct();
                    };
                }
                floatMenuOption2.Label = text2;
                opts.Add(floatMenuOption2);
            }
            if (pawn.RaceProps.Humanlike && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                foreach (LocalTargetInfo item2 in GenUI.TargetsAt(clickPos, TargetingParameters.ForArrest(pawn), true))
                {
                    LocalTargetInfo dest = item2;
                    if (!pawn.CanReach(dest, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
                    {
                        opts.Add(new FloatMenuOption("CannotArrest".Translate() + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    else
                    {
                        Pawn   pTarg   = (Pawn)dest.Thing;
                        Action action2 = delegate
                        {
                            Building_Bed building_Bed = RestUtility.FindBedFor(pTarg, pawn, true, false, false);
                            if (building_Bed == null)
                            {
                                building_Bed = RestUtility.FindBedFor(pTarg, pawn, true, false, true);
                            }
                            if (building_Bed == null)
                            {
                                Messages.Message("CannotArrest".Translate() + ": " + "NoPrisonerBed".Translate(), pTarg, MessageTypeDefOf.RejectInput);
                            }
                            else
                            {
                                Job job = new Job(JobDefOf.Arrest, pTarg, building_Bed);
                                job.count = 1;
                                pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                                TutorUtility.DoModalDialogIfNotKnown(ConceptDefOf.ArrestingCreatesEnemies);
                            }
                        };
                        string             empty    = "TryToArrest".Translate(dest.Thing.LabelCap);
                        Action             action   = action2;
                        MenuOptionPriority priority = MenuOptionPriority.High;
                        Thing thing = dest.Thing;
                        opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(empty, action, priority, null, thing, 0f, null, null), pawn, pTarg, "ReservedBy"));
                    }
                }
            }
            FloatMenuOption floatMenuOption3 = FloatMenuMakerMap.GotoLocationOption(clickCell, pawn);

            if (floatMenuOption3 != null)
            {
                opts.Add(floatMenuOption3);
            }
        }