本文整理汇总了C#中InputState.IsMenuSelect方法的典型用法代码示例。如果您正苦于以下问题:C# InputState.IsMenuSelect方法的具体用法?C# InputState.IsMenuSelect怎么用?C# InputState.IsMenuSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputState
的用法示例。
在下文中一共展示了InputState.IsMenuSelect方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleInput
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public void HandleInput(InputState input)
{
Vector2 mouseFocus = new Vector2(-1, -1);
// Check NumPad and Number Keys for manual number entering
String keyString;
Keys key = new Keys();
int keyboardInt = -1;
for (int i = 0; i < 10; i++)
{
keyString = "D" + i.ToString();
key = (Keys)Enum.Parse(typeof(Keys), keyString);
if (input.IsNewKeyPress(key))
keyboardInt = i;
keyString = "NumPad" + i.ToString();
key = (Keys)Enum.Parse(typeof(Keys), keyString);
if (input.IsNewKeyPress(key))
keyboardInt = i;
}
if (keyboardInt != -1)
AddToAnswer(keyboardInt.ToString());
if ( input.IsMouseChanged() ||input.IsMousePressed())
mouseFocus = buttonTable.CheckFocus(input);
if (mouseFocus.X != -1)
{
focus = mouseFocus;
if (input.IsNewMouseReleased())
HandleButtonInput();
}
else
{
buttonTable.SetPressed(focus, false);
buttonTable.SetFocus(focus, false);
// Move up?
if (input.IsMenuUp())
{
focus = new Vector2(focus.X, focus.Y - 1);
if (focus.Y < 1)
focus.Y = buttonTable.Rows;
}
// Move down?
if (input.IsMenuDown())
{
focus = new Vector2(focus.X, focus.Y + 1);
if (focus.Y > buttonTable.Rows)
focus.Y = 1;
}
// Move left?
if (input.IsMenuLeft())
{
focus = new Vector2(focus.X - 1, focus.Y);
if (focus.X < 1)
focus.X = buttonTable.Cols;
}
// Move right?
if (input.IsMenuRight())
{
focus = new Vector2(focus.X + 1, focus.Y);
if (focus.X > buttonTable.Cols)
focus.X = 1;
}
buttonTable.SetFocus(focus, true);
}
// Check if the button is being pressed or if the user
// is asking to exit the screen.
if (input.IsMenuSelect())
{
HandleButtonInput();
buttonTable.SetPressed(focus, true);
}
else if (input.IsMenuCancel())
{
Exiting = true;
}
}
示例2: HandleInput
/// <summary>
/// Responds to user input, accepting or cancelling the message box.
/// </summary>
public override void HandleInput(InputState input)
{
PlayerIndex playerIndex;
// We pass in our ControllingPlayer, which may either be null (to
// accept input from any player) or a specific index. If we pass a null
// controlling player, the InputState helper returns to us which player
// actually provided the input. We pass that through to our Accepted and
// Cancelled events, so they can tell which player triggered them.
if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
{
// Raise the accepted event, then exit the message box.
if (Accepted != null)
Accepted(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen();
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
{
// Raise the cancelled event, then exit the message box.
if (Cancelled != null)
Cancelled(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen();
}
}
示例3: HandleInput
/// <summary>
/// Responds to user input, accepting or cancelling the message box.
/// </summary>
public override void HandleInput(InputState input)
{
PlayerIndex playerIndex;
// We pass in our ControllingPlayer, which may either be null (to
// accept input from any player) or a specific index. If we pass a null
// controlling player, the InputState helper returns to us which player
// actually provided the input. We pass that through to our Accepted and
// Cancelled events, so they can tell which player triggered them.
if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
{
// Raise the accepted event, then exit the message box.
if (Accepted != null)
Accepted(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen();
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
{
// Raise the cancelled event, then exit the message box.
if (Cancelled != null)
Cancelled(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen();
}
// look for any taps that occurred and select any entries that were tapped
foreach (GestureSample gesture in input.Gestures)
{
if (gesture.GestureType == GestureType.Tap)
{
Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
if (tapLocation.X > 10 && tapLocation.X < 470 &&
tapLocation.Y > 10 && tapLocation.Y < 790)
{
ExitScreen();
}
}
}
}
示例4: HandleInput
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public override void HandleInput(InputState input)
{
// Move to the previous menu entry?
if (input.IsMenuUp(ControllingPlayer))
{
EventManager.QueueEvent(new GameEvent(EventType.MenuHover));
_selectedEntry--;
if (_selectedEntry < 0)
_selectedEntry = _menuEntries.Count - 1;
}
// Move to the next menu entry?
if (input.IsMenuDown(ControllingPlayer))
{
EventManager.QueueEvent(new GameEvent(EventType.MenuHover));
_selectedEntry++;
if (_selectedEntry >= _menuEntries.Count)
_selectedEntry = 0;
}
// Mouse selection of menu entries
for (var i = 0; i < _menuEntries.Count; i++)
// ReSharper disable PossibleLossOfFraction
if (ScreenManager != null && (input.LastMouseState.Y >= _menuEntries[i].Position.Y - ScreenManager.Font.LineSpacing / 2 && input.LastMouseState.Y < _menuEntries[i].Position.Y + ScreenManager.Font.LineSpacing / 2
// ReSharper restore PossibleLossOfFraction
&& input.LastMouseState.X > _menuEntries[i].Position.X && input.LastMouseState.X < _menuEntries[i].Position.X + _menuEntries[i].GetWidth(this)))
{
if (i != _selectedEntry && TransitionAlpha > 0.9999)
{
EventManager.QueueEvent(new GameEvent(EventType.MenuHover));
}
_selectedEntry = i;
if (input.IsNewLeftClick())
{
OnSelectEntry(i, PlayerIndex.One);
}
}
// Accept or cancel the menu? We pass in our ControllingPlayer, which may
// either be null (to accept input from any player) or a specific index.
// If we pass a null controlling player, the InputState helper returns to
// us which player actually provided the input. We pass that through to
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
PlayerIndex playerIndex;
if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
{
OnSelectEntry(_selectedEntry, playerIndex);
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
{
OnCancel(playerIndex);
}
}
示例5: HandleInput
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public void HandleInput(InputState input)
{
Vector2 mouseFocus = new Vector2(-1, -1);
if (input.IsMouseChanged())
mouseFocus = buttonTable.CheckFocus(input);
if (mouseFocus.X != -1)
focus = mouseFocus;
else
{
buttonTable.SetFocus(focus, false);
// Move up?
if (input.IsMenuUp())
{
focus = new Vector2(focus.X, focus.Y - 1);
if (focus.Y < 1)
focus.Y = buttonTable.Rows;
}
// Move down?
if (input.IsMenuDown())
{
focus = new Vector2(focus.X, focus.Y + 1);
if (focus.Y > buttonTable.Rows)
focus.Y = 1;
}
// Move left?
if (input.IsMenuLeft())
{
focus = new Vector2(focus.X - 1, focus.Y);
if (focus.X < 1)
focus.X = buttonTable.Cols;
}
// Move right?
if (input.IsMenuRight())
{
focus = new Vector2(focus.X + 1, focus.Y);
if (focus.X > buttonTable.Cols)
focus.X = 1;
}
buttonTable.SetFocus(focus, true);
}
// Check if the button is being pressed or if the user
// is asking to exit the screen.
if (input.IsMenuSelect())
{
buttonTable.TogglePressed(focus);
}
else if (input.IsMenuCancel())
{
Exiting = true;
}
}
示例6: HandleInput
public override void HandleInput(InputState input)
{
// previous entry
if (input.IsMenuUp(ControllingPlayer))
{
useMouse = false;
selectedEntry--;
if (selectedEntry < 0)
selectedEntry = menuEntries.Count - 1;
if (!menuEntries[selectedEntry].Enabled && selectedEntry >= 0)
{
for (int i = selectedEntry; i >= 0; i--)
{
if (menuEntries[i].Enabled)
{
selectedEntry = i;
break;
}
}
return;
}
}
// next entry
if (input.IsMenuDown(ControllingPlayer))
{
useMouse = false;
selectedEntry++;
if (selectedEntry >= menuEntries.Count)
selectedEntry = 0;
if (!menuEntries[selectedEntry].Enabled && selectedEntry < menuEntries.Count)
{
for (int i = selectedEntry; i < menuEntries.Count - 1; i++)
{
if (menuEntries[i].Enabled)
{
selectedEntry = i;
break;
}
}
return;
}
}
if (input.LastMouseState.X != mousePos.X || input.LastMouseState.Y != mousePos.Y)
{
useMouse = true;
}
for (int i = 0; i < menuEntries.Count; i++)
{
if (input.LastMouseState.Y > menuEntries[i].Position.Y - Assets.menuFont.LineSpacing / 2 &&
input.LastMouseState.Y < menuEntries[i].Position.Y + Assets.menuFont.LineSpacing / 2 &&
input.LastMouseState.X > menuEntries[i].Position.X &&
input.LastMouseState.X < menuEntries[i].Position.X + Assets.menuFont.MeasureString(menuEntries[i].Text).X && useMouse)
{
selectedEntry = i;
}
}
// Accept or cancel the menu? We pass in our ControllingPlayer, which may
// either be null (to accept input from any player) or a specific index.
// If we pass a null controlling player, the InputState helper returns to
// us which player actually provided the input. We pass that through to
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
PlayerIndex playerIndex;
if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
{
//if (OptionsFile.IsSound())
// Assets.menuSelectSound.Play();
OnSelectEntry(selectedEntry, playerIndex);
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
{
//if (OptionsFile.IsSound())
// Assets.menuSelectSound.Play();
OnCancel(playerIndex);
}
else if (input.IsNewLeftMouseClick())
{
for (int i = 0; i < menuEntries.Count; i++)
{
if (input.LastMouseState.Y > menuEntries[i].Position.Y &&
input.LastMouseState.Y < menuEntries[i].Position.Y + Assets.menuFont.LineSpacing)
{
//if (OptionsFile.IsSound())
// Assets.menuSelectSound.Play();
OnSelectEntry(i, playerIndex);
}
}
}
//.........这里部分代码省略.........
示例7: HandleInput
/// <summary>
/// Responds to user input, accepting or cancelling the message box.
/// </summary>
public override void HandleInput(InputState input)
{
PlayerIndex playerIndex;
// We pass in our ControllingPlayer, which may either be null (to
// accept input from any player) or a specific index. If we pass a null
// controlling player, the InputState helper returns to us which player
// actually provided the input. We pass that through to our Accepted and
// Cancelled events, so they can tell which player triggered them.
if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
{
// Raise the accepted event, then exit the message box.
if (Accepted != null)
Accepted(this, new PlayerIndexEventArgs(playerIndex));
#if WINRT
NewName = GamePage.Instance.GetNameEntry();
GamePage.Instance.HideNameEntry();
#endif
if (NewName.Trim() != string.Empty) GameManager.PlayerName = NewName;
Settings.Save();
ExitScreen();
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
{
// Raise the cancelled event, then exit the message box.
if (Cancelled != null)
Cancelled(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen();
}
//foreach (GestureSample gesture in input.Gestures)
//{
// if (gesture.GestureType == GestureType.Tap)
// {
// convert the position to a Point that we can test against a Rectangle
if (input.TapPosition != null)
{
Point tapLocation = new Point((int)input.TapPosition.Value.X, (int)input.TapPosition.Value.Y);
if (okRect.Contains(tapLocation))
{
if (Accepted != null)
Accepted(this, new PlayerIndexEventArgs(playerIndex));
#if WINRT
NewName = GamePage.Instance.GetNameEntry();
GamePage.Instance.HideNameEntry();
#endif
if (NewName.Trim() != string.Empty) GameManager.PlayerName = NewName;
ExitScreen();
}
if (cancelRect.Contains(tapLocation))
{
if (Cancelled != null)
Cancelled(this, new PlayerIndexEventArgs(playerIndex));
ExitScreen();
}
}
// }
//}
}
示例8: HandleInput
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public override void HandleInput(InputState input)
{
// Move to the previous menu entry?
if (input.IsMenuUp(ControllingPlayer))
{
selectedEntry--;
if (selectedEntry < 0)
selectedEntry = menuEntries.Count - 1;
}
// Move to the next menu entry?
if (input.IsMenuDown(ControllingPlayer))
{
selectedEntry++;
if (selectedEntry >= menuEntries.Count)
selectedEntry = 0;
}
// Accept or cancel the menu? We pass in our ControllingPlayer, which may
// either be null (to accept input from any player) or a specific index.
// If we pass a null controlling player, the InputState helper returns to
// us which player actually provided the input. We pass that through to
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
PlayerIndex playerIndex;
if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
{
OnSelectEntry(selectedEntry, playerIndex);
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
{
OnCancel(playerIndex);
}
}
示例9: HandleInput
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public override void HandleInput(InputState input)
{
// we cancel the current menu screen if the user presses the back button
PlayerIndex player;
if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
{
OnCancel(player);
}
// look for any taps that occurred and select any entries that were tapped
foreach (GestureSample gesture in input.Gestures)
{
if (gesture.GestureType == GestureType.Tap)
{
// convert the position to a Point that we can test against a Rectangle
Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
// iterate the entries to see if any were tapped
for (int i = 0; i < menuEntries.Count; i++)
{
MenuEntry menuEntry = menuEntries[i];
if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation))
{
// select the entry. since gestures are only available on Windows Phone,
// we can safely pass PlayerIndex.One to all entries since there is only
// one player on Windows Phone.
OnSelectEntry(i, PlayerIndex.One);
}
}
}
}
if (input.IsMenuUp(ControllingPlayer))
{
selectedEntry--;
if (selectedEntry < 0)
selectedEntry = menuEntries.Count - 1;
}
// Move to the next menu entry?
if (input.IsMenuDown(ControllingPlayer))
{
selectedEntry++;
if (selectedEntry >= menuEntries.Count)
selectedEntry = 0;
}
// Accept or cancel the menu?
if (input.IsMenuSelect(ControllingPlayer,out player))
{
OnSelectEntry(selectedEntry,player);
}
else if (input.IsMenuCancel(ControllingPlayer,out player))
{
if (this.GetType() != typeof(MainMenuScreen))
{
this.ExitScreen();
}
else
{
this.ScreenManager.Game.Exit();
}
}
}
示例10: HandleInput
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public override void HandleInput(InputState input)
{
int dirX = 0, dirY = 0;
//figure out the directions to move
if (input.IsMenuUp(ControllingPlayer))
dirX = -1;
if (input.IsMenuDown(ControllingPlayer))
dirX = 1;
if (input.IsMenuLeft(ControllingPlayer))
dirY = -1;
if (input.IsMenuRight(ControllingPlayer))
dirY = 1;
//if horizontal orientation, swap directions
if (!IsVertical) {
int temp = dirX;
dirX = dirY;
dirY = temp;
}
//process row movement
if (dirX != 0) {
if (selectedEntry.Column < 0 || selectedEntry.Column >= menuColumns.Length)
selectedEntry.Column = 0;
int length = menuColumns[selectedEntry.Column].Count;
do {
selectedEntry.Row += dirX;
if (selectedEntry.Row < 0)
selectedEntry.Row = length - 1;
selectedEntry.Row %= length;
} while (!Selected.Enabled);
}
//handle column selection (left/right)
//ultimately, index selection will also be in here
// if the index can go up/down, let it. otherwise, change columns. easy.
if (dirY != 0) {
if (selectedEntry.Row < 0 || selectedEntry.Row >= menuColumns[selectedEntry.Column].Count)
selectedEntry.Row = 0;
if (relativeSelection)
ChangeColumnsRelative(dirY);
else
ChangeColumns(dirY);
}
// Accept or cancel the menu? We pass in our ControllingPlayer, which may
// either be null (to accept input from any player) or a specific index.
// If we pass a null controlling player, the InputState helper returns to
// us which player actually provided the input. We pass that through to
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
PlayerIndex playerIndex;
if (input.IsMenuSelect(ControllingPlayer, out playerIndex)) {
OnSelectEntry(selectedEntry, playerIndex);
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) {
OnCancel(playerIndex);
}
#region Mouse Handling
#if WINDOWS
bool clicked = input.IsNewMouseButtonPress(MouseButtons.Left);
if (input.IsMouseMoved() || clicked) {
mousePosition.X = input.CurrentMouseState.X;
mousePosition.Y = input.CurrentMouseState.Y;
//check mouse pos against each menu entry and update selection if necessary
if (AllowEmptySelection)
selectedEntry.Column = selectedEntry.Row = selectedEntry.Index = -5;
for (int col = 0; col < menuColumns.Length; col++) {
for (int i = 0; i < menuColumns[col].Count; i++) {
MenuEntry menuEntry = menuColumns[col][i];
if (menuEntry.Contains(mousePosition) && menuEntry.Enabled) {
selectedEntry.Column = col;
selectedEntry.Row = i;
if (clicked)
OnSelectEntry(selectedEntry, PlayerIndex.One);
}
}
}
}
#endif
HandleSpecialInput(input, Selected);
#endregion
}
示例11: HandleInput
public override void HandleInput(InputState input)
{
if (MenuEntries.Count > 0) {
int dir = 0;
// Move to the previous menu entry?
if (input.IsMenuUp(ControllingPlayer)) {
dir = -1;
}
// Move to the next menu entry?
if (input.IsMenuDown(ControllingPlayer)) {
dir = 1;
}
if (dir != 0) {
do {
selected += dir;
if (selected < 0)
selected = menuEntries.Count - 1;
selected %= menuEntries.Count;
} while (!MenuEntries[selected].Enabled);
}
// Accept or cancel the menu? We pass in our ControllingPlayer, which may
// either be null (to accept input from any player) or a specific index.
// If we pass a null controlling player, the InputState helper returns to
// us which player actually provided the input. We pass that through to
// OnSelectEntry and OnCancel, so they can tell which player triggered them.
PlayerIndex playerIndex;
if (input.IsMenuSelect(ControllingPlayer, out playerIndex)) {
OnSelectEntry(selected, playerIndex);
}
else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) {
OnCancel(this, new MenuSelectionEventArgs(SelectedEntry, this, playerIndex));
}
}
}
示例12: HandleInput
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public void HandleInput(InputState input)
{
Vector2 mouseFocus = new Vector2(-1,-1);
if (Input.IsMouseChanged())
mouseFocus = CheckFocus(menuEntries, Input.MouseState);
if (mouseFocus.Y != -1)
selectedEntry = (int)mouseFocus.Y;
else
{
menuEntries[selectedEntry].IsPressed = false;
menuEntries[selectedEntry].IsInFocus = false;
// Move to the previous menu entry?
if (input.IsMenuUp())
{
selectedEntry--;
if (selectedEntry < 0)
selectedEntry = menuEntries.Count - 1;
}
// Move to the next menu entry?
if (input.IsMenuDown())
{
selectedEntry++;
if (selectedEntry >= menuEntries.Count)
selectedEntry = 0;
}
menuEntries[selectedEntry].IsInFocus = true;
}
// Check if the inFocus menu entry has been seletcted or if the player wants to cancel the menu
if (input.IsMenuSelect())
{
menuEntries[selectedEntry].IsPressed = true;
Exiting = true;
}
else if (input.IsMenuCancel())
{
Game.Exit();
}
}