-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from esnya/refactor/ui-improvement
feat: 💄 Improve UI
- Loading branch information
Showing
13 changed files
with
529 additions
and
360 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using FrooxEngine; | ||
using FrooxEngine; | ||
using FrooxEngine.ProtoFlux; | ||
using HarmonyLib; | ||
using ResoniteModLoader; | ||
|
This file was deleted.
Oops, something went wrong.
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,83 @@ | ||
using Elements.Core; | ||
using FrooxEngine; | ||
using FrooxEngine.UIX; | ||
using ResoniteMetricsCounter.Utils; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace ResoniteMetricsCounter.UIX.Item; | ||
|
||
|
||
internal abstract class MetricPageItemBase<T> | ||
{ | ||
|
||
private readonly Slot slot; | ||
private readonly Sync<colorX> metricTint; | ||
private readonly ReferenceProxySource referenceProxySource; | ||
private readonly RectTransform metricRect; | ||
|
||
protected readonly List<Sync<string>> LabelFields = new(); | ||
|
||
public MetricPageItemBase(Slot container, List<MetricColumnDefinition> columns) | ||
{ | ||
var uiBuilder = new UIBuilder(container); | ||
|
||
uiBuilder.Style.MinHeight = Constants.ROWHEIGHT; | ||
slot = uiBuilder.Panel(RadiantUI_Constants.Neutrals.DARK).Slot; | ||
|
||
slot.AttachComponent<Button>(); | ||
referenceProxySource = slot.AttachComponent<ReferenceProxySource>(); | ||
|
||
var metricImage = uiBuilder.Image(); | ||
metricRect = metricImage.RectTransform; | ||
metricTint = metricImage.Tint; | ||
|
||
LabelFields.Capacity = columns.Count; | ||
foreach (var label in MetricColumnDefinition.Build(uiBuilder, columns)) | ||
{ | ||
LabelFields.Add(label.Content); | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected abstract long GetTicks(in T metric); | ||
|
||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected abstract IWorldElement? GetReference(in T metric); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected abstract void UpdateColumn(in T metric, Sync<string> column, int i, long maxTicks, long elapsedTicks, long frameCount); | ||
|
||
public bool Update(in T metric, long maxTicks, long elapsedTicks, long frameCount) | ||
{ | ||
if (slot.IsDisposed) | ||
{ | ||
return false; | ||
} | ||
|
||
var ticks = GetTicks(metric); | ||
var maxRatio = (float)ticks / maxTicks; | ||
slot.OrderOffset = -ticks; | ||
|
||
for (int i = 0; i < LabelFields.Count; i++) | ||
{ | ||
UpdateColumn(metric, LabelFields[i], i, maxTicks, elapsedTicks, frameCount); | ||
} | ||
|
||
metricTint.Value = MathX.Lerp(RadiantUI_Constants.DarkLight.GREEN, RadiantUI_Constants.DarkLight.RED, MathX.Sqrt(maxRatio)); | ||
metricRect.AnchorMax.Value = new float2(maxRatio, 1.0f); | ||
|
||
var reference = GetReference(metric); | ||
if (reference is null || reference.IsRemoved) | ||
{ | ||
referenceProxySource.Enabled = false; | ||
} | ||
else | ||
{ | ||
referenceProxySource.Reference.Target = reference; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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,51 @@ | ||
using Elements.Core; | ||
using FrooxEngine; | ||
using FrooxEngine.UIX; | ||
using ResoniteMetricsCounter.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ResoniteMetricsCounter.UIX; | ||
internal struct MetricColumnDefinition | ||
{ | ||
public string Label; | ||
public float FlexWidth; | ||
public float MinWidth; | ||
public Alignment Alignment; | ||
|
||
public MetricColumnDefinition(string label, Alignment alignment = Alignment.MiddleLeft, float flexWidth = -1, float minWidth = -1) | ||
{ | ||
Label = label; | ||
FlexWidth = flexWidth; | ||
MinWidth = minWidth; | ||
Alignment = alignment; | ||
} | ||
|
||
public static IEnumerable<Text> Build(UIBuilder uiBuilder, IEnumerable<MetricColumnDefinition> columns, Action<HorizontalLayout>? containerModifier = null) | ||
{ | ||
uiBuilder.PushStyle(); | ||
|
||
uiBuilder.Style.MinHeight = Constants.ROWHEIGHT; | ||
uiBuilder.Style.TextColor = RadiantUI_Constants.TEXT_COLOR; | ||
uiBuilder.Style.TextAlignment = Alignment.MiddleCenter; | ||
uiBuilder.Style.ForceExpandWidth = false; | ||
|
||
var horizontalLayout = uiBuilder.HorizontalLayout(Constants.SPACING, Constants.PADDING); | ||
if (containerModifier != null) | ||
{ | ||
containerModifier(horizontalLayout); | ||
} | ||
|
||
foreach (var column in columns) | ||
{ | ||
uiBuilder.Style.FlexibleWidth = column.FlexWidth; | ||
uiBuilder.Style.MinWidth = column.MinWidth; | ||
uiBuilder.Panel(); | ||
yield return uiBuilder.Text(column.Label); | ||
uiBuilder.NestOut(); | ||
} | ||
uiBuilder.NestOut(); | ||
|
||
uiBuilder.PopStyle(); | ||
} | ||
} |
Oops, something went wrong.