Browse Source

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

main
Jonathan McCaffrey 4 years ago
parent
commit
ef1fa7e864
  1. 6
      Components/Form/FormTextComponent.razor
  2. 34
      IGP/Dialog/SearchDialogComponent.razor
  3. 35
      IGP/Pages/BuildCalculator/Parts/OptionsComponent.razor
  4. 2
      Model/BuildOrders/BuildOrderModel.cs
  5. 13
      Model/BuildOrders/TrainingCapacityUsedModel.cs
  6. 1
      Services/IServices.cs
  7. 44
      Services/Immortal/BuildOrderService.cs

6
Components/Form/FormTextComponent.razor

@ -12,6 +12,7 @@
type="text" type="text"
value="@Value" value="@Value"
id="@Id" id="@Id"
@onfocus="OnFocus"
@oninput="OnInput" @oninput="OnInput"
@onchange="OnChange"/> @onchange="OnChange"/>
</div> </div>
@ -66,9 +67,13 @@
[Parameter] [Parameter]
public EventCallback<ChangeEventArgs> OnInput { get; set; } public EventCallback<ChangeEventArgs> OnInput { get; set; }
[Parameter] [Parameter]
public EventCallback<ChangeEventArgs> OnChange { get; set; } public EventCallback<ChangeEventArgs> OnChange { get; set; }
[Parameter]
public EventCallback OnFocus { get; set; }
[Parameter] [Parameter]
public bool ReadOnly { get; set; } public bool ReadOnly { get; set; }
@ -83,4 +88,5 @@
labelId = Label.ToLower().Replace(" ", "_"); labelId = Label.ToLower().Replace(" ", "_");
} }
} }

34
IGP/Dialog/SearchDialogComponent.razor

@ -1,4 +1,5 @@
@implements IDisposable; @using System.Timers
@implements IDisposable;
@inject ISearchService searchService @inject ISearchService searchService
@inject IJSRuntime jsRuntime @inject IJSRuntime jsRuntime
@ -13,7 +14,7 @@
@onclick:stopPropagation="true"> @onclick:stopPropagation="true">
<FormLayoutComponent> <FormLayoutComponent>
<FormTextComponent Id="search-input-box" Placeholder="Search..." OnInput="SearchChanged"></FormTextComponent> <FormTextComponent OnFocus="OnFocus" Id="search-input-box" Placeholder="Search..." OnInput="SearchChanged"></FormTextComponent>
</FormLayoutComponent> </FormLayoutComponent>
<div class="searchBox"> <div class="searchBox">
@ -120,25 +121,33 @@
protected override void OnInitialized() protected override void OnInitialized()
{ {
searchService.Subscribe(OnSearchChanged); searchService.Subscribe(OnSearchChanged);
timer = new Timer(200);
timer.Elapsed += FocusTimer;
timer.Enabled = false;
} }
private System.Threading.Timer timer = null!;
private void OnSearchChanged() private void FocusTimer(object? sender, ElapsedEventArgs e)
{
if (searchService.IsVisible)
{
timer = new System.Threading.Timer(_ =>
{ {
jsRuntime.InvokeVoidAsync("SetFocusToElement", "search-input-box"); jsRuntime.InvokeVoidAsync("SetFocusToElement", "search-input-box");
InvokeAsync(StateHasChanged); StateHasChanged();
}, null, 1, 1); }
private Timer timer = null!;
private void OnSearchChanged()
{
if (timer.Enabled != searchService.IsVisible)
{
timer.Enabled = searchService.IsVisible;
} }
StateHasChanged();
} }
public void Dispose() public void Dispose()
{ {
searchService.Unsubscribe(OnSearchChanged); searchService.Unsubscribe(OnSearchChanged);
timer.Elapsed -= FocusTimer;
} }
@ -171,4 +180,9 @@
searchService.Hide(); searchService.Hide();
} }
private void OnFocus(object obj)
{
timer.Enabled = false;
}
} }

35
IGP/Pages/BuildCalculator/Parts/OptionsComponent.razor

@ -14,20 +14,40 @@
<FormInfoComponent>Add a input delay to constructing buildings for simulating worker movement and player micro.</FormInfoComponent> <FormInfoComponent>Add a input delay to constructing buildings for simulating worker movement and player micro.</FormInfoComponent>
</FormNumberComponent> </FormNumberComponent>
<div class="optionRow">
<FormLayoutComponent>
<FormNumberComponent Max="600" <FormNumberComponent Max="600"
Min="0" Min="0"
Value="@WaitTime" Value="@WaitTime"
OnChange="@OnWaitTimeChanged"> OnChange="@OnWaitTimeChanged">
<FormLabelComponent>Wait Time</FormLabelComponent> <FormLabelComponent>Wait Time</FormLabelComponent>
<FormInfoComponent>Not implemented</FormInfoComponent>
</FormNumberComponent> </FormNumberComponent>
<ButtonComponent OnClick="OnWaitClicked">Add Wait</ButtonComponent> <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> </FormLayoutComponent>
<style>
.optionRow {
display: flex;
gap: 12px;
}
</style>
@code { @code {
public int WaitTime { get; set; } = 30;
public int WaitTo { get; set; } = 30;
void OnBuildingInputDelayChanged(ChangeEventArgs changeEventArgs) 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() protected override bool ShouldRender()
{ {
#if DEBUG #if DEBUG
@ -63,6 +91,5 @@
#endif #endif
} }
public int WaitTime { get; set; } = 30;
} }

2
Model/BuildOrders/BuildOrderModel.cs

@ -29,6 +29,8 @@ public class BuildOrderModel
public Dictionary<string, int> UniqueCompletedCount { get; set; } = new(); public Dictionary<string, int> UniqueCompletedCount { get; set; } = new();
public Dictionary<int, int> SupplyCountTimes { get; set; } = new(); public Dictionary<int, int> SupplyCountTimes { get; set; } = new();
public List<TrainingCapacityUsedModel> TrainingCapacityModels { get; set; } = new();
public void Initialize(string faction) public void Initialize(string faction)
{ {
string factionStartingTownHall = faction.Equals(DataType.FACTION_QRath) ? DataType.STARTING_TownHall_QRath : string factionStartingTownHall = faction.Equals(DataType.FACTION_QRath) ? DataType.STARTING_TownHall_QRath :

13
Model/BuildOrders/TrainingCapacityUsedModel.cs

@ -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
Services/IServices.cs

@ -308,6 +308,7 @@ public interface IBuildOrderService
public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService toastService); public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService toastService);
public void Add(EntityModel entity, int atInterval); public void Add(EntityModel entity, int atInterval);
public bool AddWait(int forInterval); public bool AddWait(int forInterval);
public bool AddWaitTo(int interval);
public void SetName(string name); public void SetName(string name);

44
Services/Immortal/BuildOrderService.cs

@ -101,13 +101,14 @@ public class BuildOrderService : IBuildOrderService
if (!buildOrder.CompletedOrders.ContainsKey(lastInterval)) if (!buildOrder.CompletedOrders.ContainsKey(lastInterval))
buildOrder.CompletedOrders.Add(lastInterval, new List<EntityModel>()); buildOrder.CompletedOrders.Add(lastInterval, new List<EntityModel>());
NotifyDataChanged(); NotifyDataChanged();
return true; return true;
} }
public bool AddWaitTo(int interval)
{
throw new NotImplementedException();
}
public int? WillMeetRequirements(EntityModel entity) public int? WillMeetRequirements(EntityModel entity)
{ {
@ -142,6 +143,23 @@ public class BuildOrderService : IBuildOrderService
return null; 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) public bool Add(EntityModel entity, IEconomyService withEconomy, IToastService withToasts)
{ {
@ -347,6 +365,26 @@ public class BuildOrderService : IBuildOrderService
return true; 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) private bool HandleRequirements(EntityModel entity, IToastService withToasts, ref int atInterval)
{ {
var minRequirementInterval = WillMeetRequirements(entity); var minRequirementInterval = WillMeetRequirements(entity);

Loading…
Cancel
Save