void SetLevelBoolean(bool val) { string levelName = icon.level.name; switch (specialType) { case SpecialType.Regular: MadLevelProfile.SetLevelBoolean(levelName, name, val); break; case SpecialType.LevelNumber: MadDebug.Assert(false, "Level numbers are not persistent!"); break; case SpecialType.Locked: MadLevelProfile.SetLocked(levelName, val); break; case SpecialType.Completed: MadLevelProfile.SetCompleted(levelName, val); break; default: MadDebug.Assert(false, "Unknown special type: " + specialType); break; } }
private void Execute() { // gain stars for (int i = 1; i <= starsCount; i++) // i = 1, 2, 3... { string starName = "star_" + i; // this is the star property name MadLevelProfile.SetLevelBoolean(MadLevel.currentLevelName, starName, true); } // gain Water for (int i = 1; i <= starsCount; i++) { // i = 1, 2, 3... string waterName = "Waterdrop_" + i; // this is the star property name MadLevelProfile.SetLevelBoolean(MadLevel.currentLevelName, waterName, true); } // complete level if (completeLevel) { MadLevelProfile.SetCompleted(MadLevel.currentLevelName, true); } // go back to level select screen MadLevel.LoadLevelByName("Select Level"); // name from level configuration }
void LoadProfile() { if (!CheckPlaying()) { return; } string prevProfile = MadLevelProfile.profile; MadLevelProfile.profile = selectedProfileName; var path = EditorUtility.OpenFilePanel("Load Profile", "", "profile"); if (path.Length != 0) { var levels = System.IO.File.ReadAllText(path); MadLevelProfile.LoadProfileFromString(levels); MadLevelProfile.Save(); // reload level Application.LoadLevel(Application.loadedLevel); } MadLevelProfile.profile = prevProfile; }
public void SetCompleted(bool val) { var levelNames = GetLevelNames(); for (int i = 0; i < levelNames.Count; ++i) { var levelName = levelNames[i]; MadLevelProfile.SetCompleted(levelName, val); } }
void OnMouseDown() { Debug.Log("Level won", this); MadLevelProfile.SetCompleted(MadLevel.currentLevelName, true); MadLevelProfile.SetLevelInteger(MadLevel.currentLevelName, "score", points); MadLevel.LoadLevelByName("Level Select"); }
void Start() { if (textFromProperty && sprite is MadText) { var text = sprite as MadText; var level = icon.level; var str = MadLevelProfile.GetLevelAny(level.name, textPropertyName); text.text = str; } }
protected override void Update() { base.Update(); if (justEnabled) { if (Application.isPlaying) { if (isTemplate) { MadGameObject.SetActive(gameObject, false); } // completed property object is optional // if it's not present, check the completed property manually if (completedProperty == null) { if (level != null) { completed = MadLevelProfile.IsCompleted(level.name); } } onMouseUp += (sprite) => Activate(); onTap += (sprite) => Activate(); if (!isTemplate) { if (!canFocusIfLocked && locked) { var sprite = GetComponent <MadSprite>(); sprite.eventFlags = sprite.eventFlags & ~MadSprite.EventFlags.Focus; } } } // init child objects visibility if (level != null) { ChangeState(showWhenLevelLocked, locked); ChangeState(showWhenLevelUnlocked, !locked); ChangeState(showWhenLevelCompleted, completed); ChangeState(showWhenLevelNotCompleted, !completed); // if this level is mark as unlocked, make sure that it has a profile entry // this is a workaround for situation when level is unlocked, but then level order is changed if (!locked && Application.isPlaying) { MadLevelProfile.SetLocked(level.name, false); } } justEnabled = false; } }
/// <summary> /// Applies default locked state to profile data if this is not yet applied. /// This function is useful when you don't want to use level select screens or you want to get /// level locked state before running level select screen. /// </summary> public void ApplyProfile() { for (int i = 0; i < levels.Count; ++i) { var level = levels[i]; if (!MadLevelProfile.IsLockedSet(level.name)) { MadLevelProfile.SetLocked(level.name, level.lockedByDefault); } } }
/// <summary> /// Finds the last unlocked level (in the order). Be aware that locked flag in the new /// game is set when the player visits level select screen for the first time. /// </summary> /// <returns>The first locked level name or <code>null</code> if there's no level /// that is marked as locked.</returns> public static string FindLastUnlockedLevelName(string groupName) { LayoutUninitializedCheck(); return FindLastLevelName(groupName, (level) => { if (MadLevelProfile.IsLockedSet(level.name)) { return !MadLevelProfile.IsLocked(level.name); } else { return !level.lockedByDefault; } }); }
void Update() { if (resetOnRKey) { if (Input.GetKey(KeyCode.R)) { MadLevelProfile.Reset(); MadLevel.ReloadCurrent(); } } }
public int CountCompleted() { var levelNames = GetLevelNames(); int result = 0; for (int i = 0; i < levelNames.Count; ++i) { if (MadLevelProfile.IsCompleted(levelNames[i])) { result++; } } return result; }
private static void GUILevel(string levelName) { using (MadGUI.Indent(2)) { var propertyNames = MadLevelProfile.GetLevelPropertyNames(levelName); propertyNames.Sort(new MadNaturalSortComparer()); foreach (var propertyName in propertyNames) { var propertyValue = MadLevelProfile.GetLevelAny(levelName, propertyName); GUIProperty(propertyName, propertyValue); } } }
protected override void Start() { base.Start(); // completed property object is optional // if it's not present, check the completed property manually if (completedProperty == null) { completed = MadLevelProfile.IsCompleted(level.name); } onMouseUp += (sprite) => Activate(); onTap += (sprite) => Activate(); }
private void GUILevels(string path) { using (MadGUI.Indent(2)) { var levelNames = MadLevelProfile.GetLevelNames(); levelNames.Sort(new MadNaturalSortComparer()); foreach (var levelName in levelNames) { path += "/" + levelName; if (Foldout(levelName, path)) { GUILevel(levelName); } } } }
void Upgrade() { if (version == 0) { // in free layout of 1.3.x icon names were mistaken for level names // check if there's profile entry for level name of icon name // but without level name itself if (MadLevelProfile.IsLevelSet(name) && !MadLevelProfile.IsLevelSet(level.name)) { MadLevelProfile.RenameLevel(name, level.name); } } version = 1; }
void CompleteAllLevels() { if (!CheckPlaying()) { return; } var levelNames = MadLevel.GetAllLevelNames(); foreach (var levelName in levelNames) { MadLevelProfile.SetCompleted(levelName, true); } MadLevel.ReloadCurrent(); }
void DeleteProfile(string profile) { if (!CheckPlaying()) { return; } if (EditorUtility.DisplayDialog( "Delete Profile " + profile + "?", "Are you sure you want to delete profile '" + profile + "'? This cannot be undone.", "Yes", "No")) { MadLevelProfile.UnregisterProfile(profile); selectedProfileIndex = 0; } }
void UnlockAllLevels() { if (!CheckPlaying()) { return; } var levelNames = MadLevel.GetAllLevelNames(); foreach (var levelName in levelNames) { MadLevelProfile.SetLocked(levelName, false); } MadLevel.ReloadCurrent(); }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void Start() { var sprite = GetComponent <MadSprite>(); if (sprite != null) { sprite.onMouseEnter += (s) => sprite.AnimScaleTo(Vector3.one * 1.5f, 1, MadiTween.EaseType.easeOutElastic); sprite.onMouseExit += (s) => sprite.AnimScaleTo(Vector3.one, 1, MadiTween.EaseType.easeOutElastic); sprite.onMouseDown += sprite.onTap = (s) => { MadLevelProfile.Reset(); MadLevel.ReloadCurrent(); }; } }
private void GUIProfile(string profile, string path) { using (MadGUI.Indent(2)) { MadLevelProfile.profile = profile; if (Foldout("Levels", path + "/Levels")) { GUILevels(path + "/Levels"); } var profilePropertyNames = MadLevelProfile.GetProfilePropertyNames(); foreach (var profilePropertyName in profilePropertyNames) { GUIProperty(profilePropertyName, MadLevelProfile.GetProfileAny(profilePropertyName)); } } }
void Update() { if (onFirstUpdate) { // looking at the property state at first update makes it usable during runtime if (Application.isPlaying && icon.level != null && persistent) { if (propertySet) { propertyEnabled = GetLevelBoolean(); } else { // save the property if unset if (justAwaken) { SetLevelBoolean(propertyEnabled); } else { // layout rebuilded on runtime propertyEnabled = false; } } } if (textFromProperty && sprite is MadText) { var text = sprite as MadText; var level = icon.level; var str = MadLevelProfile.GetLevelAny(level.name, textPropertyName); text.text = str; } onFirstUpdate = false; justAwaken = false; } // cannot do the update every frame because of huge performance loss // if (propertySet) { // propertyEnabled = GetLevelBoolean(); // } }
/// <summary> /// Gets the last completed level icon in current group or null if cannot be found. /// </summary> /// <returns></returns> public MadLevelIcon GetLastCompletedIcon() { var lastCompleted = from l in MadLevel.activeConfiguration.levels where l.groupId == configurationGroup && l.type == MadLevel.Type.Level && MadLevelProfile.IsCompleted(l.name) orderby l.order descending select l; var lastCompletedLevel = lastCompleted.FirstOrDefault(); if (lastCompletedLevel != null) { return(MadLevelLayout.current.GetIcon(lastCompletedLevel.name)); } else { return(null); } }
void ResetProfile(string profile) { if (!CheckPlaying()) { return; } if (EditorUtility.DisplayDialog( "Reset Profile " + profile + "?", "Are you sure you want to reset profile '" + profile + "'? This cannot be undone.", "Yes", "No")) { string prevProfile = MadLevelProfile.profile; MadLevelProfile.profile = selectedProfileName; MadLevelProfile.Reset(); MadLevelProfile.profile = prevProfile; MadLevel.ReloadCurrent(); } }
private bool ProcessProperties(PropertyProcessor processor) { var levelNames = GetLevelNames(); if (propertyName == null || propertyName.Length == 0) { Debug.LogError("Missing SelectProperty() directive"); return false; } for (int i = 0; i < levelNames.Count; ++i) { var ln = levelNames[i]; for (int j = 0; j < propertyName.Length; ++j) { var pn = propertyName[j]; if (!MadLevelProfile.IsLevelPropertySet(ln, pn)) { processor(ln, pn, null); } else { processor(ln, pn, MadLevelProfile.GetLevelAny(ln, pn)); } } } return true; }
void CreateProfile() { if (!CheckPlaying()) { return; } foreach (var profileName in MadLevelProfile.profileList) { if (newProfileName == profileName) { EditorUtility.DisplayDialog( "Profile Exists!", "Profile called '" + newProfileName + "' already exists!", "Ouch!"); return; } } MadLevelProfile.RegisterProfile(newProfileName); EditorUtility.DisplayDialog( "Profile Created!", "Profile '" + newProfileName + "' created successufully!", "OK"); }
private string GetPropertyValue() { string levelName = icon.level.name; switch (propertyType) { case PropertyType.Completed: return(MadLevelProfile.IsCompleted(levelName).ToString()); case PropertyType.Locked: return(MadLevelProfile.IsLocked(levelName).ToString()); case PropertyType.LevelNumber: return(icon.levelNumber.text); case PropertyType.Custom: return(MadLevelProfile.GetLevelAny(levelName, customPropertyName, null)); default: Debug.LogError("Unknown property type: " + propertyType); return(null); } }
void SaveProfile() { if (!CheckPlaying()) { return; } string prevProfile = MadLevelProfile.profile; MadLevelProfile.profile = selectedProfileName; var path = EditorUtility.SaveFilePanel( "Save Profile", "", MadLevelProfile.profile + ".profile", "profile"); if (path.Length != 0) { string levels = MadLevelProfile.SaveProfileToString(); System.IO.File.WriteAllText(path, levels); EditorUtility.DisplayDialog("Profile Saved!", "Profile saved to " + path, "OK"); } MadLevelProfile.profile = prevProfile; }
bool IsLevelBooleanSet() { string levelName = icon.level.name; switch (specialType) { case SpecialType.Regular: return(MadLevelProfile.IsLevelPropertySet(levelName, name)); case SpecialType.LevelNumber: return(MadLevelProfile.IsLevelPropertySet(levelName, name)); case SpecialType.Locked: return(MadLevelProfile.IsLockedSet(levelName)); case SpecialType.Completed: return(MadLevelProfile.IsCompletedSet(levelName)); default: MadDebug.Assert(false, "Unknown special type: " + specialType); return(false); } }
bool GetLevelBoolean() { string levelName = icon.level.name; switch (specialType) { case SpecialType.Regular: return(MadLevelProfile.GetLevelBoolean(levelName, name)); case SpecialType.LevelNumber: MadDebug.Assert(false, "Level numbers are not persistent!"); return(false); case SpecialType.Locked: return(MadLevelProfile.IsLocked(levelName)); case SpecialType.Completed: return(MadLevelProfile.IsCompleted(levelName)); default: MadDebug.Assert(false, "Unknown special type: " + specialType); return(false); } }
public int CountLocked() { var levelNames = GetLevelNames(); int result = 0; var layout = MadLevelLayout.TryGet(); for (int i = 0; i < levelNames.Count; ++i) { var levelName = levelNames[i]; // first look for a layout, because icons locked state are more trustworthy if (layout != null) { var icon = layout.GetIcon(levelName); if (icon != null) { if (icon.locked) { result++; } continue; } } // no layout or no icon if (MadLevelProfile.IsLockedSet(levelName)) { if (MadLevelProfile.IsLocked(levelName)) { result++; } } else { var lockedByDefault = MadLevel.activeConfiguration.FindLevelByName(levelName).lockedByDefault; if (lockedByDefault) { result++; } } } return result; }