-- Offset of list and header from other store layouts
local POWERS_OFFSET = 80
local POWERS_LIST_WIDTH = 0
local DESC_GRP_SPACING = 20
-- Hint bar and store header vdo's.
local Hint_bar
local Not_popup_grp
local Store_popup
local Powers_sub_menu_data = {}
local Upgrades_descriptions = {}
local Desc_cloned_grps = {}
local Hint_bar_mouse_input_tracker
local Large_element_icon_h
local Cur_description_element
local Powers_sub_doc_h = -1
--Image
local Powers_sub_loading_img = nil
local Powers_sub_unload_img = nil
--Title
local Title_txt_h = -1
local Power_icon_h = -1
local Element_icon_h = -1
local Desc_header_txt_h = -1
local Elements_desc_txt_h = -1
local Desc_simple_txt_h = -1
local Desc_base_grp_h = -1
local Elements_locked_grp_h
local Elements_locked_txt_h
local Elements_locked_bg_h
local Elements_locked_trim_h
local Elements_locked_trim2_h
local Level_req_h
local Level_req_label_h
local Level_req_grp_h
--Anims
local Powers_out_anim_h
function powers_sub_init()
vint_force_lua_gc() --Force Garbage Collection
pause_map_dump()
Powers_sub_doc_h = vint_document_find("powers_sub")
--Anims
Powers_out_anim_h = vint_object_find("powers_out_anim", 0, Powers_sub_doc_h)
--Set up some callbacks for the common store script
Store_common_populate_list_cb = powers_sub_populate_list
Store_common_exit_cb = powers_sub_exit_to_main
--Subscribe to the button presses we need
Input_tracker:remove_input("map")
Input_tracker:add_input("map", "powers_sub_input_map", 50)
if game_get_platform() == "PC" then
Input_tracker:add_input("alt_joy_up", "powers_scroll_list", 50)
Input_tracker:add_input("alt_joy_down", "powers_scroll_list", 50)
end
Input_tracker:subscribe(false)
--Setup Button Hints
Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_common_doc_handle)
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Hint_bar:set_hints(hint_data)
Hint_bar:set_visible(true)
-- Mouse input
if game_get_platform() == "PC" then
Hint_bar:set_highlight(0)
Hint_bar_mouse_input_tracker = Vdo_input_tracker:new()
Hint_bar:add_mouse_inputs("powers_sub", Hint_bar_mouse_input_tracker)
Hint_bar_mouse_input_tracker:subscribe(true)
end
--Init large element image
Large_element_icon_h = vint_object_find("large_element_icon", 0, Powers_sub_doc_h)
vint_set_property(Large_element_icon_h, "visible", false)
--Store header
Store_header:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY)
Store_header:set_visible(true)
--Store_header:set_scale(.9, .9)
Active_list = Vdo_mega_list:new("list_1", 0, Store_common_doc_handle, "store_common.lua", "Active_list")
--turn off store logo???
-- Everything that is not in the popup so we can fade it when the popup is active
Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle)
-- Setup purchase popup
Store_popup = Vdo_store_popup:new("store_popup", 0, Store_common_doc_handle)
Store_popup:set_visible(false)
Store_popup:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY)
Store_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5))
-- Needs to be done after the list is drawn/populated
Active_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY)
local powers_grp = vint_object_find("powers_grp", 0, Powers_sub_doc_h)
vint_set_property(powers_grp, "visible", true)
-- For the rewards store, we don't want the bg to render behind the player, so change this property.
-- Perhaps these can be organized so it's easier to do this.
local grp1_h = vint_object_find("lets_pretend_bg_grp", 0, Store_common_doc_handle)
vint_set_property(grp1_h, "background", false)
vint_set_property(grp1_h, "visible", false)
-- Animate store in
local store_anim_h = vint_object_find("powers_anim_in", 0, Store_common_doc_handle)
lua_play_anim(store_anim_h, 0, Store_common_doc_handle)
Title_txt_h = vint_object_find("title_txt", 0, Powers_sub_doc_h)
Power_icon_h = vint_object_find("power_icon", 0, Powers_sub_doc_h)
Element_icon_h = vint_object_find("element_icon", 0, Powers_sub_doc_h)
Desc_header_txt_h = vint_object_find("desc_header_txt", 0, Powers_sub_doc_h)
Elements_desc_txt_h = vint_object_find("elements_desc_txt", 0, Powers_sub_doc_h)
Desc_simple_txt_h = vint_object_find("desc_simple_txt", 0, Powers_sub_doc_h)
Desc_base_grp_h = vint_object_find("desc_base_grp", 0, Powers_sub_doc_h)
Elements_locked_grp_h = vint_object_find("elements_locked_grp", 0, Powers_sub_doc_h)
Elements_locked_txt_h = vint_object_find("elements_locked_txt", 0, Powers_sub_doc_h)
Elements_locked_bg_h = vint_object_find("elements_locked_bg", 0, Powers_sub_doc_h)
Elements_locked_trim_h = vint_object_find("elements_locked_trim", 0, Powers_sub_doc_h)
Elements_locked_trim2_h = vint_object_find("elements_locked_trim2", 0, Powers_sub_doc_h)
Level_req_h = vint_object_find("level_req", 0, Powers_sub_doc_h)
Level_req_label_h = vint_object_find("level_req_label", 0, Powers_sub_doc_h)
Level_req_grp_h = vint_object_find("level_req_grp", 0, Powers_sub_doc_h)
--Set Title Area
vint_set_property(Title_txt_h, "text_tag", Powers_cur_power_name)
vint_set_property(Title_txt_h, "tint", 230/255, 230/255, 230/255)
vint_set_property(Power_icon_h, "image", Powers_cur_power_bitmap)
vint_set_property(Element_icon_h, "image", Powers_cur_element_bitmap)
--Hide element icon if not a rad power
if Powers_cur_type == POWERS_TYPE_RAD then
vint_set_property(Element_icon_h, "visible", true)
else
vint_set_property(Element_icon_h, "visible", false)
end
--Are we upgrades or elements?
--Determine which data to populate list with
if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then
vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_upgrades", 0, "get_avail_upgrades", Powers_cur_id)
Store_header:push_title(nil, "POWERS_UPGRADES_HEADER")
else
if Powers_cur_id == 6 then
vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_elements", 0, "get_elements", Powers_cur_id)
Store_header:push_title(nil, "POWERS_WING_STYLE_HEADER")
else
vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_elements", 0, "get_elements", Powers_cur_id)
Store_header:push_title(nil, "POWERS_ELEMENTS_HEADER")
end
end
powers_sub_populate_list(Powers_sub_menu_data, 1)
powers_sub_on_enter()
powers_sub_unlock_controls()
--glitch
glitch_cell()
end
function powers_sub_cleanup()
Input_tracker:subscribe(false)
powers_sub_enable_mouse(false)
if Powers_sub_unload_img ~= nil and Powers_sub_unload_img ~= -1 then
game_peg_unload(Powers_sub_unload_img)
end
if Powers_sub_loading_img ~= nil and Powers_sub_loading_img ~= -1 then
game_peg_unload(Powers_sub_loading_img)
end
pause_map_restore()
vint_force_lua_gc() --Force Garbage Collection
end
-----------------
--Image Functions
-----------------
-- Called in a thread to delay the image updating.
-- This is done for 2 reasons: to slow down rapid scrolling updates done too quickly,
-- and because the streaming system didn't always co-operate with the images being released
-- from the callback context that was executed when another stream load completed.
--
function powers_sub_image_update(image)
thread_new( "powers_sub_image_update_process", image )
end
function powers_sub_image_update_process(image)
--delay(0.2)
vint_set_property(Large_element_icon_h, "visible", false)
if Powers_sub_unload_img ~= nil and Powers_sub_unload_img ~= -1 then
game_peg_unload(Powers_sub_unload_img)
thread_yield()
thread_yield()
thread_yield()
end
Powers_sub_loading_img = image
game_peg_load_with_cb("powers_sub_show_image", 1, Powers_sub_loading_img)
end
-- Callback for when an image is done loading.
function powers_sub_show_image()
vint_set_property(Large_element_icon_h, "image", Powers_sub_loading_img)
vint_set_property(Large_element_icon_h, "visible", true)
Powers_sub_unload_img = Powers_sub_loading_img
end
-----------------
--Store Functions
-----------------
function powers_sub_add_upgrades(name_crc, is_locked, is_purchased, price, id, level_required, trumps, is_new, is_orb, orbs_collected, gameplay_gate)
local menu_idx = #Powers_sub_menu_data + 1
level_required = level_required + 1
local new_item = {
type = TYPE_BUTTON,
id = id,
--name_crc = name_crc,
label = nil,
label_crc = name_crc,
--image = image_name,
--description = desc_crc,
is_locked = is_locked,
is_purchased = is_purchased,
price = price,
-- Display of level and max_level disabled for now
level = nil,
max_level = nil,
level_required = level_required,
on_nav = powers_sub_item_nav,
on_select = powers_sub_purchase_select,
on_enter = powers_sub_on_enter,
--on_back = powers_sub_revert_header,
trumps = trumps, -- CRC for the name of the prerequisite
is_new = is_new,
is_orb = true,
orbs_collected = orbs_collected,
gameplay_gate = gameplay_gate,
}
Powers_sub_menu_data[menu_idx] = new_item
end
--call this once for each list item, and it will fill in the appropriate number of descriptions
function powers_sub_add_upgrades_descriptions(description, element)
local i = #Upgrades_descriptions + 1
Upgrades_descriptions[i] = {}
local t = Upgrades_descriptions[i]
t.description = description
t.element = element
Cur_description_element = element
end
function powers_sub_add_elements(name_crc, desc_crc, element_id, unlockable_id, is_locked, equipped, is_new, wing_id)
local menu_idx = #Powers_sub_menu_data + 1
local new_item = {
type = TYPE_BUTTON,
id = element_id,
unlockable_id = unlockable_id,
-- label = nil,
label_crc = name_crc,
--image = image_name,
desc = desc_crc,
is_locked = is_locked,
owned = true,
equipped = equipped,
-- Display of level and max_level disabled for now
level = nil,
max_level = nil,
level_required = 0,
on_nav = powers_sub_item_nav,
on_select = powers_sub_purchase_select,
on_enter = powers_sub_on_enter,
--on_back = powers_sub_revert_header,
trumps = 0, -- CRC for the name of the prerequisite
is_new = is_new,
is_element = true,
wing_id = wing_id,
--is_orb = true,
}
Powers_sub_menu_data[menu_idx] = new_item
end
-- Populate the active megalist menu,
--
-- list_data: this table contains the data to populate the megalist
-- current_index: the current index in the menu that's selected
--
function powers_sub_populate_list(list_data, current_index)
Active_list:set_scale_text_if_too_big(true)
if Powers_screen_state == POWERS_SCREEN_STATE_ELEMENT then
for i = 1, #list_data do
list_data[i].label = POWERS_ELEMENTS_ENUMS[list_data[i].id].short_label
end
end
Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10)
Menu_data = list_data
Active_list:set_visible(true)
powers_sub_item_nav(Menu_data[current_index])
if game_get_platform() == "PC" then
Mouse_input_tracker:remove_all()
Active_list:set_store("powers_sub")
Active_list:add_mouse_inputs("store_common", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
function powers_sub_on_enter()
powers_sub_item_nav(Powers_sub_menu_data[1])
end
function powers_sub_item_nav(menu_data)
--Update text on right of screen based on highlighted item
-- if this was marked as "new", then clear the flag since the player highlighted it
if menu_data.is_new then
local unlockable_id = menu_data.unlockable_id or menu_data.id
vint_dataresponder_post("cell_rewards_reward_dr", "Clear_new", unlockable_id)
--Remove our mouse inputs first...
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
end
--Get index from the list and then remove the flag...
local index = Active_list:get_index_from_id(menu_data.id)
if index ~= -1 then
Active_list:remove_new_flag(index)
end
--Update cursor,
Active_list:move_cursor(0)
--Re add mouse inputs...
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
Active_list:add_mouse_inputs("store_common", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
--Destroy any cloned grps
for i = 1, #Desc_cloned_grps do
vint_object_destroy(Desc_cloned_grps[i])
end
--Base upgrades desc handle and hide...
local desc_grp_h = vint_object_find("desc_grp", 0, Powers_sub_doc_h)
vint_set_property(desc_grp_h, "visible", false)
vint_set_property(Level_req_grp_h, "visible", false)
--Update Description
if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then
--Hide element desc text field and image
vint_set_property(Large_element_icon_h, "visible", false)
vint_set_property(Elements_desc_txt_h, "visible", false)
vint_set_property(Elements_locked_grp_h, "visible", false)
--Update Description Header
vint_set_property(Desc_header_txt_h, "text_tag_crc", menu_data.label_crc)
resize_text_element(Desc_header_txt_h, 350)
table_clear(Upgrades_descriptions, true)
Upgrades_descriptions = {}
vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_upgrades_descriptions", 0, "get_upgrade_desc", menu_data.id)
--[[powers_sub_add_upgrades_descriptions("Test ipsum dolor sit amet, ", 1)
powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2)
powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 3)
powers_sub_add_upgrades_descriptions("Test ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 1)
powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2)
powers_sub_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2)]]
--use cloned grps for element specific upgrade descriptions
if Upgrades_descriptions[1] ~= nil then
if Upgrades_descriptions[1].element ~= -1 then
vint_set_property(Desc_simple_txt_h, "visible", false)
local prev_height = 0
Desc_cloned_grps = {}
for i = 1, #Upgrades_descriptions do
--get data out of table
local description = Upgrades_descriptions[i].description
local element = Upgrades_descriptions[i].element
--clone base item...
local h = vint_object_clone(desc_grp_h)
--Set Text
local desc_type_txt_h = vint_object_find("desc_type_txt", h)
local desc_txt_h = vint_object_find("desc_txt", h)
vint_set_property(desc_type_txt_h, "text_tag", POWERS_ELEMENTS_ENUMS[element].short_label)
vint_set_property(desc_txt_h, "text_tag", description)
--Set icon
-- TODO: add ability to show non element specific description if needed
local desc_icon_h = vint_object_find("desc_icon", h)
vint_set_property(desc_icon_h, "image", POWERS_ELEMENTS_ENUMS[element].bitmap)
--Position grp...
local x, y = vint_get_property(h, "anchor")
local width1, height1 = element_get_actual_size(desc_type_txt_h)
local width2, height2 = element_get_actual_size(desc_txt_h)
y = ( (i - 1) * DESC_GRP_SPACING ) + prev_height
vint_set_property(h, "anchor", x, y )
prev_height = prev_height + height1 + height2
--store cloned grps in table to be destroyed
Desc_cloned_grps[i] = h
--Show grp
vint_set_property(h, "visible", true)
--scale if nessesary
local max_desc_height = 345
if prev_height > max_desc_height then
local scale_amount = max_desc_height/prev_height
vint_set_property(Desc_base_grp_h, "scale", scale_amount, scale_amount)
else
vint_set_property(Desc_base_grp_h, "scale", 1,1)
end
end
--use simple upgrade text box if element is -1
else
vint_set_property(desc_grp_h, "visible", false)
vint_set_property(Desc_simple_txt_h, "text_tag", Upgrades_descriptions[1].description)
vint_set_property(Desc_simple_txt_h, "visible", true)
vint_set_property(Desc_base_grp_h, "scale", 1,1)
end
else
--This should never get called hopefully
vint_set_property(desc_grp_h, "visible", false)
vint_set_property(Desc_simple_txt_h, "text_tag", "")
vint_set_property(Desc_simple_txt_h, "visible", true)
end
----------------
--Gameplay gated
----------------
if menu_data.gameplay_gate ~= nil and menu_data.gameplay_gate ~= "" then
--show and format locked text
local elements_locked_string = ""
if menu_data.gameplay_gate == "quest" then
elements_locked_string = "UPGRADES_LOCKED_QUEST"
elseif menu_data.gameplay_gate == "challenge" then
elements_locked_string = "UPGRADES_LOCKED_CHALLENGE"
end
vint_set_property(Elements_locked_txt_h, "text_tag", elements_locked_string)
local width, height = element_get_actual_size(Elements_locked_txt_h)
element_set_actual_size(Elements_locked_bg_h, width + 24, height + 14)
element_set_actual_size(Elements_locked_trim_h, width + 24, 2)
element_set_actual_size(Elements_locked_trim2_h, width + 24, 2)
vint_set_property(Elements_locked_trim_h, "anchor", 0, -(height/2) - 7)
vint_set_property(Elements_locked_trim2_h, "anchor", 0, (height/2) + 7)
vint_set_property(Elements_locked_grp_h, "visible", true)
else
vint_set_property(Elements_locked_grp_h, "visible", false)
end
--tint text desc
if (menu_data.gameplay_gate ~= nil and menu_data.gameplay_gate ~= "") then
vint_set_property(Desc_base_grp_h, "alpha", .5)
vint_set_property(Desc_simple_txt_h, "alpha", .5)
elseif menu_data.is_locked == true then
vint_set_property(Desc_base_grp_h, "alpha", .5)
vint_set_property(Desc_simple_txt_h, "alpha", .5)
vint_set_property(Level_req_grp_h, "visible", true)
vint_set_property(Level_req_h, "text_tag", var_to_string(menu_data.level_required))
vint_set_property(Level_req_label_h, "text_tag", "STORE_UPGRADES_REQUIRED")
else
vint_set_property(Desc_base_grp_h, "alpha", 1)
vint_set_property(Desc_simple_txt_h, "alpha", 1)
end
else
powers_sub_image_update(POWERS_ELEMENTS_ENUMS[menu_data.id].large_bitmap)
--Update Description Header
vint_set_property(Desc_header_txt_h, "text_tag", POWERS_ELEMENTS_ENUMS[menu_data.id].short_label)
resize_text_element(Desc_header_txt_h, 350)
if menu_data.is_locked then
--show and format locked text
vint_set_property(Large_element_icon_h, "tint", 100/255, 100/255, 100/255)
vint_set_property(Elements_desc_txt_h, "alpha", .5)
vint_set_property(Elements_locked_grp_h, "visible", true)
local width, height = element_get_actual_size(Elements_locked_txt_h)
element_set_actual_size(Elements_locked_bg_h, width + 24, height + 14)
element_set_actual_size(Elements_locked_trim_h, width + 24, 2)
element_set_actual_size(Elements_locked_trim2_h, width + 24, 2)
vint_set_property(Elements_locked_trim_h, "anchor", 0, -(height/2) - 7)
vint_set_property(Elements_locked_trim2_h, "anchor", 0, (height/2) + 7)
else
vint_set_property(Large_element_icon_h, "tint", 220/255, 220/255, 220/255)
vint_set_property(Elements_desc_txt_h, "alpha", 1)
vint_set_property(Elements_locked_grp_h, "visible", false)
end
vint_set_property(Elements_desc_txt_h, "text_tag_crc", menu_data.desc)
vint_set_property(Desc_simple_txt_h, "visible", false)
vint_set_property(desc_grp_h, "visible", false)
vint_set_property(Elements_desc_txt_h, "visible", true)
end
--Update store header
Store_header:set_price(menu_data.price, menu_data.is_orb)
Store_header:set_level(menu_data.level_required, menu_data.is_orb)
if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then
Store_header:show_cash(true)
if menu_data.is_orb == true then
Store_header:set_cash(menu_data.orbs_collected, menu_data.is_orb)
else
Store_header:set_cash(Store_common_player_cash, menu_data.is_orb)
end
else
Store_header:show_cash(false)
end
end
function powers_sub_purchase_select(menu_data)
if menu_data.is_locked == true or menu_data.is_purchased == true then
return
end
powers_sub_enable_mouse(false)
-- Are we short on orbs?
if Powers_screen_state ~= POWERS_SCREEN_STATE_ELEMENT and menu_data.price > menu_data.orbs_collected then
Store_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_popup:set_title("MENU_TITLE_NOTICE")
Store_popup:set_text("HUD_SHOP_INSUFFICIENT_ORBS")
Store_popup:nav_enable(true, "powers_sub_fail_msg", "powers_sub_popup_nav")
Not_popup_grp:set_alpha(.5)
--Active_list:set_visible(false)
return
end
-- Make sure they want to buy this
if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then
Store_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)
Store_popup:set_title("STORE_TITLE_PURCHASING")
Store_popup:set_text("STORE_TEXT_CONFIRM_PURCHASE_BLANK")
Store_popup:nav_enable(true, "powers_sub_purchase_final", "powers_sub_popup_nav")
Not_popup_grp:set_alpha(.5)
--Active_list:set_visible(false)
else
if game_death_tag_is_active() then
Store_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_popup:set_title("MENU_TITLE_NOTICE")
Store_popup:set_text("HUD_SHOP_ELEMENTS_DISABLED")
Store_popup:nav_enable(true, "powers_sub_fail_msg", "powers_sub_popup_nav")
Not_popup_grp:set_alpha(.5)
return
else
if Powers_cur_id == 6 then --Flight wings selection
local current_index = Active_list:get_selection()
vint_scriptevent_post( "ui_powers_main", "set_wing_type", Powers_sub_menu_data[current_index].wing_id )
powers_sub_exit_to_main()
else
local current_index = Active_list:get_selection()
vint_scriptevent_post( "ui_powers_main", "set_element", Powers_sub_menu_data[current_index].id )
vint_set_property(Element_icon_h, "image", POWERS_ELEMENTS_ENUMS[Powers_sub_menu_data[current_index].id].bitmap)
powers_sub_exit_to_main()
end
end
end
end
-- Finalize or cancel a purchase based on the result of the confirmation question.
function powers_sub_purchase_final(event)
Store_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
powers_sub_enable_mouse(true)
-- The user hit the B button and are cancelling the purchase
-- This is redundant to selecting "No" in the list
if event == "back" then
ui_audio_post_event("UI_Hub_Menu_Back")
if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then
return
end
end
-- Did we select yes? This assumes yes is the first item
if Store_popup:get_selected_data() ~= 1 then
ui_audio_post_event("UI_Hub_Menu_Back")
return
end
ui_audio_post_event("UI_Hub_Menu_Forward")
-- give reward and take money here
local current_index = Active_list:get_selection()
if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then
local unlockable_id = Powers_sub_menu_data[current_index].unlockable_id or Powers_sub_menu_data[current_index].id
vint_dataresponder_post("cell_rewards_reward_dr", "Purchase", unlockable_id)
elseif Powers_screen_state == POWERS_SCREEN_STATE_ELEMENT then
vint_scriptevent_post( "ui_powers_main", "set_element", Powers_sub_menu_data[current_index].id )
vint_set_property(Element_icon_h, "image", POWERS_ELEMENTS_ENUMS[Powers_sub_menu_data[current_index].id].bitmap)
end
-- do this so holding down the button doesn't cause repeated actions
Input_tracker:subscribe(false)
if game_get_platform() == "PC" then
Mouse_input_tracker:subscribe(false)
Hint_bar_mouse_input_tracker:subscribe(false)
end
-- Save off index before we refresh the list
Powers_sub_menu_data.start_index = current_index
end
function powers_sub_fail_msg(event)
Store_popup:nav_enable(false, nil, nil)
Not_popup_grp:set_alpha(1)
Active_list:set_visible(true)
powers_sub_enable_mouse(true)
end
function powers_sub_gained_focus()
debug_print("vint", "powers_sub.lua :::: powers_sub_gained_focus :::: FOCUS GAINED START\n")
local index = Active_list:get_selection()
Menu_data = {}
Powers_sub_menu_data = Menu_data
if Powers_screen_state == POWERS_SCREEN_STATE_UPGRADE then
vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_upgrades", 0, "get_avail_upgrades", Powers_cur_id)
else
vint_dataresponder_request("powers_upgrades_dr", "powers_sub_add_elements", 0, "get_elements", Powers_cur_id)
end
-- May need to update image and description if list was shifted
powers_sub_item_nav(Powers_sub_menu_data[index])
powers_sub_populate_list(Menu_data, index)
Input_tracker:subscribe(true)
store_common_safe_frame_show()
if game_get_platform() == "PC" then
Mouse_input_tracker:subscribe(true)
Hint_bar_mouse_input_tracker:subscribe(true)
end
debug_print("vint", "powers_sub.lua :::: powers_sub_gained_focus :::: FOCUS GAINED END\n")
end
function powers_sub_popup_nav(event, value)
if event == "nav_up" then
Store_popup.list:move_cursor(-1)
elseif event == "nav_down" then
Store_popup.list:move_cursor(1)
elseif event == "mouse_move" then
-- value contains the target_handle in this case
local new_index = Store_popup.list:get_button_index(value)
if new_index ~= 0 then
Store_popup.list:set_selection(new_index)
Store_popup.list:move_cursor(0, true)
end
else
--do nothing
end
end
-----------------
--Input Functions
-----------------
function powers_sub_unlock_controls()
Input_tracker:subscribe(true)
powers_sub_enable_mouse(true)
end
function powers_sub_lock_controls()
Input_tracker:subscribe(false)
powers_sub_enable_mouse(false)
end
function powers_sub_input_map()
local anim_out_h = vint_object_find("powers_anim_out", 0, Store_common_doc_handle)
local powers_exit_anim_h = vint_object_find("powers_exit_anim", 0, Powers_sub_doc_h)
lua_play_anim(anim_out_h)
lua_play_anim(powers_exit_anim_h)
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_POWERS, powers_sub_exit_to_game)
end
function powers_scroll_list(event)
--What direction did we move?
local direction = 0
if event == "alt_joy_up" then
direction = -1
elseif event == "alt_joy_down" then
direction = 1
end
--scroll lines are inverted for some reason
local scroll_lines = direction
if scroll_lines ~= 0 then
Active_list:scroll_list(scroll_lines)
if game_get_platform() == "PC" then
Active_list:update_mouse_inputs("store_common", Mouse_input_tracker, 50)
end
end
end
----------------
--Exit Functions
----------------
function powers_sub_exit_to_main(event)
-- exit the interface
powers_sub_lock_controls()
ui_audio_post_event("UI_Hub_Menu_Back")
-- Animate reward screen out
local anim_out_h = vint_object_find("powers_anim_out", 0, Store_common_doc_handle)
lua_play_anim(anim_out_h)
local twn_h = vint_object_find("end_event_twn", Powers_out_anim_h)
vint_set_property(twn_h, "end_event", "powers_sub_exit_complete")
lua_play_anim(Powers_out_anim_h)
end
function powers_sub_exit_complete()
powers_main_return_from_sub()
pop_screen()
end
function powers_sub_exit_to_game(event)
ui_audio_post_event("UI_Hub_Menu_Back")
pop_screen()
pop_screen()
pop_screen()
pop_screen()
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
function powers_sub_enable_mouse(enable)
if game_get_platform() == "PC" and enable ~= nil then
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:subscribe(enable)
end
if Hint_bar_mouse_input_tracker ~= nil then
Hint_bar_mouse_input_tracker:subscribe(enable)
end
end
end
-- Mouse inputs
function powers_sub_mouse_click(event, target_handle, mouse_x, mouse_y)
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
store_common_button_b()
end
local new_index = Active_list:get_button_index(target_handle)
--this apparently never gets used
if new_index ~= 0 then
Active_list:set_selection(new_index)
--cell_rewards_button_a()
end
end
function powers_sub_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 old_index = Active_list:get_selection()
local new_index = Active_list:get_button_index(target_handle)
if new_index ~= 0 and new_index ~= old_index then
Active_list:set_selection(new_index)
Active_list:move_cursor(0, true)
-- If the item has a callback for navigation, do it
local data_item = Active_list:return_selected_data()
if data_item.on_nav ~= nil then
data_item.on_nav(data_item)
end
end
end