Beispiel #1
0
        private void SelectPackage_Executed(object arg)
        {
            var code = (PackageSourceTypes)arg;

            switch (code)
            {
            case PackageSourceTypes.Next:
                Package = new NextPackageSource();
                break;

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

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

            case PackageSourceTypes.Local:
                var packagePath = PlatformManager.Instance.SelectLocalPackage();
                if (packagePath != null)
                {
                    Package = new CustomPackageSource(packagePath);
                }
                break;

            case PackageSourceTypes.SIStorage:
                var contentBox = new ContentBox {
                    Data = StorageInfo, Title = Resources.SIStorage
                };
                StorageInfo.Init();
                Navigate?.Invoke(contentBox);
                break;

            case PackageSourceTypes.VK:
                try
                {
                    Process.Start(Resources.ThemesLink);
                }
                catch (Exception exc)
                {
                    PlatformManager.Instance.ShowMessage(string.Format(Resources.VKThemesError + "\r\n{1}", Resources.ThemesLink, exc.Message), MessageType.Error);
                }
                break;
            }
        }
Beispiel #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();
                }
            }
        }