99#include " game/Download.h"
1010
1111ProfileViewer::ProfileViewer (std::string profileName):
12- Window_(Point(CENTERED, CENTERED), Point(200 , 300 )),
12+ Window_(Point(CENTERED, CENTERED), Point(250 , 300 )),
1313 name(profileName),
14+ avatar(NULL ),
1415 ageLabel(NULL ),
1516 websiteLabel(NULL ),
1617 biographyLabel(NULL )
1718{
18- profileInfoDownload = new Download (" http://" SERVER " /User.json?Name=" + profileName );
19+ profileInfoDownload = new Download (" http://" SERVER " /User.json?Name=" + name );
1920 // profileInfoDownload->AuthHeaders();
2021 profileInfoDownload->Start ();
2122
22- usernameLabel = new Label (Point (8 , 7 ), Point (Label::AUTOSIZE, Label::AUTOSIZE), profileName);
23+ avatarDownload = new Download (" http://" STATICSERVER " /avatars/" + name + " .pti" );
24+ avatarDownload->Start ();
25+
26+ usernameLabel = new Label (Point (8 , 7 ), Point (Label::AUTOSIZE, Label::AUTOSIZE), name);
2327 this ->AddComponent (usernameLabel);
2428 MainLoop ();
2529}
2630
2731ProfileViewer::~ProfileViewer ()
2832{
29- delete usernameLabel;
30- delete ageLabel;
31- delete websiteLabel;
32- delete biographyLabel;
33+ free (avatar);
3334}
3435
3536// To be removed later when there is a main engine loop for the entire game
@@ -45,8 +46,7 @@ void ProfileViewer::OnTick(float dt)
4546{
4647 if (profileInfoDownload && profileInfoDownload->CheckDone ())
4748 {
48- int length, status;
49- char *data = profileInfoDownload->Finish (&length, &status);
49+ char *data = profileInfoDownload->Finish (NULL , NULL );
5050
5151 json::Object parsed = ParseJSON (data);
5252
@@ -55,20 +55,41 @@ void ProfileViewer::OnTick(float dt)
5555 converter << ((json::Number)parsed[" User" ][" Age" ]).Value ();
5656 std::string age = converter.str ();
5757
58- ageLabel = new Label (Point (30 , 19 ), Point (Label::AUTOSIZE, Label::AUTOSIZE), age, true );
59- websiteLabel = new Label (Point (50 , 31 ), Point (Label::AUTOSIZE, Label::AUTOSIZE), ((json::String)parsed[" User" ][" Website" ]).Value (), true );
60- biographyLabel = new Label (Point (8 , 43 ), Point (180 , Label::AUTOSIZE), ((json::String)parsed[" User" ][" Biography" ]).Value (), true );
58+ ageLabel = new Label (Point (30 , 19 ), Point (Label::AUTOSIZE, Label::AUTOSIZE), age);
59+ websiteLabel = new Label (Point (50 , 31 ), Point (Label::AUTOSIZE, Label::AUTOSIZE), ((json::String)parsed[" User" ][" Website" ]).Value ());
60+ biographyLabel = new Label (Point (8 , 43 ), Point (230 , Label::AUTOSIZE), ((json::String)parsed[" User" ][" Biography" ]).Value (), true );
6161 this ->AddComponent (ageLabel);
6262 this ->AddComponent (websiteLabel);
6363 this ->AddComponent (biographyLabel);
6464
65- delete data;
65+ free ( data) ;
6666 profileInfoDownload = NULL ;
6767 }
68+
69+ if (avatarDownload && avatarDownload->CheckDone ())
70+ {
71+ int length;
72+ char *data = avatarDownload->Finish (&length, NULL );
73+ if (data)
74+ {
75+ int w, h;
76+ avatar = ptif_unpack (data, length, &w, &h);
77+ if (w != 40 || h != 40 )
78+ {
79+ free (avatar);
80+ avatar = NULL ;
81+ }
82+ }
83+
84+ free (data);
85+ avatarDownload = NULL ;
86+ }
6887}
6988
7089void ProfileViewer::OnDraw (VideoBuffer *buf)
7190{
91+ if (avatar)
92+ buf->DrawImage (avatar, 200 , 10 , 40 , 40 );
7293 buf->DrawText (10 , 22 , " Age:" , 175 , 175 , 175 , 255 );
7394 buf->DrawText (10 , 34 , " Website:" , 175 , 175 , 175 , 255 );
7495 buf->DrawText (10 , 46 , " Biography:" , 175 , 175 , 175 , 255 );
0 commit comments