Skip to content

Commit

Permalink
Add session capacity highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Apr 8, 2024
1 parent fdbd2c9 commit 1e77ab5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions FlexibleContactsSort/ContactsSortingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ internal sealed class ContactsSortingConfig : ConfigSection
private readonly DefiningConfigKey<int> _readMessageCooldownKey = new("ReadMessageCooldown", "Delay in seconds before a contact with freshly-read messages is counted as such. Set 0 to disable.", () => 120);

public int AlphabeticPriority => _alphabeticPriorityKey.GetValue();
public override string Description { get; } = "Contains options for how to sort the Contacts list.";
public override string Description => "Contains options for how to sort the Contacts list.";
public int HeadlessPriority => _headlessPriorityKey.GetValue();
public override string Id { get; } = "ContactsSorting";
public override string Id => "ContactsSorting";
public int IncomingContactRequestPriority => _incomingContactRequestPriorityKey.GetValue();
public int JoinablePriority => _joinablePriorityKey.GetValue();
public int OnlineStatusPriority => _onlineStatusPriorityKey.GetValue();
Expand Down
26 changes: 26 additions & 0 deletions FlexibleContactsSort/SessionCapacityConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Elements.Core;
using FrooxEngine;
using MonkeyLoader.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlexibleContactsSort
{
internal sealed class SessionCapacityConfig : ConfigSection
{
private readonly DefiningConfigKey<colorX> _emptySessionColorKey = new("EmptySessionColor", "Color of the user count when only the host is there.", () => RadiantUI_Constants.Hero.GREEN);
private readonly DefiningConfigKey<colorX> _fullSessionColorKey = new("FullSessionColor", "Color of the user count when the session is full.", () => RadiantUI_Constants.Hero.RED);
private readonly DefiningConfigKey<bool> _showUsageLevelWithColorGradientKey = new("ShowUsageLevelWithColorGradient", "Color the user count based on capacity usage.", () => true);
private readonly DefiningConfigKey<bool> _showUserCapacityInSessionListKey = new("ShowUserCapacityInSessionList", "Show the user capacity of contacts' joinable sessions.", () => true);
public override string Description => "Contains options for how to highlight contacts' session capacity.";
public colorX EmptySessionColor => _emptySessionColorKey.GetValue();
public colorX FullSessionColor => _fullSessionColorKey.GetValue();
public override string Id => "SessionCapacity";
public bool ShowUsageLevelWithColorGradient => _showUsageLevelWithColorGradientKey.GetValue();
public bool ShowUserCapacityInSessionList => _showUserCapacityInSessionListKey.GetValue();
public override Version Version { get; } = new(1, 0, 0);
}
}
45 changes: 45 additions & 0 deletions FlexibleContactsSort/SessionUserCapacity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Elements.Core;
using FrooxEngine;
using HarmonyLib;
using MonkeyLoader.Patching;
using MonkeyLoader.Resonite;
using SkyFrost.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlexibleContactsSort
{
[HarmonyPatchCategory(nameof(SessionUserCapacity))]
[HarmonyPatch(typeof(SessionItem), nameof(SessionItem.Update))]
internal sealed class SessionUserCapacity : ConfiguredResoniteMonkey<SessionUserCapacity, SessionCapacityConfig>
{
protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();

private static void Postfix(SessionItem __instance, SessionInfo session)
{
var format = "{0} ({1})";

if (ConfigSection.ShowUserCapacityInSessionList)
format += " / {2}";

if (ConfigSection.ShowUsageLevelWithColorGradient)
{
var usage = (float)session.JoinedUsers / session.MaximumUsers;

var value = usage > 1 || !usage.IsValid() ?
new ColorHSV(ConfigSection.FullSessionColor).v - .2f
: MathX.Lerp(new ColorHSV(ConfigSection.EmptySessionColor).v, new ColorHSV(ConfigSection.FullSessionColor).v, usage);

var color = MathX.Lerp(ConfigSection.EmptySessionColor, ConfigSection.FullSessionColor, usage).SetValue(value);

format = $"<color={color.ToHexString()}>{format}</color>";
}

format = "Users: " + format;
__instance._userCount.Target.Content.Value = string.Format(format, session.ActiveUsers, session.JoinedUsers, session.MaximumUsers);
}
}
}

0 comments on commit 1e77ab5

Please sign in to comment.