예제 #1
0
        public void AddAction(int id, string description, bool requireDestination, int cooldownTime, Renderable gfx)
        {
            var action = new GridiaAction(id, description, requireDestination, cooldownTime, gfx);

            _actions.Add(id, action);
            gfx.ScaleXY = 2;
            ActionGrid.AddChild(gfx);
        }
예제 #2
0
        public GridiaAction(int id, String description, bool requireDestination, int cooldownTime, Renderable gfx)
        {
            Id                  = id;
            Description         = description;
            _requireDestination = requireDestination;

            Func <float, String> formatTime = time => String.Format("{0:##.#}s", time / 1000.0);

            gfx.OnClick      = TriggerAction;
            gfx.OnEnterFrame = () =>
            {
                var timeSinceLastAttack = UnixTimeNow() - _lastAttack;
                _canPerformAction = timeSinceLastAttack >= cooldownTime;

                // :( let's do a circular alpha mask instead of this ...
                _timeLeft = cooldownTime - timeSinceLastAttack;
                var frac = (float)(UnixTimeNow() - _lastAttack) / cooldownTime;
                gfx.Alpha = (byte)(255 * Math.Min(1.0, frac));
                if (_timeLeft > 0)
                {
                    GUI.Label(gfx.Rect, formatTime(_timeLeft));
                }
            };
            gfx.ToolTip = () => _canPerformAction
                ? String.Format("Press {0} to use: {1}", id + 1, description)
                : formatTime(_timeLeft);
        }