- added a new builtin plugin: Details_YouAreNotPrepared.
- options panel recreated from scretch.
This commit is contained in:
@@ -596,7 +596,6 @@ local siege_of_orgrimmar = {
|
||||
[6] = {
|
||||
boss = "Iron Juggernaut",
|
||||
portrait = [[Interface\EncounterJournal\UI-EJ-BOSS-Iron Juggernaut]],
|
||||
|
||||
combat_end = {1, 71466},
|
||||
|
||||
spell_mechanics = {
|
||||
@@ -1030,7 +1029,7 @@ local siege_of_orgrimmar = {
|
||||
[11] = {
|
||||
boss = "Thok the Bloodthirsty",
|
||||
portrait = [[Interface\EncounterJournal\UI-EJ-BOSS-Thok the Bloodthirsty]],
|
||||
|
||||
|
||||
combat_end = {1, 71529},
|
||||
|
||||
spell_mechanics = {
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
local AceLocale = LibStub ("AceLocale-3.0")
|
||||
local Loc = AceLocale:GetLocale ("Details_YouAreNotPrepared")
|
||||
|
||||
--> create the plugin object
|
||||
local YouAreNotPrepared = _detalhes:NewPluginObject ("Details_YouAreNotPrepared", DETAILSPLUGIN_ALWAYSENABLED)
|
||||
tinsert (UISpecialFrames, "Details_YouAreNotPrepared")
|
||||
--> main frame (shortcut)
|
||||
local YouAreNotPreparedFrame = YouAreNotPrepared.Frame
|
||||
|
||||
local debugmode = false
|
||||
|
||||
local function CreatePluginFrames()
|
||||
|
||||
--> catch Details! main object
|
||||
local _detalhes = _G._detalhes
|
||||
local DetailsFrameWork = _detalhes.gump
|
||||
|
||||
local GameCooltip = GameCooltip
|
||||
local _GetSpellInfo = _detalhes.getspellinfo
|
||||
|
||||
YouAreNotPrepared.deaths_table = {}
|
||||
YouAreNotPrepared.last_death_combat_id = -1
|
||||
|
||||
---------- event parser -------------
|
||||
function YouAreNotPrepared:OnDetailsEvent (event, ...)
|
||||
if (event == "HIDE") then --> plugin hidded, disabled
|
||||
self.open = false
|
||||
|
||||
elseif (event == "SHOW") then --> plugin hidded, disabled
|
||||
self.open = true
|
||||
|
||||
elseif (event == "COMBAT_PLAYER_ENTER") then --> combat started
|
||||
|
||||
elseif (event == "COMBAT_PLAYER_LEAVE") then --> combat ended
|
||||
YouAreNotPrepared:EndCombat()
|
||||
|
||||
elseif (event == "DETAILS_DATA_RESET") then
|
||||
table.wipe (YouAreNotPrepared.deaths_table)
|
||||
YouAreNotPrepared:Clear()
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
---------- build frames -------------
|
||||
|
||||
local BAR_HEIGHT = 13
|
||||
local BAR_AMOUNT = 10
|
||||
local BUTTON_AMOUNT = 6
|
||||
|
||||
function YouAreNotPrepared:Clear()
|
||||
YouAreNotPrepared.deaths_table = {}
|
||||
_detalhes_databaseYANP = YouAreNotPrepared.deaths_table
|
||||
|
||||
for i = 1, BUTTON_AMOUNT do
|
||||
local button = YouAreNotPrepared.buttons [i]
|
||||
button:Disable()
|
||||
button.widget.b_texture:SetDesaturated (true)
|
||||
button.lefttext.text = "#" .. i
|
||||
end
|
||||
|
||||
for bar_index = 1, BAR_AMOUNT do
|
||||
YouAreNotPrepared.container_bars.bars [bar_index]:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
--main frame
|
||||
YouAreNotPreparedFrame:SetSize (424, 223)
|
||||
YouAreNotPreparedFrame:SetPoint ("center", UIParent, "center")
|
||||
YouAreNotPreparedFrame:EnableMouse (true)
|
||||
YouAreNotPreparedFrame:SetResizable (false)
|
||||
YouAreNotPreparedFrame:SetMovable (true)
|
||||
|
||||
YouAreNotPreparedFrame:SetScript ("OnMouseUp", function (self, button)
|
||||
if (button == "RightButton") then
|
||||
YouAreNotPreparedFrame:Hide()
|
||||
else
|
||||
if (YouAreNotPreparedFrame.isMoving) then
|
||||
YouAreNotPreparedFrame:StopMovingOrSizing()
|
||||
YouAreNotPreparedFrame.isMoving = false
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
YouAreNotPreparedFrame:SetScript ("OnMouseDown", function (self, button)
|
||||
if (button == "LeftButton") then
|
||||
if (not YouAreNotPreparedFrame.isMoving) then
|
||||
YouAreNotPreparedFrame:StartMoving()
|
||||
YouAreNotPreparedFrame.isMoving = true
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--close button
|
||||
local c = CreateFrame ("Button", nil, YouAreNotPreparedFrame, "UIPanelCloseButton")
|
||||
c:SetWidth (32)
|
||||
c:SetHeight (32)
|
||||
c:SetPoint ("TOPRIGHT", YouAreNotPreparedFrame, "TOPRIGHT", 1, -15)
|
||||
c:SetFrameLevel (YouAreNotPreparedFrame:GetFrameLevel()+1)
|
||||
|
||||
--background image
|
||||
local b = DetailsFrameWork:NewImage (YouAreNotPreparedFrame, nil, "$parentBackground", nil, 512, 256, [[Interface\AddOns\Details_YouAreNotPrepared\background]])
|
||||
b:SetPoint ("topleft", YouAreNotPreparedFrame, "topleft")
|
||||
|
||||
--title
|
||||
local t = DetailsFrameWork:NewLabel (YouAreNotPreparedFrame, nil, "$parentTitle", nil, Loc ["STRING_PLUGIN_NAME"], "GameFontHighlightLeft", 12, {227/255, 186/255, 4/255})
|
||||
|
||||
t:SetPoint ("top", YouAreNotPreparedFrame, "top", 20, -26)
|
||||
t:SetPoint ("center", YouAreNotPreparedFrame, "center", 0, 0)
|
||||
|
||||
--bar container
|
||||
local container_bars = CreateFrame ("frame", "Details_YouAreNotPrepared_FauxScroll_Box", YouAreNotPreparedFrame)
|
||||
container_bars:SetPoint ("topleft", YouAreNotPreparedFrame, "topleft", 23, -80)
|
||||
container_bars:SetSize (252, 137)
|
||||
container_bars:SetBackdrop ({bgFile = "Interface\\AddOns\\Details\\images\\background", tile = true, tileSize = 16,
|
||||
insets = {left = 0, right = 0, top = 0, bottom = 0}})
|
||||
container_bars:SetBackdropColor (.1, .1, .1, .2)
|
||||
YouAreNotPrepared.container_bars = container_bars
|
||||
|
||||
container_bars.bars = {}
|
||||
|
||||
local MouseUpCloseHook = function (_, button)
|
||||
if (button == "RightButton") then
|
||||
YouAreNotPreparedFrame:Hide()
|
||||
return true --> interrupt
|
||||
end
|
||||
end
|
||||
|
||||
function container_bars:CreateChild()
|
||||
|
||||
local bar_number = #self.bars + 1
|
||||
|
||||
local bar = DetailsFrameWork:NewPanel (self, YouAreNotPreparedFrame, "$parentBar" .. bar_number, nil, 250, BAR_HEIGHT)
|
||||
bar:SetPoint ("topleft", self, "topleft", 1, bar_number*13*-1+9)
|
||||
bar:SetHook ("OnMouseUp", MouseUpCloseHook)
|
||||
bar.locked = false
|
||||
bar.backdrop = nil
|
||||
bar.hide = true
|
||||
|
||||
local statusbar = DetailsFrameWork:NewBar (bar, nil, "$parentStatusbar", "statusbar", 250, BAR_HEIGHT)
|
||||
statusbar:SetPoint ("left", bar, "left")
|
||||
statusbar.fontsize = 9
|
||||
statusbar.textleft:SetHeight (16)
|
||||
YouAreNotPrepared:SetFontFace (statusbar.textleft, "GameFontHighlightSmall")
|
||||
YouAreNotPrepared:SetFontFace (statusbar.textleft, "GameFontNormal")
|
||||
|
||||
container_bars.bars [bar_number] = bar
|
||||
|
||||
return bar
|
||||
end
|
||||
|
||||
function container_bars:UpdateChild (bar_number, data, time_of_death, max_health)
|
||||
|
||||
local spellname, _, icon = _GetSpellInfo (data[2])
|
||||
local bar = container_bars.bars [bar_number]
|
||||
|
||||
if (spellname) then
|
||||
|
||||
local hp = math.floor (data[5] / max_health * 100)
|
||||
if (hp > 100) then
|
||||
hp = 100
|
||||
end
|
||||
|
||||
if (data[1]) then --> damage
|
||||
if (data[3] and type (data [1]) == "boolean") then --> is a real damage, not a battle ress and its not a last cooldown line
|
||||
bar.statusbar.textleft:SetText (string.format ("%.1f", data [4] - time_of_death) .. "s " .. spellname .. " (" .. data [6] .. ")")
|
||||
bar.statusbar.textright:SetText ("-" .. YouAreNotPrepared:ToK (data [3]) .. " (" .. hp .. "%)")
|
||||
bar.statusbar.icon:SetTexture (icon)
|
||||
bar.statusbar.color = "red"
|
||||
bar.statusbar.background:SetVertexColor (1, 0, 0, .2)
|
||||
bar.statusbar.textleft:SetWidth (250 - bar.statusbar.textright:GetStringWidth() - 20)
|
||||
bar.statusbar.value = hp
|
||||
return true
|
||||
end
|
||||
else
|
||||
bar.statusbar.textleft:SetText (string.format ("%.1f", data [4] - time_of_death) .. "s " .. spellname .. " (" .. data [6] .. ")")
|
||||
bar.statusbar.textright:SetText ("+" .. YouAreNotPrepared:ToK (data [3]) .. " (" .. hp .. "%)")
|
||||
bar.statusbar.icon:SetTexture (icon)
|
||||
bar.statusbar.color = "green"
|
||||
bar.statusbar.background:SetVertexColor (0, 1, 0, .2)
|
||||
bar.statusbar.textleft:SetWidth (250 - bar.statusbar.textright:GetStringWidth() - 20)
|
||||
bar.statusbar.value = hp
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--create 10 childs (bars)
|
||||
for i = 1, 10 do
|
||||
container_bars:CreateChild()
|
||||
end
|
||||
|
||||
--create scrollbar
|
||||
|
||||
local refresh_function = function (self)
|
||||
local offset = FauxScrollFrame_GetOffset (self)
|
||||
|
||||
for bar_index = 1, BAR_AMOUNT do
|
||||
local data = YouAreNotPrepared.s_table[4] [bar_index + offset] --bar_index + offset ---------- preciso pegar os dados de uma pool
|
||||
|
||||
if (data) then
|
||||
local successful = container_bars:UpdateChild (bar_index, data, YouAreNotPrepared.s_table[6], YouAreNotPrepared.s_table[5]) --index, death table, clock time of death, max health
|
||||
if (not successful) then
|
||||
container_bars.bars [bar_index]:Hide()
|
||||
else
|
||||
container_bars.bars [bar_index]:Show()
|
||||
end
|
||||
else
|
||||
container_bars.bars [bar_index]:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local scrollbar = CreateFrame ("scrollframe", "Details_YouAreNotPrepared_FauxScroll", container_bars, "FauxScrollFrameTemplate")
|
||||
scrollbar:SetScript ("OnVerticalScroll", function (self, offset) FauxScrollFrame_OnVerticalScroll (self, offset, BAR_HEIGHT, refresh_function) end)
|
||||
scrollbar:SetPoint ("topleft", YouAreNotPreparedFrame, "topleft", 23, -80)
|
||||
scrollbar:SetSize (250, 138)
|
||||
|
||||
container_bars:EnableMouse (true)
|
||||
|
||||
--choose death menu
|
||||
|
||||
YouAreNotPrepared.buttons = {}
|
||||
|
||||
local select_death = function (selected)
|
||||
YouAreNotPrepared.s_table = YouAreNotPrepared.deaths_table [selected]
|
||||
if (not YouAreNotPrepared.s_table) then
|
||||
return
|
||||
end
|
||||
FauxScrollFrame_Update (scrollbar, #YouAreNotPrepared.s_table[4], BAR_AMOUNT, BAR_HEIGHT)
|
||||
refresh_function (scrollbar)
|
||||
end
|
||||
YouAreNotPrepared.select_death = select_death
|
||||
|
||||
function YouAreNotPrepared:CreateDeathButton()
|
||||
local button_number = #self.buttons + 1
|
||||
|
||||
local button = DetailsFrameWork:NewButton (YouAreNotPreparedFrame, _, "$parentButton" .. button_number, nil, 113, 20, select_death, button_number)
|
||||
button:SetPoint ("topleft", YouAreNotPreparedFrame, "topleft", 300, -59 + (button_number*23*-1))
|
||||
button:Disable()
|
||||
|
||||
local b_texture = button:CreateTexture (nil, "artwork")
|
||||
b_texture:SetTexture ([[Interface\AddOns\Details\images\icons]])
|
||||
b_texture:SetTexCoord (0.297851, 0.444335, 0.004882, 0.040039) --152 228 2 21 0.0009765625
|
||||
b_texture:SetPoint ("topleft", button.widget, "topleft")
|
||||
b_texture:SetSize (113, 20)
|
||||
b_texture:SetDesaturated (true)
|
||||
button.widget.b_texture = b_texture
|
||||
|
||||
local icon = DetailsFrameWork:NewImage (button, _, "$parentIcon", "icon", 20, 20)
|
||||
icon:SetTexCoord (0, 0.4921875, 0, 0.4921875) --0.0078125
|
||||
icon:SetPoint ("left", button, "left", 1, 0)
|
||||
icon.texture = [[Interface\WorldStateFrame\SkullBones]]
|
||||
icon:SetBlendMode ("ADD")
|
||||
icon:SetAlpha (.5)
|
||||
|
||||
button:SetHook ("OnMouseDown", function (self, button)
|
||||
self.b_texture:SetPoint ("topleft", self, "topleft", 1, -1)
|
||||
--self.MyObject.lefttext:SetPoint ("left", self.MyObject.icon, "right", 2, 0)
|
||||
self.MyObject.icon:SetPoint ("left", self, "left", 2, -1)
|
||||
end)
|
||||
button:SetHook ("OnMouseUp", function (self, button)
|
||||
self.b_texture:SetPoint ("topleft", self, "topleft")
|
||||
--self.MyObject.lefttext:SetPoint ("left", self.MyObject.icon, "right", 2, 0)
|
||||
self.MyObject.icon:SetPoint ("left", self, "left", 1, 0)
|
||||
end)
|
||||
button:SetHook ("OnEnter", function (self, button)
|
||||
self.b_texture:SetBlendMode ("ADD")
|
||||
end)
|
||||
button:SetHook ("OnLeave", function (self, button)
|
||||
self.b_texture:SetBlendMode ("BLEND")
|
||||
end)
|
||||
|
||||
local lefttext = DetailsFrameWork:NewLabel (button, nil, "$parentLeftText", "lefttext", "", "GameFontHighlightSmall", 9)
|
||||
lefttext:SetPoint ("left", icon, "right", 2)
|
||||
lefttext.width = 80
|
||||
lefttext.height = 13
|
||||
|
||||
local righttext = DetailsFrameWork:NewLabel (button, nil, "$parentRightText", "righttext", " ", "GameFontHighlightSmall", 9)
|
||||
righttext:SetPoint ("right", button, "right", -1)
|
||||
|
||||
YouAreNotPrepared.buttons [button_number] = button
|
||||
|
||||
return bar
|
||||
end
|
||||
|
||||
for i = 1, 6 do
|
||||
YouAreNotPrepared:CreateDeathButton()
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:AddDeath (t)
|
||||
|
||||
--> t = [1] = enemy name [2] = time of death [3] = last cooldown [4] = death table [5] = max health [6] = clock time of the death
|
||||
|
||||
--add and remove
|
||||
table.insert (YouAreNotPrepared.deaths_table, 1, t)
|
||||
table.remove (YouAreNotPrepared.deaths_table, 7)
|
||||
|
||||
--update buttons
|
||||
for i = 1, 6 do
|
||||
local button = YouAreNotPrepared.buttons [i]
|
||||
local death_table = YouAreNotPrepared.deaths_table [i]
|
||||
if (death_table) then
|
||||
button:Enable()
|
||||
button.widget.b_texture:SetDesaturated (false)
|
||||
button.lefttext.text = "#" .. i .. " " .. death_table [1]
|
||||
else
|
||||
button:Disable()
|
||||
button.widget.b_texture:SetDesaturated (true)
|
||||
button.lefttext.text = "#" .. i
|
||||
end
|
||||
end
|
||||
|
||||
YouAreNotPrepared:DeathWarning()
|
||||
|
||||
_detalhes_databaseYANP = YouAreNotPrepared.deaths_table
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:UpdateButtons()
|
||||
for i = 1, 6 do
|
||||
local button = YouAreNotPrepared.buttons [i]
|
||||
local death_table = YouAreNotPrepared.deaths_table [i]
|
||||
if (death_table) then
|
||||
button:Enable()
|
||||
button.widget.b_texture:SetDesaturated (false)
|
||||
button.lefttext.text = "#" .. i .. " " .. death_table [1]
|
||||
else
|
||||
button:Disable()
|
||||
button.widget.b_texture:SetDesaturated (true)
|
||||
button.lefttext.text = "#" .. i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:ShowMe() --> used for debug
|
||||
YouAreNotPreparedFrame:Show()
|
||||
|
||||
YouAreNotPrepared:UpdateButtons()
|
||||
|
||||
_detalhes:InstanceAlert (Loc ["STRING_PLUGIN_ALERT"], {[[Interface\ICONS\Achievement_Boss_Illidan]], 14, 14, false, 0.8984375, 0.0546875, 0.0546875, 0.8984375}, 20, {YouAreNotPrepared.ShowMeFromInstanceAlert})
|
||||
end
|
||||
--YouAreNotPrepared:ScheduleTimer (YouAreNotPrepared.ShowMe, 3)
|
||||
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:ShowMeFromInstanceAlert()
|
||||
YouAreNotPreparedFrame:Show()
|
||||
YouAreNotPrepared.select_death (1)
|
||||
YouAreNotPrepared:UpdateButtons()
|
||||
_detalhes:InstanceAlert (false)
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:DeathWarning()
|
||||
_detalhes:InstanceAlert (Loc ["STRING_PLUGIN_ALERT"], {[[Interface\ICONS\Achievement_Boss_Illidan]], 14, 14, false, 0.8984375, 0.0546875, 0.0546875, 0.8984375} , 15, {YouAreNotPrepared.ShowMeFromInstanceAlert})
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:EndCombat()
|
||||
if (YouAreNotPrepared.last_death_combat_id == YouAreNotPrepared.combat_id) then
|
||||
_detalhes:InstanceAlert (Loc ["STRING_PLUGIN_ALERT"], {[[Interface\ICONS\Achievement_Boss_Illidan]], 14, 14, false, 0.8984375, 0.0546875, 0.0546875, 0.8984375} , 25, {YouAreNotPrepared.ShowMeFromInstanceAlert})
|
||||
end
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:OnDeath (token, time, who_serial, who_name, who_flags, alvo_serial, alvo_name, alvo_flags, death_table, last_cooldown, time_of_death, max_health)
|
||||
|
||||
if (alvo_name == YouAreNotPrepared.playername) then
|
||||
|
||||
--[[ debug mode
|
||||
if (not combat.is_boss) then
|
||||
return YouAreNotPrepared:AddDeath ({combat.enemy or "Unknown", time_of_death, last_cooldown, death_table, max_health, time})
|
||||
else
|
||||
return YouAreNotPrepared:AddDeath ({combat.is_boss.name or combat.enemy or "Unknown", time_of_death, last_cooldown, death_table, max_health, time})
|
||||
end
|
||||
--]]
|
||||
|
||||
local combat = YouAreNotPrepared:GetCombat ("current")
|
||||
|
||||
if (combat.is_boss) then --> encounter or pvp
|
||||
YouAreNotPrepared.last_death_combat_id = YouAreNotPrepared.combat_id
|
||||
return YouAreNotPrepared:AddDeath ({combat.is_boss.name or combat.enemy or "Unknown", time_of_death, last_cooldown, death_table, max_health, time})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function YouAreNotPrepared:OnEvent (_, event, ...)
|
||||
|
||||
if (event == "ADDON_LOADED") then
|
||||
local AddonName = select (1, ...)
|
||||
if (AddonName == "Details_YouAreNotPrepared") then
|
||||
|
||||
if (_G._detalhes) then
|
||||
|
||||
--> create widgets
|
||||
CreatePluginFrames()
|
||||
|
||||
--> core version required
|
||||
local MINIMAL_DETAILS_VERSION_REQUIRED = 12
|
||||
|
||||
--> install
|
||||
local install = _G._detalhes:InstallPlugin ("TOOLBAR", Loc ["STRING_PLUGIN_NAME"], "placeholder string", YouAreNotPrepared, "DETAILS_PLUGIN_YANP", MINIMAL_DETAILS_VERSION_REQUIRED)
|
||||
if (type (install) == "table" and install.error) then
|
||||
print (install.error)
|
||||
end
|
||||
|
||||
--> register needed events
|
||||
_G._detalhes:RegisterEvent (YouAreNotPrepared, "DETAILS_DATA_RESET")
|
||||
_G._detalhes:RegisterEvent (YouAreNotPrepared, "COMBAT_PLAYER_LEAVE")
|
||||
--> register needed hooks
|
||||
_G._detalhes:InstallHook (DETAILS_HOOK_DEATH, YouAreNotPrepared.OnDeath)
|
||||
|
||||
--> retrive saved data
|
||||
YouAreNotPrepared.deaths_table = _detalhes_databaseYANP or {}
|
||||
|
||||
--> install slash command
|
||||
SLASH_Details_YouAreNotPrepared1 = "/yanp"
|
||||
function SlashCmdList.Details_YouAreNotPrepared (msg, editbox)
|
||||
YouAreNotPrepared:ShowMeFromInstanceAlert()
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
## Interface: 50400
|
||||
## Title: Details You Are Not Prepared (plugin)
|
||||
## Notes: Plugin for Details
|
||||
## RequiredDeps: Details
|
||||
## SavedVariablesPerCharacter: _detalhes_databaseYANP
|
||||
## OptionalDeps: Ace3
|
||||
|
||||
#@no-lib-strip@
|
||||
embeds.xml
|
||||
#@end-no-lib-strip@
|
||||
|
||||
enUS.lua
|
||||
ptBR.lua
|
||||
Details_YouAreNotPrepared.lua
|
||||
@@ -0,0 +1,137 @@
|
||||
--- **AceLocale-3.0** manages localization in addons, allowing for multiple locale to be registered with fallback to the base locale for untranslated strings.
|
||||
-- @class file
|
||||
-- @name AceLocale-3.0
|
||||
-- @release $Id: AceLocale-3.0.lua 1035 2011-07-09 03:20:13Z kaelten $
|
||||
local MAJOR,MINOR = "AceLocale-3.0", 6
|
||||
|
||||
local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
||||
|
||||
if not AceLocale then return end -- no upgrade needed
|
||||
|
||||
-- Lua APIs
|
||||
local assert, tostring, error = assert, tostring, error
|
||||
local getmetatable, setmetatable, rawset, rawget = getmetatable, setmetatable, rawset, rawget
|
||||
|
||||
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
|
||||
-- List them here for Mikk's FindGlobals script
|
||||
-- GLOBALS: GAME_LOCALE, geterrorhandler
|
||||
|
||||
local gameLocale = GetLocale()
|
||||
if gameLocale == "enGB" then
|
||||
gameLocale = "enUS"
|
||||
end
|
||||
|
||||
AceLocale.apps = AceLocale.apps or {} -- array of ["AppName"]=localetableref
|
||||
AceLocale.appnames = AceLocale.appnames or {} -- array of [localetableref]="AppName"
|
||||
|
||||
-- This metatable is used on all tables returned from GetLocale
|
||||
local readmeta = {
|
||||
__index = function(self, key) -- requesting totally unknown entries: fire off a nonbreaking error and return key
|
||||
rawset(self, key, key) -- only need to see the warning once, really
|
||||
geterrorhandler()(MAJOR..": "..tostring(AceLocale.appnames[self])..": Missing entry for '"..tostring(key).."'")
|
||||
return key
|
||||
end
|
||||
}
|
||||
|
||||
-- This metatable is used on all tables returned from GetLocale if the silent flag is true, it does not issue a warning on unknown keys
|
||||
local readmetasilent = {
|
||||
__index = function(self, key) -- requesting totally unknown entries: return key
|
||||
rawset(self, key, key) -- only need to invoke this function once
|
||||
return key
|
||||
end
|
||||
}
|
||||
|
||||
-- Remember the locale table being registered right now (it gets set by :NewLocale())
|
||||
-- NOTE: Do never try to register 2 locale tables at once and mix their definition.
|
||||
local registering
|
||||
|
||||
-- local assert false function
|
||||
local assertfalse = function() assert(false) end
|
||||
|
||||
-- This metatable proxy is used when registering nondefault locales
|
||||
local writeproxy = setmetatable({}, {
|
||||
__newindex = function(self, key, value)
|
||||
rawset(registering, key, value == true and key or value) -- assigning values: replace 'true' with key string
|
||||
end,
|
||||
__index = assertfalse
|
||||
})
|
||||
|
||||
-- This metatable proxy is used when registering the default locale.
|
||||
-- It refuses to overwrite existing values
|
||||
-- Reason 1: Allows loading locales in any order
|
||||
-- Reason 2: If 2 modules have the same string, but only the first one to be
|
||||
-- loaded has a translation for the current locale, the translation
|
||||
-- doesn't get overwritten.
|
||||
--
|
||||
local writedefaultproxy = setmetatable({}, {
|
||||
__newindex = function(self, key, value)
|
||||
if not rawget(registering, key) then
|
||||
rawset(registering, key, value == true and key or value)
|
||||
end
|
||||
end,
|
||||
__index = assertfalse
|
||||
})
|
||||
|
||||
--- Register a new locale (or extend an existing one) for the specified application.
|
||||
-- :NewLocale will return a table you can fill your locale into, or nil if the locale isn't needed for the players
|
||||
-- game locale.
|
||||
-- @paramsig application, locale[, isDefault[, silent]]
|
||||
-- @param application Unique name of addon / module
|
||||
-- @param locale Name of the locale to register, e.g. "enUS", "deDE", etc.
|
||||
-- @param isDefault If this is the default locale being registered (your addon is written in this language, generally enUS)
|
||||
-- @param silent If true, the locale will not issue warnings for missing keys. Must be set on the first locale registered. If set to "raw", nils will be returned for unknown keys (no metatable used).
|
||||
-- @usage
|
||||
-- -- enUS.lua
|
||||
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "enUS", true)
|
||||
-- L["string1"] = true
|
||||
--
|
||||
-- -- deDE.lua
|
||||
-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "deDE")
|
||||
-- if not L then return end
|
||||
-- L["string1"] = "Zeichenkette1"
|
||||
-- @return Locale Table to add localizations to, or nil if the current locale is not required.
|
||||
function AceLocale:NewLocale(application, locale, isDefault, silent)
|
||||
|
||||
-- GAME_LOCALE allows translators to test translations of addons without having that wow client installed
|
||||
local gameLocale = GAME_LOCALE or gameLocale
|
||||
|
||||
local app = AceLocale.apps[application]
|
||||
|
||||
if silent and app and getmetatable(app) ~= readmetasilent then
|
||||
geterrorhandler()("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' must be specified for the first locale registered")
|
||||
end
|
||||
|
||||
if not app then
|
||||
if silent=="raw" then
|
||||
app = {}
|
||||
else
|
||||
app = setmetatable({}, silent and readmetasilent or readmeta)
|
||||
end
|
||||
AceLocale.apps[application] = app
|
||||
AceLocale.appnames[app] = application
|
||||
end
|
||||
|
||||
if locale ~= gameLocale and not isDefault then
|
||||
return -- nop, we don't need these translations
|
||||
end
|
||||
|
||||
registering = app -- remember globally for writeproxy and writedefaultproxy
|
||||
|
||||
if isDefault then
|
||||
return writedefaultproxy
|
||||
end
|
||||
|
||||
return writeproxy
|
||||
end
|
||||
|
||||
--- Returns localizations for the current locale (or default locale if translations are missing).
|
||||
-- Errors if nothing is registered (spank developer, not just a missing translation)
|
||||
-- @param application Unique name of addon / module
|
||||
-- @param silent If true, the locale is optional, silently return nil if it's not found (defaults to false, optional)
|
||||
-- @return The locale table for the current language.
|
||||
function AceLocale:GetLocale(application, silent)
|
||||
if not silent and not AceLocale.apps[application] then
|
||||
error("Usage: GetLocale(application[, silent]): 'application' - No locales registered for '"..tostring(application).."'", 2)
|
||||
end
|
||||
return AceLocale.apps[application]
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
<Script file="AceLocale-3.0.lua"/>
|
||||
</Ui>
|
||||
@@ -0,0 +1,51 @@
|
||||
-- $Id: LibStub.lua 76 2007-09-03 01:50:17Z mikk $
|
||||
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
|
||||
-- LibStub is hereby placed in the Public Domain
|
||||
-- Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
|
||||
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
|
||||
local LibStub = _G[LIBSTUB_MAJOR]
|
||||
|
||||
-- Check to see is this version of the stub is obsolete
|
||||
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
|
||||
LibStub = LibStub or {libs = {}, minors = {} }
|
||||
_G[LIBSTUB_MAJOR] = LibStub
|
||||
LibStub.minor = LIBSTUB_MINOR
|
||||
|
||||
-- LibStub:NewLibrary(major, minor)
|
||||
-- major (string) - the major version of the library
|
||||
-- minor (string or number ) - the minor version of the library
|
||||
--
|
||||
-- returns nil if a newer or same version of the lib is already present
|
||||
-- returns empty library object or old library object if upgrade is needed
|
||||
function LibStub:NewLibrary(major, minor)
|
||||
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
|
||||
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
|
||||
|
||||
local oldminor = self.minors[major]
|
||||
if oldminor and oldminor >= minor then return nil end
|
||||
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
|
||||
return self.libs[major], oldminor
|
||||
end
|
||||
|
||||
-- LibStub:GetLibrary(major, [silent])
|
||||
-- major (string) - the major version of the library
|
||||
-- silent (boolean) - if true, library is optional, silently return nil if its not found
|
||||
--
|
||||
-- throws an error if the library can not be found (except silent is set)
|
||||
-- returns the library object if found
|
||||
function LibStub:GetLibrary(major, silent)
|
||||
if not self.libs[major] and not silent then
|
||||
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
|
||||
end
|
||||
return self.libs[major], self.minors[major]
|
||||
end
|
||||
|
||||
-- LibStub:IterateLibraries()
|
||||
--
|
||||
-- Returns an iterator for the currently registered libraries
|
||||
function LibStub:IterateLibraries()
|
||||
return pairs(self.libs)
|
||||
end
|
||||
|
||||
setmetatable(LibStub, { __call = LibStub.GetLibrary })
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
## Interface: 40200
|
||||
## Title: Lib: LibStub
|
||||
## Notes: Universal Library Stub
|
||||
## Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel
|
||||
## X-Website: http://www.wowace.com/addons/libstub/
|
||||
## X-Category: Library
|
||||
## X-License: Public Domain
|
||||
## X-Curse-Packaged-Version: r95
|
||||
## X-Curse-Project-Name: LibStub
|
||||
## X-Curse-Project-ID: libstub
|
||||
## X-Curse-Repository-ID: wow/libstub/mainline
|
||||
|
||||
LibStub.lua
|
||||
@@ -0,0 +1,41 @@
|
||||
debugstack = debug.traceback
|
||||
strmatch = string.match
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
local lib, oldMinor = LibStub:NewLibrary("Pants", 1) -- make a new thingy
|
||||
assert(lib) -- should return the library table
|
||||
assert(not oldMinor) -- should not return the old minor, since it didn't exist
|
||||
|
||||
-- the following is to create data and then be able to check if the same data exists after the fact
|
||||
function lib:MyMethod()
|
||||
end
|
||||
local MyMethod = lib.MyMethod
|
||||
lib.MyTable = {}
|
||||
local MyTable = lib.MyTable
|
||||
|
||||
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 1) -- try to register a library with the same version, should silently fail
|
||||
assert(not newLib) -- should not return since out of date
|
||||
|
||||
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 0) -- try to register a library with a previous, should silently fail
|
||||
assert(not newLib) -- should not return since out of date
|
||||
|
||||
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 2) -- register a new version
|
||||
assert(newLib) -- library table
|
||||
assert(rawequal(newLib, lib)) -- should be the same reference as the previous
|
||||
assert(newOldMinor == 1) -- should return the minor version of the previous version
|
||||
|
||||
assert(rawequal(lib.MyMethod, MyMethod)) -- verify that values were saved
|
||||
assert(rawequal(lib.MyTable, MyTable)) -- verify that values were saved
|
||||
|
||||
local newLib, newOldMinor = LibStub:NewLibrary("Pants", "Blah 3 Blah") -- register a new version with a string minor version (instead of a number)
|
||||
assert(newLib) -- library table
|
||||
assert(newOldMinor == 2) -- previous version was 2
|
||||
|
||||
local newLib, newOldMinor = LibStub:NewLibrary("Pants", "Blah 4 and please ignore 15 Blah") -- register a new version with a string minor version (instead of a number)
|
||||
assert(newLib)
|
||||
assert(newOldMinor == 3) -- previous version was 3 (even though it gave a string)
|
||||
|
||||
local newLib, newOldMinor = LibStub:NewLibrary("Pants", 5) -- register a new library, using a normal number instead of a string
|
||||
assert(newLib)
|
||||
assert(newOldMinor == 4) -- previous version was 4 (even though it gave a string)
|
||||
@@ -0,0 +1,27 @@
|
||||
debugstack = debug.traceback
|
||||
strmatch = string.match
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
for major, library in LibStub:IterateLibraries() do
|
||||
-- check that MyLib doesn't exist yet, by iterating through all the libraries
|
||||
assert(major ~= "MyLib")
|
||||
end
|
||||
|
||||
assert(not LibStub:GetLibrary("MyLib", true)) -- check that MyLib doesn't exist yet by direct checking
|
||||
assert(not pcall(LibStub.GetLibrary, LibStub, "MyLib")) -- don't silently fail, thus it should raise an error.
|
||||
local lib = LibStub:NewLibrary("MyLib", 1) -- create the lib
|
||||
assert(lib) -- check it exists
|
||||
assert(rawequal(LibStub:GetLibrary("MyLib"), lib)) -- verify that :GetLibrary("MyLib") properly equals the lib reference
|
||||
|
||||
assert(LibStub:NewLibrary("MyLib", 2)) -- create a new version
|
||||
|
||||
local count=0
|
||||
for major, library in LibStub:IterateLibraries() do
|
||||
-- check that MyLib exists somewhere in the libraries, by iterating through all the libraries
|
||||
if major == "MyLib" then -- we found it!
|
||||
count = count +1
|
||||
assert(rawequal(library, lib)) -- verify that the references are equal
|
||||
end
|
||||
end
|
||||
assert(count == 1) -- verify that we actually found it, and only once
|
||||
@@ -0,0 +1,14 @@
|
||||
debugstack = debug.traceback
|
||||
strmatch = string.match
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
local proxy = newproxy() -- non-string
|
||||
|
||||
assert(not pcall(LibStub.NewLibrary, LibStub, proxy, 1)) -- should error, proxy is not a string, it's userdata
|
||||
local success, ret = pcall(LibStub.GetLibrary, proxy, true)
|
||||
assert(not success or not ret) -- either error because proxy is not a string or because it's not actually registered.
|
||||
|
||||
assert(not pcall(LibStub.NewLibrary, LibStub, "Something", "No number in here")) -- should error, minor has no string in it.
|
||||
|
||||
assert(not LibStub:GetLibrary("Something", true)) -- shouldn't've created it from the above statement
|
||||
@@ -0,0 +1,41 @@
|
||||
debugstack = debug.traceback
|
||||
strmatch = string.match
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
|
||||
-- Pretend like loaded libstub is old and doesn't have :IterateLibraries
|
||||
assert(LibStub.minor)
|
||||
LibStub.minor = LibStub.minor - 0.0001
|
||||
LibStub.IterateLibraries = nil
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
assert(type(LibStub.IterateLibraries)=="function")
|
||||
|
||||
|
||||
-- Now pretend that we're the same version -- :IterateLibraries should NOT be re-created
|
||||
LibStub.IterateLibraries = 123
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
assert(LibStub.IterateLibraries == 123)
|
||||
|
||||
|
||||
-- Now pretend that a newer version is loaded -- :IterateLibraries should NOT be re-created
|
||||
LibStub.minor = LibStub.minor + 0.0001
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
assert(LibStub.IterateLibraries == 123)
|
||||
|
||||
|
||||
-- Again with a huge number
|
||||
LibStub.minor = LibStub.minor + 1234567890
|
||||
|
||||
loadfile("../LibStub.lua")()
|
||||
|
||||
assert(LibStub.IterateLibraries == 123)
|
||||
|
||||
|
||||
print("OK")
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
|
||||
..\FrameXML\UI.xsd">
|
||||
|
||||
<Script file="Libs\LibStub\LibStub.lua"/>
|
||||
<Include file="Libs\AceLocale-3.0\AceLocale-3.0.xml" />
|
||||
|
||||
</Ui>
|
||||
@@ -0,0 +1,9 @@
|
||||
local Loc = LibStub("AceLocale-3.0"):NewLocale ("Details_YouAreNotPrepared", "enUS", true)
|
||||
|
||||
if (not Loc) then
|
||||
return
|
||||
end
|
||||
|
||||
Loc ["STRING_PLUGIN_NAME"] = "You Are Not Prepared (plugin for Details!)"
|
||||
Loc ["STRING_PLUGIN_ALERT"] = "|cFFFFFF00YANP|r: click to see the death log "
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
local Loc = LibStub("AceLocale-3.0"):NewLocale ("Details_YouAreNotPrepared", "ptBR")
|
||||
|
||||
if (not Loc) then
|
||||
return
|
||||
end
|
||||
|
||||
Loc ["STRING_PLUGIN_NAME"] = "You Are Not Prepared (plugin for Details!)"
|
||||
Loc ["STRING_PLUGIN_ALERT"] = "YANP: clique para ver o registro da morte"
|
||||
Reference in New Issue
Block a user