local PM_MENU_DISPLAY_CAL_OPTIONS = 3
local BRIGHTNESS_BASE_TINT = 0.05
local BRIGHTNESS_GAME_VALUE_MIN = 0.5
local BRIGHTNESS_GAME_VALUE_MAX = 1.5
local Data = {}
local Anims = {}
local Input_tracker
local Mouse_input_tracker
local Hint_bar
local Display_doc
local 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")
-- 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
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",690)
Display_list = Vdo_mega_list:new("list", 0, Display_doc)
-- 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 In_pause_menu then
if vint_is_std_res() then
screen_anchor_x = -144
else
screen_anchor_x = -190
end
else
if vint_is_std_res() then
screen_anchor_x = -106
end
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, 700, 5, .9)
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
Hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
Display_list:add_mouse_inputs("options_display_cal", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("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)
-- Move highlight left
Display_list:move_slider(-1)
options_display_cal_update_option_value()
end
function options_display_cal_nav_right(event, acceleration)
-- Move highlight right
Display_list:move_slider(1)
options_display_cal_update_option_value()
end
function options_display_cal_button_a(event, acceleration)
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()
options_display_cal_lock_input(true)
game_main_menu_join_friend_in_progress(Join_friend_after_display);
return
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, 700, 5, .9)
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 text_h = vint_object_find("brightness_text",0,Display_doc)
if curr_id == GAMMA_ID then
vint_set_property(brightness_grp_h,"visible",false)
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)
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 options_display_cal_mouse_click(event, target_handle, mouse_x, mouse_y)
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
function options_display_cal_mouse_move(event, target_handle)
Hint_bar:set_highlight(0)
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
function options_display_cal_mouse_drag(event, target_handle, mouse_x, mouse_y)
if Display_list:is_slider(target_handle) then
Display_list:move_slider(0, mouse_x)
options_display_cal_update_option_value()
end
end
function 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