Skip to content

Commit

Permalink
[refactor]: migrate announcement channel selection dropdown to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
juemrami committed Jan 30, 2025
1 parent 4e9dda4 commit 164cb26
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 46 deletions.
21 changes: 0 additions & 21 deletions LFGBulletinBoard/Chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,3 @@ function GBB.Announce()
GroupBulletinBoardFrameAnnounceMsg:ClearFocus()
end
end

function GBB.CreateChannelPulldown (frame, level, menuList)
if level~=1 then return end
local t= GBB.PhraseChannelList(GetChannelList())

local info = UIDropDownMenu_CreateInfo()


for i,channel in pairs(t) do
info.text = i..". "..channel.name
info.checked = (channel.name == GBB.DB.AnnounceChannel)
info.disabled = channel.hidden
info.arg1 = i
info.arg2 = channel.name
info.func = function(self, arg1, arg2, checked)
GBB.DB.AnnounceChannel=arg2
GroupBulletinBoardFrameSelectChannel:SetText(arg2)
end
UIDropDownMenu_AddButton(info)
end
end
40 changes: 22 additions & 18 deletions LFGBulletinBoard/GroupBulletinBoard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,6 @@ hooksecurefunc("SetItemRef", function(link)
end
end)

function GBB.BtnSelectChannel()
if UIDROPDOWNMENU_OPEN_MENU ~= GBB.FramePullDownChannel then
UIDropDownMenu_Initialize( GBB.FramePullDownChannel, GBB.CreateChannelPulldown, "MENU")
end
ToggleDropDownMenu(nil, nil, GBB.FramePullDownChannel, GroupBulletinBoardFrameSelectChannel, 0,0)
end

--gui
-------------------------------------------------------------------------------------

Expand Down Expand Up @@ -705,18 +698,31 @@ function GBB.Init()
end
end,
GBB.Title
)

GBB.FramePullDownChannel=CreateFrame("Frame", "GBB.PullDownMenu", UIParent, "UIDropDownMenuTemplate")
)
GroupBulletinBoardFrameTitle:SetFontObject(GBB.DB.FontSize)

if GBB.DB.AnnounceChannel == nil then
if GBB.L["lfg_channel"] ~= "" then
GBB.DB.AnnounceChannel = GBB.L["lfg_channel"]
else
_, GBB.DB.AnnounceChannel = GetChannelList()
if GBB.L["lfg_channel"] ~= "" then GBB.DB.AnnounceChannel = GBB.L["lfg_channel"];
else GBB.DB.AnnounceChannel = select(2, GetChannelList()) end;
end
DropdownSelectionTextMixin.OnLoad(GroupBulletinBoardFrameSelectChannel)
GroupBulletinBoardFrameSelectChannel:SetSelectionTranslator(function(selection) return selection.data end)
GroupBulletinBoardFrameSelectChannel:SetupMenu(function(frame, rootDescription)
---@cast rootDescription RootMenuDescriptionProxy
local channelInfo = GBB.PhraseChannelList(GetChannelList())
local setting = GBB.OptionsBuilder.GetSavedVarHandle(GBB.DB, "AnnounceChannel");
local isSelected = function(channel) return channel == setting:GetValue() end
local setSelected = function(channel) setting:SetValue(channel) end
for i, channel in pairs(channelInfo) do
local button = rootDescription:CreateRadio(i..". "..channel.name, isSelected, setSelected, channel.name)
button:SetEnabled(not channel.hidden)
end
end

end)
--hack: early in addon loading process `GetChannelList` can return nil; re-generate the menu in these cases.
GroupBulletinBoardFrameSelectChannel:HookScript("OnShow", function(self)
if not self:GetText() then self:GenerateMenu() end;
end)

---@type EditBox # making this local isnt required, just here for the luals linter
local GroupBulletinBoardFrameResultsFilter = _G["GroupBulletinBoardFrameResultsFilter"];
GroupBulletinBoardFrameResultsFilter:SetParent(GroupBulletinBoardFrame_ScrollFrame)
Expand All @@ -741,8 +747,6 @@ function GBB.Init()
return self.filterPatterns
end

GroupBulletinBoardFrameSelectChannel:SetText(GBB.DB.AnnounceChannel)

GBB.ResizeFrameList()

if GBB.DB.EscapeQuit then
Expand Down
12 changes: 5 additions & 7 deletions LFGBulletinBoard/GroupBulletinBoard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@
</Button>

<!-- announcebox -->
<Button name="$parentSelectChannel" inherits="UIPanelButtonTemplate" text="channel">
<DropdownButton name="$parentSelectChannel" inherits="UIPanelButtonTemplate" text="channel" mixin="WowStyle1DropdownMixin">
<KeyValues>
<KeyValue key="menuMixin" value="MenuStyle2Mixin" type="global"/>
</KeyValues>
<Anchors>
<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMLEFT" relativeTo="$parent" >
<Offset>
Expand All @@ -114,12 +117,7 @@
</Anchor>
</Anchors>
<Size><AbsDimension x="150" y="20" /></Size>
<Scripts>
<OnClick>
GroupBulletinBoard_Addon.BtnSelectChannel()
</OnClick>
</Scripts>
</Button>
</DropdownButton>

<Button name="$parentAnnounce" inherits="UIPanelButtonTemplate" text="Post">
<Anchors>
Expand Down

0 comments on commit 164cb26

Please sign in to comment.