Repository navigation
Expand file tree
/
Copy pathQuickGroup.lua
More file actions
207 lines (190 loc) · 9.38 KB
/
Copy pathQuickGroup.lua
File metadata and controls
207 lines (190 loc) · 9.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
-- Quick group: get into a group for a kill and out again without typing. With 200 players on every
-- quest mob at launch, grouping up to share the tag is half the game.
-- * A small bar with Invite (your target) and Leave group, and key bindings for both (Key Bindings,
-- AddOns, Headstart). /headstart inv and /headstart leave do the same.
-- * Invite whoever whispers you "inv" (the word can be changed): guildies and friends, anyone, or nobody.
-- * Accept group invites: from guildies and friends, anyone, or nobody (the game asks as usual).
-- Hold Shift as the invite comes in to be asked anyway.
-- Account options (YippRouteDB, Settings, QoL): groupBar (on unless turned off), groupBarLocked (on
-- unless turned off), groupBarPos, whisperInvite ("friends" default | "anyone" | "off"), whisperWord
-- ("inv"), acceptInvites ("friends" default | "anyone" | "off").
local ADDON, YR = ...
local bar
local function Choice(key, default)
local v = YippRouteDB[key]
if v == "anyone" or v == "friends" or v == "off" then return v end
return default
end
-- Both are off until you choose who (they join and form groups for you), and off with quality of life.
function YR.WhisperInviteSet() return Choice("whisperInvite", "off") end
function YR.AcceptInvitesSet() return Choice("acceptInvites", "off") end
function YR.WhisperInvite() return YR.QoLOn() and YR.WhisperInviteSet() or "off" end
function YR.AcceptInvites() return YR.QoLOn() and YR.AcceptInvitesSet() or "off" end
function YR.WhisperWord()
local w = YippRouteDB.whisperWord
return (type(w) == "string" and w ~= "") and w:lower() or "inv"
end
--- Can we invite at all: solo, or leading a group with room in it.
local function CanInvite()
if not IsInGroup() then return true end
if not YR.Open(UnitIsGroupLeader("player")) and not YR.Open(UnitIsGroupAssistant("player")) then return false, "you're not the leader" end
if not IsInRaid() and GetNumGroupMembers() >= 5 then return false, "the group is full" end
return true
end
--- Invite your target: a player, not you, not already with you.
function YR.InviteTarget()
if not UnitExists("target") then YR.Print("target someone to invite.") return end
if not UnitIsPlayer("target") or YR.Open(UnitIsUnit("target", "player")) ~= false then YR.Print("that's not a player you can invite.") return end
if YR.Open(UnitInParty("target")) or YR.Open(UnitInRaid("target")) then YR.Print("they're already in your group.") return end
local ok, why = CanInvite()
if not ok then YR.Print("can't invite: " .. why .. ".") return end
local name = GetUnitName("target", true)
if (issecretvalue and issecretvalue(name)) or not name then
YR.Print("the game doesn't tell addons who that is here: invite them from their portrait.")
return
end
C_PartyInfo.InviteUnit(name)
end
function YR.LeaveGroup()
if not IsInGroup() then YR.Print("you're not in a group.") return end
C_PartyInfo.LeaveParty()
end
-- ---------------------------------------------------------------------------
-- Whispers and invites
-- ---------------------------------------------------------------------------
local function Allowed(mode, unit, name, guid)
if mode == "anyone" then return true end
if mode == "friends" then return YR.IsFriendly(unit, name, guid) end
return false
end
local function OnWhisper(text, sender, guid)
local mode = YR.WhisperInvite()
if mode == "off" or type(text) ~= "string" then return end
if strtrim(text):lower() ~= YR.WhisperWord() then return end
if not Allowed(mode, nil, sender, guid) then return end
if not CanInvite() then return end
if UnitInParty(Ambiguate(sender, "none")) or UnitInRaid(Ambiguate(sender, "none")) then return end
C_PartyInfo.InviteUnit(sender)
end
local function OnInvite(name, guid)
local mode = YR.AcceptInvites()
if mode == "off" or IsShiftKeyDown() or IsInGroup() then return end
if not Allowed(mode, nil, name, guid) then return end
AcceptGroup()
-- Hide the game's question the way its own Accept button does: marked accepted first, because
-- the popup declines the invite when it is hidden without that mark.
local dialog = StaticPopup_FindVisible and StaticPopup_FindVisible("PARTY_INVITE")
if dialog then
dialog.inviteAccepted = 1
StaticPopup_Hide("PARTY_INVITE")
end
-- (the game says you joined: ours said it twice - 2026-10-21)
end
-- ---------------------------------------------------------------------------
-- The bar
-- ---------------------------------------------------------------------------
local function IsMe()
local me = UnitIsUnit("target", "player")
return (issecretvalue and issecretvalue(me)) or me
end
local function Paint()
if not bar then return end
-- "is the target you?" can come back secret where the game restricts comparing units: then no invite
local canInv = UnitExists("target") and UnitIsPlayer("target") and not IsMe()
and not (YR.Open(UnitInParty("target")) or YR.Open(UnitInRaid("target"))) and CanInvite()
bar.invite:SetEnabled(canInv and true or false)
bar.leave:SetEnabled(IsInGroup() and true or false)
end
local function Build()
bar = CreateFrame("Frame", "HeadstartGroupBar", UIParent)
bar:SetSize(176, 26)
bar:SetClampedToScreen(true)
bar:SetMovable(true)
bar:EnableMouse(true)
bar:RegisterForDrag("LeftButton")
-- Unlocked, the bar is dragged by anything on it: the two buttons cover nearly all of it, so
-- they drag it too (a click without moving the mouse still clicks), and the blue edge round it.
local function Start() if not YR.Option("groupBarLocked") then bar:StartMoving() end end
local function Stop()
bar:StopMovingOrSizing()
local l, t = bar:GetLeft(), bar:GetTop()
if l and t then
bar:ClearAllPoints()
bar:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", l, t)
YippRouteDB.groupBarPos = { l, t }
end
end
bar:SetScript("OnDragStart", Start)
bar:SetScript("OnDragStop", Stop)
local function Btn(text, fn, x)
local b = CreateFrame("Button", nil, bar, "UIPanelButtonTemplate")
b:SetSize(84, 22)
b:SetPoint("LEFT", x, 0)
b:SetText(text)
b:SetScript("OnClick", fn)
b:SetMotionScriptsWhileDisabled(true)
b:RegisterForDrag("LeftButton")
b:SetScript("OnDragStart", Start)
b:SetScript("OnDragStop", Stop)
return b
end
bar.invite = Btn("Invite", function() YR.InviteTarget() end, 2)
bar.leave = Btn("Leave group", function() YR.LeaveGroup() end, 90)
-- The drag edge, only while unlocked: the same blue as the campfire's.
bar.edge = bar:CreateTexture(nil, "BACKGROUND")
bar.edge:SetPoint("TOPLEFT", -8, 8)
bar.edge:SetPoint("BOTTOMRIGHT", 8, -8)
bar.edge:SetColorTexture(0.3, 0.65, 1, 0.35)
bar:ClearAllPoints()
local p = YippRouteDB.groupBarPos
if p and p[1] and p[2] then bar:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", p[1], p[2])
else bar:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 226) end -- clear of the trinket buttons, which start at 180
end
function YR.RefreshGroupBar()
if not YR.Option("groupBar") then
if bar then bar:Hide() end
return
end
if not bar then Build() end
local unlocked = not YR.Option("groupBarLocked")
bar.edge:SetShown(unlocked)
-- the edge is part of what you can grab while it shows
if unlocked then bar:SetHitRectInsets(-8, -8, -8, -8) else bar:SetHitRectInsets(0, 0, 0, 0) end
Paint()
bar:Show()
end
-- The bar's settings: every part is looked at, so the bar comes on with its events (or goes with them)
-- at once, and one that stays on is drawn again.
function YR.SetGroupBar(on) YippRouteDB.groupBar = on and true or false YR.ApplyParts() end
-- Free while off (YR.Part, Core.lua). Three parts, each listening only while it has something to do:
-- your target and the group changing only repaint the bar; whispers are read only while a whispered
-- word invites; an invite is looked at only while invites are accepted for you. The key bindings and
-- the slash commands need none of them.
local function BarOn() return YR.Option("groupBar") end
local function WhisperOn() return YR.WhisperInvite() ~= "off" end
local function AcceptOn() return YR.AcceptInvites() ~= "off" end
local function OnWhisperEvent(_, _, a, b, ...)
-- During chat lockdown whispers arrive as secret values, which can't be read: skip them.
if issecretvalue and (issecretvalue(a) or issecretvalue(b)) then return end
local guid = select(10, ...) -- arg12: the sender's GUID
pcall(OnWhisper, a, b, guid)
end
local function OnInviteEvent(_, _, a, _, ...)
local guid = select(5, ...) -- arg7: inviterGUID
OnInvite(a, guid)
end
local started
function YR.StartQuickGroup()
if started then return end
started = true
YR.Part(BarOn, { "PLAYER_TARGET_CHANGED", "GROUP_ROSTER_UPDATE", "PARTY_LEADER_CHANGED" }, Paint,
{ start = YR.RefreshGroupBar, stop = YR.RefreshGroupBar, again = YR.RefreshGroupBar })
YR.Part(WhisperOn, { "CHAT_MSG_WHISPER" }, OnWhisperEvent)
YR.Part(AcceptOn, { "PARTY_INVITE_REQUEST" }, OnInviteEvent)
end
-- Key bindings (Bindings.xml)
function Headstart_InviteTarget() YR.InviteTarget() end
function Headstart_LeaveGroup() YR.LeaveGroup() end
BINDING_HEADER_HEADSTART = "Headstart"
BINDING_NAME_HEADSTART_INVITE = "Invite target"
BINDING_NAME_HEADSTART_LEAVE = "Leave group"