Kyoma: Updated AutoInvite to the latest API version and fixed the error on startup

Sasky [11-10-15 - 03:30]
Kyoma: Updated AutoInvite to the latest API version and fixed the error on startup

Sasky: Import differences for whitespace and quick exit in one location
Filename
AutoInvite.txt
lang/en.lua
lua/queue.lua
ui/ai_enabled_fragment.lua
ui/ai_options_fragment.lua
ui/autoinvitescene.lua
ui/half_grouplist.lua
diff --git a/AutoInvite.txt b/AutoInvite.txt
index 5c2f82b..7b06bd6 100644
--- a/AutoInvite.txt
+++ b/AutoInvite.txt
@@ -1,7 +1,7 @@
-## APIVersion: 100011
+## APIVersion: 100013
 ## Title: AutoInvite
-## Version: 2.1.2
-## Author: Sasky
+## Version: 2.1.4
+## Author: Sasky & Kyoma
 ## SavedVariables: AutoInviteSettings
 ## OptionalDependsOn: LibAddonMenu-2.0

diff --git a/lang/en.lua b/lang/en.lua
index 25f12b4..3b5d546 100644
--- a/lang/en.lua
+++ b/lang/en.lua
@@ -53,6 +53,7 @@ ZO_CreateStringId("SI_AUTO_INVITE_TT_KICK_TIME", "Number of seconds to wait befo
 ZO_CreateStringId("SI_AUTO_INVITE_OPT_SLASHCMD", "Slash Commands")
 ZO_CreateStringId("SI_AUTO_INVITE_BTN_REFRESH", "Refresh List")
 ZO_CreateStringId("SI_AUTO_INVITE_BTN_REFORM", "Re-form Group")
+ZO_CreateStringId("SI_AUTO_INVITE_BTN_REINVITE", "Re-Invite Group")

 --Slash commands
 --Note: Don't translate between the color codes  |C ... |r
diff --git a/lua/queue.lua b/lua/queue.lua
index ec0d1dc..245c6ef 100644
--- a/lua/queue.lua
+++ b/lua/queue.lua
@@ -77,13 +77,25 @@ function AutoInvite:processQueue()
         local name = queue:pop()
         sentCount = sentCount + 1
         self.sentInvite[name] = now
-        GroupInviteByName(name)
+        if self.player ~= name then
+            GroupInviteByName(name)
+        end
         MINI_GROUP_LIST:updateSingle(name)
     end

     AutoInvite.sentInvites = math.max(sentCount, 0)
 end

+function AutoInvite:IsPlayerInSameGroup(name)
+    for i=1, GetGroupSize() do
+        local tag = GetGroupUnitTagByIndex(i)
+        if GetUnitName(tag) == name then
+            return true
+        end
+    end
+    return false
+end
+
 function AutoInvite:IsInviteSent(name)
     return AutoInvite.sentInvite[name]
 end
@@ -135,6 +147,19 @@ function AutoInvite:resetGroup()
     zo_callLater(function() AutoInvite:processQueue() end, 2000)
 end

+function AutoInvite:inviteGroup()
+   --self:resetQueues()
+   --for i=1,GetGroupSize() do
+   --    local tag = GetGroupUnitTagByIndex(i)
+   --    local name = GetUnitName(tag)
+   --    queue:push(name)
+   --    GroupDisband()
+   --    GroupLeave() --for group leader bug
+   --end
+
+    zo_callLater(function() AutoInvite:processQueue() end, 2000)
+end
+
 local responseCodes = {
     [GROUP_INVITE_RESPONSE_ACCEPTED] = "accept",
     [GROUP_INVITE_RESPONSE_ALREADY_GROUPED] = "inGroup",
@@ -166,4 +191,4 @@ function AutoInvite:invitePlayer(name)
     if name ~= self.player then
         queue:push(name)
     end
-end
\ No newline at end of file
+end
diff --git a/ui/ai_enabled_fragment.lua b/ui/ai_enabled_fragment.lua
index 660cd37..8c56986 100644
--- a/ui/ai_enabled_fragment.lua
+++ b/ui/ai_enabled_fragment.lua
@@ -52,6 +52,7 @@ function AutoInviteUI:CreateEnabledFragment()
         --width = "half"
     })
     ui.text:SetWidth(260)
+    ui.text.container:SetWidth(140)
     ui.text:SetAnchor(TOPRIGHT, ZO_GroupList, TOPRIGHT, -40, 20)

     AUTO_INVITE_ENABLED_FRAGMENT = ZO_FadeSceneFragment:New(ui.main)
diff --git a/ui/ai_options_fragment.lua b/ui/ai_options_fragment.lua
index 17b353e..785191b 100644
--- a/ui/ai_options_fragment.lua
+++ b/ui/ai_options_fragment.lua
@@ -99,6 +99,12 @@ function AutoInviteUI:CreateOptionFragment()
     ui.regroup:SetText(GetString(SI_AUTO_INVITE_BTN_REFORM))
     ui.regroup:SetHandler("OnClicked", function() AutoInvite:resetGroup() end)

+    ui.invite = wm:CreateControlFromVirtual(nil, ui.main, "ZO_DefaultButton")
+    ui.invite:SetAnchor(TOPLEFT, ui.kickTime, BOTTOMLEFT, 70, 105)
+    ui.invite:SetWidth(160)
+    ui.invite:SetText(GetString(SI_AUTO_INVITE_BTN_REINVITE))
+    ui.invite:SetHandler("OnClicked", function() AutoInvite:inviteGroup() end)
+
     local slashcmds = GetString(SI_AUTO_INVITE_SLASHCMD_START) ..
             "\n" .. GetString(SI_AUTO_INVITE_SLASHCMD_HELP) ..
             "\n" .. GetString(SI_AUTO_INVITE_SLASHCMD_STOP)
@@ -111,4 +117,4 @@ function AutoInviteUI:CreateOptionFragment()
     ui.note.desc:SetColor(.7,.7,.7,1)

     AUTO_INVITE_OPTIONS_FRAGMENT = ZO_FadeSceneFragment:New(ui.main)
-end
\ No newline at end of file
+end
diff --git a/ui/autoinvitescene.lua b/ui/autoinvitescene.lua
index 6271543..17f3fca 100644
--- a/ui/autoinvitescene.lua
+++ b/ui/autoinvitescene.lua
@@ -91,8 +91,10 @@ function AutoInviteUI:CreateScene()
     AUTO_INVITE_SCENE:AddFragment(AUTO_INVITE_OPTIONS_FRAGMENT)
     AUTO_INVITE_SCENE:AddFragment(AUTO_INVITE_ENABLED_FRAGMENT)

-    local indx = #MAIN_MENU.sceneGroupInfo.groupSceneGroup.menuBarIconData + 1
-    MAIN_MENU.sceneGroupInfo.groupSceneGroup.menuBarIconData[indx] = {
+    local mainMenu = GetAPIVersion() <= 100012 and MAIN_MENU or MAIN_MENU_KEYBOARD
+
+    local indx = #mainMenu.sceneGroupInfo.groupSceneGroup.menuBarIconData + 1
+    mainMenu.sceneGroupInfo.groupSceneGroup.menuBarIconData[indx] = {
         categoryName = SI_AUTO_INVITE,
         descriptor = "autoInvite",
         normal = "EsoUI/Art/Campaign/campaign_tabIcon_summary_up.dds",
@@ -101,10 +103,10 @@ function AutoInviteUI:CreateScene()
     }

     SCENE_MANAGER:GetSceneGroup("groupSceneGroup").scenes[indx] = "autoInvite"
-    AUTO_INVITE_SCENE:AddFragment(ZO_FadeSceneFragment:New(MAIN_MENU.sceneGroupBar))
+    AUTO_INVITE_SCENE:AddFragment(ZO_FadeSceneFragment:New(mainMenu.sceneGroupBar))

 --    AUTO_INVITE_SCENE:RegisterCallback("StateChange", manageKeybinds)

     --TODO: Constant for the magic number?
-    MAIN_MENU:AddRawScene("autoInvite", 6, MAIN_MENU.categoryInfo[6], "groupSceneGroup")
-end
\ No newline at end of file
+    mainMenu:AddRawScene("autoInvite", 6, mainMenu.categoryInfo[6], "groupSceneGroup")
+end
diff --git a/ui/half_grouplist.lua b/ui/half_grouplist.lua
index 1be3a11..6a2cb7c 100644
--- a/ui/half_grouplist.lua
+++ b/ui/half_grouplist.lua
@@ -32,8 +32,9 @@ local STATUS_ORDERING = setmetatable({
     OFFLINE = 2,
     SENT = 3,
     QUEUE = 4,
-    UNKNOWN = 5
-}, { __index = function() return 5 end })
+    GROUPED = 5,
+    UNKNOWN = 6,
+}, { __index = function() return 6 end })

 function AI_SmallGroupListing:New(control)
     local manager = ZO_SortFilterList.New(self, control)
@@ -115,6 +116,10 @@ function AI_SmallGroupListing:getStatus(data)
         return "|c999999Queue"
     end

+    if status == STATUS_ORDERING.GROUPED then
+        return "|cFB2B2BGrouped"
+    end
+
     return ""
 end

@@ -208,6 +213,12 @@ end
 function AI_SLG_Entry:Update()
     local name = self.displayName or ""
     local tag = self.unitName
+
+    local grouped = IsPlayerInGroup(name) and not AutoInvite:IsPlayerInSameGroup(name)
+    if grouped then
+        self.status = STATUS_ORDERING.GROUPED
+        return;
+    end
     if GetUnitName(tag) == name then
         local offline = AutoInvite.kickTable[name]
         if IsUnitOnline(tag) then
@@ -274,4 +285,4 @@ end

 function AI_SmallGroupListing_OnInitialized(self)
     MINI_GROUP_LIST = AI_SmallGroupListing:New(self)
-end
\ No newline at end of file
+end