new version 1.0.2

esorochinskiy [06-06-22 - 07:00]
new version 1.0.2
filter added
Filename
UI.lua
WellEater.lua
WellEater.txt
WellEater.xml
lang/de.lua
lang/en.lua
lang/ru.lua
diff --git a/UI.lua b/UI.lua
index 81a3993..66089c4 100644
--- a/UI.lua
+++ b/UI.lua
@@ -5,7 +5,6 @@ function WellEater:initSettingsMenu()
     local L = self:getLocale()
     local LAM = LibAddonMenu2
     local optionsTable = {}
-    local index = 0

     local function MakeControlEntry(optTable, data, category, key)

@@ -24,29 +23,26 @@ function WellEater:initSettingsMenu()

             -- setup default value
             if not data.default then
-                local default = self:getUserDefault(key)
+                local default = self:getUserDefault(key, category)
                 data.default = default
             end

-            if not data.noAlert then
-                index = index + 1
-                data.reference = "WESettingCtrl"..index
-            end
-
             -- add get/set functions if they were not provided
             if not data.getFunc then
                 data.getFunc = function()
-                    return self:getUserPreference(data.key)
+                    return self:getUserPreference(data.key, data.category)
                 end
             end
             if not data.setFunc then
                 data.setFunc = function(value)
-                    self:setUserPreference(data.key, value)
+                    self:setUserPreference(data.key, value, data.category)
                 end
             end
-
+            data.reference = "WESET_".. category .. "_".. key
         end

+
+
         -- add to appropriate table
         table.insert(optTable, data)
         return optTable
@@ -97,7 +93,7 @@ function WellEater:initSettingsMenu()
         tooltip = L.timerSetupLabel_TT,
         setFunc = function(value)

-            self:setUserPreference("updateTime", value)
+            self:setUserPreference("updateTime", value, "general")
             self.InterfaceHook_OnTimerSlider()
         end,
         min = 1000, max = 3000, step = 100,
@@ -129,6 +125,39 @@ function WellEater:initSettingsMenu()
         }, "general", i)
     end

+    sTable = MakeSubmenu(optionsTable,L.weaponSetupHeader, L.weaponSetupDescription)
+
+    MakeControlEntry(sTable,{
+        type = "checkbox",
+        name = L.weaponSetupEnchantMainHand,
+        tooltip = L.weaponSetupEnchantMainHand,
+    }, "slots", EQUIP_SLOT_MAIN_HAND)
+
+    MakeControlEntry(sTable,{
+        type = "checkbox",
+        name = L.weaponSetupEnchantOffHand,
+        tooltip = L.weaponSetupEnchantOffHand,
+    }, "slots", EQUIP_SLOT_OFF_HAND)
+
+    MakeControlEntry(sTable,{
+        type = "checkbox",
+        name = L.weaponSetupEnchantMainHandBack,
+        tooltip = L.weaponSetupEnchantMainHandBack,
+    }, "slots", EQUIP_SLOT_BACKUP_MAIN)
+
+    MakeControlEntry(sTable,{
+        type = "checkbox",
+        name = L.weaponSetupEnchantOffHandBack,
+        tooltip = L.weaponSetupEnchantOffHandBack,
+    }, "slots", EQUIP_SLOT_BACKUP_OFF)
+
+    MakeControlEntry(sTable,{
+        type = "slider",
+        name = L.minCharges,
+        tooltip = L.minCharges,
+        min = 50, max = 300, step = 10,
+    }, "general", "minCharges")
+
     MakeControlEntry(optionsTable,{
         type = "header",
         name = L.outputSetupHeader,
diff --git a/WellEater.lua b/WellEater.lua
index ad2d694..e016568 100644
--- a/WellEater.lua
+++ b/WellEater.lua
@@ -2,7 +2,7 @@ WellEater = WellEater or {}
 WellEater.WELLEATER_SAVED_VERSION = 1
 WellEater.AddonName = "WellEater"
 WellEater.DisplayName = "|cFFFFFFWell |c0099FFEater|r"
-WellEater.Version = "1.0.1"
+WellEater.Version = "1.0.2"
 WellEater.Author = "|c5EFFF5esorochinskiy|r"
 local NAMESPACE = {}
 NAMESPACE.settingsDefaults = {
@@ -15,8 +15,25 @@ NAMESPACE.settingsDefaults = {
     notifyToScreen = true,
     useFood = true,
     useDrink = true,
+    slots = {
+        [EQUIP_SLOT_MAIN_HAND] = true,
+        [EQUIP_SLOT_OFF_HAND] = true,
+        [EQUIP_SLOT_BACKUP_MAIN] = true,
+        [EQUIP_SLOT_BACKUP_OFF] = true,
+    },
+    minCharges = 300,
 }

+function WellEater:isWeaponCheckable()
+    local settings = self:getAllUserPreferences()
+    for _,val in ipairs(settings.slots) do
+        if val then
+            return true
+        end
+    end
+    return false
+end
+
 function WellEater:getAddonName()
     return self.AddonName
 end
@@ -34,32 +51,41 @@ function WellEater:getAuthor()
     return self.Author
 end

-function WellEater:getUserPreference(setting)
-    return self.settingsUser and self.settingsUser[setting]
+function WellEater:getUserPreference(setting, categ)
+    if not categ or categ == "general" then
+        return self.settingsUser and self.settingsUser[setting]
+    else
+        return self.settingsUser and self.settingsUser[categ] and
+                self.settingsUser[categ][setting]
+    end
 end

 function WellEater:getAllUserPreferences()
     return self.settingsUser
 end

-function WellEater:getUserDefault(setting)
-    return NAMESPACE.settingsDefaults and NAMESPACE.settingsDefaults[setting]
+function WellEater:getUserDefault(setting, categ)
+    if not categ or categ == "general" then
+        return NAMESPACE.settingsDefaults and NAMESPACE.settingsDefaults[setting]
+    else
+        return NAMESPACE.settingsDefaults and NAMESPACE.settingsDefaults[categ] and
+                NAMESPACE.settingsDefaults[categ][setting]
+    end
 end

-function WellEater:setUserPreference(setting, value)
+function WellEater:setUserPreference(setting, value, categ)
     self.settingsUser = self.settingsUser or {}
-    self.settingsUser[setting] = value
+    if not categ or categ == "general" then
+        self.settingsUser[setting] = value
+    else
+        self.settingsUser[categ] = self.settingsUser[categ] or {}
+        self.settingsUser[categ][setting] = value
+    end

 end

 function WellEater:isAddonEnabled()
-
-    local locEnabled = self:getUserPreference("enabled")
-
-    if not locEnabled then
-        d(WellEater.AddonName .. " NOT enabled")
-    end
-    return locEnabled
+    return self:getUserPreference("enabled")
 end

 function WellEater:prepareToAnalize()
@@ -167,11 +193,11 @@ local function processAutoEat()
                         if formattedName and abilityDescription then
                             local toScreen = locSettings.notifyToScreen
                             if toScreen then
+                                WellEaterIndicatorLabel:SetText(formattedName)
                                 WellEater.AnimIn:PlayFromStart()
                                 WellEaterIndicator:SetHidden(false)
-                                WellEaterIndicatorLabel:SetText(formattedName)
                             end
-                            d(WellEater.AddonName .. formattedName)
+                            df("[%s] %s", WellEater.AddonName, formattedName)
                         end

                         tryToUseItem(bagId, slotId)
@@ -184,6 +210,56 @@ local function processAutoEat()
     end
 end

+local function checkEquippedWeapon()
+    local bagC
+    local locSettings = WellEater:getAllUserPreferences()
+
+    if not WellEaterIndicatorWeaponLabel:IsHidden() then
+        WellEater.WeaponAnimOut:PlayFromStart()
+        WellEaterIndicatorWeaponLabel:SetHidden(true)
+    end
+
+    for testSlot,isToCheck in ipairs(locSettings.slots) do
+        if isToCheck and HasItemInSlot(BAG_WORN, testSlot)
+                and not IsLockedWeaponSlot(testSlot) then
+
+            local linkId = GetItemLink(BAG_WORN, testSlot)
+            local numCharges = GetItemLinkNumEnchantCharges(linkId)
+            if numCharges and numCharges <= locSettings.minCharges then
+                if not bagC then
+                    SHARED_INVENTORY:RefreshInventory(BAG_BACKPACK)
+                    bagC = SHARED_INVENTORY:GetOrCreateBagCache(BAG_BACKPACK)
+
+                    if not bagC or type(bagC) ~= "table" then
+                        return
+                    end
+                end
+
+                for _, itemInfo in pairs(bagC) do
+                    local slotId = itemInfo.slotIndex
+                    if not itemInfo.stolen then
+                        local itemType, specialType = GetItemType(BAG_BACKPACK, slotId)
+                        if itemType == ITEMTYPE_SOUL_GEM then
+                            ChargeItemWithSoulGem(BAG_WORN, testSlot, BAG_BACKPACK, slotId)
+                            local iName = GetItemLinkName(GetItemLink(BAG_WORN, testSlot))
+                            local locale = WellEater:getLocale()
+                            local formattedName = zo_strformat(locale.youCharge, iName) -- no control codes
+                            df("[%s] %s", WellEater.AddonName, formattedName)
+                            local toScreen = locSettings.notifyToScreen
+                            if toScreen then
+                                WellEaterIndicatorWeaponLabel:SetText(formattedName)
+                                WellEater.WeaponAnimIn:PlayFromStart()
+                                WellEaterIndicatorWeaponLabel:SetHidden(false)
+                            end
+                            break
+                        end
+                    end
+                end
+            end
+        end
+    end
+end
+
 local function TimersUpdate()
     if not WellEater:prepareToAnalize() then
         return
@@ -198,10 +274,14 @@ local function TimersUpdate()
         _, _, timeEnding, _, _, _, _, _, _, _, abilityId, canClickOff = GetUnitBuffInfo("player", i)
         local bFood = (getActiveFoodBuff(abilityId) and canClickOff)
         foodQuantity = timeEnding * 1000 - now
+
         haveFood = (bFood and (foodQuantity > 0))
         if haveFood then
-            WellEater.AnimOut:PlayFromStart()
-            WellEaterIndicator:SetHidden(true)
+            if not WellEaterIndicator:IsHidden() then
+                WellEater.AnimOut:PlayFromStart()
+                WellEaterIndicator:SetHidden(true)
+            end
+            --d(WellEater.AddonName .. "fq = " .. foodQuantity)
             break
         end
     end
@@ -210,6 +290,10 @@ local function TimersUpdate()
         processAutoEat()
     end

+    if WellEater:isWeaponCheckable() then
+        checkEquippedWeapon()
+    end
+
 end

 local function StartUp()
@@ -361,6 +445,11 @@ local function InitOnLoad(_, addonName)
     WellEater.AnimOut = ANIMATION_MANAGER:CreateTimelineFromVirtual(
             "WellEaterAnnounceFadeOut", WellEaterIndicatorLabel)

+    WellEater.WeaponAnimIn = ANIMATION_MANAGER:CreateTimelineFromVirtual(
+            "WellEaterAnnounceFadeIn", WellEaterIndicatorWeaponLabel)
+    WellEater.WeaponAnimOut = ANIMATION_MANAGER:CreateTimelineFromVirtual(
+            "WellEaterAnnounceFadeOut", WellEaterIndicatorWeaponLabel)
+
     -- lamPanel:SetHandler("OnEffectivelyHidden", OnSettingsClosed)
 end

diff --git a/WellEater.txt b/WellEater.txt
index c497a44..f71d1a4 100644
--- a/WellEater.txt
+++ b/WellEater.txt
@@ -29,9 +29,9 @@

 ## Title: |cFFFFFFWell |c0099FFEater|r
 ## Author: |c5EFFF5esorochinskiy|r
-## APIVersion: 101033
+## APIVersion: 101033 101034
 ## Description: Auto eat your preferred meals provided by your inventory after food or drink buff expiration.
-## Version: 1.0.1
+## Version: 1.0.2
 ## SavedVariables: WellEater_Settings
 ## DependsOn: LibAddonMenu-2.0>=28

diff --git a/WellEater.xml b/WellEater.xml
index e7d191d..767fa81 100644
--- a/WellEater.xml
+++ b/WellEater.xml
@@ -18,9 +18,13 @@
             <Anchor point="CENTER" relativeTo="GuiRoot" relativePoint="CENTER" />
             <Controls>
                 <Label name="$(parent)Label" width="300" height="40" font="ZoFontWinH2" inheritAlpha="true" color="FFFFFF"
-                    wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER">
+                    wrapMode="TRUNCATE" verticalAlignment="CENTER" horizontalAlignment="CENTER">
                     <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
                 </Label>
+                <Label name="$(parent)WeaponLabel" width="300" height="40" font="ZoFontWinH2" inheritAlpha="true" color="FFFFFF"
+                    wrapMode="TRUNCATE" verticalAlignment="CENTER" horizontalAlignment="CENTER">
+                    <Anchor point="BOTTOM" relativeTo="$(parent)" relativePoint="BOTTOM" />
+                </Label>
             </Controls>
         </TopLevelControl>
     </Controls>
diff --git a/lang/de.lua b/lang/de.lua
index 3ed1df9..1a08711 100644
--- a/lang/de.lua
+++ b/lang/de.lua
@@ -16,6 +16,7 @@ local L = {
             " Weile ohne Nahrung in einer kritischen Situation",

     youEat = "Sie haben <<1>> gegessen",
+    youCharge = "Eingeladen <<1>>",
     outputSetupHeader = "Anzeigen die Nachricht über das gegessene Gericht",
     outputOnScreen = "Auf den Bildschirm",
     outputSetupHeader_TT = "Wenn die Einstellung aktiviert ist, wird eine Nachricht über das gegessene Gericht" ..
@@ -29,6 +30,15 @@ local L = {
     mealSetupFood = "Essen",
     mealSetupDrink = "Trinken",

+    weaponSetupHeader = "Waffen",
+    weaponSetupDescription = "Es kommt Waffen Autoverzauberung vor, wenn die Gebühranzahl Minimal oder kleiner ist und" ..
+            " ein Seelenstein im Inventar vorliegt",
+    weaponSetupEnchantMainHand = "Haupthand Waffen",
+    weaponSetupEnchantOffHand = "Ergänzendhand Waffen",
+    weaponSetupEnchantMainHandBack = "Haupthand Waffen zweitrangig",
+    weaponSetupEnchantOffHandBack = "Ergänzendhand Waffen zweitrangig",
+    minCharges = "Minimalgebühranzahl",
+
 }

 function WellEater:getLocale()
diff --git a/lang/en.lua b/lang/en.lua
index 16c50f5..c3a2e3c 100644
--- a/lang/en.lua
+++ b/lang/en.lua
@@ -15,6 +15,7 @@ local L = {
             "you can run out of food for a long time in critical situation",

     youEat = "You have eaten <<1>>",
+    youCharge = "Charged <<1>>",
     outputSetupHeader = "Meal eaten notification output",
     outputOnScreen = "On screen",
     outputSetupHeader_TT = "When on the notification about the meal eaten is written to the screen not only to the debug log",
@@ -26,6 +27,15 @@ local L = {
     mealSetupFood = "Food",
     mealSetupDrink = "Drink",

+    weaponSetupHeader = "Weapon",
+    weaponSetupDescription = "Weapon auto enchanting will apply when number of charges decreases to minimum and if soul gem is in inventory",
+    weaponSetupEnchantMainHand = "Main hand weapon",
+    weaponSetupEnchantOffHand = "Off hand weapon",
+    weaponSetupEnchantMainHandBack = "Main hand weapon secondary",
+    weaponSetupEnchantOffHandBack = "Off hand weapon secondary",
+
+    minCharges = "Minimum number of charges",
+
 }

 function WellEater:getLocale()
diff --git a/lang/ru.lua b/lang/ru.lua
index a693a78..996462d 100644
--- a/lang/ru.lua
+++ b/lang/ru.lua
@@ -16,6 +16,7 @@ local L = {
     " в критической ситуации",

     youEat = "Вы съели: <<1>>",
+    youCharge = "Заряжено <<1>>",
     outputSetupHeader = "Вывод сообщения о съеденном блюде",
     outputOnScreen = "На экран",
     outputSetupHeader_TT = "При включенной настройке сообщение о съеденном блюде будет выведено на экран, а не только" ..
@@ -28,6 +29,16 @@ local L = {
     mealSetupFood = "Еда",
     mealSetupDrink = "Напиток",

+    weaponSetupHeader = "Оружие",
+    weaponSetupDescription = "Автоматическое зачарование оружия произойдёт при уменьшении количества зарядов до" ..
+            " минимального и наличии в инвентаре камня душ",
+    weaponSetupEnchantMainHand = "Оружие в основной руке",
+    weaponSetupEnchantOffHand = "Оружие в дополнительной руке",
+    weaponSetupEnchantMainHandBack = "Оружие в основной руке, вторая панель",
+    weaponSetupEnchantOffHandBack = "Оружие в дополнительной руке, вторая панель",
+
+    minCharges = "Минимальное количество зарядов",
+
 }

 function WellEater:getLocale()