Jypeli  9
The simple game programming library
InputWindow.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 
32 #if WINDOWS_PHONE || ANDROID
33 using Microsoft.Xna.Framework;
34 #endif
35 
36 namespace Jypeli
37 {
42  public class InputWindow : CustomQueryWindow<InputBox>
43  {
44  internal override bool OkButtonOnPhone { get { return true; } }
45 
49  public int MaxCharacters
50  {
51  get { return InputBox.MaxCharacters; }
52  set { InputBox.MaxCharacters = value; }
53  }
54 
59  {
60  get { return QueryWidget; }
61  }
62 
67  public bool ShowWindowOnPhone { get; set; }
68 
72  public delegate void InputWindowHandler( InputWindow sender );
73 
78 
79  private void OnTextEntered()
80  {
81  TextEntered?.Invoke(this);
82  }
83 
88  public InputWindow( string question )
89  : base( question )
90  {
91  Init();
92  }
93 
100  public InputWindow( double width, double height, string question )
101  : base( width, height, question )
102  {
103  Init();
104  }
105 
106  private void Init()
107  {
108  Closed += new WindowHandler(InputWindow_Closed);
109  AddedToGame += AddListeners;
110 
111 #if ANDROID
112  // Display window at the top of the screen to make space for the virtual keyboard
113 
114  // 1.5 is just a magic number that makes it show up properly on my phone,
115  // logically it should be positioned perfectly at the top with 2.0 but
116  // that doesn't seem to be the case
117  Y += Game.Screen.Top - (Height / 1.5);
118 #endif
119  }
120 
121  protected override InputBox CreateQueryWidget()
122  {
123  //double widthInChars = Width / Font.Default.CharacterWidth;
124  //return new InputBox( (int)widthInChars - 1 );
125  return new InputBox( 40 );
126  }
127 
128  static void InputWindow_Closed( Window sender )
129  {
130  ((InputWindow)sender).OnTextEntered();
131  }
132 
133  private void Cancel()
134  {
135  InputBox.Text = "";
136  Close();
137  }
138 
139  private void AddListeners()
140  {
141  var l1 = Game.Instance.Keyboard.Listen( Key.Enter, ButtonState.Pressed, Close, null ).InContext( this );
142  var l2 = Game.Instance.Keyboard.Listen( Key.Escape, ButtonState.Pressed, Cancel, null ).InContext( this );
143  var l3 = Game.Instance.PhoneBackButton.Listen( Cancel, null ).InContext( this );
144  associatedListeners.AddItems(l1, l2, l3);
145  }
146 
147 #if WINDOWS_PHONE && TESTING
148  void TouchTextEntered( IAsyncResult result )
149  {
150  string typedText = Guide.EndShowKeyboardInput( result );
151  InputBox.Text = typedText != null ? typedText : "";
152  Close();
153  }
154 #endif
155  }
156 }
Jypeli.InputWindow.AddListeners
void AddListeners()
Definition: InputWindow.cs:139
Jypeli.InputWindow.InputWindow
InputWindow(double width, double height, string question)
Alustaa uuden tekstinkyselyikkunan.
Definition: InputWindow.cs:100
Microsoft.Xna
Definition: JypeliContentManager.cs:6
Jypeli.InputWindow.OnTextEntered
void OnTextEntered()
Definition: InputWindow.cs:79
Jypeli.InputWindow.MaxCharacters
int MaxCharacters
Suurin määrä merkkejä joita tekstilaatikkoon voi kirjoittaa.
Definition: InputWindow.cs:50
Jypeli.InputWindow.InputWindowHandler
delegate void InputWindowHandler(InputWindow sender)
Syöttöikkunatapahtumien käsittelijä.
Jypeli
Definition: Automobile.cs:5
Microsoft
Definition: JypeliContentManager.cs:6
Microsoft.Xna.Framework
Definition: JypeliContentManager.cs:6
Jypeli.InputWindow.ShowWindowOnPhone
bool ShowWindowOnPhone
Näytetäänkö ikkuna puhelimella. Oletuksena false, jolloin näytetään vain puhelimen oma tekstinsyöttöi...
Definition: InputWindow.cs:67
Jypeli.InputBox.MaxCharacters
int MaxCharacters
Suurin määrä merkkejä joita tekstilaatikkoon voi kirjoittaa.
Definition: InputBox.cs:61
Jypeli.InputWindow.InputWindow_Closed
static void InputWindow_Closed(Window sender)
Definition: InputWindow.cs:128
Jypeli.Game.PhoneBackButton
BackButton PhoneBackButton
Puhelimen takaisin-näppäin.
Definition: Controls.cs:67
Jypeli.InputWindow
Ikkuna, joka sisältää käyttäjän määrittelemän kysymyksen, tekstinsyöttökentän ja OK-painikkeen....
Definition: InputWindow.cs:43
Jypeli.InputWindow.Cancel
void Cancel()
Definition: InputWindow.cs:133
Jypeli.ScreenView.Top
double Top
Näytön yläreunan y-koordinaatti.
Definition: View.cs:308
Jypeli.InputBox.Text
override string? Text
Definition: InputBox.cs:88
Jypeli.CustomQueryWindow< InputBox >::QueryWidget
W QueryWidget
Kysymyskomponentti.
Definition: CustomQueryWindow.cs:47
Jypeli.InputBox
Laatikko, johon käyttäjä voi syöttää tekstiä.
Definition: InputBox.cs:42
Jypeli.Game.Instance
static Game Instance
Käynnissä olevan pelin pääolio.
Definition: Game.cs:90
Jypeli.Game.Screen
static ScreenView Screen
Näytön dimensiot, eli koko ja reunat.
Definition: Graphics.cs:90
Jypeli.InputWindow.OkButtonOnPhone
override bool OkButtonOnPhone
Definition: InputWindow.cs:44
Jypeli.CustomQueryWindow
Definition: CustomQueryWindow.cs:36
Jypeli.InputWindow.InputWindow
InputWindow(string question)
Alustaa uuden tekstinkyselyikkunan.
Definition: InputWindow.cs:88
Jypeli.BackButton.Listen
Listener Listen(Action handler, string helpText)
Kuuntelee puhelimen takaisin-näppäintä.
Definition: BackButton.cs:31
Jypeli.InputWindow.TextEntered
InputWindowHandler TextEntered
Tapahtuu kun käyttäjä on syöttänyt tekstin ja painanut OK / sulkenut ikkunan.
Definition: InputWindow.cs:77
Jypeli.InputWindow.Init
void Init()
Definition: InputWindow.cs:106
Jypeli.Game.Keyboard
Keyboard Keyboard
Näppäimistö.
Definition: Controls.cs:44
Jypeli.InputWindow.CreateQueryWidget
override InputBox CreateQueryWidget()
Definition: InputWindow.cs:121
Jypeli.ButtonState
ButtonState
Napin (minkä tahansa) asento.
Definition: ButtonState.cs:37
Jypeli.InputWindow.InputBox
InputBox InputBox
Vastauslaatikko.
Definition: InputWindow.cs:59
Jypeli.Window
Ikkuna.
Definition: Window.cs:37
Jypeli.Game
Definition: Content.cs:46
Jypeli.Key
Key
Näppäimistön näppäin.
Definition: Key.cs:38
Jypeli.Keyboard.Listen
Listener Listen(Key k, ButtonState state, Action handler, string helpText)
Kuuntelee näppäinten painalluksia.
Definition: Keyboard.cs:161