Page MenuHomeWildfire Games

Fixed lost selection in the load game page
ClosedPublic

Authored by vladislavbelov on Apr 29 2017, 12:36 AM.

Details

Summary

When delete the last or first selected row, selection didn't appear (rP19351).

Test Plan
  1. Run the game
  2. Delete first/last/middle savegame

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Vulcan added a subscriber: Vulcan.Apr 29 2017, 1:21 AM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/912/ for more details.

mimo edited edge metadata.Apr 29 2017, 9:16 AM

No you've not understood what i meant. I don't want to select the first one, but keep the gameSelection.selected at its current value so that we select the one just after the one we've just deleted.
so i guess something like the following would do the job

if (g_SavedGamesMetadata.findIndex(metadata => metadata.id == selectedGameId) != -1) // needed when reordering

gameSelection.selected = g_SavedGamesMetadata.findIndex(metadata => metadata.id == selectedGameId);

else if (gameSelection.selected >= g_SavedGamesMetadata.length) // happens when deleting the last saved game

gameSelection.selected = g_SavedGamesMetadata.length - 1;

else if (gameSelection.selected == -1 && g_SavedGamesMetadata.length)

gameSelection.selected = 0;
binaries/data/mods/public/gui/savedgames/load.js
87 ↗(On Diff #1517)

shouldn't savedGames.length here be g_SavedGamesMetadata.length?

In D392#16194, @mimo wrote:

No you've not understood what i meant. I don't want to select the first one, but keep the gameSelection.selected at its current value so that we select the one just after the one we've just deleted.

No, by your code I understood correctly, it's bug in my code, I think, because my code is equal to your except one case, when selected item still exists and was on the last position.

binaries/data/mods/public/gui/savedgames/load.js
87 ↗(On Diff #1517)

True.

vladislavbelov marked an inline comment as done.

Now it saves the index.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/924/ for more details.

mimo accepted this revision.Apr 29 2017, 6:37 PM

Works as expected, thanks for the patch.

This revision is now accepted and ready to land.Apr 29 2017, 6:37 PM
This revision was automatically updated to reflect the committed changes.