Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void RefreshLCDs(this IMyFunctionalBlock ftl)
- {
- var objBuilderType = new MyObjectBuilderType(typeof(MyObjectBuilder_TextPanel));
- var lcdblocks = ftl.GetGroupedBlocks(objBuilderType);
- var ftld = ftl.GetFTLData();
- if (lcdblocks.Count == 0)
- {
- var list = new List<IMySlimBlock>();
- // Get all the lcdblocks on the entity
- if (ftl.GetTopMostParent() is Sandbox.ModAPI.Ingame.IMyCubeGrid)
- {
- (ftl.GetTopMostParent() as Sandbox.ModAPI.IMyCubeGrid).GetBlocks(list,
- (x) => x.FatBlock != null && x.FatBlock.BlockDefinition.TypeId == objBuilderType);
- }
- // Search all of them finding the best one
- foreach (var entity in list)
- {
- var lcdblock = entity.FatBlock as Sandbox.ModAPI.Ingame.IMyTextPanel;
- if (lcdblock == null || !lcdblock.IsFunctional)
- continue;
- //Logger.Instance.LogDebug("Found LCD: " + lcdblock.DisplayNameText);
- if (!string.IsNullOrEmpty(lcdblock.DisplayNameText) &&
- (lcdblock.DisplayNameText.ToUpperInvariant().Contains("FTL") ||
- lcdblock.GetPublicTitle().ToUpperInvariant().Contains("FTL") ||
- lcdblock.GetPrivateTitle().ToUpperInvariant().Contains("FTL")))
- {
- // If a lcdblock contains the text FTL, always use it
- lcdblocks.Add(lcdblock as IMyTerminalBlock);
- break;
- }
- }
- }
- if (lcdblocks.Count == 0)
- return;
- // TODO: have different LCDs display different information
- StringBuilder LCDText = new StringBuilder(60);
- StringBuilder LCDTextUpgrade = new StringBuilder(80);
- // Calculate distance
- double distance = (ftld.jumpDest - ftl.GetTopMostParent().PositionComp.WorldMatrix.Translation).Length();
- string distunits = "m";
- double range = ftld.baseRange * ftld.rangeFactor;
- string rangeunits = "m";
- string status = ftld.jumpState.ToString();
- if (!ftl.IsFunctional)
- status = "Offline";
- if ((ftld.flags & JumpFlags.Disabled) == JumpFlags.Disabled)
- status = "Disabled";
- CalculateUnits(ref distance, ref distunits);
- CalculateUnits(ref range, ref rangeunits);
- LCDText.Append(string.Format("FTL Status: {0}\n", status));
- LCDTextUpgrade.Append(string.Format("Upgrade Modules:\n"));
- //Logger.Instance.Active = false;
- if (ftl.IsFunctional && !((ftld.flags & JumpFlags.Disabled) == JumpFlags.Disabled))
- {
- LCDText.Append(string.Format("Power: {0,16:F2} MW\n", ftl.GetPowerWanted()));
- //LCDText.Append(string.Format("Power: {0,21:P0}\n", (MyAPIGateway.Session.CreativeMode ? 1.0 : GetTotalFTLPower(m_ftl.GetFTLDrives()) / m_ftl.GetPowerPercentage())));
- //LCDText.Append(string.Format("Power Allocated: {0:F0}/{1:P0}\n", GetTotalFTLPower(m_ftl.GetFTLDrives()) * 100, m_ftl.GetPowerPercentage()));
- LCDText.Append(string.Format("Distance: {0,13:N0} {1,-2}\n", distance, distunits));
- LCDText.Append(string.Format("Mass: {0,15:N0} kg\n", ftld.totalMass));
- bool doesCollide = false;
- // Do we collide?
- if ((ftld.flags & JumpFlags.ShowCollision) == JumpFlags.ShowCollision)
- {
- VRageMath.BoundingSphereD jumpSphere;
- jumpSphere = new VRageMath.BoundingSphereD(ftld.jumpDest, ftl.GetTopMostParent().PositionComp.LocalVolume.Radius);
- List<IMyEntity> entities = MyAPIGateway.Entities.GetEntitiesInSphere(ref jumpSphere);
- VRageMath.Vector3 lastPos = new VRageMath.Vector3();
- if (MyAPIGateway.Entities.IsInsideVoxel(
- new VRageMath.Vector3(jumpSphere.Center.X, jumpSphere.Center.Y, jumpSphere.Center.Z),
- VRageMath.Vector3D.Zero,
- out lastPos))
- {
- doesCollide = true;
- }
- if (!doesCollide)
- {
- foreach (var entity in entities)
- {
- if (entity is Sandbox.ModAPI.IMyCubeGrid && entity.GetTopMostParent().EntityId != ftl.GetTopMostParent().EntityId)
- {
- doesCollide = true;
- break;
- }
- }
- }
- }
- if (ftld.jumpState == JumpState.Spooling)
- LCDText.Append(string.Format("Jumping in {0:F0}s\n", (ftld.jumpTime - DateTime.Now).TotalSeconds));
- else if (ftld.jumpState == JumpState.Cooldown)
- LCDText.Append(string.Format("Cooldown for {0:F0}s\n", (ftld.resetTime - DateTime.Now).TotalSeconds));
- else
- LCDText.Append("\n");
- if (IsInhibited(ftld.jumpDest) || IsInhibited(ftl.GetPosition()))
- LCDText.Append("\nDestination:\nX = ?\nY = ?\nZ = ?\n");
- else
- LCDText.Append(string.Format("\nDestination{3}:\nX = {0:N0}\nY = {1:N0}\nZ = {2:N0}\n",
- ftld.jumpDest.X, ftld.jumpDest.Y, ftld.jumpDest.Z, doesCollide ? " (Warning!)" : string.Empty));
- var capblocks = ftl.GetCapacitors();
- int totalcaps = 0;
- foreach (var cap in capblocks)
- {
- if (cap.HasCapacityRemaining && cap.IsWorking && cap.IsFunctional)
- totalcaps++;
- }
- LCDTextUpgrade.Append(string.Format("Max Range: {0,10:N0} {1,-2}\n", range, rangeunits));
- LCDTextUpgrade.Append(string.Format("Max Accuracy:{0,12:P0}\n", ftld.accuracyFactor));
- LCDTextUpgrade.Append(string.Format("Spool Efficiency:{0,8:P0}\n", ftld.spoolFactor));
- LCDTextUpgrade.Append(string.Format("Power Efficiency:{0,8:P0}\n", ftld.powerFactor));
- LCDTextUpgrade.Append(string.Format("Working Capacitors: {0}\r\n", totalcaps));
- }
- else
- {
- LCDTextUpgrade.Append(string.Format("FTL Offline\n"));
- }
- Logger.Instance.Active = true;
- foreach (var entity in lcdblocks)
- {
- Sandbox.ModAPI.Ingame.IMyTextPanel lcdblock = entity as Sandbox.ModAPI.Ingame.IMyTextPanel;
- //if (Globals.Debug)
- // Sandbox.ModAPI.MyAPIGateway.Utilities.ShowNotification("Found LCD: " + lcdblock.DisplayNameText, 3500);
- var existingText = lcdblock.GetPublicText();
- var clearText = " \n \n \n \n \n \n \n ";
- // For network optimization, don't do anything if the text is the same
- if (existingText == LCDText.ToString())
- continue;
- if (!ftl.IsBlockAccessible(entity))
- {
- var accessDeniedText = "FTL Status: \nAccess Denied";
- if (lcdblock.CustomName.ToUpperInvariant().Contains("UPGRADES"))
- accessDeniedText = "Upgrade Modules: \nAccess Denied";
- if (existingText != accessDeniedText)
- {
- // The spaces prevent the ghosting that happens when updating text
- lcdblock.WritePublicText(string.Empty);
- lcdblock.WritePublicText(clearText);
- lcdblock.WritePublicText(accessDeniedText);
- }
- continue;
- }
- // Update LCD text
- if (lcdblock.CustomName.ToUpperInvariant().Contains("UPGRADE") ||
- lcdblock.GetPublicTitle().ToUpperInvariant().Contains("UPGRADE") ||
- lcdblock.GetPrivateTitle().ToUpperInvariant().Contains("UPGRADE"))
- {
- if (existingText != LCDTextUpgrade.ToString())
- {
- lcdblock.WritePublicText(string.Empty);
- lcdblock.WritePublicText(clearText);
- lcdblock.WritePublicText(LCDTextUpgrade.ToString());
- }
- else
- {
- continue;
- }
- }
- else
- {
- if (existingText != LCDText.ToString())
- {
- lcdblock.WritePublicText(string.Empty);
- lcdblock.WritePublicText(clearText);
- lcdblock.WritePublicText(LCDText.ToString());
- }
- else
- {
- continue;
- }
- }
- if (FTLAdmin.Configuration.FixedFontSize)
- {
- float fontsize = 2.0f; // Default to a more conservative 2.0, in case there are modded blocks
- // Set font size depending on the block (only handles stock blocks)
- switch (lcdblock.BlockDefinition.SubtypeId)
- {
- case "LargeLCDPanelWide":
- case "SmallLCDPanelWide":
- fontsize = 3.5f;
- break;
- case "LargeLCDPanel":
- case "SmallLCDPanel":
- fontsize = 1.7f;
- break;
- case "LargeTextPanel":
- case "SmallTextPanel":
- fontsize = 1.7f;
- break;
- }
- lcdblock.SetValueFloat("FontSize", fontsize);
- }
- lcdblock.ShowPublicTextOnScreen();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement