From 2fb86b741c4066bdd08de4510b42d5347c372a81 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Sun, 1 Jun 2014 18:26:53 +0100 Subject: [PATCH] Improve UI display --- rwgame/MenuSystem.hpp | 21 +++++++++++--------- rwgame/debugstate.cpp | 9 +++++---- rwgame/ingamestate.cpp | 2 +- rwgame/main.cpp | 45 +----------------------------------------- 4 files changed, 19 insertions(+), 58 deletions(-) diff --git a/rwgame/MenuSystem.hpp b/rwgame/MenuSystem.hpp index 34fd8f3c..d4ce2fc3 100644 --- a/rwgame/MenuSystem.hpp +++ b/rwgame/MenuSystem.hpp @@ -18,17 +18,20 @@ public: struct MenuEntry { std::string name; + float _size; - MenuEntry(const std::string& n) : name(n) {} + MenuEntry(const std::string& n, float size = 38.f) : name(n), _size(size) {} - float getHeight() { return 38.f; } + float getHeight() { return _size; } virtual void draw(const sf::Font& font, sf::RenderWindow& window, glm::vec2& basis) { sf::Text t; t.setFont(font); - t.setPosition(basis.x, basis.y); + t.setPosition(basis.x + 6, basis.y + 2); t.setString(name); + auto cSize = getHeight() - 10.f; + t.setCharacterSize(cSize); window.draw(t); basis.y += getHeight(); } @@ -40,15 +43,15 @@ public: { std::function callback; - Entry(const std::string& title, std::function cb) - : MenuEntry(title), callback(cb) {} + Entry(const std::string& title, std::function cb, float size) + : MenuEntry(title, size), callback(cb) {} void activate(float clickX, float clickY) { callback(); } }; - static std::shared_ptr lambda(const std::string& n, std::function callback) + static std::shared_ptr lambda(const std::string& n, std::function callback, float size = 38.f) { - return std::shared_ptr(new Entry(n, callback)); + return std::shared_ptr(new Entry(n, callback, size)); } std::vector> entries; @@ -73,7 +76,7 @@ public: ++i) { if(activeEntry >= 0 && i == activeEntry) { - sf::RectangleShape rs(sf::Vector2f(500.f, entries[i]->getHeight())); + sf::RectangleShape rs(sf::Vector2f(250.f, entries[i]->getHeight())); rs.setPosition(basis.x, basis.y); rs.setFillColor(sf::Color::Cyan); window.draw(rs); @@ -130,4 +133,4 @@ public: } }; -#endif \ No newline at end of file +#endif diff --git a/rwgame/debugstate.cpp b/rwgame/debugstate.cpp index fd0ee68b..a2e6f9fe 100644 --- a/rwgame/debugstate.cpp +++ b/rwgame/debugstate.cpp @@ -6,20 +6,21 @@ DebugState::DebugState() { Menu *m = new Menu(getFont()); m->offset = glm::vec2(50.f, 100.f); - m->addEntry(Menu::lambda("Create Vehicle", [this] { + float entryHeight = 24.f; + m->addEntry(Menu::lambda("Random Vehicle", [this] { auto it = getWorld()->vehicleTypes.begin(); std::uniform_int_distribution uniform(0, 3); for(size_t i = 0, n = uniform(getWorld()->randomEngine); i != n; i++) { it++; } spawnVehicle(it->first); - })); - int vehiclesMax = 5, i = 0; + }, entryHeight)); + int vehiclesMax = 16, i = 0; for( auto& v : getWorld()->vehicleTypes ) { if( (i++) > vehiclesMax ) break; m->addEntry(Menu::lambda(v.second->handlingID, [=] { spawnVehicle(v.first); - })); + }, entryHeight)); } this->enterMenu(m); } diff --git a/rwgame/ingamestate.cpp b/rwgame/ingamestate.cpp index bf975f5f..0925efe2 100644 --- a/rwgame/ingamestate.cpp +++ b/rwgame/ingamestate.cpp @@ -9,7 +9,7 @@ IngameState::IngameState() : _player(nullptr), _playerCharacter(nullptr) { - _playerCharacter = getWorld()->createPedestrian(1, {100.f, 100.f, 50.f}); + _playerCharacter = getWorld()->createPedestrian(1, {100.f, 100.f, 25.f}); _player = new GTAPlayerAIController(_playerCharacter); setPlayerCharacter( _playerCharacter ); diff --git a/rwgame/main.cpp b/rwgame/main.cpp index a8aa3985..e3e323a9 100644 --- a/rwgame/main.cpp +++ b/rwgame/main.cpp @@ -38,8 +38,6 @@ int debugMode = 0; sf::Font font; -bool showControls = false; - glm::vec3 viewPosition; glm::vec2 viewAngles; @@ -264,30 +262,6 @@ void handleCommandEvent(sf::Event &event) switch(event.type) { case sf::Event::KeyPressed: switch (event.key.code) { - case sf::Keyboard::F1: - showControls = !showControls; - break; - case sf::Keyboard::F2: - command("pedestrian-vehicle"); - break; - case sf::Keyboard::F3: - command("player-vehicle"); - break; - case sf::Keyboard::F4: - command("empty-vehicle"); - break; - case sf::Keyboard::F6: - command("vehicle-test"); - break; - case sf::Keyboard::F7: - command("pedestrian-test"); - break; - case sf::Keyboard::F8: - command("damage-object"); - break; - case sf::Keyboard::F9: - command("object-info"); - break; case sf::Keyboard::LBracket: gta->gameTime -= 60.f; break; @@ -428,17 +402,7 @@ void render() << ":" << std::setw(2) << gta->getMinute() << std::endl; ss << "Game Time: " << gta->gameTime << std::endl; ss << "Camera: " << viewPosition.x << " " << viewPosition.y << " " << viewPosition.z << std::endl; - - - if(showControls) { - ss << "F1 - Toggle Help" << std::endl; - ss << "F2 - Create Vehicle (with driver)" << std::endl; - ss << "F3 - Create Vehicle (with player)" << std::endl; - ss << "F4 - Create Vehicle (empty)" << std::endl; - ss << "F6 - Create all Vehicles" << std::endl; - ss << "F7 - Create all Pedestrians" << std::endl; - ss << "F9 - Display Object Information" << std::endl; - } + ss << "Renderered " << gta->renderer.rendered << " / " << gta->renderer.culled << std::endl; sf::Text text(ss.str(), font, 15); text.setPosition(10, 10); @@ -473,13 +437,6 @@ void render() window.draw(text); tpos.y -= text.getLocalBounds().height; } - - static size_t fc = 0; - if(fc++ == 60) - { - std::cout << "Rendered: " << gta->renderer.rendered << " / Culled: " << gta->renderer.culled << std::endl; - fc = 0; - } } std::string getGamePath()