public static void ShowMessage(NkhText nkhText, [Optional] double displayTime, [Optional] NkhImage nkhImage) { if (String.IsNullOrEmpty(nkhText.Title)) { var callingModInfo = MelonModInfo.GetCallingModInfo(); string callingModName = callingModInfo.Name; if (callingModInfo == null || callingModName.ToLower() == "nkhook6") { nkhText.Title = "NKHook6"; } else { nkhText.Title = callingModName; } } NkhMsg nkhMsg = new NkhMsg() { NkhText = nkhText, NkhImage = nkhImage, MsgShowTime = displayTime }; ShowMessage(nkhMsg); }
public static void AddNotification(NkhMsg msg) { if (InGame.instance == null || notifications.Count >= maxMessagesAtOnce) { notificationQueue.Enqueue(msg); return; } lock (notifications) { int slot = 0; for (int i = 0; i < maxMessagesAtOnce; i++) //this terrible looking code gets first availible slot for message. prevents overlapping msgs { bool skip = false; foreach (var item in notifications) { if (item.slot == i) { skip = true; break; } } if (skip) { continue; } slot = i; break; } Notification notification = new Notification(slot, msg); notifications.Add(notification); } }
public Notification(int slot, NkhMsg msg) { if (assetBundle == null) { assetBundle = AssetBundle.LoadFromMemory(Properties.Resources.ingame_popup); } if (canvas == null) { canvas = assetBundle.LoadAsset("Canvas").Cast <GameObject>(); } this.slot = slot; //====== // Initialize game object stuff //====== gameObject = GameObject.Instantiate(canvas); img = gameObject.transform.Find("Image").GetComponent <Image>(); title = gameObject.transform.Find("Image/Title").GetComponent <Text>(); body = gameObject.transform.Find("Image/Body").GetComponent <Text>(); //====== //set ui elements //====== currentMsg = msg; title.text = currentMsg.NkhText.Title; title.color = currentMsg.NkhText.TitleColor; body.text = currentMsg.NkhText.Body; body.color = currentMsg.NkhText.BodyColor; //set pos so elements are positioned correctly var windowHeight = Screen.height; //MelonLogger.Log(windowHeight.ToString()); var test1 = (windowHeight / 8) * 1.155f; //var spaceBetweenSlots = 110 * slot; //var spaceBetweenSlots = 135* slot; var spaceBetweenSlots = test1 * slot; var pos = img.transform.position; pos.x = -defaultWidth; pos.y -= spaceBetweenSlots + 55; pos.z = 955; //might get rid of this later. Setting ui to be very high up so it won't get put under other stuff. Game camera is at about 995 nextX = -defaultWidth; img.transform.position = pos; if (currentMsg.MsgShowTime == 0) { currentMsg.MsgShowTime = 1.5; } //prepping final variables for smooth transitions msgIsAlive = true; doShowMsg = true; doStallMsg = false; doHideMsg = false; UpdateEvent += Notification_UpdateEvent; }
public static void ShowMessage(NkhMsg nkhMsg) { NotificationMgr.AddNotification(nkhMsg); }