Jypeli  5
The simple game programming library
YesNoWindow.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 using System;
31 using System.Collections.Generic;
32 using System.Linq;
33 using System.Text;
34 
35 namespace Jypeli.Widgets
36 {
41  {
45  public event Action Yes;
46 
50  public event Action No;
51 
52  private void OnYes()
53  {
54  if ( Yes != null ) Yes();
55  }
56 
57  private void OnNo()
58  {
59  if ( No != null ) No();
60  }
61 
66  public YesNoWindow( string question )
67  : this( question, "Yes", "No" )
68  {
69  }
70 
71  public YesNoWindow( string question, string yesString, string noString )
72  : base( question, yesString, noString )
73  {
74  AddItemHandler( 0, OnYes );
75  AddItemHandler( 1, OnNo );
76 
77  Buttons[0].Color = Color.Green;
78  Buttons[0].AddShortcut( Button.A );
79 
80  Buttons[1].Color = Color.DarkRed;
81  Buttons[1].AddShortcut( Button.B );
82  DefaultCancel = 1;
83 
84  if ( yesString.Length > 0 && noString.Length > 0 )
85  {
86  Key yesKey = Jypeli.Controls.Keyboard.FromChar( yesString[0] );
87  Key noKey = Jypeli.Controls.Keyboard.FromChar( noString[0] );
88 
89  if ( yesKey != noKey )
90  {
91  Buttons[0].AddShortcut( yesKey );
92  Buttons[1].AddShortcut( noKey );
93  }
94  }
95  }
96  }
97 }
Action No
Tapahtuu kun käyttäjä valitsee "ei"-vaihtoehdon.
Definition: YesNoWindow.cs:50
static readonly Color Green
Vihreä.
Definition: Color.cs:644
static Key FromChar(char c)
Palauttaa näppäimen merkille c. Jos merkille ei ole näppäintä, palautetaan Key.None.
Definition: Keyboard.cs:68
Ikkuna, joka kysyy käyttäjältä kyllä tai ei -kysymyksen.
Definition: YesNoWindow.cs:40
YesNoWindow(string question, string yesString, string noString)
Definition: YesNoWindow.cs:71
Action Yes
Tapahtuu kun käyttäjä valitsee "kyllä"-vaihtoehdon.
Definition: YesNoWindow.cs:45
Näppäimistö peliohjaimena.
Definition: Keyboard.cs:41
Button
Definition: Button.cs:34
YesNoWindow(string question)
Luo uuden kyselyikkunan.
Definition: YesNoWindow.cs:66
Väri.
Definition: Color.cs:13
Key
Näppäimistön näppäin.
Definition: Key.cs:37
static readonly Color DarkRed
Tumma punainen.
Definition: Color.cs:594
Ikkuna, joka antaa käyttäjän valita yhden annetuista vaihtoehdoista.