You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
using ConsoleApp;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace ConsoleApp.Menu
|
|
{
|
|
/// <summary>
|
|
/// An abstract class that define the components of a selection-type menu.
|
|
/// </summary>
|
|
/// <typeparam name="T">The return type of the currently selected item</typeparam>
|
|
public abstract class SelectMenu<T> : IMenuDisplay
|
|
{
|
|
protected int _currentLine = 0;
|
|
protected int _maxLines = 0;
|
|
|
|
/// <summary>
|
|
/// The currently selected item.
|
|
/// </summary>
|
|
public T? CurrentSelected { get; protected set; }
|
|
|
|
/// <summary>
|
|
/// The current line selected in the menu.
|
|
/// </summary>
|
|
public int CurrentLine
|
|
{
|
|
get => _currentLine;
|
|
protected set
|
|
{
|
|
_currentLine = value;
|
|
if (_currentLine > _maxLines)
|
|
{
|
|
_currentLine = _maxLines;
|
|
}
|
|
if (_currentLine < 0)
|
|
{
|
|
_currentLine = 0;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
public int SelectNextLine() { return ++CurrentLine; }
|
|
public int SelectPrevioustLine() { return --CurrentLine; }
|
|
|
|
public abstract void UpdateDisplay();
|
|
}
|
|
}
|