view TimeManager/TimeManager.lua @ 60:2a636b00c31e

- buff time progress bars touched up
author Nenue
date Mon, 15 Aug 2016 07:23:56 -0400
parents 07ef62fe201f
children
line wrap: on
line source
--------------------------------------------
-- Veneer
-- Clock/Coordinate multi-tool
-- mouseover reveals coordinates by map yards, right-click toggles display
-- Krakyn
-- @project-revision@ @project-hash@
-- @file-revision@ @file-hash@
-- Created: 4/27/2016 1:02 AM
--------------------------------------------

local B = select(2,...).frame
local _G = _G
local clock = B:RegisterModule("Clock", _G.VeneerClock)
local print = B.print('XML') -- debug hook
-- weekday abbreviations used in display
local weekDays = {'Su', 'M', 'T', 'W', 'R' ,'F', 'Sa' }
local months = {'JA', 'FB', 'MR', 'AP', 'MY', 'JN', 'JL', 'AG', 'SP', 'OC', 'NV', 'DC'}

-- runs when visible
clock.OnUpdate = function(self)
  local weekday, month, day, year = _G.CalendarGetDate()
  local hour, min = _G.GetGameTime()
  if hour > 12 then
    hour = hour - 12
  end
  local posFunc, posF = _G.GetPlayerMapPosition, 100
  local posFormat = "|cFF00FFFF%0.1f %0.1f|r"
  if self:IsMouseOver() then
    posFunc = _G.UnitPosition
    posFormat = "yds |cFFFFFF00%d %d|r"
    posF = 1
  end

  local posX, posY = posFunc('player')
  self.coords:SetFormattedText(posFormat, posX * posF, posY * posF)
  self.time:SetFormattedText("%s |cFF44FFFF%s|r|c88FFFFFF%s|r %d:%02d", weekDays[weekday], day, months[month], hour, min)
end

-- hide/show toggler
clock.OnMouseUp = function(self, button)
  if button == 'RightButton' then
    if self:IsVisible() then
      self:Hide()
    else
      self:Show()
    end
  end
end

-- runs once per login
function clock:OnInitialize()
  print('clock thing')
  self:Show()
end

-- runs once per ui load
clock.OnEnable = function(self)
  self:SetParent(_G.UIParent)
  self:SetScript('OnUpdate', clock.OnUpdate)
  self:Show()
  self.time:SetText('Clock stuff')
end

clock.Open = function(self)
end
clock.Close = function(self)
end