Esempio n. 1
0
        public override void EnterState(Game Game)
        {
            GUICamera = new Gem.Render.OrthographicCamera(Game.Main.GraphicsDevice.Viewport);
            var renderTree = new Game.RenderTree
            {
                Camera = GUICamera,
                SceneGraph = new Gem.Render.BranchNode()
            };
            GUICamera.focus = Vector2.Zero;

            Game.RenderTrees.Add(renderTree);

            var guiQuad = Gem.Geo.Gen.FacetCopy(Gem.Geo.Gen.CreateQuad());
            Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateScale(800, -600, 1.0f));
            Gem.Geo.Gen.CalculateTangentsAndBiNormals(guiQuad);
            GuiRoot = new Gem.Gui.GuiSceneNode(guiQuad, Game.Main.GraphicsDevice, 800, 600);
            GuiRoot.uiRoot.AddPropertySet(null, new Gem.Gui.GuiProperties { Transparent = true });

            var y = 8;
            foreach (var tool in Tools)
            {
                var child = CreateGuiSprite(new Rectangle(8, y, 64, 64), tool.Icon, Blocks.Tiles);
                child.Properties[0].Values.Upsert("click-action", new Action(() =>
                    {
                        if (SelectedTool != null) SelectedTool.Deselected(Game, GuiRoot.uiRoot);
                        SelectedTool = tool;
                        tool.Selected(Game, GuiRoot.uiRoot);
                    }));
                GuiRoot.uiRoot.AddChild(child);
                y += 68;
            }

            GuiRoot.RenderOnTop = true;
            GuiRoot.DistanceBias = float.NegativeInfinity;

            renderTree.SceneGraph.Add(GuiRoot);

            SelectedTool = Tools[0];
        }
Esempio n. 2
0
        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);
                        };
            }
        }
Esempio n. 3
0
        private void CreateActorPopupGui(WorldScreen Game, Actor Actor)
        {
            var guiQuad = Gem.Geo.Gen.CreateQuad();
            Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateScale(3, 3, 1));
            Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateRotationX(Gem.Math.Angle.PI / 2.0f));
            var gui = new Gem.Gui.GuiSceneNode(guiQuad, Game.Main.GraphicsDevice, 512, 512, Actor.Orientation);
            Actor.PopupGui = gui;
            gui.uiRoot.AddPropertySet(null, new Gem.Gui.GuiProperties { Transparent = true });

            gui.uiRoot.AddChild(new Gem.Gui.UIItem(
                Gem.Gui.Shape.CreateWedge(new Vector2(256, 256), 1.9f, 4.1f, 128, 256, 6),
                new Gem.Gui.GuiProperties
                {
                    BackgroundColor = new Vector3(1, 0, 0)
                }));

            UIPopupActor = Actor;
        }
Esempio n. 4
0
        public void Begin()
        {
            Tables.Initialize();
            CurrentBoard = Tables.InitialBoard;

            Content = new EpisodeContentManager(Main.EpisodeContent.ServiceProvider, "Content");

            PieceTextures = new Texture2D[] {
                Content.Load<Texture2D>("blue-piece"),
                Content.Load<Texture2D>("white-piece")
            };

            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();

            Input.ClearBindings();
            Input.AddAxis("MAIN", new MouseAxisBinding());
            Main.Input.AddBinding("RIGHT", new KeyboardBinding(Keys.Right, KeyBindingType.Held));
            Main.Input.AddBinding("LEFT", new KeyboardBinding(Keys.Left, KeyBindingType.Held));
            Main.Input.AddBinding("UP", new KeyboardBinding(Keys.Up, KeyBindingType.Held));
            Main.Input.AddBinding("DOWN", new KeyboardBinding(Keys.Down, KeyBindingType.Held));
            Main.Input.AddBinding("CLICK", new MouseButtonBinding("LeftButton", KeyBindingType.Pressed));

            Main.Input.AddBinding("CAMERA-DISTANCE-TOGGLE", new KeyboardBinding(Keys.R, KeyBindingType.Held));

            Main.Input.AddBinding("EXIT", new KeyboardBinding(Keys.Escape, KeyBindingType.Pressed));

            var hexMesh = Gem.Geo.Gen.CreateUnitPolygon(6);

            hexMesh = Gem.Geo.Gen.FacetCopy(Gem.Geo.Gen.TransformCopy(hexMesh, Matrix.CreateRotationZ((float)System.Math.PI / 2.0f)));
            Gem.Geo.Gen.ProjectTexture(hexMesh, new Vector3(1.0f, 1.0f, 0.0f), Vector3.UnitX * 2, Vector3.UnitY * 2);
            Gem.Geo.Gen.CalculateTangentsAndBiNormals(hexMesh);

            for (var x = 0; x < 19; ++x)
            {
                var hexNode = new NormalMapMeshNode()
                {
                    Mesh = hexMesh,
                    Texture = Content.Load<Texture2D>("hex"),
                    NormalMap = Content.Load<Texture2D>("hex-normal"),
                };
                hexNode.Orientation.Position = new Vector3(Tables.HexWorldPositions[x], 0.0f);
                SceneGraph.Add(hexNode);
                HexNodes.Add(hexNode);
            }

            var tetraMesh = Gem.Geo.Gen.CreateUnitPolygon(3);
            tetraMesh.verticies[0].Position = new Vector3(0.0f, 0.0f, 1.0f);
            Gem.Geo.Gen.Transform(tetraMesh, Matrix.CreateRotationZ((float)Math.PI));
            tetraMesh = Gem.Geo.Gen.FacetCopy(tetraMesh);
            for (var i = 0; i < tetraMesh.indicies.Length; i += 3)
            {
                tetraMesh.verticies[tetraMesh.indicies[i]].TextureCoordinate = new Vector2(0.5f, 0);
                tetraMesh.verticies[tetraMesh.indicies[i + 1]].TextureCoordinate = new Vector2(1, 1);
                tetraMesh.verticies[tetraMesh.indicies[i + 2]].TextureCoordinate = new Vector2(0, 1);
            }

            Gem.Geo.Gen.CalculateTangentsAndBiNormals(tetraMesh);

            for (var x = 0; x < 36; ++x)
            {
                var tetraNode = new NormalMapMeshNode()
                {
                    Mesh = tetraMesh,
                    HiliteColor = new Vector3(1,0,0),
                    HiliteMesh = tetraMesh,
                    Hidden = true
                };
                tetraNode.Orientation.Scale = new Vector3(0.4f, 0.4f, 0.4f);

                SceneGraph.Add(tetraNode);
                PieceNodes.Add(tetraNode);
            }

            for (var x = 0; x < 6; ++x)
            {
                var ghostNode = new NormalMapMeshNode()
                {
                    Mesh = tetraMesh,
                    HiliteColor = new Vector3(1, 0, 0),
                    HiliteMesh = tetraMesh,
                    Hidden = true,
                    Alpha = 0.75f,
                    Color = new Vector3(0.8f, 0.8f, 0.0f),
                };
                ghostNode.Orientation.Scale = new Vector3(0.4f, 0.4f, 0.4f);
                SceneGraph.Add(ghostNode);
                GhostPieceNodes.Add(ghostNode);
            }

            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.CreateRotationY(Gem.Math.Angle.PI));
            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
            });
            Gui.uiRoot.AddChild(new Gem.Gui.UIItem(
                "TURN-INDICATOR",
                new Gem.Gui.QuadShape(0, 0, 1, 1),
                new Gem.Gui.GuiProperties
                {
                    Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6),
                    TextOrigin = new Vector2(32, 32),
                    TextColor = new Vector3(1, 0, 0),
                    Label = "HELLO COERCEO",
                    FontScale = 4.0f,
                    Transparent = true
                }));
            Gui.uiRoot.AddChild(new Gem.Gui.UIItem(
                "TILE-COUNT",
                new Gem.Gui.QuadShape(0, 0, 1, 1),
                new Gem.Gui.GuiProperties
                {
                    Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6),
                    TextOrigin = new Vector2(32, 56),
                    TextColor = new Vector3(1, 0, 0),
                    Label = "TILE-COUNT",
                    FontScale = 4.0f,
                    Transparent = true
                }));
            Gui.uiRoot.AddChild(new Gem.Gui.UIItem(
                "STATS",
                new Gem.Gui.QuadShape(0, 0, 1, 1),
                new Gem.Gui.GuiProperties
                {
                    Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6),
                    TextOrigin = new Vector2(768, 32),
                    TextColor = new Vector3(1, 0, 0),
                    Label = "STATS",
                    FontScale = 4.0f,
                    Transparent = true
                }));
            Gui.RenderOnTop = true;
            Gui.DistanceBias = float.NegativeInfinity;
            SceneGraph.Add(Gui);

            PushInputState(new Input.TurnScheduler(PlayerTypes));
        }
Esempio n. 5
0
        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);
        }