Esempio n. 1
0
        private void ExpandRoot(AxisAlignedBox newChildBounds)
        {
            //lock (syncLock)
            {
                bool isNorth = rootNode.Bounds.Y0 < newChildBounds.Y0;
                bool isWest  = rootNode.Bounds.X0 < newChildBounds.X0;

                Direction rootDirection;
                if (isNorth)
                {
                    rootDirection = isWest ? Direction.NW : Direction.NE;
                }
                else
                {
                    rootDirection = isWest ? Direction.SW : Direction.SE;
                }

                var newX = (rootDirection == Direction.NW || rootDirection == Direction.SW)
                                  ? rootNode.Bounds.X0
                                  : rootNode.Bounds.X0 - rootNode.Bounds.Width;
                var newY = (rootDirection == Direction.NW || rootDirection == Direction.NE)
                                  ? rootNode.Bounds.Y0
                                  : rootNode.Bounds.Y0 - rootNode.Bounds.Height;
                var newRootBounds = AxisAlignedBox.FromRect(newX, newY, rootNode.Bounds.Width * 2, rootNode.Bounds.Height * 2);
                var newRoot       = new QuadNode(newRootBounds);
                SetupChildNodes(newRoot);
                newRoot[rootDirection] = rootNode;
                rootNode = newRoot;
            }
        }
        private void render()
        {
            var ap           = _transform.DerivedPosition;
            var areaRect     = AxisAlignedBox.FromRect(ap, Settings.TileSizeV * 8);
            var cameraBounds = Camera.mainCamera.worldBounds;

            cameraBounds.Inflate(Settings.TileSizeV * 32);
            if (cameraBounds.Intersects(areaRect))
            {
                for (var xx = x; xx < x + width; xx++)
                {
                    for (var yy = y; yy < y + height; yy++)
                    {
                        var b = _terrain.foreground[xx + (yy * _terrain.width)];
                        if (b > 0)
                        {
                            var p        = new Vector2(xx - x, yy - y) * Settings.TileSizeV + _transform.DerivedPosition;
                            var destRect = AxisAlignedBox.FromRect(p, Settings.TileSizeV);

                            var sp      = new Vector2(b & 0xf, b >> 4) * Settings.TileSizeV;
                            var srcRect = AxisAlignedBox.FromRect(sp, Settings.TileSizeV);

                            Root.instance.graphics.Draw(0, _material, destRect, srcRect, Color.White);
                        }
                    }
                }
            }
            //Root.instance.graphics.Draw(0, null,
        }
        private void drawOcclussion()
        {
            var worldBounds = mainCamera.worldBounds;

            var left = AxisAlignedBox.FromRect(
                worldBounds.Minimum,
                new Vector2(world.drawRect.Minimum.X - worldBounds.Minimum.X, worldBounds.Height));

            graphics.Draw(left, new Color(0f, 0f, 0f, 0.25f));

            var right = AxisAlignedBox.FromRect(
                new Vector2(world.drawRect.Maximum.X, worldBounds.Minimum.Y),
                new Vector2(worldBounds.Maximum.X - world.drawRect.Maximum.X, worldBounds.Height));

            graphics.Draw(right, new Color(0f, 0f, 0f, 0.25f));

            var top = AxisAlignedBox.FromRect(
                new Vector2(world.drawRect.Minimum.X, worldBounds.Minimum.Y),
                new Vector2(world.drawRect.Width, world.drawRect.Minimum.Y - worldBounds.Minimum.Y));

            graphics.Draw(top, new Color(0f, 0f, 0f, 0.25f));

            var bottom = AxisAlignedBox.FromRect(
                new Vector2(world.drawRect.Minimum.X, world.drawRect.Maximum.Y),
                new Vector2(world.drawRect.Width, worldBounds.Maximum.Y - world.drawRect.Maximum.Y));

            graphics.Draw(bottom, new Color(0f, 0f, 0f, 0.25f));
            graphics.DrawRect(world.drawRect, Color.Wheat);
        }
Esempio n. 4
0
 private void render()
 {
     Root.instance.graphics.Draw(
         renderQueue,
         AxisAlignedBox.FromRect(gameObject.transform.DerivedPosition, new Vector2(width, height)),
         color,
         gameObject.transform.DerivedDepth);
 }
Esempio n. 5
0
        protected virtual void renderBuild()
        {
            var g = Root.instance.graphics;
            var p = transform.DerivedPosition;
            var s = new Vector2(p.X - 50, p.Y);
            var e = new Vector2(p.X + 50, p.Y);
            var l = 1f - buildTimeRemaining / buildTimer;

            g.Draw(null, AxisAlignedBox.FromRect(s.X, s.Y - 3, 100, 6), Color.Red);
            g.Draw(null, AxisAlignedBox.FromRect(s.X, s.Y - 3, 100 * l, 6), Color.Green);
        }
Esempio n. 6
0
 protected override void renderBuilt()
 {
     if (extractTimeRemaining > 0f)
     {
         var g = Root.instance.graphics;
         var p = transform.DerivedPosition;
         var s = new Vector2(p.X - 50, p.Y);
         var e = new Vector2(p.X + 50, p.Y);
         var l = 1f - extractTimeRemaining / extractTimer;
         g.Draw(null, AxisAlignedBox.FromRect(s.X, s.Y - 3, 100, 6), Color.Red);
         g.Draw(null, AxisAlignedBox.FromRect(s.X, s.Y - 3, 100 * l, 6), Color.Blue);
     }
 }
Esempio n. 7
0
        private void drawMouseBuild(Material m)
        {
            var size = m.textureSize;

            //var wp
            graphics.Draw(m, AxisAlignedBox.FromRect(gui.screenToGUI(input.MousePosition) - size / 2, size), Color.White);

            if (input.WasLeftMousePressed)
            {
                if (_planet.placeBuilding(_building, m))
                {
                    _building = null;
                }
            }
        }
Esempio n. 8
0
        private void ongui()
        {
            var screenSize = screen.size;
            var margin     = new Vector2(5, 5);
            var items      = 10;
            var iconSize   = new Vector2(32, 32);

            var totalSize      = items * margin + items * iconSize;
            var totalSizeOver2 = totalSize / 2f;
            var centerX        = screenSize.X / 2;


            var aabb = AxisAlignedBox.FromRect(centerX - totalSizeOver2.X, screenSize.Y - margin.Y * 4 - iconSize.Y, totalSize.X, margin.Y * 2 + iconSize.Y);

            gui.box(aabb);
        }
        private void render()
        {
            if (show)
            {
                var visited  = new HashSet <int>();
                var openlist = new PriorityQueue <int, int>();
                var moves    = new List <KeyValuePair <int, int> >();
                var start    = map.getTileId(new Point(mx, my));

                visited.Add(start);
                openlist.Enqueue(0, start);

                while (openlist.Count > 0)
                {
                    var next = openlist.Dequeue();
                    var p    = map.getTilePoint(next.Value);

                    var neighbors = map.getNeighborIds(p);
                    foreach (var n in neighbors)
                    {
                        var np = map.getTilePoint(n);
                        if (!visited.Contains(n) && map.getTile(np.X, np.Y).Movable)
                        {
                            var move = next.Key + 1;
                            if (move < moveDistance)
                            {
                                openlist.Enqueue(move, n);
                            }

                            moves.Add(new KeyValuePair <int, int>(n, move));
                            visited.Add(n);
                        }
                    }
                }

                foreach (var m in moves)
                {
                    var p    = map.getTilePoint(m.Key);
                    var mp   = map.mapToWorld(p) - new Vector2(Map.tileSize, Map.tileSize) / 2;
                    var aabb = AxisAlignedBox.FromRect(mp, Map.tileSize, Map.tileSize);

                    Root.instance.graphics.Draw(0, aabb, new Color(Color.Blue, 0.25f), 1);
                }
            }
        }
Esempio n. 10
0
        public static GameObject prefabPlayer(this GameObject parent)
        {
            var go = parent.createChild("player");

            //go.createScript<VelocityComponent>();
            //go.createScript<Camera>();
            //go.createScript<PlayerController>();
            go.createScript <Player>();
            go.transform.Depth = 1f;
            //go.createScript<MoveObject>();
            var sprite = go.createScript <Sprite>();

            sprite.material = Root.instance.resources.createMaterialFromTexture("content/textures/stickfigure.png");
            // sprite.textureName = "content/textures/stickfigure.png";
            sprite.size   = new Vector2(16, 32) * Game.WORLD_SCALE;
            sprite.origin = new Vector2(0.5f, 0.5f);

            //go.createScript<MovementAnimation>();
            go.createScript <SetObjectPosition>();
            var physics = go.createScript <Physics>();

            physics.shape = AxisAlignedBox.FromRect(Vector2.Zero, new Vector2(16f, 32f) * Game.WORLD_SCALE);

            var flashOnDamage = go.createScript <FlashSpriteOnDamage>();

            //var weapon = go.createScript<MeleeWeapon>();

            go.transform.Position = new Vector2(12.5f * Map.tileSize, 12.5f * Map.tileSize);

            var stats = go.createScript <Stats>();

            stats.maxhp = 100;
            stats.hp    = 100;
            stats.xp    = 0;

            var collider = go.createScript <Collider>();

            collider.flags        = Physics.QUERY_PLAYER;
            collider.collidesWith = Physics.QUERY_ENEMIES;
            //collider.notifyObject = go;
            collider.size   = new Vector2(16, 32) * Game.WORLD_SCALE;
            collider.origin = new Vector2(0.5f, 0.5f);

            return(go);
        }
Esempio n. 11
0
 private void executeTurn()
 {
     //show command menu
     if (canMove && gui.buttonold(AxisAlignedBox.FromRect(10, 10, 100, 20), "attack"))
     {
         doAttack();
     }
     else if (canAttack && gui.buttonold(AxisAlignedBox.FromRect(10, 40, 100, 20), "move"))
     {
         doMove();
     }
     else if (gui.buttonold(AxisAlignedBox.FromRect(10, 40, 100, 20), "done"))
     {
         canMove   = true;
         canAttack = true;
         endTurn();
     }
 }
Esempio n. 12
0
        private void ongui()
        {
            var g        = Root.instance.graphics;
            var firstSet = false;

            for (var i = 0; i < _buildActions.Length; i++)
            {
                var shouldBuild = input.WasKeyPressed(input.GetKeyByIndex(i));
                var canBuild    = _planet.canBuild(_buildActions[i]);
                if (canBuild)
                {
                    shouldBuild |= gui.button(AxisAlignedBox.FromRect(new Vector2(20 + i * 120, screen.height - 60), new Vector2(100, 40)), _buildActions[i]);
                }

                if (shouldBuild && canBuild)
                {
                    _building = _buildActions[i];
                    firstSet  = true;
                }
            }

            if (!firstSet)
            {
                if (input.WasKeyPressed(Keys.D1))
                {
                    _building = null;
                }

                switch (_building)
                {
                case "COMMAND": drawMouseBuild(_command); break;

                case "EXTRACT": drawMouseBuild(_extractor); break;

                case "RESEARCH": drawMouseBuild(_research); break;

                case "BARRACKS": drawMouseBuild(_barracks); break;

                case "CANNON": drawMouseBuild(_cannon); break;

                case "STORAGE": drawMouseBuild(_storage); break;
                }
            }
        }
Esempio n. 13
0
        private void ongui()
        {
            var index = 0;

            for (var y = 0; y < 3; y++)
            {
                for (var x = 0; x < 3; x++)
                {
                    gui.skin.label.alignment = anchors[index++];

                    var p    = new Vector2(x, y) * (size + margin) + offset;
                    var aabb = AxisAlignedBox.FromRect(p, size);
                    //var aabb = AxisAlignedBox.FromRect(
                    gui.button(aabb, new GUIContent("1234567890 0909 ", resources.createMaterialFromTexture("content/textures/ship.png")));
                    //gui.label2(AxisAlignedBox.FromRect(100, 500, 300, 300), new GUIContent("1234", new GUITexture() { material = resources.createMaterialFromTexture("content/textures/ship.png") }));
                    gui.layout.DoLabel(new GUIContent("test"), gui.skin.label, null);
                }
            }
        }
Esempio n. 14
0
        internal AxisAlignedBox computePosition(AxisAlignedBox area, Vector2 size)
        {
            var sizeOver2         = size / 2;
            var positionSizeOver2 = area.Size / 2;
            var position          = area.minVector;

            switch (alignment)
            {
            case GUIAnchor.MiddleLeft:
                position.Y = area.Y0 + positionSizeOver2.Y - sizeOver2.Y;
                break;

            case GUIAnchor.LowerLeft:
                position.Y = area.Y1 - size.Y;
                break;

            case GUIAnchor.UpperCenter:
                position.X = area.X0 + positionSizeOver2.X - sizeOver2.X;
                break;

            case GUIAnchor.MiddleCenter:
                position.X = area.X0 + positionSizeOver2.X - sizeOver2.X;
                goto case GUIAnchor.MiddleLeft;

            case GUIAnchor.LowerCenter:
                position.X = area.X0 + positionSizeOver2.X - sizeOver2.X;
                goto case GUIAnchor.LowerLeft;

            case GUIAnchor.UpperRight:
                position.X = area.X1 - size.X;
                break;

            case GUIAnchor.MiddleRight:
                position.X = area.X1 - size.X;
                goto case GUIAnchor.MiddleLeft;

            case GUIAnchor.LowerRight:
                position.X = area.X1 - size.X;
                goto case GUIAnchor.LowerLeft;
            }

            return(AxisAlignedBox.FromRect(position + contentOffset, size));
        }
Esempio n. 15
0
        private void ongui()
        {
            if (Root.instance.gui.buttonold(new Vector2(x, 100), "abcdefghiABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()"))
            {
                //do something
            }

            if (Root.instance.input.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                x -= Root.instance.time.deltaTime;
            }
            if (Root.instance.input.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                x += Root.instance.time.deltaTime;
            }

            Root.instance.gui.label(new Vector2(x, 200), "absasdasd");
            Root.instance.gui.label(0, 1f, AxisAlignedBox.FromRect(new Vector2(x, 400), new Vector2(10, 100)), null, 0f, Color.Pink, "abcdefghijklmnopqrstuvwxyz");
        }
Esempio n. 16
0
        private void queryCollision(AxisAlignedBox shape, List <MinimumTranslationVector> collisions)
        {
            var screenAABB = shape;
            var wx0        = Math.Floor(screenAABB.X0 / tileSize);
            var wx1        = Math.Ceiling(screenAABB.X1 / tileSize);
            var wy0        = Math.Floor(screenAABB.Y0 / tileSize);
            var wy1        = Math.Ceiling(screenAABB.Y1 / tileSize);

            var minX = (int)Math.Max(0, wx0);
            var maxX = (int)Math.Min(_width.Number, wx1);
            var minY = (int)Math.Max(0, wy0);
            var maxY = (int)Math.Min(_height.Number, wy1);

            var hs   = tileSize * Game.WORLD_SCALE * Vector2.One;
            var aabb = AxisAlignedBox.FromRect(Vector2.Zero, hs);
            var mtv  = MinimumTranslationVector.Zero;

            for (var y = minY; y < maxY; y++)
            {
                for (var x = minX; x < maxX; x++)
                {
                    if (tiles[x, y].tileType != MapTileType.Room)
                    {
                        aabb.Center = new Vector2(x, y) * tileSize * Game.WORLD_SCALE + hs / 2;

                        var testmtv = shape.collide(aabb);
                        if (testmtv.intersects)
                        {
                            if (!mtv.intersects || testmtv.overlap < mtv.overlap)
                            {
                                mtv = testmtv;
                            }
                        }
                    }
                }
            }

            if (mtv.intersects)
            {
                collisions.Add(mtv);
            }
        }
Esempio n. 17
0
        private void ongui()
        {
            var font       = resources.findFont("content/fonts/arial.fnt");
            var screenSize = screen.size;

            //draw the health bar
            var g = Root.instance.graphics;
            //var p = transform.DerivedPosition;
            var p = new Vector2(20, screenSize.Y - 40);
            var s = new Vector2(p.X, p.Y);
            var e = new Vector2(p.X + 200, p.Y);
            var l = (float)health / (float)maxHealth;

            var bg = AxisAlignedBox.FromRect(s.X, s.Y - 3, 200, 20);
            var fg = AxisAlignedBox.FromRect(s.X, s.Y - 3, 200 * l, 20);

            g.Draw(null, bg, Color.White);
            g.Draw(null, fg, Color.Red);

            //graphics.DrawText(font, 1f, new Vector2(100, 100), "test", Color.Red);
        }
Esempio n. 18
0
        private void render()
        {
            //draw the health bar
            if (health < maxHealth)
            {
                var g = Root.instance.graphics;
                var p = transform.DerivedPosition;
                var s = new Vector2(p.X - 50, p.Y);
                var e = new Vector2(p.X + 50, p.Y);
                var l = (float)health / (float)maxHealth;

                var bg = AxisAlignedBox.
                         FromRect(s.X, s.Y - 3, 50, 4);
                var fg = AxisAlignedBox.
                         FromRect(s.X, s.Y - 3, 50 * l, 4);

                g.Draw(null, bg, Color.White);
                g.Draw(null, fg, Color.Red);
            }

            gui.label(transform.DerivedPosition, moveState.ToString());
        }
Esempio n. 19
0
        //private void init()
        //{
        //    _transform = this.gameObject.transform2();
        //}

        private void render()
        {
            if (frame >= frames.Count || frame < 0)
            {
                return;
            }

            var src = AxisAlignedBox.FromRect(frames[frame].point * size, frames[frame].size);

            Root.instance.graphics.Draw(renderQuere,
                                        material,
                                        gameObject.transform.DerivedPosition + offset,
                                        src,
                                        color,
                                        gameObject.transform.DerivedOrientation + rotation,
                                        Vector2.Zero,//origin,
                                        size * gameObject.transform.DerivedScale,
                                        spriteEffect,
                                        gameObject.transform.DerivedDepth);
            //var end = ProjectPointFromCenterRotation(100);
            //Root.instance.graphics.DrawLine(renderQuere, material, _transform.DerivedPosition, end, color);
        }
Esempio n. 20
0
        public override void doGui()
        {
            var mp    = input.MousePosition;
            var wp    = mainCamera.screenToWorld(mp);
            var p     = world.worldToIso(wp);
            var mouse = input.MousePosition;
            var gp    = gui.screenToGUI(mouse);

            if (ray.hit)
            {
                //var wp = world.isoToWorld(mp.X, mp.Y, world.currentMapDepth) + new Vector2(0, world.currentMapDepth * (world.blockSizeOver2 + world.floorSizeOver2));
                var content = new GUIContent(string.Format("mx:{4}, my:{5}, x:{0}, y:{1}, z:{2}, type:{3}", ray.iso.x, ray.iso.y, ray.iso.z, ray.objectType, p.X, p.Y));
                var size    = gui.skin.box.CalcSize(content, 100);
                gui.box(AxisAlignedBox.FromRect(gp, size), content);
            }
            else
            {
                var content = new GUIContent(string.Format("mx:{0}, my:{1}", p.X, p.Y));
                var size    = gui.skin.box.CalcSize(content, 100);
                gui.box(AxisAlignedBox.FromRect(gp, size), content);
            }
        }
Esempio n. 21
0
        public static GameObject prefabEnemy(this GameObject parent)
        {
            var go = parent.createChild();

            go.transform.Depth    = 1f;
            go.transform.Position = new Vector2(12.5f * Map.tileSize, 12.5f * Map.tileSize);

            var ai     = go.createScript <SimpleAI>();
            var sprite = go.createScript <JsonAnimation>();

            sprite.file = "content/sprites/skeleton.json"; //textureName = "content/textures/stickfigure.png";
            //sprite.color = Color.Red;
            //sprite.size = new Vector2(16, 32) * Game.WORLD_SCALE;
            //sprite.origin = new Vector2(0.5f, 0.5f);

            var physics = go.createScript <Physics>();

            physics.shape = AxisAlignedBox.FromRect(Vector2.Zero, new Vector2(16f, 32f) * Game.WORLD_SCALE);

            var stats = go.createScript <Stats>();

            stats.maxhp = 10;
            stats.hp    = 10;
            stats.xp    = 10;

            var collider = go.createScript <Collider>();

            collider.flags        = Physics.QUERY_ENEMIES;
            collider.collidesWith = Physics.QUERY_PLAYER;
            //collider.notifyObject = go;
            collider.size = new Vector2(16, 32) * Game.WORLD_SCALE;
            //collider.origin = new Vector2(0.5f, 0.5f);

            var knockback = go.createScript <Knockback>();
            var flash     = go.createScript <FlashSpriteOnDamage>();

            return(go);
        }
        private void init()
        {
            graphics.setSortOrder(WORLD_RENDER_QUEUE, RenderQueueSortMode.PreserverOrder);
            world = Root.instance.RootObject.getScript <WorldManager>();
            tm    = rootObject.find("tools").getScript <ToolManager>();

            worldObjectRenderers = new WorldObjectRenderer[256];

            spriteSheetMaterial = resources.createMaterialFromTexture("content/textures/gnomoria.png");
            spriteSheetMaterial.SetSamplerState(SamplerState.PointClamp);

            #region Load Sprite Sheet
            spriteSheet.addSprite("dirtfloor", new WorldSprite(AxisAlignedBox.FromRect(0, 52, 32, 20), 32, 20, 0, 0));
            spriteSheet.addSprite("dirtwall", new WorldSprite(AxisAlignedBox.FromRect(0, 72, 32, 32), 32, 32, 0, -16));
            spriteSheet.addSprite("floorselection", new WorldSprite(AxisAlignedBox.FromRect(0, 0, 32, 20), 32, 20, 0, 0));
            spriteSheet.addSprite("wallselection", new WorldSprite(AxisAlignedBox.FromRect(0, 20, 32, 32), 32, 32, 0, -16));

            worldObjectRenderers[(int)WorldObjectType.DirtFloor]      = new SpriteRenderer(this, "dirtfloor", new Color(0x96, 0x63, 0x30));
            worldObjectRenderers[(int)WorldObjectType.LightDirtFloor] = new SpriteRenderer(this, "dirtfloor", new Color(0xB4, 0x81, 0x4E));
            worldObjectRenderers[(int)WorldObjectType.DarkDirtFloor]  = new SpriteRenderer(this, "dirtfloor", new Color(0x78, 0x45, 0x30));

            worldObjectRenderers[(int)WorldObjectType.ClayFloor]      = new SpriteRenderer(this, "dirtfloor", new Color(0x66, 0x33, 0x00));
            worldObjectRenderers[(int)WorldObjectType.LightClayFloor] = new SpriteRenderer(this, "dirtfloor", new Color(0x84, 0x1e, 0x51));
            worldObjectRenderers[(int)WorldObjectType.DarkClayFloor]  = new SpriteRenderer(this, "dirtfloor", new Color(0x48, 0x00, 0x15));

            worldObjectRenderers[(int)WorldObjectType.DirtWall] = new SpriteRenderer(this, "dirtwall", new Color(0x96, 0x63, 0x30));
            //worldObjectRenderers[(int)WorldObjectType.LightDirtWall] = new SpriteRenderer(this, "dirtwall", new Color(0xB4, 0x81, 0x4E));
            //worldObjectRenderers[(int)WorldObjectType.DarkDirtWall] = new SpriteRenderer(this, "dirtwall", new Color(0x78, 0x45, 0x30));

            //worldObjectRenderers[(int)WorldObjectType.ClayWall] = new SpriteRenderer(this, "dirtwall", new Color(0x66, 0x33, 0x00));
            //worldObjectRenderers[(int)WorldObjectType.LightClayWall] = new SpriteRenderer(this, "dirtwall", new Color(0x84, 0x1e, 0x51));
            //worldObjectRenderers[(int)WorldObjectType.DarkClayWall] = new SpriteRenderer(this, "dirtwall", new Color(0x48, 0x00, 0x15));

            worldObjectRenderers[(int)WorldObjectType.FloorSelection] = new SpriteRenderer(this, "floorselection", new Color(0x0, 0x88, 0x88));
            worldObjectRenderers[(int)WorldObjectType.WallSelection]  = new SpriteRenderer(this, "wallselection", new Color(0x0, 0x88, 0x88));
            #endregion
        }
Esempio n. 23
0
        internal void DrawWrappedOnWordText(int renderQueue, Vector2 pos, float scale, string text, Color color, float depth, Vector2 size)
        {
            float dx = (float)Math.Floor(pos.X);
            float dy = (float)Math.Floor(pos.Y);

            var currentSize = Vector2.Zero;
            var current     = 0;

            while (current != -1 && current < text.Length)
            {
                var start = current;
                current = FindWordIndexFromBounds(current, size.X, text, out currentSize);

                if (current > 0)
                {
                    for (int i = start; i < current; i++)
                    {
                        var      c = text[i];
                        FontChar fc;
                        if (_characterMap.TryGetValue(c, out fc))
                        {
                            var sourceRectangle = AxisAlignedBox.FromRect(fc.X, fc.Y, fc.Width, fc.Height);
                            var destRectangle   = AxisAlignedBox.FromRect(dx + fc.XOffset * scale, dy + fc.YOffset * scale, fc.Width * scale, fc.Height * scale);
                            //var position = new Vector2(dx + fc.XOffset, dy + fc.YOffset);
                            Root.instance.graphics.Draw(renderQueue, _material, destRectangle, sourceRectangle, color, 0f, new Vector2(0f, 0f), SpriteEffects.None, depth);
                            //spriteBatch.Draw(_texture, position, sourceRectangle, Color.White);
                            dx += fc.XAdvance * scale;
                        }
                    }

                    dx  = (float)Math.Floor(pos.X);
                    dy += MaxLineHeight;
                }

                size.Y += currentSize.Y;
            }
        }
Esempio n. 24
0
        internal void DrawText(int renderQueue, Vector2 pos, float scale, string text, Color color, float depth, float?width)
        {
            float dx = (float)Math.Floor(pos.X);
            float dy = (float)Math.Floor(pos.Y);

            foreach (char c in text)
            {
                FontChar fc;
                if (_characterMap.TryGetValue(c, out fc))
                {
                    if (width.HasValue && dx + fc.XAdvance * scale > width.Value + pos.X)
                    {
                        break;
                    }

                    var sourceRectangle = AxisAlignedBox.FromRect(fc.X, fc.Y, fc.Width, fc.Height);
                    var destRectangle   = AxisAlignedBox.FromRect(dx + fc.XOffset * scale, dy + fc.YOffset * scale, fc.Width * scale, fc.Height * scale);
                    //var position = new Vector2(dx + fc.XOffset, dy + fc.YOffset);
                    Root.instance.graphics.Draw(renderQueue, _material, destRectangle, sourceRectangle, color, 0f, new Vector2(0f, 0f), SpriteEffects.None, depth);
                    //spriteBatch.Draw(_texture, position, sourceRectangle, Color.White);
                    dx += fc.XAdvance * scale;
                }
            }
        }
Esempio n. 25
0
 public QuadNode(float x, float y, float width, float height)
     : this(AxisAlignedBox.FromRect(x, y, width, height))
 {
 }
Esempio n. 26
0
        private void render()
        {
            var color1     = new Vector3(1f, 0.5f, 0.1f);
            var color2     = new Vector3(0f, 0.8f, 0f);
            var screenAABB = Camera.mainCamera.worldBounds;
            var wx0        = Math.Floor(screenAABB.X0 / tileSize);
            var wx1        = Math.Ceiling(screenAABB.X1 / tileSize);
            var wy0        = Math.Floor(screenAABB.Y0 / tileSize);
            var wy1        = Math.Ceiling(screenAABB.Y1 / tileSize);

            var minX = (int)Math.Max(0, wx0);
            var maxX = (int)Math.Min(size, wx1);
            var minY = (int)Math.Max(0, wy0);
            var maxY = (int)Math.Min(size, wy1 + 10);


            for (var y = minY; y < maxY; y++)
            {
                for (var x = minX; x < maxX; x++)
                {
                    for (var z = 0; z < heights[x, y]; z++)
                    {
                        var p = new Vector2(x * tileSize, y * tileSize - z * tileHeight);

                        //var c = color1.Lerp(color2, z / 10f);
                        //if (shadowmap[x, y])
                        //    c *= 0.9f;
                        Root.instance.graphics.Draw(0, _plain, AxisAlignedBox.FromRect(p, tileSize, 72), new Color(tileColors[map[x, y, z]]), z);

                        if (z == heights[x, y] - 1)
                        {
                            if (((x + 1 < size && heights[x + 1, y] > heights[x, y])))
                            {
                                Root.instance.graphics.Draw(0, _shadow_hort, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, z + 0.1f);
                            }
                            if (((y - 1 >= 0 && heights[x, y - 1] > heights[x, y])))
                            {
                                Root.instance.graphics.Draw(0, _shadow_vert, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, z + 0.1f);
                            }

                            if (((x - 1 >= 0 && heights[x - 1, y] > heights[x, y])))
                            {
                                Root.instance.graphics.Draw(0, _shadow_hort, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, SpriteEffects.FlipHorizontally, z + 0.1f);
                            }
                            if (((y + 1 < size && heights[x, y + 1] > heights[x, y])))
                            {
                                Root.instance.graphics.Draw(0, _shadow_vert, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, SpriteEffects.FlipVertically, z + 0.1f);
                            }
                        }

                        if ((x - 1 < 0 || heights[x - 1, y] < heights[x, y]) && z == heights[x, y] - 1)
                        {
                            Root.instance.graphics.DrawLine(new Vector2(x * tileSize, y * tileSize - z * tileHeight), new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        }
                        if ((x + 1 >= size || heights[x + 1, y] < heights[x, y]) && z == heights[x, y] - 1)
                        {
                            Root.instance.graphics.DrawLine(new Vector2((x + 1) * tileSize, y * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        }
                        if ((y - 1 < 0 || heights[x, y - 1] < heights[x, y]) && z == heights[x, y] - 1)
                        {
                            Root.instance.graphics.DrawLine(new Vector2(x * tileSize, y * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, y * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        }
                        if ((y + 1 >= size || heights[x, y + 1] < heights[x, y]) && z == heights[x, y] - 1)
                        {
                            Root.instance.graphics.DrawLine(new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f);
                        }
                        if ((x - 1 < 0 || heights[x - 1, y] < z + 1) && (y + 1 >= size || heights[x, y + 1] < z + 1))
                        {
                            Root.instance.graphics.DrawLine(new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight + tileHeight), Color.Black, z + 0.1f);
                        }
                        if ((x + 1 >= size || heights[x + 1, y] < z + 1) && (y + 1 >= size || heights[x, y + 1] < z + 1))
                        {
                            Root.instance.graphics.DrawLine(new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight + tileHeight), Color.Black, z + 0.1f);
                        }
                    }
                }
            }
        }
Esempio n. 27
0
 public AxisAlignedBox getDrawRect(Vector2 p)
 {
     return(AxisAlignedBox.FromRect(p + new Vector2(offsetX, offsetY), new Vector2(width, height)));
 }
Esempio n. 28
0
 public AxisAlignedBox getTileRect(int x, int y)
 {
     return(AxisAlignedBox.FromRect(new Vector2(x, y) * tileSize - new Vector2(tileSizeHs, tileSizeHs),
                                    new Vector2(tileSize, tileSize)));
 }
Esempio n. 29
0
        internal void computeTextAndIconAbove(GUIContent content, AxisAlignedBox area, Vector2 textSize, float remainingHeight, out AxisAlignedBox icon, out AxisAlignedBox text)
        {
            var textSizeOver2     = textSize / 2;
            var positionSizeOver2 = area.Size / 2;
            var drawPosition      = area.minVector;
            var scaleSize         = Vector2.One * Utility.Min(remainingHeight, area.Height);
            var iconSize          = Utility.ScaleToSize(content.icon.textureSize, scaleSize);
            var iconSizeOver2     = iconSize / 2;
            var iconPosition      = area.minVector;

            switch (alignment)
            {
            case GUIAnchor.UpperLeft:
                drawPosition.Y += iconSize.Y;
                break;

            case GUIAnchor.MiddleLeft:
            {
                var size = (area.Height - (iconSize.Y + textSize.Y)) / 2;

                iconPosition.Y += size;
                drawPosition.Y  = iconPosition.Y + iconSize.Y;
            }
            break;

            case GUIAnchor.LowerLeft:
                drawPosition.Y = area.Y1 - textSize.Y;
                iconPosition.Y = drawPosition.Y - iconSize.Y;
                break;

            case GUIAnchor.UpperRight:
                drawPosition.X  = area.X1 - textSize.X;
                drawPosition.Y += iconSize.Y;
                iconPosition.X += area.Width - iconSize.X;
                break;

            case GUIAnchor.MiddleRight:
            {
                var sizeH = (area.Height - (iconSize.Y + textSize.Y)) / 2;

                drawPosition.X  = area.X1 - textSize.X;
                iconPosition.X  = area.X1 - iconSize.X;
                iconPosition.Y += sizeH;
                drawPosition.Y  = iconPosition.Y + iconSize.Y;
            }
            break;

            case GUIAnchor.LowerRight:
                drawPosition.Y = area.Y1 - textSize.Y;
                drawPosition.X = area.X1 - textSize.X;
                iconPosition.X = area.X1 - iconSize.X;
                iconPosition.Y = drawPosition.Y - iconSize.Y;
                break;

            case GUIAnchor.UpperCenter:
                drawPosition.X  = area.X0 + positionSizeOver2.X - textSizeOver2.X;
                iconPosition.X += positionSizeOver2.X - iconSizeOver2.X;
                drawPosition.Y += iconSize.Y;
                break;

            case GUIAnchor.MiddleCenter:
            {
                var sizeH = (area.Height - (iconSize.Y + textSize.Y)) / 2;

                iconPosition.X += positionSizeOver2.X - iconSizeOver2.X;
                iconPosition.Y += sizeH;
                drawPosition.X  = area.X0 + positionSizeOver2.X - textSizeOver2.X;
                drawPosition.Y  = iconPosition.Y + iconSize.Y;

                break;
            }

            case GUIAnchor.LowerCenter:
                drawPosition.Y  = area.Y1 - textSize.Y;
                drawPosition.X  = area.X0 + positionSizeOver2.X - textSizeOver2.X;
                iconPosition.X += positionSizeOver2.X - iconSizeOver2.X;
                iconPosition.Y  = drawPosition.Y - iconSize.Y;
                break;
            }

            switch (alignment)
            {
            case GUIAnchor.LowerLeft:
            case GUIAnchor.MiddleLeft:
            case GUIAnchor.UpperLeft:
                if (textSize.X > iconSize.X)
                {
                    iconPosition.X += textSizeOver2.X - iconSizeOver2.X;
                }
                else
                {
                    drawPosition.X += iconSizeOver2.X - textSizeOver2.X;
                }

                break;

            case GUIAnchor.LowerRight:
            case GUIAnchor.MiddleRight:
            case GUIAnchor.UpperRight:
                if (textSize.X > iconSize.X)
                {
                    iconPosition.X -= textSizeOver2.X - iconSizeOver2.X;
                }
                else
                {
                    drawPosition.X -= iconSizeOver2.X - textSizeOver2.X;
                }

                break;
            }



            icon = AxisAlignedBox.FromRect(iconPosition + contentOffset, iconSize);
            text = AxisAlignedBox.FromRect(drawPosition + contentOffset, textSize);
        }
Esempio n. 30
0
        internal void Draw(RenderManager graphics, GUIContent content, GUIDrawArguments drawArgs)
        {
            var size = drawArgs.position.Size;

            if (fixedWidth > 0f)
            {
                size.X = fixedWidth;
            }
            if (fixedHeight > 0f)
            {
                size.Y = fixedHeight;
            }

            drawArgs.content = AxisAlignedBox.FromRect(drawArgs.position.minVector + padding.min, size - padding.max - padding.min);
            var textSize = Vector2.Zero;

            if (!string.IsNullOrEmpty(content.text))
            {
                if (wordWrap)
                {
                    textSize = font.MeasureString(content.text, drawArgs.content.Size);
                }
                else
                {
                    textSize = font.MeasureString(content.text);
                }
            }

            var remainingWidth  = drawArgs.content.Width - textSize.X;
            var remainingHeight = drawArgs.content.Height - textSize.Y;

            var drawIcon = content.icon != null;
            var drawText = !string.IsNullOrEmpty(content.text);

            var state = getState(drawArgs);

            if (remainingWidth <= 0 && imagePosition == ImagePosition.ImageLeft)
            {
                textSize.X = drawArgs.content.Width;
                drawIcon   = false;
            }
            else if (remainingHeight <= 0 && imagePosition == ImagePosition.ImageAbove)
            {
                textSize.Y = drawArgs.content.Height;
                drawIcon   = false;
            }

            var material = state.material;// Root.instance.resources.createMaterialFromTexture("content/textures/gui/box.png")

            if (material != null)
            {
                if (border.min == Vector2.Zero && border.max == Vector2.Zero)
                {
                    graphics.Draw(material, drawArgs.position, state.backgroundColor);
                }
                else
                {
                    var src      = AxisAlignedBox.FromRect(Vector2.Zero, material.textureSize);
                    var dstRects = drawArgs.position.fromRectOffset(border);
                    var srcRects = src.fromRectOffset(border);
                    for (var i = 0; i < dstRects.Length; i++)
                    {
                        if (dstRects[i].Width > 0 && dstRects[i].Height > 0)
                        {
                            graphics.Draw(material, dstRects[i], srcRects[i], state.backgroundColor);
                        }
                    }
                }
            }

            if (drawIcon && imagePosition == ImagePosition.ImageLeft)
            {
                AxisAlignedBox icon, text;
                computeTextAndIconLeft(content, drawArgs.content, textSize, remainingWidth, out icon, out text);

                graphics.Draw(content.icon, icon, Color.White);
                font.DrawText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Width);
            }
            else if (drawIcon && imagePosition == ImagePosition.ImageAbove)
            {
                AxisAlignedBox icon, text;
                computeTextAndIconAbove(content, drawArgs.content, textSize, remainingHeight, out icon, out text);

                graphics.Draw(content.icon, icon, Color.White);
                if (wordWrap)
                {
                    font.DrawWrappedOnWordText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Size);
                }
                else
                {
                    font.DrawText(graphics.currentRenderQueue, text.minVector, this.fontSize, content.text, state.textColor, 0f, text.Width);
                }
            }
            else if (drawText && imagePosition != ImagePosition.ImageOnly)
            {
                var position = computePosition(drawArgs.content, textSize);
                if (wordWrap)
                {
                    font.DrawWrappedOnWordText(graphics.currentRenderQueue, position.minVector, this.fontSize, content.text, state.textColor, 0f, position.Size);
                }
                else
                {
                    font.DrawText(graphics.currentRenderQueue, position.minVector, this.fontSize, content.text, state.textColor, 0f, position.Width);
                }
            }
            else if (drawIcon && imagePosition != ImagePosition.TextOnly)
            {
                var position = computePosition(drawArgs.content, content.icon.textureSize);
                graphics.Draw(content.icon, position, Color.White);
                graphics.DrawRect(position, Color.Blue);
            }
        }