Quantcast

Fixed event handling

Jesse Adams [02-20-11 - 21:24]
Fixed event handling
Hide window when you haven't learned archaeology
Filename
README
Solvent.lua
diff --git a/README b/README
index 3f584d9..fff3daf 100644
--- a/README
+++ b/README
@@ -3,17 +3,17 @@ Solvent - A simple, attractive Archaeology display and helper for World of Warcr
 Special Thanks:
 daihenka and Archy
 Ludus of Naz'jatar-US
+The trollers of #wowuidev on irc.freenode.net

 Upcoming Changes:
-* When an artifact is solved, it should update all information
-* When a survey is completed, it should update all information
-* initial load bags bugfix
 * Display archaeology skill level next to title, unless skill is maxed
 * Double right-click surveying
+* Click on artifact bar to solve (when yellow)
+* Add slash commands to show/hide
+* Add slash command to automatically solve everything that is possible to solve, no matter what it takes

 Things to Test:
 * All races in queue
-* Archaeology not learned
 * Ensure new race shows up upon first survey

 Changelog:
@@ -22,3 +22,6 @@ Changelog:
 * Rare artifacts should have blue statusbar color
 * Statusbar color should change to yellow when artifact is solvable
 * Play a sound when something is solvable
+* Sorted out events so that initial load didn't throw errors
+* When a survey is completed, it should update all information
+* When an artifact is solved, it should update all information
diff --git a/Solvent.lua b/Solvent.lua
index a862534..c5aeed8 100644
--- a/Solvent.lua
+++ b/Solvent.lua
@@ -39,11 +39,14 @@ function TotalKeystonesFromBags()
       ["id"] = 64395,
     },
   }
-
+
   for bag=0,4 do
     numSlots = GetContainerNumSlots(bag)
+
     if SOLVENT_DEBUG then
-      print(GetBagName(bag) .. ': ' .. numSlots .. ' slot bag')
+      if SOLVENT_DEBUG then
+        print(GetBagName(bag) .. ': ' .. numSlots .. ' slot bag')
+      end
     end

     for slot=1,numSlots do
@@ -88,15 +91,22 @@ function SolventGetCurrentArtifacts()
   keystones = TotalKeystonesFromBags()

   prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions();
+  if not archaeology then
+    SolventSolveFrame:Hide()
+    return
+  end
   name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier = GetProfessionInfo(archaeology)
   if SOLVENT_DEBUG then
     print(name .. ": " .. skillLevel .. "/" .. maxSkillLevel)
   end

   local raceCount = GetNumArchaeologyRaces();
-  local artifacts = {}
   local lastRaceName

+  if SOLVENT_DEBUG then
+    print("Race Count: " .. raceCount)
+  end
+
   soundHasPlayed = false
   for i=1,raceCount do
     local raceName, raceTexture, raceItemID, numFragmentsCollected, numFragmentsRequired = GetArchaeologyRaceInfo(i);
@@ -144,19 +154,20 @@ function SolventGetCurrentArtifacts()
         end
       else
         statusBar = _G["SolventSolveFrameRow" .. raceName .. "StatusBar"]
+      end

-        if solvable then
-          if soundHasPlayed == false then
-            PlaySoundFile("Interface\\Addons\\Solvent\\sounds\\shooting_star.mp3")
-            DEFAULT_CHAT_FRAME:AddMessage("Archaeology: " .. raceName .. " Artifact '".. artifactName .. "' is now solvable!")
-            soundHasPlayed = true
-          end
-          statusBar:SetStatusBarColor(1,1,0)
-        elseif artifactRarity == 0 then
-          statusBar:SetStatusBarColor(0,1,0)
-        else
-          statusBar:SetStatusBarColor(0,0.44,0.87)
+      --print(statusBar)
+      if solvable then
+        if soundHasPlayed == false then
+          PlaySoundFile("Interface\\Addons\\Solvent\\sounds\\shooting_star.mp3")
+          DEFAULT_CHAT_FRAME:AddMessage("Archaeology: " .. raceName .. " Artifact '".. artifactName .. "' is now solvable!")
+          soundHasPlayed = true
         end
+        statusBar:SetStatusBarColor(1,1,0)
+      elseif artifactRarity == 0 then
+        statusBar:SetStatusBarColor(0,1,0)
+      else
+        statusBar:SetStatusBarColor(0,0.44,0.87)
       end

       statusBar:SetMinMaxValues(0, numFragmentsRequired)
@@ -178,11 +189,37 @@ end

 function SolventStartup()
   DEFAULT_CHAT_FRAME:AddMessage("Solvent Archaeology Addon Loaded!")
-  SolventGetCurrentArtifacts()
+  RequestArtifactCompletionHistory()
+  --SolventGetCurrentArtifacts()
+end
+
+surveyDetected = false
+initiallyLoaded = false
+function SolventHandleEvent(frame, eventName, ...)
+  --print(eventName)
+  if eventName == "ARTIFACT_HISTORY_READY" then
+    initiallyLoaded = true
+    SolventGetCurrentArtifacts()
+  elseif initiallyLoaded and (eventName == "ARTIFACT_COMPLETE" or eventName == "BAG_UPDATE") then
+    SolventGetCurrentArtifacts()
+  elseif eventName == "UNIT_SPELLCAST_SUCCEEDED" then
+    unit, spell, rank, notSure, spellId = ...
+    if unit == "player" and spellId == 80451 then
+      --print("Survey detected!")
+      surveyDetected = true
+    end
+  elseif surveyDetected and eventName == "CURRENCY_DISPLAY_UPDATE" then
+    surveyDetected = false
+    SolventGetCurrentArtifacts()
+  end
 end

 dframe = CreateFrame("Frame", nil, UIParent)
 dframe:RegisterEvent("CURRENCY_DISPLAY_UPDATE");
+dframe:RegisterEvent("ARTIFACT_HISTORY_READY")
+dframe:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
+dframe:RegisterEvent("ARTIFACT_COMPLETE")
 --dframe:RegisterEvent("ARTIFACT_UPDATE");       ONLY AFTER SOLVING!
---dframe:RegisterEvent("BAG_UPDATE");   ONLY AFTER SURVEYING!
-dframe:SetScript("OnEvent", SolventGetCurrentArtifacts);
+dframe:RegisterEvent("BAG_UPDATE");
+dframe:SetScript("OnEvent", SolventHandleEvent);
+