Exemple #1
0
        private int FindTileByScreenPos(Vector3 coords)
        {
            Find.WorldCameraDriver.JumpTo(coords);
            var uiPos  = GenWorldUI.WorldToUIPosition(coords);
            var tileId = GenWorld.TileAt(uiPos);

            if (tileId == Tile.Invalid)
            {
                return(Tile.Invalid);
            }

            // just check that the tile isn't very far from the given coordinates
            var foundTileCoords = Find.WorldGrid.GetTileCenter(tileId);
            var dist            = Vector3.Distance(foundTileCoords, coords);

            return(dist < _deltaVectorBig.magnitude ? tileId : Tile.Invalid);
        }
 public static void UpdateVisibility()
 {
     if (WorldRendererUtility.WorldRenderedNow)
     {
         int tile = GenWorld.TileAt(Verse.UI.MousePositionOnUI);
         if (tile >= 0)
         {
             Log.Message($"TILE: {tile} COST: {worldPathTexts[tile].Text}");
         }
     }
     foreach (var textMesh in worldPathTexts)
     {
         bool visibleOnWorld = !WorldRendererUtility.HiddenBehindTerrainNow(textMesh.Position);
         if (visibleOnWorld != textMesh.Active)
         {
             textMesh.SetActive(visibleOnWorld);
             textMesh.WrapAroundPlanetSurface();
         }
     }
 }
Exemple #3
0
        public static List <WorldObject> WorldObjectsUnderMouse(Vector2 mousePos)
        {
            List <WorldObject> list = new List <WorldObject>();

            ExpandableWorldObjectsUtility.GetExpandedWorldObjectUnderMouse(mousePos, list);
            float caravanDirectClickRadius = GenWorldUI.CaravanDirectClickRadius;

            GenWorldUI.clickedCaravans.Clear();
            List <Caravan> caravans = Find.WorldObjects.Caravans;

            for (int i = 0; i < caravans.Count; i++)
            {
                Caravan caravan = caravans[i];
                if (caravan.DistanceToMouse(mousePos) < caravanDirectClickRadius)
                {
                    GenWorldUI.clickedCaravans.Add(caravan);
                }
            }
            GenWorldUI.clickedCaravans.SortBy((Caravan x) => x.DistanceToMouse(mousePos));
            for (int j = 0; j < GenWorldUI.clickedCaravans.Count; j++)
            {
                if (!list.Contains(GenWorldUI.clickedCaravans[j]))
                {
                    list.Add(GenWorldUI.clickedCaravans[j]);
                }
            }
            float dynamicallyDrawnObjectDirectClickRadius = GenWorldUI.DynamicallyDrawnObjectDirectClickRadius;

            GenWorldUI.clickedDynamicallyDrawnObjects.Clear();
            List <WorldObject> allWorldObjects = Find.WorldObjects.AllWorldObjects;

            for (int k = 0; k < allWorldObjects.Count; k++)
            {
                WorldObject worldObject = allWorldObjects[k];
                if (worldObject.def.useDynamicDrawer && worldObject.DistanceToMouse(mousePos) < dynamicallyDrawnObjectDirectClickRadius)
                {
                    GenWorldUI.clickedDynamicallyDrawnObjects.Add(worldObject);
                }
            }
            GenWorldUI.clickedDynamicallyDrawnObjects.SortBy((WorldObject x) => x.DistanceToMouse(mousePos));
            for (int l = 0; l < GenWorldUI.clickedDynamicallyDrawnObjects.Count; l++)
            {
                if (!list.Contains(GenWorldUI.clickedDynamicallyDrawnObjects[l]))
                {
                    list.Add(GenWorldUI.clickedDynamicallyDrawnObjects[l]);
                }
            }
            int num = GenWorld.TileAt(mousePos, false);
            List <WorldObject> allWorldObjects2 = Find.WorldObjects.AllWorldObjects;

            for (int m = 0; m < allWorldObjects2.Count; m++)
            {
                if (allWorldObjects2[m].Tile == num && !list.Contains(allWorldObjects2[m]))
                {
                    list.Add(allWorldObjects2[m]);
                }
            }
            float caravanWideClickRadius = GenWorldUI.CaravanWideClickRadius;

            GenWorldUI.clickedCaravans.Clear();
            List <Caravan> caravans2 = Find.WorldObjects.Caravans;

            for (int n = 0; n < caravans2.Count; n++)
            {
                Caravan caravan2 = caravans2[n];
                if (caravan2.DistanceToMouse(mousePos) < caravanWideClickRadius)
                {
                    GenWorldUI.clickedCaravans.Add(caravan2);
                }
            }
            GenWorldUI.clickedCaravans.SortBy((Caravan x) => x.DistanceToMouse(mousePos));
            for (int num2 = 0; num2 < GenWorldUI.clickedCaravans.Count; num2++)
            {
                if (!list.Contains(GenWorldUI.clickedCaravans[num2]))
                {
                    list.Add(GenWorldUI.clickedCaravans[num2]);
                }
            }
            GenWorldUI.clickedCaravans.Clear();
            return(list);
        }