Bonjour, je suis entrain de réaliser une interface WPF pour un futur jeu et j'aurais voulu des conseils sur comment améliorer mon interface. En particulier je gère actuellement les différents panneau en modifiant la visibility de ceux que je veux afficher mais je ne pense pas que ce soit la bonne solution.
Que me proposez vous?
Code wpf de l'interface
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 <Window x:Class="Anakrya.PreGame.frmLogin" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Anakrya - Authentification" Height="600" Width="800" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Icon="/Anakrya.PreGame;component/Resources/anakrya.ico"> <Window.Resources> <ControlTemplate x:Key="GlassButton" TargetType="{x:Type Button}"> <ControlTemplate.Resources> <Storyboard x:Key="Timeline1"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="1"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="Timeline2"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)"> <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources> <Border BorderBrush="Gainsboro" BorderThickness="1,1,1,1" CornerRadius="4,4,4,4"> <Border x:Name="border" Background="#7F000000" BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="4,4,4,4"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="0.507*"/> <RowDefinition Height="0.493*"/> </Grid.RowDefinitions> <Border Opacity="0" HorizontalAlignment="Stretch" x:Name="glow" Width="Auto" Grid.RowSpan="2" CornerRadius="4,4,4,4"> <Border.Background> <RadialGradientBrush> <RadialGradientBrush.RelativeTransform> <TransformGroup> <ScaleTransform ScaleX="1.702" ScaleY="2.243"/> <SkewTransform AngleX="0" AngleY="0"/> <RotateTransform Angle="0"/> <TranslateTransform X="-0.368" Y="-0.152"/> </TransformGroup> </RadialGradientBrush.RelativeTransform> <GradientStop Color="#B28DBDFF" Offset="0"/> <GradientStop Color="#008DBDFF" Offset="1"/> </RadialGradientBrush> </Border.Background> </Border> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Grid.RowSpan="2"/> <Border HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="shine" Width="Auto" CornerRadius="4,4,0,0"> <Border.Background> <LinearGradientBrush EndPoint="0.494,0.889" StartPoint="0.494,0.028"> <GradientStop Color="#998D8D8D" Offset="0"/> <GradientStop Color="#338D8D8D" Offset="1"/> </LinearGradientBrush> </Border.Background> </Border> </Grid> </Border> </Border> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Property="Opacity" TargetName="shine" Value="0.2"/> <Setter Property="Background" TargetName="border" Value="#CC000000"/> <Setter Property="Visibility" TargetName="glow" Value="Hidden"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource Timeline1}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard x:Name="Timeline2_BeginStoryboard" Storyboard="{StaticResource Timeline2}"/> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="CustomPasswordBox" TargetType="{x:Type PasswordBox}"> <Border Name="Border" CornerRadius="3" Padding="0" Background="#65FFFFFF" BorderBrush="AliceBlue" BorderThickness="2" > <ScrollViewer Margin="0" x:Name="PART_ContentHost"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter TargetName="Border" Property="Background" Value="#00000000"/> <Setter TargetName="Border" Property="BorderBrush" Value="DimGray"/> <Setter Property="Foreground" Value="Red"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="CustomTextBox" TargetType="{x:Type TextBox}"> <Border Name="Border" CornerRadius="3" Padding="0" Background="#65FFFFFF" BorderBrush="AliceBlue" BorderThickness="2"> <ScrollViewer Margin="0" x:Name="PART_ContentHost" Foreground="Gainsboro"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter TargetName="Border" Property="Background" Value="#00000000"/> <Setter TargetName="Border" Property="BorderBrush" Value="DimGray"/> <Setter Property="Foreground" Value="Red"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Window.Resources> <Grid> <Image Name="imgBG" Stretch="Fill" Source="Resources/bg.jpg" Margin="0,0,0,0" /> <Label FontFamily="./Fonts/#Opiated BRK" Margin="0,50,0,0" HorizontalAlignment="Center" Name="lblTitre" Height="50" VerticalAlignment="Top" Foreground="Gainsboro" FontSize="30" Cursor="None" OverridesDefaultStyle="False" ForceCursor="False" FontWeight="Bold" Opacity="1">Anakrya</Label> <Grid Name="grdMain" Margin="0" Height="200" VerticalAlignment="Center" HorizontalAlignment="Center"> <Rectangle Name="rectangle1" Stroke="Black" Opacity="0.6" Fill="Black" RadiusX="10" RadiusY="10" /> <Grid Name="grdAuth" Margin="0" Visibility="Visible"> <Label FontFamily="Trebuchet" Height="47" Name="label3" Foreground="Gainsboro" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="18" FontWeight="Bold" Canvas.Left="0" Canvas.Top="0" VerticalAlignment="Top">Authentification</Label> <Label Height="23" Name="label1" Width="112" Foreground="Gainsboro" FontFamily="Verdanna" Canvas.Left="26" Canvas.Top="55" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="27,58,0,0">Nom d'Utilisateur :</Label> <TextBox Foreground="#FFFFFF" KeyDown="txtUsername_KeyDown" FontWeight="Bold" Height="23" Template="{DynamicResource CustomTextBox}" Name="txtUsername" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="Verdanna" Opacity="0.7" BorderThickness="0" Canvas.Left="146" Canvas.Top="55" VerticalAlignment="Top" Margin="146,58,30,0" Width="275" /> <Label FontFamily="Verdanna" Foreground="Gainsboro" Name="label2" Width="112" Canvas.Left="26" Canvas.Top="98" HorizontalAlignment="Left" Margin="27,101,0,0" Height="23" VerticalAlignment="Top">Mot de Passe :</Label> <PasswordBox Name="txtPassword" KeyDown="txtUsername_KeyDown" FontWeight="Bold" FontFamily="Verdanna" Foreground="#FFFFFF" Template="{DynamicResource CustomPasswordBox}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Opacity="0.7" BorderBrush="Black" BorderThickness="0" Canvas.Left="146" Canvas.Top="98" Margin="146,101,29,0" Height="23" VerticalAlignment="Top" /> <CheckBox Name="checkBox1" Foreground="Gainsboro" FontFamily="Verdanna" Canvas.Left="146" Canvas.Top="134" Margin="146,129,149,0" Height="16" VerticalAlignment="Top">Mémoriser mon compte</CheckBox> <Button Name="btnConnect" Click="btnConnect_Click" Height="23" Content="Se Connecter" Foreground="Gainsboro" Template="{DynamicResource GlassButton}" FontFamily="Verdanna" FontSize="12" Canvas.Left="320" Canvas.Top="148" VerticalAlignment="Top" Margin="0,144,30,0" HorizontalAlignment="Right" Width="100" /> <Label Width="106" Canvas.Left="344" Canvas.Top="195" HorizontalAlignment="Right" Margin="0,172,0,0" Height="25" VerticalAlignment="Top"> <Hyperlink Click="lnkViewNews_Click" Foreground="#999999" FontFamily="Verdanna" Name="lnkViewNews">Afficher les News</Hyperlink> </Label> <ScrollViewer Margin="5,210,5,5"> <StackPanel> <Expander Header="" Visibility="Hidden" Name="expander1" Foreground="Gainsboro" FontFamily="Verdanna" MinWidth="0" MinHeight="23" IsExpanded="False" Height="Auto" VerticalAlignment="Top"> <StackPanel> <TextBlock Name="ContentNews1" Foreground="Gainsboro" TextWrapping="Wrap" Width="420" Padding="10,5,10,5"></TextBlock> </StackPanel> </Expander> <Expander Header="" Visibility="Hidden" Name="expander2" Foreground="Gainsboro" FontFamily="Verdanna" MinWidth="0" MinHeight="23" IsExpanded="False" Height="Auto" VerticalAlignment="Top"> <StackPanel> <TextBlock Name="ContentNews2" Foreground="Gainsboro" TextWrapping="Wrap" Width="420" Padding="10,5,10,5"></TextBlock> </StackPanel> </Expander> <Expander Header="" Visibility="Hidden" Name="expander3" Foreground="Gainsboro" FontFamily="Verdanna" MinWidth="0" MinHeight="23" IsExpanded="False" Height="Auto" VerticalAlignment="Top"> <StackPanel> <TextBlock Name="ContentNews3" Foreground="Gainsboro" TextWrapping="Wrap" Width="420" Padding="10,5,10,5"></TextBlock> </StackPanel> </Expander> </StackPanel> </ScrollViewer> </Grid> <Grid Name="grdConnect" Margin="0" Visibility="Hidden"> <Grid Width="251" VerticalAlignment="Center" HorizontalAlignment="Center" Height="100"> <Ellipse Name="waitBallade" Fill="CadetBlue" Height="10" Margin="0,20,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="10" Opacity="0.6" StrokeDashOffset="1" Stroke="LightBlue"></Ellipse> <TextBlock Foreground="Gainsboro" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Center" Name="textConnexion" TextWrapping="WrapWithOverflow"></TextBlock> <Label Name="backLink" Width="52" Canvas.Left="0" Canvas.Top="0" HorizontalAlignment="Right" Margin="0,79,0,-3" Visibility="Hidden"> <Hyperlink Click="lnkRetour_Click" Foreground="#999999" FontFamily="Verdanna" Name="lnkRetour">Retour</Hyperlink> </Label> </Grid> </Grid> </Grid> </Grid> </Window>
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Media.Animation; using Anakrya.PreGame.Utils; namespace Anakrya.PreGame { /// <summary> /// Interaction logic for frmLogin.xaml /// </summary> public partial class frmLogin : Window { private bool m_newsopen = false; private ThicknessAnimation waitConnect; #region Properties public string Username { get; private set; } public string Password { get; private set; } #endregion public frmLogin() { InitializeComponent(); NewsManager.Instance.NewsLoaded += new EventHandler<NewsManager.NewsLoadedEventArgs>(Instance_NewsLoaded); NewsManager.Instance.LoadNews("FR"); } #region CrossThread #region News private void InvokeChangeHeader(Expander el, string text) { el.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.DataBind, new ChangeHeaderHandler(ChangeHeader), el, text); } private delegate void ChangeHeaderHandler(Expander el, string text); private void ChangeHeader(Expander el, string text) { el.Header = text; } private void InvokeChangeContent(TextBlock el, string text) { el.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.DataBind, new ChangeContentHandler(ChangeContent), el, text); } private delegate void ChangeContentHandler(TextBlock el, string text); private void ChangeContent(TextBlock el, string text) { el.Text = text; } private void InvokeChangeVisibility(Expander el, Visibility val) { el.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.DataBind, new ChangeVisibilityHandler(ChangeVisibility), el, val); } private delegate void ChangeVisibilityHandler(Expander el, Visibility val); private void ChangeVisibility(Expander el, Visibility val) { el.Visibility = val; } #endregion #region WaitForConnect private void InvokeChangeEllipseVisibility(Ellipse el, Visibility val) { el.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new ChangeEllipseVisibilityHandler2(ChangeEllipseVisibility), el, val); } private delegate void ChangeEllipseVisibilityHandler2(Ellipse el, Visibility val); private void ChangeEllipseVisibility(Ellipse el, Visibility val) { el.Visibility = val; } private void InvokeChangeLabelVisibility(Label el, Visibility val) { el.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new ChangeLabelVisibilityHandler2(ChangeLabelVisibility), el, val); } private delegate void ChangeLabelVisibilityHandler2(Label el, Visibility val); private void ChangeLabelVisibility(Label el, Visibility val) { el.Visibility = val; } #endregion #region Animation public delegate void BeginAnimationHandler(DependencyProperty prop, AnimationTimeline at); #endregion #endregion #region News private void Instance_NewsLoaded(object sender, NewsManager.NewsLoadedEventArgs e) { if (!e.Success) return; NewsManager.Instance.ListNews.Sort(); NewsManager.Instance.ListNews.Reverse(); if (NewsManager.Instance.ListNews.Count >= 1) { News n1 = NewsManager.Instance.ListNews[0]; this.InvokeChangeHeader(this.expander1, String.Format("[{0}] {1}", n1.DatePublication, n1.Titre)); this.InvokeChangeContent(this.ContentNews1, n1.Contenu); this.InvokeChangeVisibility(this.expander1, Visibility.Visible); } if (NewsManager.Instance.ListNews.Count >= 2) { News n2 = NewsManager.Instance.ListNews[1]; this.InvokeChangeHeader(this.expander2, String.Format("[{0}] {1}", n2.DatePublication, n2.Titre)); this.InvokeChangeContent(this.ContentNews2, n2.Contenu); this.InvokeChangeVisibility(this.expander2, Visibility.Visible); } if (NewsManager.Instance.ListNews.Count >= 3) { News n3 = NewsManager.Instance.ListNews[2]; this.InvokeChangeHeader(this.expander3, String.Format("[{0}] {1}", n3.DatePublication, n3.Titre)); this.InvokeChangeContent(this.ContentNews3, n3.Contenu); this.InvokeChangeVisibility(this.expander3, Visibility.Visible); } } private void lnkViewNews_Click(object sender, RoutedEventArgs e) { m_newsopen = !m_newsopen; if (m_newsopen) { DoubleAnimation da = new DoubleAnimation(); da.From = this.grdMain.Height; da.To = 350; da.Duration = new Duration(TimeSpan.FromSeconds(1.5)); this.grdMain.BeginAnimation(Rectangle.HeightProperty, da); } else { DoubleAnimation da = new DoubleAnimation(); da.From = this.grdMain.Height; da.To = 200; da.Duration = new Duration(TimeSpan.FromSeconds(1.5)); this.grdMain.BeginAnimation(Rectangle.HeightProperty, da); } } #endregion #region Lancement du login private void btnConnect_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(this.txtUsername.Text) || String.IsNullOrEmpty(this.txtPassword.Password)) { MessageBox.Show("Boulet on t'a demandé tes identifiants!!!"); return; } Username = this.txtUsername.Text; Password = this.txtPassword.Password; DoubleAnimation da1 = new DoubleAnimation(); da1.From = 1; da1.To = 0; da1.Duration = new Duration(TimeSpan.FromSeconds(1)); da1.Completed += new EventHandler(da1_Completed); this.grdAuth.BeginAnimation(Rectangle.OpacityProperty, da1); } private void txtUsername_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Return) { this.btnConnect_Click(sender, e); e.Handled = true; } } private void da1_Completed(object sender, EventArgs e) { this.grdAuth.Visibility = Visibility.Hidden; this.grdConnect.Opacity = 0; this.grdConnect.Visibility = Visibility.Visible; this.ConnexionProgress("Connexion au serveur...", true, false); #region Animation d'attente waitConnect = new ThicknessAnimation(); waitConnect.From = new Thickness(0, this.waitBallade.Margin.Top, 0, this.waitBallade.Margin.Bottom); waitConnect.To = new Thickness(241, this.waitBallade.Margin.Top, 0, this.waitBallade.Margin.Bottom); waitConnect.RepeatBehavior = RepeatBehavior.Forever; waitConnect.AutoReverse = true; waitConnect.Duration = new Duration(TimeSpan.FromSeconds(2.5)); this.waitBallade.BeginAnimation(Ellipse.MarginProperty, waitConnect); #endregion #region Fondu d'attente DoubleAnimation da2 = new DoubleAnimation(); da2.From = 0; da2.To = 1; da2.Duration = new Duration(TimeSpan.FromSeconds(1)); this.grdConnect.BeginAnimation(Rectangle.OpacityProperty, da2); #endregion #region Connexion au serveur Program.m_master.Connect(); #endregion } public void ConnexionProgress(string text, bool animate, bool viewBackLink) { if (!animate && this.waitBallade.Visibility != Visibility.Hidden) this.InvokeChangeEllipseVisibility(this.waitBallade, Visibility.Hidden); else if (animate && this.waitBallade.Visibility != Visibility.Visible) this.InvokeChangeEllipseVisibility(this.waitBallade, Visibility.Visible); if (!viewBackLink && this.backLink.Visibility != Visibility.Hidden) this.InvokeChangeLabelVisibility(this.backLink, Visibility.Hidden); else if (viewBackLink && this.backLink.Visibility != Visibility.Visible) this.InvokeChangeLabelVisibility(this.backLink, Visibility.Visible); this.InvokeChangeContent(this.textConnexion, text); } #endregion #region Retour au panneau de login private void lnkRetour_Click(object sender, RoutedEventArgs e) { DoubleAnimation da3 = new DoubleAnimation(); da3.From = 1; da3.To = 0; da3.Duration = new Duration(TimeSpan.FromSeconds(1)); da3.Completed += new EventHandler(da3_Completed); this.grdConnect.BeginAnimation(Rectangle.OpacityProperty, da3); } private void da3_Completed(object sender, EventArgs e) { this.grdConnect.Visibility = Visibility.Hidden; this.grdAuth.Opacity = 0; this.grdAuth.Visibility = Visibility.Visible; DoubleAnimation da4 = new DoubleAnimation(); da4.From = 0; da4.To = 1; da4.Duration = new Duration(TimeSpan.FromSeconds(1)); this.grdAuth.BeginAnimation(Rectangle.OpacityProperty, da4); } #endregion #region Affiche Panneau de la liste Serveur public void InvokeAfficheListeServeur() { this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, new AfficheListeServeurDeleguate(AfficheListeServeur)); } public delegate void AfficheListeServeurDeleguate(); public void AfficheListeServeur() { DoubleAnimation da1 = new DoubleAnimation(); da1.From = this.grdMain.Height; da1.To = 350; da1.Duration = new Duration(TimeSpan.FromSeconds(1.5)); DoubleAnimation da2 = new DoubleAnimation(); da2.From = 451; da2.To = 600; da2.Duration = new Duration(TimeSpan.FromSeconds(1.5)); this.grdMain.BeginAnimation(Rectangle.HeightProperty, da1); this.grdMain.BeginAnimation(Rectangle.WidthProperty, da2); } #endregion } }
Aperçu de l'interface :
Merci d'avance
Partager