-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |