public override void Entry(IModHelper helper) { RelationshipAPI = new RelationshipAPI(Monitor); Config = helper.ReadConfig <ModConfig>() ?? new ModConfig(); displayEnabled = Config.displayTooltipByDefault; tooltip = new Tooltip(0, 0, Color.White, anchor: FrameAnchor.BottomLeft); HoverRelationships = new List <IRelationship>(); ScreenRelationships = new List <IRelationship>(); screenCharacters = new List <Character>(); screenTooltipCache = new Dictionary <Character, Tooltip>(); RelationshipAPI.RegisterRelationships += RegisterDefaultRelationships; BookcaseEvents.FirstGameTick.Add((e) => InitRelationships(), Priority.Lowest); BookcaseEvents.GameQuaterSecondTick.Add(QuaterSecondUpdate); InputEvents.ButtonPressed += (obj, e) => { if (e.Button == Config.toggleDisplayKey) { displayEnabled = !displayEnabled; } }; GraphicsEvents.OnPostRenderEvent += DrawTooltip; helper.WriteConfig(Config); Monitor.Log("Entry Complete", LogLevel.Trace); }
/// <summary> /// Subscribes the stored Relationships to the relevant events /// </summary> private void InitRelationships() { //Fire registration event EventArgsRegisterRelationships result = RelationshipAPI.FireRegistrationEvent(); //copy arrays HoverRelationships.AddRange(result.RelationshipsOnHover); ScreenRelationships.AddRange(result.RelationshipsOnScreen); //Sort by Priority HoverRelationships.Sort((x, y) => y.Priority - x.Priority); ScreenRelationships.Sort((x, y) => y.Priority - x.Priority); //Log Monitor.Log($"API found {HoverRelationships.Count()} Hover, and {ScreenRelationships.Count()} Screen registered types.", LogLevel.Info); string str = ""; str += $"{Environment.NewLine}Hover Types ({HoverRelationships.Count()}):"; str += String.Format("{0}{1,10} :: {2}", Environment.NewLine, "<Priority>", "<Fully Qualified Type>"); foreach (IRelationship r in HoverRelationships) { str += String.Format("{0}{1,10} :: {2}", Environment.NewLine, r.Priority, r.GetType().ToString()); } str += $"{Environment.NewLine}Screen Types ({ScreenRelationships.Count()}):"; str += String.Format("{0}{1,10} :: {2}", Environment.NewLine, "<Priority>", "<Fully Qualified Type>"); foreach (IRelationship r in ScreenRelationships) { str += String.Format("{0}{1,10} :: {2}", Environment.NewLine, r.Priority, r.GetType().ToString()); } Monitor.Log(str); //subscribe to events foreach (IRelationship r in HoverRelationships.Union(ScreenRelationships)) { if (r is Relationships.IUpdateable) { var o = r as Relationships.IUpdateable; if (o.OnTick != null) { GameEvents.UpdateTick += (obj, args) => { o.OnTick(selectedCharacter, heldItem); } } ; if (o.OnQuaterSecondTick != null) { GameEvents.QuarterSecondTick += (obj, args) => { o.OnQuaterSecondTick(selectedCharacter, heldItem); } } ; } if (r is IInputListener) { var o = r as IInputListener; if (o.ButtonPressed != null) { InputEvents.ButtonPressed += (obj, args) => { o.ButtonPressed.Invoke(selectedCharacter, heldItem, args); } } ; if (o.ButtonReleased != null) { InputEvents.ButtonReleased += (obj, args) => { o.ButtonReleased(selectedCharacter, heldItem, args); } } ; } if (r is IPerSaveSerializable) { var o = r as IPerSaveSerializable; if (o.SaveData != null) { SaveEvents.AfterSave += (obj, args) => { o.SaveData(Helper); } } ; if (o.LoadData != null) { SaveEvents.AfterLoad += (obj, args) => { o.LoadData(Helper); } } ; } } Monitor.Log("Relationship Event Subscription Complete."); }