public async Task VerifyAndPass(LogInLayout LIlayout, string userName, CookieContainer cookieJar, bool saveCredentials, ContentPageController viewController) { CookieJar = cookieJar; // store credientials if it is a new login if (saveCredentials) { //Gather Cookie String var gameUri = new Uri(Constants.EndPoint); var gamecookies = CookieJar.GetCookies(gameUri); string CookieString = null; foreach (Cookie c in gamecookies) { if (c.Name == ".AspNet.ApplicationCookie") CookieString = c.Value; } //Store Cookie AuthCache.InsertObject(userName, CookieString); } //just preps the Game Manager GameManager.SetupGame(CookieJar, ViewController); if (!SeenHomeScreen) { SeenHomeScreen = true; var HLayout = new HomeLayout(ViewController, true); } else { var GSlayout = new GameSelectLayout(ViewController); } }
public async Task HandleLogIn(LogInLayout LIlayout, ContentPageController viewController) { //this is used only for debugging cause the emulator likes to save credentials //AuthCache.DeleteObject(); ViewController = viewController; if (AuthCache.DoCredentialsExist()) { // need to gather credentials and pass them on var Username = AuthCache.GetUserName(); var CookieString = AuthCache.GetCookieString(); //string Password = "******"; // build the cookiecontainer from authstring var tempcookie = new Cookie {Name = ".AspNet.ApplicationCookie", Value = CookieString}; var tempcollection = new CookieContainer(); tempcollection.Add(new Uri(Constants.EndPoint), tempcookie); await VerifyAndPass(LIlayout, Username, tempcollection, false, viewController); } else { SeenHomeScreen = true; var HLayout = new HomeLayout(ViewController, false); } }
public DialogueLayout(DialogueResponse DResponse, ContentPageController ViewController) { var labelLarge = new Label { Text = "Message From Server", FontSize = 25, HorizontalOptions = LayoutOptions.Center, HeightRequest = 55 }; var DialogueLabel = new Label { Text = DResponse.Dialogue, FontSize = 30, HorizontalOptions = LayoutOptions.Center, HeightRequest = 110 }; dialoguebutton = new Button { Text = "Ok", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), VerticalOptions = LayoutOptions.Fill, //TranslationY = 2, HeightRequest = 55 //IsVisible = false, }; // The View DiaLayout = new StackLayout { Children = { labelLarge, DialogueLabel, dialoguebutton }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; dialoguebutton.Clicked += (sender, args) => { ViewController.Invoke(() => dialoguebutton.IsEnabled = false); // return to previous sceen Display(ViewController, StoredContent); ViewController.Invoke(() => dialoguebutton.IsEnabled = false); }; StoredContent = ViewController.View.Content; Display(ViewController); }
//Home Screen public HomeLayout(ContentPageController ViewController, bool bypassLogIn) { HLayout = new StackLayout { BackgroundColor = Color.FromHex("1393c3"), Children = { new Image { Source = "unsafespaceslogo.png" }, new Label { Text = "#nooneissafe", FontSize = 20, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start, HeightRequest = 25 }, new Image { Source = "shocked_smile.png" } } }; StartButton = new Button { Text = "Play \u25B6", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), HorizontalOptions = LayoutOptions.Center, //VerticalOptions = LayoutOptions.Fill, WidthRequest = 120 }; HLayout.Children.Add(StartButton); StartButton.Clicked += (sender, args) => { ViewController.Invoke(() => StartButton.Text = "Loading \u25B6"); StartButton.IsEnabled = false; if (bypassLogIn) { var GSlayout = new GameSelectLayout(ViewController); } else { ViewController.Invoke(() => ViewController.View.Content = ViewController.LogIn.LILayout); } StartButton.IsEnabled = true; }; Display(ViewController); }
//Waiting View public WaitingLayout(WaitingResponse WResponse, ContentPageController ViewController) { var PlayersReady = WResponse.Players; var RoundNumber = WResponse.RoundNumber; var RoundLabel = new Label { Text = "Round " + RoundNumber, FontSize = 30, HorizontalOptions = LayoutOptions.Center, HeightRequest = 100 }; var labelLarge = new Label { Text = "Waiting on others", FontSize = 25, HorizontalOptions = LayoutOptions.Center, HeightRequest = 50 }; WaitLayout = new StackLayout { Children = { RoundLabel, labelLarge }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; foreach (var R in PlayersReady) { // can be Buttons, ListView, Picker WaitLayout.Children.Add(new Label { Text = R.Name + ": " + R.Status, HorizontalOptions = LayoutOptions.Center, FontSize = 15 }); } Display(ViewController); }
//Handles a new Log In and Stores Credientials public async Task NewLogIn(LogInLayout LIlayout, string userName, string password, bool saveCredentials, ContentPageController viewcontroller) { var cookieJar = await LogIn(userName, password); if (await VerifyLogin(cookieJar)) { await VerifyAndPass(LIlayout, userName, cookieJar, saveCredentials, viewcontroller); } else { if (!SeenHomeScreen) { SeenHomeScreen = true; var HLayout = new HomeLayout(ViewController, false); } else { ViewController.Invoke(() => ViewController.View.Content = ViewController.LogIn.LILayout); } } }
//Shows Question Page public QuestionLayout(QuestionResponse QResponse, ContentPageController ViewController) { var question = QResponse.Question; var RoundNumber = QResponse.RoundNumber; var RoundLabel = new Label { Text = "Round " + RoundNumber, FontSize = 30, HorizontalOptions = LayoutOptions.Center, HeightRequest = 150 }; var questionlabel = new Label { Text = question, FontSize = 20, HorizontalOptions = LayoutOptions.StartAndExpand }; QuestionAnswer = new Entry { Placeholder = "Answer Here", VerticalOptions = LayoutOptions.Center, Keyboard = Keyboard.Text }; button = new Button { Text = "Submit!", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Fill }; QLayout = new StackLayout { Children = { RoundLabel, questionlabel, QuestionAnswer, button }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; button.Clicked += async (sender, args) => { ViewController.Invoke(() => button.IsEnabled = false); if (QuestionAnswer.Text != null) { await GameManager.Answer(QuestionAnswer.Text); } else { ViewController.Invoke(() => ViewController.DisplayAlert("Nothing in Answer", "Don't forget to answer before submitting.", "OK").ConfigureAwait(false)); } ViewController.Invoke(() => button.IsEnabled = true); }; Display(ViewController); }
// Voting Page public VoteLayout(VoteResponse VResponse, ContentPageController ViewController) { var inputs = VResponse.PlayerAnswers; var RoundNumber = VResponse.RoundNumber; var RoundLabel = new Label { Text = "Round " + RoundNumber, FontSize = 30, HorizontalOptions = LayoutOptions.Center //HeightRequest = 150 }; var AnswerImage = new Image { Source = "answer_now.png" }; listview = new ListView { ItemsSource = inputs, HeightRequest = 30, ItemTemplate = new DataTemplate(() => { var textlabel = new Label { TextColor = Color.FromRgb(31, 174, 206) }; var cell = new ViewCell { View = new StackLayout { Children = { textlabel } } }; textlabel.SetBinding(Label.TextProperty, "Answer"); /* TextCell cell = new TextCell(); cell.SetBinding(TextCell.TextProperty, "Answer"); */ return cell; }) //RowHeight = 150, }; VLayout = new StackLayout { Children = { RoundLabel, AnswerImage, listview }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; listview.ItemSelected += async (sender, args) => { ViewController.Invoke(() => listview.IsEnabled = false); // GameManager.ViewController.Invoke(() => GameManager.CurrentGame.CurrentVoteChoice = ((PlayerInput)args.SelectedItem).PlayerID); var item = args.SelectedItem as PlayerAnswer; await GameManager.Vote(item.PlayerId); ViewController.Invoke(() => listview.IsEnabled = true); ViewController.Invoke(() => ((ListView) sender).SelectedItem = null); }; Display(ViewController); }
//Shows Results Page public ResultsLayout(ResultsResponse RResponse, ContentPageController ViewController) { var Input = RResponse.PlayerInputs; var PlayerGames = RResponse.PlayerGames; var roundnumber = RResponse.RoundNumber; var Admin = RResponse.Admin; var RoundLabel = new Label { Text = "Round " + roundnumber, FontSize = 35, HorizontalOptions = LayoutOptions.Center, HeightRequest = 55 }; var ResultsImage = new Image { Source = "results.png" }; nextRoundButton = new Button { Text = "Next Round", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), VerticalOptions = LayoutOptions.Fill, //TranslationY = 2, HeightRequest = 55 //IsVisible = false, }; ResLayout = new StackLayout { Children = { RoundLabel, ResultsImage }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; foreach (var p in Input) { ResLayout.Children.Add(new Label { Text = p.Name + ": " + p.Score, HorizontalOptions = LayoutOptions.Center, FontSize = 15 }); } if (Admin) { ResLayout.Children.Add(nextRoundButton); } var TotalScoreImage = new Image { Source = "total_score.png" }; ResLayout.Children.Add(TotalScoreImage); //order players by points, then display foreach (var p in PlayerGames.OrderByDescending(pg => pg.Points).ToArray()) { ResLayout.Children.Add(new Label { Text = p.Name + ": " + p.Points, HorizontalOptions = LayoutOptions.Center, FontSize = 15 }); } var VoteStatsImage = new Image { Source = "statistics.png" }; ResLayout.Children.Add(VoteStatsImage); foreach (var p in Input) { ResLayout.Children.Add(new Label { Text = p.Name + "'s Answer: " + p.Answer, FontSize = 15, HorizontalOptions = LayoutOptions.Center }); var tempInputs = Input.Where(pi => pi.Vote == p.PlayerId).Select(pi => pi.Name); var whoVoted = string.Join(", ", tempInputs); ResLayout.Children.Add(new Label { Text = "Votes: " + whoVoted, HorizontalOptions = LayoutOptions.Center, FontSize = 10, HeightRequest = 40 }); } nextRoundButton.Clicked += async (sender, args) => { ViewController.Invoke(() => nextRoundButton.IsEnabled = false); //nextRoundButon.Text = "starting next round"; await GameManager.NewRound(); ViewController.Invoke(() => nextRoundButton.IsEnabled = false); }; Display(ViewController); }
internal void Display(ContentPageController ViewController, View StoredContent) { ViewController.Invoke(() => { ViewController.View.Content = StoredContent; }); }
public EndOfGameLayout(EndOfGameResponse EOGResponse, ContentPageController ViewController) { var Input = EOGResponse.PlayerInputs; var PlayerGames = EOGResponse.PlayerGames; var labelLarge = new Label { Text = "Final Results", FontSize = 30, HorizontalOptions = LayoutOptions.Center, HeightRequest = 55 }; EndButton = new Button { Text = "End Game", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), VerticalOptions = LayoutOptions.Fill, //TranslationY = 2, HeightRequest = 55 //IsVisible = false, }; EOGLayout = new StackLayout { Children = { labelLarge }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; // Show Final Points foreach (var p in PlayerGames.OrderByDescending(pg => pg.Points).ToArray()) { EOGLayout.Children.Add(new Label { Text = p.Name + ": " + p.Points, HorizontalOptions = LayoutOptions.Center, FontSize = 15 }); } EOGLayout.Children.Add(EndButton); var TotalLabel = new Label { Text = "Round 15 Results", FontSize = 30, HorizontalOptions = LayoutOptions.Center, HeightRequest = 55 }; EOGLayout.Children.Add(TotalLabel); //order players by points, then display foreach (var p in Input) { EOGLayout.Children.Add(new Label { Text = p.Name + ": " + p.Score, HorizontalOptions = LayoutOptions.Center, FontSize = 15 }); } var VoteStatsImage = new Image { Source = "statistics.png" }; EOGLayout.Children.Add(VoteStatsImage); //Show who voted for what foreach (var p in Input) { EOGLayout.Children.Add(new Label { Text = p.Name + "'s Answer: " + p.Answer, FontSize = 15, HorizontalOptions = LayoutOptions.Center }); var tempInputs = Input.Where(pi => pi.Vote == p.PlayerId).Select(pi => pi.Name); var whoVoted = string.Join(", ", tempInputs); EOGLayout.Children.Add(new Label { Text = "Votes: " + whoVoted, HorizontalOptions = LayoutOptions.Center, FontSize = 10, HeightRequest = 40 }); } EndButton.Clicked += (sender, args) => { ViewController.Invoke(() => EndButton.IsEnabled = false); //nextRoundButon.Text = "starting next round"; GameManager.EndGame(); ViewController.Invoke(() => EndButton.IsEnabled = false); }; Display(ViewController); }
internal void Display(ContentPageController ViewController) { ViewController.Invoke(() => GameManager.ViewController.View.Content = GLLayout); }
//Layout for game selection public GameSelectLayout(ContentPageController ViewController) { //GameID = "641b0eda"; ViewController.NavDrawer.ShowLayoutMenu(); var SelectGame = new Image { Source = "select_game.png" }; var gamelabel = new Label { Text = "Enter Game Number:", FontSize = 20, HorizontalOptions = LayoutOptions.StartAndExpand }; var GameNumberEntry = new Entry { //Placeholder = GameID, VerticalOptions = LayoutOptions.Center, Keyboard = Keyboard.Text, //HeightRequest = 75 WidthRequest = 180 }; gamebutton = new Button { Text = "Play \u25B6", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), HorizontalOptions = LayoutOptions.End, //VerticalOptions = LayoutOptions.Fill, WidthRequest = 120 //HeightRequest = 50, //TranslationY= 15, }; newgamebutton = new Button { Text = "Create New Game \u25B6", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), VerticalOptions = LayoutOptions.Fill, TranslationY = 2, HeightRequest = 55 }; var RecentImage = new Image { Source = "recent_games.png" }; InfoLabel = new Label { Text = "Gathering Recent Games...", FontSize = 20, HorizontalOptions = LayoutOptions.StartAndExpand }; GSLayout = new StackLayout { Children = { SelectGame, gamelabel, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { GameNumberEntry, gamebutton } }, newgamebutton, RecentImage, InfoLabel }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; gamebutton.Clicked += async (sender, args) => { ViewController.Invoke(() => gamebutton.IsEnabled = false); if (GameNumberEntry.Text != null) { //Pass control on to Game from here on out gamebutton.Text = "Joining"; //DEBUG //await GameManager.JoinGame(this.GameID); //RELEASE await GameManager.JoinGame(GameNumberEntry.Text); ViewController.Invoke(() => gamebutton.IsEnabled = true); } else { ViewController.Invoke(() => ViewController.DisplayAlert("Nothing in Answer", "Don't forget to input answer before submitting.", "OK").ConfigureAwait(false)); } }; newgamebutton.Clicked += async (sender, args) => { //Pass control on to Game from here on out ViewController.Invoke(() => newgamebutton.IsEnabled = false); await GameManager.CreateGame(); ViewController.Invoke(() => newgamebutton.IsEnabled = false); }; GameManager.GetActiveGames(this).ConfigureAwait(false); Display(); }
internal void addActiveGames(GetActiveGamesResponse[] gameList, ContentPageController ViewController) { GSListView = new ListView { ItemsSource = gameList, ItemTemplate = new DataTemplate(() => { var gameIDlabel = new Label(); gameIDlabel.SetBinding(Label.TextProperty, "GameId"); gameIDlabel.FontSize = 10; gameIDlabel.MinimumWidthRequest = 80; var dateLabel = new Label(); dateLabel.SetBinding(Label.TextProperty, "CreatedDate"); dateLabel.FontSize = 10; var AdminLabel = new Label(); AdminLabel.SetBinding(Label.TextProperty, "AdminName"); AdminLabel.FontSize = 10; return new ViewCell { View = new StackLayout { Padding = new Thickness(0, 5), Orientation = StackOrientation.Horizontal, Children = { gameIDlabel, dateLabel, AdminLabel } } }; }) }; GSLayout.Children.Remove(InfoLabel); GSLayout.Children.Add(GSListView); GSListView.ItemSelected += async (sender, args) => { var responses = (GetActiveGamesResponse) args.SelectedItem; //This needs to call the refresh button await GameManager.JoinGame(responses.GameId); }; }
internal void Display(ContentPageController ViewController) { ViewController.Invoke(() => { ViewController.View.Content = QLayout; }); }
public GameLobbyLayout(GameLobbyResponse GLResponse, ContentPageController ViewController) { var Players = GLResponse.Names; var Admin = GLResponse.Admin; var labelLarge = new Label { Text = "Waiting Room", FontSize = 30, HorizontalOptions = LayoutOptions.Center, HeightRequest = 80 }; adminLabel = new Label { Text = "GameID = " + GLResponse.GameId, FontSize = 20, HorizontalOptions = LayoutOptions.Center //IsVisible = false, }; startgamebutton = new Button { Text = "Start Game", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), VerticalOptions = LayoutOptions.Fill, TranslationY = 2, HeightRequest = 55 //IsVisible = false, }; //view GLLayout = new StackLayout { Children = { labelLarge //adminLabel //startgamebutton, //entry, //boxView, //image }, Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) //HeightRequest = 1500 }; //Show Start Game Button if Admin if (Admin) { GLLayout.Children.Insert(1, adminLabel); GLLayout.Children.Add(startgamebutton); } foreach (var p in GLResponse.Names) { GLLayout.Children.Add(new Label {Text = p, HorizontalOptions = LayoutOptions.Center, FontSize = 20}); } startgamebutton.Clicked += async (sender, args) => { ViewController.Invoke(() => startgamebutton.IsEnabled = false); if (GLResponse.Names.Length >= 3) { startgamebutton.Text = "Starting Game"; await GameManager.StartGame(); } else { ViewController.Invoke(() => ViewController.DisplayAlert("Not Enough Players", "Need 3 or more players to start.", "OK") .ConfigureAwait(false)); } ViewController.Invoke(() => startgamebutton.IsEnabled = true); }; Display(ViewController); }
//Log In Screen public LogInLayout(ContentPageController ViewController) { //Debug variables //username = "******"; //password = "******"; var TitleImage = new Image { Source = "unsafespaceslogo.png" }; var labelusername = new Label { Text = "Username:"******"Password:"******"Click to Login", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Fill //HeightRequest = 75, }; FacebookLogin = new Button { Text = "Login with Facebook", FontSize = Device.GetNamedSize(NamedSize.Large, typeof (Button)), HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Fill //HeightRequest = 75, }; labelstr = new Label { Text = "Not Yet connected!", FontSize = 20, HorizontalOptions = LayoutOptions.CenterAndExpand }; LILayout = new StackLayout { Children = { TitleImage, labelusername, Lusername, labelpassword, Lpassword, button, FacebookLogin //labelstr, } //HeightRequest = 1500 }; }
public static void SetupGame(CookieContainer cookieJar, ContentPageController viewController) { ViewController = viewController; CookieJar = cookieJar; }
public NavigationDrawer() { Title = "Lee Game"; ViewController = new ContentPageController(this); string[] temp = {"Refresh Game", "Switch Games", "How To Play", "Logout"}; listView = GetListView(temp); MasterPage = new ContentPage { Title = "Options", Content = listView, Icon = "hamburger.png", Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5) }; Master = MasterPage; MasterPage.IsVisible = false; //menu buttons & handlers listView.ItemTapped += async (sender, e) => { switch (e.Item.ToString()) { case "Refresh Game": if (InGame) await GameManager.RefreshGame().ConfigureAwait(false); //.ConfigureAwait(false); ViewController.Invoke(() => IsPresented = false); break; case "Switch Games": var GameSelect = new GameSelectLayout(ViewController); ViewController.Invoke(() => IsPresented = false); break; case "Logout": ViewController.LogInManager.LogOut(); ViewController.Invoke(() => IsPresented = false); break; case "How To Play": ViewController.Invoke(() => ((ListView) sender).SelectedItem = null); var OkButton = new Button { Text = "Back To Menu", FontSize = 15, HorizontalOptions = LayoutOptions.Center, HeightRequest = 50 }; var tempstack = new StackLayout { Children = { /* new Label { Text = "How To Play", FontSize = 30, HorizontalOptions = LayoutOptions.Center, HeightRequest = 50, }, */ new Image { Source = "how_to_play.png" }, new Label { Text = HowToPlayOne, FontSize = 18, HorizontalOptions = LayoutOptions.Center }, new Label { Text = HowToPlayTwo, FontSize = 18, HorizontalOptions = LayoutOptions.Center }, new Label { Text = HowToPlayThree, FontSize = 18, HorizontalOptions = LayoutOptions.Center }, OkButton } }; ViewController.Invoke(() => MasterPage.Content = tempstack); OkButton.Clicked += (senderer, args) => { ViewController.Invoke(() => MasterPage.Content = listView); }; break; default: ViewController.Invoke(() => IsPresented = false); break; } ViewController.Invoke(() => ((ListView) sender).SelectedItem = null); }; Detail = new NavigationPage(ViewController); }