prebattlescene.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "ui/hotseat_prebattle/prebattlescene.h"
  2. #include "player.h"
  3. #include "playermanager.h"
  4. #include "race.h"
  5. #include "racemanager.h"
  6. #include "hotseatgame/gameproperties.h"
  7. #include "gui/guiscenemanager.h"
  8. #include "ui_prebattlescene.h"
  9. PreBattleScene::PreBattleScene(QWidget *parent) :
  10. Scene(parent),
  11. ui(new Ui::PreBattleScene)
  12. {
  13. ui->setupUi(this);
  14. watcher = new ButtonEventListener(this);
  15. ui->to_battle_button->installEventFilter(watcher);
  16. }
  17. PreBattleScene::~PreBattleScene()
  18. {
  19. delete ui;
  20. }
  21. void PreBattleScene::init() {
  22. for (unsigned i = 0; i < GameProperties::PLAYERS_NUMBER; i++) {
  23. Player* player = PlayerManager::getInstance().getPlayer(i);
  24. QLabel* name = findChild<QLabel*>("player_" + QString::number(i) + "_name");
  25. if (name)
  26. name->setText(player->getPlayerName());
  27. QLabel* race = findChild<QLabel*>("player_" + QString::number(i) + "_race");
  28. if (race)
  29. race->setText("<img src=\":/assets/units/" + player->getRace()->getRaceId() + "/icon.png\" width=\"80\" height=\"80\"/>");
  30. auto units = player->getUnitsAsVector();
  31. for (unsigned unit_number = 0; unit_number < units.size(); unit_number++) {
  32. QLabel* unit_icon = findChild<QLabel*>("player_" + QString::number(i) + "_chosen_unit_" + QString::number(unit_number));
  33. if (!unit_icon) {
  34. continue;
  35. }
  36. QString race_name = player->getRace()->getRaceId();
  37. QString unit_name = units[unit_number]->getUnitId();
  38. unit_icon->setText("<img src=\":/assets/units/" + race_name + "/" + unit_name + "/icon.png\" width=\"58\" height=\"58\"/>");
  39. }
  40. for (unsigned unit_number = units.size(); unit_number < GameProperties::MAX_PARTY_SIZE; unit_number++) {
  41. QLabel* unit_icon = findChild<QLabel*>("player_" + QString::number(i) + "_chosen_unit_" + QString::number(unit_number));
  42. if (!unit_icon) {
  43. continue;
  44. }
  45. unit_icon->hide();
  46. }
  47. QWidget* units_widget = findChild<QWidget*>("player_" + QString::number(i) + "_units");
  48. if (units_widget)
  49. units_widget->resize(64 * units.size(), 64);
  50. }
  51. }
  52. void PreBattleScene::on_to_battle_button_clicked()
  53. {
  54. GuiSceneManager::getInstance().changeScene("hotseatgame");
  55. }