private void CheckAchievementsForCrew(ProtoCrewMember kerbal, bool hasToBeFirst) { if (kerbal == null) { return; } // we want to check crew member only if (!kerbal.IsCrew()) { return; } // ok, lets check this kerbal HallOfFameEntry entry = HallOfFame.Instance().GetEntry(kerbal); if (entry != null) { foreach (Ribbon ribbon in RibbonPool.Instance()) { Achievement achievement = ribbon.GetAchievement(); if (achievement.HasToBeFirst() == hasToBeFirst) { if (achievement.Check(entry)) { recorder.Record(ribbon, kerbal); } } } } else { Log.Warning("no entry for kerbal " + kerbal.name + " in hall of fame"); } }
protected override void OnWindow(int id) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Button("Ribbons:", GUIStyles.STYLE_LABEL); if (GUILayout.Button("Close", FFStyles.STYLE_BUTTON)) { SetVisible(false); } GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView(scrollPosition, FFStyles.STYLE_SCROLLVIEW, GUILayout.Height(HEIGHT)); GUILayout.BeginVertical(); if (RibbonPool.Instance() != null) { foreach (Ribbon ribbon in RibbonPool.Instance()) { GUILayout.BeginHorizontal(FFStyles.STYLE_RIBBON_AREA); GUILayout.Label(ribbon.GetTexture(), FFStyles.STYLE_SINGLE_RIBBON); GUILayout.Label(ribbon.GetName() + ": " + ribbon.GetText(), FFStyles.STYLE_RIBBON_DESCRIPTION); GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.Label(RibbonPool.Instance().Count() + " ribbons in total (" + RibbonPool.Instance().GetCustomRibbons().Count + " custom ribbons)", FFStyles.STYLE_LABEL); GUILayout.EndVertical(); DragWindow(); }
private void changeCustomRibbon(LogbookEntry log) { string code = "X" + log.Code.Substring(2); if (Log.IsLogable(Log.LEVEL.TRACE)) { Log.Trace("changing custom ribbon for code " + code); } Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code); if (ribbon == null) { Log.Error("invalid custom ribbon code: " + code); return; } // CustomAchievement achievement = ribbon.GetAchievement() as CustomAchievement; if (achievement == null) { Log.Error("invalid custom ribbon achievement"); return; } achievement.SetName(log.Name); achievement.SetDescription(log.Data); if (Log.IsLogable(Log.LEVEL.TRACE)) { Log.Trace("custom ribbonchanged"); } }
public SaveGameConverter() { Log.Info("save game converted created"); RibbonPool pool = RibbonPool.Instance(); ScanSaveGames(); }
private void CheckAchievementsForVessel(VesselState previous, VesselState current, EventReport report, bool hasToBeFirst) { Log.Detail("CheckAchievementsForVessel, first=" + hasToBeFirst + ", with report=" + (report != null)); if (current != null) { foreach (Ribbon ribbon in RibbonPool.Instance()) { try { CheckRibbonForVessel(ribbon, previous, current, report, hasToBeFirst); } catch (Exception e) { Log.Error("exception caught in vessel check: " + e.Message + "(" + e.GetType() + ")"); } } if (Log.IsLogable(Log.LEVEL.TRACE)) { Log.Trace("all ribbons checked"); } } else { Log.Warning("no current vessel state; no achievements checked"); } }
private void CheckAchievementsForVessel(VesselState previous, VesselState current, EventReport report, bool hasToBeFirst) { if (current != null) { foreach (Ribbon ribbon in RibbonPool.Instance()) { Achievement achievement = ribbon.GetAchievement(); if (achievement.HasToBeFirst() == hasToBeFirst) { Vessel vessel = current.Origin; // check situationchanges if (achievement.Check(previous, current)) { recorder.Record(ribbon, vessel); } // check events if (report != null && achievement.Check(report)) { recorder.Record(ribbon, vessel); } } } } else { Log.Warning("no current vessel state; achievemnts not checked"); } }
private void CheckAchievementsForProgress(ProgressNode node) { Vessel vessel = FlightGlobals.ActiveVessel; HallOfFame halloffame = HallOfFame.Instance(); if (vessel != null) { foreach (Ribbon ribbon in RibbonPool.Instance()) { Achievement achievement = ribbon.GetAchievement(); if (achievement.Check(node)) { halloffame.BeginArwardOfRibbons(); try { foreach (ProtoCrewMember member in vessel.GetVesselCrew()) { // record crew member only if (member.IsCrew()) { recorder.Record(ribbon, member); } } } finally { halloffame.EndArwardOfRibbons(); } } } } }
private void DrawCustomAwardDialog() { GUILayout.BeginVertical(); GUILayout.Label("Select ribbon to award", FFStyles.STYLE_BUTTON_LABEL); GUILayout.BeginHorizontal(); // ribbon choice scrollPosCustRib = GUILayout.BeginScrollView(scrollPosCustRib, FFStyles.STYLE_SCROLLVIEW); foreach (Ribbon ribbon in RibbonPool.Instance().GetCustomRibbons()) { if (showOwnedRibbons || !entry.HasRibbon(ribbon)) { GUILayout.BeginHorizontal(); Achievement achievement = ribbon.GetAchievement(); string tooltip = ribbon.GetName(); GUIContent content = new GUIContent(ribbon.GetTexture(), tooltip); if (GUILayout.Button(content, FFStyles.STYLE_RIBBON)) { selected = ribbon; customRibbonName = achievement.GetName(); customRibbonText = achievement.GetDescription(); } GUILayout.Label(achievement.GetName(), FFStyles.STYLE_RIBBON_LABEL); GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); DrawSelectedCustomRibbon(selected); GUILayout.EndHorizontal(); // OK/CANCEL GUILayout.BeginHorizontal(); // Filter if (GUILayout.Toggle(showOwnedRibbons, "achieved ribbons", FFStyles.STYLE_TOGGLE)) { showOwnedRibbons = true; } else { showOwnedRibbons = false; } // GUILayout.FlexibleSpace(); // OK/CANCEL if (selected != null) { if (GUILayout.Button("OK", FFStyles.STYLE_CONTROL_BUTTON)) { AwardSelectedCustomRibbon(); // leave LeaveCustomRibbonSelection(); } } if (GUILayout.Button("CANCEL", FFStyles.STYLE_CONTROL_BUTTON)) { LeaveCustomRibbonSelection(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
// public static RibbonPool Instance() { if (instance == null) { instance = new RibbonPool(); Log.Info("new ribbon pool instance created"); } return(instance); }
public bool IsRibbonAwardedToKerbal(string code, ProtoCrewMember kerbal) { Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code); if (ribbon == null) { return(false); } return(IsRibbonAwardedToKerbal((object)ribbon, kerbal)); }
public void AwardRibbonToKerbal(string code, ProtoCrewMember kerbal) { Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code); if (ribbon == null) { Log.Error("no ribbon for code '" + code + "' found!"); return; } AwardRibbonToKerbal((object)ribbon, kerbal); }
protected override void OnWindow(int id) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Button("Ribbons:", GUIStyles.STYLE_LABEL); if (GUILayout.Button("Close", FFStyles.STYLE_BUTTON)) { SetVisible(false); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Search:", HighLogic.Skin.label); search = GUILayout.TextField(search, FFStyles.STYLE_STRETCHEDTEXTFIELD); GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView(scrollPosition, FFStyles.STYLE_SCROLLVIEW, GUILayout.Height(HEIGHT)); GUILayout.BeginVertical(); int ribbonsFound = 0; foreach (Ribbon ribbon in RibbonPool.Instance()) { string name = ribbon.GetName(); string description = ribbon.GetDescription(); if (search == null || search.Trim().Length == 0 || name.ContainsIgnoringCase(search) || description.ContainsIgnoringCase(search)) { GUILayout.BeginHorizontal(FFStyles.STYLE_RIBBON_AREA); GUILayout.Label(ribbon.GetTexture(), FFStyles.STYLE_SINGLE_RIBBON); GUILayout.Label(name + ": " + description, FFStyles.STYLE_RIBBON_DESCRIPTION); GUILayout.EndHorizontal(); ribbonsFound++; } } // no ribbons match search criteria if (ribbonsFound == 0) { GUILayout.BeginHorizontal(FFStyles.STYLE_RIBBON_AREA); GUILayout.Label("NONE", FFStyles.STYLE_SINGLE_RIBBON); GUILayout.Label("no ribbons found", FFStyles.STYLE_RIBBON_DESCRIPTION); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.Label( RibbonPool.Instance().Count() + " ribbons in total (" + RibbonPool.Instance().GetCustomRibbons().Count + " custom ribbons)", FFStyles.STYLE_STRETCHEDLABEL); GUILayout.EndVertical(); DragWindow(); }
public override void DoDataChange(object[] parameter) { if (parameter.Count() < 3) { Log.Warning("invalid parameter count for custom ribbon change"); return; } string s0 = parameter[0] as string; string s1 = parameter[1] as string; string s2 = parameter[2] as string; if (s0 == null || s1 == null || s2 == null) { Log.Warning("invalid parameter type for custom ribbon change"); return; } string code = "X" + s0.Substring(2); string name = s1; string text = s2; if (Log.IsLogable(Log.LEVEL.TRACE)) { Log.Trace("changing custom ribbon for code " + code); } Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code); if (ribbon == null) { Log.Error("invalid custom ribbon code: " + code); return; } // CustomAchievement achievement = ribbon.GetAchievement() as CustomAchievement; if (achievement == null) { Log.Error("invalid custom ribbon achievement"); return; } achievement.SetName(name); achievement.SetDescription(text); if (Log.IsLogable(Log.LEVEL.TRACE)) { Log.Trace("custom ribbon changed"); } }
public List <Ribbon> GetRibbonsOfLatestMission(ProtoCrewMember kerbal, double missionEndTime = 0) { List <Ribbon> result = new List <Ribbon>(); HallOfFameEntry entry = GetEntry(kerbal); // HashSet <Ribbon> ignored = new HashSet <Ribbon>(); List <LogbookEntry> log = new List <LogbookEntry>(entry.GetLogRefs()); log.Reverse(); bool start = false; string codeLaunch = ActionPool.ACTION_LAUNCH.GetCode(); string codeRecover = ActionPool.ACTION_RECOVER.GetCode(); foreach (LogbookEntry logentry in log) { string code = logentry.Code; if (code.Equals(codeRecover) && !start) { start = true; } // last launch or previous recover ends search // last launch: mission start detected // previous recover: there was no real launch else if (code.Equals(codeLaunch) || code.Equals(codeRecover)) { break; } else if (start || logentry.UniversalTime <= missionEndTime) { Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code); if (ribbon != null) { // add this ribbon if not already taken or superseded if (!ignored.Contains(ribbon)) { result.Add(ribbon); // add the new ribbon and all superseded ribbons to the ignore set while (ribbon != null) { ignored.Add(ribbon); ribbon = ribbon.SupersedeRibbon(); } } } } } return(result); }
private void CheckAchievementsForRosterStatus(ProtoCrewMember kerbal, ProtoCrewMember.RosterStatus oldState, ProtoCrewMember.RosterStatus newState, bool hasToBeFirst) { foreach (Ribbon ribbon in RibbonPool.Instance()) { Achievement achievement = ribbon.GetAchievement(); if (achievement.Check(kerbal, oldState, newState)) { // record crew member only if (kerbal.IsCrew()) { recorder.Record(ribbon, kerbal); } } } }
public override string ToString() { string timestamp = Utils.ConvertToEarthTime(UniversalTime) + ": "; Action action = ActionPool.Instance().GetActionForCode(Code); if (action != null) { return(timestamp + action.CreateLogBookEntry(this)); } Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(Code); if (ribbon != null) { Achievement achievement = ribbon.GetAchievement(); return(timestamp + achievement.CreateLogBookEntry(this)); } return("unknown logbook entry (code " + Code + ")"); }
private void CheckAchievementsForCrew(ProtoCrewMember kerbal, bool hasToBeFirst) { if (kerbal == null) { return; } // we do not want to check tourists if (kerbal.IsTourist()) { return; } // ok, lets check this kerbal HallOfFameEntry entry = HallOfFame.Instance().GetOrCreateEntry(kerbal); if (entry != null) { foreach (Ribbon ribbon in RibbonPool.Instance()) { try { Achievement achievement = ribbon.GetAchievement(); if (achievement.HasToBeFirst() == hasToBeFirst) { if (achievement.Check(entry)) { recorder.Record(ribbon, kerbal); } } } catch (Exception e) { Log.Error("exception caught in crew check: " + e.Message + "(" + e.GetType() + ")"); } } } else { Log.Warning("no entry for kerbal " + kerbal.name + " in hall of fame"); } }
private void Convert() { status = STATUS.CONVERTING; // just create a game, to fire a OnGameStateCreated event, so the RibbonPool instance gets populated new Game(); if (!RibbonPool.Instance().IsReady()) { Log.Warning("ribbon pool not ready for converting games!"); } // foreach (String folder in gamesToConvert) { ConvertSaveGameFolder(folder); } status = STATUS.DONE; // test if all saves are converted if (gamesToConvert.Count == gamesWithLegacyData.Count) { Log.Info("all games converted, disabling game converter"); FinalFrontier.configuration.convertGames = false; } }
public void Load(string filename) { StreamReader file = null; try { file = File.OpenText(filename); string line; while ((line = file.ReadLine()) != null) { string[] tokens = line.Split(' '); if (tokens.Count() > 1) { string code = tokens[0]; string supersede = tokens[1]; Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code); if (ribbon == null) { continue; } Ribbon super = RibbonPool.Instance().GetRibbonForCode(supersede); if (super == null) { continue; } chain.Add(ribbon, super); } } } finally { if (file != null) { file.Close(); } } }
private void CheckAchievementsForContracts(ProtoCrewMember kerbal, Contract contract, bool hasToBeFirst) { if (kerbal == null) { return; } // we do not want to check tourists if (kerbal.IsTourist()) { return; } // ok, lets check the kerbal foreach (Ribbon ribbon in RibbonPool.Instance()) { Achievement achievement = ribbon.GetAchievement(); if (achievement.HasToBeFirst() == hasToBeFirst) { if (achievement.Check(contract)) { recorder.Record(ribbon, kerbal); } } } }
public Ribbon RegisterRibbon(string code, string pathToRibbonTexture, string name, string description, bool first, int prestige) { return(RibbonPool.Instance().RegisterExternalRibbon(code, pathToRibbonTexture, name, description, first, prestige)); }
public Ribbon RegisterCustomRibbon(int id, string pathToRibbonTexture, string name, string description, int prestige) { return(RibbonPool.Instance().RegisterCustomRibbon(id, pathToRibbonTexture, name, description, prestige)); }
public void CreateFromLogbook(List <LogbookEntry> book) { Log.Detail("creating hall of fame from logbook"); Clear(); lock (this) { if (book.Count == 0) { Log.Detail("no logbook entries"); return; } Log.Detail("resolving logbook"); LogbookEntry lastEntry = null; foreach (LogbookEntry log in book) { if (Log.IsLogable(Log.LEVEL.TRACE)) { Log.Trace("processing logbook entry " + log.UniversalTime + ": " + log.Code + " " + log.Name); } try { // this is a custom ribbon entry if (log.Code.StartsWith(DataChange.DATACHANGE_CUSTOMRIBBON.GetCode())) { changeCustomRibbon(log); // if (Log.IsLogable(Log.LEVEL.DETAIL)) { Log.Detail("adding custom ribbon " + log.Code + ": " + log.Name); } logbook.Add(log); // continue; } HallOfFameEntry entry = GetEntry(log.Name); if (entry == null) { entry = CreateEntry(log.Name); } Action action = ActionPool.Instance().GetActionForCode(log.Code); if (action != null) { action.DoAction(log.UniversalTime, entry, log.Data); addLogbookEntry(log, entry); } else { // those codes have change switch (log.Code) { case "CO": log.Code = "CO:Sun"; break; case "CO1": log.Code = "CO1:Sun"; break; } // Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(log.Code); if (ribbon != null) { Achievement achievement = ribbon.GetAchievement(); bool sameTransaction = InSameTransaction(log, lastEntry); if (!achievement.HasToBeFirst() || !accomplished.Contains(achievement) || sameTransaction) { // make sure old transactions have same timestamps in each entry if (sameTransaction) { log.UniversalTime = lastEntry.UniversalTime; } // entry.Award(ribbon); addLogbookEntry(log, entry); // to prevent multiple first ribbon awards accomplished.Add(ribbon.GetAchievement()); } } else { Log.Warning("no ribbon for code " + log.Code + " found"); } } } catch (KeyNotFoundException) { Log.Error("kerbal " + log.Name + " not found"); } catch (Exception e) { Log.Error("failed to create data in hall of fame for " + log.Name); Log.Error(e.GetType() + ": " + e.Message); } lastEntry = log; } // end for } Log.Detail("new hall of fame created"); }