fix(Search) Fixed search auto focus, plus some WIP code

This commit is contained in:
2022-04-18 21:55:14 -04:00
parent fb70b788bc
commit ef1fa7e864
7 changed files with 127 additions and 26 deletions
+6
View File
@@ -12,6 +12,7 @@
type="text"
value="@Value"
id="@Id"
@onfocus="OnFocus"
@oninput="OnInput"
@onchange="OnChange"/>
</div>
@@ -66,9 +67,13 @@
[Parameter]
public EventCallback<ChangeEventArgs> OnInput { get; set; }
[Parameter]
public EventCallback<ChangeEventArgs> OnChange { get; set; }
[Parameter]
public EventCallback OnFocus { get; set; }
[Parameter]
public bool ReadOnly { get; set; }
@@ -83,4 +88,5 @@
labelId = Label.ToLower().Replace(" ", "_");
}
}
+24 -10
View File
@@ -1,4 +1,5 @@
@implements IDisposable;
@using System.Timers
@implements IDisposable;
@inject ISearchService searchService
@inject IJSRuntime jsRuntime
@@ -13,7 +14,7 @@
@onclick:stopPropagation="true">
<FormLayoutComponent>
<FormTextComponent Id="search-input-box" Placeholder="Search..." OnInput="SearchChanged"></FormTextComponent>
<FormTextComponent OnFocus="OnFocus" Id="search-input-box" Placeholder="Search..." OnInput="SearchChanged"></FormTextComponent>
</FormLayoutComponent>
<div class="searchBox">
@@ -120,25 +121,33 @@
protected override void OnInitialized()
{
searchService.Subscribe(OnSearchChanged);
timer = new Timer(200);
timer.Elapsed += FocusTimer;
timer.Enabled = false;
}
private System.Threading.Timer timer = null!;
private void FocusTimer(object? sender, ElapsedEventArgs e)
{
jsRuntime.InvokeVoidAsync("SetFocusToElement", "search-input-box");
StateHasChanged();
}
private Timer timer = null!;
private void OnSearchChanged()
{
if (searchService.IsVisible)
if (timer.Enabled != searchService.IsVisible)
{
timer = new System.Threading.Timer(_ =>
{
jsRuntime.InvokeVoidAsync("SetFocusToElement", "search-input-box");
InvokeAsync(StateHasChanged);
}, null, 1, 1);
timer.Enabled = searchService.IsVisible;
}
StateHasChanged();
}
public void Dispose()
{
searchService.Unsubscribe(OnSearchChanged);
timer.Elapsed -= FocusTimer;
}
@@ -171,4 +180,9 @@
searchService.Hide();
}
private void OnFocus(object obj)
{
timer.Enabled = false;
}
}
@@ -14,20 +14,40 @@
<FormInfoComponent>Add a input delay to constructing buildings for simulating worker movement and player micro.</FormInfoComponent>
</FormNumberComponent>
<FormNumberComponent Max="600"
Min="0"
Value="@WaitTime"
OnChange="@OnWaitTimeChanged">
<FormLabelComponent>Wait Time</FormLabelComponent>
<FormInfoComponent>Not implemented</FormInfoComponent>
</FormNumberComponent>
<ButtonComponent OnClick="OnWaitClicked">Add Wait</ButtonComponent>
<div class="optionRow">
<FormLayoutComponent>
<FormNumberComponent Max="600"
Min="0"
Value="@WaitTime"
OnChange="@OnWaitTimeChanged">
<FormLabelComponent>Wait Time</FormLabelComponent>
</FormNumberComponent>
<ButtonComponent OnClick="OnWaitClicked">Add Wait</ButtonComponent>
</FormLayoutComponent>
<FormLayoutComponent>
<FormNumberComponent Max="600"
Min="0"
Value="@WaitTime"
OnChange="@OnWaitTimeChanged">
<FormLabelComponent>Wait To</FormLabelComponent>
</FormNumberComponent>
<ButtonComponent OnClick="OnWaitClicked">Add Wait</ButtonComponent>
</FormLayoutComponent>
</div>
</FormLayoutComponent>
<style>
.optionRow {
display: flex;
gap: 12px;
}
</style>
@code {
public int WaitTime { get; set; } = 30;
public int WaitTo { get; set; } = 30;
void OnBuildingInputDelayChanged(ChangeEventArgs changeEventArgs)
{
@@ -47,6 +67,14 @@
}
}
public void OnWaitToClicked()
{
if (buildOrderService.AddWait(WaitTime))
{
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
}
}
protected override bool ShouldRender()
{
#if DEBUG
@@ -63,6 +91,5 @@
#endif
}
public int WaitTime { get; set; } = 30;
}
+2
View File
@@ -29,6 +29,8 @@ public class BuildOrderModel
public Dictionary<string, int> UniqueCompletedCount { get; set; } = new();
public Dictionary<int, int> SupplyCountTimes { get; set; } = new();
public List<TrainingCapacityUsedModel> TrainingCapacityModels { get; set; } = new();
public void Initialize(string faction)
{
string factionStartingTownHall = faction.Equals(DataType.FACTION_QRath) ? DataType.STARTING_TownHall_QRath :
@@ -0,0 +1,13 @@
using Model.Entity.Data;
namespace Model.BuildOrders;
public class TrainingCapacityUsedModel
{
public int TrainingCapacity { get; set; } = 4;
public string UsedBuilding { get; set; } = DataType.BUILDING_LegionHall;
public int StartingUsageTime { get; set; } = 30;
public int StopUsageTime { get; set; } = 60;
}
+1
View File
@@ -308,6 +308,7 @@ public interface IBuildOrderService
public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService toastService);
public void Add(EntityModel entity, int atInterval);
public bool AddWait(int forInterval);
public bool AddWaitTo(int interval);
public void SetName(string name);
+41 -3
View File
@@ -101,13 +101,14 @@ public class BuildOrderService : IBuildOrderService
if (!buildOrder.CompletedOrders.ContainsKey(lastInterval))
buildOrder.CompletedOrders.Add(lastInterval, new List<EntityModel>());
NotifyDataChanged();
return true;
}
public bool AddWaitTo(int interval)
{
throw new NotImplementedException();
}
public int? WillMeetRequirements(EntityModel entity)
{
@@ -142,6 +143,23 @@ public class BuildOrderService : IBuildOrderService
return null;
}
public int? WillMeetTrainingQueue(EntityModel entity)
{
var supply = entity.Supply();
if (supply == null || supply.Takes.Equals(0)) return 0;
// TODO: Finish Training Queue Logic
foreach (var supplyAtTime in buildOrder.SupplyCountTimes)
if (supply.Takes + buildOrder.CurrentSupplyUsed < supplyAtTime.Key)
return supplyAtTime.Value;
return null;
}
public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService withToasts)
{
@@ -347,6 +365,26 @@ public class BuildOrderService : IBuildOrderService
return true;
}
private bool HandleTrainingQueue(EntityModel entity, IToastService withToasts, ref int atInterval)
{
var minSupplyInterval = WillMeetSupply(entity);
if (minSupplyInterval == null)
{
withToasts.AddToast(new ToastModel
{
Title = "Supply Cap Reached", Message = "Build more supply!",
SeverityType = SeverityType.Error
});
return false;
}
if (minSupplyInterval > atInterval) atInterval = (int)minSupplyInterval;
return true;
}
private bool HandleRequirements(EntityModel entity, IToastService withToasts, ref int atInterval)
{
var minRequirementInterval = WillMeetRequirements(entity);