public static bool ShouldDraw(SectionLayer __instance)
        {
            TerrainDef def = TerrainDef.Named("HardVacuum");
            Map        map = Find.CurrentMap;

            // if we aren't in space, abort!
            if (map.terrainGrid.TerrainAt(IntVec3.Zero).defName != def.defName)
            {
                return(true);
            }

            if (__instance.GetType().Name == "SectionLayer_SunShadows")
            {
                return(false);
            }

            if (__instance.GetType().Name == "SectionLayer_LightingOverlay")
            {
                oldSkyGlow = map.skyManager.CurSkyGlow;
                MatBases.LightOverlay.color = new Color(1.0f, 1.0f, 1.0f);
                map.skyManager.ForceSetCurSkyGlow(1.0f);
            }

            if (__instance.GetType().Name == "SectionLayer_Terrain")
            {
                float   num       = (float)UI.screenWidth / (float)UI.screenHeight;
                Vector3 center    = Find.CameraDriver.GetComponent <Camera>().transform.position;
                float   cellsHigh = UI.screenHeight / Find.CameraDriver.CellSizePixels;
                float   cellsWide = cellsHigh * num;

                //recalculate uvs for planet texture.
                LayerSubMesh mesh = __instance.GetSubMesh(RenderPlanetBehindMap.PlanetMaterial);
                if (mesh != null)
                {
                    mesh.Clear(MeshParts.UVs);
                    for (int i = 0; i < mesh.verts.Count; i++)
                    {
                        float xdiff     = mesh.verts[i].x - center.x;
                        float xfromEdge = xdiff + cellsWide / 2f;
                        float zdiff     = mesh.verts[i].z - center.z;
                        float zfromEdge = zdiff + cellsHigh / 2f;

                        mesh.uvs.Add(new Vector3(xfromEdge / cellsWide, zfromEdge / cellsHigh, 0.0f));
                    }
                    mesh.FinalizeMesh(MeshParts.UVs);
                }
            }

            return(true);
        }
        public static void GenerateMesh(SectionLayer __instance)
        {
            if (__instance.GetType().Name != "SectionLayer_Terrain")
            {
                return;
            }

            Section section = __instance.GetType().GetField("section", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(__instance) as Section;

            foreach (IntVec3 cell in section.CellRect.Cells)
            {
                TerrainDef terrain1 = section.map.terrainGrid.TerrainAt(cell);
                if (terrain1.defName == "HardVacuum")
                {
                    Printer_Mesh.PrintMesh(__instance, cell.ToVector3() + new Vector3(0.5f, 0f, 0.5f), MeshMakerPlanes.NewPlaneMesh(1f), RenderPlanetBehindMap.PlanetMaterial);
                }
            }
        }
示例#3
0
        static bool Prefix(MapDrawer __instance)
        {
            Map map = __instance.map;

            if (!copyFrom.TryGetValue(map.uniqueID, out MapDrawer keepDrawer))
            {
                return(true);
            }

            map.mapDrawer  = keepDrawer;
            keepDrawer.map = map;

            foreach (Section section in keepDrawer.sections)
            {
                section.map = map;

                for (int i = 0; i < section.layers.Count; i++)
                {
                    SectionLayer layer = section.layers[i];

                    if (!ShouldKeep(layer))
                    {
                        section.layers[i] = (SectionLayer)Activator.CreateInstance(layer.GetType(), section);
                    }
                    else if (layer is SectionLayer_LightingOverlay lighting)
                    {
                        lighting.glowGrid = map.glowGrid.glowGrid;
                    }
                    else if (layer is SectionLayer_TerrainScatter scatter)
                    {
                        scatter.scats.Do(s => s.map = map);
                    }
                }
            }

            foreach (Section s in keepDrawer.sections)
            {
                foreach (SectionLayer layer in s.layers)
                {
                    if (!ShouldKeep(layer))
                    {
                        layer.Regenerate();
                    }
                }
            }

            copyFrom.Remove(map.uniqueID);

            return(false);
        }
        public static void Cleanup(SectionLayer __instance)
        {
            TerrainDef def = TerrainDef.Named("HardVacuum");
            Map        map = Find.CurrentMap;

            // if we aren't in space, abort!
            if (map.terrainGrid.TerrainAt(IntVec3.Zero).defName != def.defName)
            {
                return;
            }

            if (__instance.GetType().Name == "SectionLayer_LightingOverlay")
            {
                map.skyManager.ForceSetCurSkyGlow(oldSkyGlow);
            }
        }
示例#5
0
 static bool ShouldKeep(SectionLayer layer)
 {
     return(layer.GetType().Assembly == typeof(Game).Assembly);
 }
示例#6
0
 public static string GetLabel(SectionLayer __instance) => __instance.GetType().FullName;