added Player Info and changed UI Text Positions
[clanbomber-xamarin-client.git] / src / full_system / ConnectionTest / ConnectionTest / ConnectionTest / PostGamePage.cs
1 ´╗┐using System;
2
3 using Xamarin.Forms;
4 using static Bomberman.TcpJsonConnection;
5
6
7 namespace Bomberman
8 {
9     public class PostGamePage : ContentPage
10     {
11         private Label labelTime;
12
13         public PostGamePage(ServerPackage pkg)
14         {
15             Label labelTitle = new Label
16             {
17                 Text = "Results:",
18                 FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
19                 VerticalOptions = LayoutOptions.CenterAndExpand,
20                 HorizontalOptions = LayoutOptions.CenterAndExpand
21             };
22
23             labelTime = new Label
24             {
25                 Text = "Time until restart: " + pkg.Timeout.ToString("0.00"),
26                 FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
27                 VerticalOptions = LayoutOptions.CenterAndExpand,
28                 HorizontalOptions = LayoutOptions.CenterAndExpand
29             };
30
31             Grid outGrid = new Grid();
32             ScrollView scrollView = new ScrollView();
33             Grid innerGrid = new Grid();
34
35             outGrid.ColumnDefinitions = new ColumnDefinitionCollection()
36             {
37                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
38                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
39                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
40                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
41                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
42
43             };
44             outGrid.Children.Add(new Label() { Text = "Position" }, 1, 0);
45             outGrid.Children.Add(new Label() { Text = "ID" }, 2, 0);
46             outGrid.Children.Add(new Label() { Text = "Color" }, 3, 0);
47
48
49             innerGrid.ColumnDefinitions = new ColumnDefinitionCollection()
50             {
51                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
52                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
53                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
54                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
55                 new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)},
56             };
57
58             innerGrid.RowDefinitions = new RowDefinitionCollection();
59
60             String[] playerColorText = new String[4];
61             playerColorText[0] = "Yellow";
62             playerColorText[1] = "Red";
63             playerColorText[2] = "Purple";
64             playerColorText[3] = "Green";
65
66             Color[] PlayerColor = new Color[4];
67             PlayerColor[0] = Color.Yellow;
68             PlayerColor[1] = Color.Red;
69             PlayerColor[2] = Color.Purple;
70             PlayerColor[3] = Color.Green;
71
72             for (int i = 0; i < pkg.Players.Count; i++)
73             {
74                 innerGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
75                 innerGrid.Children.Add(new Label() { Text = "" + (i + 1) }, 1, i);
76                 innerGrid.Children.Add(new Label() { Text = "" + pkg.Players[i].Id }, 2, i);
77
78                 if (pkg.Id == pkg.Players[i].Id)
79                 {
80                     innerGrid.Children.Add(new Label() { Text = playerColorText[i % 4] + " (You)", TextColor = PlayerColor[i % 4] }, 3, i);
81
82                 }
83                 else
84                 {
85                     innerGrid.Children.Add(new Label() { Text = playerColorText[i % 4], TextColor = PlayerColor[i % 4] }, 3, i);
86                 }
87
88
89
90             }
91
92             scrollView.Content = innerGrid;
93
94             Content = new StackLayout
95             {
96                 Children =
97                 {
98                     labelTitle,
99                     outGrid,
100                     scrollView,
101                     labelTime
102
103                 }
104             };
105         }
106         public void UpdateTime(ServerPackage pkg)
107         {
108             labelTime.Text = "Time until restart: " + pkg.Timeout.ToString("0.00");
109         }
110     }
111 }
112