Fix possibility to accidentally destroy team by entering an already existing team name
--- a/ChangeLog.txt Sat Oct 07 20:07:21 2017 +0200
+++ b/ChangeLog.txt Sun Oct 08 04:14:49 2017 +0200
@@ -279,6 +279,7 @@
* Remove broken “Play again” button appearing in stats page after an online game
* Weapons scheme editor: When leaving, it no longer flickers and the selection is not reset to Default
* Team editor: Fix old team being retained when renaming a team
+ * Team editor: Automatically rename team when leaving team editor page with an already used team name
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/team.cpp Sat Oct 07 20:07:21 2017 +0200
+++ b/QTfrontend/team.cpp Sun Oct 08 04:14:49 2017 +0200
@@ -208,6 +208,14 @@
return f.exists();
}
+// Returns true if the team name has been changed but a file with the same team name already exists.
+// So if this team would be saved, another team file would be overwritten, which is generally not
+// desired.
+bool HWTeam::wouldOverwriteOtherFile()
+{
+ return (m_name != OldTeamName) && fileExists();
+}
+
bool HWTeam::deleteFile()
{
if(m_isNetTeam)
--- a/QTfrontend/team.h Sat Oct 07 20:07:21 2017 +0200
+++ b/QTfrontend/team.h Sun Oct 08 04:14:49 2017 +0200
@@ -62,6 +62,7 @@
bool deleteFile();
bool saveToFile();
bool fileExists();
+ bool wouldOverwriteOtherFile();
// attribute getters
unsigned int campaignProgress() const;
--- a/QTfrontend/ui/page/pageeditteam.cpp Sat Oct 07 20:07:21 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp Sun Oct 08 04:14:49 2017 +0200
@@ -610,7 +610,35 @@
void PageEditTeam::saveTeam()
{
- data().saveToFile();
+ HWTeam team = data();
+ if(!team.wouldOverwriteOtherFile())
+ {
+ team.saveToFile();
+ }
+ else
+ {
+ // Name already used -> look for an appropriate name:
+ int i=2;
+ QString origName = team.name();
+ QString newName;
+ while(team.wouldOverwriteOtherFile())
+ {
+ newName = tr("%1 (%2)").arg(origName).arg(i++);
+ team.setName(newName);
+ if(i > 1000)
+ break;
+ }
+
+ QMessageBox teamNameFixedMsg(this);
+ teamNameFixedMsg.setIcon(QMessageBox::Warning);
+ teamNameFixedMsg.setWindowTitle(QMessageBox::tr("Teams - Name already taken"));
+ teamNameFixedMsg.setText(QMessageBox::tr("The team name '%1' is already taken, so your team has been renamed to '%2'.").arg(origName).arg(team.name()));
+ teamNameFixedMsg.setWindowModality(Qt::WindowModal);
+ teamNameFixedMsg.setStandardButtons(QMessageBox::Ok);
+ teamNameFixedMsg.exec();
+
+ team.saveToFile();
+ }
}
// When the "Use default for all binds" is pressed...
--- a/share/hedgewars/Data/Locale/hedgewars_de.ts Sat Oct 07 20:07:21 2017 +0200
+++ b/share/hedgewars/Data/Locale/hedgewars_de.ts Sun Oct 08 04:14:49 2017 +0200
@@ -1336,6 +1336,10 @@
<extracomment>Name of a flag for computer-controlled enemies. %1 is replaced with the computer level</extracomment>
<translation>CPU %1</translation>
</message>
+ <message>
+ <source>%1 (%2)</source>
+ <translation>%1 (%2)</translation>
+ </message>
</context>
<context>
<name>PageGameStats</name>
@@ -3144,6 +3148,14 @@
<source>Cannot delete file %1.</source>
<translation>Datei %1 konnte nicht gelöscht werden.</translation>
</message>
+ <message>
+ <source>Teams - Name already taken</source>
+ <translation>Teams – Name bereits belegt</translation>
+ </message>
+ <message>
+ <source>The team name '%1' is already taken, so your team has been renamed to '%2'.</source>
+ <translation>Der Teamname »%1« ist bereits belegt, daher wurde der Name deines Teams auf »%2« geändert.</translation>
+ </message>
</context>
<context>
<name>QObject</name>
--- a/share/hedgewars/Data/Locale/hedgewars_en.ts Sat Oct 07 20:07:21 2017 +0200
+++ b/share/hedgewars/Data/Locale/hedgewars_en.ts Sun Oct 08 04:14:49 2017 +0200
@@ -1252,6 +1252,10 @@
<extracomment>Name of a flag for computer-controlled enemies. %1 is replaced with the computer level</extracomment>
<translation>CPU %1</translation>
</message>
+ <message>
+ <source>%1 (%2)</source>
+ <translation>%1 (%2)</translation>
+ </message>
</context>
<context>
<name>PageGameStats</name>
@@ -2956,6 +2960,14 @@
<source>Cannot delete file %1.</source>
<translation>Cannot delete file %1.</translation>
</message>
+ <message>
+ <source>Teams - Name already taken</source>
+ <translation>Teams—Name already taken</translation>
+ </message>
+ <message>
+ <source>The team name '%1' is already taken, so your team has been renamed to '%2'.</source>
+ <translation>The team name ‘%1’ is already taken, so your team has been renamed to ‘%2’.</translation>
+ </message>
</context>
<context>
<name>QObject</name>