Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/wndmanagement #13

Merged
merged 3 commits into from
Aug 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 92 additions & 45 deletions VikingSprintMeter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require "Window"
require "GameLib"
require "Apollo"

local VikingLib
local VikingSprintMeter = {}

function VikingSprintMeter:new(o)
Expand All @@ -23,77 +24,123 @@ end
function VikingSprintMeter:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("VikingSprintMeter.xml")
self.xmlDoc:RegisterCallback("OnDocumentReady", self)
Apollo.RegisterEventHandler("WindowManagementReady" , "OnWindowManagementReady" , self)
Apollo.RegisterEventHandler("WindowManagementUpdate" , "OnWindowManagementUpdate" , self)
end

function VikingSprintMeter:OnDocumentReady()
if self.xmlDoc == nil then
return
end
Apollo.RegisterTimerHandler("SprintMeterGracePeriod", "OnSprintMeterGracePeriod", self)
Apollo.RegisterEventHandler("VarChange_FrameCount", "OnFrame", self)
Apollo.RegisterEventHandler("Tutorial_RequestUIAnchor", "OnTutorial_RequestUIAnchor", self)
Apollo.RegisterTimerHandler("SprintMeterGracePeriod" , "OnSprintMeterGracePeriod" , self)
Apollo.RegisterEventHandler("VarChange_FrameCount" , "OnFrame" , self)
Apollo.RegisterEventHandler("Tutorial_RequestUIAnchor" , "OnTutorial_RequestUIAnchor" , self)

self.wndMain = Apollo.LoadForm(self.xmlDoc, "SprintMeterFormVert", "FixedHudStratum", self)
self.wndMain:Show(false, true)
self.xmlDoc = nil
--self.wndMain:SetUnit(GameLib.GetPlayerUnit(), 40) -- 1 or 9 are also good
self.wndMain = Apollo.LoadForm(self.xmlDoc, "VikingSprintMeterForm", "FixedHudStratum", self)
self.wndMain:Show(false, true)
--self.wndMain:SetUnit(GameLib.GetPlayerUnit(), 40) -- 1 or 9 are also good

self.bJustFilled = false
self.nLastSprintValue = 0
end
self.bJustFilled = false
self.nLastSprintValue = 0

function VikingSprintMeter:OnFrame()
local unitPlayer = GameLib.GetPlayerUnit()
if not unitPlayer then
return
end
--Settings
if VikingLib == nil then
VikingLib = Apollo.GetAddon("VikingLibrary")
end

local bWndVisible = self.wndMain:IsVisible()
local nRunCurr = unitPlayer:GetResource(0)
local nRunMax = unitPlayer:GetMaxResource(0)
local bAtMax = nRunCurr == nRunMax or unitPlayer:IsDead()
if VikingLib ~= nil then
self.db = VikingLib.Settings.RegisterSettings(self, "VikingSprintMeter", self:GetDefaults(), "Sprint Meter")
end
end

self.wndMain:FindChild("ProgBar"):SetMax(nRunMax)
self.wndMain:FindChild("ProgBar"):SetProgress(nRunCurr, bWndVisible and nRunMax or 0)
function VikingSprintMeter:OnWindowManagementReady()
Event_FireGenericEvent("WindowManagementAdd", { wnd = self.wndMain, strName = "Viking SprintBar"} )
end

if self.nLastSprintValue ~= nRunCurr then
self.nLastSprintValue = nRunCurr
end
function VikingSprintMeter:OnWindowManagementUpdate(tWindow)
if tWindow and tWindow.wnd and tWindow.wnd == self.wndMain then
local bMoveable = tWindow.wnd:IsStyleOn("Moveable")

if bWndVisible and bAtMax and not self.bJustFilled then
self.bJustFilled = true
Apollo.StopTimer("SprintMeterGracePeriod")
Apollo.CreateTimer("SprintMeterGracePeriod", 0.4, false)
--self.wndMain:FindChild("ProgFlash"):SetSprite("sprResourceBar_Sprint_ProgFlash")
end
tWindow.wnd:SetStyle("RequireMetaKeyToMove", bMoveable)
tWindow.wnd:SetStyle("IgnoreMouse", not bMoveable)
end
end

if not bAtMax then
self.bJustFilled = false
Apollo.StopTimer("SprintMeterGracePeriod")
end
function VikingSprintMeter:GetDefaults()
return {
char = {
SprintMeterShow = false
}
}
end

self.wndMain:Show(not bAtMax or self.bJustFilled, not bAtMax)
function VikingSprintMeter:OnFrame()
local unitPlayer = GameLib.GetPlayerUnit()
if not unitPlayer then
return
end

local bWndVisible = self.wndMain:IsVisible()
local nRunCurr = unitPlayer:GetResource(0)
local nRunMax = unitPlayer:GetMaxResource(0)
local bAtMax = nRunCurr == nRunMax or unitPlayer:IsDead()
local bShowSprint = self.db.char.SprintMeterShow

self.wndMain:FindChild("ProgBar"):SetMax(nRunMax)
self.wndMain:FindChild("ProgBar"):SetProgress(nRunCurr, bWndVisible and nRunMax or 0)

if self.nLastSprintValue ~= nRunCurr then
self.nLastSprintValue = nRunCurr
end

if bWndVisible and bAtMax and not self.bJustFilled then
self.bJustFilled = true
Apollo.StopTimer("SprintMeterGracePeriod")
Apollo.CreateTimer("SprintMeterGracePeriod", 0.4, false)
--self.wndMain:FindChild("ProgFlash"):SetSprite("sprResourceBar_Sprint_ProgFlash")
end

if not bAtMax then
self.bJustFilled = false
Apollo.StopTimer("SprintMeterGracePeriod")
end

self.wndMain:Show(bShowSprint or not bAtMax or self.bJustFilled, not bAtMax)
end

function VikingSprintMeter:OnSprintMeterGracePeriod()
Apollo.StopTimer("SprintMeterGracePeriod")
self.bJustFilled = false
if self.wndMain and self.wndMain:IsValid() then
self.wndMain:Show(false)
end
Apollo.StopTimer("SprintMeterGracePeriod")
self.bJustFilled = false
if self.wndMain and self.wndMain:IsValid() then
self.wndMain:Show(false)
end
end

---------------------------------------------------------------------------------------------------
-- Tutorial anchor request
---------------------------------------------------------------------------------------------------
function VikingSprintMeter:OnTutorial_RequestUIAnchor(eAnchor, idTutorial, strPopupText)
if eAnchor == GameLib.CodeEnumTutorialAnchor.VikingSprintMeter then
if eAnchor == GameLib.CodeEnumTutorialAnchor.VikingSprintMeter then

local tRect = {}
tRect.l, tRect.t, tRect.r, tRect.b = self.wndMain:GetRect()
local tRect = {}
tRect.l, tRect.t, tRect.r, tRect.b = self.wndMain:GetRect()

Event_FireGenericEvent("Tutorial_RequestUIAnchorResponse", eAnchor, idTutorial, strPopupText, tRect)
end
Event_FireGenericEvent("Tutorial_RequestUIAnchorResponse", eAnchor, idTutorial, strPopupText, tRect)
end
end

---------------------------------------------------------------------------------------------------
-- VikingSettings Functions
---------------------------------------------------------------------------------------------------

function VikingSprintMeter:OnSettingsSprintMeter( wndHandler, wndControl, eMouseButton )
self.db.char.SprintMeterShow = wndControl:IsChecked()
end

-- Called when the settings form needs to be updated so it visually reflects the options
function VikingSprintMeter:UpdateSettingsForm(wndContainer)
--Show SprintMeter to set new position
wndContainer:FindChild("SprintMeterShow:Content:ShowSprintMeter"):SetCheck(self.db.char.SprintMeterShow)
end


Expand Down
21 changes: 17 additions & 4 deletions VikingSprintMeter.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<Forms>
<SpriteFile Name="..\VikingLibrary\VikingSprites.xml"/>
<Form Class="Window" LAnchorPoint=".5" LAnchorOffset="-27" TAnchorPoint="ActionBar0_Bottom" TAnchorOffset="-123" RAnchorPoint=".5" RAnchorOffset="27" BAnchorPoint="ActionBar0_Bottom" BAnchorOffset="-111" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="SprintMeterFormVert" Border="0" Picture="1" SwallowMouseClicks="1" Moveable="1" Escapable="0" Overlapped="1" TooltipColor="">
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="8" RelativeToClient="1" Font="Default" Text="" Template="Default" TooltipType="OnCursor" Name="ProgBG" BGColor="99141122" TextColor="ffffffff" TooltipColor="" Picture="1" IgnoreMouse="1" Sprite="VikingSprites:SprintBackground" NoClip="0" Tooltip="" Moveable="0">
<Control Class="ProgressBar" Text="" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="1" BAnchorOffset="0" AutoSetText="0" UseValues="0" RelativeToClient="1" SetTextToProgress="0" DT_CENTER="1" DT_VCENTER="1" ProgressEmpty="" ProgressFull="VikingSprites:SprintBackground" TooltipType="OnCursor" Name="ProgBar" BGColor="ffffffff" TextColor="ffffffff" TooltipColor="" BarColor="ChannelWarParty" Picture="1" Sprite="" BRtoLT="0" VerticallyAligned="0" Tooltip="" NewWindowDepth="1"/>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="17" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="1" BAnchorOffset="0" RelativeToClient="1" Font="Default" Text="" Template="Default" TooltipType="OnCursor" Name="ProgFlashf" BGColor="ffffffff" TextColor="ffffffff" TooltipColor="" Sprite="" Picture="0" IgnoreMouse="1" NewControlDepth="1" Tooltip="" Overlapped="0" NoClip="0" TestAlpha="0" NewWindowDepth="0" Border="1"/>
<Form Class="Window" LAnchorPoint=".5" LAnchorOffset="-27" TAnchorPoint="1" TAnchorOffset="-122" RAnchorPoint=".5" RAnchorOffset="27" BAnchorPoint="1" BAnchorOffset="-110" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="VikingSprintMeterForm" Border="0" Picture="1" SwallowMouseClicks="1" Moveable="1" Escapable="0" Overlapped="0" TooltipColor="" IgnoreMouse="1" Tooltip="" Sizable="0" NewWindowDepth="0" NoClip="1">
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="8" RelativeToClient="1" Font="Default" Text="" Template="Default" TooltipType="OnCursor" Name="ProgBG" BGColor="99141122" TextColor="ffffffff" TooltipColor="" Picture="1" IgnoreMouse="1" Sprite="VikingSprites:SprintBackground" NoClip="1" Tooltip="" Moveable="0" Overlapped="0">
<Control Class="ProgressBar" Text="" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="1" BAnchorOffset="0" AutoSetText="0" UseValues="0" RelativeToClient="1" SetTextToProgress="0" DT_CENTER="1" DT_VCENTER="1" ProgressEmpty="" ProgressFull="VikingSprites:SprintBackground" TooltipType="OnCursor" Name="ProgBar" BGColor="ffffffff" TextColor="ffffffff" TooltipColor="" BarColor="ChannelWarParty" Picture="1" Sprite="" BRtoLT="0" VerticallyAligned="0" Tooltip="" NewWindowDepth="1" NoClip="1" Overlapped="0" IgnoreMouse="1"/>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="17" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="1" BAnchorOffset="0" RelativeToClient="1" Font="Default" Text="" Template="Default" TooltipType="OnCursor" Name="ProgFlashf" BGColor="ffffffff" TextColor="ffffffff" TooltipColor="" Sprite="" Picture="0" IgnoreMouse="1" NewControlDepth="1" Tooltip="" Overlapped="0" NoClip="1" TestAlpha="0" NewWindowDepth="0" Border="1"/>
</Control>
</Form>
<Form Class="Window" LAnchorPoint="0" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="-10" BAnchorPoint="1" BAnchorOffset="0" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="VikingSettings" Border="0" Picture="0" SwallowMouseClicks="1" Moveable="0" Escapable="0" Overlapped="1" TooltipColor="" Tooltip="" Sprite="" IgnoreMouse="0">
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="75" RelativeToClient="1" Font="Default" Text="" BGColor="11000000" TextColor="ffffffff" Template="CRB_InnerWindow" TooltipType="OnCursor" Name="SprintMeterShow" TooltipColor="" Sprite="BasicSprites:WhiteFill" Picture="0" IgnoreMouse="1" Tooltip="" LeftEdgeControlsAnchor="" BottomEdgeControlsAnchor="STYLE_BOTTOM">
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="32" RelativeToClient="1" Font="CRB_Dialog_Heading_Small" Text="Makes SprintMeter visable to set position" BGColor="0028253a" TextColor="ffbcb7da" Template="Default" TooltipType="OnCursor" Name="Header" TooltipColor="" DT_CENTER="0" DT_VCENTER="1" TextId="" Sprite="BasicSprites:WhiteFill" Picture="1" IgnoreMouse="1" BottomEdgeControlsAnchor="HEADER_BOTTOM" Tooltip="">
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="1" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="1" BAnchorOffset="1" RelativeToClient="1" Font="Default" Text="" BGColor="90645f7e" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="Line" TooltipColor="" Sprite="BasicSprites:WhiteFill" Picture="1" IgnoreMouse="1" NoClip="1"/>
</Control>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="36" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="68" RelativeToClient="1" Font="Default" Text="" BGColor="ffffffff" TextColor="ffffffff" Template="Default" TooltipType="OnCursor" Name="Content" TooltipColor="" Tooltip="">
<Control Class="Button" Base="VikingSprites:CheckBoxbtn" Font="CRB_Header10" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="0" TAnchorPoint="0" TAnchorOffset="4" RAnchorPoint=".5" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="28" DT_VCENTER="1" DT_CENTER="0" BGColor="00ffffffff" TextColor="ffbcb7da" NormalTextColor="ffffffff" PressedTextColor="ffffffff" FlybyTextColor="ffffffff" PressedFlybyTextColor="ffffffff" DisabledTextColor="ffffffff" TooltipType="OnCursor" Name="ShowSprintMeter" TooltipColor="ff4fbfff" Template="CRB_NormalFramedThin" DrawAsCheckbox="1" Text="Show SprintMeter" TooltipFont="CRB_Interface9" Tooltip="Used to see the SprintMeter to move it to new position" TooltipId="" CheckboxRight="0" TextId="" GlobalRadioGroup="" RadioDisallowNonSelection="1" DrawHotkey="0" DT_RIGHT="0" DT_SINGLELINE="0">
<Event Name="ButtonCheck" Function="OnSettingsSprintMeter"/>
<Event Name="ButtonUncheck" Function="OnSettingsSprintMeter"/>
</Control>
</Control>
</Control>
</Form>
</Forms>