local CELL_CHEATS_POPULATE_CATEGORIES = 0
local CELL_CHEATS_POPULATE_CHEATS = 1
local ID_CHEAT = -1
local Category_menu = { }
local Num_category_items = 1
local Category_selected_idx = 1
local Sub_menu = { }
local Num_submenu_items = 0
local Unlocked_cheat
local Cheat_just_unlocked = false
local Sub_menu_category = 1
local Add_cheat_button = { label = "ADD_CHEAT", type = TYPE_BUTTON, id = ID_CHEAT }
local Sub_menu_is_active = false
local Input_tracker
local Mouse_input_tracker
local Hint_bar
local Continue_hint_bar
Cheats_list = -1 --This must be global because the megalist needs it to be for callback (JMH 4/4/2011)
local Cell_cheats_doc_handle = -1
local CHEATS_LIST_WIDTH = 354
local CHEATS_LIST_NUM_OPTIONS = 9
local CHEATS_LIST_SCALE = .9
local CHEATS_LIST_TITLE_OFFSET = 30 --Offset to accomodate for header on submenus.
local Cheat_being_entered = false
--Base position for cheatslist...
local Cheats_list_start_x, Cheats_list_start_y
function cell_cheats_init()
Cell_cheats_doc_handle = vint_document_find("cell_cheats")
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("nav_up", "cell_cheats_nav_up", 50)
Input_tracker:add_input("nav_down", "cell_cheats_nav_down", 50)
Input_tracker:add_input("back", "cell_cheats_button_b", 50)
Input_tracker:add_input("select", "cell_cheats_button_a", 50)
Input_tracker:add_input("map", "cell_cheats_button_map", 50)
local grp_h = vint_object_find("new_cheat_grp", 0, Cell_cheats_doc_handle)
vint_set_property(grp_h, "visible", false)
local title_h = vint_object_find("title", 0, Cell_cheats_doc_handle)
vint_set_property(title_h, "text_tag", "HELP_TEXT_CHEATS_TITLE")
local data = {
{CTRL_MENU_BUTTON_A, "MAINMENU_CONTINUE"},
}
Continue_hint_bar = Vdo_hint_bar:new("cheat_btn_hint_bar", grp_h)
Continue_hint_bar:set_hints(data)
Cheats_list = Vdo_mega_list:new("cheats_list", 0, Cell_cheats_doc_handle, "cell_cheats.lua", "Cheats_list")
Cheats_list:set_highlight_color(COLOR_CHEATS_PRIMARY, COLOR_CHEATS_SECONDARY)
--Get base position for cheatslist...
Cheats_list_start_x, Cheats_list_start_y = vint_get_property(Cheats_list.handle, "anchor")
cell_cheats_enter_category_menu()
--Transition the screen in...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_CHEATS, CELL_SCREEN_EXTRAS, cell_cheats_unlock_controls)
if game_get_platform() == "PC" then
-- Setup Button Hints
Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Cell_cheats_doc_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)
Continue_hint_bar:set_highlight(1, COLOR_CHEATS_SECONDARY)
vint_dataitem_add_subscription("cell_cheats_text", "update", "cell_cheats_text_update")
Mouse_input_tracker = Vdo_input_tracker:new()
-- Inputs also updated in cell_cheats_mouse_update
Cheats_list:add_mouse_inputs("cell_cheats", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("cell_cheats", Mouse_input_tracker)
Mouse_input_tracker:subscribe(false)
end
end
function cell_cheats_cleanup()
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function cell_cheats_enter_category_menu()
local subtitle_h = vint_object_find("subtitle", 0, Cell_cheats_doc_handle)
local description_grp_h = vint_object_find("description_grp", 0, Cell_cheats_doc_handle)
-- set description text invisble
Cheats_list:set_anchor(Cheats_list_start_x, Cheats_list_start_y)
vint_set_property(description_grp_h, "visible", false)
vint_set_property(subtitle_h, "visible", false)
Sub_menu_is_active = false
Category_menu = {
[1] = Add_cheat_button,
}
Num_category_items = 1
vint_dataresponder_request("cell_cheats_populate", "cell_cheats_populate_categories", 0, CELL_CHEATS_POPULATE_CATEGORIES)
Cheats_list:draw_items(Category_menu, Category_selected_idx, CHEATS_LIST_WIDTH, CHEATS_LIST_NUM_OPTIONS, CHEATS_LIST_SCALE, true)
if Hint_bar ~= nil then
Hint_bar:set_anchor(-166, 244)
end
cell_cheats_mouse_update()
end
function cell_cheats_mouse_update()
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
Cheats_list:add_mouse_inputs("cell_cheats", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("cell_cheats", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
function cell_cheats_populate_categories(display_name, id)
Num_category_items = Num_category_items + 1
Category_menu[Num_category_items] = { label = display_name, type = TYPE_BUTTON, id = id }
end
function cell_cheats_enter_submenu(category_id)
local cheats_list_h = vint_object_find("cheats_list", 0, Cell_cheats_doc_handle)
local description_grp_h = vint_object_find("description_grp", 0, Cell_cheats_doc_handle)
local subtitle_h = vint_object_find("subtitle", 0, Cell_cheats_doc_handle)
-- Use category name for this
local category_tag = nil
for idx, category in pairs(Category_menu) do
if category.id == category_id then
category_tag = category.label
end
end
Num_submenu_items = 0
Sub_menu = { }
vint_dataresponder_request("cell_cheats_populate", "cell_cheats_populate_cheats", 0, CELL_CHEATS_POPULATE_CHEATS, category_id)
Cheats_list:draw_items(Sub_menu, 1, CHEATS_LIST_WIDTH, CHEATS_LIST_NUM_OPTIONS, CHEATS_LIST_SCALE, true)
Sub_menu_is_active = true
Sub_menu_category = category_id
--Move megalist to accomodate for header...
vint_set_property(Cheats_list.handle, "anchor", Cheats_list_start_x, Cheats_list_start_y + CHEATS_LIST_TITLE_OFFSET)
vint_set_property(description_grp_h, "visible", true)
vint_set_property(subtitle_h, "text_tag", category_tag)
vint_set_property(subtitle_h, "visible", true)
if Hint_bar ~= nil then
Hint_bar:set_anchor(-166, 130)
end
cell_cheats_set_description()
cell_cheats_mouse_update()
end
function cell_cheats_populate_cheats(display_name, description, cheat_is_active, cheat_index, toggleable)
Num_submenu_items = Num_submenu_items + 1
Sub_menu[Num_submenu_items] = { label = display_name, type = TYPE_BUTTON, description = description, cheat_index = cheat_index }
if toggleable then
Sub_menu[Num_submenu_items].equipped = cheat_is_active
Sub_menu[Num_submenu_items].owned = true
else
Sub_menu[Num_submenu_items].equipped = false
Sub_menu[Num_submenu_items].owned = false
end
end
function cell_cheats_set_description()
local selection = Cheats_list:get_selection()
local description = Sub_menu[selection].description
local description_grp_h = vint_object_find("description_grp", 0, Cell_cheats_doc_handle)
vint_set_property(description_grp_h, "visible", true)
local description_text_h = vint_object_find("cheats_description", description_grp_h)
vint_set_property(description_text_h, "text_tag", description)
end
function cell_cheats_cheat_unlocked(cheat_index, display_name, description, category_id)
Cheat_just_unlocked = true
local unlocked_header
local unlocked_text
if cheat_index == - 1 then
Unlocked_cheat = nil
unlocked_header = "CHEAT_NOT_FOUND"
unlocked_text = "CHEAT_NOT_FOUND_DESC"
else
Unlocked_cheat = { cheat_index = cheat_index, category_id = category_id }
unlocked_header = display_name
unlocked_text = description
game_UI_audio_play("UI_Cell_Cheat_Unlocked")
end
Cheats_list:set_visible(false)
local grp_h = vint_object_find("new_cheat_grp")
vint_set_property(grp_h, "visible", true)
local title_h = vint_object_find("new_cheat_title", grp_h)
local desc_h = vint_object_find("new_cheat_description", grp_h)
vint_set_property(title_h, "text_tag", unlocked_header)
vint_set_property(desc_h, "text_tag", unlocked_text)
--Align all elements...
--Align web info...
local data = {
{h = title_h, type = VINT_OBJECT_TEXT, space = 0},
{h = desc_h, type = VINT_OBJECT_TEXT, space = 0},
{h = Continue_hint_bar.handle, type = VINT_OBJECT_INVALID, space = 25},
}
local width, height = vint_align_elements(data, true)
--Hide back button...
if Hint_bar ~= nil then
Hint_bar:set_visible(false)
end
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
Continue_hint_bar:add_mouse_inputs("cell_cheats", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
function cell_cheats_cheat_activated(Cheat_index, is_active)
for idx, Cheat in pairs(Sub_menu) do
if Cheat.cheat_index == Cheat_index then
if Cheat.owned == true then
Cheat.equipped = is_active
end
-- repopulate the list
Num_submenu_items = 0
Sub_menu = { }
vint_dataresponder_request("cell_cheats_populate", "cell_cheats_populate_cheats", 0, CELL_CHEATS_POPULATE_CHEATS, Sub_menu_category)
Cheats_list:draw_items(Sub_menu, idx, CHEATS_LIST_WIDTH, CHEATS_LIST_NUM_OPTIONS, CHEATS_LIST_SCALE, true)
end
end
cell_cheats_mouse_update()
end
function cell_cheats_nav_up(event, acceleration)
if Cheat_just_unlocked == true then
return
end
Cheats_list:move_cursor(-1)
if Sub_menu_is_active then
cell_cheats_set_description()
end
end
function cell_cheats_nav_down(event, acceleration)
if Cheat_just_unlocked == true then
return
end
Cheats_list:move_cursor(1)
if Sub_menu_is_active then
cell_cheats_set_description()
end
end
function cell_cheats_button_map(event, acceleration)
if Cheat_just_unlocked == true then
return
end
game_UI_audio_play("UI_Cell_Close")
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_CHEATS, cell_cheats_exit_to_game)
end
function cell_cheats_button_b(event, acceleration)
if Cheat_being_entered == false then
if Cheat_just_unlocked == false then
if Sub_menu_is_active == false then
--Transition the screen out to extras...
cell_cheats_lock_controls()
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_EXTRAS, CELL_SCREEN_CHEATS, cell_cheats_exit_to_extras)
else
cell_cheats_enter_category_menu()
end
game_UI_audio_play("UI_Cell_Nav_back")
end
elseif game_get_platform() == "PC" then
cell_cheats_cancel_cheat()
end
end
function cheat_add_cb(success)
if success then
cell_cheats_unlock_cheat("VKEYBOARD_RESULTS")
end
end
function cell_cheats_button_a(event, acceleration)
if Cheat_being_entered == false then
if Cheat_just_unlocked == true then
Cheat_just_unlocked = false
if Unlocked_cheat == nil then
cell_cheats_enter_category_menu()
else
-- Update the category menu so we can get the display name for the submenu header.
Category_menu = {
[1] = Add_cheat_button,
}
Num_category_items = 1
vint_dataresponder_request("cell_cheats_populate", "cell_cheats_populate_categories", 0, CELL_CHEATS_POPULATE_CATEGORIES)
cell_cheats_enter_submenu(Unlocked_cheat.category_id)
for idx, Cheat in pairs(Sub_menu) do
if Cheat.cheat_index == Unlocked_cheat.cheat_index then
Cheats_list:draw_items(Sub_menu, idx, CHEATS_LIST_WIDTH, CHEATS_LIST_NUM_OPTIONS, CHEATS_LIST_SCALE, true)
end
end
cell_cheats_mouse_update()
end
local grp_h = vint_object_find("new_cheat_grp", 0, Cell_cheats_doc_handle)
vint_set_property(grp_h, "visible", false)
Cheats_list:set_visible(true)
--show back button...
if Hint_bar ~= nil then
Hint_bar:set_visible(true)
end
elseif Sub_menu_is_active == false then
local id = Cheats_list:get_id()
Category_selected_idx = Cheats_list:get_selection()
-- Selection made in Category menu
if id == ID_CHEAT then
-- add cheat was selected
game_vkeyboard_input("CHEAT_ENTRY_SHORT", "CHEAT_ENTRY_LONG", 32, "", "cheat_add_cb", true)
else
-- entering a sub menu
cell_cheats_enter_submenu(id)
end
else
-- Selection made in Sub menu
local selection = Cheats_list:get_selection()
cell_cheats_activate_cheat(Sub_menu[selection].cheat_index)
end
game_UI_audio_play("UI_Cell_Select")
elseif game_get_platform() == "PC" then
cell_cheats_confirm_cheat()
end
end
function cell_cheats_lock_controls()
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
function cell_cheats_unlock_controls()
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
end
end
function cell_cheats_exit_to_extras()
pop_screen()
end
function cell_cheats_exit_to_game()
pop_screen()
pop_screen()
pop_screen()
pop_screen()
end
function cell_cheats_mouse_click(event, target_handle)
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
cell_cheats_button_b()
end
local hint_index = Continue_hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
cell_cheats_button_a()
end
-- If the target_handle matches a button, activate it
local new_index = Cheats_list:get_button_index(target_handle)
if new_index ~= 0 then
-- Enter an option if the target_handle is in the List
Cheats_list:set_selection(new_index)
cell_cheats_button_a()
end
end
function cell_cheats_mouse_move(event, target_handle)
Hint_bar:set_highlight(0)
Continue_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 hint_index = Continue_hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
Continue_hint_bar:set_highlight(1, COLOR_CHEATS_PRIMARY)
end
local new_index = Cheats_list:get_button_index(target_handle)
if new_index ~= 0 then
-- Set the button as the new selected highlight
Cheats_list:set_selection(new_index)
Cheats_list:move_cursor(0, true)
if Sub_menu_is_active then
cell_cheats_set_description()
end
end
end
function cell_cheats_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
if scroll_lines ~= 0 then
Cheats_list:scroll_list(scroll_lines * -1)
cell_cheats_mouse_update()
end
end
function cell_cheats_mouse_drag(event, target_handle, mouse_x, mouse_y)
if Cheats_list.scrollbar.tab.handle == target_handle then
local new_start_index = Cheats_list.scrollbar:drag_scrolltab(mouse_y, Cheats_list.num_buttons - (Cheats_list.max_buttons - 1))
Cheats_list:scroll_list(0, new_start_index)
end
end
function cell_cheats_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
if Cheats_list.scrollbar.tab.handle == target_handle then
local start_index = Cheats_list:get_visible_indices()
Cheats_list.scrollbar:release_scrolltab(start_index, Cheats_list.num_buttons - (Cheats_list.max_buttons - 1))
cell_cheats_mouse_update()
end
end
function cell_cheats_text_update(di_h, event_name)
local override, cheat_text = vint_dataitem_get(di_h)
Cheat_being_entered = override;
if override == true then
Add_cheat_button.label = cheat_text
else
Add_cheat_button.label = "ADD_CHEAT"
end
Cheats_list:draw_items(Category_menu, 1, CHEATS_LIST_WIDTH, CHEATS_LIST_NUM_OPTIONS, CHEATS_LIST_SCALE, true)
end