# HG changeset patch # User Wuzzy # Date 1507428889 -7200 # Node ID 967990d958bc2bb2d15ab04431b1d4ea73b4cddc # Parent bc34fc75670e33dea1a349bcace5c0443914f243 Fix possibility to accidentally destroy team by entering an already existing team name diff -r bc34fc75670e -r 967990d958bc ChangeLog.txt --- 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 diff -r bc34fc75670e -r 967990d958bc QTfrontend/team.cpp --- 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) diff -r bc34fc75670e -r 967990d958bc QTfrontend/team.h --- 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; diff -r bc34fc75670e -r 967990d958bc QTfrontend/ui/page/pageeditteam.cpp --- 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... diff -r bc34fc75670e -r 967990d958bc share/hedgewars/Data/Locale/hedgewars_de.ts --- 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 @@ Name of a flag for computer-controlled enemies. %1 is replaced with the computer level CPU %1 + + %1 (%2) + %1 (%2) + PageGameStats @@ -3144,6 +3148,14 @@ Cannot delete file %1. Datei %1 konnte nicht gelöscht werden. + + Teams - Name already taken + Teams – Name bereits belegt + + + The team name '%1' is already taken, so your team has been renamed to '%2'. + Der Teamname »%1« ist bereits belegt, daher wurde der Name deines Teams auf »%2« geändert. + QObject diff -r bc34fc75670e -r 967990d958bc share/hedgewars/Data/Locale/hedgewars_en.ts --- 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 @@ Name of a flag for computer-controlled enemies. %1 is replaced with the computer level CPU %1 + + %1 (%2) + %1 (%2) + PageGameStats @@ -2956,6 +2960,14 @@ Cannot delete file %1. Cannot delete file %1. + + Teams - Name already taken + Teams—Name already taken + + + The team name '%1' is already taken, so your team has been renamed to '%2'. + The team name ‘%1’ is already taken, so your team has been renamed to ‘%2’. + QObject