recruitmentscene.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <gui/recruitmentscene.h>
  2. #include <gui/uniticon.h>
  3. #include <gui/raceicon.h>
  4. #include <gui/guiscenemanager.h>
  5. #include <gui/scene.h>
  6. #include <playermanager.h>
  7. #include <player.h>
  8. #include <racemanager.h>
  9. #include <race.h>
  10. #include <ui_recruitmentscene.h>
  11. #include <QHBoxLayout>
  12. #include <QString>
  13. #include <QStringList>
  14. #include <cassert>
  15. RecruitmentScene::RecruitmentScene(QWidget *parent)
  16. : Scene(parent)
  17. , ui(new Ui::RecruitmentScene)
  18. {
  19. ui->setupUi(this);
  20. for (int i = 0; i < 5; i++) {
  21. available_units_icons_[i] = new UnitIcon(ui->available_units_list_);
  22. ui->available_units_layout_->addWidget(available_units_icons_[i], 0, i);
  23. available_units_icons_[i]->setUnitIcon("norace", "nounit");
  24. }
  25. for (int i = 0; i < 10; i++) {
  26. chosen_units_icons_[i] = new UnitIcon(ui->chosen_units_grid_);
  27. chosen_units_icons_[i]->setUnitIcon("warcraft", "rogue");
  28. ui->chosen_units_layout_->addWidget(chosen_units_icons_[i], i / 5, i % 5);
  29. }
  30. ui->parent_spec_unit_->resize(45, 45);
  31. ui->parent_spec_unit_->setUnitIcon("warcraft", "chaosorc");
  32. ui->current_spec_unit_->resize(45, 45);
  33. ui->current_spec_unit_->setUnitIcon("warcraft", "chaosorc");
  34. ui->next_spec_unit_1_->resize(45, 45);
  35. ui->next_spec_unit_2_->resize(45, 45);
  36. ui->next_spec_unit_3_->resize(45, 45);
  37. ui->next_spec_unit_4_->resize(45, 45);
  38. ui->next_spec_unit_1_->setUnitIcon("warcraft", "chaosorc");
  39. ui->next_spec_unit_2_->setUnitIcon("warcraft", "chaosorc");
  40. ui->next_spec_unit_3_->setUnitIcon("warcraft", "chaosorc");
  41. ui->next_spec_unit_4_->setUnitIcon("warcraft", "chaosorc");
  42. available_units_icons_[0]->setUnitIcon("warcraft", "blademaster");
  43. available_units_icons_[1]->setUnitIcon("warcraft", "chaosorc");
  44. available_units_icons_[2]->setUnitIcon("warcraft", "nagasummoner");
  45. available_units_icons_[3]->setUnitIcon("warcraft", "rogue");
  46. available_units_icons_[4]->setUnitIcon("norace", "nounit");
  47. }
  48. RecruitmentScene::~RecruitmentScene()
  49. {
  50. delete ui;
  51. }
  52. void RecruitmentScene::parseArgs(QString args) {
  53. QStringList list = args.split("|");
  54. assert(list.size() >= 2);
  55. current_player_id_ = list[0].toInt();
  56. current_player_ = PlayerManager::getInstance().getPlayer(current_player_id_);
  57. available_money_ = list[1].toInt();
  58. }
  59. void RecruitmentScene::init() {
  60. current_money_ = available_money_;
  61. initAvailableRaces();
  62. initAvailableUnits();
  63. initChosenUnits();
  64. }
  65. void RecruitmentScene::initAvailableRaces() {
  66. auto races = RaceManager::getInstance().getAvailableRacesList();
  67. int race_id = 0;
  68. for (QString race_name : races) {
  69. assert(race_id < 5);
  70. auto race = RaceManager::getInstance().getRace(race_name);
  71. available_races_icons_[race_id]->setRaceIcon(race_name);
  72. race_id++;
  73. }
  74. }
  75. void RecruitmentScene::initAvailableUnits() {
  76. int unit_id = 0;
  77. for (Unit* unit : current_player_->getRace()->getAllUnitsList()) {
  78. available_units_icons_[unit_id]->setUnitIcon(unit->getUnitIcon());
  79. unit_id++;
  80. }
  81. }
  82. void RecruitmentScene::initChosenUnits() {
  83. }
  84. void RecruitmentScene::on_back_button_clicked()
  85. {
  86. GuiSceneManager::getInstance().changeScene("main_menu");
  87. }