Ticket #1839: tribute-notifications.patch
File tribute-notifications.patch, 2.5 KB (added by , 11 years ago) |
---|
-
simulation/components/Player.js
547 547 var cmpTheirStatisticsTracker = QueryPlayerIDInterface(player, IID_StatisticsTracker); 548 548 if (cmpTheirStatisticsTracker) 549 549 cmpTheirStatisticsTracker.IncreaseTributesReceivedCounter(total); 550 // TODO: notify the receiver 550 551 var notification = {"type": "tribute", "player": player, "player1": this.playerID, "amounts": amounts}; 552 var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 553 cmpGUIInterface.PushNotification(notification); 551 554 } 552 555 // else not enough resources... TODO: send gui notification 553 556 }; -
gui/session/messages.js
53 53 if (isDiplomacyOpen) 54 54 openDiplomacy(); 55 55 } 56 else if (notification.type == "tribute") 57 { 58 addChatMessage({ 59 "type": "tribute", 60 "player": notification.player, 61 "player1": notification.player1, 62 "amounts": notification.amounts 63 }) 64 } 56 65 else if (notification.type == "quit") 57 66 { 58 67 // Used for AI testing … … 306 315 else // No need for other players to know of this. 307 316 return; 308 317 break; 318 case "tribute": 319 if (msg.player != Engine.GetPlayerID()) 320 return; 321 322 username = escapeText(g_Players[msg.player].name); 323 playerColor = g_Players[msg.player].color.r + " " + g_Players[msg.player].color.g + " " + g_Players[msg.player].color.b; 324 325 // Format the amounts to proper English: 200 food, 100 wood, and 300 metal; 100 food; 400 wood and 200 stone 326 var amounts = Object.keys(msg.amounts) 327 .filter(function (type) msg.amounts[type] > 0) 328 .map(function (type) msg.amounts[type] + " " + type); 329 // This is one of the times I actually miss Common Lisp's incredibly cryptic but enormously useful format function. 330 // With that this would be a cute one-liner. I've racked my brain a bit and can't think of anything as elegant in JS. 331 // Now before I end up writing an essay in the comments, the code: 332 if (amounts.length > 1) 333 { 334 var lastAmount = amounts.pop(); 335 amounts = amounts.join(", ") + " and " + lastAmount; 336 } 337 338 formatted = "[color=\"" + playerColor + "\"]" + username + "[/color] has sent you " + amounts + "."; 339 break; 309 340 case "message": 310 341 // May have been hidden by the 'team' command. 311 342 if (msg.hide)