local Data = { }
Num_items = 0
local Input_tracker
local Mouse_input_tracker
local Hint_bar
local Call_bar
local Call_text
local Mission_in_progress = false
local MOUSE_INVALID_HANDLE = -1
local List = nil
local Call_grp
local Cell_missions_handle = -1
local Mouse_area_h = -1
function cell_missions_init()
Cell_missions_handle = vint_document_find("cell_missions")
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("nav_up", "cell_missions_nav_up", 50)
Input_tracker:add_input("nav_down", "cell_missions_nav_down", 50)
Input_tracker:add_input("back", "cell_missions_button_b", 50)
Input_tracker:add_input("select", "cell_missions_button_a", 50)
Input_tracker:add_input("map", "cell_missions_button_map", 50)
-- This needs to be hidden when in a mission and no missions are available
Call_grp = Vdo_base_object:new("call_grp")
local title = Vdo_base_object:new("title")
title:set_text("MENU_MISSIONS_TITLE")
Call_text = Vdo_base_object:new("call_txt")
Call_text:set_text("CELL_OPTION_CALL")
Call_text:set_color(0, 0, 0)
Call_bar = Vdo_base_object:new("call_img")
local in_progress_txt = Vdo_base_object:new("in_progress_txt", 0, Cell_missions_handle)
in_progress_txt:set_visible(false)
local current_mission_txt = Vdo_base_object:new("current_mission_txt", 0, Cell_missions_handle)
current_mission_txt:set_visible(false)
current_mission_txt:set_text("MISSIONS_CURRENT")
vint_dataresponder_request("cell_missions_list_items_dr", "cell_missions_add_menu_items", 0)
List = Vdo_cell_missions_list:new("list_missions")
-- Draw list or handle mission in progress text
cell_missions_update()
local hint_btn = Vdo_hint_button:new("btn_a", 0, Cell_missions_handle)
hint_btn:set_button(CTRL_MENU_BUTTON_A)
--Make sure our cellphone frame is in view, sometimes we could come straight into this menu...
cell_show_frame()
-- Add mouse inputs for the PC
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
if Num_items > 0 and Mission_in_progress == false then
List:add_mouse_inputs("cell_missions", Mouse_input_tracker)
Mouse_area_h = vint_object_find("missions_mouse_area_img", 0, Cell_missions_handle)
Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_missions_mouse_scroll", 50, Mouse_area_h)
Mouse_input_tracker:add_mouse_input("mouse_move", "cell_missions_mouse_scroll", 50, List.scrollbar.tab.handle)
Mouse_input_tracker:add_mouse_input("mouse_click", "cell_missions_mouse_scroll", 50, List.scrollbar.tab.handle)
Mouse_input_tracker:add_mouse_input("mouse_drag", "cell_missions_mouse_drag", 50, List.scrollbar.tab.handle)
Mouse_input_tracker:add_mouse_input("mouse_drag_release", "cell_missions_mouse_drag_release", 50, List.scrollbar.tab.handle)
vint_set_property(List.scrollbar.tab.handle, "mouse_depth", -5001)
end
Call_grp:set_visible(false)
-- Setup Button Hints
Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Cell_missions_handle)
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Hint_bar:set_hints(hint_data)
Hint_bar:set_visible(true)
Hint_bar:set_highlight(0)
Hint_bar:add_mouse_inputs("cell_missions", Mouse_input_tracker)
end
if Missions_from_menu then
--Transition the screen in...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MISSIONS, CELL_SCREEN_MAIN, cell_missions_unlock_controls)
else
--Transition the screen in...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MISSIONS, CELL_SCREEN_NONE, cell_missions_unlock_controls)
end
end
function cell_missions_cleanup()
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function cell_missions_add_menu_items(handle, mission_name, display_name, contact_name, contact_image, is_new, in_progress)
Num_items = Num_items + 1
Data[Num_items] = { handle = handle, mission_name = mission_name, display_name = display_name, contact_name = contact_name, contact_image = contact_image, is_new = is_new }
Mission_in_progress = in_progress
end
function cell_missions_update()
-- Check if we're in a mission
if Mission_in_progress then
-- Mission is in progress so hide everything except the in progress message
local contact_grp = Vdo_base_object:new("contact_grp", 0, Cell_missions_handle)
contact_grp:set_visible(false)
local current_mission_txt = Vdo_base_object:new("current_mission_txt", 0, Cell_missions_handle)
current_mission_txt:set_text("MISSIONS_CURRENT")
current_mission_txt:set_visible(true)
local in_progress_txt = Vdo_base_object:new("in_progress_txt", 0, Cell_missions_handle)
in_progress_txt:set_text(Data[1].display_name)
in_progress_txt:set_visible(true)
--Safe to show mission text...
vint_set_property(vint_object_find("missions_grp"), "visible", true)
else
if Num_items > 0 then
List:draw_items(Data, 1, 4)
--Safe to show missions...
vint_set_property(vint_object_find("missions_grp"), "visible", true)
end
end
end
function cell_missions_nav_up(event, acceleration)
if Num_items > 0 then
List:move_cursor(-1)
if Num_items > 1 then
game_UI_audio_play("UI_Main_Menu_Nav_Down")
end
end
end
function cell_missions_nav_down(event, acceleration)
if Num_items > 0 then
List:move_cursor(1)
if Num_items > 1 then
game_UI_audio_play("UI_Main_Menu_Nav_Down")
end
end
end
function cell_missions_button_map(event, acceleration)
cell_missions_lock_controls()
vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)
game_UI_audio_play("UI_Cell_Close")
--Transition the screen in...
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MISSIONS, cell_missions_exit_to_game)
end
function cell_missions_button_b(event, acceleration)
cell_missions_lock_controls()
game_UI_audio_play("UI_Cell_Nav_Back")
--Transition the screen in...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_MISSIONS, cell_missions_exit_to_main)
end
function cell_missions_button_a(event, acceleration)
if Num_items > 0 then
debug_print("vint", "List: " .. var_to_string(List) .. "\n")
debug_print("vint", "Data[List.current_idx]: " .. var_to_string(Data[List.current_idx]) .. "\n")
debug_print("vint", "List.current_idx: " .. var_to_string(List.current_idx) .. "\n")
if List ~= nil and Data[List.current_idx] ~= nil then
cell_missions_lock_controls()
vint_dataresponder_post("cell_missions_list_items_dr", "Choose", Data[List.current_idx].mission_name)
game_UI_audio_play("UI_Main_Menu_Select")
--Exit phone...
vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)
game_UI_audio_play("UI_Cell_Close")
--Transition the screen in...
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MISSIONS, cell_missions_exit_to_game)
end
end
end
function cell_missions_exit_to_main()
pop_screen()
end
function cell_missions_exit_to_game()
pop_screen() --mission
pop_screen() --main menu
pop_screen() --cellphone frame
end
-------------------------------------------------------------------------------
-- Controls Unlock
--
function cell_missions_unlock_controls()
if Num_items == 0 then
--No items, don't unlock anything and exit early
cell_missions_lock_controls()
thread_new("cell_missions_exit_early")
return
end
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
end
end
function cell_missions_exit_early()
--Wait a frame...
thread_yield()
--Transition the screen out to main...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_MISSIONS, cell_missions_exit_to_main)
end
-------------------------------------------------------------------------------
-- Controls Lock
--
function cell_missions_lock_controls()
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function cell_missions_mouse_click(event, target_handle)
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
cell_missions_button_b()
end
if Num_items > 0 and Mission_in_progress == false then
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index, true, false)
cell_missions_button_a()
end
end
end
function cell_missions_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)
game_UI_audio_play("UI_Cell_Nav")
end
if Num_items > 0 and Mission_in_progress == false then
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 and cell_missions_get_valid_handle(target_handle) ~= MOUSE_INVALID_HANDLE then
List:set_selection(new_index, true, false)
end
end
end
function cell_missions_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
--scroll lines are inverted for some reason
scroll_lines = scroll_lines * -1
local num_missions = #Data
--if list has enough items to scroll then allow mouse wheel
if num_missions > 4 then
if scroll_lines > 0 then
cell_missions_nav_down()
elseif scroll_lines < 0 then
cell_missions_nav_up()
end
end
end
function cell_missions_mouse_drag(event, target_handle, mouse_x, mouse_y, scroll_lines)
if List.scrollbar.tab.handle == target_handle then
local new_start_index = List.scrollbar:drag_scrolltab(mouse_y, #Data)
--don't highlight anything, just scroll the list.
List:set_selection(new_start_index, false, true)
end
end
function cell_missions_mouse_drag_release(event, target_handle, mouse_x, mouse_y, scroll_lines)
-- scroll phone book
if List.scrollbar.tab.handle == target_handle then
List.scrollbar:release_scrolltab(List.current_idx, #Data)
end
end
--Search through active buttons and determine if the mouse is over a valid target
--
function cell_missions_get_valid_handle(target_handle)
for idx, current_button in pairs(List.buttons) do
if current_button.handle ~= nil and current_button.handle == target_handle then
--if selection is visible then return idx
if idx >= List.visible_start_idx and idx <= List.visible_end_idx then
return idx
end
end
end
return MOUSE_INVALID_HANDLE
end