Exemplo n.º 1
0
        public StatisticGraph(Control parent, SpriteFont font, Statistic statistic, TimeSpan accessInterval)
            : base(parent)
        {
            if (statistic == null)
                throw new ArgumentNullException("statistic");

            if (accessInterval == TimeSpan.Zero)
                accessInterval = TimeSpan.FromMilliseconds(16);

            Strata = new ControlStrata() { Layer = Layer.Overlay };
            _tracker = new StatisticTracker(statistic, accessInterval);
            _graph = new Graph(Device, (int)(15f / (float)accessInterval.TotalSeconds)); //(byte)MathHelper.Clamp(15f / (float)accessInterval.TotalSeconds, 15, 15 * 60));
            _label = new Label(this, font) {
                Text = statistic.Name,
                Justification = Justification.Centre
            };
            _label.SetPoint(Points.TopLeft, 2, 2);
            _label.SetPoint(Points.TopRight, -2, 2);

            _value = new Label(this, font) {
                Text = "0",
                Justification = Justification.Centre
            };
            _value.SetPoint(Points.BottomLeft, 2, -2);
            _value.SetPoint(Points.BottomRight, -2, -2);

            _texture = new Texture2D(Device, 1, 1);
            _texture.SetData<Color>(new Color[] { new Color(0, 0, 0, 0.8f) });

            SetSize(200, 120);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the <see cref="Control"/> class.
        /// </summary>
        /// <param name="parent">The parent control.</param>
        public Control(Control parent)
            : base(parent.Device, parent)
        {
            if (parent == null)
                throw new ArgumentNullException("parent");

            UserInterface = parent.UserInterface;
            Initialise();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandConsole"/> class.
        /// </summary>
        /// <param name="font"></param>
        /// <param name="parent">The parent.</param>
        /// <param name="assemblies">The assemblies containing commands and options to add to this <see cref="CommandConsole"/> instance.</param>
        /// <param name="game"></param>
        public CommandConsole(Game game, SpriteFont font, Control parent, params Assembly[] assemblies)
            : base(parent)
        {
            _engine = new CommandEngine(assemblies);
            _writer = new ConsoleWriter(this);

            PresentationParameters pp = game.GraphicsDevice.PresentationParameters;
            SetSize(0, pp.BackBufferHeight / 3);
            SetPoint(Points.Top, 0, 5);
            SetPoint(Points.Left, 5, 0);
            SetPoint(Points.Right, -5, 0);
            Strata = new ControlStrata() { Layer = Layer.Overlay, Offset = 100 };
            FocusPriority = int.MaxValue;
            LikesHavingFocus = false;
            IsVisible = false;
            RespectSafeArea = true;
            ToggleKey = Keys.Oem8;

            //var font = Content.Load<SpriteFont>(game, "Consolas");
            //skin = Content.Load<Skin>(game, "Console");
            //skin.BackgroundColour = new Color(1f, 1f, 1f, 0.8f);
            _background = new Texture2D(game.GraphicsDevice, 1, 1);
            _background.SetData(new Color[] { Color.Black });

            _textBox = new TextBox(this, game, font, "Command Console", "Enter your command");
            _textBox.SetPoint(Points.Bottom, 0, -3);
            _textBox.SetPoint(Points.Left, 3, 0);
            _textBox.SetPoint(Points.Right, -3, 0);
            _textBox.FocusPriority = 1;
            _textBox.FocusedChanged += c => { if (c.IsFocused) _textBox.BeginTyping(PlayerIndex.One); };
            _textBox.IgnoredCharacters.Add('`');

            _log = new TextLog(this, font, (int)(3 * Area.Height / (float)font.LineSpacing));
            _log.SetPoint(Points.TopLeft, 3, 3);
            _log.SetPoint(Points.TopRight, -3, 3);
            _log.SetPoint(Points.Bottom, 0, 0, _textBox, Points.Top);
            _log.WriteLine("Hello world");

            _tabCompletion = new Label(this, font);
            _tabCompletion.SetSize(300, 0);
            _tabCompletion.SetPoint(Points.TopLeft, 3, 6, this, Points.BottomLeft);

            _infoBox = new Label(this, font);
            _infoBox.SetPoint(Points.TopRight, -3, 6, this, Points.BottomRight);

            AreaChanged += c => _infoBox.SetSize(Math.Max(0, c.Area.Width - 311), 0);

            _commandStack = new CommandStack(_textBox, Gestures);

            BindGestures();

            Gestures.BlockedDevices.Add(typeof(KeyboardDevice));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StatisticTextLog"/> class.
        /// </summary>
        public StatisticTextLog(Control parent, SpriteFont font, bool autoAdd)
            : base(parent)
        {
            this.autoAdd = autoAdd;
            this.font = font;
            this.textColour = Color.White;
            RespectSafeArea = true;
            stats = new Dictionary<string, StatisticText>();
            SetPoint(Points.TopLeft, 0, 0);
            SetPoint(Points.Right, 0, 0);

            //AreaChanged += delegate(Control c) { UpdatePositions(); };
        }
Exemplo n.º 5
0
        public UserInterface(GraphicsDevice graphics)
        {
            Device = graphics;
            _spriteBatch = new SpriteBatch(Device);
            _buffer = new List<Control>();
            _actors = new InputActorCollection();
            _globalGestures = new Dictionary<Type, List<IGesturePair>>();
            EnableInput = true;
            _visible = true;
            _drawOrder = 100;
            _enabled = true;
            _updateOrder = 0;

            Root = new Control(this);
            Root.SetPoint(Points.TopLeft, 0, 0);
            Root.SetPoint(Points.BottomRight, 0, 0);
        }
Exemplo n.º 6
0
        protected virtual void Focus(Control control, bool rememberPrevious)
        {
            if (control == _focused)
                return;

            // clear buffers
            _unfocused.Clear();
            _newFocused.Clear();

            if (control != null && !control.LikesHavingFocus)
            {
                foreach (var item in control.Children.OrderBy(_byFocusPriority))
                {
                    if (item.LikesHavingFocus)
                    {
                        control = item;
                        break;
                    }
                }
            }

            // find all old controls being unfocused
            for (var c = _focused; c != null; c = c.Parent)
                _unfocused.Add(c);

            // find all new controls being focused
            for (var c = control; c != null; c = c.Parent)
                _newFocused.Add(c);

            var newRoot = _newFocused.Count > 0 ? _newFocused[_newFocused.Count - 1] : null;

            // remove all the common controls
            // walk both lists backwards (from the shared root) until the trees diverge
            for (int i = _newFocused.Count - 1; i >= 0; i--)
            {
                if (_unfocused.Count > 0 && _newFocused[i] == _unfocused[_unfocused.Count - 1])
                {
                    _newFocused.RemoveAt(i);
                    _unfocused.RemoveAt(_unfocused.Count - 1);
                }
                else
                {
                    break;
                }
            }

            // walk through the old controls, from leaf towards root, unfocusing them
            for (int i = 0; i < _unfocused.Count; i++)
            {
                var u = _unfocused[i];
                _focused = u;

                RemoveFocus(u);
                u.FocusedCount--;

                // quit if FocusChanged focused another control
                if (_focused != u)
                    return;
            }

            // walk through the new controls, from root to leaf, focusing them
            for (int i = _newFocused.Count - 1; i >= 0; i--)
            {
                var f = _newFocused[i];
                _focused = f;

                AddFocus(_newFocused[i]);
                _newFocused[i].FocusedCount++;

                // quit if FocusChanged focused another control
                if (_focused != f)
                    return;
            }

            // push old control onto stack
            if (rememberPrevious && _focused != null)
            {
                unchecked
                {
                    _idCounter++;
                }

                var record = new FocusRecord() { ID = _idCounter, Control = _focused };
                _previous.Add(record);
            }

            // remember new control
            //focused = control;
            _root = newRoot;

            CompactPreviousList();
        }
Exemplo n.º 7
0
 protected virtual void RemoveFocus(Control control) { }
Exemplo n.º 8
0
 protected virtual void AddFocus(Control control) { }
Exemplo n.º 9
0
 public FocusRecord? Focus(Control control)
 {
     Focus(control, true);
     return PreviousFocus();
 }
Exemplo n.º 10
0
 private void RemoveChild(Control child)
 {
     if (children.Remove(child))
         OnChildRemoved();
 }
Exemplo n.º 11
0
        ///// <summary>
        ///// Called when the control should bind its gestres.
        ///// </summary>
        //protected internal virtual void BindGestures()
        //{
        //}
        //private bool TryToRidFocus()
        //{
        //    Control newFocus = null;
        //    for (int i = 0; i < Children.Count; i++)
        //    {
        //        var c = Children[i];
        //        if (!c.IsVisible || !c.FocusScope.Includes(FocusScope))
        //            continue;
        //        if (newFocus == null
        //            || newFocus.FocusPriority > c.FocusPriority
        //            || (newFocus.FocusPriority == c.FocusPriority && !newFocus.LikesHavingFocus && c.LikesHavingFocus))
        //            newFocus = c;
        //    }
        //    if (newFocus == null)
        //        return false;
        //    else
        //    {
        //        newFocus.Focus();
        //        return true;
        //    }
        //}
        /// <summary>
        /// Determins if this control is a parent of the specified control.
        /// This searches past the controls direct parent.
        /// </summary>
        /// <param name="control"></param>
        /// <returns>true if this control is a parent of the specified control; else false.</returns>
        public bool IsParentOf(Control control)
        {
            if (control == null)
                throw new ArgumentNullException("control");

            for (var c = control.Parent; c != null; c = c.Parent)
            {
                if (c == this)
                    return true;
            }

            return false;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a new instance of the <see cref="Control"/> class.
        /// </summary>
        /// <param name="parent">The parent control.</param>
// ReSharper disable MemberCanBeProtected.Global
        public Control(Control parent)
// ReSharper restore MemberCanBeProtected.Global
            : base(parent.Device, parent)
        {
            if (parent == null)
                throw new ArgumentNullException("parent");

            UserInterface = parent.UserInterface;
            Initialise();
        }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandConsole"/> class.
 /// </summary>
 /// <param name="font"></param>
 /// <param name="parent"></param>
 /// <param name="game"></param>
 public CommandConsole(Game game, SpriteFont font, Control parent)
     : this(game, font, parent, Assembly.GetCallingAssembly())
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatisticTextLog"/> class.
 /// </summary>
 public StatisticTextLog(Control parent, SpriteFont font)
     : this(parent, font, false)
 {
 }
Exemplo n.º 15
0
 public StatisticGraph(Control parent, SpriteFont font, string statisticName, TimeSpan accessInterval)
     : this(parent, font, Statistic.Create(statisticName), accessInterval)
 {
 }
Exemplo n.º 16
0
 private void AddChild(Control child)
 {
     children.Add(child);
     OnChildAdded();
 }
Exemplo n.º 17
0
 private void AddControlsToBuffer(Control control)
 {
     _buffer.Add(control);
     foreach (var child in control.Children)
         AddControlsToBuffer(child);
 }