comparison CrossRealmAssist.lua @ 29:7267ae761cb9 beta-0.7

* indentation
author ShadowTheAge
date Sun, 27 Sep 2015 16:05:33 +0300
parents 42a70f4b2ff5
children 7b7b3ca996fd
comparison
equal deleted inserted replaced
28:2e9ff79f6969 29:7267ae761cb9
44 minimap = {}, 44 minimap = {},
45 widgetPos=DefaultWidgetPos, 45 widgetPos=DefaultWidgetPos,
46 quickJoinHint = true, 46 quickJoinHint = true,
47 quickJoin={[6]=1}, 47 quickJoin={[6]=1},
48 allLanguages = true, 48 allLanguages = true,
49 stoplist = {"no hop","kick"} 49 stoplist = {"no hop","kick"}
50 } 50 }
51 } 51 }
52 52
53 53
54 -- Utils functions 54 -- Utils functions
164 164
165 local function WeightLfgItem(id, forAutoJoin) 165 local function WeightLfgItem(id, forAutoJoin)
166 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id) 166 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id)
167 if delisted then return 0 end 167 if delisted then return 0 end
168 local name,realm = PlayerName(fullname); 168 local name,realm = PlayerName(fullname);
169 local stoplist = db.global.stoplist or {} 169 local stoplist = db.global.stoplist or {}
170 local ldesc = string.lower(caption) .. "|" .. string.lower(desc); 170 local ldesc = string.lower(caption) .. "|" .. string.lower(desc);
171 local isHopGroup = string.find(ldesc, "realm hop") 171 local isHopGroup = string.find(ldesc, "realm hop")
172 for i=1, #stoplist do 172 for i=1, #stoplist do
173 if string.find(ldesc, stoplist[i], 1, true) then return 0 end 173 if string.find(ldesc, stoplist[i], 1, true) then return 0 end
174 end 174 end
175 if forAutoJoin then 175 if forAutoJoin then
176 if not autoinv or recentgroups[fullname] or (not isHopGroup and (pcount >= 35 or pcount <= 5)) then return 0 end 176 if not autoinv or recentgroups[fullname] or (not isHopGroup and (pcount >= 35 or pcount <= 5)) then return 0 end
177 end 177 end
178 178
179 local autoinvWeight = autoinv and 5 or 2 179 local autoinvWeight = autoinv and 5 or 2
180 local hopCoef = isHopGroup and 3 or 1 180 local hopCoef = isHopGroup and 3 or 1
181 181
182 local visCoef = 1 182 local visCoef = 1
183 if recentgroups[fullname] then 183 if recentgroups[fullname] then
184 local ago = GetTime() - recentgroups[fullname].time; 184 local ago = GetTime() - recentgroups[fullname].time;
185 visCoef = math.min(1,ago/600) 185 visCoef = math.min(1,ago/600)
192 local ago = GetTime() - realmVis 192 local ago = GetTime() - realmVis
193 leaderRealm = 1 + 2*math.min(1,ago/600); 193 leaderRealm = 1 + 2*math.min(1,ago/600);
194 end 194 end
195 195
196 local countWeight = 4 -- count weight 196 local countWeight = 4 -- count weight
197 if not isHopGroup then 197 if not isHopGroup then
198 if pcount >= 39 or pcount <= 1 then countWeight = 1 198 if pcount >= 39 or pcount <= 1 then countWeight = 1
199 elseif pcount >= 35 or pcount <= 5 then countWeight = 2 199 elseif pcount >= 35 or pcount <= 5 then countWeight = 2
200 elseif pcount >= 30 or pcount <= 10 then countWeight = 3 end 200 elseif pcount >= 30 or pcount <= 10 then countWeight = 3 end
201 end 201 end
202 202
203 local ageWeight = 2 203 local ageWeight = 2
204 if time > 1200 then ageWeight = 4 204 if time > 1200 then ageWeight = 4
205 elseif time > 300 then ageWeight = 3 end 205 elseif time > 300 then ageWeight = 3 end
367 realmSep = _G.REALM_SEPARATORS 367 realmSep = _G.REALM_SEPARATORS
368 playerName = UnitName("player") 368 playerName = UnitName("player")
369 homeRealm = GetRealmName() 369 homeRealm = GetRealmName()
370 addon:RegisterChatCommand("cra", "Activate") 370 addon:RegisterChatCommand("cra", "Activate")
371 addon:RegisterChatCommand("crossrealmassist", "Activate") 371 addon:RegisterChatCommand("crossrealmassist", "Activate")
372 if db.global.autoCreateHopGroup then 372 if db.global.autoCreateHopGroup then
373 addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") 373 addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate")
374 end 374 end
375 end 375 end
376 376
377 function addon:OnDisable() 377 function addon:OnDisable()
378 addon:Deactivate() 378 addon:Deactivate()
379 end 379 end
765 -- Auto action button 765 -- Auto action button
766 766
767 local action 767 local action
768 768
769 local function getPartyStat() 769 local function getPartyStat()
770 local curPartyStat = {} 770 local curPartyStat = {}
771 if IsInGroup() then 771 if IsInGroup() then
772 if IsInRaid() then 772 if IsInRaid() then
773 for i=1, MAX_RAID_MEMBERS do 773 for i=1, MAX_RAID_MEMBERS do
774 addon:AddUnitIdStat("raid"..i, curPartyStat) 774 addon:AddUnitIdStat("raid"..i, curPartyStat)
775 end 775 end
777 for i=1, MAX_PARTY_MEMBERS do 777 for i=1, MAX_PARTY_MEMBERS do
778 addon:AddUnitIdStat("party"..i, curPartyStat) 778 addon:AddUnitIdStat("party"..i, curPartyStat)
779 end 779 end
780 end 780 end
781 end 781 end
782 return curPartyStat 782 return curPartyStat
783 end 783 end
784 784
785 local LeaveGroup = { 785 local LeaveGroup = {
786 func = LeaveParty; 786 func = LeaveParty;
787 tooltip = function(self) 787 tooltip = function(self)
944 944
945 945
946 -- Realm hop group 946 -- Realm hop group
947 947
948 local function CreateHopGroup() 948 local function CreateHopGroup()
949 if canJoinGroup() then 949 if canJoinGroup() then
950 C_LFGList.CreateListing(16,"Realm hopping - "..homeRealm,0,"","",true) 950 C_LFGList.CreateListing(16,"Realm hopping - "..homeRealm,0,"","",true)
951 addon:ScheduleTimer(ConvertToRaid, 5) 951 addon:ScheduleTimer(ConvertToRaid, 5)
952 end 952 end
953 end 953 end
954 954
955 function addon:PlayerFlagsUpdate(event, target) 955 function addon:PlayerFlagsUpdate(event, target)
956 if target == "player" and UnitIsAFK("player") and C_Garrison.IsOnGarrisonMap() and db.global.autoCreateHopGroup then 956 if target == "player" and UnitIsAFK("player") and C_Garrison.IsOnGarrisonMap() and db.global.autoCreateHopGroup then
957 CreateHopGroup() 957 CreateHopGroup()
958 end 958 end
959 end 959 end
960 960
961 -- Settings 961 -- Settings
962 962
963 local function toggleMinimapIcon(btn, arg1, arg2, checked) 963 local function toggleMinimapIcon(btn, arg1, arg2, checked)
987 db.global.applyAsDD = checked 987 db.global.applyAsDD = checked
988 end 988 end
989 989
990 local function toggleCreateHopGroup(btn, arg1, arg2, checked) 990 local function toggleCreateHopGroup(btn, arg1, arg2, checked)
991 db.global.autoCreateHopGroup = checked 991 db.global.autoCreateHopGroup = checked
992 if checked then addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") end 992 if checked then addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") end
993 end 993 end
994 994
995 local function ClearJoinHistory() 995 local function ClearJoinHistory()
996 recentgroups = {} 996 recentgroups = {}
997 addon:UpdateAutoButtonStatus() 997 addon:UpdateAutoButtonStatus()
998 if lfgTable then lfgTable:Refresh() end 998 if lfgTable then lfgTable:Refresh() end
999 end 999 end
1000 1000
1001 local function QuickJoinStoplist() 1001 local function QuickJoinStoplist()
1002 StaticPopupDialogs["CROSS_REALM_ASSIST_STOPLIST"] = { 1002 StaticPopupDialogs["CROSS_REALM_ASSIST_STOPLIST"] = {
1003 OnShow = function (self, data) 1003 OnShow = function (self, data)
1004 self.editBox:SetText(table.concat(db.global.stoplist or {}, ",")) 1004 self.editBox:SetText(table.concat(db.global.stoplist or {}, ","))
1005 end, 1005 end,
1006 OnAccept=function(self) 1006 OnAccept=function(self)
1007 local text = self.editBox:GetText(); 1007 local text = self.editBox:GetText();
1008 local stoplist = {} 1008 local stoplist = {}
1009 for item in string.gmatch(text, "[^, ][^,]*") do 1009 for item in string.gmatch(text, "[^, ][^,]*") do
1010 table.insert(stoplist,string.lower(item)) 1010 table.insert(stoplist,string.lower(item))
1011 end 1011 end
1012 db.global.stoplist = stoplist 1012 db.global.stoplist = stoplist
1013 end, 1013 end,
1014 button1 = OKAY, 1014 button1 = OKAY,
1015 button2 = CANCEL, 1015 button2 = CANCEL,
1016 editBoxWidth = 350, 1016 editBoxWidth = 350,
1017 hasEditBox=true, 1017 hasEditBox=true,
1018 text = "Ignore groups containing following words:\nSeparated by comma", 1018 text = "Ignore groups containing following words:\nSeparated by comma",
1019 preferredIndex = 3 1019 preferredIndex = 3
1020 } 1020 }
1021 StaticPopup_Show("CROSS_REALM_ASSIST_STOPLIST") 1021 StaticPopup_Show("CROSS_REALM_ASSIST_STOPLIST")
1022 end 1022 end
1023 1023
1024 local function initMenu(self, level) 1024 local function initMenu(self, level)
1025 if not level then return end 1025 if not level then return end
1026 if level == 1 then 1026 if level == 1 then
1027 UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level) 1027 UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level)
1028 UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level) 1028 UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level)
1029 1029
1030 if canJoinGroup() then 1030 if canJoinGroup() then
1031 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) 1031 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
1032 UIDropDownMenu_AddButton({text="Create a group for realm hoppers",notCheckable=1,func=CreateHopGroup}, level) 1032 UIDropDownMenu_AddButton({text="Create a group for realm hoppers",notCheckable=1,func=CreateHopGroup}, level)
1033 end 1033 end
1034 1034
1035 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) 1035 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
1036 UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level) 1036 UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level)
1037 UIDropDownMenu_AddButton({text="Settings",notCheckable=1,hasArrow=1,value="settings",keepShownOnClick=true}, level) 1037 UIDropDownMenu_AddButton({text="Settings",notCheckable=1,hasArrow=1,value="settings",keepShownOnClick=true}, level)
1038 elseif level == 2 then 1038 elseif level == 2 then
1039 if UIDROPDOWNMENU_MENU_VALUE == "settings" then 1039 if UIDROPDOWNMENU_MENU_VALUE == "settings" then
1040 UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level) 1040 UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level)
1041 UIDropDownMenu_AddButton({text="All language groups",checked=db.global.allLanguages, func=toggleAllLanguages,keepShownOnClick=true,isNotRadio=true}, level) 1041 UIDropDownMenu_AddButton({text="All language groups",checked=db.global.allLanguages, func=toggleAllLanguages,keepShownOnClick=true,isNotRadio=true}, level)
1042 UIDropDownMenu_AddButton({text="Apply to groups as DD only",checked=db.global.applyAsDD, func=toggleApplyAsDD,keepShownOnClick=true,isNotRadio=true}, level) 1042 UIDropDownMenu_AddButton({text="Apply to groups as DD only",checked=db.global.applyAsDD, func=toggleApplyAsDD,keepShownOnClick=true,isNotRadio=true}, level)
1043 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) 1043 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
1044 UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level) 1044 UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level)
1045 UIDropDownMenu_AddButton({text="Edit Quick Join Stoplist",notCheckable=1,func=QuickJoinStoplist}, level) 1045 UIDropDownMenu_AddButton({text="Edit Quick Join Stoplist",notCheckable=1,func=QuickJoinStoplist}, level)
1046 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) 1046 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
1047 UIDropDownMenu_AddButton({text="Experimental features",notCheckable=1,hasArrow=1,value="experimental",keepShownOnClick=true}, level) 1047 UIDropDownMenu_AddButton({text="Experimental features",notCheckable=1,hasArrow=1,value="experimental",keepShownOnClick=true}, level)
1048 end 1048 end
1049 elseif level == 3 then 1049 elseif level == 3 then
1050 if UIDROPDOWNMENU_MENU_VALUE == "qjc" then 1050 if UIDROPDOWNMENU_MENU_VALUE == "qjc" then
1051 for i=1,#lfgGroups do 1051 for i=1,#lfgGroups do
1052 local groupId = lfgGroups[i] 1052 local groupId = lfgGroups[i]
1053 UIDropDownMenu_AddButton({text=(C_LFGList.GetCategoryInfo(groupId)),checked=db.global.quickJoin[groupId],arg1=groupId,func=toggleQuickJoin,keepShownOnClick=true,isNotRadio=true}, level) 1053 UIDropDownMenu_AddButton({text=(C_LFGList.GetCategoryInfo(groupId)),checked=db.global.quickJoin[groupId],arg1=groupId,func=toggleQuickJoin,keepShownOnClick=true,isNotRadio=true}, level)
1054 end 1054 end
1055 elseif UIDROPDOWNMENU_MENU_VALUE == "experimental" then 1055 elseif UIDROPDOWNMENU_MENU_VALUE == "experimental" then
1056 UIDropDownMenu_AddButton({isTitle=1,text="Use at your own risk!",notCheckable=1}, level) 1056 UIDropDownMenu_AddButton({isTitle=1,text="Use at your own risk!",notCheckable=1}, level)
1057 UIDropDownMenu_AddButton({text="Auto create group for realm hopping when AFK at garrison",checked=db.global.autoCreateHopGroup,keepShownOnClick=true,isNotRadio=true,func=toggleCreateHopGroup}, level) 1057 UIDropDownMenu_AddButton({text="Auto create group for realm hopping when AFK at garrison",checked=db.global.autoCreateHopGroup,keepShownOnClick=true,isNotRadio=true,func=toggleCreateHopGroup}, level)
1058 end 1058 end
1059 end 1059 end
1060 end 1060 end
1061 1061
1062 function addon.ShowSettings(frame) 1062 function addon.ShowSettings(frame)
1063 if not settingsMenu then 1063 if not settingsMenu then
1064 settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu") 1064 settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu")