Razor panel for the in-game field command wheel. Draws the command disc, positions each option around it with trig, shows a hint or failure reason, and executes the chosen FieldCommand through MatchController. Rebuilds only when the game revision, preference revision, or hint changes.
@using Sandbox
@using Sandbox.UI
@using Socer
@using System
@using System.Globalization
@inherits Panel
<root class="field-command-overlay localized-text">
<button class="command-dismiss" onclick=@(()=>Game.CloseCommandWheel())></button>
<div class="field-command-wheel" style="@WheelStyle()">
<div class="command-title"><label>@Game.CommandWheelTitle</label></div>
<div class="command-disc"></div>
<button class="command-close" onclick=@(()=>Game.CloseCommandWheel())><img src="@FieldCommandIcons.Dismiss" /></button>
@{var options=Game.CommandWheelOptions();}
@for(int i=0;i<options.Count;i++)
{
var option=options[i];int slot=i;
<button class="command-option @(option.Reason!=""?"unavailable":"")" style="@OptionStyle(slot)" onclick=@(()=>Choose(option.Kind)) onmouseover=@(()=>Hint=option.Reason) onmouseout=@(()=>Hint="")>
<img class="command-icon" src="@FieldCommandIcons.For(option.Kind)" /><label class="command-label">@option.Name</label>
</button>
}
<label class="command-actor">@Game.CommandWheelActorLabel</label>
<label class="command-hint">@(Hint!=""?Hint:GamePreferences.Russian?"Выберите команду · игра 0,2×":"Choose a command · play at 0.2×")</label>
</div>
</root>
@code {
public MatchController Game {get;set;}
string Hint="";
void Choose(FieldCommand kind){Game.ExecuteFieldCommand(kind);Hint=Game.CommandFailure(kind);StateHasChanged();}
string WheelStyle()
{
var at=Game.CommandWheelAnchor;
string horizontal=at.x<.18f?"left:12px;":at.x>.82f?"right:12px;":FormattableString.Invariant($"left:{at.x*100:0.##}%;margin-left:-128px;");
string vertical=at.y<.28f?"top:112px;":at.y>.72f?"bottom:12px;":FormattableString.Invariant($"top:{at.y*100:0.##}%;margin-top:-145px;");
return horizontal+vertical;
}
static string OptionStyle(int i)=>FormattableString.Invariant($"left:{82+MathF.Sin(i*MathF.Tau/5)*88:0.##}px;top:{126-MathF.Cos(i*MathF.Tau/5)*80:0.##}px;");
protected override int BuildHash()=>HashCode.Combine(Game.Revision,GamePreferences.Revision,Hint);
}