// Obtains the TrackedGame from the dummy online database. private TrackedGame getSelectedResult() { ListBoxItem lbi = (lstDBSearchResults.SelectedItem as ListBoxItem); if (lbi == null) { return(null); } string selectedGameId = lbi.Name; TrackedGame selectedGame = null; // Obtain the game from the dummy database using the listID of the selected game. foreach (TrackedGame t in Data.dummyGamesDatabase) { if (t.listId == selectedGameId) { selectedGame = t; break; } } return(selectedGame); }
// Gets the entity in the dummy database representing the currently selected game. private TrackedGame getSelectedGame() { ListBoxItem lbi = (lstTrackedGames.SelectedItem as ListBoxItem); if (lbi == null) { return(null); } string selectedGameId = lbi.Name; TrackedGame selectedGame = null; // Obtain the game from the dummy database using the listID of the selected game. foreach (TrackedGame t in Data.trackedGamesList) { if (t.listId == selectedGameId) { selectedGame = new TrackedGame(t.imagePath, t.gameTitle, t.progressStatus, t.progressNote, t.numberOfPlaythroughs, t.myRating, t.ratingNote, t.gameInformation); break; } } return(selectedGame); }
// Refresh UI with the selected game. private void lstDBSearchResults_SelectionChanged(object sender, SelectionChangedEventArgs e) { btnAdd.IsEnabled = true; TrackedGame selected = this.getSelectedResult(); if (selected != null) { refreshResultInfo(selected); } }
// Detects a change of which game is selected in the list and displays the newly selected game. private void lstTrackedGames_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Check for unsaved changes first. if (btnSave.IsEnabled == true) { // Required to avoid recursive warning messages. if (e.AddedItems[0] as ListBoxItem == previousSelectedGame) { return; } MessageBoxResult result; result = MessageBox.Show("Discard changes and switch games?", "Unsaved Changes Detected", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); #region Resets Selection + Code Required So Changes Are Not Lost On Game Switch // User does not want to discard changes. if (result != MessageBoxResult.Yes) { ListBoxItem removedItem = e.RemovedItems[0] as ListBoxItem; TrackedGame toRestore = getUnsavedGameInstance(removedItem); // Reset the selection to the game before game switch attempt. lstTrackedGames.SelectedValue = e.RemovedItems[0]; // The UI will be refreshed to the game data that is in the dummy database, // and will lost the user's changes at this point. // Restore changes to UI using refresh function and unsaved TrackedGame instance. refreshGameSection(toRestore); // Enable the save button (as it is disabled on a refresh). enableSaveForGame(); return; } else { previousSelectedGame = e.AddedItems[0] as ListBoxItem; } #endregion } TrackedGame selected = getSelectedGame(); if (selected == null) { return; } refreshGameSection(selected); }
/// <summary> /// Called when the user decides not to discard changes on game switch. /// Creates a TrackedGame object representing the unsaved changes of the user, /// By using static attributes from the dummy database (ex: image path) and /// attributes from the UI (for the user modifiable attributes). /// </summary> /// <param name="unsavedSelection"></param> /// <returns>Temporary TrackedGame object used to refresh the UI back to the user's changes.</returns> private TrackedGame getUnsavedGameInstance(ListBoxItem unsavedSelection) { string unsavedGameId = unsavedSelection.Name; // Tracked Game object TrackedGame unsavedGame = null; // Obtain the game from the dummy database using the listID of the selected game. foreach (TrackedGame t in Data.trackedGamesList) { if (t.listId == unsavedGameId) { unsavedGame = new TrackedGame(t.imagePath, t.gameTitle, t.progressStatus, t.progressNote, t.numberOfPlaythroughs, t.myRating, t.ratingNote, t.gameInformation); break; } } // Update the TrackedGame object with the unsaved changes of the user. if (txtRating.Text == "None") { unsavedGame.myRating = -1; } else { unsavedGame.myRating = Double.Parse(txtRating.Text); } unsavedGame.numberOfPlaythroughs = Int32.Parse(txtPlaythroughs.Text); unsavedGame.progressNote = txtProgressNote.Text; unsavedGame.ratingNote = txtRatingNote.Text; if (cmbProgressStatus.SelectedItem == itemCompleted) { unsavedGame.progressStatus = ProgressStatus.Completed; } else if (cmbProgressStatus.SelectedItem == itemInProgress) { unsavedGame.progressStatus = ProgressStatus.InProgress; } else if (cmbProgressStatus.SelectedItem == itemPlanToPlay) { unsavedGame.progressStatus = ProgressStatus.PlanToPlay; } return(unsavedGame); }
static Data() { // Initialize list of existing tracked games. trackedGamesList = new List <TrackedGame>(); // Initialize online dummy database with 2 additional games. dummyGamesDatabase = new List <TrackedGame>(); string tempPath = "/GameCovers/Crysis2.jpg"; string tempProgressNote = "Beat the game, but did not unlock 100% of unlockables yet."; string tempRatingNote = "I really enjoyed this game, especially the graphics and the soundtrack. The story was also pretty good but still has a little wiggle room for improvement."; string tempGameInfo = "\nRelease Date: 2011-08-29\nGenre(s): Shooter, Action\nDeveloper(s): Crytek\nPublisher(s): Electronic Arts\nPlatform(s): PC, PS3, XBOX 360\nGameplay Mode(s): Single Player, Multiplayer\n\nDescription:\nSequel to one of the greatest PC shooters ever, Crysis 2 offers console players their first taste of Crytek's unique shooter gameplay. Featuring futuristic war, gorgeous destruction and the chance to kick alien butt on the grandest stage of all, New York City, Crysis 2 is destined at the least to equal its predecessor, if not surpass it. Additional features include: challenging AI enemies in the single player campaign, 12-player support online, new and improved upgradable Nanosuit 2 technology and more.\n"; TrackedGame crysis2 = new TrackedGame(tempPath, "Crysis 2", ProgressStatus.Completed, tempProgressNote, 3, 9.4, tempRatingNote, tempGameInfo); tempPath = "/GameCovers/GearsOfWar4.jpg"; tempProgressNote = "Heard good things about this game and will play it during the Summer of 2018."; tempRatingNote = ""; tempGameInfo = "\nRelease Date: 2016-10-11\nGenre(s): Shooter\nDeveloper(s): The Coalition\nPublisher(s): Microsoft Studios\nPlatform(s): XBOX One, PC\nGameplay Mode(s): Single Player, Multiplayer, Co-Operative\n\nDescription:\nA new saga begins for one of the most acclaimed video game franchises in history. After narrowly escaping an attack on their village, JD Fenix and his friends, Kait and Del, must rescue the ones they love and discover the source of a monstrous new enemy.\n"; TrackedGame gearsOfWar4 = new TrackedGame(tempPath, "Gears Of War 4", ProgressStatus.PlanToPlay, tempProgressNote, 0, -1, tempRatingNote, tempGameInfo); tempPath = "/GameCovers/TheLastOfUs.jpg"; tempProgressNote = "Halfway done, really need to find time to finish this one !!!"; tempRatingNote = "Out of this world game, not many like it !"; tempGameInfo = "\nRelease Date: 2013-06-14\nGenre(s): Shooter, Adventure\nDeveloper(s): Naughty Dog\nPublisher(s): Sony Computer Entertainment\nPlatform(s): PS3, PS4\nGameplay Mode(s): Single Player, Multiplayer\n\nDescription:\nTwenty years after a mutated fungus started turning people all over the world into deadly zombies, humans become an endangered species. Joel, a Texan in his forties with the \"emotional range of a teaspoon\" (to quote Hermione from Harry Potter), finds himself responsible with the safety of a fourteen year old girl named Ellie whom he must smuggle to a militia group called the Fireflies. And as if the infected aren't enough of a hassle, they also have to deal with the authorities who wouldn't let them leave the quarantine zone, as well as other survivors capable of killing anyone who might have something useful in their backpacks.\n"; TrackedGame theLastOfUs = new TrackedGame(tempPath, "The Last Of Us", ProgressStatus.InProgress, tempProgressNote, 0, 9.5, tempRatingNote, tempGameInfo); trackedGamesList.Add(crysis2); trackedGamesList.Add(gearsOfWar4); trackedGamesList.Add(theLastOfUs); tempPath = "/GameCovers/MassEffect2.jpg"; tempGameInfo = "\nRelease Date: 2010-01-26\nGenre(s): Shooter, Role-playing(RPG), Simulator\nDeveloper(s): BioWare, BioWare Edmonton\nPublisher(s): Electronic Arts\nPlatform(s): PC, PS3, XBOX 360\nGameplay Mode(s): Single Player\n\nDescription:\nAre you prepared to lose everything to save the galaxy? You'll need to be, Commander Shephard. It's time to bring together your greatest allies and recruit the galaxy's fighting elite to continue the resistance against the invading Reapers. So steel yourself, because this is an astronomical mission where sacrifices must be made. You'll face tougher choices and new, deadlier enemies. Arm yourself and prepare for an unforgettable intergalactic adventure.\n"; TrackedGame massEffect2 = new TrackedGame(tempPath, "Mass Effect 2", ProgressStatus.PlanToPlay, "", 0, -1, "", tempGameInfo); tempPath = "/GameCovers/MassEffect3.png"; tempGameInfo = "\nRelease Date: 2012-03-06\nGenre(s): Shooter, Role-playing(RPG), Simulator\nDeveloper(s): BioWare, BioWare Edmonton\nPublisher(s): Electronic Arts\nPlatform(s): PC, PS3, XBOX 360\nGameplay Mode(s): Single Player\n\nDescription:\nEarth is burning.The Reapers have taken over and other civilizations are falling like dominoes. Lead the final fight to save humanity and take back Earth from these terrifying machines, Commander Shepard. You'll need backup for these battles. Fortunately, the galaxy has a habit of sending unexpected species your way. Recruit team members and forge new alliances, but be prepared to say goodbye at any time as partners make the ultimate sacrifice. It's time for Commander Shepard to fight for the fate of the human race and save the galaxy. No pressure, Commander.\n"; TrackedGame massEffect3 = new TrackedGame(tempPath, "Mass Effect 3", ProgressStatus.PlanToPlay, "", 0, -1, "", tempGameInfo); // Sorted by default. dummyGamesDatabase.Add(crysis2); dummyGamesDatabase.Add(gearsOfWar4); dummyGamesDatabase.Add(massEffect2); dummyGamesDatabase.Add(massEffect3); dummyGamesDatabase.Add(theLastOfUs); }
// Adds the game to the tracked games list (both UI and Data.trackedGamesList) public void addGame() { TrackedGame t = getSelectedResult(); Data.trackedGamesList.Add(new TrackedGame(t.imagePath, t.gameTitle, t.progressStatus, t.progressNote, t.numberOfPlaythroughs, t.myRating, t.ratingNote, t.gameInformation)); ListBoxItem item = new ListBoxItem(); item.Content = t.gameTitle; item.Name = t.listId; MainWindow.mainWindow.lstTrackedGames.Items.Add(item); MainWindow.mainWindow.txtSortingInfo.Content = "None (not supported)"; int count = MainWindow.mainWindow.lstTrackedGames.Items.Count; MainWindow.mainWindow.txtTrackedGamesCount.Content = "Displaying " + count + " out of " + count + " Tracked Games"; }
// Checks if the game being added is already in the tracked games list. public bool isAlreadyTracked() { bool result = false; TrackedGame toCheck = getSelectedResult(); foreach (TrackedGame t in Data.trackedGamesList) { if (toCheck.listId == t.listId) { result = true; break; } } return(result); }
// Refreshes the right side of the UI with the selected game's information. public void refreshGameSection(TrackedGame game) { if (game == null) { return; } else { txtTitle.Text = game.gameTitle; txtGameInformation.Text = game.gameInformation; imgGameCover.Source = new BitmapImage(new Uri(game.imagePath, UriKind.Relative)); txtPlaythroughs.Text = game.numberOfPlaythroughs.ToString(); if (String.IsNullOrWhiteSpace(game.ratingNote)) { txtRatingNote.Text = "None"; } else { txtRatingNote.Text = game.ratingNote; } if (String.IsNullOrWhiteSpace(game.progressNote)) { txtProgressNote.Text = "None"; } else { txtProgressNote.Text = game.progressNote; } if (game.myRating >= 0) { txtRating.Text = game.myRating.ToString(); sliderRating.Value = game.myRating; } else { sliderRating.Value = 0.0; txtRating.Text = "None"; } // Games are always created with Plan To Play status, so this attribute is never null. if (game.progressStatus == ProgressStatus.Completed) { cmbProgressStatus.SelectedItem = itemCompleted; } else if (game.progressStatus == ProgressStatus.InProgress) { cmbProgressStatus.SelectedItem = itemInProgress; } else if (game.progressStatus == ProgressStatus.PlanToPlay) { cmbProgressStatus.SelectedItem = itemPlanToPlay; } disableSaveForGame(); // Important for scrolling back to top for game swtiching. scrollGameInfo.ScrollToTop(); } }
// Refresh result info section. private void refreshResultInfo(TrackedGame game) { txtResultInformation.Text = game.gameInformation; imgResult.Source = new BitmapImage(new Uri(game.imagePath, UriKind.Relative)); scrollResultInfo.ScrollToTop(); }