Jypeli 10
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
31using System;
32using System.ComponentModel;
33
34namespace Jypeli.Widgets
35{
36
37#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public class ScoreItemWidget : Widget
40
41 {
42 public Label Place;
43 public Label Name;
44 public Label Score;
45
47 : base( new HorizontalLayout() )
48 {
51 Name = new Label() { Color = Color.Transparent, SizeMode = TextSizeMode.None, HorizontalAlignment = HorizontalAlignment.Left, XMargin = 20, HorizontalSizing = Sizing.Expanding };
53 Add( Place );
54 Add( Name );
55 Add( Score );
56 }
57 }
58#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
59
63 public class ScoreListWidget : ListWidget<ScoreItem, ScoreItemWidget>
64 {
69 string _scoreFormat = "{0}";
70 string _infMarker = "-";
71
75 public Font Font
76 {
77 get { return _font; }
78 set
79 {
80 _font = value;
81 for ( int i = 0; i < Content.ItemCount; i++ )
82 {
83 Content[i].Place.Font = value;
84 Content[i].Name.Font = value;
85 Content[i].Score.Font = value;
86 }
87 }
88 }
89
94 {
95 get { return _posColor; }
96 set
97 {
98 _posColor = value;
99 for ( int i = 0; i < Content.ItemCount; i++ )
100 Content[i].Place.TextColor = value;
101 }
102 }
103
108 {
109 get { return _nameColor; }
110 set
111 {
112 _nameColor = value;
113 for ( int i = 0; i < Content.ItemCount; i++ )
114 Content[i].Name.TextColor = value;
115 }
116 }
117
122 {
123 get { return _scoreColor; }
124 set
125 {
126 _scoreColor = value;
127 for ( int i = 0; i < Content.ItemCount; i++ )
128 Content[i].Score.TextColor = value;
129 }
130 }
131
135 public string ScoreFormat
136 {
137 get { return _scoreFormat; }
138 set
139 {
140 _scoreFormat = value;
141 Reset();
142 }
143 }
144
148 public string InfinityMarker
149 {
150 get { return _infMarker; }
151 set
152 {
153 _infMarker = value;
154 Reset();
155 }
156 }
157
163 : base( list )
164 {
165 }
166
168 : base( new ScoreList() )
169 {
170 }
171
173 internal protected override ScoreItemWidget CreateWidget( ScoreItem item )
174 {
175 var w = new ScoreItemWidget();
176 w.Place.Font = Font;
177 w.Place.TextColor = PositionColor;
178 w.Place.Text = String.Format( "{0}.", item.Position );
179 w.Name.Font = Font;
180 w.Name.TextColor = NameColor;
181 w.Name.Text = item.Name;
182 w.Score.Font = Font;
183 w.Score.TextColor = ScoreColor;
184 w.Score.Text = double.IsInfinity( item.Score ) ? InfinityMarker : String.Format( ScoreFormat, item.Score );
185 return w;
186 }
187 }
188}
Fontti.
Definition: Font.cs:24
static readonly Font Default
Oletusfontti.
Definition: Font.cs:31
virtual Sizing HorizontalSizing
Koon asettaminen vaakasuunnassa, kun olio on asettelijan sisällä.
Definition: Layout.cs:18
void Add(IGameObject childObject)
Lisää annetun peliolion tämän olion lapseksi. Lapsiolio liikkuu tämän olion mukana.
Definition: ChildObjects.cs:98
Asettelee widgetit riviin vaakasuunnassa.
Tekstikenttä.
Definition: Label.cs:70
Listakomponentti. Voidaan liittää listaan, joka toteuttaa INotifyList-rajapinnan. Tällöin listaan teh...
Definition: ListWidget.cs:175
ScrollableList< O > Content
Listan sisältö
Definition: ListWidget.cs:188
void Reset()
Tyhjentää widgetin sisällön
Definition: ListWidget.cs:253
Parhaiden pisteiden lista.
Definition: ScoreList.cs:42
Käyttöliittymän komponentti.
Definition: Appearance.cs:6
Käyttöliittymäkomponentti, joka näyttää parhaat pisteet.
override ScoreItemWidget CreateWidget(ScoreItem item)
Color PositionColor
Sijoitusten väri.
ScoreListWidget(ScoreList list)
Luo uuden ruudulla näytettävän parhaiden pisteiden listan.
Color ScoreColor
Pisteiden väri.
string ScoreFormat
Pisteiden muoto (oletus on {0})
string InfinityMarker
Äärettömän pistemäärän merkki. Oletus '-'
Sizing
Olion koon asettaminen asettelijan sisällä.
Definition: ILayout.cs:39
TextSizeMode
Kuinka tekstikentän kokoa käsitellään.
Definition: Label.cs:42
HorizontalAlignment
Asemointi vaakasuunnassa.
Definition: View.cs:466
Väri.
Definition: Color.cs:13
static readonly Color Blue
Sininen.
Definition: Color.cs:566
static readonly Color Transparent
Läpinäkyvä väri.
Definition: Color.cs:931
static readonly Color Black
Musta.
Definition: Color.cs:556
static readonly Color Red
Punainen.
Definition: Color.cs:866
Nimi ja pisteet.
Definition: ScoreList.cs:222
string Name
Nimi
Definition: ScoreList.cs:229
double Score
Pistemäärä
Definition: ScoreList.cs:235