/trunk
local function ShouldShowReminder(reminder) |
local show = false |
if not reminder.data.shown then --if not currently shown |
if reminder.charName and reminder.charName ~= BiM.charName then --if only for a certain char, and not THIS char, then don't show |
return |
end |
local _, m, d, y = CalendarGetDate() |
local curDate = strformat("%d-%d-%d", m, d, y) |
--if show always or haven't shown yet today |
local timeReminders = db.reminders.time |
for i = 1, #timeReminders do |
local reminder = timeReminders[i] |
if reminder.time == GameTime_GetTime(true) then |
if reminder.time == GameTime_GetTime(true) and ShouldShowReminder(reminder) then |
tinsert(sRD, reminder.data) |
BiM.DisplayReminder(reminder.data) |
end |
## Title: Bear in Mind |
## Author: Seerah |
## Notes: An addon to remind you of things. |
## Version: 0.1.1 |
## Version: 0.2 |
## OptionalDeps: Ace3, LibSharedMedia-3.0, AceGUI-3.0-SharedMediaWidgets, LibAdvancedIconSelector-1.0 |
## SavedVariables: BearInMindDB |
## SavedVariablesPerCharacter: BearInMindPCDB |
local zr, er, dr, tr, lr, cr --shortcuts to db.reminders.zone, etc. |
local zre, ere, dre, tre, lre, cre --save which reminder is currently being edited |
local dropdownContents = {} --what to display in the edit dropdown on the current tab |
local prevChar = {} --storing prevChar for tristate toggles for char specific reminders |
BiM.charName = UnitName("player") |
BiM.dayMap = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} |
local sampleData = { |
icon = "Interface\\AddOns\\Bear in Mind\\BiM-icon", |
end, |
order = 4, |
}, |
spacer1 = { |
name = "", |
type = "description", |
width = "full", |
thisChar = { |
name = "Character Specific", |
desc = function() |
return BiM.CharSpecOptionDesc(zr, zre) |
end, |
type = "toggle", |
tristate = true, |
get = function() |
return BiM.CharSpecOptionGet(zr, zre) |
end, |
set = function(_, state) |
return BiM.CharSpecOptionSet(zr, zre, state) |
end, |
order = 5, |
}, |
zone = { |
end, |
order = 7, |
}, |
spacer2 = { |
spacer = { |
name = " \n \n ", --or make a header? |
type = "description", |
width = "full", |
end, |
order = 4, |
}, |
spacer1 = { |
name = "", |
type = "description", |
width = "full", |
thisChar = { |
name = "Character Specific", |
desc = function() |
return BiM.CharSpecOptionDesc(er, ere) |
end, |
type = "toggle", |
tristate = true, |
get = function() |
return BiM.CharSpecOptionGet(er, ere) |
end, |
set = function(_, state) |
return BiM.CharSpecOptionSet(er, ere, state) |
end, |
order = 5, |
}, |
event = { |
end, |
order = 7, |
}, |
spacer2 = { |
spacer = { |
name = " \n \n ", --or make a header? |
type = "description", |
width = "full", |
end, |
order = 4, |
}, |
spacer1 = { |
name = "", |
type = "description", |
width = "full", |
thisChar = { |
name = "Character Specific", |
desc = function() |
return BiM.CharSpecOptionDesc(lr, lre) |
end, |
type = "toggle", |
tristate = true, |
get = function() |
return BiM.CharSpecOptionGet(lr, lre) |
end, |
set = function(_, state) |
return BiM.CharSpecOptionSet(lr, lre, state) |
end, |
order = 5, |
}, |
showAlways = { |
end, |
order = 7, |
}, |
spacer2 = { |
spacer = { |
name = " \n \n ", --or make a header? |
type = "description", |
width = "full", |
end, |
order = 4, |
}, |
spacer1 = { |
name = "", |
type = "description", |
width = "full", |
thisChar = { |
name = "Character Specific", |
desc = function() |
return BiM.CharSpecOptionDesc(dr, dre) |
end, |
type = "toggle", |
tristate = true, |
get = function() |
return BiM.CharSpecOptionGet(dr, dre) |
end, |
set = function(_, state) |
return BiM.CharSpecOptionSet(dr, dre, state) |
end, |
order = 5, |
}, |
day = { |
end, |
order = 7, |
}, |
spacer2 = { |
spacer = { |
name = " \n \n ", --or make a header? |
type = "description", |
width = "full", |
end, |
order = 4, |
}, |
spacer1 = { |
name = "", |
type = "description", |
width = "full", |
thisChar = { |
name = "Character Specific", |
desc = function() |
return BiM.CharSpecOptionDesc(tr, tre) |
end, |
type = "toggle", |
tristate = true, |
get = function() |
return BiM.CharSpecOptionGet(tr, tre) |
end, |
set = function(_, state) |
return BiM.CharSpecOptionSet(tr, tre, state) |
end, |
order = 5, |
}, |
time = { |
end, |
order = 6, |
}, |
spacer2 = { |
spacer = { |
name = " \n \n ", --or make a header? |
type = "description", |
width = "full", |
}, |
} |
function BiM.CharSpecOptionDesc(rtype, rem) |
local current, past |
if rem then |
local r = rtype[rem] |
if r.charName then --if saved for a char |
current = "\n\nThis reminder is currently set to display only for "..r.charName |
else |
current = "\n\nThis reminder is currently set to display for all characters." |
end |
if prevChar[r.name] and prevChar[r.name] ~= r.charName then |
past = "\n\nThis reminder was previously set to display only for "..prevChar[r.name]..". Cycle through the checkbox to return to this setting." |
end |
end |
return string.format("Display this reminder only while playing a certain character.%s%s", current or "", past or "") |
end |
function BiM.CharSpecOptionGet(rtype, rem) |
if rem then |
local r = rtype[rem] |
local name = r.charName |
if prevChar[r.name] == nil then |
if name and name ~= BiM.charName then --if previously set to a different character |
prevChar[r.name] = name --save a backup of the character name |
else |
prevChar[r.name] = false |
end |
end |
if name then |
if name == BiM.charName then --this char |
return true |
else --different char |
return nil --will be grey check |
end |
else |
return false |
end |
else |
return false |
end |
end |
function BiM.CharSpecOptionSet(rtype, rem, state) |
local r = rtype[rem] |
if state then --true |
r.charName = BiM.charName |
elseif state == false then |
r.charName = nil |
else --nil |
r.charName = prevChar[r.name] and prevChar[r.name] or false |
end |
end |
local function OnInitialize() |
BearInMindDB = BearInMindDB or {} |
db = BearInMindDB |
login = {}, |
custom = {}, |
} |
--reset any reminders that are stuck at shown (logging out without dismissing or client crash) |
for rtype, set in pairs(db.reminders) do |
for i = 1, #set do |
set[i].data.shown = false |
end |
end |
LibStub("AceConfig-3.0"):RegisterOptionsTable(addonName, options) |
BiM.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, addonName) |