/// <summary> /// Unlock the first Level /// </summary> private void UnlockFirstLevel() { Node levelNode = GetNode <Node>("Levels"); //Unlock first level TextureButton level1Texture = levelNode.GetChild(0) as TextureButton; level1Texture.Disabled = false; level1Texture.Visible = true; //Lock rest of the levels for (int i = 1; i < levelNode.GetChildren().Count; i++) { TextureButton levelTexture = levelNode.GetChild(i) as TextureButton; levelTexture.Disabled = true; Sprite starSprite = levelTexture.GetChild(0) as Sprite; starSprite.Visible = false; } }
/// <summary> /// Display Level score /// </summary> private void DisplayLevelScore() { Node levelNode = GetNode <Node>("Levels"); //If student has not cleared a single level in the section if (studentScoreBL.GetStudentScores(Global.WorldId, Global.SectionId, Global.StudentId) == null) { Node level; Section section = sectionBL.GetSectionLevels(Global.WorldId, Global.SectionId); if (Global.SectionId == 1) { //Unlock first level of section 1 by default UnlockFirstLevel(); GD.Print(section.Level.Count()); //Lock all levels other than 1 for (int i = 1; i < section.Level.Count(); i++) { level = levelNode.GetChild(i); TextureButton levelTexture = level as TextureButton; levelTexture.Visible = true; levelTexture.Disabled = true; } } else { //Lock all levels for (int i = 0; i < section.Level.Count(); i++) { level = levelNode.GetChild(i); TextureButton levelTexture = level as TextureButton; levelTexture.Visible = true; levelTexture.Disabled = true; } CheckSectionCleared(); } } else { Student student = studentScoreBL.GetStudentScores(Global.WorldId, Global.SectionId, Global.StudentId); int totalLevels = GetNode("Levels").GetChildCount(); Section section = sectionBL.GetSectionLevels(Global.WorldId, Global.SectionId); Node level; int i = 0; Node levelParent = GetNode("Levels"); //Display all section's levels foreach (Level lvl in section.Level) { level = levelNode.GetChild(i); TextureButton levelTexture = level as TextureButton; levelTexture.Visible = true; levelTexture.Disabled = true; i++; } //Load student scores int count = 0; foreach (StudentScore score in student.StudentScore) { string starAssetPath = starsImagePath; TextureButton levelTexture = levelParent.GetChild(count) as TextureButton; levelTexture.Disabled = false; levelTexture.Visible = true; Sprite starNode = levelTexture.GetChild(0) as Sprite; switch (score.LevelScore) { case int ls when(ls >= 1 && ls <= 50): starAssetPath += "1 stars.png"; break; case int ls when(ls >= 51 && ls <= 70): starAssetPath += "2 stars.png"; break; case int ls when(ls >= 71 && ls <= 100): starAssetPath += "3 stars.png"; break; } var texture = ResourceLoader.Load(starAssetPath) as Texture; starNode.Texture = texture; starNode.Visible = true; count++; } //Unlock nxt lvl TextureButton nextLevel = levelParent.GetChild(count) as TextureButton; nextLevel.Disabled = false; } }