/* Execute the named next item, and continue execution until we must
 * wait for something or we run out of items to execute.  */
static void
execute_items (struct sequence_info *sequence_data, GApplication * app)
{
  struct sequence_item_info *next_item;

  while (sequence_data->next_item_name != NULL)
    {
      next_item =
        find_item_by_name (sequence_data->next_item_name, sequence_data);

      if (next_item == NULL)
        {
          display_show_message ("Next item not found.", app);
          break;
        }

      sequence_data->next_item_name = NULL;
      execute_item (next_item, sequence_data, app);
    }

  return;
}
Combat_Screen::Combat_Screen(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Combat_Screen)
{
    ui->setupUi(this);

    //Setting Background image for TitleScreen Ui - Miguel
    QPixmap bg(":/BGCombat.png");

    bg = bg.scaled(this->size(), Qt::IgnoreAspectRatio);
    QPalette palette;
    palette.setBrush(QPalette::Background, bg);
    this->setPalette(palette);

    //set_lives(1);
    //set_hero_health(100);
    //set_attacks(8,20);
    //set_defend(false);
    atkValue=0;
    dfnValue=0;
    mgcValue=0;
    QImage hero;
    hero = QImage(":/Combathero.png");
    hero_pic = new QLabel;
    hero_pic->setPixmap(QPixmap::fromImage(hero));

    QLabel *enemy_title = new QLabel;
    QLabel *hp_label = new QLabel;
    enemy_title->setText(get_enemy_name());
    hp_label->setText(" HP");
    hp_label->setStyleSheet("font: 15pt; color: red;");

    enemy_display_timer = new QTimer;
    hero_display_timer = new QTimer;
    defend_timer = new QTimer;
    magic_timer = new QTimer;
    attack_timer = new QTimer;
    enemy_timer = new QTimer;
    standardAttackTimer = new QTimer;
    bossTimer = new QTimer;

    hero_action_label = new QLabel;
    hero_action_label->setText(" ");
    enemy_action_label = new QLabel;
    enemy_action_label->setText(" ");

    enemy_health_display = new QLabel;
    enemy_health_display->setNum(get_enemy_health());
    enemy_health_display->setStyleSheet("font: 15pt; color: red;");

    attack_button = new QPushButton;
    attack_button->setText("ATTACK");
    attack_button->setDefault(true);

    defend_button = new QPushButton;
    defend_button->setText("DEFEND");

    magic_button = new QPushButton;
    magic_button->setText("MAGIC");

    item_button = new QPushButton;
    item_button->setText("ITEM");

    hero_health_bar = new QProgressBar;
    hero_health_bar->setValue(get_hero_health());
    QString mainStyleSheet = QString("QProgressBar::chunk { background: green;}");
    mainStyleSheet.append("QProgressBar{ color: black;}");
    mainStyleSheet.append("QProgressBar {border: 2px solid grey; text-align: center; background-color: grey;}");
    hero_health_bar->setStyleSheet(mainStyleSheet);
    attack_bar = new QProgressBar;
    QString myStyleSheet1 = QString("QProgressBar::chunk { background: purple;}");
    myStyleSheet1.append("QProgressBar{ color: black;}");
    myStyleSheet1.append("QProgressBar {border: 1px solid grey; text-align: center; background-color: grey;}");
    attack_bar->setStyleSheet(myStyleSheet1);
    defend_bar = new QProgressBar;
    QString myStyleSheet2 = QString("QProgressBar::chunk { background: yellow;}");
    myStyleSheet2.append("QProgressBar{ color: black;}");
    myStyleSheet2.append("QProgressBar {border: 1px solid grey; text-align: center; background-color: grey;}");
    defend_bar->setStyleSheet(myStyleSheet2);
    magic_bar = new QProgressBar;
    QString myStyleSheet3 = QString("QProgressBar::chunk { background: blue;}");
    myStyleSheet3.append("QProgressBar{ color: black;}");
    myStyleSheet3.append("QProgressBar {border: 1px solid grey; text-align: center; background-color: grey;}");
    magic_bar->setStyleSheet(myStyleSheet3);
    attack_bar->setValue(atkValue);
    defend_bar->setValue(dfnValue);
    magic_bar->setValue(mgcValue);

    QHBoxLayout *attack_button_layout = new QHBoxLayout;
    attack_button_layout->addWidget(attack_button);
    attack_button_layout->addWidget(attack_bar);

    QHBoxLayout *defend_button_layout = new QHBoxLayout;
    defend_button_layout->addWidget(defend_button);
    defend_button_layout->addWidget(defend_bar);

    QHBoxLayout *magic_button_layout = new QHBoxLayout;
    magic_button_layout->addWidget(magic_button);
    magic_button_layout->addWidget(magic_bar);

    QHBoxLayout *item_button_layout = new QHBoxLayout;
    item_button_layout->addWidget(item_button);

    QVBoxLayout *left_layout = new QVBoxLayout;
    left_layout->addWidget(hero_health_bar);
    left_layout->addWidget(hero_pic);
    left_layout->addLayout(attack_button_layout);
    left_layout->addLayout(defend_button_layout);
    left_layout->addLayout(magic_button_layout);
    left_layout->addLayout(item_button_layout);

    QHBoxLayout *top_right_layout = new QHBoxLayout;
    top_right_layout->addWidget(enemy_title);
    top_right_layout->addWidget(hp_label);
    top_right_layout->addWidget(enemy_health_display);

    QVBoxLayout *right_layout = new QVBoxLayout;
    right_layout->addLayout(top_right_layout);
    right_layout->addStretch();

    QHBoxLayout *top_layout = new QHBoxLayout;
    top_layout->addLayout(left_layout);
    top_layout->addSpacing(100);
    top_layout->addLayout(right_layout);

    QVBoxLayout *bottom_layout = new QVBoxLayout;
    bottom_layout->addWidget(hero_action_label);
    bottom_layout->addWidget(enemy_action_label);

    QVBoxLayout *main_layout = new QVBoxLayout;
    main_layout->addLayout(top_layout);
    main_layout->addLayout(bottom_layout);

    setLayout(main_layout);

    QObject::connect(attack_button,SIGNAL(clicked()),
                     this,SLOT(calculate_attack()));
    QObject::connect(enemy_timer,SIGNAL(timeout()),
                     this,SLOT(calculate_enemy_attack()));
    QObject::connect(standardAttackTimer,SIGNAL(timeout()),
                     this,SLOT(calculate_standard_attack()));
    QObject::connect(defend_button,SIGNAL(clicked()),
                     this,SLOT(execute_defend()));
    QObject::connect(magic_button,SIGNAL(clicked()),
                     this,SLOT(execute_magic()));
    QObject::connect(item_button,SIGNAL(clicked()),
                     this,SLOT(execute_item()));
    QObject::connect(bossTimer,SIGNAL(timeout()),
                     this,SLOT(bossAttacks()));

    hero_action_label->show();
    enemy_action_label->show();

}