// c'tor public ColorPalette() { // Create elements for the color buttons. // Start with a blob of common parameters. UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob(); blob.width = 1.0f; blob.height = 1.0f; blob.edgeSize = 0.5f; blob.selectedColor = Color.White; blob.unselectedColor = Color.White; blob.normalMapName = @"QuarterRound4NormalMap"; int numColors = (int)Classification.Colors.SIZEOF - 1; buttonHitBoxes = new AABB2D[numColors]; for (int i = 0; i < numEntries; i++) { buttonHitBoxes[i] = new AABB2D(); } for (int i = 0; i < numEntries; i++) { buttons[i] = new UIGrid2DTextureElement(blob, null); buttons[i].NoZ = false; // Set initial size. textureSize[i] = inactiveSize; buttons[i].BaseColor = Classification.ColorVector4(GetColorFromIndex(i)); } camera = new UiCamera(); }
} // end of OnCancel() public void Activate() { if (!active) { // Do stack handling here. If we do it in the update object we have no // clue which order things get pushed and popped and madness ensues. CommandStack.Push(commandMap); HelpOverlay.Push(@"ToolMenu"); active = true; grid.Active = true; grid.RenderWhenInactive = false; // Never allow the Play button to be the default. if (grid.SelectionIndex.X == 0) { // Default to object edit. grid.SelectionIndex = new Point(2, 0); } // Reset all the tiles to the origin so they spring out nicely. for (int i = 0; i < grid.ActualDimensions.X; i++) { UIGrid2DTextureElement e = (UIGrid2DTextureElement)grid.Get(i, 0); e.Position = Vector3.Zero; } grid.Dirty = true; // Force the grid to update the positions before getting rendered. grid.Update(ref worldMatrix); lastChangedTime = Time.WallClockTotalSeconds; curIndex = grid.SelectionIndex.X; InGame.inGame.StopAllSounds(); } }
} // end of GetElementInfo() public override void Render(Camera camera) { if (active && alpha > 0.0f) { // Render reticule around selected brush. CameraSpaceQuad quad = CameraSpaceQuad.GetInstance(); UIGrid2DTextureElement e = (UIGrid2DTextureElement)grid.SelectionElement; Vector2 position = new Vector2(e.Position.X, e.Position.Y); position.X += grid.WorldMatrix.Translation.X; position.Y += grid.WorldMatrix.Translation.Y; position.Y -= 0.14f; // No clue. Nedd to figure this out. Vector2 size = 2.0f * new Vector2(e.Size.X, e.Size.Y); quad.Render(camera, reticuleTexture, alpha, position, size, @"AdditiveBlend"); // Trigger icons? double curTime = Time.WallClockTotalSeconds; double dTime = curTime - lastChangedTime; if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad && dTime > kPreFadeTime) { dTime -= kPreFadeTime; float triggerAlpha = Math.Min((float)(dTime / kFadeTime), 1.0f); Vector2 offset = size * 0.4f; size *= 0.4f; // Note the 12/64 in the positioning accounts for the fact that the // button textures only use the upper 40x40 out of the 64x64 space they allocate. // The 12 is actually (64-40)/2. quad.Render(camera, ButtonTextures.RightTrigger, triggerAlpha, position + offset + size * 12.0f / 64.0f, size, @"TexturedRegularAlpha"); offset.X = -offset.X; quad.Render(camera, ButtonTextures.LeftTrigger, triggerAlpha, position + offset + size * 12.0f / 64.0f, size, @"TexturedRegularAlpha"); } } base.Render(camera); } // end of BrushPicker Render()
} // end of HandleMouseInput() /// <summary> /// Helper function to cut down on the cut/paste. /// </summary> /// <param name="e">The element we want info about.</param> /// <param name="invMat">Inverse world matrix of the element.</param> /// <param name="height">Height of the element.</param> /// <param name="width">Width of the element.</param> private void GetElementInfo(UIGridElement e, out Matrix invMat, out float height, out float width) { invMat = e.InvWorldMatrix; UIGrid2DTextureElement te = e as UIGrid2DTextureElement; width = te.Width; height = te.Height; } // end of GetElementInfo()
public void Render() { if (active) { // Render menu using local camera. Fx.ShaderGlobals.SetCamera(camera); // Darken the background to emphasize to the user that they need to pick a tool. ScreenSpaceQuad ssquad = ScreenSpaceQuad.GetInstance(); ssquad.Render(dropShadowTexture, new Vector4(0, 0, 0, 0.9f), new Vector2(0, 0.6f * BokuGame.ScreenSize.Y), new Vector2(BokuGame.ScreenSize.X, 0.4f * BokuGame.ScreenSize.Y), "TexturedRegularAlpha"); grid.Render(camera); // Render reticule around selected tools tile. CameraSpaceQuad csquad = CameraSpaceQuad.GetInstance(); UIGrid2DTextureElement e = (UIGrid2DTextureElement)grid.SelectionElement; Vector2 position = new Vector2(e.Position.X, e.Position.Y); position.X += grid.WorldMatrix.Translation.X; position.Y += grid.WorldMatrix.Translation.Y; position.Y -= 0.14f; // No clue. Nedd to figure this out. Vector2 size = 2.0f * new Vector2(e.Size.X, e.Size.Y); float alpha = 1.0f; csquad.Render(camera, BasePicker.reticuleTexture, alpha, position, size, @"AdditiveBlend"); // Don't bother with trigger icons if we're modal. if (!XmlOptionsData.ModalToolMenu) { // Trigger icons? double curTime = Time.WallClockTotalSeconds; double dTime = curTime - lastChangedTime; if (dTime > kPreFadeTime) { dTime -= kPreFadeTime; float triggerAlpha = Math.Min((float)(dTime / kFadeTime), 1.0f); Vector2 offset = size * 0.4f; size *= 0.4f; // Note the 12/64 in the positioning accounts for the fact that the // button textures only use the upper 40x40 out of the 64x64 space they allocate. // The 12 is actually (64-40)/2. csquad.Render(camera, ButtonTextures.RightTrigger, triggerAlpha, position + offset + size * 12.0f / 64.0f, size, @"TexturedRegularAlpha"); offset.X = -offset.X; csquad.Render(camera, ButtonTextures.LeftTrigger, triggerAlpha, position + offset + size * 12.0f / 64.0f, size, @"TexturedRegularAlpha"); } } } } // end of ToolMenu Render()
// c'tor public ToolMenu() { // Create elements for the grid. // Start with a blob of common parameters. UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob(); blob.width = 1.1f; blob.height = 1.1f; blob.edgeSize = 0.1f; Color tileColor = new Color(110, 150, 140, 170); blob.selectedColor = tileColor; blob.unselectedColor = tileColor; blob.textColor = Color.Red; // Shouldn't need this. blob.dropShadowColor = Color.Black; blob.normalMapName = @"QuarterRound4NormalMap"; blob.altShader = true; blob.ignorePowerOf2 = true; // Create and populate grid. int maxTools = 20; numTools = 0; grid = new ToolMenuUIGrid(OnSelect, OnCancel, new Point(maxTools, 1), "ToolMenuGrid"); UIGrid2DTextureElement e = null; // JW - The toolmenu elements are now assigned names so that they can be disabled by the // same strings as the Mouse/Touch "ToolBar" elements. blob.elementName = Strings.Localize("toolBar.runGame"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\Play"); e.Tag = InGame.UpdateMode.RunSim; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.home"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\Home"); e.Tag = InGame.UpdateMode.MiniHub; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.objectEdit"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\ObjectEdit"); e.Tag = InGame.UpdateMode.EditObject; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.terrainPaint"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\TerrainMaterial"); e.Tag = InGame.UpdateMode.TerrainMaterial; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.terrainRaiseLower"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\TerrainUpDown"); e.Tag = InGame.UpdateMode.TerrainUpDown; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.terrainSmoothLevel"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\TerrainFlatten"); e.Tag = InGame.UpdateMode.TerrainFlatten; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.terrainSpikeyHilly"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\TerrainRoughHill"); e.Tag = InGame.UpdateMode.TerrainRoughHill; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.waterRaiseLower"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\TerrainWater"); e.Tag = InGame.UpdateMode.TerrainWater; grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.deleteObjects"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\DeleteObject"); e.Tag = InGame.UpdateMode.DeleteObjects; grid.Add(e, numTools++, 0); //e = new UIGrid2DTextureElement(blob, @"ToolMenu\ObjectTweak"); //e.Object = InGame.UpdateMode.TweakObject; //grid.Add(e, numTools++, 0); blob.elementName = Strings.Localize("toolBar.worldTweak"); e = new UIGrid2DTextureElement(blob, @"ToolMenu\WorldSettings"); e.Tag = InGame.UpdateMode.EditWorldParameters; grid.Add(e, numTools++, 0); Debug.Assert(numTools <= maxTools, "If this fires, just up maxTools."); // Set grid properties. grid.Spacing = new Vector2(0.1f, 0.0f); grid.Scrolling = false; grid.Wrap = false; grid.UseLeftStick = false; grid.UseTriggers = true; Matrix mat = Matrix.Identity; mat.Translation = new Vector3(0.0f, -2.2f, -10.0f); grid.LocalMatrix = mat; } // end of ToolMenu c'tor
} // end of TexturePicker InitFileList() public void Update() { if (active) { GamePadInput pad = GamePadInput.GetGamePad1(); // Switch active grid? bool changed = false; if (pad.LeftStickLeft.WasPressed || pad.DPadLeft.WasPressed) { activeGrid = (activeGrid + 3) % 4; changed = true; Foley.PlayProgrammingClick(); } if (pad.LeftStickRight.WasPressed || pad.DPadRight.WasPressed) { activeGrid = (activeGrid + 1) % 4; changed = true; Foley.PlayProgrammingClick(); } if (changed) { Vector3 newPosition = new Vector3(-2.25f + 1.5f * activeGrid, 0.0f, 0.0f); TwitchManager.GetVector3 get = delegate(Object param) { return(selectionPlate.Position); }; TwitchManager.SetVector3 set = delegate(Vector3 value, Object param) { selectionPlate.Position = value; }; TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(get, set, newPosition, 0.25f, TwitchCurve.Shape.OvershootOut); twitch.Start(); grid0.Active = false; grid1.Active = false; grid2.Active = false; grid3.Active = false; switch (activeGrid) { case 0: grid0.Active = true; break; case 1: grid1.Active = true; break; case 2: grid2.Active = true; break; case 3: grid3.Active = true; break; } changed = false; } backPlate.Update(); selectionPlate.Update(); grid0.Update(ref worldGrid); grid1.Update(ref worldGrid); grid2.Update(ref worldGrid); grid3.Update(ref worldGrid); // See if any of the grids have changed which texture is in focus. // If so, change what the terrain sees. if (grid0.SelectionIndex.Y != curFocusIndex0) { curFocusIndex0 = grid0.SelectionIndex.Y; InGame.inGame.Terrain.ChangeTerrainTexture(0, files[curFocusIndex0]); InGame.inGame.IsLevelDirty = true; } if (grid1.SelectionIndex.Y != curFocusIndex1) { curFocusIndex1 = grid1.SelectionIndex.Y; InGame.inGame.Terrain.ChangeTerrainTexture(1, files[curFocusIndex1]); InGame.inGame.IsLevelDirty = true; } if (grid2.SelectionIndex.Y != curFocusIndex2) { curFocusIndex2 = grid2.SelectionIndex.Y; InGame.inGame.Terrain.ChangeTerrainTexture(2, files[curFocusIndex2]); InGame.inGame.IsLevelDirty = true; } if (grid3.SelectionIndex.Y != curFocusIndex3) { curFocusIndex3 = grid3.SelectionIndex.Y; InGame.inGame.Terrain.ChangeTerrainTexture(3, files[curFocusIndex3]); InGame.inGame.IsLevelDirty = true; } float outerRowAlpha = 0.3f; float innerRowAlpha = 0.7f; // Update the alpha values of the visible tiles. for (int i = 0; i < grid0.ActualDimensions.Y; i++) { UIGrid2DTextureElement e = null; e = grid0.Get(0, i) as UIGrid2DTextureElement; if (e != null) { int delta = Math.Abs(i - grid0.SelectionIndex.Y); if (delta < 2) { e.Alpha = 1.0f; } else if (delta < 3) { e.Alpha = innerRowAlpha; } else { e.Alpha = outerRowAlpha; } } e = grid1.Get(0, i) as UIGrid2DTextureElement; if (e != null) { int delta = Math.Abs(i - grid1.SelectionIndex.Y); if (delta < 2) { e.Alpha = 1.0f; } else if (delta < 3) { e.Alpha = innerRowAlpha; } else { e.Alpha = outerRowAlpha; } } e = grid2.Get(0, i) as UIGrid2DTextureElement; if (e != null) { int delta = Math.Abs(i - grid2.SelectionIndex.Y); if (delta < 2) { e.Alpha = 1.0f; } else if (delta < 3) { e.Alpha = innerRowAlpha; } else { e.Alpha = outerRowAlpha; } } e = grid3.Get(0, i) as UIGrid2DTextureElement; if (e != null) { int delta = Math.Abs(i - grid3.SelectionIndex.Y); if (delta < 2) { e.Alpha = 1.0f; } else if (delta < 3) { e.Alpha = innerRowAlpha; } else { e.Alpha = outerRowAlpha; } } } } } // end of TexturePicker Update()
// c'tor public TexturePicker() { InitFileList(); // Create the back plate. backPlate = new UIGrid2DTextureElement(7.0f, 1.25f, 0.625f, @"QuarterRound4NormalMap", backPlateColor, null); backPlate.Position = new Vector3(0.0f, 0.0f, 0.0f); backPlate.NoZ = true; // Create the selection plate. selectionPlate = new UIGrid2DTextureElement(1.125f, 1.125f, 0.5625f, @"QuarterRound4NormalMap", selectionPlateColor, null); selectionPlate.NoZ = true; selectionPlate.Position = new Vector3(-2.25f, 0.0f, 0.0f); // Create texture elements for the grids. // Start with a blob of common parameters. UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob(); blob.width = 1.0f; blob.height = 1.0f; blob.edgeSize = 0.5f; blob.selectedColor = Color.White; blob.unselectedColor = Color.LightGray; blob.normalMapName = @"QuarterRound4NormalMap"; // Create and populate grid. int numElements = files.Count; grid0 = new UIGrid(OnSelect, OnCancel, new Point(1, numElements), "TerrainEdit.TextureGrid0"); grid1 = new UIGrid(OnSelect, OnCancel, new Point(1, numElements), "TerrainEdit.TextureGrid1"); grid2 = new UIGrid(OnSelect, OnCancel, new Point(1, numElements), "TerrainEdit.TextureGrid2"); grid3 = new UIGrid(OnSelect, OnCancel, new Point(1, numElements), "TerrainEdit.TextureGrid3"); for (int i = 0; i < numElements; i++) { // Note, we could probably have the grid share elements except that the element positions // are set during Update() so unless we interleaved Update() and Render() calls we would // end up seeing everything rendered in the wrong place. TextureFile file = (TextureFile)files[i]; UIGrid2DTextureElement e = new UIGrid2DTextureElement(blob, @"Terrain\GroundTextures\" + file.filename); e.NoZ = true; grid0.Add(e, 0, i); file = (TextureFile)files[i]; e = new UIGrid2DTextureElement(blob, @"Terrain\GroundTextures\" + file.filename); e.NoZ = true; grid1.Add(e, 0, i); file = (TextureFile)files[i]; e = new UIGrid2DTextureElement(blob, @"Terrain\GroundTextures\" + file.filename); e.NoZ = true; grid2.Add(e, 0, i); file = (TextureFile)files[i]; e = new UIGrid2DTextureElement(blob, @"Terrain\GroundTextures\" + file.filename); e.NoZ = true; grid3.Add(e, 0, i); } // Set grid properties. grid0.Spacing = new Vector2(0.0f, 0.25f); // The first number doesn't really matter since we're doing a 1d column. grid0.Scrolling = true; grid0.Wrap = false; grid0.LocalMatrix = Matrix.CreateTranslation(new Vector3(-2.25f, 0.0f, 0.0f)); grid1.Spacing = new Vector2(0.0f, 0.25f); // The first number doesn't really matter since we're doing a 1d column. grid1.Scrolling = true; grid1.Wrap = false; grid1.LocalMatrix = Matrix.CreateTranslation(new Vector3(-0.75f, 0.0f, 0.0f)); grid2.Spacing = new Vector2(0.0f, 0.25f); // The first number doesn't really matter since we're doing a 1d column. grid2.Scrolling = true; grid2.Wrap = false; grid2.LocalMatrix = Matrix.CreateTranslation(new Vector3(0.75f, 0.0f, 0.0f)); grid3.Spacing = new Vector2(0.0f, 0.25f); // The first number doesn't really matter since we're doing a 1d column. grid3.Scrolling = true; grid3.Wrap = false; grid3.LocalMatrix = Matrix.CreateTranslation(new Vector3(2.25f, 0.0f, 0.0f)); } // end of TexturePicker c'tor