Skip to content

Commit

Permalink
Fix doubled sounds in some places
Browse files Browse the repository at this point in the history
TeachingTip double-click workaround is here too, but its time is only 300ms... it won't stop spamming or slower double-clicks
  • Loading branch information
KimihikoAkayasaki committed Oct 4, 2022
1 parent 4832aea commit e09aa20
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 105 deletions.
21 changes: 17 additions & 4 deletions Amethyst/DevicesPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ Windows::Foundation::IAsyncAction Amethyst::implementation::DevicesPage::SetAsBa
// Update the status here
ReloadSelectedDevice(true);

SetDeviceTypeFlyout().Hide(); // Hide the flyout
LOG(INFO) << "Changed the current tracking device (Base) to " <<
WStringToString(selectedTrackingDeviceGUIDPair.first);

// Animate adding the expanders
{
// Remove the only one child of our outer main content grid
Expand Down Expand Up @@ -797,6 +801,8 @@ Windows::Foundation::IAsyncAction Amethyst::implementation::DevicesPage::DeviceC
void Amethyst::implementation::DevicesPage::ButtonFlyout_Opening(
const Windows::Foundation::IInspectable& sender, const Windows::Foundation::IInspectable& e)
{
LOG(INFO) << "Device assignment flyout opening...";

// Play a sound
playAppSound(k2app::interfacing::sounds::AppSounds::Show);
}
Expand All @@ -806,8 +812,11 @@ void Amethyst::implementation::DevicesPage::ButtonFlyout_Closing(
const Controls::Primitives::FlyoutBase& sender,
const Controls::Primitives::FlyoutBaseClosingEventArgs& args)
{
LOG(INFO) << "Device assignment flyout closing...";

// Play a sound
playAppSound(k2app::interfacing::sounds::AppSounds::Hide);
if (devices_signal_joints)
playAppSound(k2app::interfacing::sounds::AppSounds::Hide);
}


Expand Down Expand Up @@ -934,8 +943,7 @@ k2app::shared::devices::ReloadSelectedDevice(

// Refresh the device list MVVM
TrackingDevices::RefreshDevicesMVVMList();

setDeviceTypeFlyout->Hide();

if (TrackingDevices::IsABase(selectedTrackingDeviceGUIDPair.first))
{
LOG(INFO) << "Selected a base";
Expand Down Expand Up @@ -1016,13 +1024,18 @@ void Amethyst::implementation::DevicesPage::PluginManagerFlyout_Opening(
void Amethyst::implementation::DevicesPage::PluginManagerFlyout_Closing(
const Windows::Foundation::IInspectable& sender, const Windows::Foundation::IInspectable& e)
{
LOG(INFO) << "Manager flyout closing...";

// Play a sound
playAppSound(k2app::interfacing::sounds::AppSounds::Hide);
if (devices_signal_joints)
playAppSound(k2app::interfacing::sounds::AppSounds::Hide);
}

void Amethyst::implementation::DevicesPage::PluginManagerFlyout_Closed(
const Windows::Foundation::IInspectable& sender, const Windows::Foundation::IInspectable& e)
{
LOG(INFO) << "Manager flyout closed!";

k2app::shared::main::interfaceBlockerGrid->Opacity(0.0);
k2app::shared::main::interfaceBlockerGrid->IsHitTestVisible(false);

Expand Down
2 changes: 2 additions & 0 deletions Amethyst/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<Page.Resources>
<TeachingTip x:Name="NoCalibrationTeachingTip"
Closed="NoCalibrationTeachingTip_Closed"
PreferredPlacement="Top"
IsLightDismissEnabled="True"
Title="[CONTENT NOT SET]"
Expand Down Expand Up @@ -1029,6 +1030,7 @@

<ToggleButton.Resources>
<muxc:TeachingTip x:Name="FreezeTrackingTeachingTip"
Closed="NoCalibrationTeachingTip_Closed"
Target="{Binding ElementName=ToggleTrackingButton}"
PreferredPlacement="Top"
IsLightDismissEnabled="True"
Expand Down
31 changes: 26 additions & 5 deletions Amethyst/GeneralPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,12 +1250,12 @@ void Amethyst::implementation::GeneralPage::sk_dot(
// Move the ellipse to the appropriate point
ellipse.Margin({
// Left
joint.getJointPosition().x() * 300. *
joint.getJointPosition().x() * 300. *
std::min(s_scale_w, s_scale_h) * s_multiply +
s_mat_width / 2. - (s_ellipse_wh + s_ellipse_stroke) / 2.,

// Top
joint.getJointPosition().y() * -300. *
joint.getJointPosition().y() * -300. *
std::min(s_scale_w, s_scale_h) * s_multiply +
s_mat_height / 3. - (s_ellipse_wh + s_ellipse_stroke) / 2.,

Expand Down Expand Up @@ -1642,9 +1642,9 @@ void Amethyst::implementation::GeneralPage::CalibrationButton_Click(
if (k2app::K2Settings.overrideDeviceGUIDsMap.empty())
{
// Get our current device
const auto& trackingDevice =
const auto& trackingDevice =
TrackingDevices::TrackingDevicesVector.at(
k2app::K2Settings.trackingDeviceGUIDPair.second);
k2app::K2Settings.trackingDeviceGUIDPair.second);

HRESULT device_status = E_FAIL;
switch (trackingDevice.index())
Expand Down Expand Up @@ -1672,8 +1672,11 @@ void Amethyst::implementation::GeneralPage::CalibrationButton_Click(
NoCalibrationTeachingTip().PreferredPlacement(
Controls::TeachingTipPlacementMode::Top);

k2app::shared::main::interfaceBlockerGrid->IsHitTestVisible(true);
NoCalibrationTeachingTip().IsOpen(true);

Sleep(300);

// Give up
return;
}
Expand Down Expand Up @@ -1819,8 +1822,12 @@ void Amethyst::implementation::GeneralPage::CalibrationButton_Click(
// Hide the tail and open the tip
NoCalibrationTeachingTip().TailVisibility(
Controls::TeachingTipTailVisibility::Collapsed);

k2app::shared::main::interfaceBlockerGrid->IsHitTestVisible(true);
NoCalibrationTeachingTip().IsOpen(true);

Sleep(300);

// Give up
return;
}
Expand Down Expand Up @@ -1921,6 +1928,8 @@ void Amethyst::implementation::GeneralPage::ToggleTrackingButton_Click(
L"Tips/TrackingFreeze/Footer").c_str());

FreezeTrackingTeachingTip().TailVisibility(Controls::TeachingTipTailVisibility::Collapsed);

k2app::shared::main::interfaceBlockerGrid->IsHitTestVisible(true);
FreezeTrackingTeachingTip().IsOpen(true);

k2app::K2Settings.teachingTipShown_Freeze = true;
Expand Down Expand Up @@ -2165,16 +2174,20 @@ Amethyst::implementation::GeneralPage::TrackingDeviceTreeView_ItemInvoked(
{
// Set the correct target
NoCalibrationTeachingTip().Target(TrackingDeviceTreeView().
ContainerFromItem(args.InvokedItem()).as<Microsoft::UI::Xaml::FrameworkElement>());
ContainerFromItem(args.InvokedItem()).as<
Microsoft::UI::Xaml::FrameworkElement>());

// Hide the tail and open the tip
NoCalibrationTeachingTip().TailVisibility(
Controls::TeachingTipTailVisibility::Collapsed);
NoCalibrationTeachingTip().PreferredPlacement(
Controls::TeachingTipPlacementMode::Bottom);

k2app::shared::main::interfaceBlockerGrid->IsHitTestVisible(true);
NoCalibrationTeachingTip().IsOpen(true);

Sleep(300);

// Give up
co_return;
}
Expand Down Expand Up @@ -2477,3 +2490,11 @@ Windows::Foundation::IAsyncAction Amethyst::implementation::GeneralPage::Execute
k2app::K2Settings.skeletonPreviewEnabled = show_skeleton_previous; // Change to whatever
skeleton_visibility_set_ui(show_skeleton_previous); // Change to whatever
}


void Amethyst::implementation::GeneralPage::NoCalibrationTeachingTip_Closed(
const Controls::TeachingTip& sender,
const Controls::TeachingTipClosedEventArgs& args)
{
k2app::shared::main::interfaceBlockerGrid->IsHitTestVisible(false);
}
7 changes: 5 additions & 2 deletions Amethyst/GeneralPage.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace winrt::Amethyst::implementation
void SkeletonDrawingCanvas_Loaded(const Windows::Foundation::IInspectable& sender,
const Microsoft::UI::Xaml::RoutedEventArgs& e);
void CalibrationButton_Click(const Windows::Foundation::IInspectable& sender,
const Microsoft::UI::Xaml::RoutedEventArgs& e);
const Microsoft::UI::Xaml::RoutedEventArgs& e);
void ReRegisterButton_Click(const Windows::Foundation::IInspectable& sender,
const Microsoft::UI::Xaml::RoutedEventArgs& e);
void DismissSetErrorButton_Click(const Windows::Foundation::IInspectable& sender,
Expand Down Expand Up @@ -124,7 +124,10 @@ namespace winrt::Amethyst::implementation
Windows::Foundation::IAsyncAction TrackingDeviceTreeView_ItemInvoked(
const Microsoft::UI::Xaml::Controls::TreeView& sender,
const Microsoft::UI::Xaml::Controls::TreeViewItemInvokedEventArgs& args);
};
void NoCalibrationTeachingTip_Closed(
const Microsoft::UI::Xaml::Controls::TeachingTip& sender,
const Microsoft::UI::Xaml::Controls::TeachingTipClosedEventArgs& args);
};
}

namespace winrt::Amethyst::factory_implementation
Expand Down
9 changes: 7 additions & 2 deletions Amethyst/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,18 @@
Canvas.ZIndex="1" IsHitTestVisible="False" />

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
x:Name="InterfaceDimGrid"
Background="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}"
x:Name="InterfaceBlockerGrid" Opacity="0.0"
Opacity="{Binding ElementName=InterfaceBlockerGrid, Path=Opacity}"
Canvas.ZIndex="1" IsHitTestVisible="False">

<Grid.OpacityTransition>
<ScalarTransition />
</Grid.OpacityTransition>
</Grid>

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
x:Name="InterfaceBlockerGrid" Opacity="0.0"
Canvas.ZIndex="1" IsHitTestVisible="False">

<Grid.Resources>
<TeachingTip x:Name="InitializerTeachingTip"
Expand Down
42 changes: 25 additions & 17 deletions Amethyst/OffsetsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ namespace winrt::Microsoft::UI::Xaml::Controls
// Underlying object shared pointer
std::shared_ptr<Pivot> _ptr_container;

// Creation flag
std::atomic_bool setup_finished;

// Creation: register a host and a callback
void Create()
{
Expand All @@ -118,27 +121,32 @@ namespace winrt::Microsoft::UI::Xaml::Controls
_ptr_container->SelectionChanged(
[&, this](const auto&, const auto&) -> void
{
// The last item
if (_ptr_container->SelectedIndex() == _ptr_container->Items().Size() - 1)
{
playAppSound(previous_item_index == 0
? k2app::interfacing::sounds::AppSounds::MovePrevious
: k2app::interfacing::sounds::AppSounds::MoveNext);
}
// The first item
else if (_ptr_container->SelectedIndex() == 0)
// The 1st one doesn't count!
if (setup_finished)
{
playAppSound(previous_item_index == _ptr_container->Items().Size() - 1
? k2app::interfacing::sounds::AppSounds::MoveNext
: k2app::interfacing::sounds::AppSounds::MovePrevious);
// The last item
if (_ptr_container->SelectedIndex() == _ptr_container->Items().Size() - 1)
{
playAppSound(previous_item_index == 0
? k2app::interfacing::sounds::AppSounds::MovePrevious
: k2app::interfacing::sounds::AppSounds::MoveNext);
}
// The first item
else if (_ptr_container->SelectedIndex() == 0)
{
playAppSound(previous_item_index == _ptr_container->Items().Size() - 1
? k2app::interfacing::sounds::AppSounds::MoveNext
: k2app::interfacing::sounds::AppSounds::MovePrevious);
}
// Default
else
playAppSound(_ptr_container->SelectedIndex() > previous_item_index
? k2app::interfacing::sounds::AppSounds::MoveNext
: k2app::interfacing::sounds::AppSounds::MovePrevious);
}
// Default
else
playAppSound(_ptr_container->SelectedIndex() > previous_item_index
? k2app::interfacing::sounds::AppSounds::MoveNext
: k2app::interfacing::sounds::AppSounds::MovePrevious);

previous_item_index = _ptr_container->SelectedIndex();
setup_finished = true; // Mark setup/1st run as done
});

// Push all the trackers & read values
Expand Down
1 change: 1 addition & 0 deletions Amethyst/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
HorizontalAlignment="Right">
<ToggleSwitch.Resources>
<muxc:TeachingTip x:Name="ToggleFlipTeachingTip"
Closed="ToggleFlipTeachingTip_Closed"
Target="{Binding ElementName=FlipToggleDummyGrid}"
PreferredPlacement="Bottom"
IsLightDismissEnabled="True"
Expand Down
Loading

0 comments on commit e09aa20

Please sign in to comment.