Quantcast WoWInterface - View Single Post - the _G changes.
Thread: the _G changes.
View Single Post
09-24-10, 10:18 AM   #16
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
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:
  1. local addonName, addon = ...
  2.  
  3. local DB_VERSION = 11
  4.  
  5. local defaultDatabase = nil
  6.  
  7. local POPUP_TEXT = "Set a note for |cffff4488%s|r."
  8. local TARGET_ERROR = "You must target something to add a note."
  9. local NOTE_SET = "Note for |cffff4488%s|r set to \"|cff888888%s|r\"."
  10. local SET = "Set"
  11. local CANCEL = "Cancel"
  12. local NOTE_PREFIX = "|cffff4488Note:|r "
  13. -- Keybinding to output the note to chat
  14. BINDING_HEADER_GRIMUI = "GrimUI"
  15. BINDING_NAME_GTIPNOTES_PRINT = "Print ToolTip Note"
  16.  
  17. function GTipNotes_GetNote(name)
  18.     if not name then return end
  19.     return _G.GTipNotesDB[name]
  20. end
  21.  
  22. local frame = CreateFrame("Frame")
  23. frame:SetScript("OnEvent", function()
  24.     if event == "VARIABLES_LOADED" then
  25.         if not _G.GTipNotesDB then
  26.             _G.GTipNotesDB = defaultDatabase
  27.             _G.GTipNotesDB.VERSION = DB_VERSION
  28.         end
  29.  
  30.         if not _G.GTipNotesDB.VERSION or _G.GTipNotesDB.VERSION < DB_VERSION then
  31.             for k, v in pairs(defaultDatabase) do
  32.                 if not _G.GTipNotesDB[k] then
  33.                     _G.GTipNotesDB[k] = v
  34.                 end
  35.             end
  36.             DEFAULT_CHAT_FRAME:AddMessage("|cffff4488Mob Notes|r database updated to revision " .. tostring(DB_VERSION) .. ".")
  37.             _G.GTipNotesDB.VERSION = DB_VERSION
  38.         end
  39.  
  40.         local orig = GameTooltip:GetScript("OnTooltipSetUnit")
  41.         GameTooltip:SetScript("OnTooltipSetUnit", function(tooltip, ...)
  42.             local name, unitid = tooltip:GetUnit()
  43.             if UnitExists(unitid) and _G.GTipNotesDB[name] then
  44.                 GameTooltip:AddLine(NOTE_PREFIX .. _G.GTipNotesDB[name], 0.5, 0.5, 0.5, 1)
  45.             end
  46.             return orig(tooltip, ...)
  47.         end)
  48.     end
  49. end)
  50.  
  51. frame:RegisterEvent("VARIABLES_LOADED")
  52.  
  53. local function addNoteFromPopup(note)
  54.     if type(note) ~= "string" or note:trim():len() == 0 then note = nil end
  55.     local t = UnitExists("target") and UnitName("target") or nil
  56.     if t then
  57.         _G.GTipNotesDB[t] = note
  58.         DEFAULT_CHAT_FRAME:AddMessage(NOTE_SET:format(t, tostring(note)))
  59.     end
  60. end
  61.  
  62. StaticPopupDialogs["GTipNotes"] = {
  63. button1 = SET,
  64. button2 = CANCEL,
  65. hasEditBox = true,
  66. hideOnEscape = true,
  67. text = POPUP_TEXT,
  68. timeout = 0,
  69. whileDead = true,
  70. EditBoxOnEnterPressed = function(self, data)
  71. local note = self:GetText():trim()
  72. if note == "" then
  73. note = nil
  74. end
  75. GTipNotesDB[data] = note
  76. self:GetParent():Hide()
  77. end,
  78. EditBoxOnEscapePressed = function(self)
  79. self:GetParent():Hide()
  80. end,
  81. OnAccept = function(self, data)
  82. local note = _G[self:GetName() .. 'EditBox']:GetText():trim()
  83. if note == "" then
  84. note = nil
  85. end
  86. GTipNotesDB[data] = note
  87. end
  88.  
  89. }
  90.  
  91. SlashCmdList["GTIPNOTES_SHORTHAND"] = function(note)
  92. if UnitExists('target') then
  93. local name = UnitName('target')
  94. note = note:trim()
  95. if note == "" then
  96. note = GTipNotesDB[name]
  97. end
  98. StaticPopup_Show("GTipNotes", name, nil, name)
  99. if note then
  100. name = StaticPopup_Visible("GTipNotes")
  101. if name then
  102. _G[name .. 'EditBox']:SetText(note)
  103. end
  104. end
  105. else
  106. print(TARGET_ERROR)
  107. end
  108. end
  109. _G.SLASH_GTIPNOTES_SHORTHAND1 = "/gtipnotes"
  110.  
  111.  
  112. end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]