} // end of Update() private bool UpdateNonMenuItems() { bool inputHandled = false; // Check for click on signOut tile or url. if (MouseInput.Left.WasPressed || Actions.Select.WasPressed || TouchInput.WasTouched || TouchInput.WasLastReleased) { TouchContact touch = TouchInput.GetOldestTouch(); Vector2 touchHit = new Vector2(-1, -1); // touch off screen if no touch was found // url is in rt coords. if (touch != null) { touchHit = ScreenWarp.ScreenToRT(touch.position); } Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); if (shared.urlBox.Contains(mouseHit) || (shared.urlBox.Contains(touchHit) && TouchInput.WasLastReleased)) { #if NETFX_CORE Launcher.LaunchUriAsync(new Uri(KoduGameLabUrl)); #else Process.Start(KoduGameLabUrl); #endif MouseInput.Left.ClearAllWasPressedState(); inputHandled = true; } } return(inputHandled); }
} // end of Update() private bool UpdateNonMenuItems() { bool inputHandled = false; // Check for click on signOut tile or url. if (MouseInput.Left.WasPressed || Actions.Select.WasPressed || TouchInput.WasTouched || TouchInput.WasLastReleased) { TouchContact touch = TouchInput.GetOldestTouch(); Vector2 touchHit = new Vector2(-1, -1); // touch off screen if no touch was found // url is in rt coords. if (touch != null) { touchHit = ScreenWarp.ScreenToRT(touch.position); } Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); if (shared.urlBox.Contains(mouseHit) || (shared.urlBox.Contains(touchHit) && TouchInput.WasLastReleased)) { #if NETFX_CORE Launcher.LaunchUriAsync(new Uri(KoduGameLabUrl)); #else Process.Start(KoduGameLabUrl); #endif MouseInput.Left.ClearAllWasPressedState(); inputHandled = true; } //check for touch over scroll window (doesn't need to be released) if (!inputHandled && GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { if (TouchInput.WasTouched && touch != null && shared.liveFeed.IsInScrollwindow(touch.position)) { //touch in window? if so, activate the live feed shared.liveFeed.Activate(); inputHandled = true; } else { //deactivate the feed and don't consider the input handled shared.liveFeed.Deactivate(); } } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y); // mouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y); if (shared.liveFeed.IsInScrollwindow(pureMouseHit)) // mouseHit)) { shared.liveFeed.Activate(); } } return(inputHandled); }
} // end of c'tor public void Update() { if (active) { // // Input? // // Touch. for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = ScreenWarp.ScreenToRT(touch.position); HandleTouchInput(touch, touchHit); } // Mouse. Note, we explicitely look for mouse mode here so that // mouse hover doesn't change the focus level when changing it via // keyboard or gamepad. if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); HandleMouseInput(mouseHit); } // Keyboard. // Arrows are handled via Actions in HandleGamePadInput(). if (KeyboardInput.WasPressed(Keys.Escape)) { OnCancel(); } if (KeyboardInput.WasPressed(Keys.Enter)) { OnSelect(); } // Gamepad. HandleGamepadInput(); // Set frame color to indicate focus. for (int i = 0; i < levels.Count; i++) { if (focusLevelIndex == i) { levels[i].FrameColor = new Color(0, 255, 13); } else { levels[i].FrameColor = Color.Transparent; } } } // end if active. } // end of Update()
// end of HandleMouseInput() private void HandleTouchInput() { //if (TouchInput.TouchCount == 0) { return; } // nothing to see here. //TouchContact touch = TouchInput.GetOldestTouch(); //Vector2 touchHit = TouchInput.GetAspectRatioAdjustedPosition( // touch.position, // camera, // true //); if (TouchInput.TouchCount == 0) { return; } // nothing to see here. TouchContact touch = TouchInput.GetOldestTouch(); Vector2 touchHit = ScreenWarp.ScreenToRT(touch.position); if (TouchGestureManager.Get().TapGesture.WasTapped()) { if (okButton.Box.Contains(touchHit)) { Accept(); } if (cancelButton.Box.Contains(touchHit)) { Cancel(); } if (textBox.Contains(touchHit)) { KeyboardInput.ShowOnScreenKeyboard(); } } } // end of HandleTouchInput()
} // end of OnSaveLevelDialogButton() /// <summary> /// OnSelect method used by mini-hub grid. If the level is dirty and needs to /// be saved the SaveChagesDialog will be activated. Upon its deactivation /// the level should no longer be marked dirty and OnSelect() will get called /// again allowing the user's action to be executed. /// </summary> /// <param name="grid"></param> public void OnSelect(ModularMenu menu) { // Prevent the button pressed from leaking into runtime. GamePadInput.IgnoreUntilReleased(Buttons.A); // In every case, we need to reset the level to its starting state. InGame.inGame.ResetSim(preserveScores: false, removeCreatablesFromScene: false, keepPersistentScores: false); // Resetting the sim just started up all game audio, let's pause it down again. // It will be resumed when we go back into sim mode. BokuGame.Audio.PauseGameAudio(); // Flag to let us know if the level needs saving. If the save changes // dialog has already been activated then just set this to false. bool needToSaveLevel = (InGame.IsLevelDirty || InGame.AutoSaved) && !saveChangesActivated; // Does the current world belong to the user. Required to share to community. // Test the genre flag and also special case look at empty world. bool isMyWorld = false; if (InGame.XmlWorldData != null) { bool genreTest = ((int)InGame.XmlWorldData.genres & (int)Genres.MyWorlds) != 0; bool newWorldTest = InGame.XmlWorldData.Filename == emptyWorldFileName; if (genreTest && !newWorldTest) { isMyWorld = true; } } // Normally there would be a switch here but if we compare strings // we proof ourselves against changes in the order of the elements. if (menu.CurString == Strings.Localize("miniHub.reset")) { // Reset. // We've already done a Reset, so force to RunSim mode if we already aren't. Deactivate(); InGame.inGame.Activate(); InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.RunSim; InGame.inGame.RestorePlayModeCamera(); // The ResetSim above doesn't ApplyInlining since it's generally // meant for resetting into the editor. In this case we're going // into RunSim mode so be sure to apply inlining first. InGame.ApplyInlining(); if (InGame.inGame.PreGame != null) { InGame.inGame.PreGame.Active = true; } } else if (menu.CurString == Strings.Localize("miniHub.edit")) { // Edit level. Deactivate(); InGame.inGame.Activate(); InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } else if (menu.CurString == Strings.Localize("miniHub.save")) { // Save saveLevelDialog.Activate(); } else if (menu.CurString == Strings.Localize("miniHub.publish")) { // Offer to save first. Need to save if world has changed or is world doesn't belong to user. if (needToSaveLevel || !isMyWorld) { saveChangesActivated = true; saveChangesMessage.Activate(); } else { var level = LevelMetadata.CreateFromXml(InGame.XmlWorldData); shared.communityShareMenu.Activate(level); } } else if (menu.CurString == Strings.Localize("miniHub.load")) { // Load. // If we're back here and saveChangesActivated is true then the // user was given the option to save changes and chose Discard. // So don't offer to save again. if (!saveChangesActivated && needToSaveLevel) { saveChangesActivated = true; saveChangesWithDiscardMessage.Activate(); } else { saveChangesActivated = false; // Deactivate mini-hub and bring up loading menu. Deactivate(); //InGame.inGame.DiscardTerrain(); BokuGame.bokuGame.loadLevelMenu.LocalLevelMode = LoadLevelMenu.LocalLevelModes.General; BokuGame.bokuGame.loadLevelMenu.ReturnToMenu = LoadLevelMenu.ReturnTo.MiniHub; BokuGame.bokuGame.loadLevelMenu.Activate(); } } else if (menu.CurString == Strings.Localize("miniHub.emptyLevel")) { // Empty Level. // If saveChangesActivated is already true then user chose Discard and // we can ignore the needToSaveLevel flag. if (!saveChangesActivated && needToSaveLevel) { saveChangesActivated = true; saveChangesWithDiscardMessage.Activate(); } else { saveChangesActivated = false; // Undo any previous warping. ScreenWarp.FitRtToScreen(BokuGame.ScreenSize); newWorldDialog.Active = true; } } else if (menu.CurString == Strings.Localize("miniHub.print")) { Print.PrintProgramming(); // We don't want to exit the mini-hub so re-activate the menu. shared.menu.Active = true; } else if (menu.CurString == Strings.Localize("miniHub.quit")) { // Exit to main menu. // If we're back here and saveChangesActivated is true then the // user was given the option to save changes and chose Discard. // So don't offer to save again. if (!saveChangesActivated && needToSaveLevel) { saveChangesActivated = true; saveChangesWithDiscardMessage.Activate(); } else { saveChangesActivated = false; // Wave bye, bye. Go back to the main menu Deactivate(); InGame.inGame.StopAllSounds(); BokuGame.bokuGame.mainMenu.Activate(); } } } // end of MiniHub OnSelect()
} // end of c'tor public void Update(Camera camera) { if (Active) { GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); // Disable this hint for this session. if (curHint.ShowOnce) { curHint.Disabled = true; } Deactivate(); } if (Actions.X.WasPressed) { Actions.X.ClearAllWasPressedState(); // Disable this hint until reset by user. XmlOptionsData.SetHintAsDisabled(curHint.ID); // Disable this hint for this session. if (curHint.ShowOnce) { curHint.Disabled = true; } Deactivate(); } // We need to be able to slip out to the mini-hub here since // continuous, repeated calls to ScrollableModalHint can lock the // user out of control. if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); Deactivate(); InGame.inGame.SwitchToMiniHub(); } // We need to be able to slip out to the tool menu here since // continuous, repeated calls to ScrollableModalHint can lock the // user out of control. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Deactivate(); if (InGame.inGame.State == InGame.States.Active) { InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } } // 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(); // If we're rendering this into a 1280x720 rt we need a matching camera to calc mouse hits. if (useBackgroundThumbnail) { camera = new PerspectiveUICamera(); camera.Resolution = new Point(1280, 720); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; // Adjust for position and scaling of final rendering. touchHit -= renderPosition; touchHit /= renderScale; if (useRtCoords) { touchHit = ScreenWarp.ScreenToRT(touch.position); } HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; // Adjust for position and scaling of final rendering. hit -= renderPosition; hit /= renderScale; if (useRtCoords) { hit = MouseInput.GetMouseInRtCoords(); } HandleMouseInput(hit); } } // end if active. } // 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()
} // end of c'tor public void Update(Camera camera) { if (Active) { GamePadInput pad = GamePadInput.GetGamePad0(); #if !NETFX_CORE // For games using micro:bit, allow buttons to dismiss ingame dialogs. if (InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim) { Microbit bit = MicrobitExtras.GetMicrobitOrNull(GamePadSensor.PlayerId.All); if (bit != null) { // Allow either button to dismiss display. if (bit.State.ButtonA.IsPressed() || bit.State.ButtonB.IsPressed()) { Deactivate(); } } } #endif if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); Deactivate(); } if (!string.IsNullOrEmpty(textB)) { if (Actions.B.WasPressed) { Actions.B.ClearAllWasPressedState(); userHitA = false; Deactivate(); } } // We need to be able to slip out to the mini-hub here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); Deactivate(); InGame.inGame.SwitchToMiniHub(); } // We need to be able to slip out to the tool menu here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Deactivate(); if (InGame.inGame.State == InGame.States.Active) { InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } } // 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. if (dirty) { PreRender(); dirty = false; } // If we're rendering this into a 1280x720 rt we need a matching camera to calc mouse hits. if (useBackgroundThumbnail) { camera = new PerspectiveUICamera(); camera.Resolution = new Point(1280, 720); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; // Adjust for position and scaling of final rendering. touchHit -= renderPosition; touchHit /= renderScale; if (useRtCoords) { touchHit = ScreenWarp.ScreenToRT(touch.position); } HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; // Adjust for position and scaling of final rendering. hit -= renderPosition; hit /= renderScale; if (useRtCoords) { //hit = MouseInput.GetMouseInRtCoords(); } HandleMouseInput(hit); } } // end if active. } // end of Update()
public override void Render(Camera camera) { GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; HelpOverlay.RefreshTexture(); RenderTarget2D rt = UI2D.Shared.RenderTargetDepthStencil1280_720; Vector2 screenSize = BokuGame.ScreenSize; Vector2 rtSize = new Vector2(rt.Width, rt.Height); if (skipFrames > 0 || shared.waitingForStorage) { InGame.Clear(Color.Black); --skipFrames; return; } shared.liveFeed.FeedSize = shared.liveFeed.ResetScrollBoxSize; InGame.SetRenderTarget(rt); // Clear the screen & z-buffer. InGame.Clear(Color.Black); // Apply the background. ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); Vector2 position = Vector2.Zero; quad.Render(shared.backgroundTexture, position, rtSize, @"TexturedNoAlpha"); Color textColor = new Color(21, 125, 178); if (parent.newWorldDialog.Active) { // Hide the dialog if auth UI is active. Just keeps things cleaner. if (!AuthUI.IsModalActive) { // If options menu is active, render instead of main menu. parent.newWorldDialog.Render(new Vector2(rt.Width, rt.Height)); } } else if (shared.optionsMenu.Active) { // Hide the menu if auth UI is active. Just keeps things cleaner. if (!AuthUI.IsModalActive) { // If options menu is active, render instead of main menu. shared.optionsMenu.Render(); } } else { // Render url SpriteBatch batch = UI2D.Shared.SpriteBatch; UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont24; Vector2 size = Font().MeasureString(shared.screenUrl); Vector2 pos = new Vector2(rt.Width / 2 - size.X / 2, 586); batch.Begin(); TextHelper.DrawString(Font, shared.screenUrl, pos, textColor); batch.End(); shared.urlBox.Set(pos, pos + size); // Hide the menu if auth UI is active. Just keeps things cleaner. if (!AuthUI.IsModalActive) { // Render menu using local cameras. ShaderGlobals.SetCamera(shared.camera); shared.menu.WorldMatrix = Matrix.CreateTranslation(0.0f, -0.3f, 0.0f); shared.menu.Render(shared.camera); } // Render Boku. ShaderGlobals.SetCamera(shared.bokuCamera); string oldRig = BokuGame.bokuGame.shaderGlobals.PushLightRig(ShaderGlobals.GreeterRigName); // TODO (****) How to temporarily disable point lights??? // Do we really need to? //Luz.SetToEffect(true); // disable scene point lights if (BokuGame.bMarsMode) { shared.boku.Movement.Position = new Vector3(-0.0f, 0.25f, -0.5f); shared.boku.ReScale = 0.50f; //quad = ScreenSpaceQuad.GetInstance(); //float wid=shared.jplTexture.Width/2; //position = new Vector2(1250-(wid), 20); //quad.Render(shared.jplTexture, position, new Vector2(wid, shared.jplTexture.Height/2), @"TexturedRegularAlpha"); } else { shared.boku.Movement.Position = new Vector3(0.0f, 0.0f, 0.0f); } fVal += 0.01f; // Be sure to set the right camera so the env map looks correct. ShaderGlobals.SetCamera(shared.bokuCamera); shared.boku.RenderObject.Render(shared.bokuCamera); // TODO (****) How to temporarily disable point lights??? //Luz.SetToEffect(false); // re-enable scene point lights BokuGame.bokuGame.shaderGlobals.PopLightRig(oldRig); } InGame.RestoreRenderTarget(); InGame.Clear(new Color(20, 20, 20)); InGame.SetViewportToScreen(); // Copy the rendered scene to the backbuffer. { ScreenWarp.FitRtToScreen(rtSize); quad.Render(rt, ScreenWarp.RenderPosition, ScreenWarp.RenderSize, @"TexturedNoAlpha"); } // Render news feed. if (!shared.optionsMenu.Active) { shared.liveFeed.Render(); } // Hide overlay if auth UI is active. if (!AuthUI.IsModalActive) { HelpOverlay.Render(); } // Render text dialogs if being shown by OptionsMenu. // TODO (****) Need to get rid of rendering to RTs where possible. // TODO (****) Need to split OptionsMenu from MainMenu. if (shared.optionsMenu.Active) { InGame.inGame.shared.smallTextDisplay.Render(); InGame.inGame.shared.scrollableTextDisplay.Render(); } MainMenu.Instance.prevSessionCrashedMessage.Render(); MainMenu.Instance.noCommunityMessage.Render(); MainMenu.Instance.noSharingMessage.Render(); } // end of Render()
public override void Update() { shared.timer.Update(); // Keep Kodu animating even if a dialog is active. shared.boku.UpdateFace(); shared.boku.UpdateAnimations(); if (AuthUI.IsModalActive) { return; } if (parent.newWorldDialog.Active) { parent.newWorldDialog.Update(); return; } // If not modal, always show status. AuthUI.ShowStatusDialog(); // Update the dialogs. parent.prevSessionCrashedMessage.Update(); parent.noCommunityMessage.Update(); parent.noSharingMessage.Update(); // Don't do anything else until the user reads and dismisses the dialogs. if (parent.prevSessionCrashedMessage.Active || parent.exitingKodu) { return; } // Update the options menu. Do this first so that if it is active it can steal input. shared.optionsMenu.Update(); // Main menu should always be active. shared.menu.Active = true; // If OptionsMenu is active, don't look at input. This is a problem for touch input // which doesn't support any kind of "ClearAllWasPressedState" functionality. if (!shared.optionsMenu.Active) { // Check for click on signOut tile or url. if (MouseInput.Left.WasPressed || Actions.Select.WasPressed || TouchInput.WasTouched) { TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { touch.position = ScreenWarp.ScreenToRT(touch.position); } Vector2 mouseHit = MouseInput.GetMouseInRtCoords(); // url is in rt coords. if (shared.urlBox.Contains(mouseHit) || (null != touch && shared.urlBox.Contains(touch.position))) { #if NETFX_CORE Launcher.LaunchUriAsync(new Uri(KoduGameLabUrl)); #else Process.Start(KoduGameLabUrl); #endif MouseInput.Left.ClearAllWasPressedState(); } } // Enable resume option if we have something to resume to. if (InGame.UnDoStack.HaveResume() && (shared.menu.Item(0) != Strings.Localize("mainMenu.resume"))) { shared.menu.InsertText(Strings.Localize("mainMenu.resume"), 0); } shared.liveFeed.UpdateFeed(); shared.liveFeed.Update(shared.camera); if (!UpdateNonMenuItems()) { // JW - Only update the menu and process input if the interactive non-menu // items didn't already handle the input. int curIndex = shared.menu.CurIndex; shared.menu.Update(shared.camera, ref shared.worldMatrix); int newIndex = shared.menu.CurIndex; // If the user made a menu change, have boku glance over. if (curIndex != newIndex) { shared.boku.DirectGaze(new Vector3(0.2f, -0.4f, 0.08f - 0.05f * newIndex), 0.5f); } } } if (Actions.MiniHub.WasPressed && InGame.XmlWorldData != null) { parent.Deactivate(); InGame.inGame.SwitchToMiniHub(); return; } #if IMPORT_DEBUG if (!string.IsNullOrEmpty(StartupWorldFilename)) { LevelPackage.DebugPrint("MainMenu"); LevelPackage.DebugPrint(" StartupWorldFilename : " + StartupWorldFilename); } #endif // Jump into the startup world, if it was specified. if (!String.IsNullOrEmpty(StartupWorldFilename)) { if (Storage4.FileExists(StartupWorldFilename, StorageSource.All)) { #if IMPORT_DEBUG LevelPackage.DebugPrint(" level exists, trying to load and run"); #endif if (BokuGame.bokuGame.inGame.LoadLevelAndRun(StartupWorldFilename, keepPersistentScores: false, newWorld: false, andRun: true)) { #if IMPORT_DEBUG LevelPackage.DebugPrint(" success on load and run"); #endif parent.Deactivate(); } #if IMPORT_DEBUG else { LevelPackage.DebugPrint(" fail to load and run"); } #endif shared.waitingForStorage = false; } #if IMPORT_DEBUG else { LevelPackage.DebugPrint(" level not found"); } #endif StartupWorldFilename = null; } // Set news feed state to opposite of options menu. This allows the // News Feed to "hide" when the Options Menu is active. if (shared.optionsMenu.Active) { shared.liveFeed.Deactivate(); } else { shared.liveFeed.Activate(); shared.liveFeed.UpdateFeed(); } } // end of Update()
private void HandleTouchInput(Camera camera) { if (GamePadInput.ActiveMode != GamePadInput.InputMode.Touch) { return; } // Touch input // If the touch is over the menu, move the selection index to the item under the mouse. // On touch down, make the item (if any) under the touch the ClickedOnItem. // On tap, if the touch is still over the ClickedOnItem, activate it. If not, just clear ClickedOnItem. TouchContact touch = TouchInput.GetOldestTouch(); if (touch != null) { Vector2 hitUV = TouchInput.GetHitUV(touch.position, camera, ref invWorldMatrix, width, height, useRtCoords: 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 touchItem = -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 (true) // touch.position != touch.previousPosition) { CurIndex = i; } touchItem = i; } } //if ( TouchInput.TapGesture.WasTapped() ) if (TouchInput.IsTouched) { if (touchItem != -1) { touch.TouchedObject = itemList[touchItem]; } } if (TouchGestureManager.Get().TapGesture.WasTapped()) { // Make sure we're still over the ClickedOnItem. if (touchItem != -1 && touch.TouchedObject == itemList[touchItem]) { ToggleState(); } } Vector2 hit = touch.position; if (useRtCoords) { hit = ScreenWarp.ScreenToRT(hit); } if (changeBox.Touched(touch, hit)) { ToggleState(); } if (backBox.Touched(touch, hit)) { Deactivate(); Foley.PlayBack(); } // Allow Swipeto cycle through elements. // Allow scroll wheel to cycle through elements. SwipeGestureRecognizer swipeGesture = TouchGestureManager.Get().SwipeGesture; if (swipeGesture.WasSwiped()) { if (swipeGesture.SwipeDirection == Boku.Programming.Directions.South) { curIndex -= 6; if (curIndex < 0) { curIndex = itemList.Count - 1; } Foley.PlayShuffle(); } else if (swipeGesture.SwipeDirection == Boku.Programming.Directions.North) { curIndex += 6; if (curIndex > (itemList.Count - 1)) { curIndex = 0; } Foley.PlayShuffle(); } } // If we click outside of the list, close it treating it as if select was chosen. //if (TouchInput.TapGesture.WasTapped() && touch.touchedObject == null) if (TouchInput.WasTouched && touch.TouchedObject == null) { Deactivate(); } } }
} // end of DeleteText() private void HandleMouseInput(Camera camera) { if (GamePadInput.ActiveMode != GamePadInput.InputMode.KeyboardMouse) { return; } // 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: 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) { if (mouseOverItem != -1) { MouseInput.ClickedOnObject = itemList[mouseOverItem]; } } if (MouseInput.Left.WasReleased) { // Make sure we're still over the ClickedOnItem. if (mouseOverItem != -1 && MouseInput.ClickedOnObject == itemList[mouseOverItem]) { ToggleState(); } } Vector2 hit = MouseInput.PositionVec; if (useRtCoords) { hit = ScreenWarp.ScreenToRT(hit); } if (changeBox.LeftPressed(hit)) { ToggleState(); } if (backBox.LeftPressed(hit)) { Deactivate(); Foley.PlayBack(); } // Allow scroll wheel to cycle through elements. int wheel = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (wheel > 0) { --curIndex; if (curIndex < 0) { curIndex = itemList.Count - 1; } Foley.PlayShuffle(); } else if (wheel < 0) { ++curIndex; if (curIndex >= itemList.Count) { curIndex = 0; } Foley.PlayShuffle(); } // If we click outside of the list, close it treating it as if select was chosen. if (MouseInput.Left.WasPressed && MouseInput.ClickedOnObject == null) { Deactivate(); } }
public void PreRender() { RenderTarget2D rt = Shared.RenderTargetDepthStencil1280_720; Vector2 rtSize = new Vector2(rt.Width, rt.Height); ScreenWarp.FitRtToScreen(rtSize); // Render the scene to our rendertarget. InGame.SetRenderTarget(rt); InGame.Clear(Color.Transparent); // Set up params for rendering UI with this camera. ShaderGlobals.SetCamera(camera); ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); SpriteBatch batch = Shared.SpriteBatch; var center = new Vector2(640, 360); var dialogMin = center - new Vector2(dialogWidth / 2, dialogHeight / 2); var dialogMax = center + new Vector2(dialogWidth / 2, dialogHeight / 2); // Top and bottom of dialog. var size = new Vector2(dialogWidth, whiteTop.Height); Vector2 pos = dialogMin; quad.Render(whiteTop, new Vector4(0, 0, 0, 1), pos, size, "TexturedRegularAlpha"); pos += new Vector2(0, dialogHeight - 16); quad.Render(whiteBottom, new Vector4(0, 0, 0, 1), pos, size, "TexturedRegularAlpha"); //dialog center size = new Vector2(dialogWidth, dialogHeight); pos = dialogMin; pos.Y += 16; size.Y = dialogHeight - 32; pos.X += 1; //to match size of top and bottom pieces size.X -= 2; // quad.Render(new Vector4(0, 0, 0, 1), pos, size); //top and bottom highlights int highlightMargin = 3; pos = dialogMin + new Vector2(highlightMargin, 2); size.X = dialogWidth - 2 * highlightMargin; size.Y = 30; quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), pos, size, "AdditiveBlendWithAlpha"); pos = dialogMin + new Vector2(highlightMargin, dialogHeight - 60); size.X = dialogWidth - 2 * highlightMargin; size.Y = 30; quad.Render(blackHighlight, new Vector4(1, 1, 1, 0.2f), pos, size, "AdditiveBlendWithAlpha"); batch.Begin(); //Dialog title. TextHelper.DrawString(Shared.GetGameFont20, title, dialogMin + new Vector2(10, 10 + 5), Color.White); //Ok and Cancel buttons var buttonSize = cancelButton.GetSize(); pos = dialogMax - buttonSize - new Vector2(10, 10); cancelButton.Render(pos); buttonSize = okButton.GetSize(); pos -= new Vector2(buttonSize.X + 20, 0); okButton.Render(pos); batch.End(); // Render text box textLineEditor.Render(camera); InGame.RestoreRenderTarget(); InGame.SetViewportToScreen(); } // end of Render()
} // end of c'tor public void Update(Camera camera) { if (Active) { GamePadInput pad = GamePadInput.GetGamePad0(); if (InGame.inGame.State == InGame.States.Active && InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim) { // We need to be able to slip out to the mini-hub here since // continuous, repeated calls to ModalHint can lock the // user out of control. if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); Deactivate(); InGame.inGame.SwitchToMiniHub(); } // We need to be able to slip out to the tool menu here since // continuous, repeated calls to ModalHint can lock the // user out of control. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Deactivate(); InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } } if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); // Disable this hint for this session. if (curHint.ShowOnce) { curHint.Disabled = true; } Deactivate(); } if (Actions.X.WasPressed) { Actions.X.ClearAllWasPressedState(); // Disable this hint until reset by user. XmlOptionsData.SetHintAsDisabled(curHint.ID); // Disable this hint for this session. if (curHint.ShowOnce) { curHint.Disabled = true; } Deactivate(); } if (useBackgroundThumbnail) { camera = new PerspectiveUICamera(); camera.Resolution = new Point(1280, 720); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; if (useRtCoords) { touchHit = ScreenWarp.ScreenToRT(touch.position); } HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; if (useRtCoords) { hit = MouseInput.GetMouseInRtCoords(); } HandleMouseInput(hit); } } // end if active. } // end of Update()
} // end of c'tor public void Update(Camera camera) { if (Active) { // If we've just been activated, ignore input to prevent // accidental dismissal. if (Time.WallClockTotalSeconds < activationTime + deadInputTime) { return; } GamePadInput pad = GamePadInput.GetGamePad0(); if (InGame.inGame.State == InGame.States.Active && InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim) { #if !NETFX_CORE // For games using micro:bit, allow buttons to dismiss ingame dialogs. if (InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim) { Microbit bit = MicrobitExtras.GetMicrobitOrNull(GamePadSensor.PlayerId.All); if (bit != null) { // Allow either button to dismiss display. if (bit.State.ButtonA.IsPressed() || bit.State.ButtonB.IsPressed()) { Deactivate(); } } } #endif // We need to be able to slip out to the mini-hub here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); Deactivate(); InGame.inGame.SwitchToMiniHub(); } // We need to be able to slip out to the tool menu here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Deactivate(); InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } } if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); Deactivate(); } // If we're rendering this into a 1280x720 rt we need a matching camera to calc mouse hits. if (useBackgroundThumbnail) { camera = new PerspectiveUICamera(); camera.Resolution = new Point(1280, 720); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; if (useRtCoords) { touchHit = ScreenWarp.ScreenToRT(touch.position); } HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; if (useRtCoords) { hit = MouseInput.GetMouseInRtCoords(); } HandleMouseInput(hit); } } // end if active. } // end of Update()