public static bool TryMakeFloatMenu(Caravan caravan) { bool result; if (!caravan.IsPlayerControlled) { result = false; } else { Vector2 mousePositionOnUI = UI.MousePositionOnUI; List <FloatMenuOption> list = FloatMenuMakerWorld.ChoicesAtFor(mousePositionOnUI, caravan); if (list.Count == 0) { result = false; } else { FloatMenuWorld window = new FloatMenuWorld(list, caravan.LabelCap, mousePositionOnUI); Find.WindowStack.Add(window); result = true; } } return(result); }
private void HandleWorldClicks() { if (Event.current.type == EventType.MouseDown) { if (Event.current.button == 0) { if (Event.current.clickCount == 1) { dragBox.active = true; dragBox.start = UI.MousePositionOnUIInverted; } if (Event.current.clickCount == 2) { SelectAllMatchingObjectUnderMouseOnScreen(); } Event.current.Use(); } if (Event.current.button == 1 && selected.Count > 0) { if (selected.Count == 1 && selected[0] is Caravan) { Caravan caravan = (Caravan)selected[0]; if (caravan.IsPlayerControlled && !FloatMenuMakerWorld.TryMakeFloatMenu(caravan)) { AutoOrderToTile(caravan, GenWorld.MouseTile()); } } else { for (int i = 0; i < selected.Count; i++) { Caravan caravan2 = selected[i] as Caravan; if (caravan2 != null && caravan2.IsPlayerControlled) { AutoOrderToTile(caravan2, GenWorld.MouseTile()); } } } 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(); }
public static Caravan ExitMapAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile, bool sendMessage = true) { Caravan result; if (!GenWorldClosest.TryFindClosestPassableTile(exitFromTile, out exitFromTile)) { Log.Error("Could not find any passable tile for a new caravan.", false); result = null; } else { if (Find.World.Impassable(directionTile)) { directionTile = exitFromTile; } CaravanExitMapUtility.tmpPawns.Clear(); CaravanExitMapUtility.tmpPawns.AddRange(pawns); Map map = null; for (int i = 0; i < CaravanExitMapUtility.tmpPawns.Count; i++) { CaravanExitMapUtility.AddCaravanExitTaleIfShould(CaravanExitMapUtility.tmpPawns[i]); map = CaravanExitMapUtility.tmpPawns[i].MapHeld; if (map != null) { break; } } Caravan caravan = CaravanMaker.MakeCaravan(CaravanExitMapUtility.tmpPawns, faction, exitFromTile, false); Rot4 exitDir = (map == null) ? Rot4.Invalid : Find.WorldGrid.GetRotFromTo(exitFromTile, directionTile); for (int j = 0; j < CaravanExitMapUtility.tmpPawns.Count; j++) { CaravanExitMapUtility.tmpPawns[j].ExitMap(false, exitDir); } List <Pawn> pawnsListForReading = caravan.PawnsListForReading; for (int k = 0; k < pawnsListForReading.Count; k++) { if (!pawnsListForReading[k].IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawnsListForReading[k], PawnDiscardDecideMode.Decide); } } if (map != null) { map.Parent.Notify_CaravanFormed(caravan); map.retainedCaravanData.Notify_CaravanFormed(caravan); } if (!caravan.pather.Moving && caravan.Tile != directionTile) { caravan.pather.StartPath(directionTile, null, true, true); caravan.pather.nextTileCostLeft /= 2f; caravan.tweener.ResetTweenedPosToRoot(); } if (destinationTile != -1) { List <FloatMenuOption> list = FloatMenuMakerWorld.ChoicesAtFor(destinationTile, caravan); if (list.Any((FloatMenuOption x) => !x.Disabled)) { FloatMenuOption floatMenuOption = list.First((FloatMenuOption x) => !x.Disabled); floatMenuOption.action(); } else { caravan.pather.StartPath(destinationTile, null, true, true); } } if (sendMessage) { string text = "MessageFormedCaravan".Translate(new object[] { caravan.Name }).CapitalizeFirst(); if (caravan.pather.Moving && caravan.pather.ArrivalAction != null) { string text2 = text; text = string.Concat(new string[] { text2, " ", "MessageFormedCaravan_Orders".Translate(), ": ", caravan.pather.ArrivalAction.Label, "." }); } Messages.Message(text, caravan, MessageTypeDefOf.TaskCompletion, true); } result = caravan; } return(result); }
public static Caravan ExitMapAndCreateCaravan(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile, bool sendMessage = true) { if (!GenWorldClosest.TryFindClosestPassableTile(exitFromTile, out exitFromTile)) { Log.Error("Could not find any passable tile for a new caravan."); return(null); } if (Find.World.Impassable(directionTile)) { directionTile = exitFromTile; } tmpPawns.Clear(); tmpPawns.AddRange(pawns); Map map = null; for (int i = 0; i < tmpPawns.Count; i++) { AddCaravanExitTaleIfShould(tmpPawns[i]); map = tmpPawns[i].MapHeld; if (map != null) { break; } } Caravan caravan = CaravanMaker.MakeCaravan(tmpPawns, faction, exitFromTile, addToWorldPawnsIfNotAlready: false); Rot4 exitDir = (map != null) ? Find.WorldGrid.GetRotFromTo(exitFromTile, directionTile) : Rot4.Invalid; for (int j = 0; j < tmpPawns.Count; j++) { tmpPawns[j].ExitMap(allowedToJoinOrCreateCaravan: false, exitDir); } List <Pawn> pawnsListForReading = caravan.PawnsListForReading; for (int k = 0; k < pawnsListForReading.Count; k++) { if (!pawnsListForReading[k].IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawnsListForReading[k]); } } if (map != null) { map.Parent.Notify_CaravanFormed(caravan); map.retainedCaravanData.Notify_CaravanFormed(caravan); } if (!caravan.pather.Moving && caravan.Tile != directionTile) { caravan.pather.StartPath(directionTile, null, repathImmediately: true); caravan.pather.nextTileCostLeft /= 2f; caravan.tweener.ResetTweenedPosToRoot(); } if (destinationTile != -1) { List <FloatMenuOption> list = FloatMenuMakerWorld.ChoicesAtFor(destinationTile, caravan); if (list.Any((FloatMenuOption x) => !x.Disabled)) { list.First((FloatMenuOption x) => !x.Disabled).action(); } else { caravan.pather.StartPath(destinationTile, null, repathImmediately: true); } } if (sendMessage) { TaggedString taggedString = "MessageFormedCaravan".Translate(caravan.Name).CapitalizeFirst(); if (caravan.pather.Moving && caravan.pather.ArrivalAction != null) { taggedString += " " + "MessageFormedCaravan_Orders".Translate() + ": " + caravan.pather.ArrivalAction.Label + "."; } Messages.Message(taggedString, caravan, MessageTypeDefOf.TaskCompletion); } return(caravan); }