/// <summary> /// Select which help overlay to be currently displayed. /// </summary> protected virtual void SelectOverlay() { Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if (InStretchMode) { string helpStart = HelpOverlayStartID == null ? HelpOverlayID : HelpOverlayStartID; string helpGoing = HelpOverlayGoingID == null ? HelpOverlayID : HelpOverlayGoingID; if (!bButtonExits) { SetOverlay(helpStart); } else { SetOverlay(helpGoing); } } else { if (HelpOverlayMagicBrushID != null && brush.Type == Brush2DManager.BrushType.Selection) { SetOverlay(HelpOverlayMagicBrushID); } else { SetOverlay(HelpOverlayID); } } }
/// <summary> /// Check whether cursor should be displayed. /// </summary> /// <returns></returns> protected virtual void CheckSelectCursor(bool alwaysShowCursor) { /// The new pointy cursor seems always helpful, even if slightly /// redundant with the brush. inGame.ShowCursor(); Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if (brush == null) { //inGame.ShowCursor(); return; } bool isSelection = (brush.Type & Brush2DManager.BrushType.Selection) != 0; bool isStretch = (brush.Type & Brush2DManager.BrushType.StretchedAll) != 0; if (isSelection) { inGame.Cursor3D.Hidden = false; inGame.Terrain.MakeSelection(shared.editBrushPosition); } else { inGame.Cursor3D.Hidden = !alwaysShowCursor; inGame.Terrain.EndSelection(); //if (!alwaysShowCursor) // inGame.HideCursor(); } }
} // end of LevelTool Update() #endregion Public #region Internal /// <summary> /// Override when to show/hide the 3d cursor. /// </summary> /// <returns></returns> protected override void CheckSelectCursor(bool alwaysShowCursor) { Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if (brush == null) { inGame.ShowCursor(); } }
} // end of DelObjTool Update() #endregion Public #region Internal private void BuildSelected() { List <GameThing> gameThings = inGame.gameThingList; selected.Clear(); unselected.Clear(); Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); bool isSelection = (brush != null) && ((brush.Type & Brush2DManager.BrushType.Selection) != 0); for (int i = 0; i < gameThings.Count; ++i) { GameActor actor = gameThings[i] as GameActor; if (actor != null) { Vector3 pos = actor.Movement.Position; bool actorSelected = false; if (isSelection) { actorSelected = Terrain.Current.PositionSelected(pos); } else if (InStretchMode) { actorSelected = Terrain.Current.PositionSelected(pos, shared.editBrushIndex, shared.editBrushStart, shared.editBrushPosition, shared.editBrushRadius); } else { actorSelected = Terrain.Current.PositionSelected(pos, shared.editBrushIndex, shared.editBrushPosition, shared.editBrushRadius); } if (actorSelected) { actor.MakeSelected(true, Vector4.UnitX); selected.Add(actor); } else { actor.MakeSelected(false, Vector4.Zero); unselected.Add(actor); } } } }
// c'tor public BrushPicker() : base(null, null) { helpOverlay = @"BrushPicker"; altHelpOverlay = @"BrushPickerMaterial"; // Create brush elements for the grid. // Start with a blob of common parameters. UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob(); blob.width = 1.0f; blob.height = 1.0f; blob.edgeSize = 0.1f; blob.selectedColor = Color.Transparent; blob.unselectedColor = Color.Transparent; blob.normalMapName = @"QuarterRound4NormalMap"; blob.altShader = true; blob.ignorePowerOf2 = true; // Create and fill the list. int maxBrushes = Brush2DManager.NumBrushes; brushList = new List <UIGrid2DBrushElement>(maxBrushes); UIGrid2DBrushElement e = null; for (int i = 0; i < maxBrushes; i++) { Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(i); e = new UIGrid2DBrushElement(blob, brush.TileTextureName, i); e.NoZ = true; e.Tag = brush.HelpOverlay; brushList.Add(e); } // Create and populate grid. By default we'll start with the full set of brushes. grid = new BrushPickerUIGrid(OnSelect, OnCancel, new Point(maxBrushes, 1), "TerrainEdit.BrushPicker"); for (int i = 0; i < maxBrushes; i++) { grid.Add(brushList[i], i, 0); } // Set grid properties. //grid.AlwaysReadInput = true; grid.Scrolling = false; grid.IgnoreInput = true; grid.Spacing = new Vector2(0.25f, 0.0f); grid.UseLeftStick = false; grid.UseTriggers = true; grid.Wrap = false; grid.LocalMatrix = Matrix.CreateTranslation(0.0f, -2.2f, -10.0f); } // end of BrushPicker c'tor
/// <summary> /// Pass off commands as appropriate to the right handlers, depending on /// the current game pad and brush states. /// </summary> /// <param name="rightMode"></param> /// <param name="aButton"></param> /// <param name="leftMode"></param> protected void ProcessTriggers( Terrain.EditMode left, Terrain.EditMode middle, Terrain.EditMode right) { /// If any of the toolbox pickers are active, disable our selves. if (shared.ToolBox.PickersActive || Boku.InGame.inGame.mouseEditUpdateObj.ToolBox.PickersActive) { return; } Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); bool isSelection = (brush != null) && ((brush.Type & Brush2DManager.BrushType.Selection) != 0); // Size timer is used for changing selection brush size. Required for both mouse and touch sizeTimer += Time.WallClockFrameSeconds; if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { if (isSelection) { ProcessTouchSelection(left, middle, right); } else { ProcessTouch(left, middle, right); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { if (isSelection) { ProcessSelection(left, middle, right); } else if (InStretchMode) { ProcessStretched(left, middle, right); } else { ProcessPoint(left, middle, right); } } }
/// <summary> /// Determine whether to draw the 3D cursor in Touch Mode /// </summary> private void ToggleTouch3DCursor() { bool hideCursor = true; Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if ((brush != null) && (brush.Type & Brush2DManager.BrushType.Selection) != 0) { hideCursor = false; } else if ( (InGame.inGame.touchEditUpdateObj != null) && ((InGame.inGame.touchEditUpdateObj.ToolBar.CurrentMode == BaseEditUpdateObj.ToolMode.WaterRaiseLower) || (InGame.inGame.touchEditUpdateObj.ToolBar.CurrentMode == BaseEditUpdateObj.ToolMode.DeleteObjects)) ) { hideCursor = false; } parent.Cursor3D.Hidden = hideCursor; }
/// <summary> /// Pass off commands as appropriate to the right handlers, depending on /// the current game pad and brush states. /// </summary> /// <param name="rightMode"></param> /// <param name="aButton"></param> /// <param name="leftMode"></param> protected void ProcessTriggers( Terrain.EditMode rightMode, Terrain.EditMode aButton, Terrain.EditMode leftMode) { /// If any of the toolbox pickers are active, disable our selves. if (shared.ToolBox.PickersActive) { return; } Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); bool isSelection = (brush != null) && ((brush.Type & Brush2DManager.BrushType.Selection) != 0); if (isSelection) { ProcessSelection( rightMode, aButton, leftMode); } else if (InStretchMode) { ProcessStretched( rightMode, aButton, leftMode); } else { ProcessPoint( rightMode, aButton, leftMode); } }
/// <summary> /// Check whether cursor should be displayed. /// </summary> /// <returns></returns> protected virtual void CheckSelectCursor(bool alwaysShowCursor) { /// The new pointy cursor seems always helpful, even if slightly /// redundant with the brush. inGame.ShowCursor(); Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if (brush == null) { //inGame.ShowCursor(); return; } bool isSelection = (brush.Type & Brush2DManager.BrushType.Selection) != 0; bool isStretch = (brush.Type & Brush2DManager.BrushType.StretchedAll) != 0; //in touch mode, make sure we don't have the selection on unless the touch is active if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { if (TouchInput.TouchCount != 1 || TouchInput.WasMultiTouch || !Boku.InGame.inGame.TouchEdit.HasNonUITouch()) { isSelection = false; } } if (isSelection) { //inGame.ShowCursor(); inGame.Terrain.MakeSelection(shared.editBrushPosition); } else { inGame.Terrain.EndSelection(); //if (!alwaysShowCursor) // inGame.HideCursor(); } }
private void CheckStretchMode() { Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if ((brush != null) && ((brush.Type & Brush2DManager.BrushType.StretchedAll) != 0)) { /// We're in stretch now. Is that new? if (!InStretchMode) { StretchPhase = Phase.Open; InStretchMode = true; } //if (PickerXInUse || PickerYInUse) //{ // shared.editBrushStart = shared.editBrushPosition; // StretchPhase = Phase.Open; //} } else { InStretchMode = false; } }
/// <summary> /// Select which help overlay to be currently displayed. /// </summary> protected virtual void SelectOverlay() { //Note: Most mouse edit tools leave their // "HelpOverlayID" and "HelpOverlayMagicBrushID" // strings null. This is because the ToolBar // class sets help overlays when you hover over // a tool and in most cases, those help overlays // never need to change (for the duration of that // tool.) One notable exception is the PaintTool // which needs slightly different help for magic // brush mode. Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if (HelpOverlayMagicBrushID != null && brush.Type == Brush2DManager.BrushType.Selection) { SetOverlay(HelpOverlayMagicBrushID); } else if (helpOverlayID != null) { SetOverlay(HelpOverlayID); } }
/// <summary> /// Update the edit brush for texture and heightmap editing. /// </summary> public void UpdateEditBrush() { float secs = Time.WallClockFrameSeconds; // Grab the current state of the gamepad. GamePadInput pad = GamePadInput.GetGamePad0(); if (InGame.inGame.CurrentUpdateMode == UpdateMode.MouseEdit && InGame.inGame.mouseEditUpdateObj.ToolBar.CurrentMode != BaseEditUpdateObj.ToolMode.EditObject && InGame.inGame.mouseEditUpdateObj.ToolBar.CurrentMode != BaseEditUpdateObj.ToolMode.Paths) { ColorPalette.Active = false; } parent.cursor3D.Position = shared.CursorPosition; shared.CursorPosition = parent.cursor3D.Position; Vector2 newPosition = new Vector2(shared.CursorPosition.X, shared.CursorPosition.Y); if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { newPosition = parent.MouseEdit.DoTerrain(parent.Camera); parent.Cursor3D.AltPosition = new Vector3(newPosition, 0); } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { newPosition = parent.TouchEdit.DoTerrain(parent.Camera); parent.Cursor3D.AltPosition = new Vector3(newPosition, 0); ToggleTouch3DCursor(); //every frame track whether or not it's valid to apply the current terrain tool (paint, etc.) //this ensures we don't apply the tool just by selecting it if (TouchInput.TouchCount == 1 && InGame.inGame.TouchEdit.HasNonUITouch() && !TouchInput.WasMultiTouch) { float touchAge = (float)(Time.WallClockTotalSeconds - TouchInput.Touches[0].startTime); //edit brush only allowed if touch has been around for at least 1/4 of a second shared.editBrushAllowedForTouch = touchAge >= 0.25f; } else { shared.editBrushAllowedForTouch = false; } } else { parent.Cursor3D.AltPosition = parent.Cursor3D.Position; } const float minEditBrushMoveSq = 0.25f * 0.25f; if (Vector2.DistanceSquared(newPosition, shared.editBrushPosition) >= minEditBrushMoveSq) { shared.editBrushMoved = true; } else { shared.editBrushMoved = false; } // Update the position, even if it's only a tiny movement. if (InGame.inGame.SnapToGrid) { Vector2 pos = newPosition + brushPositionError; pos -= brushPositionError; Vector2 prevPos = pos; pos = InGame.SnapPosition(pos); brushPositionError = pos - prevPos; shared.editBrushPosition = pos; } else { shared.editBrushPosition = newPosition; } // // Adjust brush size, but only if it's not the selection brush (handled elsewhere). // Brush2DManager.Brush2D brush = Brush2DManager.GetBrush(shared.editBrushIndex); if (shared.editBrushSizeActive && (brush != null) && ((brush.Type & Brush2DManager.BrushType.Selection) == 0)) { if (InGame.inGame.SnapToGrid) { if (Actions.BrushSmaller.WasPressedOrRepeat || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushLess)) { shared.editBrushRadius -= 0.5f; shared.editBrushRadius = MathHelper.Max(0.5f, shared.editBrushRadius); } if (Actions.BrushLarger.WasPressedOrRepeat || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushMore)) { shared.editBrushRadius += 0.5f; } } else { const float brushGrowthRate = 1.0f; if (Actions.BrushSmaller.IsPressed || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushLess)) { shared.editBrushRadius *= 1.0f - brushGrowthRate * secs; } if (Actions.BrushLarger.IsPressed || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushMore)) { shared.editBrushRadius *= 1.0f + brushGrowthRate * secs; } } if (shared.editBrushRadius < Terrain.Current.CubeSize) { shared.editBrushRadius = Terrain.Current.CubeSize; } /// A radius of about 400 adds roughly the entire terrain budget /// to the scene at once. We'll try for allowing the user 1/3 of the /// budget at a single go (1/3 of the budget is the top of the green zone) /// and see what kind of complaints we get. /// ***-taking it down further, for many benefits. if (shared.editBrushRadius > kMaxBrushRadius) { shared.editBrushRadius = kMaxBrushRadius; } } } // end of BaseEditUpdateObj UpdateEditBrush()