comparison Main.lua @ 11:d2cbfe498c4d

first beta
author Jay Bird <a4blank@yahoo.com>
date Sat, 04 Dec 2010 05:53:52 +0300
parents f93b554bb7cf
children cc98f28b1c7c
comparison
equal deleted inserted replaced
10:f93b554bb7cf 11:d2cbfe498c4d
1 1
2 2
3 RTT = LibStub("AceAddon-3.0"):NewAddon("RaidTargetTactics", "AceConsole-3.0") 3 RTT = LibStub("AceAddon-3.0"):NewAddon("RaidTargetTactics", "AceConsole-3.0", "AceEvent-3.0")
4 local _G = _G
4 local L = LibStub("AceLocale-3.0"):GetLocale("RaidTargetTactics") 5 local L = LibStub("AceLocale-3.0"):GetLocale("RaidTargetTactics")
5
6
7 local LDB = LibStub("LibDataBroker-1.1", true) 6 local LDB = LibStub("LibDataBroker-1.1", true)
8 local LDBIcon = LibStub("LibDBIcon-1.0", true) 7 local LDBIcon = LibStub("LibDBIcon-1.0", true)
9 local AceGUI = LibStub("AceGUI-3.0") 8 local Completion = LibStub("AceGUI-3.0-Completing-EditBox");
9
10 Completion:Register("Raid", -1, 0)
11 local GetAutoCompleteResults_original = _G.GetAutoCompleteResults
12 _G.GetAutoCompleteResults = function(text, include, exclude, results, position)
13 if include == -1 then -- special hack for Raid members and self
14 local users = RTT.partyInfo:GetUsers()
15 local result = {}
16 for _, name in ipairs(users) do
17 if name:find(text) == 1 then
18 table.insert(result, name)
19 end
20 if #result > results then
21 break
22 end
23 end
24 return unpack(result)
25 else
26 return GetAutoCompleteResults_original(text, include, exclude, results, position)
27 end
28 end
29
10 30
11 local RTTIcon = LibStub("LibDataBroker-1.1"):NewDataObject("RTTIcon", { 31 local RTTIcon = LibStub("LibDataBroker-1.1"):NewDataObject("RTTIcon", {
12 type = "data source", 32 type = "data source",
13 text = "Raid Target Tactics", 33 text = "Raid Target Tactics",
14 icon = "Interface\\TARGETINGFRAME\\UI-RaidTargetingIcon_8", 34 icon = "Interface\\TARGETINGFRAME\\UI-RaidTargetingIcon_8",
15 OnClick = function() RTT:OnIconClick() end, 35 OnClick = function(frame, button) RTT:OnIconClick(frame, button) end,
16 OnTooltipShow = function(tooltip) 36 OnTooltipShow = function(tooltip)
17 tooltip:AddLine("Raid Target Tactics") 37 tooltip:AddLine("Raid Target Tactics")
18 tooltip:AddLine(L.Minimap_Icon_Tooltip) 38 tooltip:AddLine(L.Minimap_Icon_Tooltip)
19 end, 39 end,
20 }) 40 })
23 profile = { 43 profile = {
24 visible = true, 44 visible = true,
25 minimap = { 45 minimap = {
26 hide = false, 46 hide = false,
27 }, 47 },
48 setups = {},
49 locked = false,
28 }, 50 },
29 } 51 }
30 52
31 function RTT:OnInitialize() 53 function RTT:OnInitialize()
32 self.db = LibStub("AceDB-3.0"):New("TacticsSettings", defaults, true) 54 self.db = LibStub("AceDB-3.0"):New("TacticsSettings", defaults, true)
55 self.partyInfo = PartyInfo()
56 self.nameDialog = NameDialog(self:GetSetupNames())
33 57
34 LDBIcon:Register("RTTIcon", RTTIcon, self.db.profile.minimap) 58 LDBIcon:Register("RTTIcon", RTTIcon, self.db.profile.minimap)
35 self:InitFrame() 59 self:InitFrame()
60 self:BindEvents()
61 self.nameDialog:InitDialog()
62 self.partyInfo:Update()
36 if self.f:IsShown() ~= self.db.profile.visible then 63 if self.f:IsShown() ~= self.db.profile.visible then
37 if self.db.profile.visible then 64 if self.db.profile.visible then
38 self:ShowFrame() 65 self:ShowFrame()
39 else 66 else
40 self:HideFrame() 67 self:HideFrame()
41 end 68 end
42 end 69 end
70 if self.db.profile.locked then
71 self.f:SetMovable(false)
72 self.f:EnableMouse(false)
73 end
74 end
75
76 function RTT:GetSetupNames()
77 local result = {}
78 for name, _ in pairs(self.db.profile.setups) do
79 table.insert(result, name)
80 end
81 return result
82 end
83
84 function RTT:BindEvents()
85 self:RegisterEvent("PARTY_MEMBERS_CHANGED")
86 self:RegisterEvent("RAID_ROSTER_UPDATE")
87 end
88
89 function RTT:PARTY_MEMBERS_CHANGED()
90 self.partyInfo:Update()
91 end
92
93 function RTT:RAID_ROSTER_UPDATE()
94 self.partyInfo:Update()
43 end 95 end
44 96
45 function RTT:InitFrame() 97 function RTT:InitFrame()
46 self.f = CreateFrame("Frame", nil, UIParent) 98 self.f = CreateFrame("Frame", "__RTT_MAIN", UIParent)
47 self.f:SetWidth(300) 99 self.f:SetWidth(300)
48 self.f:SetHeight(200) 100 self.f:SetHeight(270)
49 self.f:SetAlpha(0.8) 101 self.f:SetAlpha(0.8)
102 self.f:SetMovable(true)
103 self.f:EnableMouse(true)
104 self.f:RegisterForDrag("LeftButton")
105 self.f:SetScript("OnDragStart", self.f.StartMoving)
106 self.f:SetScript("OnDragStop", self.f.StopMovingOrSizing)
50 self.f:SetPoint("LEFT", UIParent, "LEFT", 10, 0) 107 self.f:SetPoint("LEFT", UIParent, "LEFT", 10, 0)
51 --[[self.f:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 108 --[[self.f:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
52 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", 109 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
53 tile = true, tileSize = 16, edgeSize = 16, 110 tile = true, tileSize = 16, edgeSize = 16,
54 insets = { left = 4, right = 4, top = 4, bottom = 4 }}) 111 insets = { left = 4, right = 4, top = 4, bottom = 4 }})
74 } 131 }
75 self.f:SetBackdrop(backdrop) 132 self.f:SetBackdrop(backdrop)
76 self.f:SetFrameStrata("HIGH") 133 self.f:SetFrameStrata("HIGH")
77 --self.f:SetBackdropColor(0, 0, 0, 0.5) 134 --self.f:SetBackdropColor(0, 0, 0, 0.5)
78 135
136 local str1 = self.f:CreateFontString()
137 str1:SetFontObject(GameFontHighlightSmall)
138 str1:SetPoint("TOPLEFT", 45, -15)
139 str1:SetText(L.Action .. ":")
140 str1:SetTextColor(YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b)
141 str1:Show()
142
143 local str1 = self.f:CreateFontString()
144 str1:SetFontObject(GameFontHighlightSmall)
145 str1:SetPoint("TOPLEFT", 175, -15)
146 str1:SetText(L.Player .. ":")
147 str1:SetTextColor(YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b)
148 str1:Show()
149
150 self.icons = {}
79 self.fields = {} 151 self.fields = {}
80 self.selects = {} 152 self.selects = {}
81 for num, icon in ipairs(RaidIcons) do 153 for num, icon in ipairs(RaidIcons) do
82 icon:draw(self.f, 20, num * -20) 154 self.icons[num] = icon
83 155 icon:draw(self.f, 16, (num - 1) * -25 - 30)
84 local field = CreateFrame("EditBox", "__RTT_EditBox_" .. tostring(num), self.f, "InputBoxTemplate") 156
85 field:SetAutoFocus(false) 157 local field = RoleField()
86 field:SetFontObject(ChatFontNormal) 158 field:draw(self.f, 45, (num -1) * -25 - 30)
87 field:SetWidth(100) 159 self.fields[num] = field
88 field:SetHeight(16) 160
89 field:SetTextInsets(0, 0, 3, 3) 161 local userSelect = UserSelect()
90 field:SetPoint("TOPLEFT", 40, num * -20) 162 userSelect:draw(self.f, 170, ((num - 1) * -25) - 30)
91 table.insert(self.fields, field) 163 self.selects[num] = userSelect
92 field:Show() 164 end
93 165 self.talkButton = CreateFrame("Button", nil, self.f, "OptionsButtonTemplate")
94 local userSelect = AceGUI:Create("Dropdown") 166 self.talkButton:ClearAllPoints()
95 userSelect.frame:SetParent(self.f) 167 self.talkButton:SetText(L.Announce)
96 local raid = {} 168 self.talkButton:SetPoint("TOPLEFT", 170, -230)
97 for i=1, GetNumRaidMembers() do 169 self.talkButton:SetWidth(102)
98 raid[i] = UnitName("raid" .. i) 170 self.talkButton:SetScript("OnClick", function() RTT:Announce() end)
99 end 171
100 userSelect:SetList(raid) 172 self.dropdown = CreateFrame("Frame", "__RTT_DROPDOWN", UIParent, "UIDropDownMenuTemplate");
101 userSelect:SetWidth(100) 173 UIDropDownMenu_Initialize(self.dropdown, self.InitDropdown, "MENU");
102 userSelect:SetHeight(16) 174 end
103 userSelect:SetPoint("TOPLEFT", 160, num * -20) 175
104 table.insert(self.selects, userSelect) 176 function RTT:InitDropdown(level)
105 userSelect.frame:Show() 177 level = level or 1
106 end 178 if (level == 1) then
107 end 179 local info = UIDropDownMenu_CreateInfo()
108 180 info.hasArrow = false
109 function RTT:OnIconClick() 181 info.notCheckable = false
110 if self.db.profile.visible then 182 info.text = L.Lock
111 self:HideFrame() 183 info.func = function() RTT:ToggleMovable() end
184 info.keepShownOnClick = true
185 info.checked = RTT.db.profile.locked
186 UIDropDownMenu_AddButton(info, level)
187
188 info.hasArrow = true
189 info.notCheckable = true
190 info.text = L.Load
191 info.value = "load"
192 info.keepShownOnClick = false
193 UIDropDownMenu_AddButton(info, level)
194
195 info.hasArrow = false
196 info.notCheckable = true
197 info.text = L.Save .. "…"
198 info.keepShownOnClick = false
199 local rows = RTT:GetFormData()
200 if #rows == 0 then
201 info.disabled = true
202 else
203 info.func = function() RTT:AskForSave() end
204 end
205 UIDropDownMenu_AddButton(info, level)
206 end
207
208 if (level == 2 and UIDROPDOWNMENU_MENU_VALUE == "load") then
209 local info = UIDropDownMenu_CreateInfo();
210 for key, setup in pairs(RTT.db.profile.setups) do
211 info.hasArrow = false
212 info.notCheckable = true
213 info.text = key
214 info.func = function() RTT:Load(key) end
215 UIDropDownMenu_AddButton(info, level);
216 end
217 end
218 end
219
220 function RTT:AskForSave()
221 local this = self
222 self.nameDialog:Show()
223 self.nameDialog:OnNameChosen(function(name) this:Save(name) end)
224 end
225
226 function RTT:Save(name)
227 self.db.profile.setups[name] = self:GetFormData(true)
228 self.nameDialog:SetInvalidNames(self:GetSetupNames())
229 end
230
231 function RTT:Load(name)
232 local data = self.db.profile.setups[name]
233 self:SetFormData(data)
234 end
235
236 function RTT:OnIconClick(frame, button)
237 if button == "RightButton" then
238 -- context menu
239 ToggleDropDownMenu(1, nil, self.dropdown, LDBIcon.objects["RTTIcon"], 0, 0)
112 else 240 else
113 self:ShowFrame() 241 if self.db.profile.visible then
114 end 242 self:HideFrame()
115 self.db.profile.visible = not self.db.profile.visible 243 else
244 self:ShowFrame()
245 end
246 self.db.profile.visible = not self.db.profile.visible
247 end
116 end 248 end
117 249
118 function RTT:HideFrame() 250 function RTT:HideFrame()
119 self.f:Hide() 251 self.f:Hide()
120 end 252 end
121 253
122 function RTT:ShowFrame() 254 function RTT:ShowFrame()
123 self.f:Show() 255 self.f:Show()
124 end 256 end
125 257
126 258 function RTT:ToggleMovable()
127 259 if self.f:IsMovable() then
128 260 self.f:SetMovable(false)
261 self.f:EnableMouse(false)
262 self.db.profile.locked = true
263 else
264 self.f:SetMovable(true)
265 self.f:EnableMouse(true)
266 self.db.profile.locked = false
267 end
268 end
269
270 function RTT:GetDefaultChatChannel()
271 if self.partyInfo.is_in_raid then
272 return "RAID"
273 end
274 if self.partyInfo.is_in_party then
275 return "PARTY"
276 end
277 return nil
278 end
279
280 function RTT:SetFormData(data)
281 for idx, row in ipairs(data) do
282 self.fields[idx]:SetText(row[2])
283 self.selects[idx]:SetText(row[3])
284 end
285 end
286
287 function RTT:GetFormData(with_empty)
288 local result = {}
289 for idx, icon in ipairs(self.icons) do
290 local action = strtrim(self.fields[idx]:GetText())
291 local player = strtrim(self.selects[idx]:GetText())
292 -- Either we want empty rows (for save)
293 -- Or action or player are filled
294 if with_empty or (#action > 0 or #player > 0) then
295 table.insert(result, {icon:GetChatCommand(),
296 action,
297 player})
298 end
299 end
300 return result
301 end
302
303 function RTT:Announce()
304 local channel = self:GetDefaultChatChannel()
305 if channel then
306 for _, data in ipairs(self:GetFormData()) do
307 local str = table.concat(data, " — ")
308 SendChatMessage(str, channel)
309 end
310 if UnitName("player") == "Герадд" then
311 SendChatMessage("Герадд любит тебя!", channel)
312 end
313 end
314 end
315
316