void GetLocalScriptNames(bool reload = false)
        {
            if (!Directory.Exists(m_localBlueprintFolder))
            {
                return;
            }
            string[] scriptNames = Directory.GetDirectories(m_localBlueprintFolder);

            foreach (var scriptName in scriptNames)
            {
                string directoryName = Path.GetFileName(scriptName);
                var    info          = new MyScriptItemInfo(MyBlueprintTypeEnum.LOCAL, directoryName);
                var    item          = new MyGuiControlListbox.Item(text: new StringBuilder(directoryName), toolTip: directoryName, userData: info, icon: MyGuiConstants.TEXTURE_ICON_BLUEPRINTS_LOCAL.Normal);
                m_scriptList.Add(item);
            }

            if (m_task.IsComplete && reload)
            {
                GetWorkshopScripts();
            }
            else
            {
                AddWorkshopItemsToList();
            }
        }
 void DownloadScriptFromSteam()
 {
     if (m_selectedItem != null)
     {
         MyScriptItemInfo itemInfo = (m_selectedItem.UserData as MyScriptItemInfo);
         MySteamWorkshop.DownloadScriptBlocking(itemInfo.SteamItem);
     }
 }
 void OnScriptDownloaded()
 {
     if (OnScriptOpened != null && m_selectedItem != null)
     {
         MyScriptItemInfo itemInfo = (m_selectedItem.UserData as MyScriptItemInfo);
         OnScriptOpened(Path.Combine(MyFileSystem.UserDataPath, SCRIPTS_DIRECTORY, "workshop", itemInfo.SteamItem.PublishedFileId.ToString() + WORKSHOP_SCRIPT_EXTENSION));
     }
     m_scriptList.Enabled = true;
 }
 private static void AddWorkshopItemsToList()
 {
     foreach (var steamItem in m_subscribedItemsList)
     {
         var info = new MyScriptItemInfo(MyBlueprintTypeEnum.STEAM, steamItem.Title, steamItem.SteamIDOwner, steamItem.Description, steamItem);
         var item = new MyGuiControlListbox.Item(text: new StringBuilder(steamItem.Title), toolTip: steamItem.Title, userData: info, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal);
         m_scriptList.Add(item);
     }
 }
 public MyGuiDetailScreenScriptLocal(Action <MyScriptItemInfo> callBack, MyScriptItemInfo selectedItem, MyGuiIngameScriptsPage parent, float textScale) :
     base(new Vector2(0.37f, 0.325f), new Vector2(0.725f, 0.4f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, false)
 {
     WasPublished              = false;
     this.callBack             = callBack;
     m_parent                  = parent;
     m_selectedItem            = selectedItem;
     m_textScale               = textScale;
     m_localBlueprintFolder    = Path.Combine(MyFileSystem.UserDataPath, MyGuiIngameScriptsPage.SCRIPTS_DIRECTORY, "local");
     m_workshopBlueprintFolder = Path.Combine(MyFileSystem.UserDataPath, MyGuiIngameScriptsPage.SCRIPTS_DIRECTORY, "workshop");
     RecreateControls(true);
     EnabledBackgroundFade = true;
 }
 public MyGuiDetailScreenScriptLocal(Action<MyScriptItemInfo> callBack, MyScriptItemInfo selectedItem, MyGuiIngameScriptsPage parent, float textScale) :
     base(new Vector2(0.37f, 0.325f), new Vector2(0.725f, 0.4f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, false)
 {
     WasPublished = false;
     this.callBack = callBack;
     m_parent = parent;
     m_selectedItem = selectedItem;
     m_textScale = textScale;
     m_localBlueprintFolder = Path.Combine(MyFileSystem.UserDataPath, MyGuiIngameScriptsPage.SCRIPTS_DIRECTORY, "local");
     m_workshopBlueprintFolder = Path.Combine(MyFileSystem.UserDataPath, MyGuiIngameScriptsPage.SCRIPTS_DIRECTORY, "workshop");
     RecreateControls(true);
     EnabledBackgroundFade = true;
 }
 public void OnReplaceFromEditor(MyGuiControlButton button)
 {
     if (m_selectedItem == null)
     {
         return;
     }
     if (GetCodeFromEditor != null)
     {
         if (!Directory.Exists(m_localBlueprintFolder))
         {
             return;
         }
         MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                    buttonType : MyMessageBoxButtonsType.YES_NO,
                                    styleEnum : MyMessageBoxStyleEnum.Info,
                                    messageCaption : MyTexts.Get(MySpaceTexts.ProgrammableBlock_ReplaceScriptNameDialogTitle),
                                    messageText : MyTexts.Get(MySpaceTexts.ProgrammableBlock_ReplaceScriptDialogText),
                                    callback : delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
         {
             if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
             {
                 MyScriptItemInfo info = m_selectedItem.UserData as MyScriptItemInfo;
                 string filePath       = Path.Combine(m_localBlueprintFolder, info.ScriptName, DEFAULT_SCRIPT_NAME + SCRIPT_EXTENSION);
                 if (File.Exists(filePath))
                 {
                     string code = GetCodeFromEditor();
                     File.WriteAllText(filePath, code, Encoding.UTF8);
                 }
             }
             else
             {
                 return;
             }
         },
                                    canHideOthers: false
                                    ));
     }
 }
 protected void CallResultCallback(MyScriptItemInfo val)
 {
     callBack(val);
 }
 protected void CallResultCallback(MyScriptItemInfo val)
 {
     callBack(val);
 }
 void OpenSharedScript(MyScriptItemInfo itemInfo)
 {
     m_scriptList.Enabled = false;
     m_task = Parallel.Start(DownloadScriptFromSteam, OnScriptDownloaded);
 }
 private static void AddWorkshopItemsToList()
 {
     foreach (var steamItem in m_subscribedItemsList)
     {
         var info = new MyScriptItemInfo(MyBlueprintTypeEnum.STEAM, steamItem.Title, steamItem.SteamIDOwner, steamItem.Description, steamItem);
         var item = new MyGuiControlListbox.Item(text: new StringBuilder(steamItem.Title), toolTip: steamItem.Title, userData: info, icon: MyGuiConstants.TEXTURE_ICON_MODS_WORKSHOP.Normal);
         m_scriptList.Add(item);
     }
 }
        void GetLocalScriptNames(bool reload = false)
        {
            if (!Directory.Exists(m_localScriptFolder))
                return;
            string[] scriptNames = Directory.GetDirectories(m_localScriptFolder);

            foreach(var scriptName in scriptNames)
            {
                string directoryName = Path.GetFileName(scriptName);
                var info = new MyScriptItemInfo(MyBlueprintTypeEnum.LOCAL,directoryName);  
                var item = new MyGuiControlListbox.Item(text: new StringBuilder(directoryName), toolTip: directoryName, userData: info, icon: MyGuiConstants.TEXTURE_ICON_BLUEPRINTS_LOCAL.Normal);
                m_scriptList.Add(item);
            }

            if (m_task.IsComplete && reload)
            {
                GetWorkshopScripts();
            }
            else         
            {
                AddWorkshopItemsToList();
            }
        }
 void OpenSharedScript(MyScriptItemInfo itemInfo)
 {
     m_scriptList.Enabled = false;
     m_task = Parallel.Start(DownloadScriptFromSteam, OnScriptDownloaded);
 }