---------------------------------------------------------------------------
-- Vdo_button_toggle
--
-- A button toggle that is designed for use in the Vdo_pause_mega_list
-- This item has 2 text strings label and a value.
---------------------------------------------------------------------------
function vdo_button_toggle_init()
end
function vdo_button_toggle_cleanup()
end
-- Inherited from Vdo_base_object
Vdo_button_toggle = Vdo_base_object:new_base()
-- "defines"
COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED = {R = 218/255, G = 226/255; B = 230/255}
COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED = {R = 0/255, G = 0/255; B = 0/255}
COLOR_ICON_LOCK = {R = 90/255, G = 90/255; B = 90/255}
COLOR_ICON_CHECK = {R = 220/255, G = 220/255; B = 220/255}
COLOR_ICON_SPECIAL = {R = 118/255, G = 0/255; B = 157/255}
COLOR_ICON_SPECIAL_DARK = {R = 58/255, G = 0/255; B = 78/255}
COLOR_ICON_COMPLETED = {R = 90/255, G = 90/255; B = 90/255}
local ICON2_ANCHOR_X = 19
local ICON2_ANCHOR_Y = 0
local BUTTON_TOGGLE_LOCK_OFFSET = 15
local STRIKE_THROUGH_OFFSET = 100
BUTTON_TOGGLE_ICON_TYPE_NONE = 0 --No Icon
BUTTON_TOGGLE_ICON_TYPE_LOCK = 1 --Lock icon
BUTTON_TOGGLE_ICON_TYPE_BOX = 2 --Checkbox
BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED = 3 --ChecboxChecked
BUTTON_TOGGLE_ICON_TYPE_INDENT = 4 --Indented (No Icon)
BUTTON_TOGGLE_ICON_TYPE_NEW = 5 --New item (exclamation point)
BUTTON_TOGGLE_ICON_TYPE_DLC = 6 --DLC item (fleur)
BUTTON_TOGGLE_ICON_TYPE_SPECIAL = 7 --Background highlight
BUTTON_TOGGLE_ICON_TYPE_COMPLETED = 8 --Grey Checkbox Checked
BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED = 9 --Dual arrows
BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE = 10 --Square bullet point
BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP = 11 --2 with arrow
function Vdo_button_toggle:init()
--Store references to icons...
self.icon1 = Vdo_base_object:new("icon1", self.handle, self.doc_handle)
self.icon2 = Vdo_base_object:new("icon2", self.handle, self.doc_handle)
self.text_h = vint_object_find("toggle_text", self.handle, self.doc_handle)
-- Hide optional icons
self:set_icon(0,0)
self.text_offset = 0
self.special = false
--HVS_JPM[KING] 12/11/2014: optional for special highlighted text (used in invite friends list)
self.special_color = nil
end
-- Sets the label of the button object
function Vdo_button_toggle:set_label(new_label)
if self.text_h ~= 0 then
vint_set_property(self.text_h, "text_tag", new_label)
end
end
-- Sets the label crc of the button object
function Vdo_button_toggle:set_label_crc(new_label_crc)
if self.text_h ~= 0 then
vint_set_property(self.text_h, "text_tag_crc", new_label_crc)
end
end
-- Sets the highlighted state of the button to on or off (will eventually have grayed out here too)
function Vdo_button_toggle:set_highlight(is_highlighted)
if is_highlighted then
local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
if self.special ~= true then
self.icon1:set_color(0,0,0)
else
self.icon1:set_color(COLOR_ICON_SPECIAL)
end
if self.highlight_color ~= nil then
text_obj:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)
if self.special ~= true then
self.icon1:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)
end
self.icon2:set_color(self.highlight_color.R, self.highlight_color.G, self.highlight_color.B)
else
text_obj:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.B)
if self.special ~= true then
self.icon1:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.B)
end
self.icon2:set_color(COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.R, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.G, COLOR_PAUSE_BUTTON_TOGGLE_TEXT_SELECTED.B)
end
else
--HVS_JPM[KING] 12/11/2014: if we have a special color (for the invite friends screen) we will set the text to that instead of the regular list color (white or black)
local text_color = self.icon_color
if self.special_color ~= nil then
text_color = self.special_color
end
local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
text_obj:set_color(text_color.R, text_color.G, text_color.B)
if self.special ~= true then
self.icon1:set_color(self.icon_color.R, self.icon_color.G, self.icon_color.B)
else
self.icon1:set_color(COLOR_ICON_SPECIAL_DARK)
end
self.icon2:set_color(self.icon_color.R, self.icon_color.G, self.icon_color.B)
end
end
-- Sets the enabled state of the button to on or off
function Vdo_button_toggle:set_enabled(enabled)
local text = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
if enabled then
text:set_alpha(1)
--text:set_color(1,1,1)
else
text:set_alpha(0.35)
--text:set_color(.2,.2,.2)
end
end
function Vdo_button_toggle:set_alpha(alpha)
local text = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
text:set_alpha(alpha)
end
--HVS_JPM[KING] 12/11/2014: added special color param for none highlighted special text color (optional)
function Vdo_button_toggle:set_highlight_color(new_color, special_color)
self.highlight_color = new_color
self.special_color = special_color
end
-------------------------------------------------------------------------------
-- Function Vdo_button_toggle:set_icon()
--
-- Sets up to 2 icons on the button
--
-- @param icon1 -- First icon
-- @param icon2 -- Second icon
--
-- Icon types:
-- BUTTON_TOGGLE_ICON_TYPE_NONE = 0 --No Icon
-- BUTTON_TOGGLE_ICON_TYPE_LOCK = 1 --Lock icon
-- BUTTON_TOGGLE_ICON_TYPE_BOX = 2 --Checkbox
-- BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED = 3 --ChecboxChecked
-- BUTTON_TOGGLE_ICON_TYPE_INDENT = 4 --Indented (No Icon)
-- BUTTON_TOGGLE_ICON_TYPE_NEW = 5 --New item (exclamation point)
-- BUTTON_TOGGLE_ICON_TYPE_DLC = 6 --DLC item (fleur)
-- BUTTON_TOGGLE_ICON_TYPE_SPECIAL = 7 --Background highlight
-- BUTTON_TOGGLE_ICON_TYPE_COMPLETED = 8 --Grey checkboxChecked
-- BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED = 9 --Dual arrows
-- BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE = 10 --Square bullet point
-- BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP = 11 --2 with an Arrow
--
-------------------------------------------------------------------------------
function Vdo_button_toggle:set_icon(icon1, icon2)
local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
local text_obj_x, text_obj_y = text_obj:get_anchor()
local icon2_x, icon2_y = ICON2_ANCHOR_X, ICON2_ANCHOR_Y
local indent_count = 0
--Adjust for legacy icons - the checked box is offset by 2
self.icon2:set_anchor(ICON2_ANCHOR_X, -2)
self.icon2:set_alpha(1)
self.icon_color = COLOR_PAUSE_BUTTON_TOGGLE_TEXT_UNSELECTED
if icon1 == BUTTON_TOGGLE_ICON_TYPE_LOCK then
self.icon1:set_image("ui_store_icon_lock_sm")
self.icon1:set_visible(true)
self.icon_color = COLOR_ICON_LOCK
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_BOX then
self.icon1:set_image("ui_store_icon_box")
self.icon1:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED then
self.icon1:set_image("ui_store_icon_checkbox")
self.icon1:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_NEW then
self.icon1:set_image("ui_menu_tmp_arrow_e")
self.icon1:set_visible(true)
--self.icon_color = self.highlight_color
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_DLC then
self.icon1:set_image("ui_store_icon_dlc")
self.icon1:set_visible(true)
--self.icon_color = self.highlight_color
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_SPECIAL then
self.icon1:set_image("ui_blank")
self.icon1:set_property("auto_offset", "w")
self.icon1:set_scale(60, 1.6) -- Hacky, but works
self.icon1:set_visible(true)
local x, y = self.icon1:get_anchor()
self.icon1:set_anchor(x - 100, y) -- Hacky, but works
self.icon1:set_color(COLOR_ICON_SPECIAL_DARK)
self.special = true
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_COMPLETED then
self.icon1:set_image("ui_store_icon_checkbox")
self.icon1:set_visible(true)
self.icon_color = COLOR_ICON_COMPLETED
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED then
self.icon1:set_image("ui_quest_icon_pin")
self.icon1:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE then
self.icon1:set_image("ui_quest_icon_complete")
self.icon1:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
elseif icon1 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP then
self.icon1:set_image("ui_quest_icon_pin_coop")
self.icon1:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
else
self.icon1:set_visible(false)
end
-- If we set icon2 move the button text over as well
if icon2 == BUTTON_TOGGLE_ICON_TYPE_INDENT then
-- Indent the text to align with other text w/ checkboxes
text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y)
indent_count = indent_count + 1
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_DLC then
self.icon2:set_image("ui_store_icon_dlc")
self.icon2:set_visible(true)
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_LOCK then
text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y)
self.icon2:set_image("ui_store_icon_lock_sm")
self.icon2:set_visible(true)
self.icon_color = COLOR_ICON_LOCK
indent_count = indent_count + 1
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_BOX then
text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y)
self.icon2:set_anchor(ICON2_ANCHOR_X + 3, -2)
self.icon2:set_image("ui_store_icon_box")
self.icon2:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
indent_count = indent_count + 1
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_BOX_CHECKED then
text_obj:set_anchor(icon2_x + BUTTON_TOGGLE_LOCK_OFFSET, text_obj_y)
self.icon2:set_image("ui_store_icon_checkbox")
self.icon2:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
indent_count = indent_count + 1
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_COMPLETED then
self.icon2:set_image("ui_store_icon_checkbox")
self.icon2:set_visible(true)
self.icon_color = COLOR_ICON_COMPLETED
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED then
self.icon2:set_image("ui_quest_icon_pin")
self.icon2:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
indent_count = indent_count + 1
self.icon2:set_anchor(icon2_x, 0)
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_QUEST_COMPLETE then
self.icon2:set_image("ui_blank")
self.icon2:set_visible(true)
--Strike through the text
local label_width, label_height = element_get_actual_size(self.text_h)
vint_set_property(self.icon2.handle, "auto_offset", "w")
element_set_actual_size(self.icon2.handle, label_width * .8, 2)
self.icon2:set_anchor(ICON2_ANCHOR_X, ICON2_ANCHOR_Y)
self.icon_color = COLOR_ICON_CHECK
self.icon2:set_alpha(.35)
indent_count = indent_count + 1
elseif icon2 == BUTTON_TOGGLE_ICON_TYPE_QUEST_PINNED_COOP then
self.icon2:set_image("ui_quest_icon_pin_coop")
self.icon2:set_visible(true)
self.icon_color = COLOR_ICON_CHECK
indent_count = indent_count + 1
self.icon2:set_anchor(icon2_x, 0)
else
self.icon2:set_visible(false)
end
--Count how many times we were indented and add it to our text offset...
self.text_offset = indent_count * (BUTTON_TOGGLE_LOCK_OFFSET + icon2_x)
end
-------------------------------------------------------------------------------
-- returns the size of the first text element...
-------------------------------------------------------------------------------
function Vdo_button_toggle:get_text_width()
local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
local width, height = text_obj:get_actual_size()
--Size is the width of the text field plus the offset from the icon...
return width + self.text_offset
end
function Vdo_button_toggle:set_label_anchor(new_x)
local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
local toggle_text_x, toggle_text_y = text_obj:get_anchor()
text_obj:set_anchor(new_x, toggle_text_y)
end
function Vdo_button_toggle:get_label_anchor()
local text_obj = Vdo_base_object:new("toggle_text", self.handle, self.doc_handle)
return text_obj:get_anchor()
end
function Vdo_button_toggle:set_text_scale(scale)
local text_h = vint_object_find("toggle_text", self.handle, self.doc_handle)
vint_set_property(text_h, "text_scale", scale, scale)
end