Kukatz 3D  0.1
Török Attila szakdolgozata
projects/Kukatz 3D/src/highscores.cpp
00001 /*
00002  * highscores.cpp - Kukatz 3D
00003  * Copyright (c) 2012 - 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 "highscores.hpp"
00026 
00027 #include <cstdio>
00028 
00029 #include "guiimage.hpp"
00030 #include "scoremanager.hpp"
00031 
00032 HighScores::HighScores(unsigned int w, unsigned int h):
00033         StateBase(w, h), viewport(w, h)
00034 {
00035         resize(sf::Vector2i(w, h));
00036         
00037         gui.attach(new GUIImage("GROUND_2", 0.5f), 1, GUIElement::SCALE_MODE_BIGGER, 0.5f, 0.5f);
00038         
00039         title = new GUIString(L"Toplista", "#44");
00040         
00041         GUIElementContainer* square = new GUIElementContainer(4.0f / 3.0f);
00042         gui.attach(square, 1.0f, GUIElement::SCALE_MODE_SMALLER, 0.5f, 0.5f);
00043         
00044         square->attach(title, 0.2, GUIString::SCALE_MODE_VERTICAL, 0.5, 1);
00045         
00046         table = new GUIElementContainer(1.2f);
00047         square->attach(table, 0.8, GUIElement::SCALE_MODE_VERTICAL, 0.5, 0.1);
00048         
00049         const std::vector< std::pair< sf::Unicode::Text, sf::Uint32 > >& scores =
00050                 ScoreManager::instance().get_scores();
00051         
00052         for (unsigned int i = 0; i < scores.size(); ++i)
00053         {
00054                 table->attach(new GUIString(scores[i].first, "#44"), 1.0f / 10.0f,
00055                         GUIElement::SCALE_MODE_VERTICAL, 0.0f,
00056                         1.0f - ((float)i / 9.0f));
00057                 
00058                 char buffer[32];
00059                 sprintf(buffer, "%d", scores[i].second);
00060                 
00061                 table->attach(new GUIString(buffer, "#44"), 1.0f / 10.0f,
00062                         GUIElement::SCALE_MODE_VERTICAL, 1.0f,
00063                         1.0f - ((float)i / 9.0f));
00064         }
00065 }
00066 
00067 void HighScores::process_events(std::vector<sf::Event>& events)
00068 {
00069         for (unsigned int i = 0; i < events.size(); ++i)
00070         {
00071                 switch (events[i].Type)
00072                 {
00073                         case sf::Event::KeyPressed:
00074                         {
00075                                 switch (events[i].Key.Code)
00076                                 {
00077                                         case sf::Key::Return:
00078                                         case sf::Key::Escape:
00079                                         {
00080                                                 pop();
00081                                         }
00082                                         break;
00083                                         default:
00084                                         {
00085                                                 
00086                                         }
00087                                         break;
00088                                 }
00089                         }
00090                         break;
00091                         default:
00092                         {
00093                                 
00094                         }
00095                         break;
00096                 }
00097         }
00098 }
00099 
00100 void HighScores::render()
00101 {
00102         viewport.look_2d();
00103         gui.render();
00104 }
00105 
00106 void HighScores::update(float)
00107 {
00108         
00109 }
00110 
00111 void HighScores::resize(const sf::Vector2i& s)
00112 {
00113         size = s;
00114         viewport.size = s;
00115         gui.size = s;
00116 }
00117 
00118 HighScores::~HighScores()
00119 {
00120         
00121 }
 Összes Osztályok