From 9c0749360ef875931d1e8daabe27c9d25930b680 Mon Sep 17 00:00:00 2001 From: Dru Date: Mon, 14 Oct 2019 20:19:47 +0200 Subject: [PATCH 1/2] Bionic power display in kJ, J, mJ --- data/json/bionics.json | 2 +- src/bionics_ui.cpp | 12 ++++++------ src/units.h | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/data/json/bionics.json b/data/json/bionics.json index 70dcb57f63f43..9d278ba11a511 100644 --- a/data/json/bionics.json +++ b/data/json/bionics.json @@ -632,7 +632,7 @@ "id": "bio_night", "type": "bionic", "name": "Artificial Night Generator", - "description": "When active, this bionic eliminates all light within a 15 tile radius through destructive interference.", + "description": "When active, this bionic eliminates all light within a 2 tile radius through destructive interference.", "occupied_bodyparts": [ [ "TORSO", 16 ] ], "flags": [ "BIONIC_TOGGLED" ], "act_cost": "9 kJ", diff --git a/src/bionics_ui.cpp b/src/bionics_ui.cpp index 745c2bb1bdffc..25a23dbf604ea 100644 --- a/src/bionics_ui.cpp +++ b/src/bionics_ui.cpp @@ -91,17 +91,17 @@ static std::string build_bionic_poweronly_string( const bionic &bio ) std::vector properties; if( bio_data.power_activate > 0_kJ ) { - properties.push_back( string_format( _( "%d kJ act" ), - units::to_kilojoule( bio_data.power_activate ) ) ); + properties.push_back( string_format( _( "%s act" ), + units::display( bio_data.power_activate ) ) ); } if( bio_data.power_deactivate > 0_kJ ) { - properties.push_back( string_format( _( "%d kJ deact" ), - units::to_kilojoule( bio_data.power_deactivate ) ) ); + properties.push_back( string_format( _( "%s deact" ), + units::display( bio_data.power_deactivate ) ) ); } if( bio_data.charge_time > 0 && bio_data.power_over_time > 0_kJ ) { properties.push_back( bio_data.charge_time == 1 - ? string_format( _( "%d kJ/turn" ), units::to_kilojoule( bio_data.power_over_time ) ) - : string_format( _( "%d kJ/%d turns" ), units::to_kilojoule( bio_data.power_over_time ), + ? string_format( _( "%s/turn" ), units::display( bio_data.power_over_time ) ) + : string_format( _( "%s/%d turns" ), units::display( bio_data.power_over_time ), bio_data.charge_time ) ); } if( bio_data.toggled ) { diff --git a/src/units.h b/src/units.h index dcc5afa8be355..315a274b31b3f 100644 --- a/src/units.h +++ b/src/units.h @@ -488,6 +488,20 @@ inline std::ostream &operator<<( std::ostream &o, const quantity= 1 && float( j ) / kj == 1000 ) { // at least 1 kJ and there is no fraction + return string_format( "%d kJ", kj ); + } + const int mj = units::to_millijoule( v ); + if( j >= 1 && float( mj ) / j == 1000 ) { // at least 1 J and there is no fraction + return string_format( "%d J", j ); + } + return string_format( "%d mJ", mj ); +} + } // namespace units // Implicitly converted to volume, which has int as value_type! From 0e15abefae3eb271910d6f4b624bb16f572dcc2e Mon Sep 17 00:00:00 2001 From: Dru Date: Mon, 14 Oct 2019 22:39:14 +0200 Subject: [PATCH 2/2] translatable untis --- src/units.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/units.h b/src/units.h index 315a274b31b3f..9d9d64f4b6918 100644 --- a/src/units.h +++ b/src/units.h @@ -9,6 +9,7 @@ #include "calendar.h" #include "json.h" +#include "translations.h" namespace units { @@ -493,13 +494,13 @@ inline const std::string display( const units::energy v ) const int kj = units::to_kilojoule( v ); const int j = units::to_joule( v ); if( kj >= 1 && float( j ) / kj == 1000 ) { // at least 1 kJ and there is no fraction - return string_format( "%d kJ", kj ); + return to_string( kj ) + ' ' + pgettext( "energy unit: kilojoule", "kJ" ); } const int mj = units::to_millijoule( v ); if( j >= 1 && float( mj ) / j == 1000 ) { // at least 1 J and there is no fraction - return string_format( "%d J", j ); + return to_string( j ) + ' ' + pgettext( "energy unit: joule", "J" ); } - return string_format( "%d mJ", mj ); + return to_string( mj ) + ' ' + pgettext( "energy unit: millijoule", "mJ" ); } } // namespace units