Пример #1
0
        public CreateGameViewModel() : base()
        {
            Decks           = new List <SelectableItem>(0);
            settings        = new SettingsLoader();
            LoadDecksStatus = "Refreshing Decks";
            Thread thd = new Thread(async() =>
            {
                List <string> deckNames = await CardsAgainstHumility.GetDecks();
                dispatcher.BeginInvoke(() =>
                {
                    try
                    {
                        var preferredDecks = settings.GetPreferredDecks(deckNames);
                        Decks = deckNames.Select(c => new SelectableItem()
                        {
                            IsSelected = preferredDecks.Contains(c),
                            Text       = c
                        }).ToList();
                        LoadDecksStatus = $"{deckNames.Count} Decks Available";
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });
            });

            thd.Start();
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.CreateGameMenu);
            settings = new SettingsLoader(this);

            startBtn        = FindViewById <Button>(Resource.Id.cg_btnStart);
            gameNameTxt     = FindViewById <EditText>(Resource.Id.cg_txtGameName);
            maxPlayersTxt   = FindViewById <EditText>(Resource.Id.cg_txtMaxPlayers);
            pointsToWinTxt  = FindViewById <EditText>(Resource.Id.cg_txtPointsToWin);
            decksList       = FindViewById <ListView>(Resource.Id.cg_deckList);
            decksListStatus = FindViewById <TextView>(Resource.Id.cg_deckListStatus);

            var gameNameLbl    = FindViewById <TextView>(Resource.Id.cg_lblGameName);
            var maxPlayersLbl  = FindViewById <TextView>(Resource.Id.cg_lblMaxPlayers);
            var pointsToWinLbl = FindViewById <TextView>(Resource.Id.cg_lblPointsToWin);

            if (UIAssets.AppFont != null)
            {
                startBtn.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                gameNameTxt.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                maxPlayersTxt.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                pointsToWinTxt.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                gameNameLbl.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                maxPlayersLbl.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                pointsToWinLbl.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
                decksListStatus.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal);
            }

            gameNameTxt.Text    = $"{CardsAgainstHumility.PlayerName}'s Game";
            maxPlayersTxt.Text  = "10";
            pointsToWinTxt.Text = "10";

            startBtn.Enabled = false;
            startBtn.Click  += async delegate
            {
                try
                {
                    await CreateGame();
                }
                catch (Exception ex)
                {
                    ShowAlert("Unexpected Error", ex.Message);
                }
            };

            var thd = new Thread(async() =>
            {
                string error             = null;
                List <string> deckTitles = null;
                try
                {
                    deckTitles = await CardsAgainstHumility.GetDecks();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error getting deck titles: {0}", ex.Message);
                    error = "Connection Error";
                }
                RunOnUiThread(() =>
                {
                    if (error == null)
                    {
                        var preferredDecks = settings.GetPreferredDecks(deckTitles);
                        decks = deckTitles.Select(c => new SelectableItem()
                        {
                            IsSelected = preferredDecks.Contains(c),
                            Text       = c
                        }).ToList();
                        decksListStatus.Text = $"{deckTitles.Count} Decks Available";
                        decksList.Adapter    = new SelectionListArrayAdapter(this, decks);
                        startBtn.Enabled     = true;
                    }
                    else
                    {
                        decksListStatus.Text = error;
                    }
                });
            });

            thd.Start();
        }