UI done

Zig Zichterman [02-29-16 - 05:48]
UI done

Prefs I/O done
Dynamic UI done
Filename
GuildGoldDeposits.lua
diff --git a/GuildGoldDeposits.lua b/GuildGoldDeposits.lua
index de88ab0..390d6f3 100644
--- a/GuildGoldDeposits.lua
+++ b/GuildGoldDeposits.lua
@@ -8,6 +8,8 @@ GuildGoldDeposits.default = {
     , duration_days = 7
 }

+-- Init ----------------------------------------------------------------------
+
 function GuildGoldDeposits.OnAddOnLoaded(event, addonName)
     if addonName ~= GuildGoldDeposits.name then return end
     if not GuildGoldDeposits.version then return end
@@ -15,15 +17,6 @@ function GuildGoldDeposits.OnAddOnLoaded(event, addonName)
     GuildGoldDeposits:Initialize()
 end

-function GuildGoldDeposits:SaveNow()
-    d("GGD:Saving!")
-    d("sv.days " .. self.savedVariables.duration_days)
-    for i = 1, 5 do
-        d("sv.eg[" .. i .. "] = "
-          .. tostring(self.savedVariables.enable_guild[i]))
-    end
-end
-
 function GuildGoldDeposits:Initialize()
     self.savedVariables = ZO_SavedVars:New(
                               "GuildGoldDepositsVars"
@@ -31,15 +24,11 @@ function GuildGoldDeposits:Initialize()
                             , nil
                             , self.default
                             )
-    -- self.savedVariables.duration_days = 8
     self:CreateSettingsWindow()
     EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_ADD_ON_LOADED)
 end

-function SaveNow()
-    d("Saving!")
-    GuildGoldDeposits:SaveNow()
-end
+-- UI ------------------------------------------------------------------------

 function GuildGoldDeposits:CreateSettingsWindow()
     local panelData = {
@@ -50,7 +39,7 @@ function GuildGoldDeposits:CreateSettingsWindow()
         version             = self.version,
         slashCommand        = "/gg",
         registerForRefresh  = true,
-        registerForDefaults = true,
+        registerForDefaults = false,
     }
     local cntrlOptionsPanel = LAM2:RegisterAddonPanel( self.name
                                                      , panelData
@@ -59,9 +48,7 @@ function GuildGoldDeposits:CreateSettingsWindow()
         { type      = "button"
         , name      = "Save Data Now"
         , tooltip   = "Save guild gold deposit data to file now."
-        , func      = function() d("hi") SaveNow() end
-        , width     = "full" --or "half" (optional
-        , reference = "GuildGoldDesposits_save" --(optional) unique global reference to contro
+        , func      = function() GuildGoldDeposits:SaveNow() end
         },
         { type      = "header"
         , name      = "Duration"
@@ -74,7 +61,6 @@ function GuildGoldDeposits:CreateSettingsWindow()
         , step      = 1
         , getFunc   = function() return self.savedVariables.duration_days end
         , setFunc   = function(value) self.savedVariables.duration_days = value end
-        , reference = "GuildGoldDeposits_dur"
         },
         { type      = "header"
         , name      = "Guilds"
@@ -86,7 +72,6 @@ function GuildGoldDeposits:CreateSettingsWindow()
             { type      = "checkbox"
             , name      = "(guild " .. i .. ")"
             , tooltip   = "Save data for guild " .. i .. "?"
-            --, getFunc   = function() return true end
             , getFunc   = function() return self.savedVariables.enable_guild[i] end
             , setFunc   = function(e) self.savedVariables.enable_guild[i] = e end
             , reference = "GuildGoldDeposits_cbg" .. i
@@ -94,8 +79,59 @@ function GuildGoldDeposits:CreateSettingsWindow()
     end

     LAM2:RegisterOptionControls("GuildGoldDeposits", optionsData)
+    CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated"
+            , GuildGoldDeposits.OnPanelControlsCreated)
+
+end
+
+-- Delayed initialization of options panel: don't waste time fetching
+-- guild names until a human actually opens our panel.
+function GuildGoldDeposits.OnPanelControlsCreated(panel)
+    guild_ct = GetNumGuilds()
+    for i = 1,5 do
+        cb = _G["GuildGoldDeposits_cbg" .. i]
+        if i <= guild_ct then
+            guildId   = GetGuildId(i)
+            guildName = GetGuildName(guildId)
+            cb.label:SetText(guildName)
+            cb:SetHidden(false)
+        else
+            -- If no guild #N, hide and disable it.
+            cb:SetHidden(true)
+            GuildGoldDeposits.savedVariables.enable_guild[i] = false
+        end
+    end
+end
+
+-- Saving Guild Data ---------------------------------------------------------
+
+function GuildGoldDeposits:SaveNow()
+    d("sv.days " .. self.savedVariables.duration_days)
+    for i = 1, 5 do
+        d("sv.eg[" .. i .. "] = "
+          .. tostring(self.savedVariables.enable_guild[i]))
+    end
 end

+-- GetGuildEventInfo(3, GUILD_HISTORY_BANK_DEPOSITS, 2)
+-- 21 1656 @J-man8898 5000 nil nil nil nil
+-- 2016-02-29 14:45:37 -0700 ziggr: "@J-man8898 deposited 5,000g 27 minutes ago
+-- 21 1741 @J-man8898 5000 nil nil nil nil
+-- 2016-02-29 14:46:44 -0700 ziggr:  "@J-man8898 deposited 5,000g 27 minutes ago
+-- So field 2 is RELATIVE TIME AGO and likeluy SECONDS ago
+
+-- GetGuildEventInfo(3, GUILD_HISTORY_BANK_DEPOSITS, 2)
+-- 0/nil at first, until I opened the Guild history.
+-- So there must be an open/init sequence.
+
+-- GetTimeStamp() returns seconds since the epoch. That, minus above, is
+-- seconds-since-the-epoch of the item/event.
+
+
+
+
+
+-- Postamble -----------------------------------------------------------------

 EVENT_MANAGER:RegisterForEvent( GuildGoldDeposits.name
                               , EVENT_ADD_ON_LOADED