![]() |
Kukatz 3D
0.1
Török Attila szakdolgozata
|
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 "summarygui.hpp" 00026 00027 #include <sstream> 00028 00029 #include "guistring.hpp" 00030 #include "misc.hpp" 00031 #include "guiimage.hpp" 00032 00033 SummaryGUI::SummaryGUI(const std::vector< Player* >& p): 00034 players(p) 00035 { 00036 smallrect = new GUIElementContainer(4.0f / 3.0f); 00037 attach(smallrect, 0.75f, GUIElement::SCALE_MODE_SMALLER, 0.5f, 0.5f); 00038 00039 smallrect->attach(new GUIImage("GUI_BIG"), 1.05f, GUIElement::SCALE_MODE_SMALLER, 0.5f, 0.5f); 00040 smallrect->children.back()->aspect_ratio = 4.0f / 3.0f; 00041 00042 for (unsigned int i = 0; i < players.size(); ++i) 00043 { 00044 GUIString* str_ptr = new GUIString("", "#44"); 00045 str_ptr->set_color(sf::Color::Red); 00046 smallrect->attach(str_ptr, 0.1f, 00047 GUIElement::SCALE_MODE_VERTICAL, 0.5, 1.0f - (float)(2 * i) / 9.0f); 00048 00049 float y = 1.0f - (float)(2 * i + 1) / 9.0f; 00050 00051 smallrect->attach(new GUIString("", "#44"), 0.1f, 00052 GUIElement::SCALE_MODE_VERTICAL, 0, y); 00053 00054 smallrect->attach(new GUIString("", "#44"), 0.1f, 00055 GUIElement::SCALE_MODE_VERTICAL, 0.55f, y, 1, y); 00056 00057 smallrect->attach(new GUIString("", "#44"), 0.1f, 00058 GUIElement::SCALE_MODE_VERTICAL, 1, y); 00059 } 00060 00061 update(0); // HACKY, but works 00062 } 00063 00064 void SummaryGUI::update(float) // delta time not needed... 00065 { 00066 for (unsigned int i = 0; i < players.size() - 1; ++i) 00067 { 00068 for (unsigned int j = i + 1; j < players.size(); ++j) 00069 { 00070 if (players[j]->score > players[i]->score) 00071 { 00072 std::swap(players[i], players[j]); 00073 } 00074 } 00075 } 00076 00077 for (unsigned int i = 0; i < players.size(); ++i) 00078 { 00079 GUIString* str = dynamic_cast< GUIString* >(smallrect->children[1 + i * 4]); 00080 if (str) 00081 { 00082 str->set_text(players[i]->name); 00083 str->set_color(players[i]->kukac_ptr->is_alive()?sf::Color::Red:(sf::Color(128, 128, 128))); 00084 } 00085 00086 std::wstringstream ss; 00087 00088 ss << (int)round(players[i]->score); 00089 str = dynamic_cast< GUIString* >(smallrect->children[2 + i * 4]); 00090 if (str) 00091 { 00092 str->set_text(ss.str()); 00093 } 00094 00095 ss.clear(); 00096 ss.str(L""); 00097 00098 if (players[i]->kukac_ptr->get_growth()) 00099 { 00100 ss << L"\xC\xCC\xCC\xCC\xCC" << players[i]->kukac_ptr->get_growth() << L"+\t\xE"; 00101 } 00102 00103 ss << players[i]->kukac_ptr->get_length(); 00104 00105 str = dynamic_cast< GUIString* >(smallrect->children[3 + i * 4]); 00106 if (str) 00107 { 00108 str->set_text(ss.str()); 00109 } 00110 00111 ss.clear(); 00112 ss.str(L""); 00113 ss << players[i]->kukac_ptr->get_speed(); 00114 str = dynamic_cast< GUIString* >(smallrect->children[4 + i * 4]); 00115 if (str) 00116 { 00117 str->set_text(ss.str()); 00118 } 00119 } 00120 } 00121 00122 SummaryGUI::~SummaryGUI() 00123 { 00124 00125 }