} // end of VictoryOverlay LoadContent() public static void InitDeviceResources(GraphicsDevice device) { // Done here since the camera needs a valid graphics device to init correctly. camera = new PerspectiveUICamera(); // Init the vertex buffer. if (vbuf == null) { vbuf = new VertexBuffer(device, typeof(Vertex), 4, BufferUsage.WriteOnly); // Check the dimensions of the destination. // TODO (****) *** This needs to scale with the window. int width = device.Viewport.Width; int height = device.Viewport.Height; float pixelWidth = 1.0f / width; float pixelHeight = 1.0f / height; // Fill in the local vertex data. localVerts[0] = new Vertex(new Vector2(-1.0f - pixelWidth, 1.0f + pixelHeight), new Vector2(0.0f, 0.0f)); localVerts[1] = new Vertex(new Vector2(1.0f - pixelWidth, 1.0f + pixelHeight), new Vector2(1.0f, 0.0f)); localVerts[2] = new Vertex(new Vector2(-1.0f - pixelWidth, -1.0f + pixelHeight), new Vector2(0.0f, 1.0f)); localVerts[3] = new Vertex(new Vector2(1.0f - pixelWidth, -1.0f + pixelHeight), new Vector2(1.0f, 1.0f)); // Copy to vertex buffer. vbuf.SetData <Vertex>(localVerts); } }
} // end of HandleMouseInput() public override void Update(PerspectiveUICamera camera) { if (Active) { if (Hidden) { if (HelpOverlay.Peek() == (UseAltOverlay ? altHelpOverlay : helpOverlay)) { HelpOverlay.Pop(); } } else { if (Actions.MaterialFabric.WasPressed) { Actions.MaterialFabric.ClearAllWasPressedState(); FabricMode = true; RefreshPositions(); } if (Actions.MaterialCubic.WasPressed) { Actions.MaterialCubic.ClearAllWasPressedState(); FabricMode = false; RefreshPositions(); } HelpOverlay.ReplaceTop(UseAltOverlay ? altHelpOverlay : helpOverlay); } } base.Update(camera); }
} // 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 LiveFeedDisplay 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 LiveFeedDisplay 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); // Touch input on grid. // Hit the in-focus tile, then open popup. // Hit another tile, then bring that one to focus. Note because of overlap of // the tiles we should do this center-out. Vector2 touchHit = TouchInput.GetAspectRatioAdjustedPosition( touch.position, camera, useOverscanForHitTesting ); HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.GetAspectRatioAdjustedPosition(camera, useOverscanForHitTesting); HandleMouseInput(hit); } } // end if active. } // end of Update()
} // end of c'tor public void Update(Camera camera) { if (gettingFeeds) { msNewsFeed.Update(); if (msNewsFeed.CurrentState == NewsFeeds.OpState.Failed) { newsScroller.Clear(); FeedMs item = new FeedMs(FeedSize, "Failed to get news feed...", TitleFont, DateFont, BodyFont); newsScroller.AddItem(item); gettingFeeds = false; newsScroller.Dirty = true; } else if (msNewsFeed.CurrentState == NewsFeeds.OpState.Retrieving) { newsScroller.Clear(); FeedMs item = new FeedMs(FeedSize, "Updating news...", TitleFont, DateFont, BodyFont); newsScroller.AddItem(item); //gettingFeeds = false; newsScroller.Dirty = true; } else if (msNewsFeed.CurrentState == NewsFeeds.OpState.Retrieved) { try { // Done getting Tweets newsScroller.Clear(); List <FeedMs> feedList = msNewsFeed.GetFeedList( (int)(FeedSize.X - newsScroller.ScrollBoxSize.X), TitleFont, DateFont, BodyFont); if (feedList != null) { foreach (FeedMs newsItem in feedList) { newsScroller.AddItem(newsItem); } } newsScroller.ResizeItemWidths(); gettingFeeds = false; newsScroller.Dirty = true; } catch { newsScroller.Clear(); FeedMs item = new FeedMs(FeedSize, "Error getting news feed...", TitleFont, DateFont, BodyFont); newsScroller.AddItem(item); gettingFeeds = false; newsScroller.Dirty = true; } } } Vector2 pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y); if (moreLessHitBox.Contains(pureMouseHit) && MouseInput.Left.WasReleased) { expanded = !expanded; } //check touch hit TouchContact touch = TouchInput.GetOldestTouch(); if (TouchInput.WasLastReleased && moreLessHitBox.Contains(touch.position)) { expanded = !expanded; } // Even if not active we need to refresh the rendertarget. newsScroller.RefreshRT(); if (Active) { newsScroller.Update(camera); if (camera == null) { camera = new PerspectiveUICamera(); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.GetAspectRatioAdjustedPosition(camera, useOverscanForHitTesting); pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y); if (!IsInScrollwindow(pureMouseHit)) { // Don't Deactivate here just because the mouse cursor has left the bounds of the scroll window. // We should only deactivate if ComboRight is pressed. //Deactivate(); // But if we're out of bounds and the used clicks, then Deactivate() if (MouseInput.Left.WasPressed) { Deactivate(); } } else if (MouseInput.PrevPosition != MouseInput.Position) { newsScroller.Activate(); } if (true) //newsScroller.IsFocused) { if (Actions.ComboUp.WasPressedOrRepeat) { newsScroller.FocusPrev(); } else if (Actions.ComboDown.WasPressedOrRepeat) { newsScroller.FocusNext(); } else if (Actions.ComboRight.WasPressed) { Deactivate(); } if (Actions.ZoomIn.WasPressedOrRepeat) { newsScroller.FocusPrevItem(); } else if (Actions.ZoomOut.WasPressedOrRepeat) { newsScroller.FocusNextItem(); } } if (Actions.ComboLeft.WasPressed) { newsScroller.Activate(); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad) { HandleGamepadInput(); } } // end if active. } // end of Update()
} // end of BasePicker RestorePreviousChoice() public virtual void Update(PerspectiveUICamera camera) { if (active) { if (hidden) { // Note, even though we're hidden we may still be rendering our fade out. double elapsedTime = Time.WallClockTotalSeconds - startFadeTime; if (elapsedTime >= fadeTime) { Alpha = 0.0f; } else { Alpha = 1.0f - (float)(elapsedTime / fadeTime); } } else { // Not hidden, so respond to user input. int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (Actions.PickerRight.WasPressedOrRepeat || scroll > 0) { Actions.PickerRight.ClearAllWasPressedState(); DecrementFocus(); } if (Actions.PickerLeft.WasPressedOrRepeat || scroll < 0) { Actions.PickerLeft.ClearAllWasPressedState(); IncrementFocus(); } if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); SelectCurrentChoice(); Foley.PlayPressA(); } if (Actions.Cancel.WasPressedOrRepeat) { Actions.Cancel.ClearAllWasPressedState(); RestorePreviousChoice(); Foley.PlayBack(); } bool handled = false; if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { handled = HandleTouchInput(camera); } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { handled = HandleMouseInput(camera); } if (!handled) { // If the user clicked but didn't hit any of the picker elements, close the picker. // If alt is pressed, they must be in eyedropper mode. if ((MouseInput.Left.WasPressed && !KeyboardInput.AltIsPressed) || (TouchGestureManager.Get().TapGesture.WasRecognized)) { SelectCurrentChoice(); Foley.PlayPressA(); } else if (Actions.Sample.WasPressed || MouseEdit.TriggerSample() || TouchEdit.TriggerSample()) { Actions.Sample.ClearAllWasPressedState(); int t = OnSampleType(); if (t >= 0) { OnSetType(t); Point selection = grid.SelectionIndex; selection.X = t; grid.SelectionIndex = selection; Foley.PlayCut(); } else { Foley.PlayNoBudget(); } } } grid.Update(ref worldMatrix); } } // end if active } // end of BasePicker Update()
public MicrobitPatternEditor() { // Create a blob of common parameters. UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob(); blob.width = 512.0f / 96.0f; // 5.33333 blob.height = blob.width / 5.0f; // 1.06667 blob.edgeSize = 0.06f; blob.Font = UI2D.Shared.GetGameFont24Bold; blob.textColor = Color.White; blob.dropShadowColor = Color.Black; blob.useDropShadow = true; blob.invertDropShadow = false; blob.unselectedColor = new Color(new Vector3(4, 100, 90) / 255.0f); blob.selectedColor = new Color(new Vector3(5, 180, 160) / 255.0f); blob.normalMapName = @"Slant0Smoothed5NormalMap"; blob.justify = UIGridModularCheckboxElement.Justification.Left; brightnessSlider = new UIGridModularIntegerSliderElement(blob, Strings.Localize("microbitPatternEditor.brightness")); brightnessSlider.Position = new Vector3(1.06667f, 1.01f, 0); brightnessSlider.MinValue = 0; brightnessSlider.MaxValue = 255; brightnessSlider.IncrementByAmount = 1; brightnessSlider.FastScrollScalar = 10; brightnessSlider.UseRightStick = true; brightnessSlider.OnChange = delegate(int brightness) { pattern.Brightness = brightness; }; brightnessSlider.SetHelpOverlay = false; durationSlider = new UIGridModularFloatSliderElement(blob, Strings.Localize("microbitPatternEditor.duration")); durationSlider.Position = new Vector3(1.06667f, 0.0f, 0); durationSlider.MinValue = 0.0f; durationSlider.MaxValue = 5.0f; durationSlider.IncrementByAmount = 0.1f; durationSlider.CurrentValueImmediate = 0.1f; durationSlider.UseRightStick = true; durationSlider.OnChange = delegate(float duration) { pattern.Duration = duration; }; durationSlider.SetHelpOverlay = false; blob.width = 2.06777f; blob.height = blob.width; ledGrid = new UIGrid2DLEDArrayElement(blob); ledGrid.Position = new Vector3(-2.58f, 0.51f, 0); ledGrid.SetHelpOverlay = false; blob.width = brightnessSlider.Width + ledGrid.Width - 0.04f; blob.height = brightnessSlider.Height * 0.75f; bar = new UIGrid2DButtonBarElement(blob); bar.Position = new Vector3(0.055f, -0.875f, 0); bar.SetHelpOverlay = false; camera = new PerspectiveUICamera(); leftStickPosition = new Vector2(-3.9f, 0.5f); rightStickPositionBrightness = new Vector2(4.0f, 1.0f); rightStickPositionDuration = new Vector2(4.0f, 0.0f); rightStickPosition = rightStickPositionBrightness; // Buttons { GetTexture getTexture = delegate() { return(ButtonTextures.BButton); }; cancelButton = new Button(Strings.Localize("saveLevelDialog.cancel"), labelColor, getTexture, UI2D.Shared.GetGameFont20); } { GetTexture getTexture = delegate() { return(ButtonTextures.AButton); }; saveButton = new Button(Strings.Localize("saveLevelDialog.save"), labelColor, getTexture, UI2D.Shared.GetGameFont20); } { GetTexture getTexture = delegate() { return(ButtonTextures.YButton); }; toggleLEDButton = new Button(Strings.Localize("microbitPatternEditor.toggleLED"), labelColor, getTexture, UI2D.Shared.GetGameFont20); } } // end of c'tor
} // 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()