private void DrawMinimapObject(MinimapObject minimap, ref Object2D parent) { if (minimapUpdate == true) { System.IO.Stream stream = System.IO.File.Open(minimap.TextureLocation + ".png", System.IO.FileMode.Open); minimap.Texture = Texture2D.FromStream(Configuration.GraphicsDevice, stream); stream.Close(); minimap.Init = false; } minimap.Size.X = ((parent as GraphicObject).Size.X / 100 * minimap.iSize.X); minimap.Size.Y = ((parent as GraphicObject).Size.Y / 100 * minimap.iSize.Y); minimap.DrawRect = new Rectangle( (int)(MathHelper.Clamp(((float)GameHandler.Player.CurrentTile.X * 4) - (minimap.Size.X / 2), 0.0f, minimap.Texture.Width-minimap.Size.X)), (int)(MathHelper.Clamp((GameHandler.Player.CurrentTile.Y * 4) - ((int)minimap.Size.Y / 2), 0.0f, minimap.Texture.Height-minimap.Size.Y)), (int)minimap.Size.X, (int)minimap.Size.Y); minimap.Position.X = ((parent as GraphicObject).Size.X / 100 * minimap.iPosition.X); minimap.Position.Y = ((parent as GraphicObject).Size.Y / 100 * minimap.iPosition.Y); minimap.Position += (parent as GraphicObject).Position; SpriteManager.Draw(minimap.Texture, new Vector2(minimap.Position.X, minimap.Position.Y), minimap.DrawRect, Color.White); }
private void DrawTextBoxComponent(TextBoxObject component, Object2D parent) { GraphicObject Parent = (GraphicObject)parent; component.offset.X = Parent.Size.X / 100 * component.ioffset.X; component.offset.Y = Parent.Size.Y / 100 * component.ioffset.Y; component.Init = true; Vector2 off = component.offset; component.BoundingRect = new Rectangle((int)Parent.Position.X + (int)off.X, (int)Parent.Position.Y + (int)off.Y, (int)Parent.Size.X, (int)Parent.Size.Y); if (Game.Content.Load<SpriteFont>(component.Font).MeasureString(component.Text).Y > component.BoundingRect.Height) { float maxY = (Parent.Position.Y - (Parent.Size.Y / 2)+5); float minY = (Parent.Position.Y + component.BoundingRect.Height - (Parent.Size.Y / 2)) - (Game.Content.Load<SpriteFont>(component.Font).MeasureString(component.Text).Y); if (component.currentOffset.Y > maxY) component.currentOffset.Y = maxY; else if (component.currentOffset.Y < minY) component.currentOffset.Y = minY; } Rectangle currentRect = SpriteManager.ScissorRectangle; SpriteManager.ScissorRectangle = component.BoundingRect; SpriteManager.DrawString(Game.Content.Load<SpriteFont>(component.Font), component.Text, Parent.Position + off + component.currentOffset, new Color(component.fontColor)); SpriteManager.ScissorRectangle = currentRect; DrawGraphicComponent(component.UpScroller, ref parent); DrawGraphicComponent(component.DownScroller, ref parent); }
private void DrawGraphicComponent(GraphicObject component, ref Object2D parent) { if (component.TextureLocation != "") { if (component.TextureLocation.StartsWith("@")) { if (component.TextureLocation == "@AppleTexture") { if (GameHandler.Inventory.NumberOfApples > 0) component.Texture = Game.Content.Load<Texture2D>("Sprites\\Apple"); else component.Texture = Game.Content.Load<Texture2D>("Sprites\\NullItems\\NullApple"); } if(component.TextureLocation == "@GoldenAppleTexture") { if (GameHandler.Inventory.NumberOfGoldenApples > 0) component.Texture = Game.Content.Load<Texture2D>("Sprites\\GoldenApple"); else component.Texture = Game.Content.Load<Texture2D>("Sprites\\NullItems\\NullGoldenApple"); } if(component.TextureLocation == "@SpringWaterTexture") { if (GameHandler.Inventory.NumberOfSpringWater > 0) component.Texture = Game.Content.Load<Texture2D>("Sprites\\SpringWater"); else component.Texture = Game.Content.Load<Texture2D>("Sprites\\NullItems\\NullSpringWater"); } if(component.TextureLocation == "@HoneyTexture") { if (GameHandler.Inventory.NumberOfHoney > 0) component.Texture = Game.Content.Load<Texture2D>("Sprites\\Honey"); else component.Texture = Game.Content.Load<Texture2D>("Sprites\\NullItems\\NullHoney"); } if (component.TextureLocation == "@ChilliTexture") { if (GameHandler.Inventory.NumberOfChilli > 0) component.Texture = Game.Content.Load<Texture2D>("Sprites\\Chilli"); else component.Texture = Game.Content.Load<Texture2D>("Sprites\\NullItems\\NullChilli"); } if (component.TextureLocation == "@PlayerCanFlyIcon") { if (GameHandler.Player.canFly) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/FlyingIcon"); else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } if (component.TextureLocation == "@PlayerCanClimbIcon") { if (GameHandler.Player.canClimb) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/ClimingIcon"); else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } if (component.TextureLocation == "@PlayerCanSwimIcon") { if (GameHandler.Player.canSwim) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/SwimmingIcon"); else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } if (component.TextureLocation == "@SelectedCanFly") { if (GameHandler.Inventory.SelectedDNA != null) { if (GameHandler.Inventory.SelectedDNA.canFly) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/FlyingIcon"); else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } if (component.TextureLocation == "@SelectedCanClimb") { if (GameHandler.Inventory.SelectedDNA != null) { if (GameHandler.Inventory.SelectedDNA.canClimb) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/ClimingIcon"); else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } if (component.TextureLocation == "@SelectedCanSwim") { if (GameHandler.Inventory.SelectedDNA != null) { if (GameHandler.Inventory.SelectedDNA.canSwim) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/SwimmingIcon"); else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } else component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/BlankIcon"); } if (component.TextureLocation == "@CurrentAttributeInUse") { if (GameHandler.CurrentAttributeInUse != Attributes.None) { if(GameHandler.Player.canFly) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/FlyingIcon"); else { if (GameHandler.CurrentAttributeInUse == Attributes.FlyingAndClimbing) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/ClimingIcon"); if (GameHandler.CurrentAttributeInUse == Attributes.FlyingAndSwimming) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/SwimmingIcon"); } } else { component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/Icons/IconBackground"); } } } else if (component.Texture == null) component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/" + (component as GraphicObject).TextureLocation); } else if (component.Texture == null) component.Texture = new Texture2D(Game.GraphicsDevice, 1, 1); if (((component.GetType() == typeof(GraphicObject)) || component.GetType() == typeof(Scroller)) && (parent.GetType() == typeof(GraphicObject))) { component.Size.X = ((parent as GraphicObject).Size.X / 100 * component.iSize.X); component.Size.Y = ((parent as GraphicObject).Size.Y / 100 * component.iSize.Y); component.Position.X = ((parent as GraphicObject).Size.X / 100 * component.iPosition.X) - (component.Size.X / 2); component.Position.Y = ((parent as GraphicObject).Size.Y / 100 * component.iPosition.Y) - (component.Size.Y / 2); component.Position += (parent as GraphicObject).Position; } /* if(component.isCentered) component.offset = new Vector2(component.Size.X, component.Size.Y) / 2; */ if (component.fullscreen) { component.Position.X = 0; component.Position.Y = 0; component.Size.X = Game.GraphicsDevice.Viewport.Width; component.Size.Y = Game.GraphicsDevice.Viewport.Height; SpriteManager.Draw(component.Texture, Configuration.Bounds, Color.White); } else { if (component.isClickable) { Rectangle textureRect = new Rectangle((int)component.Position.X, (int)component.Position.Y, (int)component.Size.X, (int)component.Size.Y); if(textureRect.Contains(new Point(InputHandler.MouseX, InputHandler.MouseY))) SpriteManager.Draw(component.Texture, new Rectangle((int)component.Position.X - 10, (int)component.Position.Y - 10, (int)component.Size.X+20, (int)component.Size.Y+20), null, Color.White); else SpriteManager.Draw(component.Texture, new Rectangle((int)component.Position.X, (int)component.Position.Y, (int)component.Size.X, (int)component.Size.Y), null, Color.White); } else SpriteManager.Draw(component.Texture, new Rectangle((int)component.Position.X, (int)component.Position.Y, (int)component.Size.X, (int)component.Size.Y), null, Color.White); } }
private void DrawListBox(ListBox component, Object2D parent) { GraphicObject Parent = (GraphicObject)parent; component.offset.X = Parent.Size.X / 100 * component.ioffset.X; component.offset.Y = Parent.Size.Y / 100 * component.ioffset.Y; if (component.Init == false) { string[] itemText = new string[0]; string[] actions = new string[0]; // Displays player's attacks if (component.ListContentType == "PlayerAttacks") { itemText = new string[GameHandler.Player.AvailableAttacks.Count]; actions = new string[GameHandler.Player.AvailableAttacks.Count]; for (int i = 0; i < itemText.Length; i++) { itemText[i] = GameHandler.Player.AvailableAttacks[i].Name; actions[i] = "PlayerUse" + GameHandler.Player.AvailableAttacks[i].Name; } } // Displays player's traits if (component.ListContentType == "PlayerTraits") { // -- DISPLAY TRAITS HERE \\ itemText = new string[GameHandler.Player.Dominant.NumberOfActiveTraits()]; actions = new string[itemText.Length]; int currentTrait = 0; if (GameHandler.Player.Dominant.Head.Active) { itemText[currentTrait] = "Head"; currentTrait++; } if (GameHandler.Player.Dominant.Legs.Active) { itemText[currentTrait] = "Legs"; currentTrait++; } if (GameHandler.Player.Dominant.Arms.Active) { itemText[currentTrait] = "Arms"; currentTrait++; } if (GameHandler.Player.Dominant.Wings.Active) { itemText[currentTrait] = "Wings"; currentTrait++; } if (GameHandler.Player.Dominant.Claws.Active) { itemText[currentTrait] = "Claws"; currentTrait++; } if(GameHandler.Player.Dominant.TailColumns.Level >= 0) { itemText[currentTrait] = "Tail"; currentTrait++; } } // Displays player's owned DNA if (component.ListContentType == "PlayerDNAInventory") { itemText = new string[GameHandler.Inventory.DNA.Count]; actions = new string[GameHandler.Inventory.DNA.Count]; for (int i = 0; i < itemText.Length; i++) { itemText[i] = Convert.ToString(i+1); actions[i] = Convert.ToString(GameHandler.Inventory.DNA[i].ID); } } // Displays currently selected DNA's traits if (component.ListContentType == "SelectedDNATraits") { if (GameHandler.Inventory.SelectedDNA != null) { // -- DISPLAY SELECTED CREATURE'S TRAITS HERE -- \\ itemText = new string[GameHandler.Inventory.SelectedDNA.Dominant.NumberOfActiveTraits()]; actions = new string[itemText.Length]; int currentTrait = 0; if (GameHandler.Inventory.SelectedDNA.Dominant.Head.Active) { itemText[currentTrait] = "Head"; currentTrait++; } if (GameHandler.Inventory.SelectedDNA.Dominant.Legs.Active) { itemText[currentTrait] = "Legs"; currentTrait++; } if (GameHandler.Inventory.SelectedDNA.Dominant.Arms.Active) { itemText[currentTrait] = "Arms"; currentTrait++; } if (GameHandler.Inventory.SelectedDNA.Dominant.Wings.Active) { itemText[currentTrait] = "Wings"; currentTrait++; } if (GameHandler.Inventory.SelectedDNA.Dominant.Claws.Active) { itemText[currentTrait] = "Claws"; currentTrait++; } if(GameHandler.Inventory.SelectedDNA.Dominant.TailColumns.Level >= 0) { itemText[currentTrait] = "Tail"; currentTrait++; } } } // The following will render the text to their own individual textures with bounding rects component.Items = new ListBox.Item[itemText.Length]; for (int i = 0; i < component.Items.Length; i++) { // Create RenderTarget of correct size RenderListTextToTexture(component, i, itemText[i]); component.Items[i].Text = itemText[i]; // Set Inividual element's offset component.Items[i].offset = new Vector2(0, i > 0 ? component.Items[i - 1].Texture.Height*i : 0); // Set component's Action component.Items[i].Action = actions[i]; } component.currentOffset = Vector2.Zero; } component.Init = true; Vector2 off = component.offset; component.BoundingRect = new Rectangle((int)Parent.Position.X + (int)off.X, (int)Parent.Position.Y + (int)off.Y, (int)Parent.Size.X, (int)Parent.Size.Y); // Get Height of the text in the list float textHeight = 0.0f; for (int i = 0; i < component.Items.Length; i++) textHeight += component.Items[i].Texture.Height; // Modify Current Offset to ensure within the box if (textHeight > component.BoundingRect.Height) { float maxY = (Parent.Position.Y - (Parent.Size.Y / 2)); float minY = (Parent.Position.Y + component.BoundingRect.Height - (Parent.Size.Y / 2)) - textHeight; if (component.currentOffset.Y > maxY) component.currentOffset.Y = maxY; else if (component.currentOffset.Y < minY) component.currentOffset.Y = minY; DrawGraphicComponent(component.UpScroller, ref parent); DrawGraphicComponent(component.DownScroller, ref parent); } // Set Scissor rectangle Rectangle currentRect = SpriteManager.ScissorRectangle; SpriteManager.ScissorRectangle = component.BoundingRect; // Draw List for (int i = 0; i < component.Items.Length; i++) { SpriteManager.Draw(component.Items[i].Texture, Parent.Position + off + component.Items[i].offset + component.currentOffset, new Color(component.fontColor)); component.Items[i].Update(Parent.Position + off + component.Items[i].offset + component.currentOffset); } // Revert Scissor Rectangle SpriteManager.ScissorRectangle = currentRect; }
private void DrawComponent(List<Object2D> children, ref Object2D parent) { foreach (Object2D thing in children) { DrawComponent(thing, ref parent); } }
private void DrawComponent(Object2D component, ref Object2D parent) { if (component.GetType() == typeof(GraphicObject)) { DrawGraphicComponent((component as GraphicObject), ref parent); } else if (component.GetType() == typeof(MinimapObject)) { DrawMinimapObject((component as MinimapObject), ref parent); } else if (component.GetType() == typeof(TextObject)) { if (parent.GetType() == typeof(GraphicObject)) DrawTextComponent((component as TextObject), (parent as GraphicObject)); } else if (component.GetType() == typeof(TextBoxObject)) { if(parent.GetType() == typeof(GraphicObject)) DrawTextBoxComponent((component as TextBoxObject), (parent as GraphicObject)); } else if (component.GetType() == typeof(ListBox)) { if(parent.GetType() == typeof(GraphicObject)) DrawListBox((component as ListBox), (parent as GraphicObject)); } else if (component.GetType() == typeof(AnimatedObject)) { if(parent.GetType() == typeof(GraphicObject)) DrawAnimatedObject((component as AnimatedObject), (parent as GraphicObject)); } if(component.GetType() == typeof(GraphicObject)) DrawComponent((component as GraphicObject).Children, ref component); }
private void DrawComponent(List<Object2D> Interface) { Object2D sam = new Object2D(); foreach (Object2D thing in Interface) { DrawComponent(thing, ref sam); } }
private void UpdateComponent(Object2D component, GameTime gameTime) { if (component.GetType() == typeof(GraphicObject) || component.GetType() == typeof(Scroller)) { UpdateComponent((component as GraphicObject).Children, gameTime); if ((component as GraphicObject).isClickable) ClickableComponent((component as GraphicObject)); } if (component.GetType() == typeof(AnimatedObject)) UpdateAnimation((component as AnimatedObject), gameTime); }
private void ResetListBox(Object2D component) { List<Object2D> list = new List<Object2D>(); list.Add(component); ResetListBoxes(list); }