From 6b24a39944e19e530dbbdc7223325685599bc632 Mon Sep 17 00:00:00 2001 From: milek7 Date: Fri, 16 Feb 2018 18:04:17 +0100 Subject: [PATCH] on-screen log --- Globals.cpp | 4 ++++ Globals.h | 1 + Logs.cpp | 9 +++++++++ Logs.h | 4 +++- World.cpp | 8 ++++++++ uilayer.cpp | 2 ++ uilayer.h | 3 ++- 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index 48e3fa8b..284ba8ef 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -622,6 +622,10 @@ global_settings::ConfigParse(cParser &Parser) { Parser.getTokens( 1 ); Parser >> uart_conf.debug; } + else if (token == "loadinglog") { + Parser.getTokens( 1 ); + Parser >> loading_log; + } } while ((token != "") && (token != "endconfig")); //(!Parser->EndOfFile) // na koniec trochę zależności if (!bLoadTraction) // wczytywanie drutów i słupów diff --git a/Globals.h b/Globals.h index d484e95e..4003b3b0 100644 --- a/Globals.h +++ b/Globals.h @@ -166,6 +166,7 @@ struct global_settings { std::string asVersion{ "UNKNOWN" }; // z opisem motiontelemetry::conf_t motiontelemetry_conf; std::string screenshot_dir; + bool loading_log = true; // methods void LoadIniFile( std::string asFileName ); diff --git a/Logs.cpp b/Logs.cpp index 0df4c1b9..2167cac1 100644 --- a/Logs.cpp +++ b/Logs.cpp @@ -13,6 +13,9 @@ http://mozilla.org/MPL/2.0/. #include "Globals.h" #include "winheaders.h" #include "utilities.h" +#include "uilayer.h" + +std::shared_ptr ui_log = std::make_shared( 20, 140 ); std::ofstream output; // standardowy "log.txt", można go wyłączyć std::ofstream errors; // lista błędów "errors.txt", zawsze działa @@ -82,6 +85,10 @@ void WriteLog( const char *str, logtype const Type ) { output.flush(); } + ui_log->text_lines.emplace_back(std::string(str), Global.UITextColor); + if (ui_log->text_lines.size() > 20) + ui_log->text_lines.pop_front(); + #ifdef _WIN32 if( Global.iWriteLogEnabled & 2 ) { // hunter-271211: pisanie do konsoli tylko, gdy nie jest ukrywana @@ -90,6 +97,8 @@ void WriteLog( const char *str, logtype const Type ) { WriteConsole( GetStdHandle( STD_OUTPUT_HANDLE ), str, (DWORD)strlen( str ), &wr, NULL ); WriteConsole( GetStdHandle( STD_OUTPUT_HANDLE ), endstring, (DWORD)strlen( endstring ), &wr, NULL ); } +#else + printf("%s\n", str); #endif } diff --git a/Logs.h b/Logs.h index dee95e5f..514421b5 100644 --- a/Logs.h +++ b/Logs.h @@ -9,7 +9,7 @@ http://mozilla.org/MPL/2.0/. #pragma once -#include +#include "uilayer.h" enum logtype : unsigned int { @@ -26,3 +26,5 @@ void ErrorLog( const std::string &str, logtype const Type = logtype::generic ); void WriteLog( const std::string &str, logtype const Type = logtype::generic ); void CommLog( const char *str ); void CommLog( const std::string &str ); + +extern std::shared_ptr ui_log; diff --git a/World.cpp b/World.cpp index 692d25a8..a640ae70 100644 --- a/World.cpp +++ b/World.cpp @@ -245,6 +245,8 @@ bool TWorld::Init( GLFWwindow *Window ) { WriteLog( "\nStarting MaSzyna rail vehicle simulator (release: " + Global.asVersion + ")" ); WriteLog( "For online documentation and additional files refer to: http://eu07.pl"); + if (Global.loading_log) + UILayer.push_back( ui_log ); UILayer.set_background( "logo" ); glfwSetWindowTitle( window, ( Global.AppName + " (" + Global.SceneryFile + ")" ).c_str() ); // nazwa scenerii UILayer.set_progress(0.01); @@ -342,6 +344,8 @@ bool TWorld::Init( GLFWwindow *Window ) { UILayer.push_back( UIHeader ); UILayer.push_back( UITable ); UILayer.push_back( UITranscripts ); + UILayer.push_back( ui_log ); + ui_log->enabled = false; return true; }; @@ -596,6 +600,10 @@ void TWorld::OnKeyDown(int cKey) { } break; } + case GLFW_KEY_F11: { + ui_log->enabled = !ui_log->enabled; + break; + } case GLFW_KEY_F12: { // coś tam jeszcze if( Global.ctrlState diff --git a/uilayer.cpp b/uilayer.cpp index c403168d..70c5820c 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -193,6 +193,8 @@ ui_layer::render_panels() { float const height = Global.iWindowHeight / 768.f; for( auto const &panel : m_panels ) { + if (!panel->enabled) + continue; int lineidx = 0; for( auto const &line : panel->text_lines ) { diff --git a/uilayer.h b/uilayer.h index e16aaf55..a3b396d5 100644 --- a/uilayer.h +++ b/uilayer.h @@ -21,7 +21,8 @@ struct ui_panel { origin_x(X), origin_y(Y) {} - std::vector text_lines; + bool enabled = true; + std::deque text_lines; int origin_x; int origin_y; };