changeset 27:42a70f4b2ff5

New beta features: - Quick join stoplist (Ignore key words) - Create group button - Experimental auto create group
author ShadowTheAge
date Sun, 27 Sep 2015 16:03:43 +0300
parents 521897e5e0b9
children 2e9ff79f6969
files CrossRealmAssist.lua
diffstat 1 files changed, 108 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/CrossRealmAssist.lua	Sat Sep 26 13:23:04 2015 +0300
+++ b/CrossRealmAssist.lua	Sun Sep 27 16:03:43 2015 +0300
@@ -12,7 +12,7 @@
 local cbHideGroups, cbHideRaids, cbHideNoAutoinv
 
 local tabs = {}
-local curRealmStat, curPartyStat
+local curRealmStat
 local scanstate=0
 local recentRealms={}
 local recentgroups={}
@@ -44,8 +44,9 @@
         minimap = {},
         widgetPos=DefaultWidgetPos,
         quickJoinHint = true,
-        quickJoin={[6]=1,[10]=1},
-        allLanguages = true
+        quickJoin={[6]=1},
+        allLanguages = true,
+		stoplist = {"no hop","kick"}
     }
 }
 
@@ -165,11 +166,18 @@
     local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id)
     if delisted then return 0 end
     local name,realm = PlayerName(fullname);
+	local stoplist = db.global.stoplist or {}
+	local ldesc = string.lower(caption) .. "|" .. string.lower(desc);
+	local isHopGroup = string.find(ldesc, "realm hop")
+	for i=1, #stoplist do
+		if string.find(ldesc, stoplist[i], 1, true) then return 0 end
+	end
     if forAutoJoin then
-        if not autoinv or pcount >= 35 or pcount <= 5 or recentgroups[fullname] then return 0 end
+        if not autoinv or recentgroups[fullname] or (not isHopGroup and (pcount >= 35 or pcount <= 5)) then return 0 end
     end
 
     local autoinvWeight = autoinv and 5 or 2
+	local hopCoef = isHopGroup and 3 or 1
 
     local visCoef = 1
     if recentgroups[fullname] then
@@ -186,16 +194,17 @@
     end
 
     local countWeight = 4 -- count weight
-    if pcount >= 39 or pcount <= 1 then countWeight = 1
-    elseif pcount >= 35 or pcount <= 5 then countWeight = 2
-    elseif pcount >= 30 or pcount <= 10 then countWeight = 3
-    else countWeight = 4 end
+	if not isHopGroup then
+		if pcount >= 39 or pcount <= 1 then countWeight = 1
+		elseif pcount >= 35 or pcount <= 5 then countWeight = 2
+		elseif pcount >= 30 or pcount <= 10 then countWeight = 3 end
+    end
 
     local ageWeight = 2
     if time > 1200 then ageWeight = 4
     elseif time > 300 then ageWeight = 3 end
 
-    return leaderRealm * countWeight * visCoef * autoinvWeight * ageWeight;
+    return leaderRealm * countWeight * visCoef * autoinvWeight * ageWeight * hopCoef;
 end
 
 local function AddLfgGroupInfo(id, short)
@@ -342,14 +351,6 @@
     tooltip:Show()
 end
 
---[[function addon.MmClick(self, button)
-    if button == "RightButton" then
-        addon.ShowSettings(self)
-    else
-        addon:Activate()
-    end
-end]]
-
 function addon:OnInitialize()
     db = LibStub("AceDB-3.0"):New("CrossRealmAssistDB", SettingsDefaults)
     local minimapData = ldb:NewDataObject("CrossRealmAssistMinimapIcon",{
@@ -368,6 +369,9 @@
     homeRealm = GetRealmName()
     addon:RegisterChatCommand("cra", "Activate")
     addon:RegisterChatCommand("crossrealmassist", "Activate")
+	if db.global.autoCreateHopGroup then
+		addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate")
+	end
 end
 
 function addon:OnDisable()
@@ -621,22 +625,9 @@
 end
 
 function addon:updatePartyInfo()
-    curPartyStat = {}
-    local inGroup = IsInGroup()
-    if inGroup then
-        if IsInRaid() then
-            for i=1, MAX_RAID_MEMBERS do
-                addon:AddUnitIdStat("raid"..i, curPartyStat)
-            end
-        else
-            for i=1, MAX_PARTY_MEMBERS do
-                addon:AddUnitIdStat("party"..i, curPartyStat)
-            end
-        end
-    end
-    if inGroup ~= wasInGroup  then
+    if IsInGroup() ~= wasInGroup  then
         addon:RefreshZone(true)
-        wasInGroup = inGroup
+        wasInGroup = IsInGroup()
         addon:UpdateAutoButtonStatus()
     end
 end
@@ -669,7 +660,7 @@
         if scanstate == 0 then
             addon:ScanRealm()
         elseif shedule == true and scanstate == 2 then
-            addon:SetStatus("Rescan sheduled...")
+            addon:SetStatus("Rescan scheduled...")
             scanstate = 3
         end
     end
@@ -681,7 +672,7 @@
     if InCombatLockdown() then
         addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat")
         scanstate = 1
-        addon:SetStatus("Scan sheduled after combat...");
+        addon:SetStatus("Scan scheduled after combat...");
         return
     end
     scanstate = 2
@@ -775,10 +766,26 @@
 
 local action
 
+local function getPartyStat()
+	local curPartyStat = {}
+    if IsInGroup() then
+        if IsInRaid() then
+            for i=1, MAX_RAID_MEMBERS do
+                addon:AddUnitIdStat("raid"..i, curPartyStat)
+            end
+        else
+            for i=1, MAX_PARTY_MEMBERS do
+                addon:AddUnitIdStat("party"..i, curPartyStat)
+            end
+        end
+    end
+	return curPartyStat
+end
+
 local LeaveGroup = {
     func = LeaveParty;
     tooltip = function(self)
-        local partyStat = addon:GetRealmStat(curPartyStat)
+        local partyStat = addon:GetRealmStat(getPartyStat())
         GameTooltip:AddLine("Players in party "..partyStat.players)
         local max = partyStat.max;
         for i=1,#partyStat do
@@ -936,7 +943,20 @@
 
 
 
+-- Realm hop group
 
+local function CreateHopGroup()
+	if canJoinGroup() then
+		C_LFGList.CreateListing(16,"Realm hopping - "..homeRealm,0,"","",true)
+		addon:ScheduleTimer(ConvertToRaid, 5)
+	end
+end
+
+function addon:PlayerFlagsUpdate(event, target)
+	if target == "player" and UnitIsAFK("player") and C_Garrison.IsOnGarrisonMap() and db.global.autoCreateHopGroup then
+		CreateHopGroup()
+	end
+end
 
 -- Settings
 
@@ -967,40 +987,76 @@
     db.global.applyAsDD = checked
 end
 
+local function toggleCreateHopGroup(btn, arg1, arg2, checked)
+    db.global.autoCreateHopGroup = checked
+	if checked then addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") end
+end
+
 local function ClearJoinHistory()
     recentgroups = {}
     addon:UpdateAutoButtonStatus()
     if lfgTable then lfgTable:Refresh() end
 end
 
---[[local function resetPos()
-    db.global.widgetPos = DefaultWidgetPos
-    if gui then
-        gui:ClearAllPoints()
-        gui:SetPoint(DefaultWidgetPos.to,DefaultWidgetPos.x,DefaultWidgetPos.y)
-    end
-end]]
+local function QuickJoinStoplist()
+    StaticPopupDialogs["CROSS_REALM_ASSIST_STOPLIST"] = {
+		OnShow = function (self, data)
+			self.editBox:SetText(table.concat(db.global.stoplist or {}, ","))
+		end,
+		OnAccept=function(self)
+			local text = self.editBox:GetText();
+			local stoplist = {}
+			for item in string.gmatch(text, "[^, ][^,]*") do
+				table.insert(stoplist,string.lower(item))
+			end
+			db.global.stoplist = stoplist
+		end,
+		button1 = OKAY,
+		button2 = CANCEL,
+		editBoxWidth = 350,
+		hasEditBox=true,
+		text = "Ignore groups containing following words:\nSeparated by comma",
+		preferredIndex = 3
+	}
+	StaticPopup_Show("CROSS_REALM_ASSIST_STOPLIST")
+end
 
 local function initMenu(self, level)
     if not level then return end
     if level == 1 then
         UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level)
         UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level)
-        UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
-        UIDropDownMenu_AddButton({isTitle=1,text="Settings",notCheckable=1}, level)
-        UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level)
-        UIDropDownMenu_AddButton({text="All language groups",checked=db.global.allLanguages, func=toggleAllLanguages,keepShownOnClick=true,isNotRadio=true}, level)
-        UIDropDownMenu_AddButton({text="Apply to groups as DD only",checked=db.global.applyAsDD, func=toggleApplyAsDD,keepShownOnClick=true,isNotRadio=true}, level)
-        UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level)
-        UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level)
+		
+		if canJoinGroup() then
+			UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
+			UIDropDownMenu_AddButton({text="Create a group for realm hoppers",notCheckable=1,func=CreateHopGroup}, level)
+		end
+		
+		UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
+		UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level)
+		UIDropDownMenu_AddButton({text="Settings",notCheckable=1,hasArrow=1,value="settings",keepShownOnClick=true}, level)
     elseif level == 2 then
-        if UIDROPDOWNMENU_MENU_VALUE == "qjc" then
+		if UIDROPDOWNMENU_MENU_VALUE == "settings" then
+			UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level)
+			UIDropDownMenu_AddButton({text="All language groups",checked=db.global.allLanguages, func=toggleAllLanguages,keepShownOnClick=true,isNotRadio=true}, level)
+			UIDropDownMenu_AddButton({text="Apply to groups as DD only",checked=db.global.applyAsDD, func=toggleApplyAsDD,keepShownOnClick=true,isNotRadio=true}, level)
+			UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
+			UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level)
+			UIDropDownMenu_AddButton({text="Edit Quick Join Stoplist",notCheckable=1,func=QuickJoinStoplist}, level)
+			UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
+			UIDropDownMenu_AddButton({text="Experimental features",notCheckable=1,hasArrow=1,value="experimental",keepShownOnClick=true}, level)
+		end
+    elseif level == 3 then
+		if UIDROPDOWNMENU_MENU_VALUE == "qjc" then
             for i=1,#lfgGroups do
                 local groupId = lfgGroups[i]
                 UIDropDownMenu_AddButton({text=(C_LFGList.GetCategoryInfo(groupId)),checked=db.global.quickJoin[groupId],arg1=groupId,func=toggleQuickJoin,keepShownOnClick=true,isNotRadio=true}, level)
             end
-        end
-    end
+        elseif UIDROPDOWNMENU_MENU_VALUE == "experimental" then
+			UIDropDownMenu_AddButton({isTitle=1,text="Use at your own risk!",notCheckable=1}, level)
+			UIDropDownMenu_AddButton({text="Auto create group for realm hopping when AFK at garrison",checked=db.global.autoCreateHopGroup,keepShownOnClick=true,isNotRadio=true,func=toggleCreateHopGroup}, level)
+		end
+	end
 end
 
 function addon.ShowSettings(frame)