Ticket #2030: saveAs.patch

File saveAs.patch, 7.2 KB (added by Crynux, 11 years ago)

patch file

  • binaries/data/mods/public/gui/savedgames/load.js

    diff --git a/binaries/data/mods/public/gui/savedgames/load.js b/binaries/data/mods/public/gui/savedgames/load.js
    index de1150c..9e38cb6 100644
    a b function generateLabel(metadata)  
    1414
    1515    var date = t.getFullYear()+"-"+twoDigits(1+t.getMonth())+"-"+twoDigits(t.getDate());
    1616    var time = twoDigits(t.getHours())+":"+twoDigits(t.getMinutes())+":"+twoDigits(t.getSeconds());
    17     return "["+date+" "+time+"] "+metadata.initAttributes.map;
     17    return "["+date+" "+time+"] "+metadata.initAttributes.map+(metadata.savename?" ("+metadata.savename+")":"");
    1818}
    1919
    2020function init()
  • binaries/data/mods/public/gui/session/menu.js

    diff --git a/binaries/data/mods/public/gui/session/menu.js b/binaries/data/mods/public/gui/session/menu.js
    index ae3b5b6..5f7e9e8 100644
    a b const RESUME = "Resume";  
    99const MARGIN = 4;
    1010
    1111// Includes the main menu button
    12 const NUM_BUTTONS = 8;
     12const NUM_BUTTONS = 9;
    1313
    1414// Regular menu buttons
    1515const BUTTON_HEIGHT = 32;
    function exitMenuButton()  
    148148    messageBox(400, 200, "Are you sure you want to quit?", "Confirmation", 0, btCaptions, btCode);
    149149}
    150150
     151function openSaveAs()
     152{
     153    closeMenu();
     154    closeOpenDialogs();
     155    pauseGame();
     156   
     157    getGUIObjectByName("saveAsPanel").focus();
     158    getGUIObjectByName("saveAsPanel").hidden = false;
     159   
     160}
     161
     162function closeSaveAs()
     163{
     164    getGUIObjectByName("saveAsPanel").hidden = true;
     165
     166    resumeGame();
     167}
     168
     169
    151170function openDeleteDialog(selection)
    152171{
    153172    closeMenu();
  • binaries/data/mods/public/gui/session/session.xml

    diff --git a/binaries/data/mods/public/gui/session/session.xml b/binaries/data/mods/public/gui/session/session.xml
    index 38d2e5b..583470d 100644
    a b  
    427427    </object>
    428428
    429429    <!-- ================================  ================================ -->
     430    <!-- Save As Window -->
     431    <!-- ================================  ================================ -->
     432        <object name="saveAsPanel"
     433            style="StoneDialog"
     434            type="image"
     435            size="50%-180 50%-64 50%+180 50%+64"
     436            hidden="true"
     437            z="200"
     438            >
     439            <object type="text" style="TitleText" size="50%-96 -16 50%+96 16">Save Game As</object>
     440            <object size="25%-64 35%-12 25%+64 35%+12" type="text"  style="LeftLabelText">
     441                Save As:
     442            </object>
     443            <object name="savegameName" size="25% 35%-12 95%-8 35%+12" type="input" style="StoneInput" max_length="80">
     444                savegame
     445            </object>
     446
     447            <!-- Cancel button -->
     448            <object type="button"
     449                style="StoneButton"
     450                size="75%-64 100%-52 75%+64 100%-24"
     451                tooltip_style="sessionToolTip"
     452                >
     453                Cancel
     454                <action on="Press">closeSaveAs();</action>
     455            </object>
     456            <!-- Save button -->
     457            <object type="button"
     458                style="StoneButton"
     459                size="25%-64 100%-52 25%+64 100%-24"
     460                tooltip_style="sessionToolTip"
     461                >
     462                Save
     463                <action on="Press">closeSaveAs();Engine.SaveGameAs(getGUIObjectByName("savegameName").caption);</action>
     464            </object>
     465        </object>
     466
     467    <!-- ================================  ================================ -->
    430468    <!-- Settings Window -->
    431469    <!-- ================================  ================================ -->
    432470        <object name="settingsDialogPanel"
     
    707745            </action>
    708746        </object>
    709747
     748        <!-- Save game as button -->
     749        <object type="button"
     750            name="saveGameAsButton"
     751            style="StoneButtonFancy"
     752            size="0 64 100% 92"
     753            tooltip_style="sessionToolTip"
     754        >
     755            Save As
     756            <action on="Press">
     757           
     758            openSaveAs();
     759            </action>
     760        </object>
     761
    710762        <!-- Chat button -->
    711763        <object type="button"
    712764            name="chatButton"
    713765            style="StoneButtonFancy"
    714             size="0 64 100% 92"
     766            size="0 96 100% 124"
    715767            tooltip_style="sessionToolTip"
    716768        >
    717769            Chat
     
    722774        <object type="button"
    723775            name="menuResignButton"
    724776            style="StoneButtonFancy"
    725             size="0 96 100% 124"
     777            size="0 128 100% 156"
    726778            tooltip_style="sessionToolTip"
    727779        >
    728780            Resign
     
    733785        <object type="button"
    734786            name="menuExitButton"
    735787            style="StoneButtonFancy"
    736             size="0 128 100% 156"
     788            size="0 160 100% 188"
    737789            tooltip_style="sessionToolTip"
    738790        >
    739791            Exit
     
    744796        <object type="button"
    745797            name="pauseButton"
    746798            style="StoneButtonFancy"
    747             size="0 160 100% 188"
     799            size="0 192 100% 220"
    748800            tooltip_style="sessionToolTip"
    749801        >
    750802            <object name="pauseButtonText" type="text" style="CenteredButtonText" ghost="true">Pause</object>
     
    755807        <object type="button"
    756808            name="manualButton"
    757809            style="StoneButtonFancy"
    758             size="0 192 100% 220"
     810            size="0 224 100% 252"
    759811            tooltip_style="sessionToolTip"
    760812        >
    761813            Manual
  • source/gui/scripting/ScriptFunctions.cpp

    diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp
    index dd530cb..b8febdc 100644
    a b void SaveGame(void* cbdata)  
    266266        LOGERROR(L"Failed to save game");
    267267}
    268268
     269void SaveGameAs(void* cbdata, std::wstring prefix)
     270{
     271    CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
     272
     273    if (SavedGames::Save(prefix, *g_Game->GetSimulation2(), guiManager, g_Game->GetPlayerID()) < 0)
     274        LOGERROR(L"Failed to save game as");
     275}
     276
    269277void SetNetworkGameAttributes(void* cbdata, CScriptVal attribs)
    270278{
    271279    CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
    void GuiScriptingInit(ScriptInterface& scriptInterface)  
    670678    scriptInterface.RegisterFunction<std::vector<CScriptValRooted>, &GetSavedGames>("GetSavedGames");
    671679    scriptInterface.RegisterFunction<bool, std::wstring, &DeleteSavedGame>("DeleteSavedGame");
    672680    scriptInterface.RegisterFunction<void, &SaveGame>("SaveGame");
     681    scriptInterface.RegisterFunction<void, std::wstring, &SaveGameAs>("SaveGameAs");
    673682    scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave");
    674683    scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad");
    675684
  • source/ps/SavedGame.cpp

    diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp
    index 20bb944..837fafa 100644
    a b  
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2013 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    Status SavedGames::Save(const std::wstring& prefix, CSimulation2& simulation, CG  
    6868    simulation.GetScriptInterface().SetProperty(metadata.get(), "version_minor", SAVED_GAME_VERSION_MINOR);
    6969    simulation.GetScriptInterface().SetProperty(metadata.get(), "time", (double)now);
    7070    simulation.GetScriptInterface().SetProperty(metadata.get(), "player", playerID);
     71    simulation.GetScriptInterface().SetProperty(metadata.get(), "savename", prefix);
    7172    simulation.GetScriptInterface().SetProperty(metadata.get(), "initAttributes", simulation.GetInitAttributes());
    7273    if (gui)
    7374    {
  • source/ps/SavedGame.h

    diff --git a/source/ps/SavedGame.h b/source/ps/SavedGame.h
    index 019f31b..93f8881 100644
    a b  
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2013 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify