public void CreateBannerLabel(string chirpStr, uint senderID) { if (Shutdown || string.IsNullOrEmpty(chirpStr)) { return; } hasChirps = true; ChirpLabel = this.AddUIComponent <UILabel> (); if (ChirpLabel != null) { //ChirpLabel.autoHeight = true; //ChirpLabel.autoSize = true; ChirpLabel.verticalAlignment = UIVerticalAlignment.Middle; ChirpLabel.textAlignment = UIHorizontalAlignment.Left; ChirpLabel.relativePosition = new Vector3((this.width), 0); //ChirpLabel.height = (float)ChirpyBanner.CurrentConfig.TextSize; ChirpLabel.height = 10.0f; ChirpLabel.padding = new RectOffset(0, 0, 2, 2); ChirpLabel.textScaleMode = UITextScaleMode.None; ChirpLabel.textScale = 1.0f; ChirpLabel.autoHeight = false; ChirpLabel.opacity = 1.0f; ChirpLabel.processMarkup = true; ChirpLabel.text = chirpStr; ChirpLabel.objectUserData = (object)new InstanceID() { Citizen = senderID }; ChirpLabel.eventClick += (UIComponent comp, UIMouseEventParameter p) => { if (!((UnityEngine.Object)p.source != (UnityEngine.Object)null) || !((UnityEngine.Object)ToolsModifierControl.cameraController != (UnityEngine.Object)null)) { return; } InstanceID id = (InstanceID)p.source.objectUserData; if (!InstanceManager.IsValid(id)) { return; } ToolsModifierControl.cameraController.SetTarget(id, ToolsModifierControl.cameraController.transform.position, true); }; BannerLabelStruct bls = new BannerLabelStruct(); bls.RelativePosition = new Vector3(this.width, label_y_inset); // starting position is off screen, at max extent of parent panel bls.Label = ChirpLabel; bls.IsCurrentlyVisible = false; BannerLabelsQ.Enqueue(bls); ChirpLabel.SendToBack(); } }
public void RemoveBannerLabel(BannerLabelStruct blsfree) { this.RemoveUIComponent(blsfree.Label); }
public void OnGUI() { if (Shutdown) { return; } // if game is in free camera (screenshot/cinematic) mode, don't display chirp banner GameObject gameObject = GameObject.FindGameObjectWithTag("MainCamera"); if (gameObject != null) { CameraController cameraController = gameObject.GetComponent <CameraController>(); if (cameraController != null) { if (cameraController.m_freeCamera) { return; } } } // HideUI mod uses different mechanism to hide ui - it looks like it's disabling the UIView camera. // - check and see if uiview cam is disabled, and if so don't show banner var cameras = GameObject.FindObjectsOfType <Camera>(); foreach (var cam in cameras) { if (cam.name == "UIView") { if (!cam.enabled) { return; } break; } } // move the labels in the banner across the screen // - foreach label that is visible, move left by step // - if the first one is off screen pop it off queue // - if the last one is fully onscreen, start moving next in line bool bPopIt = false; float currentTrailingEdge = 0; // A queue can be enumerated without disturbing its contents. foreach (BannerLabelStruct bls in BannerLabelsQ) { if (bls.IsCurrentlyVisible) { bls.Label.relativePosition = new Vector3(bls.Label.relativePosition.x - Time.deltaTime * ChirpyBanner.CurrentConfig.ScrollSpeed, bls.Label.relativePosition.y, bls.Label.relativePosition.z); bls.RelativePosition = bls.Label.relativePosition; // is it off to the left entirely? if ((bls.Label.relativePosition.x + bls.Label.width) <= 0) { bPopIt = true; bls.IsCurrentlyVisible = false; bls.Label.isVisible = false; } else { // still in banner (in whole or in part) currentTrailingEdge += bls.RelativePosition.x + bls.Label.width; bls.Label.isVisible = true; } } else // I'm not yet visible... { // is there room for me to start scrolling? if (currentTrailingEdge < this.width) { // yes, there's room bls.Label.relativePosition = new Vector3(this.width, bls.Label.relativePosition.y, bls.Label.relativePosition.z); bls.RelativePosition = bls.Label.relativePosition; bls.IsCurrentlyVisible = true; bls.Label.isVisible = true; currentTrailingEdge += bls.RelativePosition.x + bls.Label.width; } } } if (bPopIt) { BannerLabelStruct blsfree = BannerLabelsQ.Dequeue(); this.RemoveUIComponent(blsfree.Label); } }
public void moveChirps(float simulationTimeDelta) { if (BannerPanel.hasChirps) { bool bPopIt = false; float currentTrailingEdge = 20; foreach (BannerLabelStruct bls in ChirpyBanner.theBannerPanel.BannerLabelsQ) { //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("chirp y position: {0}", bls.Label.relativePosition.y)); //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("chirp x position: {0}", bls.Label.relativePosition.x)); //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("chirp width: {0}", bls.Label.width)); if (bls.IsCurrentlyVisible) { bls.Label.relativePosition = new Vector3(bls.Label.relativePosition.x - simulationTimeDelta * MyConfig.ConfigHolder.Config.ScrollSpeed, bls.Label.relativePosition.y, bls.Label.relativePosition.z); bls.RelativePosition = bls.Label.relativePosition; //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("bls.Label.width: {0}", bls.Label.width)); //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("bls.Label.relativePosition: {0}", bls.Label.relativePosition)); // is it off to the left entirely? if ((bls.Label.relativePosition.x + bls.Label.width) <= 0) { //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("off to the left entirely")); bPopIt = true; bls.IsCurrentlyVisible = false; bls.Label.isVisible = false; } else { //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("still in banner")); // still in banner (in whole or in part) currentTrailingEdge += (bls.RelativePosition.x + bls.Label.width); bls.Label.isVisible = true; } } else // I'm not yet visible... //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("currentTrailingEdge: {0}", currentTrailingEdge)); // is there room for me to start scrolling? { if (currentTrailingEdge < ChirpyBanner.theBannerPanel.width) { //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("currentTrailingEdge: {0}", currentTrailingEdge)); //DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Message, string.Format("chirp width: {0}", bls.Label.width)); // yes, there's room bls.Label.relativePosition = new Vector3(ChirpyBanner.theBannerPanel.width, bls.Label.relativePosition.y, bls.Label.relativePosition.z); bls.RelativePosition = bls.Label.relativePosition; bls.IsCurrentlyVisible = true; bls.Label.isVisible = true; currentTrailingEdge += bls.RelativePosition.x + bls.Label.width; } } } if (bPopIt) { BannerLabelStruct blsfree = ChirpyBanner.theBannerPanel.BannerLabelsQ.Dequeue(); //ChirpyBanner.theBannerPanel.RemoveBannerLabel(blsfree); ChirpyBanner.theBannerPanel.RemoveUIComponent(blsfree.Label); } } }
public void CreateBannerLabel(string chirpStr, uint senderID) { if (Shutdown || string.IsNullOrEmpty(chirpStr)) { return; } UILabel newLabel = (UILabel)this.AddUIComponent <UILabel>(); if (newLabel != null) { //newLabel.autoSize = true; //newLabel.autoHeight = true; newLabel.verticalAlignment = UIVerticalAlignment.Middle; newLabel.textAlignment = UIHorizontalAlignment.Left; newLabel.height = this.height; newLabel.padding = new RectOffset(0, 0, 5, 5); newLabel.relativePosition = new Vector3(this.width, 0); newLabel.textScaleMode = UITextScaleMode.ScreenResolution; newLabel.textScale = (float)ChirpyBanner.CurrentConfig.TextSize / 20f; newLabel.opacity = 1.0f; newLabel.processMarkup = true; newLabel.text = chirpStr; newLabel.objectUserData = (object)new InstanceID() { Citizen = senderID }; newLabel.eventClick += (UIComponent comp, UIMouseEventParameter p) => { if (!((UnityEngine.Object)p.source != (UnityEngine.Object)null) || !((UnityEngine.Object)ToolsModifierControl.cameraController != (UnityEngine.Object)null)) { return; } InstanceID id = (InstanceID)p.source.objectUserData; if (!InstanceManager.IsValid(id)) { return; } ToolsModifierControl.cameraController.SetTarget(id, ToolsModifierControl.cameraController.transform.position, true); }; if (OurLabelFont == null) { OurLabelFont = newLabel.font; } if (OurLabelFont != null) { //OurLabelFont.size = ChirpyBanner.CurrentConfig.TextSize; UIFontRenderer fr = OurLabelFont.ObtainRenderer(); fr.textScale = newLabel.textScale; if (fr != null) { Vector2 ms = fr.MeasureString(chirpStr); newLabel.width = ms.x; newLabel.height = ms.y; if (this.height != (newLabel.height + 0)) { this.height = newLabel.height + 0; } } } BannerLabelStruct bls = new BannerLabelStruct(); bls.RelativePosition = new Vector3(this.width, label_y_inset); // starting position is off screen, at max extent of parent panel bls.Label = newLabel; bls.IsCurrentlyVisible = false; // add to queue BannerLabelsQ.Enqueue(bls); } }