Guest User

Untitled

a guest
Feb 26th, 2020
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 96.38 KB | None | 0 0
  1. // ---------------------------------------------------------------------------//
  2. // --- Information Section ---------------------------------------------------//
  3. // ---------------------------------------------------------------------------//
  4. // Originally from http://steamcommunity.com/sharedfiles/filedetails/?id=379969347
  5. // Author(s) : Heisenboy http://steamcommunity.com/profiles/76561198010919614/myworkshopfiles/?appid=244850
  6. // Phil Allen [email protected]
  7. // Last Edited By: [email protected]
  8. // Version : 2019040301
  9. //========================================================================//
  10. // Variables to Edit
  11. //========================================================================//
  12. string strProjectorNameContains = "[BP]"; // name of the projector
  13. const string strDisplayNameContains = "[BPLCD]"; // name of the text panel/lcd
  14. int intRescanTicks = 10; // ticks till cargo/projector components are rescanned.
  15. //The projector doesn't tell how many Interior wall is in
  16. // the blueprint. You'll have to enter it manually
  17. int numberOfInteriorWall = 0;
  18. bool boolDebug = false; // debug data sent to echo. sends lots of data....
  19. //========================================================================//
  20. // Dictionaries of component info.
  21. // Add new blocks, change component totals and volumes etc here.
  22. // Would appreciate if you submitted changes to the discussions thread
  23. // in the steam workshop so I can update it too!
  24. //========================================================================//
  25. // Component Volumes
  26. Dictionary<string, int> dVolumes = new Dictionary<string, int>()
  27. {
  28. {"BulletproofGlass", 8},
  29. {"Computer", 1},
  30. {"Construction", 2},
  31. {"Detector", 6},
  32. {"Display", 6},
  33. {"Explosives", 2},
  34. {"GravityGenerator", 200},
  35. {"Girder", 2},
  36. {"InteriorPlate", 5},
  37. {"LargeTube", 38},
  38. {"Medical", 160},
  39. {"MetalGrid", 15},
  40. {"Motor", 8},
  41. {"PowerCell", 45},
  42. {"RadioCommunication", 140},
  43. {"Reactor", 8},
  44. {"SmallTube", 2},
  45. {"SolarCell", 50},
  46. {"SteelPlate", 3},
  47. {"Superconductor",8},
  48. {"Thrust", 10}
  49. };
  50. //========================================================================//
  51. //Small ship blocks from projector
  52. //========================================================================//
  53. Dictionary<string, Dictionary<string, int>> dSmallShipComponentPieces = new Dictionary<string, Dictionary<string, int>>()
  54. {
  55. {"Advanced Rotor", new Dictionary<string, int>{
  56. {"SteelPlate",35},
  57. {"Construction",5},
  58. {"SmallTube",1},
  59. {"Motor",1},
  60. {"Computer",1},
  61. {"LargeTube",10}
  62. }}, //Includes Adv. rotor part
  63. {"Air Vent", new Dictionary<string, int>{{"SteelPlate",8},{"Construction",10},{"Motor",2},{"Computer",5}}},
  64. {"Antenna", new Dictionary<string, int>{
  65. {"RadioCommunication",4},
  66. {"Computer",1},
  67. {"Construction",2},
  68. {"SmallTube",1},
  69. {"SteelPlate",1}
  70. }},
  71. {"Armor blocks", new Dictionary<string, int>{{"SteelPlate",1}}},
  72. {"Artificial Mass", new Dictionary<string, int>{
  73. {"GravityGenerator",1},
  74. {"Computer",2},
  75. {"Construction",2},
  76. {"Superconductor",2},
  77. {"SteelPlate",3}
  78. }},
  79. {"Atmospheric Thrusters", new Dictionary<string, int>{
  80. {"SteelPlate",3},
  81. {"Construction",22},
  82. {"LargeTube",1},
  83. {"MetalGrid",1},
  84. {"Motor", 18}
  85. }},
  86. {"Battery", new Dictionary<string, int>{
  87. {"SteelPlate",25},
  88. {"Construction",5},
  89. {"PowerCell",20},
  90. {"Computer", 2}
  91. }},
  92. {"Beacon", new Dictionary<string, int> {
  93. {"RadioCommunication",4},
  94. {"Computer",1},
  95. {"SmallTube",1},
  96. {"Construction",1},
  97. {"SteelPlate",2}
  98. }},
  99. {"Blast doors", new Dictionary<string, int>{{"SteelPlate",5}}},
  100. {"Blast door corner", new Dictionary<string, int>{{"SteelPlate",5}}},
  101. {"Blast door corner inverted", new Dictionary<string, int>{{"SteelPlate",5}}},
  102. {"Blast door edge", new Dictionary<string, int>{{"SteelPlate",5}}},
  103. {"Button Panel", new Dictionary<string, int> {
  104. {"Computer", 1},
  105. {"Construction",2},
  106. {"InteriorPlate",2}
  107. }},
  108. {"Camera", new Dictionary<string, int>{{"Computer",3},{"SteelPlate",2}}},
  109. {"Cockpit", new Dictionary<string, int>{
  110. {"SteelPlate",10},
  111. {"Construction",10},
  112. {"Motor",1},
  113. {"Display",5},
  114. {"Computer",15},
  115. {"BulletproofGlass", 30}
  116. }},
  117. {"Collector", new Dictionary<string, int>{{"SteelPlate",35},{"Construction",35},{"SmallTube",12},{"Motor",8},{"Display",2},{"Computer",8}}},
  118. {"Connector", new Dictionary<string, int>{{"SteelPlate",21},{"Construction",12},{"SmallTube",6},{"Motor",6},{"Computer",6}}},
  119. {"Control Panel", new Dictionary<string, int>{
  120. {"Display",1},
  121. {"Computer",1},
  122. {"Construction",1},
  123. {"SteelPlate",1}
  124. }},
  125. {"Conveyor", new Dictionary<string, int> {{"InteriorPlate", 25}, {"Construction", 70}, {"SmallTube", 25}, {"Motor", 2}}},
  126. {"Conveyor Junction", new Dictionary<string, int> {{"InteriorPlate", 25}, {"Construction", 70}, {"SmallTube", 25}, {"Motor", 2}}},
  127. {"Conveyor Frame", new Dictionary<string, int> {{"SteelPlate", 4}, {"Construction", 12}, {"SmallTube", 5}, {"Motor", 2}}},
  128. {"Conveyor Sorter", new Dictionary<string, int> {{"Motor", 2}, {"Computer", 5}, {"SmallTube", 5}, {"Construction", 12}, {"InteriorPlate", 5}}},
  129. {"Conveyor Tube", new Dictionary<string, int> {{"SteelPlate", 8}, {"Construction", 30}, {"SmallTube", 10}, {"Motor", 6}}},
  130. {"Corner LCD Bottom", new Dictionary<string, int> {{"Display", 1}, {"Computer", 2}, {"Construction", 3}}},
  131. {"Corner LCD Top", new Dictionary<string, int> {{"Display", 1}, {"Computer", 2}, {"Construction", 3}}},
  132. {"Curved Conveyor Tube", new Dictionary<string, int> {{"SteelPlate", 7}, {"Construction", 30}, {"SmallTube", 10}, {"Motor", 6}}},
  133. {"Decoy", new Dictionary<string, int> {{"Construction", 1}, {"Computer", 1}, {"RadioCommunication", 1}, {"SmallTube", 2}, {"Girder", 1}}},
  134. {"Drill", new Dictionary<string, int> {{"SteelPlate", 32}, {"Construction", 8}, {"SmallTube", 8}, {"LargeTube", 4}, {"Motor", 1}, {"Computer", 1}}},
  135. {"Ejector", new Dictionary<string, int> {{"SteelPlate", 7}, {"Construction", 4}, {"SmallTube", 2}, {"Motor", 1}, {"Computer", 4}}},
  136. {"Fighter Cockpit", new Dictionary<string, int> {{"Construction", 20}, {"Motor", 1}, {"SteelPlate", 18}, {"InteriorPlate", 15}, {"Display", 4}, {"Computer", 20}, {"BulletproofGlass", 40}}},
  137. {"Gatling Gun", new Dictionary<string, int> {{"Construction", 1}, {"SmallTube", 3}, {"Motor", 1}, {"Computer", 1}, {"SteelPlate", 4}}},
  138. {"Gatling Turret", new Dictionary<string, int> {{"SteelPlate", 10}, {"Construction", 30}, {"MetalGrid", 5}, {"LargeTube", 1}, {"Motor", 4}, {"Computer", 10}}},
  139. {"Grinder", new Dictionary<string, int> {{"SteelPlate", 12}, {"Construction", 17}, {"SmallTube", 4}, {"LargeTube", 1}, {"Motor", 4}, {"Computer", 2}}},
  140. {"Gyroscope", new Dictionary<string, int> {{"SteelPlate", 25}, {"Construction", 5}, {"LargeTube", 1}, {"Motor", 2}, {"Computer", 3}}},
  141. {"Heavy Armor Block", new Dictionary<string, int> {{"SteelPlate", 3}, {"MetalGrid",2}}},
  142. {"Heavy Armor Corner", new Dictionary<string, int> {{"SteelPlate", 1}, {"MetalGrid",1}}},
  143. {"Heavy Armor Inv. Corner", new Dictionary<string, int> {{"SteelPlate", 2}, {"MetalGrid",1}}},
  144. {"Heavy Armor Slope", new Dictionary<string, int> {{"SteelPlate", 2}, {"MetalGrid",1}}},
  145. {"Hydrogen Tank Small", new Dictionary<string, int> {{"SteelPlate", 80}, {"LargeTube",40}, {"SmallTube",60}, {"Computer", 8}, {"Construction", 40}}},
  146. {"Hydrogen Thrusters", new Dictionary<string, int> {{"SteelPlate", 30}, {"Construction",30}, {"MetalGrid",22}, {"LargeTube",10}}},
  147.  
  148. {"Ion Thrusters", new Dictionary<string, int> {{"Construction", 2}, {"LargeTube", 5}, {"Thrust", 12}, {"SteelPlate", 5}}},
  149. {"Landing Gear", new Dictionary<string, int> {{"Construction", 1}, {"LargeTube", 1}, {"Motor", 1}, {"SteelPlate", 1}}},
  150. {"Large Atmospheric Thruster", new Dictionary<string, int> {{"SteelPlate", 20}, {"Construction", 30}, {"LargeTube",4}, {"MetalGrid", 8}, {"Motor", 144}}},
  151. {"Large Cargo Container", new Dictionary<string, int> {{"InteriorPlate", 75}, {"Construction", 25}, {"Computer", 6}, {"Motor", 8}, {"Display", 1}}},
  152. {"Large Hydrogen Thruster", new Dictionary<string, int> {{"SteelPlate", 30}, {"Construction",30}, {"MetalGrid",22}, {"LargeTube",10}}},
  153. {"Large Ion Thruster", new Dictionary<string, int> {{"Construction", 2}, {"LargeTube", 5}, {"Thrust", 12}, {"SteelPlate", 5}}},
  154. {"Large Reactor", new Dictionary<string, int> {{"SteelPlate", 60}, {"Construction", 9}, {"MetalGrid", 9}, {"LargeTube", 3}, {"Reactor", 95}, {"Motor", 5}, {"Computer", 25}}},
  155. {"Laser Antenna", new Dictionary<string, int> {{"BulletproofGlass", 2}, {"Computer", 30}, {"RadioCommunication", 5}, {"Motor", 5}, {"Construction", 10}, {"SmallTube", 10}, {"SteelPlate", 10},{"Superconductor",10}}},
  156. {"LCD Panel", new Dictionary<string, int> {{"Construction", 4}, {"Computer", 4}, {"Display", 3}}},
  157. {"Light Armor Block", new Dictionary<string, int> {{"SteelPlate", 1}}},
  158. {"Light Armor Corner", new Dictionary<string, int> {{"SteelPlate", 1}}},
  159. {"Light Armor Corner 2x1x1 Base", new Dictionary<string, int> {{"SteelPlate", 1}}},
  160. {"Light Armor Corner 2x1x1 Tip", new Dictionary<string, int> {{"SteelPlate", 1}}},
  161. {"Light Armor Slope", new Dictionary<string, int> {{"SteelPlate", 1}}},
  162. {"Light Armor Slope 2x1x1 Base", new Dictionary<string, int> {{"SteelPlate", 1}}},
  163. {"Light Armor Slope 2x1x1 Tip", new Dictionary<string, int> {{"SteelPlate", 1}}},
  164. {"Medium Cargo Container", new Dictionary<string, int> {{"InteriorPlate", 30}, {"Construction", 10}, {"Computer", 4}, {"Motor", 6}, {"Display", 1}}},
  165. {"Merge Block", new Dictionary<string, int> {{"Construction", 5}, {"Motor", 1}, {"SmallTube", 2}, {"Computer", 1}, {"SteelPlate", 4}}},
  166. {"Ore Detector", new Dictionary<string, int> {{"Construction", 2}, {"Motor", 1}, {"Computer", 1}, {"Detector", 1}, {"SteelPlate", 2}}},
  167. //{"Oxygen Generator", new Dictionary<string, int> {{"Computer", 3}, {"Motor", 1}, {"LargeTube", 2}, {"Construction", 8}, {"SteelPlate", 8}}},
  168. {"O2/H2 Generator", new Dictionary<string, int> {{"Computer", 3}, {"Motor", 1}, {"LargeTube", 2}, {"Construction", 8}, {"SteelPlate", 8}}},
  169. {"Oxygen Tank", new Dictionary<string, int> {{"Construction", 10}, {"Computer", 3}, {"SmallTube", 10}, {"LargeTube", 2}, {"SteelPlate", 14}}},
  170. {"Passenger Seat", new Dictionary<string, int> {{"InteriorPlate", 20}, {"Construction", 20}}},
  171. {"Piston", new Dictionary<string, int> {{"LargeTube", 2}, {"SteelPlate", 8}, {"Construction", 4}, {"SmallTube", 4}, {"Motor", 2}, {"Computer", 1}}}, //Includes piston head since it's not available as a single block
  172. {"Programmable block", new Dictionary<string, int> {{"Construction", 2}, {"LargeTube", 2}, {"Motor", 1}, {"Display", 1}, {"Computer", 2}, {"SteelPlate", 2}}},
  173. {"Projector", new Dictionary<string, int> {{"Construction", 2}, {"LargeTube", 2}, {"Motor", 1}, {"Computer", 2}, {"SteelPlate", 2}}},
  174. {"Remote Control", new Dictionary<string, int> {{"Construction", 1}, {"Motor", 1}, {"Computer", 1}, {"InteriorPlate", 2}}},
  175. {"Rocket Launcher", new Dictionary<string, int> {{"Construction", 2}, {"LargeTube", 4}, {"Motor", 1}, {"Computer", 1}, {"SteelPlate", 4}, {"MetalGrid", 1}}},
  176. {"Reloadable Rocket Launcher", new Dictionary<string, int> {{"SteelPlate", 8}, {"SmallTube", 50}, {"InteriorPlate", 50}, {"Construction", 24}, {"LargeTube", 8}, {"Motor", 4}, {"Computer", 2}}},
  177. {"Rotor", new Dictionary<string, int> {{"SteelPlate", 5}, {"Construction", 5}, {"SmallTube", 1}, {"Motor", 1}, {"Computer", 1}}},
  178. {"Rotor Part", new Dictionary<string, int> {{"SteelPlate", 12}, {"SmallTube", 6}}},
  179. {"Sensor", new Dictionary<string, int> {{"InteriorPlate", 5}, {"Construction", 5}, {"Computer", 6}, {"RadioCommunication", 6}, {"Detector", 6}, {"SteelPlate", 2}}},
  180. {"Small Atmospheric Thruster", new Dictionary<string, int> {{"SteelPlate", 3}, {"LargeTube", 1}, {"MetalGrid", 1}, {"Motor", 18}, {"Construction", 2}}},
  181.  
  182. {"Small Battery", new Dictionary<string, int>{
  183. {"Computer",2},
  184. {"PowerCell",2},
  185. {"Construction",2},
  186. {"SteelPlate",4}
  187. }},
  188. {"Small Cargo Container", new Dictionary<string, int> {{"InteriorPlate", 3}, {"Construction", 1}, {"Computer", 2}, {"Motor", 2}, {"Display", 1}}},
  189. {"Small Conveyor", new Dictionary<string, int> {{"InteriorPlate", 4}, {"Construction", 4}, {"Motor", 1}}},
  190. {"Small Conveyor Sorter", new Dictionary<string, int> {{"Motor", 2}, {"Computer", 5}, {"SmallTube", 5}, {"Construction", 12}, {"InteriorPlate", 5}}},
  191. {"Small Conveyor Tube", new Dictionary<string, int> {{"InteriorPlate", 1}, {"Construction", 1}, {"Motor", 1}}},
  192. {"Small Curved Tube", new Dictionary<string, int> {{"InteriorPlate", 1}, {"Motor", 1}, {"Construction", 1}}},
  193. {"Small Curved Conveyor Tube", new Dictionary<string, int> {{"InteriorPlate", 1}, {"Motor", 1}, {"Construction", 1}}},
  194. {"Small Hydrogen Thruster", new Dictionary<string, int> {{"SteelPlate",7},{"Construction",15}, {"MetalGrid",4}, {"LargeTube",2}}},
  195. {"Small Ion Thruster", new Dictionary<string, int> {{"LargeTube", 1}, {"Thrust", 1}, {"Construction", 1}, {"SteelPlate", 1}}},
  196. {"Small Reactor", new Dictionary<string, int> {{"Construction", 1}, {"MetalGrid", 1}, {"LargeTube", 1}, {"Reactor", 1}, {"Motor", 1}, {"Computer", 10}, {"SteelPlate", 2}}},
  197. {"Solar Panel", new Dictionary<string, int> {{"MetalGrid", 2}, {"SmallTube", 1}, {"SteelPlate", 1}, {"Computer", 1}, {"SolarCell", 16}, {"Construction", 2}}},
  198. {"Sound Block", new Dictionary<string, int> {{"InteriorPlate", 4}, {"Construction", 6}, {"Computer", 3}}},
  199. {"Space Ball", new Dictionary<string, int> {{"GravityGenerator", 1}, {"Computer", 7}, {"Construction", 10}, {"SteelPlate", 70}}},
  200. {"Spotlight", new Dictionary<string, int> {{"SteelPlate", 1}, {"Construction", 1}, {"InteriorPlate", 1}}},
  201. {"Survival kit", new Dictionary<string, int>{
  202. {"Computer",5},
  203. {"Display",1},
  204. {"Motor",4},
  205. {"Medical",3},
  206. {"Construction",2},
  207. {"SteelPlate",6}
  208. }},
  209. {"Text panel", new Dictionary<string, int> {{"Construction", 4}, {"Computer", 4}, {"Display", 3}}},
  210. {"Timer Block", new Dictionary<string, int> {{"InteriorPlate", 2}, {"Construction", 3}, {"Computer", 1}}},
  211. {"Warhead", new Dictionary<string, int> {{"Girder", 1}, {"Construction", 1}, {"SmallTube", 2}, {"Computer", 1}, {"Explosives", 2}}},
  212. {"Welder", new Dictionary<string, int> {{"SteelPlate", 12}, {"Construction", 17}, {"SmallTube", 6}, {"LargeTube", 1}, {"Motor", 2}, {"Computer", 2}}},
  213. {"Wheel 1x1", new Dictionary<string, int> {{"MetalGrid", 2}, {"Construction", 5}, {"LargeTube", 1}, {"SteelPlate", 2}}},
  214. {"Wheel 3x3", new Dictionary<string, int> {{"SteelPlate", 4}, {"MetalGrid", 3}, {"Construction", 15}, {"LargeTube", 2}}},
  215. {"Wheel 5x5", new Dictionary<string, int> {{"SteelPlate", 6}, {"MetalGrid", 6}, {"Construction", 30}, {"LargeTube", 3}}},
  216. {"Wheel Suspension 1x1", new Dictionary<string, int> {{"SteelPlate", 8}, {"Construction", 7}, {"SmallTube", 2}, {"Motor", 1}}},
  217. {"Wheel Suspension 3x3", new Dictionary<string, int> {{"SteelPlate", 8}, {"Construction", 7}, {"SmallTube", 2}, {"Motor", 1}}},
  218. {"Wheel Suspension 5x5", new Dictionary<string, int> {{"SteelPlate", 16}, {"Construction", 12}, {"SmallTube", 4}, {"Motor", 2}}},
  219. {"Wide LCD panel", new Dictionary<string, int> {{"Construction", 8}, {"Computer", 8}, {"Display", 6}}},
  220. };
  221. //========================================================================//
  222. //Large ship blocks from projector
  223. //Projector doesn't differentiate between armor block, heavy armor and interior wall...
  224. //========================================================================//
  225. Dictionary<string, Dictionary<string, int>> dLargeShipComponentPieces = new Dictionary<string, Dictionary<string, int>>()
  226. {
  227. {"Basic Assembler", new Dictionary<string, int>{
  228. {"Computer",80},
  229. {"Display",4},
  230. {"Motor",10},
  231. {"Construction",40},
  232. {"SteelPlate",80}
  233. }},
  234. {"Basic Refinery", new Dictionary<string, int>{
  235. {"Computer",10},
  236. {"Motor",10},
  237. {"Construction",20},
  238. {"SteelPlate",120}
  239. }},
  240. {"Ladder", new Dictionary<string, int>{
  241. {"SmallTube",10},
  242. {"Construction",20},
  243. {"InteriorPlate",10}
  244. }},
  245. {"Survival kit", new Dictionary<string, int>{
  246. {"Computer",5},
  247. {"Display",1},
  248. {"Motor",4},
  249. {"Medical",3},
  250. {"Construction",2},
  251. {"SteelPlate",30}
  252. }},
  253. {"Wind Turbine", new Dictionary<string, int>{
  254. {"Computer",2},
  255. {"Girder", 24},
  256. {"Construction",20},
  257. {"Motor",8},
  258. {"InteriorPlate",40}
  259. }},
  260. {"Advanced Rotor", new Dictionary<string, int>{{"Computer",2},{"Motor",4},{"LargeTube",14},{"Construction",10},{"SteelPlate",45}}},//Includes Adv. rotor part
  261. {"Air Vent", new Dictionary<string, int>{{"Computer",5},{"Motor",10},{"Construction",20},{"SteelPlate",45}}},
  262. {"Airtight Hangar Door", new Dictionary<string, int>{{"Computer",2},{"Motor",16},{"SmallTube",40},{"Construction",40},{"SteelPlate",350}}},
  263. {"Antenna", new Dictionary<string, int>{{"RadioCommunication",40},{"Computer",8},{"Construction",30},{"SmallTube",60},{"LargeTube",40},{"SteelPlate",80}}},
  264. //{"Arc furnace", new Dictionary<string, int> {{"SteelPlate", 120}, {"Construction", 5}, {"LargeTube", 2}, {"Motor", 4}, {"Computer", 5}}},
  265. {"Armor blocks", new Dictionary<string, int>{{"SteelPlate",25}}},
  266. {"Artificial Mass", new Dictionary<string, int>{{"GravityGenerator",9},{"Computer",20},{"Construction",30},{"Superconductor",20},{"SteelPlate",90}}},
  267. {"Assembler", new Dictionary<string, int>{{"Computer",160},{"MetalGrid",10},{"Display",10},{"Motor",20},{"Construction",80},{"SteelPlate",140}}},
  268. {"Atmospheric Thrusters", new Dictionary<string, int>{{"Motor",110},{"MetalGrid",10},{"LargeTube",8},{"Construction",50},{"SteelPlate",35}}},
  269. {"Battery", new Dictionary<string, int>{{"Computer",25},{"PowerCell",80},{"Construction",30},{"SteelPlate",80}}},
  270. {"Beacon", new Dictionary<string, int>{{"RadioCommunication",40},{"Computer",10},{"LargeTube",20},{"Construction",30},{"SteelPlate",80}}},
  271. {"Blast doors", new Dictionary<string, int>{{"SteelPlate",140}}},
  272. {"Blast door corner", new Dictionary<string, int>{{"SteelPlate",120}}},
  273. {"Blast door corner inverted", new Dictionary<string, int>{{"SteelPlate",135}}},
  274. {"Blast door edge", new Dictionary<string, int>{{"SteelPlate",130}}},
  275. {"Button Panel", new Dictionary<string, int> {{"Computer",20},{"Construction",20},{"InteriorPlate",10}}},
  276. {"Camera", new Dictionary<string, int>{{"Computer",3},{"SteelPlate",2}}},
  277. {"Cockpit", new Dictionary<string, int>{{"BulletproofGlass",60},{"Computer",100},{"Display",8},{"Motor",1},{"Construction",20},{"InteriorPlate",30}}},
  278. {"Collector", new Dictionary<string, int>{{"Computer",10},{"Display",4},{"Motor",8},{"SmallTube",12},{"Construction",50},{"SteelPlate",45}}},
  279. {"Connector", new Dictionary<string, int>{{"Computer",20},{"Motor",8},{"SmallTube",12},{"Construction",40},{"SteelPlate",150}}},
  280. {"Control Panel", new Dictionary<string, int>{{"Display",1},{"Computer",1},{"Construction",1},{"SteelPlate",1}}},
  281. {"Control Station", new Dictionary<string, int>{{"Display",10},{"Computer",100},{"Motor",2},{"Construction",20},{"InteriorPlate",20}}},
  282. //{"Conveyor", new Dictionary<string, int> {{"InteriorPlate", 50}, {"Construction", 120}, {"SmallTube", 50}, {"Motor", 2}}},
  283. {"Conveyor Junction", new Dictionary<string, int>{{"InteriorPlate",20},{"Construction",30},{"SmallTube",20},{"Motor",6}}},
  284. {"Conveyor Sorter", new Dictionary<string, int>{{"Motor",2},{"Computer",20},{"SmallTube",50},{"Construction",120},{"InteriorPlate",50}}},
  285. {"Conveyor Tube", new Dictionary<string, int>{{"Motor",6},{"SmallTube",12},{"Construction",20},{"InteriorPlate",14}}},
  286. {"Corner LCD Bottom", new Dictionary<string, int>{{"Display",1},{"Computer",3},{"Construction",5}}},
  287. {"Corner LCD Top", new Dictionary<string, int>{{"Display",1},{"Computer",3},{"Construction",5}}},
  288. {"Corner Light", new Dictionary<string, int>{
  289. {"Construction",3}
  290. }},
  291. {"Corner Light - Double", new Dictionary<string, int>{
  292. {"Construction",6}
  293. }},
  294.  
  295. {"Cover Walls", new Dictionary<string, int>{{"Construction",10},{"SteelPlate",4}}},
  296. {"Cryo Chamber", new Dictionary<string, int>{{"BulletproofGlass",10},{"Computer",30},{"Display",8},{"Motor",8},{"Construction",20},{"InteriorPlate",40}}},
  297. {"Curved Conveyor Tube", new Dictionary<string, int> {{"InteriorPlate",10},{"Construction",20},{"SmallTube",12},{"Motor",6}}},
  298. {"Door", new Dictionary<string, int>{{"SteelPlate",8},{"Computer",2},{"Display",1},{"Motor",2},{"SmallTube",4},{"Construction",40},{"InteriorPlate",10}}},
  299. {"Decoy", new Dictionary<string, int>{{"LargeTube",2},{"RadioCommunication",1},{"Computer",10},{"Construction",10},{"SteelPlate",30}}},
  300. {"Diagonal Window", new Dictionary<string, int>{{"InteriorPlate",16},{"Construction",12},{"SmallTube",6}}},
  301. {"Drill", new Dictionary<string, int>{{"SteelPlate",300},{"Construction",40},{"LargeTube",12},{"Motor",5},{"Computer",5}}},
  302. //{"Effectiveness Module", new Dictionary<string, int> {{"Motor", 5}, {"MetalGrid", 10}, {"SmallTube", 15}, {"Construction", 50}, {"SteelPlate", 100}}},
  303. {"Flight Seat", new Dictionary<string, int>{{"InteriorPlate",20},{"Construction",20},{"Motor",2},{"Computer",100},{"Display",4}}},
  304. //{"Full Cover Wall", new Dictionary<string, int> {{"SteelPlate", 4}, {"Construction", 10}}},
  305. {"Gatling Turret", new Dictionary<string, int>{{"SteelPlate",20},{"Construction",30},{"MetalGrid",15},{"SmallTube",6},{"Motor",8},{"Computer",10}}},
  306. {"Gravity Generator", new Dictionary<string, int>{{"SteelPlate",150},{"GravityGenerator",6},{"Construction",60},{"LargeTube",4},{"Motor",6},{"Computer",40}}},
  307. {"Grinder", new Dictionary<string, int>{{"SteelPlate",20},{"Construction",30},{"LargeTube",1},{"Motor",4},{"Computer",2}}},
  308. {"Gyroscope", new Dictionary<string, int>{{"SteelPlate",600},{"Construction",40},{"LargeTube",4},{"MetalGrid",50},{"Motor",4},{"Computer",5}}},
  309. {"Half Cover Wall", new Dictionary<string, int>{{"SteelPlate",2},{"Construction",6}}},
  310. //{"Heavy Armor Block", new Dictionary<string, int> {{"SteelPlate", 150}, {"MetalGrid",50}}},
  311. //{"Heavy Armor Corner", new Dictionary<string, int> {{"SteelPlate", 25}, {"MetalGrid",10}}},
  312. //{"Heavy Armor Inv. Corner", new Dictionary<string, int> {{"SteelPlate", 125}, {"MetalGrid",50}}},
  313. //{"Heavy Armor Slope", new Dictionary<string, int> {{"SteelPlate", 75}, {"MetalGrid",25}}},
  314. {"Hydrogen Tank", new Dictionary<string, int>{{"SteelPlate",280},{"LargeTube",80},{"SmallTube",60},{"Computer",8},{"Construction",40}}},
  315. {"Hydrogen Thrusters", new Dictionary<string,int>{{"SteelPlate",25},{"Construction",60},{"MetalGrid",40},{"LargeTube",8}}},
  316. {"Ion Thrusters", new Dictionary<string, int>{{"SteelPlate",25},{"Construction",60},{"LargeTube",8},{"Thrust",80}}},
  317. {"Interior Light", new Dictionary<string, int> {{"Construction", 2}}},
  318. {"Interior Pillar", new Dictionary<string, int>{{"InteriorPlate",25},{"Construction",10},{"SmallTube", 4}}},
  319. {"Interior Turret", new Dictionary<string, int>{{"InteriorPlate",6},{"Construction",20},{"SmallTube",1},{"Motor",2},{"Computer",5},{"SteelPlate",4}}},
  320. {"Jump Drive", new Dictionary<string, int>{{"SteelPlate",60},{"MetalGrid",50},{"GravityGenerator",20},{"Detector",20},{"PowerCell",120},{"Superconductor",1000},{"Computer",300},{"Construction",40}}},
  321. {"Landing Gear", new Dictionary<string, int>{{"SteelPlate",150},{"Construction",20},{"Motor", 6}}},
  322. {"Large Atmospheric Thruster", new Dictionary<string, int>{{"SteelPlate",230},{"Construction",60},{"LargeTube",50},{"MetalGrid",40},{"Motor",1100}}},
  323. {"Large Cargo Container", new Dictionary<string, int>{{"InteriorPlate",360},{"Construction",80},{"MetalGrid",24},{"SmallTube",60},{"Motor",20},{"Display",1},{"Computer",8}}},
  324. {"Large Hydrogen Thruster", new Dictionary<string,int>{{"SteelPlate",150},{"Construction",180},{"MetalGrid",250},{"LargeTube",40}}},
  325. {"Large Ion Thruster", new Dictionary<string, int>{{"SteelPlate",150},{"Construction",100},{"LargeTube",40},{"Thrust",960}}},
  326. {"Large Reactor", new Dictionary<string, int>{{"SteelPlate",1000},{"Construction",70},{"MetalGrid", 40},{"LargeTube",40},{"Reactor",2000},{"Motor",20},{"Computer",75},{"Superconductor",100}}},
  327. {"Laser Antenna", new Dictionary<string, int>{{"BulletproofGlass",4},{"Computer",50},{"Superconductor",100},{"RadioCommunication",20},{"Detector",30},{"Motor",16},{"Construction",40},{"SteelPlate",50}}},
  328. {"LCD Panel", new Dictionary<string, int>{{"BulletproofGlass",6},{"Display",10},{"Computer",6},{"Construction",6},{"InteriorPlate",1}}},
  329. {"Light Armor Block", new Dictionary<string, int> {{"SteelPlate", 25}}},
  330. {"Light Armor Corner", new Dictionary<string, int> {{"SteelPlate", 4}}},
  331. {"Light Armor Corner 2x1x1 Base", new Dictionary<string, int> {{"SteelPlate", 10}}},
  332. {"Light Armor Corner 2x1x1 Tip", new Dictionary<string, int> {{"SteelPlate", 4}}},
  333. {"Light Armor Slope", new Dictionary<string, int> {{"SteelPlate", 13}}},
  334. {"Light Armor Slope 2x1x1 Base", new Dictionary<string, int> {{"SteelPlate", 19}}},
  335. {"Light Armor Slope 2x1x1 Tip", new Dictionary<string, int> {{"SteelPlate", 4}}},
  336. {"Medical Room", new Dictionary<string, int>{{"InteriorPlate",240},{"Construction",80},{"MetalGrid",60},{"SmallTube",20},{"LargeTube",5},{"Display",10},{"Computer",10},{"Medical",15}}},
  337. {"Merge Block", new Dictionary<string, int>{{"SteelPlate",12},{"Construction",15},{"Motor",2},{"LargeTube",6},{"Computer",2}}},
  338. {"Missile Turret", new Dictionary<string, int>{{"SteelPlate",20},{"Construction",40},{"MetalGrid",5},{"LargeTube",6},{"Motor",16},{"Computer",12}}},
  339. {"Ore Detector", new Dictionary<string, int>{{"SteelPlate",50},{"Construction",40},{"Motor",5},{"Computer",25},{"Detector",20}}},
  340. {"Oxygen Farm", new Dictionary<string, int>{{"Computer",20},{"Construction",20},{"SmallTube",10},{"LargeTube",20},{"BulletproofGlass",100},{"SteelPlate", 40}}},
  341. //{"Oxygen Generator", new Dictionary<string, int> {{"Computer", 5}, {"Motor", 4}, {"LargeTube", 2}, {"Construction", 5}, {"SteelPlate", 120}}},
  342. {"O2/H2 Generator", new Dictionary<string, int>{{"Computer",5},{"Motor",4},{"LargeTube",2},{"Construction",5},{"SteelPlate",120}}},
  343. {"Oxygen Tank", new Dictionary<string, int>{{"Construction",40},{"Computer",8},{"SmallTube",60},{"LargeTube",40},{"SteelPlate",80}}},
  344. {"Passage", new Dictionary<string, int>{{"InteriorPlate",74},{"Construction",20},{"SmallTube",48}}},
  345. {"Passenger Seat", new Dictionary<string, int>{{"InteriorPlate",20},{"Construction",20}}},
  346. {"Piston", new Dictionary<string, int>{{"SteelPlate",25},{"Construction",10},{"LargeTube",14},{"Motor",4},{"Computer",2}}}, //Includes piston head
  347. {"Power Efficiency Module", new Dictionary<string, int>{{"Motor",4},{"PowerCell",20},{"SmallTube",20},{"Construction",40},{"SteelPlate",100}}},
  348. //{"Productivity Module", new Dictionary<string, int> {{"Motor", 2}, {"LargeTube", 10}, {"SmallTube", 20}, {"Construction", 40}, {"SteelPlate", 100}}},
  349. {"Programmable block", new Dictionary<string, int>{{"SteelPlate",21},{"Construction",4},{"LargeTube",2},{"Motor",1},{"Display",1},{"Computer",2}}},
  350. {"Projector", new Dictionary<string, int>{{"SteelPlate",21},{"Construction",4},{"LargeTube",2},{"Motor",1},{"Computer",2}}},
  351. {"Ramp", new Dictionary<string, int>{{"InteriorPlate",70},{"Construction",16}}},
  352. {"Refinery", new Dictionary<string, int>{{"SteelPlate",1200},{"Construction",40},{"LargeTube",20},{"Motor",16},{"MetalGrid",20},{"Computer",20}}},
  353. {"Remote Control", new Dictionary<string, int>{{"InteriorPlate",10},{"Construction",10},{"Motor",1},{"Computer",15}}},
  354. {"Rocket Launcher", new Dictionary<string, int>{{"SteelPlate",35},{"Construction",8},{"MetalGrid",30},{"LargeTube",25},{"Motor",6},{"Computer",4}}},
  355. {"Rotor", new Dictionary<string, int>{{"SteelPlate",15},{"Construction",10},{"LargeTube",4},{"Motor",4},{"Computer",2}}}, // does not include rotor part as it's added via addcomops
  356. {"Rotor Part", new Dictionary<string, int>{{"SteelPlate",30},{"LargeTube",6}}},
  357. {"Sensor", new Dictionary<string, int>{{"InteriorPlate",5},{"Construction",5},{"Computer",6},{"RadioCommunication",4},{"Detector",6},{"SteelPlate",2}}},
  358. {"Sliding Door", new Dictionary<string, int>{
  359. {"BulletproofGlass",15},
  360. {"Computer",2},
  361. {"Display",1},
  362. {"Motor",4},
  363. {"SmallTube",4},
  364. {"Construction",40},
  365. {"SteelPlate",20}
  366. }},
  367. {"Small Cargo Container", new Dictionary<string, int> {
  368. {"InteriorPlate",40},
  369. {"Construction", 40},
  370. {"MetalGrid",4},
  371. {"SmallTube",20},
  372. {"Motor",4},
  373. {"Display",1},
  374. {"Computer", 2}
  375. }},
  376. //{"Small Atmospheric Thruster", new Dictionary<string, int>{{"SteelPlate",35},{"Construction", 50}, {"LargeTube",8}, {"MetalGrid", 10}, {"Motor", 113}}},
  377. //{"Small Hydrogen Thruster", new Dictionary<string, int> {{"SteelPlate", 25}, {"Construction", 60}, {"LargeTube", 8}, {"MetalGrid",40}}},
  378. //{"Small Ion Thruster", new Dictionary<string, int> {{"SteelPlate", 25}, {"Construction", 60}, {"LargeTube", 8}, {"Thrust", 80}}},
  379. {"Small Reactor", new Dictionary<string, int> {
  380. {"SteelPlate",80},
  381. {"Construction",40},
  382. {"MetalGrid",4},
  383. {"LargeTube",8},
  384. {"Reactor",100},
  385. {"Motor",6},
  386. {"Computer",25}
  387. }},
  388. {"Solar Panel", new Dictionary<string, int> {
  389. {"BulletproofGlass", 4},
  390. {"SolarCell",32},
  391. {"Computer",4},
  392. {"Girder",12},
  393. {"Construction",14},
  394. {"SteelPlate",4}
  395. }},
  396. {"Sound Block", new Dictionary<string, int>{
  397. {"Computer",3},
  398. {"Construction",6},
  399. {"InteriorPlate",4},
  400. }},
  401. {"Space Ball", new Dictionary<string, int>{
  402. {"GravityGenerator",3},
  403. {"Computer",20},
  404. {"Construction",30},
  405. {"SteelPlate",225}
  406. }},
  407. {"Speed Module", new Dictionary<string, int>{
  408. {"Motor",4},
  409. {"Computer",60},
  410. {"SmallTube",20},
  411. {"Construction",40},
  412. {"SteelPlate",100}
  413. }},
  414. {"Spherical Gravity Generator", new Dictionary<string, int>{
  415. {"SteelPlate",150},
  416. {"GravityGenerator",6},
  417. {"Construction",60},
  418. {"LargeTube",4},
  419. {"Motor",6},
  420. {"Computer", 40}
  421. }},
  422. {"Spotlight", new Dictionary<string, int> {
  423. {"BulletproofGlass",4},
  424. {"Construction",15},
  425. {"InteriorPlate",20},
  426. {"LargeTube",2},
  427. {"SteelPlate",8}
  428. }},
  429. {"Stairs", new Dictionary<string, int>{
  430. {"Construction",30},
  431. {"InteriorPlate",50}
  432. }},
  433. //{"Steel Catwalk", new Dictionary<string, int>{{"Construction",5},{"MetalGrid",25},{"SmallTube",20},{"InteriorPlate", 2}}},
  434. {"Steel Catwalk Corner", new Dictionary<string, int>{
  435. {"SmallTube",25},
  436. {"Construction",7},
  437. {"InteriorPlate",32}
  438. }},
  439. {"Steel Catwalk Plate", new Dictionary<string, int>{
  440. {"SmallTube",25},
  441. {"Construction",7},
  442. {"InteriorPlate",23}
  443. }},
  444. {"Steel Catwalk Two Sides", new Dictionary<string, int>{
  445. {"SmallTube",25},
  446. {"Construction",7},
  447. {"InteriorPlate",32}
  448. }},
  449. {"Steel Catwalks", new Dictionary<string, int>{
  450. {"SmallTube",20},
  451. {"Construction",5},
  452. {"InteriorPlate",27}
  453. }},
  454. {"Timer Block", new Dictionary<string, int>{{"InteriorPlate",6},{"Construction",30},{"Computer",5}}},
  455. {"Text panel", new Dictionary<string, int>{
  456. {"BulletproofGlass",2},
  457. {"Display", 10},
  458. {"Computer",6},
  459. {"Construction",6},
  460. {"InteriorPlate",1}
  461. }},
  462. {"Warhead", new Dictionary<string, int>{
  463. {"SteelPlate",20},
  464. {"Girder",24},
  465. {"Construction",12},
  466. {"SmallTube",12},
  467. {"Computer",2},
  468. {"Explosives", 6}
  469. }},
  470. {"Welder", new Dictionary<string, int>{
  471. {"SteelPlate",20},
  472. {"Construction",30},
  473. {"LargeTube",1},
  474. {"Motor",2},
  475. {"Computer",2}
  476. }},
  477. {"Wheel 1x1", new Dictionary<string, int>{
  478. {"SteelPlate",8},
  479. {"Construction",20},
  480. {"LargeTube",4}
  481. }},
  482. {"Wheel 3x3", new Dictionary<string, int>{
  483. {"SteelPlate",12},
  484. {"Construction",25},
  485. {"LargeTube", 6}
  486. }},
  487. {"Wheel 5x5", new Dictionary<string, int> {
  488. {"SteelPlate",16},
  489. {"Construction",30},
  490. {"LargeTube",8}
  491. }},
  492. //{"Wheel Suspension 3x3", new Dictionary<string, int> {{"SteelPlate", 25}, {"Construction", 15}, {"LargeTube", 6}, {"SmallTube", 12}, {"Motor", 6}}},
  493. {"Wheel Suspension 1x1 Left", new Dictionary<string, int>{
  494. {"Motor", 6},
  495. {"SmallTube",12},
  496. {"LargeTube",6},
  497. {"Construction",15},
  498. {"SteelPlate",25}
  499. }},
  500. {"Wheel Suspension 1x1 Right", new Dictionary<string, int>{
  501. {"Motor", 6},
  502. {"SmallTube",12},
  503. {"LargeTube",6},
  504. {"Construction",15},
  505. {"SteelPlate",25}
  506. }},
  507. {"Wheel Suspension 3x3 Left", new Dictionary<string, int>{
  508. {"Motor", 6},
  509. {"SmallTube",12},
  510. {"LargeTube",6},
  511. {"Construction",15},
  512. {"SteelPlate",25}
  513. }},
  514. {"Wheel Suspension 3x3 Right", new Dictionary<string, int>{
  515. {"Motor", 6},
  516. {"SmallTube",12},
  517. {"LargeTube",6},
  518. {"Construction",15},
  519. {"SteelPlate",25}
  520. }},
  521. {"Wheel Suspension 5x5 Left", new Dictionary<string, int>{
  522. {"Motor",20},
  523. {"SmallTube",30},
  524. {"LargeTube",20},
  525. {"Construction",40},
  526. {"SteelPlate",70}
  527. }},
  528. {"Wheel Suspension 5x5 Right", new Dictionary<string, int>{
  529. {"Motor",20},
  530. {"SmallTube",30},
  531. {"LargeTube",20},
  532. {"Construction",40},
  533. {"SteelPlate",70}
  534. }},
  535. //{"Wheel Suspension 5x5", new Dictionary<string, int> {{"SteelPlate",70},{"Construction",40},{"LargeTube",20},{"SmallTube",30},{"Motor",20}}},
  536. {"Wide LCD panel", new Dictionary<string, int>{
  537. {"BulletproofGlass",12},
  538. {"Display", 20},
  539. {"Computer",12},
  540. {"Construction",12},
  541. {"InteriorPlate",2}
  542. }},
  543. {"Window 1x2 Slope", new Dictionary<string, int> {{"Girder", 16}, {"BulletproofGlass", 55}}},
  544. {"Window 1x2 Inv.", new Dictionary<string, int> {{"Girder", 15}, {"BulletproofGlass", 40}}},
  545. {"Window 1x2 Face", new Dictionary<string, int> {{"Girder", 15}, {"BulletproofGlass", 40}}},
  546. {"Window 1x2 Side Left", new Dictionary<string, int> {{"Girder", 13}, {"BulletproofGlass", 26}}},
  547. {"Window 1x2 Side Right", new Dictionary<string, int> {{"Girder", 13}, {"BulletproofGlass", 26}}},
  548. {"Window 1x1 Slope", new Dictionary<string, int> {{"Girder", 12}, {"BulletproofGlass", 35}}},
  549. {"Window 1x1 Face", new Dictionary<string, int> {{"Girder", 11}, {"BulletproofGlass", 24}}},
  550. {"Window 1x1 Side", new Dictionary<string, int> {{"Girder", 9}, {"BulletproofGlass", 17}}},
  551. {"Window 1x1 Inv.", new Dictionary<string, int> {{"Girder", 11}, {"BulletproofGlass", 24}}},
  552. {"Window 1x1 Flat", new Dictionary<string, int> {{"Girder", 10}, {"BulletproofGlass", 25}}},
  553. {"Window 1x1 Flat Inv.", new Dictionary<string, int> {{"Girder", 10}, {"BulletproofGlass", 25}}},
  554. {"Window 1x2 Flat", new Dictionary<string, int> {{"Girder", 15}, {"BulletproofGlass", 50}}},
  555. {"Window 1x2 Flat Inv.", new Dictionary<string, int> {{"Girder", 15}, {"BulletproofGlass", 50}}},
  556. {"Window 2x3 Flat", new Dictionary<string, int> {{"Girder", 25}, {"BulletproofGlass", 140}}},
  557. {"Window 2x3 Flat Inv.", new Dictionary<string, int> {{"Girder", 25}, {"BulletproofGlass", 140}}},
  558. {"Window 3x3 Flat", new Dictionary<string, int> {{"Girder", 40}, {"BulletproofGlass", 196}}},
  559. {"Window 3x3 Flat Inv.", new Dictionary<string, int> {{"Girder", 40}, {"BulletproofGlass", 196}}},
  560. {"Vertical Window", new Dictionary<string, int> {{"InteriorPlate", 12}, {"Construction", 8}, {"SmallTube", 4}}},
  561. {"Yield Module", new Dictionary<string, int>{
  562. {"Motor",4},
  563. {"Superconductor",20},
  564. {"SmallTube",15},
  565. {"Construction",50},
  566. {"SteelPlate", 100}
  567. }},
  568.  
  569. };
  570. //========================================================================//
  571. // Variables used by code
  572. //========================================================================//
  573. bool boolInitComplete = false;
  574. List<string> blocks = new List<string>();
  575. List<IMyTerminalBlock> AllStorageBlocks=new List<IMyTerminalBlock>();
  576. List<IMyTerminalBlock> ProjectorBlocks=new List<IMyTerminalBlock>();
  577.  
  578. Dictionary<string, int> dReqComponents = new Dictionary<string, int>();
  579. Dictionary<string, int> dComponentsCount = new Dictionary<string, int>();
  580. ClapYoFace CYF = new ClapYoFace(true);
  581.  
  582. IMyProjector projo = null;
  583. bool boolProjectorLoading = false;
  584. bool boolProjectionComplete = false;
  585. //int intProjectorLoadingCounter = 0;
  586. int intDelayCounter = 0;
  587. string strEchoData = "";
  588. string strDisplayData = "";
  589. string strDisplayDataMangled = "";
  590.  
  591. bool boolAutoScroll = true;
  592.  
  593. int intTotalVolume=0;
  594.  
  595. string strTimData = "";
  596.  
  597. List<string> strKey = new List<string>(); // type of component
  598. List<int> intValue = new List<int>(); // amount of type of component
  599.  
  600. string strSubTypeForCompoCount="";
  601.  
  602. //============================================================================//
  603. // Main
  604. //============================================================================//
  605. void Main(string argument)
  606. {
  607. //========================================================================//
  608. // Init
  609. //========================================================================//
  610. if(!boolInitComplete)
  611. {
  612. CYF.SetExactName(false);
  613. if(!CYF.SetDisplay(strDisplayNameContains, GridTerminalSystem)){Echo(CYF.strError); return;} // Find display, error checking.
  614. Init();
  615. return;
  616. }
  617. //========================================================================//
  618. // Argument Handling (Scroll arguments lower)
  619. //========================================================================//
  620. if(argument.ToLower().Trim().StartsWith("rescanticks"))
  621. {
  622. argument = argument.Remove(0,11).Trim();
  623. if(!Int32.TryParse(argument,out intRescanTicks))
  624. {
  625. Echo("Error Parsing argument not an int:"+argument);
  626. return;
  627. }
  628. }
  629. else if(argument.ToLower().Trim()=="getrescanticks")
  630. {
  631. Echo("RescanTicks: "+intRescanTicks.ToString());
  632. }
  633. else if(argument.ToLower().Trim()=="pscanonloaded")
  634. {
  635. ProjectorSearch(true,true);
  636. }
  637. else if(argument.ToLower().Trim()=="pscanon")
  638. {
  639. ProjectorSearch(true);
  640. }
  641. else if(argument.ToLower().Trim()=="pscan")
  642. {
  643. ProjectorSearch();
  644. }
  645. else if(argument.ToLower().Trim()=="reinit")
  646. {
  647. Init();
  648. }
  649. else if(argument.ToLower().Trim()=="debugon")
  650. boolDebug=true;
  651. else if(argument.ToLower().Trim()=="debugoff")
  652. boolDebug=false;
  653. else if(argument.ToLower().Trim()=="help")
  654. {
  655. help();
  656. return;
  657. }
  658. else if(argument.ToLower().Trim()=="settings")
  659. {
  660. EchoSettings();
  661. return;
  662. }
  663. //========================================================================//
  664. // Display Config, checks/sets display configuration based on the display found.
  665. // if font/font size are change this updates the settings.
  666. //========================================================================//
  667. CYF.SetDisplayConfig(); // configure display, font sizes, etc.
  668. //========================================================================//
  669. // Debug Messages for me.
  670. //========================================================================//
  671. if (boolDebug)
  672. {
  673. Echo("boolProjectionComplete:"+boolProjectionComplete.ToString());
  674. Echo("boolProjectorLoading:"+boolProjectorLoading.ToString());
  675. Echo("IsProjecting:"+projo.IsProjecting.ToString());
  676. Echo("DelayCounter :"+intDelayCounter.ToString());
  677. }
  678. //========================================================================//
  679. // Delay Counter, so we don't hose your game by scanning cargo containers
  680. // every tick/program run iteration.
  681. //========================================================================//
  682. if (intDelayCounter<intRescanTicks)
  683. intDelayCounter++;
  684. else
  685. {
  686. GetComponentCount(AllStorageBlocks);//this before GetProjectorData
  687. GetProjectorData();
  688. intDelayCounter=0;
  689. }
  690. //========================================================================//
  691. // Variable Resets
  692. //========================================================================//
  693. intTotalVolume=0;
  694. strEchoData = "";
  695. strDisplayData = "";
  696. //========================================================================//
  697. // Display Projection Complete
  698. //========================================================================//
  699. if(boolProjectionComplete)
  700. {
  701. strDisplayData+=CYF.AlignCenter("Blueprint Requirements");
  702. strDisplayData+="\n\n\n\n\n\n";
  703. strDisplayData+=CYF.AlignCenter("Projection is Built!");
  704. CYF.WriteDisplay(strDisplayData);
  705. Echo("Projection is Built!");
  706. return;
  707. }
  708. //========================================================================//
  709. // Display Projector Loading Screen
  710. //========================================================================//
  711. if(boolProjectorLoading)
  712. {
  713. strDisplayData+=CYF.AlignCenter("Blueprint Requirements");
  714. strDisplayData+="\n\n\n\n\n\n";
  715. strDisplayData+=CYF.AlignCenter("Waiting for Projection to load...");
  716. CYF.WriteDisplay(strDisplayData);
  717. Echo("Waiting for Projection to load...");
  718. Echo("Projector is either off or no BP is loaded");
  719. return;
  720. }
  721. //========================================================================//
  722. // Iterate through Components list
  723. //========================================================================//
  724. // these need to be added to init, run clears here?
  725. // string builder too.. err.
  726. //List<string> strKey = new List<string>(dReqComponents.Keys); // type of component
  727. //List<int> intValue = new List<int>(dReqComponents.Values); // amount of type of component
  728. strKey = new List<string>(dReqComponents.Keys); // type of component
  729. intValue = new List<int>(dReqComponents.Values); // amount of type of component
  730. //Store the list of components in a string
  731. //strDisplayData += CYF.AlignCenter("Blueprint Requirements")+"\n\n";
  732. strEchoData += "This blueprint requires (have/need):\n";
  733. strTimData = "[TIM";
  734. for(int i=0; i<strKey.Count; i++)
  735. {
  736. strEchoData += strKey[i]+": "+dComponentsCount[strKey[i]]+"/"+intValue[i]+"\n";
  737. strDisplayData += CYF.AlignLeftRight(strKey[i],dComponentsCount[strKey[i]]+"/"+intValue[i])+"\n";
  738. strDisplayData += CYF.ProgressBarTrailingNumbers((float)dComponentsCount[strKey[i]],(float)intValue[i])+"\n";
  739. intTotalVolume += intValue[i] * dVolumes[strKey[i]];
  740. strTimData += " " + strKey[i] + ":" + intValue[i]; // lead in with space
  741. }
  742. strTimData += "]";
  743. Me.CustomData = strTimData;
  744. strEchoData += "\nTotal volume of required components: "+intTotalVolume.ToString()+" L.\n";
  745. strDisplayData += "\nTotal volume of required components: "+intTotalVolume.ToString()+" L.\n";
  746. //========================================================================//
  747. // Scroll Argument Handling (must be here auto for autoresizing, something about component list iteration, brain derp.)
  748. //========================================================================//
  749. if(argument.ToLower()=="scrollup")
  750. {
  751. Echo(strEchoData);
  752. strDisplayDataMangled = CYF.WordWrap(strDisplayData);
  753. strDisplayDataMangled = CYF.ScrollLoop(strDisplayDataMangled,-1,CYF.AlignCenter("Blueprint Requirements")+"\n",CYF.AlignLeftRight("","Build Progress:"+(projo.TotalBlocks-projo.RemainingBlocks).ToString()+"/"+projo.TotalBlocks));
  754. CYF.WriteDisplay(strDisplayDataMangled);
  755. return;
  756. }
  757. if(argument.ToLower()=="scrolldown")
  758. {
  759. Echo(strEchoData);
  760. strDisplayDataMangled = CYF.WordWrap(strDisplayData);
  761. strDisplayDataMangled = CYF.ScrollLoop(strDisplayDataMangled,1,CYF.AlignCenter("Blueprint Requirements")+"\n",CYF.AlignLeftRight("","Build Progress:"+(projo.TotalBlocks-projo.RemainingBlocks).ToString()+"/"+projo.TotalBlocks));
  762. CYF.WriteDisplay(strDisplayDataMangled);
  763. return;
  764. }
  765. else if(argument.ToLower()=="autoscroll=on")
  766. {
  767. boolAutoScroll = true;
  768. return;
  769. }
  770. else if(argument.ToLower()=="autoscroll=off")
  771. {
  772. boolAutoScroll = false;
  773. return;
  774. }
  775. else if(argument.ToLower()=="toggleautoscroll")
  776. {
  777. if (boolAutoScroll)
  778. boolAutoScroll = false;
  779. else
  780. boolAutoScroll = true;
  781. return;
  782. }
  783. //========================================================================//
  784. // END Argument Handling
  785. //========================================================================//
  786. // Output section
  787. Echo(strEchoData);
  788. //strDisplayData = CYF.FormatString(strDisplayData);
  789. strDisplayDataMangled = CYF.WordWrap(strDisplayData);
  790. if(boolAutoScroll)
  791. strDisplayDataMangled = CYF.ScrollLoop(strDisplayDataMangled,1,CYF.AlignCenter("Blueprint Requirements")+"\n",CYF.AlignLeftRight("","Build Progress:"+(projo.TotalBlocks-projo.RemainingBlocks).ToString()+"/"+projo.TotalBlocks));
  792. else
  793. strDisplayDataMangled = CYF.ScrollLoop(strDisplayDataMangled,0,CYF.AlignCenter("Blueprint Requirements")+"\n",CYF.AlignLeftRight("","Build Progress:"+(projo.TotalBlocks-projo.RemainingBlocks).ToString()+"/"+projo.TotalBlocks));
  794. //strDisplayDataMangled = CYF.AlignCenter("Blueprint Requirements")+"\n" + strDisplayDataMangled);
  795.  
  796. //strDisplayData = CYF.ScrollLoop(strDisplayData);
  797. CYF.WriteDisplay(strDisplayDataMangled);
  798. }
  799. //============================================================================//
  800. // Init
  801. //============================================================================//
  802. void Init()
  803. {
  804. Echo ("Initializing System\n");
  805. //Get the Projector
  806. //var ProjectorBlocks = new List<IMyTerminalBlock>();
  807. GridTerminalSystem.GetBlocksOfType<IMyProjector>(ProjectorBlocks);
  808. // sort through all projector blocks found and locate the one with [BP] in the name
  809. if (ProjectorBlocks.Count < 1) // no projector blocks found
  810. {
  811. Echo("No projectors found on this grid.");
  812. boolProjectorLoading=true;
  813. return;
  814. }
  815. else //projectors found lets see if any of them contain our string [BPCR]
  816. {
  817. for(int i=0; i < ProjectorBlocks.Count; i++)
  818. {
  819. if(ProjectorBlocks[i].CustomName.Contains(strProjectorNameContains))
  820. {
  821. projo = (IMyProjector)ProjectorBlocks[i];
  822. Echo("Using " + ProjectorBlocks[i].CustomName);
  823. break;
  824. }
  825. }
  826. if(projo == null)
  827. {
  828. Echo("No projector with "+strProjectorNameContains+" in it's name");
  829. boolProjectorLoading=true;
  830. return;
  831. }
  832. }
  833. GetProjectorData();
  834. // get all cargo blocks and mash into allstorageblockslist.
  835. List<IMyTerminalBlock> CargoBlocks=new List<IMyTerminalBlock>();
  836. GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(CargoBlocks);
  837. if(CargoBlocks.Count > 0)
  838. {
  839. for (int i=0; i < CargoBlocks.Count; i++)
  840. {
  841. AllStorageBlocks.Add(CargoBlocks[i]);
  842. }
  843. }
  844. CargoBlocks.Clear();
  845.  
  846. List<IMyTerminalBlock> ConnectorBlocks=new List<IMyTerminalBlock>();
  847. GridTerminalSystem.GetBlocksOfType<IMyShipConnector>(ConnectorBlocks);
  848. if(ConnectorBlocks.Count > 0)
  849. {
  850. for (int i=0; i < ConnectorBlocks.Count; i++)
  851. {
  852. AllStorageBlocks.Add(ConnectorBlocks[i]);
  853. }
  854. }
  855. ConnectorBlocks.Clear();
  856.  
  857. List<IMyTerminalBlock> AssemblerBlocks=new List<IMyTerminalBlock>();
  858. GridTerminalSystem.GetBlocksOfType<IMyAssembler>(AssemblerBlocks);
  859. if(AssemblerBlocks.Count > 0)
  860. {
  861. for (int i=0; i < AssemblerBlocks.Count; i++)
  862. {
  863. AllStorageBlocks.Add(AssemblerBlocks[i]);
  864. }
  865. }
  866. AssemblerBlocks.Clear();
  867.  
  868. List<IMyTerminalBlock> WelderBlocks=new List<IMyTerminalBlock>();
  869. GridTerminalSystem.GetBlocksOfType<IMyShipWelder>(WelderBlocks);
  870. if(WelderBlocks.Count > 0)
  871. {
  872. for (int i=0; i < WelderBlocks.Count; i++)
  873. {
  874. AllStorageBlocks.Add(WelderBlocks[i]);
  875. }
  876. }
  877. WelderBlocks.Clear();
  878.  
  879. GetComponentCount(AllStorageBlocks);
  880. // flag that we've run init.
  881. boolInitComplete=true;
  882. }
  883. //============================================================================//
  884. // help
  885. //============================================================================//
  886. void help()
  887. {
  888. string strHelp="==== Command arguments ====\n"+
  889. "ScrollUp - text up 1\n"+
  890. "ScrollDown - text down 1\n"+
  891. "Autoscroll=on - enable autoscroll\n"+
  892. "Autoscroll=off - disable autoscroll\n"+
  893. "ToggleAutoscroll - toggles autoscroll\n"+
  894. "\n"+
  895. "==== Setting arguments ====\n"+
  896. "Settings - list settings\n"+
  897. "pscan - rescans projector\n"+
  898. "pscanon - rescans projector must be on\n"+
  899. "pscanonloaded - rescans projector must be on and loaded\n"+
  900. "reinit - rescan projector and containers\n"+
  901. "DebugOn - Default off\n"+
  902. "DebugOff";
  903. Echo(strHelp);
  904. }
  905. //============================================================================//
  906. // EchoSettings
  907. //============================================================================//
  908. void EchoSettings()
  909. {
  910. Echo("==== Current Settings ====");
  911. Echo("Using " +projo.CustomName);
  912. if (boolAutoScroll)
  913. Echo("Autoscroll: Off");
  914. else
  915. Echo("Autoscroll: On");
  916. if(boolDebug)
  917. Echo("Debug: On");
  918. else
  919. Echo("Debug: Off");
  920. }
  921. //========================================================================//
  922. // ProjectorSearch
  923. // Search for a projector outside of init.
  924. //========================================================================//
  925. void ProjectorSearch(bool boolProjectorOn=false, bool boolProjectorLoaded=false)
  926. {
  927. GridTerminalSystem.GetBlocksOfType<IMyProjector>(ProjectorBlocks);
  928. // sort through all projector blocks found and locate the one with [BP] in the name
  929. if (ProjectorBlocks.Count < 1) // no projector blocks found
  930. {
  931. Echo("No projectors found on this grid.");
  932. boolProjectorLoading=true;
  933. return;
  934. }
  935. else //projectors found lets see if any of them contain our string [BPCR]
  936. {
  937. for(int i=0; i < ProjectorBlocks.Count; i++)
  938. {
  939. if(ProjectorBlocks[i].CustomName.Contains(strProjectorNameContains))
  940. {
  941. if (boolProjectorOn)
  942. {
  943. //if(ProjectorBlocks[i].GetValue<Boolean>("OnOff"))
  944. if(ProjectorBlocks[i].IsWorking)
  945. {
  946. if(boolProjectorLoaded)
  947. {
  948. if(((IMyProjector)ProjectorBlocks[i]).IsProjecting)
  949. {
  950. projo = (IMyProjector)ProjectorBlocks[i];
  951. Echo("Using " + ProjectorBlocks[i].CustomName);
  952. break;
  953. }
  954. }
  955. else
  956. {
  957. projo = (IMyProjector)ProjectorBlocks[i];
  958. Echo("Using " + ProjectorBlocks[i].CustomName);
  959. break;
  960. }
  961. }
  962. }
  963. else
  964. {
  965. projo = (IMyProjector)ProjectorBlocks[i];
  966. Echo("Using " + ProjectorBlocks[i].CustomName);
  967. break;
  968. }
  969. }
  970. }
  971. if(projo == null)
  972. {
  973. Echo("No projector with "+strProjectorNameContains+" in it's name");
  974. boolProjectorLoading=true;
  975. return;
  976. }
  977. }
  978. GetProjectorData();
  979. }
  980. //========================================================================//
  981. // GetProjectorData
  982. //========================================================================//
  983. bool GetProjectorData()
  984. {
  985. if(boolDebug)
  986. Echo ("In Get Projector");
  987. dReqComponents.Clear();
  988. //if(!projo.GetValue<Boolean>("OnOff"))
  989. if(!projo.IsWorking)
  990. {
  991. boolProjectorLoading=true;
  992. boolProjectionComplete=false;
  993. return false;
  994. }
  995. // Get the correct dictionary of part depending on the projector size
  996. Dictionary<string, Dictionary<string, int>> dParts = new Dictionary<string, Dictionary<string, int>>();
  997. if((projo as IMyCubeBlock).BlockDefinition.ToString().Split('/')[1].Contains("Large"))
  998. dParts = dLargeShipComponentPieces; //partsDict
  999. else
  1000. dParts = dSmallShipComponentPieces;
  1001. //Get the blocks list from the projo detailed infos
  1002. string[] strDetailedInfo = (projo as IMyTerminalBlock).DetailedInfo.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
  1003. blocks = new List<string>(strDetailedInfo);
  1004. if(projo.RemainingBlocks==0 && projo.IsProjecting)
  1005. {
  1006. boolProjectionComplete = true;
  1007. return false;
  1008. }
  1009. else
  1010. boolProjectionComplete = false;
  1011. if(blocks.Count < 6)
  1012. {
  1013. //throw new Exception("\n\nThe projector doesn't seem to be projecting anything.");
  1014. //Echo ("The projector doesn't seem to be projecting anything.");
  1015. boolProjectorLoading=true;
  1016. return false;
  1017. }
  1018. blocks.RemoveRange(0,5);
  1019. string blockName = "";
  1020. int amount = 0;
  1021. //The first block of DetailedInfos should be "Armor blocks"
  1022. blockName = blocks[0].Split(':')[0];
  1023. amount = Int32.Parse(blocks[0].Split(':')[1]);
  1024. if(blockName != "Armor blocks")
  1025. {
  1026. //throw new Exception("\n\nProjector info didn't show armor blocks. If you don't have armor blocks on the BP this could be an issue.");
  1027. Echo ("\n\nProjector info didn't show armor blocks. If you don't have armor blocks on the BP this could be an issue.");
  1028. return false;
  1029. }
  1030. // add armor blocks if statement starts @1.
  1031. AddCompos(ref dReqComponents, amount, dParts[blockName]);
  1032. // Iterate through projector detailed info.
  1033. for(int i=1; i<blocks.Count; i++)
  1034. {
  1035. blockName = blocks[i].Split(':')[0];
  1036. amount = Int32.Parse(blocks[i].Split(':')[1]);
  1037. // Add a way to bug out if part is not found. and spit it to console thingie.
  1038. if (!dParts.ContainsKey(blockName))
  1039. Echo(blockName +" is not in the dictionary, this block will not be calculated");
  1040. else
  1041. {
  1042. // if blocks are a two piece set add the second set.
  1043. switch (blockName)
  1044. {
  1045. case "Wheel Suspension 1x1":
  1046. AddCompos(ref dReqComponents, amount, dParts["Wheel 1x1"]);
  1047. AddCompos(ref dReqComponents, amount, dParts[blockName]);
  1048. break;
  1049. case "Wheel Suspension 3x3":
  1050. AddCompos(ref dReqComponents, amount, dParts["Wheel 3x3"]);
  1051. AddCompos(ref dReqComponents, amount, dParts[blockName]);
  1052. break;
  1053. case "Wheel Suspension 5x5":
  1054. AddCompos(ref dReqComponents, amount, dParts["Wheel 5x5"]);
  1055. AddCompos(ref dReqComponents, amount, dParts[blockName]);
  1056. break;
  1057. case "Rotor":
  1058. AddCompos(ref dReqComponents, amount, dParts["Rotor Part"]);
  1059. AddCompos(ref dReqComponents, amount, dParts[blockName]);
  1060. break;
  1061. default:
  1062. AddCompos(ref dReqComponents, amount, dParts[blockName]);
  1063. break;
  1064. }
  1065. }
  1066. }
  1067. //Since the projector doesn't count them, add compos for Interior Wall if there's any
  1068. if(numberOfInteriorWall > 0)
  1069. AddCompos(ref dReqComponents, numberOfInteriorWall, new Dictionary<string, int> {{"InteriorPlate", 25}, {"Construction", 10}});
  1070. boolProjectorLoading = false;
  1071. return true;
  1072. }
  1073. //========================================================================//
  1074. // TestProjector
  1075. // no longer used.
  1076. //========================================================================//
  1077. bool TestProjector()
  1078. {
  1079. if(boolDebug)
  1080. Echo ("In Projector Test");
  1081. //if(!projo.GetValue<Boolean>("OnOff"))
  1082. if(!projo.IsWorking)
  1083. {
  1084. //Echo("Projector is Off");
  1085. return false;
  1086. }
  1087. if(projo.RemainingBlocks==0)
  1088. {
  1089. //Echo("Projection Complete");
  1090. return false;
  1091. }
  1092. string[] strDetailedInfo = (projo as IMyTerminalBlock).DetailedInfo.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
  1093. //List<string> blocks = new List<string>(strDetailedInfo);
  1094. blocks = new List<string>(strDetailedInfo);
  1095. if(blocks.Count < 6)
  1096. {
  1097. //throw new Exception("\n\nThe projector doesn't seem to be projecting anything.");
  1098. //Echo ("The projector doesn't seem to be projecting anything.");
  1099. return false;
  1100. }
  1101. return true;
  1102. }
  1103. //========================================================================//
  1104. // AddCompos
  1105. // Add the amount of compos from a Dictionary to another and update the total volume
  1106. //========================================================================//
  1107. void AddCompos(ref Dictionary<string, int> compos, int amount, Dictionary<string, int> toAdd)
  1108. {
  1109. //For this block, get a list of compos and a list of their respective amount
  1110. List<string> listKey = new List<string>(toAdd.Keys);
  1111. List<int> listValue = new List<int>(toAdd.Values);
  1112. //For each compos needed on a block
  1113. for(int i=0; i<listKey.Count; i++)
  1114. {
  1115. if(compos.ContainsKey(listKey[i]))
  1116. compos[listKey[i]] += amount * listValue[i];
  1117. else
  1118. compos.Add(listKey[i], amount*listValue[i]);
  1119. }
  1120. }
  1121. //========================================================================//
  1122. // GetComponentCount
  1123. //========================================================================//
  1124. void GetComponentCount(List<IMyTerminalBlock> Blocks)
  1125. {
  1126. MakedComponentsCount();// sets base for dComponentsCount and resets dict
  1127. if (Blocks.Count > 0)
  1128. {
  1129. for(int i=0; i < Blocks.Count; i++)
  1130. {
  1131. // need to get (1) for blocks like assemblers
  1132. //VRage.ModAPI.Ingame.IMyInventory Inventory;
  1133. IMyInventory Inventory; // 2019031500 may need to comment this section inventory returns list not array see https://steamcommunity.com/app/244850/discussions/0/1841314700707693244/
  1134. if(Blocks[i].BlockDefinition.ToString().Contains("Assembler"))
  1135. Inventory = Blocks[i].GetInventory(1);
  1136. else
  1137. Inventory = Blocks[i].GetInventory(0);
  1138. //var Items = Inventory.GetItems();
  1139. List<MyInventoryItem> Items = new List<MyInventoryItem>();
  1140. Inventory.GetItems(Items);
  1141.  
  1142. if(Items.Count > 0)
  1143. {
  1144. for (int o=0;o <Items.Count;o++)
  1145. {
  1146. /*
  1147. //1.187.089 did something with SubtypeName, private variabe for m_subtypeName, but SubtypeName is public.
  1148. // I don't understand why it's not accessible
  1149. //so we'll work around it by doing some substring magic to get the SubtypeName
  1150. if (boolDebug)
  1151. Echo("Found "+ Items[o].Amount.ToString() + Items[o].Content.SubtypeName);
  1152. // add to dict totals. make sure key exists so we don't dict fail.
  1153. if(dComponentsCount.ContainsKey(Items[o].Content.SubtypeName))
  1154. dComponentsCount[Items[o].Content.SubtypeName] += (int)Items[o].Amount;
  1155. */
  1156. //Echo(Items[o].ToString().Substring(Items[o].ToString().IndexOf("/")+1, Items[o].ToString().Length - Items[o].ToString().IndexOf("/")-1));
  1157. strSubTypeForCompoCount = Items[o].ToString().Substring(Items[o].ToString().IndexOf("/")+1, Items[o].ToString().Length - Items[o].ToString().IndexOf("/")-1);
  1158. if (boolDebug)
  1159. Echo("Found "+ Items[o].Amount.ToString() + strSubTypeForCompoCount);
  1160. // add to dict totals. make sure key exists so we don't dict fail.
  1161. if(dComponentsCount.ContainsKey(strSubTypeForCompoCount))
  1162. dComponentsCount[strSubTypeForCompoCount] += (int)Items[o].Amount;
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. //========================================================================//
  1169. // MakedComponentsCount
  1170. //========================================================================//
  1171. void MakedComponentsCount()
  1172. {
  1173. dComponentsCount.Clear();
  1174. PopulateDictionary(dComponentsCount, "BulletproofGlass", 0);
  1175. PopulateDictionary(dComponentsCount, "Computer", 0);
  1176. PopulateDictionary(dComponentsCount, "Construction", 0);
  1177. PopulateDictionary(dComponentsCount, "Detector", 0);
  1178. PopulateDictionary(dComponentsCount, "Display", 0);
  1179. PopulateDictionary(dComponentsCount, "Explosives", 0);
  1180. PopulateDictionary(dComponentsCount, "GravityGenerator", 0);
  1181. PopulateDictionary(dComponentsCount, "Girder", 0);
  1182. PopulateDictionary(dComponentsCount, "InteriorPlate", 0);
  1183. PopulateDictionary(dComponentsCount, "LargeTube", 0);
  1184. PopulateDictionary(dComponentsCount, "Medical", 0);
  1185. PopulateDictionary(dComponentsCount, "MetalGrid", 0);
  1186. PopulateDictionary(dComponentsCount, "Motor", 0);
  1187. PopulateDictionary(dComponentsCount, "PowerCell", 0);
  1188. PopulateDictionary(dComponentsCount, "RadioCommunication", 0);
  1189. PopulateDictionary(dComponentsCount, "Reactor", 0);
  1190. PopulateDictionary(dComponentsCount, "SmallTube", 0);
  1191. PopulateDictionary(dComponentsCount, "SolarCell", 0);
  1192. PopulateDictionary(dComponentsCount, "SteelPlate", 0);
  1193. PopulateDictionary(dComponentsCount, "Superconductor", 0);
  1194. PopulateDictionary(dComponentsCount, "Thrust", 0);
  1195. }
  1196. //========================================================================//
  1197. // PopulateDictionary
  1198. //========================================================================//
  1199. void PopulateDictionary(Dictionary<string, int> dComp, string strComponent, int intAmount)
  1200. {
  1201. dComp.Add(strComponent, intAmount);
  1202. }
  1203. //============================================================================//
  1204. // ClapYoFace Class!
  1205. //============================================================================//
  1206. // General Information (algorithm) :
  1207. // Finds a display and handles all the error checking.
  1208. // Format the Display, create progress bars, scroll the data and wordwrap!
  1209. // Works with Text Panels, LCD, Wide LCD, Display On HUD, Antenna's and Beacons.
  1210. // Author(s) : Phil Allen [email protected] https://steamcommunity.com/id/the-phil/myworkshopfiles/?appid=244850
  1211. // Last Edited By: [email protected]
  1212. // Version : 2019033100
  1213. // Copyright (C) 2015,2016,2017,2018,2019 Philip Allen
  1214. // This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  1215. // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  1216. // You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  1217. public class ClapYoFace
  1218. {
  1219. //========================================================================//
  1220. // ClapYoFace variables
  1221. //========================================================================//
  1222. // basic display stuff
  1223. public IMyTerminalBlock DisplayBlock;
  1224. public string strDebug = "";
  1225. public string strError = "";
  1226. IMyGridTerminalSystem _GridTerminalSystem = null;
  1227. string strDisplayName ="";
  1228. bool boolExactName=false;
  1229. bool boolDisplayOn=true;
  1230. bool boolMultiDisplay=false; // Not implemented. Stuck on thinking this through..
  1231. public string strDisplayType="lcd"; // LCD - text/lcd, Block - others will change CustomName to be displayed on HUD.
  1232. // formatting stuff
  1233. public Dictionary<char, float> FontCharSize = new Dictionary<char, float>();
  1234. public int intScrollLoopOffset = 0; // counter for scrollloop
  1235. public float fltFontSize = 0;
  1236. int intInitialDisplayWidth = 0;
  1237. int intDisplayWidth = 0; // 93 is the arbitary standard number based on the font size. smallest char on LCD is ' which takes 93 to span 100%. All of the dictionary char sizes are based on a percentage of 93... We should probably do this off of 100 as its a cleaner base 10 number, easier to understand.
  1238. public int intLinesPerScreen = 17;
  1239. bool boolWordWrap = true;
  1240. bool boolScroll = true;
  1241. string strFontType;
  1242. bool boolResetFontSize=false;
  1243. //========================================================================//
  1244. // ClapYoFace Constructor
  1245. //========================================================================//
  1246. public ClapYoFace(bool ExactName=false, string FontType="default")
  1247. {
  1248. boolExactName = ExactName;
  1249. // need to get font type from property of LCD
  1250. if(FontType=="default")
  1251. intDisplayWidth = 93;
  1252. intInitialDisplayWidth=intDisplayWidth;
  1253. CreateFontSizeDictionary(FontType);
  1254. }
  1255. //========================================================================//
  1256. // ClapYoFace Gets and Sets
  1257. //========================================================================//
  1258. // SetExactName - for boolExactName
  1259. public void SetExactName(bool ExactName)
  1260. {
  1261. boolExactName = ExactName;
  1262. }
  1263. // GetExactName - for boolExactName
  1264. public bool GetExactName()
  1265. {
  1266. return boolExactName;
  1267. }
  1268. // MultiDisplay Gets/Sets
  1269. public void SetMultiDisplay(bool MultiDisplay)
  1270. {
  1271. boolMultiDisplay = MultiDisplay;
  1272. }
  1273. public bool GetMultiDisplay()
  1274. {
  1275. return boolMultiDisplay;
  1276. }
  1277. // DisplayType Gets/Sets
  1278. public void SetDisplayType(string strType)
  1279. {
  1280. strDisplayType = strType.ToLower();
  1281. }
  1282. public string GetDisplayType()
  1283. {
  1284. return strDisplayType;
  1285. }
  1286. // Toggle Display OnOff
  1287. public void SetDisplayOn(bool OnOff=true)
  1288. {
  1289. if(OnOff)
  1290. boolDisplayOn=true;
  1291. else
  1292. boolDisplayOn=false;
  1293. }
  1294. public bool GetDisplayOn()
  1295. {
  1296. if(boolDisplayOn)
  1297. return true;
  1298. else
  1299. return false;
  1300. }
  1301. public void SetBoolScroll(bool OnOff)
  1302. {
  1303. if (OnOff)
  1304. boolScroll = true;
  1305. else
  1306. boolScroll = false;
  1307. }
  1308. public void SetBoolWordWrap(bool OnOff)
  1309. {
  1310. if (OnOff)
  1311. boolWordWrap = true;
  1312. else
  1313. boolWordWrap = false;
  1314. }
  1315.  
  1316. //============================== Displays ==============================//
  1317. //========================================================================//
  1318. // ClapYoFace SetDisplayBlock Method - Sets the DisplayBlock and does error checking.
  1319. // If you just want to use the formatting feature pass your own display block through.
  1320. //========================================================================//
  1321. public bool SetDisplayBlock(IMyTerminalBlock Block)
  1322. {
  1323. // Check for display block if we haven't checked before, first make sure the display block name was not changed.
  1324. // add workaround for cleaner HUD vs LCD.
  1325. bool boolCheckDisplay=false;
  1326. if (strDisplayType == "lcd")
  1327. {
  1328. if(DisplayBlock == null || strDisplayName != DisplayBlock.CustomName)
  1329. boolCheckDisplay=true;
  1330. }
  1331. else
  1332. {
  1333. if(DisplayBlock == null)
  1334. boolCheckDisplay=true;
  1335. }
  1336. if(boolCheckDisplay)
  1337. {
  1338. DisplayBlock = Block;
  1339. if (DisplayBlock == null)
  1340. {
  1341. strError = "Supplied Terminal Block is Empty";
  1342. return false;
  1343. }
  1344. if (!DisplayBlock.BlockDefinition.ToString().Contains("TextPanel"))
  1345. strDisplayType = "block";
  1346. strDisplayName = DisplayBlock.CustomName;
  1347. return true;
  1348. }
  1349. else
  1350. return true;
  1351. }
  1352. //========================================================================//
  1353. // ClapYoFace SetDisplay Method - Sets the display and does error checking.
  1354. //========================================================================//
  1355. public bool SetDisplay(string strName, IMyGridTerminalSystem grid)
  1356. {
  1357. // reset debug and error message.
  1358. strDebug = "";
  1359. //strError = "";
  1360. if(strName != strDisplayName) // check if the name matches, if code uses external variable this will force it to update.
  1361. strDisplayName = strName;
  1362. if(_GridTerminalSystem == null) // make sure gridterminalsystem exists, first run
  1363. _GridTerminalSystem = grid;
  1364. // make sure DisplayName is not empty
  1365. if (String.IsNullOrEmpty(strDisplayName))
  1366. {
  1367. strError="Display Name is empty or null. Please provide the name of your display";
  1368. return false;
  1369. }
  1370. // Check for display block if we haven't checked before, first make sure the display block name was not changed.
  1371. // add workaround for cleaner HUD vs LCD.
  1372. bool boolCheckDisplay=false;
  1373. if (strDisplayType == "lcd")
  1374. {
  1375. if(DisplayBlock == null || strDisplayName != DisplayBlock.CustomName)
  1376. boolCheckDisplay=true;
  1377. }
  1378. else
  1379. {
  1380. if(DisplayBlock == null)
  1381. boolCheckDisplay=true;
  1382. }
  1383. //if(DisplayBlock == null || strDisplayName != DisplayBlock.CustomName)
  1384. // remove check on custom name as it messes with the Show On Hud
  1385. //if(DisplayBlock == null)
  1386. if(boolCheckDisplay)
  1387. {
  1388. var DisplayBlocks = new List<IMyTerminalBlock>();
  1389. if (boolExactName)
  1390. {
  1391. if(_GridTerminalSystem.GetBlockWithName(strDisplayName) == null)
  1392. {
  1393. strError = "No Block found with name '"+strDisplayName+"'\n";
  1394. return false;
  1395. }
  1396. DisplayBlocks.Add(_GridTerminalSystem.GetBlockWithName(strDisplayName));//getblockwithname returns one block not a list.
  1397. }
  1398. else
  1399. _GridTerminalSystem.SearchBlocksOfName(strDisplayName, DisplayBlocks);
  1400. if (DisplayBlocks.Count == 1)
  1401. {
  1402. DisplayBlock = DisplayBlocks[0];
  1403. // find object type
  1404. /*
  1405. MyObjectBuilder_TextPanel/LargeLCDPanel // Large Ship Normal LCD
  1406. MyObjectBuilder_TextPanel/LargeLCDPanelWide // Large Ship Wide LCD
  1407. MyObjectBuilder_TextPanel/LargeTextPanel // Large Ship TextPanel
  1408. */
  1409. //if (!DisplayBlock.BlockDefinition.ToString().Contains("LCDPanel") || !DisplayBlock.BlockDefinition.ToString().Contains("TextPanel"))
  1410. if (!DisplayBlock.BlockDefinition.ToString().Contains("TextPanel"))
  1411. strDisplayType = "block";
  1412. return true;
  1413. }
  1414. else if (DisplayBlocks.Count > 1)
  1415. {
  1416. if(boolExactName)
  1417. {
  1418. strError = "Multiple matches found for a block with the name of '"+strDisplayName+"'.\n\n Change the name of your block so that it does not match the names of other blocks.\n";
  1419. }
  1420. else
  1421. {
  1422. strError = "Multiple matches found for a block with the name of '"+strDisplayName+"'.\n\n The script is currently set to use 'SearchBlocksOfName' try adding 'if(!<object>.GetExactName()) <object>.SetExactName(true)' to your code.\n";
  1423. }
  1424. }
  1425. else
  1426. strError = "Could not find a display with the supplied name. Please validate the name of your display is '"+strDisplayName+"'. Are you the current owner of the programmable block and display?";
  1427. return false;
  1428. }
  1429. else // We checked before and nothing changed.
  1430. return true;
  1431. }
  1432. //========================================================================//
  1433. // ClapYoFace WriteDisplay Method - Write input string to display
  1434. //========================================================================//
  1435. public void WriteDisplay(string strData)
  1436. {
  1437. if(strDisplayType.ToLower() == "lcd")
  1438. {
  1439. ((IMyTextPanel)DisplayBlock).WriteText(strData);
  1440.  
  1441.  
  1442. }
  1443. else //assume user set to Block
  1444. {
  1445. DisplayBlock.CustomName = strData;
  1446. DisplayOnHud(true);
  1447. }
  1448. }
  1449. //========================================================================//
  1450. // ClearDisplay Method - Clears Display. Mainly used for DisplayOnHUDtype
  1451. //========================================================================//
  1452. public void ClearDisplay()
  1453. {
  1454. if(strDisplayType.ToLower() == "lcd")
  1455. {
  1456. ((IMyTextPanel)DisplayBlock).WriteText("");
  1457.  
  1458.  
  1459. }
  1460. else //assume user set to Block
  1461. {
  1462. if(DisplayBlock.CustomName != strDisplayName) // only reset it if it isn't the original.
  1463. {
  1464. //DisplayBlock.SetCustomName(strDisplayName);
  1465. DisplayBlock.CustomName = strDisplayName;
  1466. DisplayOnHud(false);
  1467. }
  1468. }
  1469. }
  1470. //========================================================================//
  1471. // DisplayOnHUD - Sets Display Block to Display On HUD.
  1472. //========================================================================//
  1473. public void DisplayOnHud(bool OnOff)
  1474. {
  1475. if(OnOff)
  1476. {
  1477. DisplayBlock.SetValueBool("ShowOnHUD", true);
  1478. }
  1479. else
  1480. {
  1481. DisplayBlock.SetValueBool("ShowOnHUD", false);
  1482. }
  1483. }
  1484. //========================================================================//
  1485. // SetDisplayConfig
  1486. //========================================================================//
  1487. public void SetDisplayConfig()
  1488. {
  1489. strDebug = "";
  1490. // this will reset everything user changes display size
  1491. if (strDisplayType == "lcd")
  1492. {
  1493. if(strFontType != ((IMyTextPanel)DisplayBlock).Font)
  1494. {
  1495. strFontType = ((IMyTextPanel)DisplayBlock).Font;
  1496. if(strFontType == "Monospace")
  1497. {
  1498. intDisplayWidth=26;
  1499. intInitialDisplayWidth=intDisplayWidth;
  1500. intLinesPerScreen=17;
  1501. CreateFontSizeDictionary(strFontType);
  1502. }
  1503. else // assume default font, covers Debug,Red,Green,Blue,White,DarkBlue,UrlNormal,UrlHighlight,ErrorMessageBoxCaption,ErrorMessageBoxText,InfoMessageBoxCaption,InfoMessageBoxText,ScreenCaption,GameCredits,LoadingScreen,BuildInfo,BuildInfoHighlight
  1504. {
  1505. intDisplayWidth=93;
  1506. intInitialDisplayWidth=intDisplayWidth;
  1507. intLinesPerScreen=17;
  1508. CreateFontSizeDictionary(strFontType);
  1509. }
  1510. boolResetFontSize=true;
  1511. }
  1512. if(fltFontSize != ((IMyTextPanel)DisplayBlock).FontSize || boolResetFontSize)
  1513. {
  1514. // get font info
  1515. fltFontSize = ((IMyTextPanel)DisplayBlock).FontSize;
  1516. // get Display Width
  1517. float fltDisplayWidth = (float)intInitialDisplayWidth;
  1518. if (DisplayBlock.BlockDefinition.ToString().Contains("LargeLCDPanelWide"))
  1519. fltDisplayWidth = fltDisplayWidth*2.010752f;
  1520. fltDisplayWidth = fltDisplayWidth/fltFontSize;
  1521. intDisplayWidth = (int)fltDisplayWidth;
  1522. //strDebug += fltDisplayWidth.ToString()+"\n";
  1523. //strDebug += intDisplayWidth.ToString()+"\n";
  1524. //17.6 seems like a good standard. just int it.
  1525. intLinesPerScreen = (int)(17.6/fltFontSize);
  1526. boolResetFontSize=false;
  1527. }
  1528. }
  1529. else // using show on hud, e.g. antenna or beacon.
  1530. {
  1531. if(fltFontSize == 0)
  1532. {
  1533. // display size keep at default.. e.g. 93.
  1534. intDisplayWidth=93;
  1535. // font size to one.
  1536. fltFontSize = 1f;
  1537. // lines are good at 17.
  1538. intLinesPerScreen = 17;
  1539. }
  1540. }
  1541. strDebug += intDisplayWidth.ToString()+"\n";
  1542. }
  1543. //============================ Font Sizes ============================//
  1544. //========================================================================//
  1545. // CreateFontSizeDictionary
  1546. //========================================================================//
  1547. void CreateFontSizeDictionary(string FontType)
  1548. {
  1549. if (FontType=="Monospace")
  1550. {
  1551. FontCharSize.Clear();
  1552. FontSizeAddCharToDictionary("\n",0f);
  1553. FontSizeAddCharToDictionary("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",1f);//basic letters
  1554. FontSizeAddCharToDictionary("1234567890",1f);// numbers
  1555. FontSizeAddCharToDictionary("!@#$%^&*()<>?,./[]{}\\|-=_+`~;':\" ",1f); // common symbols
  1556. FontSizeAddCharToDictionary("ƒ«°",1f);// uncommon characters
  1557. // need to set this up so it defaults non loaded
  1558. }
  1559. else // all the other fonts, DEBUG, etc should be this.
  1560. {
  1561. FontCharSize.Clear();
  1562. FontSizeAddCharToDictionary("\n",0f);
  1563. FontSizeAddCharToDictionary("'|",1f);
  1564. FontSizeAddCharToDictionary(" !`Iijl",1.29166f);
  1565. FontSizeAddCharToDictionary("(),.:;[]{}1ft",1.43076f);
  1566. FontSizeAddCharToDictionary("\"-r",1.57627f);
  1567. FontSizeAddCharToDictionary("*",1.72222f);
  1568. FontSizeAddCharToDictionary("\\°",1.86f);
  1569. FontSizeAddCharToDictionary("/",2.16279f);
  1570. FontSizeAddCharToDictionary("«Lvx_ƒ",2.325f);
  1571. FontSizeAddCharToDictionary("?7Jcz",2.44736f);
  1572. FontSizeAddCharToDictionary("3FKTabdeghknopqsuy",2.58333f);
  1573. FontSizeAddCharToDictionary("+<>=^~E",2.73529f);
  1574. FontSizeAddCharToDictionary("#0245689CXZ",2.90625f);
  1575. FontSizeAddCharToDictionary("$&GHPUVY",3f);
  1576. FontSizeAddCharToDictionary("ABDNOQRS",3.20689f);
  1577. FontSizeAddCharToDictionary("%",3.57692f);
  1578. FontSizeAddCharToDictionary("@",3.72f);
  1579. FontSizeAddCharToDictionary("M",3.875f);
  1580. FontSizeAddCharToDictionary("mw",4.04347f);
  1581. FontSizeAddCharToDictionary("W",4.65f);
  1582. }
  1583. }
  1584. //========================================================================//
  1585. // FontSizeAddCharToDictionary
  1586. //========================================================================//
  1587. public void FontSizeAddCharToDictionary(string CharList, float CharSize)
  1588. {
  1589. for (int i=0; i<CharList.Length;i++)
  1590. FontCharSize.Add(CharList[i], CharSize);
  1591. }
  1592. //=================== Percentage and Progress bars ===================//
  1593. //========================================================================//
  1594. // PercentFirstDecimal - find percentage return formatted "100.0%" "80.9%" etc.
  1595. //========================================================================//
  1596. public string PercentFirstDecimal(float Numerator, float Denominator)
  1597. {
  1598. float fltPercent = Numerator/Denominator;
  1599. if (Numerator > Denominator)// check if numerator is higher and percent is 100.
  1600. fltPercent = 1;
  1601. return Math.Round((fltPercent*100), 1).ToString("F1")+"%";// round to first decimal
  1602. }
  1603. //========================================================================//
  1604. // ProgressBar - Create a Bar [||||''] that spans the entire width
  1605. //========================================================================//
  1606. public string ProgressBar(float Numerator, float Denominator=-1, float fltWidth=1)
  1607. {
  1608. float fltPercent=0;
  1609. if(Denominator==-1f)
  1610. fltPercent = Numerator;
  1611. else
  1612. fltPercent = Numerator/Denominator;
  1613. // Find out how much space will be used before bar.
  1614. float fltBracketSize = StringSize("[]"); // border of bar graph.
  1615. // find how many | or ' we should have
  1616. float fltBarSize = ((float)intDisplayWidth)*fltWidth-fltBracketSize;
  1617. int intBarLength = (int)(fltBarSize/StringSize("|"));
  1618. // Find out how many "filled" bars we will have
  1619. int intFilledBars = (int)(fltPercent*intBarLength);
  1620. // make sure we have one bar filled if greater than 0
  1621. if (intFilledBars == 0 && fltPercent >0)
  1622. intFilledBars = 1;
  1623. // make bar
  1624. string strPercentBar = "[";
  1625. for (int i=0;i<intBarLength;i++)
  1626. {
  1627. if (i<intFilledBars)
  1628. strPercentBar += "|";
  1629. else
  1630. strPercentBar += "'";
  1631. }
  1632. strPercentBar += "]";
  1633. return strPercentBar;
  1634. }
  1635. //========================================================================//
  1636. // ProgressBarTrailingNumbers - Create a Bar "[||||''] 100.0%" Has percent on end and fills the rest.
  1637. //========================================================================//
  1638. public string ProgressBarTrailingNumbers(float Numerator, float Denominator=-1, float fltWidth=1)
  1639. {
  1640. // types: trailing %
  1641. float fltPercent=0;
  1642. if(Denominator==-1f)
  1643. fltPercent = Numerator;
  1644. else if (Numerator > Denominator)// check if numerator is higher and percent is 100.
  1645. fltPercent = 1;
  1646. else
  1647. fltPercent = Numerator/Denominator;
  1648. string strPercent = Math.Round((fltPercent*100), 1).ToString("F1")+"%";
  1649. // Find out how much space will be used before bar.
  1650. float fltExtraSpace = StringSize(" 100.0%"); // largest size of text percent.
  1651. float fltBracketSize = StringSize("[]"); // border of bar graph.
  1652. // find how many | or ' we should have
  1653. float fltBarSize = ((float)intDisplayWidth)*fltWidth-fltExtraSpace-fltBracketSize;
  1654. int intBarLength = (int)(fltBarSize/StringSize("|"));
  1655. // Find out how many "filled" bars we will have
  1656. int intFilledBars = (int)(fltPercent*intBarLength);
  1657. // make sure we have one bar filled if greater than 0
  1658. if (intFilledBars == 0 && fltPercent >0)
  1659. intFilledBars = 1;
  1660. // make bar
  1661. string strPercentBar = "[";
  1662. for (int i=0;i<intBarLength;i++)
  1663. {
  1664. if (i<intFilledBars)
  1665. strPercentBar += "|";
  1666. else
  1667. strPercentBar += "'";
  1668. }
  1669. strPercentBar += "]";
  1670. // find out how many space we need to get the % at the end of the line.
  1671. float fltRightTextSize = StringSize(strPercentBar);
  1672. float fltLeftTextSize = StringSize(strPercent);
  1673. float fltLeftOverSpace = ((float)intDisplayWidth)*fltWidth-fltRightTextSize-fltLeftTextSize;
  1674. int intSpacesToFill = (int)(fltLeftOverSpace/StringSize(" "));
  1675. // add spaces to bar
  1676. for(int i=0;i<intSpacesToFill;i++)
  1677. strPercentBar+=" ";
  1678. // add percent to bar
  1679. strPercentBar+=strPercent;
  1680. return strPercentBar;
  1681. }
  1682. //========================================================================//
  1683. // AlignLeftRight - Takes two strings and aligns one on the left the other on the right.
  1684. //========================================================================//
  1685. public string AlignLeftRight(string Left, string Right,string TruncatePreference="left")
  1686. {
  1687. float fltRightTextSize = StringSize(Right);
  1688. float fltLeftTextSize = StringSize(Left);
  1689. float fltLeftOverSpace = ((float)intDisplayWidth)-fltRightTextSize-fltLeftTextSize;
  1690. if (fltLeftOverSpace > 0)
  1691. {
  1692. int intSpacesToFill = (int)(fltLeftOverSpace/StringSize(" "));
  1693. for(int i=0;i<intSpacesToFill;i++)
  1694. Left+=" ";
  1695. }
  1696. else
  1697. {
  1698. if(TruncatePreference=="left")
  1699. {
  1700. //strDebug +="Here!\n";
  1701. Left=StringTruncate(Left,((float)intDisplayWidth-fltRightTextSize)/intDisplayWidth);
  1702. }
  1703. else
  1704. Right=StringTruncate(Right,((float)intDisplayWidth-fltLeftTextSize)/intDisplayWidth);
  1705. }
  1706. return Left+Right;
  1707. }
  1708. //========================================================================//
  1709. // AlignCenter - Adds spaces to begining of string
  1710. //========================================================================//
  1711. public string AlignCenter(string Center)
  1712. {
  1713. float fltCenterTextSize = StringSize(Center);
  1714. float fltLeftOverSpace = ((float)intDisplayWidth)-fltCenterTextSize;
  1715. if (fltLeftOverSpace > 0)
  1716. {
  1717. int intSpacesToFill = (int)(fltLeftOverSpace/StringSize(" "));
  1718. for(int i=0;i<intSpacesToFill/2;i++)
  1719. Center = " "+Center; // add spaces to the front of text.
  1720. }
  1721. else
  1722. {
  1723. Center=StringTruncate(Center,((float)intDisplayWidth-fltCenterTextSize)/intDisplayWidth);
  1724. }
  1725. return Center;
  1726. }
  1727. //========================= String Formatting ========================//
  1728. //========================================================================//
  1729. // FormatString
  1730. //========================================================================//
  1731. public string FormatString(string strData)
  1732. {
  1733. if(boolWordWrap)
  1734. strData = WordWrap(strData);
  1735. if(boolScroll)
  1736. strData = ScrollLoop(strData);
  1737. return strData;
  1738. }
  1739. //========================================================================//
  1740. // StringTruncate
  1741. //========================================================================//
  1742. public string StringTruncate(string Truncate, float Width=1, bool AtWhiteSpace=false, int intDotCount=3)
  1743. {
  1744. //strDebug="";
  1745. float fltDotSize = 0;
  1746. string strDots = "";
  1747. if (intDotCount != 0)
  1748. {
  1749. for(int i=0;i<intDotCount;i++)
  1750. strDots += ".";
  1751. //intDotSize = (int)StringSize(".")*intDotCount;
  1752. }
  1753. //strDebug += StringSize(strDots).ToString()+"\n";
  1754. //strDebug += ((int)StringSize(strDots)).ToString()+"\n";
  1755. fltDotSize = (int)StringSize(strDots);
  1756. int intCutAt = 0;
  1757. if(AtWhiteSpace)
  1758. intCutAt = StringCutLocation(Truncate, (int)(((float)(intDisplayWidth))*Width-fltDotSize));
  1759. else
  1760. intCutAt = StringCutLocation(Truncate, (int)(((float)(intDisplayWidth))*Width-fltDotSize), false);
  1761. Truncate = Truncate.Substring(0,intCutAt);
  1762. return Truncate+strDots;
  1763. }
  1764. //========================================================================//
  1765. // StringSize
  1766. //========================================================================//
  1767. public float StringSize(string strData)
  1768. {
  1769. float fltTotal = 0;
  1770. for (int i=0; i<strData.Length;i++)
  1771. {
  1772. fltTotal += FontCharSize[strData[i]];
  1773. }
  1774. return fltTotal;
  1775. }
  1776. //============================================================================//
  1777. // StringCutLocation
  1778. //============================================================================//
  1779. public int StringCutLocation(string strData, int intDisplayWidth,bool boolCutAtSpace=true)
  1780. {
  1781. int intCurrentLocation = 0;
  1782. float fltTotal = 0;
  1783. for (int i=0; i<strData.Length;i++)
  1784. {
  1785. fltTotal += FontCharSize[strData[i]];
  1786. if (fltTotal < intDisplayWidth)
  1787. intCurrentLocation = i;
  1788. // else
  1789. // break; //this should break out of loop?
  1790. }
  1791. // find last space to cut.
  1792. int intCutPosition = strData.Substring(0,intCurrentLocation).LastIndexOf(" ");
  1793. if (intCutPosition == -1 || !boolCutAtSpace) intCutPosition = intCurrentLocation;
  1794. return intCutPosition;
  1795. }
  1796. //============================================================================//
  1797. // StringCutAddNewLine
  1798. //============================================================================//
  1799. public string StringCutAddNewLine(string strData, int intDisplayWidth)
  1800. {
  1801. string strNL = "";// NewLine
  1802. string strT = ""; // Temp
  1803. int intCL = StringCutLocation(strData, intDisplayWidth); // Cut Location
  1804. strNL += strData.Substring(0,intCL)+"\n";
  1805. strT += strData.Substring(intCL).Trim();
  1806. //Echo (strT.Length.ToString());
  1807. //Echo (StringSize(strT).ToString());
  1808. if (StringSize(strT) > intDisplayWidth)
  1809. strNL+=StringCutAddNewLine(strT,intDisplayWidth)+"\n";
  1810. else
  1811. strNL+=strT+"\n";
  1812. return strNL;
  1813. }
  1814. //============================================================================//
  1815. // WordWrap
  1816. //============================================================================//
  1817. //http://stackoverflow.com/questions/3961278/word-wrap-a-string-in-multiple-lines
  1818. public string WordWrap(string strData)
  1819. {
  1820. strDebug = "";
  1821. string strNew = "";
  1822. // split string up by EOL
  1823. // if string has no new line this code is poopoop.
  1824. // add a find char \n if it doesn't exist don't do the loop.
  1825. int intIndexOfNewLine = strData.IndexOf("\n");
  1826. if(intIndexOfNewLine == -1)
  1827. {
  1828. if(StringSize(strData) > intDisplayWidth)
  1829. {
  1830. // needs a line break.
  1831. strNew += StringCutAddNewLine(strData,intDisplayWidth);
  1832. }
  1833. else
  1834. strNew += strData+"\n";
  1835. }
  1836. else
  1837. {
  1838. string[] arrStrData = strData.Split('\n');
  1839. for (int i=0;i<arrStrData.Length-1;i++)
  1840. {
  1841. if(StringSize(arrStrData[i]) > intDisplayWidth)
  1842. {
  1843. // needs a line break.
  1844. strNew += StringCutAddNewLine(arrStrData[i],intDisplayWidth);
  1845. }
  1846. else
  1847. strNew += arrStrData[i]+"\n";
  1848. }
  1849. }
  1850. //strNew=intIndexOfNewLine.ToString();
  1851. return strNew;
  1852. }
  1853. //============================================================================//
  1854. // ScrollLoop
  1855. // Scrolls in continuous loop
  1856. //============================================================================//
  1857. // hmm would a more simple version of this, simply be taking the top line and adding it to the bottom? lol.
  1858. public string ScrollLoop(string strData, int intScrollLines=1, string strHeader=null, string strFooter=null)
  1859. {
  1860.  
  1861. //return strData.IndexOf("\n").ToString();
  1862. int intDisplayLines = intLinesPerScreen;
  1863. string strReturn = "";
  1864. // get lines from data.
  1865. string[] arrData = strData.Split('\n');
  1866. int intDataLength = arrData.Length;
  1867. int x = 0; // recycle data for smooth looping.
  1868. // header
  1869. if (strHeader != null)
  1870. {
  1871. strReturn += strHeader+"\n";
  1872. intDisplayLines = intDisplayLines-1;
  1873. }
  1874. // change counter for footer
  1875. if (strFooter != null)
  1876. intDisplayLines = intDisplayLines-1;
  1877. // process data if longer than limit
  1878. if (intDisplayLines < intDataLength) // need to truncate size.
  1879. {
  1880. for (int i=0; i < intDisplayLines; i++)
  1881. {
  1882. //strReturn += (intScrollLoopOffset+1).ToString()+" - ";
  1883. if (i+intScrollLoopOffset < intDataLength)
  1884. {
  1885. strReturn += arrData[i+intScrollLoopOffset]+"\n";
  1886. x=0;
  1887. }
  1888. else // over the line limit, need to recycle data.
  1889. {
  1890. strReturn += arrData[x]+"\n";
  1891. x++;
  1892. }
  1893. }
  1894. }
  1895. // no need to scroll return the original data.
  1896. else
  1897. {
  1898. strReturn = strReturn+strData;
  1899. }
  1900. if (strFooter != null)
  1901. strReturn += strFooter+"\n";
  1902. // set variable for
  1903. intScrollLoopOffset+=intScrollLines;
  1904. if ((intDataLength)-1 < intScrollLoopOffset)
  1905. //if ((intDataLength+intScrollLines-intDisplayLines+4) < scrollOffset)
  1906. intScrollLoopOffset=0;
  1907. else if (intScrollLoopOffset < 0)
  1908. // set scroll loop offset to the max length
  1909. intScrollLoopOffset = intDataLength-1;
  1910. // return processed data
  1911. //strReturn=intDataLength.ToString();
  1912. return strReturn;
  1913. }
  1914. //============================================================================//
  1915. // Scroll
  1916. // Scrolls till reached end, or top.
  1917. //============================================================================//
  1918. public string Scroll(string strData, int intScrollLines=1, string strHeader=null, string strFooter=null)
  1919. {
  1920. int intDisplayLines = intLinesPerScreen;
  1921. string strReturn = "";
  1922. // get lines from data.
  1923. string[] arrData = strData.Split('\n');
  1924. int intDataLength = arrData.Length;
  1925. // header
  1926. if (strHeader != null)
  1927. {
  1928. strReturn += strHeader+"\n";
  1929. intDisplayLines = intDisplayLines-1;
  1930. }
  1931. // change counter for footer
  1932. if (strFooter != null)
  1933. intDisplayLines = intDisplayLines-1;
  1934. // process data if longer than limit
  1935. if (intDisplayLines < intDataLength) // need to truncate size.
  1936. {
  1937. for (int i=0; i < intDisplayLines; i++)
  1938. {
  1939. //strReturn += (intScrollLoopOffset+1).ToString()+" - ";
  1940. if (i+intScrollLoopOffset < intDataLength+intDisplayLines)
  1941. {
  1942. strReturn += arrData[i+intScrollLoopOffset]+"\n";
  1943. }
  1944. else
  1945. {
  1946. // Under/Over the line limit do nothing
  1947. }
  1948. }
  1949. }
  1950. // no need to scroll return the original data.
  1951. else
  1952. {
  1953. strReturn = strData;
  1954. }
  1955. if (strFooter != null)
  1956. strReturn += strFooter+"\n";
  1957. // set variable for
  1958. intScrollLoopOffset+=intScrollLines;
  1959. // if we reached the end of the screen revert the offset we just gave.
  1960. if ((intDataLength) < intScrollLoopOffset+intDisplayLines || intScrollLoopOffset < 0)
  1961. intScrollLoopOffset=intScrollLoopOffset-=intScrollLines;
  1962. // return processed data
  1963. return strReturn;
  1964. }
  1965. }
  1966. //============================================================================//
  1967. // END ClapYoFace Class!
  1968. //============================================================================//
Add Comment
Please, Sign In to add comment