Search box for vending machine ui. (#822)
This commit is contained in:
@@ -15,6 +15,7 @@ namespace Content.Client.VendingMachines
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private List<int> _cachedFilteredIndex = new();
|
private List<int> _cachedFilteredIndex = new();
|
||||||
|
|
||||||
|
private VendingMachineComponent component = new(); // WD edit
|
||||||
public VendingMachineBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
public VendingMachineBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -26,7 +27,7 @@ namespace Content.Client.VendingMachines
|
|||||||
var vendingMachineSys = EntMan.System<VendingMachineSystem>();
|
var vendingMachineSys = EntMan.System<VendingMachineSystem>();
|
||||||
|
|
||||||
// WD EDIT START
|
// WD EDIT START
|
||||||
var component = EntMan.GetComponent<VendingMachineComponent>(Owner);
|
component = EntMan.GetComponent<VendingMachineComponent>(Owner);
|
||||||
_cachedInventory = vendingMachineSys.GetAllInventory(Owner, component);
|
_cachedInventory = vendingMachineSys.GetAllInventory(Owner, component);
|
||||||
|
|
||||||
_menu = new VendingMenu { Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName };
|
_menu = new VendingMenu { Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName };
|
||||||
@@ -34,6 +35,7 @@ namespace Content.Client.VendingMachines
|
|||||||
_menu.OnClose += Close;
|
_menu.OnClose += Close;
|
||||||
_menu.OnItemSelected += OnItemSelected;
|
_menu.OnItemSelected += OnItemSelected;
|
||||||
_menu.OnWithdraw += SendMessage;
|
_menu.OnWithdraw += SendMessage;
|
||||||
|
_menu.SearchBar.OnTextChanged += UpdateFilter;
|
||||||
// WD EDIT END
|
// WD EDIT END
|
||||||
|
|
||||||
_menu.Populate(_cachedInventory, component.PriceMultiplier, component.Credits);
|
_menu.Populate(_cachedInventory, component.PriceMultiplier, component.Credits);
|
||||||
@@ -41,6 +43,17 @@ namespace Content.Client.VendingMachines
|
|||||||
_menu.OpenCenteredLeft();
|
_menu.OpenCenteredLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WD EDIT START
|
||||||
|
private void UpdateFilter(Robust.Client.UserInterface.Controls.LineEdit.LineEditEventArgs obj)
|
||||||
|
{
|
||||||
|
if (_menu != null)
|
||||||
|
{
|
||||||
|
_menu.filter = obj.Text;
|
||||||
|
_menu.Populate(_cachedInventory, component.PriceMultiplier, component.Credits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// WD EDIT END
|
||||||
|
|
||||||
protected override void UpdateState(BoundUserInterfaceState state)
|
protected override void UpdateState(BoundUserInterfaceState state)
|
||||||
{
|
{
|
||||||
base.UpdateState(state);
|
base.UpdateState(state);
|
||||||
@@ -84,7 +97,7 @@ namespace Content.Client.VendingMachines
|
|||||||
|
|
||||||
private void OnSearchChanged(string? filter)
|
private void OnSearchChanged(string? filter)
|
||||||
{
|
{
|
||||||
//_menu?.Populate(_cachedInventory, out _cachedFilteredIndex, filter);
|
//_menu?.filter = (filter ?? "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<DefaultWindow xmlns="https://spacestation14.io">
|
<DefaultWindow xmlns="https://spacestation14.io"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||||
|
xmlns:style="clr-namespace:Content.Client.Stylesheets">
|
||||||
<BoxContainer Orientation="Vertical">
|
<BoxContainer Orientation="Vertical">
|
||||||
<BoxContainer Orientation="Horizontal">
|
<BoxContainer Orientation="Horizontal">
|
||||||
<Label Name="CreditsLabel" HorizontalExpand="True"/>
|
<Label Name="CreditsLabel" HorizontalExpand="True"/>
|
||||||
@@ -7,6 +10,9 @@
|
|||||||
Text="{Loc 'store-ui-default-withdraw-text'}"
|
Text="{Loc 'store-ui-default-withdraw-text'}"
|
||||||
HorizontalAlignment="Right"/>
|
HorizontalAlignment="Right"/>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
|
<BoxContainer Orientation="Horizontal">
|
||||||
|
<LineEdit Name="SearchBar" PlaceHolder="{Loc 'vending-machine-component-search-filter'}" HorizontalExpand="True" Margin ="4 4" Access="Public"/>
|
||||||
|
</BoxContainer>
|
||||||
<PanelContainer StyleClasses="HighDivider" />
|
<PanelContainer StyleClasses="HighDivider" />
|
||||||
<Label
|
<Label
|
||||||
Name="OutOfStockLabel"
|
Name="OutOfStockLabel"
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ public sealed partial class VendingMenu : DefaultWindow
|
|||||||
|
|
||||||
public event Action<int>? OnItemSelected;
|
public event Action<int>? OnItemSelected;
|
||||||
public Action<VendingMachineWithdrawMessage>? OnWithdraw;
|
public Action<VendingMachineWithdrawMessage>? OnWithdraw;
|
||||||
|
public string filter = "";
|
||||||
public VendingMenu()
|
public VendingMenu()
|
||||||
{
|
{
|
||||||
MinSize = SetSize = new Vector2(250, 150);
|
MinSize = SetSize = new Vector2(250, 150);
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
// SearchBar.OnTextChanged += UpdateFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -38,7 +39,7 @@ public sealed partial class VendingMenu : DefaultWindow
|
|||||||
return;
|
return;
|
||||||
OnWithdraw?.Invoke(new VendingMachineWithdrawMessage());
|
OnWithdraw?.Invoke(new VendingMachineWithdrawMessage());
|
||||||
};
|
};
|
||||||
|
|
||||||
VendingContents.RemoveAllChildren();
|
VendingContents.RemoveAllChildren();
|
||||||
if (inventory.Count == 0)
|
if (inventory.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -67,13 +68,15 @@ public sealed partial class VendingMenu : DefaultWindow
|
|||||||
if (itemName.Length > longestEntry.Length)
|
if (itemName.Length > longestEntry.Length)
|
||||||
longestEntry = itemName;
|
longestEntry = itemName;
|
||||||
|
|
||||||
var price = (int)(entry.Price * priceMultiplier);
|
var price = (int) (entry.Price * priceMultiplier);
|
||||||
var vendingItem = new VendingItem($"{itemName} [{entry.Amount}]", price > 0 ? $"{price} \u00a2" : "выдать", icon);
|
var vendingItem = new VendingItem($"{itemName} [{entry.Amount}]", price > 0 ? $"{price} \u00a2" : "выдать", icon);
|
||||||
|
|
||||||
var j = i;
|
var j = i;
|
||||||
vendingItem.VendingItemBuyButton.OnPressed += _ => { OnItemSelected?.Invoke(j); };
|
vendingItem.VendingItemBuyButton.OnPressed += _ => { OnItemSelected?.Invoke(j); };
|
||||||
|
|
||||||
VendingContents.AddChild(vendingItem);
|
|
||||||
|
if (filter == "" || (prototype?.Name?.Contains(filter) == true))
|
||||||
|
VendingContents.AddChild(vendingItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSizeAfterUpdate(longestEntry.Length);
|
SetSizeAfterUpdate(longestEntry.Length);
|
||||||
@@ -84,4 +87,4 @@ public sealed partial class VendingMenu : DefaultWindow
|
|||||||
SetSize = new Vector2(Math.Clamp((longestEntryLength + 10) * 12, 250, 700),
|
SetSize = new Vector2(Math.Clamp((longestEntryLength + 10) * 12, 250, 700),
|
||||||
Math.Clamp(VendingContents.ChildCount * 50, 150, 400));
|
Math.Clamp(VendingContents.ChildCount * 50, 150, 400));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
vending-machine-component-try-eject-invalid-item = Несуществующий предмет
|
vending-machine-component-try-eject-invalid-item = Несуществующий предмет
|
||||||
vending-machine-component-try-eject-out-of-stock = Нет в наличии
|
vending-machine-component-try-eject-out-of-stock = Нет в наличии
|
||||||
vending-machine-component-try-eject-access-denied = Доступ запрещён
|
vending-machine-component-try-eject-access-denied = Доступ запрещён
|
||||||
|
vending-machine-component-search-filter = Поиск...
|
||||||
vending-machine-action-name = Выдать предмет
|
vending-machine-action-name = Выдать предмет
|
||||||
vending-machine-action-description = Выдаёт случайный предмет из вашего инвентаря.
|
vending-machine-action-description = Выдаёт случайный предмет из вашего инвентаря.
|
||||||
vending-machine-insert-fromStorage-success = Перемещено предметов: { $count }
|
vending-machine-insert-fromStorage-success = Перемещено предметов: { $count }
|
||||||
|
|||||||
Reference in New Issue
Block a user