Guest User

Untitled

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