Skip to content

Instantly share code, notes, and snippets.

@merlight
Created February 12, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merlight/d2faf30475afc7440158 to your computer and use it in GitHub Desktop.
Save merlight/d2faf30475afc7440158 to your computer and use it in GitHub Desktop.
local wm = WINDOW_MANAGER
local PRIVATE = {}
local function df(...)
d(string.format(...))
end
function PRIVATE.init()
local panelName = "SOUNDS"
local panelData = {name = panelName}
local panelId = KEYBOARD_OPTIONS.currentPanelId
KEYBOARD_OPTIONS.currentPanelId = KEYBOARD_OPTIONS.currentPanelId + 1
KEYBOARD_OPTIONS.panelNames[panelId] = panelName
local listPopulated = false
function panelData.callback()
local fragment = PRIVATE.getSoundsWindowFragment()
SCENE_MANAGER:AddFragment(fragment)
KEYBOARD_OPTIONS:ChangePanels(panelId)
local tlw = fragment:GetControl()
local title = tlw:GetNamedChild("Title")
title:SetText(panelName)
if not listPopulated then
PRIVATE.populateSoundList(tlw:GetNamedChild("SoundList"))
listPopulated = true
end
end
function panelData.unselectedCallback()
SCENE_MANAGER:RemoveFragment(PRIVATE.getSoundsWindowFragment())
SetCameraOptionsPreviewModeEnabled(false)
end
ZO_GameMenu_AddSettingPanel(panelData)
end
function PRIVATE.createSoundList(name, parent)
local list = wm:CreateControlFromVirtual(name, parent, "ZO_ScrollList")
ZO_PreHook(list.scrollbar, "SetThumbTextureHeight", function(self, height)
df("|c33ff33%s", self:GetName())
df(":SetThumbTextureHeight(%s)", tostring(height))
df("self:GetHeight() == %s, :GetDesiredHeight() == %s", self:GetHeight(), self:GetDesiredHeight())
df("list:GetHeight() == %s, :GetDesiredHeight() == %s", list:GetHeight(), list:GetDesiredHeight())
df("list.windowHeight == %s", tostring(list.windowHeight))
local _, loc = pcall(error, "no error", 4)
loc = loc:gsub(".-(stack traceback)", "|cff3333%1")
loc = loc:gsub("%S+/(%S+%.lua:)", "|cff3333> |c999999%1")
df("%s", loc)
end)
local function listRow_OnMouseDown(control, button)
if button == 1 then
local data = ZO_ScrollList_GetData(control)
local sound = SOUNDS[data.soundName]
if sound then
PlaySound(sound)
LAMTestLastPlayedSound = sound
end
ZO_ScrollList_SelectData(list, data, control)
end
end
local function listRow_Select(previouslySelectedData, selectedData, reselectingDuringRebuild)
if not reselectingDuringRebuild then
ZO_ScrollList_RefreshVisible(list, nil,
function(control, data, list)
control:SetSelected(data == selectedData)
end)
end
end
local function listRow_Setup(control, data, list)
control:SetHandler("OnMouseDown", listRow_OnMouseDown)
control:SetHeight(28)
control:SetFont("ZoFontWinH4")
control:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
control:SetVerticalAlignment(TEXT_ALIGN_CENTER)
control:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS)
control:SetText(data.index .. " " .. data.soundName)
control:SetSelected(ZO_ScrollList_IsDataSelected(list, data))
end
ZO_ScrollList_AddDataType(list, 1, "ZO_SelectableLabel", 28, listRow_Setup)
ZO_ScrollList_EnableSelection(list, "ZO_ThinListHighlight", listRow_Select)
return list
end
function PRIVATE.createSoundsWindow()
local tlw = wm:CreateTopLevelWindow("LAMSoundsWindow")
tlw:SetHidden(true)
tlw:SetDimensions(768, 914) -- same size as ZO_OptionsWindow
--ZO_ReanchorControlForLeftSidePanel(tlw)
local bgLeft = wm:CreateControl("$(parent)BackgroundLeft", tlw, CT_TEXTURE)
bgLeft:SetTexture("EsoUI/Art/Login/login_UIWindowBG_left.dds")
bgLeft:SetDimensions(512, 1024)
bgLeft:SetAnchor(TOPLEFT, nil, TOPLEFT)
bgLeft:SetDrawLayer(DL_BACKGROUND)
bgLeft:SetExcludeFromResizeToFitExtents(true)
local bgRight = wm:CreateControl("$(parent)BackgroundRight", tlw, CT_TEXTURE)
bgRight:SetTexture("EsoUI/Art/Login/login_UIWindowBG_right.dds")
bgRight:SetDimensions(256, 1024)
bgRight:SetAnchor(TOPLEFT, bgLeft, TOPRIGHT)
bgRight:SetDrawLayer(DL_BACKGROUND)
bgRight:SetExcludeFromResizeToFitExtents(true)
local title = wm:CreateControl("$(parent)Title", tlw, CT_LABEL)
title:SetAnchor(TOPLEFT, nil, TOPLEFT, 65, 70)
title:SetFont("ZoFontWinH1")
title:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
local divider = wm:CreateControlFromVirtual("$(parent)Divider", tlw, "ZO_Options_Divider")
divider:SetAnchor(TOPLEFT, title, BOTTOMLEFT, 0, 2)
-- create scrollable sound list
local list = PRIVATE.createSoundList("$(parent)SoundList", tlw)
list:SetAnchor(TOPLEFT, divider, BOTTOMLEFT, 0, 5)
list:SetAnchor(BOTTOMRIGHT, tlw, BOTTOMRIGHT, -120, -120)
return tlw
end
function PRIVATE.populateSoundList(list)
local entryList = ZO_ScrollList_GetDataList(list)
for k, v in pairs(SOUNDS) do
local data = {soundName = k}
local entry = ZO_ScrollList_CreateDataEntry(1, data)
table.insert(entryList, entry)
if #entryList >= 26 then
break
end
end
table.sort(entryList,
function(a, b)
return a.data.soundName < b.data.soundName
end)
for i, entry in ipairs(entryList) do
entry.data.index = i
end
ZO_ScrollList_Commit(list)
end
function PRIVATE.getSoundsWindow()
if not LAMSoundsWindow then
PRIVATE.createSoundsWindow()
end
return LAMSoundsWindow
end
function PRIVATE.getSoundsWindowFragment()
if not LAMSoundsWindowFragment then
local tlw = PRIVATE.getSoundsWindow()
--ZO_ReanchorControlForLeftSidePanel(tlw)
-- ok so the ZO_ReanchorWhatever is not the problem here,
-- simple fixed anchor breaks the scroll bar as well
tlw:SetAnchor(TOPLEFT, nil, TOPLEFT, 245, 100)
LAMSoundsWindowFragment = ZO_FadeSceneFragment:New(tlw)
end
return LAMSoundsWindowFragment
end
PRIVATE.init()
EVENT_MANAGER:RegisterForEvent("LAMSoundList_Loaded", EVENT_ADD_ON_LOADED,
function(event, addonName)
if addonName:find("^ZO_") then return end
EVENT_MANAGER:UnregisterForEvent("LAMSoundList_Loaded", EVENT_ADD_ON_LOADED)
if "want broken scrollbar" then
PRIVATE.getSoundsWindowFragment()
-- ^ this wraps the window in a fragment, and also anchors it,
-- which appears to cause the scroll bar desync issue, because
-- when the fragment is added to scene manager for the first time
-- and the list is populated, it has the wrong height
else
PRIVATE.getSoundsWindow()
-- ^ this only creates the window, doesn't anchor it
end
end)
SLASH_COMMANDS["/fixlist"] = function()
local tlw = PRIVATE.getSoundsWindow()
local list = tlw:GetNamedChild("SoundList")
ZO_ScrollList_Commit(list)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment