Jypeli  9
The simple game programming library
SplashScreen.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 
3 namespace Jypeli.Widgets
4 {
8  public class SplashScreen : Window
9  {
10  private string _controlHelp = DefaultControlHelp;
11  private string _loadingText = "Loading...";
12 
16  public Label NameLabel { get; private set; }
17 
21  public Label CopyrightLabel { get; private set; }
22 
26  public Label AuthorsLabel { get; private set; }
27 
31  public StringListWidget TextBody { get; private set; }
32 
37  public Label StartLabel { get; private set; }
38 
42  public string ControlHelp
43  {
44  get { return _controlHelp; }
45  set
46  {
47  if (StartLabel.Text == _controlHelp) StartLabel.Text = value;
48  _controlHelp = value;
49  }
50  }
51 
55  public string LoadingText
56  {
57  get { return _loadingText; }
58  set
59  {
60  if (StartLabel.Text == _loadingText) StartLabel.Text = value;
61  _loadingText = value;
62  }
63  }
64 
69  public event Action GameStarted;
70 
71  #region Default dimensions
72 
73  private static double DefaultWidth
74  {
75  get
76  {
77 #if WINDOWS_PHONE || ANDROID
78  return Game.Screen.Width;
79 #else
80  return 600;
81 #endif
82  }
83  }
84 
85  private static double DefaultTextWidth
86  {
87  get
88  {
89 #if WINDOWS_PHONE
90  return Game.Instance.Phone.DisplayResolution == DisplayResolution.Small ? 300 : 500;
91 #else
92  return 500;
93 #endif
94  }
95  }
96 
97  private static double DefaultHeight
98  {
99  get
100  {
101 #if WINDOWS_PHONE || ANDROID
102  return Game.Screen.Height;
103 #else
104  return 600;
105 #endif
106  }
107  }
108 
109  private static double DefaultSpacing
110  {
111  get
112  {
113 #if WINDOWS_PHONE
114  return Game.Instance.Phone.DisplayResolution == WP7.DisplayResolution.Small ? 0 : 20;
115 #else
116  return 50;
117 #endif
118  }
119  }
120 
121  private static string DefaultControlHelp
122  {
123  get
124  {
125 #if WINDOWS_PHONE || ANDROID
126  return "Start the game by tapping here";
127 #elif XBOX
128  return "Start the game by pressing A";
129 #else
130  return "Start the game by pressing Enter";
131 #endif
132  }
133  }
134 
135  #endregion
136 
140  public SplashScreen(string gameName, string authors, string copyright, string textBody)
141  : base(DefaultWidth, DefaultHeight)
142  {
143  Layout = new VerticalLayout() { Spacing = DefaultSpacing };
144 
149 
150  double targetWidth = 2 * this.Width / 3;
151  NameLabel.TextScale = new Vector(targetWidth / NameLabel.TextSize.X, 2);
152  NameLabel.SizeMode = TextSizeMode.Wrapped;
154 
155  TextBody = new StringListWidget();
157  TextBody.Width = DefaultTextWidth;
159  TextBody.Color = new Color(0, 0, 255, 4);
160 #if WINDOWS_PHONE || ANDROID
161  if ( DefaultTextWidth < 500 )
163  else
165 #endif
166  TextBody.Text = textBody;
167 
168  StartLabel.SizeMode = TextSizeMode.Wrapped;
169 
170  AddedToGame += AddControls;
171 
172  Add(NameLabel);
173  Add(CopyrightLabel);
174  Add(AuthorsLabel);
175  Add(TextBody);
176  Add(StartLabel);
177  }
178 
179  private void AddControls()
180  {
181  var l1 = Game.Keyboard.Listen(Key.Enter, ButtonState.Pressed, BeginLoad, null, StartLabel).InContext(this);
182  var l2 = Game.Keyboard.Listen(Key.Escape, ButtonState.Pressed, Game.Instance.Exit, null).InContext(this); ;
183  var l3 = Game.Mouse.Listen(MouseButton.Left, ButtonState.Down, BeginLoad, null, StartLabel).InContext(this);
184  associatedListeners.AddItems(l1, l2, l3);
185 
186  for (int i = 0; i < Game.GameControllers.Count; i++)
187  {
188  l1 = Game.GameControllers[i].Listen(Button.A, ButtonState.Pressed, BeginLoad, null, StartLabel).InContext(this);
189  l2 = Game.GameControllers[i].Listen(Button.B, ButtonState.Pressed, Game.Instance.Exit, null).InContext(this);
190  associatedListeners.AddItems(l1, l2);
191  }
192 
193  l1 = Game.TouchPanel.ListenOn(StartLabel, ButtonState.Pressed, delegate { BeginLoad(StartLabel); }, null).InContext(this);
194  l2 = Game.PhoneBackButton.Listen(Game.Instance.Exit, null).InContext(this);
195  associatedListeners.AddItems(l1, l2);
196  }
197 
198  private void BeginLoad(Label aloitusohje)
199  {
200  // Don't trigger twice
201  if (aloitusohje.Text == LoadingText)
202  return;
203 
204  aloitusohje.TextColor = Color.Red;
205  aloitusohje.Text = LoadingText;
207  }
208 
209  private void ResumeLoad()
210  {
211  Close();
212  if (GameStarted != null)
213  GameStarted();
214  }
215 
216  private Label InitializeTextDisplay(string text, Color textColor)
217  {
218  Label kentta = new Label(text);
219 
222  kentta.Width = DefaultTextWidth;
223  kentta.Text = text;
224  kentta.TextColor = textColor;
225 
226  return kentta;
227  }
228  }
229 }
Jypeli.Font.DefaultLarge
static readonly Font DefaultLarge
Suuri oletusfontti.
Definition: Font.cs:52
Jypeli.StringListWidget.Text
string? Text
Kaikki listan alkiot rivinvaihdoilla erotettuna.
Definition: StringListWidget.cs:92
Jypeli.Label.TextSize
Vector TextSize
Näytettävän tekstin koko. Ei välttämättä sama kuin Size.
Definition: Label.cs:202
Jypeli.Widgets.SplashScreen.LoadingText
string LoadingText
Latausteksti.
Definition: SplashScreen.cs:56
Jypeli.Widgets.SplashScreen.GameStarted
Action GameStarted
Tapahtuu kun ruudusta poistutaan. Tee varsinaiset pelin alustukset tämän tapahtuman käsittelijässä.
Definition: SplashScreen.cs:69
Jypeli.Color.Black
static readonly Color Black
Musta.
Definition: Color.cs:503
Jypeli.Timer.SingleShot
static void SingleShot(double seconds, Action onTimeout)
Kutsuu aliohjelmaa onTimeout annetun ajan kuluttua. Ajastin luodaan automaattisesti.
Definition: Timer.cs:220
Jypeli.Mouse.Listen
Listener Listen(MouseButton button, ButtonState state, Action handler, string helpText)
Kuuntelee hiiren nappulan painalluksia.
Definition: Mouse.cs:350
Jypeli.Vector.X
double X
Definition: Vector.cs:312
Jypeli.StringListWidget
Käyttöliittymäkomponentti, joka näyttää listan merkkijonoja.
Definition: StringListWidget.cs:41
Jypeli.Color.Red
static readonly Color Red
Punainen.
Definition: Color.cs:813
Jypeli.TextSizeMode
TextSizeMode
Definition: Label.cs:38
Jypeli.Widgets.SplashScreen.InitializeTextDisplay
Label InitializeTextDisplay(string text, Color textColor)
Definition: SplashScreen.cs:216
Jypeli.Widgets.SplashScreen.ControlHelp
string ControlHelp
Kontrolliohje (Aloita peli painamalla Enter / Xbox A).
Definition: SplashScreen.cs:43
Jypeli.Widgets.SplashScreen.AuthorsLabel
Label AuthorsLabel
Pelin tekijät näyttävä tekstikenttä.
Definition: SplashScreen.cs:26
Jypeli.Window.Close
void Close()
Sulkee ikkunan.
Definition: Window.cs:213
Jypeli.Label
Tekstikenttä.
Definition: Label.cs:66
Jypeli.Label.HorizontalAlignment
HorizontalAlignment HorizontalAlignment
Tekstin sijoitus vaakasuunnassa. Vaikuttaa vain, jos tekstikentän koko on suurempi kuin tekstin koko ...
Definition: Label.cs:223
Jypeli.Widgets.SplashScreen.CopyrightLabel
Label CopyrightLabel
Pelin tekijänoikeudet näyttävä tekstikenttä.
Definition: SplashScreen.cs:21
Jypeli.StringListWidget.ItemAligment
HorizontalAlignment ItemAligment
Listan alkioiden sijoitus vaakasuunnassa.
Definition: StringListWidget.cs:78
Jypeli.Label.TextScale
Vector TextScale
Tekstin skaalaus. Oletus (1,1) ; isompi suurempi.
Definition: Label.cs:117
Jypeli.Game.PhoneBackButton
BackButton PhoneBackButton
Puhelimen takaisin-näppäin.
Definition: Controls.cs:67
Jypeli.Game.Phone
Device Phone
Phone-olio esim. puhelimen tärisyttämiseen.
Definition: Game.cs:109
Jypeli.ScreenView.Width
double Width
Näytön leveys x-suunnassa.
Definition: View.cs:222
Jypeli.Game.Mouse
Mouse Mouse
Hiiri.
Definition: Controls.cs:49
Jypeli.Window.Color
override Color Color
Ikkunan väri.
Definition: Window.cs:51
Jypeli.Label.SizeMode
TextSizeMode SizeMode
Kuinka tekstikentän koko määräytyy.
Definition: Label.cs:193
Jypeli.Widgets.SplashScreen.StartLabel
Label StartLabel
Aloita peli painamalla... -tekstin näyttävä tekstikenttä. Käytä ominaisuuksia ControlHelp ja LoadingT...
Definition: SplashScreen.cs:37
Jypeli.Game.Instance
static Game Instance
Käynnissä olevan pelin pääolio.
Definition: Game.cs:90
Jypeli.Color.Green
static readonly Color Green
Vihreä.
Definition: Color.cs:648
Jypeli.HorizontalAlignment
HorizontalAlignment
Asemointi vaakasuunnassa.
Definition: View.cs:441
Jypeli.Font.DefaultSmall
static readonly Font DefaultSmall
Pieni oletusfontti.
Definition: Font.cs:45
Jypeli.ScreenView.Height
double Height
Näytön korkeus y-suunnassa.
Definition: View.cs:235
Jypeli.VerticalLayout
Asettelee widgetit päällekäin, järjestyksessä ylhäältä alas.
Definition: VerticalLayout.cs:39
Jypeli.Widgets.SplashScreen.BeginLoad
void BeginLoad(Label aloitusohje)
Definition: SplashScreen.cs:198
Jypeli.Game.Screen
static ScreenView Screen
Näytön dimensiot, eli koko ja reunat.
Definition: Graphics.cs:90
Jypeli.StringListWidget.Font
Font Font
Tekstifontti.
Definition: StringListWidget.cs:50
Jypeli.Color.Blue
static readonly Color Blue
Sininen.
Definition: Color.cs:513
Jypeli.Widgets.SplashScreen.ResumeLoad
void ResumeLoad()
Definition: SplashScreen.cs:209
Jypeli.BackButton.Listen
Listener Listen(Action handler, string helpText)
Kuuntelee puhelimen takaisin-näppäintä.
Definition: BackButton.cs:31
Jypeli.Widgets.SplashScreen.DefaultHeight
static double DefaultHeight
Definition: SplashScreen.cs:98
Jypeli.Game.GameControllers
List< GamePad > GameControllers
Lista kaikista peliohjaimista järjestyksessä.
Definition: Controls.cs:72
Jypeli.Button
Button
Definition: Button.cs:35
Jypeli.Widgets.SplashScreen.NameLabel
Label NameLabel
Pelin nimen näyttävä tekstikenttä.
Definition: SplashScreen.cs:16
Jypeli.Color
Väri.
Definition: Color.cs:13
Jypeli.Widgets.SplashScreen.AddControls
void AddControls()
Definition: SplashScreen.cs:179
Jypeli.StringListWidget.TextColor
Color TextColor
Tekstin väri.
Definition: StringListWidget.cs:64
Jypeli.Widgets.SplashScreen
Aloitusruutu, joka voidaan näyttää ennen pelin käynnistämistä.
Definition: SplashScreen.cs:9
Jypeli.Widgets.SplashScreen.TextBody
StringListWidget TextBody
Päätekstikenttä.
Definition: SplashScreen.cs:31
Jypeli.Widgets.SplashScreen.DefaultSpacing
static double DefaultSpacing
Definition: SplashScreen.cs:110
Jypeli.MouseButton
MouseButton
Hiiren napit.
Definition: MouseButton.cs:7
Jypeli.Widgets.SplashScreen.DefaultTextWidth
static double DefaultTextWidth
Definition: SplashScreen.cs:86
Jypeli.Widgets.SplashScreen._controlHelp
string _controlHelp
Definition: SplashScreen.cs:10
Jypeli.Game.Keyboard
Keyboard Keyboard
Näppäimistö.
Definition: Controls.cs:44
Jypeli.Widgets
Definition: Background.cs:34
Jypeli.Label.TextColor
Color TextColor
Tekstin väri.
Definition: Label.cs:207
Jypeli.Widgets.SplashScreen.SplashScreen
SplashScreen(string gameName, string authors, string copyright, string textBody)
Alustaa aloitusruudun.
Definition: SplashScreen.cs:140
Jypeli.DisplayResolution.Small
static readonly DisplayResolution Small
Pieni tarkkuus (WVGA, 400 x 240). WP7-yhteensopivuustila, ei varsinaisesti paranna suorituskykyä.
Definition: DisplayResolution.cs:11
Jypeli.ButtonState
ButtonState
Napin (minkä tahansa) asento.
Definition: ButtonState.cs:37
Jypeli.Vector
2D-vektori.
Definition: Vector.cs:59
System
Definition: CFFauxAttributes.cs:29
Jypeli.Timer
Ajastin, joka voidaan asettaa laukaisemaan tapahtumia tietyin väliajoin.
Definition: Timer.cs:38
Jypeli.Widget.associatedListeners
List< Listener > associatedListeners
Tähän listaan lisätyt kuuntelijat tuhotaan automaattisesti kun Widget poistetaan pelistä.
Definition: Control.cs:14
Jypeli.Widgets.SplashScreen._loadingText
string _loadingText
Definition: SplashScreen.cs:11
Jypeli.Game.TouchPanel
TouchPanel TouchPanel
Kosketusnäyttö
Definition: Controls.cs:62
Jypeli.TouchPanel.ListenOn
Listener ListenOn(GameObject obj, HoverState hoverstate, ButtonState buttonstate, TouchHandler handler, string helpText)
Kuuntelee kosketusnäyttöä olion päällä.
Definition: TouchPanel.cs:354
Jypeli.Window
Ikkuna.
Definition: Window.cs:37
Jypeli.Font
Fontti.
Definition: Font.cs:23
Jypeli.Label.Text
virtual string Text
Teksti.
Definition: Label.cs:92
Jypeli.VerticalAlignment
VerticalAlignment
Asemointi pystysuunnassa.
Definition: View.cs:462
Jypeli.Widgets.SplashScreen.DefaultControlHelp
static string DefaultControlHelp
Definition: SplashScreen.cs:122
Jypeli.Label.VerticalAlignment
VerticalAlignment VerticalAlignment
Tekstin sijoitus pystysuunnassa. Vaikuttaa vain, jos tekstikentän koko on suurempi kuin tekstin koko ...
Definition: Label.cs:230
Jypeli.Game
Definition: Content.cs:46
Jypeli.Key
Key
Näppäimistön näppäin.
Definition: Key.cs:38
Jypeli.DisplayResolution
Definition: DisplayResolution.cs:6
Jypeli.Keyboard.Listen
Listener Listen(Key k, ButtonState state, Action handler, string helpText)
Kuuntelee näppäinten painalluksia.
Definition: Keyboard.cs:161
Jypeli.Widgets.SplashScreen.DefaultWidth
static double DefaultWidth
Definition: SplashScreen.cs:74