Jypeli  5
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 using System.Collections.Generic;
33 using System.Linq;
34 using System.Text;
35 using System.ComponentModel;
36 using Jypeli.GameObjects;
37 
38 namespace Jypeli.Widgets
39 {
44  public class MessageWindow : Window
45  {
49  public Label Message { get; private set; }
50 
54  public PushButton OKButton { get; private set; }
55 
56  public override Color Color
57  {
58  get
59  {
60  return base.Color;
61  }
62  set
63  {
64  OKButton.Color = Color.Darker( value, 40 );
65  base.Color = value;
66  }
67  }
68 
73  public MessageWindow( string question )
74  {
75  Layout = new VerticalLayout { Spacing = 20, LeftPadding = 15, RightPadding = 15, TopPadding = 15, BottomPadding = 15 };
76 
77  Message = new Label( 400, 100, question ) { SizeMode = TextSizeMode.Wrapped, VerticalSizing = Sizing.Expanding };
78  Add( Message );
79 
80 #if !WINDOWS_PHONE
81  OKButton = new PushButton( "OK" );
82  OKButton.Clicked += new Action( Close );
83  Add( OKButton );
84 #endif
85 
86  AddedToGame += AddListeners;
87  }
88 
89  private void AddListeners()
90  {
91 #if WINDOWS_PHONE
92  Game.Instance.TouchPanel.Listen( ButtonState.Pressed, delegate { Close(); }, null ).InContext( this );
93  Game.Instance.PhoneBackButton.Listen( delegate { Close(); }, null ).InContext( this );
94 #else
95  Game.Instance.Keyboard.Listen( Key.Enter, ButtonState.Pressed, Close, null ).InContext( this );
96  Game.Instance.Keyboard.Listen( Key.Space, ButtonState.Pressed, Close, null ).InContext( this );
97  Game.Instance.ControllerOne.Listen(Button.A, ButtonState.Pressed, Close, null).InContext(this);
98  Game.Instance.ControllerOne.Listen(Button.B, ButtonState.Pressed, Close, null).InContext(this);
99 #endif
100  }
101  }
102 }
PhoneBackButton PhoneBackButton
Definition: Game.cs:260
static Color Darker(Color c, int howMuch)
Antaa tummemman värin. Vähentaa jokaista kolmea osaväriä arvon howMuch verran.
Definition: Color.cs:407
Sizing
Olion koon asettaminen asettelijan sisällä.
Definition: ILayout.cs:38
Tekstikenttä.
Definition: Label.cs:65
ButtonState
Napin (minkä tahansa) asento.
Definition: ButtonState.cs:37
static Game Instance
Definition: Game.cs:149
GamePad ControllerOne
Peliohjain yksi.
Definition: Game.cs:265
Peliluokka reaaliaikaisille peleille.
Definition: DebugScreen.cs:10
Button
Definition: Button.cs:34
Asettelee widgetit päällekäin, järjestyksessä ylhäältä alas.
MessageWindow(string question)
Alustaa uuden viesti-ikkunan.
Keyboard Keyboard
Näppäimistö.
Definition: Game.cs:248
TouchPanel TouchPanel
Kosketusnäyttö. Vain kännykässä.
Definition: Game.cs:258
Väri.
Definition: Color.cs:13
Ikkuna, joka sisältää käyttäjän määrittelemän viestin ja OK-painikkeen. Ikkunan koko määräytyy automa...
Key
Näppäimistön näppäin.
Definition: Key.cs:37