public HudElementNotification CreateNotification(string text, double[] color) { var elem = new HudElementNotification(capi, text, color); Notifications.Enqueue(elem); return(elem); }
public override void StartClientSide(ICoreClientAPI api) { this.capi = api; capi.Network.RegisterChannel("VSHUD.Notification").RegisterMessageType <AssetLocation>().SetMessageHandler <AssetLocation>((a) => { try { string notification = a.ToShortString(); CreateNotification(notification); } catch (Exception) { CreateNotification("Tried Parsing Bad Notification Packet, Ignoring."); } }); //move to separate thread at some point id = api.Event.RegisterGameTickListener((dt) => { if (IncomingNotifications.Count > 0) { if (Notifications.Count < maxElements) { for (int i = 0; i < maxElements - Notifications.Count; i++) { if (i > IncomingNotifications.Count) { break; } var notif = IncomingNotifications.Dequeue(); var elem = new HudElementNotification(api, notif.text, notif.color, notif.expiryTime - dt); Notifications.Enqueue(elem); } } else { //yea Notifications.First().expiryTime = -0.1f; } } }, 30); api.RegisterCommand("notification", "creates client notification", "", (id, args) => { string text = args.PopAll(); text = text.Length < 1 ? "Notification" : text; CreateNotification(text); }); }