local PAUSE_VOICE_TUT_NUM_LINES = 10
local Input_tracker
local Mouse_input_tracker
local Hint_bar
local pause_voice_tut_doc_handle = -1
local pause_voice_tut_objects = { }
local pause_voice_tut_page = 1
local pause_voice_tut_num_pages = 1
local Num_stat_data = 0
local pause_voice_tut_data = { }
local Arrow_left
local Arrow_right
local Page_header
local Screen_width
if vint_is_std_res() then
Screen_width = 750
else
Screen_width = 840
end
function pause_voice_tut_init()
pause_voice_tut_doc_handle = vint_document_find("pause_voice_tut")
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("nav_left", "pause_voice_tut_nav_left", 50)
Input_tracker:add_input("nav_right", "pause_voice_tut_nav_right", 50)
Input_tracker:add_input("back", "pause_voice_tut_button_b", 50)
Input_tracker:add_input("map", "pause_voice_tut_button_map", 50)
-- unused
Input_tracker:add_input("nav_up", "pause_voice_tut_nav_nothing", 50)
Input_tracker:add_input("nav_down", "pause_voice_tut_nav_nothing", 50)
Input_tracker:add_input("select", "pause_voice_tut_nav_nothing", 50)
--hintbar...
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Hint_bar = Vdo_hint_bar:new("hint_bar")
Hint_bar:set_hints(hint_data)
--Set up title
local cell_title_h = Vdo_pause_header:new("cell_title", 0, pause_voice_tut_doc_handle)
cell_title_h:set_text("MENU_VOICE_TUT", Screen_width)
--cell_title_h:set_icon("ui_cell_icon_stats")
--cell_title_h:play_dots_anim()
--add right and left group objects
local label_grp_h = vint_object_find("label_grp", 0, pause_voice_tut_doc_handle)
local value_grp_h = vint_object_find("value_grp", 0, pause_voice_tut_doc_handle)
for i = 1, PAUSE_VOICE_TUT_NUM_LINES do
pause_voice_tut_objects[i] = {
label_h = vint_object_find("label_" .. i, label_grp_h),
value_h = vint_object_find("value_" .. i, value_grp_h),
}
end
-- populate the stats
vint_dataresponder_request("pause_voice_tut_populate", "pause_voice_tut_populate", 0)
pause_voice_tut_num_pages = Num_stat_data / PAUSE_VOICE_TUT_NUM_LINES
pause_voice_tut_page = 1
pause_voice_tut_show_page(pause_voice_tut_page)
-- Add mouse input subscriptions for the PC
if game_get_platform() == "PC" then
Arrow_left = Vdo_base_object:new("arrow_l", 0, pause_voice_tut_doc_handle)
Arrow_right = Vdo_base_object:new("arrow_r", 0, pause_voice_tut_doc_handle)
Page_header = Vdo_base_object:new("scroll_bg", 0, pause_voice_tut_doc_handle)
Hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
Hint_bar:add_mouse_inputs("pause_voice_tut", Mouse_input_tracker)
Mouse_input_tracker:add_mouse_input("mouse_move", "pause_voice_tut_mouse_move", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_down", "pause_voice_tut_mouse_down", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_click", "pause_voice_tut_mouse_click", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_drag", "pause_voice_tut_mouse_drag", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_drag_release", "pause_voice_tut_mouse_drag_release", 0, Page_header.handle)
Mouse_input_tracker:subscribe(false)
end
--Transition the screen in...
--cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_STATS, CELL_SCREEN_EXTRAS, pause_voice_tut_unlock_controls)
--glitch
pause_voice_tut_unlock_controls()
glitch_cell()
end
function pause_voice_tut_cleanup()
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function pause_voice_tut_populate(display_name, has_value, value_str)
pause_voice_tut_data[Num_stat_data] = { }
pause_voice_tut_data[Num_stat_data].display_name = display_name
if has_value == 1 then
pause_voice_tut_data[Num_stat_data].value = value_str
end
Num_stat_data = Num_stat_data + 1
end
function pause_voice_tut_show_page(page_idx)
local stat_index = (page_idx - 1) * PAUSE_VOICE_TUT_NUM_LINES
for i = 1, PAUSE_VOICE_TUT_NUM_LINES do
if stat_index < Num_stat_data then
vint_set_property(pause_voice_tut_objects[i].label_h, "visible", true)
vint_set_property(pause_voice_tut_objects[i].label_h, "text_tag", pause_voice_tut_data[stat_index].display_name)
--checks if label string is too long and scales
vint_set_property(pause_voice_tut_objects[i].label_h, "scale", 1,1)
local MAX_WIDTH_LABEL = 509
local text_width_label, text_height_label = element_get_actual_size(pause_voice_tut_objects[i].label_h)
if text_width_label > MAX_WIDTH_LABEL then
local text_scale_label = MAX_WIDTH_LABEL/text_width_label
vint_set_property(pause_voice_tut_objects[i].label_h, "scale", text_scale_label,1)
end
if pause_voice_tut_data[stat_index].value ~= nil then
vint_set_property(pause_voice_tut_objects[i].value_h, "visible", true)
vint_set_property(pause_voice_tut_objects[i].value_h, "text_tag", pause_voice_tut_data[stat_index].value)
--checks if value string is too long and scales
vint_set_property(pause_voice_tut_objects[i].value_h, "scale", 1,1)
local MAX_WIDTH_VALUE = 408
local text_width_value, text_height_value = element_get_actual_size(pause_voice_tut_objects[i].value_h)
if text_width_value > MAX_WIDTH_VALUE then
local text_scale_value = MAX_WIDTH_VALUE/text_width_value
vint_set_property(pause_voice_tut_objects[i].value_h, "scale", text_scale_value,1)
end
else
vint_set_property(pause_voice_tut_objects[i].value_h, "visible", false)
end
else
vint_set_property(pause_voice_tut_objects[i].label_h, "visible", false)
vint_set_property(pause_voice_tut_objects[i].value_h, "visible", false)
end
stat_index = stat_index + 1
end
--pause_voice_tut_num_pages = 3
--Sets the text in the scroll bar
local current_page_h = vint_object_find("current_page", 0, pause_voice_tut_doc_handle)
local total_page_round = ceil(pause_voice_tut_num_pages)
local insert_values = {[0] = pause_voice_tut_page, [1] = total_page_round}
local stats_string = vint_insert_values_in_string("STATS_PAGE", insert_values)
vint_set_property(current_page_h, "text_tag", stats_string)
vint_set_property(current_page_h, "scale", 1,1)
local max_width = 130
local text_width, text_height = element_get_actual_size(current_page_h)
if text_width > max_width then
local text_scale = max_width/text_width
vint_set_property(current_page_h, "scale", text_scale,1)
end
-----------------------------------------------------------------
--THIS EQUATION IS MAGIC, FOR THE LOVE OF GOD DON'T DELETE IT!
--sets scroll bar in correct spot
--629 is the width of the total bg minus the scroll bar (188)
--The -475 offsets it to the correct spot on the screen
-----------------------------------------------------------------
--local scroll_pct = (((pause_voice_tut_page / total_page_round) * 629) - ((1 / total_page_round ) * 629)) + ((((pause_voice_tut_page - 1) / total_page_round) / (total_page_round - 1)) * 629) - 475
local scroll_pct = (((pause_voice_tut_page / total_page_round) * 629) - ((1 / total_page_round ) * 629)) + ((((pause_voice_tut_page - 1) / total_page_round) / (total_page_round - 1)) * 629) - 495
local scroll_grp_h = vint_object_find("scroll_grp", 0, pause_voice_tut_doc_handle)
vint_set_property(scroll_grp_h, "anchor", scroll_pct, 20)
end
MOUSE_DOWN = 0
local PAGE_SPACING
function cells_stats_adjust_page_position(mouse_diff_x, pure_mouse_x)
local moved = false;
PAGE_SPACING = 629 / (pause_voice_tut_num_pages + 1)
--local x = Page_header:get_anchor()
if mouse_diff_x > PAGE_SPACING * 1.0 then
pause_voice_tut_nav_right()
moved = true
elseif mouse_diff_x < PAGE_SPACING * -1.0 then
pause_voice_tut_nav_left()
moved = true
end
if moved == true then
--x = Page_header:get_anchor()
MOUSE_DOWN = pure_mouse_x
end
end
function pause_voice_tut_nav_left(event, acceleration)
if pause_voice_tut_page > 1 then
pause_voice_tut_page = pause_voice_tut_page - 1
pause_voice_tut_show_page(pause_voice_tut_page)
ui_audio_post_event("UI_Hub_Navigate")
end
end
function pause_voice_tut_nav_right(event, acceleration)
if pause_voice_tut_page < pause_voice_tut_num_pages then
pause_voice_tut_page = pause_voice_tut_page + 1
pause_voice_tut_show_page(pause_voice_tut_page)
ui_audio_post_event("UI_Hub_Navigate")
end
end
function pause_voice_tut_nav_nothing(event, accel)
end
function pause_voice_tut_button_map(event, acceleration)
ui_audio_post_event("UI_Hub_Menu_Back")
pause_voice_tut_lock_controls()
--Transition the screen out
--cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_STATS, pause_voice_tut_exit_to_game)
end
function pause_voice_tut_button_b(event, acceleration)
ui_audio_post_event("UI_Hub_Menu_Back")
pause_voice_tut_lock_controls()
--Transition the screen back
pop_screen()
end
function pause_voice_tut_exit_to_extras()
pop_screen() -- stats
end
function pause_voice_tut_exit_to_game()
pop_screen() -- stats
pop_screen() -- extras
pop_screen() -- main
pop_screen() -- cell frame
end
function pause_voice_tut_lock_controls()
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function pause_voice_tut_unlock_controls()
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
end
end
function pause_voice_tut_mouse_click(event, target_handle)
-- First check if the target_handle is in the hint bar
local hint_index =Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
pause_voice_tut_button_b(event)
end
if target_handle == Arrow_left.handle then
pause_voice_tut_nav_left()
elseif target_handle == Arrow_right.handle then
pause_voice_tut_nav_right()
end
end
function pause_voice_tut_mouse_move(event, target_handle)
-- Reset highlights
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
-- Highlight the page header
local page_text = vint_object_find("current_page", 0, pause_voice_tut_doc_handle)
vint_set_property(page_text, "tint", 0, 0, 0)
-- Highlight the arrows
Arrow_left:set_color(0, 0, 0)
Arrow_right:set_color(0, 0, 0)
if target_handle == Page_header.handle then
vint_set_property(page_text, "tint", COLOR_CELL_MENU_HIGHLIGHT_TEXT.R, COLOR_CELL_MENU_HIGHLIGHT_TEXT.G, COLOR_CELL_MENU_HIGHLIGHT_TEXT.B)
Arrow_left:set_color(COLOR_CELL_MENU_HIGHLIGHT_TEXT)
Arrow_right:set_color(COLOR_CELL_MENU_HIGHLIGHT_TEXT)
vint_set_mouse_cursor("Ui_cursor_hand_open")
else
vint_set_mouse_cursor("")
end
end
function pause_voice_tut_mouse_drag(event, target_handle, mouse_x)
if target_handle == Page_header.handle then
cells_stats_adjust_page_position(mouse_x - MOUSE_DOWN, mouse_x)
vint_set_mouse_cursor("Ui_cursor_hand_closed")
end
end
function pause_voice_tut_mouse_drag_release(event, target_handle, mouse_x, mouse_y, scroll_lines, current_target_handle)
debug_print("vint", "highlighted_handle: " .. var_to_string(current_target_handle) .. "\n")
debug_print("vint", "Page_header.handle: " .. var_to_string(Page_header.handle) .. "\n")
if current_target_handle == Page_header.handle then
vint_set_mouse_cursor("Ui_cursor_hand_open")
else
vint_set_mouse_cursor("")
end
end
function pause_voice_tut_mouse_down(event, target_handle, mouse_x)
if target_handle == Page_header.handle then
MOUSE_DOWN = mouse_x
end
end
function pause_voice_tut_mouse_release(event, target_handle, mouse_x)
if target_handle == Page_header.handle then
MOUSE_DOWN = mouse_x
vint_set_mouse_cursor("Ui_cursor_hand_closed")
end
end