Ticket #3437: replaybutton_v3.1.patch

File replaybutton_v3.1.patch, 5.4 KB (added by Imarok, 8 years ago)

Adds a button which replays the game to the summary of a quit game or the summary preview of a replay or the summary of a replay

  • binaries/data/mods/public/gui/replaymenu/replay_actions.js

     
    7979    // Open summary screen
    8080    summary.isReplay = true;
    8181    summary.gameResult = translate("Scores at the end of the game.");
     82    summary.replayDirectory = g_ReplaysFiltered[selected].directory;
    8283    Engine.SwitchGuiPage("page_summary.xml", summary);
    8384}
    8485
  • binaries/data/mods/public/gui/session/session.js

     
    472472    if (!g_IsReplay)
    473473        Engine.SaveReplayMetadata(JSON.stringify(summary));
    474474
     475    summary.replayDirectory = Engine.GetCurrentReplayFile();
     476
    475477    Engine.EndGame();
    476478
    477479    if (g_IsController && Engine.HasXmppClient())
  • binaries/data/mods/public/gui/summary/summary.js

     
    129129        teamCounterFn(panelInfo.counters);
    130130}
    131131
     132function startReplay()
     133{
     134    if (Engine.HasXmppClient())
     135        Engine.StopXmppClient();
     136
     137    Engine.StartVisualReplay(g_GameData.replayDirectory);
     138    Engine.SwitchGuiPage("page_loading.xml", {
     139        "attribs": Engine.GetReplayAttributes(g_GameData.replayDirectory),
     140        "isNetworked" : false,
     141        "playerAssignments": {
     142            "local":{
     143                "name": translate("You"),
     144                "player": -1
     145            }
     146        },
     147        "savedGUIData": "",
     148        "isReplay" : true
     149    });
     150}
     151
    132152function init(data)
    133153{
    134154    updateObjectPlayerPosition();
     
    139159    Engine.GetGUIObjectByName("timeElapsed").caption = sprintf(translate("Game time elapsed: %(time)s"), { "time": timeToString(data.timeElapsed) });
    140160    Engine.GetGUIObjectByName("summaryText").caption = data.gameResult;
    141161    Engine.GetGUIObjectByName("mapName").caption = sprintf(translate("%(mapName)s - %(mapType)s"), { "mapName": translate(data.mapSettings.Name), "mapType": mapSize ? mapSize.LongName : (mapType ? mapType.Title : "") });
     162    Engine.GetGUIObjectByName("replayButton").hidden = g_GameData.isInGame || !g_GameData.replayDirectory;
    142163
    143164    // Panels
    144165    g_PlayerCount = data.playerStates.length - 1;
  • binaries/data/mods/public/gui/summary/summary.xml

     
    157157            </object>
    158158        </object>
    159159
     160        <object type="button" name="replayButton" style="ModernButtonRed" size="100%-310 100%-48 100%-170 100%-20">
     161            <translatableAttribute id="caption">Replay</translatableAttribute>
     162            <action on="Press"><![CDATA[
     163                if (!g_GameData.isInGame)
     164                {
     165                    if (Engine.HasXmppClient())
     166                        messageBox(
     167                            400, 200,
     168                            translate("Are you sure you want to quit the lobby?"),
     169                            translate("Confirmation"),
     170                            0,
     171                            [translate("No"), translate("Yes")],
     172                            [null, startReplay]
     173                        );
     174                    else
     175                        startReplay();
     176                }
     177                ]]>
     178            </action>
     179        </object>
     180
    160181        <object type="button" style="ModernButtonRed" size="100%-160 100%-48 100%-20 100%-20">
    161182            <translatableAttribute id="caption">Continue</translatableAttribute>
    162183            <action on="Press"><![CDATA[
  • source/gui/scripting/ScriptFunctions.cpp

     
    5050#include "ps/Hotkey.h"
    5151#include "ps/ProfileViewer.h"
    5252#include "ps/Pyrogenesis.h"
     53#include "ps/Replay.h"
    5354#include "ps/SavedGame.h"
    5455#include "ps/UserReport.h"
    5556#include "ps/World.h"
     
    902903    return width;
    903904}
    904905
     906OsPath GetCurrentReplayFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
     907{
     908    if (g_Game->GetReplayLogger().GetDirectory().Filename() != "")
     909        return g_Game->GetReplayLogger().GetDirectory().Filename();
     910    else
     911    {
     912        OsPath dir = OsPath(g_Game->GetReplayPath());
     913        dir = dir.BeforeCommon(dir.Filename());
     914        dir = dir.Parent().Filename();
     915        return dir.Filename();
     916    }
     917}
     918
    905919//-----------------------------------------------------------------------------
    906920// Timer
    907921//-----------------------------------------------------------------------------
     
    10791093    scriptInterface.RegisterFunction<bool, std::string, &TemplateExists>("TemplateExists");
    10801094    scriptInterface.RegisterFunction<CParamNode, std::string, &GetTemplate>("GetTemplate");
    10811095    scriptInterface.RegisterFunction<int, CStr, CStrW, &GetTextWidth>("GetTextWidth");
     1096    scriptInterface.RegisterFunction<OsPath, &GetCurrentReplayFile>("GetCurrentReplayFile");
    10821097
    10831098    // User report functions
    10841099    scriptInterface.RegisterFunction<bool, &IsUserReportEnabled>("IsUserReportEnabled");
  • source/ps/Game.h

     
    161161    inline float GetSimRate() const
    162162    {   return m_SimRate; }
    163163
     164    inline std::string GetReplayPath() const
     165    {
     166        return m_ReplayPath;
     167    }
     168
    164169    /**
    165170     * Replace the current turn manager.
    166171     * This class will take ownership of the pointer.