16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 14:49:19 +02:00

build 190514. partial usage of utf8 in the ui, timetable panel appeaance improvements

This commit is contained in:
tmj-fstate
2019-05-14 20:15:01 +02:00
parent 1626224dc8
commit 9cdce2d346
10 changed files with 144 additions and 55 deletions

View File

@@ -6595,17 +6595,18 @@ std::string TController::NextStop() const
// dodać godzinę odjazdu // dodać godzinę odjazdu
if (!TrainParams) if (!TrainParams)
return ""; // tu nie powinno nigdy wejść return ""; // tu nie powinno nigdy wejść
std::string nextstop = asNextStop; std::string nextstop = Bezogonkow( asNextStop, true );
TMTableLine *t = TrainParams->TimeTable + TrainParams->StationIndex; TMTableLine *t = TrainParams->TimeTable + TrainParams->StationIndex;
if( t->Ah >= 0 ) { if( t->Ah >= 0 ) {
// przyjazd // przyjazd
nextstop += " przyj." + std::to_string( t->Ah ) + ":" nextstop += " przyj." + std::to_string( t->Ah ) + ":"
+ ( t->Am < 10 ? "0" : "" ) + std::to_string( t->Am ); + to_minutes_str( t->Am, true, 3 );
} }
if( t->Dh >= 0 ) { if( t->Dh >= 0 ) {
// jeśli jest godzina odjazdu // jeśli jest godzina odjazdu
nextstop += " odj." + std::to_string( t->Dh ) + ":" nextstop += " odj." + std::to_string( t->Dh ) + ":"
+ ( t->Dm < 10 ? "0" : "" ) + std::to_string( t->Dm ); + to_minutes_str( t->Dm, true, 3 );
} }
return nextstop; return nextstop;
}; };

View File

@@ -229,6 +229,7 @@ timetable_panel::update() {
if( false == is_open ) { return; } if( false == is_open ) { return; }
text_lines.clear(); text_lines.clear();
m_tablelines.clear();
auto const *train { simulation::Train }; auto const *train { simulation::Train };
auto const *controlled { ( train ? train->Dynamic() : nullptr ) }; auto const *controlled { ( train ? train->Dynamic() : nullptr ) };
@@ -239,7 +240,7 @@ timetable_panel::update() {
std::snprintf( std::snprintf(
m_buffer.data(), m_buffer.size(), m_buffer.data(), m_buffer.size(),
locale::strings[ locale::string::driver_timetable_header ].c_str(), locale::strings[ locale::string::driver_timetable_header ].c_str(),
40, 40, 37, 37,
locale::strings[ locale::string::driver_timetable_name ].c_str(), locale::strings[ locale::string::driver_timetable_name ].c_str(),
time.wHour, time.wHour,
time.wMinute, time.wMinute,
@@ -274,7 +275,7 @@ timetable_panel::update() {
} }
{ // next station { // next station
auto const nextstation = Bezogonkow( owner->NextStop(), true ); auto const nextstation = owner->NextStop();
if( false == nextstation.empty() ) { if( false == nextstation.empty() ) {
// jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania // jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania
auto textline = " -> " + nextstation; auto textline = " -> " + nextstation;
@@ -317,67 +318,126 @@ timetable_panel::update() {
} }
else { else {
auto const loadingcolor { glm::vec4( 164.0f / 255.0f, 84.0f / 255.0f, 84.0f / 255.0f, 1.f ) };
auto const waitcolor { glm::vec4( 164.0f / 255.0f, 132.0f / 255.0f, 84.0f / 255.0f, 1.f ) };
auto const readycolor { glm::vec4( 84.0f / 255.0f, 164.0f / 255.0f, 132.0f / 255.0f, 1.f ) }; auto const readycolor { glm::vec4( 84.0f / 255.0f, 164.0f / 255.0f, 132.0f / 255.0f, 1.f ) };
// header // header
text_lines.emplace_back( "+-----+------------------------------------+-------+-----+", Global.UITextColor ); m_tablelines.emplace_back( u8"┌─────┬────────────────────────────────────┬─────────┬─────┐", Global.UITextColor );
TMTableLine const *tableline; TMTableLine const *tableline;
for( int i = owner->iStationStart; i <= table->StationCount; ++i ) { for( int i = owner->iStationStart; i <= table->StationCount; ++i ) {
// wyświetlenie pozycji z rozkładu // wyświetlenie pozycji z rozkładu
tableline = table->TimeTable + i; // linijka rozkładu tableline = table->TimeTable + i; // linijka rozkładu
std::string vmax = bool vmaxchange { true };
" " if( i > owner->iStationStart ) {
+ to_string( tableline->vmax, 0 ); auto const *previoustableline { tableline - 1 };
vmax = vmax.substr( vmax.size() - 3, 3 ); // z wyrównaniem do prawej if( tableline->vmax == previoustableline->vmax ) {
std::string const station = ( vmaxchange = false;
}
}
std::string vmax { " " };
if( true == vmaxchange ) {
vmax += to_string( tableline->vmax, 0 );
vmax = vmax.substr( vmax.size() - 3, 3 ); // z wyrównaniem do prawej
}
auto const station { (
Bezogonkow( tableline->StationName, true ) Bezogonkow( tableline->StationName, true )
+ " " ) + " " )
.substr( 0, 34 ); .substr( 0, 34 ) };
std::string const location = ( auto const location { (
( tableline->km > 0.0 ? ( tableline->km > 0.0 ?
to_string( tableline->km, 2 ) : to_string( tableline->km, 2 ) :
"" ) "" )
+ " " ) + " " )
.substr( 0, 34 - tableline->StationWare.size() ); .substr( 0, 34 - tableline->StationWare.size() ) };
std::string const arrival = ( auto const arrival { (
tableline->Ah >= 0 ? tableline->Ah >= 0 ?
to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Am ) ).substr( 1, 2 ) : to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Am, true, 3 ) :
" | " ); u8" " ) };
std::string const departure = ( auto const departure { (
tableline->Dh >= 0 ? tableline->Dh >= 0 ?
to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_string( int( 100 + tableline->Dm ) ).substr( 1, 2 ) : to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Dm, true, 3 ) :
" | " ); u8" " ) };
auto const candeparture = ( auto const candeparture { (
( owner->iStationStart < table->StationIndex ) ( owner->iStationStart < table->StationIndex )
&& ( i < table->StationIndex ) && ( i < table->StationIndex )
&& ( ( tableline->Ah < 0 ) // pass-through, always valid && ( ( tableline->Ah < 0 ) // pass-through, always valid
|| ( time.wHour * 60 + time.wMinute + time.wSecond * 0.0167 >= tableline->Dh * 60 + tableline->Dm ) ) ); || ( time.wHour * 60 + time.wMinute + time.wSecond * 0.0167 >= tableline->Dh * 60 + tableline->Dm ) ) ) };
auto traveltime = auto const loadchangeinprogress { ( ( static_cast<int>( std::ceil( -1.0 * owner->fStopTime ) ) ) > 0 ) };
" " auto const isatpassengerstop { ( true == owner->IsAtPassengerStop ) && ( vehicle->MoverParameters->Vel < 1.0 ) };
+ ( i < 2 ? "" : auto const traveltime { (
tableline->Ah >= 0 ? to_string( CompareTime( table->TimeTable[ i - 1 ].Dh, table->TimeTable[ i - 1 ].Dm, tableline->Ah, tableline->Am ), 0 ) : i < 2 ? " " :
to_string( std::max( 0.0, CompareTime( table->TimeTable[ i - 1 ].Dh, table->TimeTable[ i - 1 ].Dm, tableline->Dh, tableline->Dm ) - 0.5 ), 0 ) ); tableline->Ah >= 0 ? to_minutes_str( CompareTime( table->TimeTable[ i - 1 ].Dh, table->TimeTable[ i - 1 ].Dm, tableline->Ah, tableline->Am ), false, 3 ) :
traveltime = traveltime.substr( traveltime.size() - 3, 3 ); // z wyrównaniem do prawej to_minutes_str( std::max( 0.0, CompareTime( table->TimeTable[ i - 1 ].Dh, table->TimeTable[ i - 1 ].Dm, tableline->Dh, tableline->Dm ) - 0.5 ), false, 3 ) ) };
auto const linecolor { (
text_lines.emplace_back( ( i != owner->iStationStart ) ? Global.UITextColor :
( "| " + vmax + " | " + station + " | " + arrival + " | " + traveltime + " |" ), loadchangeinprogress ? loadingcolor :
( candeparture ? candeparture ? readycolor : // czas minął i odjazd był, to nazwa stacji będzie na zielono
readycolor :// czas minął i odjazd był, to nazwa stacji będzie na zielono isatpassengerstop ? waitcolor :
Global.UITextColor ) ); Global.UITextColor ) };
text_lines.emplace_back( m_tablelines.emplace_back(
( "| | " + location + tableline->StationWare + " | " + departure + " | |" ), ( u8"" + vmax + u8" " + station + u8"" + arrival + u8" " + traveltime + u8" " ),
( candeparture ? linecolor );
readycolor :// czas minął i odjazd był, to nazwa stacji będzie na zielono m_tablelines.emplace_back(
Global.UITextColor ) ); ( u8"│ │ " + location + tableline->StationWare + u8"" + departure + u8" │ │" ),
linecolor );
// divider/footer // divider/footer
text_lines.emplace_back( "+-----+------------------------------------+-------+-----+", Global.UITextColor ); if( i < table->StationCount ) {
auto const *nexttableline { tableline + 1 };
if( tableline->vmax == nexttableline->vmax ) {
m_tablelines.emplace_back( u8"│ ├────────────────────────────────────┼─────────┼─────┤", Global.UITextColor );
}
else {
m_tablelines.emplace_back( u8"├─────┼────────────────────────────────────┼─────────┼─────┤", Global.UITextColor );
}
}
else {
m_tablelines.emplace_back( u8"└─────┴────────────────────────────────────┴─────────┴─────┘", Global.UITextColor );
}
} }
} }
} // is_expanded } // is_expanded
} }
void
timetable_panel::render() {
if( false == is_open ) { return; }
if( true == text_lines.empty() ) { return; }
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
| ( size.x > 0 ? ImGuiWindowFlags_NoResize : 0 );
if( size.x > 0 ) {
ImGui::SetNextWindowSize( ImVec2( size.x, size.y ) );
}
if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2( size_min.x, size_min.y ), ImVec2( size_max.x, size_max.y ) );
}
auto const panelname { (
title.empty() ?
name :
title )
+ "###" + name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
for( auto const &line : text_lines ) {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() );
}
if( is_expanded ) {
ImGui::PushStyleVar( ImGuiStyleVar_ItemSpacing, ImVec2( 1, 0 ) );
for( auto const &line : m_tablelines ) {
ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() );
}
ImGui::PopStyleVar();
}
}
ImGui::End();
}
void void
debug_panel::update() { debug_panel::update() {

View File

@@ -50,12 +50,14 @@ public:
: ui_panel( Name, Isopen ) {} : ui_panel( Name, Isopen ) {}
void update() override; void update() override;
void render() override;
bool is_expanded{ false }; bool is_expanded{ false };
private: private:
// members // members
std::array<char, 256> m_buffer; std::array<char, 256> m_buffer;
std::vector<text_line> m_tablelines;
}; };
class debug_panel : public ui_panel { class debug_panel : public ui_panel {

View File

@@ -480,14 +480,14 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
{ {
if ((TimeTable[i].Ah >= 0)) if ((TimeTable[i].Ah >= 0))
{ {
adjustedtime = clamp_circular( TimeTable[i].Ah * 60 + TimeTable[i].Am + timeoffset, 24.0 * 60.0 ); // nowe minuty adjustedtime = clamp_circular<float>( TimeTable[i].Ah * 60 + TimeTable[i].Am + timeoffset, 24 * 60 ); // nowe minuty
TimeTable[i].Am = (int(60 * adjustedtime) % 3600) / 60.0; TimeTable[i].Am = (int(60 * adjustedtime) % 3600) / 60.f;
TimeTable[i].Ah = int((adjustedtime) / 60) % 24; TimeTable[i].Ah = int((adjustedtime) / 60) % 24;
} }
if ((TimeTable[i].Dh >= 0)) if ((TimeTable[i].Dh >= 0))
{ {
adjustedtime = clamp_circular( TimeTable[i].Dh * 60 + TimeTable[i].Dm + timeoffset, 24.0 * 60.0 ); // nowe minuty adjustedtime = clamp_circular<float>( TimeTable[i].Dh * 60 + TimeTable[i].Dm + timeoffset, 24 * 60 ); // nowe minuty
TimeTable[i].Dm = (int(60 * adjustedtime) % 3600) / 60.0; TimeTable[i].Dm = (int(60 * adjustedtime) % 3600) / 60.f;
TimeTable[i].Dh = int((adjustedtime) / 60) % 24; TimeTable[i].Dh = int((adjustedtime) / 60) % 24;
} }
} }

View File

@@ -24,18 +24,18 @@ static char const *hrsd = ".";
struct TMTableLine struct TMTableLine
{ {
double km; // kilometraz linii float km; // kilometraz linii
double vmax; // predkosc rozkladowa przed przystankiem float vmax; // predkosc rozkladowa przed przystankiem
// StationName:string[32]; //nazwa stacji ('_' zamiast spacji) // StationName:string[32]; //nazwa stacji ('_' zamiast spacji)
// StationWare:string[32]; //typ i wyposazenie stacji, oddz. przecinkami} // StationWare:string[32]; //typ i wyposazenie stacji, oddz. przecinkami}
std::string StationName; // nazwa stacji ('_' zamiast spacji) std::string StationName; // nazwa stacji ('_' zamiast spacji)
std::string StationWare; // typ i wyposazenie stacji, oddz. przecinkami} std::string StationWare; // typ i wyposazenie stacji, oddz. przecinkami}
int TrackNo; // ilosc torow szlakowych int TrackNo; // ilosc torow szlakowych
int Ah; int Ah;
double Am; // godz. i min. przyjazdu, -1 gdy bez postoju float Am; // godz. i min. przyjazdu, -1 gdy bez postoju
int Dh; int Dh;
double Dm; // godz. i min. odjazdu float Dm; // godz. i min. odjazdu
double tm; // czas jazdy do tej stacji w min. (z kolumny) float tm; // czas jazdy do tej stacji w min. (z kolumny)
TMTableLine() TMTableLine()
{ {
km = 0; km = 0;

View File

@@ -179,7 +179,7 @@ state_serializer::deserialize_atmo( cParser &Input, scene::scratch_data &Scratch
Global.fFogEnd = Global.fFogEnd =
clamp( clamp(
Random( std::min( fograngestart, fograngeend ), std::max( fograngestart, fograngeend ) ), Random( std::min( fograngestart, fograngeend ), std::max( fograngestart, fograngeend ) ),
100.0, 2000.0 ); 10.0, 2000.0 );
} }
std::string token { Input.getToken<std::string>() }; std::string token { Input.getToken<std::string>() };

View File

@@ -74,8 +74,15 @@ ui_layer::init( GLFWwindow *Window ) {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
static ImWchar const glyphranges[] = {
0x0020, 0x00FF, // ascii + extension
0x2070, 0x2079, // superscript
0x2500, 0x256C, // box drawings
0,
};
m_imguiio = &ImGui::GetIO(); m_imguiio = &ImGui::GetIO();
// m_imguiio->Fonts->AddFontFromFileTTF( "c:/windows/fonts/lucon.ttf", 13.0f ); m_imguiio->Fonts->AddFontFromFileTTF( "fonts/dejavusansmono.ttf", 13.0f, nullptr, &glyphranges[ 0 ] );
ImGui_ImplGlfw_InitForOpenGL( m_window, false ); ImGui_ImplGlfw_InitForOpenGL( m_window, false );
#ifdef EU07_USEIMGUIIMPLOPENGL2 #ifdef EU07_USEIMGUIIMPLOPENGL2

View File

@@ -1,4 +1,4 @@
/* /*
This Source Code Form is subject to the This Source Code Form is subject to the
terms of the Mozilla Public License, v. terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not 2.0. If a copy of the MPL was not
@@ -246,6 +246,24 @@ std::string to_hex_str( int const Value, int const Width )
return converter.str(); return converter.str();
}; };
char * const fractionlabels[] = { " ", u8"¹", u8"²", u8"³", u8"", u8"", u8"", u8"", u8"", u8"" };
std::string to_minutes_str( float const Minutes, bool const Leadingzero, int const Width ) {
float minutesintegral;
auto const minutesfractional { std::modf( Minutes, &minutesintegral ) };
auto const width { Width - 1 };
auto minutes = (
std::string( width - 1, ' ' )
+ ( Leadingzero ?
to_string( 100 + minutesintegral ).substr( 1, 2 ) :
to_string( minutesintegral, 0 ) ) );
return (
minutes.substr( minutes.size() - width, width )
+ fractionlabels[ static_cast<int>( std::floor( minutesfractional * 10 + 0.1 ) ) ] );
}
int stol_def(const std::string &str, const int &DefaultValue) { int stol_def(const std::string &str, const int &DefaultValue) {
int result { DefaultValue }; int result { DefaultValue };

View File

@@ -107,6 +107,7 @@ std::string to_string(double Value);
std::string to_string(double Value, int precision); std::string to_string(double Value, int precision);
std::string to_string(double Value, int precision, int width); std::string to_string(double Value, int precision, int width);
std::string to_hex_str( int const Value, int const width = 4 ); std::string to_hex_str( int const Value, int const width = 4 );
std::string to_minutes_str( float const Minutes, bool const Leadingzero, int const Width );
inline std::string to_string(bool Value) { inline std::string to_string(bool Value) {

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 19 #define VERSION_MAJOR 19
#define VERSION_MINOR 504 #define VERSION_MINOR 514
#define VERSION_REVISION 0 #define VERSION_REVISION 0