Ticket #3742: restore_selection_v2.4.patch
File restore_selection_v2.4.patch, 11.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/replaymenu/replay_actions.js
1 1 /** 2 * Creates the data for restoring selection, order and filters when returning to the replay menu 3 */ 4 function createReplaySelectionData(selectedDirectory) 5 { 6 let replaySelection = Engine.GetGUIObjectByName("replaySelection"); 7 let dateTimeFilter = Engine.GetGUIObjectByName("dateTimeFilter"); 8 let mapNameFilter = Engine.GetGUIObjectByName("mapNameFilter"); 9 let mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter"); 10 let populationFilter = Engine.GetGUIObjectByName("populationFilter"); 11 let durationFilter = Engine.GetGUIObjectByName("durationFilter"); 12 return { 13 "directory": selectedDirectory, 14 "column": replaySelection.selected_column, 15 "columnOrder": replaySelection.selected_column_order, 16 "filters": { 17 "date": dateTimeFilter.list_data[dateTimeFilter.selected], 18 "playernames": Engine.GetGUIObjectByName("playersFilter").caption, 19 "mapName": mapNameFilter.list_data[mapNameFilter.selected], 20 "mapSize": mapSizeFilter.list_data[mapSizeFilter.selected], 21 "popCap": populationFilter.list_data[populationFilter.selected], 22 "duration": durationFilter.list_data[durationFilter.selected] 23 } 24 } 25 } 26 /** 2 27 * Starts the selected visual replay, or shows an error message in case of incompatibility. 3 28 */ 4 29 function startReplay() … … 25 50 Engine.StartVisualReplay(replayDirectory); 26 51 Engine.SwitchGuiPage("page_loading.xml", { 27 52 "attribs": Engine.GetReplayAttributes(replayDirectory), 28 "isNetworked" 53 "isNetworked": false, 29 54 "playerAssignments": { 30 55 "local":{ 31 56 "name": translate("You"), … … 33 58 } 34 59 }, 35 60 "savedGUIData": "", 36 "isReplay" : true 61 "isReplay": true, 62 "replaySelectionData": createReplaySelectionData(replayDirectory) 37 63 }); 38 64 } 39 65 … … 80 106 summary.isReplay = true; 81 107 summary.gameResult = translate("Scores at the end of the game."); 82 108 summary.replayDirectory = g_ReplaysFiltered[selected].directory; 109 summary.replaySelectionData = createReplaySelectionData(g_ReplaysFiltered[selected].directory); 83 110 Engine.SwitchGuiPage("page_summary.xml", summary); 84 111 } 85 112 -
binaries/data/mods/public/gui/replaymenu/replay_filters.js
21 21 * Reloads the selectable values in the filters. The filters depend on g_Settings and g_Replays 22 22 * (including its derivatives g_MapSizes, g_MapNames). 23 23 */ 24 function initFilters( )24 function initFilters(filters) 25 25 { 26 initDateFilter(); 27 initMapNameFilter(); 28 initMapSizeFilter(); 29 initPopCapFilter(); 30 initDurationFilter(); 26 if (filters && filters.playernames) 27 Engine.GetGUIObjectByName("playersFilter").caption = filters.playernames; 28 29 initDateFilter(filters && filters.date); 30 initMapSizeFilter(filters && filters.mapSize); 31 initMapNameFilter(filters && filters.mapName); 32 initPopCapFilter(filters && filters.popCap); 33 initDurationFilter(filters && filters.duration); 31 34 } 32 35 33 36 /** 34 37 * Allow to filter by month. Uses g_Replays. 35 38 */ 36 function initDateFilter( )39 function initDateFilter(date) 37 40 { 38 41 var months = g_Replays.map(replay => getReplayMonth(replay)); 39 42 months = months.filter((month, index) => months.indexOf(month) == index).sort(); 40 months.unshift(translateWithContext("datetime", "Any"));41 43 42 44 var dateTimeFilter = Engine.GetGUIObjectByName("dateTimeFilter"); 43 dateTimeFilter.list = months;44 dateTimeFilter.list_data = months;45 dateTimeFilter.list = [translateWithContext("datetime", "Any")].concat(months); 46 dateTimeFilter.list_data = [""].concat(months); 45 47 48 if (date) 49 dateTimeFilter.selected = dateTimeFilter.list_data.indexOf(date); 50 46 51 if (dateTimeFilter.selected == -1 || dateTimeFilter.selected >= dateTimeFilter.list.length) 47 52 dateTimeFilter.selected = 0; 48 53 } … … 50 55 /** 51 56 * Allow to filter by mapsize. Uses g_MapSizes. 52 57 */ 53 function initMapSizeFilter( )58 function initMapSizeFilter(mapSize) 54 59 { 55 60 var mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter"); 56 61 mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(g_MapSizes.Name); 57 62 mapSizeFilter.list_data = [-1].concat(g_MapSizes.Tiles); 58 63 64 if (mapSize) 65 mapSizeFilter.selected = mapSizeFilter.list_data.indexOf(mapSize); 66 59 67 if (mapSizeFilter.selected == -1 || mapSizeFilter.selected >= mapSizeFilter.list.length) 60 68 mapSizeFilter.selected = 0; 61 69 } … … 63 71 /** 64 72 * Allow to filter by mapname. Uses g_MapNames. 65 73 */ 66 function initMapNameFilter( )74 function initMapNameFilter(mapName) 67 75 { 68 76 var mapNameFilter = Engine.GetGUIObjectByName("mapNameFilter"); 69 mapNameFilter.list = [translateWithContext("map name", "Any")].concat(g_MapNames );70 mapNameFilter.list_data = [""].concat(g_MapNames .map(mapName => translate(mapName)));77 mapNameFilter.list = [translateWithContext("map name", "Any")].concat(g_MapNames.map(mapName => translate(mapName))); 78 mapNameFilter.list_data = [""].concat(g_MapNames); 71 79 80 if (mapName) 81 mapNameFilter.selected = mapNameFilter.list_data.indexOf(mapName); 82 72 83 if (mapNameFilter.selected == -1 || mapNameFilter.selected >= mapNameFilter.list.length) 73 84 mapNameFilter.selected = 0; 74 85 } … … 76 87 /** 77 88 * Allow to filter by population capacity. 78 89 */ 79 function initPopCapFilter( )90 function initPopCapFilter(popCap) 80 91 { 81 92 var populationFilter = Engine.GetGUIObjectByName("populationFilter"); 82 93 populationFilter.list = [translateWithContext("population capacity", "Any")].concat(g_PopulationCapacities.Title); 83 94 populationFilter.list_data = [""].concat(g_PopulationCapacities.Population); 84 95 96 if (popCap) 97 populationFilter.selected = populationFilter.list_data.indexOf(popCap); 98 85 99 if (populationFilter.selected == -1 || populationFilter.selected >= populationFilter.list.length) 86 100 populationFilter.selected = 0; 87 101 } … … 89 103 /** 90 104 * Allow to filter by game duration. Uses g_DurationFilterIntervals. 91 105 */ 92 function initDurationFilter( )106 function initDurationFilter(duration) 93 107 { 94 108 var durationFilter = Engine.GetGUIObjectByName("durationFilter"); 95 109 durationFilter.list = g_DurationFilterIntervals.map((interval, index) => { … … 110 124 }); 111 125 durationFilter.list_data = g_DurationFilterIntervals.map((interval, index) => index); 112 126 127 if (duration) 128 durationFilter.selected = durationFilter.list_data.indexOf(duration); 129 113 130 if (durationFilter.selected == -1 || durationFilter.selected >= g_DurationFilterIntervals.length) 114 131 durationFilter.selected = 0; 115 132 } -
binaries/data/mods/public/gui/replaymenu/replay_menu.js
36 36 /** 37 37 * Directory name of the currently selected replay. Used to restore the selection after changing filters. 38 38 */ 39 var g_ selectedReplayDirectory = "";39 var g_SelectedReplayDirectory = ""; 40 40 41 41 /** 42 42 * Initializes globals, loads replays and displays the list. 43 43 */ 44 function init( )44 function init(data) 45 45 { 46 46 if (!g_Settings) 47 47 { … … 49 49 return; 50 50 } 51 51 52 loadReplays( );52 loadReplays(data && data.replaySelectionData); 53 53 54 54 if (!g_Replays) 55 55 { … … 64 64 * Store the list of replays loaded in C++ in g_Replays. 65 65 * Check timestamp and compatibility and extract g_Playernames, g_MapNames 66 66 */ 67 function loadReplays( )67 function loadReplays(replaySelectionData) 68 68 { 69 69 g_Replays = Engine.GetReplays(); 70 70 … … 105 105 g_MapNames.sort(); 106 106 107 107 // Reload filters (since they depend on g_Replays and its derivatives) 108 initFilters(); 108 initFilters(replaySelectionData && replaySelectionData.filters); 109 110 if (replaySelectionData) 111 { 112 if(replaySelectionData.directory) 113 g_SelectedReplayDirectory = replaySelectionData.directory; 114 115 let replaySelection = Engine.GetGUIObjectByName("replaySelection"); 116 if (replaySelectionData.column) 117 replaySelection.selected_column = replaySelectionData.column; 118 if (replaySelectionData.columnOrder) 119 replaySelection.selected_column_order = replaySelectionData.columnOrder; 120 } 109 121 } 110 122 111 123 /** … … 152 164 // Remember previously selected replay 153 165 var replaySelection = Engine.GetGUIObjectByName("replaySelection"); 154 166 if (replaySelection.selected != -1) 155 g_ selectedReplayDirectory = g_ReplaysFiltered[replaySelection.selected].directory;167 g_SelectedReplayDirectory = g_ReplaysFiltered[replaySelection.selected].directory; 156 168 157 169 filterReplays(); 158 170 … … 188 200 replaySelection.list_data = list.directories || []; 189 201 190 202 // Restore selection 191 replaySelection.selected = replaySelection.list.findIndex(directory => directory == g_ selectedReplayDirectory);203 replaySelection.selected = replaySelection.list.findIndex(directory => directory == g_SelectedReplayDirectory); 192 204 193 205 displayReplayDetails(); 194 206 } -
binaries/data/mods/public/gui/session/session.js
61 61 62 62 /** 63 63 * Not constant as we add "gaia". 64 * */64 */ 65 65 var g_CivData = {}; 66 66 67 /** 68 * For restoring selection, order and filters when returning to the replay menu 69 */ 70 var g_ReplaySelectionData; 71 67 72 var g_PlayerAssignments = { "local": { "name": translate("You"), "player": 1 } }; 68 73 69 74 /** … … 213 218 g_PlayerAssignments = initData.playerAssignments; 214 219 g_MatchID = initData.attribs.matchID; 215 220 221 g_ReplaySelectionData = initData.replaySelectionData; 222 216 223 // Cache the player data 217 224 // (This may be updated at runtime by handleNetMessage) 218 225 g_Players = getPlayerData(g_PlayerAssignments); … … 473 480 Engine.SaveReplayMetadata(JSON.stringify(summary)); 474 481 475 482 summary.replayDirectory = Engine.GetCurrentReplayDirectory(); 483 summary.replaySelectionData = g_ReplaySelectionData; 476 484 477 485 Engine.EndGame(); 478 486 -
binaries/data/mods/public/gui/summary/summary.js
137 137 Engine.StartVisualReplay(g_GameData.replayDirectory); 138 138 Engine.SwitchGuiPage("page_loading.xml", { 139 139 "attribs": Engine.GetReplayAttributes(g_GameData.replayDirectory), 140 "isNetworked" 140 "isNetworked": false, 141 141 "playerAssignments": { 142 "local" 142 "local": { 143 143 "name": translate("You"), 144 144 "player": -1 145 145 } 146 146 }, 147 147 "savedGUIData": "", 148 "isReplay" : true 148 "isReplay": true, 149 "replaySelectionData": g_GameData.replaySelectionData 149 150 }); 150 151 } 151 152 -
binaries/data/mods/public/gui/summary/summary.xml
187 187 } 188 188 else if (g_GameData.isReplay) 189 189 { 190 Engine.SwitchGuiPage("page_replaymenu.xml" );190 Engine.SwitchGuiPage("page_replaymenu.xml", { "replaySelectionData": g_GameData.replaySelectionData }); 191 191 } 192 192 else if (!Engine.HasXmppClient()) 193 193 {