Quantcast

Basic clock functionality

MilleXIV [08-13-16 - 16:50]
Basic clock functionality
Filename
core.lua
locales/enUS.lua
modules/clock.lua
modules/load_modules.xml
modules/micromenu.lua
modules/old/clock.lua
diff --git a/core.lua b/core.lua
index 3ef5514..fcfea3c 100644
--- a/core.lua
+++ b/core.lua
@@ -218,7 +218,7 @@ end

 function XIVBar:Refresh()
   if self.frames.bar == nil then return; end
-  --error(debugstack())
+
   local barColor = self.db.profile.color.barColor
   self.frames.bar:ClearAllPoints()
   self.frames.bar:SetPoint(self.db.profile.general.barPosition)
diff --git a/locales/enUS.lua b/locales/enUS.lua
index 80a95dc..1e1db8a 100644
--- a/locales/enUS.lua
+++ b/locales/enUS.lua
@@ -36,3 +36,9 @@ L['Micromenu'] = true;
 L['Show Social Tooltips'] = true;
 L['Main Menu Icon Right Spacing'] = true;
 L['Icon Spacing'] = true;
+
+L['Armor'] = true;
+
+L['Clock'] = true;
+L['Time Format'] = true;
+L['Use Server Time'] = true;
diff --git a/modules/clock.lua b/modules/clock.lua
index 80c17a3..5a6604c 100644
--- a/modules/clock.lua
+++ b/modules/clock.lua
@@ -1,110 +1,190 @@
-local addon, ns = ...
-local cfg = ns.cfg
-local unpack = unpack
---------------------------------------------------------------
-if not cfg.clock.show then return end
-
-local hour, minu = 0,0
-local AmPmTimeText = ""
-
-local clockFrame = CreateFrame("BUTTON",nil, cfg.SXframe)
-clockFrame:SetSize(32, 32)
-clockFrame:SetPoint("CENTER")
-clockFrame:EnableMouse(true)
-clockFrame:RegisterForClicks("AnyUp")
-
-local clockText = clockFrame:CreateFontString(nil, "OVERLAY")
-clockText:SetFont(cfg.text.font, cfg.SXframe:GetHeight()-4)
-clockText:SetPoint("LEFT")
-clockText:SetTextColor(unpack(cfg.color.normal))
-
-local amText = clockFrame:CreateFontString(nil, "OVERLAY")
-amText:SetFont(cfg.text.font, cfg.text.normalFontSize)
-amText:SetPoint("RIGHT")
-amText:SetTextColor(unpack(cfg.color.inactive))
-
-local calendarText = clockFrame:CreateFontString(nil, "OVERLAY")
-calendarText:SetFont(cfg.text.font, cfg.text.smallFontSize)
-calendarText:SetPoint("CENTER", clockFrame, "TOP")
-if cfg.core.position ~= "BOTTOM" then
-	calendarText:SetPoint("CENTER", clockFrame, "BOTTOM")
+local AddOnName, XIVBar = ...;
+local _G = _G;
+local xb = XIVBar;
+local L = XIVBar.L;
+
+local ClockModule = xb:NewModule("ClockModule")
+
+function ClockModule:GetName()
+  return L['Clock'];
+end
+
+function ClockModule:OnInitialize()
+  if IsWindowsClient() then
+    self.timeFormats = {
+      twelveAmPm = '%I:%M %p',
+      twelveNoAm = '%I:%M',
+      twelveAmNoZero = '%#I:%M %p',
+      twelveNoAmNoZero = '%#I:%M',
+      twoFour = '%#H:%M',
+      twoFourNoZero = '%H:%M',
+    }
+  else
+    self.timeFormats = {
+      twelveAmPm = '%I:%M %p',
+      twelveNoAm = '%I:%M',
+      twelveAmNoZero = '%l:%M %p',
+      twelveNoAmNoZero = '%l:%M',
+      twoFour = '%R',
+      twoFourNoZero = '%k:%M',
+    }
+  end
+
+  self.exampleTimeFormats = {
+    twelveAmPm = '08:00 AM (12 Hour)',
+    twelveNoAm = '08:00 (12 Hour)',
+    twelveAmNoZero = '8:00 AM (12 Hour)',
+    twelveNoAmNoZero = '8:00 (12 Hour)',
+    twoFour = '08:00 (24 Hour)',
+    twoFourNoZero = '8:00 (24 Hour)'
+  }
+
+  self.elapsed = 0
+
+  self.functions = {}
+end
+
+function ClockModule:OnEnable()
+  if self.clockFrame == nil then
+    self.clockFrame = CreateFrame("FRAME", nil, xb:GetFrame('bar'))
+    xb:RegisterFrame('clockFrame', self.clockFrame)
+  end
+  self.elapsed = 0
+  self:CreateFrames()
+  self:CreateClickFunctions()
+  self:RegisterFrameEvents()
+  self:Refresh()
+end
+
+function ClockModule:OnDisable()
+  self.clockFrame:Hide()
+end
+
+function ClockModule:Refresh()
+  local db = xb.db.profile
+  if self.clockFrame == nil then return; end
+  if not db.modules.clock.enabled then return; end
+
+  --self.clockText:SetAllPoints()
+  self.clockText:SetFont(xb.LSM:Fetch(xb.LSM.MediaType.FONT, db.text.font), db.modules.clock.fontSize)
+  ClockModule:SetClockColor()
+  --self.clockFrame:SetSize(self.clockText:GetStringWidth(), self.clockText:GetStringHeight())
+  self.clockFrame:SetSize(100, 30)
+  self.clockFrame:SetPoint('CENTER', self.clockFrame:GetParent())
+  self.clockTextFrame:SetSize(self.clockText:GetStringWidth(), self.clockText:GetStringHeight())
+  self.clockTextFrame:SetPoint('CENTER')
+  self.clockText:SetPoint('CENTER')
+end
+
+function ClockModule:CreateFrames()
+  self.clockTextFrame = self.clockTextFrame or CreateFrame("BUTTON", 'XIV_ClockTextFrame', self.clockFrame)
+  self.clockText = self.clockText or self.clockTextFrame:CreateFontString(nil, "OVERLAY")
+  self.eventText = self.eventText or self.clockTextFrame:CreateFontString(nil, "OVERLAY")
+end
+
+function ClockModule:RegisterFrameEvents()
+
+  self.clockTextFrame:EnableMouse(true)
+  self.clockTextFrame:RegisterForClicks("AnyUp")
+
+  self.clockFrame:SetScript("OnUpdate", function(self, elapsed)
+    ClockModule.elapsed = ClockModule.elapsed + elapsed
+    if ClockModule.elapsed >= 1 then
+      local clockTime = nil
+      if xb.db.profile.modules.clock.serverTime then
+        clockTime = GetServerTime()
+      else
+        clockTime = time()
+      end
+      local dateString = date(ClockModule.timeFormats[xb.db.profile.modules.clock.timeFormat], clockTime)
+      ClockModule.clockText:SetText(dateString)
+      ClockModule:Refresh()
+      ClockModule.elapsed = 0
+    end
+  end)
+
+  self.clockTextFrame:SetScript('OnEnter', function()
+    if InCombatLockdown() then return; end
+    ClockModule:SetClockColor()
+  end)
+
+  self.clockTextFrame:SetScript('OnLeave', function()
+    if InCombatLockdown() then return; end
+    ClockModule:SetClockColor()
+  end)
+end
+
+function ClockModule:SetClockColor()
+  local db = xb.db.profile
+  if self.clockTextFrame:IsMouseOver() then
+    self.clockText:SetTextColor(unpack(xb:HoverColors()))
+  else
+    self.clockText:SetTextColor(db.color.normal.r, db.color.normal.g, db.color.normal.b, db.color.normal.a)
+  end
+end
+
+function ClockModule:UnregisterFrameEvents()
+end
+
+function ClockModule:CreateClickFunctions()
+end
+
+function ClockModule:GetDefaultOptions()
+  return 'clock', {
+      enabled = true,
+      timeFormat = 'twelveAmPm',
+      fontSize = 20,
+      serverTime = false
+    }
+end
+
+function ClockModule:GetConfig()
+  local timeFormatOptions = self.exampleTimeFormats
+  return {
+    name = self:GetName(),
+    type = "group",
+    args = {
+      enable = {
+        name = ENABLE,
+        order = 0,
+        type = "toggle",
+        get = function() return xb.db.profile.modules.clock.enabled; end,
+        set = function(_, val) xb.db.profile.modules.clock.enabled = val; end,
+        width = "full"
+      },
+      enable = {
+        name = L['Use Server Time'],
+        order = 1,
+        type = "toggle",
+        get = function() return xb.db.profile.modules.clock.serverTime; end,
+        set = function(_, val) xb.db.profile.modules.clock.serverTime = val; end
+      },
+      timeFormat = {
+        name = L['Time Format'],
+        order = 2,
+        type = "select",
+        values = { --TODO: WTF is with this not accepting a variable?
+          twelveAmPm = '08:00 AM (12 Hour)',
+          twelveNoAm = '08:00 (12 Hour)',
+          twelveAmNoZero = '8:00 AM (12 Hour)',
+          twelveNoAmNoZero = '8:00 (12 Hour)',
+          twoFour = '08:00 (24 Hour)',
+          twoFourNoZero = '8:00 (24 Hour)'
+        },
+        style = "dropdown",
+        get = function() return xb.db.profile.modules.clock.timeFormat; end,
+        set = function(info, val) xb.db.profile.modules.clock.timeFormat = val; self:Refresh(); end
+      },
+      fontSize = {
+        name = L['Font Size'],
+        type = 'range',
+        order = 3,
+        min = 10,
+        max = 20,
+        step = 1,
+        get = function() return xb.db.profile.modules.clock.fontSize; end,
+        set = function(info, val) xb.db.profile.modules.clock.fontSize = val; self:Refresh(); end
+      }
+    }
+  }
 end
-calendarText:SetTextColor(unpack(cfg.color.normal))
-
-local elapsed = 0
-clockFrame:SetScript('OnUpdate', function(self, e)
-	elapsed = elapsed + e
-	if elapsed >= 1 then
-		hour, minu = GetGameTime()
-		if minu < 10 then minu = ("0"..minu) end
-		if ( GetCVarBool("timeMgrUseLocalTime") ) then
-			if ( GetCVarBool("timeMgrUseMilitaryTime") ) then
-				clockText:SetText(date("%H:%M"))
-				amText:SetText("")
-			else
-				clockText:SetText(date("%I:%M"))
-				amText:SetText(date("%p"))
-			end
-		else
-			if ( GetCVarBool("timeMgrUseMilitaryTime") ) then
-				clockText:SetText(hour..":"..minu)
-				amText:SetText("")
-			else
-				if hour > 12 then
-					hour = hour - 12
-					hour = ("0"..hour)
-					AmPmTimeText = "PM"
-				else
-					AmPmTimeText = "AM"
-				end
-				clockText:SetText(hour..":"..minu)
-				amText:SetText(AmPmTimeText)
-			end
-
-		end
-		if (CalendarGetNumPendingInvites() > 0) then
-			calendarText:SetText(string.format("%s  (|cffffff00%i|r)", "New Event!", (CalendarGetNumPendingInvites())))
-		else
-			calendarText:SetText("")
-		end
-		clockFrame:SetWidth(clockText:GetStringWidth() + amText:GetStringWidth())
-		clockFrame:SetPoint("CENTER", cfg.SXframe)
-		elapsed = 0
-	end
-end)
-
---[[
-
---]]
-
-clockFrame:SetScript("OnEnter", function()
-	if InCombatLockdown() then return end
-	clockText:SetTextColor(unpack(cfg.color.hover))
-	if cfg.clock.showTooltip then
-	hour, minu = GetGameTime()
-	if minu < 10 then minu = ("0"..minu) end
-	GameTooltip:SetOwner(clockFrame, cfg.tooltipPos)
-	GameTooltip:AddLine("[|cff6699FFClock|r]")
-	GameTooltip:AddLine(" ")
-	if ( GetCVarBool("timeMgrUseLocalTime") ) then
-		GameTooltip:AddDoubleLine("Realm Time", hour..":"..minu, 1, 1, 0, 1, 1, 1)
-	else
-		GameTooltip:AddDoubleLine("Local Time", date("%H:%M"), 1, 1, 0, 1, 1, 1)
-	end
-	GameTooltip:AddLine(" ")
-	GameTooltip:AddDoubleLine("<Left-click>", "Open Calendar", 1, 1, 0, 1, 1, 1)
-	GameTooltip:AddDoubleLine("<Right-click>", "Open Clock", 1, 1, 0, 1, 1, 1)
-	GameTooltip:Show()
-	end
-end)
-
-clockFrame:SetScript("OnLeave", function() if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end clockText:SetTextColor(unpack(cfg.color.normal)) end)
-
-clockFrame:SetScript("OnClick", function(self, button, down)
-	if InCombatLockdown() then return end
-	if button == "LeftButton" then
-		ToggleCalendar()
-	elseif button == "RightButton" then
-		ToggleTimeManager()
-	end
-end)
\ No newline at end of file
diff --git a/modules/load_modules.xml b/modules/load_modules.xml
index 54b1f09..e80a701 100644
--- a/modules/load_modules.xml
+++ b/modules/load_modules.xml
@@ -1,4 +1,5 @@
 <Ui xmlns="http://www.blizzard.com/wow/ui/">
   <!--<Script file="test.lua" />-->
   <Script file="micromenu.lua" />
+  <Script file="clock.lua" />
 </Ui>
diff --git a/modules/micromenu.lua b/modules/micromenu.lua
index c485ee5..4a7594e 100644
--- a/modules/micromenu.lua
+++ b/modules/micromenu.lua
@@ -3,7 +3,7 @@ local _G = _G;
 local xb = XIVBar;
 local L = XIVBar.L;

-MenuModule = xb:NewModule("MenuModule", 'AceEvent-3.0')
+local MenuModule = xb:NewModule("MenuModule", 'AceEvent-3.0')

 function MenuModule:GetName()
   return L['Micromenu'];
@@ -204,6 +204,8 @@ function MenuModule:DefaultLeave(name)
 end

 function MenuModule:CreateClickFunctions()
+  if self.functions.menu ~= nil then return; end
+
   self.functions.menu = function(self, button, down)
     if InCombatLockdown() then return; end
     if button == "LeftButton" then
diff --git a/modules/old/clock.lua b/modules/old/clock.lua
new file mode 100644
index 0000000..80c17a3
--- /dev/null
+++ b/modules/old/clock.lua
@@ -0,0 +1,110 @@
+local addon, ns = ...
+local cfg = ns.cfg
+local unpack = unpack
+--------------------------------------------------------------
+if not cfg.clock.show then return end
+
+local hour, minu = 0,0
+local AmPmTimeText = ""
+
+local clockFrame = CreateFrame("BUTTON",nil, cfg.SXframe)
+clockFrame:SetSize(32, 32)
+clockFrame:SetPoint("CENTER")
+clockFrame:EnableMouse(true)
+clockFrame:RegisterForClicks("AnyUp")
+
+local clockText = clockFrame:CreateFontString(nil, "OVERLAY")
+clockText:SetFont(cfg.text.font, cfg.SXframe:GetHeight()-4)
+clockText:SetPoint("LEFT")
+clockText:SetTextColor(unpack(cfg.color.normal))
+
+local amText = clockFrame:CreateFontString(nil, "OVERLAY")
+amText:SetFont(cfg.text.font, cfg.text.normalFontSize)
+amText:SetPoint("RIGHT")
+amText:SetTextColor(unpack(cfg.color.inactive))
+
+local calendarText = clockFrame:CreateFontString(nil, "OVERLAY")
+calendarText:SetFont(cfg.text.font, cfg.text.smallFontSize)
+calendarText:SetPoint("CENTER", clockFrame, "TOP")
+if cfg.core.position ~= "BOTTOM" then
+	calendarText:SetPoint("CENTER", clockFrame, "BOTTOM")
+end
+calendarText:SetTextColor(unpack(cfg.color.normal))
+
+local elapsed = 0
+clockFrame:SetScript('OnUpdate', function(self, e)
+	elapsed = elapsed + e
+	if elapsed >= 1 then
+		hour, minu = GetGameTime()
+		if minu < 10 then minu = ("0"..minu) end
+		if ( GetCVarBool("timeMgrUseLocalTime") ) then
+			if ( GetCVarBool("timeMgrUseMilitaryTime") ) then
+				clockText:SetText(date("%H:%M"))
+				amText:SetText("")
+			else
+				clockText:SetText(date("%I:%M"))
+				amText:SetText(date("%p"))
+			end
+		else
+			if ( GetCVarBool("timeMgrUseMilitaryTime") ) then
+				clockText:SetText(hour..":"..minu)
+				amText:SetText("")
+			else
+				if hour > 12 then
+					hour = hour - 12
+					hour = ("0"..hour)
+					AmPmTimeText = "PM"
+				else
+					AmPmTimeText = "AM"
+				end
+				clockText:SetText(hour..":"..minu)
+				amText:SetText(AmPmTimeText)
+			end
+
+		end
+		if (CalendarGetNumPendingInvites() > 0) then
+			calendarText:SetText(string.format("%s  (|cffffff00%i|r)", "New Event!", (CalendarGetNumPendingInvites())))
+		else
+			calendarText:SetText("")
+		end
+		clockFrame:SetWidth(clockText:GetStringWidth() + amText:GetStringWidth())
+		clockFrame:SetPoint("CENTER", cfg.SXframe)
+		elapsed = 0
+	end
+end)
+
+--[[
+
+--]]
+
+clockFrame:SetScript("OnEnter", function()
+	if InCombatLockdown() then return end
+	clockText:SetTextColor(unpack(cfg.color.hover))
+	if cfg.clock.showTooltip then
+	hour, minu = GetGameTime()
+	if minu < 10 then minu = ("0"..minu) end
+	GameTooltip:SetOwner(clockFrame, cfg.tooltipPos)
+	GameTooltip:AddLine("[|cff6699FFClock|r]")
+	GameTooltip:AddLine(" ")
+	if ( GetCVarBool("timeMgrUseLocalTime") ) then
+		GameTooltip:AddDoubleLine("Realm Time", hour..":"..minu, 1, 1, 0, 1, 1, 1)
+	else
+		GameTooltip:AddDoubleLine("Local Time", date("%H:%M"), 1, 1, 0, 1, 1, 1)
+	end
+	GameTooltip:AddLine(" ")
+	GameTooltip:AddDoubleLine("<Left-click>", "Open Calendar", 1, 1, 0, 1, 1, 1)
+	GameTooltip:AddDoubleLine("<Right-click>", "Open Clock", 1, 1, 0, 1, 1, 1)
+	GameTooltip:Show()
+	end
+end)
+
+clockFrame:SetScript("OnLeave", function() if ( GameTooltip:IsShown() ) then GameTooltip:Hide() end clockText:SetTextColor(unpack(cfg.color.normal)) end)
+
+clockFrame:SetScript("OnClick", function(self, button, down)
+	if InCombatLockdown() then return end
+	if button == "LeftButton" then
+		ToggleCalendar()
+	elseif button == "RightButton" then
+		ToggleTimeManager()
+	end
+end)
\ No newline at end of file