Jypeli  9
The simple game programming library
HighScoreWindow.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 
33 namespace Jypeli.Widgets
34 {
38  public class HighScoreWindow : CustomQueryWindow<ScoreListWidget>
39  {
40  double lastScore;
41  string nameStr = "";
42 
46  public InputWindow NameInputWindow { get; private set; }
47 
52  {
53  get { return QueryWidget; }
54  }
55 
59  public int MaxNameLength
60  {
61  get { return NameInputWindow.MaxCharacters; }
62  set { NameInputWindow.MaxCharacters = value; }
63  }
64 
65  internal override bool OkButtonOnPhone { get { return true; } }
66 
72  public HighScoreWindow( string message, ScoreList list )
73  : base( message )
74  {
75  Initialize( list );
76  }
77 
85  public HighScoreWindow( double width, double height, string message, ScoreList list )
86  : base( width, height, message )
87  {
88  Initialize( list );
89  }
90 
91  private void Initialize( ScoreList list )
92  {
93  this.List.Bind( list );
94  NameInputWindow = new InputWindow( "Congratulations, you got a high score of %p points! Please enter your name." );
95  AddedToGame += AddControls;
96  }
97 
107  public HighScoreWindow( string normalMessage, string nameMessage, ScoreList list, double newScore )
108  : base( normalMessage )
109  {
110  Initialize( list );
111  NameInputWindow.Message.Text = nameMessage;
112  ShowNameInput( newScore );
113  }
114 
126  public HighScoreWindow( double width, double height, string normalMessage, string nameMessage, ScoreList list, double newScore )
127  : base( width, height, normalMessage )
128  {
129  Initialize( list );
130  NameInputWindow.Message.Text = nameMessage;
131  ShowNameInput( newScore );
132  }
133 
138  public void ShowNameInput( double newScore )
139  {
140  this.lastScore = newScore;
141 
142  if ( ( this.List.Items as ScoreList).Qualifies( newScore ) )
143  {
144  if ( IsAddedToGame ) showNameWindow();
145  else AddedToGame += showNameWindow;
146  }
147  }
148 
149  void AddControls()
150  {
151  var l = Jypeli.Game.Instance.PhoneBackButton.Listen( Close, null ).InContext( this );
152  associatedListeners.Add(l);
153  }
154 
156  {
157  AddedToGame -= showNameWindow;
158  IsVisible = false;
159 
161  NameInputWindow.Message.Text = String.Format( NameInputWindow.Message.Text.Replace( "%p", "{0}" ), lastScore );
162  NameInputWindow.InputBox.Text = ( List.Items as ScoreList ).LastEnteredName;
165  }
166 
167  void nameEntered( InputWindow sender )
168  {
169  sender.TextEntered -= nameEntered;
171 
172  string newName = sender.InputBox.Text.Trim();
173  if ( !string.IsNullOrEmpty( newName ) )
174  ( List.Items as ScoreList ).Add( newName, lastScore );
175 
176  IsVisible = true;
177  }
178 
179  protected override ScoreListWidget CreateQueryWidget()
180  {
181  return new ScoreListWidget() { Color = Color.Transparent };
182  }
183  }
184 }
Jypeli.Widgets.HighScoreWindow.nameStr
string nameStr
Definition: HighScoreWindow.cs:41
Jypeli.CustomQueryWindow.Message
Label Message
Viesti tai kysymys.
Definition: CustomQueryWindow.cs:42
Jypeli.Widgets.HighScoreWindow.HighScoreWindow
HighScoreWindow(string normalMessage, string nameMessage, ScoreList list, double newScore)
Luo uuden parhaiden pisteiden ikkunan. Tämä versio antaa pelaajan kirjoittaa nimensä listalle jos tul...
Definition: HighScoreWindow.cs:107
Jypeli.InputWindow.MaxCharacters
int MaxCharacters
Suurin määrä merkkejä joita tekstilaatikkoon voi kirjoittaa.
Definition: InputWindow.cs:50
Jypeli.Widgets.HighScoreWindow.MaxNameLength
int MaxNameLength
Pisin mahdollinen nimi, jonka listaan voi syöttää.
Definition: HighScoreWindow.cs:60
Jypeli.Widgets.HighScoreWindow.CreateQueryWidget
override ScoreListWidget CreateQueryWidget()
Definition: HighScoreWindow.cs:179
Jypeli
Definition: Automobile.cs:5
Jypeli.Widgets.HighScoreWindow.HighScoreWindow
HighScoreWindow(string message, ScoreList list)
Luo uuden parhaiden pisteiden ikkunan.
Definition: HighScoreWindow.cs:72
Jypeli.ScoreList
Parhaiden pisteiden lista.
Definition: ScoreList.cs:42
Jypeli.Widgets.HighScoreWindow.NameInputWindow
InputWindow NameInputWindow
Nimensyöttöikkuna.
Definition: HighScoreWindow.cs:46
Jypeli.Game.PhoneBackButton
BackButton PhoneBackButton
Puhelimen takaisin-näppäin.
Definition: Controls.cs:67
Jypeli.InputWindow
Ikkuna, joka sisältää käyttäjän määrittelemän kysymyksen, tekstinsyöttökentän ja OK-painikkeen....
Definition: InputWindow.cs:43
Jypeli.InputBox.Text
override string? Text
Definition: InputBox.cs:88
Jypeli.Widgets.HighScoreWindow.List
ScoreListWidget List
Listakomponentti.
Definition: HighScoreWindow.cs:52
Jypeli.Widgets.HighScoreWindow.HighScoreWindow
HighScoreWindow(double width, double height, string normalMessage, string nameMessage, ScoreList list, double newScore)
Luo uuden parhaiden pisteiden ikkunan. Tämä versio antaa pelaajan kirjoittaa nimensä listalle jos tul...
Definition: HighScoreWindow.cs:126
Jypeli.Widgets.HighScoreWindow.ShowNameInput
void ShowNameInput(double newScore)
Näyttää nimensyöttöikkunan.
Definition: HighScoreWindow.cs:138
Jypeli.Widgets.HighScoreWindow.lastScore
double lastScore
Definition: HighScoreWindow.cs:40
Jypeli.Widgets.HighScoreWindow.nameEntered
void nameEntered(InputWindow sender)
Definition: HighScoreWindow.cs:167
Jypeli.CustomQueryWindow< ScoreListWidget >::QueryWidget
W QueryWidget
Kysymyskomponentti.
Definition: CustomQueryWindow.cs:47
Jypeli.Game.Instance
static Game Instance
Käynnissä olevan pelin pääolio.
Definition: Game.cs:90
Jypeli.Color.Transparent
static readonly Color Transparent
Läpinäkyvä väri.
Definition: Color.cs:878
Jypeli.Game.Add
void Add(Light light)
Lisää valon peliin. Nykyisellään valoja voi olla ainoastaan yksi kappale. Toistaiseksi ei tuettu Wind...
Definition: Effects.cs:27
Jypeli.Widgets.HighScoreWindow.Initialize
void Initialize(ScoreList list)
Definition: HighScoreWindow.cs:91
Jypeli.ListWidget.Bind
void Bind(INotifyList< T > list)
Sitoo olemassaolevan listan tähän näyttöön. Kun listaa muutetaan, näytetyt arvot päivittyvät automaat...
Definition: ListWidget.cs:304
Jypeli.ListWidget.Items
INotifyList< T > Items
Listan alkiot.
Definition: ListWidget.cs:173
Jypeli.CustomQueryWindow
Definition: CustomQueryWindow.cs:36
Jypeli.BackButton.Listen
Listener Listen(Action handler, string helpText)
Kuuntelee puhelimen takaisin-näppäintä.
Definition: BackButton.cs:31
Jypeli.InputWindow.TextEntered
InputWindowHandler TextEntered
Tapahtuu kun käyttäjä on syöttänyt tekstin ja painanut OK / sulkenut ikkunan.
Definition: InputWindow.cs:77
Jypeli.Widgets.ScoreListWidget
Käyttöliittymäkomponentti, joka näyttää parhaat pisteet.
Definition: ScoreListWidget.cs:60
Jypeli.Widgets.HighScoreWindow.OkButtonOnPhone
override bool OkButtonOnPhone
Definition: HighScoreWindow.cs:65
Jypeli.Color
Väri.
Definition: Color.cs:13
Jypeli.Widgets.HighScoreWindow.AddControls
void AddControls()
Definition: HighScoreWindow.cs:149
Jypeli.Widgets
Definition: Background.cs:34
System
Definition: CFFauxAttributes.cs:29
Jypeli.InputWindow.InputBox
InputBox InputBox
Vastauslaatikko.
Definition: InputWindow.cs:59
Jypeli.Widgets.HighScoreWindow
Parhaiden pisteiden ikkuna.
Definition: HighScoreWindow.cs:39
Jypeli.Widgets.HighScoreWindow.HighScoreWindow
HighScoreWindow(double width, double height, string message, ScoreList list)
Luo uuden parhaiden pisteiden ikkunan.
Definition: HighScoreWindow.cs:85
Jypeli.Label.Text
virtual string Text
Teksti.
Definition: Label.cs:92
Jypeli.Game
Definition: Content.cs:46
Jypeli.Widgets.HighScoreWindow.showNameWindow
void showNameWindow()
Definition: HighScoreWindow.cs:155