Team editor: Disable flag widget when selecting CPU team
authorWuzzy <almikes@aol.com>
Thu, 13 Apr 2017 23:50:00 +0200
changeset 12250 05f1935175da
parent 12249 d23695f96290
child 12251 caff1a3a7456
Team editor: Disable flag widget when selecting CPU team
ChangeLog.txt
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/ui/page/pageeditteam.h
--- a/ChangeLog.txt	Thu Apr 13 21:22:32 2017 +0200
+++ b/ChangeLog.txt	Thu Apr 13 23:50:00 2017 +0200
@@ -195,6 +195,7 @@
  * Clicking on "New" in weapon scheme editor now creates empty weapon scheme instead of default
  * Fix language names in language list being always in English
  * Prevent starting game with >48 hogs (because engine doesn't support it yet)
+ * Team editor Fix flag being selectable for computer players although it had no effect
 
 Content Creation:
  + Theme objects can now have more than 1 in-land rect specified. You can specify the amount in theme.cfg by adding another number (and ,) before the first rect
--- a/QTfrontend/ui/page/pageeditteam.cpp	Thu Apr 13 21:22:32 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Thu Apr 13 23:50:00 2017 +0200
@@ -150,6 +150,7 @@
     CBGrave->setFixedHeight(44);
     GBTLayout->addWidget(CBGrave, 2, 1, 1, 2);
 
+    // Player flags, combobox to select flag
     CBFlag = new QComboBox(GBoxTeam);
     CBFlag->setMaxCount(65535);
     CBFlag->setMaxVisibleItems(50);
@@ -157,6 +158,38 @@
     CBFlag->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
     GBTLayout->addWidget(CBFlag, 3, 1, 1, 2);
 
+    // CPU level flag. Static image, only displayed when computer player is selected
+    QImage imgBotlevels = QImage("physfs://Graphics/botlevels.png");
+
+    int botlevelOffsets[5]= { 19, 14, 10, 6, 0 };   
+
+    for(int i=0; i<5; i++) {
+        QImage imgCPU = QImage("physfs://Graphics/Flags/cpu.png");
+        QPainter painter(&imgCPU);
+        painter.drawImage(botlevelOffsets[i], 0, imgBotlevels, botlevelOffsets[i]);
+
+        pixCPU[i] = QPixmap::fromImage(imgCPU);
+    }
+
+    QHBoxLayout* hboxCPU = new QHBoxLayout();
+    hboxCPU->setContentsMargins(0, 0, 0, 0);
+
+    hboxCPUWidget = new QWidget();
+    hboxCPUWidget->setLayout(hboxCPU);
+
+    CPUFlag = new QLabel();
+    CPUFlag->setPixmap(pixCPU[0]);
+    CPUFlag->setFixedHeight(38);
+
+    hboxCPU->addWidget(CPUFlag);
+
+    CPUFlagLabel = new QLabel("CPU");
+    CPUFlagLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+    hboxCPU->addWidget(CPUFlagLabel);
+
+    hboxCPUWidget->setHidden(true);
+    GBTLayout->addWidget(hboxCPUWidget, 3, 1, 1, 1);
+
     btnRandomTeamName = addButton(":/res/dice.png", GBTLayout, 0, 3, 1, 1, true);
     btnRandomTeamName->setWhatsThis(tr("Randomize the team name"));
 
@@ -234,6 +267,8 @@
     connect(btnRandomNames, SIGNAL(clicked()), this, SLOT(setRandomHogNames()));
     connect(btnRandomHats, SIGNAL(clicked()), this, SLOT(setRandomHats()));
 
+    connect(CBTeamLvl, SIGNAL(currentIndexChanged(const int)), this, SLOT(CBTeamLvl_activated(const int)));
+
     connect(btnRandomTeamName, SIGNAL(clicked()), this, SLOT(setRandomTeamName()));
     connect(btnRandomGrave, SIGNAL(clicked()), this, SLOT(setRandomGrave()));
     connect(btnRandomFlag, SIGNAL(clicked()), this, SLOT(setRandomFlag()));
@@ -360,6 +395,20 @@
     FortPreview->setPixmap(pix);
 }
 
+void PageEditTeam::CBTeamLvl_activated(const int index)
+{
+    CBFlag->setHidden(index != 0);
+    btnRandomFlag->setHidden(index != 0);
+
+    if(index > 0) 
+    {
+        int cpuLevel = 6 - index;
+        CPUFlag->setPixmap(pixCPU[cpuLevel - 1]);
+        CPUFlagLabel->setText(tr("CPU %1").arg(cpuLevel));
+    }
+    hboxCPUWidget->setHidden(index == 0);
+}
+
 void PageEditTeam::testSound()
 {
     DataManager & dataMgr = DataManager::instance();
--- a/QTfrontend/ui/page/pageeditteam.h	Thu Apr 13 21:22:32 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.h	Thu Apr 13 23:50:00 2017 +0200
@@ -43,6 +43,7 @@
         void deleteTeam(const QString & name);
 
     public slots:
+        void CBTeamLvl_activated(const int index);
         void CBFort_activated(const QString & gravename);
 
     private:
@@ -56,6 +57,10 @@
         SquareLabel *FortPreview;
         QComboBox *CBGrave;
         QComboBox *CBFlag;
+        QLabel *CPUFlag;
+        QLabel *CPUFlagLabel;
+        QWidget *hboxCPUWidget;
+        QPixmap pixCPU[5];
         QComboBox *CBTeamLvl;
         QComboBox *CBVoicepack;
         QGroupBox *GBoxBinds;