Kukatz 3D  0.1
Török Attila szakdolgozata
projects/Kukatz 3D/src/playergui.cpp
00001 /*
00002  * playergui.cpp - Kukatz 3D
00003  * Copyright (c) 2011 - TÖRÖK Attila (torokati44@gmail.com)
00004  *
00005  * This software is provided 'as-is', without any express or implied
00006  * warranty. In no event will the authors be held liable for any damages
00007  * arising from the use of this software.
00008  *
00009  * Permission is granted to anyone to use this software for any purpose,
00010  * including commercial applications, and to alter it and redistribute it
00011  * freely, subject to the following restrictions:
00012  *
00013  *       1. The origin of this software must not be misrepresented; you must not
00014  *                      claim that you wrote the original software. If you use this software
00015  *                      in a product, an acknowledgment in the product documentation would be
00016  *                      appreciated but is not required.
00017  *
00018  *       2. Altered source versions must be plainly marked as such, and must not be
00019  *                      misrepresented as being the original software.
00020  *
00021  *       3. This notice may not be removed or altered from any source
00022  *                      distribution.
00023  */
00024 
00025 #include "playergui.hpp"
00026 
00027 #include <sstream>
00028 
00029 #include "guistring.hpp"
00030 #include "misc.hpp"
00031 #include "guiimage.hpp"
00032 
00033 PlayerGUI::PlayerGUI(Player* p_ptr):
00034         player_ptr(p_ptr)
00035 {
00036         smallrect = new GUIElementContainer(2.0f);
00037         attach(smallrect, 0.3f, GUIElement::SCALE_MODE_SMALLER, 0.04f, 0.96f);
00038         
00039         smallrect->attach(new GUIImage("HUD"), 1.1f, GUIElement::SCALE_MODE_SMALLER, 0.5f, 0.5f);
00040         
00041         GUIString* str = new GUIString(p_ptr->name, "#44");
00042         smallrect->attach(str, 0.25f, GUIElement::SCALE_MODE_VERTICAL, 0.5f, 1.0f);
00043         
00044         str = new GUIString(L"Pontszám:", "#44");
00045         smallrect->attach(str, 0.25f, GUIElement::SCALE_MODE_VERTICAL, 0.0f, 0.67f);
00046         
00047         str = new GUIString(L"Hosszúság:", "#44");
00048         smallrect->attach(str, 0.25f, GUIElement::SCALE_MODE_VERTICAL, 0.0f, 0.33f);
00049         
00050         str = new GUIString(L"Sebesség:", "#44");
00051         smallrect->attach(str, 0.25f, GUIElement::SCALE_MODE_VERTICAL, 0.0f, 0.0f);
00052         
00053         str = new GUIString("", "#44");
00054         smallrect->attach(str, 0.25f, GUIElement::SCALE_MODE_VERTICAL, 1.0f, 0.67f);
00055         
00056         str = new GUIString("", "#44");
00057         smallrect->attach(str, 0.25f, GUIElement::SCALE_MODE_VERTICAL, 1.0f, 0.33f);
00058         
00059         str = new GUIString("", "#44");
00060         smallrect->attach(str, 0.25f, GUIElement::SCALE_MODE_VERTICAL, 1.0f, 0.0f);
00061 }
00062 
00063 void PlayerGUI::update(float) // delta time not needed...
00064 {
00065         GUIString* str = dynamic_cast< GUIString* >(smallrect->children[1]);
00066         if (str)
00067         {
00068                 str->set_text(player_ptr->name);
00069                 
00070                 str->set_color(player_ptr->kukac_ptr->is_alive()?sf::Color::Red:sf::Color(128, 128, 128));
00071         }
00072         
00073         std::wstringstream ss;
00074         
00075         ss << (int)round(player_ptr->score);
00076         str = dynamic_cast< GUIString* >(smallrect->children[5]);
00077         if (str)
00078         {
00079                 str->set_text(ss.str());
00080         }
00081         
00082         ss.clear();
00083         ss.str(L"");
00084         
00085         if (player_ptr->kukac_ptr->get_growth())
00086         {
00087                 ss << L"\xC\xCC\xCC\xCC\xCC" << player_ptr->kukac_ptr->get_growth() << L"+\t\xE";
00088         }
00089         
00090         ss << player_ptr->kukac_ptr->get_length();
00091         
00092         str = dynamic_cast< GUIString* >(smallrect->children[6]);
00093         if (str)
00094         {
00095                 str->set_text(ss.str());
00096         }
00097         
00098         ss.clear();
00099         ss.str(L"");
00100         ss << player_ptr->kukac_ptr->get_speed();
00101         str = dynamic_cast< GUIString* >(smallrect->children[7]);
00102         if (str)
00103         {
00104                 str->set_text(ss.str());
00105         }
00106 }
00107 
00108 PlayerGUI::~PlayerGUI()
00109 {
00110         
00111 }
 Összes Osztályok