--Addon: RaidScore
--Game: The Elder Scrolls Online: Tamriel Unlimited
--Author: Woeler
local LAM = LibStub:GetLibrary("LibAddonMenu-2.0")
local LMP = LibStub:GetLibrary("LibMediaProvider-1.0")
--function for getting the current score
function RaidScoreUpdate()
RAIDSCORECounter:SetText(string.format(GetCurrentRaidScore()))
end
local savedVariables --local reference for saved variables, actual object will be assigned later in EVENT_ADD_ON_LOADED event handler
local defaults = { --default values for saved variables
offsetX = 200,
offsetY = 200,
HideScores = false,
lockWindow = false,
postResults = true,
raidStart = false,
}
--event handler for OnMoveStop
local function OnMoveStop(self)
savedVariables.offsetX = self:GetLeft()
savedVariables.offsetY = self:GetTop()
end
--event handler for EVENT_ADD_ON_LOADED
local function OnAddonLoaded(event, addonName)
if addonName == "RaidScore" then --addonName is in general name of your addon manifext without .txt extension
EVENT_MANAGER:UnregisterForEvent(MoveHandler, EVENT_ADD_ON_LOADED)
ZO_CreateStringId("SI_BINDING_NAME_TOGGLEHIDDEN", "Toggle hidden")
ZO_CreateStringId("SI_BINDING_NAME_POSTSCORE", "Post current score")
--saved variables (in this case account wide)
savedVariables = ZO_SavedVars:NewAccountWide("RaidScore", 1, "namespace", defaults)
--create top level window, so we have something to work with
RAIDSCORE:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, savedVariables.offsetX, savedVariables.offsetY) --restore window position from saved variables
RAIDSCORE:SetHandler("OnMoveStop", OnMoveStop) --set handler to event "OnMoveStop", it means when you stop moving the window
RAIDSCORE:SetHidden(savedVariables.HideScores) --set window invisible or visible
RAIDSCORE:SetMovable(savedVariables.lockWindow) --lock the window in place or not
RAIDSCORETimer:SetText("Total Time: ")
if IsRaidInProgress() then
Timer.TimerStart()
else
savedVariables.raidStart = nil
end
end
end
function ToggleHidden()
if savedVariables.HideScores == true then
RAIDSCORE:SetHidden(false)
savedVariables.HideScores = false
elseif savedVariables.HideScores == false then
RAIDSCORE:SetHidden(true)
savedVariables.HideScores = true
end
end
function PostScore()
if savedVariables.postResults == true then
d("|cFF0000Current trial score: "..GetCurrentRaidScore())
end
end
function PostEndScore()
if savedVariables.postResults == true then
d("|cFF0000Trial completed with a score of: "..GetCurrentRaidScore())
end
end
------Timer stuff------
local Timer = {
stop = false,
complete = false,
showTimers = false,
instance = false,
}
function Timer.TimerUpdate()
if Timer.stop == true then
EVENT_MANAGER:UnregisterForUpdate("RAID_TIMER_UPDATE")
return
end
local currentTime = GetTimeStamp()
local raidDuration = GetDiffBetweenTimeStamps(currentTime, Timer.raidStart)
local formatedTime = ZO_FormatTime(raidDuration, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_SECONDS)
RAIDSCORETimer:SetText(zo_strformat("Total Time: <<1>>", formatedTime))
end
function Timer.TimerStart()
Timer.stop = false
Timer.instance = true
if Timer.savedVariables.raidStart then
Timer.raidStart = savedVariables.raidStart
else
Timer.raidStart = GetTimeStamp()
savedVariables.raidStart = Timer.raidStart
end
Timer.TimerUpdate()
EVENT_MANAGER:RegisterForUpdate("RAID_TIMER_UPDATE", 1000, Timer.TimerUpdate)
end
function Timer.TimerStop(event, trialName, score, totalTime)
Timer.stop = true
Timer.instance = false
local template = "Trial |cFFFFFF<<1>>|r completed in |cFFFFFF<<2>>|r, score: |cFFFFFF<<3>>|r."
if totalTime == nil then
local currentTime = GetTimeStamp()
totalTime = GetDiffBetweenTimeStamps(currentTime, Timer.raidStart) * 1000
template = "Trial |cFFFFFF<<1>>|r failed. Total time: |cFFFFFF<<2>>|r, score: |cFFFFFF<<3>>|r."
end
local formatedTime = ZO_FormatTimeMilliseconds(totalTime, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_SECONDS)
d(zo_strformat(template, trialName, formatedTime, score))
Timer.raidStart = nil
savedVariables.raidStart = nil
end
local RS = {
Menu = LibStub:GetLibrary("LibAddonMenu-2.0"),
hideScore = false,
lockScore = false,
}
------Creating the menu with LibAddonMenu-2.0-------
RS.panelData = {
type = "panel",
name = "RaidScore",
author = "Woeler",
version = "1.1.3",
registerForRefresh = false,
}
RS.optionsData = {
[1] = {
type = "description",
text = "Welcome to RaidScore by Woeler (EU: @Woeler)",
width = "full",
},
[2] = {
type = "checkbox",
name = "Show RaidScore",
tooltip = "Toggle RaidScore visible.",
getFunc = function() return not savedVariables.HideScores end,
setFunc = function(value)
--RS.hideScore = not value
savedVariables.HideScores = not value
RAIDSCORE:SetHidden(savedVariables.HideScores)
end,
},
[3] = {
type = "checkbox",
name = "Lock window",
tooltip = "Lock the RaidScore window in place.",
getFunc = function() return not savedVariables.lockWindow end,
setFunc = function(value)
savedVariables.lockWindow = not value
RAIDSCORE:SetMovable(savedVariables.lockWindow)
end,
},
[4] = {
type = "checkbox",
name = "Post endscore in chat",
tooltip = "When a trial is completed post the endscore in the chat.",
getFunc = function() return savedVariables.postResults end,
setFunc = function(value)
savedVariables.postResults = value
end,
},
width = "full",
},
RS.Menu:RegisterAddonPanel("RaidScorePanel", RS.panelData)
RS.Menu:RegisterOptionControls("RaidScorePanel", RS.optionsData)
EVENT_MANAGER:RegisterForEvent(MoveHandler, EVENT_ADD_ON_LOADED, OnAddonLoaded)
EVENT_MANAGER:RegisterForEvent("RAID_SCORE_POST", EVENT_RAID_TRIAL_COMPLETE, PostEndScore)
EVENT_MANAGER:RegisterForEvent("RAID_TIMER_UPDATE", EVENT_RAID_TRIAL_SCORE_UPDATE, RaidScoreUpdate)
EVENT_MANAGER:RegisterForEvent("RAID_TIMER_START", EVENT_RAID_TRIAL_STARTED, Timer.TimerStart)
EVENT_MANAGER:RegisterForEvent("RAID_TIMER_STOP", EVENT_RAID_TRIAL_COMPLETE, Timer.TimerStop)
EVENT_MANAGER:RegisterForEvent("RAID_TIMER_STOP", EVENT_RAID_TRIAL_FAILED, Timer.TimerStop)