Esempio n. 1
0
 protected CommandButton(ICommand command, IQueueable <TextureValue> queueableObject, Point Size)
 {
     this.bounds   = new Rectangle(queueableObject.Position.ToPoint(), Size);
     this.Position = queueableObject.Position;
     this.picture  = ContentHandler.DrawnTexture(queueableObject.Icon);
     this.command  = command;
 }
Esempio n. 2
0
 protected CommandButton(ICommand command, Vector2 position, TextureValue picture, Point size) : base(position, size, Color.White)
 {
     this.bounds   = new Rectangle(position.ToPoint(), Size);
     this.Position = position;
     this.picture  = ContentHandler.DrawnTexture(picture);
     this.command  = command;
     this.Size     = size;
 }
Esempio n. 3
0
 public void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.Begin();
     foreach (Projectile projectile in projectiles)
     {
         spriteBatch.Draw(ContentHandler.DrawnTexture(projectile.Texture), projectile.Position * Tile.Zoom * 16 - cam.Position * Tile.Zoom * 16, null, Color.White, projectile.Direction, new Vector2(), projectile.Scale, SpriteEffects.None, 0);
     }
     spriteBatch.End();
 }
 public override void Update(GameTime gameTime)
 {
     if (tile is Building)
     {
         if (((Building)tile).trainingQueue.Count != prevCount)//Handle Queued item display
         {
             float x = 220;
             foreach (IComponent comp in QueueableUnits)
             {
                 if (components.Contains(comp))
                 {
                     components.Remove(comp);
                 }
             }
             QueueableUnits.Clear();
             foreach (IQueueable <TextureValue> queueable in ((Building)tile).trainingQueue)
             {
                 float width = ContentHandler.DrawnTexture(queueable.Icon).Bounds.Size.X;
                 x += 16 + 1;
                 QueueableUnits.Add(new ImageBox(queueable.Icon, new Vector2(x, 433), ContentHandler.DrawnTexture(queueable.Icon).Bounds.Size, Color.White));
                 float scale = width / 16;
                 ((Component)QueueableUnits[QueueableUnits.Count - 1]).Scale = 1f / scale;
                 components.Add(QueueableUnits[QueueableUnits.Count - 1]);
             }
             prevCount = ((Building)tile).trainingQueue.Count;
         }
     }
     for (int i = 0; i < components.Count; i++)
     {
         if (components[i] is StatComponent)
         {
             StatComponent component = (StatComponent)components[i];
             string        display   = component.component.Text;
             if (tile.stats[component.statType] is Health)
             {
                 if (prevHealth != tile.CurrentHealth)
                 {
                     display = $"{tile.CurrentHealth}/{tile.TotalHealth}";
                 }
             }
             else if (tile.stats[component.statType].Value + tile.TeamStats[component.statType].Value != component.value)
             {
                 display = tile.stats[component.statType].Value.ToString();
                 if (tile.TeamStats[component.statType] != null)
                 {
                     display += $"({tile.TeamStats[component.statType].Value})";
                 }
                 component.value = tile.stats[component.statType].Value + tile.TeamStats[component.statType].Value;
             }
             component.component.Text = display;
         }
     }
     base.Update(gameTime);
 }
Esempio n. 5
0
 /// <summary>
 /// Drawing for selected buildings and the spawn marker(Visual placement markers - Buildings/spawn markers)
 /// </summary>
 private void ComponentOverlay(SpriteBatch spriteBatch)
 {
     if (cp.cc.SelectedBuild != null)
     {
         Building build = cp.cc.SelectedBuild;
         if (world.CheckPlacement(cp.CurrentPos, build.Size))
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(build.block.texture), (cp.CurrentPos * Tile.Zoom * 16) - (cp.camera.Position * Tile.Zoom * 16), null, Color.Green, 0, ZeroVector, Tile.Zoom, SpriteEffects.None, 0);
         }
         else
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(build.block.texture), (cp.CurrentPos * Tile.Zoom * 16) - (cp.camera.Position * Tile.Zoom * 16), null, Color.Red, 0, ZeroVector, Tile.Zoom, SpriteEffects.None, 0);
         }
     }
     else if (cp.cc.SpawnMarker != null)
     {
         spriteBatch.Draw(cp.cc.SpawnMarker, (cp.CurrentPos * Tile.Zoom * 16) - (cp.camera.Position * Tile.Zoom * 16), null, Color.Red, 0, ZeroVector, Tile.Zoom, SpriteEffects.None, 0);
     }
 }
Esempio n. 6
0
        private void DrawScreen(SpriteBatch sb, int x, int y, int i)
        {
            Tile tile = null;

            if (x >= 0 && x < bounds.Width && y >= 0 && y < bounds.Height)
            {
                TilePos = new Vector2(x, y);
                //Background tiles are drawn first
                if (i == 0)
                {
                    tile = world.GetBackgroundTile(TilePos);
                    sb.Draw(ContentHandler.DrawnTexture(tile.block.texture), (tile.Position * Tile.Zoom * 16) - (position * Tile.Zoom * 16), null, Color.White, 0, Zero, Tile.Zoom, SpriteEffects.None, 0);
                }
                //Units are drawn second
                else if (i == 1)
                {
                    tile = (ModifiableTile)world.GetUnit(TilePos);
                    if (tile != null && tile.block.texture != TextureValue.None)
                    {
                        Texture2D texture = ContentHandler.DrawnTexture(tile.block.texture);
                        ((BasicUnit)tile).UpdatePosition(Game.GraphicsDevice, tile.Position);
                        sb.Draw(ContentHandler.DrawnTexture(tile.block.texture), (tile.Position * Tile.Zoom * 16) - (position * Tile.Zoom * 16), null, Color.White, 0, Zero, Tile.Zoom, SpriteEffects.None, 0);
                        DrawHealth(sb, (ModifiableTile)tile);
                    }
                }
                //Draw buildings third
                else
                {
                    tile = world.GetTile(TilePos);
                    if (tile != null && tile.block.texture != TextureValue.None)
                    {
                        Texture2D texture = ContentHandler.DrawnTexture(tile.block.texture);
                        tile.UpdatePosition(Game.GraphicsDevice, tile.Position);
                        sb.Draw(ContentHandler.DrawnTexture(tile.block.texture), (tile.Position * Tile.Zoom * 16) - (position * Tile.Zoom * 16), null, Color.White, 0, Zero, Tile.Zoom, SpriteEffects.None, 0);
                        if (!(tile is IHarvestable))
                        {
                            DrawHealth(sb, (ModifiableTile)tile);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// set a spawn point if the spawnmarker isn't null otherwise set the spawn marker
        /// </summary>
        /// <param name="position"></param>
        /// <param name="building"></param>
        internal void SetSpawnPoint(Vector2 position, Building building)
        {
            if (SpawnMarker != null)
            {
                spawnMarkerBuilding.SetSpawn(position);
                SpawnMarker         = null;
                spawnMarkerBuilding = null;
            }
            else
            {
                SpawnMarker = ContentHandler.DrawnTexture(TextureValue.SpawnPoint);

                ModifiableTile tile = world.GetTile(position);
                if (tile is ReferenceTile)
                {
                    tile = ((ReferenceTile)tile).tile;
                }
                spawnMarkerBuilding = (Building)tile;
            }
        }
Esempio n. 8
0
        private void AddQueueables(Tile tile)
        {
            if (EntityDetails != null)
            {
                overlay.RemoveComponent(EntityActions);
            }
            EntityActions = new Panel(Game, new Rectangle(new Point(591, 359), new Point(200, 120)), this);
            EntityActions.Initialize();
            //BuildQueue size
            //Pos: (591,391) Size: (200,120)
            float x     = 591; //MaxX = 791
            float y     = 359; //MaxY = 511
            float scale = 0.25f;

            if (tile is BasicUnit && !(tile is HostileMob) && ((BasicUnit)tile).QueueableThings != null) // HACK need to move the queueable things up the chain
            {
                foreach (IQueueable <TextureValue> queueable in ((BasicUnit)tile).QueueableThings)
                {
                    if (queueable is Building)
                    {
                        ((Building)queueable).UpdatePosition(Game.GraphicsDevice, new Vector2(x, y));
                        Component com    = new CommandButton(Game.GraphicsDevice, new BuildSelectCommand((Building)queueable), new Vector2(x, y), queueable.Icon, new Point(32));
                        float     width  = ((Building)queueable).Size.X;
                        float     height = ((Building)queueable).Size.Y;
                        com.Scale = 0.25f;
                        EntityActions.AddComponent(com);
                        x += 128 * scale;
                        if (x + 128 * scale > 791)
                        {
                            x  = 591;
                            y += 128 * scale;
                        }
                    }
                }
            }
            else if (tile is Building && ((ModifiableTile)tile).built)
            {
                foreach (IQueueable <TextureValue> queueable in ((Building)tile).QueueableThings)
                {
                    if (queueable is BasicUnit)
                    {
                        ((BasicUnit)queueable).UpdatePosition(Game.GraphicsDevice, new Vector2(x, y));
                        Component com    = new CommandButton(Game.GraphicsDevice, new TrainCommand((IUnit)queueable, (Building)tile), queueable, new Point(32));
                        float     width  = ((BasicUnit)queueable).Size.X;
                        float     height = ((BasicUnit)queueable).Size.Y;
                        com.Scale = 2;
                        EntityActions.AddComponent(com);
                        x += 128 * scale;
                        if (x + 128 * scale > 791)
                        {
                            x  = 591;
                            y += 128 * scale;
                        }
                    }
                    if (queueable is ITech)
                    {
                        ((Technology)queueable).Position = new Vector2(x, y);
                        Component com    = new CommandButton(Game.GraphicsDevice, new LearnCommand((ITech)queueable, (Building)tile), queueable, new Point(32));
                        float     width  = ContentHandler.DrawnTexture(((Technology)queueable).Icon).Bounds.Size.X;
                        float     height = ContentHandler.DrawnTexture(((Technology)queueable).Icon).Bounds.Size.Y;
                        com.Scale = 0.5f;
                        EntityActions.AddComponent(com);
                        x += 128 * scale;
                        if (x + 128 * scale > 791)
                        {
                            x  = 591;
                            y += 128 * scale;
                        }
                    }
                }
                if (((Building)tile).QueueableThings.Find(l => l is BasicUnit) != null)
                {
                    Component com = new CommandButton(Game.GraphicsDevice, new SetSpawnPointCommand(CurrentPos, (Building)tile), new Vector2(757, 447), TextureValue.SpawnPoint, new Point(32));
                    com.Scale = 2;
                    EntityActions.AddComponent(com);
                }
            }
            overlay.AddComponent(EntityActions);
        }
Esempio n. 9
0
 public ImageBox(TextureValue texture, Vector2 position, Point size, Color color) : base(position, size, color)
 {
     this.picture = ContentHandler.DrawnTexture(texture);
     this.texture = texture;
 }
Esempio n. 10
0
 public override void Draw(SpriteBatch spriteBatch)
 {
     tile = world.GetTile(cp.camera.ConvertToWorldSpace(input.InputPos));
     if (tile == null)
     {
         tile = (ModifiableTile)world.GetUnit(input.InputPos);
     }
     if (tile != null)
     {
         if (tile is ReferenceTile)
         {
             tile = ((ReferenceTile)tile).tile;
         }
         if (tile != null && tile.TeamAssociation != CommandComponent.ID) //HACK if I add multiple players this might change but ID's at the moment this will work
         {
             if (tile is IHarvestable)
             {
                 currentCursorTexture = TextureValue.HarvestPower;
             }
             else
             {
                 currentCursorTexture = TextureValue.Damage;
             }
         }
         else
         {
             if (tile is Building)
             {
                 currentCursorTexture = TextureValue.BuildPower;
             }
             else
             {
                 currentCursorTexture = TextureValue.Cursor;
             }
         }
     }
     else
     {
         currentCursorTexture = TextureValue.Cursor;
     }
     spriteBatch.Begin();
     ComponentOverlay(spriteBatch);
     spriteBatch.Draw(ContentHandler.DrawnTexture(TextureValue.Overlay), Vector2.Zero, Color.White);
     DrawMap(spriteBatch);
     DrawText(spriteBatch);
     foreach (CommandButton button in components.Where(l => l is CommandButton))//For all queueable objects if you can afford it, it shows up normally if not it shows up red
     {
         if (button.command is BuildSelectCommand)
         {
             if (!cp.cc.CheckCost(((BuildSelectCommand)button.command).build))
             {
                 button.Color = Color.Red;
             }
             else
             {
                 button.Color = Color.White;
             }
         }
     }
     base.Draw(spriteBatch);
     if (description.drawComponent)
     {
         spriteBatch.Draw(description.picture, description.Position, description.Color);
         spriteBatch.DrawString(ContentHandler.Font, description.Text, description.Position, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
     }
     if (currentCursorTexture == TextureValue.Cursor)
     {
         if (cp.clicked)
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.Yellow, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
         else
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.Red, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
     }
     else
     {
         if (cp.clicked)
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.Green, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
         else
         {
             spriteBatch.Draw(ContentHandler.DrawnTexture(currentCursorTexture), input.InputPos, null, Color.White, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 0);
         }
     }
     spriteBatch.End();
 }