2019-05-27 16:23:14 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.ObjectModel;
|
2019-07-05 18:17:09 +00:00
|
|
|
using Aurora.Executors;
|
2019-07-06 19:52:28 +00:00
|
|
|
using Aurora.Proto;
|
2019-06-26 01:17:52 +00:00
|
|
|
using Xamarin.Forms;
|
2019-05-27 16:23:14 +00:00
|
|
|
|
2019-07-05 18:17:09 +00:00
|
|
|
namespace Aurora.Design.Views.Party
|
2019-05-27 16:23:14 +00:00
|
|
|
{
|
2019-06-26 01:17:52 +00:00
|
|
|
enum PartyState
|
|
|
|
{
|
|
|
|
SelectingHost,
|
|
|
|
InParty,
|
|
|
|
Connecting,
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:23:14 +00:00
|
|
|
public class PartyViewModel : BaseViewModel
|
|
|
|
{
|
2019-06-26 01:17:52 +00:00
|
|
|
private PartyState _state;
|
|
|
|
|
2019-07-05 15:37:44 +00:00
|
|
|
private BaseExecutor _executor;
|
2019-06-26 01:17:52 +00:00
|
|
|
|
|
|
|
private string _hostname;
|
|
|
|
|
2019-07-05 21:37:10 +00:00
|
|
|
private ObservableCollection<PartyMember> _members;
|
|
|
|
|
2019-06-26 01:17:52 +00:00
|
|
|
|
2019-05-27 16:23:14 +00:00
|
|
|
public PartyViewModel()
|
|
|
|
{
|
2019-06-26 01:17:52 +00:00
|
|
|
this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute);
|
|
|
|
this.HostCommand = new Command(OnHostExecute, CanHostExecute);
|
2019-07-05 21:37:10 +00:00
|
|
|
_members = new ObservableCollection<PartyMember>();
|
2019-06-26 01:17:52 +00:00
|
|
|
|
|
|
|
State(PartyState.SelectingHost);
|
2019-05-27 16:23:14 +00:00
|
|
|
}
|
2019-06-26 01:17:52 +00:00
|
|
|
#region Properties
|
2019-05-27 16:23:14 +00:00
|
|
|
|
2019-07-05 21:37:10 +00:00
|
|
|
public ObservableCollection<PartyMember> Members
|
2019-05-27 16:23:14 +00:00
|
|
|
{
|
2019-07-05 21:37:10 +00:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return _members;
|
|
|
|
}
|
2019-05-27 16:23:14 +00:00
|
|
|
set { SetProperty(ref _members, value); }
|
|
|
|
}
|
2019-06-26 01:17:52 +00:00
|
|
|
|
|
|
|
public bool IsSelectingHost
|
|
|
|
{
|
|
|
|
get { return _state == PartyState.SelectingHost; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsNotSelectingHost
|
|
|
|
{
|
|
|
|
get { return _state != PartyState.SelectingHost; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public Command JoinCommand { get; set; }
|
|
|
|
public Command HostCommand { get; set; }
|
|
|
|
|
|
|
|
public string Hostname
|
|
|
|
{
|
|
|
|
get { return _hostname; }
|
|
|
|
set { SetProperty(ref _hostname, value); }
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion Properties
|
|
|
|
|
|
|
|
|
|
|
|
private void State(PartyState state)
|
|
|
|
{
|
|
|
|
_state = state;
|
|
|
|
OnPropertyChanged("IsSelectingHost");
|
2019-07-05 21:37:10 +00:00
|
|
|
OnPropertyChanged("IsNotSelectingHost");
|
2019-06-26 01:17:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region Commands
|
|
|
|
private void OnJoinExecute()
|
|
|
|
{
|
2019-07-05 15:37:44 +00:00
|
|
|
_executor = BaseExecutor.CreateExecutor<ClientExecutor>();
|
2019-07-06 19:52:28 +00:00
|
|
|
_executor.Connect(this.Hostname);
|
|
|
|
|
|
|
|
SetUpMembers();
|
|
|
|
|
2019-06-26 01:17:52 +00:00
|
|
|
State(PartyState.Connecting);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CanJoinExecute()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnHostExecute()
|
|
|
|
{
|
2019-07-05 15:37:44 +00:00
|
|
|
|
|
|
|
//Instantiate and initialize all executors
|
|
|
|
_executor = BaseExecutor.CreateExecutor<HostExecutor>();
|
2019-07-06 19:52:28 +00:00
|
|
|
_executor.Connect(this.Hostname);
|
2019-07-05 15:37:44 +00:00
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
SetUpMembers();
|
2019-07-05 21:37:10 +00:00
|
|
|
|
2019-07-05 15:37:44 +00:00
|
|
|
//Change state
|
2019-06-26 01:17:52 +00:00
|
|
|
State(PartyState.Connecting);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool CanHostExecute()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion Commands
|
|
|
|
|
2019-07-06 19:52:28 +00:00
|
|
|
private void SetUpMembers()
|
|
|
|
{
|
|
|
|
_members = _executor.PartyMembers;
|
|
|
|
OnPropertyChanged("Members");
|
|
|
|
_executor.PartyMembers.CollectionChanged += (sender, e) =>
|
|
|
|
{
|
|
|
|
if (_executor != null)
|
|
|
|
{
|
|
|
|
_members = _executor.PartyMembers;
|
|
|
|
}
|
|
|
|
OnPropertyChanged("Members");
|
|
|
|
};
|
|
|
|
}
|
2019-05-27 16:23:14 +00:00
|
|
|
}
|
|
|
|
}
|