Jypeli  9
The simple game programming library
MessageWindow.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
34 {
39  public class MessageWindow : Window
40  {
44  public Label Message { get; private set; }
45 
49  public PushButton OKButton { get; private set; }
50 
51  public override Color Color
52  {
53  get
54  {
55  return base.Color;
56  }
57  set
58  {
59  OKButton.Color = Color.Darker( value, 40 );
60  base.Color = value;
61  }
62  }
63 
68  public MessageWindow( string message )
69  {
70  Layout = new VerticalLayout { Spacing = 20, LeftPadding = 15, RightPadding = 15, TopPadding = 15, BottomPadding = 15 };
71 
72  int maxWidth = (int)Game.Screen.Width - 30;
73 
74  Message = new Label( Math.Min(maxWidth, Font.Default.MeasureSize(message).X), 100, message )
75  { SizeMode = TextSizeMode.Wrapped, VerticalSizing = Sizing.Expanding };
76  Add( Message );
77 
78 #if !WINDOWS_PHONE && !ANDROID
79  OKButton = new PushButton( "OK" );
80  OKButton.Clicked += new Action( Close );
81  Add( OKButton );
82 #endif
83 
84  AddedToGame += AddListeners;
85  }
86 
87  private void AddListeners()
88  {
89  var l1 = Game.Instance.PhoneBackButton.Listen( delegate { Close(); }, null ).InContext( this );
90  var l2 = Game.Instance.TouchPanel.Listen( ButtonState.Pressed, delegate { Close(); }, null ).InContext( this );
91  var l3 = Game.Instance.Keyboard.Listen( Key.Enter, ButtonState.Pressed, Close, null ).InContext( this );
92  var l4 = Game.Instance.Keyboard.Listen( Key.Space, ButtonState.Pressed, Close, null ).InContext( this );
93  associatedListeners.AddItems(l1, l2, l3, l4);
94 
95  foreach ( var controller in Game.Instance.GameControllers )
96  {
97  l1 = controller.Listen( Button.A, ButtonState.Pressed, Close, null ).InContext( this );
98  l2 = controller.Listen( Button.B, ButtonState.Pressed, Close, null ).InContext( this );
99  associatedListeners.AddItems(l1, l2);
100  }
101  }
102  }
103 }
Jypeli.Vector.X
double X
Definition: Vector.cs:312
Jypeli
Definition: Automobile.cs:5
Jypeli.TextSizeMode
TextSizeMode
Definition: Label.cs:38
Jypeli.Font.Default
static readonly Font Default
Oletusfontti.
Definition: Font.cs:30
Jypeli.Window.Close
void Close()
Sulkee ikkunan.
Definition: Window.cs:213
Jypeli.Label
Tekstikenttä.
Definition: Label.cs:66
Jypeli.MessageWindow.OKButton
PushButton OKButton
OK-painike
Definition: MessageWindow.cs:49
Jypeli.Game.PhoneBackButton
BackButton PhoneBackButton
Puhelimen takaisin-näppäin.
Definition: Controls.cs:67
Jypeli.ScreenView.Width
double Width
Näytön leveys x-suunnassa.
Definition: View.cs:222
Jypeli.TouchPanel.Listen
Listener Listen(ButtonState state, TouchHandler handler, string helpText)
Kuuntelee kosketusnäyttöä.
Definition: TouchPanel.cs:296
Jypeli.Game.Instance
static Game Instance
Käynnissä olevan pelin pääolio.
Definition: Game.cs:90
Jypeli.Font.MeasureSize
Vector MeasureSize(string str)
Laskee tekstin koon fontilla.
Definition: Font.cs:282
Jypeli.VerticalLayout
Asettelee widgetit päällekäin, järjestyksessä ylhäältä alas.
Definition: VerticalLayout.cs:39
Jypeli.Game.Screen
static ScreenView Screen
Näytön dimensiot, eli koko ja reunat.
Definition: Graphics.cs:90
Jypeli.MessageWindow
Ikkuna, joka sisältää käyttäjän määrittelemän viestin ja OK-painikkeen. Ikkunan koko määräytyy automa...
Definition: MessageWindow.cs:40
Jypeli.PushButton
Painonappi.
Definition: PushButton.cs:40
Jypeli.MessageWindow.Message
Label Message
Viesti.
Definition: MessageWindow.cs:44
Jypeli.BackButton.Listen
Listener Listen(Action handler, string helpText)
Kuuntelee puhelimen takaisin-näppäintä.
Definition: BackButton.cs:31
Jypeli.Game.GameControllers
List< GamePad > GameControllers
Lista kaikista peliohjaimista järjestyksessä.
Definition: Controls.cs:72
Jypeli.Button
Button
Definition: Button.cs:35
Jypeli.PushButton.Color
override Color Color
Definition: PushButton.cs:127
Jypeli.Color
Väri.
Definition: Color.cs:13
Jypeli.Game.Keyboard
Keyboard Keyboard
Näppäimistö.
Definition: Controls.cs:44
Jypeli.ButtonState
ButtonState
Napin (minkä tahansa) asento.
Definition: ButtonState.cs:37
System
Definition: CFFauxAttributes.cs:29
Jypeli.MessageWindow.AddListeners
void AddListeners()
Definition: MessageWindow.cs:87
Jypeli.Widget.associatedListeners
List< Listener > associatedListeners
Tähän listaan lisätyt kuuntelijat tuhotaan automaattisesti kun Widget poistetaan pelistä.
Definition: Control.cs:14
Jypeli.Color.Darker
static Color Darker(Color c, int howMuch)
Antaa tummemman värin. Vähentaa jokaista kolmea osaväriä arvon howMuch verran.
Definition: Color.cs:417
Jypeli.Game.TouchPanel
TouchPanel TouchPanel
Kosketusnäyttö
Definition: Controls.cs:62
Jypeli.Window
Ikkuna.
Definition: Window.cs:37
Jypeli.Font
Fontti.
Definition: Font.cs:23
Jypeli.PushButton.Clicked
Action Clicked
Tapahtuu kun nappia on painettu.
Definition: PushButton.cs:144
Jypeli.MessageWindow.MessageWindow
MessageWindow(string message)
Alustaa uuden viesti-ikkunan.
Definition: MessageWindow.cs:68
Jypeli.Game
Definition: Content.cs:46
Jypeli.Color.Color
Color(XnaColor c)
Definition: Color.cs:38
Jypeli.Key
Key
Näppäimistön näppäin.
Definition: Key.cs:38
Jypeli.Sizing
Sizing
Olion koon asettaminen asettelijan sisällä.
Definition: ILayout.cs:39
Jypeli.Keyboard.Listen
Listener Listen(Key k, ButtonState state, Action handler, string helpText)
Kuuntelee näppäinten painalluksia.
Definition: Keyboard.cs:161