} // end of DeleteAll() public void Update() { if (Active) { // Ensure everything is in the right place before trying any hit testing. if (dirty) { CalcLayout(); dirty = false; } // Check for input. if (Active && itemList.Count > 0 && CommandStack.Peek() == commandMap) { // Allow user to hit esc to exit. if (Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); Deactivate(); return; } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { UpdateTouchInput(); } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { UpdateMouseInput(); } } } // end if active } // end of MouseMenu Update()
} // end of TextDialog UpdateObj c'tor public override void Update() { // Check if we have input focus. if (CommandStack.Peek() == commandMap) { GamePadInput pad = GamePadInput.GetGamePad0(); if (pad.ButtonA.WasPressed && (0 != (parent.Buttons & TextDialogButtons.Accept))) { Accept(); } if (pad.ButtonB.WasPressed && (0 != (parent.Buttons & TextDialogButtons.Cancel))) { Cancel(); } if (pad.ButtonX.WasPressed && (0 != (parent.Buttons & TextDialogButtons.Discard))) { Discard(); } if (pad.ButtonY.WasPressed) { shared.IncrementString(); } } parent.renderObj.RefreshTexture(); } // end of UpdateObj Update()
} // end of EditTextureUpdateObj c'tor /// <summary> /// EditTextureUpdateObj Update() /// </summary> /// <param name="camera"></param> public override void Update() { float secs = Time.WallClockFrameSeconds; // Check if we have input focus. Don't do any input // related update if we don't. if (CommandStack.Peek() == commandMap) { // Grab the current state of the gamepad. GamePadInput pad = GamePadInput.GetGamePad1(); // Switch to Mini-Hub? if (pad.Back.WasPressed) { parent.SwitchToMiniHub(); return; } // Cycle through textures. /* * if (pad.ButtonB.WasPressed) * { * Foley.PlayProgrammingClick(); * shared.editBrushTextureIndex = (shared.editBrushTextureIndex + 1) % 4; // Move to the right. * } */ if (pad.ButtonX.WasPressed) { Foley.PlayProgrammingClick(); //shared.editBrushTextureIndex = (shared.editBrushTextureIndex + 3) % 4; // Move to the left. shared.editBrushTextureIndex = (shared.editBrushTextureIndex + 1) % 4; // Move to the right. } // Texture picker. if (pad.ButtonY.WasPressed) { parent.CurrentUpdateMode = UpdateMode.TexturePicker; return; } // Paint texture? if (pad.ButtonA.WasPressed || (pad.ButtonA.IsPressed && shared.editBrushMoved)) { parent.terrain.UpdateSelectTexture(shared.editBrushTextureIndex, shared.editBrushPosition, shared.editBrushRadius, shared.editBrushIndex); shared.textureSelectModified = true; InGame.inGame.IsLevelDirty = true; } } // end if we have input focus. // Do the common bits of the Update(). UpdateCamera(); UpdateWorld(); UpdateEditBrush(); } // end of EditTextureUpdateObj Update()
} // end of Deactivate() /// <summary> /// Called once per frame by the /// </summary> public void Update() { if (Active) { /// Don't let anyone else grab focus, if anyone has, grab it back. if (CommandStack.Peek() != commandMap) { CommandStack.Pop(commandMap); CommandStack.Push(commandMap); } // Check if we have input focus. if (CommandStack.Peek() == commandMap) { GamePadInput pad = GamePadInput.GetGamePad0(); if (handlerA != null && (pad.ButtonA.WasPressed || KeyboardInput.WasPressed(Keys.A))) { GamePadInput.ClearAllWasPressedState(); GamePadInput.IgnoreUntilReleased(Buttons.A); handlerA(this); } if (handlerB != null && (pad.ButtonB.WasPressed || KeyboardInput.WasPressed(Keys.B))) { GamePadInput.ClearAllWasPressedState(); GamePadInput.IgnoreUntilReleased(Buttons.B); handlerB(this); } if (handlerX != null && (pad.ButtonX.WasPressed || KeyboardInput.WasPressed(Keys.X))) { GamePadInput.ClearAllWasPressedState(); GamePadInput.IgnoreUntilReleased(Buttons.X); handlerX(this); } if (handlerY != null && (pad.ButtonY.WasPressed || KeyboardInput.WasPressed(Keys.Y))) { GamePadInput.ClearAllWasPressedState(); GamePadInput.IgnoreUntilReleased(Buttons.Y); handlerY(this); } } // end if we have input focus. if (dirty) { // Calc max width for text string. maxWidth = (int)(width - 2.0f * margin); RefreshTexture(); } } } // end of Update()
public override void Update() { if (CommandStack.Peek() == commandMap) { GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); GamePadInput.ClearAllWasPressedState(3); parent.PlaceReflex(null, null); } if (Actions.ComboUp.WasPressedOrRepeat) { Actions.ComboUp.ClearAllWasPressedState(); GamePadInput.ClearAllWasPressedState(3); parent.MoveUp(null, null); } if (Actions.ComboDown.WasPressedOrRepeat) { Actions.ComboDown.ClearAllWasPressedState(); GamePadInput.ClearAllWasPressedState(3); parent.MoveDown(null, null); } if (Actions.ComboRight.WasPressed) { // Indent the current block. reflexBlock.Indent(true); } if (Actions.ComboLeft.WasPressed) { // Unindent the current block. reflexBlock.Unindent(true); } } }
public override void Update() { if (!parent.Active) { return; } if (CommandStack.Peek() == parent.commandMap) { bool done = false; if (shared.curFileIndex >= shared.filenames.Count) { done = true; } else { bool doneCurFile = ShowFile(shared.filenames[shared.curFileIndex]); if (doneCurFile) { ++shared.curFileIndex; } } if (done || Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); parent.Deactivate(); BokuGame.bokuGame.loadLevelMenu.LocalLevelMode = LoadLevelMenu.LocalLevelModes.General; BokuGame.bokuGame.loadLevelMenu.ReturnToMenu = LoadLevelMenu.ReturnTo.MainMenu; BokuGame.bokuGame.loadLevelMenu.Activate(); return; } } } // end of Update()
} // end of PreGameBase c'tor public virtual void Update() { // Default Update lets pregame run until user kicks it out. if (commandMap == CommandStack.Peek() && Active) { if (Actions.X.WasPressed) { Actions.X.ClearAllWasPressedState(); Active = false; } // Exit pre-game mode. if (KeyboardInput.WasPressed(Keys.Escape)) { KeyboardInput.ClearAllWasPressedState(Keys.Escape); Active = false; } if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Active = false; InGame.inGame.CurrentUpdateMode = UpdateMode.ToolMenu; } if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); // Leave active so when we come out of the mini-hub we know to re-start pregame. //Active = false; InGame.inGame.SwitchToMiniHub(); } } } // end of PreGameBase Update()
public override void Update() { // Check for input focus. if (commandMap == CommandStack.Peek()) { GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(3); parent.MoveReflex(null, null); } /* * // Replaced w/ auto blank line feature. * if(pad.ButtonY.WasPressed) * { * parent.InsertReflex(null, null); * * GamePadInput.ClearAllWasPressedState(3); * } */ // Cut. if (Actions.Cut.WasPressed) { Actions.Cut.ClearAllWasPressedState(3); reflexBlock.Init(this.parent.LineNumber - 1); reflexBlock.Cut(); } // Copy if (Actions.X.WasPressed) { Actions.X.ClearAllWasPressedState(); // Update the cut/paste buffer with the current ReflexData. reflexBlock.Init(this.parent.LineNumber - 1); reflexBlock.Copy(); HelpOverlay.Pop(); if (ReflexPanel.CutPasteBuffer == null) { HelpOverlay.Push("RowHandleEmptyPasteBuffer"); } else { HelpOverlay.Push("RowHandleFullPasteBuffer"); } } // Paste if (Actions.Paste.WasPressed) { Actions.Paste.ClearAllWasPressedState(3); reflexBlock.Init(this.parent.LineNumber - 1); reflexBlock.Paste(); } } // end of if we have input focus. // Ensure the reflex has the correct indent. //ReflexPanel curPanel = (ReflexPanel)parent.parent; //curPanel.AnimatePanelIndent(false); } // end of Update()
} // end of c'tor public void Update() { changeLanguageMessage.Update(camera); if (active && CommandStack.Peek() == grid.CommandMap) { UIGridElement prevE = grid.SelectionElement; HandleTouchInput(); HandleMouseInput(); HandleGamepadInput(); // Update the grid. grid.Update(ref worldGrid); // If the Update deactived us, bail. if (!active) { return; } // Update help square's positioning to line up with current selection. Vector3 selectionElementOffset = grid.SelectionElement.Position - grid.ScrollOffset; helpSquare.Position = new Vector2(helpSquare.Position.X, selectionElementOffset.Y); // For each element in the grid, calc it's screen space Y position // and give it a slight twist around the Y axis based on this. // Note this assumes that this grid is 1d vertical. for (int j = 0; j < grid.ActualDimensions.Y; j++) { UIGridElement e = grid.Get(0, j); Vector3 pos = Vector3.Transform(e.Position, grid.WorldMatrix); Vector3 rot = Vector3.Zero; float rotationScaling = 0.2f; rot.Y = -rotationScaling * pos.Y; e.Rotation = rot; } if (prevE != grid.SelectionElement) { if (grid.SelectionElement.ShowHelpButton) { helpSquare.Show(); } else { helpSquare.Hide(); } } helpSquare.Update(); GamePadInput.ClearAllWasPressedState(); } // end of if active and have input focus. // Update the text displays. Internally they check if they're active before doing anything. if (active) { InGame.inGame.shared.smallTextDisplay.Update(camera); InGame.inGame.shared.scrollableTextDisplay.Update(camera); } } // end of Update()
/// <summary> /// Called once per frame. /// If camera is null, assumes everything is in screenspace. /// </summary> public void Update(Camera camera) { if (Active) { // Don't let anyone else grab focus, if anyone has, grab it back. if (CommandStack.Peek() != commandMap) { CommandStack.Pop(commandMap); CommandStack.Push(commandMap); } // Check if we have input focus. if (CommandStack.Peek() == commandMap) { GamePadInput pad = GamePadInput.GetGamePad0(); if (handlerA != null && Actions.A.WasPressed) { Actions.A.ClearAllWasPressedState(); Actions.A.IgnoreUntilReleased(); handlerA(this); } if (handlerB != null && Actions.B.WasPressed) { Actions.B.ClearAllWasPressedState(); Actions.B.IgnoreUntilReleased(); handlerB(this); } if (handlerX != null && Actions.X.WasPressed) { Actions.X.ClearAllWasPressedState(); Actions.X.IgnoreUntilReleased(); handlerX(this); } if (handlerY != null && Actions.Y.WasPressed) { Actions.Y.ClearAllWasPressedState(); Actions.Y.IgnoreUntilReleased(); handlerY(this); } Vector2 hit; if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); hit = touch.position; if (camera != null) { hit = MouseInput.AdjustHitPosition(hit, camera, false, false); } hit = hit - pos; HandleTouchInput(hit, touch); } } else { // Since the dialog is screenspace we can use the mouse position directly. hit = MouseInput.PositionVec; if (useRtCoords) { hit = ScreenWarp.ScreenToRT(hit); } hit -= pos; HandleMouseInput(hit); } } // end if we have input focus. RefreshTexture(); } } // end of Update()
/// <summary> /// TopLevelPaletteUpdateObj Update() /// </summary> /// <param name="camera"></param> public override void Update() { float secs = Time.WallClockFrameSeconds; // Check if we have input focus. Don't do any input // related update if we don't. if (CommandStack.Peek() == commandMap) { // Grab the current state of the gamepad. GamePadInput pad = GamePadInput.GetGamePad1(); // Switch to Mini-Hub? if (pad.Back.WasPressed) { GamePadInput.ClearAllWasPressedState(); parent.ResetSim(CurrentLevelFilename()); // Needed to make sure that deactivated objects are actually removed from // the list otherwise they may get saved along with the newly activated ones. parent.Refresh(BokuGame.gameListManager.updateList, BokuGame.gameListManager.renderList); parent.SwitchToMiniHub(); return; } // The start button should always return to run mode. if (pad.Start.WasPressed) { BokuGame.Audio.GetCue("programming add").Play(); parent.CurrentUpdateMode = UpdateMode.RunSim; HelpOverlay.Pop(); return; } // Return to previous mode if (pad.ButtonB.WasPressed) { parent.CurrentUpdateMode = UpdateMode.RunSim; HelpOverlay.Pop(); return; } // Select current mode. if (pad.ButtonA.WasPressed) { BokuGame.Audio.GetCue("programming add").Play(); parent.CurrentUpdateMode = curMode; HelpOverlay.Pop(); // Remove whichever help overlay is active. } // Change selected mode. if (pad.LeftTriggerButton.WasPressed || pad.DPadLeft.WasPressed) { BokuGame.Audio.GetCue("programming click").Play(); MoveToPreviousMode(); SetHelpOverlay(); } if (pad.RightTriggerButton.WasPressed || pad.DPadRight.WasPressed) { BokuGame.Audio.GetCue("programming click").Play(); MoveToNextMode(); SetHelpOverlay(); } } // end if we have input focus. UpdateCamera(); UpdateWorld(); UpdateEditBrush(); } // end of TopLevelPaletteUpdateObj Update()
public override void Update() { // Did we switch modes? if (inputMode != GamePadInput.ActiveMode) { inputMode = GamePadInput.ActiveMode; shared.dirty = true; } if (AuthUI.IsModalActive) { return; } // Input focus and not pushing? if (parent.Active && CommandStack.Peek() == parent.commandMap && shared.pushOffset == 0.0f) { GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); parent.Deactivate(); Foley.PlayShuffle(); shared.dirty = true; } bool moveLeft = false; bool moveRight = false; // left if (Actions.ComboLeft.WasPressedOrRepeat) { moveLeft = true; } // right if (Actions.ComboRight.WasPressedOrRepeat) { moveRight = true; } //touch? if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { TouchContact touch = TouchInput.GetOldestTouch(); Vector2 touchHit = Vector2.Zero; SwipeGestureRecognizer swipeGesture = TouchGestureManager.Get().SwipeGesture; if (swipeGesture.WasSwiped() && swipeGesture.SwipeDirection == Boku.Programming.Directions.East) { moveLeft = true; } else if (swipeGesture.WasSwiped() && swipeGesture.SwipeDirection == Boku.Programming.Directions.West) { moveRight = true; } else if (touch != null) { touchHit = touch.position; if (shared.leftArrowBox.Touched(touch, touchHit)) { moveLeft = true; } if (shared.rightArrowBox.Touched(touch, touchHit)) { moveRight = true; } if (shared.backBox.Touched(touch, touchHit)) { Actions.Cancel.ClearAllWasPressedState(); parent.Deactivate(); Foley.PlayShuffle(); shared.dirty = true; } } } // Mouse hit? else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 mouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y); if (shared.leftArrowBox.LeftPressed(mouseHit)) { moveLeft = true; } if (shared.rightArrowBox.LeftPressed(mouseHit)) { moveRight = true; } if (shared.backBox.LeftPressed(mouseHit)) { Actions.Cancel.ClearAllWasPressedState(); parent.Deactivate(); Foley.PlayShuffle(); shared.dirty = true; } } if (moveLeft) { --shared.curScreen; if (shared.curScreen < 0) { parent.Deactivate(); } Foley.PlayShuffle(); shared.dirty = true; shared.pushOffset = -BokuGame.ScreenSize.X; } if (moveRight) { ++shared.curScreen; if (shared.curScreen >= shared.screenList.Count) { parent.Deactivate(); } Foley.PlayShuffle(); shared.dirty = true; shared.pushOffset = BokuGame.ScreenSize.X; } } if (shared.dirty && shared.curScreen >= 0 && shared.curScreen < shared.screenList.Count) { shared.prevTexture = shared.curTexture; // Get the correct overlay image to use depending on input mode. string name = GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad ? shared.screenList[shared.curScreen].name : shared.screenList[shared.curScreen].mouseName; shared.curTexture = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\HelpScreens\" + name); shared.dirty = false; // Create a twitch to do the push. TwitchManager.Set <float> set = delegate(float val, Object param) { shared.pushOffset = val; }; TwitchManager.CreateTwitch <float>(shared.pushOffset, 0.0f, set, 0.3f, TwitchCurve.Shape.EaseOut); } } // end of Update()
} // end of ClearAllItems() public void Update(Camera camera, ref Matrix parentMatrix) { CommandMap map = CommandStack.Peek(); if (map != commandMap) { return; } // Check for input. if (active && itemList.Count > 0) { GamePadInput pad = GamePadInput.GetGamePad0(); bool mouseDown = false; bool mouseUp = false; bool mouseSelect = false; bool touchSelect = false; if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) // MouseInput { // Did user double click? If so, treat as a shortcut to play. if (MouseInput.Left.WasDoubleClicked) { // This works because we _know_ Play is the first one in the list. // Not exactly a great solution. curIndex = 0; mouseSelect = true; } Vector2 hit = MouseInput.GetMouseInRtCoords(); if (!mouseSelect) { if (itemList[CurIndex].hitBox.LeftPressed(hit)) { mouseSelect = true; } } // If mouse is over menu and moving, choose item under mouse as selection. if (!mouseSelect && MouseInput.Position != MouseInput.PrevPosition) { for (int i = 0; i < itemList.Count; i++) { if (itemList[i].hitBox.Contains(hit)) { CurIndex = i; break; } } } int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (scroll > 0) { mouseUp = true; } else if (scroll < 0) { mouseDown = true; } // If user clicks off of the popup, treat as Back. if (MouseInput.Left.WasPressed && MouseInput.ClickedOnObject == null) { Active = false; return; } } // end of mouse input. else if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) // TouchInput { TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { Vector2 hit = TouchInput.GetAspectRatioAdjustedPosition(touch.position, camera, true); bool hitSomething = false; // Check for a hit on any of the items. for (int i = 0; i < itemList.Count; i++) { if (itemList[i].hitBox.Contains(hit)) { CurIndex = i; hitSomething = true; } } if (touch.phase == TouchPhase.Ended) { if (hitSomething) { // We've touched off on an item so choose it. touchSelect = true; } else { // We touched off and didn't hit anything. if (touch.TouchedObject == this) { touch.TouchedObject = null; } else { Active = false; } } } } } // end of Touch input. if (Actions.Select.WasPressed || mouseSelect || touchSelect) { Actions.Select.ClearAllWasPressedState(); if (itemList[curIndex].OnSelect != null) { itemList[curIndex].OnSelect(); } Foley.PlayPressA(); return; } if (Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); Active = false; Foley.PlayBack(); return; } int prevIndex = curIndex; // Handle input changes here. if (Actions.ComboDown.WasPressedOrRepeat || mouseDown) { ++curIndex; if (curIndex >= itemList.Count) { curIndex = 0; } Foley.PlayShuffle(); } if (Actions.ComboUp.WasPressedOrRepeat || mouseUp) { --curIndex; if (curIndex < 0) { curIndex = itemList.Count - 1; } Foley.PlayShuffle(); } // Ensure that the selected state of all items is correct. for (int i = 0; i < itemList.Count; i++) { itemList[i].Selected = i == CurIndex; } } } // end of LoadLevelPopup Update()
public bool OwnsFocus() { return(commandMap == CommandStack.Peek()); }
} // end of DeleteAll() public void Update(Camera camera, ref Matrix parentMatrix) { // Check for input. if (active && itemList.Count > 1 && !IgnoreInput && CommandStack.Peek() == commandMap) { bool selectionChanged = false; bool moveUp = false; bool moveDown = false; { // Mouse input if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { // If the mouse is over the menu, move the selection index to the item under the mouse. // On mouse down, make the item (if any) under the mouse the ClickedOnItem. // On mouse up, if the mouse is still over the ClickedOnItem, activate it. If not, just clear ClickedOnItem. Vector2 hitUV = MouseInput.GetHitUV(camera, ref invWorldMatrix, width, height, useRtCoords); // See if we're over anything. If so, set that item to being selected but only if we've moved the mouse. // This prevents the menu from feeling 'broken' if the mouse is over it and the user tries to use // the gamepad or keyboard. int mouseOverItem = -1; for (int i = 0; i < itemList.Count; i++) { if (itemList[i].UVBoundingBox != null && itemList[i].UVBoundingBox.Contains(hitUV)) { // Only update the current in-focus element when the mouse moves. if (MouseInput.Position != MouseInput.PrevPosition) { CurIndex = i; } mouseOverItem = i; } } if (MouseInput.Left.WasPressed && mouseOverItem != -1) { MouseInput.ClickedOnObject = itemList[mouseOverItem]; } if (MouseInput.Left.WasReleased && mouseOverItem != -1 && MouseInput.ClickedOnObject == itemList[mouseOverItem]) { // Normally this is already set except in the case where the app didn't have focus and a menu item is clicked. // In that case, the CurIndex value stays stuck at its previous position. In particular this was causing Kodu's // Main Menu to think RESUME was clicked even when it was one of the other menu items. CurIndex = mouseOverItem; if (onSelect != null) { onSelect(this); } Foley.PlayPressA(); return; } // Allow scroll wheel to cycle through elements. int wheel = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (wheel > 0) { moveUp = true; } else if (wheel < 0) { moveDown = true; } } // end if KeyboardMouse mode. if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { // Look for Tap gesture first. No need to care about touch response if we've got a tap. bool goodTapGesture = false; if (TouchGestureManager.Get().TapGesture.WasTapped()) { // Check if tap position hit any of the menu elements. Vector2 tapPosition = TouchGestureManager.Get().TapGesture.Position; Vector2 touchHitUV = TouchInput.GetHitUV(tapPosition, camera, ref invWorldMatrix, width, height, useRtCoords); for (int index = 0; index < itemList.Count; index++) { if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV)) { CurIndex = index; if (onSelect != null) { onSelect(this); Foley.PlayPressA(); selectionChanged = true; goodTapGesture = true; } } } } // Look for touch events to change focus. Ignore this if we had a good tap gesture. if (!goodTapGesture) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); // Touch input // If the user touched the menu, move the selection index to the item under the touch. // On touch down, make the item (if any) under the contact the touchedItem. // On touch up, if the touch is still over the touchedItem, activate it. If not, just clear touchedItem. Vector2 touchHitUV = TouchInput.GetHitUV(touch.position, camera, ref invWorldMatrix, width, height, useRtCoords); // See what UI element we are over, if anything. If it hits, set that item to being selected but only if the touch has moved. // This emulates how the mouse is being handled by allowing the input to change only if the touch has moved. If a user moves // the gamepad or keyboard but doesn't move their touch contact, then the selection won't flicker back and forth and feel 'broken' int touchOverIndex = -1; for (int index = 0; index < itemList.Count; index++) { if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV)) { touchOverIndex = index; } } if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) { // Touch is down! if (touchOverIndex != -1) { touch.TouchedObject = itemList[touchOverIndex]; if (CurIndex != touchOverIndex) { selectionChanged = true; } CurIndex = touchOverIndex; } } else if (touch.phase == TouchPhase.Moved) { // Touch moved!!! Update Something!! if (CurIndex != touchOverIndex) { CurIndex = touchOverIndex; } } } } // end if not good tap gesture. if (selectionChanged) { if (onChange != null) { onChange(this); } dirty = true; //RecalcPositions(); // Ensure that the selected state of all items is correct. for (int i = 0; i < itemList.Count; i++) { itemList[i].Selected = i == CurIndex; } } } // end of touch mode processing. } if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad || GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { // Gamepad / Keyboard input. GamePadInput pad = GamePadInput.GetGamePad0(); if ((AcceptStartForCancel && Actions.Start.WasPressed) || Actions.Cancel.WasPressed) { Actions.Cancel.ClearAllWasPressedState(); if (onCancel != null) { onCancel(this); } Foley.PlayBack(); return; } if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); if (onSelect != null) { onSelect(this); } Foley.PlayPressA(); return; } int prevIndex = CurIndex; // Handle input changes here. if (Actions.ComboDown.WasPressedOrRepeat || moveDown) { ++CurIndex; if (CurIndex >= itemList.Count) { CurIndex = 0; } selectionChanged = true; } if (Actions.ComboUp.WasPressedOrRepeat || moveUp) { --CurIndex; if (CurIndex < 0) { CurIndex = itemList.Count - 1; } selectionChanged = true; } if (selectionChanged) { if (onChange != null) { onChange(this); } dirty = true; //RecalcPositions(); } // Ensure that the selected state of all items is correct. for (int i = 0; i < itemList.Count; i++) { itemList[i].Selected = i == CurIndex; } } } RefreshTexture(); } // end of UIGridModularMenu Update()
} // end of c'tor public void Update() { if (Active) { // Due to command stack funkiness, need to bring the command map to top. if (CommandStack.Peek() != commandMap) { CommandStack.Pop(commandMap); CommandStack.Push(commandMap); } GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); if (OnContinue != null) { OnContinue(); } Deactivate(); return; } /* * if (Actions.Cancel.WasPressed) * { * Actions.Cancel.ClearAllWasPressedState(); * * if (OnBack != null) * { * OnBack(); * } * Deactivate(); * return; * } */ if (Actions.X.WasPressed) { Actions.X.ClearAllWasPressedState(); if (OnExitTutorial != null) { OnExitTutorial(); } Deactivate(); return; } // Change text? switch (GamePadInput.ActiveMode) { case GamePadInput.InputMode.KeyboardMouse: if (blob.RawText != mouseText) { blob.RawText = mouseText; } break; case GamePadInput.InputMode.GamePad: if (blob.RawText != gamepadText) { blob.RawText = gamepadText; } break; case GamePadInput.InputMode.Touch: if (blob.RawText != touchText) { blob.RawText = touchText; } break; } // Scroll text??? if (blob.NumLines != 0) { int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (Actions.Up.WasPressedOrRepeat || scroll > 0) { ScrollDown(); } if (Actions.Down.WasPressedOrRepeat || scroll < 0) { ScrollUp(); } // If we're not shutting down... if (Active) { } // end if not shutting down. } // We should be on top and owning all input // focus so don't let anthing trickle down. GamePadInput.ClearAllWasPressedState(); // Disable the help overlay's tool icon because in some situations // it can overlap the text making it unreadable. HelpOverlay.ToolIcon = null; // If active we need to pre-render the text to the 1k rendertarget since // changing render targets on the Xbox forces a resolve. PreRender(); Vector2 hit; if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { Vector2 touchHit = touch.position; // Adjust for position and scaling of final rendering. touchHit -= renderPosition; touchHit /= renderScale; HandleTouchInput(touch, touchHit); } else { continueButton.ClearState(); backButton.ClearState(); exitTutorialButton.ClearState(); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { // Consider adjusting modal dialog size to take overscan into account BUT NOT tutorial mode. hit = MouseInput.PositionVec; // Adjust for position and scaling of final rendering. hit -= renderPosition; hit /= renderScale; HandleMouseInput(hit); } } // end if active. } // end of Update()
} // end of TweakObjectUpdateObj c'tor /// <summary> /// TweakObjectUpdateObj Update() /// </summary> /// <param name="camera"></param> public override void Update() { base.Update(); float secs = Time.WallClockFrameSeconds; // Do the common bits of the Update(). UpdateCamera(); UpdateWorld(); // Check if we have input focus. Don't do any input // related update if we don't. if (CommandStack.Peek() == commandMap) { // Grab the current state of the gamepad. GamePadInput pad = GamePadInput.GetGamePad0(); // Switch to Mini-Hub? if (pad.Start.WasPressed) { parent.SwitchToMiniHub(); return; } // If B is pressed, return to the ToolMenu if (pad.ButtonB.WasPressed) { parent.CurrentUpdateMode = UpdateMode.ToolMenu; return; } // Assign the new position to the 3d cursor and then read it back since // it will modify the height to accommodate the terrain. parent.cursor3D.Position = shared.CursorPosition; shared.CursorPosition = parent.cursor3D.Position; // See if there's something under the cursor. CheckForEditFocusObject(); if (editFocusObject != null) { GameActor actor = editFocusObject as GameActor; if (actor != null) { shared.camera.ChangeHeightOffset(actor.Movement.Altitude); } } else { shared.camera.SetDefaultHeightOffset(shared.CursorPosition, 0.5f); } // // Y button edits the brain. // if (pad.ButtonY.WasPressed) { GameActor actor = editFocusObject as GameActor; if (actor != null) { if (parent.ShowEditor(actor)) { InGame.IsLevelDirty = true; // Hide the color palette and then return. If we just fall // through then the color palette will be re-enabled. ColorPalette.Active = false; } return; } } // // A button edits the tweakables. // if (pad.ButtonA.WasPressed) { GameActor actor = editFocusObject as GameActor; if (actor != null) { // If we're editing a clone, edit its creatable instead. if (actor.IsClone) { actor = parent.GetCreatable(actor.CreatableId); } // Tell EditObjectParameters which actor's params we want to edit. parent.shared.editObjectParameters.Actor = actor; // Switch modes. parent.CurrentUpdateMode = UpdateMode.EditObjectParameters; InGame.IsLevelDirty = true; // Hide the color palette and then return. If we just fall // through then the color palette will be re-enabled. ColorPalette.Active = false; return; } } // Check state of color palette and respond to any inputs. UpdateColorPalette(pad); UpdateAura(); } // end if we have input focus. } // end of TweakObjectUpdateObj Update()
} // end of EditHeightMapUpdateObj c'tor /// <summary> /// EditHeightMapUpdateObj Update() /// </summary> /// <param name="camera"></param> public override void Update() { float secs = Time.WallClockFrameSeconds; /// Do the common bits of the Update(). /// Do these first, as they are input to any editing below. UpdateCamera(); UpdateWorld(); UpdateEditBrush(); // Check if we have input focus. Don't do any input // related update if we don't. if (CommandStack.Peek() == commandMap) { // Grab the current state of the gamepad. GamePadInput pad = GamePadInput.GetGamePad1(); // Switch to Mini-Hub? if (pad.Back.WasPressed) { parent.SwitchToMiniHub(); return; } /// Debounce. Make sure the button press that brought /// us up is released before using it to make changes. if (starting) { if (pad.ButtonY.IsPressed || pad.ButtonA.IsPressed || pad.ButtonX.IsPressed) { return; } starting = false; } int modeShift = shared.editBrushBase; // Up if (pad.ButtonY.IsPressed) { InGame.inGame.terrain.RenderToHeightMap( shared.editBrushIndex, shared.editBrushPosition, shared.editBrushRadius, 0 + modeShift); shared.heightMapModified = true; InGame.inGame.IsLevelDirty = true; } // Smooth if (pad.ButtonX.IsPressed) { InGame.inGame.terrain.RenderToHeightMap( shared.editBrushIndex, shared.editBrushPosition, shared.editBrushRadius, 2 + modeShift); shared.heightMapModified = true; InGame.inGame.IsLevelDirty = true; } // Down if (pad.ButtonA.IsPressed) { InGame.inGame.terrain.RenderToHeightMap( shared.editBrushIndex, shared.editBrushPosition, shared.editBrushRadius, 1 + modeShift); shared.heightMapModified = true; InGame.inGame.IsLevelDirty = true; } } // end if we have input focus. } // end of EditHeightMapUpdateObj Update()
public override void Update() { // Our children have input focus but we can still steal away the buttons we care about. GamePadInput pad = GamePadInput.GetGamePad1(); UIGrid curGrid = shared.GetGridFromCurTab(); bool sortNeeded = false; // Do we or our children have input focus? This is so we can steal some inputs from them. if (CommandStack.Peek() == parent.commandMap || (curGrid != null && CommandStack.Peek() == curGrid.commandMap)) { if (pad.RightShoulder.WasPressed || pad.DPadRight.WasPressed || pad.LeftStickRight.WasPressed) { parent.curTab = (Tab)(((int)parent.curTab + 1) % (int)Tab.NumTabs); #if HIDE_MISSIONS if (parent.curTab == Tab.Missions) { parent.curTab = (Tab)(((int)parent.curTab + 1) % (int)Tab.NumTabs); } #endif // Update active state. if (curGrid != null) { curGrid.Active = false; } curGrid = shared.GetGridFromCurTab(); if (curGrid != null) { curGrid.Active = true; } sortNeeded = true; } if (pad.LeftShoulder.WasPressed || pad.DPadLeft.WasPressed || pad.LeftStickLeft.WasPressed) { parent.curTab = (Tab)(((int)parent.curTab + (int)Tab.NumTabs - 1) % (int)Tab.NumTabs); #if HIDE_MISSIONS if (parent.curTab == Tab.Missions) { parent.curTab = (Tab)(((int)parent.curTab + (int)Tab.NumTabs - 1) % (int)Tab.NumTabs); } #endif // Update active state. if (curGrid != null) { curGrid.Active = false; } curGrid = shared.GetGridFromCurTab(); if (curGrid != null) { curGrid.Active = true; } sortNeeded = true; } if (pad.ButtonY.WasPressed) { shared.curSortOrder = (LevelSort.SortBy)(((int)shared.curSortOrder + 1) % (int)LevelSort.SortBy.NumSorts); sortNeeded = true; shared.bottomBarDirty = true; BokuGame.Audio.GetCue("programming add").Play(); } if (shared.curSortOrder == LevelSort.SortBy.UnSorted) { shared.curSortOrder = LevelSort.SortBy.Date; sortNeeded = true; } if (sortNeeded && curGrid != null) { LevelSort.SortGrid(curGrid, shared.curSortOrder); sortNeeded = false; } if (pad.ButtonB.WasPressed) { // Back to Main Menu. parent.Deactivate(); MainMenu.Instance.Activate(); } // Only allow deletions from Downloads or MyWorlds. if (pad.ButtonX.WasPressed && (parent.curTab == Tab.Downloads || parent.curTab == Tab.MyWorlds)) { // TODO delete file. Ask are you sure??? // Delete the file. If curGrid is null then there's no file to delete. if (curGrid != null) { UIGridWorldTile tile = (UIGridWorldTile)curGrid.SelectionElement; String filename = tile.FullPath; if (Storage.Exists(filename)) { // NOTE: It is not safe to delete the following files since they could // be shared by multiple worlds: // // - The "stuff" file // - The terrain heightmap file // - The terrain texture select file // Delete world xml file Storage.Delete(filename); // Delete thumbnail image Storage.TextureDelete(Path.GetDirectoryName(filename) + @"\" + Path.GetFileNameWithoutExtension(filename)); if (InGame.CurrentWorldId.ToString() == Path.GetFileNameWithoutExtension(filename)) { // Reset the current world information InGame.AutoSaved = false; InGame.XmlWorldData = null; } } // Remove the shared render targets from all elements. UIGridWorldTile.SharedRenderTarget.ResetAll(); // Remove the element from the grid. if (curGrid.RemoveAndCollapse(curGrid.SelectionIndex)) { // This was last element in grid. Delete it. // Pop its command map. CommandStack.Pop(curGrid.commandMap); // Remove the grid itself. switch (parent.curTab) { case Tab.Missions: shared.missionsGrid = null; break; case Tab.MyWorlds: shared.myWorldsGrid = null; break; case Tab.StarterWorlds: shared.starterWorldsGrid = null; break; case Tab.Downloads: shared.downloadsGrid = null; break; } curGrid = null; } } // end if curGrid != null } // end if 'X' was pressed. } // end of if we have input focus // If we're not shutting down, update the tabs and the child grids. if (parent.pendingState != States.Inactive) { Matrix world = Matrix.Identity; // Set the backdrop color and unfade current tab. switch (parent.curTab) { case Tab.Missions: shared.missionsTab.Selected = true; shared.myWorldsTab.Selected = false; shared.starterWorldsTab.Selected = false; shared.downloadsTab.Selected = false; break; case Tab.MyWorlds: shared.missionsTab.Selected = false; shared.myWorldsTab.Selected = true; shared.starterWorldsTab.Selected = false; shared.downloadsTab.Selected = false; break; case Tab.StarterWorlds: shared.missionsTab.Selected = false; shared.myWorldsTab.Selected = false; shared.starterWorldsTab.Selected = true; shared.downloadsTab.Selected = false; break; case Tab.Downloads: shared.missionsTab.Selected = false; shared.myWorldsTab.Selected = false; shared.starterWorldsTab.Selected = false; shared.downloadsTab.Selected = true; break; } shared.missionsTab.Update(); shared.myWorldsTab.Update(); shared.starterWorldsTab.Update(); shared.downloadsTab.Update(); shared.UpdateBottomBarTexture(); shared.bottomBar.Update(); if (shared.missionsGrid != null) { shared.missionsGrid.Update(ref world); } if (shared.myWorldsGrid != null) { shared.myWorldsGrid.Update(ref world); } if (shared.starterWorldsGrid != null) { shared.starterWorldsGrid.Update(ref world); } if (shared.downloadsGrid != null) { shared.downloadsGrid.Update(ref world); } // Make sure the visible elements for the current grid have render targets. if (curGrid != null) { int focus = curGrid.SelectionIndex.Y; int start = Math.Max(focus - 3, 0); int end = Math.Min(focus + 3, curGrid.ActualDimensions.Y - 1); for (int i = start; i <= end; i++) { UIGridWorldTile tile = (UIGridWorldTile)curGrid.Get(0, i); if (tile.SRT == null) { // Get a rendertarget and assign to current tile. UIGridWorldTile.SharedRenderTarget srt = UIGridWorldTile.SharedRenderTarget.Get(curGrid); srt.Grid = curGrid; srt.Index = i; tile.SRT = srt; } } } } // end if not shutting down. } // end of Update()
} // end of RunSimUpdateObj c'tor /// <summary> /// RunSimUpdateObj Update() /// </summary> /// <param name="camera"></param> public override void Update() { base.Update(); parent.Camera.Update(); float secs = Time.WallClockFrameSeconds; ThoughtBalloonManager.Update(shared.camera); SaidStringManager.Update(); #if !NETFX_CORE MicrobitManager.Update(); #endif // Start with visible cursor. parent.cursor3D.Activate(); parent.cursor3D.Rep = Cursor3D.Visual.RunSim; parent.cursor3D.Hidden = false; // // Determine the correct camera mode. // // // The priorities used to determine the camera mode when the game is running are: // // 1) First person. This can be either via programming or because the user zoomed // into a bot the camera was following. // 2) Follow mode caused by bot(s) programmed with "follow" camera view. // 3) World tweak screen fixed camera or fixed offset camera. // 4) Follow mode caused by user controlled bot(s). // 5) Free camera. // // Start with a fake loop to break out of. while (true) { Terrain terrain = InGame.inGame.Terrain; // Just a shortcut. // // Always use edit mode when the game is paused except during victory on level with one of the fixed cameras // or when game is paused for a bot to speak (modal text display). // bool victoryActive = VictoryOverlay.ActiveGameOver || VictoryOverlay.ActiveWinner; bool speaking = InGame.inGame.shared.smallTextDisplay.Active || InGame.inGame.shared.scrollableTextDisplay.Active; if (Time.Paused && !((terrain.FixedCamera || terrain.FixedOffsetCamera) && victoryActive) && !speaking) { CameraInfo.Mode = CameraInfo.Modes.Edit; CameraInfo.CameraFocusGameActor = null; break; } // // 1) First person // if (CameraInfo.FirstPersonActive) { CameraInfo.Mode = CameraInfo.Modes.Actor; // We're following a single actor so update the FollowActor camera values. shared.camera.FollowCameraValid = false; // Turn off 3d cursor since we don't need it. parent.cursor3D.Deactivate(); if (parent.cursorClone != null) { parent.cursorClone.Deactivate(); parent.cursorClone = null; } break; } // // 2) Follow mode caused by bot(s) programmed with "follow" camera view. // if (CameraInfo.ProgrammedFollowList.Count > 0) { // Note that even though we looked at the count of bot programmed to // have the camera follow them, for this mode we want to keep all // deserving bots in camera. So, the rest of this section will use // the merged follow list instead of just the programmed follow list. SetUpCameraFollowMode(); break; } // // 3) World tweak fixed cameras. Note for fixed offset we have to let // the later modes do their stuff and then override the camera. // if (terrain.FixedCamera) { CameraInfo.Mode = CameraInfo.Modes.FixedTarget; CameraInfo.CameraFocusGameActor = null; // Turn off 3d cursor since we don't need it. parent.cursor3D.Deactivate(); if (parent.cursorClone != null) { parent.cursorClone.Deactivate(); parent.cursorClone = null; } break; } // // 4) Follow mode caused by user controlled bot(s). // if (CameraInfo.MergedFollowList.Count > 0) { SetUpCameraFollowMode(); break; } // // 5) Free! // // Not following an actor. CameraInfo.Mode = CameraInfo.Modes.Edit; CameraInfo.CameraFocusGameActor = null; // Turn on 3d cursor in case we previously disabled it. parent.cursor3D.Activate(); parent.CreateCursorClone(); parent.cursor3D.Hidden = false; // We have no camera restrictions, so keep track of what the user is doing. shared.camera.PlayValid = true; shared.camera.PlayCameraFrom = shared.camera.From; shared.camera.PlayCameraAt = shared.camera.At; shared.camera.FollowCameraValid = false; // Final break just to be sure the loop exits. break; } // // Now that we're done, we need to check again to see if // we should be in FixedOffsetMode. // if (!Time.Paused && InGame.inGame.Terrain.FixedOffsetCamera && !CameraInfo.FirstPersonActive) { CameraInfo.Mode = CameraInfo.Modes.FixedOffset; } // Zero out any offset while running. float t = Math.Min(Time.GameTimeFrameSeconds, 1.0f); shared.camera.HeightOffset = MyMath.Lerp(shared.camera.HeightOffset, 0.0f, t); // bool inputFocus = CommandStack.Peek() == commandMap; // Move the camera. switch (CameraInfo.Mode) { case CameraInfo.Modes.Edit: MoveCameraEditMode(inputFocus, false); break; case CameraInfo.Modes.Actor: MoveCameraActorMode(true, false); break; case CameraInfo.Modes.FixedTarget: MoveCameraFixedTargetMode(inputFocus); break; case CameraInfo.Modes.FixedOffset: MoveCameraFixedOffsetMode(inputFocus); break; case CameraInfo.Modes.MultiTarget: MoveCameraMultiTargetMode(inputFocus, false); break; } shared.camera.Update(); // Update terrain. parent.terrain.Update(shared.camera); // Update the list of objects using our local camera. for (int i = 0; i < updateList.Count; i++) { UpdateObject obj = (UpdateObject)updateList[i]; obj.Update(); } parent.UpdateObjects(); /// Pregame must update after parent.UpdateObjects, in case it /// decides to switchToMiniHub if (InGame.inGame.preGame != null) { InGame.inGame.preGame.Update(); } // Update the particle system. shared.particleSystemManager.Update(); DistortionManager.Update(); FirstPersonEffectMgr.Update(); // This must be done after all brains are updated. Scoreboard.Update(shared.camera); // Update the TextDisplays. Ignored if not active. shared.scrollableTextDisplay.Update(shared.camera); shared.smallTextDisplay.Update(shared.camera); VictoryOverlay.Update(); // Do the input processing after object update because there will be order of operation issue if we don't // // Check if we have input focus. Don't do any input // related update if we don't. if (inputFocus) { // Grab the current state of the gamepad. GamePadInput pad = GamePadInput.GetGamePad0(); // Switch to Mini-Hub? if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); //parent.ResetSim(CurrentLevelFilename()); // Needed to make sure that deactivated objects are actually removed from // the list otherwise they may get saved along with the newly activated ones. //parent.Refresh(BokuGame.gameListManager.updateList, BokuGame.gameListManager.renderList); parent.SwitchToMiniHub(); return; } //handle swipe to return to edit for touch input if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { SwipeGestureRecognizer swipeGesture = TouchGestureManager.Get().SwipeGesture; if (swipeGesture.WasRecognized && swipeGesture.SwipeDirection == Directions.North) { #if NETFX_CORE float halfWidth = (float)BokuGame.bokuGame.Window.ClientBounds.Width * 0.5f; float height = (float)BokuGame.bokuGame.Window.ClientBounds.Height; #else float halfWidth = (float)XNAControl.Instance.ClientSize.Width * 0.5f; float height = (float)XNAControl.Instance.ClientSize.Height; #endif //center half of the screen width-wise float minX = halfWidth - (halfWidth * k_TouchExitAreaWidthPercent); float maxX = halfWidth + (halfWidth * k_TouchExitAreaWidthPercent); //bottom 20% height-wise float minY = height - (height * k_TouchExitAreaHeightPercent); Vector2 pos = swipeGesture.InitialPosition; if (pos.X >= minX && pos.X <= maxX && pos.Y >= minY) { // User did a swipe from the bottom of the screen, enter edit mode InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject; InGame.inGame.CurrentUpdateMode = UpdateMode.TouchEdit; Foley.PlayPressStart(); return; } } // HACKHACK (****) Put in a tap recognizer since swipe seems to fail. { TapGestureRecognizer hackTapGesture = TouchGestureManager.Get().TapGesture; if (hackTapGesture.WasTapped()) { #if NETFX_CORE float halfWidth = (float)BokuGame.bokuGame.Window.ClientBounds.Width * 0.5f; float height = (float)BokuGame.bokuGame.Window.ClientBounds.Height; #else float halfWidth = (float)XNAControl.Instance.ClientSize.Width * 0.5f; float height = (float)XNAControl.Instance.ClientSize.Height; #endif //center area of the screen width-wise float minX = halfWidth - (halfWidth * 0.1f); float maxX = halfWidth + (halfWidth * 0.1f); //bottom 10% height-wise float minY = height - (height * 0.1f); Vector2 pos = hackTapGesture.Position; if (pos.X >= minX && pos.X <= maxX && pos.Y >= minY) { // User did a tap on the bottom of the screen, enter edit mode InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject; InGame.inGame.CurrentUpdateMode = UpdateMode.TouchEdit; Foley.PlayPressStart(); return; } } } } bool gameOver = VictoryOverlay.GameOver; if (Time.Paused && !gameOver) { // We must be in user induced pause mode. if (Actions.Unpause.WasPressed) { Actions.Unpause.ClearAllWasPressedState(); Time.Paused = false; HelpOverlay.Pop(); } } else { if (gameOver) { // Game over man! Let the user restart if they want. if (Actions.Restart.WasPressed) { Actions.Restart.ClearAllWasPressedState(); InGame.inGame.ResetSim(preserveScores: false, removeCreatablesFromScene: true, keepPersistentScores: false); // Since we're going right back into RunSim mode we need to first inline. ApplyInlining(); } } // Open ToolMenu. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); parent.CurrentUpdateMode = UpdateMode.ToolMenu; Foley.PlayPressStart(); return; } // Pause? // We want to make pause hard to get into so it requires both triggers and both stickButtons to be pressed. if ((pad.LeftStickButton.IsPressed && pad.RightStickButton.IsPressed && pad.LeftTriggerButton.IsPressed && pad.RightTriggerButton.IsPressed) || Actions.Pause.WasPressed) { Actions.Pause.ClearAllWasPressedState(); if (!Time.Paused) { Time.Paused = true; HelpOverlay.Push("PauseGame"); GamePadInput.GetGamePad0().IgnoreLeftStickUntilZero(); GamePadInput.GetGamePad0().IgnoreRightStickUntilZero(); } } } } // Force the the HelpOverlay to be correct. if (!Time.Paused || VictoryOverlay.Active) { if (InGame.inGame.PreGame != null && InGame.inGame.PreGame.Active) { if (HelpOverlay.Depth() != 1 || HelpOverlay.Peek() != "RunSimulationPreGame") { HelpOverlay.Clear(); HelpOverlay.Push("RunSimulationPreGame"); } } else { if (HelpOverlay.Depth() != 1 || HelpOverlay.Peek() != "RunSimulation") { HelpOverlay.Clear(); HelpOverlay.Push("RunSimulation"); } } } else { // We're paused. if (HelpOverlay.Depth() != 2 || HelpOverlay.Peek(1) != "RunSimulation") { HelpOverlay.Clear(); HelpOverlay.Push("RunSimulation"); HelpOverlay.Push("PauseGame"); } } // When in run mode, allow the user to click on the "Press [esc] to edit" text as if it was a button. if (MouseInput.Left.WasPressed) { Point mousePos = MouseInput.Position; if (HelpOverlay.MouseHitBottomText(mousePos)) { // Switch to edit mode. InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject; } } TapGestureRecognizer tapGesture = TouchGestureManager.Get().TapGesture; if (tapGesture.WasTapped()) { // JW - Until we have proper Touch help overlays, we are still using the mouse/keyboard // overlays. The mouse handling code for these depends on being able to 'absorb' pressed // info to hide it from later callers. Our touch stuff doesn't (and really shouldn't) // do this. So, we handle cases here based on what type of overlay is being displayed. if (HelpOverlay.Peek() == "RunSimulationPreGame") { // Tap during instructions: just begin game. InGame.inGame.PreGame.Active = false; } // Also test if running sim for tapping on "tap to edit" at bottom. if (HelpOverlay.Peek() == "RunSimulation") { Point pos = new Point((int)tapGesture.Position.X, (int)tapGesture.Position.Y); if (HelpOverlay.MouseHitBottomText(pos)) { // Switch to edit mode. InGame.inGame.CurrentUpdateMode = UpdateMode.EditObject; } } } } // end of RunSimUpdateObj Update()
} // end of UpdateCamera() /// <summary> /// Common camera controls for edit modes. /// </summary> /// <param name="preventZoom">Lock the zoom. This is kind of a hack used /// by the tool palette since that palette uses the shoulder buttons to /// cycle through it. Without locking the zoom we'd zoom in and out /// as we're moving though the tool options.</param> public void UpdateCamera(bool preventZoom) { float secs = Time.WallClockFrameSeconds; Vector3 lookAt = parent.Camera.At; Vector3 lookFrom = parent.Camera.From; // If we were in first person mode, reset things as needed. if (CameraInfo.FirstPersonActive) { CameraInfo.FirstPersonActor.SetFirstPerson(false); CameraInfo.ResetAllLists(); CameraInfo.Mode = CameraInfo.Modes.Edit; InGame.inGame.Camera.FollowCameraDistance = 10.0f; } // Check if we have input focus. Don't do any input // related update if we don't. if (CommandStack.Peek() == commandMap) { // Grab the current state of the gamepad. GamePadInput pad = GamePadInput.GetGamePad0(); // From all edit modes, <back> should bring up the tool menu. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Foley.PlayBack(); parent.CurrentUpdateMode = UpdateMode.ToolMenu; return; } // From all edit modes, <start> should to to the mini-hub. if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); Foley.PlayPressStart(); parent.SwitchToMiniHub(); return; } // From all edit modes the B button should activate the ToolMenu. // Edit object handles the B button itself since it may be in Waypoint mode. if (Actions.AltToolMenu.WasPressed && parent.CurrentUpdateMode != UpdateMode.EditObject) { Actions.AltToolMenu.ClearAllWasPressedState(); parent.CurrentUpdateMode = UpdateMode.ToolMenu; return; } // If the ToolMenu is active and it's modal, don't allow the camera to move. if (InGame.inGame.toolMenuUpdateObj.active && XmlOptionsData.ModalToolMenu) { return; } // // Use common camera controls for all edit modes. // const float cursorSpeed = 20.0f; // Meters per second. const float orbitSpeed = 2.0f; // Radians per second. const float zoomFactor = 1.1f; // Right stick to orbit around cursor. float drot = GamePadInput.InvertCamX() ? -pad.RightStick.X : pad.RightStick.X; float dpitch = GamePadInput.InvertCamY() ? -pad.RightStick.Y : pad.RightStick.Y; parent.Camera.DesiredRotation += drot * Time.WallClockFrameSeconds * orbitSpeed; parent.Camera.DesiredPitch -= dpitch * Time.WallClockFrameSeconds * orbitSpeed; // Left/right arrow keys also orbit but not if the tool menu or a picker is up. //if (inGame.CurrentUpdateMode != UpdateMode.ToolMenu && !HelpOverlay.Peek().EndsWith("Picker") ) //{ // if (KeyboardInput.IsPressed(Keys.Left)) // { // parent.Camera.DesiredRotation -= 1.0f * Time.WallClockFrameSeconds * orbitSpeed; // } // else if (KeyboardInput.IsPressed(Keys.Right)) // { // parent.Camera.DesiredRotation += 1.0f * Time.WallClockFrameSeconds * orbitSpeed; // } //} // Shoulder buttons track camera in/out. if (!preventZoom) { if (Actions.ZoomOut.IsPressed) { parent.Camera.DesiredDistance *= 1.0f + Time.WallClockFrameSeconds * zoomFactor; } if (Actions.ZoomIn.IsPressed) { float desiredDistance = parent.Camera.DesiredDistance * (1.0f - Time.WallClockFrameSeconds * zoomFactor); // If not in RunSim mode, don't allow the camera to get closer than 4 meters. if (InGame.inGame.CurrentUpdateMode != UpdateMode.RunSim) { desiredDistance = Math.Max(4.0f, desiredDistance); } parent.Camera.DesiredDistance = desiredDistance; } parent.MouseEdit.DoZoom(parent.Camera); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { parent.MouseEdit.DoCamera(parent.Camera); } // Left stick to control cursor position. // Cursor movement is relative to view heading. // Cursor speed grows with view distance. Vector2 position = new Vector2(shared.CursorPosition.X, shared.CursorPosition.Y); Vector2 forward = new Vector2((float)Math.Cos(parent.Camera.Rotation), (float)Math.Sin(parent.Camera.Rotation)); Vector2 right = new Vector2(forward.Y, -forward.X); float speedFactor = (parent.Camera.Distance - 10.0f) / 50.0f; // At 10 meters out start growing the speedFactor. speedFactor = MathHelper.Clamp(speedFactor, 1.0f, 3.0f); position += forward * pad.LeftStick.Y * Time.WallClockFrameSeconds * cursorSpeed * speedFactor; position += right * pad.LeftStick.X * Time.WallClockFrameSeconds * cursorSpeed * speedFactor; // Numpad controls cursor position. NumLock must be on! float y = KeyboardInput.IsPressed(Keys.NumPad7) || KeyboardInput.IsPressed(Keys.NumPad8) || KeyboardInput.IsPressed(Keys.NumPad9) ? 1.0f : 0.0f; y += KeyboardInput.IsPressed(Keys.NumPad1) || KeyboardInput.IsPressed(Keys.NumPad2) || KeyboardInput.IsPressed(Keys.NumPad3) ? -1.0f : 0.0f; float x = KeyboardInput.IsPressed(Keys.NumPad3) || KeyboardInput.IsPressed(Keys.NumPad6) || KeyboardInput.IsPressed(Keys.NumPad9) ? 1.0f : 0.0f; x += KeyboardInput.IsPressed(Keys.NumPad1) || KeyboardInput.IsPressed(Keys.NumPad4) || KeyboardInput.IsPressed(Keys.NumPad7) ? -1.0f : 0.0f; position += forward * y * Time.WallClockFrameSeconds * cursorSpeed * speedFactor; position += right * x * Time.WallClockFrameSeconds * cursorSpeed * speedFactor; // Allow LeftStickClick RightStickClick to cycle though actors. if (inGame.gameThingList.Count > 0) { // Move to next actor if (Actions.NextActor.WasPressed) { Actions.NextActor.ClearAllWasPressedState(); // If we have an actor in focus, find index. GameActor focusActor = InGame.inGame.EditFocusObject; if (focusActor != null) { for (int i = 0; i < inGame.gameThingList.Count; i++) { if (focusActor == inGame.gameThingList[i]) { actorTabIndex = i; break; } } } // Increment index. actorTabIndex = (actorTabIndex + 1) % inGame.gameThingList.Count; Vector3 actorPos = inGame.gameThingList[actorTabIndex].Movement.Position; Vector2 delta = new Vector2(actorPos.X - position.X, actorPos.Y - position.Y); position += delta; } // Move to prev actor if (Actions.PrevActor.WasPressed) { Actions.PrevActor.ClearAllWasPressedState(); // If we have an actor in focus, find index. GameActor focusActor = InGame.inGame.EditFocusObject; if (focusActor != null) { for (int i = 0; i < inGame.gameThingList.Count; i++) { if (focusActor == inGame.gameThingList[i]) { actorTabIndex = i; break; } } } // Decrement index. actorTabIndex = (actorTabIndex + inGame.gameThingList.Count - 1) % inGame.gameThingList.Count; Vector3 actorPos = inGame.gameThingList[actorTabIndex].Movement.Position; Vector2 delta = new Vector2(actorPos.X - position.X, actorPos.Y - position.Y); position += delta; } } if (!shared.editWayPoint.Dragging) { // TODO (mouse) Why was this here? //position = parent.MouseEdit.DoCursor(parent.Camera, position); } position = shared.editWayPoint.DoCursor(position); // Keep cursor within 50 units of existing terrain. float maxBrush = InGame.kMaxBrushRadius; Vector2 min = new Vector2(InGame.inGame.totalBounds.Min.X, InGame.inGame.totalBounds.Min.Y) - new Vector2(maxBrush, maxBrush); Vector2 max = new Vector2(InGame.inGame.totalBounds.Max.X, InGame.inGame.totalBounds.Max.Y) + new Vector2(maxBrush, maxBrush); position.X = MathHelper.Clamp(position.X, min.X, max.X); position.Y = MathHelper.Clamp(position.Y, min.Y, max.Y); shared.CursorPosition = new Vector3(position, shared.CursorPosition.Z); } // end if we have input focus. // Keep the camera from going into the ground. shared.KeepCameraAboveGround(); // Update camera based on new position/orientation. parent.Camera.DesiredAt = shared.CursorPosition; // Finally, call Update on the camera to let all the changes filter through. parent.Camera.Update(); } // end of BaseEditUpdateObj UpdateCamera()