Space Engineers

Space Engineers

评价数不足
LCD library for modders
   
奖励
收藏
已收藏
取消收藏
文件大小
发表于
更新日期
2.243 KB
2018 年 6 月 6 日 上午 8:04
2018 年 6 月 7 日 下午 12:59
6 项改动说明 ( 查看 )

订阅以下载
LCD library for modders

描述
Description
This library is made for other modders. I wanted to make something very simple to handle LCDs. I designed these helpers using classes so the library code wont never conflit with yours.

Basic Usage

BasicLibrary basicLibrary = new BasicLibrary(GridTerminalSystem, Echo); LCDHelper lcdHelper = new LCDHelper(basicLibrary, new Color(150,20,20)); IMyTextPanel lcd = lcdHelper.FindFirst(); lcdHelper.DisplayMessage("Hello world !", lcd);

The following code will find lcds named or contrained in groups LCDName1, LCDName2 and LCDGroupName and return a list of them (It will warn using Echo if group are not existing/empty and then if it could find find a LCD matching the name. It will return an empty list if it could not find anything) :

string[] lcdNamesAndGroupNames = { "LCDName1", "LCDName2", "LCDGroupName" }; List<IMyTextPanel> list = lcdHelper.Find(lcdNamesAndGroupNames );

A bit more advanced usage

You can use the internal buffer to display text (prevent multiple display call to LCD, more performance friendly) :

.... Vector3D shipForwardVector = controller.WorldMatrix.Forward; lcdHelper.ClearMessageBuffer(); lcdHelper.AppendMessageBuffer("Hello\n"); lcdHelper.AppendMessageBufferFormatted("forward ({0}, {1}, {2})", Math.Round(shipForwardVector.X,0), Math.Round(shipForwardVector.Y, 0), Math.Round(shipForwardVector.Z, 0)); lcdHelper.DisplayMessageBuffer(lcds); ----

API

InitDiplay methods is called in search method. But you can use them to change color or font size.

  • public LCDHelper(BasicLibrary basicLibrary, Color defaultFontColor, float defaultSize=2)
  • void DisplayMessage(string message, List<IMyTextPanel> myTextPanels, bool append = false)
  • void DisplayMessage(string message, IMyTextPanel myTextPanel, bool append = false)
  • IMyTextPanel FindFirst()
  • List<IMyTextPanel> Find(string[] lcdGoupsAndNames) : will return all blocks of type LCD found by names and inside group by their names too (you can mix those in the array)
  • InitDisplays(List<IMyTextPanel> myTextPanels) : init LCD with the default color and font size
  • void InitDisplay(IMyTextPanel myTextPanel) : init LCD with the default color and font size
  • void InitDisplays(List<IMyTextPanel> myTextPanels, Color color, float fontSize)
  • void InitDisplay(IMyTextPanel myTextPanel, Color color, float fontSize)

Next 4 methods are made to use an internal stringbuffer to output a lot of text and not call display on LCD for each line of text for performance issues :
  • void ClearMessageBuffer()
  • void AppendMessageBuffer(string text)
  • void AppendMessageBufferFormatted(string text, params object[] args)
  • void DisplayMessageBuffer(List<IMyTextPanel> myTextPanels)

More about it

This library come with another library which adds some handy functions :
  • T FindFirstBlockByType<T>() : return the first block of type T it finds (or null if none)
  • List<T> FindBlocksByNameAndGroup<T>(string[] names, string typeOfBlockForMessage) : will return all blocks of type found by names and inside group by their names too (you can mix those in the array)
  • AppendFormatted / AppendFormattedNewLine : help with adding formatted text to a stringbuffer
  • static double GetCurrentTimeInMs() : return number of ms since 1/1/1970

If you use this library please credit me on your workshop creation page. Thanks :)

Don't forget to rate this mod, it helps people to see it and i hope i can help the community focus on more important tasks than writing code to handle finding and writing to LCD.