forked from BoyC/GW2TacO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocationalTimer.cpp
151 lines (119 loc) · 4.75 KB
/
LocationalTimer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "LocationalTimer.h"
#include "MumbleLink.h"
#include "OverlayConfig.h"
CArray<LocationalTimer> LocationalTimers;
void ImportLocationalTimers()
{
CXMLDocument d;
if ( !d.LoadFromFile( "locationaltimers.xml" ) ) return;
if ( !d.GetDocumentNode().GetChildCount( "timers" ) ) return;
CXMLNode root = d.GetDocumentNode().GetChild( "timers" );
for ( TS32 x = 0; x < root.GetChildCount( "areatriggeredtimer" ); x++ )
{
LocationalTimer t;
t.ImportData( root.GetChild( "areatriggeredtimer", x ) );
LocationalTimers += t;
}
}
LocationalTimer::LocationalTimer()
{
}
LocationalTimer::~LocationalTimer()
{
}
void LocationalTimer::Update()
{
if ( mumbleLink.mapID != MapID )
{
IsRunning = false;
return;
}
if ( !IsRunning )
{
if ( EnterSphere.Contains( mumbleLink.charPosition ) )
{
IsRunning = true;
StartTime = GetTime();
}
}
if ( IsRunning )
{
if ( ( GetTime() - StartTime ) / 1000.0f > TimerLength )
IsRunning = false;
if ( !ExitSphere.Contains( mumbleLink.charPosition ) )
IsRunning = false;
if ( ( ResetPoint - mumbleLink.charPosition ).Length() < 0.1 )
IsRunning = false;
}
}
void LocationalTimer::ImportData( CXMLNode &node )
{
if ( node.HasAttribute( "mapid" ) ) node.GetAttributeAsInteger( "mapid", &MapID );
if ( node.HasAttribute( "length" ) ) node.GetAttributeAsInteger( "length", &TimerLength );
if ( node.HasAttribute( "startdelay" ) ) node.GetAttributeAsInteger( "startdelay", &StartDelay );
if ( node.HasAttribute( "enterspherex" ) ) node.GetAttributeAsFloat( "enterspherex", &EnterSphere.Position.x );
if ( node.HasAttribute( "enterspherey" ) ) node.GetAttributeAsFloat( "enterspherey", &EnterSphere.Position.y );
if ( node.HasAttribute( "enterspherez" ) ) node.GetAttributeAsFloat( "enterspherez", &EnterSphere.Position.z );
if ( node.HasAttribute( "entersphererad" ) ) node.GetAttributeAsFloat( "entersphererad", &EnterSphere.Radius );
if ( node.HasAttribute( "exitspherex" ) ) node.GetAttributeAsFloat( "exitspherex", &ExitSphere.Position.x );
if ( node.HasAttribute( "exitspherey" ) ) node.GetAttributeAsFloat( "exitspherey", &ExitSphere.Position.y );
if ( node.HasAttribute( "exitspherez" ) ) node.GetAttributeAsFloat( "exitspherez", &ExitSphere.Position.z );
if ( node.HasAttribute( "exitsphererad" ) ) node.GetAttributeAsFloat( "exitsphererad", &ExitSphere.Radius );
if ( node.HasAttribute( "resetpointx" ) ) node.GetAttributeAsFloat( "resetpointx", &ResetPoint.x );
if ( node.HasAttribute( "resetpointy" ) ) node.GetAttributeAsFloat( "resetpointy", &ResetPoint.y );
if ( node.HasAttribute( "resetpointz" ) ) node.GetAttributeAsFloat( "resetpointz", &ResetPoint.z );
for ( TS32 x = 0; x < node.GetChildCount( "timeevent" ); x++ )
{
CXMLNode te = node.GetChild( "timeevent", x );
TimerEvent tmr;
if ( te.HasAttribute( "text" ) ) tmr.Text = te.GetAttributeAsString( "text" );
if ( te.HasAttribute( "timestamp" ) ) te.GetAttributeAsInteger( "timestamp", &tmr.Time );
if ( te.HasAttribute( "countdown" ) ) te.GetAttributeAsInteger( "countdown", &tmr.CountdownLength );
if ( te.HasAttribute( "onscreentime" ) ) te.GetAttributeAsInteger( "onscreentime", &tmr.OnScreenLength );
Events += tmr;
}
}
void TimerDisplay::OnDraw( CWBDrawAPI *API )
{
if ( !HasConfigValue( "LocationalTimersVisible" ) )
SetConfigValue( "LocationalTimersVisible", 1 );
if ( !GetConfigValue( "LocationalTimersVisible" ) )
return;
TS32 tme = GetTime();
CWBFont *f = GetFont( GetState() );
TS32 ypos = Lerp( GetClientRect().y1, GetClientRect().y2, 0.25f );
for ( TS32 x = 0; x < LocationalTimers.NumItems(); x++ )
{
LocationalTimer &t = LocationalTimers[ x ];
t.Update();
if ( !t.IsRunning )
continue;
TF32 timepos = ( tme - LocationalTimers[ x ].StartTime ) / 1000.0f - t.StartDelay;
for ( TS32 y = 0; y < t.Events.NumItems(); y++ )
{
auto &e = t.Events[ y ];
if ( !( timepos > e.Time - e.CountdownLength && timepos < e.Time + e.OnScreenLength ) )
continue;
CString s = e.Text;
if ( timepos<e.Time && timepos>e.Time - e.CountdownLength )
s += CString::Format( " in %d", (TS32)( e.Time - timepos ) );
CPoint pos = f->GetTextPosition( s, CRect( GetClientRect().x1, ypos, GetClientRect().x2, ypos ), WBTA_CENTERX, WBTA_CENTERY, WBTT_NONE, true );
ypos += f->GetLineHeight();
f->Write( API, s, pos );
}
}
}
TBOOL TimerDisplay::IsMouseTransparent( CPoint &ClientSpacePoint, WBMESSAGE MessageType )
{
return true;
}
TimerDisplay::TimerDisplay( CWBItem *Parent, CRect Position ) : CWBItem( Parent, Position )
{
}
TimerDisplay::~TimerDisplay()
{
}
CWBItem * TimerDisplay::Factory( CWBItem *Root, CXMLNode &node, CRect &Pos )
{
return new TimerDisplay( Root, Pos );
}