예제 #1
0
        public StatusEffectBar(IResourceManager resourceManager, IPlayerManager playerManager)
        {
            _resourceManager = resourceManager;
            _playerManager = playerManager;

            if (playerManager.ControlledEntity != null &&
                playerManager.ControlledEntity.HasComponent(ComponentFamily.StatusEffects))
            {
                assignedEnt = playerManager.ControlledEntity;
                assigned = (StatusEffectComp) playerManager.ControlledEntity.GetComponent(ComponentFamily.StatusEffects);
                assigned.Changed += assigned_Changed;
            }

            UpdateButtons();
            Update(0);
            //Pull info from compo and sub to event.
        }
예제 #2
0
 private void assigned_Changed(StatusEffectComp sender)
 {
     UpdateButtons();
 }
예제 #3
0
        public override sealed void Update(float frameTime)
        {
            if (assignedEnt != null)
            {
                if (assignedEnt.Uid != _playerManager.ControlledEntity.Uid) //Seems like the controled ent changed.
                {
                    assigned.Changed -= assigned_Changed;
                    assigned = null;
                }
            }

            if (assigned == null && _playerManager.ControlledEntity != null &&
                _playerManager.ControlledEntity.HasComponent(ComponentFamily.StatusEffects))
            {
                assignedEnt = _playerManager.ControlledEntity;
                assigned =
                    (StatusEffectComp) _playerManager.ControlledEntity.GetComponent(ComponentFamily.StatusEffects);
                assigned.Changed += assigned_Changed;
                UpdateButtons();
            }

            if (buttons.Count > 0)
            {
                const int spacing = 3;
                const int max_per_row = 5;

                int curr_row_count = 0;
                int curr_row_num = 0;

                int x_off = spacing;
                int y_off = spacing;

                int max_x = 0;
                int max_y = 0;

                foreach (StatusEffectButton button in buttons)
                {
                    button.Position = new Vector2i(Position.X + x_off, Position.Y + y_off);

                    if (Position.X + x_off + 32 + spacing > max_x) max_x = Position.X + x_off + 32 + spacing;
                    if (Position.Y + y_off + 32 + spacing > max_y) max_y = Position.Y + y_off + 32 + spacing;

                    if (curr_row_count >= (max_per_row - 1))
                    {
                        curr_row_num++;
                        curr_row_count = 0;
                        x_off = spacing + (spacing*curr_row_count) + (curr_row_count*32);
                        y_off = spacing + (spacing*curr_row_num) + (curr_row_num*32);
                    }
                    else
                    {
                        curr_row_count++;
                        x_off = spacing + (spacing*curr_row_count) + (curr_row_count*32);
                        y_off = spacing + (spacing*curr_row_num) + (curr_row_num*32);
                    }

                    button.Update(frameTime);
                }

                ClientArea = new IntRect(Position, new Vector2i(max_x - Position.X, max_y - Position.Y));
            }
        }