Ticket #3841: 3841_ingame_summary_v1.4.patch

File 3841_ingame_summary_v1.4.patch, 10.0 KB (added by Imarok, 2 years ago)

adapted guiInterface tests; create and use Player.prototype.HasSharedLos?

  • binaries/data/mods/public/gui/session/menu.js

     
    620620    Engine.PushGuiPage("page_summary.xml", {
    621621        "sim": {
    622622            "mapSettings": g_GameAttributes.settings,
    623             "playerStates": extendedSimState.players,
     623            "playerStates":extendedSimState.players.filter((state,player) =>
     624                g_IsObserver || player == 0 || player == g_ViewedPlayer ||
     625                extendedSimState.players[g_ViewedPlayer].hasSharedLos && g_Players[player].isMutualAlly[g_ViewedPlayer]),
    624626            "timeElapsed" : extendedSimState.timeElapsed
    625627        },
    626628        "gui": {
  • binaries/data/mods/public/gui/session/menu.xml

     
    4848            style="StoneButtonFancy"
    4949            size="0 96 100% 124"
    5050            tooltip_style="sessionToolTip"
    51             enabled="false"
    5251        >
    5352            <translatableAttribute id="caption">Summary</translatableAttribute>
    5453            <action on="Press">openGameSummary();</action>
  • binaries/data/mods/public/gui/session/session.js

     
    480480    // Disable stuff observers shouldn't use
    481481    Engine.GetGUIObjectByName("pauseButton").enabled = !g_IsObserver || !g_IsNetworked;
    482482    Engine.GetGUIObjectByName("menuResignButton").enabled = !g_IsObserver;
    483     Engine.GetGUIObjectByName("summaryButton").enabled = g_IsObserver;
    484483}
    485484
    486485function reportPerformance(time)
     
    933932    debug.caption = text.replace(/\[/g, "\\[");
    934933}
    935934
     935function getAllyStatTooltip(resource)
     936{
     937    let playersState = GetSimState().players;
     938    let ret = "";
     939    for (let player in playersState)
     940        if (player != 0 && player != g_ViewedPlayer &&
     941            (g_IsObserver || playersState[g_ViewedPlayer].hasSharedLos && g_Players[player].isMutualAlly[g_ViewedPlayer]))
     942            ret += sprintf(translate("\n%(playername)s: %(statValue)s"),{
     943                "playername": colorizePlayernameByID(player),
     944                "statValue": resource == "pop" ?
     945                    playersState[player].popCount + "/" + playersState[player].popLimit :
     946                    playersState[player].resourceCounts[resource]
     947            });
     948    return ret;
     949}
     950
    936951function updatePlayerDisplay()
    937952{
    938953    let playerState = GetSimState().players[g_ViewedPlayer];
     
    939954    if (!playerState)
    940955        return;
    941956
    942     Engine.GetGUIObjectByName("resourceFood").caption = Math.floor(playerState.resourceCounts.food);
    943     Engine.GetGUIObjectByName("resourceWood").caption = Math.floor(playerState.resourceCounts.wood);
    944     Engine.GetGUIObjectByName("resourceStone").caption = Math.floor(playerState.resourceCounts.stone);
    945     Engine.GetGUIObjectByName("resourceMetal").caption = Math.floor(playerState.resourceCounts.metal);
     957    for (let res of RESOURCES)
     958    {
     959        Engine.GetGUIObjectByName("resource_" + res).caption = Math.floor(playerState.resourceCounts[res]);
     960        Engine.GetGUIObjectByName(res).tooltip = localisedResourceNames.firstWord[res] + getAllyStatTooltip(res);
     961    }
    946962    Engine.GetGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit;
    947963    Engine.GetGUIObjectByName("population").tooltip = translate("Population (current / limit)") + "\n" +
    948                     sprintf(translate("Maximum population: %(popCap)s"), { "popCap": playerState.popMax });
     964        sprintf(translate("Maximum population: %(popCap)s"), { "popCap": playerState.popMax }) +
     965        getAllyStatTooltip("pop");
    949966
    950967    g_IsTrainingBlocked = playerState.trainingBlocked;
    951968}
  • binaries/data/mods/public/gui/session/top_panel/resource_food.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<object name="food" size="10 0 100 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <translatableAttribute id="tooltip">Food</translatableAttribute>
    43        <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/food.png" ghost="true"/>
    5         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceFood"/>
     4        <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_food"/>
    65</object>
  • binaries/data/mods/public/gui/session/top_panel/resource_metal.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<object name="metal" size="280 0 370 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <translatableAttribute id="tooltip">Metal</translatableAttribute>
    43        <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/metal.png" ghost="true"/>
    5         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceMetal"/>
     4        <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_metal"/>
    65</object>
  • binaries/data/mods/public/gui/session/top_panel/resource_stone.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<object name="stone" size="190 0 280 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <translatableAttribute id="tooltip">Stone</translatableAttribute>
    43        <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/stone.png" ghost="true"/>
    5         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceStone"/>
     4        <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_stone"/>
    65</object>
  • binaries/data/mods/public/gui/session/top_panel/resource_wood.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22<object name="wood" size="100 0 190 100%" type="image" style="resourceCounter" tooltip_style="sessionToolTipBold">
    3         <translatableAttribute id="tooltip">Wood</translatableAttribute>
    43        <object size="0 -4 40 36" type="image" sprite="stretched:session/icons/resources/wood.png" ghost="true"/>
    5         <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resourceWood"/>
     4        <object size="32 0 100% 100%-2" type="text" style="resourceText" name="resource_wood"/>
    65</object>
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    107107            "cheatsEnabled": cmpPlayer.GetCheatsEnabled(),
    108108            "disabledTemplates": cmpPlayer.GetDisabledTemplates(),
    109109            "hasSharedDropsites": cmpPlayer.HasSharedDropsites(),
     110            "hasSharedLos": cmpPlayer.HasSharedLos(),
    110111            "phase": phase,
    111112            "isAlly": allies,
    112113            "isMutualAlly": mutualAllies,
  • binaries/data/mods/public/simulation/components/Player.js

     
    545545    return this.startCam !== undefined;
    546546};
    547547
     548Player.prototype.HasSharedLos = function()
     549{
     550    let cmpTechnologyManager = Engine.QueryInterface(this.entity, IID_TechnologyManager);
     551    return cmpTechnologyManager && cmpTechnologyManager.IsTechnologyResearched(this.template.SharedLosTech);
     552};
    548553Player.prototype.HasSharedDropsites = function()
    549554{
    550555    return this.sharedDropsites;
  • binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js

     
    9191    IsEnemy: function() { return true; },
    9292    GetDisabledTemplates: function() { return {}; },
    9393    HasSharedDropsites: function() { return false; },
     94    HasSharedLos: function() { return false; },
    9495});
    9596
    9697AddMock(100, IID_EntityLimits, {
     
    174175    IsEnemy: function() { return false; },
    175176    GetDisabledTemplates: function() { return {}; },
    176177    HasSharedDropsites: function() { return false; },
     178    HasSharedLos: function() { return false; },
    177179});
    178180
    179181AddMock(101, IID_EntityLimits, {
     
    257259            cheatsEnabled: false,
    258260            disabledTemplates: {},
    259261            hasSharedDropsites: false,
     262            hasSharedLos: false,
    260263            phase: "village",
    261264            isAlly: [false, false],
    262265            isMutualAlly: [false, false],
     
    298301            cheatsEnabled: false,
    299302            disabledTemplates: {},
    300303            hasSharedDropsites: false,
     304            hasSharedLos: false,
    301305            phase: "village",
    302306            isAlly: [true, true],
    303307            isMutualAlly: [false, false],
     
    348352            cheatsEnabled: false,
    349353            disabledTemplates: {},
    350354            hasSharedDropsites: false,
     355            hasSharedLos: false,
    351356            phase: "village",
    352357            isAlly: [false, false],
    353358            isMutualAlly: [false, false],
     
    402407            cheatsEnabled: false,
    403408            disabledTemplates: {},
    404409            hasSharedDropsites: false,
     410            hasSharedLos: false,
    405411            phase: "village",
    406412            isAlly: [true, true],
    407413            isMutualAlly: [false, false],