function vdo_store_popup_init()
end
-- Inherited from Vdo_base_object
Vdo_store_popup = Vdo_base_object:new_base()
local Input_tracker
local Mouse_input_tracker
local STORE_POPUP_BORDER_PAD = 5
local STORE_POPUP_TITLE_PAD = 38
local STORE_POPUP_TEXT_PAD = 10
local STORE_POPUP_LIST_PAD = 2
function Vdo_store_popup:init()
self.title = Vdo_base_object:new("popup_title",self.handle, self.doc_handle)
self.text = Vdo_base_object:new("popup_text",self.handle, self.doc_handle)
self.border_h = vint_object_find("popup_border",self.handle, self.doc_handle)
self.fill_h = vint_object_find("popup_fill",self.handle, self.doc_handle)
self.list = Vdo_mega_list:new("popup_list", self.handle, self.doc_handle)
self.menu_option_text_scale = 1
Input_tracker = Vdo_input_tracker:new()
-- Initialize the mouse input tracker for the PC
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
end
end
function Vdo_store_popup:cleanup()
self.list:cleanup()
self:subscribe_modify(false)
end
function Vdo_store_popup:populate_list(list_data, current_index, width, max_buttons)
self.list:draw_items(list_data, current_index, width - (STORE_POPUP_BORDER_PAD * 4), max_buttons, LIST_FONT_SCALE, nil, false)
self.max_buttons = max_buttons
game_UI_audio_play("UI_HUD_Help")
end
function Vdo_store_popup:set_text(new_text)
self.text:set_text(new_text)
-- Resize the list and border to fit text size
local text_width, text_height = self.text:get_actual_size()
local text_x, text_y = self.text:get_anchor()
local list_x, list_y = self.list:get_anchor()
self.list:set_anchor(list_x, (text_y - STORE_POPUP_LIST_PAD) + text_height + STORE_POPUP_TEXT_PAD)
--calculate width and height of box and set it...
local list_width, list_height = self.list:get_size()
local height = STORE_POPUP_TITLE_PAD + list_height + text_height + (STORE_POPUP_TEXT_PAD * 2)
local width = self.width
self:set_size(width, height)
end
function Vdo_store_popup:set_title(new_title)
self.title:set_text(new_title)
end
function Vdo_store_popup:set_menu_option_text_scale(scale)
self.menu_option_text_scale = scale
end
-------------------------------------------------------------------------------
-- Sets color of popup...
-- primary table.R, table.G, table.B
-- secondary table.R, table.G, table.B
-- tertiary table.R, table.G, table.B
-------------------------------------------------------------------------------
function Vdo_store_popup:set_color(primary, secondary, tertiary)
vint_set_property(self.border_h, "tint", primary.R, primary.G, primary.B)
self.list:set_highlight_color(primary)
end
function Vdo_store_popup:set_size(width, height)
self.width = width
self.height = height
local fill_width = width - (STORE_POPUP_BORDER_PAD * 2)
local fill_height = height - STORE_POPUP_TITLE_PAD
element_set_actual_size(self.border_h, width, height)
element_set_actual_size(self.fill_h, fill_width, fill_height)
vint_set_property(self.text.handle, "wrap_width", width - 67) -- This should be standardized... I just took this out of store common list size and subtracted what was in the document. JMH 7/5/2011)
end
function Vdo_store_popup:get_size()
return self.width, self.height
end
function Vdo_store_popup:subscribe_modify(do_subscribe)
Input_tracker:subscribe(do_subscribe)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(do_subscribe)
end
end
function Vdo_store_popup:nav_enable(is_on, callback_action, callback_nav)
if is_on then
-- Remove the button presses that are already set
Input_tracker:remove_input("select")
Input_tracker:remove_input("back")
Input_tracker:remove_input("nav_up")
Input_tracker:remove_input("nav_down")
Input_tracker:remove_input("alt_select")
Input_tracker:remove_input("all_unassigned")
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
end
-- Subscribe to the button presses we need
Input_tracker:add_input("select", callback_action, 200)
Input_tracker:add_input("back", callback_action, 200)
Input_tracker:add_input("nav_up", callback_nav, 200)
Input_tracker:add_input("nav_down", callback_nav, 200)
Input_tracker:add_input("alt_select", "store_common_do_nothing", 200)
Input_tracker:add_input("all_unassigned", "store_common_do_nothing", 200)
Input_tracker:subscribe(true)
-- Subscribe to the mouse inputs needed for the PC
if Mouse_input_tracker ~= nil and self.list.buttons ~= nil then
self:add_mouse_inputs(callback_action, callback_nav, Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
self:set_visible(true)
self.callback_action = callback_action
else
-- Remove the button presses we needed
Input_tracker:remove_input("select")
Input_tracker:remove_input("back")
Input_tracker:remove_input("nav_up")
Input_tracker:remove_input("nav_down")
Input_tracker:remove_input("alt_select")
Input_tracker:remove_input("all_unassigned")
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
end
self:set_visible(false)
self.callback_action = nil
end
end
function Vdo_store_popup:get_selected_data()
return self.list:get_selection()
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
-- Adds "mouse_click" and "mouse_move" input subscriptions to each button in the popup's list
--
function Vdo_store_popup:add_mouse_inputs(callback_action, callback_nav, input_tracker, priority)
if (self.list.buttons == nil) or (callback_action == nil) or (callback_nav == nil) then
return
end
-- Default priority value to 200
priority = priority or 200
-- Use the list to add the actual inputs because it's not exactly straightforward
self.list:add_mouse_inputs("blank", Mouse_input_tracker, priority, callback_nav, callback_action, -9000)
end