Skip to content
Snippets Groups Projects
Commit c8a0e551 authored by BotyDns's avatar BotyDns
Browse files

Comment TradeViewModel

parent fa49f611
No related branches found
No related tags found
No related merge requests found
Pipeline #30771 canceled
......@@ -7,37 +7,71 @@ using CatanGame.Model;
namespace CatanGame.ViewModel
{
/// <summary>
/// ViewModel representing a trade.
/// </summary>
public class TradeViewModel : ViewModelBase
{
#region Private fields
private GameModel _model;
private ObservableDictionary<string, TradeDataViewModel> _tradeData;
#endregion
#region Public properties
private ObservableDictionary<string, TradeDataViewModel> _tradeData;
/// <summary>
/// Gets or sets the Data related to trading.
/// </summary>
public ObservableDictionary<string, TradeDataViewModel> TradeData { get => _tradeData; set => ChangeProperty(ref _tradeData, value); }
/// <summary>
/// Gets whether a trade is possible.
/// </summary>
public bool CanTrade { get => _model.CanTrade(OfferedResources, RequestedResources); }
/// <summary>
/// Gets whether the player can request anymore resources.
/// </summary>
public bool CanRequest { get => _model.CanRequest(OfferedResources, RequestedResources); }
#endregion
#region Commands
/// <summary>
/// Command for accepting a trade.
/// </summary>
public DelegateCommand AcceptTradeCommand { get; private set; }
/// <summary>
/// Command for clearing the trade.
/// </summary>
public DelegateCommand ClearTradeCommand { get; private set; }
/// <summary>
/// Command for canceling a trade.
/// </summary>
public DelegateCommand CancelCommand { get; private set; }
#endregion
#region Public events
/// <summary>
/// Event: Gets invoked when a trade is accepted.
/// </summary>
public event EventHandler<TradeAcceptedEventArgs> TradeAccepted;
/// <summary>
/// Event: Gets invoked when a trade is canceled.
/// </summary>
public event EventHandler Cancel;
#endregion
#region Private properties
/// <summary>
/// Gets the resources offered by the player.
/// </summary>
private List<(ResourceType, int)> OfferedResources
{
get => _tradeData.Dict.Select(data => ((ResourceType)Enum.Parse(typeof(ResourceType), data.Key), data.Value.OfferedCnt)).ToList();
}
}
/// <summary>
/// Gets the resources requested by the player.
/// </summary>
private List<(ResourceType, int)> RequestedResources
{
get => _tradeData.Dict.Select(data => ((ResourceType)Enum.Parse(typeof(ResourceType), data.Key), data.Value.RequestedCnt)).ToList();
......@@ -63,6 +97,10 @@ namespace CatanGame.ViewModel
#endregion
#region Public methods
/// <summary>
/// Updates this viewmodel with the data from the given player.
/// </summary>
/// <param name="player">The player who wants to make a trade.</param>
public void Update(PlayerViewModel player)
{
TradeData.Dict.Clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment