forked from guoyongshi/BFFilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraghandle.lua
156 lines (131 loc) · 4.24 KB
/
draghandle.lua
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
local draghandle_prototype = CreateFrame and CreateFrame('Frame',nil,UIParent) or {} --方便做语法错误检查
local draghandle_meta = { __index = draghandle_prototype }
local function onMouseDown(self,button)
self.xpos = self:GetLeft()
self.ypos = self:GetTop()
if button == 'LeftButton' then
self:StartMoving()
self.isMoving = true
end
end
local function onMouseUp(self,button)
if self.isMoving then
self:StopMovingOrSizing()
self.isMoving = false
end
if not self.xpos or not self.ypos then
return
end
local dx = self:GetLeft()-self.xpos
local dy = self:GetTop()-self.ypos
local dis = math.sqrt(dx*dx+dy*dy)
if dis>2 then
return
end
if button == 'LeftButton' then
self:OnLeftButton()
elseif button == 'RightButton' then
self:OnRightButton()
end
end
local function onMouseEnter(self)
self.icon:SetAlpha(1.0)
self.bg:SetAlpha(1.0)
self:ShowTooltip(true)
end
local function onMouseLeave(self)
self.icon:SetAlpha(0.5)
self.bg:SetAlpha(0.5)
self:ShowTooltip(false)
end
function draghandle_prototype:Init()
self.bg = self:CreateTexture(nil,'BACKGROUND')
self.bg:SetTexture('Interface/Buttons/UI-EmptySlot')
self.bg:SetPoint("TOPLEFT", self, "TOPLEFT",0,0)
self.bg:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT",0,0)
self.bg:SetAlpha(0.5)
self.bg:Show()
self.icon = self:CreateTexture(nil,'ARTWORK')
if BFWC_Filter_SavedConfigs.enable then
self.icon:SetTexture('Interface/AddOns/BFFilter/texture/minimap')
else
self.icon:SetTexture('Interface/AddOns/BFFilter/texture/pause')
end
self.icon:SetPoint("TOPLEFT", self, "TOPLEFT",6,-6)
self.icon:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT",-6,6)
self.icon:SetAlpha(0.5)
self.icon:Show()
self:SetMovable(true)
self:EnableMouse(true)
self:SetUserPlaced(true)
self:SetScript('OnMouseDown',onMouseDown)
self:SetScript('OnMouseUp',onMouseUp)
self:SetScript('OnEnter',onMouseEnter)
self:SetScript('OnLeave',onMouseLeave)
self:SetSize(32,32)
self.is_enable = 'x'
self.tooltip = CreateFrame("GameTooltip", "BFWFDragHandleTooltip", UIParent, "GameTooltipTemplate")
end
local function getAnchors(frame)
local x, y = frame:GetCenter()
if not x or not y then return "CENTER" end
local hhalf = (x > UIParent:GetWidth()*2/3) and "RIGHT" or (x < UIParent:GetWidth()/3) and "LEFT" or ""
local vhalf = (y > UIParent:GetHeight()/2) and "TOP" or "BOTTOM"
return vhalf..hhalf, frame, (vhalf == "TOP" and "BOTTOM" or "TOP")..hhalf
end
function draghandle_prototype:ShowTooltip(show)
if not show then
self.tooltip:Hide()
return
end
self.tooltip:SetOwner(self, "ANCHOR_NONE")
self.tooltip:SetPoint(getAnchors(self))
GameTooltip_SetTitle(self.tooltip, '组队频道信息过滤')
GameTooltip_AddInstructionLine(self.tooltip, '鼠标左键打开设置窗口')
GameTooltip_AddInstructionLine(self.tooltip, '鼠标右键启用/禁用过滤器')
if BFWC_Filter_SavedConfigs.enable then
GameTooltip_AddInstructionLine(self.tooltip, '当前状态:已启用')
else
GameTooltip_AddInstructionLine(self.tooltip, '当前状态:已禁用')
end
self.tooltip:Show()
end
local cfgdlg = LibStub('AceConfigDialog-3.0')
function draghandle_prototype:OnLeftButton()
bfwf_toggle_config_dialog()
end
function draghandle_prototype:OnRightButton()
bfwf_toggle_bf_filter()
end
local function onHide(self)
if self.isMoving then
self:StopMoving()
self.isMoving = false
end
end
--在插件加载时创建窗口,窗口位置缓存才生效
local hdl = setmetatable(CreateFrame('Frame','BFWFDragHandle',UIParent),draghandle_meta)
hdl:SetScript('OnHide',onHide)
hdl:Init()
hdl:SetPoint('TOPRIGHT',-150,-150)
hdl:Hide()
bfwf_show_drag_handle = function()
hdl:Show()
end
bfwf_hide_drag_handle = function()
hdl:Hide()
end
bfwf_update_drag_handle = function()
if not hdl then
return
end
if hdl.is_enable == BFWC_Filter_SavedConfigs.enable then
return
end
hdl.is_enable = BFWC_Filter_SavedConfigs.enable
if BFWC_Filter_SavedConfigs.enable then
hdl.icon:SetTexture('Interface/AddOns/BFFilter/texture/minimap')
else
hdl.icon:SetTexture('Interface/AddOns/BFFilter/texture/pause')
end
end