fix auto-hide and add /leoalt checklist to toggle it

Leandro Silva [02-18-20 - 14:27]
fix auto-hide and add /leoalt checklist to toggle it
Filename
LeoAltholic.lua
LeoAltholic.txt
LeoAltholicInit.lua
ui/checklist.lua
diff --git a/LeoAltholic.lua b/LeoAltholic.lua
index b44d9e6..890848f 100644
--- a/LeoAltholic.lua
+++ b/LeoAltholic.lua
@@ -1206,9 +1206,7 @@ local function onGameMenuEnter()
 end

 local function onGameMenuExit()
-    if LeoAltholicChecklistUI.IsEnabled() and not LeoAltholicChecklistUI.IsHideWhenToolbar() then
-        LeoAltholicChecklist:SetHidden(false)
-    end
+    LeoAltholicChecklistUI:CheckHide()
 end

 local function initialize()
@@ -1339,7 +1337,17 @@ local function onAddOnLoaded(event, addonName)
     if GetDisplayName() == "@LeandroSilva" then
         SLASH_COMMANDS["/rr"] = function(cmd) ReloadUI() end
     end
-    SLASH_COMMANDS["/leoalt"] = function(cmd) LeoAltholic:ToggleUI() end
+    SLASH_COMMANDS["/leoalt"] = function(cmd)
+        if not cmd or cmd == "" then
+            LeoAltholic:ToggleUI()
+            return
+        end
+
+        if cmd == "checklist" then
+            LeoAltholicChecklistUI.ToggleUI()
+            return
+        end
+    end

     initializeVars()

diff --git a/LeoAltholic.txt b/LeoAltholic.txt
index c26eb4c..62d60a3 100644
--- a/LeoAltholic.txt
+++ b/LeoAltholic.txt
@@ -1,7 +1,7 @@
 ## Title: Leo's Altholic
 ## APIVersion: 100029 100030
-## Version: 1.7.6
-## AddOnVersion: 176
+## Version: 1.7.7
+## AddOnVersion: 177
 ## Author: |c39B027@LeandroSilva|r
 ## SavedVariables: LeoAltholicSavedVariables LeoAltholicCharVariables
 ## DependsOn: LibStub LibFeedback LibAddonMenu-2.0
diff --git a/LeoAltholicInit.lua b/LeoAltholicInit.lua
index 617f553..92d433f 100644
--- a/LeoAltholicInit.lua
+++ b/LeoAltholicInit.lua
@@ -6,7 +6,7 @@ LeoAltholicToolbarUI = LeoAltholicToolbarUI or {}

 LeoAltholic.name = "LeoAltholic"
 LeoAltholic.displayName = "Leo's Altholic"
-LeoAltholic.version = "1.7.6"
+LeoAltholic.version = "1.7.7"
 LeoAltholic.chatPrefix = "|c39B027" .. LeoAltholic.name .. "|r: "

 LeoAltholic.TAB_BIO = "Bio"
diff --git a/ui/checklist.lua b/ui/checklist.lua
index df3d7c7..91f9257 100644
--- a/ui/checklist.lua
+++ b/ui/checklist.lua
@@ -23,7 +23,6 @@ function LeoAltholicChecklistUI.GetFontScale()
 end
 function LeoAltholicChecklistUI.SetMinimized(value)
     LeoAltholic.globalData.settings.checklist.minimized = value
-    LeoAltholicChecklistUI.update()
 end
 function LeoAltholicChecklistUI.IsMinimized()
     if LeoAltholic.globalData.settings.checklist.minimized == nil then LeoAltholic.globalData.settings.checklist.minimized = false end
@@ -99,22 +98,28 @@ function LeoAltholicChecklistUI.ShowUI()
     LeoAltholicChecklist:SetHidden(false)
 end

+function LeoAltholicChecklistUI.CheckHide()
+    if not LeoAltholicChecklistUI.IsEnabled() or LeoAltholicChecklistUI.IsHideWhenToolbar() then
+        LeoAltholicChecklist:SetHidden(true)
+        return
+    end
+
+    if LeoAltholicChecklistUI.checkAllDone() then
+        LeoAltholicChecklist:SetHidden(true)
+        return
+    end
+
+    LeoAltholicChecklist:SetHidden(false)
+    LeoAltholicChecklistUI.MaximizeUI()
+end
+
 function LeoAltholicChecklistUI.RestorePosition()
     local position = LeoAltholicChecklistUI.GetPosition()
     local left = position.left
     local top = position.top
     LeoAltholicChecklist:ClearAnchors()
     LeoAltholicChecklist:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
-    if LeoAltholicChecklistUI.IsEnabled() and not LeoAltholicChecklistUI.IsHideWhenToolbar() then
-		LeoAltholicChecklist:SetHidden(false)
-        if not LeoAltholicChecklistUI.checkAllDone() then    --added by Teva
-            LeoAltholicChecklistUI.MaximizeUI()
-        else
-            LeoAltholicChecklistUI.MinimizeUI()
-        end
-    else
-        LeoAltholicChecklist:SetHidden(true)
-    end
+    LeoAltholicChecklistUI:CheckHide()
 end

 local SPACE = 34
@@ -264,7 +269,7 @@ function LeoAltholicChecklistUI.checkAllDone()
     if LeoAltholicChecklistUI.GetRiding() and char.attributes.riding.time - GetTimeStamp() < 0 then
         return false
     end
---    LeoAltholicChecklist:SetHidden(true)
+
     return true
 end

@@ -276,7 +281,6 @@ function LeoAltholicChecklistUI.doneWrit(craft)
     local label = GetControl(panel, "Craft"..craft)
     local texture = GetControl(panel, "Craft"..craft.."Status")
     writdoneItem(label, texture)        --TevaNOTE: was doneItem but was always saying that instead of between, so modified to at least warn it might be wrong
-    if LeoAltholicChecklistUI.checkAllDone() then LeoAltholicChecklistUI.MinimizeUI() end
     LeoAltholicChecklistUI.update()    --TevaNOTE: this line may be the key to solving the between/done issue in the checklist!
 end

@@ -326,7 +330,7 @@ function LeoAltholicChecklistUI.doneRiding()
     local label = GetControl(panel, "Riding")
     local texture = GetControl(panel, "RidingStatus")
     doneItem(label, texture)
-    if LeoAltholicChecklistUI.checkAllDone() then LeoAltholicChecklistUI.MinimizeUI() end
+    LeoAltholicChecklistUI.update()
 end

 function LeoAltholicChecklistUI.initializeQuests()
@@ -413,7 +417,6 @@ function LeoAltholicChecklistUI.update()
         if canShow == true then
             if isDone then
                 doneItem(label, texture)
-                LeoAltholicChecklistUI.checkAllDone()
             elseif isBetween then    --Teva added the isBetween condition and effects
                 betweenItem(label, texture)
             elseif isPreDeliver then
@@ -427,24 +430,6 @@ function LeoAltholicChecklistUI.update()
                 texture.tooltip = "Never Done or Needs Reload UI"
                 --texture:SetColor(1,0,0,1) --red
             end
---[[--
-            if isStarted then
-                startItem(label, texture)
-            elseif isUpdated then
-                updateItem(label, texture)
-            elseif isPreDeliver then
-                preDeliverItem(label, texture)
-            elseif isBetween then    --Teva added isBetween condition and effects
-                betweenItem(label, texture)
-            elseif isDone then
-                doneItem(label, texture)
---                LeoAltholicChecklistUI.checkAllDone()
-            else
-                texture:SetTexture("esoui/art/buttons/decline_up.dds")
-                texture.tooltip = "Never Done or Needs Reload UI"
-                --texture:SetColor(1,0,0,1) --red
-            end
---]]--
         end
     end

@@ -455,7 +440,6 @@ function LeoAltholicChecklistUI.update()
     createItem(label, GetString(SI_STAT_GAMEPAD_RIDING_HEADER_TRAINING), texture, craftIcon, LeoAltholicChecklistUI.GetRiding())
     if char.attributes.riding.time > 0 and char.attributes.riding.time - GetTimeStamp() > 0 then
         doneItem(label, texture)
-        LeoAltholicChecklistUI.checkAllDone()
     else
         betweenItem(label, texture)
     end
@@ -481,4 +465,6 @@ function LeoAltholicChecklistUI.update()
     panel:SetWidth(width)
     header:SetWidth(width)
     checklist:SetScale(scale)
+
+    LeoAltholicChecklistUI:CheckHide()
 end