-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimap.lua
More file actions
executable file
·245 lines (217 loc) · 7.61 KB
/
Copy pathminimap.lua
File metadata and controls
executable file
·245 lines (217 loc) · 7.61 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
local _, ns = ...
---------------------------------------------------------------------------
-- Floating Button — freely draggable anywhere on screen
-- Also registers with LibDBIcon (if available) so minimap button manager
-- addons like MinimapButtonButton can collect the icon.
---------------------------------------------------------------------------
local ICON_PATH = "Interface\\AddOns\\iChat\\media\\textures\\"
---------------------------------------------------------------------------
-- LibDBIcon / LibDataBroker integration (optional)
---------------------------------------------------------------------------
local function RegisterLibDBIcon()
local LDB = LibStub and LibStub("LibDataBroker-1.1", true)
local LDBIcon = LibStub and LibStub("LibDBIcon-1.0", true)
if not LDB or not LDBIcon then return end
local faction = UnitFactionGroup("player")
local iconFile = ICON_PATH .. (faction == "Horde" and "icon_horde" or "icon_alliance")
local dataObj = LDB:NewDataObject("iChat", {
type = "launcher",
icon = iconFile,
label = "iChat",
OnClick = function(self, button)
if button == "RightButton" then
ns.ToggleSettings()
else
if ns.StopFlashButton then ns.StopFlashButton() end
ns.ToggleWindow()
end
end,
OnTooltipShow = function(tooltip)
tooltip:AddLine("|cff007AFFiChat|r")
tooltip:AddLine("Left-click: Toggle window", 0.7, 0.7, 0.7)
tooltip:AddLine("Right-click: Settings", 0.7, 0.7, 0.7)
end,
})
-- Use saved minimap position from DB, or defaults
if not ns.db.minimapIcon then
ns.db.minimapIcon = { hide = false }
end
LDBIcon:Register("iChat", dataObj, ns.db.minimapIcon)
ns.ldbIcon = LDBIcon
ns.ldbDataObj = dataObj
end
function ns.CreateMinimapButton()
if ns.minimapButton then return end
local size = ns.db.settings.buttonSize or 40
local faction = UnitFactionGroup("player")
local iconFile = ICON_PATH .. (faction == "Horde" and "icon_horde" or "icon_alliance")
local btn = CreateFrame("Button", "iChatFloatingButton", UIParent)
btn:SetSize(size, size)
btn:SetFrameStrata("MEDIUM")
btn:SetFrameLevel(8)
btn:SetMovable(true)
btn:SetClampedToScreen(true)
btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
btn:RegisterForDrag("LeftButton")
-- Shield icon (blue for Alliance, red for Horde)
local icon = btn:CreateTexture(nil, "ARTWORK")
icon:SetAllPoints()
icon:SetTexture(iconFile)
btn.icon = icon
-- Restore saved position
local pos = ns.db.settings.buttonPos
if pos then
btn:SetPoint(pos.point or "CENTER", UIParent, pos.relPoint or "BOTTOMLEFT", pos.x or 0, pos.y or 0)
else
btn:SetPoint("CENTER", UIParent, "CENTER", -300, -200)
end
-- Click handlers
btn:SetScript("OnClick", function(self, button)
ns.StopFlashButton()
if button == "RightButton" then
ns.ToggleSettings()
else
ns.ToggleWindow()
end
end)
-- Free drag
btn:SetScript("OnDragStart", function(self)
if not InCombatLockdown() then
self:StartMoving()
end
end)
btn:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local point, _, relPoint, x, y = self:GetPoint()
ns.db.settings.buttonPos = {
point = point,
relPoint = relPoint,
x = x,
y = y,
}
end)
-- Hover effect (brighten icon)
btn:SetScript("OnEnter", function(self)
self.icon:SetVertexColor(2.0, 2.0, 2.0)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("|cff007AFFiChat|r")
GameTooltip:AddLine("Left-click: Toggle window", 0.7, 0.7, 0.7)
GameTooltip:AddLine("Right-click: Settings", 0.7, 0.7, 0.7)
GameTooltip:AddLine("Drag: Reposition", 0.7, 0.7, 0.7)
GameTooltip:Show()
end)
btn:SetScript("OnLeave", function(self)
self.icon:SetVertexColor(1.5, 1.5, 1.5)
GameTooltip:Hide()
end)
-- Unread badge (red dot with count)
local badge = CreateFrame("Frame", nil, btn)
badge:SetSize(18, 18)
badge:SetPoint("TOPRIGHT", 4, 4)
local badgeBg = badge:CreateTexture(nil, "ARTWORK")
badgeBg:SetAllPoints()
badgeBg:SetColorTexture(1.0, 0.22, 0.17, 1)
local badgeCount = badge:CreateFontString(nil, "OVERLAY")
badgeCount:SetFont("Fonts\\FRIZQT__.TTF", 9, "OUTLINE")
badgeCount:SetPoint("CENTER")
badgeCount:SetTextColor(1, 1, 1)
badge:Hide()
btn.unreadBadge = badge
btn.unreadCount = badgeCount
ns.minimapButton = btn
if not ns.db.settings.showMinimapButton then
btn:Hide()
end
-- Register with LibDBIcon for minimap button manager addons
RegisterLibDBIcon()
end
-- Update the unread badge on the floating button
function ns.UpdateButtonBadge()
if not ns.minimapButton or not ns.minimapButton.unreadBadge then return end
local total = 0
if ns.db and ns.db.conversations then
for _, convo in pairs(ns.db.conversations) do
total = total + (convo.unread or 0)
end
end
if total > 0 then
ns.minimapButton.unreadCount:SetText(total > 99 and "99+" or tostring(total))
ns.minimapButton.unreadBadge:Show()
else
ns.minimapButton.unreadBadge:Hide()
end
-- Update LibDataBroker text (shown by LDB display addons)
if ns.ldbDataObj then
ns.ldbDataObj.text = total > 0 and tostring(total) or ""
end
-- Update Titan Panel
if ns.UpdateTitanButton then
ns.UpdateTitanButton()
end
-- Update ElvUI DataText
if ns.UpdateElvUIDataText then
ns.UpdateElvUIDataText()
end
-- Fire WeakAuras event
if ns.FireUnreadChanged then
ns.FireUnreadChanged(total)
end
end
-- Repeating flash on incoming whisper — pulses until user opens iChat
function ns.FlashButton()
if not ns.minimapButton then return end
-- Already flashing, just let it continue
if ns.buttonFlashTicker then return end
local btn = ns.minimapButton
local on = false
ns.buttonFlashTicker = C_Timer.NewTicker(0.5, function()
if not btn.icon then
ns.StopFlashButton()
return
end
on = not on
if on then
btn.icon:SetVertexColor(1.0, 0.4, 0.4)
else
btn.icon:SetVertexColor(1, 1, 1)
end
end)
end
function ns.StopFlashButton()
if ns.buttonFlashTicker then
ns.buttonFlashTicker:Cancel()
ns.buttonFlashTicker = nil
end
if ns.minimapButton and ns.minimapButton.icon then
ns.minimapButton.icon:SetVertexColor(1.5, 1.5, 1.5)
end
end
function ns.SetMinimapButtonVisible(show)
if not ns.minimapButton then return end
if show then
ns.minimapButton:Show()
else
ns.minimapButton:Hide()
end
-- Sync LibDBIcon visibility
if ns.ldbIcon then
if show then
ns.ldbIcon:Show("iChat")
else
ns.ldbIcon:Hide("iChat")
end
end
end
function ns.ResizeButton(size)
if not ns.minimapButton then return end
ns.minimapButton:SetSize(size, size)
-- Scale badge relative to button size
local badgeSize = math.max(14, math.floor(size * 0.45))
local fontSize = math.max(7, math.floor(size * 0.22))
if ns.minimapButton.unreadBadge then
ns.minimapButton.unreadBadge:SetSize(badgeSize, badgeSize)
end
if ns.minimapButton.unreadCount then
ns.minimapButton.unreadCount:SetFont("Fonts\\FRIZQT__.TTF", fontSize, "OUTLINE")
end
end