Ticket #3999: 3999_guiinterface_cleanup_v1.patch

File 3999_guiinterface_cleanup_v1.patch, 8.5 KB (added by elexis, 8 years ago)
  • binaries/data/mods/public/simulation/components/GuiInterface.js

    GuiInterface.prototype.Init = function()  
    4646
    4747/**
    4848 * Returns global information about the current game state.
    4949 * This is used by the GUI and also by AI scripts.
    5050 */
    51 GuiInterface.prototype.GetSimulationState = function(player)
     51GuiInterface.prototype.GetSimulationState = function()
    5252{
    5353    let ret = {
    5454        "players": []
    5555    };
    5656
    GuiInterface.prototype.GetSimulationStat  
    167167 * Returns global information about the current game state, plus statistics.
    168168 * This is used by the GUI at the end of a game, in the summary screen.
    169169 * Note: Amongst statistics, the team exploration map percentage is computed from
    170170 * scratch, so the extended simulation state should not be requested too often.
    171171 */
    172 GuiInterface.prototype.GetExtendedSimulationState = function(player)
     172GuiInterface.prototype.GetExtendedSimulationState = function()
    173173{
    174174    // Get basic simulation info
    175175    let ret = this.GetSimulationState();
    176176
    177177    // Add statistics to each player
    GuiInterface.prototype.GetRenamedEntitie  
    194194        return this.renamedEntities.concat(this.miragedEntities[player]);
    195195    else
    196196        return this.renamedEntities;
    197197};
    198198
    199 GuiInterface.prototype.ClearRenamedEntities = function(player)
     199GuiInterface.prototype.ClearRenamedEntities = function()
    200200{
    201201    this.renamedEntities = [];
    202202    this.miragedEntities = [];
    203203};
    204204
    GuiInterface.prototype.CheckTechnologyRe  
    648648    return cmpTechnologyManager.CanResearch(data.tech);
    649649};
    650650
    651651// Returns technologies that are being actively researched, along with
    652652// which entity is researching them and how far along the research is.
    653 GuiInterface.prototype.GetStartedResearch = function(player, viewedPlayer)
     653GuiInterface.prototype.GetStartedResearch = function(player)
    654654{
    655     let cmpTechnologyManager = QueryPlayerIDInterface(viewedPlayer, IID_TechnologyManager);
     655    let cmpTechnologyManager = QueryPlayerIDInterface(player, IID_TechnologyManager);
    656656    if (!cmpTechnologyManager)
    657657        return {};
    658658
    659659    let ret = {};
    660660    for (let tech in cmpTechnologyManager.GetTechsStarted())
    GuiInterface.prototype.GetStartedResearc  
    668668    }
    669669    return ret;
    670670};
    671671
    672672// Returns the battle state of the player.
    673 GuiInterface.prototype.GetBattleState = function(player, viewedPlayer)
     673GuiInterface.prototype.GetBattleState = function(player)
    674674{
    675     let cmpBattleDetection = QueryPlayerIDInterface(viewedPlayer, IID_BattleDetection);
     675    let cmpBattleDetection = QueryPlayerIDInterface(player, IID_BattleDetection);
    676676
    677677    if (!cmpBattleDetection)
    678678        return false;
    679679
    680680    return cmpBattleDetection.GetState();
    GuiInterface.prototype.AddTimeNotificati  
    724724GuiInterface.prototype.DeleteTimeNotification = function(notificationID)
    725725{
    726726    this.timeNotifications = this.timeNotifications.filter(n => n.id != notificationID);
    727727};
    728728
    729 GuiInterface.prototype.GetTimeNotifications = function(playerID, viewedPlayer)
     729GuiInterface.prototype.GetTimeNotifications = function(player)
    730730{
    731731    let time = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).GetTime();
    732732    // 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);
    734734};
    735735
    736736GuiInterface.prototype.PushNotification = function(notification)
    737737{
    738738    if (!notification.type || notification.type == "text")
    GuiInterface.prototype.SetStatusBars = f  
    887887        if (cmpStatusBars)
    888888            cmpStatusBars.RegenerateSprites();
    889889    }
    890890};
    891891
    892 GuiInterface.prototype.GetPlayerEntities = function(player, data)
     892GuiInterface.prototype.GetPlayerEntities = function(player)
    893893{
    894     return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer(data.viewedPlayer);
     894    return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetEntitiesByPlayer(player);
    895895};
    896896
    897897GuiInterface.prototype.GetNonGaiaEntities = function()
    898898{
    899899    return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities();
    GuiInterface.prototype.PlaySound = funct  
    16471647};
    16481648
    16491649/**
    16501650 * Find any idle units.
    16511651 *
    1652  * @param data.viewedPlayer The player for which to find idle units.
    16531652 * @param data.idleClasses      Array of class names to include.
    16541653 * @param data.prevUnit     The previous idle unit, if calling a second time to iterate through units.  May be left undefined.
    16551654 * @param data.limit            The number of idle units to return.  May be left undefined (will return all idle units).
    16561655 * @param data.excludeUnits Array of units to exclude.
    16571656 *
    GuiInterface.prototype.FindIdleUnits = f  
    16621661{
    16631662    let idleUnits = [];
    16641663    // The general case is that only the 'first' idle unit is required; filtering would examine every unit.
    16651664    // This loop imitates a grouping/aggregation on the first matching idle class.
    16661665    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))
    16681667    {
    16691668        let filtered = this.IdleUnitFilter(entity, data.idleClasses, data.excludeUnits);
    16701669        if (!filtered.idle)
    16711670            continue;
    16721671
    GuiInterface.prototype.FindIdleUnits = f  
    16931692};
    16941693
    16951694/**
    16961695 * Discover if the player has idle units.
    16971696 *
    1698  * @param data.viewedPlayer The player for which to find idle units.
    16991697 * @param data.idleClasses  Array of class names to include.
    17001698 * @param data.excludeUnits Array of units to exclude.
    17011699 *
    17021700 * Returns a boolean of whether the player has any idle units
    17031701 */
    17041702GuiInterface.prototype.HasIdleUnits = function(player, data)
    17051703{
    17061704    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);
    17081706};
    17091707
    17101708/**
    17111709 * Whether to filter an idle unit
    17121710 *
    GuiInterface.prototype.SetMotionDebugOve  
    18651863GuiInterface.prototype.SetRangeDebugOverlay = function(player, enabled)
    18661864{
    18671865    Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetDebugOverlay(enabled);
    18681866};
    18691867
    1870 GuiInterface.prototype.GetTraderNumber = function(player, viewedPlayer)
     1868GuiInterface.prototype.GetTraderNumber = function(player)
    18711869{
    18721870    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));
    18741872
    18751873    let landTrader = { "total": 0, "trading": 0, "garrisoned": 0 };
    18761874    let shipTrader = { "total": 0, "trading": 0 };
    18771875
    18781876    for each (let ent in traders)
    GuiInterface.prototype.GetTraderNumber =  
    19041902    }
    19051903
    19061904    return { "landTrader": landTrader, "shipTrader": shipTrader };
    19071905};
    19081906
    1909 GuiInterface.prototype.GetTradingGoods = function(player, viewedPlayer)
     1907GuiInterface.prototype.GetTradingGoods = function(player)
    19101908{
    1911     return QueryPlayerIDInterface(viewedPlayer).GetTradingGoods();
     1909    return QueryPlayerIDInterface(player).GetTradingGoods();
    19121910};
    19131911
    19141912GuiInterface.prototype.OnGlobalEntityRenamed = function(msg)
    19151913{
    19161914    this.renamedEntities.push(msg);
  • source/gui/scripting/ScriptFunctions.cpp

    JS::Value GuiInterfaceCall(ScriptInterfa  
    121121
    122122    CmpPtr<ICmpGuiInterface> cmpGuiInterface(*sim, SYSTEM_ENTITY);
    123123    if (!cmpGuiInterface)
    124124        return JS::UndefinedValue();
    125125
    126     int player = g_Game->GetPlayerID();
    127 
    128126    JSContext* cxSim = sim->GetScriptInterface().GetContext();
    129127    JSAutoRequest rqSim(cxSim);
    130128    JS::RootedValue arg(cxSim, sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), data));
    131129    JS::RootedValue ret(cxSim);
    132     cmpGuiInterface->ScriptCall(player, name, arg, &ret);
     130    cmpGuiInterface->ScriptCall(g_Game->GetViewedPlayerID(), name, arg, &ret);
    133131
    134132    return pCxPrivate->pScriptInterface->CloneValueFromOtherContext(sim->GetScriptInterface(), ret);
    135133}
    136134
    137135void PostNetworkCommand(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue cmd)