*reorganized code fragments

Martin Unkel [06-02-18 - 08:27]
*reorganized code fragments
Filename
AwesomeEvents2/AE_HUD.lua
AwesomeEvents2/AE_Settings.lua
AwesomeEvents2/AwesomeEvents2.lua
AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
AwesomeEvents2/Modules/Clock.lua
diff --git a/AwesomeEvents2/AE_HUD.lua b/AwesomeEvents2/AE_HUD.lua
index 1c225e9..ad07139 100644
--- a/AwesomeEvents2/AE_HUD.lua
+++ b/AwesomeEvents2/AE_HUD.lua
@@ -17,6 +17,7 @@ local ENTRY_TEMPLATE = "AWEVS_ListEntry"
 local LIST_ENTRY_LIMIT = 20
 local FADE_MS = 200

+
 local EntryList = {}

 function EntryList:Initialize(control)
@@ -73,6 +74,7 @@ end

 local DRAGGING = false
 local AwesomeEventsHUD = {}
+local AwesomeColors = { [COLOR_AWEVS_AVAILABLE]=nil,[COLOR_AWEVS_HINT]=nil,[COLOR_AWEVS_WARNING]=nil}

 function AwesomeEventsHUD:Initialize(control)
     self.control = control
@@ -164,16 +166,17 @@ function AwesomeEventsHUD:RemoveEventsForModule(modId)
 end

 --Events
+
 function AwesomeEventsHUD:RegisterForEvents()

     local function OnShow(right,bottom,movable,drawLayer,scale)
-        AwesomeEventsHUD:SetRigth(right)
-        AwesomeEventsHUD:SetBottom(bottom)
-        AwesomeEventsHUD:SetDrawLayer(drawLayer)
-        AwesomeEventsHUD:SetMovable(movable)
+        self:SetRigth(right)
+        self:SetBottom(bottom)
+        self:SetDrawLayer(drawLayer)
+        self:SetMovable(movable)

         if(scale ~= nil) then
-            AwesomeEventsHUD:SetScale(scale)
+            self:SetScale(scale)
         end

         self.listFade:FadeIn(0, FADE_MS)
@@ -182,45 +185,63 @@ function AwesomeEventsHUD:RegisterForEvents()
     local function OnHide()
         self.listFade:FadeOut(0, 0)
     end
+
+    local function SetColor(type,value)
+        if(AwesomeColors[type]==nil)then
+            AwesomeColors[type] = ZO_ColorDef:New(value.r,value.g,value.b)
+        else
+            AwesomeColors[type]:SetRGB(value.r,value.g,value.b)
+        end
+    end

-    libAM.RegisterCallback("SHOW", OnShow())
-    libAM.RegisterCallback("HIDE", OnHide())
-    libAM.RegisterCallback("NEW_ENTRY", function(eventCode, ...) self:OnNewEntry(...) end)
-    libAM.RegisterCallback("OUTDATED_ENTRY", function(eventCode, ...) self:OnOutdatedEntry(...) end)
-    libAM.RegisterCallback("MODULE_DISABLED", function(eventCode, ...) self:OnRemoveModule(...) end)
-
-    libAM.RegisterCallback("hud.movable", function(eventCode, value) AwesomeEventsHUD:SetMovable(value) end)
-    libAM.RegisterCallback("hud.scale", function(eventCode, value) AwesomeEventsHUD:SetScale(value) end)
-    libAM.RegisterCallback("hud.right", function(eventCode, value)
-        if (not DRAGGING)then
-            AwesomeEventsHUD:SetRight(value)
+    local function OnConfigure(property,value)
+        if(property=="movable")then
+            self:SetMovable(value)
+        elseif(property=="scale")then
+            self:SetScale(value)
+        elseif(property=="right")then
+            if (not DRAGGING)then
+                self:SetRight(value)
+            end
+        elseif(property=="bottom")then
+            if (not DRAGGING)then
+                self:SetBottom(value)
+            end
+        elseif(property=="color_available")then
+            SetColor(COLOR_AWEVS_AVAILABLE,value)
+        elseif(property=="color_hint")then
+            SetColor(COLOR_AWEVS_HINT,value)
+        elseif(property=="color_warning")then
+            SetColor(COLOR_AWEVS_WARNING,value)
         end
-    end)
-    libAM.RegisterCallback("hud.bottom", function(eventCode, value)
-        if (not DRAGGING)then
-            AwesomeEventsHUD:SetBottom(value)
+    end
+
+    local function OnNewEntry(modId, entryId, icon, text, color, duration_ms)
+        local uniqueId = self.GetUniqueId(modId, entryId)
+        if duration_ms == 0 then
+            self.delayedClears[uniqueId] = nil
+            self:Insert(uniqueId, icon, text, color)
+        else
+            self.delayedClears[uniqueId] = GetFrameTimeMilliseconds() + duration_ms
         end
-    end)
-end
+    end

-function AwesomeEventsHUD:OnNewEvent(modId, entryId, icon, text, color, duration_ms)
-    local uniqueId = self.GetUniqueId(modId, entryId)
-    if duration_ms == 0 then
-        self.delayedClears[uniqueId] = nil
-        self:Insert(uniqueId, icon, text, color)
-    else
-        self.delayedClears[uniqueId] = GetFrameTimeMilliseconds() + duration_ms
+    local function OnOutdatedEntry(modId, entryId)
+        self:Remove(self.GetUniqueId(modId, entryId))
     end
-end

-function AwesomeEventsHUD:OnOutdatedEvent(modId, entryId)
-    self:Remove(self.GetUniqueId(modId, entryId))
-end
+    local function OnRemoveModule(modId)
+        self:RemoveEventsForModule(modId)
+    end

-function AwesomeEventsHUD:OnRemoveModule(modId)
-    self:RemoveEventsForModule(modId)
-end
+    libAM.RegisterCallback("SHOW", OnShow())
+    libAM.RegisterCallback("HIDE", OnHide())
+    libAM.RegisterCallback("NEW_ENTRY", function(modId, entryId, icon, text, color, duration_ms) OnNewEntry(modId, entryId, icon, text, color, duration_ms) end)
+    libAM.RegisterCallback("OUTDATED_ENTRY", function(modId, entryId) OnOutdatedEntry(modId,entryId) end)
+    libAM.RegisterCallback("MODULE_DISABLED", function(modId) OnRemoveModule(modId) end)

+    libAM.RegisterCallback("SET_hud", function(property,value) OnConfigure(property,value) end);
+end

 function AwesomeEventsHUD_OnInitialize(control)
     AwesomeEventsHUD:Initialize(control)
@@ -249,8 +270,8 @@ end
 function AwesomeEventsHUD_OnMoveStop(control)
     -- save only in default view, not in settings
     if(control:GetDrawLayer() == DL_OVERLAY)then
-        libAM.SetVar('hud.right',control:GetRight())
-        libAM.SetVar('hud.bottom',control:GetBottom())
+        libAM.SetVar('hud','right',control:GetRight())
+        libAM.SetVar('hud','bottom',control:GetBottom())
     end
     DRAGGING = false
 end
\ No newline at end of file
diff --git a/AwesomeEvents2/AE_Settings.lua b/AwesomeEvents2/AE_Settings.lua
index 43883ad..49254ef 100644
--- a/AwesomeEvents2/AE_Settings.lua
+++ b/AwesomeEvents2/AE_Settings.lua
@@ -27,43 +27,39 @@ local defaults = {
         bottom = 100,
         movable = true,
         scale = 1.0,
-        textColor = {
-            [COLOR_AWEVS_AVAILABLE] = {r=0.5,g=0.83,b=0.5},
-            [COLOR_AWEVS_HINT] = {r=0.83,g=0.8,b=0.5},
-            [COLOR_AWEVS_WARNING] = {r=0.83,g=0.59,b=0.5},
-        }
+        color_available = {r=0.5,g=0.83,b=0.5},
+        color_hint = {r=0.83,g=0.8,b=0.5},
+        color_warning = {r=0.83,g=0.59,b=0.5},
     },
 }
 local vars = {}

-local function GetEnabledValue(enabledText)
-    if(enabledText == GetString(SI_AWEMOD_SHOW_ICON))then return 2 end
-    if(enabledText == GetString(SI_AWEMOD_SHOW_TEXT))then return 3 end
-    if(enabledText == GetString(SI_AWEMOD_SHOW_NONE))then return 0 end
-    return 1
+local function SetEnabledTransformer(enabledText)
+    if(enabledText == GetString(SI_AWEMOD_SHOW_ICON))then return ENABLED_AWEVS_ICON_ONLY end
+    if(enabledText == GetString(SI_AWEMOD_SHOW_TEXT))then return ENABLED_AWEVS_TEXT_ONLY end
+    if(enabledText == GetString(SI_AWEMOD_SHOW_NONE))then return ENABLED_AWEVS_NONE end
+    return ENABLED_AWEVS_ICON_AND_TEXT
 end

-local function GetEnabledString(enabled)
+local function GetEnabledTransformer(enabled)
     if(enabled == ENABLED_AWEVS_NONE)then return GetString(SI_AWEMOD_SHOW_NONE) end
     if(enabled == ENABLED_AWEVS_ICON_AND_TEXT)then return GetString(SI_AWEMOD_SHOW_ICON_AND_TEXT) end
     if(enabled == ENABLED_AWEVS_ICON_ONLY)then return GetString(SI_AWEMOD_SHOW_ICON) end
     if(enabled == ENABLED_AWEVS_TEXT_ONLY)then return GetString(SI_AWEMOD_SHOW_TEXT) end
-    return nil
+    return ""
 end

-local function View_SetTextColor(type,rValue,gValue,bValue)
+local function SetColorTransformer(rValue,gValue,bValue,aValue)
     rValue = math.floor(rValue*100)/100
     gValue = math.floor(gValue*100)/100
     bValue = math.floor(bValue*100)/100
-    libAM.SetColorDef(type,rValue,gValue,bValue)
-    vars.window.textColor[type] = {r=rValue,g=gValue,b=bValue}
-    for mod_id,mod in libAM:module_pairs() do
-        if(vars[mod_id].enabled>0)then
-            mod.dataUpdated = true
-        end
-    end
-end -- View_SetTextColor
+    aValue = math.floor(aValue*100)/100
+    return {r=rValue,g=gValue,b=bValue,a=aValue}
+end -- GetColorValue

+local function GetColorTransformer(color)
+    return color.r,color.g,color.b,color.a
+end

 local function __recursive_copy(orig)
     local orig_type = type(orig)
@@ -104,14 +100,13 @@ local function ImportConfigFromCharacter(characterName)
             libAM.d('settings','Imported successfully!')
             -- restore module user config
             for mod_id,mod in libAM:module_pairs() do
-
                 mod:Disable()
                 if(vars[mod_id].enabled>0)then
                     mod:Enable(vars[mod_id])
                 end
             end
             -- restore gui user config
-            for key,color in pairs(vars.window.textColor) do
+            for key,color in pairs(vars.hud.textColor) do
                 libAM.SetColorDef(key,color.r,color.g,color.b)
             end

@@ -119,56 +114,36 @@ local function ImportConfigFromCharacter(characterName)
     end
 end -- ImportConfigFromCharacter

---- create a getFcn function callback for LAM panelOptions
-local function __CreateSettingsGetter(mod_id,property,dataTransformer)
-    if(libAM.modules[mod_id] == nil) then return end
+--- GET callback for LAM panelOptions
+local function _GET(mod_id,property,dataTransformer)
+    if(vars[mod_id] == nil) then return end
     if(dataTransformer ~= nil)then
         return function() return dataTransformer(vars[mod_id][property]) end
     else
         return function() return vars[mod_id][property] end
     end
-end -- __CreateSettingsGetter
-
---- create a setFcn function callback for LAM panelOptions
-local function __CreateSettingsSetter(mod_id,key)
-    if(libAM.modules[mod_id] == nil) then return end
-    local mod = libAM.modules[mod_id]
-    if(key=='enabled')then
-        return function(value)
-            value = GetEnabledValue(value)
-            vars[mod.id][key] = value
-            libAM.d('SetEnabled',value)
-            if(value>0)then
-                libAM.d('main','Enable['..mod_id..']')
-                mod:Enable(vars[mod_id])
-            else
-                libAM.d('main','Disable['..mod_id..']')
-                mod:Disable()
-            end
-            SetEventListeners()
-            View_SetSize()
-        end
-    elseif(key=='fontSize')then
-        return function(value)
-            vars[mod_id][key] = value
-            View_SetTextSize()
-            View_SetSize()
-        end
-    end
-    return function(value)
-        vars[mod_id][key] = value
-        libAM.d('settings','Set['..mod_id..']: '..key,value)
-        mod:Set(key,value)
+end -- _GET
+
+--- SET callback for LAM panelOptions
+local function _SET(mod_id,key,dataTransformer)
+    if(dataTransformer ~= nil)then
+        return function(...) libAM.SetVar(mod_id,key,dataTransformer(...)) end
+    else
+        return function(value) libAM.SetVar(mod_id,key,value) end
     end
-end -- __CreateSettingsSetter
+end -- _SET

---- create a disabled function callback for LAM panelOptions
-local function __CreateSettingsDisabler(mod_id)
-    return function() return vars[mod_id].enabled > 0 end
-end -- __CreateSettingsDisabler
+--- DISABLED callback for LAM panelOptions
+local function _DISABLED(mod_id,callback)
+    if( callback == nil)then
+        return function() return vars[mod_id].enabled ~= ENABLED_AWEVS_NONE end
+    else
+        return function() return (vars[mod_id].enabled ~= ENABLED_AWEVS_NONE) and callback() end
+    end
+end -- _DISABLED

 --- create the addon menu with libaddonmenu
-local function CreateSettingsMenu(panelOptions)
+local function BuildAddonMenu(panelOptions)
     local LAM2 = LibStub('LibAddonMenu-2.0')
     local panelData = {
         type = 'panel',
@@ -182,10 +157,10 @@ local function CreateSettingsMenu(panelOptions)

     LAM2:RegisterAddonPanel(addon.panelName, panelData)
     LAM2:RegisterOptionControls(addon.panelName, panelOptions)
-end -- CreateSettingsMenu
+end -- BuildAddonMenu

 --- load module configuration and inject getter/setter, build default configuration
-local function LoadModulesConfiguration()
+local function BuildPanelOptions()
     -- load characters for copy button
     local importOptions = {GetString(SI_AWEVS_IMPORT_CHARACTER_SELECT)}
     for i = 1, GetNumCharacters() do
@@ -208,18 +183,9 @@ local function LoadModulesConfiguration()
             type = 'checkbox',
             name = GetString(SI_AWEVS_APPEARANCE_MOVABLE),
             tooltip = GetString(SI_AWEVS_APPEARANCE_MOVABLE_HINT),
-            getFunc = function() return vars.window.movable end,
-            setFunc = function(newValue) View_SetMovable(newValue) end,
-            default = defaults.window.movable,
-        },
-        {
-            type = 'dropdown',
-            name = GetString(SI_AWEVS_APPEARANCE_TEXTALIGN),
-            tooltip = GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_HINT),
-            choices = {GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_LEFT),GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_CENTER),GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_RIGHT)},
-            getFunc = function() return GetTextAlignString(vars.window.textAlign) end,
-            setFunc = function(newValue) View_SetTextAlign(newValue) end,
-            default = function() return GetTextAlignString(defaults.window.textAlign) end,
+            getFunc = _GET('hud','movable'),
+            setFunc = _SET('hud','movable'),
+            default = defaults.hud.movable,
         },
         {
             type = 'slider',
@@ -227,33 +193,33 @@ local function LoadModulesConfiguration()
             tooltip = GetString(SI_AWEVS_APPEARANCE_UISCALE_HINT),
             min  = 5,
             max = 15,
-            getFunc = function() return 10 * vars.window.scaling end,
-            setFunc = function(newValue) View_SetScale(newValue) end,
-            default = 10 * defaults.window.scaling,
+            getFunc = _GET('hud','scale',function(value) return 10*value end),
+            setFunc = _SET('hud','scale',function(value) return value/10 end),
+            default = 10 * defaults.hud.scale,
         },
         {
             type = 'colorpicker',
             name = GetString(SI_AWEVS_APPEARANCE_COLOR_AVAILABLE),
             tooltip = GetString(SI_AWEVS_APPEARANCE_COLOR_AVAILABLE_HINT),
-            getFunc = function() local c=vars.window.textColor[COLOR_AWEVS_AVAILABLE]; return c.r,c.g,c.b,1 end,
-            setFunc = function(r, g, b, a) View_SetTextColor(COLOR_AWEVS_AVAILABLE,r,g,b) end,
-            default = defaults.window.textColor[COLOR_AWEVS_AVAILABLE],
+            getFunc = _GET('hud','color_available',GetColorTransformer),
+            setFunc = _SET('hud','color_available',SetColorTransformer),
+            default = defaults.hud.color_available,
         },
         {
             type = 'colorpicker',
             name = GetString(SI_AWEVS_APPEARANCE_COLOR_HINT),
             tooltip = GetString(SI_AWEVS_APPEARANCE_COLOR_HINT_HINT),
-            getFunc = function() local c=vars.window.textColor[COLOR_AWEVS_HINT]; return c.r,c.g,c.b,1 end,
-            setFunc = function(r, g, b, a) View_SetTextColor(COLOR_AWEVS_HINT,r,g,b) end,
-            default = defaults.window.textColor[COLOR_AWEVS_HINT],
+            getFunc = _GET('hud','color_hint',GetColorTransformer),
+            setFunc = _SET('hud','color_hint',SetColorTransformer),
+            default = defaults.hud.color_hint,
         },
         {
             type = 'colorpicker',
             name = GetString(SI_AWEVS_APPEARANCE_COLOR_WARNING),
             tooltip = GetString(SI_AWEVS_APPEARANCE_COLOR_WARNING_HINT),
-            getFunc = function() local c=vars.window.textColor[COLOR_AWEVS_WARNING]; return c.r,c.g,c.b,1 end,
-            setFunc = function(r, g, b, a) View_SetTextColor(COLOR_AWEVS_WARNING,r,g,b) end,
-            default = defaults.window.textColor[COLOR_AWEVS_WARNING],
+            getFunc = _GET('hud','color_warning',GetColorTransformer),
+            setFunc = _SET('hud','color_warning',SetColorTransformer),
+            default = defaults.hud.color_warning,
         },
         {
             type = 'header',
@@ -283,8 +249,6 @@ local function LoadModulesConfiguration()
         -- create defaults
         defaults[mod_id] = defaults[mod_id] or {}
         defaults[mod_id].enabled = 1
-        defaults[mod_id].spacingPosition = mod.spacingPosition or TEXT_ALIGN_BOTTOM
-        defaults[mod_id].spacing = mod.spacing or 5
         defaults[mod_id].fontSize = mod.fontSize or 1
         table.insert( panelOptions,{
             type = 'header',
@@ -295,49 +259,28 @@ local function LoadModulesConfiguration()
             name = GetString(SI_AWEMOD_SHOW),
             tooltip = mod.hint .. '\n' .. GetString(SI_AWEMOD_SHOW_HINT),
             choices = {GetString(SI_AWEMOD_SHOW_ICON_AND_TEXT),GetString(SI_AWEMOD_SHOW_ICON),GetString(SI_AWEMOD_SHOW_TEXT),GetString(SI_AWEMOD_SHOW_NONE)},
-            getFunc = __CreateSettingsGetter(mod_id,'enabled',GetEnabledString),
-            setFunc = __CreateSettingsSetter(mod_id,'enabled',GetEnabledValue),
-            default = GetEnabledString(defaults[mod_id].enabled),
+            getFunc = _GET(mod_id,'enabled',GetEnabledTransformer),
+            setFunc = _SET(mod_id,'enabled',SetEnabledTransformer),
+            default = defaults[mod_id].enabled,
         })
         table.insert( panelOptions, {
-            type = 'dropdown',
-            name = GetString(SI_AWEMOD_SPACING_POSITION),
-            tooltip = GetString(SI_AWEMOD_SPACING_POSITION_HINT),
-            choices = {GetString(SI_AWEMOD_SPACING_TOP),GetString(SI_AWEMOD_SPACING_BOTTOM),GetString(SI_AWEMOD_SPACING_BOTH)},
-            getFunc = __CreateSettingsGetter(mod_id,'spacingPosition',GetSpacingPositionString),
-            setFunc = __CreateSettingsSetter(mod_id,'spacingPosition',GetSpacingPositionValue),
-            disabled = __CreateSettingsDisabler(mod_id),
-            default = GetSpacingPositionString(defaults[mod_id].spacingPosition),
-        })
-        table.insert( panelOptions,{
-            type = 'slider',
-            name = GetString(SI_AWEMOD_SPACING),
-            tooltip = GetString(SI_AWEMOD_SPACING_HINT),
-            min  = 0,
-            max = 30,
-            getFunc = __CreateSettingsGetter(mod_id,'spacing'),
-            setFunc = __CreateSettingsSetter(mod_id,'spacing'),
-            disabled = __CreateSettingsDisabler(mod_id),
-            default = defaults[mod_id].spacing,
-        })
-        table.insert( panelOptions,{
             type = 'slider',
             name = GetString(SI_AWEMOD_FONTSIZE),
             tooltip = GetString(SI_AWEMOD_FONTSIZE_HINT),
             min  = 1,
             max = 5,
-            getFunc = __CreateSettingsGetter(mod_id,'fontSize'),
-            setFunc = __CreateSettingsSetter(mod_id,'fontSize'),
-            disabled = __CreateSettingsDisabler(mod_id),
+            getFunc = _GET(mod_id,'fontSize'),
+            setFunc = _SET(mod_id,'fontSize'),
+            disabled = _DISABLED(mod_id),
             default = defaults[mod_id].fontSize,
         })
         -- foreach options
         for key,option in mod:option_pairs() do
             if(option.type~=nil and option.name ~= nil and option.tooltip ~= nil and option.default ~= nil)then
                 defaults[mod_id][key] = option.default
-                option.getFunc = __CreateSettingsGetter(mod_id,key)
-                option.setFunc = __CreateSettingsSetter(mod_id,key)
-                option.disabled = __CreateSettingsDisabler(mod_id)
+                option.getFunc = _GET(mod_id,key,option.getTransfomer)
+                option.setFunc = _SET(mod_id,key,option.setTransfomer)
+                option.disabled = _DISABLED(mod_id,option.disabled)
                 table.insert( panelOptions, option )
             else
                 libAM.d('main','LoadModule['..mod_id..']',GetString(SI_AWEVS_DEBUG_MODULE_OPTION_INVALID),option)
@@ -345,7 +288,7 @@ local function LoadModulesConfiguration()
         end
     end
     return panelOptions
-end -- LoadModulesConfiguration
+end -- BuildPanelOptions

 local function ShowHUD()
     if(IN_GAME_MENU)then
@@ -368,8 +311,7 @@ local function LAM_OnChangeActivePanel(panel)
     end
 end -- LAM_OnChangeActivePanel

-local function SetVar(property,value)
-    local mod_id,option = string.match(property,"(%w+)\.(%w+)")
+local function SetVar(mod_id,option,value)
     if(vars[mod_id] == nil)then
         vars[mod_id] = {}
     end
@@ -380,11 +322,12 @@ local function Initialize()
     EVENT_MANAGER:UnregisterForEvent('Awesome_Events_Settings', EVENT_PLAYER_ACTIVATED)

     -- load configuration
-    local panelOptions = LoadModulesConfiguration()
     vars = ZO_SavedVars:New('AwesomeEvents2', 1, nil, defaults)

     -- create addon menu (LAM)
-    CreateSettingsMenu(panelOptions)
+    BuildAddonMenu(
+        BuildPanelOptions()
+    )

     -- register LAM/optionsPanel events
     local lamControl = WINDOW_MANAGER:GetControlByName('LAMAddonSettingsWindow')
@@ -423,6 +366,7 @@ local function Initialize()
     -- init modules
     libAM:Initialize(vars)

+    -- register settings callback
     libAM.RegisterCallback("SET",SetVar)

     ShowHUD()
diff --git a/AwesomeEvents2/AwesomeEvents2.lua b/AwesomeEvents2/AwesomeEvents2.lua
index 6a8fa43..702400f 100644
--- a/AwesomeEvents2/AwesomeEvents2.lua
+++ b/AwesomeEvents2/AwesomeEvents2.lua
@@ -24,8 +24,8 @@ local function OnEvent(...)
     local args = {... }
     local eventCode = args[1] or 'unknown'
     if(events[eventCode] ~= nil)then
-        for mod_id,callback in pairs(events[eventCode]) do
-            -- slibAM.d('main','OnEvent['..mod_id..']: '..eventCode)
+        for _,callback in pairs(events[eventCode]) do
+            -- libAM.d('main','OnEvent['..mod_id..']: '..eventCode)
             callback(unpack(args))
         end
     else
@@ -37,7 +37,7 @@ end -- OnEvent
 local function SetEventListeners()
     libAM.d('main','SetEventListeners')
     -- remove old listeners
-    for eventCode,event in pairs(events) do
+    for eventCode in pairs(events) do
         EVENT_MANAGER:UnregisterForEvent('Awesome_Events', eventCode)
     end

@@ -109,7 +109,6 @@ local function Update(timestamp)
         if(vars[mod.id].enabled > 0 and mod:HasUpdate())then
             mod.dataUpdated = false
             mod:Update(vars[mod.id])
-            resizeView = true
         end
     end
 end -- Update
diff --git a/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua b/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
index c194d25..3d37872 100644
--- a/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
+++ b/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
@@ -23,19 +23,15 @@ COLOR_AWEVS_AVAILABLE = 1
 COLOR_AWEVS_HINT = 2
 COLOR_AWEVS_WARNING = 3

+-- DisplayType
 ENABLED_AWEVS_NONE = 0
 ENABLED_AWEVS_ICON_AND_TEXT = 1
 ENABLED_AWEVS_ICON_ONLY = 2
 ENABLED_AWEVS_TEXT_ONLY = 3

-local colorDefs = { [COLOR_AWEVS_AVAILABLE]=nil,[COLOR_AWEVS_HINT]=nil,[COLOR_AWEVS_WARNING]=nil}
-
 libAM.version = MINOR
-libAM.modules = {}
-libAM.labelToMod = {}
-libAM.timer = {}

-local DEBUG,CM = false,ZO_CallbackObject:Subclass()
+local CM,DEBUG,MODULES,TIMER = ZO_CallbackObject:Subclass(),false,{},{}

 ---
 -- Write new debug message
@@ -48,21 +44,6 @@ function libAM.d(...)
 end

 ---
--- Create color object from RGB values
--- @param type ColorType
--- @param r int
--- @param g int
--- @param b int
---
-function libAM.SetColorDef(type,r,g,b)
-    if(colorDefs[type]==nil)then
-        colorDefs[type] = ZO_ColorDef:New(r,g,b)
-    else
-        colorDefs[type]:SetRGB(r,g,b)
-    end
-end
-
----
 -- Create sorted map of options
 -- @param options table
 --
@@ -116,18 +97,18 @@ end
 -- get modules in sorted order
 --
 function libAM:module_pairs()
-    if(self.modules.__orderedIndex == nil)then
-        self.modules.__orderedIndex = __genOrderedIndex( self.modules )
+    if(MODULES.__orderedIndex == nil)then
+        MODULES.__orderedIndex = __genOrderedIndex( MODULES )
     end
     -- Equivalent of the pairs() function on tables. Allows to iterate
     -- in order
-    return __getNextElement, self.modules, nil
+    return __getNextElement, MODULES, nil
 end

 -- Mod Constructor

 function libAM:New(uniqueId)
-    if(uniqueId==nil or self.modules[uniqueId]~=nil)then
+    if(uniqueId==nil or uniqueId=="hud" or MODULES[uniqueId]~=nil)then
         d('[AwesomeEvents] Fatal error: Module id empty or already in use (id:'.. uniqueId..')')
         return {}
     end
@@ -141,7 +122,6 @@ function libAM:New(uniqueId)
         options = {
             enabled = true,
             fontSize = 1,
-            spacing = 0,
         },
         order = 40,

@@ -206,27 +186,13 @@ function libAM:New(uniqueId)
         end
     end

-    function Module:Enable(options)
-        self:d('Enable (in debug-mode)')
-        if(type(self.label)=='table')then
-            for i,_data in pairs(self.label) do
-                self.label[i]:SetText('')
-            end
-        else
-            self.label:SetText('')
-        end
+    function Module:Initialize(options)
+        self:d('Enable')
         self.dataUpdated = true
     end

     function Module:Disable()
         self:d('Disable')
-        if(type(self.label)=='table')then
-            for i,_data in pairs(self.label) do
-                self.label[i]:SetText('')
-            end
-        else
-            self.label:SetText('')
-        end
     end

     function Module:Set(key,value)
@@ -313,13 +279,25 @@ function libAM:New(uniqueId)
         return __getNextElement, self.options, nil
     end

-    self.modules[Module.id] = Module
+    MODULES[Module.id] = Module
+
+    CM:RegisterCallback('SET_'..uniqueId,function(key,value)

-    libAM.CM:RegisterCallback('AwesomeEventsModConfig_'..uniqueId,function(options)
-        self.modules[uniqueId]:Initialize(options)
+        if(key=='enabled')then
+            if(value>0)then
+                self:Enable()
+            else
+                self:Disable()
+            end
+        elseif(key=='fontSize')then
+            self:Disable()
+            self:Enable()
+        else
+            self:Set(key,value)
+        end
     end)

-    return self.modules[Module.id]
+    return MODULES[Module.id]
 end

 ---
@@ -359,25 +337,42 @@ function libAM.SetHidden(value,right,bottom,movable,drawLayer,scale)
     end
 end

-function libAM.SetVar(property,value)
-    CM:FireCallbacks(property,value)
-    CM:FireCallbacks("SET",property,value)
+function libAM.SetVar(mod_id,option,value)
+    --local mod_id,option = string.match(property,"(%w+)\.(%w+)")
+    CM:FireCallbacks("SET",mod_id,option,value)
+
+    local mod = MODULES[mod_id]
+    if(mod ~= nil)then
+        if(option=='enabled')then
+            if(value>0)then
+                mod:Enable()
+            else
+                CM:FireCallbacks("MODULE_DISABLED",mod_id)
+            end
+        elseif(option=='fontSize')then
+            CM:FireCallbacks("MODULE_DISABLED",mod_id)
+        else
+            mod:Set(option,value)
+        end
+    else
+        CM:FireCallbacks("SET_"..mod_id,option,value)
+    end
 end

 local INITIALIZED = false
 function libAM:Initialize(vars)
     if(INITIALIZED)then return end

-    -- init modules: create labels and preload data
-    for mod_id,mod in self.modules do
-        mod:Initialize( vars[mod_id] )
-    end
-
     -- restore colors
     for key,color in pairs(vars.hud.textColor) do
         self.SetColorDef(key,color.r,color.g,color.b)
     end

+    -- enable modules
+    for mod_id,mod in MODULES do
+        mod:Initialize( vars[mod_id] )
+    end
+
     INITIALIZED = true
     self.d('main','Complete!')
     CM:FireCallbacks('RELOAD_EVENT_LISTENER')
diff --git a/AwesomeEvents2/Modules/Clock.lua b/AwesomeEvents2/Modules/Clock.lua
index 5fcc915..db0af32 100644
--- a/AwesomeEvents2/Modules/Clock.lua
+++ b/AwesomeEvents2/Modules/Clock.lua
@@ -14,17 +14,18 @@
 local libAM = LibStub('LibAwesomeModule-2.0')
 local MOD = libAM:New('clock')

-local CLOCK_TYPE_TIME = 0
-local CLOCK_TYPE_DATE = 1
-
 MOD.title = GetString(SI_AWEMOD_CLOCK)
 MOD.hint = GetString(SI_AWEMOD_CLOCK_HINT)
 MOD.order = 10
 MOD.debug = false

-MOD.label = {}
-MOD.label[CLOCK_TYPE_TIME] = {}
-MOD.label[CLOCK_TYPE_DATE] = {}
+local CLOCK_TYPE_TIME = 0
+local CLOCK_TYPE_DATE = 1
+
+MOD.label = {
+    [CLOCK_TYPE_TIME] = {},
+    [CLOCK_TYPE_DATE] = {}
+}

 -- USER SETTINGS