public MyGuiScreenSaveAs(MyWorldInfo copyFrom, string sessionPath, List<string> existingSessionNames) : base(new Vector2(0.5f, 0.5f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, new Vector2(0.5f, 0.35f)) { EnabledBackgroundFade = true; AddCaption(MyCommonTexts.ScreenCaptionSaveAs); float textboxPositionY = -0.02f; m_nameTextbox = new MyGuiControlTextbox( position: new Vector2(0, textboxPositionY), defaultText: copyFrom.SessionName, maxLength: 75); m_okButton = new MyGuiControlButton( text: MyTexts.Get(MyCommonTexts.Ok), onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM); m_cancelButton = new MyGuiControlButton( text: MyTexts.Get(MyCommonTexts.Cancel), onButtonClick: OnCancelButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM); Vector2 buttonOrigin = new Vector2(0f, Size.Value.Y * 0.4f); Vector2 buttonOffset = new Vector2(0.01f, 0f); m_okButton.Position = buttonOrigin - buttonOffset; m_cancelButton.Position = buttonOrigin + buttonOffset; Controls.Add(m_nameTextbox); Controls.Add(m_okButton); Controls.Add(m_cancelButton); m_nameTextbox.MoveCarriageToEnd(); m_copyFrom = copyFrom; m_sessionPath = sessionPath; m_existingSessionNames = existingSessionNames; CloseButtonEnabled = true; CloseButtonOffset = new Vector2(-0.005f, 0.0035f); OnEnterCallback = OnEnterPressed; }
private void endWorkshop(IMyAsyncResult result, MyGuiScreenProgressAsync screen) { var loadResult = (LoadWorkshopResult)result; m_subscribedScenarios = loadResult.SubscribedScenarios; foreach(var item in loadResult.SubscribedScenarios) { MyWorldInfo wi = new MyWorldInfo(); wi.SessionName = item.Title; wi.Briefing = item.Description; wi.WorkshopId = item.PublishedFileId; m_availableSavesWorkshop.Add(new Tuple<string, MyWorldInfo>(WORKSHOP_PATH_TAG, wi)); } m_availableSavesWorkshop.Sort((x, y) => x.Item2.SessionName.CompareTo(y.Item2.SessionName)); AfterPartLoaded(); screen.CloseScreen(); }
public static void Publish(string sessionPath, MyWorldInfo worlInfo) { if (MyFakes.XBOX_PREVIEW) { MyGuiSandbox.Show(MyCommonTexts.MessageBoxTextErrorFeatureNotAvailableYet, MyCommonTexts.MessageBoxCaptionError); return; } MyStringId textQuestion, captionQuestion; if (worlInfo.WorkshopId.HasValue) { textQuestion = MyCommonTexts.MessageBoxTextDoYouWishToUpdateWorld; captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToUpdateWorld; } else { textQuestion = MyCommonTexts.MessageBoxTextDoYouWishToPublishWorld; captionQuestion = MyCommonTexts.MessageBoxCaptionDoYouWishToPublishWorld; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum: MyMessageBoxStyleEnum.Info, buttonType: MyMessageBoxButtonsType.YES_NO, messageText: MyTexts.Get(textQuestion), messageCaption: MyTexts.Get(captionQuestion), callback: delegate(MyGuiScreenMessageBox.ResultEnum val) { if (val == MyGuiScreenMessageBox.ResultEnum.YES) { Action<MyGuiScreenMessageBox.ResultEnum, string[]> onTagsChosen = delegate(MyGuiScreenMessageBox.ResultEnum tagsResult, string[] outTags) { if (tagsResult == MyGuiScreenMessageBox.ResultEnum.YES) { MySteamWorkshop.PublishWorldAsync(sessionPath, worlInfo.SessionName, worlInfo.Description, worlInfo.WorkshopId, outTags, SteamSDK.PublishedFileVisibility.Public, callbackOnFinished: delegate(bool success, Result result, ulong publishedFileId) { if (success) { ulong dummy; var checkpoint = MyLocalCache.LoadCheckpoint(sessionPath, out dummy); worlInfo.WorkshopId = publishedFileId; checkpoint.WorkshopId = publishedFileId; MyLocalCache.SaveCheckpoint(checkpoint, sessionPath); MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( styleEnum: MyMessageBoxStyleEnum.Info, messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextWorldPublished), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublished), callback: (a) => { MySteam.API.OpenOverlayUrl(string.Format("http://steamcommunity.com/sharedfiles/filedetails/?id={0}", publishedFileId)); })); } else { MyStringId error; switch (result) { case Result.AccessDenied: error = MyCommonTexts.MessageBoxTextPublishFailed_AccessDenied; break; default: error = MyCommonTexts.MessageBoxTextWorldPublishFailed; break; } MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: MyTexts.Get(error), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionWorldPublishFailed))); } }); } }; if (MySteamWorkshop.WorldCategories.Length > 0) MyGuiSandbox.AddScreen(new MyGuiScreenWorkshopTags(MySteamWorkshop.WORKSHOP_WORLD_TAG, MySteamWorkshop.WorldCategories, null, onTagsChosen)); else onTagsChosen(MyGuiScreenMessageBox.ResultEnum.YES, new string[] { MySteamWorkshop.WORKSHOP_WORLD_TAG }); } })); }
private static MyWorldInfo LoadWorldInfo(string sessionPath) { MyWorldInfo worldInfo = null; try { System.Xml.Linq.XDocument doc = null; string checkpointFile = Path.Combine(sessionPath, CHECKPOINT_FILE); if (!File.Exists(checkpointFile)) return null; using (var stream = MyFileSystem.OpenRead(checkpointFile).UnwrapGZip()) { doc = XDocument.Load(stream); } Debug.Assert(doc != null); var root = doc.Root; Debug.Assert(root != null); var session = root.Element("SessionName"); var description = root.Element("Description"); var lastSaveTime = root.Element("LastSaveTime"); var lastLoadTime = root.Element("LastLoadTime"); var worldId = root.Element("WorldID"); var workshopId = root.Element("WorkshopId"); var briefing = root.Element("Briefing"); var settings = root.Element("Settings"); var scenarioEdit = settings != null ? root.Element("Settings").Element("ScenarioEditMode") : null; worldInfo = new MyWorldInfo(); if (session != null) worldInfo.SessionName = session.Value; if (description != null) worldInfo.Description = description.Value; if (lastSaveTime != null) DateTime.TryParse(lastSaveTime.Value, out worldInfo.LastSaveTime); if (lastLoadTime != null) DateTime.TryParse(lastLoadTime.Value, out worldInfo.LastLoadTime); if (workshopId != null) { ulong tmp; if (ulong.TryParse(workshopId.Value, out tmp)) worldInfo.WorkshopId = tmp; } if (briefing != null) worldInfo.Briefing = briefing.Value; if (scenarioEdit != null) bool.TryParse(scenarioEdit.Value, out worldInfo.ScenarioEditMode); } catch (Exception ex) { MySandboxGame.Log.WriteLine(ex); } return worldInfo; }
void SaveAsync(string newSaveName, string sessionPath, MyWorldInfo copyFrom) { // Try a simple path, then a random if it already exists var newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName, false, false); while (Directory.Exists(newSessionPath)) { newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false); } Directory.CreateDirectory(newSessionPath); MyUtils.CopyDirectory(sessionPath, newSessionPath); ulong sizeInBytes; var checkpoint = MyLocalCache.LoadCheckpoint(newSessionPath, out sizeInBytes); Debug.Assert(checkpoint != null); checkpoint.SessionName = copyFrom.SessionName; checkpoint.WorkshopId = null; MyLocalCache.SaveCheckpoint(checkpoint, newSessionPath); MyLocalCache.SaveLastLoadedTime(newSessionPath, DateTime.Now); }
public SaveResult(string saveDir, string sessionPath, MyWorldInfo copyFrom) { Task = Parallel.Start(() => SaveAsync(saveDir, sessionPath, copyFrom)); }