-
Notifications
You must be signed in to change notification settings - Fork 1
/
Phrase.h
97 lines (77 loc) · 2.18 KB
/
Phrase.h
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
#ifndef __PHRASE_H__
#define __PHRASE_H__
#include <string>
#include "Vector.h"
namespace typing
{
class WorldToScreenCoords;
class Phrase
{
public:
static const std::string PHRASE_FONT;
Phrase()
: m_phraseIndex(0), m_startTime(0.0f), m_lastCorrectTypeTime(0.0f)
{
}
Phrase(const std::string& phrase)
: m_phrase(phrase), m_phraseIndex(0), m_startTime(0.0f),
m_lastCorrectTypeTime(0.0f)
{
}
static void Init();
typedef enum {
PHRASE_DRAW_DEFAULT,
PHRASE_DRAW_BACKWARDS,
PHRASE_DRAW_BLOCKED,
PHRASE_DRAW_HIDDEN,
} PhraseDrawOption;
bool OnType(char c, float time);
void Draw(const juzutil::Vector3& origin,
PhraseDrawOption option = PHRASE_DRAW_DEFAULT);
void Reset(const std::string& phrase)
{
m_phrase = phrase;
m_phraseIndex = 0;
m_startTime = 0.0f;
m_lastCorrectTypeTime = 0.0f;
}
bool IsEmpty() const
{
return (m_phrase.empty());
}
char GetStartChar() const
{
if (m_phrase.empty())
{
return '\0';
}
return m_phrase[0];
}
unsigned int Length() const
{
return static_cast<unsigned int>(m_phrase.length());
}
bool Finished() const
{
return (m_phraseIndex >= m_phrase.length());
}
float GetTypingSpeed() const
{
if (m_phrase.empty())
{
return 0;
}
return (m_lastCorrectTypeTime - m_startTime) / static_cast<float>(m_phrase.length());
}
private:
static const float PHRASE_HEIGHT;
static const float PHRASE_BORDER_GAP;
static const float PHRASE_BORDER_LINE_LENGTH;
static const float PHRASE_Y_OFFSET;
std::string m_phrase;
unsigned int m_phraseIndex;
float m_startTime;
float m_lastCorrectTypeTime;
};
}
#endif // __PHRASE_H__