Visuals - Custom Themes - Random Events

Enjoy a bit of unpredictability with random events that can occur during certain driving conditions. This is purely cosmetic and has no impact on driving controls!
This commit is contained in:
FrogAi
2024-07-07 05:26:08 -07:00
parent 3be51ac310
commit 38df29bd11
23 changed files with 252 additions and 11 deletions
+44 -2
View File
@@ -19,6 +19,18 @@ void drawIcon(QPainter &p, const QPoint &center, const QPixmap &img, const QBrus
p.restore();
}
void drawIconGif(QPainter &p, const QPoint &center, const QMovie &img, const QBrush &bg, float opacity) {
p.setRenderHint(QPainter::Antialiasing);
p.setOpacity(1.0); // bg dictates opacity of ellipse
p.setPen(Qt::NoPen);
p.setBrush(bg);
p.drawEllipse(center.x() - btn_size / 2, center.y() - btn_size / 2, btn_size, btn_size);
p.setOpacity(opacity);
QPixmap currentFrame = img.currentPixmap();
p.drawPixmap(center - QPoint(currentFrame.width() / 2, currentFrame.height() / 2), currentFrame);
p.setOpacity(1.0);
}
// ExperimentalButton
ExperimentalButton::ExperimentalButton(QWidget *parent) : experimental_mode(false), engageable(false), QPushButton(parent) {
setFixedSize(btn_size, btn_size);
@@ -36,6 +48,13 @@ ExperimentalButton::ExperimentalButton(QWidget *parent) : experimental_mode(fals
{5, loadPixmap("../frogpilot/assets/wheel_images/hyundai.png", {img_size, img_size})},
{6, loadPixmap("../frogpilot/assets/wheel_images/stalin.png", {img_size, img_size})},
};
wheelImagesGif = {
{0, new QMovie("../frogpilot/assets/random_events/images/firefox.gif", QByteArray(), this)},
{1, new QMovie("../frogpilot/assets/random_events/images/weeb_wheel.gif", QByteArray(), this)},
{2, new QMovie("../frogpilot/assets/random_events/images/tree_fiddy.gif", QByteArray(), this)},
{3, new QMovie("../frogpilot/assets/random_events/images/great_scott.gif", QByteArray(), this)},
};
}
void ExperimentalButton::changeMode() {
@@ -67,13 +86,31 @@ void ExperimentalButton::updateState(const UIState &s) {
conditionalExperimental = scene.conditional_experimental;
conditionalStatus = scene.conditional_status;
navigateOnOpenpilot = scene.navigate_on_openpilot;
randomEvent = scene.current_random_event;
rotatingWheel = scene.rotating_wheel;
trafficModeActive = scene.traffic_mode_active;
wheelIcon = scene.wheel_icon;
wheelIconGif = 0;
if (rotatingWheel && steeringAngleDeg != scene.steering_angle_deg) {
if (randomEvent == 0 && gifLabel) {
delete gifLabel;
gifLabel = nullptr;
} else if (randomEvent == 1 || randomEvent == 2 || randomEvent == 3 || randomEvent == 4) {
gifLabel = new QLabel(this);
QMovie *movie = wheelImagesGif[randomEvent - 1];
if (movie) {
movie->setScaledSize(QSize(img_size, img_size));
gifLabel->setMovie(movie);
gifLabel->move((width() - gifLabel->width()) / 2, (height() - gifLabel->height()) / 2);
gifLabel->movie()->start();
}
wheelIconGif = randomEvent - 1;
update();
} else if (rotatingWheel && steeringAngleDeg != scene.steering_angle_deg) {
steeringAngleDeg = scene.steering_angle_deg;
update();
} else if (!rotatingWheel) {
steeringAngleDeg = 0;
}
@@ -87,6 +124,7 @@ void ExperimentalButton::paintEvent(QPaintEvent *event) {
QPainter p(this);
engage_img = wheelImages[wheelIcon];
QPixmap img = wheelIcon != 0 ? engage_img : (experimental_mode ? experimental_img : engage_img);
QMovie *gif = wheelImagesGif[wheelIconGif];
QColor background_color = wheelIcon != 0 && !isDown() && engageable ?
(alwaysOnLateralActive ? bg_colors[STATUS_ALWAYS_ON_LATERAL_ACTIVE] :
@@ -96,7 +134,11 @@ void ExperimentalButton::paintEvent(QPaintEvent *event) {
(navigateOnOpenpilot ? bg_colors[STATUS_NAVIGATION_ACTIVE] : QColor(0, 0, 0, 166)))))) :
QColor(0, 0, 0, 166);
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, QColor(0, 0, 0, 166), (isDown() || !engageable) ? 0.6 : 1.0, steeringAngleDeg);
if (wheelIconGif != 0) {
drawIconGif(p, QPoint(btn_size / 2, btn_size / 2), *gif, background_color, 1.0);
} else {
drawIcon(p, QPoint(btn_size / 2, btn_size / 2), img, background_color, (isDown() || !engageable) ? 0.6 : 1.0, steeringAngleDeg);
}
}
// MapSettingsButton
+7
View File
@@ -1,5 +1,7 @@
#pragma once
#include <QLabel>
#include <QMovie>
#include <QPushButton>
#include "selfdrive/ui/ui.h"
@@ -32,10 +34,15 @@ private:
bool trafficModeActive;
int conditionalStatus;
int randomEvent;
int steeringAngleDeg;
int wheelIcon;
int wheelIconGif;
QLabel *gifLabel;
QMap<int, QPixmap> wheelImages;
QMap<int, QMovie*> wheelImagesGif;
Params paramsMemory{"/dev/shm/params"};
};
+35 -4
View File
@@ -41,6 +41,17 @@ sound_list: dict[int, tuple[str, int | None, float]] = {
AudibleAlert.warningSoft: ("warning_soft.wav", None, MAX_VOLUME),
AudibleAlert.warningImmediate: ("warning_immediate.wav", None, MAX_VOLUME),
# Random Events
AudibleAlert.angry: ("angry.wav", 1, MAX_VOLUME),
AudibleAlert.dejaVu: ("dejaVu.wav", 1, MAX_VOLUME),
AudibleAlert.doc: ("doc.wav", 1, MAX_VOLUME),
AudibleAlert.fart: ("fart.wav", 1, MAX_VOLUME),
AudibleAlert.firefox: ("firefox.wav", 1, MAX_VOLUME),
AudibleAlert.hal9000: ("hal9000.wav", 1, MAX_VOLUME),
AudibleAlert.nessie: ("nessie.wav", 1, MAX_VOLUME),
AudibleAlert.noice: ("noice.wav", 1, MAX_VOLUME),
AudibleAlert.uwu: ("uwu.wav", 1, MAX_VOLUME),
# Other
AudibleAlert.goat: ("goat.wav", None, MAX_VOLUME),
}
@@ -69,6 +80,20 @@ class Soundd:
self.frogpilot_toggles = FrogPilotVariables.toggles
self.previous_sound_directory = None
self.random_events_directory = BASEDIR + "/selfdrive/frogpilot/assets/random_events/sounds/"
self.random_events_map = {
AudibleAlert.angry: MAX_VOLUME,
AudibleAlert.dejaVu: MAX_VOLUME,
AudibleAlert.doc: MAX_VOLUME,
AudibleAlert.fart: MAX_VOLUME,
AudibleAlert.firefox: MAX_VOLUME,
AudibleAlert.goat: MAX_VOLUME,
AudibleAlert.hal9000: MAX_VOLUME,
AudibleAlert.nessie: MAX_VOLUME,
AudibleAlert.noice: MAX_VOLUME,
AudibleAlert.uwu: MAX_VOLUME,
}
self.update_toggles = False
@@ -81,12 +106,15 @@ class Soundd:
for sound in sound_list:
filename, play_count, volume = sound_list[sound]
try:
if sound in self.random_events_map:
wavefile = wave.open(self.random_events_directory + filename, 'r')
else:
if sound == AudibleAlert.goat and not self.frogpilot_toggles.goat_scream:
continue
wavefile = wave.open(self.sound_directory + filename, 'r')
except FileNotFoundError:
wavefile = wave.open(BASEDIR + "/selfdrive/assets/sounds/" + filename, 'r')
try:
wavefile = wave.open(self.sound_directory + filename, 'r')
except FileNotFoundError:
wavefile = wave.open(BASEDIR + "/selfdrive/assets/sounds/" + filename, 'r')
assert wavefile.getnchannels() == 1
assert wavefile.getsampwidth() == 2
@@ -172,6 +200,9 @@ class Soundd:
elif self.frogpilot_toggles.alert_volume_control and self.current_alert in self.volume_map:
self.current_volume = self.volume_map[self.current_alert] / 100.0
elif self.current_alert in self.random_events_map:
self.current_volume = self.random_events_map[self.current_alert]
self.get_audible_alert(sm)
rk.keep_time()
+2
View File
@@ -336,6 +336,7 @@ void ui_update_frogpilot_params(UIState *s, Params &params) {
scene.custom_icons = custom_theme ? params.getInt("CustomIcons") : 0;
scene.custom_signals = custom_theme ? params.getInt("CustomSignals") : 0;
scene.holiday_themes = custom_theme && params.getBool("HolidayThemes");
scene.random_events = custom_theme && params.getBool("RandomEvents");
scene.disable_smoothing_mtsc = params.getBool("MTSCEnabled") && params.getBool("DisableMTSCSmoothing");
scene.disable_smoothing_vtsc = params.getBool("VisionTurnControl") && params.getBool("DisableVTSCSmoothing");
@@ -461,6 +462,7 @@ void UIState::update() {
// FrogPilot variables that need to be constantly updated
scene.conditional_status = scene.conditional_experimental && scene.enabled ? paramsMemory.getInt("CEStatus") : 0;
scene.current_holiday_theme = scene.holiday_themes ? paramsMemory.getInt("CurrentHolidayTheme") : 0;
scene.current_random_event = scene.random_events ? paramsMemory.getInt("CurrentRandomEvent") : 0;
scene.started_timer = scene.started || started_prev ? scene.started_timer + 1 : 0;
}
+2
View File
@@ -146,6 +146,7 @@ typedef struct UIScene {
bool onroad_distance_button;
bool parked;
bool pedals_on_ui;
bool random_events;
bool red_light;
bool reverse;
bool reverse_cruise;
@@ -189,6 +190,7 @@ typedef struct UIScene {
int conditional_speed_lead;
int conditional_status;
int current_holiday_theme;
int current_random_event;
int custom_colors;
int custom_icons;
int custom_signals;