local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
local Addon =
{
name = "ProvisionsIntelSpeller",
namePublic = "Prov's IntelSpeller",
nameColor = "|cFF9999Intel|cFF0000Speller|r",
author = "|c00C000Provision|r",
version = "0.1", --3 endroits
CPL = nil,
defaults =
{
enabled = true,
posx = 0,
posy = 50,
locked = true,
refreshRate = 25,
siege = true,
},
debug = {
enabled = false,
}
}
local IntelSpeller = {}
local KeyIS = {}
function IntelSpeller_Keypress(num)
local a, b
a = "A5" b = "A4"
d(KeyIS[a][3] .. " <=> " .. KeyIS[b][3])
if num == 1 then
d("INTELSPELLER_A")
CallSecureProtected("BindKeyToAction", KeyIS[a][1][1], KeyIS[a][1][2], KeyIS[a][1][3], 1, KeyIS[b][2])
CallSecureProtected("BindKeyToAction", KeyIS[b][1][1], KeyIS[b][1][2], KeyIS[b][1][3], 1, KeyIS[a][2])
else
d("INTELSPELLER_B")
CallSecureProtected("BindKeyToAction", KeyIS[a][1][1], KeyIS[a][1][2], KeyIS[a][1][3], 1, KeyIS[a][2])
CallSecureProtected("BindKeyToAction", KeyIS[b][1][1], KeyIS[b][1][2], KeyIS[b][1][3], 1, KeyIS[b][2])
end
end
local function GetActionBindingFullInfo(keyName)
local a, b, c, key, name
a, b, c = GetActionIndicesFromName(keyName)
key = GetActionBindingInfo(a, b, c, 1)
name = GetString(_G["SI_BINDING_NAME_" .. keyName])
return { { a, b, c }, key, name }
end
local IS_myFirstTime = true
local function IntelSpeller_OnUpdate()
if not Addon.vars.enabled then
return
end
if (IS_myFirstTime) then
IS_myFirstTime = false
local c
for i = 1, 7 do
c = "A" .. i
KeyIS[c] = GetActionBindingFullInfo("ACTION_BUTTON_" .. (i + 2))
d(KeyIS[c][3] .. " = " .. KeyIS[c][2])
end
end
end
local function IntelSpeller_OnMoveStop()
Addon.vars.posx = math.floor(IntelSpeller.UI:GetLeft())
Addon.vars.posy = math.floor(IntelSpeller.UI:GetTop())
end
local function createLAM2Panel()
local panelData =
{
type = "panel",
name = Addon.namePublic,
displayName = Addon.nameColor,
author = Addon.author,
version = Addon.version,
--slashCommand = "/is",
registerForRefresh = true,
registerForDefaults = true,
resetFunc = function()
Addon.vars = Addon.defaults
IntelSpeller.UI:SetAnchor(CENTER, GuiRoot, CENTER, Addon.vars.posx, Addon.vars.posy)
IntelSpeller.UI:SetMovable(not Addon.vars.locked)
IntelSpeller_SetHidden(not Addon.vars.enabled)
EVENT_MANAGER:UnRegisterForUpdate(Addon.name .. "Update")
EVENT_MANAGER:RegisterForUpdate(Addon.name .. "Update", Addon.vars.refreshRate, function(...) IntelSpeller_OnUpdate() end)
end,
}
local optionsData =
{
{
type = "checkbox",
name = GetString(SI_INTELS_SETTING_ENABLED),
tooltip = GetString(SI_INTELS_SETTING_ENABLED_TOOLTIP),
getFunc = function() return Addon.vars.enabled end,
setFunc = function(value)
Addon.vars.enabled = value
IntelSpeller_SetHidden(not Addon.vars.enabled)
end,
width = "full",
},
{
type = "description",
text = GetString(SI_INTELS_SETTING_SHOWNOW_TOOLTIP),
width = "half",
},
{
type = "button",
name = GetString(SI_INTELS_SETTING_SHOWNOW),
tooltip = GetString(SI_INTELS_SETTING_SHOWNOW_TOOLTIP),
func = function()
if Addon.vars.enabled then
IntelSpeller_SetHidden(false)
end
end,
width = "half"
},
{
type = "submenu",
name = GetString(SI_INTELS_SETTING_SIZEOPTIONS),
controls =
{
[1] = {
type = "description",
text = GetString(SI_INTELS_SETTING_SIZEOPTIONS_TOOLTIP),
},
[2] = {
type = "slider",
name = GetString(SI_INTELS_SETTING_X),
tooltip = GetString(SI_INTELS_SETTING_X_TOOLTIP),
min = -zo_round(GuiRoot:GetWidth() / 2), max = zo_round(GuiRoot:GetWidth() / 2), step = 1,
getFunc = function() return Addon.vars.posx end,
setFunc = function(value)
Addon.vars.posx = value
IntelSpeller.UI:SetAnchor(CENTER, GuiRoot, CENTER, Addon.vars.posx, Addon.vars.posy)
end,
width = "half",
},
[3] = {
type = "slider",
name = GetString(SI_INTELS_SETTING_Y),
tooltip = GetString(SI_INTELS_SETTING_Y_TOOLTIP),
min = -zo_round(GuiRoot:GetHeight() / 2), max = zo_round(GuiRoot:GetHeight() / 2), step = 1,
getFunc = function() return Addon.vars.posy end,
setFunc = function(value)
Addon.vars.posy = value
IntelSpeller.UI:SetAnchor(CENTER, GuiRoot, CENTER, Addon.vars.posx, Addon.vars.posy)
end,
width = "half",
},
[4] =
{
type = "checkbox",
name = GetString(SI_INTELS_SETTING_LOCK),
tooltip = GetString(SI_INTELS_SETTING_LOCK_TOOLTIP),
getFunc = function() return Addon.vars.locked end,
setFunc = function(value)
Addon.vars.locked = value
IntelSpeller.UI:SetMovable(not Addon.vars.locked)
end,
width = "full",
},
},
},
{
type = "submenu",
name = GetString(SI_INTELS_SETTING_FOCUSOPTIONS),
controls =
{
[1] = {
type = "description",
text = GetString(SI_INTELS_SETTING_FOCUSOPTIONS_TOOLTIP),
},
[2] = {
type = "slider",
name = GetString(SI_INTELS_SETTING_REFRESHRATE),
tooltip = GetString(SI_INTELS_SETTING_REFRESHRATE_TOOLTIP),
warning = GetString(SI_INTELS_SETTING_REFRESHRATE_WARNING),
min = 10, max = 100, step = 1,
getFunc = function() return Addon.vars.refreshRate end,
setFunc = function(value)
Addon.vars.refreshRate = value
EVENT_MANAGER:UnregisterForUpdate(Addon.name .. "Update")
EVENT_MANAGER:RegisterForUpdate(Addon.name .. "Update", Addon.vars.refreshRate, function(...) IntelSpeller_OnUpdate() end)
end,
width = "full",
},
[3] =
{
type = "checkbox",
name = GetString(SI_INTELS_SETTING_SIEGE),
tooltip = GetString(SI_INTELS_SETTING_SIEGE_TOOLTIP),
getFunc = function() return Addon.vars.siege end,
setFunc = function(value)
Addon.vars.siege = value
end,
width = "full",
},
},
},
{
type = "description",
text = GetString(SI_INTELS_DESC_INTELSPELLER),
},
}
if GetUnitName("player") == "Elium" or GetUnitName("player") == "Elena d'Alizarine" then -- Just for me ;) (Prevent crash)
table.insert(optionsData, {
type = "submenu",
name = "Espace de développement",
controls =
{
[1] =
{
type = "checkbox",
name = "Activer",
getFunc = function() return Addon.debug.enabled end,
setFunc = function(value) Addon.debug.enabled = value end,
width = "full",
},
},
})
end
Addon.CPL = LAM2:RegisterAddonPanel(Addon.name .. "LAM2Options", panelData)
LAM2:RegisterOptionControls(Addon.name .. "LAM2Options", optionsData)
end
local function IntelSpeller_OnAddOnLoad(eventCode, addOnName)
if (Addon.name ~= addOnName) then return end
Addon.vars = ZO_SavedVars:NewAccountWide("ProvISSV", 1, nil, Addon.defaults)
SLASH_COMMANDS["/is"] = function(...)
LAM2:OpenToPanel(Addon.CPL)
end
IntelSpeller.UI = WINDOW_MANAGER:CreateControl(nil, GuiRoot, CT_TOPLEVELCONTROL)
IntelSpeller.UI:SetMouseEnabled(true)
IntelSpeller.UI:SetMovable(not Addon.vars.locked)
IntelSpeller.UI:SetClampedToScreen(true)
IntelSpeller.UI:SetDimensions(100, 64)
IntelSpeller.UI:SetDrawLevel(0)
IntelSpeller.UI:SetHidden(not Addon.vars.enabled)
IntelSpeller.UI:ClearAnchors()
IntelSpeller.UI:SetAnchor(CENTER, GuiRoot, CENTER, Addon.vars.posx, Addon.vars.posy)
IntelSpeller.UI:SetHandler("OnMoveStop", function(...) IntelSpeller_OnMoveStop(...) end)
--IntelSpeller.Background = WINDOW_MANAGER:CreateControl(nil, IntelSpeller.UI, CT_BACKDROP)
--IntelSpeller.Background:SetAnchorFill(IntelSpeller.UI)
--IntelSpeller.Background:SetEdgeColor(1, 1, 1, 1)
local fragment = ZO_SimpleSceneFragment:New(IntelSpeller.UI)
SCENE_MANAGER:GetScene('hud'):AddFragment(fragment)
SCENE_MANAGER:GetScene('hudui'):AddFragment(fragment)
EVENT_MANAGER:UnregisterForEvent(Addon.name, EVENT_ADD_ON_LOADED)
createLAM2Panel()
EVENT_MANAGER:RegisterForUpdate(Addon.name .. "Update", Addon.vars.refreshRate, function(...) IntelSpeller_OnUpdate() end)
EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_BEGIN_SIEGE_CONTROL, function(...)
if Addon.vars.enabled then
IntelSpeller_SetHidden(not Addon.vars.siege)
end
end)
end
function IntelSpeller_OnInitialized()
EVENT_MANAGER:RegisterForEvent(Addon.name, EVENT_ADD_ON_LOADED, function(...) IntelSpeller_OnAddOnLoad(...) end)
end