Outsource commonly used words in siPointType to QTfrontend
authorWuzzy <Wuzzy2@mail.ru>
Mon, 14 Jan 2019 07:14:18 +0100
changeset 14599 50f511588635
parent 14598 221380cdee7e
child 14600 42f3d6860971
Outsource commonly used words in siPointType to QTfrontend
ChangeLog.txt
QTfrontend/ui/page/pagegamestats.cpp
share/hedgewars/Data/Maps/ClimbHome/map.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua
share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua
share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua
share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua
share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
share/hedgewars/Data/Scripts/SpeedShoppa.lua
share/hedgewars/Data/Scripts/TargetPractice.lua
--- a/ChangeLog.txt	Mon Jan 14 06:17:35 2019 +0100
+++ b/ChangeLog.txt	Mon Jan 14 07:14:18 2019 +0100
@@ -62,6 +62,7 @@
  + New return value: AddTeam/AddMissionTeam return <real team name>, <team index>
  + Utils library: New calls: getReadableChallengeRecord, updateChallengeRecord
  + New callback: onGameResult(winningClan): Called when the game ends normally. winningClan = index of winning clan or -1 on draw
+ + SendStat extension: Option to use predefined modes with siPointType, like "!POINTS" or "!TIME"
  + SimpleMission: Add isMissionTeam attribute for teams
  + SpeedShoppa/TargetPractice libraries: Remove custom hog and team info settings
  + Params explode, poison in the SpawnFake*Crate functions now optional and default to false
--- a/QTfrontend/ui/page/pagegamestats.cpp	Mon Jan 14 06:17:35 2019 +0100
+++ b/QTfrontend/ui/page/pagegamestats.cpp	Mon Jan 14 07:14:18 2019 +0100
@@ -320,7 +320,8 @@
 
             i = playerinfo.indexOf(' ');
 
-            int kills = playerinfo.left(i).toInt();
+            QString killsString = playerinfo.left(i);
+            int kills = killsString.toInt();
             QString playername = playerinfo.mid(i + 1);
             QString image;
 
@@ -351,14 +352,30 @@
 
             QString message;
             QString killstring;
-            if(kindOfPoints.compare("") == 0) {
+            if(kindOfPoints.isEmpty()) {
                 //: Number of kills in stats screen, written after the team name
                 killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills);
+            } else if (kindOfPoints == "!POINTS") {
+                //: Number of points in stats screen, written after the team name
+                killstring = PageGameStats::tr("(%1 point(s))", "", kills).arg(kills);
+            } else if (kindOfPoints == "!TIME") {
+                //: Time in seconds
+                killstring = PageGameStats::tr("(%L1 second(s))", "", kills).arg((double) kills/1000, 0, 'g', 3);
+            } else if (kindOfPoints.startsWith("!TIME") && kindOfPoints.length() == 6) {
+                int len = kindOfPoints.at(6).digitValue();
+                if(len != -1)
+                    killstring = PageGameStats::tr("(%L1 second(s))", "", kills).arg((double) kills/1000, 0, 'g', len);
+                else
+                    qWarning("SendStat: siPointType received with !TIME and invalid number length!");
+            } else if (kindOfPoints == "!CRATES") {
+                killstring = PageGameStats::tr("(%1 crate(s))", "", kills).arg(kills);
+            } else if (kindOfPoints == "!EMPTY") {
+                killstring = QString("");
             } else {
                 //: For custom number of points in the stats screen, written after the team name. %1 is the number, %2 is the word. Example: “4 points”
                 killstring = PageGameStats::tr("(%1 %2)", "", kills).arg(kills).arg(kindOfPoints);
-                kindOfPoints = QString("");
             }
+            kindOfPoints = QString("");
 
             message = QString("<p><h2>%1 %2. <font color=\"%4\">%3</font> ").arg(image, QString::number(realPlayerPosition), playername, clanColor.name()) + killstring + "</h2></p>";
 
--- a/share/hedgewars/Data/Maps/ClimbHome/map.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Maps/ClimbHome/map.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -448,8 +448,8 @@
                 updateChallengeRecord("TimeRecord", rawFinishTime, false)
                 SendStat(siCustomAchievement, string.format(loc("%s bravely climbed up to a dizzy height of %d to reach home."), GetHogName(CurrentHedgehog), getActualHeight(RecordHeight)))
                 updateChallengeRecord("Highscore", getActualHeight(RecordHeight))
-                SendStat(siPointType, loc("seconds"))
-                SendStat(siPlayerKills, tostring(roundedFinishTime), GetHogTeamName(CurrentHedgehog))
+                SendStat(siPointType, "!TIME")
+                SendStat(siPlayerKills, tostring(rawFinishTime), GetHogTeamName(CurrentHedgehog))
 
                 EndGame()
                 onAchievementsDeclaration()
@@ -693,7 +693,7 @@
     end
 
     updateChallengeRecord("Highscore", actualHeight)
-    SendStat(siPointType, loc("points"))
+    SendStat(siPointType, "!POINTS")
     SendStat(siPlayerKills, actualHeight, GetHogTeamName(CurrentHedgehog))
     EndGame()
     onAchievementsDeclaration()
@@ -749,7 +749,7 @@
     end
     checkAwards()
     for i = #ranking, 1, -1 do
-	SendStat(siPointType, loc("points"))
+	SendStat(siPointType, "!POINTS")
         SendStat(siPlayerKills, tostring(ranking[i].score), ranking[i].name)
     end
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -179,7 +179,7 @@
 				SaveCampaignVar("IceStadiumLeastSaucersUsed", tostring(saucersUsed))
 			end
 
-			SendStat(siPointType, loc("milliseconds"))
+			SendStat(siPointType, "!TIME")
 			SendStat(siPlayerKills, totalTime, GetHogTeamName(hero.gear))
 			SaveCampaignVar("Mission6Won", "true")
 			checkAllMissionsCompleted()
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -278,18 +278,19 @@
 	SendStat(siCustomAchievement, loc("The time that you have left when you reach the blue hedgehog will be added to the next turn."))
 	SendStat(siCustomAchievement, loc("Each turn you'll have only one rope to use."))
 	SendStat(siCustomAchievement, loc("You'll lose if you die or if your time is up."))
-	SendStat(siPointType, loc("milliseconds"))
+	SendStat(siPointType, "!TIME")
 	SendStat(siPlayerKills, tostring(runnerTimeTotal), teamB.name)
-	SendStat(siPlayerKills, tostring(GetTeamStats(teamA.name).Kills), teamA.name)
+	SendStat(siPointType, "!EMPTY")
+	SendStat(siPlayerKills, "0", teamA.name)
 	EndGame()
 end
 
 function win()
 	SendStat(siGameResult, loc("Congratulations, you are the fastest!"))
 	-- siCustomAchievements were added earlier
-	SendStat(siPointType, loc("milliseconds"))
+	SendStat(siPointType, "!TIME")
 	SendStat(siPlayerKills, tostring(winningTime), teamA.name)
-	SendStat(siPointType, loc("milliseconds"))
+	SendStat(siPointType, "!TIME")
 	SendStat(siPlayerKills, tostring(runnerTimeTotal), teamB.name)
 	SaveCampaignVar("Mission13Won", "true")
 	checkAllMissionsCompleted()
--- a/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/Basic_Training_-_Sniper_Rifle.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -432,7 +432,7 @@
 		SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots))
 		end_score_overall = end_score_targets
 	end
-	SendStat(siPointType, loc("points"))
+	SendStat(siPointType, "!POINTS")
 	SendStat(siPlayerKills, tostring(end_score_overall), playerTeamName)
 	updateChallengeRecord("Highscore", end_score_overall)
 end
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_Rope_Knock_Challenge.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -96,7 +96,7 @@
 	SendStat(siGameResult, loc("Challenge over!"))
 	local score = GetKillScore()
 	SendStat(siCustomAchievement, string.format(loc("You have killed %d of 16 hedgehogs (+%d points)."), hogsKilled, score))
-	SendStat(siPointType, loc("points"))
+	SendStat(siPointType, "!POINTS")
 	SendStat(siPlayerKills, tostring(score), playerTeamName)
 	PlaySound(sndHellish)
 
@@ -118,7 +118,7 @@
 
 	SendStat(siCustomAchievement, string.format(loc("You have killed %d of 16 hedgehogs (+%d points)."), hogsKilled, hogScore))
 	SendStat(siCustomAchievement, string.format(loc("You have completed this challenge in %.2f s (+%d points)."), completeTime, timeScore))
-	SendStat(siPointType, loc("points"))
+	SendStat(siPointType, "!POINTS")
 	SendStat(siPlayerKills, tostring(score), playerTeamName)
 	SetTeamLabel(playerTeamName, tostring(score))
 
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -241,7 +241,7 @@
 				GameOver = true
 				AddCaption(loc("The flood has stopped! Challenge over."))
 				SendStat(siGameResult, loc("Challenge completed!"))
-				SendStat(siPointType, loc("rescues"))
+				SendStat(siPointType, "!POINTS")
 				SendStat(siPlayerKills, tostring(hhCount), playerTeamName)
 
 				-- Do not count drowning hedgehogs
@@ -308,7 +308,7 @@
 		else
 			SendStat(siCustomAchievement, loc("You haven't rescued anyone."))
 		end
-		SendStat(siPointType, loc("points"))
+		SendStat(siPointType, "!POINTS")
 		SendStat(siPlayerKills, "0", playerTeamName)
 		local highscore = tonumber(GetMissionVar("Highscore"))
 		show = (type(highscore) == "number") and (highscore > 0)
--- a/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Capture_the_Flag.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -171,7 +171,7 @@
 		table.sort(teamList, teamRank)
 
 		for i=1, #teamList do
-			SendStat(siPointType, loc("point(s)"))
+			SendStat(siPointType, "!POINTS")
 			SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
 		end
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Mutant.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -438,7 +438,7 @@
     local showScore = ""
     table.sort(teamsSorted, function(team1, team2) return getTeamValue(team1, "Score") > getTeamValue(team2, "Score") end)
     for i=1, TeamsCount do
-        SendStat(siPointType, loc("point(s)"))
+        SendStat(siPointType, "!POINTS")
         local score = getTeamValue(teamsSorted[i], "Score")
         local deaths = getTeamValue(teamsSorted[i], "DeadHogs")
         SendStat(siPlayerKills, score, teamsSorted[i])
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -560,7 +560,7 @@
 
                 -- Write all the stats!
                 for i = 1, #sortedTeams do
-                        SendStat(siPointType, loc("milliseconds"))
+                        SendStat(siPointType, "!TIME")
 			SendStat(siTeamRank, tostring(clanRanks[GetTeamClan(sortedTeams[i].name)]))
                         SendStat(siPlayerKills, sortedTeams[i].score, sortedTeams[i].name)
                 end
--- a/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Space_Invasion.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -587,7 +587,7 @@
 		SendStat(siGameResult, string.format(loc("%s wins!"), winnerTeam))
 
 		for i = 1, TeamsCount do
-			SendStat(siPointType, loc("points"))
+			SendStat(siPointType, "!POINTS")
 			SendStat(siPlayerKills, tostring(teamStats[i].score), teamStats[i].name)
 		end
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -456,7 +456,7 @@
 
 		-- Write all the stats!
 		for i = 1, #sortedTeams do
-			SendStat(siPointType, loc("milliseconds"))
+			SendStat(siPointType, "!TIME")
 			SendStat(siTeamRank, tostring(clanRanks[GetTeamClan(sortedTeams[i].name)]))
 			SendStat(siPlayerKills, sortedTeams[i].score, sortedTeams[i].name)
 		end
--- a/share/hedgewars/Data/Scripts/SpeedShoppa.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Scripts/SpeedShoppa.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -163,7 +163,7 @@
 				SetState(playerHog, band(GetState(playerHog), bnot(gstHHDriven)))
 				AddCaption(loc("Challenge completed!"))
 				SendStat(siGameResult, loc("Challenge completed!"))
-				SendStat(siPointType, loc("milliseconds"))
+				SendStat(siPointType, "!TIME")
 				local time = startTime - endTime
 				SendStat(siPlayerKills, tostring(time), GetHogTeamName(playerHog))
 				SendStat(siCustomAchievement, string.format(loc("You have finished the challenge in %.3f s."), (time/1000)))
@@ -171,7 +171,7 @@
 				updateChallengeRecord("TimeRecord", time)
 			else
 				SendStat(siGameResult, loc("Challenge failed!"))
-				SendStat(siPointType, loc("crate(s)"))
+				SendStat(siPointType, "!CRATES")
 				SendStat(siPlayerKills, tostring(cratesCollected), GetHogTeamName(playerHog))
 				SendStat(siCustomAchievement, string.format(loc("You have collected %d out of %d crate(s)."), cratesCollected, #crates))
 			end
--- a/share/hedgewars/Data/Scripts/TargetPractice.lua	Mon Jan 14 06:17:35 2019 +0100
+++ b/share/hedgewars/Data/Scripts/TargetPractice.lua	Mon Jan 14 07:14:18 2019 +0100
@@ -302,7 +302,7 @@
 			end
 			end_score_overall = end_score_targets
 		end
-		SendStat(siPointType, loc("point(s)"))
+		SendStat(siPointType, "!POINTS")
 		SendStat(siPlayerKills, tostring(end_score_overall), GetHogTeamName(player))
 		-- Update highscore
 		updateChallengeRecord("Highscore", end_score_overall)