public override void Selected(Game Game, Gem.Gui.UIItem GuiRoot) { this.SelectedBlock = null; BlockContainer = new Gem.Gui.UIItem(Gem.Gui.Shape.CreateQuad(96, 8, 512, 128), new Gem.Gui.GuiProperties { Transparent = false, BackgroundColor = new Microsoft.Xna.Framework.Vector3(0.8f, 0.2f, 0.2f) }); GuiRoot.AddChild(BlockContainer); var x = 96 + 8; foreach (var template in Game.Sim.Blocks.Templates) { var lambdaTemplate = template; var child = HoverTest.CreateGuiSprite(new Rectangle(x, 16, 32, 32), template.Value.Preview, Game.Sim.Blocks.Tiles); child.Properties[0].Values.Upsert("click-action", new Action(() => { this.SelectedBlock = lambdaTemplate.Value; GuiRoot.RemoveChild(BlockContainer); BlockContainer = null; })); BlockContainer.AddChild(child); x += 32; } }
public override void EnterState(WorldScreen Game, World World) { //TODO: Run some kind of turn-begins rule. if (!BoundActor.Properties.TryGetPropertyAs("max-energy", out MaxEnergy)) MaxEnergy = 8; BoundActor.Properties.Upsert("turn-energy", MaxEnergy); #region Prepare GUI var guiMesh = Gem.Geo.Gen.CreatePatch( new Vector3[] { new Vector3(0,-2,4), new Vector3(6,-2,2), new Vector3(10,-2,2), new Vector3(16,-2,4), new Vector3(0,-2,2.66f), new Vector3(6,-2,1.33f), new Vector3(10,-2,1.33f), new Vector3(16,-2,2.66f), new Vector3(0,-2,1.33f), new Vector3(6,-2,0.66f), new Vector3(10,-2,0.66f), new Vector3(16,-2,1.33f), new Vector3(0,-2,0), new Vector3(6,-2,0), new Vector3(10,-2,0), new Vector3(16,-2,0) }, 8); Gui = new Gem.Gui.GuiSceneNode( guiMesh, Game.Main.GraphicsDevice, 512, 256); //Gui.LayoutScaling = new Vector2(4, 4); Gui.Orientation.Position = new Vector3(0, 2, 0); // Make this GUI 'always on top' Gui.RenderOnTop = true; Gui.DistanceBias = float.NegativeInfinity; Game.SceneGraph.Add(Gui); Gui.uiRoot.AddPropertySet(null, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0, 0, 1), Transparent = true }); var guardButton = new Gem.Gui.UIItem( Gem.Gui.Shape.CreateQuad(512 - 48 - 64, 128 - 32, 64, 32), new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.7f, 0.7f, 0.7f), ClickAction = () => Guard(), Image = Game.Main.EpisodeContent.Load<Microsoft.Xna.Framework.Graphics.Texture2D>("Content/guard"), ImageTransform = Matrix.CreateTranslation(-(512 - 48 - 64), -(128 - 32), 0) * Matrix.CreateScale(1.0f / 64, 1.0f / 32, 1.0f) }); guardButton.AddPropertySet(item => item.Hover, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.9f, 0.9f, 0.9f) }); Gui.uiRoot.AddChild(guardButton); var chevronLeftEdge = 48; var chevronRightEdge = 512 - 48; var chevronRange = chevronRightEdge - chevronLeftEdge; var chevronSize = (int)Math.Round((float)chevronRange / (float)MaxEnergy); EnergyBar = new Gem.Gui.UIItem[2, MaxEnergy]; for (var chevronIndex = 0; chevronIndex < MaxEnergy; ++chevronIndex) { var topShape = MakeTopChevron( chevronLeftEdge, chevronIndex == MaxEnergy - 1 ? chevronRightEdge : chevronLeftEdge + chevronSize, 128, 128 + 64, 16, chevronIndex == 0, chevronIndex == MaxEnergy - 1); var bottomShape = MakeBottomChevron( chevronLeftEdge, chevronIndex == MaxEnergy - 1 ? chevronRightEdge : chevronLeftEdge + chevronSize, 128 + 64, 128 + 128, 16, chevronIndex == 0, chevronIndex == MaxEnergy - 1); chevronLeftEdge += chevronSize; EnergyBar[0, chevronIndex] = new Gem.Gui.UIItem(topShape, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.8f, 0, 0) }); EnergyBar[1, chevronIndex] = new Gem.Gui.UIItem(bottomShape, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0, 0, 0.2f) }); Gui.uiRoot.AddChild(EnergyBar[0, chevronIndex]); Gui.uiRoot.AddChild(EnergyBar[1, chevronIndex]); } #endregion PrepareCombatGrid(Game, World); var hilite = Game.Main.Content.Load<Texture2D>("Content/hilite"); var footstep = Game.Main.Content.Load<Texture2D>("Content/path"); CombatGridVisual = new CombatGridVisual(World.CombatGrid); CombatGridVisual.HoverTexture = Game.Main.Content.Load<Texture2D>("Content/swirl"); CombatGridVisual.TextureTable = new Texture2D[] { hilite, footstep }; Game.SceneGraph.Add(CombatGridVisual); foreach (var actor in Game.World.Actors) { var localActor = actor; if (actor.Renderable != null) actor.Renderable.ClickAction = () => { ClearActorPopup(); CreateActorPopupGui(Game, localActor); }; } }
public override void Deselected(Game Game, Gem.Gui.UIItem GuiRoot) { if (BlockContainer != null) GuiRoot.RemoveChild(BlockContainer); BlockContainer = null; }
public void Begin() { Content = new EpisodeContentManager(Main.EpisodeContent.ServiceProvider, "Content"); RenderContext = new RenderContext(Content.Load<Effect>("draw"), Main.GraphicsDevice); Camera = new FreeCamera(new Vector3(0.0f, -8.0f, 8.0f), Vector3.UnitY, Vector3.UnitZ, Main.GraphicsDevice.Viewport); Camera.Viewport = Main.GraphicsDevice.Viewport; Camera.LookAt(Vector3.Zero); RenderContext.Camera = Camera; SceneGraph = new Gem.Render.BranchNode(); Main.Input.ClearBindings(); Input.AddAxis("MAIN", new MouseAxisBinding()); Main.Input.AddBinding("CLICK", new MouseButtonBinding("LeftButton", KeyBindingType.Pressed)); Main.Input.AddBinding("EXIT", new KeyboardBinding(Keys.Escape, KeyBindingType.Pressed)); var guiQuad = Gem.Geo.Gen.CreateQuad(); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateRotationX(Gem.Math.Angle.PI / 2.0f)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateScale(10.0f, 1.0f, 5.0f)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateTranslation(0.0f, 0.0f, 2.0f)); Gui = new Gem.Gui.GuiSceneNode(guiQuad, Main.GraphicsDevice, 1024, 512); Gui.uiRoot.AddPropertySet(null, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0, 0, 1), Transparent = true }); var button1 = new Gem.Gui.UIItem( "BUTTON", new Gem.Gui.QuadShape(32, 32, 512, 32), new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.9f, 0.4f, 0.4f), Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 32), TextColor = new Vector3(0, 0, 0), Label = "PLAYER VS PLAYER", FontScale = 4.0f, Transparent = false, ClickAction = () => { Main.Game = new WorldScreen(PlayerType.Player, PlayerType.Player); } }); button1.AddPropertySet(i => i.Hover, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(1, 0, 0) }); Gui.uiRoot.AddChild(button1); var button2 = new Gem.Gui.UIItem( "BUTTON", new Gem.Gui.QuadShape(32, 32 + 32 + 16, 512, 32), new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.9f, 0.4f, 0.4f), Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 32 + 32 + 16), TextColor = new Vector3(0, 0, 0), Label = "PLAYER VS AI", FontScale = 4.0f, Transparent = false, ClickAction = () => { Main.Game = new WorldScreen(PlayerType.Player, PlayerType.AI); } }); button2.AddPropertySet(i => i.Hover, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(1, 0, 0) }); Gui.uiRoot.AddChild(button2); var button3 = new Gem.Gui.UIItem( "BUTTON", new Gem.Gui.QuadShape(32, 128, 512, 32), new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0.9f, 0.4f, 0.4f), Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 128), TextColor = new Vector3(0, 0, 0), Label = "AI VS AI", FontScale = 4.0f, Transparent = false, ClickAction = () => { Main.Game = new WorldScreen(PlayerType.AI, PlayerType.AI); } }); button3.AddPropertySet(i => i.Hover, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(1, 0, 0) }); Gui.uiRoot.AddChild(button3); Gui.RenderOnTop = true; Gui.DistanceBias = float.NegativeInfinity; SceneGraph.Add(Gui); }