Jypeli  5
The simple game programming library
ScoreListWidget.cs
Siirry tämän tiedoston dokumentaatioon.
1 #region MIT License
2 /*
3  * Copyright (c) 2009-2011 University of Jyväskylä, Department of Mathematical
4  * Information Technology.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #endregion
25 
26 /*
27  * Authors: Tomi Karppinen, Tero Jäntti
28  */
29 
30 
31 using System;
32 using System.ComponentModel;
33 using System.Collections.Generic;
34 using Microsoft.Xna.Framework.Graphics;
35 using Jypeli.GameObjects;
36 
37 namespace Jypeli.Widgets
38 {
39  [EditorBrowsable(EditorBrowsableState.Never)]
40  public class ScoreItemWidget : Widget
41  {
42  public Label Position;
43  public Label Name;
44  public Label Score;
45 
46  public ScoreItemWidget()
47  : base( new HorizontalLayout() )
48  {
50  Position = new Label() { Color = Color.Transparent, HorizontalAlignment = HorizontalAlignment.Left };
51  Name = new Label() { Color = Color.Transparent, SizeMode = TextSizeMode.None, HorizontalAlignment = HorizontalAlignment.Left, XMargin = 20, HorizontalSizing = Sizing.Expanding };
53  Add( Position );
54  Add( Name );
55  Add( Score );
56  }
57  }
58 
62  public class ScoreListWidget : ListWidget<ScoreItem, ScoreItemWidget>
63  {
64  Font _font = Font.Default;
65  Color _posColor = Color.Blue;
66  Color _nameColor = Color.Black;
67  Color _scoreColor = Color.Red;
68  string _scoreFormat = "{0}";
69  string _infMarker = "-";
70 
74  public Font Font
75  {
76  get { return _font; }
77  set
78  {
79  _font = value;
80  for ( int i = 0; i < Content.ItemCount; i++ )
81  {
82  Content[i].Position.Font = value;
83  Content[i].Name.Font = value;
84  Content[i].Score.Font = value;
85  }
86  }
87  }
88 
92  public Color PositionColor
93  {
94  get { return _posColor; }
95  set
96  {
97  _posColor = value;
98  for ( int i = 0; i < Content.ItemCount; i++ )
99  Content[i].Position.TextColor = value;
100  }
101  }
102 
106  public Color NameColor
107  {
108  get { return _nameColor; }
109  set
110  {
111  _nameColor = value;
112  for ( int i = 0; i < Content.ItemCount; i++ )
113  Content[i].Name.TextColor = value;
114  }
115  }
116 
120  public Color ScoreColor
121  {
122  get { return _scoreColor; }
123  set
124  {
125  _scoreColor = value;
126  for ( int i = 0; i < Content.ItemCount; i++ )
127  Content[i].Score.TextColor = value;
128  }
129  }
130 
134  public string ScoreFormat
135  {
136  get { return _scoreFormat; }
137  set
138  {
139  _scoreFormat = value;
140  Reset();
141  }
142  }
143 
147  public string InfinityMarker
148  {
149  get { return _infMarker; }
150  set
151  {
152  _infMarker = value;
153  Reset();
154  }
155  }
156 
161  public ScoreListWidget( ScoreList list )
162  : base( list )
163  {
164  }
165 
166  internal ScoreListWidget()
167  : base( new ScoreList() )
168  {
169  }
170 
171  internal protected override ScoreItemWidget CreateWidget( ScoreItem item )
172  {
173  var w = new ScoreItemWidget();
174  w.Position.Font = Font;
175  w.Position.TextColor = PositionColor;
176  w.Position.Text = String.Format( "{0}.", item.Position );
177  w.Name.Font = Font;
178  w.Name.TextColor = NameColor;
179  w.Name.Text = item.Name;
180  w.Score.Font = Font;
181  w.Score.TextColor = ScoreColor;
182  w.Score.Text = double.IsInfinity( item.Score ) ? InfinityMarker : String.Format( ScoreFormat, item.Score );
183  return w;
184  }
185  }
186 }
double Score
Pistemäärä
Definition: ScoreList.cs:207
HorizontalAlignment
Asemointi vaakasuunnassa.
Definition: View.cs:177
override ScoreItemWidget CreateWidget(ScoreItem item)
Listakomponentti. Voidaan liittää listaan, joka toteuttaa INotifyList-rajapinnan. Tällöin listaan teh...
Definition: ListWidget.cs:155
static readonly Color Black
Musta.
Definition: Color.cs:494
static readonly Color Red
Punainen.
Definition: Color.cs:804
Fontti.
Definition: Font.cs:22
Sizing
Olion koon asettaminen asettelijan sisällä.
Definition: ILayout.cs:38
Tekstikenttä.
Definition: Label.cs:65
Nimi ja pisteet.
Definition: ScoreList.cs:193
Asettelee widgetit riviin vaakasuunnassa.
Käyttöliittymän komponentti.
Definition: Appearance.cs:9
Käyttöliittymäkomponentti, joka näyttää parhaat pisteet.
string Name
Nimi
Definition: ScoreList.cs:201
static readonly Color Transparent
Läpinäkyvä väri.
Definition: Color.cs:869
Parhaiden pisteiden lista.
Definition: ScoreList.cs:41
static readonly Font Default
OletusFontti.
Definition: Font.cs:27
static readonly Color Blue
Sininen.
Definition: Color.cs:504
Väri.
Definition: Color.cs:13
ScoreListWidget(ScoreList list)
Luo uuden ruudulla näytettävän parhaiden pisteiden listan.