local CELL_STATS_NUM_LINES = 10
local Input_tracker
local Mouse_input_tracker
local Hint_bar
local Cell_stats_doc_handle = -1
local Cell_stats_objects = { }
local Cell_stats_page = 1
local Cell_stats_num_pages = 1
local Num_stat_data = 0
local Cell_stats_data = { }
local Arrow_left
local Arrow_right
local Page_header
function cell_stats_init()
Cell_stats_doc_handle = vint_document_find("cell_stats")
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("nav_left", "cell_stats_nav_left", 50)
Input_tracker:add_input("nav_right", "cell_stats_nav_right", 50)
Input_tracker:add_input("back", "cell_stats_button_b", 50)
Input_tracker:add_input("map", "cell_stats_button_map", 50)
-- unused
Input_tracker:add_input("nav_up", "cell_stats_nav_nothing", 50)
Input_tracker:add_input("nav_down", "cell_stats_nav_nothing", 50)
Input_tracker:add_input("select", "cell_stats_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_cell_title:new("cell_title", 0, Cell_stats_doc_handle)
cell_title_h:set_text("MENU_STATS")
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, Cell_stats_doc_handle)
local value_grp_h = vint_object_find("value_grp", 0, Cell_stats_doc_handle)
for i = 1, CELL_STATS_NUM_LINES do
Cell_stats_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("cell_stats_populate", "cell_stats_populate", 0)
Cell_stats_num_pages = Num_stat_data / CELL_STATS_NUM_LINES
Cell_stats_page = 1
cell_stats_show_page(Cell_stats_page)
-- Add mouse input subscriptions for the PC
if game_get_platform() == "PC" then
Arrow_left = Vdo_base_object:new("arrow_l", 0, Cell_stats_doc_handle)
Arrow_right = Vdo_base_object:new("arrow_r", 0, Cell_stats_doc_handle)
Page_header = Vdo_base_object:new("scroll_bg", 0, Cell_stats_doc_handle)
Hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
Hint_bar:add_mouse_inputs("cell_stats", Mouse_input_tracker)
Mouse_input_tracker:add_mouse_input("mouse_move", "cell_stats_mouse_move", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_down", "cell_stats_mouse_down", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_click", "cell_stats_mouse_click", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_drag", "cell_stats_mouse_drag", 0, Page_header.handle)
Mouse_input_tracker:add_mouse_input("mouse_drag_release", "cell_stats_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_MAIN, cell_stats_unlock_controls)
--glitch
glitch_cell()
end
function cell_stats_cleanup()
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function cell_stats_populate(display_name, has_value, value_str)
Cell_stats_data[Num_stat_data] = { }
Cell_stats_data[Num_stat_data].display_name = display_name
if has_value == 1 then
Cell_stats_data[Num_stat_data].value = value_str
end
Num_stat_data = Num_stat_data + 1
end
function cell_stats_show_page(page_idx)
local stat_index = (page_idx - 1) * CELL_STATS_NUM_LINES
for i = 1, CELL_STATS_NUM_LINES do
if stat_index < Num_stat_data then
vint_set_property(Cell_stats_objects[i].label_h, "visible", true)
vint_set_property(Cell_stats_objects[i].label_h, "text_tag", Cell_stats_data[stat_index].display_name)
--checks if label string is too long and scales
vint_set_property(Cell_stats_objects[i].label_h, "scale", 1,1)
local MAX_WIDTH_LABEL = 555
local text_width_label, text_height_label = element_get_actual_size(Cell_stats_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(Cell_stats_objects[i].label_h, "scale", text_scale_label,1)
end
if Cell_stats_data[stat_index].value ~= nil then
vint_set_property(Cell_stats_objects[i].value_h, "visible", true)
vint_set_property(Cell_stats_objects[i].value_h, "text_tag", Cell_stats_data[stat_index].value)
--checks if value string is too long and scales
vint_set_property(Cell_stats_objects[i].value_h, "scale", 1,1)
local MAX_WIDTH_VALUE = 211
local text_width_value, text_height_value = element_get_actual_size(Cell_stats_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(Cell_stats_objects[i].value_h, "scale", text_scale_value,1)
end
else
vint_set_property(Cell_stats_objects[i].value_h, "visible", false)
end
else
vint_set_property(Cell_stats_objects[i].label_h, "visible", false)
vint_set_property(Cell_stats_objects[i].value_h, "visible", false)
end
stat_index = stat_index + 1
end
--Cell_stats_num_pages = 3
--Sets the text in the scroll bar
local current_page_h = vint_object_find("current_page", 0, Cell_stats_doc_handle)
local total_page_round = ceil(Cell_stats_num_pages)
local insert_values = {[0] = Cell_stats_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 = (((Cell_stats_page / total_page_round) * 629) - ((1 / total_page_round ) * 629)) + ((((Cell_stats_page - 1) / total_page_round) / (total_page_round - 1)) * 629) - 475
local scroll_grp_h = vint_object_find("scroll_grp", 0, Cell_stats_doc_handle)
vint_set_property(scroll_grp_h, "anchor", scroll_pct, 0)
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 / (Cell_stats_num_pages + 1)
--local x = Page_header:get_anchor()
if mouse_diff_x > PAGE_SPACING * 1.0 then
cell_stats_nav_right()
moved = true
elseif mouse_diff_x < PAGE_SPACING * -1.0 then
cell_stats_nav_left()
moved = true
end
if moved == true then
--x = Page_header:get_anchor()
MOUSE_DOWN = pure_mouse_x
end
end
function cell_stats_nav_left(event, acceleration)
if Cell_stats_page > 1 then
Cell_stats_page = Cell_stats_page - 1
cell_stats_show_page(Cell_stats_page)
ui_audio_post_event("UI_Hub_Navigate")
end
end
function cell_stats_nav_right(event, acceleration)
if Cell_stats_page < Cell_stats_num_pages then
Cell_stats_page = Cell_stats_page + 1
cell_stats_show_page(Cell_stats_page)
ui_audio_post_event("UI_Hub_Navigate")
end
end
function cell_stats_nav_nothing(event, accel)
end
function cell_stats_button_map(event, acceleration)
ui_audio_post_event("UI_Hub_Menu_Back")
cell_stats_lock_controls()
--Transition the screen out
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_MAIN, CELL_SCREEN_STATS, cell_stats_exit_to_game)
end
function cell_stats_button_b(event, acceleration)
ui_audio_post_event("UI_Hub_Menu_Back")
cell_stats_lock_controls()
--Transition the screen to extras
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_STATS, cell_stats_exit_to_extras)
end
--Added missing *_unload() function
function cell_stats_unload()
ui_audio_post_event("UI_Hub_Menu_Back")
--Transition the screen to extras
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_STATS, nil)
end
function cell_stats_exit_to_extras()
pop_screen() -- stats
end
function cell_stats_exit_to_game()
pop_screen() -- stats
pop_screen() -- extras
pop_screen() -- main
pop_screen() -- cell frame
end
function cell_stats_lock_controls()
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function cell_stats_unlock_controls()
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
end
end
function cell_stats_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
cell_stats_button_b(event)
end
if target_handle == Arrow_left.handle then
cell_stats_nav_left()
elseif target_handle == Arrow_right.handle then
cell_stats_nav_right()
end
end
function cell_stats_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, Cell_stats_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 cell_stats_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 cell_stats_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 cell_stats_mouse_down(event, target_handle, mouse_x)
if target_handle == Page_header.handle then
MOUSE_DOWN = mouse_x
end
end
function cell_stats_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