Fixing craft

Leandro Silva [10-07-18 - 12:30]
Fixing craft
Filename
LeoTrainer.lua
LeoTrainer.txt
LeoTrainer.xml
LeoTrainerConst.lua
LeoTrainerUI.lua
diff --git a/LeoTrainer.lua b/LeoTrainer.lua
index 7863735..af7cf74 100644
--- a/LeoTrainer.lua
+++ b/LeoTrainer.lua
@@ -65,8 +65,17 @@ function LeoTrainer.GetPatternIndexes(craft)
     end
 end

+function LeoTrainer.OnCraftFailed(event, station)
+    --GetString("SI_TRADESKILLRESULT", result)
+    --d("FAILED " .. event)
+end
+
 function LeoTrainer.OnCraftComplete(event, station)

+    --local numItemsGained = GetNumLastCraftingResultItemsAndPenalty()
+    --local craftFailed = numItemsGained == 0
+    --d(craftFailed)
+
     if LeoTrainer.isCrafting == 0 then return end

     LeoTrainer.RemoveFromQueue(LeoTrainer.isCrafting)
@@ -74,7 +83,7 @@ function LeoTrainer.OnCraftComplete(event, station)

     -- Player still at station and pressed Craft All
     if GetCraftingInteractionType() ~= CRAFTING_TYPE_INVALID and LeoTrainer.continueCrating == true then
-        zo_callLater(function() LeoTrainer.CraftNext() end, 1000)
+        zo_callLater(function() LeoTrainer.CraftNext() end, 200)
     end
 end

@@ -89,9 +98,11 @@ function LeoTrainer.CraftItem(queueIndex, data)

     data.patternIndex = LeoTrainer.namesToPatternIndexes[data.craft]["lines"][data.line]

+    local matName, _, matReq = GetSmithingPatternMaterialItemInfo(data.patternIndex, data.materialIndex)
+    data.materialQuantity = matReq
+
     local curMats = GetCurrentSmithingMaterialItemCount(data.patternIndex, data.materialIndex)
     if curMats < data.materialQuantity then
-        local matName, _, matReq = GetSmithingPatternMaterialItemInfo(data.patternIndex, data.materialIndex)
         local diff = data.materialQuantity - curMats
         LeoTrainer.log("Not enough " .. matName .. ". Need " .. diff .. " more.")
         LeoTrainer.continueCrating = false
@@ -143,33 +154,32 @@ function LeoTrainer.stationEnter(eventcode, station)
     LeoTrainerWindowQueuePanelQueueScrollCraftAll:SetState(BSTATE_NORMAL)
     LeoTrainer.GetPatternIndexes(station)

-    --[[
     local namesToPatternIndexes = {}
     for patternIndex = 1, GetNumSmithingPatterns() do
         local _, name = GetSmithingPatternInfo(patternIndex)
         namesToPatternIndexes[name] = patternIndex
     end

-    for line = 1, GetNumSmithingResearchLines(station) do
+    --[[for line = 1, GetNumSmithingResearchLines(station) do
         local lineName, lineIcon, numTraits = GetSmithingResearchLineInfo(station, line)
         local patternIndex = namesToPatternIndexes[lineName]
+        local _, _, matReq = GetSmithingPatternMaterialItemInfo(patternIndex, 1)
+        d(line.." "..lineName.." "..patternIndex.." "..matReq)
         for trait = 1, numTraits do
             local traitType = GetSmithingResearchLineTraitInfo(station, line, trait)
             local traitName = GetString('SI_ITEMTRAITTYPE', traitType)
-            local _, _, matReq = GetSmithingPatternMaterialItemInfo(patternIndex, 1)
-            local styleId = maxStyle(lineId)
-            local requestResult = {
-                patternIndex,
-                1,
-                matReq,
-                styleId,
-                traitType + 1,
-                LINK_STYLE_BRACKETS
-            }
+            --local styleId = maxStyle(lineId)
+            --local requestResult = {
+            --    patternIndex,
+            --    1,
+            --    matReq,
+            --    styleId,
+            --    traitType + 1,
+            --    LINK_STYLE_BRACKETS
+            --}
             --d(GetSmithingPatternResultLink(unpack(requestResult)) .. "{line="..line..", patternIndex="..patternIndex..", materialIndex=1, materialQuantity="..matReq..", itemStyleId="..styleId..", trait="..trait..", traitType="..traitType.."} -- " .. lineName .. " " .. traitName)
         end
-    end
-    ]]
+    end]]
 end

 function LeoTrainer.stationExit(eventcode, station)
@@ -250,6 +260,7 @@ function LeoTrainer.OnAddOnLoaded(event, addonName)
         EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFTING_STATION_INTERACT, LeoTrainer.stationEnter)
         EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_END_CRAFTING_STATION_INTERACT, LeoTrainer.stationExit)
         EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFT_COMPLETED, LeoTrainer.OnCraftComplete)
+        EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFT_FAILED, LeoTrainer.OnCraftFailed)
         CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", OnSettingsControlsCreated)

         LeoTrainer.log("started.")
diff --git a/LeoTrainer.txt b/LeoTrainer.txt
index ce0ab06..36dd134 100644
--- a/LeoTrainer.txt
+++ b/LeoTrainer.txt
@@ -1,6 +1,6 @@
 ## Title: Leo's Trainer
 ## APIVersion: 100024 100025
-## Version: 0.9.1
+## Version: 0.9.2
 ## Author: |c39B027@LeandroSilva|r
 ## SavedVariables: LeoTrainerSavedVariables
 ## DependsOn: LeoAltholic
diff --git a/LeoTrainer.xml b/LeoTrainer.xml
index 186bf6c..5e19315 100644
--- a/LeoTrainer.xml
+++ b/LeoTrainer.xml
@@ -782,14 +782,14 @@
                                         </Control>
                                         <Control name="$(parent)Trait" inherits="ZO_SortHeader">
                                             <Anchor point="TOPLEFT" relativeTo="$(parent)Trainee" relativePoint="TOPRIGHT" offsetX="10" />
-                                            <Dimensions x="150" y="20" />
+                                            <Dimensions x="200" y="20" />
                                             <OnInitialized>
-                                                ZO_SortHeader_Initialize(self, "Trait", "trait", ZO_SORT_ORDER_DOWN, TEXT_ALIGN_LEFT, "ZoFontGameLargeBold")
+                                                ZO_SortHeader_Initialize(self, "Trait", "researchName", ZO_SORT_ORDER_DOWN, TEXT_ALIGN_LEFT, "ZoFontGameLargeBold")
                                             </OnInitialized>
                                         </Control>
                                         <Control name="$(parent)Item" inherits="ZO_SortHeader">
                                             <Anchor point="TOPLEFT" relativeTo="$(parent)Trait" relativePoint="TOPRIGHT" offsetX="10" />
-                                            <Dimensions x="150" y="20" />
+                                            <Dimensions x="200" y="20" />
                                             <OnInitialized>
                                                 ZO_SortHeader_Initialize(self, "Item", "item", ZO_SORT_ORDER_DOWN, TEXT_ALIGN_LEFT, "ZoFontGameLargeBold")
                                             </OnInitialized>
@@ -869,11 +869,11 @@
                     <Anchor point="TOPLEFT" relativeTo="$(parent)Trainer" relativePoint="TOPRIGHT" offsetX="10"/>
                 </Label>
                 <Label name="$(parent)Trait" font="LeoTrainerNormalFont" verticalAlignment="CENTER">
-                    <Dimensions x="150" y="32" />
+                    <Dimensions x="200" y="32" />
                     <Anchor point="TOPLEFT" relativeTo="$(parent)Trainee" relativePoint="TOPRIGHT" offsetX="10"/>
                 </Label>
                 <Label name="$(parent)Item" font="LeoTrainerNormalFont" verticalAlignment="CENTER" mouseEnabled="true">
-                    <Dimensions x="150" y="32" />
+                    <Dimensions x="200" y="32" />
                     <Anchor point="TOPLEFT" relativeTo="$(parent)Trait" relativePoint="TOPRIGHT" offsetX="10"/>
                     <OnMouseEnter>
                         InitializeTooltip(ItemTooltip, self)
diff --git a/LeoTrainerConst.lua b/LeoTrainerConst.lua
index 414afab..27ce663 100644
--- a/LeoTrainerConst.lua
+++ b/LeoTrainerConst.lua
@@ -2,7 +2,7 @@
 LeoTrainer = {}
 LeoTrainer.name = "LeoTrainer"
 LeoTrainer.displayName = "Leo's Trainer"
-LeoTrainer.version = "0.9.1"
+LeoTrainer.version = "0.9.2"
 LeoTrainer.chatPrefix = "|c39B027" .. LeoTrainer.name .. "|r: "
 LeoTrainer.setting = nil
 LeoTrainer.hidden = true
diff --git a/LeoTrainerUI.lua b/LeoTrainerUI.lua
index 0212d2f..5f8e21f 100644
--- a/LeoTrainerUI.lua
+++ b/LeoTrainerUI.lua
@@ -45,11 +45,12 @@ function LeoTrainerQueueList:New(control)
     {
         ["trainer"] = {},
         ["trainee"] = { tiebreaker = "trainer"},
-        ["trait"] = { tiebreaker = "trainee"},
-        ["item"] = { tiebreaker = "trainee"},
+        ["researchName"] = { tiebreaker = "trainee"},
+        ["item"] = { tiebreaker = "researchName"},
     }

     self.masterList = {}
+    self.currentSortKey = "researchName"
     ZO_ScrollList_AddDataType(self.list, 1, "LeoTrainerQueueListTemplate", 32, function(control, data) self:SetupEntry(control, data) end)

     self.sortFunction = function(listEntry1, listEntry2)
@@ -69,15 +70,15 @@ function LeoTrainerQueueList:SetupEntry(control, data)
     control.trainee = GetControl(control, "Trainee")
     control.trainee:SetText(data.trainee)

-    control.trait = GetControl(control, "Trait")
-    control.trait:SetText(data.researchName)
+    control.researchName = GetControl(control, "Trait")
+    control.researchName:SetText(data.researchName)

     control.item = GetControl(control, "Item")
     control.item:SetText(data.itemLink)
     control.item:SetHandler('OnMouseUp', function(control, button, upInside)
         if upInside == false then return end
         if button == MOUSE_BUTTON_INDEX_RIGHT then
-            LeoTrainer.RemoveFromQueue(data.index)
+            LeoTrainer.RemoveFromQueue(data.queueIndex)
         end
     end)

@@ -245,7 +246,7 @@ function LeoTrainer.CreateUI()
                             return
                         end
                         if button == MOUSE_BUTTON_INDEX_LEFT and #unknown > 0 then
-                            local matReq = LeoTrainer.const.materialRequirements[craft][line]
+                            --local matReq = LeoTrainer.const.materialRequirements[craft][line]
                             local styleId = LeoTrainer.maxStyle(line)
                             for _, charName in pairs(unknown) do
                                 LeoTrainer.AddToQueue({
@@ -256,7 +257,7 @@ function LeoTrainer.CreateUI()
                                     trait = trait,
                                     patternIndex = -1,
                                     materialIndex = 1,
-                                    materialQuantity = matReq,
+                                    materialQuantity = -1,
                                     itemStyleId = styleId,
                                     traitIndex = traitType,
                                     useUniversalStyleItem = false,