public ComboBox(string displayName, IEnumerable <string> textValues, int defaultIndex = 0) : base(displayName, 30)
        {
            var values = textValues.ToList();

            if (defaultIndex >= values.Count)
            {
                throw new IndexOutOfRangeException("Default index cannot be greater than values count!");
            }

            // Initialize properties
            TextObjects.Add(TextHandle = new Text(displayName, DefaultFont)
            {
                Color           = DefaultColorGold,
                TextOrientation = Text.Orientation.Center
            });
            ControlHandle  = new ComboBoxHandle(values[defaultIndex]);
            _currentValue  = defaultIndex;
            OverlayControl = new OverlayContainer(this)
            {
                IsVisible       = false,
                BackgroundColor = Color.FromArgb(200, 14, 27, 25)
            };

            // Add a button to the container for each combo box entry
            foreach (var value in values)
            {
                Overlay.Add(new Button(Button.ButtonType.ComboBoxSub, value));
            }

            // Add handle to base
            Add(ControlHandle);

            // Initalize theme specific properties
            OnThemeChange();

            // Listen to required events
            ControlHandle.OnActiveStateChanged += delegate
            {
                // Set visibility state of the overlay
                Overlay.IsVisible = ControlHandle.IsActive;
            };
            Messages.OnMessage += delegate(Messages.WindowMessage args)
            {
                switch (args.Message)
                {
                // Collapse combo box on blacklist message
                case WindowMessages.KeyUp:
                case WindowMessages.LeftButtonDoubleClick:
                case WindowMessages.LeftButtonDown:
                case WindowMessages.MiddleButtonDoubleClick:
                case WindowMessages.MiddleButtonDown:
                case WindowMessages.MouseWheel:
                case WindowMessages.RightButtonDoubleClick:
                case WindowMessages.RightButtonDown:

                    CloseOverlayOnInteraction(args.Message == WindowMessages.MouseWheel);
                    break;
                }
            };
        }
        public CheckBox(string displayName, bool defaultValue = true) : base(displayName, DefaultHeight)
        {
            // Initialize properties
            TextObjects.Add(TextHandle = new Text(displayName, DefaultFont)
            {
                Color           = DefaultColorGold,
                TextOrientation = Text.Orientation.Center
            });
            ControlHandle = new CheckBoxHandle();
            CurrentValue  = defaultValue;

            ControlHandle.OnActiveStateChanged += delegate
            {
                // Listen to active state changes
                CurrentValue = ControlHandle.IsActive;

                // Hover even when clicked on text
                if (IsMouseInside && !ControlHandle.IsMouseInside)
                {
                    ControlHandle.CurrentState = ControlHandle.IsActive ? DynamicControl.States.ActiveHover : DynamicControl.States.Hover;
                }
            };

            // Add handle to base
            Add(ControlHandle);

            // Initalize theme specific properties
            OnThemeChange();
        }
Esempio n. 3
0
        protected internal override void OnThemeChange()
        {
            switch (CurrentButtonType)
            {
            case ButtonType.AddonSub:
            case ButtonType.ComboBoxSub:

                // Update fake sizes
                DynamicRectangle = ThemeManager.GetDynamicRectangle(this);
                var rectangle =
                    Enum.GetValues(typeof(States))
                    .Cast <States>()
                    .Select(state => DynamicRectangle.GetRectangle(state))
                    .FirstOrDefault(rect => !rect.IsEmpty);
                Size          = new Vector2(rectangle.Width, (int)(rectangle.Height * (CurrentButtonType == ButtonType.AddonSub ? 0.75f : 1)));
                SizeRectangle = new Rectangle(0, 0, (int)Size.X, (int)Size.Y);
                UpdateCropRectangle();

                // Update TextObject positions to current position
                TextObjects.ForEach(o => o.ApplyToControlPosition(this));
                break;

            default:

                // Update base theme
                base.OnThemeChange();
                break;
            }
        }
Esempio n. 4
0
        public KeyBind(string displayName, bool defaultValue, BindTypes bindType, Tuple <uint, uint> defaultKeys)
            : base(displayName, DefaultHeight)
        {
            // Initialize properties
            ControlHandle = new CheckBoxHandle(bindType)
            {
                IsActive = defaultValue
            };
            TextObjects.Add(TextHandle = new Text(DisplayName, DefaultFont)
            {
                TextOrientation = Text.Orientation.Bottom,
                Color           = DefaultColorGold
            });
            DefaultValue = defaultValue;
            CurrentValue = defaultValue;
            BindType     = bindType;
            Keys         = defaultKeys;
            Buttons      = new Tuple <KeyButtonHandle, KeyButtonHandle>(new KeyButtonHandle(KeyStrings.Item1, this, true), new KeyButtonHandle(KeyStrings.Item2, this));

            // Initalize theme specific properties
            OnThemeChange();

            // Listen to active state changes
            ControlHandle.OnActiveStateChanged += delegate(DynamicControl sender, EventArgs args) { CurrentValue = sender.IsActive; };

            // Add controls to base container
            Add(ControlHandle);
            Add(Buttons.Item1);
            Add(Buttons.Item2);

            // Listen to required events
            Buttons.Item1.OnActiveStateChanged += OnActiveStateChanged;
            Buttons.Item2.OnActiveStateChanged += OnActiveStateChanged;
        }
            internal ComboBoxHandle(string defaultText) : base(ThemeManager.SpriteType.ControlComboBox)
            {
                // Initialize properties
                TextObjects.Add(TextHandle = new Text(defaultText, DefaultFont)
                {
                    Color = DefaultColorGold
                });

                // Initalize theme specific properties
                OnThemeChange();
            }
Esempio n. 6
0
        internal Label(string displayName, int height) : base(displayName, height)
        {
            // Initialize properties
            TextObjects.Add(TextHandle = new Text(displayName, DefaultFont)
            {
                Color = DefaultColorGreen
            });
            TextWidthMultiplier = 1;

            // Initalize theme specific properties
            OnThemeChange();
        }
Esempio n. 7
0
        public Slider(string displayName, int defaultValue = 0, int minValue = 0, int maxValue = 100)
            : base(displayName, DefaultHeight + ThemeManager.CurrentTheme.Config.SpriteAtlas.Backgrounds.Slider.Height)
        {
            // Initialize properties
            TextObjects.AddRange(new[]
            {
                TextHandle = new Text(displayName, DefaultFont)
                {
                    TextOrientation = Text.Orientation.Top,
                    Color           = DefaultColorGold
                },
                ValueDisplayHandle = new Text("placeholder", DefaultFont)
                {
                    TextOrientation = Text.Orientation.Top,
                    TextAlign       = Text.Align.Right,
                    Color           = DefaultColorGold
                }
            });
            Background = new EmptyControl(ThemeManager.SpriteType.BackgroundSlider)
            {
                DrawBase = true
            };
            ControlHandle = new SliderHandle();
            _minValue     = Math.Min(minValue, maxValue);
            _maxValue     = Math.Max(minValue, maxValue);
            CurrentValue  = defaultValue;

            // Add handle to base
            Add(Background);
            Add(ControlHandle);

            // Listen to required events
            Background.OnLeftMouseDown += delegate
            {
                if (!ControlHandle.IsLeftMouseDown && Background.IsInside(Game.CursorPos2D))
                {
                    MoveOffset = 0 - SliderSize / 2;
                    RecalculateSliderPosition((int)Game.CursorPos2D.X - SliderSize / 2);
                    ControlHandle.IsLeftMouseDown = true;
                }
            };
            ControlHandle.OnLeftMouseDown      += delegate { MoveOffset = (int)((ControlHandle.Position.X - RelativeOffset.X) - Game.CursorPos2D.X); };
            ControlHandle.OnActiveStateChanged += delegate
            {
                if (ControlHandle.IsActive)
                {
                    ControlHandle.IsActive = false;
                }
            };

            // Initalize theme specific properties
            OnThemeChange();
        }
Esempio n. 8
0
            public KeyButtonHandle(string keyText, KeyBind parent, bool isFirstButton = false) : base(ThemeManager.SpriteType.Empty)
            {
                // Initialize properties
                TextObjects.Add(TextHandle = new Text(keyText, DefaultFont)
                {
                    TextAlign = Text.Align.Center,
                    Color     = DefaultColorGold
                });
                KeyText       = keyText;
                ParentHandle  = parent;
                IsFirstButton = isFirstButton;

                // Initalize theme specific properties
                OnThemeChange();
            }
        protected internal override void OnThemeChange()
        {
            DynamicRectangle = ThemeManager.GetDynamicRectangle(this);
            var rectangle =
                Enum.GetValues(typeof(States))
                .Cast <States>()
                .Select(state => DynamicRectangle.GetRectangle(state))
                .FirstOrDefault(rect => !rect.IsEmpty);

            Size          = new Vector2(rectangle.Width, rectangle.Height);
            SizeRectangle = new Rectangle(0, 0, rectangle.Width, rectangle.Height);
            UpdateCropRectangle();

            // Update TextObject positions to current position
            TextObjects.ForEach(o => o.ApplyToControlPosition(this));
        }
Esempio n. 10
0
 internal void SetText(string text, Text.Align align, int xOffset = 0, int yOffset = 0)
 {
     TextValue = text;
     if (TextHandle == null)
     {
         if (TextDictionary.ContainsKey(CurrentButtonType))
         {
             TextHandle       = TextDictionary[CurrentButtonType](CurrentButtonType == ButtonType.Addon ? text.ToUpper() : text);
             TextHandle.Color = CurrentColorModificationValue.Combine(DefaultColorValues[CurrentButtonType]);
             TextObjects.Add(TextHandle);
         }
         else
         {
             return;
         }
     }
     else
     {
         TextHandle.TextValue = CurrentButtonType == ButtonType.Addon ? text.ToUpper() : text;
     }
     TextHandle.TextAlign = align;
     TextHandle.Padding   = new Vector2(xOffset, yOffset);
     TextHandle.ApplyToControlPosition(this);
 }