./msn_text_adventure.lua

  1. local Data = { 
  2. 	[0] = { 
  3. 		scenario = "M16_TXT_ADV_SC_00", 
  4. 		choices = { 
  5. 			[1] = { 
  6. 				label = "M16_TXT_ADV_SC_00_CH1", 
  7. 				target = 2, 
  8. 				type = TYPE_BUTTON,				 
  9. 			}, 
  10. 			[2] = { 
  11. 				label = "M16_TXT_ADV_SC_00_CH2", 
  12. 				target = 3,				 
  13. 				type = TYPE_BUTTON,				 
  14. 			}, 
  15. 			[3] = { 
  16. 				label = "M16_TXT_ADV_SC_00_CH3", 
  17. 				target = 1,				 
  18. 				type = TYPE_BUTTON,				 
  19. 			}, 
  20. 			[4] = { 
  21. 				label = "M16_TXT_ADV_SC_00_CH4", 
  22. 				target = 0,				 
  23. 				type = TYPE_BUTTON,				 
  24. 			}, 
  25. 		}, 
  26. 		sfx = "Scenario", 
  27. 	}, 
  28. 	[1] = { 
  29. 		scenario = "M16_TXT_ADV_SC_01", 
  30. 		choices = { 
  31. 			[1] = { 
  32. 				label = "M16_TXT_ADV_SC_01_CH1", 
  33. 				target = 2,		 
  34. 				type = TYPE_BUTTON,				 
  35. 			}, 
  36. 			[2] = { 
  37. 				label = "M16_TXT_ADV_SC_01_CH2", 
  38. 				target = 3,				 
  39. 				type = TYPE_BUTTON, 
  40. 			}, 
  41. 			[3] = { 
  42. 				label = "M16_TXT_ADV_SC_01_CH3", 
  43. 				target = 0,			 
  44. 				type = TYPE_BUTTON,				 
  45. 			}, 
  46. 		}, 
  47. 		sfx = "Neutral",		 
  48. 	}, 
  49. 	[2] = { 
  50. 		scenario = "M16_TXT_ADV_SC_02", 
  51. 		choices = { 
  52. 			[1] = { 
  53. 				label = "M16_TXT_ADV_SC_02_CH1", 
  54. 				target = 0, 
  55. 				type = TYPE_BUTTON,				 
  56. 			}, 
  57. 		},	 
  58. 		sfx = "Dead", 
  59. 	},	 
  60. 	[3] = { 
  61. 		scenario = "M16_TXT_ADV_SC_03", 
  62. 		choices = { 
  63. 			[1] = { 
  64. 				label = "M16_TXT_ADV_SC_03_CH1", 
  65. 				target = 6, 
  66. 				type = TYPE_BUTTON,				 
  67. 			}, 
  68. 			[2] = { 
  69. 				label = "M16_TXT_ADV_SC_03_CH2", 
  70. 				target = 4,				 
  71. 				type = TYPE_BUTTON, 
  72. 			}, 
  73. 			[3] = { 
  74. 				label = "M16_TXT_ADV_SC_03_CH3", 
  75. 				target = 5,			 
  76. 				type = TYPE_BUTTON,				 
  77. 			}, 
  78. 		}, 
  79. 		sfx = "Progress",		 
  80. 	}, 
  81. 	[4] = { 
  82. 		scenario = "M16_TXT_ADV_SC_04", 
  83. 		choices = { 
  84. 			[1] = { 
  85. 				label = "M16_TXT_ADV_SC_04_CH1", 
  86. 				target = 6,	 
  87. 				type = TYPE_BUTTON,				 
  88. 			}, 
  89. 			[2] = { 
  90. 				label = "M16_TXT_ADV_SC_04_CH2", 
  91. 				target = 5,				 
  92. 				type = TYPE_BUTTON, 
  93. 			}, 
  94. 		}, 
  95. 		sfx = "Neutral", 
  96. 	}, 
  97. 	[5] = { 
  98. 		scenario = "M16_TXT_ADV_SC_05", 
  99. 		choices = { 
  100. 			[1] = { 
  101. 				label = "M16_TXT_ADV_SC_05_CH1", 
  102. 				target = 0,			 
  103. 				type = TYPE_BUTTON,				 
  104. 			}, 
  105. 		}, 
  106. 		sfx = "Dead",		 
  107. 	},	 
  108. 	[6] = { 
  109. 		scenario = "M16_TXT_ADV_SC_06", 
  110. 		choices = { 
  111. 			[1] = { 
  112. 				label = "M16_TXT_ADV_SC_06_CH1", 
  113. 				target = 9,				 
  114. 				type = TYPE_BUTTON, 
  115. 			}, 
  116. 			[2] = { 
  117. 				label = "M16_TXT_ADV_SC_06_CH2", 
  118. 				target = 8,			 
  119. 				type = TYPE_BUTTON,				 
  120. 			}, 
  121. 			[3] = { 
  122. 				label = "M16_TXT_ADV_SC_06_CH3", 
  123. 				target = 7,				 
  124. 				type = TYPE_BUTTON, 
  125. 			}, 
  126. 		}, 
  127. 		sfx = "Progress",		 
  128. 	}, 
  129. 	[7] = { 
  130. 		scenario = "M16_TXT_ADV_SC_07", 
  131. 		choices = { 
  132. 			[1] = { 
  133. 				label = "M16_TXT_ADV_SC_07_CH1", 
  134. 				target = 9,			 
  135. 				type = TYPE_BUTTON,				 
  136. 			}, 
  137. 			[2] = { 
  138. 				label = "M16_TXT_ADV_SC_07_CH2", 
  139. 				target = 8,				 
  140. 				type = TYPE_BUTTON, 
  141. 			}, 
  142. 		}, 
  143. 		sfx = "Neutral",		 
  144. 	}, 
  145. 	[8] = { 
  146. 		scenario = "M16_TXT_ADV_SC_08", 
  147. 		choices = { 
  148. 			[1] = { 
  149. 				label = "M16_TXT_ADV_SC_08_CH1", 
  150. 				target = 0,			 
  151. 				type = TYPE_BUTTON,				 
  152. 			}, 
  153. 		}, 
  154. 		sfx = "Dead",		 
  155. 	},	 
  156. 	[9] = { 
  157. 		scenario = "M16_TXT_ADV_SC_09", 
  158. 		choices = { 
  159. 			[1] = { 
  160. 				label = "M16_TXT_ADV_SC_09_CH1", 
  161. 				target = 10,				 
  162. 				type = TYPE_BUTTON, 
  163. 			}, 
  164. 			[2] = { 
  165. 				label = "M16_TXT_ADV_SC_09_CH2", 
  166. 				target = 11,		 
  167. 				type = TYPE_BUTTON,				 
  168. 			}, 
  169. 			[3] = { 
  170. 				label = "M16_TXT_ADV_SC_09_CH3", 
  171. 				target = 12,				 
  172. 				type = TYPE_BUTTON, 
  173. 			}, 
  174. 		}, 
  175. 		sfx = "Progress",		 
  176. 	}, 
  177. 	[10] = { 
  178. 		scenario = "M16_TXT_ADV_SC_10", 
  179. 		choices = { 
  180. 			[1] = { 
  181. 				label = "M16_TXT_ADV_SC_10_CH1", 
  182. 				target = 11,		 
  183. 				type = TYPE_BUTTON,				 
  184. 			}, 
  185. 			[2] = { 
  186. 				label = "M16_TXT_ADV_SC_10_CH2", 
  187. 				target = 12,				 
  188. 				type = TYPE_BUTTON, 
  189. 			}, 
  190. 		}, 
  191. 		sfx = "Neutral",					 
  192. 	}, 
  193. 	[11] = { 
  194. 		scenario = "M16_TXT_ADV_SC_11", 
  195. 		choices = { 
  196. 			[1] = { 
  197. 				label = "M16_TXT_ADV_SC_11_CH1", 
  198. 				target = 0,			 
  199. 				type = TYPE_BUTTON,				 
  200. 			}, 
  201. 		}, 
  202. 		sfx = "Dead",		 
  203. 	},	 
  204. 	[12] = { 
  205. 		scenario = "M16_TXT_ADV_SC_12", 
  206. 		choices = { 
  207. 			[1] = { 
  208. 				label = "M16_TXT_ADV_SC_12_CH2", 
  209. 				target = -1,				 
  210. 				type = TYPE_BUTTON, 
  211. 			}, 
  212. 			[2] = { 
  213. 				label = "M16_TXT_ADV_SC_12_CH1", 
  214. 				target = 0,			 
  215. 				type = TYPE_BUTTON,				 
  216. 			}, 
  217. 		}, 
  218. 		sfx = "Win",		 
  219. 	}, 
  220. } 
  221. 	 
  222. local COLOR_TEXT_ADVENTURE_PRIMARY = {R = 220/255, G = 220/255, B = 220/255} 
  223. local COLOR_TEXT_ADVENTURE_SECONDARY = {R = 120/255, G = 120/255, B = 120/255} 
  224. local COLOR_TEXT_ADVENTURE_TERTIARY = {R = 90/255, G = 90/255, B = 90/255} 
  225.  
  226. local Text_buffer = {} 
  227. local Max_text_buffer_length = 6 
  228. local Input_tracker 
  229. local Mouse_input_tracker 
  230. local Msn_text_adventure_doc_handle = -1 
  231. local Active_list 
  232. local Cur_scen = 0 
  233. local Cur_audio_id = -1 
  234. local Action = {} 
  235.  
  236. function msn_text_adventure_init() 
  237.  
  238. 	--Get doc handle 
  239. 	Msn_text_adventure_doc_handle = vint_document_find("msn_text_adventure") 
  240.  
  241. 	--Handle Input Tracker 
  242. 	Input_tracker = Vdo_input_tracker:new() 
  243. 	Input_tracker:add_input("nav_up", "msn_text_adventure_nav_up", 50) 
  244. 	Input_tracker:add_input("nav_down", "msn_text_adventure_nav_down", 50) 
  245. 	Input_tracker:add_input("select", "msn_text_adventure_button_a", 50) 
  246. 	Input_tracker:subscribe(true)	 
  247.  
  248. 		-- Add mouse input subscriptions for the PC 
  249. 	if game_get_platform() == "PC" then 
  250. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  251. 	end 
  252. 	 
  253. 	--Setup megalist 
  254. 	Active_list = Vdo_mega_list:new("choice_list", 0, Msn_text_adventure_doc_handle) 
  255. 	Active_list:set_highlight_color(COLOR_TEXT_ADVENTURE_TERTIARY,COLOR_STORE_VEHICLE_SECONDARY,COLOR_STORE_VEHICLE_TERTIARY) 
  256. 		 
  257.  
  258. 	--Hide base text 
  259. 	local base_text = vint_object_find("base_text", 0, Msn_text_adventure_doc_handle) 
  260. 	vint_set_property(base_text, "visible", false)	 
  261. 	 
  262. 	local cursor_blink = Vdo_anim_object:new("cursor_blink", 0, Msn_text_adventure_doc_handle) 
  263. 	cursor_blink:play(0) 
  264. 	 
  265. 	msn_text_adventure_update(Data) 
  266. 	 
  267.  
  268. end 
  269.  
  270. function msn_text_adventure_cleanup() 
  271. 	for i = 1, #Text_buffer do 
  272. 		Text_buffer[i]:object_destroy() 
  273. 	end 
  274. end 
  275.  
  276. function msn_text_adventure_update(data) 
  277.  
  278. 	local base_text = vint_object_find("base_txt", 0, Msn_text_adventure_doc_handle) 
  279. 	vint_set_property(base_text, "visible", false) 
  280. 	 
  281. 	--If we're on the first page play typing audio 
  282. 	if Cur_scen == 0 then 
  283. 		audio_stop(Cur_audio_id) 
  284. 		Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", Data[Cur_scen].sfx) 
  285. 	end 
  286. 	 
  287. 	--Make current text first in the queue 
  288. 	if Text_buffer[1] ~= nil then 
  289. 		for i = Max_text_buffer_length, 1, -1 do 
  290. 			if Text_buffer[i] ~= nil then 
  291. 				Text_buffer[i+1] = Text_buffer[i] 
  292. 			end 
  293. 		end 
  294. 	end 
  295.  
  296. 	Text_buffer[1] = Vdo_base_object:clone(base_text)	 
  297. 	Text_buffer[1]:set_text(data[Cur_scen].scenario)	 
  298. 	Text_buffer[1]:set_visible(true) 
  299. 	 
  300. 	local move_width, move_height = Text_buffer[1]:get_actual_size() 
  301. 	 
  302. 	local text_x, text_y  
  303.  
  304. 	--Scroll text up if text exist 
  305. 	if Text_buffer[2] ~= nil then 
  306. 		text_x, text_y = Text_buffer[2]:get_anchor() 
  307. 		Text_buffer[2]:set_anchor(text_x, text_y - move_height) 
  308. 		Text_buffer[2]:set_color(COLOR_TEXT_ADVENTURE_TERTIARY.R,COLOR_TEXT_ADVENTURE_TERTIARY.G,COLOR_TEXT_ADVENTURE_TERTIARY.B) 
  309. 		 
  310. 		--Delete items that go off the screen 
  311. 		if text_y < -200 then 
  312. 			Text_buffer[2]:object_destroy() 
  313. 		end 
  314. 	end 
  315. 	 
  316. 	--Populate megalist	 
  317. 	Active_list:draw_items(data[Cur_scen].choices, 1, 500, 4, .8) 
  318. 		 
  319. 	--Update inputs if on pc... 
  320. 	if game_get_platform() == "PC" then 
  321. 		Mouse_input_tracker:remove_all() 
  322. 		Active_list:add_mouse_inputs("msn_text_adventure", Mouse_input_tracker) 
  323. 		Mouse_input_tracker:subscribe(true) 
  324. 	end 
  325. end 
  326.  
  327. function msn_text_adventure_button_a(event, acceleration) 
  328. 	--What choice did they pick? 
  329. 	local user_choice = Active_list:get_selection() 
  330. 	local previous_scen = Cur_scen 
  331. 	 
  332. 	--Set cur_scene to target 
  333. 	Cur_scen = Data[Cur_scen].choices[user_choice].target 
  334. 	 
  335. 	if Cur_scen == -1 then 
  336. 		msn_text_adventure_set_screen(12) -- count the success as a 12th screen 
  337. 		pop_screen() 
  338. 		return 
  339. 	end 
  340. 	 
  341. 	if Cur_scen == 0 then 
  342. 		-- if the current scene is 0, and the previous was 0, the player decided to nap 
  343. 		if previous_scen == 0 then 
  344. 			msn_text_adventure_set_screen(Cur_scen) 
  345. 		end 
  346. 	else 
  347. 		msn_text_adventure_set_screen(Cur_scen) 
  348. 	end 
  349. 	 
  350. 	audio_stop(Cur_audio_id) 
  351. 	Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", Data[Cur_scen].sfx) 
  352. 		 
  353. 	--What is the string for that choice? 
  354. 	Action = Active_list:return_selected_data() 
  355. 	 
  356. 	Text_buffer[1]:set_text(Action.label) 
  357. 	 
  358. 	if Text_buffer[2] ~= nil then 
  359. 		Text_buffer[2]:object_destroy() 
  360. 	end 
  361. 	 
  362. 	--Update text 
  363. 	msn_text_adventure_update(Data) 
  364. 	 
  365. end 
  366.  
  367. function msn_text_adventure_nav_up(event, acceleration) 
  368. 	Active_list:move_cursor(-1) 
  369. 	Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", "Navigation") 
  370. end 
  371.  
  372. function msn_text_adventure_nav_down(event, acceleration) 
  373. 	Active_list:move_cursor(1) 
  374. 	Cur_audio_id = audio_object_post_event("Text_Adventure", "Mission_16_Text_Adventure", "Navigation") 
  375. end 
  376.  
  377. ------------------------------------------------------------------------------- 
  378. -- Mouse inputs 
  379. -- 
  380.  
  381. function msn_text_adventure_mouse_click(event, target_handle) 
  382. 	--Click item in megalist... 
  383. 	local new_index = Active_list:get_button_index(target_handle) 
  384. 	if new_index ~= 0 then 
  385. 		-- Enter an option if the target_handle is in the List 
  386. 		Active_list:set_selection(new_index) 
  387. 		msn_text_adventure_button_a() 
  388. 	end 
  389. end 
  390.  
  391. function msn_text_adventure_mouse_move(event, target_handle) 
  392. 	--nav item in megalist... 
  393. 	local new_index = Active_list:get_button_index(target_handle) 
  394. 	if new_index ~= 0 then 
  395. 		-- Set the button as the new selected highlight 
  396. 		Active_list:set_selection(new_index) 
  397. 		Active_list:move_cursor(0, true) 
  398. 	end 
  399. end 
  400.  
  401.