public override void Update() { m_rateButton.IsEnabled = (m_starRating.Rating != 0f); if (m_rateButton.IsClicked) { DialogsManager.HideDialog(this); CancellableBusyDialog busyDialog = new CancellableBusyDialog("иб╦═к└иоол...", autoHideOnCancel: false); DialogsManager.ShowDialog(base.ParentWidget, busyDialog); CommunityContentManager.Rate(m_address, m_userId, (int)m_starRating.Rating, busyDialog.Progress, delegate { DialogsManager.HideDialog(busyDialog); }, delegate { DialogsManager.HideDialog(busyDialog); }); } if (m_reportLink.IsClicked && UserManager.ActiveUser != null) { DialogsManager.HideDialog(this); DialogsManager.ShowDialog(base.ParentWidget, new ReportCommunityContentDialog(m_address, m_displayName, UserManager.ActiveUser.UniqueId)); } if (base.Input.Cancel || m_cancelButton.IsClicked) { DialogsManager.HideDialog(this); } }
public void UpdateList() { m_directoryList.ClearItems(); if (m_externalContentProvider != null && m_externalContentProvider.IsLoggedIn) { CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 9), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); m_externalContentProvider.List(m_path, busyDialog.Progress, delegate(ExternalContentEntry entry) { DialogsManager.HideDialog(busyDialog); List <ExternalContentEntry> list = new List <ExternalContentEntry>(entry.ChildEntries.Where((ExternalContentEntry e) => EntryFilter(e)).Take(1000)); m_directoryList.ClearItems(); list.Sort(delegate(ExternalContentEntry e1, ExternalContentEntry e2) { if (e1.Type == ExternalContentType.Directory && e2.Type != ExternalContentType.Directory) { return(-1); } return((e1.Type != ExternalContentType.Directory && e2.Type == ExternalContentType.Directory) ? 1 : string.Compare(e1.Path, e2.Path)); }); foreach (ExternalContentEntry item in list) { m_directoryList.AddItem(item); } }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } }
public void PopulateList(string cursor) { string text = string.Empty; if (SettingsManager.CommunityContentMode == CommunityContentMode.Strict) { text = "1"; } if (SettingsManager.CommunityContentMode == CommunityContentMode.Normal) { text = "0"; } string text2 = (m_filter is string) ? ((string)m_filter) : string.Empty; string text3 = (m_filter is ExternalContentType) ? LanguageControl.Get(fName, m_filter.ToString()) : string.Empty; string text4 = LanguageControl.Get(fName, m_order.ToString()); string cacheKey = text2 + "\n" + text3 + "\n" + text4 + "\n" + text; m_moreLink = null; if (string.IsNullOrEmpty(cursor)) { m_listPanel.ClearItems(); m_listPanel.ScrollPosition = 0f; if (m_contentExpiryTime != 0.0 && Time.RealTime < m_contentExpiryTime && m_itemsCache.TryGetValue(cacheKey, out IEnumerable <object> value)) { foreach (object item in value) { m_listPanel.AddItem(item); } return; } } CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 2), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); CommunityContentManager.List(cursor, text2, text3, text, text4, busyDialog.Progress, delegate(List <CommunityContentEntry> list, string nextCursor) { DialogsManager.HideDialog(busyDialog); m_contentExpiryTime = Time.RealTime + 300.0; while (m_listPanel.Items.Count > 0 && !(m_listPanel.Items[m_listPanel.Items.Count - 1] is CommunityContentEntry)) { m_listPanel.RemoveItemAt(m_listPanel.Items.Count - 1); } foreach (CommunityContentEntry item2 in list) { m_listPanel.AddItem(item2); } if (list.Count > 0 && !string.IsNullOrEmpty(nextCursor)) { m_listPanel.AddItem(nextCursor); } m_itemsCache[cacheKey] = new List <object>(m_listPanel.Items); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); }
public void DownloadEntry(CommunityContentEntry entry) { string userId = (UserManager.ActiveUser != null) ? UserManager.ActiveUser.UniqueId : string.Empty; CancellableBusyDialog busyDialog = new CancellableBusyDialog(string.Format(LanguageControl.Get(fName, 1), entry.Name), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); CommunityContentManager.Download(entry.Address, entry.Name, entry.Type, userId, busyDialog.Progress, delegate { DialogsManager.HideDialog(busyDialog); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); }
public static void ShowLoginUiIfNeeded(IExternalContentProvider provider, bool showWarningDialog, Action handler) { if (provider.RequiresLogin && !provider.IsLoggedIn) { Action loginAction = delegate { CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 5), autoHideOnCancel: true); DialogsManager.ShowDialog(null, busyDialog); provider.Login(busyDialog.Progress, delegate { DialogsManager.HideDialog(busyDialog); handler?.Invoke(); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); if (error != null) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); } }); }; if (showWarningDialog) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get(fName, 6), string.Format(LanguageControl.Get(fName, 7), provider.DisplayName), LanguageControl.Get(fName, 8), LanguageControl.Get("Usual", "cancel"), delegate(MessageDialogButton b) { if (b == MessageDialogButton.Button1) { loginAction(); } })); } else { loginAction(); } } else { handler?.Invoke(); } }
public void DeleteEntry(CommunityContentEntry entry) { if (UserManager.ActiveUser != null) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get(fName, 4), LanguageControl.Get(fName, 5), LanguageControl.Get("Usual", "yes"), LanguageControl.Get("Usual", "no"), delegate(MessageDialogButton button) { if (button == MessageDialogButton.Button1) { CancellableBusyDialog busyDialog = new CancellableBusyDialog(string.Format(LanguageControl.Get(fName, 3), entry.Name), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); CommunityContentManager.Delete(entry.Address, UserManager.ActiveUser.UniqueId, busyDialog.Progress, delegate { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get(fName, 6), LanguageControl.Get(fName, 7), LanguageControl.Get("Usual", "ok"), null, null)); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } })); } }
public override void Update() { string text = m_linkTextBoxWidget.Text.Trim(); string text2 = m_nameTextBoxWidget.Text.Trim(); m_typeLabelWidget.Text = ExternalContentManager.GetEntryTypeDescription(m_type); m_typeIconWidget.Subtexture = ExternalContentManager.GetEntryTypeIcon(m_type); m_publishButtonWidget.IsEnabled = (text.Length > 0 && text2.Length > 0); if (m_changeTypeButtonWidget.IsClicked) { DialogsManager.ShowDialog(base.ParentWidget, new SelectExternalContentTypeDialog("Select Content Type", delegate(ExternalContentType item) { m_type = item; })); } else if (base.Input.Cancel || m_cancelButtonWidget.IsClicked) { DialogsManager.HideDialog(this); } else if (m_publishButtonWidget.IsClicked) { CancellableBusyDialog busyDialog = new CancellableBusyDialog("Publishing", autoHideOnCancel: false); DialogsManager.ShowDialog(base.ParentWidget, busyDialog); CommunityContentManager.Publish(text, text2, m_type, m_user, busyDialog.Progress, delegate { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Link Published Successfully", "It should start appearing in the listings after it is moderated. Please keep the file accessible through this link, so that other community members can download it.", LanguageControl.Get("Usual", "ok"), null, delegate { DialogsManager.HideDialog(this); })); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } }
public void DownloadEntry(ExternalContentEntry entry) { CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 10), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); m_externalContentProvider.Download(entry.Path, busyDialog.Progress, delegate(Stream stream) { busyDialog.LargeMessage = LanguageControl.Get(fName, 12); ExternalContentManager.ImportExternalContent(stream, entry.Type, Storage.GetFileName(entry.Path), delegate { stream.Dispose(); DialogsManager.HideDialog(busyDialog); }, delegate(Exception error) { stream.Dispose(); DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); }
public override void Update() { m_reportButton.IsEnabled = (m_reasonWidgetsList.Count((CheckboxWidget w) => w.IsChecked) == 1); if (m_reportButton.IsClicked) { DialogsManager.HideDialog(this); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Are you sure?", "Reporting offensive content is a serious matter. Please make sure you checked the right box. Do not report content which is not offensive.", "Proceed", "Cancel", delegate(MessageDialogButton b) { if (b == MessageDialogButton.Button1) { string report = string.Empty; foreach (CheckboxWidget reasonWidgets in m_reasonWidgetsList) { if (reasonWidgets.IsChecked) { report = (string)reasonWidgets.Tag; break; } } CancellableBusyDialog busyDialog = new CancellableBusyDialog("Sending Report", autoHideOnCancel: false); DialogsManager.ShowDialog(base.ParentWidget, busyDialog); CommunityContentManager.Report(m_address, m_userId, report, busyDialog.Progress, delegate { DialogsManager.HideDialog(busyDialog); }, delegate { DialogsManager.HideDialog(busyDialog); }); } })); } if (base.Input.Cancel || m_cancelButton.IsClicked) { DialogsManager.HideDialog(this); } }
public override void Update() { if (m_listDirty) { m_listDirty = false; UpdateList(); } ExternalContentEntry externalContentEntry = null; if (m_directoryList.SelectedIndex.HasValue) { externalContentEntry = (m_directoryList.Items[m_directoryList.SelectedIndex.Value] as ExternalContentEntry); } if (externalContentEntry != null) { m_actionButton.IsVisible = true; if (externalContentEntry.Type == ExternalContentType.Directory) { m_actionButton.Text = LanguageControl.Get(fName, 1); m_actionButton.IsEnabled = true; m_copyLinkButton.IsEnabled = false; } else { m_actionButton.Text = LanguageControl.Get(fName, 2); if (ExternalContentManager.IsEntryTypeDownloadSupported(ExternalContentManager.ExtensionToType(Storage.GetExtension(externalContentEntry.Path).ToLower()))) { m_actionButton.IsEnabled = true; m_copyLinkButton.IsEnabled = true; } else { m_actionButton.IsEnabled = false; m_copyLinkButton.IsEnabled = false; } } } else { m_actionButton.IsVisible = false; m_copyLinkButton.IsVisible = false; } m_directoryLabel.Text = m_externalContentProvider.IsLoggedIn ? string.Format(LanguageControl.Get(fName, 3), m_path) : LanguageControl.Get(fName, 4); m_providerNameLabel.Text = m_externalContentProvider.DisplayName; m_upDirectoryButton.IsEnabled = (m_externalContentProvider.IsLoggedIn && m_path != "/"); m_loginLogoutButton.Text = (m_externalContentProvider.IsLoggedIn ? LanguageControl.Get(fName, 5) : LanguageControl.Get(fName, 6)); m_loginLogoutButton.IsVisible = m_externalContentProvider.RequiresLogin; m_copyLinkButton.IsVisible = m_externalContentProvider.SupportsLinks; m_copyLinkButton.IsEnabled = (externalContentEntry != null && ExternalContentManager.IsEntryTypeDownloadSupported(externalContentEntry.Type)); if (m_changeProviderButton.IsClicked) { DialogsManager.ShowDialog(null, new SelectExternalContentProviderDialog(LanguageControl.Get(fName, 7), listingSupportRequired : true, delegate(IExternalContentProvider provider) { m_externalContentProvider = provider; m_listDirty = true; SetPath(null); })); } if (m_upDirectoryButton.IsClicked) { string directoryName = Storage.GetDirectoryName(m_path); SetPath(directoryName); } if (m_actionButton.IsClicked && externalContentEntry != null) { if (externalContentEntry.Type == ExternalContentType.Directory) { SetPath(externalContentEntry.Path); } else { DownloadEntry(externalContentEntry); } } if (m_copyLinkButton.IsClicked && externalContentEntry != null && ExternalContentManager.IsEntryTypeDownloadSupported(externalContentEntry.Type)) { CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 8), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); m_externalContentProvider.Link(externalContentEntry.Path, busyDialog.Progress, delegate(string link) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new ExternalContentLinkDialog(link)); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } if (m_loginLogoutButton.IsClicked) { if (m_externalContentProvider.IsLoggedIn) { m_externalContentProvider.Logout(); SetPath(null); m_listDirty = true; } else { ExternalContentManager.ShowLoginUiIfNeeded(m_externalContentProvider, showWarningDialog: false, delegate { SetPath(null); m_listDirty = true; }); } } if (base.Input.Back || base.Input.Cancel || Children.Find <ButtonWidget>("TopBar.Back").IsClicked) { ScreensManager.SwitchScreen("Content"); } }
public override void Update() { string text = m_linkTextBoxWidget.Text.Trim(); string name = m_nameTextBoxWidget.Text.Trim(); m_typeLabelWidget.Text = ExternalContentManager.GetEntryTypeDescription(m_type); m_typeIconWidget.Subtexture = ExternalContentManager.GetEntryTypeIcon(m_type); if (ExternalContentManager.DoesEntryTypeRequireName(m_type)) { m_nameTextBoxWidget.IsEnabled = true; m_downloadButtonWidget.IsEnabled = (text.Length > 0 && name.Length > 0 && m_type != ExternalContentType.Unknown); if (m_updateContentName) { m_nameTextBoxWidget.Text = GetNameFromLink(m_linkTextBoxWidget.Text); m_updateContentName = false; } } else { m_nameTextBoxWidget.IsEnabled = false; m_nameTextBoxWidget.Text = string.Empty; m_downloadButtonWidget.IsEnabled = (text.Length > 0 && m_type != ExternalContentType.Unknown); } if (m_updateContentType) { m_type = GetTypeFromLink(m_linkTextBoxWidget.Text); m_updateContentType = false; } if (m_changeTypeButtonWidget.IsClicked) { DialogsManager.ShowDialog(base.ParentWidget, new SelectExternalContentTypeDialog("Select Content Type", delegate(ExternalContentType item) { m_type = item; m_updateContentName = true; })); } else if (base.Input.Cancel || m_cancelButtonWidget.IsClicked) { DialogsManager.HideDialog(this); } else if (m_downloadButtonWidget.IsClicked) { CancellableBusyDialog busyDialog = new CancellableBusyDialog("Downloading", autoHideOnCancel: false); DialogsManager.ShowDialog(base.ParentWidget, busyDialog); WebManager.Get(text, null, null, busyDialog.Progress, delegate(byte[] data) { ExternalContentManager.ImportExternalContent(new MemoryStream(data), m_type, name, delegate { DialogsManager.HideDialog(busyDialog); DialogsManager.HideDialog(this); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); }, delegate(Exception error) { DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } }
public static void ShowUploadUi(ExternalContentType type, string name) { DialogsManager.ShowDialog(null, new SelectExternalContentProviderDialog(LanguageControl.Get(fName, 9), listingSupportRequired : false, delegate(IExternalContentProvider provider) { try { if (provider != null) { ShowLoginUiIfNeeded(provider, showWarningDialog: true, delegate { CancellableBusyDialog busyDialog = new CancellableBusyDialog(LanguageControl.Get(fName, 10), autoHideOnCancel: false); DialogsManager.ShowDialog(null, busyDialog); Task.Run(delegate { bool needsDelete = false; string sourcePath = null; Stream stream = null; Action cleanup = delegate { Utilities.Dispose(ref stream); if (needsDelete && sourcePath != null) { try { Storage.DeleteFile(sourcePath); } catch { } } }; try { string path; if (type == ExternalContentType.BlocksTexture) { sourcePath = BlocksTexturesManager.GetFileName(name); if (sourcePath == null) { throw new InvalidOperationException(LanguageControl.Get(fName, 11)); } path = Storage.GetFileName(sourcePath); } else if (type == ExternalContentType.CharacterSkin) { sourcePath = CharacterSkinsManager.GetFileName(name); if (sourcePath == null) { throw new InvalidOperationException(LanguageControl.Get(fName, 11)); } path = Storage.GetFileName(sourcePath); } else if (type == ExternalContentType.FurniturePack) { sourcePath = FurniturePacksManager.GetFileName(name); if (sourcePath == null) { throw new InvalidOperationException(LanguageControl.Get(fName, 11)); } path = Storage.GetFileName(sourcePath); } else { if (type != ExternalContentType.World) { throw new InvalidOperationException(LanguageControl.Get(fName, 12)); } busyDialog.LargeMessage = LanguageControl.Get(fName, 13); sourcePath = "android:SurvivalCraft2.2/WorldUpload.tmp"; needsDelete = true; string name2 = WorldsManager.GetWorldInfo(name).WorldSettings.Name; path = $"{name2}.scworld"; using (Stream targetStream = Storage.OpenFile(sourcePath, OpenFileMode.Create)) { WorldsManager.ExportWorld(name, targetStream); } } busyDialog.LargeMessage = LanguageControl.Get(fName, 14); stream = Storage.OpenFile(sourcePath, OpenFileMode.Read); provider.Upload(path, stream, busyDialog.Progress, delegate(string link) { long length = stream.Length; cleanup(); DialogsManager.HideDialog(busyDialog); if (string.IsNullOrEmpty(link)) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "success"), string.Format(LanguageControl.Get(fName, 15), DataSizeFormatter.Format(length)), LanguageControl.Get("Usual", "ok"), null, null)); } else { DialogsManager.ShowDialog(null, new ExternalContentLinkDialog(link)); } }, delegate(Exception error) { cleanup(); DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), error.Message, LanguageControl.Get("Usual", "ok"), null, null)); }); } catch (Exception ex2) { cleanup(); DialogsManager.HideDialog(busyDialog); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), ex2.Message, LanguageControl.Get("Usual", "ok"), null, null)); } }); }); } } catch (Exception ex) { DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get("Usual", "error"), ex.Message, LanguageControl.Get("Usual", "ok"), null, null)); } })); }