./pause_options_display_cal.lua

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