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