代码WelcomeHome.toc
## Interface: 12000
## Title: Welcome Home
## Notes: Displays a welcome message when you get to your home zone.
## Author: Your Name Here
## Version: 0.1
## OptionalDeps: Ace2
## SavedVariables: WelcomeHomeDB
## SavedVariablesPerCharacter: WelcomeHomeDBPC
## X-Category: Interface Enhancements
Libs\AceLibrary\AceLibrary.lua
Libs\AceOO-2.0\AceOO-2.0.lua
Libs\AceAddon-2.0\AceAddon-2.0.lua
Libs\AceDB-2.0\AceDB-2.0.lua
Libs\AceConsole-2.0\AceConsole-2.0.lua
Libs\AceEvent-2.0\AceEvent-2.0.lua
Libs\AceLocale-2.2\AceLocale-2.2.lua
Locale-enUS.lua
Core.lua
Core.lualocal L = AceLibrary("AceLocale-2.2"):new("WelcomeHome")
local opts = {
type='group',
args = {
msg = {
type = 'text',
name = L["Message"],
desc = L["Sets the message to be displayed when you get home."],
usage = L["<your message>"],
get = "GetMessage",
set = "SetMessage",
},
showInChat = {
type = 'toggle',
name = L["Show in Chat"],
desc = L["If set, your message will be displayed in the General chat window."],
get = "IsShowInChat",
set = "ToggleShowInChat",
},
showOnScreen = {
type = 'toggle',
name = L["Show on Screen"],
desc = L["If set, your message will be displayed on the screen near the top of the game field."],
get = "IsShowOnScreen",
set = "ToggleShowOnScreen"
},
},
}
WelcomeHome = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceEvent-2.0", "AceDB-2.0")
WelcomeHome:RegisterChatCommand(L["Slash-Commands"], opts)
WelcomeHome:RegisterDB("WelcomeHomeDB", "WelcomeHomeDBPC")
WelcomeHome:RegisterDefaults("profile", {
message = L["Welcome Home!"],
showInChat = false,
showOnScreen = true,
} )
function WelcomeHome:OnEnable()
self:RegisterEvent("ZONE_CHANGED")
end
function WelcomeHome:ZONE_CHANGED()
if GetBindLocation() == GetSubZoneText() then
if self.db.profile.showInChat then
self rint(self.db.profile.message)
end
if self.db.profile.showOnScreen then
UIErrorsFrame:AddMessage(self.db.profile.message, 1.0, 1.0, 1.0, 5.0)
end
end
end
function WelcomeHome:GetMessage()
return self.db.profile.message
end
function WelcomeHome:SetMessage(newValue)
self.db.profile.message = newValue
end
function WelcomeHome:IsShowInChat()
return self.db.profile.showInChat
end
function WelcomeHome:ToggleShowInChat()
self.db.profile.showInChat = not self.db.profile.showInChat
end
function WelcomeHome:IsShowOnScreen()
return self.db.profile.showOnScreen
end
function WelcomeHome:ToggleShowOnScreen()
self.db.profile.showOnScreen = not self.db.profile.showOnScreen
end
Locale-enUS.lualocal L = AceLibrary("AceLocale-2.2"):new("WelcomeHome")
L:RegisterTranslations("enUS", function() return {
["Slash-Commands"] = { "/welcomehome", "/wh" }
["Welcome Home!"] = true, -- default message
["Message"] = true,
["Sets the message to be displayed when you get home."] = true,
["<your message>"] = true, -- usage
["Show in Chat"] = true,
["If set, your message will be displayed in the General chat window."] = true,
["Show on Screen"] = true,
["If set, your message will be displayed on the screen near the top of the game field."] = true,
} end)
|