Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. Replace the LCD_NAME value with a part of your LCD IDs
- const string LCD_NAME = "LCD-Tank";
- // 2. Replace the LCD_NAME value with a part of your Oxygen/Hydrogen Tank ID that is unique
- const string tank_TAG = "Tnk";
- // 3. Add to both names a '#' followed by a number between '000' and '999'
- // 4. Run the program.
- void Main()
- {
- List<IMyTerminalBlock> _screens = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName (LCD_NAME, _screens);
- const string imagePrefix1 = "Oxygen ";
- const string imagePrefix2 = "Hydrogen ";
- const string nonFunctionalImage = "Construction";
- const string warningImage = "Danger";
- const int roundpercent = 1;
- for(int i = 0; i < _screens.Count; i++)
- {
- if(_screens [i] != null) {
- List<IMyTerminalBlock> _tanks = new List<IMyTerminalBlock>();
- GridTerminalSystem.SearchBlocksOfName (tank_TAG, _tanks);
- IMyTextPanel screen = (IMyTextPanel) _screens[i];
- string _name = screen.CustomName;
- if(_name.Contains ("#")) {
- string _tankID = _name.Substring (_name.IndexOf ('#'), 4);
- for(int a = 0; a < _tanks.Count; a++) {
- if(_tanks [a] != null) {
- if (_tanks [a].CustomName.Contains (_tankID)) {
- // Get current visible Image
- string _oldImage = screen.CurrentlyShownImage;
- string _imagename = screen.CurrentlyShownImage;
- if (_tanks [a].IsFunctional) {
- IMyOxygenTank tank = (IMyOxygenTank) _tanks [a];
- float currentLevel;
- if(tank != null) {
- if(tank.BlockDefinition.SubtypeId.Contains("Hydrogen")){
- currentLevel = tank.GetOxygenLevel();
- var roundfill = (int)System.Math.Round(currentLevel * 100 / roundpercent) * roundpercent;
- _imagename = imagePrefix2 + roundfill.ToString("D3");
- if (!_tanks [a].IsWorking) {
- // If new Image == null, load former image
- if (screen.CurrentlyShownImage != warningImage) {
- _imagename = warningImage;
- }
- }
- Echo("Tank " + _tankID + " - " + roundfill.ToString("D3") + "% - '" + _imagename + "'");
- } else {
- currentLevel = tank.GetOxygenLevel();
- var roundfill = (int)System.Math.Round(currentLevel * 100 / roundpercent) * roundpercent;
- _imagename = imagePrefix1 + roundfill.ToString("D3");
- if (!_tanks [a].IsWorking) {
- // If new Image == null, load former image
- if (screen.CurrentlyShownImage != warningImage) {
- _imagename = warningImage;
- }
- }
- Echo("Tank " + _tankID + " - " + roundfill.ToString("D3") + "% - '" + _imagename + "'");
- }
- }
- } else {
- // If new Image == null, load former image
- if (screen.CurrentlyShownImage == warningImage) {
- _imagename = nonFunctionalImage;
- } else {
- _imagename = warningImage;
- }
- }
- screen.ClearImagesFromSelection();
- screen.AddImageToSelection(_imagename);
- // Check if new Image does exist, else load former Image
- if (screen.CurrentlyShownImage == null) {
- Echo (_tankID + " '" + screen.CurrentlyShownImage + "' does not exist!");
- screen.AddImageToSelection(_oldImage);
- }
- screen.ShowTextureOnScreen();
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment