Advertisement
StanHebben

Jagged arrays

Jan 19th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. const float PROGRAM_VERSION = 0.01f;
  2.  
  3. string[] DataLoadedFromMemoryBank;
  4.  
  5. string SelOpenBracket = "<";
  6. string SelCloseBracket = ">";
  7.  
  8. const string NLCR = "\n\r";
  9. const string ITEM_PERFIX = "- ";
  10.  
  11. const string ARG1 = "NEXT";
  12. const string ARG2 = "PREV";
  13. const string ARG3 = "OK";
  14. const string ARG4 = "CANCEL";
  15. const string ARG5 = "BACK";
  16.  
  17. static string[] ConfirmSubMenu = new string[2] { "Confirm", "Cancel" };
  18. static string[] SelectMenu = new string[2] { "Select", "Cancel" };
  19. static string SecondSubMenu = "Back";
  20.  
  21. static string[] MainMenu = new string[2] { "Login", "Power Off" };
  22. static string[] SecondMenu = new string[4] { "Ship Control Systems", "Installation", "Ship Data", "Logout" };
  23. static string[] InstallationMenu = new string[5] { "Install Ship Profile", "Remove Ship Profile", "Update Ship Profile", "Add User", "Remove User" };
  24. static string[] ShipProfiles = new string[5] { "Fighter", "Miner", "Transporter", "Builder", "Escape Pod" };
  25.  
  26. static string[] FighterControlSystems = new string[8] { "Check Systems", "Dock", "Undock", "Trun Engines On", "Turn Engines Off", "Restock Ammo", "Activate Weapons", "Deactivate Weapons" };
  27. static string[] MTBControlSystems = new string[7] { "Check Systems", "Dock", "Undock", "Trun Engines On", "Turn Engines Off", "Load Cargo", "Unload Cargo" };
  28. static string[] EscapePodSystems = new string[6] { "Check Systems", "Turn Engines On", "Turn Engines Off", "Load Cargo", "Unload Cargo", "LAUNCH!" };
  29.  
  30. static string[] Keyboard = new string[63]{
  31. "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
  32. "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
  33. "0","1","2","3","4","5","6","7","8","9"," "};
  34.  
  35. static string[][] AllMenusArrayHolder;
  36.  
  37. const float ESCAPE_POD_LAUNCH_TIME = 30f;
  38.  
  39. bool UsingModdedCockpit = false;
  40. string ModdedCockpitName = "";
  41.  
  42. string MenuTitle = "";
  43.  
  44. string ShipName = "";
  45.  
  46. bool UsingAlertMod = false;
  47. string AlertModProgBlockName = "";
  48.  
  49. int MenuIndex = 0;
  50. int ItemIndex = 0;
  51.  
  52.  
  53. bool FirstRun = true;
  54.  
  55. static Program()
  56. {
  57. AllMenusArrayHolder = new string[10][];
  58. AllMenusArrayHolder[0] = MainMenu;
  59. AllMenusArrayHolder[1] = SecondMenu;
  60. AllMenusArrayHolder[2] = InstallationMenu;
  61. AllMenusArrayHolder[3] = ShipProfiles;
  62. AllMenusArrayHolder[4] = FighterControlSystems;
  63. AllMenusArrayHolder[5] = MTBControlSystems;
  64. AllMenusArrayHolder[6] = EscapePodSystems;
  65. AllMenusArrayHolder[7] = ConfirmSubMenu;
  66. AllMenusArrayHolder[8] = SelectMenu;
  67. AllMenusArrayHolder[9] = Keyboard;
  68. }
  69.  
  70. void Main(string argument)
  71. {
  72.  
  73. if (FirstRun)
  74. {
  75. for (int i = 0; i < AllMenusArrayHolder.Length; i++)
  76. {
  77. for (int j = 0; j < AllMenusArrayHolder[i].Length; j++)
  78. {
  79. WriteToScreen("LCD Panel", AllMenusArrayHolder[i][j] + NLCR, true);
  80. }
  81. }
  82.  
  83. TextBuilder(1, AllMenusArrayHolder[1]);
  84. }
  85.  
  86. if (argument != "")
  87. ArgumentHandler(argument);
  88. }
  89.  
  90. void ArgumentHandler(string args)
  91. {
  92. Echo("TEST 1");
  93. string[] SelectedArray = AllMenusArrayHolder[1];
  94. Echo("----------");
  95.  
  96. switch (args)
  97. {
  98. case ARG1:
  99. {
  100. Echo("arg given: " + ARG1);
  101.  
  102. if (ItemIndex == SelectedArray.Length - 1)
  103. {
  104. ItemIndex = 0;
  105. Echo("arg 1 condition 1 opt 1");
  106. }
  107. else
  108. {
  109. ItemIndex++;
  110. Echo("arg 1 condition 1 opt 2");
  111. }
  112.  
  113. TextBuilder(1, SelectedArray);
  114. break;
  115. }
  116.  
  117. case ARG2:
  118. {
  119. ItemIndex--;
  120. if (ItemIndex < 0) ItemIndex = SelectedArray.Length - 1;
  121. Echo("arg 2 condition 1 opt 2");
  122.  
  123. Echo("arg given: " + ARG2);
  124. Echo("" + ItemIndex);
  125. TextBuilder(2, SelectedArray);
  126. break;
  127. }
  128.  
  129. case ARG3:
  130. {
  131.  
  132. Echo("arg given: " + ARG3);
  133. break;
  134. }
  135.  
  136. case ARG4:
  137. {
  138.  
  139. Echo("arg given: " + ARG4);
  140. break;
  141. }
  142.  
  143. default:
  144. {
  145. Echo("Unknown command");
  146. break;
  147. }
  148. }
  149. }
  150.  
  151. void TextBuilder(int Direction, string[] MenuArray)
  152. {
  153. string TextToDisp = "";
  154. string SelectedMenuItem = "";
  155.  
  156. string[] TextArray = new string[MenuArray.Length];
  157. Echo("INIT VAR");
  158.  
  159. if (Direction == 1)
  160. {
  161. if (ItemIndex != MenuArray.Length)
  162. {
  163. //Echo("Check Index");
  164. SelectedMenuItem = SelOpenBracket + MenuArray[ItemIndex] + SelCloseBracket;
  165.  
  166. for (int i = 0; i < TextArray.Length; i++)
  167. {
  168. TextArray[i] = MenuArray[i]; //copy the array in preparation to display selected item
  169. }
  170. if (SelectedMenuItem != "" || SelectedMenuItem != "<>")
  171. {
  172. TextArray[ItemIndex] = SelectedMenuItem;
  173. }
  174.  
  175. for (int i = 0; i < TextArray.Length; i++)
  176. {
  177. if (i != TextArray.Length - 1)
  178. {
  179. TextToDisp = TextToDisp + TextArray[i] + NLCR;
  180. }
  181. else
  182. {
  183. TextToDisp = TextToDisp + TextArray[TextArray.Length - 1];
  184. }
  185. }
  186.  
  187. //TextToDisp = TextArray[0] + NLCR + TextArray[1] + NLCR + TextArray[2] + NLCR + TextArray[3] + NLCR + TextArray[4];
  188.  
  189. WriteToScreen("LCD Panel", TextToDisp, false);
  190. }
  191. else
  192. {
  193. SelectedMenuItem = SelOpenBracket + MenuArray[0] + SelCloseBracket;
  194.  
  195. TextArray[0] = SelectedMenuItem;
  196.  
  197. TextToDisp = TextArray[0];
  198.  
  199. for (int i = 1; i < MenuArray.Length; i++)
  200. {
  201. if (i != MenuArray.Length - 1)
  202. {
  203. TextToDisp = TextToDisp + MenuArray[i] + NLCR;
  204. }
  205. else
  206. {
  207. TextToDisp = TextToDisp + MenuArray[MenuArray.Length - 1];
  208. }
  209. }
  210.  
  211. //TextToDisp = TextArray[0] + NLCR + MenuArray[1] + NLCR + MenuArray[2] + NLCR + MenuArray[3] + NLCR + MenuArray[4];
  212.  
  213. WriteToScreen("LCD Panel", TextToDisp, false);
  214. }
  215. }
  216. else if (Direction == 2)
  217. {
  218. if (ItemIndex != -1)// && MenuIndex > 0)
  219. {
  220. SelectedMenuItem = SelOpenBracket + MenuArray[ItemIndex] + SelCloseBracket;
  221.  
  222. for (int i = 0; i < TextArray.Length; i++)
  223. {
  224. TextArray[i] = MenuArray[i];
  225. }
  226. if (SelectedMenuItem != "" || SelectedMenuItem != "<>")
  227. {
  228. TextArray[ItemIndex] = SelectedMenuItem;
  229. }
  230.  
  231. for (int i = 0; i < TextArray.Length; i++)
  232. {
  233. if (i != TextArray.Length - 1)
  234. {
  235. TextToDisp = TextToDisp + TextArray[i] + NLCR;
  236. }
  237. else
  238. {
  239. TextToDisp = TextToDisp + TextArray[TextArray.Length - 1];
  240. }
  241. }
  242.  
  243. //TextToDisp = TextArray[0] + NLCR + TextArray[1] + NLCR + TextArray[2] + NLCR + TextArray[3] + NLCR + TextArray[4];
  244.  
  245. WriteToScreen("LCD Panel", TextToDisp, false);
  246. }
  247. else if (ItemIndex == -1)
  248. {
  249. SelectedMenuItem = SelOpenBracket + MenuArray[MenuArray.Length - 1] + SelCloseBracket;
  250.  
  251. TextArray[TextArray.Length - 1] = SelectedMenuItem;
  252.  
  253. for (int i = 0; i < MenuArray.Length - 1; i++)
  254. {
  255. TextToDisp = TextToDisp + MenuArray[i] + NLCR;
  256. }
  257.  
  258. TextToDisp = TextToDisp + TextArray[TextArray.Length - 1];
  259.  
  260. //TextToDisp = MenuArray[0] + MenuArray[1] + MenuArray[2] + MenuArray[3] + TextArray[4];
  261.  
  262. WriteToScreen("LCD Panel", TextToDisp, false);
  263. }
  264. }
  265. }
  266.  
  267. // Write text to LCD screen
  268. void WriteToScreen(string ScreenName, string text, bool AppendToScreen)
  269. {
  270. IMyTextPanel LCD = GridTerminalSystem.GetBlockWithName(ScreenName) as IMyTextPanel;
  271. if (LCD != null)
  272. {
  273. LCD.ShowTextureOnScreen();
  274. LCD.WritePublicText(text, AppendToScreen);
  275. LCD.ShowPublicTextOnScreen();
  276. }
  277. }
  278.  
  279. //Read text from LCD screen
  280. string ReadFromScreen(string ScreenName)
  281. {
  282. string TextFromPanel = "";
  283. IMyTextPanel LCD = GridTerminalSystem.GetBlockWithName(ScreenName) as IMyTextPanel;
  284. TextFromPanel = LCD.GetPublicText();
  285. return TextFromPanel;
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement