Skip to content

Commit

Permalink
Initial Version
Browse files Browse the repository at this point in the history
First feature-complete version with timer and chat announcement. QoL
improvements such as configuration menu to follow.
  • Loading branch information
MaeBee committed Apr 29, 2017
1 parent 970a05b commit 69662da
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
90 changes: 90 additions & 0 deletions WereWatch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
-- WereWatch
-- by gobbo (@gobbo1008)
WereWatch = {}
WereWatch.name = "WereWatch"

function WereWatch:Initialize()
self.savedVariables = ZO_SavedVars:New("WereWatchSavedVariables", 1, nil, {})
self.werewolf = IsWerewolf()
local left = self.savedVariables.left
local top = self.savedVariables.top
WereWatchUI:ClearAnchors()
WereWatchUI:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
end -- function

-- Load handler
function WereWatch.OnAddOnLoaded(event, addonName)
if addonName == WereWatch.name then
WereWatch:Initialize()
end -- if
end -- function

local timelastrun = 0
function WereWatch.OnUpdate(timerun)
if WereWatch.running then
if (timerun - timelastrun) >= 0.1 then
timelastrun = timerun
WereWatchUILabel:SetText(WereWatch.ToMinSec(GetTimeStamp() - WereWatch.startTime))
end -- if timerun - timelastrun
elseif ((timerun - timelastrun) >= 5) and ((timerun - timelastrun) <= 6) then
WereWatchUI:SetHidden(true)
end -- if WereWatch.running
end -- function

function WereWatch.OnIndicatorMoveStop()
WereWatch.savedVariables.left = WereWatchUI:GetLeft()
WereWatch.savedVariables.top = WereWatchUI:GetTop()
end -- function

function WereWatch.OnWerewolfStateChanged(eventCode, werewolf)
if werewolf ~= WereWatch.werewolf then
-- state changed from previous
WereWatch.werewolf = werewolf
if werewolf then
-- player turned into werewolf
-- start the stopwatch
WereWatch.startTime = GetTimeStamp()
WereWatch.running = true
WereWatchUI:SetHidden(false)
else
-- player turned into human again
-- stop the stopwatch
WereWatch.stopTime = GetTimeStamp()
WereWatch.running = false
-- calculate time difference and break down into minutes and seconds
WereWatch.deltaTime = GetDiffBetweenTimeStamps(WereWatch.stopTime, WereWatch.startTime)
-- announce to player
d("[WereWatch] You held your werewolf form for ".. WereWatch.ToMinSec(WereWatch.deltaTime) .. ".")
end -- if werewolf
end -- if werewolf ~= WereWatch.werewolf
end -- function

function WereWatch.ToMinSec(timestamp)
timestamp = math.floor(timestamp)
local minutes = math.floor(timestamp/60)
if minutes < 10 then
minutes = "0" .. minutes
end -- if
local seconds = timestamp % 60
if seconds < 10 then
seconds = "0" .. seconds
end -- if
return minutes .. ":" .. seconds
end -- function

SLASH_COMMANDS["/ww"] = function(arg)
if arg == "show" then
WereWatchUI:SetHidden(false)
elseif arg == "hide" then
WereWatchUI:SetHidden(true)
elseif arg == "start" then
WereWatch.OnWerewolfStateChanged("debug", true)
elseif arg == "stop" then
WereWatch.OnWerewolfStateChanged("debug", false)
elseif arg == "pos" then
d("[WereWatch] Timer position: " .. WereWatchUI:GetLeft() .. ", " .. WereWatchUI:GetTop())
end -- if
end -- function

EVENT_MANAGER:RegisterForEvent(WereWatch.name, EVENT_ADD_ON_LOADED, WereWatch.OnAddOnLoaded)
EVENT_MANAGER:RegisterForEvent(WereWatch.name, EVENT_WEREWOLF_STATE_CHANGED, WereWatch.OnWerewolfStateChanged)
6 changes: 6 additions & 0 deletions WereWatch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Title: WereWatch
## APIVersion: 100018
## SavedVariables: WereWatchSavedVariables

WereWatch.xml
WereWatch.lua
21 changes: 21 additions & 0 deletions WereWatch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<GuiXml>
<Controls>
<TopLevelControl name="WereWatchUI" mouseEnabled="true" movable="true" clampedToScreen="true" hidden="true">
<Dimensions x="200" y="24" />
<Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" />

<OnUpdate>
WereWatch.OnUpdate(time)
</OnUpdate>
<OnMoveStop>
WereWatch.OnIndicatorMoveStop()
</OnMoveStop>

<Controls>
<Label name="$(parent)Label" width="200" height="24" font="ZoFontWinT1" inheritAlpha="true" color="FFFFFF" wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="WereWatch">
<Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
</Label>
</Controls>
</TopLevelControl>
</Controls>
</GuiXml>

0 comments on commit 69662da

Please sign in to comment.