Window for Working with a Group of Elements and Their Quantity
In API version V7Preview6, a new window was added for the convenience of working with the quantity of a certain group of elements
IViewManager.ShowQuantityChangerPopup.
The method takes
string title— the title of the window,string text— the description text,int minimalQuantity— the overall minimum possible quantity for the group,int maximalQuantity— the overall maximum possible quantity for the group,IReadOnlyCollection<(string name, int quantity, int minimalQuantity, int maximalQuantity)> items— the list of elements.
Each element is
string name— its name,int quantity— the current quantity of the element,int minimalQuantity— the minimum possible quantity of the element,int maximalQuantity— the maximum possible quantity of the element.
As a result, the method returns a list IReadOnlyCollection<int>, which contains the quantity of each element in the order corresponding to the order in the input argument items.
The + and - buttons allow you to increase or decrease the quantity of the element by one.
The central area of the element with its name is also clickable and allows you to open a numeric popup for extended editing of the quantity of the selected element.
To the right of the name, the current quantity of the element is indicated.
In cases where the minimum possible quantity of each element is zero, the maximum possible quantity of each element is equal to the maximum possible quantity for the group, the current quantity of one of the elements is equal to the maximum possible quantity for the group, and the current quantity of the other elements is zero, clicking on the central area of the other elements does not open the numeric popup, but completely transfers the quantity of the previously selected element to the current element.
Example
private static void ShowListWithQuantitiesPopup(IViewManager viewManager)
{
const string title = "Santa's gift";
const string hintText = "Choose sweets";
var list = new List<(string name, int quantity, int minimalQuantity, int maximalQuantity)>
{
("Chocolate", 0, 0, 3),
("Tangerines", 0, 0, 3),
("Candies", 0, 0, 3),
("Waffles", 0, 0, 3),
("Biscuits", 0, 0, 3),
("Marshmallow", 0, 0, 3),
("Meringue", 0, 0, 3),
};
var inputResult = viewManager.ShowQuantityChangerPopup(title, hintText, 3, 3, list);
ShowNotification(inputResult == null
? "Nothing"
: $"Selected : {string.Join(", ", inputResult.Zip(list, (quantity, item) => (name: item.name, quantity: quantity)).Where(i => i.quantity != 0).Select(i => $"{i.quantity} × {i.name}"))}",
TimeSpan.FromSeconds(10));
}