./pause_options_display_cal.lua

  1. local PM_MENU_DISPLAY_CAL_OPTIONS		= 3 
  2.  
  3. local BRIGHTNESS_BASE_TINT					= 0.05 
  4.  
  5. local BRIGHTNESS_GAME_VALUE_MIN			= 0.5 
  6. local BRIGHTNESS_GAME_VALUE_MAX			= 1.5 
  7.  
  8. local Data = {} 
  9.  
  10. local Anims = {} 
  11.  
  12. local Input_tracker 
  13. local Mouse_input_tracker 
  14.  
  15. local Hint_bar 
  16.  
  17. local Display_doc 
  18. local Display_list = -1 
  19. local Texticles = {} 
  20.  
  21. local Tween_done = true 
  22.  
  23. local GAMMA_ID									= 1 
  24. local BRIGHTNESS_ID							= 2 
  25. local GAMMA_OPTION = { 
  26. 	type = TYPE_SLIDER, 
  27. 	label = "MENU_OPTIONS_GAMMA", 
  28. 	min = 0, 
  29. 	max = 100, 
  30. 	step = 10, 
  31. 	current_value = 100, 
  32. 	id = GAMMA_ID, 
  33. 	option_index = 1 
  34. } 
  35. local BRIGHTNESS_OPTION = { 
  36. 	type = TYPE_SLIDER, 
  37. 	label = "MENU_DISPLAY_BRIGHTNESS", 
  38. 	min = 0, 
  39. 	max = 100, 
  40. 	step = 5, 
  41. 	current_value = 100, 
  42. 	id = BRIGHTNESS_ID, 
  43. 	option_index = 2 
  44. } 
  45.  
  46. function pause_options_display_cal_init() 
  47. 	Display_doc = vint_document_find("pause_options_display_cal") 
  48. 	 
  49. 	-- Subscribe to the button presses we need 
  50. 	Input_tracker = Vdo_input_tracker:new() 
  51. 	Input_tracker:add_input("select", "options_display_cal_button_a", 60) 
  52. 	Input_tracker:add_input("back", "options_display_cal_button_b", 60) 
  53. 	if not Start_game_after_display and Join_friend_after_display == -1 then 
  54. 		Input_tracker:add_input("alt_select", "options_display_cal_button_x", 60) 
  55. 	end 
  56. 	Input_tracker:add_input("pause", "options_display_cal_button_start", 60) 
  57. 	Input_tracker:add_input("nav_up", "options_display_cal_nav_up", 60) 
  58. 	Input_tracker:add_input("nav_down", "options_display_cal_nav_down", 60) 
  59. 	Input_tracker:add_input("nav_left", "options_display_cal_nav_left", 60) 
  60. 	Input_tracker:add_input("nav_right", "options_display_cal_nav_right", 60) 
  61. 	Input_tracker:subscribe(false) 
  62.  
  63. 	local hint_data 
  64. 	if Start_game_after_display or Join_friend_after_display ~= -1 then 
  65. 		hint_data = { 
  66. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  67. 			{CTRL_MENU_BUTTON_A, "MAINMENU_CONTINUE"}, 
  68. 		} 
  69. 	else 
  70. 		hint_data = { 
  71. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  72. 			{CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"}, 
  73. 		} 
  74. 	end 
  75. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Display_doc) 
  76. 	Hint_bar:set_hints(hint_data) 	 
  77. 	 
  78. 	--Initialize Header 
  79. 	local ctrl_header_obj = Vdo_pause_header:new("display_header", 0, Display_doc) 
  80. 	ctrl_header_obj:set_text("MENU_DISPLAY_MONITOR_ADJUSTMENT",690) 
  81.  
  82. 	Display_list = Vdo_mega_list:new("list", 0, Display_doc) 
  83. --	Display_list:set_input_tracker(Input_tracker) 
  84. 	Display_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY) 
  85. 	 
  86. 	--Get the selection option from when the menu was last loaded 
  87. 	local last_option_selected = menu_common_stack_get_index() 
  88. 	 
  89. 	vint_dataresponder_request("pause_menu_options", "options_display_cal_populate", 0, PM_MENU_DISPLAY_CAL_OPTIONS)	 
  90. 	 
  91. 	local screen_anchor_x = 0 
  92. 	if In_pause_menu then 
  93. 		if vint_is_std_res() then 
  94. 			screen_anchor_x = -144 
  95. 		else 
  96. 			screen_anchor_x = -190 
  97. 		end 
  98. 	else	 
  99. 		if vint_is_std_res() then 
  100. 			screen_anchor_x = -106 
  101. 		end 
  102. 	end 
  103. 	 
  104. 	local screen_grp_h = vint_object_find("screen_grp", 0, Display_doc) 
  105. 	vint_set_property(screen_grp_h,"anchor",screen_anchor_x,0) 
  106. 	 
  107. 	local anim_in_h = vint_object_find("back_in_anim", 0, Display_doc) 
  108. 	lua_play_anim(anim_in_h, 0, Display_doc) 
  109. 	 
  110. 	--Store some locals to the pause menu common for screen processing. 
  111. 	menu_common_set_list_style(List, Header_obj, 700) 
  112. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  113. 	 
  114. 	Display_list:draw_items(Data, last_option_selected, 700, 5, .9) 
  115. 	 
  116. 	game_peg_load_with_cb("options_display_show_images", 1, "ui_bms_video_calibrate") 
  117. 	 
  118. 	options_display_set_display_type() 
  119. 	 
  120. 	List:set_visible(false) 
  121. 	Header_obj:set_visible(false) 
  122. 	Menu_hint_bar:set_visible(false) 
  123. 	 
  124. 	-- Add mouse inputs for the PC 
  125. 	if game_get_platform() == "PC" then 
  126. 		Hint_bar:set_highlight(0) 
  127. 		 
  128. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  129. 		Display_list:add_mouse_inputs("options_display_cal", Mouse_input_tracker) 
  130. 		Hint_bar:add_mouse_inputs("options_display_cal", Mouse_input_tracker) 
  131. 		Mouse_input_tracker:subscribe(true) 
  132. 		 
  133. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  134. 	end 
  135. end 
  136.  
  137. function pause_options_display_cal_cleanup() 
  138. 	-- Nuke all button subscriptions 
  139. 	Input_tracker:subscribe(false) 
  140. 	if Mouse_input_tracker ~= nil then 
  141. 		Mouse_input_tracker:subscribe(false) 
  142. 	end 
  143. 	List:enable_toggle_input(false) 
  144. 	game_peg_unload("ui_bms_video_calibrate") 
  145. 	 
  146. 	Start_game_after_display = false 
  147. 	 
  148. 	Menu_hint_bar:set_visible(true) 
  149. 	 
  150. end 
  151.  
  152. function options_display_cal_populate(gamma, brightness) 
  153.  
  154. 	GAMMA_OPTION.current_value = floor(gamma * 100) 
  155. 	 
  156. 	-- special conversion for brightness	 
  157. 	brightness = (brightness - BRIGHTNESS_GAME_VALUE_MIN) / (BRIGHTNESS_GAME_VALUE_MAX - BRIGHTNESS_GAME_VALUE_MIN) 
  158. 	if brightness < 0 then 
  159. 		brightness = 0 
  160. 	end 
  161. 	if brightness > 1 then 
  162. 		brightness = 1 
  163. 	end 
  164. 	 
  165. 	BRIGHTNESS_OPTION.current_value = floor(brightness * 100) 
  166. 	 
  167. 	Data = {} 
  168. 	if not Start_game_after_display and Join_friend_after_display == -1 and game_get_platform() ~= "PC" then 
  169. 		Data[#Data + 1] = GAMMA_OPTION 
  170. 	end 
  171. 	Data[#Data + 1] = BRIGHTNESS_OPTION 
  172. end 
  173.  
  174. function options_display_cal_nav_up(event, acceleration) 
  175. 	-- Move highlight up 
  176. 	if Start_game_after_display == false and Join_friend_after_display == -1 then 
  177. 		Display_list:move_cursor(-1) 
  178. 		options_display_set_display_type() 
  179. 	end 
  180. end 
  181.  
  182. function options_display_cal_nav_down(event, acceleration) 
  183. 	-- Move highlight down 
  184. 	if Start_game_after_display == false and Join_friend_after_display == -1 then 
  185. 		Display_list:move_cursor(1) 
  186. 		options_display_set_display_type() 
  187. 	end 
  188. end 
  189.  
  190. function options_display_cal_nav_left(event, acceleration) 
  191. 	-- Move highlight left 
  192. 	Display_list:move_slider(-1) 
  193. 	options_display_cal_update_option_value() 
  194. end 
  195.  
  196. function options_display_cal_nav_right(event, acceleration) 
  197. 	-- Move highlight right 
  198. 	Display_list:move_slider(1) 
  199. 	options_display_cal_update_option_value() 
  200. end 
  201.  
  202. function options_display_cal_button_a(event, acceleration) 
  203. 	if Start_game_after_display then 
  204. 		game_UI_audio_play("UI_Main_Menu_Select") 
  205. 		-- save the gamma 
  206. 		pause_menu_accept_options() 
  207. 		options_display_cal_lock_input(true) 
  208. 		main_menu_new_game() 
  209. 		return 
  210. 	end 
  211. 	 
  212. 	if Join_friend_after_display ~= -1 then 
  213. 		game_UI_audio_play("UI_Main_Menu_Select") 
  214. 		-- save the gamma 
  215. 		pause_menu_accept_options() 
  216. 		options_display_cal_lock_input(true) 
  217. 		game_main_menu_join_friend_in_progress(Join_friend_after_display); 
  218. 		return 
  219. 	end 
  220. end 
  221.  
  222. function options_display_cal_button_b(event, acceleration) 
  223. 	if Tween_done == true then 
  224.  
  225. 		--pass off the input to the list 
  226. 		Display_list:button_b() 
  227. 		-- save the gamma 
  228. 		pause_menu_accept_options()	 
  229. 		 
  230. 		Input_tracker:subscribe(false) 
  231. 		if Mouse_input_tracker ~= nil then 
  232. 			Mouse_input_tracker:subscribe(false) 
  233. 		end 
  234. 		 
  235. 		local anim_out_h = vint_object_find("slide_out_anim", 0, Display_doc) 
  236. 		lua_play_anim(anim_out_h, 0, Display_doc) 
  237. 		--Remove current menu from the stack 
  238. 		menu_common_stack_remove() 
  239. 		if Join_friend_after_display ~= -1 then 
  240. 			menu_common_transition_pop(2) 
  241. 		else 
  242. 			menu_common_transition_pop(1) 
  243. 		end 
  244. 		 
  245. 	end 
  246. end 
  247.  
  248. function options_display_cal_button_x(event, acceleration) 
  249. 	dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_display_cal_revert", true, true,1) 
  250. end 
  251.  
  252. function options_display_cal_revert(result, action) 
  253. 	if result == 0 then 
  254. 		pause_menu_restore_defaults(PM_MENU_DISPLAY_CAL_OPTIONS) 
  255. 		vint_dataresponder_request("pause_menu_options", "options_display_cal_populate", 0, PM_MENU_DISPLAY_CAL_OPTIONS) 
  256. 		local current_idx = 	Display_list:get_selection() 
  257. 		Display_list:draw_items(Data, current_idx, 700, 5, .9) 
  258. 		update_brightness() 
  259. 	end 
  260. end 
  261.  
  262. function options_display_cal_update_option_value() 
  263. 	local current_id = Display_list:get_id() 
  264. 	local menu_item = Display_list:get_data_from_id(current_id) 
  265. 	 
  266. 	local bool_val = true 
  267. 	if menu_item.current_value == 1 then 
  268. 		bool_val = false 
  269. 	end 
  270. 	 
  271. 	-- Convert the value to [0.0 - 1.0] 
  272. 	local converted_float = menu_item.current_value 
  273. 	if converted_float ~= 0 then 
  274. 		converted_float = menu_item.current_value / 100 
  275. 	end 
  276. 	 
  277. 	-- special conversion for brightness, also need to tint the box 
  278. 	if current_id == BRIGHTNESS_ID then 
  279. 		local brightness_img_h = vint_object_find("brightness_image",0,Display_doc) 
  280. 		local new_tint = BRIGHTNESS_BASE_TINT * converted_float 
  281. 		vint_set_property(brightness_img_h,"tint", new_tint, new_tint, new_tint)					 
  282. 	 
  283. 		-- convert to value used by game 
  284. 		converted_float = ((BRIGHTNESS_GAME_VALUE_MAX - BRIGHTNESS_GAME_VALUE_MIN) * converted_float) + BRIGHTNESS_GAME_VALUE_MIN 
  285. 	end 
  286. 	 
  287. 	pause_menu_update_option(PM_MENU_DISPLAY_CAL_OPTIONS, menu_item.option_index, bool_val, converted_float) 
  288. end 
  289.  
  290. function update_brightness() 
  291.  
  292. 	-- Convert the value to [0.0 - 1.0] 
  293. 	local brightness_item = Display_list:get_data_from_id(BRIGHTNESS_ID) 
  294. 	local converted_float = brightness_item.current_value 
  295. 	if converted_float ~= 0 then 
  296. 		converted_float = converted_float / 100 
  297. 	end 
  298.  
  299. 	local brightness_img_h = vint_object_find("brightness_image",0,Display_doc) 
  300. 	local new_tint = BRIGHTNESS_BASE_TINT * converted_float 
  301. 	vint_set_property(brightness_img_h,"tint", new_tint, new_tint, new_tint) 
  302.  
  303. end 
  304.  
  305. function options_display_cal_button_start(event, acceleration) 
  306. 	if In_pause_menu and Tween_done == true then 
  307. 		-- we still want to save the options? 
  308. 		pause_menu_accept_options() 
  309. 		 
  310. 		local screen_grp_h = vint_object_find("screen_grp", 0, Display_doc) 
  311. 		local screen_x,screen_y = vint_get_property(screen_grp_h, "anchor") 
  312. 	 
  313. 		local screen_out_anim_h = vint_object_find("screen_out_anim", 0, Display_doc) 
  314. 		lua_play_anim(screen_out_anim_h, 0, Display_doc) 
  315. 		 
  316. 		menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim, pause_menu_top_anim_in_done) 
  317.  
  318. 		bg_saints_slide_out() 
  319. 		-- stack is part of common, which is getting popped, so we don't update it. 
  320. 		menu_common_transition_pop(5)	-- options_display_cal, options_display, options_menu, pause_menu_top, menu_common 
  321. 	end 
  322. end 
  323.  
  324. function options_display_show_images() 
  325. 	local image = vint_object_find("image_1") 
  326. 	vint_set_property(image,"visible",true) 
  327. 	image = vint_object_find("image_2") 
  328. 	vint_set_property(image,"visible",true) 
  329. end 
  330.  
  331. function options_display_set_display_type() 
  332. 	local curr_id = Display_list:get_id() 
  333. 	local brightness_grp_h = vint_object_find("brightness_grp",0,Display_doc) 
  334. 	local text_h = vint_object_find("brightness_text",0,Display_doc) 
  335. 	if curr_id == GAMMA_ID then 
  336. 		vint_set_property(brightness_grp_h,"visible",false) 
  337. 		if Start_game_after_display or Join_friend_after_display ~= -1 then 
  338. 			vint_set_property(text_h,"text_tag","MENU_DISPLAY_CALIBRATION_DESCRIPTION_ONE_TIME") 
  339. 		else 
  340. 			vint_set_property(text_h,"text_tag","MENU_DISPLAY_CALIBRATION_DESCRIPTION") 
  341. 		end 
  342. 	else 
  343. 		vint_set_property(brightness_grp_h,"visible",true) 
  344. 		if Start_game_after_display or Join_friend_after_display ~= -1 then 
  345. 			vint_set_property(text_h,"text_tag","MENU_BRIGHTNESS_CALIBRATION_DESCRIPTION_ONE_TIME") 
  346. 		else 
  347. 			vint_set_property(text_h,"text_tag","MENU_BRIGHTNESS_CALIBRATION_DESCRIPTION") 
  348. 		end 
  349. 		 
  350. 		-- Convert the value to [0.0 - 1.0] 
  351. 		local converted_float = Display_list:get_data_from_id(BRIGHTNESS_ID).current_value 
  352. 		if converted_float ~= 0 then 
  353. 			converted_float = Display_list:get_data_from_id(BRIGHTNESS_ID).current_value / 100 
  354. 		end 
  355. 		 
  356. 		local brightness_img_h = vint_object_find("brightness_image",0,Display_doc) 
  357. 		local new_tint = BRIGHTNESS_BASE_TINT * converted_float 
  358. 		vint_set_property(brightness_img_h,"tint", new_tint, new_tint, new_tint)				 
  359. 	end 
  360. end 
  361.  
  362. -- Mouse inputs 
  363. function options_display_cal_mouse_click(event, target_handle, mouse_x, mouse_y) 
  364. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  365. 	if hint_index == 1 then 
  366. 		options_display_cal_button_b() 
  367. 	end 
  368. 	 
  369. 	if hint_index == 2 then 
  370. 		if Start_game_after_display or Join_friend_after_display ~= -1 then 
  371. 			options_display_cal_button_a() 
  372. 		else 
  373. 			options_display_cal_button_x() 
  374. 		end 
  375. 	end 
  376. 	 
  377. 	local new_index = Display_list:get_button_index(target_handle) 
  378. 	--[[if new_index ~= 0 then 
  379. 		Display_list:set_selection(new_index) 
  380. 		options_display_cal_button_a() 
  381. 	end]] 
  382. 	 
  383. 	if Display_list:is_left_arrow(target_handle) then 
  384. 		Display_list:move_slider(-1) 
  385. 		options_display_cal_update_option_value() 
  386. 	elseif Display_list:is_right_arrow(target_handle) then 
  387. 		Display_list:move_slider(1) 
  388. 		options_display_cal_update_option_value() 
  389. 	end 
  390. 	if Display_list:is_slider(target_handle) then 
  391. 		Display_list:move_slider(0, mouse_x) 
  392. 		options_display_cal_update_option_value() 
  393. 	end 
  394. end 
  395.  
  396. function options_display_cal_mouse_move(event, target_handle) 
  397. 	Hint_bar:set_highlight(0) 
  398. 	 
  399. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  400. 	if hint_index ~= 0 then 
  401. 		Hint_bar:set_highlight(hint_index) 
  402. 	end 
  403. 	 
  404. 	local new_index = Display_list:get_button_index(target_handle) 
  405. 	if new_index ~= 0 then 
  406. 		Display_list:set_selection(new_index) 
  407. 		Display_list:move_cursor(0, true) 
  408. 		options_display_set_display_type() 
  409. 	end 
  410. end 
  411.  
  412. function options_display_cal_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  413. 	if Display_list:is_slider(target_handle) then 
  414. 		Display_list:move_slider(0, mouse_x) 
  415. 		options_display_cal_update_option_value() 
  416. 	end 
  417. end 
  418.  
  419. function options_display_cal_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  420. end 
  421.  
  422. function options_display_cal_lock_input(locked) 
  423. 		-- Nuke all button subscriptions 
  424. 	Input_tracker:subscribe(not locked) 
  425. 	if Mouse_input_tracker ~= nil then 
  426. 		Mouse_input_tracker:subscribe(not locked) 
  427. 	end 
  428. end