Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using Sandbox.Game.EntityComponents;
  2. using Sandbox.ModAPI.Ingame;
  3. using Sandbox.ModAPI.Interfaces;
  4. using SpaceEngineers.Game.ModAPI.Ingame;
  5. using System.Collections.Generic;
  6. using System.Collections;
  7. using System.Linq;
  8. using System.Text;
  9. using System;
  10. using VRage.Collections;
  11. using VRage.Game.Components;
  12. using VRage.Game.GUI.TextPanel;
  13. using VRage.Game.ModAPI.Ingame.Utilities;
  14. using VRage.Game.ModAPI.Ingame;
  15. using VRage.Game.ObjectBuilders.Definitions;
  16. using VRage.Game;
  17. using VRage;
  18. using VRageMath;
  19.  
  20. namespace IngameScript
  21. {
  22.     partial class Program : MyGridProgram
  23.     {
  24.  
  25.         IMyTextSurface _drawingSurface;
  26.         RectangleF _viewport;
  27.         public Program()
  28.         {
  29.             // The constructor, called only once every session and
  30.             // always before any other method is called. Use it to
  31.             // initialize your script.
  32.             //    
  33.             // The constructor is optional and can be removed if not
  34.             // needed.
  35.             //
  36.             // It's recommended to set Runtime.UpdateFrequency
  37.             // here, which will allow your script to run itself without a
  38.             // timer block.
  39.             _drawingSurface = Me.GetSurface(0);
  40.             Runtime.UpdateFrequency = UpdateFrequency.Update100;
  41.             _viewport = new RectangleF(
  42.     (_drawingSurface.TextureSize - _drawingSurface.SurfaceSize) / 2f,
  43.     _drawingSurface.SurfaceSize
  44. );
  45.  
  46.         }
  47.  
  48.         public void Save()
  49.         {
  50.         }
  51.  
  52.         public void Main(string argument, UpdateType updateSource)
  53.         {
  54.             var position = new Vector2(256, 20) + _viewport.Position;
  55.             var frame = _drawingSurface.DrawFrame();
  56.    
  57.                
  58.             List<IMySolarPanel> solarPanels = new List<IMySolarPanel>();
  59.             GridTerminalSystem.GetBlocksOfType(solarPanels);
  60.             int i = 1;
  61.             foreach(IMySolarPanel p in solarPanels)
  62.             {
  63.                 var sprite = new MySprite()
  64.                 {
  65.                     Type = SpriteType.TEXT,
  66.                     Data = "Solar[" + i + "] - " + p.CurrentOutput +"/" + p.MaxOutput + "MW (" + ((int)(p.CurrentOutput/p.MaxOutput*100.0)*1000)/1000.0 + "%)",
  67.                     Position = position,
  68.                     RotationOrScale = 0.8f /* 80 % of the font's default size */,
  69.                     Color = Color.Red,
  70.                     Alignment = TextAlignment.CENTER /* Center the text on the position */,
  71.                     FontId = "White"
  72.                 };
  73.                 frame.Add(sprite);
  74.                 position += new Vector2(0, 20);
  75.                 i++;
  76.             }
  77.             frame.Dispose();
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement