-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First feature-complete version with timer and chat announcement. QoL improvements such as configuration menu to follow.
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Title: WereWatch | ||
## APIVersion: 100018 | ||
## SavedVariables: WereWatchSavedVariables | ||
|
||
WereWatch.xml | ||
WereWatch.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |