public ChallengeView(ChallengeData data, ChallengeProgress progress, int id)
 {
     Data = data;
     Progress = progress;
     progress.PropertyChanged += SubView_PropertyChanged;
     Id = id;
     if (data.Type == ChallengeType.Progressable)
     {
         subChallenges = new ObservableCollection<SubChallengeView>();
     }
 }
 public List<ChallengeProgress> createChallengeProgressListFromChallengeList(List<ChallengeData> dataList)
 {
     var progressList = new List<ChallengeProgress>();
     foreach (var data in dataList)
     {
         var progress = new ChallengeProgress(data.Type);
         if (data.Type == ChallengeType.Progressable)
         {
             foreach (var subData in data.SubChallenges)
             {
                 progress.AddSubChallengeProgress(new SubChallengeProgress());
             }
         }
         progressList.Add(progress);
     }
     return progressList;
 }
Exemplo n.º 3
0
        internal void toogleChallengeIsDone(ChallengeData data, ChallengeProgress progress)
        {
            switch (data.Type)
            {
                case ChallengeType.Binary:
                    progress.IsDone = !progress.IsDone;
                    break;
                case ChallengeType.Progressable:
                    //Determine current progress
                    var currentProgress = 0;
                    foreach (var item in progress.SubChallengesProgress)
                    {
                        if (item.CurrentCompletion != SubChallengeCompletionType.Not)
                        {
                            currentProgress++;
                        }
                    }

                    if (currentProgress >= data.NeedForCompletion)
                    {
                        //Need to uncomplete subs
                        foreach (var item in progress.SubChallengesProgress.Where(x => x.CurrentCompletion == SubChallengeCompletionType.Auto))
                        {
                            item.CurrentCompletion = SubChallengeCompletionType.Not;
                        }
                    }
                    else
                    {
                        //Need to complete subs
                        foreach (var item in progress.SubChallengesProgress)
                        {
                            if (currentProgress < data.NeedForCompletion && item.CurrentCompletion == SubChallengeCompletionType.Not)
                            {
                                item.CurrentCompletion = SubChallengeCompletionType.Auto;
                                currentProgress++;
                            }
                        }
                    }
                    break;
            }
        }