Ticket #638: Summary.diff
File Summary.diff, 18.4 KB (added by , 14 years ago) |
---|
-
binaries/data/mods/public/gui/session_new/session.js
106 106 stopMusic(); 107 107 endGame(); 108 108 109 Engine.SwitchGuiPage("page_summary.xml", { "gameResult" : gameResult }); 110 109 Engine.SwitchGuiPage("page_summary.xml", 110 { "gameResult" : gameResult, 111 "timeElapsed" : simState.timeElapsed, 112 "playerStates": simState.players 113 }); 111 114 } 112 115 113 116 // Return some data that we'll use when hotloading this file after changes -
binaries/data/mods/public/gui/summary/summary.js
1 // Max player slots for any map (should read from config) 2 const MAX_SLOTS = 8; 3 4 var panelNames = [ 'unitsBuildingsPanel', 'resourcesPanel' ]; 5 var panelButtonNames = [ 'unitsBuildingsPanelButton', 'resourcesPanelButton' ]; 6 7 8 function /* string */ timeToString(/* int */ time /* in milliseconds */) 9 { 10 var hours = Math.floor(time / 1000 / 60 / 60); 11 var minutes = Math.floor(time / 1000 / 60) % 60; 12 var seconds = Math.floor(time / 1000) % 60; 13 return hours + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds); 14 } 15 16 function selectPanel(/*int*/ panelNumber) 17 { 18 for (var i = 0; i < panelNames.length; i++) 19 { 20 if (i != panelNumber) 21 { 22 getGUIObjectByName(panelNames[i]).hidden = true; 23 getGUIObjectByName(panelButtonNames[i]).sprite = "wheatIndentFillLight"; 24 } 25 else 26 { 27 getGUIObjectByName(panelNames[i]).hidden = false; 28 getGUIObjectByName(panelButtonNames[i]).sprite = "wheatIndentFillVeryLight"; 29 } 30 } 31 } 32 1 33 function init(data) 2 34 { 35 getGUIObjectByName("timeElapsed").caption = "Time elapsed: " + timeToString(data.timeElapsed); 36 3 37 getGUIObjectByName("summaryText").caption = data.gameResult; 38 39 //Space player boxes 40 var boxSpacing = 32; 41 for (var i = 0; i < panelNames.length; ++i) 42 for (var j = 0; j < MAX_SLOTS; ++j) 43 { 44 var box = getGUIObjectByName("playerBox"+i+"["+j+"]"); 45 var boxSize = box.size; 46 var h = boxSize.bottom - boxSize.top; 47 boxSize.top = j * boxSpacing; 48 boxSize.bottom = j * boxSpacing + h; 49 box.size = boxSize; 50 } 51 52 // TODO set mapPlayers as playerCounters.length 53 var maxPlayers = data.playerStates.length - 1; 54 55 // Show counters 56 for (var i = 0; i < MAX_SLOTS; ++i) 57 { 58 // Show only needed player slots 59 for (var k = 0; k < panelNames.length; ++k) 60 { 61 getGUIObjectByName("playerBox"+k+"["+i+"]").hidden = (i >= maxPlayers); 62 } 63 64 if (i < maxPlayers) 65 { 66 var playerState = data.playerStates[i+1]; 67 68 for (var k = 0; k < panelNames.length; ++k) 69 { 70 var playerName = getGUIObjectByName("playerName"+k+"["+i+"]"); 71 playerName.caption = playerState.name; 72 } 73 74 var unitsTrained = getGUIObjectByName("unitsTrained["+i+"]"); 75 var unitsLost = getGUIObjectByName("unitsLost["+i+"]"); 76 var buildingsConstructed = getGUIObjectByName("buildingsConstructed["+i+"]"); 77 var buildingsLost = getGUIObjectByName("buildingsLost["+i+"]"); 78 var civCentresBuild = getGUIObjectByName("civCentresBuild["+i+"]"); 79 var foodGathered = getGUIObjectByName("foodGathered["+i+"]"); 80 var woodGathered = getGUIObjectByName("woodGathered["+i+"]"); 81 var metalGathered = getGUIObjectByName("metalGathered["+i+"]"); 82 var stoneGathered = getGUIObjectByName("stoneGathered["+i+"]"); 83 84 unitsTrained.caption = playerState.unitsTrained; 85 unitsLost.caption = playerState.unitsLost; 86 buildingsConstructed.caption = playerState.buildingsConstructed; 87 buildingsLost.caption = playerState.buildingsLost; 88 civCentresBuild.caption = playerState.civCentresBuild; 89 foodGathered.caption = playerState.resourcesGathered.food; 90 woodGathered.caption = playerState.resourcesGathered.wood; 91 metalGathered.caption = playerState.resourcesGathered.metal; 92 stoneGathered.caption = playerState.resourcesGathered.stone; 93 } 94 } 4 95 } -
binaries/data/mods/public/gui/summary/summary.xml
20 20 21 21 <object name="summaryText" 22 22 type="text" 23 size="50 50 100%-50 100%-200" 23 size="50 10 100%-50 80" 24 font="serif-bold-18" 25 text_align="center" 26 /> 27 28 <object name="timeElapsed" 29 type="text" 30 size="100%-200 10 100%-10 50" 24 31 font="serif-16" 25 32 text_align="center" 26 text_valign="center"27 33 /> 28 34 35 <object name="unitsBuildingsPanelButton" type="button" sprite="wheatIndentFillVeryLight" size="50 75 200 101"> 36 <action on="Press">selectPanel(0);</action> 37 Units/buildings 38 </object> 39 <object name="resourcesPanelButton" type="button" sprite="wheatIndentFillLight" size="200 75 350 101"> 40 <action on="Press">selectPanel(1);</action> 41 Resources 42 </object> 43 <object name="unitsBuildingsPanel" type="image" sprite="wheatIndentFillVeryLight" size="50 100 100%-50 100%-50"> 44 45 <object size="50 0 100%-50 100%-50"> 46 <object name="playerNameHeading" type="text" text_align="left" 47 size="0 16 100 100%" font="serif-bold-14" 48 > 49 Player name 50 </object> 51 <object name="unitsTrainedHeading" type="text" text_align="center" 52 size="200 6 300 100%" font="serif-bold-14" 53 > 54 Units trained 55 </object> 56 <object name="unitsLostHeading" type="text" text_align="center" 57 size="300 6 400 100%" font="serif-bold-14" 58 > 59 Units lost 60 </object> 61 <object name="buildingsConstructedHeading" type="text" text_align="center" 62 size="400 6 500 100%" font="serif-bold-14" 63 > 64 Buildings constructed 65 </object> 66 <object name="buildingsLostHeading" type="text" text_align="center" 67 size="500 6 600 100%" font="serif-bold-14" 68 > 69 Buildings lost 70 </object> 71 <object name="civCentresBuildHeading" type="text" text_align="center" 72 size="600 6 700 100%" font="serif-bold-14" 73 > 74 CivCentres build 75 </object> 76 77 </object> 78 79 <object size="50 50 100%-50 100%-50"> 80 <repeat count="8"> 81 <object name="playerBox0[n]" size="0 0 100% 30" hidden="true"> 82 <object name="playerName0[n]" type="text" text_align="left" size="0 2 100 100%" /> 83 <object name="unitsTrained[n]" type="text" text_align="center" size="200 2 300 100%"/> 84 <object name="unitsLost[n]" type="text" text_align="center" size="300 2 400 100%"/> 85 <object name="buildingsConstructed[n]" type="text" text_align="center" size="400 2 500 100%"/> 86 <object name="buildingsLost[n]" type="text" text_align="center" size="500 2 600 100%"/> 87 <object name="civCentresBuild[n]" type="text" text_align="center" size="600 2 700 100%"/> 88 </object> 89 </repeat> 90 </object> 91 92 </object> 93 <object name="resourcesPanel" type="image" sprite="wheatIndentFillVeryLight" size="50 100 100%-50 100%-50" hidden="true"> 94 95 <object size="50 0 100%-50 100%-50"> 96 <object name="playerName2Heading" type="text" text_align="left" 97 size="0 16 100 100%" font="serif-bold-14" 98 > 99 Player name 100 </object> 101 <object name="foodGatheredHeading" type="text" text_align="center" 102 size="200 6 300 100%" font="serif-bold-14" 103 > 104 Food gathered 105 </object> 106 <object name="woodGatheredHeading" type="text" text_align="center" 107 size="300 6 400 100%" font="serif-bold-14" 108 > 109 Wood gathered 110 </object> 111 <object name="metalGatheredHeading" type="text" text_align="center" 112 size="400 6 500 100%" font="serif-bold-14" 113 > 114 Metal gathered 115 </object> 116 <object name="stoneGatheredHeading" type="text" text_align="center" 117 size="500 6 600 100%" font="serif-bold-14" 118 > 119 Stone gathered 120 </object> 121 122 </object> 123 124 <object size="50 50 100%-50 100%-50"> 125 <repeat count="8"> 126 <object name="playerBox1[n]" size="0 0 100% 30" hidden="true"> 127 <object name="playerName1[n]" type="text" text_align="left" size="0 2 100 100%" /> 128 <object name="foodGathered[n]" type="text" text_align="center" size="200 2 300 100%"/> 129 <object name="woodGathered[n]" type="text" text_align="center" size="300 2 400 100%"/> 130 <object name="metalGathered[n]" type="text" text_align="center" size="400 2 500 100%"/> 131 <object name="stoneGathered[n]" type="text" text_align="center" size="500 2 600 100%"/> 132 </object> 133 </repeat> 134 </object> 135 136 </object> 137 29 138 <object type="button" style="wheatButton" size="100%-150 100%-40 100% 100%"> 30 139 Main menu 31 140 <action on="Press"><![CDATA[ -
binaries/data/mods/public/simulation/components/GuiInterface.js
20 20 GuiInterface.prototype.GetSimulationState = function(player) 21 21 { 22 22 var ret = { 23 "players": [] 23 "players": [], 24 "timeElapsed": 0 24 25 }; 25 26 27 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 28 ret.timeElapsed = cmpTimer.GetTime(); 29 26 30 var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 27 31 var n = cmpPlayerMan.GetNumPlayers(); 28 32 for (var i = 0; i < n; ++i) … … 37 41 "popLimit": cmpPlayer.GetPopulationLimit(), 38 42 "resourceCounts": cmpPlayer.GetResourceCounts(), 39 43 "trainingQueueBlocked": cmpPlayer.IsTrainingQueueBlocked(), 40 "state": cmpPlayer.GetState() 44 "state": cmpPlayer.GetState(), 45 "unitsTrained": cmpPlayer.GetUnitsTrained(), 46 "unitsLost": cmpPlayer.GetUnitsLost(), 47 "buildingsConstructed": cmpPlayer.GetBuildingsConstructed(), 48 "buildingsLost": cmpPlayer.GetBuildingsLost(), 49 "civCentresBuild": cmpPlayer.GetCivCentresBuild(), 50 "resourcesGathered": cmpPlayer.GetResourcesGathered() 41 51 }; 42 52 ret.players.push(playerData); 43 53 } -
binaries/data/mods/public/simulation/components/Identity.js
66 66 "<value>Mechanical</value>" + 67 67 "<value>Super</value>" + 68 68 "<value>Hero</value>" + 69 "<value>Unit</value>" + 69 70 "<value>Structure</value>" + 70 71 "<value>Civic</value>" + 72 "<value>CivCentre</value>" + 71 73 "<value>Economic</value>" + 72 74 "<value>Defensive</value>" + 73 75 "<value>Village</value>" + -
binaries/data/mods/public/simulation/components/Player.js
20 20 "stone": 1000 21 21 }; 22 22 this.state = "active"; // game state - one of "active", "defeated", "won" 23 this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class 23 this.conquestCriticalEntitiesCount = 0; // number of owned units and buildings with ConquestCritical class 24 25 // statistics 26 // units 27 this.unitsTrained = 0; 28 this.unitsLost = 0; 29 //buildings 30 this.buildingsConstructed = 0; 31 this.buildingsLost = 0; 32 // civ centres 33 this.civCentresBuild = 0; 34 // resources 35 this.resourcesGathered = { 36 "food": 0, 37 "wood": 0, 38 "metal": 0, 39 "stone": 0 40 }; 24 41 }; 25 42 26 43 Player.prototype.SetPlayerID = function(id) … … 110 127 Player.prototype.AddResource = function(type, amount) 111 128 { 112 129 this.resourceCount[type] += (+amount); 130 this.resourcesGathered[type] += amount; 113 131 }; 114 132 115 133 Player.prototype.AddResources = function(amounts) 116 134 { 117 135 for (var type in amounts) 136 { 118 137 this.resourceCount[type] += (+amounts[type]); 138 this.resourcesGathered[type] += amounts[type]; 139 } 119 140 }; 120 141 121 142 Player.prototype.TrySubtractResources = function(amounts) … … 163 184 return this.conquestCriticalEntitiesCount; 164 185 }; 165 186 187 Player.prototype.GetUnitsTrained = function() 188 { 189 return this.unitsTrained; 190 }; 191 192 Player.prototype.GetUnitsLost = function() 193 { 194 return this.unitsLost; 195 }; 196 197 Player.prototype.GetBuildingsConstructed = function() 198 { 199 return this.buildingsConstructed; 200 }; 201 202 Player.prototype.GetBuildingsLost = function() 203 { 204 return this.buildingsLost; 205 }; 206 207 Player.prototype.GetCivCentresBuild = function() 208 { 209 return this.civCentresBuild; 210 }; 211 212 Player.prototype.GetResourcesGathered = function() 213 { 214 return this.resourcesGathered; 215 }; 216 166 217 // Keep track of population effects of all entities that 167 218 // become owned or unowned by this player 168 219 Player.prototype.OnGlobalOwnershipChanged = function(msg) 169 220 { 170 var classes = []; 221 var isConquestCritical = false; 222 var isStructure = false; 223 var isUnit = false; 224 var isCivCentre = false; 171 225 172 226 // Load class list only if we're going to need it 173 227 if (msg.from == this.playerID || msg.to == this.playerID) 174 228 { 175 229 var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity); 176 230 if (cmpIdentity) 177 classes = cmpIdentity.GetClassesList(); 231 { 232 var classes = cmpIdentity.GetClassesList(); 233 isConquestCritical = classes.indexOf("ConquestCritical") != -1; 234 // we want to count only real structures, not foundations 235 var cmpFoundation = Engine.QueryInterface(msg.entity, IID_Foundation); 236 isStructure = classes.indexOf("Structure") != -1 && cmpFoundation == null; 237 isUnit = classes.indexOf("Unit") != -1; 238 isCivCentre = classes.indexOf("CivCentre") != -1; 239 } 178 240 } 179 241 180 242 if (msg.from == this.playerID) 181 243 { 182 if (classes.indexOf("ConquestCritical") != -1) 183 this.conquestCriticalEntitiesCount--; 244 if (isConquestCritical) 245 this.conquestCriticalEntitiesCount--; 246 if (isStructure) 247 this.buildingsLost++; 248 if (isUnit) 249 this.unitsLost++; 184 250 185 251 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 186 252 if (cost) … … 192 258 193 259 if (msg.to == this.playerID) 194 260 { 195 if ( classes.indexOf("ConquestCritical") != -1)261 if (isConquestCritical) 196 262 this.conquestCriticalEntitiesCount++; 263 if (isStructure) 264 this.buildingsConstructed++; 265 if (isUnit) 266 this.unitsTrained++; 197 267 198 268 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 199 269 if (cost) -
binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
36 36 GetResourceCounts: function() { return { food: 100 }; }, 37 37 IsTrainingQueueBlocked: function() { return false; }, 38 38 GetState: function() { return "active"; }, 39 GetConquestCriticalEntitiesCount: function() { return 1; }, 40 GetUnitsTrained: function() { return 10; }, 41 GetUnitsLost: function() { return 9; }, 42 GetBuildingsConstructed: function() { return 5; }, 43 GetBuildingsLost: function() { return 4; }, 44 GetCivCentresBuild: function() { return 1; }, 45 GetResourcesGathered: function() { return { food: 100 }; }, 39 46 }); 40 47 41 48 AddMock(101, IID_Player, { … … 47 54 GetResourceCounts: function() { return { food: 200 }; }, 48 55 IsTrainingQueueBlocked: function() { return false; }, 49 56 GetState: function() { return "active"; }, 57 GetConquestCriticalEntitiesCount: function() { return 1; }, 58 GetUnitsTrained: function() { return 10; }, 59 GetUnitsLost: function() { return 9; }, 60 GetBuildingsConstructed: function() { return 5; }, 61 GetBuildingsLost: function() { return 4; }, 62 GetCivCentresBuild: function() { return 1; }, 63 GetResourcesGathered: function() { return { food: 100 }; }, 50 64 }); 51 65 52 66 TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), { … … 60 74 resourceCounts: { food: 100 }, 61 75 trainingQueueBlocked: false, 62 76 state: "active", 77 conquestCriticalEntitiesCount = 1; 78 unitsTrained = 10; 79 unitsLost = 9; 80 buildingsConstructed = 5; 81 buildingsLost = 4; 82 civCentresBuild = 1; 83 resourcesGathered = { 84 "food": 100, 85 "wood": 0, 86 "metal": 0, 87 "stone": 0 88 }, 63 89 }, 64 90 { 65 91 name: "Player 2", … … 70 96 resourceCounts: { food: 200 }, 71 97 trainingQueueBlocked: false, 72 98 state: "active", 99 conquestCriticalEntitiesCount = 1; 100 unitsTrained = 10; 101 unitsLost = 9; 102 buildingsConstructed = 5; 103 buildingsLost = 4; 104 civCentresBuild = 1; 105 resourcesGathered = { 106 "food": 100, 107 "wood": 0, 108 "metal": 0, 109 "stone": 0 110 }, 73 111 } 74 112 ] 75 113 }); -
binaries/data/mods/public/simulation/templates/template_structure_civic_civil_centre.xml
4 4 <GenericName>Civic Centre</GenericName> 5 5 <IconCell>1</IconCell> 6 6 <Tooltip>Build upon a settlement to capture territory.</Tooltip> 7 <Classes datatype="tokens">Village Defensive</Classes> 7 <Classes datatype="tokens"> 8 Village 9 Defensive 10 CivCentre 11 </Classes> 8 12 </Identity> 9 13 <BuildRestrictions> 10 14 <PlacementType>settlement</PlacementType> -
binaries/data/mods/public/simulation/templates/template_unit.xml
3 3 <Identity> 4 4 <GenericName>Unit</GenericName> 5 5 <Classes datatype="tokens"> 6 Unit 6 7 ConquestCritical 7 8 </Classes> 8 9 </Identity>