This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNickname.cpp
84 lines (66 loc) · 1.52 KB
/
Nickname.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
#include "Nickname.h"
Nickname::Nickname(std::string Nickname) : CurrentNickname(Nickname)
{
Running = true;
DisplaySurface = SDL_GetVideoSurface();
}
Nickname::~Nickname()
{ }
void Nickname::set_nickname(std::string Nick)
{
CurrentNickname = Nick;
}
std::string Nickname::get_nickname()
{
return CurrentNickname;
}
void Nickname::handle_events(SDL_Event &Event)
{
while (SDL_PollEvent(&Event))
{
if (Event.type == SDL_KEYDOWN)
{
if (Event.key.keysym.sym == SDLK_BACKSPACE)
{
if (CurrentNickname.size() > 0)
CurrentNickname.erase(CurrentNickname.size()-1);
}
if (CurrentNickname.size() < 3)
{
int keystroke = Event.key.keysym.sym;
if ((Uint16)keystroke >= 97 && (Uint16)keystroke <= 122)
{
CurrentNickname += toupper((Uint16)keystroke);
}
}
else
{
if (Event.key.keysym.sym == SDLK_y)
{
set_nickname(CurrentNickname);
Running = false;
}
}
}
}
}
void Nickname::run_nickname()
{
Draw *d = new Draw();
while(Running)
{
SDL_FillRect(DisplaySurface, NULL, 0x000000);
d->draw_text(DisplaySurface, "Initials plz", 50, 100, -1, 51, 108, 184);
d->draw_text(DisplaySurface, CurrentNickname, 30, 200, -1, 255, 255, 0);
if (CurrentNickname.length() == 3)
{
d->draw_text(DisplaySurface, "Proceed with '"+ CurrentNickname +"'?", 20, 450, -1, 255, 0, 0);
d->draw_text(DisplaySurface, "Y / Backspace", 20, 500, -1, 255, 0, 255);
}
SDL_Delay(10);
SDL_Flip(DisplaySurface);
handle_events(Events);
}
delete d;
d = 0;
}