Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions example_community_patch_settings_da.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[======================================================================================================]>
#
# ***** * * *
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=======================================]>
#
# **** ** **
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_en-GB-x-cockney.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=======================================]>
#
# **** ** **
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_en-x-minionese.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=======================================]>
#
# **** ** **
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=======================================]>
#
# **** ** **
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=====================================================]>
#
# * * *
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=======================================]>
#
# **** ** **
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_nl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=======================================]>
#
# **** ** **
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_ru.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[============================================================]>
#
#
Expand Down
9 changes: 9 additions & 0 deletions example_community_patch_settings_tlh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ disabled_events = ""
# Write audio event names to the trace log for troubleshooting
trace_events = false

# Optional generated notification cues; "none" disables an alert.
# Available sounds: default, info, success, warning, alarm, arrival, soft, ping, repair
# Requires patches.toastbannerhooks = true.
alert_victory = "none"
alert_defeat = "none"
alert_armada_created = "none"
alert_armada_battle_won = "none"
alert_armada_battle_lost = "none"

# <[=====================================================]>
#
# * * **** * *
Expand Down
54 changes: 54 additions & 0 deletions mods/src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ namespace DCS = DefaultConfig::Sync;
namespace DCSC = DefaultConfig::SystemConfig;
namespace DCSH = DefaultConfig::Shortcuts;

namespace
{
struct ToastAudioAlertConfig {
int toast_state;
std::string_view config_name;
std::string_view default_sound;
NotificationSound Config::* config_member;
};

constexpr auto kToastAudioAlerts = std::to_array<ToastAudioAlertConfig>({
{ToastState::Victory, "alert_victory", DCA::alert_victory, &Config::alert_victory},
{ToastState::Defeat, "alert_defeat", DCA::alert_defeat, &Config::alert_defeat},
{ToastState::ArmadaCreated, "alert_armada_created", DCA::alert_armada_created, &Config::alert_armada_created},
{ToastState::ArmadaBattleWon, "alert_armada_battle_won", DCA::alert_armada_battle_won,
&Config::alert_armada_battle_won},
{ToastState::ArmadaBattleLost, "alert_armada_battle_lost", DCA::alert_armada_battle_lost,
&Config::alert_armada_battle_lost},
});
} // namespace

static const eastl::tuple<const char*, int> bannerTypes[] = {
{"All", ToastState::All},
{"Standard", ToastState::Standard},
Expand Down Expand Up @@ -128,6 +148,12 @@ Config& Config::Get()
return config;
}

NotificationSound Config::NotificationSoundForToast(int toast_state) const
{
const auto alert = std::ranges::find(kToastAudioAlerts, toast_state, &ToastAudioAlertConfig::toast_state);
return alert == kToastAudioAlerts.end() ? NotificationSound::None : this->*(alert->config_member);
}

MissionHudVisibility Config::MissionHudButtonVisibility(std::string_view button_name) const
{
const auto it = this->mission_hud_buttons.find(std::string(button_name));
Expand Down Expand Up @@ -330,6 +356,25 @@ T get_config_or_default(toml::table& config, toml::table& new_config, std::strin
return (T)final_value;
}

NotificationSound get_notification_sound(toml::table& config, toml::table& new_config, std::string_view item,
std::string_view default_value, bool write_log)
{
const auto value = get_config_or_default<std::string>(config, new_config, "audio", item,
std::string(default_value), false);
auto sound = notification_sound_from_name(StripAsciiWhitespace(value));
if (!sound.has_value()) {
spdlog::warn("invalid config value audio.{}: '{}'; using {}", item, value, default_value);
sound = notification_sound_from_name(default_value);
}

const auto result = sound.value_or(NotificationSound::None);
new_config["audio"].as_table()->insert_or_assign(item, notification_sound_name(result));
if (write_log) {
spdlog::debug("config value audio.{} value: {}", item, notification_sound_name(result));
}
return result;
}

std::string_view to_string(MissionHudVisibility visibility)
{
switch (visibility) {
Expand Down Expand Up @@ -1036,6 +1081,15 @@ void Config::Load()
}
}
this->installAudioEventHooks = this->trace_audio_events || !this->disabled_audio_events.empty();
bool any_toast_audio_alert_configured = false;
for (const auto& alert : kToastAudioAlerts) {
const auto sound = get_notification_sound(config, parsed, alert.config_name, alert.default_sound, write_config);
this->*(alert.config_member) = sound;
any_toast_audio_alert_configured |= sound != NotificationSound::None;
}
if (!this->installToastBannerHooks && any_toast_audio_alert_configured) {
spdlog::warn("audio alerts require patches.toastbannerhooks = true");
}
this->auto_open_bulk_claim_flyout = get_config_or_default(config, parsed, "ui", "auto_open_bulk_claim_flyout",
DCU::auto_open_bulk_claim_flyout, write_config);

Expand Down
8 changes: 8 additions & 0 deletions mods/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <toml++/toml.h>

#include "patches/notification_audio.h"

#if _WIN32
#include <Windows.h>
#endif
Expand Down Expand Up @@ -152,6 +154,7 @@ class Config final

[[nodiscard]] MissionHudVisibility MissionHudButtonVisibility(std::string_view button_name) const;
[[nodiscard]] bool MissionHudTweaksEnabled() const;
[[nodiscard]] NotificationSound NotificationSoundForToast(int toast_state) const;

// Disallow copying/moving to enforce singleton
Config(const Config&) = delete;
Expand Down Expand Up @@ -211,6 +214,11 @@ class Config final
bool disable_toast_banners;
bool trace_audio_events;
std::vector<std::string> disabled_audio_events;
NotificationSound alert_victory = NotificationSound::None;
NotificationSound alert_defeat = NotificationSound::None;
NotificationSound alert_armada_created = NotificationSound::None;
NotificationSound alert_armada_battle_won = NotificationSound::None;
NotificationSound alert_armada_battle_lost = NotificationSound::None;
bool auto_open_bulk_claim_flyout;
bool auto_confirm_ft_upgrade;

Expand Down
5 changes: 5 additions & 0 deletions mods/src/defaultconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace Audio
{
constexpr const char* disabled_events = "";
constexpr bool trace_events = false;
constexpr const char* alert_victory = "none";
constexpr const char* alert_defeat = "none";
constexpr const char* alert_armada_created = "none";
constexpr const char* alert_armada_battle_won = "none";
constexpr const char* alert_armada_battle_lost = "none";
} // namespace Audio

namespace SystemConfig
Expand Down
27 changes: 27 additions & 0 deletions mods/src/notification_audio_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifdef __APPLE__

#include "patches/notification_audio_platform.h"

#import <AppKit/AppKit.h>

bool notification_audio_platform_play(const uint8_t* data, size_t size)
{
@autoreleasepool {
static NSSound* current_sound = nil;

NSData* sound_data = [NSData dataWithBytesNoCopy:const_cast<uint8_t*>(data) length:size freeWhenDone:NO];
NSSound* sound = [[NSSound alloc] initWithData:sound_data];
if (!sound) return false;

[current_sound stop];
#if __has_feature(objc_arc)
current_sound = sound;
#else
[current_sound release];
current_sound = sound;
#endif
return [current_sound play];
}
}

#endif
Loading
Loading