initial commit
This commit is contained in:
163
Core/UI/Util/Contacts.lua
Normal file
163
Core/UI/Util/Contacts.lua
Normal file
@@ -0,0 +1,163 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local Contacts = TSM.UI.Util:NewPackage("Contacts")
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local String = TSM.Include("Util.String")
|
||||
local UIElements = TSM.Include("UI.UIElements")
|
||||
local private = {
|
||||
listElements = {},
|
||||
}
|
||||
local PLAYER_NAME = UnitName("player")
|
||||
local PLAYER_NAME_REALM = gsub(PLAYER_NAME.."-"..GetRealmName(), "%s+", "")
|
||||
local LIST_ENTRIES = {L["Recent"], L["Alts"], L["Friends"], L["Guild"]}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Functions
|
||||
-- ============================================================================
|
||||
|
||||
function Contacts.ShowDialog(button, input, callback)
|
||||
input:SetFocused(false)
|
||||
:Draw()
|
||||
button:GetBaseElement():ShowDialogFrame(UIElements.New("Frame", "frame")
|
||||
:SetLayout("VERTICAL")
|
||||
:SetSize(152, 90)
|
||||
:AddAnchor("TOP", button:_GetBaseFrame(), "BOTTOM", 0, -6)
|
||||
:SetBackgroundColor("FRAME_BG", true)
|
||||
:SetBorderColor("ACTIVE_BG")
|
||||
:SetContext(input)
|
||||
:AddChild(UIElements.New("ViewContainer", "contacts")
|
||||
:SetNavCallback(private.GetContactsContentFrame)
|
||||
:SetContext(callback)
|
||||
:AddPath("menu", true)
|
||||
:AddPath("list")
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Local Script Handlers
|
||||
-- ============================================================================
|
||||
|
||||
function private.GetContactsContentFrame(viewContainer, path)
|
||||
if path == "menu" then
|
||||
return private.GetContactsMenuFrame()
|
||||
elseif path == "list" then
|
||||
return private.GetContactListFrame()
|
||||
else
|
||||
error("Unexpected path: "..tostring(path))
|
||||
end
|
||||
end
|
||||
|
||||
function private.GetContactsMenuFrame()
|
||||
return UIElements.New("Frame", "frame")
|
||||
:SetLayout("VERTICAL")
|
||||
:SetPadding(1, 1, 5, 5)
|
||||
:AddChild(UIElements.New("SelectionList", "list")
|
||||
:SetBackgroundColor("FRAME_BG")
|
||||
:SetEntries(LIST_ENTRIES)
|
||||
:SetScript("OnEntrySelected", private.MenuOnEntrySelected)
|
||||
)
|
||||
end
|
||||
|
||||
function private.GetContactListFrame()
|
||||
return UIElements.New("Frame", "frame")
|
||||
:SetLayout("VERTICAL")
|
||||
:SetPadding(1, 1, 5, 5)
|
||||
:AddChild(UIElements.New("Button", "back")
|
||||
:SetHeight(20)
|
||||
:SetMargin(8, 0, 0, 0)
|
||||
:SetFont("BODY_BODY2_BOLD")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetText(L["Back"])
|
||||
:SetScript("OnClick", private.ListBackButtonOnClick)
|
||||
)
|
||||
:AddChild(UIElements.New("SelectionList", "list")
|
||||
:SetBackgroundColor("FRAME_BG")
|
||||
:SetEntries(private.listElements)
|
||||
:SetScript("OnEntrySelected", private.ListOnEntrySelected)
|
||||
)
|
||||
end
|
||||
|
||||
function private.MenuOnEntrySelected(list, name)
|
||||
private.GenerateListElements(name)
|
||||
|
||||
list:GetElement("__parent.__parent.__parent")
|
||||
:SetHeight(min((#private.listElements + 1) * 20 + 10, 130))
|
||||
:Draw()
|
||||
|
||||
list:GetElement("__parent.__parent")
|
||||
:SetPath("list", true)
|
||||
end
|
||||
|
||||
function private.ListBackButtonOnClick(button)
|
||||
button:GetElement("__parent.__parent.__parent")
|
||||
:SetHeight(90)
|
||||
:Draw()
|
||||
|
||||
button:GetElement("__parent.__parent")
|
||||
:SetPath("menu", true)
|
||||
end
|
||||
|
||||
function private.ListOnEntrySelected(list, name)
|
||||
local callback = list:GetElement("__parent.__parent"):GetContext()
|
||||
local input = list:GetElement("__parent.__parent.__parent"):GetContext()
|
||||
input:SetValue(name)
|
||||
:Draw()
|
||||
|
||||
if callback then
|
||||
callback(input)
|
||||
end
|
||||
|
||||
list:GetBaseElement():HideDialog()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.GenerateListElements(category)
|
||||
wipe(private.listElements)
|
||||
if category == L["Recent"] then
|
||||
for k in pairs(TSM.db.global.mailingOptions.recentlyMailedList) do
|
||||
local character = Ambiguate(k, "none")
|
||||
tinsert(private.listElements, character)
|
||||
end
|
||||
elseif category == L["Alts"] then
|
||||
for factionrealm in TSM.db:GetConnectedRealmIterator("realm") do
|
||||
for _, character in TSM.db:FactionrealmCharacterIterator(factionrealm) do
|
||||
character = Ambiguate(gsub(strmatch(character, "(.*) "..String.Escape("-")).."-"..gsub(factionrealm, String.Escape("-"), ""), " ", ""), "none")
|
||||
if character ~= UnitName("player") then
|
||||
tinsert(private.listElements, character)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif category == L["Friends"] then
|
||||
for i = 1, C_FriendList.GetNumFriends() do
|
||||
local info = C_FriendList.GetFriendInfoByIndex(i)
|
||||
if info.name ~= PLAYER_NAME_REALM then
|
||||
local character = Ambiguate(info.name, "none")
|
||||
tinsert(private.listElements, character)
|
||||
end
|
||||
end
|
||||
elseif category == L["Guild"] then
|
||||
for i = 1, GetNumGuildMembers() do
|
||||
local name = GetGuildRosterInfo(i)
|
||||
if name ~= PLAYER_NAME_REALM then
|
||||
local character = Ambiguate(name, "none")
|
||||
tinsert(private.listElements, character)
|
||||
end
|
||||
end
|
||||
end
|
||||
sort(private.listElements)
|
||||
end
|
||||
128
Core/UI/Util/Core.lua
Normal file
128
Core/UI/Util/Core.lua
Normal file
@@ -0,0 +1,128 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local Util = TSM.UI:NewPackage("Util")
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Color = TSM.Include("Util.Color")
|
||||
local Theme = TSM.Include("Util.Theme")
|
||||
local private = {}
|
||||
local THEME_COLOR_SETS = {
|
||||
{
|
||||
key = "midnight",
|
||||
name = L["Midnight"],
|
||||
colors = {
|
||||
PRIMARY_BG = Color.NewFromHex("#000000"),
|
||||
PRIMARY_BG_ALT = Color.NewFromHex("#121212"),
|
||||
FRAME_BG = Color.NewFromHex("#232323"),
|
||||
ACTIVE_BG = Color.NewFromHex("#404046"),
|
||||
ACTIVE_BG_ALT = Color.NewFromHex("#a0a0a0"),
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "duskwood",
|
||||
name = L["Duskwood"],
|
||||
colors = {
|
||||
PRIMARY_BG = Color.NewFromHex("#000000"),
|
||||
PRIMARY_BG_ALT = Color.NewFromHex("#2e2e2e"),
|
||||
FRAME_BG = Color.NewFromHex("#404040"),
|
||||
ACTIVE_BG = Color.NewFromHex("#585858"),
|
||||
ACTIVE_BG_ALT = Color.NewFromHex("#9d9d9d"),
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "dalaran",
|
||||
name = L["Dalaran"],
|
||||
colors = {
|
||||
PRIMARY_BG = Color.NewFromHex("#15141f"),
|
||||
PRIMARY_BG_ALT = Color.NewFromHex("#262537"),
|
||||
FRAME_BG = Color.NewFromHex("#35334d"),
|
||||
ACTIVE_BG = Color.NewFromHex("#4a476c"),
|
||||
ACTIVE_BG_ALT = Color.NewFromHex("#958fd9"),
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "swampOfSorrows",
|
||||
name = L["Swamp of Sorrows"],
|
||||
colors = {
|
||||
PRIMARY_BG = Color.NewFromHex("#151e1b"),
|
||||
PRIMARY_BG_ALT = Color.NewFromHex("#273430"),
|
||||
FRAME_BG = Color.NewFromHex("#364942"),
|
||||
ACTIVE_BG = Color.NewFromHex("#567551"),
|
||||
ACTIVE_BG_ALT = Color.NewFromHex("#B5B28C"),
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "orgrimmar",
|
||||
name = L["Orgrimmar"],
|
||||
colors = {
|
||||
PRIMARY_BG = Color.NewFromHex("#120908"),
|
||||
PRIMARY_BG_ALT = Color.NewFromHex("#40221b"),
|
||||
FRAME_BG = Color.NewFromHex("#6F3A2F"),
|
||||
ACTIVE_BG = Color.NewFromHex("#A25B3E"),
|
||||
ACTIVE_BG_ALT = Color.NewFromHex("#E1D4C4"),
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "stormwind",
|
||||
name = L["Stormwind"],
|
||||
colors = {
|
||||
PRIMARY_BG = Color.NewFromHex("#191a1a"),
|
||||
PRIMARY_BG_ALT = Color.NewFromHex("#2b3131"),
|
||||
FRAME_BG = Color.NewFromHex("#4C585C"),
|
||||
ACTIVE_BG = Color.NewFromHex("#6B7673"),
|
||||
ACTIVE_BG_ALT = Color.NewFromHex("#D9DCD3"),
|
||||
},
|
||||
},
|
||||
{
|
||||
key = "winamp",
|
||||
name = L["Winamp"],
|
||||
colors = {
|
||||
PRIMARY_BG = Color.NewFromHex("#000000"),
|
||||
PRIMARY_BG_ALT = Color.NewFromHex("#1B1B2A"),
|
||||
FRAME_BG = Color.NewFromHex("#383858"),
|
||||
ACTIVE_BG = Color.NewFromHex("#6a6a7a"),
|
||||
ACTIVE_BG_ALT = Color.NewFromHex("#bdced6"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Functions
|
||||
-- ============================================================================
|
||||
|
||||
function Util.OnInitialize()
|
||||
-- register themes
|
||||
local foundCurrentColorSet = false
|
||||
for _, info in ipairs(THEME_COLOR_SETS) do
|
||||
Theme.RegisterColorSet(info.key, info.name, info.colors)
|
||||
foundCurrentColorSet = foundCurrentColorSet or info.key == TSM.db.global.appearanceOptions.colorSet
|
||||
end
|
||||
if not foundCurrentColorSet then
|
||||
TSM.db.global.appearanceOptions.colorSet = TSM.db:GetDefaultReadOnly("global", "appearanceOptions", "colorSet")
|
||||
end
|
||||
Theme.SetActiveColorSet(TSM.db.global.appearanceOptions.colorSet)
|
||||
end
|
||||
|
||||
function Util.ColorSetIterator()
|
||||
return private.ColorSetIterator, THEME_COLOR_SETS, 0
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.ColorSetIterator(tbl, index)
|
||||
index = index + 1
|
||||
if not tbl[index] then
|
||||
return
|
||||
end
|
||||
return index, tbl[index].key, tbl[index].name
|
||||
end
|
||||
146
Core/UI/Util/QueryScrollingTableInfo.lua
Normal file
146
Core/UI/Util/QueryScrollingTableInfo.lua
Normal file
@@ -0,0 +1,146 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local ObjectPool = TSM.Include("Util.ObjectPool")
|
||||
local QueryScrollingTableInfo = TSM.Include("LibTSMClass").DefineClass("QueryScrollingTableInfo", TSM.UI.Util.ScrollingTableInfo)
|
||||
local QueryScrollingTableColumnInfo = TSM.Include("LibTSMClass").DefineClass("QueryScrollingTableColumnInfo", TSM.UI.Util.ScrollingTableColumnInfo)
|
||||
TSM.UI.Util.QueryScrollingTableInfo = QueryScrollingTableInfo
|
||||
QueryScrollingTableInfo._COL_INFO_POOL = ObjectPool.New("QUERY_SCROLLING_TABLE_COL_INFO", QueryScrollingTableColumnInfo, 1)
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- QueryScrollingTableColumnInfo Class
|
||||
-- ============================================================================
|
||||
|
||||
function QueryScrollingTableColumnInfo.__init(self)
|
||||
self.__super:__init()
|
||||
self._textField = nil
|
||||
self._iconField = nil
|
||||
self._tooltipField = nil
|
||||
self._sortField = nil
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo._Release(self)
|
||||
self.__super:_Release()
|
||||
self._textField = nil
|
||||
self._iconField = nil
|
||||
self._tooltipField = nil
|
||||
self._sortField = nil
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo.SetTextFunction(self)
|
||||
error("This method is not allowed for QueryScrollingTableColumnInfo")
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo.SetIconFunction(self, func)
|
||||
error("This method is not allowed for QueryScrollingTableColumnInfo")
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo.SetTooltipFunction(self, func)
|
||||
error("This method is not allowed for QueryScrollingTableColumnInfo")
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo.SetTextInfo(self, field, func)
|
||||
self._textField = field
|
||||
self._textFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo.SetIconInfo(self, field, func)
|
||||
self._iconField = field
|
||||
self._iconFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo.SetTooltipInfo(self, field, func)
|
||||
self._tooltipField = field
|
||||
self._tooltipFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo.SetSortInfo(self, field)
|
||||
self._sortField = field
|
||||
return self
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo._GetSortField(self)
|
||||
return self._sortField
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo._HasText(self)
|
||||
return (self._textField or self._textFunc) and true or false
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo._HasTooltip(self)
|
||||
return (self._tooltipField or self._tooltipFunc) and true or false
|
||||
end
|
||||
|
||||
function QueryScrollingTableColumnInfo._GetValueHelper(self, dataType, context, ...)
|
||||
local value = self._element._query:GetResultRowByUUID(context)
|
||||
local field, func = nil, nil
|
||||
if dataType == "text" then
|
||||
field = self._textField
|
||||
func = self._textFunc
|
||||
elseif dataType == "icon" then
|
||||
field = self._iconField
|
||||
func = self._iconFunc
|
||||
elseif dataType == "tooltip" then
|
||||
field = self._tooltipField
|
||||
func = self._tooltipFunc
|
||||
elseif dataType == "expanderState" then
|
||||
return self._expanderStateFunc(self._element, value)
|
||||
elseif dataType == "badgeState" then
|
||||
return self._badgeStateFunc(self._element, value)
|
||||
elseif dataType == "actionIcon" then
|
||||
local index, isMouseOver = ...
|
||||
return self._actionIconFunc(self._element, context, index, isMouseOver)
|
||||
else
|
||||
error("Unknown dataType: "..tostring(dataType))
|
||||
end
|
||||
|
||||
if field then
|
||||
value = value:GetField(field)
|
||||
end
|
||||
if func then
|
||||
value = func(value, ...)
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- QueryScrollingTableInfo Class
|
||||
-- ============================================================================
|
||||
|
||||
function QueryScrollingTableInfo._IsSortEnabled(self)
|
||||
for _, col in ipairs(self._cols) do
|
||||
if col:_GetSortField() then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function QueryScrollingTableInfo._GetSortFieldById(self, id)
|
||||
for _, col in ipairs(self._cols) do
|
||||
if col:_GetId() == id then
|
||||
return col:_GetSortField()
|
||||
end
|
||||
end
|
||||
error("Unknown id: "..tostring(id))
|
||||
end
|
||||
|
||||
function QueryScrollingTableInfo._GetIdBySortField(self, field)
|
||||
for _, col in ipairs(self._cols) do
|
||||
if col:_GetSortField() == field then
|
||||
return col:_GetId()
|
||||
end
|
||||
end
|
||||
error("Unknown field: "..tostring(field))
|
||||
end
|
||||
522
Core/UI/Util/ScrollingTableInfo.lua
Normal file
522
Core/UI/Util/ScrollingTableInfo.lua
Normal file
@@ -0,0 +1,522 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local ObjectPool = TSM.Include("Util.ObjectPool")
|
||||
local Theme = TSM.Include("Util.Theme")
|
||||
local ScrollingTableInfo = TSM.Include("LibTSMClass").DefineClass("ScrollingTableInfo")
|
||||
local ScrollingTableColumnInfo = TSM.Include("LibTSMClass").DefineClass("ScrollingTableColumnInfo")
|
||||
TSM.UI.Util.ScrollingTableInfo = ScrollingTableInfo
|
||||
TSM.UI.Util.ScrollingTableColumnInfo = ScrollingTableColumnInfo
|
||||
ScrollingTableInfo._COL_INFO_POOL = ObjectPool.New("SCROLLING_TABLE_COL_INFO", ScrollingTableColumnInfo, 1)
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- ScrollingTableColumnInfo Class
|
||||
-- ============================================================================
|
||||
|
||||
function ScrollingTableColumnInfo.__init(self)
|
||||
-- general
|
||||
self._tableInfo = nil
|
||||
self._id = nil
|
||||
self._element = nil
|
||||
self._tooltipLinkingDisabled = false
|
||||
self._expanderStateFunc = nil
|
||||
self._flagStateFunc = nil
|
||||
self._checkStateFunc = nil
|
||||
self._badgeStateFunc = nil
|
||||
self._iconHoverEnabled = false
|
||||
self._iconClickHandler = nil
|
||||
self._numActionIcons = 0
|
||||
self._actionIconSize = nil
|
||||
self._actionIconFunc = nil
|
||||
self._actionIconShowOnHover = false
|
||||
self._actionIconClickHandler = nil
|
||||
self._hidden = false
|
||||
self._hidingDisabled = false
|
||||
-- style
|
||||
self._width = nil
|
||||
self._justifyH = nil
|
||||
self._iconSize = nil
|
||||
self._font = nil
|
||||
self._headerIndent = nil
|
||||
-- header
|
||||
self._title = nil
|
||||
self._titleIcon = nil
|
||||
self._headerTooltip = nil
|
||||
-- content functions
|
||||
self._textFunc = nil
|
||||
self._iconFunc = nil
|
||||
self._tooltipFunc = nil
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._Acquire(self, tableInfo, id, element)
|
||||
self._tableInfo = tableInfo
|
||||
self._id = id
|
||||
self._element = element
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._Release(self)
|
||||
self._tableInfo = nil
|
||||
self._id = nil
|
||||
self._element = nil
|
||||
self._tooltipLinkingDisabled = false
|
||||
self._expanderStateFunc = nil
|
||||
self._flagStateFunc = nil
|
||||
self._checkStateFunc = nil
|
||||
self._badgeStateFunc = nil
|
||||
self._iconHoverEnabled = false
|
||||
self._iconClickHandler = nil
|
||||
self._numActionIcons = 0
|
||||
self._actionIconSize = nil
|
||||
self._actionIconFunc = nil
|
||||
self._actionIconShowOnHover = false
|
||||
self._actionIconClickHandler = nil
|
||||
self._hidden = false
|
||||
self._hidingDisabled = false
|
||||
self._width = nil
|
||||
self._justifyH = nil
|
||||
self._iconSize = nil
|
||||
self._font = nil
|
||||
self._headerIndent = nil
|
||||
self._title = nil
|
||||
self._titleIcon = nil
|
||||
self._headerTooltip = nil
|
||||
self._textFunc = nil
|
||||
self._iconFunc = nil
|
||||
self._tooltipFunc = nil
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetTitle(self, title)
|
||||
self._title = title
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetTitleIcon(self, icon)
|
||||
self._titleIcon = icon
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetWidth(self, width)
|
||||
assert(type(width) == "number")
|
||||
self._width = width
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetAutoWidth(self)
|
||||
self._width = true
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetJustifyH(self, justifyH)
|
||||
self._justifyH = justifyH
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetIconSize(self, iconSize)
|
||||
self._iconSize = iconSize
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetIconHoverEnabled(self, enabled)
|
||||
self._iconHoverEnabled = enabled
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetIconClickHandler(self, handler)
|
||||
self._iconClickHandler = handler
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetFont(self, font)
|
||||
self._font = font
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetHeaderIndent(self, headerIndent)
|
||||
self._headerIndent = headerIndent
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetTextFunction(self, func)
|
||||
self._textFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetIconFunction(self, func)
|
||||
self._iconFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetHeaderTooltip(self, tooltip)
|
||||
self._headerTooltip = tooltip
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetTooltipFunction(self, func)
|
||||
self._tooltipFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetTooltipLinkingDisabled(self, disabled)
|
||||
self._tooltipLinkingDisabled = disabled
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetExpanderStateFunction(self, func)
|
||||
self._expanderStateFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetFlagStateFunction(self, func)
|
||||
self._flagStateFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetCheckStateFunction(self, func)
|
||||
self._checkStateFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetBadgeStateFunction(self, func)
|
||||
self._badgeStateFunc = func
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetActionIconInfo(self, numIcons, iconSize, func, showOnHover)
|
||||
self._numActionIcons = numIcons
|
||||
self._actionIconSize = iconSize
|
||||
self._actionIconFunc = func
|
||||
self._actionIconShowOnHover = showOnHover
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.SetActionIconClickHandler(self, handler)
|
||||
self._actionIconClickHandler = handler
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.DisableHiding(self)
|
||||
assert(not self._hidden)
|
||||
self._hidingDisabled = true
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo.Commit(self)
|
||||
return self._tableInfo
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetId(self)
|
||||
return self._id
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._IsHidden(self)
|
||||
return self._hidden
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._CanHide(self)
|
||||
return not self._hidingDisabled
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetTitle(self)
|
||||
return self._title
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetTitleIcon(self)
|
||||
return self._titleIcon
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetWidth(self)
|
||||
return self._width
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetJustifyH(self)
|
||||
return self._justifyH
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetIconSize(self)
|
||||
return self._iconSize
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._IsIconHoverEnabled(self)
|
||||
return self._iconHoverEnabled
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._OnIconClick(self, context, mouseButton)
|
||||
self._iconClickHandler(self._element, context, mouseButton)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetWowFont(self)
|
||||
return Theme.GetFont(self._font):GetWowFont()
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetHeaderIndent(self)
|
||||
return self._headerIndent
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._HasText(self)
|
||||
return self._textFunc and true or false
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetText(self, context)
|
||||
return self:_GetValueHelper("text", context)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetIcon(self, context, isMouseOver)
|
||||
return self:_GetValueHelper("icon", context, isMouseOver)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetHeaderTooltip(self)
|
||||
return self._headerTooltip
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._HasTooltip(self)
|
||||
return self._tooltipFunc and true or false
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetTooltip(self, context)
|
||||
return self:_GetValueHelper("tooltip", context)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetTooltipLinkingDisabled(self)
|
||||
return self._tooltipLinkingDisabled
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._HasExpander(self)
|
||||
return self._expanderStateFunc and true or false
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetExpanderState(self, context)
|
||||
if not self._expanderStateFunc then
|
||||
return
|
||||
end
|
||||
return self:_GetValueHelper("expanderState", context)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._HasFlag(self)
|
||||
return self._flagStateFunc and true or false
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetFlagState(self, context, isMouseOverRow)
|
||||
if not self._flagStateFunc then
|
||||
return
|
||||
end
|
||||
return self:_GetValueHelper("flagState", context, isMouseOverRow)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._HasCheck(self)
|
||||
return self._checkStateFunc and true or false
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetCheckState(self, context)
|
||||
if not self._checkStateFunc then
|
||||
return
|
||||
end
|
||||
return self:_GetValueHelper("checkState", context)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._HasBadge(self)
|
||||
return self._badgeStateFunc and true or false
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetBadgeState(self, context)
|
||||
if not self._badgeStateFunc then
|
||||
return
|
||||
end
|
||||
return self:_GetValueHelper("badgeState", context)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetActionIconInfo(self)
|
||||
return self._numActionIcons, self._actionIconSize, self._actionIconShowOnHover
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetActionIcon(self, context, index, isMouseOver)
|
||||
if not self._actionIconFunc then
|
||||
return
|
||||
end
|
||||
return self:_GetValueHelper("actionIcon", context, index, isMouseOver)
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._OnActionButtonClick(self, context, index, mouseButton)
|
||||
if self._actionIconClickHandler then
|
||||
self._actionIconClickHandler(self._element, context, index, mouseButton)
|
||||
end
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._GetValueHelper(self, dataType, context, ...)
|
||||
if dataType == "text" then
|
||||
return self._textFunc and self._textFunc(self._element, context) or ""
|
||||
elseif dataType == "icon" then
|
||||
local isMouseOver = ...
|
||||
return self._iconFunc(self._element, context, isMouseOver)
|
||||
elseif dataType == "tooltip" then
|
||||
if not self._tooltipFunc then
|
||||
return nil
|
||||
end
|
||||
return self._tooltipFunc(self._element, context)
|
||||
elseif dataType == "expanderState" then
|
||||
return self._expanderStateFunc(self._element, context)
|
||||
elseif dataType == "flagState" then
|
||||
local isMouseOverRow = ...
|
||||
return self._flagStateFunc(self._element, context, isMouseOverRow)
|
||||
elseif dataType == "checkState" then
|
||||
return self._checkStateFunc(self._element, context)
|
||||
elseif dataType == "badgeState" then
|
||||
return self._badgeStateFunc(self._element, context)
|
||||
elseif dataType == "actionIcon" then
|
||||
local index, isMouseOver = ...
|
||||
return self._actionIconFunc(self._element, context, index, isMouseOver)
|
||||
else
|
||||
error("Unknown dataType: "..tostring(dataType))
|
||||
end
|
||||
end
|
||||
|
||||
function ScrollingTableColumnInfo._SetHidden(self, hidden)
|
||||
assert(not self._hidingDisabled)
|
||||
self._hidden = hidden
|
||||
self._tableInfo:_UpdateHiddenCols()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- ScrollingTableInfo Class
|
||||
-- ============================================================================
|
||||
|
||||
function ScrollingTableInfo.__init(self)
|
||||
self._cols = {}
|
||||
self._visibleCols = {}
|
||||
self._hiddenCols = {}
|
||||
self._element = nil
|
||||
self._cursor = nil
|
||||
self._menuIterator = nil
|
||||
self._menuClickHandler = nil
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._Acquire(self, element)
|
||||
self._element = element
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._Release(self)
|
||||
for _, col in ipairs(self._cols) do
|
||||
col:_Release()
|
||||
self._COL_INFO_POOL:Recycle(col)
|
||||
end
|
||||
wipe(self._cols)
|
||||
wipe(self._visibleCols)
|
||||
wipe(self._hiddenCols)
|
||||
self._element = nil
|
||||
self._cursor = nil
|
||||
self._menuIterator = nil
|
||||
self._menuClickHandler = nil
|
||||
end
|
||||
|
||||
function ScrollingTableInfo.NewColumn(self, id, prepend)
|
||||
local col = self._COL_INFO_POOL:Get()
|
||||
col:_Acquire(self, id, self._element)
|
||||
if prepend then
|
||||
tinsert(self._cols, 1, col)
|
||||
else
|
||||
tinsert(self._cols, col)
|
||||
end
|
||||
return col
|
||||
end
|
||||
|
||||
function ScrollingTableInfo.RemoveColumn(self, id)
|
||||
local index = nil
|
||||
for i, col in ipairs(self._cols) do
|
||||
if col:_GetId() == id then
|
||||
assert(not index)
|
||||
index = i
|
||||
end
|
||||
end
|
||||
assert(index)
|
||||
local col = tremove(self._cols, index)
|
||||
col:_Release()
|
||||
self._COL_INFO_POOL:Recycle(col)
|
||||
self:_UpdateHiddenCols()
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableInfo.SetCursor(self, cursor)
|
||||
self._cursor = cursor
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableInfo.SetMenuInfo(self, iterator, clickHandler)
|
||||
if not iterator and not clickHandler then
|
||||
self._menuIterator = nil
|
||||
self._menuClickHandler = nil
|
||||
return self
|
||||
end
|
||||
assert(type(iterator) == "function" and type(clickHandler) == "function")
|
||||
self._menuIterator = iterator
|
||||
self._menuClickHandler = clickHandler
|
||||
return self
|
||||
end
|
||||
|
||||
function ScrollingTableInfo.Commit(self)
|
||||
self:_UpdateHiddenCols()
|
||||
return self._element:CommitTableInfo()
|
||||
end
|
||||
|
||||
function ScrollingTableInfo.GetColById(self, id)
|
||||
for _, col in ipairs(self._cols) do
|
||||
if col:_GetId() == id then
|
||||
return col
|
||||
end
|
||||
end
|
||||
error("Unknown id: "..tostring(id))
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._GetCols(self)
|
||||
return self._cols
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._ColIterator(self)
|
||||
return ipairs(self._cols)
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._VisibleColIterator(self)
|
||||
return ipairs(self._visibleCols)
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._HiddenColIterator(self)
|
||||
return ipairs(self._hiddenCols)
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._GetVisibleCols(self)
|
||||
return self._visibleCols
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._GetCursor(self)
|
||||
return self._cursor
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._UpdateHiddenCols(self)
|
||||
wipe(self._visibleCols)
|
||||
wipe(self._hiddenCols)
|
||||
for _, col in ipairs(self._cols) do
|
||||
if col:_IsHidden() then
|
||||
tinsert(self._hiddenCols, col)
|
||||
else
|
||||
tinsert(self._visibleCols, col)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._MenuDialogIterator(self, prevIndex)
|
||||
if not self._menuIterator then
|
||||
return
|
||||
end
|
||||
return self._menuIterator(self._element, prevIndex)
|
||||
end
|
||||
|
||||
function ScrollingTableInfo._HandleMenuButtonClick(self, index1, index2)
|
||||
assert(self._menuClickHandler)
|
||||
self._menuClickHandler(self._element, index1, index2)
|
||||
end
|
||||
1476
Core/UI/Util/TableRow.lua
Normal file
1476
Core/UI/Util/TableRow.lua
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user