1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 11:52:40 +01:00

Add HUD scaling config parameter

This commit is contained in:
Petar Kukolj 2018-10-26 22:04:09 +02:00 committed by Filip Gawin
parent 4940ae0d6b
commit 36f188611c
7 changed files with 95 additions and 25 deletions

View File

@ -169,11 +169,11 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
glm::vec2 plyblip(player->getPosition()); glm::vec2 plyblip(player->getPosition());
float hdg = glm::roll(player->getRotation()); float hdg = glm::roll(player->getRotation());
drawBlip(plyblip, view, mi, "radar_centre", drawBlip(plyblip, view, mi, "radar_centre",
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), 18.0f, mi.rotation - hdg); glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), defaultBlipSize, mi.rotation - hdg);
} }
drawBlip(mi.worldCenter + glm::vec2(0.f, mi.worldSize), view, mi, drawBlip(mi.worldCenter + glm::vec2(0.f, mi.worldSize), view, mi,
"radar_north", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), 24.f); "radar_north", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), radarNorthBlipSize);
for (auto& radarBlip : world->state->radarBlips) { for (auto& radarBlip : world->state->radarBlips) {
const auto& blip = radarBlip.second; const auto& blip = radarBlip.second;
@ -194,7 +194,7 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
const auto& texture = blip.texture; const auto& texture = blip.texture;
if (!texture.empty()) { if (!texture.empty()) {
drawBlip(blippos, view, mi, texture, drawBlip(blippos, view, mi, texture,
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), 18.0f); glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), defaultBlipSize);
} else { } else {
// Colours from http://www.gtamodding.com/wiki/0165 (colors not // Colours from http://www.gtamodding.com/wiki/0165 (colors not
// specific to that opcode!) // specific to that opcode!)
@ -232,7 +232,7 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
1.0f // Note: Alpha is not controlled by blip 1.0f // Note: Alpha is not controlled by blip
); );
drawBlip(blippos, view, mi, colour, blip.size * 2.0f); drawBlip(blippos, view, mi, colour, blip.size * otherBlipsScalingFactor * 2.0f);
} }
} }
@ -289,3 +289,9 @@ void MapRenderer::drawBlip(const glm::vec2& coord, const glm::mat4& view,
renderer->setUniform(rectProg.get(), "colour", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); renderer->setUniform(rectProg.get(), "colour", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
glDrawArrays(GL_LINE_LOOP, 0, 4); glDrawArrays(GL_LINE_LOOP, 0, 4);
} }
void MapRenderer::setHUDScale(const float scale) {
defaultBlipSize *= scale;
radarNorthBlipSize *= scale;
otherBlipsScalingFactor = scale;
}

View File

@ -39,6 +39,7 @@ public:
MapRenderer(std::shared_ptr<Renderer> renderer, GameData* data); MapRenderer(std::shared_ptr<Renderer> renderer, GameData* data);
void draw(GameWorld* world, const MapInfo& mi); void draw(GameWorld* world, const MapInfo& mi);
void setHUDScale(const float scale);
private: private:
GameData* data; GameData* data;
@ -50,6 +51,10 @@ private:
GeometryBuffer circleGeom; GeometryBuffer circleGeom;
DrawBuffer circle; DrawBuffer circle;
float radarNorthBlipSize = 24.f;
float defaultBlipSize = 18.f;
float otherBlipsScalingFactor = 1.f;
std::unique_ptr<Renderer::ShaderProgram> rectProg; std::unique_ptr<Renderer::ShaderProgram> rectProg;
void prepareBlip(const glm::vec2& coord, const glm::mat4& view, void prepareBlip(const glm::vec2& coord, const glm::mat4& view,

View File

@ -35,15 +35,29 @@ constexpr float ui_mapSize = 150.f;
constexpr float ui_worldSizeMin = 200.f; constexpr float ui_worldSizeMin = 200.f;
constexpr float ui_worldSizeMax = 300.f; constexpr float ui_worldSizeMax = 300.f;
static float hudScale = 1.f;
static float final_ui_textSize = ui_textSize;
static float final_ui_textHeight = ui_textHeight;
static float final_ui_elementMargin = ui_elementMargin;
static float final_ui_outerMargin = ui_outerMargin;
static float final_ui_infoMargin = ui_infoMargin;
static float final_ui_weaponSize = ui_weaponSize;
static float final_ui_ammoSize = ui_ammoSize;
static float final_ui_ammoHeight = ui_ammoHeight;
static float final_ui_wantedLevelHeight = ui_wantedLevelHeight;
static float final_ui_scriptTimerHeight = ui_scriptTimerHeight;
static float final_ui_armourOffset = ui_armourOffset;
static float final_ui_mapSize = ui_mapSize;
void drawScriptTimer(GameWorld* world, GameRenderer* render) { void drawScriptTimer(GameWorld* world, GameRenderer* render) {
if (world->state->scriptTimerVariable) { if (world->state->scriptTimerVariable) {
float scriptTimerTextX = static_cast<float>( float scriptTimerTextX = static_cast<float>(
render->getRenderer()->getViewport().x - ui_outerMargin); render->getRenderer()->getViewport().x - final_ui_outerMargin);
float scriptTimerTextY = ui_scriptTimerHeight; float scriptTimerTextY = final_ui_scriptTimerHeight;
TextRenderer::TextInfo ti; TextRenderer::TextInfo ti;
ti.font = FONT_PRICEDOWN; ti.font = FONT_PRICEDOWN;
ti.size = ui_textSize; ti.size = final_ui_textSize;
ti.align = TextRenderer::TextInfo::TextAlignment::Right; ti.align = TextRenderer::TextInfo::TextAlignment::Right;
{ {
@ -84,12 +98,12 @@ void drawMap(ViewCamera& currentView, PlayerController* player,
const glm::ivec2& vp = render->getRenderer()->getViewport(); const glm::ivec2& vp = render->getRenderer()->getViewport();
glm::vec2 mapTop = glm::vec2 mapTop =
glm::vec2(ui_outerMargin, vp.y - (ui_outerMargin + ui_mapSize)); glm::vec2(final_ui_outerMargin, vp.y - (final_ui_outerMargin + final_ui_mapSize));
glm::vec2 mapBottom = glm::vec2 mapBottom =
glm::vec2(ui_outerMargin + ui_mapSize, vp.y - ui_outerMargin); glm::vec2(final_ui_outerMargin + final_ui_mapSize, vp.y - final_ui_outerMargin);
map.screenPosition = (mapTop + mapBottom) / 2.f; map.screenPosition = (mapTop + mapBottom) / 2.f;
map.screenSize = ui_mapSize * 0.95f; map.screenSize = final_ui_mapSize * 0.95f;
render->map.draw(world, map); render->map.draw(world, map);
} }
@ -98,17 +112,17 @@ void drawMap(ViewCamera& currentView, PlayerController* player,
void drawPlayerInfo(PlayerController* player, GameWorld* world, void drawPlayerInfo(PlayerController* player, GameWorld* world,
GameRenderer* render) { GameRenderer* render) {
float infoTextX = static_cast<float>(render->getRenderer()->getViewport().x - float infoTextX = static_cast<float>(render->getRenderer()->getViewport().x -
(ui_outerMargin + ui_weaponSize + ui_infoMargin)); (final_ui_outerMargin + final_ui_weaponSize + ui_infoMargin));
float infoTextY = 0.f + ui_outerMargin; float infoTextY = 0.f + ui_outerMargin;
float iconX = static_cast<float>(render->getRenderer()->getViewport().x - float iconX = static_cast<float>(render->getRenderer()->getViewport().x -
(ui_outerMargin + ui_weaponSize)); (final_ui_outerMargin + final_ui_weaponSize));
float iconY = ui_outerMargin; float iconY = final_ui_outerMargin;
float wantedX = static_cast<float>(render->getRenderer()->getViewport().x - ui_outerMargin); float wantedX = static_cast<float>(render->getRenderer()->getViewport().x - final_ui_outerMargin);
float wantedY = ui_wantedLevelHeight; float wantedY = final_ui_wantedLevelHeight;
TextRenderer::TextInfo ti; TextRenderer::TextInfo ti;
ti.font = FONT_PRICEDOWN; ti.font = FONT_PRICEDOWN;
ti.size = ui_textSize; ti.size = final_ui_textSize;
ti.align = TextRenderer::TextInfo::TextAlignment::Right; ti.align = TextRenderer::TextInfo::TextAlignment::Right;
{ {
@ -128,7 +142,7 @@ void drawPlayerInfo(PlayerController* player, GameWorld* world,
render->text.renderText(ti); render->text.renderText(ti);
infoTextY += ui_textHeight; infoTextY += final_ui_textHeight;
{ {
std::stringstream ss; std::stringstream ss;
@ -147,7 +161,7 @@ void drawPlayerInfo(PlayerController* player, GameWorld* world,
ti.screenPosition = glm::vec2(infoTextX, infoTextY); ti.screenPosition = glm::vec2(infoTextX, infoTextY);
render->text.renderText(ti); render->text.renderText(ti);
infoTextY += ui_textHeight; infoTextY += final_ui_textHeight;
if ((world->state->hudFlash != HudFlash::FlashHealth && if ((world->state->hudFlash != HudFlash::FlashHealth &&
player->getCharacter()->getCurrentState().health > ui_lowHealth) || player->getCharacter()->getCurrentState().health > ui_lowHealth) ||
@ -178,11 +192,11 @@ void drawPlayerInfo(PlayerController* player, GameWorld* world,
ti.baseColour = ui_shadowColour; ti.baseColour = ui_shadowColour;
ti.screenPosition = ti.screenPosition =
glm::vec2(infoTextX + 1.f - ui_armourOffset, infoTextY + 1.f); glm::vec2(infoTextX + 1.f - final_ui_armourOffset, infoTextY + 1.f);
render->text.renderText(ti); render->text.renderText(ti);
ti.baseColour = ui_armourColour; ti.baseColour = ui_armourColour;
ti.screenPosition = glm::vec2(infoTextX - ui_armourOffset, infoTextY); ti.screenPosition = glm::vec2(infoTextX - final_ui_armourOffset, infoTextY);
render->text.renderText(ti); render->text.renderText(ti);
} }
@ -231,7 +245,7 @@ void drawPlayerInfo(PlayerController* player, GameWorld* world,
RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture"); RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture");
render->drawTexture( render->drawTexture(
itemTexture.get(), itemTexture.get(),
glm::vec4(iconX, iconY, ui_weaponSize, ui_weaponSize)); glm::vec4(iconX, iconY, final_ui_weaponSize, final_ui_weaponSize));
} }
if (weapon->fireType != WeaponData::MELEE) { if (weapon->fireType != WeaponData::MELEE) {
@ -263,10 +277,10 @@ void drawPlayerInfo(PlayerController* player, GameWorld* world,
ti.baseColour = ui_shadowColour; ti.baseColour = ui_shadowColour;
ti.font = FONT_ARIAL; ti.font = FONT_ARIAL;
ti.size = ui_ammoSize; ti.size = final_ui_ammoSize;
ti.align = TextRenderer::TextInfo::TextAlignment::Center; ti.align = TextRenderer::TextInfo::TextAlignment::Center;
ti.screenPosition = glm::vec2(iconX + ui_weaponSize / 2.f, ti.screenPosition = glm::vec2(iconX + final_ui_weaponSize / 2.f,
iconY + ui_weaponSize - ui_ammoHeight); iconY + final_ui_weaponSize - final_ui_ammoHeight);
render->text.renderText(ti); render->text.renderText(ti);
} }
} }
@ -292,7 +306,7 @@ void drawOnScreenText(GameWorld* world, GameRenderer* renderer) {
for (auto& l : alltext) { for (auto& l : alltext) {
for (auto& t : l) { for (auto& t : l) {
ti.size = static_cast<float>(t.size); ti.size = static_cast<float>(t.size * hudScale);
ti.font = t.font; ti.font = t.font;
ti.text = t.text; ti.text = t.text;
ti.wrapX = t.wrapX; ti.wrapX = t.wrapX;
@ -330,3 +344,19 @@ void drawOnScreenText(GameWorld* world, GameRenderer* renderer) {
} }
} }
} }
void setHUDScale(const float scale) {
hudScale = scale;
final_ui_textSize = ui_textSize * scale;
final_ui_textHeight = ui_textHeight * scale;
final_ui_elementMargin = ui_elementMargin * scale;
final_ui_outerMargin = ui_outerMargin * scale;
final_ui_infoMargin = ui_infoMargin * scale;
final_ui_weaponSize = ui_weaponSize * scale;
final_ui_ammoSize = ui_ammoSize * scale;
final_ui_ammoHeight = ui_ammoHeight * scale;
final_ui_wantedLevelHeight = ui_wantedLevelHeight * scale;
final_ui_scriptTimerHeight = ui_scriptTimerHeight * scale;
final_ui_armourOffset = ui_armourOffset * scale;
final_ui_mapSize = ui_mapSize * scale;
}

View File

@ -10,4 +10,6 @@ void drawHUD(ViewCamera& currentView, PlayerController* player,
void drawOnScreenText(GameWorld* world, GameRenderer* renderer); void drawOnScreenText(GameWorld* world, GameRenderer* renderer);
void setHUDScale(const float scale);
#endif #endif

View File

@ -129,6 +129,22 @@ struct IntTranslator {
} }
}; };
struct FloatTranslator {
typedef std::string internal_type;
typedef float external_type;
boost::optional<external_type> get_value(const internal_type &str) {
boost::optional<external_type> res;
try {
res = std::stof(stripComments(str));
} catch (std::invalid_argument &) {
}
return res;
}
boost::optional<internal_type> put_value(const external_type &f) {
return std::to_string(f);
}
};
GameConfig::ParseResult GameConfig::saveConfig() { GameConfig::ParseResult GameConfig::saveConfig() {
auto configPath = getConfigPath().string(); auto configPath = getConfigPath().string();
return parseConfig(ParseType::CONFIG, "", ParseType::FILE, configPath); return parseConfig(ParseType::CONFIG, "", ParseType::FILE, configPath);
@ -229,6 +245,7 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType,
auto boolt = BoolTranslator(); auto boolt = BoolTranslator();
auto patht = PathTranslator(); auto patht = PathTranslator();
auto intt = IntTranslator(); auto intt = IntTranslator();
auto floatt = FloatTranslator();
// Add new configuration parameters here. // Add new configuration parameters here.
// Additionally, add them to the unit test. // Additionally, add them to the unit test.
@ -237,6 +254,7 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType,
read_config("game.path", this->m_gamePath, "/opt/games/Grand Theft Auto 3", read_config("game.path", this->m_gamePath, "/opt/games/Grand Theft Auto 3",
patht, false); patht, false);
read_config("game.language", this->m_gameLanguage, "american", deft); read_config("game.language", this->m_gameLanguage, "american", deft);
read_config("game.hud_scale", this->m_HUDscale, 1.f, floatt);
read_config("input.invert_y", this->m_inputInvertY, false, boolt); read_config("input.invert_y", this->m_inputInvertY, false, boolt);

View File

@ -231,6 +231,9 @@ public:
bool getWindowFullscreen() const { bool getWindowFullscreen() const {
return m_windowFullscreen; return m_windowFullscreen;
} }
float getHUDScale() const {
return m_HUDscale;
}
static rwfs::path getDefaultConfigPath(); static rwfs::path getDefaultConfigPath();
private: private:
@ -272,6 +275,9 @@ private:
/// Set the window to fullscreen /// Set the window to fullscreen
bool m_windowFullscreen = false; bool m_windowFullscreen = false;
/// HUD scale parameter
float m_HUDscale = 1.f;
}; };
#endif #endif

View File

@ -108,6 +108,9 @@ RWGame::RWGame(Logger& log, int argc, char* argv[])
} }
}); });
setHUDScale(config.getHUDScale());
renderer.map.setHUDScale(config.getHUDScale());
log.info("Game", "Started"); log.info("Game", "Started");
RW_TIMELINE_LEAVE("Startup"); RW_TIMELINE_LEAVE("Startup");
} }