Example #1
0
        public void TestNoRecursion()
        {
            var control1 = new Control();
            var control2 = new Control();
            var control3 = new Control();

            control1.AddChild(control2);
            // Test direct parent/child.
            Assert.That(() => control2.AddChild(control1), Throws.ArgumentException);

            control2.AddChild(control3);
            // Test grand child.
            Assert.That(() => control3.AddChild(control1), Throws.ArgumentException);
        }
        public void TestVisibleInTree()
        {
            var control1 = new Control();

            // Not visible because not parented to root control.
            Assert.That(control1.Visible, Is.True);
            Assert.That(control1.VisibleInTree, Is.False);

            control1.UserInterfaceManager.RootControl.AddChild(control1);
            Assert.That(control1.Visible, Is.True);
            Assert.That(control1.VisibleInTree, Is.True);

            control1.Visible = false;
            Assert.That(control1.Visible, Is.False);
            Assert.That(control1.VisibleInTree, Is.False);
            control1.Visible = true;

            var control2 = new Control();

            Assert.That(control2.VisibleInTree, Is.False);

            control1.AddChild(control2);
            Assert.That(control2.VisibleInTree, Is.True);

            control1.Visible = false;
            Assert.That(control2.VisibleInTree, Is.False);

            control2.Visible = false;
            Assert.That(control2.VisibleInTree, Is.False);

            control1.Visible = true;
            Assert.That(control2.VisibleInTree, Is.False);

            control1.Dispose();
        }
Example #3
0
        public virtual void DrawInterface(Control parent)
        {
            Label label = new Label();

            parent.AddChild(label);
            label.Text = "Add the module properties here";
        }
        private void LoadCurrentExample()
        {
            var scene = sceneLoader.GetCurrentSample();

            if (scene == null)
            {
                return;
            }

            foreach (Node child in CurrentSceneContainer.GetChildren())
            {
                child.QueueFree();
            }

            var instance = scene.Instance();

            CurrentSceneContainer.AddChild(instance);

            // Show code
            var    script     = (CSharpScript)instance.GetScript();
            string scriptPath = script.ResourcePath;

            CodeLabel.BbcodeEnabled = true;
            CodeLabel.BbcodeText    = ReadSourceCodeAtPath(scriptPath);
            CodeLabel.ScrollToLine(0);

            // Set summary
            if (instance is Examples.IExample baseInstance)
            {
                SummaryLabel.Text = baseInstance.GetSummary();
            }
        }
Example #5
0
        public void VerifyCandidateChosenWhenDescendant()
        {
            var element   = new Control();
            var candidate = new Control();
            var parent    = new Control();
            var directionOverrideOfParent = new Control();

            parent.AddChild(element);
            parent.AddChild(candidate);

            parent.SetValue(UIElement.XYFocusRightProperty, directionOverrideOfParent);

            DependencyObject?retrievedElement = TryXYFocusBubble(element, candidate, null, FocusNavigationDirection.Right);

            VerifyAreEqual(retrievedElement, candidate);
        }
Example #6
0
    public void OpenPopup()
    {
        var popup = new AcceptDialog();

        popup.SizeFlagsHorizontal = (int)Control.SizeFlags.ExpandFill;
        popup.SizeFlagsVertical   = (int)Control.SizeFlags.ExpandFill;
        popup.PopupExclusive      = true;
        popup.WindowTitle         = "Configure snap";
        var container = new VBoxContainer();
        var snapSpin  = new SpinBox();

        snapSpin.MinValue = 0;
        snapSpin.MaxValue = 99;
        snapSpin.Step     = 0.0001f;
        snapSpin.Value    = snapLength;
        snapSpin.Connect("value_changed", this, "SetSnapLength");
        var snapHBox  = new HBoxContainer();
        var snapLabel = new Label();

        snapLabel.Text = "Snap length";
        snapHBox.AddChild(snapLabel);
        snapHBox.AddChild(snapSpin);
        container.AddChild(snapHBox);
        popup.AddChild(container);

        popup.Connect("popup_hide", popup, "queue_free");
        baseControl.AddChild(popup);

        popup.PopupCentered(new Vector2(200, 100));
    }
        public void TestLayoutSet()
        {
            var control = new Control {
                Size = new Vector2(100, 100)
            };
            var child = new Control();

            control.AddChild(child);
            control.ForceRunLayoutUpdate();

            Assert.That(child.Position, Is.EqualTo(Vector2.Zero));
            Assert.That(child.Size, Is.EqualTo(Vector2.Zero));

            child.Size = new Vector2(50, 50);
            Assert.That(child.Size, Is.EqualTo(new Vector2(50, 50)));
            Assert.That(child.Position, Is.EqualTo(Vector2.Zero));

            Assert.That(child.MarginTop, Is.EqualTo(0));
            Assert.That(child.MarginLeft, Is.EqualTo(0));
            Assert.That(child.MarginRight, Is.EqualTo(50));
            Assert.That(child.MarginBottom, Is.EqualTo(50));

            child.Position = new Vector2(50, 50);
            Assert.That(child.Size, Is.EqualTo(new Vector2(50, 50)));
            Assert.That(child.Position, Is.EqualTo(new Vector2(50, 50)));

            Assert.That(child.MarginTop, Is.EqualTo(50));
            Assert.That(child.MarginLeft, Is.EqualTo(50));
            Assert.That(child.MarginRight, Is.EqualTo(100));
            Assert.That(child.MarginBottom, Is.EqualTo(100));
        }
    void InitializeKeybindings()
    {
        foreach (Node node in buttonContainer.GetChildren())
        {
            node.QueueFree();
        }

        foreach (string action in InputMap.GetActions())
        {
            if (SkipUiActions && action.StartsWith("ui_"))
            {
                continue;
            }
            if (SkipDebugActions && action.StartsWith("debug_"))
            {
                continue;
            }

            KeybindingElement element = (KeybindingElement)keybindingElement.Instance();
            buttonContainer.AddChild(element);
            element.Action = action;

            foreach (InputEvent _event in InputMap.GetActionList(action))
            {
                if (_event.MatchInputMethod(CurrentInputMethod))
                {
                    element.InputEvent = _event;
                    break;
                }
                //Debug
            }
            element.ConnectPressed(this, nameof(GetNewInput), element.Action.InArray());
        }
    }
Example #9
0
        private void NewControl()
        {
            if (m_root != null)
            {
                if (!EditorUtility.DisplayDialog("Confirm New Control", "Are you sure you would like to create a new control? Current layout will be discarded!", "Ok", "Cancel"))
                {
                    return;
                }

                foreach (Control child in m_root.Children)
                {
                    RemoveChildControl(child);
                }

                m_workarea.RemoveChild(m_root);
                RemoveHierarchyEntry(m_root);
            }

            m_root = new Control();

            m_root.SetSize(100.0f, 100.0f);
            m_root.SetPosition(m_workarea.Size.x / 2.0f - 50.0f, m_workarea.Size.y / 2.0f - 50.0f);
            m_root.AddDecorator(new BackgroundColor(Color.gray));

            m_workarea.AddChild(m_root);
            SetSelectedControl(m_root);
            SetInspectorTarget(m_root);

            CreateHierarchyEntry(m_root, 0);
        }
Example #10
0
    public Sprite AddMarker(MinimapIconType iconType)
    {
        Sprite newMarker = (Sprite)icons[iconType].Duplicate();

        Markers.AddChild(newMarker);
        newMarker.Show();
        return(newMarker);
    }
        static public Label NewAttachedLabel(string name, Control parent)
        {
            Label newLabel = new Label();

            newLabel.Text = name;
            newLabel.SizeFlagsVertical = (int)SizeFlags.ExpandFill;
            parent.AddChild(newLabel);
            return(newLabel);
        }
Example #12
0
        /// <summary>
        /// Adds a child to the control list.
        /// </summary>
        /// <param name="control">Control object to add.</param>
        /// <returns>The method returns the control that was added.</returns>
        public Control AddChild(Control control)
        {
            if (m_rootObject != null)
            {
                m_rootObject.AddChild(control);
            }

            return(control);
        }
        public void NewResults(Control f, string label, Label rh, ref Vector2 elementPosition)
        {
            var tb = new Label
            {
                AutoSize   = AutoSizeMode.Full,
                Size       = new Vector2(150f, descriptionTextBoxHeight),
                Text       = label,
                Background = null,
                Position   = elementPosition,
            };

            f.AddChild(tb);

            rh.Position = elementPosition + new Vector2(250, 0);
            f.AddChild(rh);

            elementPosition.Y += System.Math.Max(tb.Size.Y, rh.Size.Y);
        }
Example #14
0
 public void AddChildControl(Type controlType)
 {
     if (m_root != null)
     {
         Control control = ( Control )Activator.CreateInstance(controlType);
         m_root.AddChild(control);
         CreateHierarchyEntry(control, 1);
     }
 }
Example #15
0
 private void LoadAllYokai()
 {
     containerField.QueueFreeChildren();
     for (YokaiId yokai = YokaiId.Hitotsumekozo; yokai != YokaiId.TOTAL; yokai++)
     {
         WantedTable wanted = WantedTable.Instance();
         containerField.AddChild(wanted);
         wanted.Load(yokai.Data());
     }
 }
Example #16
0
 public void createElements()
 {
     foreach (int idlevel in sel_levels)
     {
         Control element = create_Element(idlevel);
         element.RectPosition = new Vector2(100 + nb_bt_placed * size_element, 0);
         nb_bt_placed++;
         container.AddChild(element);
     }
 }
Example #17
0
 public void createElements()
 {
     for (int idcat = 0; idcat < sel_levels.Count; idcat++)
     {
         Control element = create_Element(idcat);
         element.RectPosition = new Vector2(100 + nb_bt_placed * size_element, 0);
         nb_bt_placed++;
         container.AddChild(element);
     }
     globale.affNode(container, 0);
 }
Example #18
0
    public void ItemButtonReleased()
    {
        if (_inventory.SelectedItemId < 0)
        {
            return;
        }

        Item.ItemStack selectedItemStack = _itemList[_inventory.SelectedItemId];

        if (_alchemyStage == AlchemyStage.MortarPestle && _mortarPestleStage == MortarPestleStage.PickReagents && _potionReagents.Count < 4)
        {
            if (selectedItemStack.stackCount > 1)
            {
                _itemList[_inventory.SelectedItemId] = Item.DecreaseItemStackCount(selectedItemStack, 1);
            }
            else
            {
                _itemList.RemoveAt(_inventory.SelectedItemId);
            }

            _inventory.Update();

            HBoxContainer itemInfo = new HBoxContainer();
            itemInfo.Set("custom_constants/separation", 10f);

            Control itemIcon = new Control();
            itemIcon.RectMinSize = new Vector2(16f, 16f);

            Sprite itemBG = new Sprite();
            itemBG.Texture  = _singleItemSlot;
            itemBG.Centered = false;

            Sprite itemSprite = new Sprite();
            itemSprite.Texture  = selectedItemStack.item.IconTex;
            itemSprite.Centered = false;
            itemSprite.Position = new Vector2(2f, 2f);
            itemBG.AddChild(itemSprite);
            itemIcon.AddChild(itemBG);
            itemInfo.AddChild(itemIcon);

            Label itemName = new Label();
            itemName.Text = selectedItemStack.item.Name;
            itemName.AddFontOverride("font", _smallFont);
            itemName.MarginLeft = 4f;
            itemInfo.AddChild(itemName);

            _potionReagentsBox.AddChild(itemInfo);

            _potionReagents.Add(selectedItemStack.item);
            _proceedToCrush.Disabled = false;
        }

        GD.Print("Selected: " + selectedItemStack.item.Name);
    }
Example #19
0
            protected override void Initialize()
            {
                base.Initialize();

                ActualButton = new Button("Button")
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand,
                    SizeFlagsVertical   = SizeFlags.FillExpand,
                    ToggleMode          = true,
                    MouseFilter         = MouseFilterMode.Stop
                };
                AddChild(ActualButton);

                var hBoxContainer = new HBoxContainer("HBoxContainer")
                {
                    MouseFilter = MouseFilterMode.Ignore
                };

                EntitySpriteView = new SpriteView("SpriteView")
                {
                    CustomMinimumSize = new Vector2(32.0f, 32.0f), MouseFilter = MouseFilterMode.Ignore
                };
                EntityName = new Label("Name")
                {
                    SizeFlagsVertical = SizeFlags.ShrinkCenter,
                    Text        = "Backpack",
                    MouseFilter = MouseFilterMode.Ignore
                };
                hBoxContainer.AddChild(EntitySpriteView);
                hBoxContainer.AddChild(EntityName);

                EntityControl = new Control("Control")
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand, MouseFilter = MouseFilterMode.Ignore
                };
                EntitySize = new Label("Size")
                {
                    SizeFlagsVertical = SizeFlags.ShrinkCenter,
                    Text         = "Size 6",
                    Align        = Label.AlignMode.Right,
                    AnchorLeft   = 1.0f,
                    AnchorRight  = 1.0f,
                    AnchorBottom = 0.5f,
                    AnchorTop    = 0.5f,
                    MarginLeft   = -38.0f,
                    MarginTop    = -7.0f,
                    MarginRight  = -5.0f,
                    MarginBottom = 7.0f
                };

                EntityControl.AddChild(EntitySize);
                hBoxContainer.AddChild(EntityControl);
                AddChild(hBoxContainer);
            }
Example #20
0
        private void CreateHierarchyEntry(Control control, int level)
        {
            HierarchyItem item = new HierarchyItem(control, level);

            m_hierarchyItems.Add(control, item);

            item.BoundControlSelected    += item_BoundControlSelected;
            item.BoundDecoratorlSelected += item_BoundDecoratorlSelected;

            m_hierarchy.AddChild(item);
        }
Example #21
0
    public Control create_Element(int idl)
    {
        //on crée l'element
        Control element = new Control();

        element.Name = "element-" + globale.levels_names[idl];
        //on crée le bouton pour acceder au level
        if (globale.levels_finis[idl])
        {
            PackedScene packedScene = (PackedScene)ResourceLoader.Load("res://menus/buttons/Bt_Cube_Finished.tscn");
            Bt_Cube     button      = (Bt_Cube)packedScene.Instance();
            button.texte = globale.levels_names[idl];
            button.id    = idl;
            button.Connect("cliqued", this, nameof(on_level_pressed));
            element.AddChild(button);
        }
        else
        {
            if (globale.levels_requirements[idl] == -1 || globale.levels_finis[globale.levels_requirements[idl]])
            {
                PackedScene packedScene = (PackedScene)ResourceLoader.Load("res://menus/buttons/Bt_Cube_Base.tscn");
                Bt_Cube     button      = (Bt_Cube)packedScene.Instance();
                button.texte = globale.levels_names[idl];
                button.id    = idl;
                button.Connect("cliqued", this, nameof(on_level_pressed));
                element.AddChild(button);
            }
            else
            {
                PackedScene packedScene = (PackedScene)ResourceLoader.Load("res://menus/buttons/Bt_Cube_Locked.tscn");
                Bt_Cube     button      = (Bt_Cube)packedScene.Instance();
                button.texte = globale.levels_names[idl];
                button.id    = idl;
                button.Connect("cliqued", this, nameof(on_level_pressed));
                element.AddChild(button);
            }
        }

        //on le retourne
        return(element);
    }
Example #22
0
        private void BuildEntityList(string searchStr = null)
        {
            PrototypeList.DisposeAllChildren();
            SelectedButton = null;
            searchStr      = searchStr?.ToLowerInvariant();

            var prototypes = new List <EntityPrototype>();

            foreach (var prototype in prototypeManager.EnumeratePrototypes <EntityPrototype>())
            {
                if (prototype.Abstract)
                {
                    continue;
                }

                if (searchStr != null && !_doesPrototypeMatchSearch(prototype, searchStr))
                {
                    continue;
                }

                prototypes.Add(prototype);
            }

            prototypes.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));

            foreach (var prototype in prototypes)
            {
                var button = new EntitySpawnButton()
                {
                    Prototype = prototype,
                };
                var container = button.GetChild("HBoxContainer");
                button.ActualButton.OnToggled           += OnItemButtonToggled;
                container.GetChild <Label>("Label").Text = prototype.Name;

                var tex  = IconComponent.GetPrototypeIcon(prototype);
                var rect = container.GetChild("TextureWrap").GetChild <TextureRect>("TextureRect");
                if (tex != null)
                {
                    rect.Texture = tex.Default;
                    // Ok I can't find a way to make this TextureRect scale down sanely so let's do this.
                    var scale = (float)TARGET_ICON_HEIGHT / tex.Default.Height;
                    rect.Scale = new Vector2(scale, scale);
                }
                else
                {
                    rect.Dispose();
                }

                PrototypeList.AddChild(button);
            }
        }
            public EntityButton()
            {
                ActualButton = new Button
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand,
                    SizeFlagsVertical   = SizeFlags.FillExpand,
                    ToggleMode          = true,
                    MouseFilter         = MouseFilterMode.Stop
                };
                AddChild(ActualButton);

                var hBoxContainer = new HBoxContainer {
                    MouseFilter = MouseFilterMode.Ignore
                };

                EntitySpriteView = new SpriteView
                {
                    CustomMinimumSize = new Vector2(32.0f, 32.0f), MouseFilter = MouseFilterMode.Ignore
                };
                EntityName = new Label
                {
                    SizeFlagsVertical = SizeFlags.ShrinkCenter,
                    Text        = "Backpack",
                    MouseFilter = MouseFilterMode.Ignore
                };
                hBoxContainer.AddChild(EntitySpriteView);
                hBoxContainer.AddChild(EntityName);

                EntityControl = new Control
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand, MouseFilter = MouseFilterMode.Ignore
                };
                EntitySize = new Label
                {
                    SizeFlagsVertical = SizeFlags.ShrinkCenter,
                    Text  = "Size 6",
                    Align = Label.AlignMode.Right,

                    /*AnchorLeft = 1.0f,
                     * AnchorRight = 1.0f,
                     * AnchorBottom = 0.5f,
                     * AnchorTop = 0.5f,
                     * MarginLeft = -38.0f,
                     * MarginTop = -7.0f,
                     * MarginRight = -5.0f,
                     * MarginBottom = 7.0f*/
                };

                EntityControl.AddChild(EntitySize);
                hBoxContainer.AddChild(EntityControl);
                AddChild(hBoxContainer);
            }
Example #24
0
        public void TestStylesheetOverride()
        {
            var sheetA = new Stylesheet(new[]
            {
                new StyleRule(SelectorElement.Class("A"), new[] { new StyleProperty("foo", "bar") }),
            });

            var sheetB = new Stylesheet(new[]
            {
                new StyleRule(SelectorElement.Class("A"), new[] { new StyleProperty("foo", "honk!") })
            });

            // Set style sheet to null, property shouldn't exist.

            var uiMgr = IoCManager.Resolve <IUserInterfaceManager>();

            uiMgr.Stylesheet = null;

            var baseControl = new Control();

            baseControl.AddStyleClass("A");
            var childA = new Control();

            childA.AddStyleClass("A");
            var childB = new Control();

            childB.AddStyleClass("A");

            uiMgr.StateRoot.AddChild(baseControl);

            baseControl.AddChild(childA);
            childA.AddChild(childB);

            baseControl.ForceRunStyleUpdate();

            Assert.That(baseControl.TryGetStyleProperty("foo", out object?_), Is.False);

            uiMgr.RootControl.Stylesheet = sheetA;
            childA.Stylesheet            = sheetB;

            // Assign sheets.
            baseControl.ForceRunStyleUpdate();

            baseControl.TryGetStyleProperty("foo", out object?value);
            Assert.That(value, Is.EqualTo("bar"));

            childA.TryGetStyleProperty("foo", out value);
            Assert.That(value, Is.EqualTo("honk!"));

            childB.TryGetStyleProperty("foo", out value);
            Assert.That(value, Is.EqualTo("honk!"));
        }
Example #25
0
    private void SetDescription(Item.Type type)
    {
        imageDesc.Texture    = Item.textures[(int)type];
        titleDesc.Text       = type.ToString();
        energyDesc.Text      = "-> " + infirmary.energy2heal + "e";
        descriptionDesc.Text = "Health : +" + Item.healingPower[type];
        ClearItemsList();
        Control it = (Control)itemBox.Instance();

        it.GetNode <TextureRect>("img").Texture = Item.textures[(int)type];
        it.GetNode <Label>("texte").Text        = Player.inventoryItems.GetItemCount(type) + "/ 1";
        itemListDesc.AddChild(it);
    }
Example #26
0
        private static Button AddButton(string text, Control parent, DebugMenuAction action)
        {
            Button btn = new Button();

            btn.Text = text;
            btn.SizeFlagsHorizontal = (int)SizeFlags.Expand + (int)SizeFlags.Fill;
            Instance.ActionList.Add(action);
            Godot.Collections.Array parameters = new Godot.Collections.Array();
            parameters.Add(Instance.ActionList.Count - 1);
            btn.Connect("pressed", Instance, nameof(ButtonPressed), parameters);
            parent.AddChild(btn);
            return(btn);
        }
        private void AddInZone(Lifeform lifeform, int zoneIdx)
        {
            var size           = GetViewportRect().Size;
            var zoneSplit      = size.y / zoneCount;
            var zoneLowerLimit = size.y - (zoneMargin + (zoneIdx * zoneSplit));
            var zoneUpperLimit = zoneLowerLimit - zoneSplit;

            var xPosition = (float)GD.RandRange(lifeform.MeshSize.x, size.x - lifeform.MeshSize.x);
            var yPosition = (float)GD.RandRange(zoneLowerLimit, zoneUpperLimit);

            lifeform.Position = new Vector2(xPosition, yPosition);
            drawZone.AddChild(lifeform);
        }
            public StorageWindow()
            {
                Title           = "Storage Item";
                RectClipContent = true;

                VSplitContainer = new VBoxContainer();
                Information     = new Label
                {
                    Text = "Items: 0 Volume: 0/0 Stuff",
                    SizeFlagsVertical = SizeFlags.ShrinkCenter
                };
                VSplitContainer.AddChild(Information);

                var listScrollContainer = new ScrollContainer
                {
                    SizeFlagsVertical   = SizeFlags.FillExpand,
                    SizeFlagsHorizontal = SizeFlags.FillExpand,
                    HScrollEnabled      = true,
                    VScrollEnabled      = true
                };

                EntityList = new VBoxContainer
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand
                };
                listScrollContainer.AddChild(EntityList);
                VSplitContainer.AddChild(listScrollContainer);

                AddItemButton = new Button
                {
                    Text                = "Add Item",
                    ToggleMode          = false,
                    SizeFlagsHorizontal = SizeFlags.FillExpand
                };
                AddItemButton.OnPressed += OnAddItemButtonPressed;
                VSplitContainer.AddChild(AddItemButton);

                Contents.AddChild(VSplitContainer);
            }
        public Control ActionBox(Statistics.Action statistics, ref Vector2 elementPosition)
        {
            Control f = new Control();

            f.AddChild(HeaderText("Actions", ref elementPosition));

            NewTextResults(f, "Hits taken", statistics.HitsTaken.ToString(), ref elementPosition);
            NewTextResults(f, "Damage dealt", statistics.DamageDealt.ToString(), ref elementPosition);
            NewTextResults(f, "Damage taken", statistics.DamageTaken.ToString(), ref elementPosition);
            NewTextResults(f, "Caught in net", statistics.TimesNetted.ToString(), ref elementPosition);

            return(f);
        }
Example #30
0
        private void SpawnParticle(string name)
        {
            if (HasParticle(name))
            {
                return;
            }

            var particle =
                GD.Load <PackedScene>(string.Format(ParticlePath, name.ToLower()))
                .Instance();

            particle.Name = name;
            _particlePos.AddChild(particle);
        }
Example #31
0
        protected override void OnInitialize()
        {
            title = "Toolbox";

            m_buttonMapping = new Dictionary<Button, CachedControl>();
            m_controlsCache = new ToolboxControlCache();

            m_root = new Control();
            m_root.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) );
            m_root.AddDecorator( new Scrollbars( true, false, true ) );
            m_root.SetSize( 100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage );

            // Create category foldouts, index them by name so we can assign our controls
            Dictionary< string, FoldoutList > foldouts = new Dictionary<string, FoldoutList>();

            foreach( string category in m_controlsCache.Categories )
            {
                FoldoutList foldout = new FoldoutList( category, 4.0f, true );
                foldout.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
                m_root.AddChild( foldout );

                foldouts.Add( category, foldout );
            }

            foreach( CachedControl c in m_controlsCache.Controls )
            {
                Button button = new Button( c.name );
                button.SetSize( 100.0f, CONTROL_DISPLAY_HEIGHT, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel );
                button.Clicked += HandleControlButtonClick;

                m_buttonMapping.Add( button, c );

                foldouts[ c.category ].AddItem( button );
            }

            AddChild( m_root );
        }
Example #32
0
    protected override void OnInitialize()
    {
        // Create a container control that will stack several foldouts with categorized system information
        // Control will fill 100% of our viewport, and will create vertical scrollbars if necesary
        Control sysinfo = new Control();
        sysinfo.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) );
        sysinfo.AddDecorator( new Scrollbars( true, false, true ) );
        sysinfo.SetSize( 100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage );

        // Create a system information foldout list that will categorize our system information into general and feature categories
        // Don't forget to set width to 100% of the container width
        FoldoutList system = new FoldoutList( "System", LIST_INDENTATION_PIXELS, true );
        system.SetWidth( 100.0f, Control.MetricsUnits.Percentage );

        // Create a new foldout list to contain general system infromation and populate it with data
        // Child foldouts will stretch horizontally to fill the container
        FoldoutList systemGeneral = new FoldoutList( "General", LIST_INDENTATION_PIXELS, true );
        systemGeneral.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        systemGeneral.AddItem( new LabelField( SystemInfo.deviceName, "Device Name:" ) );
        
        // Trying to access SystemInfo.deviceUniqueIdentifier from OnGUI seems to made Unity bleed internally, so we pre-cache it
        systemGeneral.AddItem( new LabelField( UDID, "UDID:" ) );
        
        systemGeneral.AddItem( new LabelField( SystemInfo.deviceModel, "Model:" ) );
        systemGeneral.AddItem( new LabelField( SystemInfo.deviceType.ToString(), "Type:" ) );
        systemGeneral.AddItem( new LabelField( SystemInfo.processorType, "Processor Type:" ) );
        systemGeneral.AddItem( new LabelField( SystemInfo.processorCount.ToString(), "Processor Count:" ) );
        systemGeneral.AddItem( new LabelField( string.Format( "{0} MB", SystemInfo.systemMemorySize ), "System Memory:" ) );
        systemGeneral.AddItem( new LabelField( SystemInfo.operatingSystem, "Operating System:" ) );

        // Second list for system features
        FoldoutList systemFeatures = new FoldoutList( "Features", LIST_INDENTATION_PIXELS, true );
        systemFeatures.SetWidth( 100.0f, Control.MetricsUnits.Percentage );

        systemFeatures.AddItem( new LabelField( SystemInfo.supportsVibration.ToString(), "Vibration:" ) );
        systemFeatures.AddItem( new LabelField( SystemInfo.supportsGyroscope.ToString(), "Gyroscope:" ) );
        systemFeatures.AddItem( new LabelField( SystemInfo.supportsAccelerometer.ToString(), "Accelerometer:" ) );
        systemFeatures.AddItem( new LabelField( SystemInfo.supportsLocationService.ToString(), "Location Service:" ) );

        // Add both category lists to the system list
        system.AddItem( systemGeneral );
        system.AddItem( systemFeatures );


        // Now recreate the previous structure for graphics information with 3 subcategories for general, features and texture support
        FoldoutList graphics = new FoldoutList( "Graphics Device", LIST_INDENTATION_PIXELS, true );
        graphics.SetWidth( 100.0f, Control.MetricsUnits.Percentage );

        FoldoutList graphicsGeneral = new FoldoutList( "General", LIST_INDENTATION_PIXELS, true );
        graphicsGeneral.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceID.ToString(), "ID:" ) );
        graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceName, "Name:" ) );
        graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceVendorID.ToString(), "VendorID:" ) );
        graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceVendor, "Vendor:" ) );
        graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsDeviceVersion, "Version:" ) );
        graphicsGeneral.AddItem( new LabelField( string.Format( "{0} MB", SystemInfo.graphicsMemorySize ), "Memory:" ) );
        graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsPixelFillrate.ToString(), "Fillrate:" ) );
        graphicsGeneral.AddItem( new LabelField( SystemInfo.graphicsShaderLevel.ToString(), "Shader Level:" ) );

        FoldoutList graphicsFeatures = new FoldoutList( "Features", LIST_INDENTATION_PIXELS, true );
        graphicsFeatures.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportedRenderTargetCount.ToString(), "Render Target Count:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supports3DTextures.ToString(), "3D Textures:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsComputeShaders.ToString(), "Compute Shaders:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsImageEffects.ToString(), "Image Effects:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsInstancing.ToString(), "Instancing:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsRenderTextures.ToString(), "Render Textures:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsRenderToCubemap.ToString(), "Render To Cubemap:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsShadows.ToString(), "Built-in Shdows:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsSparseTextures.ToString(), "Sparse Textures:" ) );
        graphicsFeatures.AddItem( new LabelField( SystemInfo.supportsStencil.ToString(), "Stencil:" ) );

        FoldoutList graphicsTextures = new FoldoutList( "Texture Support", LIST_INDENTATION_PIXELS, true );
        graphicsTextures.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        graphicsTextures.AddItem( new LabelField( SystemInfo.npotSupport.ToString(), "Non Power of Two:" ) );

        foreach ( RenderTextureFormat format in System.Enum.GetValues( typeof( RenderTextureFormat ) ) )
        {
            graphicsTextures.AddItem( new LabelField( SystemInfo.SupportsRenderTextureFormat( format ).ToString(), format.ToString() ) );
        }


        graphics.AddItem( graphicsGeneral );
        graphics.AddItem( graphicsFeatures );
        graphics.AddItem( graphicsTextures );

        // Add top level lists to our container element
        sysinfo.AddChild( system );
        sysinfo.AddChild( graphics );

        // Attach parent container
        AddChild( sysinfo );
    }
Example #33
0
    protected override void OnInitialize()
    {
        Vector2 winSize = new Vector3( 312.0f, 265.0f );
        maxSize = winSize;
        minSize = winSize;        

        autoRepaintOnSceneChange = true;

        m_root = new Control();
        m_root.SetSize( 100.0f, 100.0f, Control.MetricsUnits.Percentage, Control.MetricsUnits.Percentage );
        m_root.AddDecorator( new StackContent() );

        AddChild( m_root );

        // Input object field
        m_original = new ObjectField( typeof( GameObject ), true, null, "Original" );
        m_original.SetHeight( 26.0f, Control.MetricsUnits.Pixel );
        m_original.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        m_original.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f );
        m_root.AddChild( m_original );

        // Rotation pivot point
        m_pivot = new Vector3Field( Vector3.zero, "Pivot:" );
        m_pivot.SetHeight( 40.0f, Control.MetricsUnits.Pixel );
        m_pivot.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        m_pivot.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f );
        m_root.AddChild( m_pivot );

        // Transform control
        m_transform = new TransformControl();
        m_transform.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        m_transform.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f );
        m_root.AddChild( m_transform );

        // Count field
        m_count = new IntField( 1, "Duplicate Count:" );
        m_count.SetHeight( 26.0f, Control.MetricsUnits.Pixel );
        m_count.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        m_count.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f );
        m_root.AddChild( m_count );

        // Space field
        m_space = new EnumDropdown( Space.World, "Space:" );
        m_space.SetHeight( 26.0f, Control.MetricsUnits.Pixel );
        m_space.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        m_space.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f );
        m_root.AddChild( m_space );

        // Duplicate button
        m_duplicate = new Button( "Duplicate" );
        m_duplicate.SetWidth( 100.0f, Control.MetricsUnits.Percentage );
        m_duplicate.SetMargin( 5.0f, 5.0f, 5.0f, 5.0f );
        m_duplicate.Enabled = false;
        m_root.AddChild( m_duplicate );

        // Events
        m_original.ValueChange += m_original_ValueChange;
        m_count.ValueChange += m_count_ValueChange;
        m_duplicate.Clicked += m_duplicate_Clicked;

        SceneView.onSceneGUIDelegate += SceneViewGUI;
    }