Add buttons to randomize hats and hog names only
authorWuzzy <almikes@aol.com>
Thu, 13 Apr 2017 18:48:06 +0200
changeset 12253 07f67ee424dc
parent 12252 a6e0977be914
child 12254 d23695f96290
Add buttons to randomize hats and hog names only
ChangeLog.txt
QTfrontend/game.cpp
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/ui/page/pageeditteam.h
QTfrontend/util/namegen.cpp
QTfrontend/util/namegen.h
--- a/ChangeLog.txt	Thu Apr 13 17:58:32 2017 +0200
+++ b/ChangeLog.txt	Thu Apr 13 18:48:06 2017 +0200
@@ -187,7 +187,7 @@
  + Randomizing map/theme in online-mode will not include DLC-content
  + New teams start with a random grave and fort
  + Hedgewars creates 4 teams instead of 1 on its first launch
- + Allow to randomize team name, flag, grave, voice and fort seperately
+ + Allow to randomize hog names, hats, team name, flag, grave, voice and fort separately
  * Campaign screen does no longer show AI-controlled teams
  * Campaign names and campaign mission names can now be translated
  * Creating randomized teams now randomizes (almost) every aspect
--- a/QTfrontend/game.cpp	Thu Apr 13 17:58:32 2017 +0200
+++ b/QTfrontend/game.cpp	Thu Apr 13 18:48:06 2017 +0200
@@ -154,7 +154,7 @@
     team1.setDifficulty(0);
     team1.setColor(0);
     team1.setNumHedgehogs(4);
-    HWNamegen::teamRandomEverything(team1,true);
+    HWNamegen::teamRandomEverything(team1, HWNamegen::rtmEverything);
     team1.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
                                    team1.teamGameConfig(100));
@@ -164,7 +164,7 @@
     team2.setColor(1);
     team2.setNumHedgehogs(4);
     do
-        HWNamegen::teamRandomEverything(team2,true);
+        HWNamegen::teamRandomEverything(team2, HWNamegen::rtmEverything);
     while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat));
     team2.setVoicepack("Default");
     HWProto::addStringListToBuffer(teamscfg,
--- a/QTfrontend/ui/page/pageeditteam.cpp	Thu Apr 13 17:58:32 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Thu Apr 13 18:48:06 2017 +0200
@@ -77,17 +77,29 @@
         HHNameEdit[i]->setFixedHeight(36);
         HHNameEdit[i]->setWhatsThis(tr("This hedgehog's name"));
         HHNameEdit[i]->setStyleSheet("padding: 6px;");
-        GBHLayout->addWidget(HHNameEdit[i], i + 1, 1);
+        GBHLayout->addWidget(HHNameEdit[i], i + 1, 1, 1, 3);
 
-        btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i + 1, 3, 1, 1, true);
+        btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i + 1, 5, 1, 1, true);
         btnRandomHogName[i]->setFixedHeight(HHNameEdit[i]->height());
         btnRandomHogName[i]->setWhatsThis(tr("Randomize this hedgehog's name"));
     }
 
+    btnRandomHats = new QPushButton();
+    btnRandomHats->setText(tr("Random Hats"));
+    btnRandomHats->setStyleSheet("padding: 6px 10px;");
+    GBHLayout->addWidget(btnRandomHats, 9, 1, 1, 1, Qt::AlignCenter);
+    btnRandomHats->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+    btnRandomNames = new QPushButton();
+    btnRandomNames->setText(tr("Random Names"));
+    btnRandomNames->setStyleSheet("padding: 6px 10px;");
+    GBHLayout->addWidget(btnRandomNames, 9, 2, 1, 1, Qt::AlignCenter);
+    btnRandomNames->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
     btnRandomTeam = new QPushButton();
     btnRandomTeam->setText(tr("Random Team"));
     btnRandomTeam->setStyleSheet("padding: 6px 10px;");
-    GBHLayout->addWidget(btnRandomTeam, 9, 0, 1, 4, Qt::AlignCenter);
+    GBHLayout->addWidget(btnRandomTeam, 9, 3, 1, 1, Qt::AlignCenter);
     btnRandomTeam->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
 
     vbox1->addWidget(GBoxHedgehogs);
@@ -219,6 +231,9 @@
     }
 
     connect(btnRandomTeam, SIGNAL(clicked()), this, SLOT(setRandomTeam()));
+    connect(btnRandomNames, SIGNAL(clicked()), this, SLOT(setRandomHogNames()));
+    connect(btnRandomHats, SIGNAL(clicked()), this, SLOT(setRandomHats()));
+
     connect(btnRandomTeamName, SIGNAL(clicked()), this, SLOT(setRandomTeamName()));
     connect(btnRandomGrave, SIGNAL(clicked()), this, SLOT(setRandomGrave()));
     connect(btnRandomFlag, SIGNAL(clicked()), this, SLOT(setRandomFlag()));
@@ -407,7 +422,21 @@
 void PageEditTeam::setRandomTeam()
 {
     HWTeam team = data();
-    HWNamegen::teamRandomEverything(team, true);
+    HWNamegen::teamRandomEverything(team, HWNamegen::rtmEverything);
+    loadTeam(team);
+}
+
+void PageEditTeam::setRandomHogNames()
+{
+    HWTeam team = data();
+    HWNamegen::teamRandomEverything(team, HWNamegen::rtmHogNames);
+    loadTeam(team);
+}
+
+void PageEditTeam::setRandomHats()
+{
+    HWTeam team = data();
+    HWNamegen::teamRandomEverything(team, HWNamegen::rtmHats);
     loadTeam(team);
 }
 
--- a/QTfrontend/ui/page/pageeditteam.h	Thu Apr 13 17:58:32 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.h	Thu Apr 13 18:48:06 2017 +0200
@@ -75,13 +75,16 @@
         void loadTeam(const HWTeam & team);
 
         // page 1
+        QPushButton * btnRandomTeam;
+        QPushButton * btnRandomNames;
+        QPushButton * btnRandomHats;
+
         QPushButton * btnRandomHogName[HEDGEHOGS_PER_TEAM];
         QPushButton * btnRandomTeamName;
         QPushButton * btnRandomGrave;
         QPushButton * btnRandomFlag;
         QPushButton * btnRandomVoice;
         QPushButton * btnRandomFort;
-        QPushButton * btnRandomTeam;
         QPushButton * btnTestSound;
 
         void lazyLoad();
@@ -89,6 +92,9 @@
     private slots:
         void saveTeam();
         void setRandomTeam();
+        void setRandomHogNames();
+        void setRandomHats();
+
         void setRandomTeamName();
         void setRandomGrave();
         void setRandomFlag();
--- a/QTfrontend/util/namegen.cpp	Thu Apr 13 17:58:32 2017 +0200
+++ b/QTfrontend/util/namegen.cpp	Thu Apr 13 18:48:06 2017 +0200
@@ -60,7 +60,7 @@
     team.setFort(getRandomFort());
 }
 
-void HWNamegen::teamRandomEverything(HWTeam & team, const bool changeteamname)
+void HWNamegen::teamRandomEverything(HWTeam & team, const RandomTeamMode mode)
 {
     // load types if not already loaded
     if (!typesAvailable)
@@ -75,7 +75,7 @@
     int kind = (rand()%(TypesHatnames.size()));
 
     // pick team name based on hat
-    if (changeteamname)
+    if (mode == HWNamegen::rtmEverything)
     {
         team.setName(getRandomTeamName(kind));
         team.setGrave(getRandomGrave());
@@ -95,13 +95,12 @@
 
     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
     {
-        if ((TypesHatnames[kind].size()) > 0)
+        if (((TypesHatnames[kind].size()) > 0) && (mode == HWNamegen::rtmEverything || mode == HWNamegen::rtmHats))
         {
             HWHog hh = team.hedgehog(i);
             hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
             team.setHedgehog(i,hh);
         }
-
         // there is a chance that this hog has the same hat as the previous one
         // let's reuse the hat-specific dict in this case
         if ((i == 0) || (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat))
@@ -111,7 +110,8 @@
         }
 
         // give each hedgehog a random name
-        HWNamegen::teamRandomHogName(team,i,dict);
+        if (mode == HWNamegen::rtmHogNames || mode == HWNamegen::rtmEverything)
+            HWNamegen::teamRandomHogName(team,i,dict);
     }
 
 }
--- a/QTfrontend/util/namegen.h	Thu Apr 13 17:58:32 2017 +0200
+++ b/QTfrontend/util/namegen.h	Thu Apr 13 18:48:06 2017 +0200
@@ -28,6 +28,12 @@
 class HWNamegen
 {
     public:
+        enum RandomTeamMode
+        {
+            rtmEverything = 0,
+            rtmHogNames = 1,
+            rtmHats = 2
+        };
 
         static void teamRandomTeamName(HWTeam & team);
         static void teamRandomGrave(HWTeam & team);
@@ -35,7 +41,8 @@
         static void teamRandomFlag(HWTeam & team);
         static void teamRandomVoice(HWTeam & team);
         static void teamRandomHogName(HWTeam & team, const int HedgehogNumber);
-        static void teamRandomEverything(HWTeam & team, const bool changeteamname);
+        static void teamRandomEverything(HWTeam & team, const enum RandomTeamMode mode);
+        static void teamRandomHats(HWTeam & team);
 
     private:
         HWNamegen();