Vrul - okay so remember you had said before i should remove the default db stuff which i did. I wonder if that is where i broke this? I have made all the changes you suggested and still get errors as far as it thinking the db is a nil value certain changes make that happen and certain things break the /commands. Im still really not understanding the use of _G now because almost everything that is broken, not just in the GrimUI has to do with _G. like baggins is borked and it has to do with the _G usage again and i just dont see why?
My entire move frames code is borked to in cata but im not even going there right now lol.
I also noticed something strange with the item coloring on the inspect window, when you inspect 2-3 items will have the boarder, then inspect again and more appear until you inspect like 3 times and they all are there then. Is this because of the inspect throttle stuff? Or some other problem?
The tipnotes looks like this, this is with all changes you have suggested including the one months ago about the default db not being stuffed into the base lua.
lua Code:
local addonName, addon = ...
local DB_VERSION = 11
local defaultDatabase = nil
local POPUP_TEXT = "Set a note for |cffff4488%s|r."
local TARGET_ERROR = "You must target something to add a note."
local NOTE_SET = "Note for |cffff4488%s|r set to \"|cff888888%s|r\"."
local SET = "Set"
local CANCEL = "Cancel"
local NOTE_PREFIX = "|cffff4488Note:|r "
-- Keybinding to output the note to chat
BINDING_HEADER_GRIMUI = "GrimUI"
BINDING_NAME_GTIPNOTES_PRINT = "Print ToolTip Note"
function GTipNotes_GetNote(name)
if not name then return end
return _G.GTipNotesDB[name]
end
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", function()
if event == "VARIABLES_LOADED" then
if not _G.GTipNotesDB then
_G.GTipNotesDB = defaultDatabase
_G.GTipNotesDB.VERSION = DB_VERSION
end
if not _G.GTipNotesDB.VERSION or _G.GTipNotesDB.VERSION < DB_VERSION then
for k, v in pairs(defaultDatabase) do
if not _G.GTipNotesDB[k] then
_G.GTipNotesDB[k] = v
end
end
DEFAULT_CHAT_FRAME:AddMessage("|cffff4488Mob Notes|r database updated to revision " .. tostring(DB_VERSION) .. ".")
_G.GTipNotesDB.VERSION = DB_VERSION
end
local orig = GameTooltip:GetScript("OnTooltipSetUnit")
GameTooltip:SetScript("OnTooltipSetUnit", function(tooltip, ...)
local name, unitid = tooltip:GetUnit()
if UnitExists(unitid) and _G.GTipNotesDB[name] then
GameTooltip:AddLine(NOTE_PREFIX .. _G.GTipNotesDB[name], 0.5, 0.5, 0.5, 1)
end
return orig(tooltip, ...)
end)
end
end)
frame:RegisterEvent("VARIABLES_LOADED")
local function addNoteFromPopup(note)
if type(note) ~= "string" or note:trim():len() == 0 then note = nil end
local t = UnitExists("target") and UnitName("target") or nil
if t then
_G.GTipNotesDB[t] = note
DEFAULT_CHAT_FRAME:AddMessage(NOTE_SET:format(t, tostring(note)))
end
end
StaticPopupDialogs["GTipNotes"] = {
button1 = SET,
button2 = CANCEL,
hasEditBox = true,
hideOnEscape = true,
text = POPUP_TEXT,
timeout = 0,
whileDead = true,
EditBoxOnEnterPressed = function(self, data)
local note = self:GetText():trim()
if note == "" then
note = nil
end
GTipNotesDB[data] = note
self:GetParent():Hide()
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide()
end,
OnAccept = function(self, data)
local note = _G[self:GetName() .. 'EditBox']:GetText():trim()
if note == "" then
note = nil
end
GTipNotesDB[data] = note
end
}
SlashCmdList["GTIPNOTES_SHORTHAND"] = function(note)
if UnitExists('target') then
local name = UnitName('target')
note = note:trim()
if note == "" then
note = GTipNotesDB[name]
end
StaticPopup_Show("GTipNotes", name, nil, name)
if note then
name = StaticPopup_Visible("GTipNotes")
if name then
_G[name .. 'EditBox']:SetText(note)
end
end
else
print(TARGET_ERROR)
end
end
_G.SLASH_GTIPNOTES_SHORTHAND1 = "/gtipnotes"
end