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. 49
      IGP/Pages/BuildCalculator/Parts/OptionsComponent.razor
  4. 2
      Model/BuildOrders/BuildOrderModel.cs
  5. 13
      Model/BuildOrders/TrainingCapacityUsedModel.cs
  6. 1
      Services/IServices.cs
  7. 46
      Services/Immortal/BuildOrderService.cs

6
Components/Form/FormTextComponent.razor

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

34
IGP/Dialog/SearchDialogComponent.razor

@ -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;
}
}

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

@ -14,21 +14,41 @@
<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)
{
buildOrderService.BuildingInputDelay = int.Parse(changeEventArgs.Value!.ToString()!);
@ -46,6 +66,14 @@
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
}
}
public void OnWaitToClicked()
{
if (buildOrderService.AddWait(WaitTime))
{
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
}
}
protected override bool ShouldRender()
{
@ -63,6 +91,5 @@
#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<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 :

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 void Add(EntityModel entity, int atInterval);
public bool AddWait(int forInterval);
public bool AddWaitTo(int interval);
public void SetName(string name);

46
Services/Immortal/BuildOrderService.cs

@ -101,14 +101,15 @@ 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)
{
var requirements = entity.Requirements();
@ -141,7 +142,24 @@ 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);

Loading…
Cancel
Save