コード例 #1
0
        public void ExportWithSizeHeightmap()
        {
            int scale = int.Parse(TerrainScale.text);

            scale = Mathf.Clamp(scale, 129, 2049);

            //string Filename = EnvPaths.GetMapsPath() + MapLuaParser.Current.FolderName + "/heightmap.raw";

            var extensions = new[]
            {
                new ExtensionFilter("Heightmap", new string[] { "raw" })
                //new ExtensionFilter("Stratum mask", "raw, bmp")
            };

            var paths = StandaloneFileBrowser.SaveFilePanel("Export heightmap scalled", DefaultPath, "heightmap", extensions);


            if (paths == null || string.IsNullOrEmpty(paths))
            {
                return;
            }

            float h = ScmapEditor.Current.Teren.terrainData.heightmapHeight;
            float w = ScmapEditor.Current.Teren.terrainData.heightmapWidth;

            float[,] data = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, (int)w, (int)h);

            ExportAs = new Texture2D((int)w, (int)h, TextureFormat.RGB24, false, true);

            Debug.Log(w + ", " + h);

            float HeightValue = 1;

            HeightValue = float.Parse(TerrainScale_HeightValue.text);
            if (HeightValue < 0)
            {
                HeightValue = 1;
            }

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    float Value = data[y, x];                    // / HeightConversion;

                    if (TerrainScale_Height.isOn)
                    {
                        Value *= HeightValue;
                    }
                    //float ColorR = (Mathf.Floor(Value) * (1f / 255f));
                    //float ColorG = (Value - Mathf.Floor(Value));

                    ExportAs.SetPixel((int)(h - (y + 1)), x, new Color(Value, 0, 0));
                }
            }
            ExportAs.Apply();

            bool differentSize = w != scale || h != scale;

            h = scale;
            w = scale;

            using (BinaryWriter writer = new BinaryWriter(new System.IO.FileStream(paths, System.IO.FileMode.Create)))
            {
                Color pixel = Color.black;

                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        if (differentSize)
                        {
                            pixel = ExportAs.GetPixelBilinear(y / h, x / w);
                        }
                        else
                        {
                            pixel = ExportAs.GetPixel(y, x);
                        }
                        //float value = (pixel.r + pixel.g * (1f / 255f));
                        float value = pixel.r;
                        //uint ThisPixel = (uint)(value * HeightConversion);
                        uint ThisPixel = (uint)((double)value * (double)HeightConversion + 0.5);
                        writer.Write(System.BitConverter.GetBytes(System.BitConverter.ToUInt16(System.BitConverter.GetBytes(ThisPixel), 0)));
                    }
                }
                writer.Close();
            }
            //ExportAs = null;
            EnvPaths.SetLastPath(ExportPathKey, System.IO.Path.GetDirectoryName(paths));

            GenericInfoPopup.ShowInfo("Rescaled Heightmap export success!\n" + System.IO.Path.GetFileName(paths));
        }
コード例 #2
0
        void ReadAllFolders()
        {
            EnvType.ClearOptions();

            LoadedEnvPaths = new List <string>();
            List <Dropdown.OptionData> NewOptions = new List <Dropdown.OptionData>();

            if (!Directory.Exists(EnvPaths.GetGamedataPath()))
            {
                Debug.LogError("Gamedata path not exist!");
                return;
            }



            ZipFile zf = GetGamedataFile.GetZipFileInstance(GetGamedataFile.EnvScd);

            foreach (ZipEntry zipEntry in zf)
            {
                if (!zipEntry.IsDirectory)
                {
                    continue;
                }

                string LocalName = zipEntry.Name.Replace("env/", "");

                if (LocalName.Length == 0)
                {
                    continue;
                }

                int  ContSeparators = 0;
                char Separator      = ("/")[0];
                for (int i = 0; i < LocalName.Length; i++)
                {
                    if (LocalName[i] == Separator)
                    {
                        ContSeparators++;
                        if (ContSeparators > 1)
                        {
                            break;
                        }
                    }
                }
                if (ContSeparators > 1)
                {
                    continue;
                }

                LocalName = LocalName.Replace("/", "");

                LoadedEnvPaths.Add(LocalName);
                Dropdown.OptionData NewOptionInstance = new Dropdown.OptionData(LocalName);
                NewOptions.Add(NewOptionInstance);
            }

            LoadedEnvPaths.Add(CurrentMapFolderPath);
            Dropdown.OptionData NewOptionInstance2 = new Dropdown.OptionData("Map folder");
            NewOptions.Add(NewOptionInstance2);

            LoadedEnvPaths.Add(CurrentMapPath);
            Dropdown.OptionData NewOptionInstance3 = new Dropdown.OptionData("On map");
            NewOptions.Add(NewOptionInstance3);

            EnvType.AddOptions(NewOptions);
        }
コード例 #3
0
        public void ImportHeightmap()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Heightmap", new string[] { "raw", "r16", "bmp" })
                //new ExtensionFilter("Stratum mask", "raw, bmp")
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Import heightmap", DefaultPath, extensions, false);


            if (paths == null || paths.Length == 0 || string.IsNullOrEmpty(paths[0]))
            {
                return;
            }


            int h = ScmapEditor.Current.Teren.terrainData.heightmapHeight;
            int w = ScmapEditor.Current.Teren.terrainData.heightmapWidth;

            ScmapEditor.GetAllHeights(ref beginHeights);
            MapLuaParser.Current.History.RegisterTerrainHeightmapChange(beginHeights);


            float[,] data = new float[h, w];
            //float[,] old = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, w, h);

            if (paths[0].ToLower().EndsWith("bmp"))
            {
                BMPLoader loader = new BMPLoader();
                BMPImage  img    = loader.LoadBMP(paths[0]);
                Debug.Log(img.info.compressionMethod + ", " + img.info.nBitsPerPixel + ", " + img.rMask + ", " + img.imageData[0].r);
                Texture2D ImportedImage = img.ToTexture2D();


                if (ImportedImage.width != h || ImportedImage.height != w)
                {
                    Debug.Log("Wrong size");
                    TextureScale.Bilinear(ImportedImage, h, w);
                    ImportedImage.Apply(false);
                }

                Color[] ImportedColors = ImportedImage.GetPixels();

                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        data[y, x] = (float)ImportedColors[x + y * w].r / 0.567f;                         // 0.58
                    }
                }
            }
            else
            {
                using (var file = System.IO.File.OpenRead(paths[0]))
                    using (var reader = new System.IO.BinaryReader(file))
                    {
                        for (int y = 0; y < h; y++)
                        {
                            for (int x = 0; x < w; x++)
                            {
                                float v = (float)(((double)reader.ReadUInt16() - 0.5) / (double)HeightConversion);
                                data[h - (y + 1), x] = v;
                            }
                        }
                    }
            }

            //ScmapEditor.Current.Teren.terrainData.SetHeights(0, 0, data);
            ScmapEditor.SetAllHeights(data);
            RegenerateMaps();
            OnTerrainChanged();
            EnvPaths.SetLastPath(ExportPathKey, System.IO.Path.GetDirectoryName(paths[0]));
            GenericInfoPopup.ShowInfo("Heightmap import success!\n" + System.IO.Path.GetFileName(paths[0]));
        }
コード例 #4
0
 public void ResetMap()
 {
     EnvPaths.GenerateMapPath();
     MapsPathField.text = EnvPaths.DefaultMapPath;
 }
コード例 #5
0
        public void ImportPropsSet()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Props paint set", "proppaintset")
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Import props paint set", DefaultPath, extensions, false);


            if (paths.Length <= 0 || string.IsNullOrEmpty(paths[0]))
            {
                return;
            }

            string data = File.ReadAllText(paths[0]);

            PaintButtonsSet PaintSet = JsonUtility.FromJson <PaintButtonsSet>(data);



            while (PaintButtons.Count > 0)
            {
                RemoveProp(0);
            }



            //bool[] Exist = new bool[PaintPropObjects.Count];

            for (int i = 0; i < PaintSet.PaintProps.Length; i++)
            {
                //bool Found = false;
                int o = 0;

                /*
                 * for(o = 0; i < PaintPropObjects.Count; o++)
                 * {
                 *      if(PaintPropObjects[i].BP.Path == PaintSet.PaintProps[i].Blueprint)
                 *      {
                 *              if (o < Exist.Length)
                 *                      Exist[o] = true;
                 *              Found = true;
                 *              break;
                 *      }
                 * }*/

                //if (!Found)
                {
                    // Load
                    if (!LoadProp(GetGamedataFile.LoadProp(PaintSet.PaintProps[i].Blueprint)))
                    {
                        Debug.LogWarning("Can't load prop at path: " + PaintSet.PaintProps[i].Blueprint);
                        continue;
                    }

                    o = PaintButtons.Count - 1;
                }

                PaintButtons[o].ScaleMin.SetValue(PaintSet.PaintProps[i].ScaleMin);
                PaintButtons[o].ScaleMax.SetValue(PaintSet.PaintProps[i].ScaleMax);

                PaintButtons[o].RotationMin.SetValue(PaintSet.PaintProps[i].RotationMin);
                PaintButtons[o].RotationMax.SetValue(PaintSet.PaintProps[i].RotationMax);

                PaintButtons[o].Chance.SetValue(PaintSet.PaintProps[i].Chance);
            }

            /*
             * for(int i = Exist.Length - 1; i >= 0; i--)
             * {
             *      if (!Exist[i])
             *      {
             *              RemoveProp(i);
             *      }
             * }
             */

            EnvPaths.SetLastPath(ExportPathKey, System.IO.Path.GetDirectoryName(paths[0]));
        }
コード例 #6
0
    public void BrowseBackupPath()
    {
        var paths = StandaloneFileBrowser.OpenFolderPanel("Select backup 'Maps' folder.", EnvPaths.GetMapsPath(), false);

        if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
        {
            BackupPathField.text = paths[0];
        }
    }
コード例 #7
0
 public void ResetGamedata()
 {
     EnvPaths.GenerateGamedataPath();
     PathField.text = EnvPaths.DefaultGamedataPath;
 }
コード例 #8
0
        public void SetMapFolderClicked()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Scenario", "lua")
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Select Scenario.lua of map to upload", EnvPaths.GetMapsPath(), extensions, false);

            if (paths.Length != 0 && paths[0] != null)
            {
                MapFolderPathInputField.SetValue(Path.GetDirectoryName(paths[0]));
            }
        }
コード例 #9
0
    private static extern void SaveFileDialog();     //in your case : OpenFileDialog

    public void BrowseGamedataPath()
    {
        var paths = StandaloneFileBrowser.OpenFolderPanel("Select Forged Alliance instalation path", EnvPaths.GetMapsPath(), false);

        if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
        {
            PathField.text = paths[0];
        }
    }
コード例 #10
0
        public void ImportMarkers()
        {
            var extensions = new[] {
                new ExtensionFilter("Faf Markers", "fafmapmarkers")
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Import markers", EnvPaths.GetMapsPath(), extensions, false);


            /*
             * OpenFileDialog FileDialog = new OpenFileDialog();
             * FileDialog.Title = "Import markers";
             * FileDialog.AddExtension = true;
             * FileDialog.DefaultExt = ".fafmapmarkers";
             * FileDialog.Filter = "Faf Markers (*.fafmapmarkers)|*.fafmapmarkers";
             * FileDialog.CheckFileExists = true;
             */

            if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
            {
                ExportMarkers ImpMarkers = JsonUtility.FromJson <ExportMarkers>(System.IO.File.ReadAllText(paths[0]));

                bool AnyCreated = false;
                int  mc         = 0;

                MapLua.SaveLua.Marker[] CreatedMarkers = new MapLua.SaveLua.Marker[ImpMarkers.Markers.Length];

                for (int m = 0; m < ImpMarkers.Markers.Length; m++)
                {
                    if (!AnyCreated)
                    {
                        Undo.Current.RegisterMarkersAdd();
                    }
                    AnyCreated = true;


                    if (SelectionManager.Current.SnapToGrid)
                    {
                        ImpMarkers.Markers[m].Pos = ScmapEditor.SnapToGridCenter(ImpMarkers.Markers[m].Pos, true, SelectionManager.Current.SnapToWater);
                    }

                    MapLua.SaveLua.Marker NewMarker = new MapLua.SaveLua.Marker(ImpMarkers.Markers[m].MarkerType);
                    CreatedMarkers[m]     = NewMarker;
                    NewMarker.position    = ScmapEditor.WorldPosToScmap(ImpMarkers.Markers[m].Pos);
                    NewMarker.orientation = ImpMarkers.Markers[m].Rot.eulerAngles;
                    MarkersControler.CreateMarker(NewMarker, mc);
                    ChainsList.AddToCurrentChain(NewMarker);


                    MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Add(NewMarker);
                }


                for (int m = 0; m < ImpMarkers.Markers.Length; m++)
                {
                    CreatedMarkers[m].AdjacentToMarker = new List <MapLua.SaveLua.Marker>();
                    for (int c = 0; c < ImpMarkers.Markers[m].Connected.Length; c++)
                    {
                        CreatedMarkers[m].AdjacentToMarker.Add(CreatedMarkers[ImpMarkers.Markers[m].Connected[c]]);
                    }
                }

                RenderMarkersConnections.Current.UpdateConnections();
            }
        }
コード例 #11
0
        public void ImportHeightmap()
        {
            var extensions = new[]
            {
                new ExtensionFilter("Heightmap", new string[] { "raw", "r16", "bmp" })
            };

            var paths = StandaloneFileBrowser.OpenFilePanel("Import heightmap", DefaultPath, extensions, false);


            if (paths == null || paths.Length == 0 || string.IsNullOrEmpty(paths[0]))
            {
                return;
            }

            int h = ScmapEditor.Current.Teren.terrainData.heightmapHeight;
            int w = ScmapEditor.Current.Teren.terrainData.heightmapWidth;

            ScmapEditor.GetAllHeights(ref beginHeights);
            Undo.RegisterUndo(new UndoHistory.HistoryTerrainHeight(), new UndoHistory.HistoryTerrainHeight.TerrainHeightHistoryParameter(beginHeights));


            float[,] data = new float[h, w];
            //float[,] old = ScmapEditor.Current.Teren.terrainData.GetHeights(0, 0, w, h);

            if (paths[0].ToLower().EndsWith("bmp"))
            {
                BMPLoader loader = new BMPLoader();
                BMPImage  img    = loader.LoadBMP(paths[0]);
                Debug.Log(img.info.compressionMethod + ", " + img.info.nBitsPerPixel + ", " + img.rMask + ", " + img.imageData[0].r);
                Texture2D ImportedImage = img.ToTexture2D();


                if (ImportedImage.width != h || ImportedImage.height != w)
                {
                    Debug.Log("Wrong size");
                    TextureScale.Bilinear(ImportedImage, h, w);
                    ImportedImage.Apply(false);
                }

                Color[] ImportedColors = ImportedImage.GetPixels();

                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        data[y, x] = (float)ImportedColors[x + y * w].r / 0.567f;                         // 0.58
                    }
                }
            }
            else
            {
                using (var file = System.IO.File.OpenRead(paths[0]))
                    using (var reader = new System.IO.BinaryReader(file))
                    {
                        long CheckValue = 2;
                        CheckValue *= (long)(w);
                        CheckValue *= (long)(h);
                        long FileLength = file.Length;

                        if (FileLength != CheckValue)
                        {
                            reader.Dispose();
                            file.Dispose();
                            GenericPopup.ShowPopup(GenericPopup.PopupTypes.Error, "Error", "Selected heightmap is in wrong size.\nIs: " + FileLength + "B, should be: " + CheckValue + "B", "OK", null);
                            return;
                        }

                        for (int y = 0; y < h; y++)
                        {
                            for (int x = 0; x < w; x++)
                            {
                                float v = (float)(reader.ReadUInt16() / ScmapEditor.HeightResize);
                                data[h - (y + 1), x] = v;
                            }
                        }
                    }
            }

            //ScmapEditor.Current.Teren.terrainData.SetHeights(0, 0, data);
            ScmapEditor.SetAllHeights(data);
            RegenerateMaps();
            OnTerrainChanged();
            EnvPaths.SetLastPath(ExportPathKey, System.IO.Path.GetDirectoryName(paths[0]));
            GenericInfoPopup.ShowInfo("Heightmap import success!\n" + System.IO.Path.GetFileName(paths[0]));
        }
コード例 #12
0
    public void MenuButton(string func)
    {
        if (!MenuOpen)
        {
            return;
        }
        switch (func)
        {
        case "NewMap":
            OpenNewMap();
            break;

        case "Open":
            OpenMap();
            //MapHelper.Map = false;
            //MapHelper.OpenComposition(0);
            break;

        case "OpenRecent":
            RecentMaps.SetActive(true);
            ButtonClicked = true;
            break;

        case "Save":
            MapLuaParser.Current.SaveMap();
            break;

        case "SaveAs":
            SaveMapAs();
            break;

        case "SaveAsNewVersion":
            SaveAsNewVersion();
            break;

        case "Undo":
            break;

        case "Redo":
            break;

        case "Symmetry":
            Symmetry.SetActive(true);
            break;

        case "Grid":
            ScmapEditor.Current.ToogleGrid(GridToggle.isOn);
            break;

        case "BuildGrid":
            ScmapEditor.Current.ToogleBuildGrid(BuildGridToggle.isOn);
            break;

        case "Slope":
            ScmapEditor.Current.ToogleSlope(SlopeToggle.isOn);
            break;

        case "Forum":
            Application.OpenURL("http://forums.faforever.com/viewtopic.php?f=45&t=10647");
            break;

        case "Wiki":
            Application.OpenURL("https://wiki.faforever.com/index.php?title=FA_Forever_Map_Editor");
            break;

        case "UnitDb":
            Application.OpenURL("http://direct.faforever.com/faf/unitsDB/");
            break;

        case "EditorLog":
            ShowEditorLog();
            break;

        case "Donate":
            Application.OpenURL("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=LUYMTPBDH5V4E&lc=GB&item_name=FAF%20Map%20Editor&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted");
            break;

        case "Shortcuts":
            Application.OpenURL("https://wiki.faforever.com/index.php?title=FA_Forever_Map_Editor#Useful_shortuts");
            break;

        case "PlayMap":
            if (MapLuaParser.IsMapLoaded)
            {
                string Arguments = "";
                Arguments += "/map \"" + "/maps/" + MapLuaParser.Current.FolderName + "/" + MapLuaParser.Current.ScenarioFileName + ".lua" + "\"";
                //Arguments += "/map \"" + MapLuaParser.LoadedMapFolderPath + MapLuaParser.Current.ScenarioFileName + ".lua" + "\"";
                Arguments += " /faction " + (FafEditorSettings.GetFaction() + 1).ToString();
                Arguments += " /victory sandbox";
                Arguments += " /gamespeed adjustable";
                Arguments += " /predeployed /enablediskwatch";

                if (!FafEditorSettings.GetFogOfWar())
                {
                    Arguments += " /nofog";
                }

                string GamePath = EnvPaths.GetInstalationPath() + "bin/SupremeCommander.exe";

                if (!System.IO.File.Exists(GamePath))
                {
                    string OtherPath = EnvPaths.GetInstalationPath() + "bin/ForgedAlliance.exe";
                    if (System.IO.File.Exists(OtherPath))
                    {
                        GamePath = OtherPath;
                    }
                    else
                    {
                        Debug.LogWarning("Game executable not exist at given path: " + EnvPaths.GetInstalationPath() + "bin/");
                        return;
                    }
                }
                Debug.Log("Start game: " + GamePath);
                Debug.Log("Args: " + Arguments);

                System.Diagnostics.Process.Start(GamePath, Arguments);
            }
            break;
        }
    }
コード例 #13
0
    public void SaveMapAs()
    {
        if (!MapLuaParser.IsMapLoaded)
        {
            return;
        }

        LateUpdate();


        var paths = StandaloneFileBrowser.OpenFolderPanel("Save map as...", EnvPaths.GetMapsPath(), false);

        if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0]))
        {
            // If its the same folder, then its the same map
            if (paths[0].Replace("\\", "/") + "/" == MapLuaParser.LoadedMapFolderPath)
            {
                MapLuaParser.Current.SaveMap();
                return;
            }

            string[] PathSeparation   = paths[0].Replace("\\", "/").Split("/".ToCharArray());
            string   ChosenFolderName = PathSeparation[PathSeparation.Length - 1];
            string   NewFolderName    = ChosenFolderName;
            NewFolderName = NewFolderName.Replace(" ", "_");
            int ReplaceVersion = GetVersionControll(NewFolderName);
            if (ReplaceVersion <= 0)
            {
                ReplaceVersion = 1;                 // Map without versioning should always be v1
            }
            //ReplaceVersion = (int)MapLuaParser.Current.ScenarioLuaFile.Data.map_version;
            NewFolderName = ForceVersionControllValue(NewFolderName, ReplaceVersion);

            string ChosenPath = "";

            if (ChosenFolderName != NewFolderName)
            {
                // Combine system path using old separation and new folder name
                ChosenPath = "";
                for (int i = 0; i < PathSeparation.Length - 1; i++)
                {
                    ChosenPath += PathSeparation[i] + "/";
                }
                ChosenPath += NewFolderName;

                // If selected folder does not exist, then remove wrong folder, and make a new, proper one
                if (!Directory.Exists(ChosenPath))
                {
                    Directory.CreateDirectory(ChosenPath);

                    // Remove only when folder is empty
                    if (Directory.GetFiles(paths[0]).Length <= 0 && System.IO.Directory.GetFiles(paths[0]).Length <= 0)
                    {
                        Directory.Delete(paths[0]);
                    }
                }
            }
            else
            {
                ChosenPath = paths[0];
            }


            string[] FilePaths = System.IO.Directory.GetFiles(ChosenPath);
            if (System.IO.Directory.GetDirectories(ChosenPath).Length > 0 || System.IO.Directory.GetFiles(ChosenPath).Length > 0)
            {
                Debug.LogWarning("Selected directory is not empty! " + ChosenPath);

                // Check if its a map folder
                foreach (string path in FilePaths)
                {
                    // If contains any of the map files, then it need to be a map
                    if (path.EndsWith("_scenario.lua") || path.EndsWith("_save.lua") || path.EndsWith(".scmap"))
                    {
                        OverwritePath = ChosenPath;
                        GenericPopup.ShowPopup(GenericPopup.PopupTypes.TwoButton, "Folder is not empty!", "Overwrite map " + NewFolderName + "?\nThis can't be undone!", "Overwrite", OverwriteYes, "Cancel", null);
                        return;
                    }
                }

                // Not a map folder, return error to prevent data lose
                GenericPopup.ShowPopup(GenericPopup.PopupTypes.Error, "Error!", "Selected " + NewFolderName + " folder is not empty and it's not a map folder!", "OK", null);
                return;
            }

            System.IO.DirectoryInfo Dir = new DirectoryInfo(ChosenPath);
            MapLuaParser.Current.FolderParentPath = Dir.Parent.FullName.Replace("\\", "/") + "/";
            Debug.Log(MapLuaParser.Current.FolderParentPath);

            if (SaveAsNewFolder(NewFolderName, NonVersionControlledName(NewFolderName)))
            {
                // Inform user, that map was saved into different folder than he chose
                if (ChosenFolderName != NewFolderName)
                {
                    string LogText = "Wrong folder name: " + ChosenFolderName + "\n Instead saved as: " + NewFolderName;
                    Debug.Log(LogText);
                    GenericInfoPopup.ShowInfo(LogText);
                }
            }
        }
    }
コード例 #14
0
 void Awake()
 {
     Current = this;
     ResBrowser.Instantiate();
     EnvPaths.CurrentGamedataPath = EnvPaths.GetGamedataPath();
 }
コード例 #15
0
    public IEnumerator LoadScmapFile()
    {
        //UnloadMap();

        map = new Map();

        //string MapPath = EnvPaths.GetMapsPath();
        string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map);

        //Debug.Log("Load SCMAP file: " + path);


        if (map.Load(path))
        {
            UpdateLighting();
            Skybox.LoadSkybox();
        }
        else
        {
            Debug.LogError("File not found");
            StopCoroutine("LoadScmapFile");
        }


        if (map.VersionMinor >= 60)
        {
        }
        else
        {
            LoadDefaultSkybox();
        }


        EnvPaths.CurrentGamedataPath = EnvPaths.GetGamedataPath();

        //Shader
        MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = map.TerrainShader == "TTerrainXP";
        ToogleShader();

        // Set Variables
        int   xRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0];
        int   zRes     = MapLuaParser.Current.ScenarioLuaFile.Data.Size[1];
        float HalfxRes = xRes / 10f;
        float HalfzRes = zRes / 10f;


        TerrainMaterial.SetTexture("_TerrainNormal", map.UncompressedNormalmapTex);
        Shader.SetGlobalTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        Shader.SetGlobalFloat("_WaterScaleX", xRes);
        Shader.SetGlobalFloat("_WaterScaleZ", xRes);

        //*****************************************
        // ***** Set Terrain proportives
        //*****************************************

        LoadHeights();


        // Load Stratum Textures Paths
        LoadStratumScdTextures();
        MapLuaParser.Current.InfoPopup.Show(true, "Loading map...\n( Assing scmap data )");


        WaterLevel.transform.localScale = new Vector3(HalfxRes, 1, HalfzRes);
        TerrainMaterial.SetFloat("_GridScale", HalfxRes);
        TerrainMaterial.SetTexture("_UtilitySamplerC", map.UncompressedWatermapTex);
        WaterMaterial.SetFloat("_GridScale", HalfxRes);



        /*
         * // Cubemap
         * Texture2D Cubemap = GetGamedataFile.LoadTexture2DFromGamedata(GetGamedataFile.TexturesScd, map.Water.TexPathCubemap);
         * Debug.Log(Cubemap.width);
         * Cubemap cb = new Cubemap(Cubemap.width, TextureFormat.RGB24, Cubemap.mipmapCount > 1);
         * cb.SetPixels(Cubemap.GetPixels(), CubemapFace.PositiveX);
         * WaterMaterial.SetTexture("_Reflection", cb);
         */

        for (int i = 0; i < map.EnvCubemapsFile.Length; i++)
        {
            if (map.EnvCubemapsName[i] == "<default>")
            {
                try
                {
                    CurrentEnvironmentCubemap = GetGamedataFile.GetGamedataCubemap(GetGamedataFile.TexturesScd, map.EnvCubemapsFile[i]);
                    Shader.SetGlobalTexture("environmentSampler", CurrentEnvironmentCubemap);
                }
                catch
                {
                    WaterMaterial.SetTexture("environmentSampler", DefaultWaterSky);
                }
            }
        }

        SetWaterTextures();

        SetWater();



        Teren.gameObject.layer = 8;

        SetTextures();

        if (Slope)
        {
            ToogleSlope(Slope);
        }

        yield return(null);
        //Debug.Log("Scmap load complited");

        //GetGamedataFile.UnitObject NewUnit = new GetGamedataFile.UnitObject();
    }
コード例 #16
0
    IEnumerator LoadingFile()
    {
        while (SavingMapProcess)
        {
            yield return(null);
        }

        Undo.Current.Clear();

        bool   AllFilesExists = true;
        string Error          = "";

        if (!System.IO.Directory.Exists(FolderParentPath))
        {
            Error = "Map folder does not exist:\n" + FolderParentPath;
            Debug.LogError(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists && !System.IO.File.Exists(LoadedMapFolderPath + ScenarioFileName + ".lua"))
        {
            AllFilesExists = SearchForScenario();

            if (!AllFilesExists)
            {
                Error = "Scenario.lua does not exist:\n" + LoadedMapFolderPath + ScenarioFileName + ".lua";
                Debug.LogError(Error);
            }
        }

        if (AllFilesExists)
        {
            string ScenarioText = System.IO.File.ReadAllText(LoadedMapFolderPath + ScenarioFileName + ".lua");

            if (!ScenarioText.StartsWith("version = 3") && ScenarioText.StartsWith("version ="))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Wrong scenario file version. Should be 3, is " + ScenarioText.Remove(11).Replace("version =", "");
                    Debug.LogError(Error);
                }
            }


            if (AllFilesExists && !ScenarioText.StartsWith("version = 3"))
            {
                AllFilesExists = SearchForScenario();

                if (!AllFilesExists)
                {
                    Error = "Selected file is not a proper scenario.lua file. ";
                    Debug.LogError(Error);
                }
            }
        }

        if (AllFilesExists && !System.IO.File.Exists(EnvPaths.GetGamedataPath() + "/env.scd"))
        {
            Error = "No source files in gamedata folder: " + EnvPaths.GetGamedataPath();
            Debug.LogError(Error);
            AllFilesExists = false;
        }

        if (AllFilesExists)
        {
            // Begin load
            LoadRecentMaps.MoveLastMaps(ScenarioFileName, FolderName, FolderParentPath);
            LoadingMapProcess = true;
            InfoPopup.Show(true, "Loading map...\n( " + ScenarioFileName + ".lua" + " )");
            EditMenu.gameObject.SetActive(true);
            Background.SetActive(false);
            yield return(null);

            ScenarioLuaFile = new ScenarioLua();
            SaveLuaFile     = new SaveLua();
            TablesLuaFile   = new TablesLua();
            AsyncOperation ResUn = Resources.UnloadUnusedAssets();
            while (!ResUn.isDone)
            {
                yield return(null);
            }

            // Scenario LUA
            if (ScenarioLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
            }


            CameraControler.Current.MapSize = Mathf.Max(ScenarioLuaFile.Data.Size[0], ScenarioLuaFile.Data.Size[1]);
            CameraControler.Current.RestartCam();


            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.map + ")");
            yield return(null);

            // SCMAP
            var LoadScmapFile = HeightmapControler.StartCoroutine(ScmapEditor.Current.LoadScmapFile());
            yield return(LoadScmapFile);

            CameraControler.Current.RestartCam();

            EditMenu.MapInfoMenu.SaveAsFa.isOn = HeightmapControler.map.VersionMinor >= 60;
            EditMenu.MapInfoMenu.SaveAsSc.isOn = !EditMenu.MapInfoMenu.SaveAsFa.isOn;

            InfoPopup.Show(true, "Loading map...\n(" + ScenarioLuaFile.Data.save + ")");
            yield return(null);

            if (loadSave)
            {
                // Save LUA
                SaveLuaFile.Load();
                SetSaveLua();
                //LoadSaveLua();
                yield return(null);
            }

            //GetGamedataFile.LoadUnit("XEL0209").CreateUnitObject(MapLuaParser.Current.MapCenterPoint, Quaternion.identity);

            //GetGamedataFile.LoadUnit("UEB0201").CreateUnitObject(MapLuaParser.Current.MapCenterPoint + Vector3.forward * 0.7f, Quaternion.identity);

            //GetGamedataFile.LoadUnit("UEL0001").CreateUnitObject(MapLuaParser.Current.MapCenterPoint + Vector3.left * 0.3f, Quaternion.identity);

            /*
             * //4k Sparkys with GPU instancing
             * for (int x = 0; x < 63; x++)
             * {
             *      for(int y = 0; y < 63; y++)
             *      {
             *              Vector3 Pos = MapLuaParser.Current.MapCenterPoint + new Vector3(x * -0.1f, 0, y * -0.1f);
             *              GetGamedataFile.LoadUnit("XEL0209").CreateUnitObject(Pos, Quaternion.identity);
             *      }
             * }
             */

            // Load Props
            if (LoadProps)
            {
                PropsMenu.gameObject.SetActive(true);

                PropsMenu.AllowBrushUpdate = false;
                PropsMenu.StartCoroutine(PropsMenu.LoadProps());
                while (PropsMenu.LoadingProps)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading props " + PropsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Props.Count + ")");
                    yield return(null);
                }

                PropsMenu.gameObject.SetActive(false);
            }

            if (LoadDecals)
            {
                DecalsMenu.gameObject.SetActive(true);

                //DecalsMenu.AllowBrushUpdate = false;
                DecalsMenu.StartCoroutine(DecalsMenu.LoadDecals());
                while (DecalsInfo.LoadingDecals)
                {
                    InfoPopup.Show(true, "Loading map...\n( Loading decals " + DecalsMenu.LoadedCount + "/" + ScmapEditor.Current.map.Decals.Count + ")");
                    yield return(null);
                }

                DecalsMenu.gameObject.SetActive(false);
            }

            if (TablesLuaFile.Load(FolderName, ScenarioFileName, FolderParentPath))
            {
                //Map Loaded
            }

            InfoPopup.Show(false);
            WindowStateSever.WindowStateSaver.ChangeWindowName(FolderName);
            LoadingMapProcess = false;


            RenderMarkersConnections.Current.UpdateConnections();

            EditMenu.Categorys[0].GetComponent <MapInfo>().UpdateFields();
        }
        else
        {
            ResetUI();
            ReturnLoadingWithError(Error);
        }
    }