*lib: move properties to local variables

Martin Unkel [05-30-18 - 14:39]
*lib: move properties to local variables
+lib: add CallbackManager accessors
+update mvc logic
Filename
AwesomeEvents2/AE_DebugWindow.lua
AwesomeEvents2/AE_HUD.lua
AwesomeEvents2/AE_Settings.lua
AwesomeEvents2/AwesomeEvents2.lua
AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
diff --git a/AwesomeEvents2/AE_DebugWindow.lua b/AwesomeEvents2/AE_DebugWindow.lua
index 410fabb..9f54005 100644
--- a/AwesomeEvents2/AE_DebugWindow.lua
+++ b/AwesomeEvents2/AE_DebugWindow.lua
@@ -57,6 +57,7 @@ local function __tostring(object,level)
     return str..'\n'
 end

+-- write new debug message to debug window
 local function WriteDebugMessage(...)
     if(debugWindow == nil)then return end

@@ -80,31 +81,30 @@ local function WriteDebugMessage(...)
     debugWindow:AddText(value)
 end

--- Create Debug Window
+---
+-- Create the Debug Window
+-- @param show
+--
 local function ToggleDebugWindow(show)
     -- show debug window
     if(show)then

         if(debugWindow==nil)then
             local libMW = LibStub:GetLibrary("LibMsgWin-1.0")
-            debugWindow = libMW:CreateMsgWindow("AwesomeEventsDebugWindow", "Awesome Events Debug Log", 0, 0)
+            debugWindow = libMW:CreateMsgWindow("AwesomeEvents2DebugWindow", "AwesomeEvents Log", 0, 0)
         else
             debugWindow:SetHidden(false)
         end

-        if(not libAM.debug)then
-            debugWindow:AddText('Debug-Log: '..GetString(SI_AWEVS_DEBUG_DISABLED))
-            debugWindow:AddText('Usage: /aedebug mod_id (on\off)')
-        end
-
-        libAM.CallbackManager:RegisterCallback('DEBUG_MESSAGE',WriteDebugMessage)
+        libAM.RegisterCallback('DEBUG_MESSAGE',WriteDebugMessage)

     -- hide debug window
     else
         if(debugWindow~=nil)then
             debugWindow:SetHidden(true)
+            debugWindow:ClearText()
         end
-        libAM.CallbackManager:UnregisterCallback('DEBUG_MESSAGE',WriteDebugMessage)
+        libAM.UnregisterCallback('DEBUG_MESSAGE',WriteDebugMessage)
     end
 end -- ToggleDebugWindow

@@ -131,41 +131,54 @@ local function __SlashAEDebug(command)
     local value = args[2] or nil

     if(mod_id ~= nil and libAM.modules[mod_id] ~= nil)then
+        local debug = false
         local mod = libAM.modules[mod_id]
         if(value ~= nil)then
             if(value=='on' or value=='On' or value=='ON'or value=='oN')then
                 mod.debug = true
-                libAM.debug = true
-                ToggleDebugWindow(true)
+                debug = true
             else
                 mod.debug = false

                 -- any other module in debug mode ?
-                libAM.debug = false
-                for mod_id,mod in libAM:module_pairs() do
+                for _,mod in libAM:module_pairs() do
                     if(mod.debug)then
-                        libAM.debug = true
-                    end
-                end
-
-                -- clear old logs
-                if(not libAM.debug)then
-                    if(debugWindow ~= nil)then
-                        debugWindow:SetHidden(true)
-                        debugWindow:ClearText()
+                        debug = true
                     end
                 end
             end
         end
+        libAM.SetDebug(debug)
+
         local enabled = GetString(SI_AWEVS_DEBUG_DISABLED)
         if(mod.debug)then enabled =  GetString(SI_AWEVS_DEBUG_ENABLED) end
         d('[AwesomeEvents] Debug [' .. mod_id .. ']: ' .. enabled)
         libAM.d('Debug-Log: ' .. enabled)
     else
-        d('[AwesomeEvents] Debug [' .. mod_id .. ']: '..GetString(SI_AWEVS_DEBUG_MODULE_NOT_FOUND),'Usage: /aedebug mod_id (on||off)')
+        d('[AwesomeEvents] Debug [' .. mod_id .. ']: '..GetString(SI_AWEVS_DEBUG_MODULE_NOT_FOUND),'Usage: /ae2 mod_id (on||off)')
     end
 end -- __SlashAEDebug

-SLASH_COMMANDS['/aedebug'] = __SlashAEDebug
+SLASH_COMMANDS['/ae2'] = __SlashAEDebug
+
+libAM.RegisterCallback("DEBUG_TOGGLE", ToggleDebugWindow);
+
+---
+--- INIT
+---
+
+local function Initialize()
+    EVENT_MANAGER:UnregisterForEvent('Awesome_Events_Debug', EVENT_PLAYER_ACTIVATED)
+
+    -- test if any mod is in debug mode
+    local debug = false
+    for _,mod in libAM:module_pairs() do
+        if(mod.debug)then
+            debug = true
+        end
+    end
+    libAM.SetDebug(debug)
+end
+

-libAM.CallbackManager:RegisterCallback("DEBUG_TOGGLE", ToggleDebugWindow);
\ No newline at end of file
+EVENT_MANAGER:RegisterForEvent('Awesome_Events_Debug', EVENT_PLAYER_ACTIVATED, Initialize)
\ No newline at end of file
diff --git a/AwesomeEvents2/AE_HUD.lua b/AwesomeEvents2/AE_HUD.lua
index f5bc361..1c225e9 100644
--- a/AwesomeEvents2/AE_HUD.lua
+++ b/AwesomeEvents2/AE_HUD.lua
@@ -71,7 +71,7 @@ end



-
+local DRAGGING = false
 local AwesomeEventsHUD = {}

 function AwesomeEventsHUD:Initialize(control)
@@ -166,18 +166,41 @@ end
 --Events
 function AwesomeEventsHUD:RegisterForEvents()

-    local function OnShow()
+    local function OnShow(right,bottom,movable,drawLayer,scale)
+        AwesomeEventsHUD:SetRigth(right)
+        AwesomeEventsHUD:SetBottom(bottom)
+        AwesomeEventsHUD:SetDrawLayer(drawLayer)
+        AwesomeEventsHUD:SetMovable(movable)
+
+        if(scale ~= nil) then
+            AwesomeEventsHUD:SetScale(scale)
+        end
+
         self.listFade:FadeIn(0, FADE_MS)
+
     end
     local function OnHide()
         self.listFade:FadeOut(0, 0)
     end

-    libAM.CallbackManager:RegisterCallback("AwesomeEventsShow", OnShow())
-    libAM.CallbackManager:RegisterCallback("AwesomeEventsHide", OnHide())
-    libAM.CallbackManager:RegisterCallback("AwesomeEventsNewEntry", function(eventCode, ...) self:OnNewEntry(...) end)
-    libAM.CallbackManager:RegisterCallback("AwesomeEventsOutdatedEntry", function(eventCode, ...) self:OnOutdatedEntry(...) end)
-    libAM.CallbackManager:RegisterCallback("AwesomeEventsModuleDisabled", function(eventCode, ...) self:OnRemoveModule(...) 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)
+        end
+    end)
+    libAM.RegisterCallback("hud.bottom", function(eventCode, value)
+        if (not DRAGGING)then
+            AwesomeEventsHUD:SetBottom(value)
+        end
+    end)
 end

 function AwesomeEventsHUD:OnNewEvent(modId, entryId, icon, text, color, duration_ms)
@@ -215,10 +238,19 @@ function AwesomeEventsHUD_OnUpdate(frameTime)
     --local timestamp = GetTimeStamp()
     if ( frameTime ~= LAST_FRAME_TIME ) then
         LAST_FRAME_TIME = frameTime
-        libAM.CallbackManager:FireCallbacks('AwesomeEventsUpdate',GetTimeStamp())
+        libAM.Update()
     end
 end

+function AwesomeEventsHUD_OnMoveStart()
+    DRAGGING = true
+end
+
 function AwesomeEventsHUD_OnMoveStop(control)
-    libAM.CallbackManager:FireCallbacks('AwesomeEventsPositionChanged',control:GetRight(),control:GetBottom())
+    -- 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())
+    end
+    DRAGGING = false
 end
\ No newline at end of file
diff --git a/AwesomeEvents2/AE_Settings.lua b/AwesomeEvents2/AE_Settings.lua
index 7d91a20..43883ad 100644
--- a/AwesomeEvents2/AE_Settings.lua
+++ b/AwesomeEvents2/AE_Settings.lua
@@ -19,15 +19,14 @@ local addon = {

 local libAM = LibStub('LibAwesomeModule-2.0')

-local vars = {}
+local IN_GAME_MENU = false
+
 local defaults = {
-    isDefault = true,
-    window = {
-        left = GuiRoot:GetWidth()/2,
-        top = 100,
+    hud = {
+        right = GuiRoot:GetWidth()/2,
+        bottom = 100,
         movable = true,
-        scaling = 1.0,
-        textAlign = TEXT_ALIGN_CENTER,
+        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},
@@ -35,9 +34,7 @@ local defaults = {
         }
     },
 }
-
-
-
+local vars = {}

 local function GetEnabledValue(enabledText)
     if(enabledText == GetString(SI_AWEMOD_SHOW_ICON))then return 2 end
@@ -54,30 +51,18 @@ local function GetEnabledString(enabled)
     return nil
 end

---- return a spacingPosition property as localized string
-local function GetSpacingPositionValue(spacingPositionText)
-    if(spacingPositionText == GetString(SI_AWEMOD_SPACING_BOTTOM)) then return TEXT_ALIGN_BOTTOM end
-    if(spacingPositionText == GetString(SI_AWEMOD_SPACING_BOTH)) then return TEXT_ALIGN_CENTER end
-    return TEXT_ALIGN_TOP
-end
-
-local function GetSpacingPositionString(spacingPosition)
-    if(spacingPosition == TEXT_ALIGN_TOP) then return GetString(SI_AWEMOD_SPACING_TOP) end
-    if(spacingPosition == TEXT_ALIGN_BOTTOM) then return GetString(SI_AWEMOD_SPACING_BOTTOM) end
-    if(spacingPosition == TEXT_ALIGN_CENTER) then return GetString(SI_AWEMOD_SPACING_BOTH) end
-    return nil
-end -- GetSpacingPositionString
-
---- return a textAlign property as localized string
-local function GetTextAlignString(textAlign)
-    if(textAlign == TEXT_ALIGN_LEFT) then return GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_LEFT) end
-    if(textAlign == TEXT_ALIGN_CENTER) then return GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_CENTER) end
-    if(textAlign == TEXT_ALIGN_RIGHT) then return GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_RIGHT) end
-    return nil
-end -- GetTextAlignString
-
-
-
+local function View_SetTextColor(type,rValue,gValue,bValue)
+    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


 local function __recursive_copy(orig)
@@ -120,7 +105,6 @@ local function ImportConfigFromCharacter(characterName)
             -- restore module user config
             for mod_id,mod in libAM:module_pairs() do

-                libAM.CallbackManager:FireCallbacks('AwesomeEventsModConfig_'..mod_id, vars[mod_id])
                 mod:Disable()
                 if(vars[mod_id].enabled>0)then
                     mod:Enable(vars[mod_id])
@@ -131,7 +115,6 @@ local function ImportConfigFromCharacter(characterName)
                 libAM.SetColorDef(key,color.r,color.g,color.b)
             end

-            libAM.CallbackManager:FireCallbacks("AwesomeEventsViewConfig",vars.window);
         end
     end
 end -- ImportConfigFromCharacter
@@ -165,15 +148,6 @@ local function __CreateSettingsSetter(mod_id,key)
             SetEventListeners()
             View_SetSize()
         end
-    elseif(key=='spacingPosition')then
-        return function(value)
-            View_SetSpacingPosition(mod_id,value)
-        end
-    elseif(key=='spacing')then
-        return function(value)
-            vars[mod_id][key] = value
-            View_SetSize()
-        end
     elseif(key=='fontSize')then
         return function(value)
             vars[mod_id][key] = value
@@ -373,19 +347,89 @@ local function LoadModulesConfiguration()
     return panelOptions
 end -- LoadModulesConfiguration

+local function ShowHUD()
+    if(IN_GAME_MENU)then
+        libAM.SetHidden(false,vars.hud.right,vars.hud.bottom,true,DL_OVERLAY,1)
+    else
+        libAM.SetHidden(false,vars.hud.right,vars.hud.bottom,vars.hud.movable,DL_BACKGROUND,vars.hud.scale)
+    end
+end
+
 local function LAM_OnChangeActivePanel(panel)
     if(panel==nil or panel:GetName() == '')then
         panel = WINDOW_MANAGER:GetControlByName(addon.panelName)
         if not panel:IsHidden() then
-            View_SetHidden(false)
+            libAM.SetHidden(false)
         end
     elseif(panel:GetName()==addon.panelName)then
-        View_SetHidden(false)
+        libAM.SetHidden(false)
     else
-        View_SetHidden(true)
+        ShowHUD(true)
     end
 end -- LAM_OnChangeActivePanel

-libAM.RegisterCallback('AwesomeEventsPositionChanged',function(right,bottom)
-        vars.window.
-    end)
\ No newline at end of file
+local function SetVar(property,value)
+    local mod_id,option = string.match(property,"(%w+)\.(%w+)")
+    if(vars[mod_id] == nil)then
+        vars[mod_id] = {}
+    end
+    vars[mod_id][option] = value
+end
+
+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)
+
+    -- register LAM/optionsPanel events
+    local lamControl = WINDOW_MANAGER:GetControlByName('LAMAddonSettingsWindow')
+    local lamOnShowHandler = lamControl:GetHandler('OnShow')
+    if(lamOnShowHandler ~= nil) then
+        lamControl:SetHandler('OnShow',function(self,hidden)
+            LAM_OnChangeActivePanel()
+            lamOnShowHandler(self,hidden)
+        end)
+    else
+        lamControl:SetHandler('OnShow',function(self,hidden)
+            LAM_OnChangeActivePanel()
+        end)
+    end
+
+    CALLBACK_MANAGER:RegisterCallback("LAM-RefreshPanel",LAM_OnChangeActivePanel)
+
+    -- register SCENE events
+    SCENE_MANAGER:RegisterCallback("SceneStateChanged", function(scene,oldState,newState)
+        if(scene.name == 'hud' or scene.name == 'hudui')then
+            if(newState == SCENE_HIDING)then
+                libAM.SetHidden(true)
+            elseif(newState == SCENE_SHOWN)then
+                ShowHUD()
+            end
+        elseif(scene.name == 'gameMenuInGame')then
+            if(newState == SCENE_HIDING)then
+                IN_GAME_MENU = false
+                libAM.SetHidden(true)
+            elseif(newState == SCENE_SHOWN)then
+                IN_GAME_MENU = true
+            end
+        end
+    end)
+
+    -- init modules
+    libAM:Initialize(vars)
+
+    libAM.RegisterCallback("SET",SetVar)
+
+    ShowHUD()
+end
+
+----------------
+-- INIT EVENT --
+----------------
+
+EVENT_MANAGER:RegisterForEvent('Awesome_Events_Settings', EVENT_PLAYER_ACTIVATED, Initialize)
\ No newline at end of file
diff --git a/AwesomeEvents2/AwesomeEvents2.lua b/AwesomeEvents2/AwesomeEvents2.lua
index 29023cd..6a8fa43 100644
--- a/AwesomeEvents2/AwesomeEvents2.lua
+++ b/AwesomeEvents2/AwesomeEvents2.lua
@@ -11,301 +11,12 @@
   Please read the README file for further information.
   ]]

-local state = {
-    initialized = false,
-    dragging = false,
-    lastUpdate = 0,
-    lastWidth = 0,
-    updateFrequency = 10,

-    inSettingsPanel = false,
-    position = {left=1000,top=30},
-
-    importFromCharacter = nil
-}
-
-local defaults = {
-    isDefault = true,
-    window = {
-        left = GuiRoot:GetWidth()/2,
-        top = 100,
-        movable = true,
-        scaling = 1.0,
-        textAlign = TEXT_ALIGN_CENTER,
-        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},
-        }
-    },
-}
-local vars = {}
 local events = {}

 local libAM = LibStub('LibAwesomeModule-2.0')

 ---
---- VIEW FUNCTIONS
----
-
---- after resizing the window or at first load, the anchors have to be resetted
-local function View_SetAnchors()
-    --[[
-    AwesomeEventsView:ClearAnchors()
-    if (vars.window.textAlign == TEXT_ALIGN_LEFT) then
-        AwesomeEventsView:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, state.position.left, state.position.top)
-    elseif (vars.window.textAlign == TEXT_ALIGN_RIGHT) then
-        AwesomeEventsView:SetAnchor(TOPRIGHT, GuiRoot, TOPLEFT, state.position.left, state.position.top)
-    else
-        AwesomeEventsView:SetAnchor(TOP, GuiRoot, TOPLEFT, state.position.left, state.position.top)
-    end
-    ]]
-end -- View_SetAnchors
-
---- resize the window to show all visible labels
-local function View_SetSize()
-    --[[
-    if state.dragging then return end
-
-    local maxWidth,totalHeight,lastModId,lastLabel,lastModLabelCount = 0,0,nil,nil,0
-    local lazyAddSpacing = 0
-
-    -- starting at 1, but 1 = backgorund, 2 = title
-    for i = 3, AwesomeEventsView:GetNumChildren() do
-        local child = AwesomeEventsView:GetChild(i)
-        local text = child:GetText()
-
-        -- hide if text is empty
-        if(text == '')then
-            -- not hidden yet?
-            if(child:GetHeight() > 0)then
-                child:SetHeight(0)
-            end
-
-            -- show label with text
-        else
-            child:SetWidth(0)
-            local mod_id,spacing = libAM.labelToMod[i],0
-            -- last mod ended ?
-            if(lastModId~=mod_id)then
-                -- add bottom spacing to previous label (if mod has multiple label for)
-                if(lazyAddSpacing>0)then
-                    lastLabel:SetHeight(lastLabel:GetHeight() + lazyAddSpacing);
-                    totalHeight = totalHeight + lazyAddSpacing
-                    if(lastModLabelCount>1 or vars[lastModId].spacingPosition==TEXT_ALIGN_TOP)then
-                        lastLabel:SetVerticalAlignment(TEXT_ALIGN_TOP);
-                    else
-                        lastLabel:SetVerticalAlignment(TEXT_ALIGN_CENTER);
-                    end
-                    lazyAddSpacing = 0
-                end
-                lastModLabelCount = 0
-
-                -- add top spacing
-                if(vars[mod_id].spacingPosition==TEXT_ALIGN_BOTTOM)then
-                    spacing = vars[mod_id].spacing
-                    child:SetVerticalAlignment(TEXT_ALIGN_BOTTOM);
-                elseif(vars[mod_id].spacingPosition==TEXT_ALIGN_CENTER)then
-                    spacing = vars[mod_id].spacing
-                    child:SetVerticalAlignment(TEXT_ALIGN_BOTTOM);
-                    lazyAddSpacing = spacing
-                elseif(vars[mod_id].spacingPosition==TEXT_ALIGN_TOP)then
-                    child:SetVerticalAlignment(TEXT_ALIGN_TOP);
-                    lazyAddSpacing = vars[mod_id].spacing
-                end
-            end
-
-            local newHeight = child:GetTextHeight() + spacing
-            -- not yet visible or wrong spacing ?
-            if(newHeight ~= child:GetHeight())then
-                child:SetHeight(newHeight)
-            end
-            totalHeight = totalHeight + newHeight
-            maxWidth = math.max(maxWidth,child:GetTextWidth())
-
-            lastModLabelCount = lastModLabelCount+1
-            lastModId = mod_id
-            lastLabel = child
-        end
-    end
-
-    if(lazyAddSpacing>0)then
-        lastLabel:SetHeight(lastLabel:GetHeight() + lazyAddSpacing);
-        totalHeight = totalHeight + lazyAddSpacing
-        if(lastModLabelCount>1)then
-            lastLabel:SetVerticalAlignment(TEXT_ALIGN_TOP);
-        else
-            lastLabel:SetVerticalAlignment(TEXT_ALIGN_CENTER);
-        end
-    end
-
-    -- show awesome events label if no other label active
-    local child = AwesomeEventsView:GetChild(2)
-    local text = child:GetText()
-    if(totalHeight>0 and text~='')then
-        child:SetText('')
-        child:SetHeight(0)
-    elseif(totalHeight==0)then
-        text = GetString(SI_AWEVS_NO_ACTIVE_MOD)
-        for mod_id in libAM:module_pairs() do
-            if(vars[mod_id].enabled>0)then
-                text = addon.title
-            end
-        end
-        child:SetText(text)
-        child:SetWidth(0)
-        totalHeight = child:GetTextHeight()
-        child:SetHeight(totalHeight)
-        maxWidth = child:GetTextWidth()
-    end
-
-    maxWidth = (maxWidth+20)
-    totalHeight = totalHeight+10
-
-    for i = 2, AwesomeEventsView:GetNumChildren() do
-        local child = AwesomeEventsView:GetChild(i)
-        child:SetWidth(maxWidth)
-    end
-
-    AwesomeEventsView:SetWidth(maxWidth)
-    AwesomeEventsView:SetHeight(totalHeight)
-
-    if(state.lastWidth ~= maxWidth)then
-        state.lastWidth = maxWidth
-        View_SetAnchors();
-    end
-    ]]
-end -- View_SetSize
-
---- change view movability
-local function View_SetMovable(movable)
-    vars.window.movable = movable
-    AwesomeEventsView:SetMovable(movable)
-end -- View_SetMovable
-
---- change view scale
-local function View_SetScale(scaling)
-    vars.window.scaling = scaling / 10;
-    AwesomeEventsView:SetScale(vars.window.scaling)
-    View_SetSize()
-end -- View_SetScale
-
---- change vertical alignment of a label, adjust view size
-local function View_SetSpacingPosition(mod_id,newSpacingPosition)
-    --[[ translate value to key
-    if(newSpacingPosition == GetString(SI_AWEMOD_SPACING_TOP)) then
-        newSpacingPosition = TEXT_ALIGN_TOP
-    elseif(newSpacingPosition == GetString(SI_AWEMOD_SPACING_BOTTOM)) then
-        newSpacingPosition = TEXT_ALIGN_BOTTOM
-    elseif(newSpacingPosition == GetString(SI_AWEMOD_SPACING_BOTH)) then
-        newSpacingPosition = TEXT_ALIGN_CENTER
-    end
-    vars[mod_id].spacingPosition = newSpacingPosition
-    View_SetSize()
-    ]]
-end -- View_SetSpacingPosition
-
---- change horizontal alignment of all labels, adjust view position
-local function View_SetTextAlign(newTextAlign)
-    --[[ translate value to key
-    if(newTextAlign == GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_LEFT)) then
-        newTextAlign = TEXT_ALIGN_LEFT
-    elseif(newTextAlign == GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_RIGHT)) then
-        newTextAlign = TEXT_ALIGN_RIGHT
-    elseif(newTextAlign == GetString(SI_AWEVS_APPEARANCE_TEXTALIGN_CENTER)) then
-        newTextAlign = TEXT_ALIGN_CENTER
-    end
-    -- keep the position even if the anchor changes
-    if(state.initialized)then
-        local halfWindowWidth,leftShift = math.floor(AwesomeEventsView:GetWidth()/2),0
-        if(vars.window.textAlign == TEXT_ALIGN_LEFT)then
-            leftShift = halfWindowWidth
-        elseif(vars.window.textAlign == TEXT_ALIGN_RIGHT)then
-            leftShift = 0 - halfWindowWidth
-        end
-        if(newTextAlign == TEXT_ALIGN_LEFT)then
-            leftShift = leftShift - halfWindowWidth
-        elseif(newTextAlign == TEXT_ALIGN_RIGHT)then
-            leftShift = leftShift + halfWindowWidth
-        end
-        state.position.left = state.position.left + leftShift
-        vars.window.left = vars.window.left + leftShift
-    end
-    vars.window.textAlign = newTextAlign
-
-    View_SetAnchors()
-    for i = 2, AwesomeEventsView:GetNumChildren() do
-        local child = AwesomeEventsView:GetChild(i)
-        child:SetHorizontalAlignment(newTextAlign)
-    end
-    ]]
-end -- View_SetTextAlign
-
-local function View_SetTextColor(type,rValue,gValue,bValue)
-    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
-
---- update the font size of all labels
-local function View_SetTextSize()
-    --[[ starting at 1, but 1 = background, 2 = title
-    for i = 3, AwesomeEventsView:GetNumChildren() do
-        local child = AwesomeEventsView:GetChild(i)
-        local mod_id = libAM.labelToMod[i]
-        local fontSize = 6-vars[mod_id].fontSize
-        if(fontSize<1)then fontSize = 1 end
-        if(fontSize>5)then fontSize = 5 end
-        child:SetFont('ZoFontWinH'..fontSize)
-    end
-    ]]
-end -- View_SetTextSize
-
-local function View_SetHidden(hidden)
-   --[[ if(hidden == null)then
-        hidden = false
-    end
-    if (not hidden and AwesomeEventsView:IsHidden()) then
-        if (state.inSettingsPanel) then
-            local sub = {
-                [TEXT_ALIGN_LEFT] = AwesomeEventsView:GetWidth(),
-                [TEXT_ALIGN_CENTER] = AwesomeEventsView:GetWidth()/2,
-                [TEXT_ALIGN_RIGHT] = 0,
-            }
-            state.position.left = math.floor(GuiRoot:GetWidth()*0.96) - sub[vars.window.textAlign]
-            state.position.top = 200
-
-            AwesomeEventsView:SetDrawLayer(DL_OVERLAY)
-            AwesomeEventsView:SetMovable(true)
-            AwesomeEventsViewBg:SetAlpha(1)
-        else
-            state.position.left = vars.window.left
-            state.position.top = vars.window.top
-
-            AwesomeEventsView:SetDrawLayer(DL_BACKGROUND)
-            AwesomeEventsView:SetMovable(vars.window.movable)
-            AwesomeEventsViewBg:SetAlpha(0)
-        end
-        View_SetAnchors()
-    end
-    AwesomeEventsView:SetHidden(false)
-    ]]
-    if(hidden == true)then
-        libAM.CallbackManager:FireCallbacks("AwesomeEventsShow")
-    else
-        libAM.CallbackManager:FireCallbacks("AwesomeEventsHide")
-    end
-end -- View_SetHidden
-
-
----
 -- EVENT MANAGER
 ---

@@ -358,96 +69,6 @@ local function SetEventListeners()
     end
 end -- SetEventListeners

-
---- Initialize modules, config menu, views and user configuration
-local function Initialize()
-    -- Only initialize the addon (after all addons are loaded)
-    EVENT_MANAGER:UnregisterForEvent('Awesome_Events', EVENT_PLAYER_ACTIVATED)
-
-    -- test if any mod is in debug mode
-    for mod_id,mod in libAM:module_pairs() do
-        if(mod.debug)then
-            libAM.debug = true
-        end
-    end
-    if(libAM.debug)then
-        libAM.CallbackManager:FireCallbacks("DEBUG_TOGGLE",true)
-    end
-
-    libAM.RegisterCallback("AwesomeEventsConfigReloaded", function(_vars)
-        AwesomeEventsView:SetScale(_vars.window.scaling)
-        AwesomeEventsView:SetMovable(_vars.window.movable)
-        View_SetTextAlign(_vars.window.textAlign)
-        View_SetTextSize()
-        View_SetSize()
-    end);
-
-    -- load module- and user configuration
-    local panelOptions = LoadModulesConfiguration()
-    vars = ZO_SavedVars:New('AwesomeEvents', 2, nil, defaults)
-    vars.isDefault = false
-
-    -- init modules: create labels and preload data
-    for mod_id,mod in libAM:module_pairs() do
-        mod:Initialize( vars[mod_id] )
-    end
-    libAM.d('main','Complete!')
-
-    -- restore gui user config
-    for key,color in pairs(vars.window.textColor) do
-        libAM.SetColorDef(key,color.r,color.g,color.b)
-    end
-    AwesomeEventsView:SetScale(vars.window.scaling)
-    AwesomeEventsView:SetMovable(vars.window.movable)
-    View_SetTextAlign(vars.window.textAlign)
-    View_SetTextSize()
-    View_SetSize()
-
-    -- create addon menu (LAM)
-    CreateSettingsMenu(panelOptions)
-
-    -- register LAM/optionsPanel events
-    local lamControl = WINDOW_MANAGER:GetControlByName('LAMAddonSettingsWindow')
-    local lamOnShowHandler = lamControl:GetHandler('OnShow')
-    if(lamOnShowHandler ~= nil) then
-        lamControl:SetHandler('OnShow',function(self,hidden)
-            LAM_OnChangeActivePanel()
-            lamOnShowHandler(self,hidden)
-        end)
-    else
-        lamControl:SetHandler('OnShow',function(self,hidden)
-            LAM_OnChangeActivePanel()
-        end)
-    end
-    CALLBACK_MANAGER:RegisterCallback("LAM-RefreshPanel",LAM_OnChangeActivePanel)
-
-    -- register SCENE events
-    SCENE_MANAGER:RegisterCallback("SceneStateChanged", function(scene,oldState,newState)
-        if(scene.name == 'hud' or scene.name == 'hudui')then
-            if(newState == SCENE_HIDING)then
-                View_SetHidden(true)
-            elseif(newState == SCENE_SHOWN)then
-                View_SetHidden(false)
-            end
-        elseif(scene.name == 'gameMenuInGame')then
-            if(newState == SCENE_HIDING)then
-                state.inSettingsPanel = false
-                View_SetHidden(true)
-            elseif(newState == SCENE_SHOWN)then
-                state.inSettingsPanel = true
-            end
-        end
-    end)
-
-    -- register MODULE events
-    SetEventListeners()
-
-    state.initialized = true
-
-    View_SetHidden(false)
-end -- Initialize
-
-
 ---
 -- MAIN FRAME UPDATE
 ---
@@ -482,7 +103,7 @@ local function Update(timestamp)
             end
         end
     end
-    local resizeView = false
+
     -- update each module
     for mod_id,mod in libAM:module_pairs() do
         if(vars[mod.id].enabled > 0 and mod:HasUpdate())then
@@ -491,58 +112,8 @@ local function Update(timestamp)
             resizeView = true
         end
     end
-    if(resizeView)then
-        View_SetSize();
-    end
 end -- Update


--------------------------
--- VIEW EVENT LISTENER --
--------------------------
-
-function AWESOME_EVENTS_OnMoveStart()
-    if (not state.initialized) then return end
-
-    -- start dragging mode
-    state.dragging = true
-
-    -- do not change alpha in LAMSettingsPanel
-    if(not state.inSettingsPanel)then
-        AwesomeEventsViewBg:SetAlpha(0.5)
-    end
-end -- AWESOME_EVENTS_OnMoveStart
-
-function AWESOME_EVENTS_OnMoveStop()
-    --[[
-    if (not state.initialized) then return end
-
-    if (vars.window.textAlign == TEXT_ALIGN_LEFT) then
-        state.position.left = AwesomeEventsView:GetLeft()
-        state.position.top = AwesomeEventsView:GetTop()
-    elseif (vars.window.textAlign == TEXT_ALIGN_RIGHT) then
-        state.position.left = AwesomeEventsView:GetRight()
-        state.position.top = AwesomeEventsView:GetTop()
-    else
-        state.position.left = AwesomeEventsView:GetCenter()
-        state.position.top = AwesomeEventsView:GetTop()
-    end
-
-    -- do not store movement or change alpha in LAMSettingsPanel
-    if(not state.inSettingsPanel)then
-        AwesomeEventsViewBg:SetAlpha(0)
-        vars.window.left = math.floor(state.position.left*100)/100;
-        vars.window.top = math.floor(state.position.top*100)/100;
-    end
-    state.dragging = false
-    ]]
-end -- AWESOME_EVENTS_OnMoveStop
-
-
-
-
-----------------
--- INIT EVENT --
-----------------
-
-EVENT_MANAGER:RegisterForEvent('Awesome_Events', EVENT_PLAYER_ACTIVATED, Initialize)
\ No newline at end of file
+libAM.RegisterCallback('RELOAD_EVENT_LISTENER',SetEventListeners)
+libAM.RegisterCallback('UPDATE',Update)
\ No newline at end of file
diff --git a/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua b/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
index 43f037a..c194d25 100644
--- a/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
+++ b/AwesomeEvents2/Libs/LibAwesomeModule-2.0/LibAwesomeModule-2.0.lua
@@ -18,6 +18,7 @@ if not libAM then return end
 EVENT_AWESOME_MODULE_TIMER = 1
 ORDER_AWESOME_MODULE_PUSH_NOTIFICATION = 75

+-- ColorType
 COLOR_AWEVS_AVAILABLE = 1
 COLOR_AWEVS_HINT = 2
 COLOR_AWEVS_WARNING = 3
@@ -33,15 +34,26 @@ libAM.version = MINOR
 libAM.modules = {}
 libAM.labelToMod = {}
 libAM.timer = {}
-libAM.debug = false
-libAM.CallbackManager = ZO_CallbackObject:Subclass()

+local DEBUG,CM = false,ZO_CallbackObject:Subclass()
+
+---
+-- Write new debug message
+-- @param ... mixed
+--
 function libAM.d(...)
-    if libAM.debug then
-        libAM.CallbackManager:FireCallbacks('DEBUG_MESSAGE',...)
+    if DEBUG then
+        CM:FireCallbacks('DEBUG_MESSAGE',...)
     end
 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)
@@ -50,6 +62,10 @@ function libAM.SetColorDef(type,r,g,b)
     end
 end

+---
+-- Create sorted map of options
+-- @param options table
+--
 local function __genOrderedIndex( options )
     local orderToKeyMap,orderedNumbers,orderedIndex = {},{},{}
     for key,option in pairs(options) do
@@ -61,12 +77,17 @@ local function __genOrderedIndex( options )
         table.insert( orderedNumbers, order )
     end
     table.sort( orderedNumbers )
-    for i,order in ipairs(orderedNumbers) do
+    for _,order in ipairs(orderedNumbers) do
         table.insert( orderedIndex, orderToKeyMap[order] )
     end
     return orderedIndex
 end

+---
+-- iterator for ordered tables
+-- @param t table
+-- @param state last object
+--
 local function __getNextElement(t, state)
     -- Equivalent of the next function, but returns the keys in the alphabetic order
     local key
@@ -91,6 +112,18 @@ local function __getNextElement(t, state)
     return
 end

+---
+-- get modules in sorted order
+--
+function libAM:module_pairs()
+    if(self.modules.__orderedIndex == nil)then
+        self.modules.__orderedIndex = __genOrderedIndex( self.modules )
+    end
+    -- Equivalent of the pairs() function on tables. Allows to iterate
+    -- in order
+    return __getNextElement, self.modules, nil
+end
+
 -- Mod Constructor

 function libAM:New(uniqueId)
@@ -282,48 +315,77 @@ function libAM:New(uniqueId)

     self.modules[Module.id] = Module

-    libAM.CallbackManager:RegisterCallback('AwesomeEventsModConfig_'..uniqueId,function(options)
+    libAM.CM:RegisterCallback('AwesomeEventsModConfig_'..uniqueId,function(options)
         self.modules[uniqueId]:Initialize(options)
     end)

     return self.modules[Module.id]
 end

-local function __genModulesIndex( modules )
-    local titleToIdMap,orderedTitles,orderedIndex = {},{},{}
-    for mod_id,mod in pairs(modules) do
-        local i,title = 1,mod.title
-        while(titleToIdMap[title]~=nil)do
-            title = mod.title .. i
-            i = i+1
-        end
-        titleToIdMap[title] = mod_id
-        table.insert( orderedTitles, title )
-    end
-    table.sort( orderedTitles )
-    for i,title in ipairs(orderedTitles) do
-        table.insert( orderedIndex, titleToIdMap[title] )
+---
+-- Register new Callback
+-- @param event string
+-- @param callback Callable
+--
+function libAM.RegisterCallback(event, callback)
+    CM:RegisterCallback(event, callback)
+end
+
+---
+-- Unregister existing Callback
+-- @param event string
+-- @param callback Callable
+--
+function libAM.UnregisterCallback(event, callback)
+    CM:UnregisterCallback(event, callback)
+end
+
+---
+-- toggel debug window
+-- @param value bool
+--
+function libAM:SetDebug(value)
+    if(DEBUG ~= value)then
+        DEBUG = value
+        CM:FireCallbacks("DEBUG_TOGGLE",value)
     end
-    return orderedIndex
 end

-function libAM:module_pairs()
-    if(self.modules.__orderedIndex == nil)then
-        self.modules.__orderedIndex = __genOrderedIndex( self.modules )
+function libAM.SetHidden(value,right,bottom,movable,drawLayer,scale)
+    if(value)then
+        CM:FireCallbacks("HIDE")
+    else
+        CM:FireCallbacks("SHOW",right,bottom,movable,drawLayer,scale)
     end
-    -- Equivalent of the pairs() function on tables. Allows to iterate
-    -- in order
-    return __getNextElement, self.modules, nil
 end

-function libAM.Initialize()
-    -- test for debug mode in modules
-    for mod_id,mod in libAM:module_pairs() do
-        if(mod.debug)then
-            libAM.debug = true
-        end
+function libAM.SetVar(property,value)
+    CM:FireCallbacks(property,value)
+    CM:FireCallbacks("SET",property,value)
+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
-    if(libAM.debug)then
-        libAM.CallbackManager:FireCallbacks("DEBUG_TOGGLE",true)
+
+    -- restore colors
+    for key,color in pairs(vars.hud.textColor) do
+        self.SetColorDef(key,color.r,color.g,color.b)
     end
+
+    INITIALIZED = true
+    self.d('main','Complete!')
+    CM:FireCallbacks('RELOAD_EVENT_LISTENER')
+end
+
+---
+-- fire update callbacks
+--
+function libAM.Update()
+    CM:FireCallbacks('UPDATE',GetTimeStamp())
 end
\ No newline at end of file