public MyScriptItemInfo(MyBlueprintTypeEnum type,string scriptName,ulong? id = null,string description =null,MySteamWorkshop.SubscribedItem item=null):
     base(type,id)
 {
     ScriptName = scriptName;
     Description = description;
     SteamItem = item;
 }
        void GetBlueprints(string directory, MyBlueprintTypeEnum type)
        {
            if (!Directory.Exists(directory))
            {
                return;
            }
            string[]      folders        = Directory.GetDirectories(directory);
            List <string> fileNames      = new List <string>();
            List <string> blueprintNames = new List <string>();

            foreach (var f in folders)
            {
                fileNames.Add(f + "\\bp.sbc");
                var tokens = f.Split('\\');
                blueprintNames.Add(tokens[tokens.Length - 1]);
            }

            for (int i = 0; i < blueprintNames.Count; i++)
            {
                String name = blueprintNames[i];
                var    info = new MyBlueprintItemInfo(type);
                var    item = new MyGuiControlListbox.Item(text: new StringBuilder(name), toolTip: name, userData: info, icon: MyGuiConstants.TEXTURE_ICON_BLUEPRINTS_LOCAL.Normal);
                m_blueprintList.Add(item);
            }
        }
 public MyScriptItemInfo(MyBlueprintTypeEnum type, string scriptName, ulong?id = null, string description = null, MySteamWorkshop.SubscribedItem item = null) :
     base(type, id)
 {
     ScriptName  = scriptName;
     Description = description;
     SteamItem   = item;
 }
        protected static void SavePrefabToFile(MyObjectBuilder_Definitions prefab, string name = null, bool replace = false, MyBlueprintTypeEnum type = MyBlueprintTypeEnum.LOCAL)
        {
            if (name == null)
            {
                name = MyUtils.StripInvalidChars(MyCubeBuilder.Static.Clipboard.CopiedGridsName);
            }

            string file = "";

            if (type == MyBlueprintTypeEnum.LOCAL)
            {
                file = Path.Combine(m_localBlueprintFolder, name);
            }
            else
            {
                file = Path.Combine(m_workshopBlueprintFolder, "temp", name);
            }
            string filePath = "";
            int    index    = 1;

            try
            {
                if (!replace)
                {
                    while (MyFileSystem.DirectoryExists(file))
                    {
                        file = Path.Combine(m_localBlueprintFolder, name + "_" + index);
                        index++;
                    }
                    if (index > 1)
                    {
                        name += new StringBuilder("_" + (index - 1));
                    }
                }
                filePath = file + "\\bp.sbc";
                var success = MyObjectBuilderSerializer.SerializeXML(filePath, false, prefab);

                Debug.Assert(success, "falied to write blueprint to file");
                if (!success)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               buttonType: MyMessageBoxButtonsType.OK,
                                               styleEnum: MyMessageBoxStyleEnum.Error,
                                               messageCaption: new StringBuilder("Error"),
                                               messageText: new StringBuilder("There was a problem with saving blueprint")
                                               ));
                    if (Directory.Exists(file))
                    {
                        Directory.Delete(file, true);
                    }
                }
            }
            catch (Exception e)
            {
                MySandboxGame.Log.WriteLine(String.Format("Failed to write prefab at file {0}, message: {1}, stack:{2}", filePath, e.Message, e.StackTrace));
            }
        }
Beispiel #5
0
 public MyBlueprintItemInfo(MyBlueprintTypeEnum type, ulong?id = null)
 {
     Type            = type;
     PublishedItemId = id;
 }
        protected static void SavePrefabToFile(MyObjectBuilder_Definitions prefab, string name, bool replace = false, MyBlueprintTypeEnum type = MyBlueprintTypeEnum.LOCAL)
        { 
            //if (name == null)
            //{
            //    name = MyUtils.StripInvalidChars(MyCubeBuilder.Static.Clipboard.CopiedGridsName);
            //}

            Debug.Assert(name != null, "Name cannot be null");

            string file = "";
            if (type == MyBlueprintTypeEnum.LOCAL)
            {
                file = Path.Combine(m_localBlueprintFolder, name);
            }
            else 
            {
                file = Path.Combine(m_workshopBlueprintFolder, "temp", name);
            }
            string filePath = "";
            int index = 1;

            try
            {
                if (!replace)
                {
                    while (MyFileSystem.DirectoryExists(file))
                    {
                        file = Path.Combine(m_localBlueprintFolder, name + "_" + index);
                        index++;
                    }
                    if (index > 1)
                    {
                        name += new StringBuilder("_" + (index - 1));
                    }
                }
                filePath = file + "\\bp.sbc";
                var success = MyObjectBuilderSerializer.SerializeXML(filePath, false, prefab);

                Debug.Assert(success, "falied to write blueprint to file");
                if (!success)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                        buttonType: MyMessageBoxButtonsType.OK,
                        styleEnum: MyMessageBoxStyleEnum.Error,
                        messageCaption: new StringBuilder("Error"),
                        messageText: new StringBuilder("There was a problem with saving blueprint")
                        ));
                    if (Directory.Exists(file))
                        Directory.Delete(file, true);
                }

            }
            catch (Exception e)
            {
                MySandboxGame.Log.WriteLine(String.Format("Failed to write prefab at file {0}, message: {1}, stack:{2}", filePath, e.Message, e.StackTrace));
            }
        }
 public MyBlueprintItemInfo(MyBlueprintTypeEnum type, ulong? id = null)
 {
     Type = type;
     PublishedItemId = id;
 }
        void GetBlueprints(string directory, MyBlueprintTypeEnum type)
        {
            if (!Directory.Exists(directory))
                return;
            string[] folders = Directory.GetDirectories(directory);
            List<string> fileNames = new List<string>();
            List<string> blueprintNames = new List<string>();

            foreach (var f in folders)
            {
                fileNames.Add(f + "\\bp.sbc");
                var tokens = f.Split('\\');
                blueprintNames.Add(tokens[tokens.Length - 1]);
            }

            for (int i = 0; i < blueprintNames.Count; i++)
            {
                String name = blueprintNames[i];
                var info = new MyBlueprintItemInfo(type);
                var item = new MyGuiControlListbox.Item(text: new StringBuilder(name), toolTip: name, userData: info, icon: MyGuiConstants.TEXTURE_ICON_BLUEPRINTS_LOCAL.Normal);
                m_blueprintList.Add(item);
            }
        }
 public MyScriptItemInfo(MyBlueprintTypeEnum type, string scriptName, ulong?id = null, string description = null) :
     base(type, id)
 {
     ScriptName  = scriptName;
     Description = description;
 }
 public MyScriptItemInfo(MyBlueprintTypeEnum type, string scriptName, ulong? id = null, string description = null) :
     base(type, id)
 {
     ScriptName = scriptName;
     Description = description;
 }