18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 23:57:09 +01:00
Files
maszyna/application/uitranscripts.cpp
jerrrrycho 4e0c2f71bb feat(ui): names and texts of the data shown with their letters
MaSzyna-EU07/maszyna#94. What the panels took the marks off, they show as written, in utf-8:

- timetable panel: the relation, the train, the station rows (the column cut and filled by characters, a
  letter being more than one byte now)
- transcripts of the sounds and the assignment of a trainset, which lost their polish letters when read
- debug panel (event of the current signal, scan table) and the editor panels (names of nodes, layers,
  events, tracks and include files), which went through Bezogonkow()

Bezogonkow() and win1250_to_ascii() are left where the ascii form is what is wanted: file names, the python
dictionary, the multiplayer packets, the search key of the editor's station list.
2026-11-18 23:50:07 +01:00

94 lines
3.2 KiB
C++

#include "stdafx.h"
#include "application/uitranscripts.h"
#include "utilities/Globals.h"
#include "utilities/parser.h"
#include "utilities/utilities.h"
namespace ui {
TTranscripts Transcripts;
// dodanie linii do tabeli, (show) i (hide) w [s] od aktualnego czasu
void
TTranscripts::AddLine( std::string_view txt, float show, float hide, bool it ) {
if( show == hide ) { return; } // komentarz jest ignorowany
// TODO: replace the timeangledeg mess with regular time points math
show = static_cast<float>(Global.fTimeAngleDeg + show / 240.0); // jeśli doba to 360, to 1s będzie równe 1/240
hide = static_cast<float>(Global.fTimeAngleDeg + hide / 240.0);
TTranscript transcript;
transcript.asText = txt;
std::ranges::replace(transcript.asText, '|', ' '); // NOTE: legacy transcript lines use | as new line mark
transcript.fShow = show;
transcript.fHide = hide;
transcript.bItalic = it;
aLines.emplace_back( transcript );
// set the next refresh time while at it
// TODO, TBD: sort the transcript lines? in theory, they should be coming arranged in the right order anyway
// short of cases with multiple sounds overleaping
fRefreshTime = aLines.front().fHide;
}
// dodanie tekstów, długość dźwięku, czy istotne
void
TTranscripts::Add( std::string const &txt, bool /*backgorund*/ ) {
if( true == txt.empty() ) { return; }
// the captions are read as their files have them (windows-1250, the newer ones utf-8) and shown with their letters
cParser parser( txt );
while( true == parser.getTokens( 3, false, "[]\n" ) ) {
float begin{ 0.f };
float end{ 0.f };
std::string transcript;
parser
>> begin
>> end
>> transcript;
AddLine( data_text_to_utf8( transcript ), static_cast<float>(0.10 * begin), static_cast<float>(0.12 * end), false );
}
// try to handle malformed(?) cases with no show/hide times
std::string transcript; parser >> transcript;
while( false == transcript.empty() ) {
// WriteLog( "Transcript text with no display/hide times: \"" + transcript + "\"" );
AddLine( data_text_to_utf8( transcript ), 0.0, static_cast<float>(0.12 * static_cast<double>(transcript.size())), false );
transcript = ""; parser >> transcript;
}
}
// usuwanie niepotrzebnych (nie częściej niż 10 razy na sekundę)
void
TTranscripts::Update() {
// HACK: detect day change
if( fRefreshTime - Global.fTimeAngleDeg > 180 ) {
fRefreshTime -= 360;
}
if( Global.fTimeAngleDeg < fRefreshTime ) { return; } // nie czas jeszcze na zmiany
// remove expired lines
while( false == aLines.empty() ) {
// HACK: detect day change
if( aLines.front().fHide - Global.fTimeAngleDeg > 180 ) {
aLines.front().fShow -= 360;
aLines.front().fHide -= 360;
}
if( Global.fTimeAngleDeg <= aLines.front().fHide ) {
// no expired lines yet
break;
}
aLines.pop_front(); // this line expired, discard it and start anew with the next one
}
// update next refresh time
if( false == aLines.empty() ) { fRefreshTime = aLines.front().fHide; }
else { fRefreshTime = 360.0f; }
}
} // namespace ui