source: 2013/30/MiskaK/MW2(My Warfare 2)/Paranneltu Jypeli/Widgets/YesNoWindow.cs @ 4507

Revision 4507, 3.2 KB checked in by anlakane, 6 years ago (diff)

Talletus.

Line 
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
30using System;
31using System.Collections.Generic;
32using System.Linq;
33using System.Text;
34
35namespace Jypeli.Widgets
36{
37    /// <summary>
38    /// Ikkuna, joka kysyy käyttäjältä kyllä tai ei -kysymyksen.
39    /// </summary>
40    public class YesNoWindow : MultiSelectWindow
41    {
42        /// <summary>
43        /// Tapahtuu kun käyttäjä valitsee "kyllä"-vaihtoehdon.
44        /// </summary>
45        public event Action Yes;
46
47        /// <summary>
48        /// Tapahtuu kun käyttäjä valitsee "ei"-vaihtoehdon.
49        /// </summary>
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
62        /// <summary>
63        /// Luo uuden kyselyikkunan.
64        /// </summary>
65        /// <param name="question">Kysymys</param>
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}
Note: See TracBrowser for help on using the repository browser.