예제 #1
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            //DEBUG only, using debug interface for buying
            #region debug
            /*
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            string xml_filename = XML_NOK;
            if (localSettings.Values.ContainsKey("XML"))
            {
                xml_filename = (string)localSettings.Values["XML"];
            }
            
            Debug.WriteLine("xml_filename: " + xml_filename);

            if (xml_filename == XML_OK)
            {
                buyBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                purchasedLbl.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            LoadInAppPurchaseProxyFileAsync(xml_filename);
            */
            #endregion

            
            // check if propack is purchased and show the purchase button accordingly
            if (Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("ProPackPurchased") || licenseInformation.ProductLicenses[PRO_PACK].IsActive)
            {
                buyBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                purchasedLbl.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            //fetch price from store and set it to priceLbl
            ListingInformation listingInfo = await CurrentApp.LoadListingInformationAsync();
            if(listingInfo.ProductListings.Count > 0)
            {
                ProductListing proPackListing = listingInfo.ProductListings.Values.ElementAt(0);
                priceLbl.Text = proPackListing.FormattedPrice;
            }
        }
예제 #2
0
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // if players page is reached from a game page, go back to the game main page
            selectedGameMode_ = (int)e.NavigationParameter;
            gameModeName.Text = " " + gameModes_[selectedGameMode_].ToString();

            int counter = 0;
            PlayerGroup playerGroup = null;
            while (playerGroup == null && counter < RETRY_COUNT)
            {
                playerGroup = await SampleDataSource.GetPlayerGroupOne();
                counter++;
            }
            this.DefaultViewModel[PlayerGroupName] = playerGroup;
        }
예제 #3
0
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>.
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            Debug.WriteLine("HS: load");
            // navigation parameter is gameModeId as string
            GameResultsGroup resultGroup = null;
            int counter = 0;
            while (resultGroup == null && counter < RETRY_COUNT)
            {
                resultGroup = await SampleDataSource.GetResultGroupAsync(e.NavigationParameter.ToString());
                counter++;
            }
            Debug.WriteLine("HiScores: counter: " + counter);

            this.DefaultViewModel[ResultGroupName] = resultGroup;

            Header.Text = gameModes[e.NavigationParameter.ToString()];
            navParameter = e.NavigationParameter.ToString();
        }
예제 #4
0
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }

            // set results to the viewmodel

            //create pivot items based on the selected players
            //parse selected players from navigation parameter string or local settings to a list

            string players = "";

            if (e.PageState == null)
            {
                players = e.NavigationParameter.ToString();
            }
            else
            {
                players = (string)e.PageState["Players"];
            }

            List<string> selectedPlayers = new List<string>();

            parseParametersToList(players, ref selectedPlayers);

            // create pivot items (came pages) for each player
            for (int i = 0; i < selectedPlayers.Count; ++i)
            {
                PivotItem pivotItem = new PivotItem();
                CXPivotItem cxItem = new CXPivotItem();
                
                cxItem.PlayerCompletedGame += cxItem_PlayerCompletedGame;
                cxItem.PlayerUncompletedGame += cxItem_PlayerUncompletedGame;
                pivotItem.Content = cxItem;
                pivotItem.Header = selectedPlayers[i];
                this.pivot.Items.Add(pivotItem);
            }

            // if there was a saved state, set counters to their values
            // format of the saved string is "PlayerName;ThrowsIn;ThrowsOut"
            if (e.PageState != null)
            {
                for (int i = 0; i < pivot.Items.Count; ++i)
                {
                    PivotItem item = pivot.Items[i] as PivotItem;
                    CXPivotItem CXitem = item.Content as CXPivotItem;
                    
                    string throws = (string)e.PageState[i.ToString()];
                    string throwsIn = throws.Substring(0, throws.IndexOf(";"));
                    string throwsOut = throws.Substring(throws.IndexOf(";") + 1);
                    CXitem.setThrows(throwsIn,throwsOut);
                }
                if (e.PageState.ContainsKey("SelectedIndex"))
                {
                    pivot.SelectedIndex = (int)e.PageState["SelectedIndex"];
                }
            }
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            //DEBUG
            #region debug
            /*
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            string xml_filename = XML_NOK;
            if (localSettings.Values.ContainsKey("XML"))
            {
                xml_filename = (string)localSettings.Values["XML"];
            }

            Debug.WriteLine("xml_filename: " + xml_filename);

            LoadInAppPurchaseProxyFileAsync(xml_filename);
            */
            #endregion
            
            // get player name and set it to the header
            string currentPlayerName = (string)e.NavigationParameter;

            Player player = null;
            int counter = 0;
            while (player == null && counter < RETRY_COUNT)
            {
                player = await SampleDataSource.GetPlayerAsync(currentPlayerName);
                counter++;
            }
            playerName.Text = currentPlayerName;

            

            if(Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("ProPackPurchased") || licenseInformation.ProductLicenses[PRO_PACK].IsActive)
            {
                rating.Text = player.PuttRating.ToString();
                rating.Visibility = Windows.UI.Xaml.Visibility.Visible;
                buyProPackText.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            else
            {
                rating.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                buyProPackText.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            // Get results for all game modes
            IEnumerable<GameResultsGroup> resultGroups = null;
            int counter2 = 0;
            while (resultGroups == null && counter2 < 20)
            {
                resultGroups = await SampleDataSource.GetResultsAsync();
                counter2++;
            }

            
            if (resultGroups == null)
            {
                Debug.WriteLine("groups NULL");
            }

            List<GameResultsGroup> allResultGroups = new List<GameResultsGroup>();
            allResultGroups.Add(resultGroups.ElementAt(0));
            allResultGroups.Add(resultGroups.ElementAt(1));
            allResultGroups.Add(resultGroups.ElementAt(2));
            allResultGroups.Add(resultGroups.ElementAt(3));

            // count game mode games played for player
            // get highest score
            // calculate avg score
            
            int totalGamesPlayedNr = 0;
            
            // go through the result groups
            for(int i = 0; i < allResultGroups.Count; ++i)
            {
                double highestScore = 0;
                List<Result> gameModeResultsForPlayer = new List<Result>();
                // go through the results in one result group
                foreach (Result result in allResultGroups.ElementAt(i).Results)
                {
                    if (result.ResultPlayerName == currentPlayerName)
                    {
                        
                        gameModeResultsForPlayer.Add(result);
                        totalGamesPlayedNr++;
            
                        if (result.Score > highestScore)
                        {
                            highestScore = result.Score;
                        }
                    }
                }
                //playerResultsInAllModes.Add(gameModeResultsForPlayer);
                //gameModeAvgRatings.Add(singleResultRatings.Average());
                //Debug.WriteLine("singleresultratings.average: " + singleResultRatings.Average());

                bestScoreTextBlocks.ElementAt(i).Text = highestScore.ToString();

                double avgScore = 0;
                if (gameModeResultsForPlayer.Count > 0)
                {
                    avgScore = Math.Round(gameModeResultsForPlayer.Sum(a => a.Score) / gameModeResultsForPlayer.Count);
                }
                avgScoreTextBlocks.ElementAt(i).Text = avgScore.ToString();
                gamesPlayedTextBlocks.ElementAt(i).Text = gameModeResultsForPlayer.Count.ToString();
                skillLevelTextBlocks.ElementAt(i).Text = GetSkillLevelString(avgScore, i);
            }
            
            // update summary labels
            totalGamesPlayed.Text = totalGamesPlayedNr.ToString();
            
        }
예제 #6
0
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 /// The source of the event; typically <see cref="NavigationHelper"/>
 /// </param>
 /// <param name="e">Event data that provides both the navigation parameter passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
 /// a dictionary of state preserved by this page during an earlier
 /// session.  The state will be null the first time a page is visited.</param>
 private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
 }
예제 #7
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }

            string players = "";

            if (e.PageState == null)
            {
                players = e.NavigationParameter.ToString();
            }
            else if (e.PageState.ContainsKey("Players"))
            {
                players = (string)e.PageState["Players"];
            }
            else
            {
                // we have screwed up smthing
            }

            List<string> selectedPlayers = new List<string>();

            parseParametersToList(players, ref selectedPlayers);

            // create pivot items (came pages) for each player
            for (int i = 0; i < selectedPlayers.Count; ++i)
            {
                PivotItem pivotItem = new PivotItem();
                JYLYPivotItem JYLYItem = new JYLYPivotItem();
                
                JYLYItem.PlayerCompletedGame += JYLYItem_PlayerCompletedGame;
                JYLYItem.PlayerUncompletedGame += JYLYItem_PlayerUncompletedGame;

                pivotItem.Content = JYLYItem;
                pivotItem.Header = selectedPlayers[i];
                this.pivot.Items.Add(pivotItem);
            }

            // if there was a saved state, set counters to their values

            if (e.PageState != null)
            {
                for (int i = 0; i < pivot.Items.Count; ++i)
                {
                    //Debug.WriteLine("i: " + i);
                    PivotItem item = pivot.Items[i] as PivotItem;
                    JYLYPivotItem pivotItem = item.Content as JYLYPivotItem;
                    pivotItem.setState((string)e.PageState[i.ToString()]);
                }
                if (e.PageState.ContainsKey("SelectedIndex"))
                {
                    pivot.SelectedIndex = (int)e.PageState["SelectedIndex"];
                }
            }
        }
예제 #8
0
        /* DEBUG ONLY
        private async void LoadInAppPurchaseProxyFileAsync(string filename)
        {
            StorageFile proxyFile =
                await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///DataModel/" + filename));
            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
        }*/

        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>.
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            //DEBUG

            #region debug
            /*
            string xml_filename = XML_NOK;
            if (localSettings.Values.ContainsKey("XML"))
            {
                xml_filename = (string)localSettings.Values["XML"];
            }

            Debug.WriteLine("xml_filename: " + xml_filename);

            LoadInAppPurchaseProxyFileAsync(xml_filename);
            Debug.WriteLine("xml loaded");
            //debug only
            if (xml_filename == XML_OK)
            {
                Debug.WriteLine("xml_OK");
                buyProPackText.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }*/
            #endregion

            // If a hardware Back button is present, hide the "soft" Back button
            // in the command bar, and register a handler for presses of the hardware
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }

            IEnumerable<GameResultsGroup> resultGroups = null;
            int counter = 0;
            while (resultGroups == null && counter < RETRY_COUNT)
            {
                resultGroups = await SampleDataSource.GetResultsAsync();
                counter++;
            }

            this.DefaultViewModel[FirstGroupName] = resultGroups.ElementAt(0);
            this.DefaultViewModel[SecondGroupName] = resultGroups.ElementAt(1);
            this.DefaultViewModel[ThirdGroupName] = resultGroups.ElementAt(2);
            this.DefaultViewModel[FourthGroupName] = resultGroups.ElementAt(3);

            PlayerGroup playerDatGroup = null;
            counter = 0;
            while (playerDatGroup == null && counter < RETRY_COUNT)
            {
                playerDatGroup = await SampleDataSource.GetPlayerGroupOne();
                counter++;
            }
            this.DefaultViewModel[PlayerGroupName] = playerDatGroup;
            
            
            bool saveData = false;

            #region newResults
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            if (localSettings.Values.ContainsKey("NewResults"))
            {
                // parse new results into Json
                JsonArray jsonArray = JsonArray.Parse(localSettings.Values["NewResults"].ToString());

                // result group where to add new results
                GameResultsGroup group = null;

                // every new result is handled
                foreach (JsonValue jsonVal in jsonArray)
                {
                    JsonObject jsonObject = jsonVal.GetObject();
                    Result newResult = new Result(jsonObject["ResultId"].GetString(),
                                                    jsonObject["ResultPlayerName"].GetString(),
                                                    jsonObject["ResultGameModeId"].GetString(),
                                                    jsonObject["Score"].GetNumber(),
                                                    jsonObject["ResultDateTime"].GetString());

                    // variable 'group' is set to the result group where the new results are going to be added
                    if (jsonObject["ResultGameModeId"].GetString() == "0")
                    {
                        group = (GameResultsGroup)DefaultViewModel[FirstGroupName];
                    }
                    else if (jsonObject["ResultGameModeId"].GetString() == "1")
                    {
                        group = (GameResultsGroup)DefaultViewModel[SecondGroupName];
                    }
                    else if (jsonObject["ResultGameModeId"].GetString() == "2")
                    {
                        group = (GameResultsGroup)DefaultViewModel[ThirdGroupName];
                    }
                    else if (jsonObject["ResultGameModeId"].GetString() == "3")
                    {
                        group = (GameResultsGroup)DefaultViewModel[FourthGroupName];
                    }
                    else
                    {
                        // if a new result does not contain gamemode information, it is omitted and the next one is processed
                        continue;
                    }

                    // check if placeholder results are to be removed
                    // if this is the first time results are added to this group, clear it first
                    if (!localSettings.Values.ContainsKey("ResultsAddedForGroup" + jsonObject["ResultGameModeId"].GetString()))
                    {
                        group.Results.Clear();

                        // set flag that results have been added to this group
                        localSettings.Values["ResultsAddedForGroup" + jsonObject["ResultGameModeId"].GetString()] = true;
                    }

                    // add new result to the gameResultsGroup
                    group.Results.Add(newResult);

                    // if there is at least two results, try to sort
                    if (group.Results.Count > 1)
                    {
                        // sort by moving the item upwards as long as necessary
                        for (int i = 0; i < group.Results.Count; ++i)
                        {
                            // move one upwards, if 
                            if (group.Results.Count > i - 1 &&
                                group.Results.ElementAt(group.Results.Count - 2 - i).Score < newResult.Score)
                            {
                                group.Results.Move(group.Results.Count - 1 - i, group.Results.Count - 2 - i);

                                if (group.Results.Count - 2 - i == 0)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    // modify the player's gamesplayed data
                    string resultPlayerName = jsonObject["ResultPlayerName"].GetString();

                    int counter2 = 0;
                    PlayerGroup playerDataGroup = null;
                    while (playerDataGroup == null && counter2 < RETRY_COUNT)
                    {
                        playerDataGroup = await SampleDataSource.GetPlayerGroupOne();

                        counter2++;
                    }


                    //get player from the defaultviewmodel's player group
                    Player player = null;

                    foreach (Player p in playerDataGroup.Players)
                    {
                        if (p.PlayerName == resultPlayerName)
                        {
                            player = p;
                            break;
                        }
                    }
                    if (player != null)
                    {
                        player.PuttRating = await ratingCalculator.PlayerRating(player.PlayerName);
                        Debug.WriteLine("player: " + player.PlayerName + " rating: " + player.PuttRating);
                        player.GamesPlayed += 1;
                    }
                }
                // new results read from memory, remove them and set up save flag
                localSettings.Values.Remove("NewResults");
                saveData = true;
            }
            // new JYLYresults
            if (localSettings.Values.ContainsKey("NewJYLYResults"))
            {
                IEnumerable<JYLYResult> IJYLYResultGroup = null;
                int counter3 = 0;
                while (IJYLYResultGroup == null && counter3 < RETRY_COUNT)
                {
                    IJYLYResultGroup = await SampleDataSource.GetJYLYResultsAsync();
                    counter3++;
                }
                ObservableCollection<JYLYResult> JYLYResultGroup = (ObservableCollection<JYLYResult>)IJYLYResultGroup;

                // parse new results into Json
                JsonArray jsonArray = JsonArray.Parse(localSettings.Values["NewJYLYResults"].ToString());

                // result group where to add new results

                // every new result is handled
                foreach (JsonValue jsonVal in jsonArray)
                {
                    JsonObject jsonObject = jsonVal.GetObject();
                    JYLYResult newJYLYResult = new JYLYResult(jsonObject["Serie"].GetString(),
                                                    jsonObject["PlayerName"].GetString(),
                                                    jsonObject["Score"].GetNumber(),
                                                    jsonObject["DateTime"].GetString());
                    JYLYResultGroup.Add(newJYLYResult);
                }
                // new JYLYresults read from memory, remove them and set up save flag
                localSettings.Values.Remove("NewJYLYResults");
                saveData = true;
            }
            #endregion

            Debug.WriteLine("DII: resultGroups.count: " + resultGroups.Count<GameResultsGroup>());

            // check if this is the first boot or is the app udated to Abo or JYLY versions to save all data
            if (saveData || !localSettings.Values.ContainsKey("FirstBootDone") ||
                !localSettings.Values.ContainsKey("update1.2.0.0_done") ||
                localSettings.Values.ContainsKey("SaveAboGroup") ||
                localSettings.Values.ContainsKey("SaveJYLYGroup"))
            {
                dataSaver.SaveAllDataToJson();

                localSettings.Values["FileCreated"] = true;
                localSettings.Values["FirstBootDone"] = true;

                if (localSettings.Values.ContainsKey("SaveAboGroup"))
                {
                    localSettings.Values.Remove("SaveAboGroup");
                }
                if (localSettings.Values.ContainsKey("SaveJYLYGroup"))
                {
                    localSettings.Values.Remove("SaveJYLYGroup");
                }
            }
            if (localSettings.Values.ContainsKey(PIVOT_INDEX))
            {
                this.pivot.SelectedIndex = (int)localSettings.Values[PIVOT_INDEX];
                localSettings.Values.Remove(PIVOT_INDEX);
            }

            Debug.WriteLine("MainPage LoadState done");
        }
예제 #9
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }
            // set results to the viewmodel

            //create pivot items based on the selected players
            //parse selected players from navigation parameter string or local settings to a list

            string players = "";

            // first navigation to the page
            if (e.PageState == null)
            {
                players = e.NavigationParameter.ToString();
            }
            // there is a saved state, resume
            else if (e.PageState.ContainsKey("Players"))
            {
                players = (string)e.PageState["Players"];
            }
            
            List<string> selectedPlayers = new List<string>();
            parseParametersToList(players, ref selectedPlayers);

            // create pivot items (game pages) for each player
            for (int i = 0; i < selectedPlayers.Count; ++i)
            {
                PivotItem pivotItem = new PivotItem();
                AboPivotItem cxItem = new AboPivotItem();
                pivotItem.Content = cxItem;
                pivotItem.Header = selectedPlayers[i];
                this.pivot.Items.Add(pivotItem);
            }

            // if there was a saved state, set counters to their values
            if (e.PageState != null)
            {
                for (int i = 0; i < pivot.Items.Count; ++i)
                {
                    PivotItem item = pivot.Items[i] as PivotItem;
                    AboPivotItem pivotItem = item.Content as AboPivotItem;
                    pivotItem.setState((string)e.PageState[i.ToString()]);
                }
                if (e.PageState.ContainsKey("SelectedIndex"))
                {
                    pivot.SelectedIndex = (int)e.PageState["SelectedIndex"];
                }
            }
        }