Example #1
0
        protected override void Initialize()
        {
            base.Initialize();

            _join   = new ExtendedCommand(Join_Executed);
            NewGame = new CustomCommand(NewGame_Executed);
        }
Example #2
0
        public GameSettingsViewModel(
            GameSettings gameSettings,
            CommonSettings commonSettings,
            UserSettings userSettings,
            bool isNetworkGame = false)
            : base(gameSettings)
        {
            NetworkGame     = isNetworkGame;
            _commonSettings = commonSettings;

            UpdateComputerPlayers();
            UpdateComputerShowmans();

            StorageInfo             = new SIStorageViewModel(userSettings);
            StorageInfo.AddPackage += StorageInfo_AddPackage;

            gameSettings.Updated += GameSettings_Updated;

            _selectPackage = new ExtendedCommand(SelectPackage_Executed);

            _selectPackage.ExecutionArea.Add(PackageSourceTypes.Local);
            _selectPackage.ExecutionArea.Add(PackageSourceTypes.SIStorage);
            _selectPackage.ExecutionArea.Add(PackageSourceTypes.VK);

            var packageDirExists = Directory.Exists(Global.PackagesUri);

            if (packageDirExists)
            {
                _selectPackage.ExecutionArea.Add(PackageSourceTypes.Random);
            }

            if (NetworkGame && NetworkGameType == NetworkGameType.GameServer)
            {
                _selectPackage.ExecutionArea.Add(PackageSourceTypes.RandomServer);
            }

            if (packageDirExists)
            {
                _selectPackage.ExecutionArea.Add(PackageSourceTypes.Next);
            }

            if (_package == null)
            {
                if (_model.PackageKey != null && _selectPackage.ExecutionArea.Contains(_model.PackageKey.Type))
                {
                    switch (_model.PackageKey.Type)
                    {
                    case PackageSourceTypes.Next:
                        Package = new NextPackageSource();
                        break;

                    case PackageSourceTypes.Random:
                        Package = new RandomPackageSource();
                        break;

                    case PackageSourceTypes.RandomServer:
                        Package = new RandomServerPackageSource();
                        break;

                    case PackageSourceTypes.Local:
                        Package = new CustomPackageSource(_model.PackageKey.Data);
                        break;

                    case PackageSourceTypes.SIStorage:
                        var key = _model.PackageKey;
                        Uri uri;
                        if (Uri.TryCreate(key.Data, UriKind.Absolute, out uri))
                        {
                            Package = new SIStoragePackageSource(uri, key.ID, key.Name, key.PackageID);
                        }
                        break;
                    }
                }
                else if (packageDirExists)
                {
                    Package = new RandomPackageSource();
                }
            }
        }