Version 3.0, Sent to CDG

His Dad [12-10-14 - 08:45]
Version 3.0, Sent to CDG
Filename
AIResearchGrid.lua
AIResearchGrid.txt
diff --git a/AIResearchGrid.lua b/AIResearchGrid.lua
index 9f437d2..4dede08 100644
--- a/AIResearchGrid.lua
+++ b/AIResearchGrid.lua
@@ -1,13 +1,16 @@
 -- AI Research Grid Addon for Elder Scrolls Online
 -- Author: Stormknight/LCAmethyst
+-- "All"  functionality by His Dad

 local _
 AIRG = {}

 AIRG.name = "AIResearchGrid"
-AIRG.version = "1.3.4"
+AIRG.version = "3.0.0"
 AIRG.initialised = false
 AIRG.processing = false
+AIRG.all = " #ALL"  -- displayname for Virtual character
+

 -- Set-up the defaults options for saved variables.
 AIRG.defaults = {
@@ -36,10 +39,69 @@ function AIRG.Initialise(eventCode, addOnName)
     AIRG.craftNames[CRAFTING_TYPE_WOODWORKING]      = "WOODWORKING"
     AIRG.playerName = GetUnitName("player")
     AIRG.curCharacter = GetUnitName("player")       -- Default the display to the current character
-
     AIRG.AssignGridTraits()
     AIRG.AssignStyleLookups()
+    AIRG.vars.styles[AIRG.all] = {}           -- and our virtual character
+
+    -- Create these here so the UI dropdown will have them first time around.
+    AIRG.vars.data[AIRG.playerName] = {}    -- create a table for this character's matrix
+    AIRG.vars.data[AIRG.all] = {}    -- and our virtual character
+
+  -- Create Empty data for Virtual Char set to 0, (Not known)
+    local i, j
+
+    AIRG.vars.data[AIRG.all][CRAFTING_TYPE_BLACKSMITHING] = {}
+    -- Cycle through items for this profession
+    for i = 1, 7 do   -- Weapons
+        AIRG.vars.data[AIRG.all][CRAFTING_TYPE_BLACKSMITHING][i] = {}
+        -- Cycle through the traits for this item
+        for j = 1, 9 do
+                       AIRG.vars.data[AIRG.all][CRAFTING_TYPE_BLACKSMITHING][i][j] = 0   -- set to not known
+        end
+    end
+    for i = 8, 14 do  -- Armour
+        AIRG.vars.data[AIRG.all][CRAFTING_TYPE_BLACKSMITHING][i] = {}
+        -- Cycle through the traits for this item
+        for j = 10, 18 do
+                       AIRG.vars.data[AIRG.all][CRAFTING_TYPE_BLACKSMITHING][i][j] = 0   -- set to not known
+        end
+    end

+    AIRG.vars.data[AIRG.all][CRAFTING_TYPE_CLOTHIER] = {}
+    -- Cycle through items for this profession
+    for i = 1, 14 do
+        AIRG.vars.data[AIRG.all][CRAFTING_TYPE_CLOTHIER][i] = {}
+        -- Cycle through the traits for this item
+        for j = 10, 18  do
+                       AIRG.vars.data[AIRG.all][CRAFTING_TYPE_CLOTHIER][i][j] = 0   -- set to not known
+        end
+    end
+
+     AIRG.vars.data[AIRG.all][CRAFTING_TYPE_WOODWORKING] = {}
+    -- Cycle through items for this profession
+    for i = 1, 5 do
+        AIRG.vars.data[AIRG.all][CRAFTING_TYPE_WOODWORKING][i] = {}
+        -- Cycle through the traits for this item
+        for j = 1, 9 do
+                       AIRG.vars.data[AIRG.all][CRAFTING_TYPE_WOODWORKING][i][j] = 0   -- set to not known
+        end
+    end
+    for i = 6, 6 do  --Shields
+        AIRG.vars.data[AIRG.all][CRAFTING_TYPE_WOODWORKING][i] = {}
+        -- Cycle through the traits for this item
+        for j = 10, 18 do
+                       AIRG.vars.data[AIRG.all][CRAFTING_TYPE_WOODWORKING][i][j] = 0   -- set to not known
+        end
+    end
+
+    --Create Empty Style Table
+    for i = 1, 14 do
+        AIRG.vars.styles[AIRG.all][i] = false
+    end
+
+ -- AIRG.CreateDataMatrix
+
+    -- Following replaced with PlayerActivate
     -- Query data for THIS character and populate the data matrix with fresh data.
     --AIRG.PopulateMatrix()

@@ -67,19 +129,14 @@ end -- AIRG.Initialise
 EVENT_MANAGER:RegisterForEvent("AIRG", EVENT_ADD_ON_LOADED, AIRG.Initialise)


--- SLASH COMMAND FUNCTIONALITY
-function AIRGslash(extra)
-    AIRG.ToggleMainWindow()
-end -- AIRGslash
-
-
-SLASH_COMMANDS["/airg"] = AIRGslash

 function AIRG.PlayerActivated()
         -- somehow somewhere it sometimes happens that the data is not correct completely for whatever reason
         -- so we force a reload of the current character data when we are actually loaded into the world.
-    	AIRG.PopulateMatrix()
-	AIRG.PopulateStyleData()
+  AIRG.PopulateMatrix()
+  AIRG.PopulateStyleData()
+  AIRG.PopulateAll()  -- do last
+
 end

 function AIRG.ToggleMainWindow()
@@ -98,6 +155,7 @@ end -- AIRG.ToggleMainWindow
 -- (integer eventCode, integer craftingSkillType, luaindex researchLineIndex, luaindex traitIndex)
 function AIRG.ResearchStarted(eventCode, craftingSkillType, researchLineIndex, traitIndex)
     AIRG.PopulateMatrix()
+    AIRG.PopulateAll()
     -- TO DO: If it's visible, invoke a redisplay
     AIRG.OnCraftSelected()              -- Redisplay data for the current profession
 end -- AIRG.ResearchStarted
@@ -106,6 +164,7 @@ end -- AIRG.ResearchStarted
 -- (integer eventCode, integer craftingSkillType, luaindex researchLineIndex, luaindex traitIndex)
 function AIRG.ResearchCompleted()
     AIRG.PopulateMatrix()
+    AIRG.PopulateAll()
     -- TO DO: If it's visible, invoke a redisplay
     AIRG.OnCraftSelected()              -- Redisplay data for the current profession
 end -- AIRG.ResearchEnded
@@ -113,6 +172,7 @@ end -- AIRG.ResearchEnded
 function AIRG.StyleLearned(eventCode, styleIndex)
     AIRG.PopulateStyleData()
     AIRG.DisplayStyles()
+    AIRG.PopulateAll()
 end -- AIRG.StyleLearned

 -- Invoked from AIRG.Initialise but lengthy so in it's own function to not clutter Initialise
@@ -171,6 +231,7 @@ function AIRG.initUI()
         local entry = AIRG.UI.charDropdown.dropdown:CreateItemEntry(charName, OnItemSelect)
         AIRG.UI.charDropdown.dropdown:AddItem(entry)
     end
+
     -- PEOPLE ICON NEXT TO THE DROPDOWN BOX
 --    AIRG.UI.PeopleIcon = WINDOW_MANAGER:CreateControl("AIResearchGridPeopleIcon", AIResearchGrid, CT_TEXTURE)
 --    AIRG.UI.PeopleIcon:SetDimensions(40, 32)
@@ -403,19 +464,19 @@ function AIRG.OnCraftSelected(_,thisCraft)
                     AIRG.UI.gridButtons[i][rowNum]:SetTexture("ESOUI/art/buttons/decline_up.dds")
                 end
             end
-            if (traitCount > 0) then
-                AIRG.UI.columnFooters[i]:SetText(traitCount)
-            else
-                AIRG.UI.columnFooters[i]:SetText("")
-            end
+      --      if (traitCount > 0) then
+               AIRG.UI.columnFooters[i]:SetText(traitCount)
+      --      else
+      --          AIRG.UI.columnFooters[i]:SetText("")
+      --      end
         end
     end
 end -- AIRG:OnCraftSelected

 -- Invoked when the user selected a character from the dropdown box
 function AIRG.OnCharacterSelect(charName)
-    if (charName == nil) then
-    else
+
+    if (charName == nil) then else
         AIRG.curCharacter = charName
     end
     AIRG.DisplayStyles()
@@ -425,7 +486,7 @@ end -- AIRG.OnCharacterSelect
 -- Deletes data for the named character from the saved data and removes them from the dropdown box.
 function AIRG.DeleteCharacter(charName)
     -- Can't delete the current character
-    if (charName == AIRG.playerName) then
+    if (charName == AIRG.playerName or charName == AIRG.all) then
         d(AIRG.L["DeleteFalse"])
     else
         if (AIRG.vars.data[charName] ~= nil) then
@@ -438,40 +499,67 @@ function AIRG.DeleteCharacter(charName)
     end
 end -- AIRG.DeleteCharacter

--- This function cycles through all three professions and populates the data matrix for THIS character.
+-- This function cycles through all three professions and populates the data matrix for this characters
 -- This is carried out when the addon loasd to ensure the current character data is up-to-date.
 -- The "if" logic in this function guesses at which profession should be default to display as the one with most research in.
 function AIRG.PopulateMatrix()
     local curCount = 0
     local thisCount
-    AIRG.vars.data[AIRG.playerName] = {}    -- create a table for this character's matrix
-    thisCount = AIRG.CreateDataMatrix(CRAFTING_TYPE_BLACKSMITHING)
-    if (thisCount > curCount) then
-        AIRG.curCraft = CRAFTING_TYPE_BLACKSMITHING
-        curCount = thisCount
-    end
-    thisCount = AIRG.CreateDataMatrix(CRAFTING_TYPE_CLOTHIER)
-    if (thisCount > curCount) then
-        AIRG.curCraft = CRAFTING_TYPE_CLOTHIER
-        curCount = thisCount
-    end
-    thisCount = AIRG.CreateDataMatrix(CRAFTING_TYPE_WOODWORKING)
-    if (thisCount > curCount) then
-        AIRG.curCraft = CRAFTING_TYPE_WOODWORKING
-        curCount = thisCount
-    end
+        AIRG.curCraft = CRAFTING_TYPE_BLACKSMITHING  --Default for new chars
+        thisCount = AIRG.CreateDataMatrix(CRAFTING_TYPE_BLACKSMITHING)
+        if (thisCount > curCount) then
+          AIRG.curCraft = CRAFTING_TYPE_BLACKSMITHING
+          curCount = thisCount
+        end
+        thisCount = AIRG.CreateDataMatrix(CRAFTING_TYPE_CLOTHIER)
+        if (thisCount > curCount) then
+          AIRG.curCraft = CRAFTING_TYPE_CLOTHIER
+            curCount = thisCount
+        end
+        thisCount = AIRG.CreateDataMatrix(CRAFTING_TYPE_WOODWORKING)
+        if (thisCount > curCount) then
+          AIRG.curCraft = CRAFTING_TYPE_WOODWORKING
+          curCount = thisCount
+        end
+
 end -- AIRG.PopulateMatrix

 -- Lookup the style data for the current character and send it to saved vars.
 function AIRG.PopulateStyleData()
     AIRG.vars.styles[AIRG.playerName] = {}    -- create a table for this character's matrix
-    local i, j
+    local i, j, known
     for i = 1, 14 do
         j = AIRG.styleLookupItem[i]
-        AIRG.vars.styles[AIRG.playerName][i] = IsSmithingStyleKnown(j, 1) --patternIndex set to 1, temporary workaround for changes introduced in Update 4
+        known = IsSmithingStyleKnown(j, 1) --patternIndex set to 1, temporary workaround for changes introduced in Update 4
+        AIRG.vars.styles[AIRG.playerName][i] = known
     end
 end -- AIRG.PopulateStyleData

+-- When any character data changes we have to go through and create our virtual "All" from the beginning.
+-- its simplified by not having to reset to unknown as traits can't be forgotton.
+function AIRG.PopulateAll()
+    local craft, item, trait, thisname, style, known
+    for thisname, _ in pairs(AIRG.vars.data) do   --iterate over all characters
+      if thisname ~= AIRG.all then                --skip our virtual
+        for craft, _ in pairs(AIRG.vars.data[thisname]) do   --iterate over all crafts
+          for item, _ in pairs(AIRG.vars.data[thisname][craft]) do   --iterate over all weapons/armour
+            for trait, _ in pairs(AIRG.vars.data[thisname][craft][item]) do   --iterate over all traits
+              if AIRG.vars.data[thisname][craft][item][trait] ~=  0 then -- researching counts as learned.
+                 AIRG.vars.data[AIRG.all][craft][item][trait] = -1
+              end
+            end
+          end
+        end
+        -- Update the Styles for this char.
+        for style, known in pairs (AIRG.vars.styles[thisname]) do   --iterate over all styles
+          if known  then
+            AIRG.vars.styles[AIRG.all][style] = true
+          end
+       end
+      end
+    end
+ end  -- AIRG.PopulateAll
+
 -- Set the icon highlights for the currently selected character
 function AIRG.DisplayStyles()
     local i
@@ -496,7 +584,7 @@ end -- AIRG.DisplayStyles()
 -- Look up all the data on this profession and commit to saved variables for this character.
 -- TO DO: At some point, get clever with storing the timestamp for when research will be complete
 function AIRG.CreateDataMatrix(thisCraft)
-    local i, j
+  local i, j
     local tType, tKnown, tRemain, rowNum, tTargetStamp
     local rCount = 0
     local maxLines = GetNumSmithingResearchLines(thisCraft)     -- the number of columns for this profession
@@ -527,6 +615,9 @@ function AIRG.CreateDataMatrix(thisCraft)
     return rCount       -- the total number of traits already researched in this profession
 end -- AIRG.CreateDataMatrix

+
+
+
 function AIRG.AssignGridTraits()
     -- Translates the traitType to the correct ROW of the grid
     AIRG.gridTraits = {}
@@ -601,4 +692,11 @@ function AIRG.AssignStyleLookups()
     AIRG.styleLookupItem[14] = 20   -- Primal       = Argentum
 end -- AIRG.AssignStyleLookups

+-- SLASH COMMAND FUNCTIONALITY
+function AIRGslash(extra)
+    AIRG.ToggleMainWindow()
+end -- AIRGslash
+
+
+SLASH_COMMANDS["/airg"] = AIRGslash
 -- EOF
diff --git a/AIResearchGrid.txt b/AIResearchGrid.txt
index f3fa9a1..7dcbb09 100644
--- a/AIResearchGrid.txt
+++ b/AIResearchGrid.txt
@@ -1,7 +1,7 @@
-## Title: |cFFFFB0Research Grid|r v2.3 by |c00C000CrazyDutchGuy|r
-## APIVersion: 100009
-## Version: 2.3
-## Author: Stormknight & CrazyDutchGuy
+## Title: |cFFFFB0Research Grid|r v3.0 by |c00C000CrazyDutchGuy|r and His Dad
+## APIVersion: 100010
+## Version: 3.0
+## Author: Stormknight, CrazyDutchGuy &  His Dad
 ## OptionalDependsOn: LibAddonMenu-2.0
 ## SavedVariables: AIRG_SavedVariables
 ## Description: Allows you to quickly and easily see which traits your characters have researched for Blacksmithing, Clothing & Woodworking, wherever you are in the world.