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:
parent
6d604ffec0
commit
2fb86b741c
@ -18,17 +18,20 @@ public:
|
|||||||
struct MenuEntry
|
struct MenuEntry
|
||||||
{
|
{
|
||||||
std::string name;
|
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)
|
virtual void draw(const sf::Font& font, sf::RenderWindow& window, glm::vec2& basis)
|
||||||
{
|
{
|
||||||
sf::Text t;
|
sf::Text t;
|
||||||
t.setFont(font);
|
t.setFont(font);
|
||||||
t.setPosition(basis.x, basis.y);
|
t.setPosition(basis.x + 6, basis.y + 2);
|
||||||
t.setString(name);
|
t.setString(name);
|
||||||
|
auto cSize = getHeight() - 10.f;
|
||||||
|
t.setCharacterSize(cSize);
|
||||||
window.draw(t);
|
window.draw(t);
|
||||||
basis.y += getHeight();
|
basis.y += getHeight();
|
||||||
}
|
}
|
||||||
@ -40,15 +43,15 @@ public:
|
|||||||
{
|
{
|
||||||
std::function<void (void)> callback;
|
std::function<void (void)> callback;
|
||||||
|
|
||||||
Entry(const std::string& title, std::function<void (void)> cb)
|
Entry(const std::string& title, std::function<void (void)> cb, float size)
|
||||||
: MenuEntry(title), callback(cb) {}
|
: MenuEntry(title, size), callback(cb) {}
|
||||||
|
|
||||||
void activate(float clickX, float clickY) { callback(); }
|
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;
|
std::vector<std::shared_ptr<MenuEntry>> entries;
|
||||||
@ -73,7 +76,7 @@ public:
|
|||||||
++i)
|
++i)
|
||||||
{
|
{
|
||||||
if(activeEntry >= 0 && i == activeEntry) {
|
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.setPosition(basis.x, basis.y);
|
||||||
rs.setFillColor(sf::Color::Cyan);
|
rs.setFillColor(sf::Color::Cyan);
|
||||||
window.draw(rs);
|
window.draw(rs);
|
||||||
@ -130,4 +133,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,20 +6,21 @@ DebugState::DebugState()
|
|||||||
{
|
{
|
||||||
Menu *m = new Menu(getFont());
|
Menu *m = new Menu(getFont());
|
||||||
m->offset = glm::vec2(50.f, 100.f);
|
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();
|
auto it = getWorld()->vehicleTypes.begin();
|
||||||
std::uniform_int_distribution<int> uniform(0, 3);
|
std::uniform_int_distribution<int> uniform(0, 3);
|
||||||
for(size_t i = 0, n = uniform(getWorld()->randomEngine); i != n; i++) {
|
for(size_t i = 0, n = uniform(getWorld()->randomEngine); i != n; i++) {
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
spawnVehicle(it->first);
|
spawnVehicle(it->first);
|
||||||
}));
|
}, entryHeight));
|
||||||
int vehiclesMax = 5, i = 0;
|
int vehiclesMax = 16, i = 0;
|
||||||
for( auto& v : getWorld()->vehicleTypes ) {
|
for( auto& v : getWorld()->vehicleTypes ) {
|
||||||
if( (i++) > vehiclesMax ) break;
|
if( (i++) > vehiclesMax ) break;
|
||||||
m->addEntry(Menu::lambda(v.second->handlingID, [=] {
|
m->addEntry(Menu::lambda(v.second->handlingID, [=] {
|
||||||
spawnVehicle(v.first);
|
spawnVehicle(v.first);
|
||||||
}));
|
}, entryHeight));
|
||||||
}
|
}
|
||||||
this->enterMenu(m);
|
this->enterMenu(m);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
IngameState::IngameState()
|
IngameState::IngameState()
|
||||||
: _player(nullptr), _playerCharacter(nullptr)
|
: _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);
|
_player = new GTAPlayerAIController(_playerCharacter);
|
||||||
|
|
||||||
setPlayerCharacter( _playerCharacter );
|
setPlayerCharacter( _playerCharacter );
|
||||||
|
@ -38,8 +38,6 @@ int debugMode = 0;
|
|||||||
|
|
||||||
sf::Font font;
|
sf::Font font;
|
||||||
|
|
||||||
bool showControls = false;
|
|
||||||
|
|
||||||
glm::vec3 viewPosition;
|
glm::vec3 viewPosition;
|
||||||
glm::vec2 viewAngles;
|
glm::vec2 viewAngles;
|
||||||
|
|
||||||
@ -264,30 +262,6 @@ void handleCommandEvent(sf::Event &event)
|
|||||||
switch(event.type) {
|
switch(event.type) {
|
||||||
case sf::Event::KeyPressed:
|
case sf::Event::KeyPressed:
|
||||||
switch (event.key.code) {
|
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:
|
case sf::Keyboard::LBracket:
|
||||||
gta->gameTime -= 60.f;
|
gta->gameTime -= 60.f;
|
||||||
break;
|
break;
|
||||||
@ -428,17 +402,7 @@ void render()
|
|||||||
<< ":" << std::setw(2) << gta->getMinute() << std::endl;
|
<< ":" << std::setw(2) << gta->getMinute() << std::endl;
|
||||||
ss << "Game Time: " << gta->gameTime << std::endl;
|
ss << "Game Time: " << gta->gameTime << std::endl;
|
||||||
ss << "Camera: " << viewPosition.x << " " << viewPosition.y << " " << viewPosition.z << std::endl;
|
ss << "Camera: " << viewPosition.x << " " << viewPosition.y << " " << viewPosition.z << std::endl;
|
||||||
|
ss << "Renderered " << gta->renderer.rendered << " / " << gta->renderer.culled << 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::Text text(ss.str(), font, 15);
|
sf::Text text(ss.str(), font, 15);
|
||||||
text.setPosition(10, 10);
|
text.setPosition(10, 10);
|
||||||
@ -473,13 +437,6 @@ void render()
|
|||||||
window.draw(text);
|
window.draw(text);
|
||||||
tpos.y -= text.getLocalBounds().height;
|
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()
|
std::string getGamePath()
|
||||||
|
Loading…
Reference in New Issue
Block a user