コード例 #1
0
ファイル: Interface.cs プロジェクト: hkeeble/GroupProject
        private void UpdateListBox(ListBox component)
        {
            float textHeight = 0f;
            for (int i = 0; i < component.Items.Length; i++)
                textHeight += component.Items[i].Texture.Height;

            if (textHeight > component.BoundingRect.Height)
            {
                Rectangle UpRect = new Rectangle((int)component.UpScroller.Position.X, (int)component.UpScroller.Position.Y,
                    (int)component.UpScroller.Size.X, (int)component.UpScroller.Size.Y);
                Rectangle DownRect = new Rectangle((int)component.DownScroller.Position.X, (int)component.DownScroller.Position.Y,
                    (int)component.DownScroller.Size.X, (int)component.DownScroller.Size.Y);

                // Update Scrollers
                if (InputHandler.LeftClickDown)
                {
                    if (UpRect.Contains(InputHandler.MouseX, InputHandler.MouseY))
                        component.Scroll(component.UpScroller.scrollDirection);
                    if (DownRect.Contains(InputHandler.MouseX, InputHandler.MouseY))
                        component.Scroll(component.DownScroller.scrollDirection);
                }
            }

            if (component.isClickable)
            {
                // Update Items
                if (InputHandler.LeftClickPressed)
                {
                    for (int i = 0; i < component.Items.Length; i++)
                    {
                        if (component.Items[i].BoundingRect.Contains(InputHandler.MouseX, InputHandler.MouseY))
                        {
                            #region PlayerDNAInventory Actions
                            if (component.ListContentType == "PlayerDNAInventory")
                            {
                                GameHandler.Inventory.SetDNA(i);
                                ResetListBoxes(subMenu.content);
                            }
                            #endregion
                            if (currentScreen == Screens.Battle)
                            {
                                if (BattleHandler.CanSelectAction)
                                {
                                    BattleHandler.ActionSelected = true;
                                    BattleHandler.AttackSelection = i;
                                    BattleHandler.PlayerActionType = BattleHandler.ActionType.Attack;
                                }
                            }
                            // Add if statements for other list actions here
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Interface.cs プロジェクト: hkeeble/GroupProject
        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;
        }
コード例 #3
0
ファイル: Interface.cs プロジェクト: hkeeble/GroupProject
        private void RenderListTextToTexture(ListBox component, int itemIndex, string text)
        {
            SpriteFont font = Game.Content.Load<SpriteFont>(component.Font);

            RenderTarget2D target = new RenderTarget2D(Configuration.GraphicsDevice, (int)font.MeasureString(text).X,
                                                (int)font.MeasureString(text).Y, false, Configuration.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24);
            component.Items[itemIndex] = new ListBox.Item();

            // Render string to RenderTarget
            Configuration.GraphicsDevice.SetRenderTarget(target);
            Configuration.GraphicsDevice.Clear(Color.Transparent);
            SpriteManager.End();
            SpriteManager.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
            SpriteManager.DrawString(font, text, Vector2.Zero, new Color(component.fontColor));
            SpriteManager.End();
            SpriteManager.Begin();
            Configuration.GraphicsDevice.SetRenderTarget(null);

            // Move RenderTarget data to Texture2D
            Color[] data = new Color[target.Width * target.Height];
            Texture2D temp = new Texture2D(Configuration.GraphicsDevice, target.Width, target.Height);
            target.GetData<Color>(data);
            temp.SetData<Color>(data);
            component.Items[itemIndex].Texture = temp;
            target.Dispose();
        }