local PM_MENU_DISPLAY_CAL_OPTIONS = 3
local BRIGHTNESS_BASE_TINT = 0.11
local BRIGHTNESS_GAME_VALUE_MIN = 0.5
local BRIGHTNESS_GAME_VALUE_MAX = 1.5
--local HINT_BAR_Y_MAIN = 611
--local HINT_BAR_Y_PAUSE = 652
local Screen_width = 840
local Data = {}
local Anims = {}
local Input_tracker
local Mouse_input_tracker
--local Hint_bar
local Display_doc
Display_list = -1
local Texticles = {}
local Tween_done = true
local GAMMA_ID = 1
local BRIGHTNESS_ID = 2
local GAMMA_OPTION = {
type = TYPE_SLIDER,
label = "MENU_OPTIONS_GAMMA",
min = 0,
max = 100,
step = 10,
current_value = 100,
id = GAMMA_ID,
option_index = 1
}
local BRIGHTNESS_OPTION = {
type = TYPE_SLIDER,
label = "MENU_DISPLAY_BRIGHTNESS",
min = 0,
max = 100,
step = 5,
current_value = 100,
id = BRIGHTNESS_ID,
option_index = 2
}
function pause_options_display_cal_init()
Display_doc = vint_document_find("pause_options_display_cal")
if vint_is_std_res() then
Screen_width = 750
else
Screen_width = 840
end
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "options_display_cal_button_a", 60)
Input_tracker:add_input("back", "options_display_cal_button_b", 60)
if not Start_game_after_display and Join_friend_after_display == -1 then
Input_tracker:add_input("alt_select", "options_display_cal_button_x", 60)
end
Input_tracker:add_input("pause", "options_display_cal_button_start", 60)
Input_tracker:add_input("nav_up", "options_display_cal_nav_up", 60)
Input_tracker:add_input("nav_down", "options_display_cal_nav_down", 60)
Input_tracker:add_input("nav_left", "options_display_cal_nav_left", 60)
Input_tracker:add_input("nav_right", "options_display_cal_nav_right", 60)
Input_tracker:subscribe(false)
local hint_data
if Start_game_after_display or Join_friend_after_display ~= -1 then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_MENU_BUTTON_A, "MAINMENU_CONTINUE"},
}
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"},
}
end
Menu_hint_bar:set_hints(hint_data)
--Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Display_doc)
--Hint_bar:set_hints(hint_data)
--Initialize Header
local ctrl_header_obj = Vdo_pause_header:new("display_header", 0, Display_doc)
ctrl_header_obj:set_text("MENU_DISPLAY_MONITOR_ADJUSTMENT",Screen_width)
Display_list = Vdo_mega_list:new("list", 0, Display_doc, "pause_options_display_cal.lua", "Display_list")
-- Display_list:set_input_tracker(Input_tracker)
Display_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY)
--Get the selection option from when the menu was last loaded
local last_option_selected = menu_common_stack_get_index()
vint_dataresponder_request("pause_menu_options", "options_display_cal_populate", 0, PM_MENU_DISPLAY_CAL_OPTIONS)
local screen_anchor_x = 0
if vint_is_std_res() then
screen_anchor_x = 0
else
screen_anchor_x = 0
end
--adjust hint bar to match other screens
--[[local hint_bar_x, hint_bar_y = Hint_bar:get_anchor()
if In_pause_menu then
Hint_bar:set_anchor(hint_bar_x,HINT_BAR_Y_PAUSE)
else
Hint_bar:set_anchor(hint_bar_x,HINT_BAR_Y_MAIN)
end]]--
local screen_grp_h = vint_object_find("screen_grp", 0, Display_doc)
vint_set_property(screen_grp_h,"anchor",screen_anchor_x,0)
local anim_in_h = vint_object_find("back_in_anim", 0, Display_doc)
lua_play_anim(anim_in_h, 0, Display_doc)
--Store some locals to the pause menu common for screen processing.
menu_common_set_list_style(List, Header_obj, 700)
menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim)
Display_list:draw_items(Data, last_option_selected, Screen_width, 5, LIST_FONT_SCALE, nil, false)
game_peg_load_with_cb("options_display_show_images", 1, "ui_bms_video_calibrate")
options_display_set_display_type()
List:set_visible(false)
Header_obj:set_visible(false)
--Menu_hint_bar:set_visible(false)
-- Add mouse inputs for the PC
if game_get_platform() == "PC" then
Menu_hint_bar:set_highlight(0)
--Hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
Display_list:add_mouse_inputs("pause_options_display_cal", Mouse_input_tracker)
Menu_hint_bar:add_mouse_inputs("pause_options_display_cal", Mouse_input_tracker)
--Hint_bar:add_mouse_inputs("pause_options_display_cal", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
--menu_common_set_mouse_tracker(Mouse_input_tracker)
end
end
function pause_options_display_cal_cleanup()
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
List:enable_toggle_input(false)
game_peg_unload("ui_bms_video_calibrate")
Start_game_after_display = false
--Menu_hint_bar:set_visible(true)
end
function options_display_cal_populate(gamma, brightness)
GAMMA_OPTION.current_value = floor(gamma * 100)
-- special conversion for brightness
brightness = (brightness - BRIGHTNESS_GAME_VALUE_MIN) / (BRIGHTNESS_GAME_VALUE_MAX - BRIGHTNESS_GAME_VALUE_MIN)
if brightness < 0 then
brightness = 0
end
if brightness > 1 then
brightness = 1
end
BRIGHTNESS_OPTION.current_value = floor(brightness * 100)
Data = {}
if not Start_game_after_display and Join_friend_after_display == -1 and game_get_platform() ~= "PC" then
Data[#Data + 1] = GAMMA_OPTION
end
Data[#Data + 1] = BRIGHTNESS_OPTION
end
function options_display_cal_nav_up(event, acceleration)
-- Move highlight up
if Start_game_after_display == false and Join_friend_after_display == -1 then
Display_list:move_cursor(-1)
options_display_set_display_type()
end
end
function options_display_cal_nav_down(event, acceleration)
-- Move highlight down
if Start_game_after_display == false and Join_friend_after_display == -1 then
Display_list:move_cursor(1)
options_display_set_display_type()
end
end
function options_display_cal_nav_left(event, acceleration)
if Display_list:list_is_playing() == false then
-- Move highlight left
Display_list:move_slider(-1)
options_display_cal_update_option_value()
end
end
function options_display_cal_nav_right(event, acceleration)
if Display_list:list_is_playing() == false then
-- Move highlight right
Display_list:move_slider(1)
options_display_cal_update_option_value()
end
end
function options_display_cal_button_a(event, acceleration)
if Display_list:list_is_playing() == false then
if Start_game_after_display then
game_UI_audio_play("UI_Main_Menu_Select")
-- save the gamma
pause_menu_accept_options()
options_display_cal_lock_input(true)
main_menu_new_game()
return
end
if Join_friend_after_display ~= -1 then
game_UI_audio_play("UI_Main_Menu_Select")
-- save the gamma
pause_menu_accept_options()
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.
else
options_display_cal_lock_input(true)
end
game_main_menu_join_friend_in_progress(Join_friend_after_display);
return
end
end
end
function options_display_cal_button_b(event, acceleration)
if Tween_done == true then
--pass off the input to the list
Display_list:button_b()
-- save the gamma
pause_menu_accept_options()
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
local anim_out_h = vint_object_find("slide_out_anim", 0, Display_doc)
lua_play_anim(anim_out_h, 0, Display_doc)
--Remove current menu from the stack
menu_common_stack_remove()
if Join_friend_after_display ~= -1 then
menu_common_transition_pop(2)
else
menu_common_transition_pop(1)
end
end
end
function options_display_cal_button_x(event, acceleration)
dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_display_cal_revert", true, true,1)
end
function options_display_cal_revert(result, action)
if result == 0 then
pause_menu_restore_defaults(PM_MENU_DISPLAY_CAL_OPTIONS)
vint_dataresponder_request("pause_menu_options", "options_display_cal_populate", 0, PM_MENU_DISPLAY_CAL_OPTIONS)
local current_idx = Display_list:get_selection()
Display_list:draw_items(Data, current_idx, Screen_width, 5, LIST_FONT_SCALE, nil, false)
update_brightness()
end
end
function options_display_cal_update_option_value()
local current_id = Display_list:get_id()
local menu_item = Display_list:get_data_from_id(current_id)
local bool_val = true
if menu_item.current_value == 1 then
bool_val = false
end
-- Convert the value to [0.0 - 1.0]
local converted_float = menu_item.current_value
if converted_float ~= 0 then
converted_float = menu_item.current_value / 100
end
-- special conversion for brightness, also need to tint the box
if current_id == BRIGHTNESS_ID then
local brightness_img_h = vint_object_find("brightness_image",0,Display_doc)
local new_tint = BRIGHTNESS_BASE_TINT * converted_float
vint_set_property(brightness_img_h,"tint", new_tint, new_tint, new_tint)
-- convert to value used by game
converted_float = ((BRIGHTNESS_GAME_VALUE_MAX - BRIGHTNESS_GAME_VALUE_MIN) * converted_float) + BRIGHTNESS_GAME_VALUE_MIN
end
pause_menu_update_option(PM_MENU_DISPLAY_CAL_OPTIONS, menu_item.option_index, bool_val, converted_float)
end
function update_brightness()
-- Convert the value to [0.0 - 1.0]
local brightness_item = Display_list:get_data_from_id(BRIGHTNESS_ID)
local converted_float = brightness_item.current_value
if converted_float ~= 0 then
converted_float = converted_float / 100
end
local brightness_img_h = vint_object_find("brightness_image",0,Display_doc)
local new_tint = BRIGHTNESS_BASE_TINT * converted_float
vint_set_property(brightness_img_h,"tint", new_tint, new_tint, new_tint)
end
function options_display_cal_button_start(event, acceleration)
if In_pause_menu and Tween_done == true then
-- we still want to save the options?
pause_menu_accept_options()
local screen_grp_h = vint_object_find("screen_grp", 0, Display_doc)
local screen_x,screen_y = vint_get_property(screen_grp_h, "anchor")
local screen_out_anim_h = vint_object_find("screen_out_anim", 0, Display_doc)
lua_play_anim(screen_out_anim_h, 0, Display_doc)
menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim, pause_menu_top_anim_in_done)
bg_saints_slide_out()
-- stack is part of common, which is getting popped, so we don't update it.
menu_common_transition_pop(5) -- options_display_cal, options_display, options_menu, pause_menu_top, menu_common
end
end
function options_display_show_images()
local image = vint_object_find("image_1")
vint_set_property(image,"visible",true)
image = vint_object_find("image_2")
vint_set_property(image,"visible",true)
end
function options_display_set_display_type()
local curr_id = Display_list:get_id()
local brightness_grp_h = vint_object_find("brightness_grp",0,Display_doc)
local image_grp_h = vint_object_find("image_grp",0,Display_doc)
local text_h = vint_object_find("brightness_text",0,Display_doc)
if curr_id == GAMMA_ID then
vint_set_property(brightness_grp_h,"visible",false)
vint_set_property(image_grp_h,"visible",true)
if Start_game_after_display or Join_friend_after_display ~= -1 then
vint_set_property(text_h,"text_tag","MENU_DISPLAY_CALIBRATION_DESCRIPTION_ONE_TIME")
else
vint_set_property(text_h,"text_tag","MENU_DISPLAY_CALIBRATION_DESCRIPTION")
end
else
vint_set_property(brightness_grp_h,"visible",true)
vint_set_property(image_grp_h,"visible",false)
if Start_game_after_display or Join_friend_after_display ~= -1 then
vint_set_property(text_h,"text_tag","MENU_BRIGHTNESS_CALIBRATION_DESCRIPTION_ONE_TIME")
else
vint_set_property(text_h,"text_tag","MENU_BRIGHTNESS_CALIBRATION_DESCRIPTION")
end
-- Convert the value to [0.0 - 1.0]
local converted_float = Display_list:get_data_from_id(BRIGHTNESS_ID).current_value
if converted_float ~= 0 then
converted_float = Display_list:get_data_from_id(BRIGHTNESS_ID).current_value / 100
end
local brightness_img_h = vint_object_find("brightness_image",0,Display_doc)
local new_tint = BRIGHTNESS_BASE_TINT * converted_float
vint_set_property(brightness_img_h,"tint", new_tint, new_tint, new_tint)
end
end
-- Mouse inputs
function pause_options_display_cal_mouse_click(event, target_handle, mouse_x, mouse_y)
if Display_list:list_is_playing() == false then
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
--local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
options_display_cal_button_b()
end
if hint_index == 2 then
if Start_game_after_display or Join_friend_after_display ~= -1 then
options_display_cal_button_a()
else
options_display_cal_button_x()
end
end
local new_index = Display_list:get_button_index(target_handle)
--[[if new_index ~= 0 then
Display_list:set_selection(new_index)
options_display_cal_button_a()
end]]
if Display_list:is_left_arrow(target_handle) then
Display_list:move_slider(-1)
options_display_cal_update_option_value()
elseif Display_list:is_right_arrow(target_handle) then
Display_list:move_slider(1)
options_display_cal_update_option_value()
end
if Display_list:is_slider(target_handle) then
Display_list:move_slider(0, mouse_x)
options_display_cal_update_option_value()
end
end
end
function pause_options_display_cal_mouse_move(event, target_handle)
if Display_list:list_is_playing() == false then
Menu_hint_bar:set_highlight(0)
--Hint_bar:set_highlight(0)
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Menu_hint_bar:set_highlight(hint_index)
end
--local hint_index = Hint_bar:get_hint_index(target_handle)
--[[if hint_index ~= 0 then
Hint_bar:set_highlight(hint_index)
end]]
local new_index = Display_list:get_button_index(target_handle)
if new_index ~= 0 then
Display_list:set_selection(new_index)
Display_list:move_cursor(0, true)
options_display_set_display_type()
end
end
end
function pause_options_display_cal_mouse_drag(event, target_handle, mouse_x, mouse_y)
if Display_list:list_is_playing() == false then
if Display_list:is_slider(target_handle) then
Display_list:move_slider(0, mouse_x)
options_display_cal_update_option_value()
end
end
end
function pause_options_display_cal_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
end
function options_display_cal_lock_input(locked)
-- Nuke all button subscriptions
Input_tracker:subscribe(not locked)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(not locked)
end
end