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

Revision 4507, 3.7 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
30
31using System;
32using System.Collections.Generic;
33using System.Linq;
34using System.Text;
35using System.ComponentModel;
36using Jypeli.GameObjects;
37
38namespace Jypeli.Widgets
39{
40    /// <summary>
41    /// Ikkuna, joka sisältää käyttäjän määrittelemän viestin ja OK-painikkeen.
42    /// Ikkunan koko määräytyy automaattisesti tekstin ja ruudun koon mukaan.
43    /// </summary>
44    public class MessageWindow : Window
45    {
46        /// <summary>
47        /// Viesti.
48        /// </summary>
49        public Label Message { get; private set; }
50
51        /// <summary>
52        /// OK-painike
53        /// </summary>
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
69        /// <summary>
70        /// Alustaa uuden viesti-ikkunan.
71        /// </summary>
72        /// <param name="question">Kysymys</param>
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}
Note: See TracBrowser for help on using the repository browser.