Skip to content

Instantly share code, notes, and snippets.

@dsandler
Created May 12, 2020 01:27
Show Gist options
  • Save dsandler/7f03e70d390b6a34f685389909715c6f to your computer and use it in GitHub Desktop.
Save dsandler/7f03e70d390b6a34f685389909715c6f to your computer and use it in GitHub Desktop.
Space Engineers programmable block script to show all sprites in the game, one by one
// https://github.com/malware-dev/MDK-SE/wiki/Text-Panels-and-Drawing-Sprites
// https://steamcommunity.com/app/244850/discussions/0/3158630999987167277/
IMyTextSurface _drawingSurface;
RectangleF _viewport;
float _minSize;
int _t = 0;
const float TEXT_BOX_SIZE = 20;
const float TEXT_BOX_MARGIN = 2;
// Script constructor
public Program()
{
_drawingSurface = Me.GetSurface(0);
Runtime.UpdateFrequency = UpdateFrequency.Update100;
_viewport = new RectangleF(
(_drawingSurface.TextureSize - _drawingSurface.SurfaceSize) / 2f,
_drawingSurface.SurfaceSize
);
_minSize = Math.Min(_viewport.Width, _viewport.Height) - TEXT_BOX_SIZE - TEXT_BOX_MARGIN;
PrepareTextSurfaceForSprites(_drawingSurface);
}
// Main Entry Point
public void Main(string argument, UpdateType updateType)
{
// Begin a new frame
var frame = _drawingSurface.DrawFrame();
// All sprites must be added to the frame here
DrawSprites(ref frame);
// We are done with the frame, send all the sprites to the text panel
frame.Dispose();
_t++;
}
// Drawing Sprites
public void DrawSprites(ref MySpriteDrawFrame frame)
{
List<string> allSprites = new List<string>();
_drawingSurface.GetSprites(allSprites);
var sprite = new MySprite(SpriteType.TEXTURE, allSprites[_t], color: new Color(1f, 1f, 1f, 1f), size: new Vector2(_minSize, _minSize));
sprite.Position = new Vector2(_viewport.Width / 2, _viewport.Height / 2 - TEXT_BOX_SIZE - TEXT_BOX_MARGIN) + _viewport.Position;
frame.Add(sprite);
sprite = MySprite.CreateText($"Sprite #{_t}: \"{allSprites[_t]}\"", "Monospace", Color.White, 0.5f, TextAlignment.LEFT);
sprite.Position = new Vector2(_viewport.X + TEXT_BOX_MARGIN, _viewport.Bottom - TEXT_BOX_SIZE - TEXT_BOX_MARGIN);
frame.Add(sprite);
}
public void PrepareTextSurfaceForSprites(IMyTextSurface textSurface)
{
textSurface.ContentType = ContentType.SCRIPT;
textSurface.Script = "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment