Пример #1
0
        private void useSizeForObject()
        {
            GUILabel s_label = new GUILabel(Game, new Vector2(10, 100), "s_label", "Dimensions : ");

            s_label.Initialize();
            AddComponent(s_label);

            GUIEditBox s_width = new GUIEditBox(Game, new Vector2(100, 100), "s_width", 50, Dimensions.X.ToString());

            s_width.Initialize();
            AddComponent(s_width);

            GUIEditBox s_height = new GUIEditBox(Game, new Vector2(160, 100), "s_height", 50, Dimensions.Y.ToString());

            s_height.Initialize();
            AddComponent(s_height);
        }
Пример #2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            // TODO: Add your initialization code here
            batch     = new SpriteBatch(Game.GraphicsDevice);
            font      = Game.Content.Load <SpriteFont>(@"Fonts\Console");
            primBatch = new PrimitiveBatch(Game.GraphicsDevice);

            // Set up visible items
            if (numItems > Items.Count)
            {
                numItems = Items.Count;
            }


            // Initialise the buttons
            foreach (GUIListBoxItem lbi in Items)
            {
                lbi.Initialize();
                lbi.Parent = this;

                if (font.MeasureString(lbi.Name).X > maxWidth)
                {
                    maxWidth = font.MeasureString(lbi.Name).X;
                }
                lbi.OnMouseClick += new GUIListBoxItem.MouseClickHandler(SelectItem);
            }

            maxWidth += 20;

            foreach (GUIListBoxItem lbi in Items)
            {
                lbi.boxDimensions.X = maxWidth;
            }

            // And set the initial locations
            UpdateList();

            components = new List <GUIComponent>();

            // Get width of the listbox
            float boxHeight = (numItems - 1) * Items[0].Bounds.Height;

            // Display Down button
            DownButton = new GUIButton(Game, new Vector2(maxWidth, boxHeight + 20), new Vector2(20, 20), "down", "+");
            DownButton.Initialize();
            DownButton.OnMouseClick += new GUIButton.MouseClickHandler(ScrollDown);
            DownButton.UpdateLocation(DownButton.Location + new Vector2(Location.X, Location.Y));
            components.Add(DownButton);

            // Display Up button
            UpButton = new GUIButton(Game, new Vector2(maxWidth, 20), new Vector2(20, 20), "up", "-");
            UpButton.Initialize();
            UpButton.OnMouseClick += new GUIButton.MouseClickHandler(ScrollUp);
            UpButton.UpdateLocation(UpButton.Location + new Vector2(Location.X, Location.Y));
            components.Add(UpButton);

            // Calculate bar intervals
            barIntervals = ((boxHeight - 20) / Items.Count);

            PosBar = new GUIButton(Game, new Vector2(maxWidth, 40), new Vector2(20, barIntervals * numItems), "bar", "");
            PosBar.BackgroundColor = HighlightColor;
            PosBar.AllowHold       = true;
            PosBar.Initialize();
            PosBar.OnMouseHold += new GUIButton.MouseClickHandler(DragScroll);
            PosBar.UpdateLocation(PosBar.Location + new Vector2(Location.X, Location.Y));
            components.Add(PosBar);

            currentItem = new GUILabel(Game, new Vector2(0, 0), new Vector2(maxWidth, 20), "label", "Select ...");
            currentItem.Initialize();
            currentItem.BackgroundColor = Color.AntiqueWhite;
            currentItem.UpdateLocation(currentItem.Location + new Vector2(Location.X, Location.Y));
            components.Add(currentItem);

            OpenCloseList = new GUIButton(Game, new Vector2(maxWidth, 0), new Vector2(20, 20), "openclose", "+");
            OpenCloseList.Initialize();
            OpenCloseList.OnMouseClick += new GUIButton.MouseClickHandler(OCList);
            OpenCloseList.UpdateLocation(OpenCloseList.Location + new Vector2(Location.X, Location.Y));
            components.Add(OpenCloseList);
        }
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            GUILabel label = new GUILabel(Game, new Vector2(10, 10), "lblOpen", "Filename:");

            label.Initialize();
            AddComponent(label);
            //GUIEditBox edit = new GUIEditBox(Game, new Vector2(100, 10), "edtOpen", 300, "");
            //edit.Initialize();
            //AddComponent(edit);
            GUIButton ok = new GUIButton(Game, new Vector2(480, 50), "okbutton", "Ok");

            ok.Initialize();
            ok.OnMouseClick += new GUIButton.MouseClickHandler(OkMouseClick);
            AddComponent(ok);
            GUIButton cancel = new GUIButton(Game, new Vector2(520, 50), "cancelbutton", "Cancel");

            cancel.Initialize();
            cancel.OnMouseClick += new GUIButton.MouseClickHandler(CancelMouseClick);
            AddComponent(cancel);

            GUICheckbox isphys = new GUICheckbox(Game, new Vector2(100, 50), "isphys", "Generate Collision Mesh");

            isphys.Initialize();
            AddComponent(isphys);

            GUILabel bouncylbl = new GUILabel(Game, new Vector2(10, 90), "lblBounce", "Bounciness");

            bouncylbl.Initialize();
            AddComponent(bouncylbl);

            GUIEditBox bouncy = new GUIEditBox(Game, new Vector2(100, 90), "edtBouncy", 50, "500");

            bouncy.Initialize();
            AddComponent(bouncy);

            GUILabel frictionlbl = new GUILabel(Game, new Vector2(10, 120), "lblFriction", "Friction");

            frictionlbl.Initialize();
            AddComponent(frictionlbl);

            GUIEditBox friction = new GUIEditBox(Game, new Vector2(100, 120), "edtFriction", 50, "500");

            friction.Initialize();
            AddComponent(friction);


            // Add List Box
            List <GUIListBoxItem> guiListItems = new List <GUIListBoxItem>();

            string[] filenames = Directory.GetFiles("Content\\LevelArt");

            for (int i = 0; i < filenames.Length; i++)
            {
                string shortName = (string)filenames[i].Substring(17);
                guiListItems.Add(new GUIListBoxItem(Game, filenames[i], shortName));
            }

            fileList = new GUIListBox(Game, new Vector2(100, 10), "list box", guiListItems);
            fileList.Initialize();
            AddComponent(fileList);
        }
Пример #4
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            this.minimised = false;
            base.Initialize();
            GUILabel label = new GUILabel(Game, new Vector2(10, 10), "physobjname", "Texture:");

            label.Initialize();
            AddComponent(label);

            // Use Texture
            List <GUIListBoxItem> guiListItems = new List <GUIListBoxItem>();

            string[] filenames = Directory.GetFiles("Content\\LevelArt");

            for (int i = 0; i < filenames.Length; i++)
            {
                string shortName = (string)filenames[i].Substring(17);
                guiListItems.Add(new GUIListBoxItem(Game, filenames[i], shortName));
            }

            fileList = new GUIListBox(Game, new Vector2(10, 30), "list box", guiListItems);
            fileList.Initialize();


            GUILabel weightlbl = new GUILabel(Game, new Vector2(10, 60), "lblMass", "Mass");

            weightlbl.Initialize();
            AddComponent(weightlbl);

            GUIEditBox weight = new GUIEditBox(Game, new Vector2(100, 60), "edtMass", 50, "10");

            weight.Initialize();
            AddComponent(weight);

            GUILabel bouncylbl = new GUILabel(Game, new Vector2(10, 90), "lblBounce", "Bounciness");

            bouncylbl.Initialize();
            AddComponent(bouncylbl);

            GUIEditBox bouncy = new GUIEditBox(Game, new Vector2(100, 90), "edtBouncy", 50, "500");

            bouncy.Initialize();
            AddComponent(bouncy);

            GUILabel frictionlbl = new GUILabel(Game, new Vector2(10, 120), "lblFriction", "Friction");

            frictionlbl.Initialize();
            AddComponent(frictionlbl);

            GUIEditBox friction = new GUIEditBox(Game, new Vector2(100, 120), "edtFriction", 50, "500");

            friction.Initialize();
            AddComponent(friction);

            GUIButton ok = new GUIButton(Game, new Vector2(150, 375), "okbutton", "Apply");

            ok.Initialize();
            ok.OnMouseClick += new GUIButton.MouseClickHandler(OkMouseClick);
            ok.Location.X   -= ok.Bounds.Width / 2;
            AddComponent(ok);
            GUIButton cancel = new GUIButton(Game, new Vector2(200, 375), "cancelbutton", "Cancel");

            cancel.Initialize();
            cancel.OnMouseClick += new GUIButton.MouseClickHandler(CancelMouseClick);
            cancel.Location.X   -= cancel.Bounds.Width / 2;
            AddComponent(cancel);

            AddComponent(fileList);
        }