1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Improve UI display

This commit is contained in:
Daniel Evans 2014-06-01 18:26:53 +01:00
parent 6d604ffec0
commit 2fb86b741c
4 changed files with 19 additions and 58 deletions

View File

@ -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<void (void)> callback;
Entry(const std::string& title, std::function<void (void)> cb)
: MenuEntry(title), callback(cb) {}
Entry(const std::string& title, std::function<void (void)> cb, float size)
: MenuEntry(title, size), callback(cb) {}
void activate(float clickX, float clickY) { callback(); }
};
static std::shared_ptr<MenuEntry> lambda(const std::string& n, std::function<void (void)> callback)
static std::shared_ptr<MenuEntry> lambda(const std::string& n, std::function<void (void)> callback, float size = 38.f)
{
return std::shared_ptr<MenuEntry>(new Entry(n, callback));
return std::shared_ptr<MenuEntry>(new Entry(n, callback, size));
}
std::vector<std::shared_ptr<MenuEntry>> 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
#endif

View File

@ -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<int> 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);
}

View File

@ -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 );

View File

@ -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()