// ---------[ UI FUNCTIONALITY ]--------- /// <summary>Displays the appropriate field of a given modfile.</summary> public void DisplayDownload(FileDownloadInfo download) { this.m_download = download; string displayText = string.Empty; if (download != null) { if (download.request == null || download.request.downloadedBytes == 0) { displayText = this.m_unstartedText; } else if (download.isDone) { displayText = this.m_completedText; } else if (download.bytesPerSecond <= 1) { displayText = this.m_notDownloadingText; } else { int secondsRemaining = (int)((download.fileSize - (Int64)download.request.downloadedBytes) / download.bytesPerSecond); displayText = ValueFormatting.SecondsAsTime(secondsRemaining); } } this.m_textComponent.text = displayText; }
private void BuildDisplayMap() { string dateTimeFormat = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; m_displayMapping = new Dictionary <Text, GetDisplayString>(); if (modfileIdDisplay != null) { m_displayMapping.Add(modfileIdDisplay, (d) => d.modfileId.ToString()); } if (modIdDisplay != null) { m_displayMapping.Add(modIdDisplay, (d) => d.modId.ToString()); } if (dateAddedDisplay != null) { m_displayMapping.Add(dateAddedDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.dateAdded).ToString(dateTimeFormat)); } if (fileNameDisplay != null) { m_displayMapping.Add(fileNameDisplay, (d) => d.fileName); } if (fileSizeDisplay != null) { m_displayMapping.Add(fileSizeDisplay, (d) => ValueFormatting.ByteCount(d.fileSize, "0.0")); } if (MD5Display != null) { m_displayMapping.Add(MD5Display, (d) => d.MD5); } if (versionDisplay != null) { m_displayMapping.Add(versionDisplay, (d) => d.version); } if (changelogDisplay != null) { m_displayMapping.Add(changelogDisplay, (d) => d.changelog); } if (metadataBlobDisplay != null) { m_displayMapping.Add(metadataBlobDisplay, (d) => d.metadataBlob); } if (virusScanDateDisplay != null) { m_displayMapping.Add(virusScanDateDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.virusScanDate).ToString(dateTimeFormat)); } if (virusScanStatusDisplay != null) { m_displayMapping.Add(virusScanStatusDisplay, (d) => d.virusScanStatus.ToString()); } if (virusScanResultDisplay != null) { m_displayMapping.Add(virusScanResultDisplay, (d) => d.virusScanResult.ToString()); } if (virusScanHashDisplay != null) { m_displayMapping.Add(virusScanHashDisplay, (d) => d.virusScanHash); } }
// ---------[ UI FUNCTIONALITY ]--------- /// <summary>Displays the appropriate field of a given statistics.</summary> public void DisplayStatistics(ModStatistics statistics) { this.m_statistics = statistics; // display object fieldValue = this.reference.GetValue(this.m_statistics); string displayString = ValueFormatting.FormatValue(fieldValue, this.formatting.method, this.formatting.toStringParameter); this.m_textComponent.text = displayString; }
// ---------[ UI FUNCTIONALITY ]--------- /// <summary>Displays the appropriate field of a given profile.</summary> public void DisplayProfile(ModProfile profile) { this.m_profile = profile; // display object fieldValue = this.reference.GetValue(this.m_profile); string displayString = ValueFormatting.FormatValue(fieldValue, this.formatting.method, this.formatting.toStringParameter); this.m_textComponent.text = displayString; }
// ---------[ UI FUNCTIONALITY ]--------- /// <summary>Displays the appropriate field of a given download.</summary> public void DisplayDownload(FileDownloadInfo downloadInfo) { this.m_downloadInfo = downloadInfo; // display object fieldValue = this.reference.GetValue(this.m_downloadInfo); string displayString = ValueFormatting.FormatValue(fieldValue, this.formatting.method, this.formatting.toStringParameter); this.m_textComponent.text = displayString; }
private void PresentData() { float percentComplete = 0f; if (data.bytesTotal > 0) { percentComplete = (float)data.bytesReceived / (float)data.bytesTotal; } if (percentageText != null) { percentageText.text = (percentComplete * 100f).ToString("0.0") + "%"; } if (progressBar != null) { progressBar.percentComplete = percentComplete; } if (bytesReceivedText != null) { bytesReceivedText.text = ValueFormatting.ByteCount(data.bytesReceived, "0.0"); } if (bytesTotalText != null) { bytesTotalText.text = ValueFormatting.ByteCount(data.bytesTotal, "0.0"); } if (bytesPerSecondText != null) { bytesPerSecondText.text = ValueFormatting.ByteCount(data.bytesPerSecond, "0.0") + "/s"; } if (timeRemainingText != null) { // TODO(@jackson): Localize? TimeSpan remaining = TimeSpan.FromSeconds(0f); timeRemainingText.text = (remaining.TotalHours + ":" + remaining.Minutes + ":" + remaining.Seconds); } }
// ---------[ FUNCTIONALITY ]--------- /// <summary>Formats a value as a display string.</summary> public static string FormatValue(object value, Method method, string toStringParameter) { string displayString = string.Empty; if (string.IsNullOrEmpty(toStringParameter)) { // Default value for ToString() in most cases is (G)eneral toStringParameter = "G"; } switch (method) { case Method.ByteCount: { Int64 bytes = 0; if (value != null) { bytes = (Int64)value; } displayString = ValueFormatting.ByteCount(bytes, toStringParameter); } break; case Method.AbbreviatedNumber: { int number = 0; if (value != null) { number = (int)value; } displayString = ValueFormatting.AbbreviateInteger(number, toStringParameter); } break; case Method.TimeStampAsDateTime: { if (value == null) { displayString = "--"; } else { displayString = ServerTimeStamp.ToLocalDateTime((int)value).ToString(toStringParameter); } } break; case Method.Percentage: { if (value == null) { displayString = "--%"; } else { displayString = ((float)value * 100.0f).ToString(toStringParameter) + "%"; } } break; case Method.SecondsAsTime: { int seconds = 0; if (value != null) { seconds = (int)value; } displayString = ValueFormatting.SecondsAsTime(seconds); } break; default: { displayString = null; if (value != null && !string.IsNullOrEmpty(toStringParameter)) { if (value is float) { displayString = ((float)value).ToString(toStringParameter); } else if (value is int) { displayString = ((int)value).ToString(toStringParameter); } else if (value is Int64) { displayString = ((Int64)value).ToString(toStringParameter); } } if (displayString == null) { if (value != null) { displayString = value.ToString(); } else { displayString = string.Empty; } } } break; } return(displayString); }
private void BuildDisplayMap() { m_displayMapping = new Dictionary <Text, GetDisplayString>(); if (popularityRankDisplay != null) { m_displayMapping.Add(popularityRankDisplay, (s) => ValueFormatting.AbbreviateInteger(s.popularityRankPosition, "0.0")); } if (popularityModCountDisplay != null) { m_displayMapping.Add(popularityModCountDisplay, (s) => ValueFormatting.AbbreviateInteger(s.popularityRankModCount, "0.0")); } if (downloadCountDisplay != null) { m_displayMapping.Add(downloadCountDisplay, (s) => ValueFormatting.AbbreviateInteger(s.downloadCount, "0.0")); } if (subscriberCountDisplay != null) { m_displayMapping.Add(subscriberCountDisplay, (s) => ValueFormatting.AbbreviateInteger(s.subscriberCount, "0.0")); } if (ratingCountDisplay != null) { m_displayMapping.Add(ratingCountDisplay, (s) => ValueFormatting.AbbreviateInteger(s.ratingCount, "0.0")); } if (ratingPositiveCountDisplay != null) { m_displayMapping.Add(ratingPositiveCountDisplay, (s) => ValueFormatting.AbbreviateInteger(s.ratingPositiveCount, "0.0")); } if (ratingPositivePercentageDisplay != null) { m_displayMapping.Add(ratingPositivePercentageDisplay, (s) => (s.ratingCount > 0 ? (100f * (float)s.ratingPositiveCount / (float)s.ratingCount).ToString("0") + "%" : "--")); } if (ratingNegativeCountDisplay != null) { m_displayMapping.Add(ratingNegativeCountDisplay, (s) => ValueFormatting.AbbreviateInteger(s.ratingNegativeCount, "0.0")); } if (ratingNegativePercentageDisplay != null) { m_displayMapping.Add(ratingNegativePercentageDisplay, (s) => (s.ratingCount > 0 ? (100f * (float)s.ratingNegativeCount / (float)s.ratingCount).ToString("0") + "%" : "--")); } if (ratingWeightedAggregateDisplay != null) { m_displayMapping.Add(ratingWeightedAggregateDisplay, (s) => (100f * s.ratingWeightedAggregate).ToString("0") + "%"); } if (ratingAsTextDisplay != null) { m_displayMapping.Add(ratingAsTextDisplay, (s) => s.ratingDisplayText); } }