internal AchievementGUI(Achievement achievement, AchievementEarn earn) { this.achievement = achievement; this.earn = earn; // achievements from other assemblies are always addons addon = achievement.isAddon() || !achievement.GetType().Assembly.Equals(typeof(Achievements).Assembly); #if false toastTex = GameDatabase.Instance.GetTexture("Achievements/toast", false); toastNotEarnedTex = GameDatabase.Instance.GetTexture("Achievements/toast-not-earned", false); toastAddonTex = GameDatabase.Instance.GetTexture("Achievements/toast-addon", false); toastAddonNotEarnedTex = GameDatabase.Instance.GetTexture("Achievements/toast-addon-not-earned", false); toastExpandedTex = GameDatabase.Instance.GetTexture("Achievements/toast-expanded", false); toastAddonExpandedTex = GameDatabase.Instance.GetTexture("Achievements/toast-addon-expanded", false); #endif toastTex = new Texture2D(2, 2); toastNotEarnedTex = new Texture2D(2, 2); toastAddonTex = new Texture2D(2, 2); toastAddonNotEarnedTex = new Texture2D(2, 2); toastExpandedTex = new Texture2D(2, 2); toastAddonExpandedTex = new Texture2D(2, 2); if (!ToolbarControl.LoadImageFromFile(ref toastTex, "GameData/Achievements/PluginData/Textures/toast")) { Log.Error("Unable to load toast from file"); } if (!ToolbarControl.LoadImageFromFile(ref toastNotEarnedTex, "GameData/Achievements/PluginData/Textures/toast-not-earned")) { Log.Error("Unable to load toast-not-earned from file"); } if (!ToolbarControl.LoadImageFromFile(ref toastAddonTex, "GameData/Achievements/PluginData/Textures/toast-addon")) { Log.Error("Unable to load toast-addon from file"); } if (!ToolbarControl.LoadImageFromFile(ref toastAddonNotEarnedTex, "GameData/Achievements/PluginData/Textures/toast-addon-not-earned")) { Log.Error("Unable to load toast-addon-not-earned from file"); } if (!ToolbarControl.LoadImageFromFile(ref toastExpandedTex, "GameData/Achievements/PluginData/Textures/toast-expanded")) { Log.Error("Unable to load toast-expanded from file"); } if (!ToolbarControl.LoadImageFromFile(ref toastAddonExpandedTex, "GameData/Achievements/PluginData/Textures/toast-addon-expanded")) { Log.Error("Unable to load toast-addon-expanded from file"); } int width = TEX_WIDTH + 300; int height = Screen.height / 2; bgStyle = new GUIStyle(); bgStyle.normal.background = toastTex; bgStyle.fixedWidth = TEX_WIDTH; bgStyle.fixedHeight = TEX_HEIGHT + TEX_BORDER * 2; bgNotEarnedStyle = new GUIStyle(); bgNotEarnedStyle.normal.background = toastNotEarnedTex; bgNotEarnedStyle.fixedWidth = TEX_WIDTH; bgNotEarnedStyle.fixedHeight = TEX_HEIGHT + TEX_BORDER * 2; bgAddonStyle = new GUIStyle(bgStyle); bgAddonStyle.normal.background = toastAddonTex; bgAddonNotEarnedStyle = new GUIStyle(bgNotEarnedStyle); bgAddonNotEarnedStyle.normal.background = toastAddonNotEarnedTex; bgExpandedStyle = new GUIStyle(bgStyle); bgExpandedStyle.normal.background = toastExpandedTex; bgExpandedStyle.fixedHeight = TEX_HEIGHT + TEX_HEIGHT_EXPANSION + TEX_BORDER * 2; bgAddonExpandedStyle = new GUIStyle(bgStyle); bgAddonExpandedStyle.normal.background = toastAddonExpandedTex; bgAddonExpandedStyle.fixedHeight = TEX_HEIGHT + TEX_HEIGHT_EXPANSION + TEX_BORDER * 2; textStyle = new GUIStyle(); textStyle.alignment = TextAnchor.MiddleCenter; textStyle.fontSize = FONT_SIZE; textStyle.normal.textColor = Color.black; textStyle.padding = new RectOffset(TEXT_MARGIN, TEXT_MARGIN, 0, 0); textStyle.wordWrap = true; textStyle.fixedWidth = TEX_WIDTH; textNotEarnedStyle = new GUIStyle(); textNotEarnedStyle.alignment = TextAnchor.MiddleCenter; textNotEarnedStyle.fontSize = FONT_SIZE; textNotEarnedStyle.normal.textColor = Color.grey; textNotEarnedStyle.padding = new RectOffset(TEXT_MARGIN, TEXT_MARGIN, 0, 0); textNotEarnedStyle.wordWrap = true; textNotEarnedStyle.fixedWidth = TEX_WIDTH; textExpansionStyle = new GUIStyle(textStyle); textExpansionStyle.fontSize = FONT_SIZE_EXPANSION; textExpansionStyle.fixedWidth = TEX_WIDTH - EXPANDED_INSET; titleStyle = new GUIStyle(textStyle); titleStyle.fontSize = TITLE_FONT_SIZE; titleStyle.fontStyle = FontStyle.Bold; titleNotEarnedStyle = new GUIStyle(textNotEarnedStyle); titleNotEarnedStyle.fontSize = TITLE_FONT_SIZE; titleNotEarnedStyle.fontStyle = FontStyle.Bold; }
public static AssetReference ReturnSpriteAssetReference(Achievement achievement) => Achievements[achievement].SpriteAssetReference;
public static bool ReturnUnlockedState(Achievement achievement) => Achievements[achievement].Unlocked;
public static string ReturnDescription(Achievement achievement) => Achievements[achievement].Description;
public static int ReturnReward(Achievement achievement) => Achievements[achievement].Reward;
public Achievement CreatFromJSON(string JSONObject) { Achievement toReturn = new Achievement(); return(toReturn); }
private void OnGUI() { scrollPos = EditorGUILayout.BeginScrollView(scrollPos); EditorGUILayout.BeginHorizontal(); if (!add) { add = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/TestPlayFab/Editor/Resources/plus.png", typeof(Texture)); } if (GUILayout.Button(add, GUILayout.Width(64), GUILayout.Height(64))) { if (!creator) { creator = new AchievementsCreator(); creator.Display(); } } if (Achievement.achievements.Count != 0) { if (achievementsTexture == null || achievementsTexture.Length < Achievement.achievements.Count) { achievementsTexture = new Texture2D[Achievement.achievements.Count]; } for (int i = 0; i < Achievement.achievements.Count; i++) { if (!achievementsTexture[i]) { achievementsTexture[i] = (Texture2D)AssetDatabase.LoadAssetAtPath(Achievement.achievements[i].sPath, typeof(Texture)); } if (GUILayout.Button(achievementsTexture[i], GUILayout.Width(64), GUILayout.Height(64))) { Achievement.EditorDisplay(Achievement.achievements[i]); } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save to PlayFab", GUILayout.Width(128), GUILayout.Height(20))) { Achievement.PushToPlayFab(position); } else if (GUILayout.Button("Load From Playfab", GUILayout.Width(128), GUILayout.Height(20))) { Achievement.LoadFromPlayfab(position); } else if (GUILayout.Button("Clear list", GUILayout.Width(128), GUILayout.Height(20))) { Achievement.ClearList(); } else if (GUILayout.Button("Save to Local", GUILayout.Width(128), GUILayout.Height(20))) { folderPath = EditorUtility.OpenFolderPanel("Select destination folder", folderPath, ""); if (folderPath != string.Empty) { Achievement.PushToLocalJSON(folderPath); } } else if (GUILayout.Button("Load from Local", GUILayout.Width(128), GUILayout.Height(20))) { filePath = EditorUtility.OpenFilePanel("Select destination folder", filePath, "json"); if (filePath != string.Empty) { Achievement.LoadFromLocalJSON(filePath); } } EditorGUILayout.EndHorizontal(); }
private void checkAchievements() { long now = DateTime.UtcNow.Ticks / 10000; // 1 millisecond if ((now - lastCheck) >= CHECK_INTERVAL) // this delays it to every 1.5 seconds { Vessel vessel = (FlightGlobals.fetch != null) ? FlightGlobals.ActiveVessel : null; if (vessel != null && EarnedAchievements.instance != null) { foreach (Achievement achievement in EarnedAchievements.instance.achievementsList) { if (EarnedAchievements.instance.earnedAchievements == null || !EarnedAchievements.instance.earnedAchievements.ContainsKey(achievement.getKey())) { string key = achievement.getKey(); //Vessel vessel = (FlightGlobals.fetch != null) ? FlightGlobals.ActiveVessel : null; //if (vessel != null) //{ try { if (achievement.check(vessel)) { string key2 = achievement.getKey(); AchievementEarn earn = new AchievementEarn(now, (vessel != null) ? vessel.vesselName : Achievements.UNKNOWN_VESSEL, achievement); EarnedAchievements.instance.earnedAchievements.Add(achievement.getKey(), earn); // queue for later display queuedEarnedAchievements.Add(achievement.getKey(), achievement); } } catch (Exception e) { Log.Exception(e); } } } } #if DEBUG long done = DateTime.UtcNow.Ticks / 10000; Log.Info("checking achievements took " + (done - now) + " ms"); #endif if ((queuedEarnedAchievements.Count() > 0) && (toast == null)) { Achievement achievement = queuedEarnedAchievements[queuedEarnedAchievements.Keys.Min()]; queuedEarnedAchievements.Remove(achievement.getKey()); //if (EarnedAchievements.instance.earnedAchievements.ContainsKey(achievement)) toast = null; //bool found = false; foreach (var e in EarnedAchievements.instance.earnedAchievements) { if (e.Key == achievement.getKey()) { toast = new Toast(achievement, e.Value); playAchievementEarnedClip(); awardReputation(achievement); //found = true; break; } } } lastCheck = now; } }
/// <summary> /// <see cref="IsCompleted(string)"/> /// </summary> /// <param name="achievement">the achievement to check</param> /// <returns>whether the user has completed the <paramref name="achievement"/></returns> public bool IsCompleted(Achievement achievement) { return(IsCompleted(achievement.Id)); }
/// <summary> /// <see cref="MarkCompleted(string,bool)"/> /// </summary> /// <param name="achievement">achievement to complete</param> /// <param name="completed">whether it should be completed</param> public void MarkCompleted(Achievement achievement, bool completed = true) { MarkCompleted(achievement.Id, completed); }