Ticket #3999: 3999_guiinterface_cleanup_v1.patch
File 3999_guiinterface_cleanup_v1.patch, 8.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GuiInterface.js
GuiInterface.prototype.Init = function() 46 46 47 47 /** 48 48 * Returns global information about the current game state. 49 49 * This is used by the GUI and also by AI scripts. 50 50 */ 51 GuiInterface.prototype.GetSimulationState = function( player)51 GuiInterface.prototype.GetSimulationState = function() 52 52 { 53 53 let ret = { 54 54 "players": [] 55 55 }; 56 56 … … GuiInterface.prototype.GetSimulationStat 167 167 * Returns global information about the current game state, plus statistics. 168 168 * This is used by the GUI at the end of a game, in the summary screen. 169 169 * Note: Amongst statistics, the team exploration map percentage is computed from 170 170 * scratch, so the extended simulation state should not be requested too often. 171 171 */ 172 GuiInterface.prototype.GetExtendedSimulationState = function( player)172 GuiInterface.prototype.GetExtendedSimulationState = function() 173 173 { 174 174 // Get basic simulation info 175 175 let ret = this.GetSimulationState(); 176 176 177 177 // Add statistics to each player … … GuiInterface.prototype.GetRenamedEntitie 194 194 return this.renamedEntities.concat(this.miragedEntities[player]); 195 195 else 196 196 return this.renamedEntities; 197 197 }; 198 198 199 GuiInterface.prototype.ClearRenamedEntities = function( player)199 GuiInterface.prototype.ClearRenamedEntities = function() 200 200 { 201 201 this.renamedEntities = []; 202 202 this.miragedEntities = []; 203 203 }; 204 204 … … GuiInterface.prototype.CheckTechnologyRe 648 648 return cmpTechnologyManager.CanResearch(data.tech); 649 649 }; 650 650 651 651 // Returns technologies that are being actively researched, along with 652 652 // which entity is researching them and how far along the research is. 653 GuiInterface.prototype.GetStartedResearch = function(player , viewedPlayer)653 GuiInterface.prototype.GetStartedResearch = function(player) 654 654 { 655 let cmpTechnologyManager = QueryPlayerIDInterface( viewedPlayer, IID_TechnologyManager);655 let cmpTechnologyManager = QueryPlayerIDInterface(player, IID_TechnologyManager); 656 656 if (!cmpTechnologyManager) 657 657 return {}; 658 658 659 659 let ret = {}; 660 660 for (let tech in cmpTechnologyManager.GetTechsStarted()) … … GuiInterface.prototype.GetStartedResearc 668 668 } 669 669 return ret; 670 670 }; 671 671 672 672 // Returns the battle state of the player. 673 GuiInterface.prototype.GetBattleState = function(player , viewedPlayer)673 GuiInterface.prototype.GetBattleState = function(player) 674 674 { 675 let cmpBattleDetection = QueryPlayerIDInterface( viewedPlayer, IID_BattleDetection);675 let cmpBattleDetection = QueryPlayerIDInterface(player, IID_BattleDetection); 676 676 677 677 if (!cmpBattleDetection) 678 678 return false; 679 679 680 680 return cmpBattleDetection.GetState(); … … GuiInterface.prototype.AddTimeNotificati 724 724 GuiInterface.prototype.DeleteTimeNotification = function(notificationID) 725 725 { 726 726 this.timeNotifications = this.timeNotifications.filter(n => n.id != notificationID); 727 727 }; 728 728 729 GuiInterface.prototype.GetTimeNotifications = function(player ID, viewedPlayer)729 GuiInterface.prototype.GetTimeNotifications = function(player) 730 730 { 731 731 let time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime(); 732 732 // filter on players and time, since the delete timer might be executed with a delay 733 return this.timeNotifications.filter(n => n.players.indexOf( viewedPlayer) != -1 && n.endTime > time);733 return this.timeNotifications.filter(n => n.players.indexOf(player) != -1 && n.endTime > time); 734 734 }; 735 735 736 736 GuiInterface.prototype.PushNotification = function(notification) 737 737 { 738 738 if (!notification.type || notification.type == "text") … … GuiInterface.prototype.SetStatusBars = f 887 887 if (cmpStatusBars) 888 888 cmpStatusBars.RegenerateSprites(); 889 889 } 890 890 }; 891 891 892 GuiInterface.prototype.GetPlayerEntities = function(player , data)892 GuiInterface.prototype.GetPlayerEntities = function(player) 893 893 { 894 return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer( data.viewedPlayer);894 return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer(player); 895 895 }; 896 896 897 897 GuiInterface.prototype.GetNonGaiaEntities = function() 898 898 { 899 899 return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities(); … … GuiInterface.prototype.PlaySound = funct 1647 1647 }; 1648 1648 1649 1649 /** 1650 1650 * Find any idle units. 1651 1651 * 1652 * @param data.viewedPlayer The player for which to find idle units.1653 1652 * @param data.idleClasses Array of class names to include. 1654 1653 * @param data.prevUnit The previous idle unit, if calling a second time to iterate through units. May be left undefined. 1655 1654 * @param data.limit The number of idle units to return. May be left undefined (will return all idle units). 1656 1655 * @param data.excludeUnits Array of units to exclude. 1657 1656 * … … GuiInterface.prototype.FindIdleUnits = f 1662 1661 { 1663 1662 let idleUnits = []; 1664 1663 // The general case is that only the 'first' idle unit is required; filtering would examine every unit. 1665 1664 // This loop imitates a grouping/aggregation on the first matching idle class. 1666 1665 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 1667 for (let entity of cmpRangeManager.GetEntitiesByPlayer( data.viewedPlayer))1666 for (let entity of cmpRangeManager.GetEntitiesByPlayer(player)) 1668 1667 { 1669 1668 let filtered = this.IdleUnitFilter(entity, data.idleClasses, data.excludeUnits); 1670 1669 if (!filtered.idle) 1671 1670 continue; 1672 1671 … … GuiInterface.prototype.FindIdleUnits = f 1693 1692 }; 1694 1693 1695 1694 /** 1696 1695 * Discover if the player has idle units. 1697 1696 * 1698 * @param data.viewedPlayer The player for which to find idle units.1699 1697 * @param data.idleClasses Array of class names to include. 1700 1698 * @param data.excludeUnits Array of units to exclude. 1701 1699 * 1702 1700 * Returns a boolean of whether the player has any idle units 1703 1701 */ 1704 1702 GuiInterface.prototype.HasIdleUnits = function(player, data) 1705 1703 { 1706 1704 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 1707 return cmpRangeManager.GetEntitiesByPlayer( data.viewedPlayer).some(unit => this.IdleUnitFilter(unit, data.idleClasses, data.excludeUnits).idle);1705 return cmpRangeManager.GetEntitiesByPlayer(player).some(unit => this.IdleUnitFilter(unit, data.idleClasses, data.excludeUnits).idle); 1708 1706 }; 1709 1707 1710 1708 /** 1711 1709 * Whether to filter an idle unit 1712 1710 * … … GuiInterface.prototype.SetMotionDebugOve 1865 1863 GuiInterface.prototype.SetRangeDebugOverlay = function(player, enabled) 1866 1864 { 1867 1865 Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetDebugOverlay(enabled); 1868 1866 }; 1869 1867 1870 GuiInterface.prototype.GetTraderNumber = function(player , viewedPlayer)1868 GuiInterface.prototype.GetTraderNumber = function(player) 1871 1869 { 1872 1870 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 1873 let traders = cmpRangeManager.GetEntitiesByPlayer( viewedPlayer).filter(e => Engine.QueryInterface(e, IID_Trader));1871 let traders = cmpRangeManager.GetEntitiesByPlayer(player).filter(e => Engine.QueryInterface(e, IID_Trader)); 1874 1872 1875 1873 let landTrader = { "total": 0, "trading": 0, "garrisoned": 0 }; 1876 1874 let shipTrader = { "total": 0, "trading": 0 }; 1877 1875 1878 1876 for each (let ent in traders) … … GuiInterface.prototype.GetTraderNumber = 1904 1902 } 1905 1903 1906 1904 return { "landTrader": landTrader, "shipTrader": shipTrader }; 1907 1905 }; 1908 1906 1909 GuiInterface.prototype.GetTradingGoods = function(player , viewedPlayer)1907 GuiInterface.prototype.GetTradingGoods = function(player) 1910 1908 { 1911 return QueryPlayerIDInterface( viewedPlayer).GetTradingGoods();1909 return QueryPlayerIDInterface(player).GetTradingGoods(); 1912 1910 }; 1913 1911 1914 1912 GuiInterface.prototype.OnGlobalEntityRenamed = function(msg) 1915 1913 { 1916 1914 this.renamedEntities.push(msg); -
source/gui/scripting/ScriptFunctions.cpp
JS::Value GuiInterfaceCall(ScriptInterfa 121 121 122 122 CmpPtr<ICmpGuiInterface> cmpGuiInterface(*sim, SYSTEM_ENTITY); 123 123 if (!cmpGuiInterface) 124 124 return JS::UndefinedValue(); 125 125 126 int player = g_Game->GetPlayerID();127 128 126 JSContext* cxSim = sim->GetScriptInterface().GetContext(); 129 127 JSAutoRequest rqSim(cxSim); 130 128 JS::RootedValue arg(cxSim, sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), data)); 131 129 JS::RootedValue ret(cxSim); 132 cmpGuiInterface->ScriptCall( player, name, arg, &ret);130 cmpGuiInterface->ScriptCall(g_Game->GetViewedPlayerID(), name, arg, &ret); 133 131 134 132 return pCxPrivate->pScriptInterface->CloneValueFromOtherContext(sim->GetScriptInterface(), ret); 135 133 } 136 134 137 135 void PostNetworkCommand(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue cmd)