function vdo_store_header_init()
end
-- Inherited from Vdo_base_object
Vdo_store_header = Vdo_base_object:new_base()
CRUMB_NUM_TITLE = 3
CRUMB_PAD = 3
CRUMB_FONT_SCALE_SMALL = .8
CRUMB_FONT_SCALE_MEDIUM = .9
CRUMB_FONT_SCALE_LARGE = 1.0
CRUMB_MAX_TITLE_WIDTH = 348
PCR_BAR_WIDTH = 435
PCR_CRUMB_ANCHOR_OFFSET = -70
STORE_HEADER_BAR_WIDTH = 360
Store_respect_meter = {}
function Vdo_store_header:init()
self.price = Vdo_base_object:new("price",self.handle, self.doc_handle)
self.respect = Vdo_base_object:new("store_respect",self.handle, self.doc_handle)
self.bar_bottom_grp = Vdo_base_object:new("bar_bottom_grp",self.handle, self.doc_handle)
self.bar_bottom = Vdo_base_object:new("bar_bottom", self.handle, self.doc_handle)
self.bar_end = Vdo_base_object:new("bar_end", self.handle, self.doc_handle)
self.bar_top = Vdo_base_object:new("bar_top",self.handle, self.doc_handle)
self.font_grp = Vdo_base_object:new("font_grp",self.handle, self.doc_handle)
self.bar_end_outline = Vdo_base_object:new("bar_end_outline", self.handle, self.doc_handle)
self.bar_left_line = Vdo_base_object:new("bar_left_line", self.handle, self.doc_handle)
self.bar_top_line = Vdo_base_object:new("bar_top_line", self.handle, self.doc_handle)
self.bar_bottom_line = Vdo_base_object:new("bar_bottom_line", self.handle, self.doc_handle)
self.title = {}
self.arrow = {}
self.title_stack = {}
for i = 1, CRUMB_NUM_TITLE do
self.title[i] = Vdo_base_object:new("title" .. i, self.handle, self.doc_handle)
self.title[i]:set_visible(false)
if i ~= CRUMB_NUM_TITLE then
self.arrow[i] = Vdo_base_object:new("arrow" .. i, self.handle, self.doc_handle)
self.arrow[i]:set_visible(false)
end
end
self.cash = Vdo_base_object:new("cash",self.handle, self.doc_handle)
self.title_grp = Vdo_base_object:new("title_grp",self.handle, self.doc_handle)
--unfortunatly this uses a global so, there cannot be multiple instances of this header at one time...(JMH 6/22/2010)
Store_respect_meter = Vdo_respect_meter:new("store_respect_meter", self.handle, self.doc_handle, "vdo_store_header.lua", "Store_respect_meter")
self.respect_meter = Store_respect_meter --store it as part of this instance...
self.respect_meter:set_is_in_store(true)
-- Scale max width for standard res
if vint_is_std_res() == true then
CRUMB_MAX_TITLE_WIDTH = CRUMB_MAX_TITLE_WIDTH * SCALE_STD_RES
end
self:enable_price_respect(false)
end
-- Update the titles (breadcrumbs) in the header.
-- The store header keeps a stack of titles that have been pushed onto it, and we use the
-- last CRUMB_NUM_TITLE titles to populate our header.
--
function Vdo_store_header:set_title()
local title_count = #self.title_stack
-- Get the last CRUMB_NUM_TITLE titles in the stack and set them in vint
for i = 1, CRUMB_NUM_TITLE do
local stack_index = title_count - CRUMB_NUM_TITLE + i
-- Handle if we have less than CRUMB_NUM_TITLE titles
if stack_index < i then
stack_index = i
end
if self.title_stack[stack_index] ~= nil then
if self.title_stack[stack_index].crc ~= nil then
self.title[i]:set_text_crc(self.title_stack[stack_index].crc)
else
self.title[i]:set_text(self.title_stack[stack_index].label)
end
self.title[i]:set_visible(true)
if i > 1 then
self.arrow[i - 1]:set_visible(true)
end
else
self.title[i]:set_visible(false)
if i > 1 then
self.arrow[i - 1]:set_visible(false)
end
end
end
-- Handle Scaling, based on how many titles are visible. Rightmost title is always largest, and ones to the left get smaller.
local scale_tbl = { [1] = CRUMB_FONT_SCALE_SMALL, [2] = CRUMB_FONT_SCALE_MEDIUM, [3] = CRUMB_FONT_SCALE_LARGE }
local curr_scale = 3
for i = CRUMB_NUM_TITLE, 1, -1 do
if self.title[i]:get_property("visible") then
self.title[i]:set_property("scale", scale_tbl[curr_scale], scale_tbl[curr_scale])
if curr_scale > 1 then
curr_scale = curr_scale - 1
end
end
end
-- Now change titles to "..." to try to make text fit - start from left, and stop when it either fits, or we reach the last title.
for i = 1, CRUMB_NUM_TITLE - 1 do
if self:get_title_size() > CRUMB_MAX_TITLE_WIDTH then
self.title[i]:set_text("...")
end
end
-- Position titles
for i = 1, CRUMB_NUM_TITLE - 1 do
local title_width, title_height = self.title[i]:get_property("screen_size")
local title_x,title_y = self.title[i]:get_anchor()
local arrow_width, arrow_height = self.arrow[i]:get_property("screen_size")
local arrow_x, arrow_y = self.arrow[i]:get_anchor()
--Scale for standard res
if vint_is_std_res() == true then
title_width = title_width / SCALE_STD_RES
end
arrow_x = title_x + title_width + CRUMB_PAD * 2
local title2_x = arrow_x + arrow_width + CRUMB_PAD * 2
self.arrow[i]:set_property("anchor",arrow_x, arrow_y)
self.title[i+1]:set_property("anchor",title2_x, title_y)
end
end
-- Get the width of all the visible titles
function Vdo_store_header:get_title_size()
local total_title_width = 0
for i = 1, CRUMB_NUM_TITLE do
if self.title[i]:get_visible() then
local title_width,title_height = self.title[i]:get_property("screen_size")
total_title_width = total_title_width + title_width
end
end
return total_title_width
end
function Vdo_store_header:set_color(primary, secondary, tertiary)
self.bar_top:set_color(primary.R, primary.G, primary.B)
self.font_grp:set_color(primary.R, primary.G, primary.B)
self.title_grp:set_color(secondary.R, secondary.G, secondary.B)
self.cash:set_color(secondary.R, secondary.G, secondary.B)
self.bar_bottom_grp:set_color(tertiary.R, tertiary.G, tertiary.B)
self.respect_meter:set_color(primary)
for i = 1, CRUMB_NUM_TITLE - 1 do
self.arrow[i]:set_color(primary.R, primary.G, primary.B)
end
end
function Vdo_store_header:set_cash(cash, is_orb)
local body, insert_values
if is_orb == true then
insert_values = { [0] = (cash) }
body = vint_insert_values_in_string("STORE_ORBS_TOTAL", insert_values)
self.cash:set_text(body)
else
self.cash:set_text("{GAME_CASH}" .. format_cash(cash))
end
end
function Vdo_store_header:show_cash(visible)
if visible == false then
self.cash:set_visible(false)
else
self.cash:set_visible(true)
end
end
-- This function can be used to disable (or re-enable) the price and respect text fields,
-- regardless of what is set for price and respect. Useful for modes like wardrobe.
--
function Vdo_store_header:enable_price_respect(enabled)
self.price:set_visible(enabled)
self.respect:set_visible(enabled)
end
function Vdo_store_header:set_price(price, is_orb)
if type(price) == "string" then
self.price:set_text(price)
elseif price ~= nil then
-- don't allow negative prices
if price < 0 then
price = 0
end
self.price:set_visible(true)
local body, insert_values
if is_orb == true then
insert_values = { [0] = (price) }
body = vint_insert_values_in_string("STORE_ORBS_PRICE", insert_values)
else
insert_values = { [0] = format_cash(price) }
body = vint_insert_values_in_string("STORE_PRICE", insert_values)
end
self.price:set_text(body)
else
self.price:set_visible(false)
end
end
function Vdo_store_header:set_respect(respect)
if respect ~= nil then
self.respect:set_visible(true)
local body
local insert_values = { [0] = respect }
body = vint_insert_values_in_string("STORE_RESPECT", insert_values)
self.respect:set_text(body)
else
self.respect:set_visible(false)
end
end
-- Pushes a title on the title stack and calls set_title to redraw the current titles
--
function Vdo_store_header:push_title(title_crc, title_label)
local stack_index = #self.title_stack + 1
self.title_stack[stack_index] = { crc = title_crc, label = title_label }
self:set_title()
end
-- Pops a title off the title stack and calls set_title to redraw the current titles
--
function Vdo_store_header:pop_title()
local stack_index = #self.title_stack
self.title_stack[stack_index] = nil
self:set_title()
end
-- Clears all titles off the stack.
--
function Vdo_store_header:clear_titles()
self.title_stack = {}
self:set_title()
end
----------------------------------------------------
-- Reuses the respect slot to show level needed
-- for items that require a level
--
-- @ param level level required to unlock item
----------------------------------------------------
function Vdo_store_header:set_level(level)
if level ~= nil and level ~= 0 then
self.respect:set_visible(true)
local body
local insert_values = { [0] = level }
body = vint_insert_values_in_string("STORE_LEVEL_REQ", insert_values)
self.respect:set_text(body)
else
self.respect:set_visible(false)
end
end
function Vdo_store_header:set_respect_meter(total_respect, pct, rank)
Store_respect_meter:update_respect(total_respect, pct, rank)
end
----------------------------------------------------
-- Hides elements not needed for player creation
-- and resizes graphics
----------------------------------------------------
function Vdo_store_header:reformat_and_resize(resize,custom_width)
local arrow1_x, arrow1_y = self.arrow[1]:get_anchor()
local title1_x, title1_y = self.title[1]:get_anchor()
local bar_top_width, bar_top_height = element_get_actual_size(self.bar_top.handle)--:get_screen_size()
local bar_bottom_width, bar_bottom_height = element_get_actual_size(self.bar_bottom.handle)--:get_screen_size()
local bar_top_x, bar_top_y = self.bar_top:get_anchor()
local bar_bottom_x, bar_bottom_y = self.bar_bottom:get_anchor()
local cash_x,cash_y = self.cash:get_anchor()
local price_x,price_y = self.price:get_anchor()
local new_bar_width = 0
if resize == false then
self.font_grp:set_visible(true)
self.cash:set_visible(true)
self.respect_meter:set_visible(true)
self.bar_end:set_visible(true)
self.bar_end_outline:set_visible(true)
self.bar_left_line:set_visible(false)
self.title[1]:set_anchor(0, title1_y)
self.arrow[1]:set_anchor(0, arrow1_y)
-- scale for standard res
if custom_width == nil then
new_bar_width = STORE_HEADER_BAR_WIDTH
else
new_bar_width = custom_width
end
self.bar_top:set_anchor(new_bar_width, bar_top_y)
self.bar_bottom:set_anchor(new_bar_width, bar_bottom_y)
else
self.font_grp:set_visible(false)
self.cash:set_visible(false)
self.respect_meter:set_visible(false)
self.bar_end:set_visible(false)
self.bar_end_outline:set_visible(false)
self.bar_left_line:set_visible(true)
self.title[1]:set_anchor(PCR_CRUMB_ANCHOR_OFFSET, title1_y)
self.arrow[1]:set_anchor(PCR_CRUMB_ANCHOR_OFFSET, arrow1_y)
-- scale for standard res
if custom_width == nil then
new_bar_width = PCR_BAR_WIDTH
else
new_bar_width = custom_width
end
self.bar_top:set_anchor(new_bar_width - 74, bar_top_y)
self.bar_bottom:set_anchor(new_bar_width - 75, bar_bottom_y)
self.bar_left_line:set_anchor(-75, 38)
end
self.cash:set_anchor(new_bar_width - 4, cash_y)
self.price:set_anchor(new_bar_width - 4, price_y)
element_set_actual_size(self.bar_top.handle,new_bar_width, bar_top_height)
element_set_actual_size(self.bar_bottom.handle,new_bar_width, bar_bottom_height)
element_set_actual_size(self.bar_top_line.handle, new_bar_width * -1, -2)
element_set_actual_size(self.bar_bottom_line.handle, new_bar_width * -1, -2)
--self.bar_top:set_screen_size(new_bar_width, bar_top_height)
--self.bar_bottom:set_screen_size(new_bar_width, bar_bottom_height)
end
function Vdo_store_header:respect_meter_show()
self.respect_meter:set_visible(true)
end
function Vdo_store_header:respect_meter_hide()
self.respect_meter:set_visible(false)
end