Skip to content

Commit

Permalink
Enhance text content display
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Jan 16, 2024
1 parent 1390162 commit 3e71abb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
25 changes: 20 additions & 5 deletions src/SICore/SICore/Clients/Viewer/ViewerHumanLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ private record struct ContentInfo(string Type, string Uri);
/// </summary>
private const int MaxAdditionalTableTextLength = 150;

/// <summary>
/// Minimum weight for the small content.
/// </summary>
private const double SmallContentWeight = 1.0;

/// <summary>
/// Maximum weight for the large content.
/// </summary>
private const double LargeContentWeight = 5.0;

/// <summary>
/// Length of text having weight of 1.
/// </summary>
private const int TextLengthWithBasicWeight = 80;

private static readonly TimeSpan HintLifetime = TimeSpan.FromSeconds(6);

private bool _disposed = false;
Expand Down Expand Up @@ -819,16 +834,16 @@ private void OnScreenContent(IEnumerable<ContentInfo> contentInfo)
currentGroup = null;
}

var text = contentValue.UnescapeNewLines();
var group = new ContentGroup();
group.Content.Add(new ContentViewModel(ContentType.Text, text.ToString().Shorten(_data.Host.MaximumTableTextLength, "…"), groups.Count == 0 ? TInfo.TextSpeed : 0.0));
var text = contentValue.UnescapeNewLines().Shorten(_data.Host.MaximumTableTextLength, "…");
var group = new ContentGroup { Weight = Math.Max(SmallContentWeight, Math.Min(LargeContentWeight, (double)text.Length / TextLengthWithBasicWeight)) };
group.Content.Add(new ContentViewModel(ContentType.Text, text, groups.Count == 0 ? TInfo.TextSpeed : 0.0));
groups.Add(group);
break;

case ContentTypes.Video:
case ContentTypes.Image:
case ContentTypes.Html:
currentGroup ??= new ContentGroup { Weight = 4.0 };
currentGroup ??= new ContentGroup { Weight = LargeContentWeight };

var uri = contentValue;

Expand All @@ -850,13 +865,13 @@ private void OnScreenContent(IEnumerable<ContentInfo> contentInfo)
}

uri = _localFileManager.TryGetFile(mediaUri) ?? uri;
Data.Host.Log($"Media uri conversion: {mediaUri} => {uri}");

var tableContentType = contentType == ContentTypes.Image
? ContentType.Image
: (contentType == ContentTypes.Video ? ContentType.Video : ContentType.Html);

currentGroup.Content.Add(new ContentViewModel(tableContentType, uri));
OnSpecialReplic($"Media uri: \"{uri}\"");
break;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/SICore/SICore/Contracts/IGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ public interface IGameHost : IPlatformManager
/// </summary>
string? GetAd(string localization, out int adId);

/// <summary>
/// Logs a message.
/// </summary>
/// <param name="message">Message to log.</param>
void Log(string message);

void LogWarning(string message);
}
2 changes: 2 additions & 0 deletions src/SICore/SICore/GameHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public Stream CreateLog(string userName, out string logUri)

public abstract void OnGameFinished(string packageId);

public abstract void Log(string message);

public abstract void LogWarning(string message);

public abstract bool AreAnswersShown { get; set; }
Expand Down
14 changes: 11 additions & 3 deletions src/SIGame/SIGame.ViewModel/ViewModel/Data/BackLink.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Notions;
using SICore;
using SICore.Models;
Expand All @@ -10,7 +11,6 @@
using SIStatisticsService.Contract;
using SIStatisticsService.Contract.Models;
using SIUI.ViewModel;
using System.Diagnostics;

namespace SIGame.ViewModel;

Expand All @@ -25,13 +25,19 @@ public sealed class BackLink : GameHostBase
private readonly AppState _appState;

private readonly IServiceProvider _serviceProvider;
private readonly ILogger<BackLink> _logger;

internal BackLink(AppSettingsViewModel settings, UserSettings userSettings, AppState appState, IServiceProvider serviceProvider)
internal BackLink(
AppSettingsViewModel settings,
UserSettings userSettings,
AppState appState,
IServiceProvider serviceProvider)
{
_settings = settings;
_userSettings = userSettings;
_appState = appState;
_serviceProvider = serviceProvider;
_logger = serviceProvider.GetRequiredService<ILogger<BackLink>>();
}

public override void OnFlash(bool flash = true) => PlatformSpecific.PlatformManager.Instance.Activate();
Expand All @@ -54,7 +60,9 @@ internal BackLink(AppSettingsViewModel settings, UserSettings userSettings, AppS

public override void OnError(Exception exc) => PlatformSpecific.PlatformManager.Instance.ShowMessage(exc.ToString(), PlatformSpecific.MessageType.Error, true);

public override void LogWarning(string message) => Trace.TraceWarning(message);
public override void Log(string message) => _logger.LogInformation("Game info: {message}", message);

public override void LogWarning(string message) => _logger.LogWarning("Game warning: {warning}", message);

public override void SendError(Exception exc, bool isWarning = false) => PlatformSpecific.PlatformManager.Instance.SendErrorReport(exc);

Expand Down

0 comments on commit 3e71abb

Please sign in to comment.