Пример #1
0
        private void TryAddWaypoint(int tile, bool playSound = true)
        {
            if (Find.World.Impassable(tile))
            {
                Messages.Message("MessageCantAddWaypointBecauseImpassable".Translate(), MessageTypeDefOf.RejectInput, historical: false);
                return;
            }
            if (waypoints.Any() && !Find.WorldReachability.CanReach(waypoints[waypoints.Count - 1].Tile, tile))
            {
                Messages.Message("MessageCantAddWaypointBecauseUnreachable".Translate(), MessageTypeDefOf.RejectInput, historical: false);
                return;
            }
            if (waypoints.Count >= 25)
            {
                Messages.Message("MessageCantAddWaypointBecauseLimit".Translate(25), MessageTypeDefOf.RejectInput, historical: false);
                return;
            }
            RoutePlannerWaypoint routePlannerWaypoint = (RoutePlannerWaypoint)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.RoutePlannerWaypoint);

            routePlannerWaypoint.Tile = tile;
            Find.WorldObjects.Add(routePlannerWaypoint);
            waypoints.Add(routePlannerWaypoint);
            RecreatePaths();
            if (playSound)
            {
                SoundDefOf.Tick_High.PlayOneShotOnCamera();
            }
        }
Пример #2
0
 public void TryRemoveWaypoint(RoutePlannerWaypoint point, bool playSound = true)
 {
     if (cantRemoveFirstWaypoint && waypoints.Any() && point == waypoints[0])
     {
         Messages.Message("MessageCantRemoveWaypointBecauseFirst".Translate(), MessageTypeDefOf.RejectInput, historical: false);
     }
     else
     {
         Find.WorldObjects.Remove(point);
         waypoints.Remove(point);
         for (int num = waypoints.Count - 1; num >= 1; num--)
         {
             if (waypoints[num].Tile == waypoints[num - 1].Tile)
             {
                 Find.WorldObjects.Remove(waypoints[num]);
                 waypoints.RemoveAt(num);
             }
         }
         RecreatePaths();
         if (playSound)
         {
             SoundDefOf.Tick_Low.PlayOneShotOnCamera();
         }
     }
 }
Пример #3
0
 public void WorldRoutePlannerOnGUI()
 {
     if (!active)
     {
         return;
     }
     if (KeyBindingDefOf.Cancel.KeyDownEvent)
     {
         if (currentFormCaravanDialog != null)
         {
             Find.WindowStack.Add(currentFormCaravanDialog);
         }
         else
         {
             SoundDefOf.Tick_Low.PlayOneShotOnCamera();
         }
         Stop();
         Event.current.Use();
         return;
     }
     GenUI.DrawMouseAttachment(MouseAttachment);
     if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
     {
         int tile = (Find.WorldSelector.SelectableObjectsUnderMouse().FirstOrDefault() as Caravan)?.Tile ?? GenWorld.MouseTile(snapToExpandableWorldObjects: true);
         if (tile >= 0)
         {
             RoutePlannerWaypoint waypoint = MostRecentWaypointAt(tile);
             if (waypoint != null)
             {
                 if (waypoint == waypoints[waypoints.Count - 1])
                 {
                     TryRemoveWaypoint(waypoint);
                 }
                 else
                 {
                     List <FloatMenuOption> list = new List <FloatMenuOption>();
                     list.Add(new FloatMenuOption("AddWaypoint".Translate(), delegate
                     {
                         TryAddWaypoint(tile);
                     }));
                     list.Add(new FloatMenuOption("RemoveWaypoint".Translate(), delegate
                     {
                         TryRemoveWaypoint(waypoint);
                     }));
                     Find.WindowStack.Add(new FloatMenu(list));
                 }
             }
             else
             {
                 TryAddWaypoint(tile);
             }
             Event.current.Use();
         }
     }
     DoRouteDetailsBox();
     if (!DoChooseRouteButton())
     {
         DoTileTooltips();
     }
 }
Пример #4
0
 public void WorldRoutePlannerOnGUI()
 {
     if (this.active)
     {
         if (KeyBindingDefOf.Cancel.KeyDownEvent)
         {
             if (this.currentFormCaravanDialog != null)
             {
                 Find.WindowStack.Add(this.currentFormCaravanDialog);
             }
             else
             {
                 SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
             }
             this.Stop();
             Event.current.Use();
         }
         else
         {
             GenUI.DrawMouseAttachment(WorldRoutePlanner.MouseAttachment);
             if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
             {
                 Caravan caravan = Find.WorldSelector.SelectableObjectsUnderMouse().FirstOrDefault <WorldObject>() as Caravan;
                 int     tile    = (caravan == null) ? GenWorld.MouseTile(true) : caravan.Tile;
                 if (tile >= 0)
                 {
                     RoutePlannerWaypoint waypoint = this.MostRecentWaypointAt(tile);
                     if (waypoint != null)
                     {
                         if (waypoint == this.waypoints[this.waypoints.Count - 1])
                         {
                             this.TryRemoveWaypoint(waypoint, true);
                         }
                         else
                         {
                             List <FloatMenuOption> list = new List <FloatMenuOption>();
                             list.Add(new FloatMenuOption("AddWaypoint".Translate(), delegate()
                             {
                                 this.TryAddWaypoint(tile, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             list.Add(new FloatMenuOption("RemoveWaypoint".Translate(), delegate()
                             {
                                 this.TryRemoveWaypoint(waypoint, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             Find.WindowStack.Add(new FloatMenu(list));
                         }
                     }
                     else
                     {
                         this.TryAddWaypoint(tile, true);
                     }
                     Event.current.Use();
                 }
             }
             this.DoRouteDetailsBox();
             if (!this.DoChooseRouteButton())
             {
                 this.DoTileTooltips();
             }
         }
     }
 }
Пример #5
0
 public void WorldRoutePlannerOnGUI()
 {
     if (this.active)
     {
         if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
         {
             if (this.currentFormCaravanDialog != null)
             {
                 Find.WindowStack.Add(this.currentFormCaravanDialog);
             }
             else
             {
                 SoundDefOf.TickLow.PlayOneShotOnCamera(null);
             }
             this.Stop();
             Event.current.Use();
         }
         else
         {
             GenUI.DrawMouseAttachment(WorldRoutePlanner.MouseAttachment);
             if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
             {
                 Caravan caravan = Find.WorldSelector.SelectableObjectsUnderMouse().FirstOrDefault() as Caravan;
                 int     tile    = (caravan == null) ? GenWorld.MouseTile(true) : caravan.Tile;
                 if (tile >= 0)
                 {
                     RoutePlannerWaypoint waypoint = this.MostRecentWaypointAt(tile);
                     if (waypoint != null)
                     {
                         if (waypoint == this.waypoints[this.waypoints.Count - 1])
                         {
                             this.TryRemoveWaypoint(waypoint, true);
                         }
                         else
                         {
                             List <FloatMenuOption> list = new List <FloatMenuOption>();
                             list.Add(new FloatMenuOption("AddWaypoint".Translate(), delegate
                             {
                                 this.TryAddWaypoint(tile, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             list.Add(new FloatMenuOption("RemoveWaypoint".Translate(), delegate
                             {
                                 this.TryRemoveWaypoint(waypoint, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             Find.WindowStack.Add(new FloatMenu(list));
                         }
                     }
                     else
                     {
                         this.TryAddWaypoint(tile, true);
                     }
                     Event.current.Use();
                 }
             }
             float   num = (float)UI.screenWidth;
             Vector2 bottomWindowSize = WorldRoutePlanner.BottomWindowSize;
             double  x    = (num - bottomWindowSize.x) / 2.0;
             float   num2 = (float)UI.screenHeight;
             Vector2 bottomWindowSize2 = WorldRoutePlanner.BottomWindowSize;
             double  y = num2 - bottomWindowSize2.y - 45.0;
             Vector2 bottomWindowSize3 = WorldRoutePlanner.BottomWindowSize;
             float   x2 = bottomWindowSize3.x;
             Vector2 bottomWindowSize4 = WorldRoutePlanner.BottomWindowSize;
             Rect    rect = new Rect((float)x, (float)y, x2, bottomWindowSize4.y);
             if (Current.ProgramState == ProgramState.Entry)
             {
                 rect.y -= 22f;
             }
             Find.WindowStack.ImmediateWindow(1373514241, rect, WindowLayer.Dialog, delegate
             {
                 if (this.active)
                 {
                     GUI.color   = Color.white;
                     Text.Anchor = TextAnchor.UpperCenter;
                     Text.Font   = GameFont.Small;
                     float num3  = 6f;
                     if (this.waypoints.Count >= 2)
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerEstTimeToFinalDest".Translate(this.GetTicksToWaypoint(this.waypoints.Count - 1).ToStringTicksToDays("0.#")));
                     }
                     else if (this.cantRemoveFirstWaypoint)
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerAddOneOrMoreWaypoints".Translate());
                     }
                     else
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerAddTwoOrMoreWaypoints".Translate());
                     }
                     num3 = (float)(num3 + 20.0);
                     if (this.CaravanPawns.NullOrEmpty())
                     {
                         GUI.color = new Color(0.8f, 0.6f, 0.6f);
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerUsingAverageTicksPerMoveWarning".Translate());
                     }
                     else if (this.currentFormCaravanDialog == null && this.CaravanAtTheFirstWaypoint != null)
                     {
                         GUI.color = Color.gray;
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerUsingTicksPerMoveOfCaravan".Translate(this.CaravanAtTheFirstWaypoint.LabelCap));
                     }
                     num3      = (float)(num3 + 20.0);
                     GUI.color = Color.gray;
                     Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerPressRMBToAddAndRemoveWaypoints".Translate());
                     num3 = (float)(num3 + 20.0);
                     if (this.currentFormCaravanDialog != null)
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerPressEscapeToReturnToCaravanFormationDialog".Translate());
                     }
                     else
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerPressEscapeToExit".Translate());
                     }
                     num3        = (float)(num3 + 20.0);
                     GUI.color   = Color.white;
                     Text.Anchor = TextAnchor.UpperLeft;
                 }
             }, true, false, 1f);
         }
     }
 }