media: trim paths from display

This commit is contained in:
Sattva
2025-05-18 05:49:06 +03:00
parent 9fba331bf7
commit d518a7fe1a
+167 -127
View File
@@ -15171,6 +15171,35 @@ function LeaPlusLC:RunOnce()
---------------------------------------------------------------------- ----------------------------------------------------------------------
function LeaPlusLC:MediaFunc() function LeaPlusLC:MediaFunc()
-- Helper function for shortening paths in debug prints
local function getShortDisplayPathForDebug(fullPathString)
-- Ensure it's a string before trying string operations
if type(fullPathString) ~= "string" then
return tostring(fullPathString) -- Convert non-strings to string for printing
end
-- Only attempt to shorten if it looks like a track path we expect to shorten
-- (e.g., contains a # for duration or .mp3, and likely a / for a path)
if not (strfind(fullPathString, "#") and strfind(fullPathString, "/")) and
not (string.lower(fullPathString):find(".mp3") and strfind(fullPathString, "/")) then
return fullPathString -- Return as is if it doesn't look like a full path to shorten
end
local prefix = ""
local contentToShorten = fullPathString
-- Check for color code prefix like "|CffffffaaZone Name |rActualPath"
local p, t = fullPathString:match("^(.-|r)(.*)$")
if p and t and t ~= "" then -- Ensure both parts were captured and 't' (the path part) is not empty
prefix = p
contentToShorten = t
end
-- Remove path, keep filename.mp3#duration (or whatever is after the last /)
local filenamePart = contentToShorten:gsub(".*/", "")
return prefix .. filenamePart
end
-- Create tables for list data and zone listing -- Create tables for list data and zone listing
local ListData, playlist = {}, {} local ListData, playlist = {}, {}
@@ -15187,7 +15216,6 @@ function LeaPlusLC:RunOnce()
local ZoneList = Leatrix_Plus["ZoneList"] local ZoneList = Leatrix_Plus["ZoneList"]
-- Show relevant list items -- Show relevant list items
-- Replace your UpdateList entirely with this:
local function UpdateList() local function UpdateList()
FauxScrollFrame_Update(scrollFrame, #ListData, numButtons, 16) FauxScrollFrame_Update(scrollFrame, #ListData, numButtons, 16)
for index = 1, numButtons do for index = 1, numButtons do
@@ -15196,57 +15224,79 @@ function LeaPlusLC:RunOnce()
button.index = offset button.index = offset
if offset <= #ListData then if offset <= #ListData then
local text = ListData[offset].zone or ListData[offset] local rawItem = ListData[offset]
local displayText = ""
local itemIsValid = true
-- Set the text and immediately reset its color to white: if type(rawItem) == "table" and rawItem.zone then
button:SetText(text) displayText = rawItem.zone
button:GetFontString():SetTextColor(1.0, 1.0, 1.0) elseif type(rawItem) == "string" then
if strfind(rawItem, "#") then -- It's a track string
local prefix = ""
local trackPathWithDuration = rawItem
local p, t = rawItem:match("^(.-|r)(.*)$")
if p and t and t ~= "" then
prefix = p
trackPathWithDuration = t
end
-- highlighttexture sizing local filenameWithExtensionAndDuration = trackPathWithDuration:gsub(".*/", "")
if button:GetTextWidth() > 290 then local filenameOnly = filenameWithExtensionAndDuration:match("([^%.#]+)") -- Get text before first . or #
button.t:SetSize(290, 16) displayText = prefix .. (filenameOnly or filenameWithExtensionAndDuration) -- Fallback if no . or #
else
displayText = rawItem -- Headings or simple zone names
end
else else
button.t:SetSize(button:GetTextWidth(), 16) button:Hide()
itemIsValid = false
end end
button:Show() if itemIsValid then
button.s:Hide() button:SetText(displayText)
button:GetFontString():SetTextColor(1.0, 1.0, 1.0)
if strfind(text, "|c") then local currentTextWidth = button:GetTextWidth()
button.t:Hide() if currentTextWidth > 290 then
button.t:SetSize(290, 16)
else
button.t:SetSize(currentTextWidth, 16)
end
button:Show()
button.s:Hide()
if strfind(displayText, "|c") then
button.t:Hide()
end
if LastPlayed == rawItem and ListData[1] == HeadingOfClickedTrack then
button.s:Show()
button:GetFontString():SetTextColor(1.0, 0.82, 0.0)
end
if LastFolder == displayText then
button.s:Show()
end
if currentTextWidth > 290 then
button.s:SetSize(290, 16)
else
button.s:SetSize(currentTextWidth, 16)
end
local bWidth = button:GetFontString():GetStringWidth() or 0
if bWidth > 290 then bWidth = 290 end
button:SetHitRectInsets(0, 454 - bWidth, 0, 0)
button:SetPushedTextOffset(0, 0)
button:GetFontString():SetWidth(290)
button:GetFontString():SetWordWrap(false)
end end
-- only show the highlight bar—and recolor—if this really is the current track in the current folder:
if LastPlayed == text and ListData[1] == HeadingOfClickedTrack then
button.s:Show()
button:GetFontString():SetTextColor(1.0, 0.82, 0.0)
end
-- still keep your “lastfolder” bar logic unchanged:
if LastFolder == text then
button.s:Show()
end
-- resize the bar again (you already had this)
if button:GetTextWidth() > 290 then
button.s:SetSize(290, 16)
else
button.s:SetSize(button:GetTextWidth(), 16)
end
-- your hitrect, wrap, etc. all unchanged:
local bWidth = button:GetFontString():GetStringWidth() or 0
if bWidth > 290 then bWidth = 290 end
button:SetHitRectInsets(0, 454 - bWidth, 0, 0)
button:SetPushedTextOffset(0, 0)
button:GetFontString():SetWidth(290)
button:GetFontString():SetWordWrap(false)
else else
button:Hide() button:Hide()
end end
end end
end end
LeaPlusLC.UpdateList = UpdateList LeaPlusLC.UpdateList = UpdateList -- Assuming this is where you assign it globally if needed
-- Right-button click to go back -- Right-button click to go back
@@ -15790,127 +15840,117 @@ function LeaPlusLC:RunOnce()
-- Click handler for track, zone and back button -- Click handler for track, zone and back button
button:SetScript("OnClick", function(self, btn) button:SetScript("OnClick", function(self, btn)
if btn == "LeftButton" then if btn == "LeftButton" then
-- Remove focus from search box
sBox:ClearFocus() sBox:ClearFocus()
-- Get clicked track text local displayedItemText = self:GetText()
local item = self:GetText() local originalTrackItemFromListData = ListData[self.index]
-- Do nothing if its a blank line or informational heading
if not item or strfind(item, "|c") then if not displayedItemText or strfind(displayedItemText, "|c") then
return return
end end
if item == "|Cffffffaa{" .. L["click here for new selection"] .. "}" then
-- must be capital |C if displayedItemText == "|Cffffffaa{" .. L["click here for new selection"] .. "}" then
-- Create new random track listing
ShowRandomList() ShowRandomList()
return return
elseif strfind(item, "#") then elseif originalTrackItemFromListData and type(originalTrackItemFromListData) == "string" and strfind(originalTrackItemFromListData, "#") then
-- Enable all sound if the user had it off -- Playable track
if GetCVar("Sound_EnableAllSound") == "0" then if GetCVar("Sound_EnableAllSound") == "0" then SetCVar("Sound_EnableAllSound", "1") end
SetCVar("Sound_EnableAllSound", "1") if not PrevMusicCVar then PrevMusicCVar = GetCVar("Sound_EnableMusic") end
end if GetCVar("Sound_EnableMusic") == "0" then SetCVar("Sound_EnableMusic", "1") end
-- remember user music CVar and ensure music channel is on for PlayMusic()
if not PrevMusicCVar then
PrevMusicCVar = GetCVar("Sound_EnableMusic")
end
if GetCVar("Sound_EnableMusic") == "0" then
SetCVar("Sound_EnableMusic", "1")
end
-- Add all tracks to playlist
wipe(playlist) wipe(playlist)
local StartItem = 0 local listDataIndexForClickedItem = 0
-- Get item clicked row number for i = 1, #ListData do
for index = 1, #ListData do if ListData[i] == originalTrackItemFromListData then
local item = ListData[index] listDataIndexForClickedItem = i
if self:GetText() == item then break
StartItem = index
end end
end end
-- Add all items from clicked item onwards to playlist
for index = StartItem, #ListData do if listDataIndexForClickedItem == 0 then
local item = ListData[index] if originalTrackItemFromListData then
if item then tinsert(playlist, originalTrackItemFromListData)
if strfind(item, "#") then else
LeaPlusLC:Print("Error: Cannot determine track to play.")
return
end
else
for i = listDataIndexForClickedItem, #ListData do
local item = ListData[i]
if item and type(item) == "string" and strfind(item, "#") then
tinsert(playlist, item)
end
end
for i = 1, listDataIndexForClickedItem - 1 do
local item = ListData[i]
if item and type(item) == "string" and strfind(item, "#") then
tinsert(playlist, item) tinsert(playlist, item)
end end
end end
end end
-- Add all items up to clicked item to playlist
for index = 1, StartItem do if #playlist == 0 then
local item = ListData[index] LeaPlusLC:Print("Error: Playlist is empty.")
if item then return
if strfind(item, "#") then
tinsert(playlist, item)
end
end
end end
-- Enable the stop button
LeaPlusLC:LockItem(stopBtn, false) LeaPlusLC:LockItem(stopBtn, false)
-- Set Temp Folder to Random if track is in Random if ListData[1] == "|cffffd800" .. L["Random"] then TempFolder = L["Random"] end
if ListData[1] == "|cffffd800" .. L["Random"] then if ListData[1] == "|cffffd800" .. L["Search"] then TempFolder = L["Search"] end
TempFolder = L["Random"]
end
-- Set Temp Folder to Search if track is in Search
if ListData[1] == "|cffffd800" .. L["Search"] then
TempFolder = L["Search"]
end
-- Store information about the track we are about to play
tracknumber = 1 tracknumber = 1
LastPlayed = item LastPlayed = playlist[1]
LastFolder = TempFolder LastFolder = TempFolder
HeadingOfClickedTrack = ListData[1] HeadingOfClickedTrack = ListData[1]
-- Play first track
PlayTrack() PlayTrack()
-- Play subsequent tracks
uframe:RegisterEvent("SOUNDKIT_FINISHED") uframe:RegisterEvent("SOUNDKIT_FINISHED")
uframe:RegisterEvent("LOADING_SCREEN_DISABLED") uframe:RegisterEvent("LOADING_SCREEN_DISABLED")
return return
elseif strfind(item, "|r") then
--print(item) elseif originalTrackItemFromListData and type(originalTrackItemFromListData) == "string" and strfind(originalTrackItemFromListData, "|r") and not strfind(originalTrackItemFromListData, "#") then
-- A movie was clicked -- Movie
local movieName, movieID = item:match("([^,]+)%|r([^,]+)") local movieName, movieID = originalTrackItemFromListData:match("([^,]+)%|r([^,]+)")
--print(movieName) if movieName and movieID then
movieID = strtrim(movieID, "()") movieID = strtrim(movieID, "()")
--if IsMoviePlayable(movieID) then stopBtn:Click()
stopBtn:Click() print("Movies are not yet supported in 3.3.5 backport.")
--MovieFrame_PlayMovie(MovieFrame, movieName) end
--FIXME
--_G["MovieFrame"]:StartMovie(movieName,100); MovieFrame:Show()
print("Movies are not yet supported in 3.3.5 backport.")
--else
-- LeaPlusLC:Print("Movie not playable.")
--end
return return
else else
-- A zone was clicked so show track listing -- Zone or other navigation
ZonePage = scrollFrame:GetVerticalScroll() ZonePage = scrollFrame:GetVerticalScroll()
-- Find the track listing for the clicked zone local clickedZoneName = ""
for q, w in pairs(ZoneList) do if type(originalTrackItemFromListData) == "table" and originalTrackItemFromListData.zone then
for k, v in pairs(ZoneList[w]) do clickedZoneName = originalTrackItemFromListData.zone
if item == v.zone then elseif type(originalTrackItemFromListData) == "string" and not strfind(originalTrackItemFromListData, "|c") then
-- Show track listing clickedZoneName = originalTrackItemFromListData
TempFolder = item end
LeaPlusDB["MusicZone"] = item
ListData = v.tracks if clickedZoneName ~= "" then
UpdateList() local foundZone = false
-- Hide hover highlight if track under pointer is a heading for q_cat_key, w_category_list in pairs(ZoneList) do
if strfind(scrollFrame.buttons[i]:GetText(), "|c") then if ZoneList[w_category_list] then
scrollFrame.buttons[i].t:Hide() for k_zone_idx, v_zone_entry in pairs(ZoneList[w_category_list]) do
if v_zone_entry.zone == clickedZoneName then
TempFolder = v_zone_entry.zone
LeaPlusDB["MusicZone"] = v_zone_entry.zone
ListData = v_zone_entry.tracks
UpdateList()
scrollFrame:SetVerticalScroll(0)
foundZone = true
break
end
end end
-- Show top of track list
scrollFrame:SetVerticalScroll(0)
return
end end
if foundZone then break end
end end
end end
return
end end
elseif btn == "RightButton" then elseif btn == "RightButton" then
-- Back button was clicked
BackClick() BackClick()
end end
end) end)
end end
-- Right-click to go back (from anywhere on the main content area of the panel) -- Right-click to go back (from anywhere on the main content area of the panel)