} // end of HandleMouseInput() public override void HandleTouchInput(TouchContact touch, Vector2 hitUV) { // Press in slider region? if (touch.phase == TouchPhase.Began && hitUV.Y > 0.5f) { touch.TouchedObject = this; } if (touch.TouchedObject == this && TouchPhase.Stationary != touch.phase) { // Adjust for ends of slide not filling all the way to border of shape. float value = hitUV.X; value = (value - 0.05f) / 0.9f; value = MyMath.Clamp(value, 0.0f, 1.0f); float delta = GetSliderPercentage() - value; if (SetSliderPercentage(value)) { // Only make nose if the value changes. if (delta > 0) { Foley.PlayClickDown(); } else if (delta < 0) { Foley.PlayClickUp(); } } } } // end of HandleTouchInput()
} // end of UIGridBaseModularSliderElement Update() public override void HandleMouseInput(Vector2 hitUV) { // Press in slider region? if (MouseInput.Left.WasPressed && hitUV.Y > 0.5f) { MouseInput.ClickedOnObject = this; } if (MouseInput.ClickedOnObject == this && MouseInput.Left.IsPressed) { // Adjust for ends of slide not filling all the way to border of shape. float value = hitUV.X; value = (value - 0.05f) / 0.9f; value = MyMath.Clamp(value, 0.0f, 1.0f); float delta = GetSliderPercentage() - value; if (SetSliderPercentage(value)) { // Only make nose if the value changes. if (delta > 0) { Foley.PlayClickDown(); } else if (delta < 0) { Foley.PlayClickUp(); } } } } // end of HandleMouseInput()
} // end of TextInput() // TODO (****) Clean this up. We're mixing text as input with text as control here. // Probably the right thing to do would be to push/pop the text input callbacks // dynamically to mirror the state we're in. public void KeyInput(Keys key) { if (EditingCreator || EditingPin) { KeyboardInput.ClearAllWasPressedState(key); TextBlob curBlob = EditingCreator ? creatorBlob : pinBlob; //string curString = EditingCreator ? curCreator : curPin; //int curLength = curString.Length; switch (key) { case Keys.Enter: Foley.PlayClickDown(); OnAccept(); break; case Keys.Escape: Foley.PlayClickDown(); OnCancel(); break; case Keys.Left: curBlob.CursorLeft(); Foley.PlayClickDown(); break; case Keys.Right: curBlob.CursorRight(); Foley.PlayClickDown(); break; case Keys.Home: Foley.PlayClickDown(); creatorBlob.Home(); break; case Keys.End: Foley.PlayClickDown(); curBlob.End(); break; case Keys.Back: curBlob.Backspace(); Foley.PlayClickDown(); break; case Keys.Delete: curBlob.Delete(); break; case Keys.Tab: ToggleEditTarget(); break; } // end of switch on special characters. } } // end of KeyInput()
} // end of UpdateObj TextInput() public void KeyInput(Keys key) { switch (key) { case Keys.Enter: Foley.PlayClickDown(); KeyboardInput.ClearAllWasPressedState(Keys.Enter); Accept(); break; case Keys.Escape: Foley.PlayClickDown(); KeyboardInput.ClearAllWasPressedState(Keys.Escape); Cancel(); break; case Keys.Left: Foley.PlayClickDown(); shared.blob.CursorLeft(); break; case Keys.Right: Foley.PlayClickDown(); shared.blob.CursorRight(); break; //case Keys.Up: // shared.blob.CursorUp(); // break; //case Keys.Down: // shared.blob.CursorDown(); // break; case Keys.Home: Foley.PlayClickDown(); shared.blob.Home(); break; case Keys.End: Foley.PlayClickDown(); shared.blob.End(); break; case Keys.Back: Foley.PlayClickDown(); shared.blob.Backspace(); break; case Keys.Delete: Foley.PlayClickDown(); shared.blob.Delete(); break; } // end of switch on special characters. } // end of UpdateObj KeyInput()
} // end of SetXButton() public override void Update(ref Matrix parentMatrix) { // Check for input but only if selected. if (selected) { GamePadInput pad = GamePadInput.GetGamePad0(); bool changed = false; // Handle input changes here. if (pad.DPadLeft.WasPressed || pad.DPadLeft.WasRepeatPressed || pad.LeftStickLeft.WasPressed || pad.LeftStickLeft.WasRepeatPressed) { curIndex = (curIndex + pictures.Count - 1) % pictures.Count; Foley.PlayClickDown(); changed = true; } if (pad.DPadRight.WasPressed || pad.DPadRight.WasRepeatPressed || pad.LeftStickRight.WasPressed || pad.LeftStickRight.WasRepeatPressed) { curIndex = (curIndex + 1) % pictures.Count; Foley.PlayClickUp(); changed = true; } if (pad.ButtonX.WasPressed) { if (onXButton != null) { onXButton(curIndex); } } if (changed || curIndex == -1) { RecalcPositions(); if (onChange != null) { onChange(curIndex); } } } RefreshTexture(); base.Update(ref parentMatrix); } // end of UIGridPictureListElement Update()
} // end of SetXButton() public override void Update(ref Matrix parentMatrix) { // Check for input but only if selected. if (selected) { GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.ComboRight.WasPressedOrRepeat) { Actions.ComboRight.ClearAllWasPressedState(); curIndex = (curIndex + 1) % 3; Foley.PlayClickUp(); dirty = true; } if (Actions.ComboLeft.WasPressedOrRepeat) { Actions.ComboLeft.ClearAllWasPressedState(); curIndex = (curIndex + 3 - 1) % 3; Foley.PlayClickDown(); dirty = true; } if (Actions.X.WasPressed) { Actions.X.ClearAllWasPressedState(); if (onXButton != null) { onXButton(curIndex); } } } RefreshTexture(); base.Update(ref parentMatrix); } // end of UIGridModularCameraModeElement Update()
} // end of HandleMouseInput() public override void HandleTouchInput(TouchContact touch, Vector2 hitUV) { // Only respond to clicks in the black region of the element if (hitUV.Y > 0.4f) { int hit = (int)(hitUV.X * 9.0f); if (TouchInput.WasTouched) { // Ignore reselecting the current selection. hitIndex = hit == 4 ? -1 : hit; } if (TouchInput.WasReleased) { if (hit == hitIndex) { if (hit < 4) { int steps = hit == 0 ? 1 : 4 - hit; curIndex = (curIndex + pics.Count - steps) % pics.Count; Foley.PlayClickDown(); recalcPositions = true; dirty = true; } else if (hit > 4) { int steps = hit == 8 ? 1 : hit - 4; curIndex = (curIndex + steps) % pics.Count; Foley.PlayClickDown(); recalcPositions = true; dirty = true; } } hitIndex = -1; } } }
public void TextInput(char c) { shared.lastKeyPressedAt = DateTime.Now; // Handle special character input. if (KeyboardInput.AltWasPressed) { specialChar = null; } if (KeyboardInput.AltIsPressed) { // accumulate keystrokes specialChar += c; return; } //Ignore backspace and return character if (c == '\b' || c == '\r') { return; } var oldText = shared.blob.RawText; shared.blob.InsertString(new string(c, 1)); //Validate the text if required. if (shared.validateTextCallback != null && !shared.validateTextCallback(shared.blob)) { //Invalid so restore text. shared.blob.RawText = oldText; Foley.PlayNoBudget(); } else { Foley.PlayClickDown(); } } // end of UpdateObj TextInput()
public void TextInput(char c) { // Handle special character input. if (KeyboardInput.AltWasPressed) { specialChar = null; } if (KeyboardInput.AltIsPressed) { // accumulate keystrokes specialChar += c; return; } // Grab the tab and use it for cycling through the focus options. if (c == '\t') { ToggleEditTarget(); KeyboardInput.ClearAllWasPressedState(Keys.Tab); return; } if (EditingCreator || EditingPin) { // Ignore enter. if (c == 13) { return; } string str = new string(c, 1); str = TextHelper.FilterInvalidCharacters(str); if (!string.IsNullOrEmpty(str)) { // Check if we've gotten too long. if (EditingCreator) { creatorBlob.InsertString(str); int width = creatorBlob.GetLineWidth(0); if (width >= creatorBox.Width) { // Bzzzt! Foley.PlayNoBudget(); for (int i = 0; i < str.Length; i++) { creatorBlob.Backspace(); } } else { Foley.PlayClickDown(); } } else if (EditingPin) { // With the pin, max out at 4 digits and only allow digits. if (pinBlob.ScrubbedText.Length > 3 || !char.IsDigit(str[0])) { Foley.PlayNoBudget(); } else { pinBlob.InsertString(str); } } } } } // end of TextInput()
private void HandleMouseInput(Camera uicamera) { if (GamePadInput.ActiveMode != GamePadInput.InputMode.KeyboardMouse) { return; } // If the mouse took over from the touch, it should clear any // highlights the touch had going. Boku.InGame.inGame.TouchEdit.Clear(); Camera camera = Boku.InGame.inGame.shared.camera; MouseEdit mouseEdit = Boku.InGame.inGame.MouseEdit; MouseEdit.MouseHitInfo hitInfo = null; hitInfo = MouseEdit.HitInfo; mouseEdit.DoObject(camera); if (hitInfo.HaveActor) { FocusActor = hitInfo.ActorHit; focusColorIndex = ColorPalette.GetIndexFromColor(FocusActor.Classification.Color); Boku.InGame.ColorPalette.Active = true; } else { FocusActor = null; Boku.InGame.ColorPalette.Active = false; } if (MouseInput.Left.WasReleased) { selectedActor = null; } //don't add if we detected a paste if (MouseInput.Left.WasPressed && !MenusActive && (mouseEdit.MiddleAction != true)) { MouseInput.Left.ClearAllWasPressedState(); if (FocusActor != null) { // Start draggin if over actor. selectedActor = FocusActor; actorOffset = selectedActor.Movement.Position - hitInfo.TerrainPosition; } else if (!MenusActive && !SliderActive && inGame.editObjectUpdateObj.newItemSelectorShim.State != UIShim.States.Active) { // No actor in focus so activate AddItem menu. Vector2 position = new Vector2(hitInfo.TerrainPosition.X, hitInfo.TerrainPosition.Y); inGame.editObjectUpdateObj.ActivateNewItemSelector(position, true); } } if (MouseInput.Left.IsPressed && (selectedActor != null) && (hitInfo != null)) { Vector3 position = hitInfo.TerrainPosition + actorOffset; selectedActor.Movement.Position = Boku.InGame.SnapPosition(position); // Try and keep the bot directly under the mouse cursor while still being at the correct height. // A possible alternative would be to use the cursor's 2d position for the bot and just have the // bot float at the appropriate height over the cursor. This would allow more exact placement of // bots over terrain but it would mean a visual disconnect between where the cursor is and where // the bot is. There would also be a jump when the bot is first clicked on since the terrain // position of the cursor is most likely further back than the bot's current position. if (hitInfo.VerticalOffset == 0.0f) { Vector3 terrainToCameraDir = hitInfo.TerrainPosition - camera.From; terrainToCameraDir.Normalize(); position = hitInfo.TerrainPosition + terrainToCameraDir * (selectedActor.EditHeight / terrainToCameraDir.Z); selectedActor.Movement.Position = Boku.InGame.SnapPosition(position); } // If the actor is supposed to stay above water, try to enforce that. // This can have some strange visual effects since it forces the actor to // float above where the mouse cursor is but the alternative is to have // actor get dragged under water. if (selectedActor.StayAboveWater) { float waterAlt = Terrain.GetWaterBase(position); if (waterAlt != 0) { position.Z = waterAlt + selectedActor.EditHeight; selectedActor.Movement.Position = Boku.InGame.SnapPosition(position); } } Boku.InGame.IsLevelDirty = true; } if (MouseInput.Right.WasReleased) { menuActor = FocusActor; menuCursorPosition = hitInfo.TerrainPosition; // We need to do this repeatedly since the Paste option will // change depending on what's in the cut/paste buffer. SetUpMenus(); if (FocusActor == null) { actorMenu.Deactivate(); noActorMenu.Activate(new Vector2(MouseInput.Position.X, MouseInput.Position.Y)); } else { noActorMenu.Deactivate(); actorMenu.Activate(new Vector2(MouseInput.Position.X, MouseInput.Position.Y)); // Turn off any thought balloons so they don't clutter the menu. ThoughtBalloonManager.RemoveThoughts(FocusActor); } } noActorMenu.Update(); actorMenu.Update(); // Support for changing tree types via up/down arrow keys. if (FocusActor != null && FocusActor.Classification.name == "tree") { inGame.editObjectUpdateObj.MakeTreeChange(FocusActor); } // Color palette support. if (FocusActor != null && !MenusActive && !sliderActive) { int numColors = Boku.InGame.ColorPalette.NumEntries; if (Actions.Left.WasPressedOrRepeat) { focusColorIndex = (focusColorIndex + numColors - 1) % numColors; shared.curObjectColor = focusColorIndex; FocusActor.ClassColor = ColorPalette.GetColorFromIndex(focusColorIndex); Foley.PlayColorChange(); Boku.InGame.IsLevelDirty = true; } if (Actions.Right.WasPressedOrRepeat) { focusColorIndex = (focusColorIndex + 1) % numColors; shared.curObjectColor = focusColorIndex; FocusActor.ClassColor = ColorPalette.GetColorFromIndex(focusColorIndex); Foley.PlayColorChange(); Boku.InGame.IsLevelDirty = true; } } // Align NSEW if (FocusActor != null && !MenusActive && !sliderActive) { if (Actions.Up.WasPressedOrRepeat) { // Rotate clockwise. float targetRotation = MathHelper.PiOver2 * (int)((FocusActor.Movement.RotationZ + MathHelper.TwoPi - 0.0001f) / MathHelper.PiOver2); FocusActor.Movement.RotationZ = targetRotation; Foley.PlayClickUp(); Boku.InGame.IsLevelDirty = true; } if (Actions.Down.WasPressedOrRepeat) { // Rotate counter-clockwise. float targetRotation = MathHelper.PiOver2 * (int)((FocusActor.Movement.RotationZ + MathHelper.PiOver2 + 0.0001f) / MathHelper.PiOver2); FocusActor.Movement.RotationZ = targetRotation; Foley.PlayClickDown(); Boku.InGame.IsLevelDirty = true; } } // Cut/Copy/Paste via keyboard. if (Actions.Cut.WasPressed && FocusActor != null) { inGame.editObjectUpdateObj.CutAction(FocusActor); } if (Actions.Copy.WasPressed && FocusActor != null) { inGame.editObjectUpdateObj.CopyAction(FocusActor); } if (Actions.Paste.WasPressed) { inGame.editObjectUpdateObj.PasteAction(null, hitInfo.TerrainPosition); } // // Figure out help overlay mode. // if (inGame.editObjectUpdateObj.newItemSelectorShim.State == UIShim.States.Active) { // The pie menu is active. HelpOverlay.ReplaceTop("MouseObjectEditAddItemMenu"); } else if (hitInfo != null && hitInfo.HaveActor) { // We have an actor in focus. if (FocusActor != null && FocusActor.Classification.name == "tree") { HelpOverlay.ReplaceTop("MouseEditEditObjectFocusTree"); } else { HelpOverlay.ReplaceTop("MouseEditEditObjectFocus"); } } }
public override void Update(ref Matrix parentMatrix) { // Do we need to render the gradients? GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; RenderTarget2D rt = UI2D.Shared.RenderTarget64_64; for (int i = 0; i < pics.Count; i++) { if (pics[i].texture == null) { if (pics[i].gradient >= 0) { // Create the texture gradient. InGame.SetRenderTarget(rt); ScreenSpaceQuad quad = ScreenSpaceQuad.GetInstance(); quad.RenderGradient(SkyBox.Gradient(pics[i].gradient)); InGame.RestoreRenderTarget(); pics[i].texture = new Texture2D(device, 64, 64, false, SurfaceFormat.Color); // Copy rendertarget result into texture. int[] data = new int[64 * 64]; rt.GetData <int>(data); pics[i].texture.SetData <int>(data); } else { // Load the texture image. pics[i].texture = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\" + pics[i].picName); } dirty = true; } } // Check for input but only if selected. if (selected) { GamePadInput pad = GamePadInput.GetGamePad0(); if (Actions.ComboRight.WasPressedOrRepeat) { curIndex = (curIndex + 1) % pics.Count; Foley.PlayClickUp(); recalcPositions = true; dirty = true; } if (Actions.ComboLeft.WasPressedOrRepeat) { curIndex = (curIndex + pics.Count - 1) % pics.Count; Foley.PlayClickDown(); recalcPositions = true; dirty = true; } } if (recalcPositions) { if (onChange != null) { OnChange(CurIndex); } RefreshPositions(); } RefreshTexture(); base.Update(ref parentMatrix); } // end of UIGridModularPictureListElement Update()
public override void Update(ref Matrix parentMatrix) { // Check for input but only if selected. if (selected) { GamePadInput pad = GamePadInput.GetGamePad0(); bool leftStickTouched = pad.DPadLeft.IsPressed || pad.LeftStickLeft.IsPressed || pad.DPadRight.IsPressed || pad.LeftStickRight.IsPressed; bool rightStickTouched = pad.RightStickLeft.IsPressed || pad.RightStickRight.IsPressed; bool keyboardTouched = KeyboardInput.IsPressed(Keys.Left) || KeyboardInput.IsPressed(Keys.Right); // If there is no scroll input currently, reset fast scroll timer. if (useRightStick) { if (!rightStickTouched) { lastNonPressTime = Time.WallClockTotalSeconds; } } else { // Using left stick. if (!leftStickTouched && !keyboardTouched) { lastNonPressTime = Time.WallClockTotalSeconds; } } double time = Time.WallClockTotalSeconds; double delta = time - lastNonPressTime; FastScrolling = (Time.WallClockTotalSeconds - lastNonPressTime > FastScrollTime); // Handle input changes here. if (useRightStick) { if (pad.RightStickLeft.WasPressedOrRepeat) { if (DecrementCurrentValue()) { Foley.PlayClickDown(); } } if (pad.RightStickRight.WasPressedOrRepeat) { if (IncrementCurrentValue()) { Foley.PlayClickUp(); } } } else { if (Actions.ComboLeft.WasPressedOrRepeat) { if (DecrementCurrentValue()) { Foley.PlayClickDown(); } } if (Actions.ComboRight.WasPressedOrRepeat) { if (IncrementCurrentValue()) { Foley.PlayClickUp(); } } } } RefreshTexture(); base.Update(ref parentMatrix); } // end of UIGridBaseModularSliderElement Update()