|  |  | @ -7,29 +7,34 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | #include <QVBoxLayout> |  |  |  | #include <QVBoxLayout> | 
			
		
	
		
		
			
				
					
					|  |  |  | #include <QDesktopWidget> |  |  |  | #include <QDesktopWidget> | 
			
		
	
		
		
			
				
					
					|  |  |  | #include <QPainter> |  |  |  | #include <QPainter> | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "common/params.h" |  |  |  | #include "common/params.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "onboarding.hpp" |  |  |  | #include "onboarding.hpp" | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "home.hpp" |  |  |  | #include "home.hpp" | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "util.h" |  |  |  | #include "util.h" | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) { |  |  |  | void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |   int leftOffset = (geometry().width()-1620)/2; |  |  |  |   int leftOffset = (geometry().width()-1620)/2; | 
			
		
	
		
		
			
				
					
					|  |  |  |   int mousex = e->x()-leftOffset; |  |  |  |   int mousex = e->x()-leftOffset; | 
			
		
	
		
		
			
				
					
					|  |  |  |   int mousey = e->y(); |  |  |  |   int mousey = e->y(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   // Check for restart
 |  |  |  |   // Check for restart
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (currentIndex == (boundingBox.size() - 1) && 1050 <= mousex && mousex <= 1500 && 773 <= mousey && mousey <= 954) { |  |  |  |   if (currentIndex == (boundingBox.size() - 1) && 1050 <= mousex && mousex <= 1500 && | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       773 <= mousey && mousey <= 954) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     currentIndex = 0; |  |  |  |     currentIndex = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |   } else if (boundingBox[currentIndex][0] <= mousex && mousex <= boundingBox[currentIndex][1] && boundingBox[currentIndex][2] <= mousey && mousey <= boundingBox[currentIndex][3]) { |  |  |  |   } else if (boundingBox[currentIndex][0] <= mousex && mousex <= boundingBox[currentIndex][1] && | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     ++currentIndex; |  |  |  |              boundingBox[currentIndex][2] <= mousey && mousey <= boundingBox[currentIndex][3]) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     currentIndex += 1; | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (currentIndex >= boundingBox.size()) { |  |  |  |   if (currentIndex >= boundingBox.size()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     emit completedTraining(); |  |  |  |     emit completedTraining(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     return; |  |  |  |     return; | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } else { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     image.load("../assets/training/step" + QString::number(currentIndex) + ".jpg"); |  |  |  |     image.load("../assets/training/step" + QString::number(currentIndex) + ".jpg"); | 
			
		
	
		
		
			
				
					
					|  |  |  |   repaint(); |  |  |  |     update(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | TrainingGuide::TrainingGuide(QWidget* parent) { |  |  |  | TrainingGuide::TrainingGuide(QWidget* parent) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -51,7 +56,7 @@ void TrainingGuide::paintEvent(QPaintEvent *event) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | QWidget* OnboardingWindow::terms_screen() { |  |  |  | QWidget* OnboardingWindow::terms_screen() { | 
			
		
	
		
		
			
				
					
					|  |  |  |   QVBoxLayout *main_layout = new QVBoxLayout; |  |  |  |   QVBoxLayout *main_layout = new QVBoxLayout; | 
			
		
	
		
		
			
				
					
					|  |  |  |   main_layout->setContentsMargins(40, 20, 40, 0); |  |  |  |   main_layout->setContentsMargins(40, 20, 40, 20); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   QString terms_html = QString::fromStdString(util::read_file("../assets/offroad/tc.html")); |  |  |  |   QString terms_html = QString::fromStdString(util::read_file("../assets/offroad/tc.html")); | 
			
		
	
		
		
			
				
					
					|  |  |  |   terms_text = new QTextEdit(); |  |  |  |   terms_text = new QTextEdit(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -95,8 +100,12 @@ QWidget* OnboardingWindow::terms_screen() { | 
			
		
	
		
		
			
				
					
					|  |  |  |   QScroller::grabGesture(terms_text, QScroller::TouchGesture); |  |  |  |   QScroller::grabGesture(terms_text, QScroller::TouchGesture); | 
			
		
	
		
		
			
				
					
					|  |  |  |   terms_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |  |  |  |   terms_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 
			
		
	
		
		
			
				
					
					|  |  |  | #endif |  |  |  | #endif | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   QObject::connect(sb, &QScrollBar::valueChanged, [sb, accept_btn]() { |  |  |  |   QObject::connect(sb, &QScrollBar::valueChanged, [sb, accept_btn]() { | 
			
		
	
		
		
			
				
					
					|  |  |  |     accept_btn->setEnabled(accept_btn->isEnabled() || (sb->value() == sb->maximum())); |  |  |  |     if (sb->value() == sb->maximum()){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       accept_btn->setText("Accept"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       accept_btn->setEnabled(true); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |   }); |  |  |  |   }); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   QWidget *widget = new QWidget; |  |  |  |   QWidget *widget = new QWidget; | 
			
		
	
	
		
		
			
				
					|  |  | @ -116,10 +125,9 @@ QWidget* OnboardingWindow::terms_screen() { | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | void OnboardingWindow::updateActiveScreen() { |  |  |  | void OnboardingWindow::updateActiveScreen() { | 
			
		
	
		
		
			
				
					
					|  |  |  |   Params params = Params(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0; |  |  |  |   bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |   bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0; |  |  |  |   bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (!accepted_terms) { |  |  |  |   if (!accepted_terms) { | 
			
		
	
		
		
			
				
					
					|  |  |  |     setCurrentIndex(0); |  |  |  |     setCurrentIndex(0); | 
			
		
	
		
		
			
				
					
					|  |  |  |   } else if (!training_done) { |  |  |  |   } else if (!training_done) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -130,16 +138,9 @@ void OnboardingWindow::updateActiveScreen() { | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { |  |  |  | OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { | 
			
		
	
		
		
			
				
					
					|  |  |  |   Params params = Params(); |  |  |  |   params = Params(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |   current_terms_version = params.get("TermsVersion", false); |  |  |  |   current_terms_version = params.get("TermsVersion", false); | 
			
		
	
		
		
			
				
					
					|  |  |  |   current_training_version = params.get("TrainingVersion", false); |  |  |  |   current_training_version = params.get("TrainingVersion", false); | 
			
		
	
		
		
			
				
					
					|  |  |  |   bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   // Don't initialize widgets unless neccesary.
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   if (accepted_terms && training_done) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     return; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   addWidget(terms_screen()); |  |  |  |   addWidget(terms_screen()); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |