修改优化等

This commit is contained in:
rucky
2026-03-18 02:01:36 +08:00
parent 2a55dd6dad
commit 923a1f9ce2
15 changed files with 1578 additions and 371 deletions

View File

@@ -61,6 +61,63 @@ local function BuildClassReverseLookup()
end
end
--------------------------------------------------------------------------------
-- Chinese -> English search-term translation for SendWho
--------------------------------------------------------------------------------
local WHO_ZH_TO_EN = {
-- Classes
["战士"] = "Warrior", ["法师"] = "Mage", ["盗贼"] = "Rogue",
["德鲁伊"] = "Druid", ["猎人"] = "Hunter", ["萨满祭司"] = "Shaman",
["萨满"] = "Shaman", ["牧师"] = "Priest", ["术士"] = "Warlock",
["圣骑士"] = "Paladin",
-- Races
["人类"] = "Human", ["矮人"] = "Dwarf", ["暗夜精灵"] = "Night Elf",
["侏儒"] = "Gnome", ["兽人"] = "Orc", ["巨魔"] = "Troll",
["亡灵"] = "Undead", ["牛头人"] = "Tauren", ["高等精灵"] = "High Elf",
["哥布林"] = "Goblin",
-- Zones (Alliance)
["暴风城"] = "Stormwind", ["铁炉堡"] = "Ironforge", ["达纳苏斯"] = "Darnassus",
["艾尔文森林"] = "Elwynn Forest", ["西部荒野"] = "Westfall",
["丹莫罗"] = "Dun Morogh", ["洛克莫丹"] = "Loch Modan",
["湿地"] = "Wetlands", ["赤脊山"] = "Redridge Mountains",
["暮色森林"] = "Duskwood", ["荆棘谷"] = "Stranglethorn Vale",
["泰达希尔"] = "Teldrassil", ["黑海岸"] = "Darkshore",
["灰谷"] = "Ashenvale", ["石爪山脉"] = "Stonetalon Mountains",
-- Zones (Horde)
["奥格瑞玛"] = "Orgrimmar", ["雷霆崖"] = "Thunder Bluff",
["幽暗城"] = "Undercity", ["杜隆塔尔"] = "Durotar",
["莫高雷"] = "Mulgore", ["贫瘠之地"] = "The Barrens",
["银松森林"] = "Silverpine Forest", ["提瑞斯法林地"] = "Tirisfal Glades",
["希尔斯布莱德丘陵"] = "Hillsbrad Foothills",
-- Zones (Contested / High-level)
["塔纳利斯"] = "Tanaris", ["菲拉斯"] = "Feralas",
["凄凉之地"] = "Desolace", ["尘泥沼泽"] = "Dustwallow Marsh",
["千针石林"] = "Thousand Needles", ["辛特兰"] = "The Hinterlands",
["阿拉希高地"] = "Arathi Highlands", ["荒芜之地"] = "Badlands",
["灼热峡谷"] = "Searing Gorge", ["燃烧平原"] = "Burning Steppes",
["西瘟疫之地"] = "Western Plaguelands", ["东瘟疫之地"] = "Eastern Plaguelands",
["费伍德森林"] = "Felwood", ["冬泉谷"] = "Winterspring",
["安戈洛环形山"] = "Un'Goro Crater", ["希利苏斯"] = "Silithus",
["艾萨拉"] = "Azshara", ["诅咒之地"] = "Blasted Lands",
["逆风小径"] = "Deadwind Pass", ["悲伤沼泽"] = "Swamp of Sorrows",
-- Dungeons / Raids
["熔火之心"] = "Molten Core", ["黑翼之巢"] = "Blackwing Lair",
["奥妮克希亚的巢穴"] = "Onyxia's Lair", ["祖尔格拉布"] = "Zul'Gurub",
["安其拉"] = "Ahn'Qiraj", ["纳克萨玛斯"] = "Naxxramas",
["黑石深渊"] = "Blackrock Depths", ["黑石塔"] = "Blackrock Spire",
["斯坦索姆"] = "Stratholme", ["通灵学院"] = "Scholomance",
["厄运之槌"] = "Dire Maul", ["玛拉顿"] = "Maraudon",
["祖尔法拉克"] = "Zul'Farrak",
}
local function TranslateWhoQuery(text)
if not text then return "" end
for zh, en in pairs(WHO_ZH_TO_EN) do
text = string.gsub(text, zh, en)
end
return text
end
local CLASS_ICON_PATH = "Interface\\AddOns\\Nanami-UI\\img\\UI-Classes-Circles"
local CLASS_ICON_TCOORDS = {
["WARRIOR"] = { 0, 0.25, 0, 0.25 },
@@ -446,6 +503,12 @@ local function CreateScrollArea(parent, w, h)
return container
end
local function WhoDebug(msg)
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage("|cff00ffcc[Who调试]|r " .. msg)
end
end
--------------------------------------------------------------------------------
-- Hide Blizzard FriendsFrame
--------------------------------------------------------------------------------
@@ -458,6 +521,55 @@ local function HideBlizzardFriends()
FriendsFrame:ClearAllPoints()
FriendsFrame:SetPoint("TOPLEFT", UIParent, "BOTTOMRIGHT", 2000, 2000)
FriendsFrame.Show = function() end
if SetWhoToUI then
local origSetWhoToUI = SetWhoToUI
SetWhoToUI = function(flag)
if flag ~= 1 then
WhoDebug("拦截 SetWhoToUI(" .. tostring(flag) .. ") -> 强制为1")
end
origSetWhoToUI(1)
end
end
end
--------------------------------------------------------------------------------
-- Who query helper
--------------------------------------------------------------------------------
local whoQueryPending = false
local whoTimeoutFrame = nil
local function DoSendWho(query)
if whoQueryPending and whoTimeoutFrame then
WhoDebug("取消上次挂起的查询")
whoQueryPending = false
whoTimeoutFrame:SetScript("OnUpdate", nil)
end
WhoDebug("发送查询: \"" .. (query or "") .. "\"")
if SetWhoToUI then SetWhoToUI(1) end
whoQueryPending = true
SendWho(query or "")
WhoDebug("SendWho() 已调用, 等待 WHO_LIST_UPDATE...")
if not whoTimeoutFrame then
whoTimeoutFrame = CreateFrame("Frame", nil, UIParent)
end
whoTimeoutFrame.elapsed = 0
whoTimeoutFrame:SetScript("OnUpdate", function()
this.elapsed = (this.elapsed or 0) + (arg1 or 0.016)
if not whoQueryPending then
this:SetScript("OnUpdate", nil)
return
end
if this.elapsed >= 6 then
local n = GetNumWhoResults()
WhoDebug("超时! 6秒未收到事件, 强制刷新, 当前结果=" .. tostring(n))
whoQueryPending = false
this:SetScript("OnUpdate", nil)
SUI:UpdateWhoList()
end
end)
end
--------------------------------------------------------------------------------
@@ -902,20 +1014,54 @@ local function BuildWhoPage(page)
searchBar:SetPoint("TOPLEFT", page, "TOPLEFT", 0, 0)
searchBar:SetPoint("TOPRIGHT", page, "TOPRIGHT", 0, 0)
local editBox = MakeEditBox(searchBar, CONTENT_W - 70, 22)
local editBox = MakeEditBox(searchBar, CONTENT_W - 110, 22)
editBox:SetPoint("LEFT", searchBar, "LEFT", 0, 0)
editBox:SetScript("OnEnterPressed", function()
local placeholder = editBox:CreateFontString(nil, "ARTWORK")
placeholder:SetFont(GetFont(), 10, "OUTLINE")
placeholder:SetPoint("LEFT", editBox, "LEFT", 6, 0)
placeholder:SetTextColor(T.dimText[1], T.dimText[2], T.dimText[3], 0.6)
placeholder:SetText("名称/等级/职业/种族/区域")
editBox.placeholder = placeholder
editBox:SetScript("OnTextChanged", function()
local text = this:GetText()
if text and text ~= "" then SendWho(text) end
if text and text ~= "" then
this.placeholder:Hide()
else
this.placeholder:Show()
end
end)
editBox:SetScript("OnEditFocusGained", function()
if this:GetText() == "" then this.placeholder:Show() end
end)
editBox:SetScript("OnEditFocusLost", function()
if this:GetText() == "" then this.placeholder:Show() end
end)
editBox:SetScript("OnEnterPressed", function()
local text = this:GetText() or ""
SUI:ClearWhoList()
DoSendWho(text)
this:ClearFocus()
end)
page.editBox = editBox
local clearBtn = MakeButton(searchBar, "X", 28, 22)
clearBtn:SetPoint("LEFT", editBox, "RIGHT", 2, 0)
clearBtn:SetScript("OnClick", function()
if page.editBox then
page.editBox:SetText("")
page.editBox:SetFocus()
end
end)
local searchBtn = MakeButton(searchBar, "搜索", 64, 22)
searchBtn:SetPoint("LEFT", editBox, "RIGHT", 4, 0)
searchBtn:SetPoint("LEFT", clearBtn, "RIGHT", 2, 0)
searchBtn:SetScript("OnClick", function()
local text = page.editBox:GetText()
if text and text ~= "" then SendWho(text) end
local text = page.editBox:GetText() or ""
SUI:ClearWhoList()
DoSendWho(text)
end)
-- Column headers
@@ -935,12 +1081,13 @@ local function BuildWhoPage(page)
end
MakeSep(page, -46)
-- Results scroll
-- Results scroll (leave 16px above btnBar for totalFS)
local listArea = CreateFrame("Frame", nil, page)
listArea:SetPoint("TOPLEFT", page, "TOPLEFT", 0, -48)
listArea:SetPoint("BOTTOMRIGHT", page, "BOTTOMRIGHT", 0, BOTTOM_H)
listArea:SetPoint("BOTTOMRIGHT", page, "BOTTOMRIGHT", 0, BOTTOM_H + 18)
local wScroll = CreateScrollArea(listArea, CONTENT_W, FRAME_H - HEADER_H - TAB_BAR_H - 48 - BOTTOM_H - 16)
local scrollH = FRAME_H - HEADER_H - TAB_BAR_H - 48 - BOTTOM_H - 18
local wScroll = CreateScrollArea(listArea, CONTENT_W, scrollH)
wScroll:SetPoint("TOPLEFT", listArea, "TOPLEFT", 0, 0)
page.wScroll = wScroll
@@ -1032,6 +1179,27 @@ local function BuildWhoPage(page)
end)
end
function SUI:ClearWhoList()
selectedWho = nil
for i = 1, 50 do
local row = whoRows[i]
if not row then break end
row.nameFS:SetText("")
row.lvlFS:SetText("")
row.classFS:SetText("")
row.zoneFS:SetText("")
SetRowNormal(row)
HideSelHighlight(row)
row:Hide()
end
if pages[2] and pages[2].wScroll then
pages[2].wScroll:SetContentHeight(4)
end
if pages[2] and pages[2].totalFS then
pages[2].totalFS:SetText("搜索中...")
end
end
function SUI:UpdateWhoList()
local numWho, totalCount = GetNumWhoResults()
local totalH = 0
@@ -1120,11 +1288,12 @@ local function BuildGuildPage(page)
end)
page.gSearchBox = gSearchBox
local offlineToggle = MakeButton(toolBar, "隐藏离线", 56, 16)
local offlineToggle = MakeButton(toolBar, guildHideOffline and "显示离线" or "隐藏离线", 56, 16)
offlineToggle:SetPoint("TOPRIGHT", toolBar, "TOPRIGHT", 0, 0)
offlineToggle.text:SetFont(GetFont(), 9, "OUTLINE")
offlineToggle:SetScript("OnClick", function()
guildHideOffline = not guildHideOffline
SFramesDB.guildHideOffline = guildHideOffline
if guildHideOffline then
this.text:SetText("显示离线")
else
@@ -2099,6 +2268,7 @@ local function ShowPage(tabIdx)
if origShowFriendsAPI then origShowFriendsAPI() end
SUI:UpdateFriendsPage()
elseif tabIdx == 2 then
if SetWhoToUI then SetWhoToUI(1) end
SUI:UpdateWhoList()
elseif tabIdx == 3 then
SUI:UpdateGuildList()
@@ -2108,7 +2278,16 @@ local function ShowPage(tabIdx)
if MainFrame and MainFrame.titleFS then
local titles = { "好友名单", "查询玩家", "公会", "团队" }
MainFrame.titleFS:SetText(titles[tabIdx] or "社交")
if tabIdx == 3 and IsInGuild() then
local guildName = GetGuildInfo("player")
if guildName and guildName ~= "" then
MainFrame.titleFS:SetText("< " .. guildName .. " >")
else
MainFrame.titleFS:SetText(titles[tabIdx])
end
else
MainFrame.titleFS:SetText(titles[tabIdx] or "社交")
end
end
end
@@ -2260,6 +2439,8 @@ function SUI:Initialize()
if initialized then return end
initialized = true
guildHideOffline = SFramesDB.guildHideOffline or false
BuildClassReverseLookup()
HideBlizzardFriends()
BuildMainFrame()
@@ -2272,11 +2453,29 @@ function SUI:Initialize()
ef:RegisterEvent("RAID_ROSTER_UPDATE")
ef:RegisterEvent("PARTY_MEMBERS_CHANGED")
ef:SetScript("OnEvent", function()
if event == "WHO_LIST_UPDATE" then
local n, t = GetNumWhoResults()
WhoDebug("收到 WHO_LIST_UPDATE! 结果=" .. tostring(n) .. " 总计=" .. tostring(t) .. " pending=" .. tostring(whoQueryPending))
local wasPending = whoQueryPending
whoQueryPending = false
if SetWhoToUI then SetWhoToUI(1) end
if MainFrame and MainFrame:IsShown() and currentMainTab == 2 then
WhoDebug("更新列表显示")
SUI:UpdateWhoList()
else
WhoDebug("自动打开查询页显示结果")
if not MainFrame then BuildMainFrame() end
if MainFrame then
MainFrame:Show()
ShowPage(2)
SUI:UpdateWhoList()
end
end
return
end
if not MainFrame or not MainFrame:IsShown() then return end
if event == "FRIENDLIST_UPDATE" or event == "IGNORELIST_UPDATE" then
if currentMainTab == 1 then SUI:UpdateFriendsPage() end
elseif event == "WHO_LIST_UPDATE" then
if currentMainTab == 2 then SUI:UpdateWhoList() end
elseif event == "GUILD_ROSTER_UPDATE" then
if currentMainTab == 3 then SUI:UpdateGuildList() end
elseif event == "RAID_ROSTER_UPDATE" or event == "PARTY_MEMBERS_CHANGED" then
@@ -2314,6 +2513,46 @@ if ShowFriends then
end
end
--------------------------------------------------------------------------------
-- Hook SetItemRef: shift-click player name -> WHO query in our panel
--------------------------------------------------------------------------------
do
local origSetItemRef_SUI = SetItemRef
SetItemRef = function(link, text, button)
if link and IsShiftKeyDown and IsShiftKeyDown() then
local playerName = nil
if string.sub(link, 1, 7) == "player:" then
playerName = string.sub(link, 8)
local colonPos = string.find(playerName, ":")
if colonPos then playerName = string.sub(playerName, 1, colonPos - 1) end
end
if playerName and playerName ~= "" then
if SFramesDB and SFramesDB.enableSocial ~= false and initialized then
WhoDebug("Shift点击玩家: " .. playerName .. ", 发起WHO查询")
local query = "n-\"" .. playerName .. "\""
if not MainFrame then BuildMainFrame() end
if MainFrame then
MainFrame:Show()
ShowPage(2)
end
if pages[2] and pages[2].editBox then
pages[2].editBox:SetText(playerName)
if pages[2].editBox.placeholder then
pages[2].editBox.placeholder:Hide()
end
end
SUI:ClearWhoList()
DoSendWho(query)
return
end
end
end
if origSetItemRef_SUI then
origSetItemRef_SUI(link, text, button)
end
end
end
--------------------------------------------------------------------------------
-- Bootstrap
--------------------------------------------------------------------------------